@bigid/apps-infrastructure-node-js 0.1.0 → 1.180.0

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 (88) hide show
  1. package/.github/workflows/bigid_config +3 -0
  2. package/.github/workflows/npmjs_config +3 -0
  3. package/.github/workflows/private-registry-publish.yml +16 -0
  4. package/.github/workflows/public-registry-publish.yml +14 -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/{routes/router.js → abstractProviders/configureProvider.js} +7 -3
  10. package/lib/abstractProviders/executionProvider.d.ts +3 -2
  11. package/lib/abstractProviders/executionProvider.js +5 -10
  12. package/lib/abstractProviders/index.d.ts +1 -0
  13. package/lib/abstractProviders/index.js +3 -1
  14. package/lib/abstractProviders/logsProvider.js +9 -1
  15. package/lib/abstractProviders/manifestProvider.d.ts +2 -1
  16. package/lib/dto/actionResponseDetails.d.ts +3 -1
  17. package/lib/dto/actionResponseDetails.js +2 -1
  18. package/lib/dto/executionContext.d.ts +8 -5
  19. package/lib/dto/executionContext.js +0 -14
  20. package/lib/dto/index.d.ts +1 -1
  21. package/lib/dto/index.js +1 -3
  22. package/lib/dto/subExecutionItem.d.ts +7 -0
  23. package/lib/dto/subExecutionItem.js +12 -0
  24. package/lib/dto/tenantRegistration.d.ts +5 -0
  25. package/lib/index.d.ts +1 -1
  26. package/lib/index.js +16 -2
  27. package/lib/server.d.ts +11 -7
  28. package/lib/server.js +16 -12
  29. package/lib/services/actionsHubService.d.ts +45 -0
  30. package/lib/services/actionsHubService.js +105 -0
  31. package/lib/services/batchProcessManager.d.ts +2 -0
  32. package/lib/services/batchProcessManager.js +45 -0
  33. package/lib/services/bigidProxyService.d.ts +28 -13
  34. package/lib/services/bigidProxyService.js +67 -55
  35. package/lib/services/dataSourceService.d.ts +4 -0
  36. package/lib/services/dataSourceService.js +26 -0
  37. package/lib/services/encryptionService.d.ts +1 -0
  38. package/lib/services/encryptionService.js +67 -0
  39. package/lib/services/index.d.ts +3 -0
  40. package/lib/services/index.js +12 -1
  41. package/lib/services/schedulerService.d.ts +11 -0
  42. package/lib/services/schedulerService.js +41 -0
  43. package/lib/utils/appLogger.d.ts +10 -1
  44. package/lib/utils/appLogger.js +38 -7
  45. package/lib/utils/index.d.ts +1 -1
  46. package/lib/utils/index.js +15 -3
  47. package/lib/utils/tokenUtil.d.ts +3 -0
  48. package/lib/utils/tokenUtil.js +62 -0
  49. package/package.json +11 -4
  50. package/src/abstractProviders/configureProvider.ts +15 -0
  51. package/src/abstractProviders/executionProvider.ts +5 -7
  52. package/src/abstractProviders/index.ts +1 -0
  53. package/src/abstractProviders/logsProvider.ts +11 -3
  54. package/src/abstractProviders/manifestProvider.ts +3 -1
  55. package/src/dto/actionResponseDetails.ts +5 -1
  56. package/src/dto/executionContext.ts +8 -23
  57. package/src/dto/index.ts +2 -2
  58. package/src/dto/subExecutionItem.ts +13 -0
  59. package/src/dto/tenantRegistration.ts +5 -0
  60. package/src/index.ts +17 -1
  61. package/src/server.ts +33 -20
  62. package/src/services/actionsHubService.ts +141 -0
  63. package/src/services/batchProcessManager.ts +39 -0
  64. package/src/services/bigidProxyService.ts +84 -62
  65. package/src/services/dataSourceService.ts +20 -0
  66. package/src/services/encryptionService.ts +44 -0
  67. package/src/services/index.ts +5 -1
  68. package/src/services/schedulerService.ts +39 -0
  69. package/src/utils/appLogger.ts +44 -6
  70. package/src/utils/index.ts +1 -1
  71. package/src/utils/tokenUtil.ts +65 -0
  72. package/.dcignore +0 -1547
  73. package/.idea/apps-infrastructure-node-js.iml +0 -9
  74. package/.idea/misc.xml +0 -6
  75. package/.idea/modules.xml +0 -8
  76. package/.idea/prettier.xml +0 -7
  77. package/.idea/runConfigurations.xml +0 -10
  78. package/.idea/snyk.project.settings.xml +0 -6
  79. package/.idea/vcs.xml +0 -6
  80. package/lib/appTypes/actionResponseDetails.d.ts +0 -6
  81. package/lib/appTypes/executionContext.d.ts +0 -10
  82. package/lib/appTypes/executionContext.js +0 -2
  83. package/lib/appTypes/index.d.ts +0 -2
  84. package/lib/appTypes/index.js +0 -2
  85. package/lib/dto/keysValuesToStore.d.ts +0 -5
  86. package/lib/dto/keysValuesToStore.js +0 -19
  87. package/lib/routes/router.d.ts +0 -1
  88. /package/lib/{appTypes/actionResponseDetails.js → dto/tenantRegistration.js} +0 -0
@@ -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
@@ -0,0 +1,16 @@
1
+ name: Upload to private registry
2
+ on:
3
+ workflow_dispatch:
4
+ push:
5
+ branches:
6
+ - main
7
+ jobs:
8
+ Upload:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v2.1.1
12
+ - run: npm i
13
+ - run: tsc
14
+ - run: npm publish --userconfig .github/workflows/bigid_config
15
+ env:
16
+ TOKEN: ${{ secrets.TOKEN }}
@@ -0,0 +1,14 @@
1
+ name: Upload to public registry - npmjs
2
+ on:
3
+ workflow_dispatch:
4
+
5
+ jobs:
6
+ Upload:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2.1.1
10
+ - run: npm i
11
+ - run: tsc
12
+ - run: npm publish --userconfig .github/workflows/npmjs_config
13
+ env:
14
+ 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
+ }
@@ -9,7 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.router = void 0;
13
- const router = () => __awaiter(void 0, void 0, void 0, function* () {
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);
14
15
  });
15
- exports.router = router;
16
+ exports.handleTenantConfigure = handleTenantConfigure;
17
+ class ConfigureProvider {
18
+ }
19
+ exports.ConfigureProvider = ConfigureProvider;
@@ -1,4 +1,5 @@
1
1
  import { Request, Response } from 'express';
2
+ import { ExecutionContext } from '../dto';
2
3
  export declare const StatusEnum: {
3
4
  COMPLETED: string;
4
5
  IN_PROGRESS: string;
@@ -6,8 +7,8 @@ export declare const StatusEnum: {
6
7
  };
7
8
  export declare const handleExecution: (req: Request, res: Response, executionProvider: ExecutionProvider) => Promise<void>;
8
9
  export declare abstract class ExecutionProvider {
9
- abstract executeAction(req: Request, res: Response): Promise<void>;
10
+ abstract executeAction(executionContext: ExecutionContext, res: Response): Promise<void>;
10
11
  generateSyncSuccessMessage: (res: Response, executionId: string, message: string) => Response<any, Record<string, any>>;
11
12
  generateAsyncSuccessMessage: (res: Response, executionId: string, message: string) => Response<any, Record<string, any>>;
12
- generateFailedResponse: (res: Response, executionId: string, e: Error) => Response<any, Record<string, any>>;
13
+ generateFailedResponse: (res: Response, executionId: string, errorMessage: string) => Response<any, Record<string, any>>;
13
14
  }
@@ -10,26 +10,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ExecutionProvider = exports.handleExecution = exports.StatusEnum = void 0;
13
- const actionResponseDetails_1 = require("../dto/actionResponseDetails");
14
- const services_1 = require("../services");
13
+ const dto_1 = require("../dto");
15
14
  exports.StatusEnum = {
16
15
  COMPLETED: 'COMPLETED',
17
16
  IN_PROGRESS: 'IN_PROGRESS',
18
17
  ERROR: 'ERROR',
19
18
  };
20
19
  const handleExecution = (req, res, executionProvider) => __awaiter(void 0, void 0, void 0, function* () {
21
- (0, services_1.setValuesForBigIDProxy)(req.body);
22
- yield executionProvider.executeAction(req, res);
20
+ yield executionProvider.executeAction(req.body, res);
23
21
  });
24
22
  exports.handleExecution = handleExecution;
25
23
  class ExecutionProvider {
26
24
  constructor() {
27
- this.generateSyncSuccessMessage = (res, executionId, message) => res.status(200)
28
- .json(new actionResponseDetails_1.ActionResponseDetails(executionId, exports.StatusEnum.COMPLETED, 1, message));
29
- this.generateAsyncSuccessMessage = (res, executionId, message) => res.status(202)
30
- .json(new actionResponseDetails_1.ActionResponseDetails(executionId, exports.StatusEnum.IN_PROGRESS, 0, message));
31
- this.generateFailedResponse = (res, executionId, e) => res.status(400)
32
- .json(new actionResponseDetails_1.ActionResponseDetails(executionId, exports.StatusEnum.ERROR, 0, e.message));
25
+ this.generateSyncSuccessMessage = (res, executionId, message) => res.status(200).json(new dto_1.ActionResponseDetails(executionId, exports.StatusEnum.COMPLETED, 1, message));
26
+ this.generateAsyncSuccessMessage = (res, executionId, message) => res.status(202).json(new dto_1.ActionResponseDetails(executionId, exports.StatusEnum.IN_PROGRESS, 0, message));
27
+ this.generateFailedResponse = (res, executionId, errorMessage) => res.status(400).json(new dto_1.ActionResponseDetails(executionId, exports.StatusEnum.ERROR, 0, errorMessage));
33
28
  }
34
29
  }
35
30
  exports.ExecutionProvider = ExecutionProvider;
@@ -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,11 +1,14 @@
1
- export declare class 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
- constructor(actionName: string, executionId: string, globalParams: Record<string, string>, actionParams: Record<string, string>, bigidBaseUrl: string, bigidToken: string, updateResultCallback: any, tpaId: string);
11
- }
10
+ };
11
+ export type GeneralParam = {
12
+ paramName: string;
13
+ paramValue: string;
14
+ };
@@ -1,16 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExecutionContext = void 0;
4
- class ExecutionContext {
5
- constructor(actionName, executionId, globalParams, actionParams, bigidBaseUrl, bigidToken, updateResultCallback, tpaId) {
6
- this.actionName = actionName;
7
- this.executionId = executionId;
8
- this.globalParams = globalParams;
9
- this.actionParams = actionParams;
10
- this.bigidBaseUrl = bigidBaseUrl;
11
- this.bigidToken = bigidToken;
12
- this.updateResultCallback = updateResultCallback;
13
- this.tpaId = tpaId;
14
- }
15
- }
16
- exports.ExecutionContext = ExecutionContext;
@@ -1,2 +1,2 @@
1
- export { ExecutionContext } from './executionContext';
1
+ export { ExecutionContext, GeneralParam } from './executionContext';
2
2
  export { ActionResponseDetails } from './actionResponseDetails';
package/lib/dto/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ActionResponseDetails = exports.ExecutionContext = void 0;
4
- var executionContext_1 = require("./executionContext");
5
- Object.defineProperty(exports, "ExecutionContext", { enumerable: true, get: function () { return executionContext_1.ExecutionContext; } });
3
+ exports.ActionResponseDetails = void 0;
6
4
  var actionResponseDetails_1 = require("./actionResponseDetails");
7
5
  Object.defineProperty(exports, "ActionResponseDetails", { enumerable: true, get: function () { return actionResponseDetails_1.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
+ };
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";
3
- import { ExecutionProvider } from "./abstractProviders/executionProvider";
4
- export interface ServerInit {
1
+ import { Express } from 'express';
2
+ import { ManifestProvider } from './abstractProviders';
3
+ import { IconsProviders } from './abstractProviders';
4
+ import { ExecutionProvider } from './abstractProviders/executionProvider';
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,34 +14,38 @@ 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
- ;
21
+ const configureProvider_1 = require("./abstractProviders/configureProvider");
22
22
  const app = (0, express_1.default)();
23
- const deployServer = (serverInit) => {
23
+ const deployServer = ({ manifestController, iconsController, executionController, serverPort, configureController, additionalEndpoints, }) => {
24
24
  app.use(express_1.default.json());
25
25
  app.use(express_1.default.urlencoded({ extended: false }));
26
- app.get('/assets/icon', (req, res) => res.sendFile(serverInit.iconsController.getIconPath()));
27
- app.get('/assets/sideBarIcon', (req, res) => res.sendFile(serverInit.iconsController.getSideBarIconPath()));
28
- app.get('/manifest', serverInit.manifestController.getManifest);
29
- app.post('/execute', (req, res) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, executionProvider_1.handleExecution)(req, res, serverInit.executionController); }));
30
- app.get('/logs', logsProvider_1.fetchLogs);
31
- app.listen(serverInit.serverPort || process.env.PORT, () => appLogger_1.appLogger.info(`Started server at port ${serverInit.serverPort || process.env.PORT}`));
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}`));
32
36
  // catch 404 and forward to error handler
33
37
  app.use((req, res, next) => next((0, http_errors_1.default)(404)));
34
38
  // error handler
35
39
  app.use((err, req, res, next) => {
36
40
  const { message, status } = err;
37
- appLogger_1.appLogger.error(err);
41
+ (0, utils_1.logError)(err);
38
42
  res.locals.message = message;
39
43
  res.locals.error = req.app.get('env') === 'development' ? err : {};
40
44
  res.status(status || 500);
41
45
  res.json({
42
- status: "error",
46
+ status: 'error',
43
47
  statusCode: status || 500,
44
- message
48
+ message,
45
49
  });
46
50
  });
47
51
  };
@@ -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>;