Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poc/web extension #873

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"streetsidesoftware.code-spell-checker",
"eamodio.gitlens",
"ms-playwright.playwright",
"wayou.vscode-todo-highlight"
"wayou.vscode-todo-highlight",
"firsttris.vscode-jest-runner"
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
"[prisma]": {
"editor.defaultFormatter": "Prisma.prisma"
},
"json.schemas": [
{
"fileMatch": ["apps/jetstream-web-extension/public/manifest.json"],
"url": "https://json.schemastore.org/chrome-manifest.json"
}
],
"typescript.updateImportsOnFileMove.enabled": "always",
"editor.tabCompletion": "on",
"editor.defaultFormatter": "esbenp.prettier-vscode",
Expand Down
100 changes: 76 additions & 24 deletions apps/api/src/app/controllers/sf-misc.controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ORG_VERSION_PLACEHOLDER } from '@jetstream/shared/constants';
import { toBoolean } from '@jetstream/shared/utils';
import { GenericRequestPayload, ManualRequestPayload, ManualRequestResponse } from '@jetstream/types';
import { CompositeResponse, GenericRequestPayload, ManualRequestPayload, ManualRequestResponse } from '@jetstream/types';
import axios, { AxiosError, AxiosRequestConfig } from 'axios';
import { NextFunction, Request, Response } from 'express';
import { body, query } from 'express-validator';
import * as jsforce from 'jsforce';
import { isObject, isString } from 'lodash';
import * as request from 'superagent';
import { UserFacingError } from '../utils/error-handler';
import { sendJson } from '../utils/response.handlers';
import * as request from 'superagent';

const SESSION_ID_RGX = /\{sessionId\}/i;

Expand Down Expand Up @@ -183,51 +183,103 @@ export async function recordOperation(req: Request, res: Response, next: NextFun
// FIXME: add express validator to operation
const { sobject, operation } = req.params;
const { externalId } = req.query;
// FIXME: move to express validator to do data conversion

const allOrNone = toBoolean(req.query.allOrNone as string, true);
// TODO: validate combination based on operation or add validation to case statement
// ids and records can be one or an array
const { ids, records } = req.body;
const isTooling = toBoolean(req.query.isTooling as string, false);
let { ids, records } = req.body;

const conn: jsforce.Connection = res.locals.jsforceConn;
const sobjectOperation = conn.sobject(sobject);

// FIXME: submit PR to fix these types - allOrNone / allowRecursive
const options: any = { allOrNone };
if (ids) {
ids = Array.isArray(ids) ? ids : [ids];
}
if (records) {
records = Array.isArray(records) ? records : [records];
}

let operationPromise: Promise<unknown>;
const baseUrl = `/services/data/v${conn.version}`;
const headers = { Accept: 'application/json', 'Content-Type': 'application/json' };

switch (operation) {
case 'retrieve':
if (!ids) {
case 'retrieve': {
if (!Array.isArray(ids)) {
return next(new UserFacingError(`The ids property must be included`));
}
operationPromise = sobjectOperation.retrieve(ids, options);
operationPromise = conn
.request<CompositeResponse>({
method: 'POST',
headers,
url: `/composite`,
body: JSON.stringify({
allOrNone,
compositeRequest: ids
.map((id) => (isTooling ? `${baseUrl}/tooling/sobjects/${sobject}/${id}` : `${baseUrl}/sobjects/${sobject}/${id}`))
.map((url, i) => ({ method: 'GET', url: url, referenceId: `${i}` })),
}),
})
.then((response) => response.compositeResponse.map((item) => item.body));
break;
case 'create':
if (!records) {
}
case 'create': {
if (!Array.isArray(records)) {
return next(new UserFacingError(`The records property must be included`));
}
operationPromise = sobjectOperation.create(records, options);
operationPromise = conn.request({
method: 'POST',
headers,
url: isTooling ? `${baseUrl}/tooling/composite/sobjects` : `${baseUrl}/composite/sobjects`,
body: JSON.stringify({
allOrNone,
records: records.map((record) => ({ ...record, attributes: { type: sobject }, Id: undefined })),
}),
});
break;
case 'update':
if (!records) {
}
case 'update': {
if (!Array.isArray(records)) {
return next(new UserFacingError(`The records property must be included`));
}
operationPromise = sobjectOperation.update(records, options);
operationPromise = conn.request({
method: 'PATCH',
headers,
url: isTooling ? `${baseUrl}/tooling/composite/sobjects` : `${baseUrl}/composite/sobjects`,
body: JSON.stringify({
allOrNone,
records: records.map((record) => ({ ...record, attributes: { type: sobject }, Id: record.Id })),
}),
});
break;
case 'upsert':
if (!records || !externalId) {
}
case 'upsert': {
if (!Array.isArray(records) || !externalId) {
return next(new UserFacingError(`The records and external id properties must be included`));
}
operationPromise = sobjectOperation.upsert(records, externalId as string, options);
operationPromise = conn.request({
method: 'PATCH',
headers,
url: isTooling
? `${baseUrl}/tooling/composite/sobjects/${sobject}/${externalId}`
: `${baseUrl}/composite/sobjects/${sobject}/${externalId}`,
body: JSON.stringify({
allOrNone,
records: records.map((record) => ({ ...record, attributes: { type: sobject } })),
}),
});
break;
case 'delete':
if (!ids) {
}
case 'delete': {
if (!Array.isArray(ids)) {
return next(new UserFacingError(`The ids property must be included`));
}
operationPromise = sobjectOperation.delete(ids, options);
operationPromise = conn.request({
method: 'DELETE',
url: isTooling
? `${baseUrl}/tooling/composite/sobjects?ids=${ids.join(',')}`
: `${baseUrl}/composite/sobjects?ids=${ids.join(',')}`,
});
break;
}
default:
return next(new UserFacingError(`The operation ${operation} is not valid`));
}
Expand Down
12 changes: 12 additions & 0 deletions apps/jetstream-web-extension/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"@nx/react/babel",
{
"runtime": "automatic",
"importSource": "@emotion/react"
}
]
],
"plugins": ["@emotion/babel-plugin"]
}
18 changes: 18 additions & 0 deletions apps/jetstream-web-extension/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["plugin:@nx/react", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
11 changes: 11 additions & 0 deletions apps/jetstream-web-extension/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: 'jetstream-web-extension',
preset: '../../jest.preset.js',
transform: {
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',
'^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nx/react/babel'] }],
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/apps/jetstream-web-extension',
};
46 changes: 46 additions & 0 deletions apps/jetstream-web-extension/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "Jetstream",
"description": "Jetstream is a set of tools that supercharge your administration of Salesforce.com.",
"version": "1.0",
"manifest_version": 3,
"action": {
"default_popup": "popup.html"
},
"permissions": ["storage", "cookies", "activeTab"],
"host_permissions": [
"https://*.cloudforce.com/*",
"https://*.force.com/*",
"https://*.lightning.force.com/*",
"https://*.salesforce.com/*",
"https://*.visual.force.com/*",
"https://*.visualforce.com/*"
],
"background": {
"service_worker": "serviceWorker.js"
},
"options_ui": {
"page": "options.html",
"open_in_tab": true
},
"content_scripts": [
{
"matches": [
"https://*.cloudforce.com/*",
"https://*.force.com/*",
"https://*.lightning.force.com/*",
"https://*.salesforce.com/*",
"https://*.visual.force.com/*",
"https://*.visualforce.com/*"
],
"all_frames": true,
"js": ["contentScript.js"]
}
],
"web_accessible_resources": [
{
"resources": ["*.html", "*.js", "*.css", "*.map", "*.png", "*.svg", "/app/", "/assets/"],
"matches": ["https://*.salesforce.com/*", "https://*.force.com/*", "https://*.cloudforce.com/*", "https://*.visualforce.com/*"]
}
],
"minimum_chrome_version": "100"
}
70 changes: 70 additions & 0 deletions apps/jetstream-web-extension/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"name": "jetstream-web-extension",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/jetstream-web-extension/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nx/webpack:webpack",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"compiler": "babel",
"outputPath": "dist/apps/jetstream-web-extension",
"baseHref": "/",
"tsConfig": "apps/jetstream-web-extension/tsconfig.app.json",
"assets": ["apps/jetstream-web-extension/src/favicon.ico", "apps/jetstream-web-extension/src/assets"],
"styles": [],
"scripts": [],
"webpackConfig": "apps/jetstream-web-extension/webpack.config.js"
},
"configurations": {
"development": {
"extractLicenses": false,
"optimization": false,
"sourceMap": true,
"vendorChunk": false
},
"production": {
"fileReplacements": [],
"optimization": false,
"outputHashing": "none",
"sourceMap": true,
"namedChunks": false,
"extractLicenses": false,
"vendorChunk": false
}
}
},
"serve": {
"executor": "@nx/webpack:dev-server",
"defaultConfiguration": "development",
"options": {
"buildTarget": "jetstream-web-extension:build",
"port": 4201,
"hmr": true
},
"configurations": {
"development": {
"buildTarget": "jetstream-web-extension:build:development"
},
"production": {
"buildTarget": "jetstream-web-extension:build:production",
"hmr": false
}
}
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"]
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "apps/jetstream-web-extension/jest.config.ts"
}
}
},
"tags": []
}
10 changes: 10 additions & 0 deletions apps/jetstream-web-extension/src/app/Settings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function App() {
return (
<h1>
<span> Hello there, </span>
Welcome jetstream-web-extension 👋
</h1>
);
}

export default App;
Loading