@bigid/apps-infrastructure-node-js 0.2.0 → 1.180.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/.github/workflows/bigid_config +3 -0
  2. package/.github/workflows/npmjs_config +3 -0
  3. package/.github/workflows/{build-and-push.yml → private-registry-publish.yml} +5 -2
  4. package/.github/workflows/public-registry-publish.yml +17 -0
  5. package/CODEOWNERS +1 -0
  6. package/README.md +31 -2
  7. package/jsdoc.json +14 -0
  8. package/lib/abstractProviders/configureProvider.d.ts +10 -0
  9. package/lib/abstractProviders/configureProvider.js +19 -0
  10. package/lib/abstractProviders/index.d.ts +1 -0
  11. package/lib/abstractProviders/index.js +3 -1
  12. package/lib/abstractProviders/logsProvider.js +9 -1
  13. package/lib/abstractProviders/manifestProvider.d.ts +2 -1
  14. package/lib/dto/actionResponseDetails.d.ts +3 -1
  15. package/lib/dto/actionResponseDetails.js +2 -1
  16. package/lib/dto/executionContext.d.ts +8 -4
  17. package/lib/dto/index.d.ts +1 -1
  18. package/lib/dto/subExecutionItem.d.ts +7 -0
  19. package/lib/dto/subExecutionItem.js +12 -0
  20. package/lib/dto/tenantRegistration.d.ts +5 -0
  21. package/lib/dto/tenantRegistration.js +2 -0
  22. package/lib/index.d.ts +1 -1
  23. package/lib/index.js +16 -2
  24. package/lib/server.d.ts +10 -6
  25. package/lib/server.js +14 -9
  26. package/lib/services/actionsHubService.d.ts +45 -0
  27. package/lib/services/actionsHubService.js +105 -0
  28. package/lib/services/batchProcessManager.d.ts +2 -0
  29. package/lib/services/batchProcessManager.js +45 -0
  30. package/lib/services/bigidProxyService.d.ts +18 -2
  31. package/lib/services/bigidProxyService.js +34 -14
  32. package/lib/services/dataSourceService.d.ts +4 -0
  33. package/lib/services/dataSourceService.js +26 -0
  34. package/lib/services/encryptionService.d.ts +1 -0
  35. package/lib/services/encryptionService.js +67 -0
  36. package/lib/services/index.d.ts +3 -0
  37. package/lib/services/index.js +12 -1
  38. package/lib/services/schedulerService.d.ts +11 -0
  39. package/lib/services/schedulerService.js +41 -0
  40. package/lib/utils/appLogger.d.ts +10 -1
  41. package/lib/utils/appLogger.js +38 -7
  42. package/lib/utils/index.d.ts +1 -1
  43. package/lib/utils/index.js +15 -3
  44. package/lib/utils/tokenUtil.d.ts +3 -0
  45. package/lib/utils/tokenUtil.js +62 -0
  46. package/package.json +11 -4
  47. package/src/abstractProviders/configureProvider.ts +15 -0
  48. package/src/abstractProviders/index.ts +1 -0
  49. package/src/abstractProviders/logsProvider.ts +11 -3
  50. package/src/abstractProviders/manifestProvider.ts +3 -1
  51. package/src/dto/actionResponseDetails.ts +5 -1
  52. package/src/dto/executionContext.ts +9 -4
  53. package/src/dto/index.ts +2 -2
  54. package/src/dto/subExecutionItem.ts +13 -0
  55. package/src/dto/tenantRegistration.ts +5 -0
  56. package/src/index.ts +17 -1
  57. package/src/server.ts +33 -20
  58. package/src/services/actionsHubService.ts +141 -0
  59. package/src/services/batchProcessManager.ts +39 -0
  60. package/src/services/bigidProxyService.ts +48 -24
  61. package/src/services/dataSourceService.ts +20 -0
  62. package/src/services/encryptionService.ts +44 -0
  63. package/src/services/index.ts +5 -1
  64. package/src/services/schedulerService.ts +39 -0
  65. package/src/utils/appLogger.ts +44 -6
  66. package/src/utils/index.ts +1 -1
  67. package/src/utils/tokenUtil.ts +65 -0
  68. package/.dcignore +0 -1547
  69. package/.idea/apps-infrastructure-node-js.iml +0 -9
  70. package/.idea/misc.xml +0 -6
  71. package/.idea/modules.xml +0 -8
  72. package/.idea/prettier.xml +0 -7
  73. package/.idea/runConfigurations.xml +0 -10
  74. package/.idea/snyk.project.settings.xml +0 -6
  75. package/.idea/vcs.xml +0 -6
@@ -0,0 +1,3 @@
1
+ registry = https://artifactory.bigid-integrations.net/artifactory/api/npm/NPM-Private/
2
+ //artifactory.bigid-integrations.net/artifactory/api/npm/NPM-Private/:_authToken = ${TOKEN}
3
+ always-auth = true
@@ -0,0 +1,3 @@
1
+ registry = https://registry.npmjs.org/
2
+ //registry.npmjs.org/:_authToken = ${TOKEN}
3
+ always-auth = true
@@ -1,5 +1,6 @@
1
- name: Upload to artifactory
1
+ name: Upload to private registry
2
2
  on:
3
+ workflow_dispatch:
3
4
  push:
4
5
  branches:
5
6
  - main
@@ -8,6 +9,8 @@ jobs:
8
9
  runs-on: ubuntu-latest
9
10
  steps:
10
11
  - uses: actions/checkout@v2.1.1
11
- - run: npm publish --userconfig .github/workflows/.npmrc
12
+ - run: npm i
13
+ - run: tsc
14
+ - run: npm publish --userconfig .github/workflows/bigid_config
12
15
  env:
13
16
  TOKEN: ${{ secrets.TOKEN }}
@@ -0,0 +1,17 @@
1
+ name: Upload to public registry - npmjs
2
+ on:
3
+ workflow_dispatch:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ Upload:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v2.1.1
13
+ - run: npm i
14
+ - run: tsc
15
+ - run: npm publish --userconfig .github/workflows/npmjs_config
16
+ env:
17
+ TOKEN: ${{ secrets.NPMJS_TOKEN }}
package/CODEOWNERS ADDED
@@ -0,0 +1 @@
1
+ * @bigexchange/app_admins
package/README.md CHANGED
@@ -3,9 +3,38 @@ The applications infrastructure for node.js is a wrapper for node application.
3
3
 
4
4
  This wrapper handles all the necessary endpoints for communicate with bigid, provide dtos and logger for quick application development.
5
5
 
6
- ### HOW TO USE?
6
+ ## HOW TO USE?
7
7
  First get the package from npm.
8
8
 
9
9
  ```npm install @bigid/apps-infrastructure-node-js```
10
10
 
11
- After the package installed - implement all the providers in your application and in your root app file use ```deployServer()``` for creating the server.
11
+ After the package installed - implement all the providers in your application and in your root app file use ```deployServer()``` for creating the server.
12
+
13
+ ## How to use sdk's scheduler service?
14
+ If you have any function that needs to be running for each of the tenants that uses the application in any time period
15
+ you can use the sdk's scheduler service.
16
+
17
+ First import the schedule function
18
+
19
+ ```const { scheduleFunction } = require('apps-infrastructure-node-js');```
20
+
21
+ Then call it with the necessary params
22
+
23
+ ```scheduleFunction('dailyInsightUniqueName', '* * * * *', callbackToExecute)```
24
+
25
+ But before you are running your application please make sure you configure the next environment variables
26
+ depends where the application was deployed
27
+
28
+ ###Single tenant mode
29
+ BIGID_BASE_URL - bigid url
30
+
31
+ BIGID_REFRESH_TOKEN - refresh token that will be used to execute api calls
32
+
33
+ ###Multi tenant mode
34
+ BIGID_BASE_URL - bigid url
35
+
36
+ AUTH0_DOMAIN - auth0 domain where the application configured - will be provided by BigID's application framework team
37
+
38
+ CLIENT_ID - client id of the application in auth0 - will be provided by BigID's application framework team
39
+
40
+ CLIENT_SECRET - client secret of the application - will be provided by BigID's application framework team
package/jsdoc.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "source": {
3
+ "include": [
4
+ "./lib"
5
+ ],
6
+ "includePattern": ".js$"
7
+ },
8
+ "opts": {
9
+ "encoding": "utf8",
10
+ "readme": "./readme.md",
11
+ "destination": "docs/",
12
+ "recurse": true
13
+ }
14
+ }
@@ -0,0 +1,10 @@
1
+ import { Request, Response } from 'express';
2
+ export type ConfigurePayload = {
3
+ tenantId: string;
4
+ bigidBaseUrl?: string;
5
+ isDeleted?: boolean;
6
+ };
7
+ export declare const handleTenantConfigure: (req: Request, res: Response, configureProvider: ConfigureProvider) => Promise<void>;
8
+ export declare abstract class ConfigureProvider {
9
+ abstract configureTenant(configurePayload: ConfigurePayload, res: Response): Promise<void> | void;
10
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ConfigureProvider = exports.handleTenantConfigure = void 0;
13
+ const handleTenantConfigure = (req, res, configureProvider) => __awaiter(void 0, void 0, void 0, function* () {
14
+ yield configureProvider.configureTenant(req.body, res);
15
+ });
16
+ exports.handleTenantConfigure = handleTenantConfigure;
17
+ class ConfigureProvider {
18
+ }
19
+ exports.ConfigureProvider = ConfigureProvider;
@@ -1,3 +1,4 @@
1
1
  export { ManifestProvider } from './manifestProvider';
2
2
  export { IconsProviders } from './iconsProviders';
3
3
  export { ExecutionProvider, StatusEnum } from './executionProvider';
4
+ export { ConfigureProvider, ConfigurePayload } from './configureProvider';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StatusEnum = exports.ExecutionProvider = exports.IconsProviders = exports.ManifestProvider = void 0;
3
+ exports.ConfigureProvider = exports.StatusEnum = exports.ExecutionProvider = exports.IconsProviders = exports.ManifestProvider = void 0;
4
4
  var manifestProvider_1 = require("./manifestProvider");
5
5
  Object.defineProperty(exports, "ManifestProvider", { enumerable: true, get: function () { return manifestProvider_1.ManifestProvider; } });
6
6
  var iconsProviders_1 = require("./iconsProviders");
@@ -8,3 +8,5 @@ Object.defineProperty(exports, "IconsProviders", { enumerable: true, get: functi
8
8
  var executionProvider_1 = require("./executionProvider");
9
9
  Object.defineProperty(exports, "ExecutionProvider", { enumerable: true, get: function () { return executionProvider_1.ExecutionProvider; } });
10
10
  Object.defineProperty(exports, "StatusEnum", { enumerable: true, get: function () { return executionProvider_1.StatusEnum; } });
11
+ var configureProvider_1 = require("./configureProvider");
12
+ Object.defineProperty(exports, "ConfigureProvider", { enumerable: true, get: function () { return configureProvider_1.ConfigureProvider; } });
@@ -3,5 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchLogs = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const constants_1 = require("../utils/constants");
6
- const fetchLogs = (req, res) => (0, fs_1.createReadStream)(constants_1.LOGS_PATH).pipe(res);
6
+ const fetchLogs = (req, res) => {
7
+ const tenantId = req.headers.tenantid;
8
+ const data = (0, fs_1.readFileSync)(constants_1.LOGS_PATH, { encoding: 'utf8' });
9
+ const lines = data.split('\n');
10
+ const tenantLogLines = lines
11
+ .filter(line => line.includes(`[tenantId: ${tenantId}`) || !line.includes('[tenantId: '))
12
+ .join('\n');
13
+ return res.send(tenantLogLines);
14
+ };
7
15
  exports.fetchLogs = fetchLogs;
@@ -1,3 +1,4 @@
1
+ import { Response, Request } from 'express';
1
2
  export declare abstract class ManifestProvider {
2
- abstract getManifest(req: any, res: any): string;
3
+ abstract getManifest(req: Request, res: Response): Response;
3
4
  }
@@ -1,8 +1,10 @@
1
+ import { SubExecutionItem } from "./subExecutionItem";
1
2
  export declare class ActionResponseDetails {
2
3
  executionId: string;
3
4
  statusEnum: string;
4
5
  progress: number;
5
6
  message: string;
6
7
  additionalData?: any;
7
- constructor(executionId: string, statusEnum: string, progress: number, message: string, additionalData?: any);
8
+ subExecutionItems?: SubExecutionItem[];
9
+ constructor(executionId: string, statusEnum: string, progress: number, message: string, additionalData?: any, subExecutionItems?: SubExecutionItem[]);
8
10
  }
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ActionResponseDetails = void 0;
4
4
  class ActionResponseDetails {
5
- constructor(executionId, statusEnum, progress, message, additionalData) {
5
+ constructor(executionId, statusEnum, progress, message, additionalData, subExecutionItems) {
6
6
  this.executionId = executionId;
7
7
  this.statusEnum = statusEnum;
8
8
  this.progress = progress;
9
9
  this.message = message;
10
10
  this.additionalData = additionalData;
11
+ this.subExecutionItems = subExecutionItems;
11
12
  }
12
13
  }
13
14
  exports.ActionResponseDetails = ActionResponseDetails;
@@ -1,10 +1,14 @@
1
- export interface ExecutionContext {
1
+ export type ExecutionContext = {
2
2
  actionName: string;
3
3
  executionId: string;
4
- globalParams: Record<string, string>;
5
- actionParams: Record<string, string>;
4
+ globalParams: Array<GeneralParam>;
5
+ actionParams: Array<GeneralParam>;
6
6
  bigidBaseUrl: string;
7
7
  bigidToken: string;
8
8
  updateResultCallback: any;
9
9
  tpaId: string;
10
- }
10
+ };
11
+ export type GeneralParam = {
12
+ paramName: string;
13
+ paramValue: string;
14
+ };
@@ -1,2 +1,2 @@
1
- export { ExecutionContext } from './executionContext';
1
+ export { ExecutionContext, GeneralParam } from './executionContext';
2
2
  export { ActionResponseDetails } from './actionResponseDetails';
@@ -0,0 +1,7 @@
1
+ export declare class SubExecutionItem {
2
+ name: string;
3
+ statusEnum: string;
4
+ message?: string;
5
+ errorCode?: string;
6
+ constructor(name: string, statusEnum: string, message?: string, errorCode?: string);
7
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SubExecutionItem = void 0;
4
+ class SubExecutionItem {
5
+ constructor(name, statusEnum, message, errorCode) {
6
+ this.name = name;
7
+ this.statusEnum = statusEnum;
8
+ this.message = message;
9
+ this.errorCode = errorCode;
10
+ }
11
+ }
12
+ exports.SubExecutionItem = SubExecutionItem;
@@ -0,0 +1,5 @@
1
+ export type TenantRegistration = {
2
+ tenantId: string;
3
+ tenantDomain: string;
4
+ companyName: string;
5
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './abstractProviders';
2
2
  export * from './dto';
3
3
  export * from './utils';
4
- export { updateActionStatusToBigID, uploadAttachment, getValueFromAppStorage, saveInStorage, executeHttpGet } from './services';
4
+ export { updateActionStatusToBigID, uploadAttachment, getValueFromAppStorage, saveInStorage, executeHttpGet, scheduleFunction, unscheduleFunction, unscheduleAllFunctions, deleteKeyFromAppStorage, sendBiEvent, getCommandsRegistrations, executeCommand, getExecutionStatus, registerActionAsCommand, fetchDataSourceCredentials, } from './services';
5
5
  export { deployServer, ServerInit } from './server';
package/lib/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -10,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
15
  };
12
16
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.deployServer = exports.executeHttpGet = exports.saveInStorage = exports.getValueFromAppStorage = exports.uploadAttachment = exports.updateActionStatusToBigID = void 0;
17
+ exports.deployServer = exports.fetchDataSourceCredentials = exports.registerActionAsCommand = exports.getExecutionStatus = exports.executeCommand = exports.getCommandsRegistrations = exports.sendBiEvent = exports.deleteKeyFromAppStorage = exports.unscheduleAllFunctions = exports.unscheduleFunction = exports.scheduleFunction = exports.executeHttpGet = exports.saveInStorage = exports.getValueFromAppStorage = exports.uploadAttachment = exports.updateActionStatusToBigID = void 0;
14
18
  __exportStar(require("./abstractProviders"), exports);
15
19
  __exportStar(require("./dto"), exports);
16
20
  __exportStar(require("./utils"), exports);
@@ -20,5 +24,15 @@ Object.defineProperty(exports, "uploadAttachment", { enumerable: true, get: func
20
24
  Object.defineProperty(exports, "getValueFromAppStorage", { enumerable: true, get: function () { return services_1.getValueFromAppStorage; } });
21
25
  Object.defineProperty(exports, "saveInStorage", { enumerable: true, get: function () { return services_1.saveInStorage; } });
22
26
  Object.defineProperty(exports, "executeHttpGet", { enumerable: true, get: function () { return services_1.executeHttpGet; } });
27
+ Object.defineProperty(exports, "scheduleFunction", { enumerable: true, get: function () { return services_1.scheduleFunction; } });
28
+ Object.defineProperty(exports, "unscheduleFunction", { enumerable: true, get: function () { return services_1.unscheduleFunction; } });
29
+ Object.defineProperty(exports, "unscheduleAllFunctions", { enumerable: true, get: function () { return services_1.unscheduleAllFunctions; } });
30
+ Object.defineProperty(exports, "deleteKeyFromAppStorage", { enumerable: true, get: function () { return services_1.deleteKeyFromAppStorage; } });
31
+ Object.defineProperty(exports, "sendBiEvent", { enumerable: true, get: function () { return services_1.sendBiEvent; } });
32
+ Object.defineProperty(exports, "getCommandsRegistrations", { enumerable: true, get: function () { return services_1.getCommandsRegistrations; } });
33
+ Object.defineProperty(exports, "executeCommand", { enumerable: true, get: function () { return services_1.executeCommand; } });
34
+ Object.defineProperty(exports, "getExecutionStatus", { enumerable: true, get: function () { return services_1.getExecutionStatus; } });
35
+ Object.defineProperty(exports, "registerActionAsCommand", { enumerable: true, get: function () { return services_1.registerActionAsCommand; } });
36
+ Object.defineProperty(exports, "fetchDataSourceCredentials", { enumerable: true, get: function () { return services_1.fetchDataSourceCredentials; } });
23
37
  var server_1 = require("./server");
24
38
  Object.defineProperty(exports, "deployServer", { enumerable: true, get: function () { return server_1.deployServer; } });
package/lib/server.d.ts CHANGED
@@ -1,10 +1,14 @@
1
- import { ManifestProvider } from './abstractProviders/manifestProvider';
2
- import { IconsProviders } from './abstractProviders/iconsProviders';
1
+ import { Express } from 'express';
2
+ import { ManifestProvider } from './abstractProviders';
3
+ import { IconsProviders } from './abstractProviders';
3
4
  import { ExecutionProvider } from './abstractProviders/executionProvider';
4
- export interface ServerInit {
5
+ import { ConfigureProvider } from './abstractProviders/configureProvider';
6
+ export type ServerInit = {
5
7
  manifestController: ManifestProvider;
6
8
  iconsController: IconsProviders;
7
- executionController: ExecutionProvider;
9
+ executionController?: ExecutionProvider;
10
+ configureController?: ConfigureProvider;
8
11
  serverPort?: number;
9
- }
10
- export declare const deployServer: (serverInit: ServerInit) => void;
12
+ additionalEndpoints?: (app: Express) => void;
13
+ };
14
+ export declare const deployServer: ({ manifestController, iconsController, executionController, serverPort, configureController, additionalEndpoints, }: ServerInit) => void;
package/lib/server.js CHANGED
@@ -14,26 +14,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.deployServer = void 0;
16
16
  const express_1 = __importDefault(require("express"));
17
- const appLogger_1 = require("./utils/appLogger");
17
+ const utils_1 = require("./utils");
18
18
  const executionProvider_1 = require("./abstractProviders/executionProvider");
19
19
  const logsProvider_1 = require("./abstractProviders/logsProvider");
20
20
  const http_errors_1 = __importDefault(require("http-errors"));
21
+ const configureProvider_1 = require("./abstractProviders/configureProvider");
21
22
  const app = (0, express_1.default)();
22
- const deployServer = (serverInit) => {
23
+ const deployServer = ({ manifestController, iconsController, executionController, serverPort, configureController, additionalEndpoints, }) => {
23
24
  app.use(express_1.default.json());
24
25
  app.use(express_1.default.urlencoded({ extended: false }));
25
- app.get('/assets/icon', (req, res) => res.sendFile(serverInit.iconsController.getIconPath()));
26
- app.get('/assets/sideBarIcon', (req, res) => res.sendFile(serverInit.iconsController.getSideBarIconPath()));
27
- app.get('/manifest', serverInit.manifestController.getManifest);
28
- app.post('/execute', (req, res) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, executionProvider_1.handleExecution)(req, res, serverInit.executionController); }));
29
- app.get('/logs', logsProvider_1.fetchLogs);
30
- app.listen(process.env.PORT || serverInit.serverPort, () => appLogger_1.appLogger.info(`Started server at port ${process.env.PORT || serverInit.serverPort}`));
26
+ app.get('/assets/icon', (req, res) => res.sendFile(iconsController.getIconPath()));
27
+ app.get('/assets/sideBarIcon', (req, res) => res.sendFile(iconsController.getSideBarIconPath()));
28
+ app.get('/manifest', manifestController.getManifest);
29
+ app.get('/logs', (req, res) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, logsProvider_1.fetchLogs)(req, res); }));
30
+ executionController &&
31
+ app.post('/execute', (req, res) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, executionProvider_1.handleExecution)(req, res, executionController); }));
32
+ configureController &&
33
+ app.post('/configure', (req, res) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, configureProvider_1.handleTenantConfigure)(req, res, configureController); }));
34
+ additionalEndpoints && additionalEndpoints(app);
35
+ app.listen(process.env.PORT || serverPort, () => (0, utils_1.logInfo)(`Started server at port ${process.env.PORT || serverPort}`));
31
36
  // catch 404 and forward to error handler
32
37
  app.use((req, res, next) => next((0, http_errors_1.default)(404)));
33
38
  // error handler
34
39
  app.use((err, req, res, next) => {
35
40
  const { message, status } = err;
36
- appLogger_1.appLogger.error(err);
41
+ (0, utils_1.logError)(err);
37
42
  res.locals.message = message;
38
43
  res.locals.error = req.app.get('env') === 'development' ? err : {};
39
44
  res.status(status || 500);
@@ -0,0 +1,45 @@
1
+ export type Param = {
2
+ name: string;
3
+ value: string;
4
+ };
5
+ export type Command = {
6
+ actionName: string;
7
+ command: string;
8
+ params: Param[];
9
+ id: string;
10
+ };
11
+ /**
12
+ * use this method to get the currently registered action-center commands.
13
+ * the method is building an execution context for the api call, so you must provide REFRESH_TOKEN and BIGID_BASE_URL as ENV variables
14
+ *
15
+ * @return {Promise<Command[]>} array of the action-center register commands
16
+ */
17
+ export declare const getCommandsRegistrations: () => Promise<Command[]>;
18
+ /**
19
+ * use this method to execute an action-center commands.
20
+ * this method is used without endpoint for getting status messages, but rather return an execution id.
21
+ * the execution id can be used to poll the current execution status of the executed command.
22
+ *
23
+ * @param {string} actionName - the action name to be executed.
24
+ * @param {string} command - the command to be executed.
25
+ * @param {string} requestorAppName - the app name of the execution requestor.
26
+ * @param {string} webhookEndpoint - the endpoint of the requestor app to receive execution status messages.
27
+ * @param {Record<string, any>} params - the relevant params of the action to be executed.
28
+ * @return {Promise<string>} execution id of the executed action.
29
+ */
30
+ export declare const executeCommand: (actionName: string, command: string, requestorAppName?: string, webhookEndpoint?: string, params?: Record<string, any>[]) => Promise<string>;
31
+ /**
32
+ * use this method to poll an execution status from the action-center.
33
+ *
34
+ * @param {string} execution - the execution id to poll status for.
35
+ * @return object with the updated status details.
36
+ */
37
+ export declare const getExecutionStatus: (executionId: string) => Promise<any>;
38
+ /**
39
+ * use this method to register application action as an action center command.
40
+ *
41
+ * @param {string} applicationName - the application name of the command to be registered.
42
+ * @param {string} actionName - the action name of the command to be registered.
43
+ * @param {string} command - the command to be registered.
44
+ */
45
+ export declare const registerActionAsCommand: (applicationName: string, actionName: string, command: string) => Promise<void>;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.registerActionAsCommand = exports.getExecutionStatus = exports.executeCommand = exports.getCommandsRegistrations = void 0;
13
+ const bigidProxyService_1 = require("./bigidProxyService");
14
+ const tokenUtil_1 = require("../utils/tokenUtil");
15
+ const REFRESH_TOKEN = process.env.BIGID_REFRESH_TOKEN;
16
+ const getBigidAccessToken = () => __awaiter(void 0, void 0, void 0, function* () {
17
+ if (!REFRESH_TOKEN) {
18
+ throw new Error('BIGID_REFRESH_TOKEN must be supplied as an ENV var in order to call bigid actions hub');
19
+ }
20
+ return yield (0, tokenUtil_1.getAccessTokenFromRefreshToken)(REFRESH_TOKEN);
21
+ });
22
+ /**
23
+ * use this method to get the currently registered action-center commands.
24
+ * the method is building an execution context for the api call, so you must provide REFRESH_TOKEN and BIGID_BASE_URL as ENV variables
25
+ *
26
+ * @return {Promise<Command[]>} array of the action-center register commands
27
+ */
28
+ const getCommandsRegistrations = () => __awaiter(void 0, void 0, void 0, function* () {
29
+ try {
30
+ const bigidToken = yield getBigidAccessToken();
31
+ const { data: { commands }, } = yield (0, bigidProxyService_1.doCallToUrl)(bigidToken, bigidProxyService_1.RequestMethod.GET, `${process.env.BIGID_BASE_URL}/api/v1/action-center/general-commands`);
32
+ return commands;
33
+ }
34
+ catch (e) {
35
+ throw new Error(`Could not get commands registrations from bigid: ${e}`);
36
+ }
37
+ });
38
+ exports.getCommandsRegistrations = getCommandsRegistrations;
39
+ /**
40
+ * use this method to execute an action-center commands.
41
+ * this method is used without endpoint for getting status messages, but rather return an execution id.
42
+ * the execution id can be used to poll the current execution status of the executed command.
43
+ *
44
+ * @param {string} actionName - the action name to be executed.
45
+ * @param {string} command - the command to be executed.
46
+ * @param {string} requestorAppName - the app name of the execution requestor.
47
+ * @param {string} webhookEndpoint - the endpoint of the requestor app to receive execution status messages.
48
+ * @param {Record<string, any>} params - the relevant params of the action to be executed.
49
+ * @return {Promise<string>} execution id of the executed action.
50
+ */
51
+ const executeCommand = (actionName, command, requestorAppName, webhookEndpoint, params) => __awaiter(void 0, void 0, void 0, function* () {
52
+ try {
53
+ const bigidToken = yield getBigidAccessToken();
54
+ const { data: { executionId }, } = yield (0, bigidProxyService_1.doCallToUrl)(bigidToken, bigidProxyService_1.RequestMethod.POST, `${process.env.BIGID_BASE_URL}/api/v1/action-center/general-commands/execute`, Object.assign({ actionName,
55
+ command, feedbackRequestorDetails: requestorAppName && webhookEndpoint
56
+ ? {
57
+ requestorAppName,
58
+ requestorFeedbackEndpoint: webhookEndpoint,
59
+ }
60
+ : null }, (params && { params })));
61
+ return executionId;
62
+ }
63
+ catch (e) {
64
+ throw new Error(`Could not execute ${command}: ${e}`);
65
+ }
66
+ });
67
+ exports.executeCommand = executeCommand;
68
+ /**
69
+ * use this method to poll an execution status from the action-center.
70
+ *
71
+ * @param {string} execution - the execution id to poll status for.
72
+ * @return object with the updated status details.
73
+ */
74
+ const getExecutionStatus = (executionId) => __awaiter(void 0, void 0, void 0, function* () {
75
+ try {
76
+ const bigidToken = yield getBigidAccessToken();
77
+ const { data } = yield (0, bigidProxyService_1.doCallToUrl)(bigidToken, bigidProxyService_1.RequestMethod.GET, `${process.env.BIGID_BASE_URL}/api/v1/action-center/general-commands/execute/${executionId}`);
78
+ return data;
79
+ }
80
+ catch (e) {
81
+ throw new Error(`Could not get status for execution id ${executionId}: ${e}`);
82
+ }
83
+ });
84
+ exports.getExecutionStatus = getExecutionStatus;
85
+ /**
86
+ * use this method to register application action as an action center command.
87
+ *
88
+ * @param {string} applicationName - the application name of the command to be registered.
89
+ * @param {string} actionName - the action name of the command to be registered.
90
+ * @param {string} command - the command to be registered.
91
+ */
92
+ const registerActionAsCommand = (applicationName, actionName, command) => __awaiter(void 0, void 0, void 0, function* () {
93
+ try {
94
+ const bigidToken = yield getBigidAccessToken();
95
+ yield (0, bigidProxyService_1.doCallToUrl)(bigidToken, bigidProxyService_1.RequestMethod.POST, `${process.env.BIGID_BASE_URL}/api/v1/action-center/general-commands/register`, {
96
+ applicationName,
97
+ actionName,
98
+ command,
99
+ });
100
+ }
101
+ catch (e) {
102
+ throw new Error(`Could not register ${command}: ${e}`);
103
+ }
104
+ });
105
+ exports.registerActionAsCommand = registerActionAsCommand;
@@ -0,0 +1,2 @@
1
+ export type BatchFunction = (tenantId: string, tenantDomain: string, tenantToken: string) => void;
2
+ export declare const handleBatchProcess: (callback: BatchFunction) => Promise<void>;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.handleBatchProcess = void 0;
13
+ const tokenUtil_1 = require("../utils/tokenUtil");
14
+ const bigidProxyService_1 = require("./bigidProxyService");
15
+ const utils_1 = require("../utils");
16
+ const path_1 = require("path");
17
+ const scriptName = (0, path_1.basename)(__filename).replace('.ts', '');
18
+ const handleBatchProcess = (callback) => __awaiter(void 0, void 0, void 0, function* () {
19
+ try {
20
+ (0, utils_1.logInfo)(`Starting scheduled process: ${callback.name}`);
21
+ const auth0Token = yield (0, tokenUtil_1.getAuth0Token)();
22
+ const bigidToken = yield (0, tokenUtil_1.tokenExchange)(auth0Token);
23
+ const appRegistrations = yield (0, bigidProxyService_1.getTenantRegistrations)(bigidToken);
24
+ appRegistrations.forEach(tenantRegistration => executeBatchForTenant(auth0Token, tenantRegistration, callback));
25
+ }
26
+ catch (err) {
27
+ (0, utils_1.logError)(`Problem occurred while fetching registrations info: ${err.message}`);
28
+ }
29
+ });
30
+ exports.handleBatchProcess = handleBatchProcess;
31
+ const executeBatchForTenant = (auth0Token, tenantRegistration, callback) => __awaiter(void 0, void 0, void 0, function* () {
32
+ const { tenantId, tenantDomain, companyName } = tenantRegistration;
33
+ try {
34
+ (0, utils_1.logInfo)(`Fetching token for scheduled process`, { tenantId, functionName: executeBatchForTenant.name, scriptName });
35
+ const tenantToken = yield (0, tokenUtil_1.tokenExchange)(auth0Token, tenantId);
36
+ callback(tenantId, tenantDomain, tenantToken);
37
+ }
38
+ catch (err) {
39
+ (0, utils_1.logError)(`Problem occurred while starting scheduled process for tenant: ${companyName}. error: ${err.message}`, {
40
+ tenantId,
41
+ functionName: executeBatchForTenant.name,
42
+ scriptName,
43
+ });
44
+ }
45
+ });
@@ -1,4 +1,14 @@
1
- import { ExecutionContext, ActionResponseDetails } from '../dto';
1
+ import { ActionResponseDetails, ExecutionContext } from '../dto';
2
+ import { TenantRegistration } from '../dto/tenantRegistration';
3
+ export declare enum RequestMethod {
4
+ POST = "post",
5
+ GET = "get",
6
+ PUT = "put",
7
+ PATCH = "patch",
8
+ DELETE = "delete"
9
+ }
10
+ export declare const getTenantRegistrations: (bigidToken: string) => Promise<TenantRegistration[]>;
11
+ export declare const doCallToUrl: (bigidToken: string, requestMethod: RequestMethod, endpoint: string, bodyJson?: Record<string, any>) => Promise<any>;
2
12
  /**
3
13
  * This method receives a message object to update BigID regarding the current state of the action execution
4
14
  * (should be used in case of an async actions)
@@ -16,12 +26,18 @@ export declare const executeHttpGet: (executionContext: ExecutionContext, endpoi
16
26
  /**
17
27
  * the endpoint in BigID, used for POST requests. e.g - {BigIDBaseUrl}/scan
18
28
  */
19
- export declare const executeHttpPost: (executionContext: ExecutionContext, endpoint: string, actionResponseDetails: ActionResponseDetails) => Promise<any>;
29
+ export declare const executeHttpPost: (executionContext: ExecutionContext, endpoint: string, obj: any) => Promise<any>;
20
30
  /**
21
31
  * the endpoint in BigID, used for POST requests. e.g - {BigIDBaseUrl}/scan
22
32
  */
23
33
  export declare const executeHttpPut: (executionContext: ExecutionContext, endpoint: string, obj: any) => Promise<any>;
34
+ /**
35
+ * the endpoint in BigID, used for DELETE requests.
36
+ */
37
+ export declare const executeHttpDelete: (executionContext: ExecutionContext, endpoint: string) => Promise<any>;
24
38
  export declare const uploadAttachment: (executionContext: ExecutionContext, filePathToUpload: string) => import("axios").AxiosPromise<any>;
25
39
  export declare const getAppStorage: (executionContext: ExecutionContext) => Promise<any>;
26
40
  export declare const getValueFromAppStorage: (executionContext: ExecutionContext, key: string) => Promise<string>;
41
+ export declare const deleteKeyFromAppStorage: (executionContext: ExecutionContext, key: string) => Promise<void>;
42
+ export declare const sendBiEvent: (executionContext: ExecutionContext, eventType: string, data: Object) => Promise<any>;
27
43
  export declare const saveInStorage: (executionContext: ExecutionContext, keyToStore: any, valueToStore: any) => Promise<void>;