@bigid/apps-infrastructure-node-js 1.218.0 → 1.218.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.
@@ -14,7 +14,7 @@ export type CacheEntry = {
14
14
  expiry: number;
15
15
  };
16
16
  export type AppsConfigurationsManagement = {
17
- appName: string;
17
+ appName?: string;
18
18
  shouldInitAppConfigurationsPollingFromBigID?: boolean;
19
- manifest: Record<string, any>;
19
+ manifest?: Record<string, any>;
20
20
  };
@@ -21,17 +21,20 @@ const appConfigurationsCache = new Map();
21
21
  let appConfigurationsManagementParams;
22
22
  const initAppConfigurationsManagement = (appsConfigurationsManagement) => __awaiter(void 0, void 0, void 0, function* () {
23
23
  setAppConfigurationsManagementParams(appsConfigurationsManagement);
24
- const { shouldInitAppConfigurationsPollingFromBigID: shouldInitAppConfigurationsPollingFromBigID, appName } = appsConfigurationsManagement;
25
- if (process.env.BIGID_BASE_URL && appName) {
24
+ const { shouldInitAppConfigurationsPollingFromBigID: shouldInitAppConfigurationsPollingFromBigID, appName, manifest } = appsConfigurationsManagement;
25
+ if (process.env.BIGID_BASE_URL && manifest) {
26
26
  yield initApplicationConfigurationInConfigServer();
27
- if (shouldInitAppConfigurationsPollingFromBigID) {
28
- (0, schedulerService_1.scheduleFunction)('AppConfigurationsInCachePerTenant', '* * * * *', updateAppConfigurationsInCache);
29
- }
27
+ }
28
+ if (shouldInitAppConfigurationsPollingFromBigID && appName) {
29
+ (0, schedulerService_1.scheduleFunction)('AppConfigurationsInCachePerTenant', '* * * * *', updateAppConfigurationsInCache);
30
30
  }
31
31
  });
32
32
  exports.initAppConfigurationsManagement = initAppConfigurationsManagement;
33
33
  const setAppConfigurationsManagementParams = (AppConfigurationsManagement) => {
34
+ var _a, _b;
34
35
  appConfigurationsManagementParams = AppConfigurationsManagement;
36
+ const appNameFromManifest = (_a = AppConfigurationsManagement === null || AppConfigurationsManagement === void 0 ? void 0 : AppConfigurationsManagement.manifest) === null || _a === void 0 ? void 0 : _a.app_name;
37
+ appConfigurationsManagementParams.appName = (_b = AppConfigurationsManagement.appName) !== null && _b !== void 0 ? _b : appNameFromManifest;
35
38
  };
36
39
  const initApplicationConfigurationInConfigServer = () => __awaiter(void 0, void 0, void 0, function* () {
37
40
  try {
@@ -46,13 +49,13 @@ const initApplicationConfigurationInConfigServer = () => __awaiter(void 0, void
46
49
  }
47
50
  }
48
51
  catch (e) {
49
- throw new Error(`Could not get/update app configurations from BigID: ${e}`);
52
+ (0, utils_1.logError)(`Could not get/update app configurations from BigID: ${e}`);
50
53
  }
51
54
  });
52
55
  const setApplicationConfigurationInConfigServer = (tenantId, url, token) => __awaiter(void 0, void 0, void 0, function* () {
53
56
  const baseUrl = url || process.env.BIGID_BASE_URL;
54
57
  if (!baseUrl || !(appConfigurationsManagementParams === null || appConfigurationsManagementParams === void 0 ? void 0 : appConfigurationsManagementParams.manifest)) {
55
- throw new Error(`url and manifest must be provided`);
58
+ throw new Error(`URL and manifest must be provided`);
56
59
  }
57
60
  try {
58
61
  const initAppConfigurationsEndPoint = createUrl(baseUrl, generateTpaConfigurationEndpoint(appConfigurationsManagementParams.appName));
@@ -69,7 +72,7 @@ const updateAppConfigurationsInCache = (tenantId, url, token) => __awaiter(void
69
72
  const decodedToken = (0, tokenUtil_2.decodeToken)(token);
70
73
  const primaryKey = (decodedToken === null || decodedToken === void 0 ? void 0 : decodedToken.tenantId) || tenantId || token;
71
74
  try {
72
- const allAppConfigurations = yield fetchAppConfigurations(token, url);
75
+ const allAppConfigurations = yield fetchAppConfigurations(token, url, appConfigurationsManagementParams.appName);
73
76
  updateAppConfigurationInCache(primaryKey, allAppConfigurations);
74
77
  }
75
78
  catch (e) {
@@ -77,14 +80,15 @@ const updateAppConfigurationsInCache = (tenantId, url, token) => __awaiter(void
77
80
  }
78
81
  });
79
82
  const getAppConfiguration = (appConfigurationsParams) => __awaiter(void 0, void 0, void 0, function* () {
80
- var _a;
83
+ var _a, _b;
81
84
  const { key, executionContext, accessToken, bigidUrl } = appConfigurationsParams;
82
- if (!(appConfigurationsManagementParams === null || appConfigurationsManagementParams === void 0 ? void 0 : appConfigurationsManagementParams.appName)) {
83
- throw new Error('The appName parameter must be provided to the deployServer function to enable calling the getAppConfiguration function.');
85
+ const resolvedAppName = (_a = executionContext === null || executionContext === void 0 ? void 0 : executionContext.tpaName) !== null && _a !== void 0 ? _a : appConfigurationsManagementParams === null || appConfigurationsManagementParams === void 0 ? void 0 : appConfigurationsManagementParams.appName;
86
+ if (!resolvedAppName) {
87
+ throw new Error('App name must be provided, either from execution context, or from appName parameter on the deployServer function.');
84
88
  }
85
89
  const token = (executionContext === null || executionContext === void 0 ? void 0 : executionContext.bigidToken) || accessToken || (yield (0, tokenUtil_1.getBigidAccessToken)());
86
90
  const decodedToken = (0, tokenUtil_2.decodeToken)(token);
87
- const url = (_a = ((executionContext === null || executionContext === void 0 ? void 0 : executionContext.bigidBaseUrl) || bigidUrl || process.env.BIGID_BASE_URL)) === null || _a === void 0 ? void 0 : _a.replace('/api/v1', '');
91
+ const url = (_b = ((executionContext === null || executionContext === void 0 ? void 0 : executionContext.bigidBaseUrl) || bigidUrl || process.env.BIGID_BASE_URL)) === null || _b === void 0 ? void 0 : _b.replace('/api/v1', '');
88
92
  if (!url || !token) {
89
93
  throw new Error(`url and token must be provided`);
90
94
  }
@@ -106,7 +110,11 @@ const getAppConfiguration = (appConfigurationsParams) => __awaiter(void 0, void
106
110
  });
107
111
  exports.getAppConfiguration = getAppConfiguration;
108
112
  const fetchAppConfigurations = (token, url, appNameFromExecutionContext) => __awaiter(void 0, void 0, void 0, function* () {
109
- const appConfigurationsEndPoint = createUrl(url, generateTpaConfigurationEndpoint(appNameFromExecutionContext !== null && appNameFromExecutionContext !== void 0 ? appNameFromExecutionContext : appConfigurationsManagementParams.appName));
113
+ const resolvedAppName = appNameFromExecutionContext !== null && appNameFromExecutionContext !== void 0 ? appNameFromExecutionContext : appConfigurationsManagementParams.appName;
114
+ if (!resolvedAppName) {
115
+ throw new Error('Can not fetch app configuration, have no app name from execution context nor injected name');
116
+ }
117
+ const appConfigurationsEndPoint = createUrl(url, generateTpaConfigurationEndpoint(resolvedAppName));
110
118
  const { data = {} } = yield (0, bigidProxyService_1.doCallToUrl)(token, bigidProxyService_1.RequestMethod.GET, appConfigurationsEndPoint);
111
119
  return data;
112
120
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigid/apps-infrastructure-node-js",
3
- "version": "1.218.0",
3
+ "version": "1.218.1",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -18,7 +18,7 @@ export type CacheEntry = {
18
18
  };
19
19
 
20
20
  export type AppsConfigurationsManagement = {
21
- appName: string;
21
+ appName?: string;
22
22
  shouldInitAppConfigurationsPollingFromBigID?: boolean;
23
- manifest: Record<string, any>;
23
+ manifest?: Record<string, any>;
24
24
  };
@@ -4,7 +4,7 @@ import { CacheEntry, AppsConfigurationsManagement, AppConfigurationsParams } fro
4
4
  import { decodeToken } from '../utils/tokenUtil';
5
5
  import { isMultiTenantMode, scheduleFunction } from './schedulerService';
6
6
  import { handleBatchProcess } from './batchProcessManager';
7
- import { logInfo } from '../utils';
7
+ import { logError, logInfo } from '../utils';
8
8
 
9
9
  const APP_CONFIGURATIONS_CACHE_TTL = 10 * 1000;
10
10
 
@@ -15,18 +15,20 @@ export const initAppConfigurationsManagement = async (
15
15
  appsConfigurationsManagement: AppsConfigurationsManagement,
16
16
  ): Promise<void> => {
17
17
  setAppConfigurationsManagementParams(appsConfigurationsManagement);
18
- const { shouldInitAppConfigurationsPollingFromBigID: shouldInitAppConfigurationsPollingFromBigID, appName } =
18
+ const { shouldInitAppConfigurationsPollingFromBigID: shouldInitAppConfigurationsPollingFromBigID, appName, manifest } =
19
19
  appsConfigurationsManagement;
20
- if (process.env.BIGID_BASE_URL && appName) {
20
+ if (process.env.BIGID_BASE_URL && manifest) {
21
21
  await initApplicationConfigurationInConfigServer();
22
- if (shouldInitAppConfigurationsPollingFromBigID) {
23
- scheduleFunction('AppConfigurationsInCachePerTenant', '* * * * *', updateAppConfigurationsInCache);
24
- }
22
+ }
23
+ if (shouldInitAppConfigurationsPollingFromBigID && appName) {
24
+ scheduleFunction('AppConfigurationsInCachePerTenant', '* * * * *', updateAppConfigurationsInCache);
25
25
  }
26
26
  };
27
27
 
28
28
  const setAppConfigurationsManagementParams = (AppConfigurationsManagement: AppsConfigurationsManagement): void => {
29
29
  appConfigurationsManagementParams = AppConfigurationsManagement;
30
+ const appNameFromManifest = AppConfigurationsManagement?.manifest?.app_name;
31
+ appConfigurationsManagementParams.appName = AppConfigurationsManagement.appName ?? appNameFromManifest;
30
32
  };
31
33
 
32
34
  const initApplicationConfigurationInConfigServer = async (): Promise<void> => {
@@ -40,7 +42,7 @@ const initApplicationConfigurationInConfigServer = async (): Promise<void> => {
40
42
  await setApplicationConfigurationInConfigServer(tenantId, '', token);
41
43
  }
42
44
  } catch (e) {
43
- throw new Error(`Could not get/update app configurations from BigID: ${e}`);
45
+ logError(`Could not get/update app configurations from BigID: ${e}`);
44
46
  }
45
47
  };
46
48
 
@@ -51,12 +53,12 @@ const setApplicationConfigurationInConfigServer = async (
51
53
  ): Promise<void> => {
52
54
  const baseUrl = url || process.env.BIGID_BASE_URL;
53
55
  if (!baseUrl || !appConfigurationsManagementParams?.manifest) {
54
- throw new Error(`url and manifest must be provided`);
56
+ throw new Error(`URL and manifest must be provided`);
55
57
  }
56
58
  try {
57
59
  const initAppConfigurationsEndPoint = createUrl(
58
60
  baseUrl,
59
- generateTpaConfigurationEndpoint(appConfigurationsManagementParams.appName),
61
+ generateTpaConfigurationEndpoint(appConfigurationsManagementParams.appName!),
60
62
  );
61
63
  const manifestString = JSON.stringify(appConfigurationsManagementParams.manifest);
62
64
  const enrichedManifestString = enrichManifestWithEnvConfigurations(manifestString);
@@ -71,7 +73,7 @@ const updateAppConfigurationsInCache = async (tenantId: string, url: string, tok
71
73
  const decodedToken = decodeToken(token);
72
74
  const primaryKey = decodedToken?.tenantId || tenantId || token;
73
75
  try {
74
- const allAppConfigurations = await fetchAppConfigurations(token, url);
76
+ const allAppConfigurations = await fetchAppConfigurations(token, url, appConfigurationsManagementParams.appName);
75
77
  updateAppConfigurationInCache(primaryKey, allAppConfigurations);
76
78
  } catch (e) {
77
79
  throw new Error(`Could not get/update app configurations from BigID: ${e}`);
@@ -80,9 +82,10 @@ const updateAppConfigurationsInCache = async (tenantId: string, url: string, tok
80
82
 
81
83
  export const getAppConfiguration = async (appConfigurationsParams: AppConfigurationsParams): Promise<string | null> => {
82
84
  const { key, executionContext, accessToken, bigidUrl } = appConfigurationsParams;
83
- if (!appConfigurationsManagementParams?.appName) {
85
+ const resolvedAppName = executionContext?.tpaName ?? appConfigurationsManagementParams?.appName;
86
+ if (!resolvedAppName) {
84
87
  throw new Error(
85
- 'The appName parameter must be provided to the deployServer function to enable calling the getAppConfiguration function.',
88
+ 'App name must be provided, either from execution context, or from appName parameter on the deployServer function.',
86
89
  );
87
90
  }
88
91
  const token = executionContext?.bigidToken || accessToken || (await getBigidAccessToken());
@@ -112,9 +115,13 @@ const fetchAppConfigurations = async (
112
115
  url: string,
113
116
  appNameFromExecutionContext?: string,
114
117
  ): Promise<Record<string, any>> => {
118
+ const resolvedAppName = appNameFromExecutionContext ?? appConfigurationsManagementParams.appName;
119
+ if (!resolvedAppName){
120
+ throw new Error('Can not fetch app configuration, have no app name from execution context nor injected name')
121
+ }
115
122
  const appConfigurationsEndPoint = createUrl(
116
123
  url,
117
- generateTpaConfigurationEndpoint(appNameFromExecutionContext ?? appConfigurationsManagementParams.appName),
124
+ generateTpaConfigurationEndpoint(resolvedAppName),
118
125
  );
119
126
  const { data = {} } = await doCallToUrl(token!, RequestMethod.GET, appConfigurationsEndPoint);
120
127
  return data;