@azure/api-management-custom-widgets-tools 1.0.0-beta.1 → 1.0.0-beta.3
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.
- package/LICENSE +17 -17
- package/README.md +3 -3
- package/dist/browser/index.d.ts +10 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/{dist-esm/src → dist/browser}/index.js +4 -4
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/node/CustomWidgetBlobService.d.ts +27 -0
- package/dist/browser/node/CustomWidgetBlobService.d.ts.map +1 -0
- package/{dist-esm/src → dist/browser}/node/CustomWidgetBlobService.js +10 -17
- package/dist/browser/node/CustomWidgetBlobService.js.map +1 -0
- package/dist/browser/node/deploy-browser.d.mts.map +1 -0
- package/dist/browser/node/deploy-browser.mjs.map +1 -0
- package/dist/browser/node/deploy.d.ts +3 -0
- package/dist/browser/node/deploy.js +7 -0
- package/dist/browser/node/getStorageSasUrl.d.ts +10 -0
- package/dist/browser/node/getStorageSasUrl.d.ts.map +1 -0
- package/{dist-esm/src → dist/browser}/node/getStorageSasUrl.js +8 -8
- package/dist/browser/node/getStorageSasUrl.js.map +1 -0
- package/dist/browser/node/readdir-browser.d.mts.map +1 -0
- package/dist/browser/node/readdir-browser.mjs.map +1 -0
- package/dist/browser/node/readdir.d.ts +3 -0
- package/dist/browser/node/readdir.js +7 -0
- package/dist/browser/node/types.d.ts +24 -0
- package/dist/browser/node/types.d.ts.map +1 -0
- package/dist/browser/node/types.js +4 -0
- package/dist/browser/node/types.js.map +1 -0
- package/dist/browser/package.json +3 -0
- package/dist/browser/paths.d.ts +21 -0
- package/dist/browser/paths.d.ts.map +1 -0
- package/{dist-esm/src → dist/browser}/paths.js +1 -1
- package/{dist-esm/src → dist/browser}/paths.js.map +1 -1
- package/{types/latest/api-management-custom-widgets-tools.d.ts → dist/browser/utils.d.ts} +98 -154
- package/dist/browser/utils.d.ts.map +1 -0
- package/{dist-esm/src → dist/browser}/utils.js +4 -5
- package/dist/browser/utils.js.map +1 -0
- package/dist/commonjs/index.d.ts +10 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +29 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/node/CustomWidgetBlobService.d.ts +27 -0
- package/dist/commonjs/node/CustomWidgetBlobService.d.ts.map +1 -0
- package/dist/commonjs/node/CustomWidgetBlobService.js +68 -0
- package/dist/commonjs/node/CustomWidgetBlobService.js.map +1 -0
- package/dist/commonjs/node/deploy.d.ts +12 -0
- package/dist/commonjs/node/deploy.d.ts.map +1 -0
- package/dist/commonjs/node/deploy.js +59 -0
- package/dist/commonjs/node/deploy.js.map +1 -0
- package/dist/commonjs/node/getStorageSasUrl.d.ts +10 -0
- package/dist/commonjs/node/getStorageSasUrl.d.ts.map +1 -0
- package/dist/commonjs/node/getStorageSasUrl.js +35 -0
- package/dist/commonjs/node/getStorageSasUrl.js.map +1 -0
- package/dist/commonjs/node/readdir.d.ts +3 -0
- package/dist/commonjs/node/readdir.d.ts.map +1 -0
- package/dist/commonjs/node/readdir.js +22 -0
- package/dist/commonjs/node/readdir.js.map +1 -0
- package/dist/commonjs/node/types.d.ts +24 -0
- package/dist/commonjs/node/types.d.ts.map +1 -0
- package/dist/commonjs/node/types.js +5 -0
- package/dist/commonjs/node/types.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/paths.d.ts +21 -0
- package/dist/commonjs/paths.d.ts.map +1 -0
- package/dist/commonjs/paths.js +32 -0
- package/dist/commonjs/paths.js.map +1 -0
- package/dist/commonjs/tsdoc-metadata.json +11 -0
- package/dist/commonjs/utils.d.ts +98 -0
- package/dist/commonjs/utils.d.ts.map +1 -0
- package/dist/commonjs/utils.js +134 -0
- package/dist/commonjs/utils.js.map +1 -0
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/node/CustomWidgetBlobService.d.ts +27 -0
- package/dist/esm/node/CustomWidgetBlobService.d.ts.map +1 -0
- package/dist/esm/node/CustomWidgetBlobService.js +64 -0
- package/dist/esm/node/CustomWidgetBlobService.js.map +1 -0
- package/dist/esm/node/deploy.d.ts +12 -0
- package/dist/esm/node/deploy.d.ts.map +1 -0
- package/{dist-esm/src → dist/esm}/node/deploy.js +9 -9
- package/dist/esm/node/deploy.js.map +1 -0
- package/dist/esm/node/getStorageSasUrl.d.ts +10 -0
- package/dist/esm/node/getStorageSasUrl.d.ts.map +1 -0
- package/dist/esm/node/getStorageSasUrl.js +33 -0
- package/dist/esm/node/getStorageSasUrl.js.map +1 -0
- package/dist/esm/node/readdir.d.ts +3 -0
- package/dist/esm/node/readdir.d.ts.map +1 -0
- package/{dist-esm/src → dist/esm}/node/readdir.js +3 -3
- package/dist/esm/node/readdir.js.map +1 -0
- package/dist/esm/node/types.d.ts +24 -0
- package/dist/esm/node/types.d.ts.map +1 -0
- package/dist/esm/node/types.js +4 -0
- package/dist/esm/node/types.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/paths.d.ts +21 -0
- package/dist/esm/paths.d.ts.map +1 -0
- package/dist/esm/paths.js +27 -0
- package/dist/esm/paths.js.map +1 -0
- package/dist/esm/utils.d.ts +98 -0
- package/dist/esm/utils.d.ts.map +1 -0
- package/dist/esm/utils.js +122 -0
- package/dist/esm/utils.js.map +1 -0
- package/package.json +70 -85
- package/dist/index.js +0 -344
- package/dist/index.js.map +0 -1
- package/dist-esm/src/index.js.map +0 -1
- package/dist-esm/src/node/CustomWidgetBlobService.js.map +0 -1
- package/dist-esm/src/node/deploy.browser.js +0 -7
- package/dist-esm/src/node/deploy.browser.js.map +0 -1
- package/dist-esm/src/node/deploy.js.map +0 -1
- package/dist-esm/src/node/getStorageSasUrl.js.map +0 -1
- package/dist-esm/src/node/readdir.js.map +0 -1
- package/dist-esm/src/utils.js.map +0 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
const identity_1 = require("@azure/identity");
|
|
6
|
+
const core_client_1 = require("@azure-rest/core-client");
|
|
7
|
+
async function getAccessToken(managementApiEndpoint, options = {}) {
|
|
8
|
+
const credentials = new identity_1.InteractiveBrowserCredential(options);
|
|
9
|
+
const scope = `${managementApiEndpoint}/user_impersonation`;
|
|
10
|
+
const { token } = await credentials.getToken(scope);
|
|
11
|
+
return `Bearer ${token}`;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Function to get storage SAS URL.
|
|
15
|
+
*
|
|
16
|
+
* @returns storage SAS URL
|
|
17
|
+
*/
|
|
18
|
+
async function getStorageSasUrl({ managementApiEndpoint, resourceId, apiVersion = "2019-01-01", tokenOverride, }, interactiveBrowserCredentialOptions) {
|
|
19
|
+
const httpClient = (0, core_client_1.getClient)(`${managementApiEndpoint}/${resourceId}`, { apiVersion });
|
|
20
|
+
const response = await httpClient
|
|
21
|
+
.pathUnchecked(`/portalSettings/mediaContent/listSecrets?apiVersion=${apiVersion}`) // TODO
|
|
22
|
+
.post({
|
|
23
|
+
headers: {
|
|
24
|
+
"If-Match": "*",
|
|
25
|
+
"Content-Type": "application/json",
|
|
26
|
+
Authorization: tokenOverride ??
|
|
27
|
+
(await getAccessToken(managementApiEndpoint, interactiveBrowserCredentialOptions)),
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
if (!response?.body?.containerSasUrl)
|
|
31
|
+
throw new Error("Could not get storage SAS URL");
|
|
32
|
+
return response.body.containerSasUrl;
|
|
33
|
+
}
|
|
34
|
+
exports.default = getStorageSasUrl;
|
|
35
|
+
//# sourceMappingURL=getStorageSasUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getStorageSasUrl.js","sourceRoot":"","sources":["../../../src/node/getStorageSasUrl.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAElC,8CAGyB;AAEzB,yDAAoD;AAEpD,KAAK,UAAU,cAAc,CAC3B,qBAA6B,EAC7B,UAAuB,EAAE;IAEzB,MAAM,WAAW,GAAG,IAAI,uCAA4B,CAAC,OAAO,CAAC,CAAC;IAC9D,MAAM,KAAK,GAAG,GAAG,qBAAqB,qBAAqB,CAAC;IAC5D,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACpD,OAAO,UAAU,KAAK,EAAE,CAAC;AAC3B,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,gBAAgB,CAC7B,EACE,qBAAqB,EACrB,UAAU,EACV,UAAU,GAAG,YAAY,EACzB,aAAa,GACM,EACrB,mCAAiD;IAEjD,MAAM,UAAU,GAAG,IAAA,uBAAS,EAAC,GAAG,qBAAqB,IAAI,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IACvF,MAAM,QAAQ,GAAG,MAAM,UAAU;SAC9B,aAAa,CAAC,uDAAuD,UAAU,EAAE,CAAC,CAAC,OAAO;SAC1F,IAAI,CAAC;QACJ,OAAO,EAAE;YACP,UAAU,EAAE,GAAG;YACf,cAAc,EAAE,kBAAkB;YAClC,aAAa,EACX,aAAa;gBACb,CAAC,MAAM,cAAc,CAAC,qBAAqB,EAAE,mCAAmC,CAAC,CAAC;SACrF;KACF,CAAC,CAAC;IAEL,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,eAAe;QAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACvF,OAAO,QAAQ,CAAC,IAAI,CAAC,eAAe,CAAC;AACvC,CAAC;AAED,kBAAe,gBAAgB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n InteractiveBrowserCredential,\n type InteractiveBrowserCredentialNodeOptions as IBCNOptions,\n} from \"@azure/identity\";\nimport type { ServiceInformation } from \"./types.js\";\nimport { getClient } from \"@azure-rest/core-client\";\n\nasync function getAccessToken(\n managementApiEndpoint: string,\n options: IBCNOptions = {},\n): Promise<string> {\n const credentials = new InteractiveBrowserCredential(options);\n const scope = `${managementApiEndpoint}/user_impersonation`;\n const { token } = await credentials.getToken(scope);\n return `Bearer ${token}`;\n}\n\n/**\n * Function to get storage SAS URL.\n *\n * @returns storage SAS URL\n */\nasync function getStorageSasUrl(\n {\n managementApiEndpoint,\n resourceId,\n apiVersion = \"2019-01-01\",\n tokenOverride,\n }: ServiceInformation,\n interactiveBrowserCredentialOptions?: IBCNOptions,\n): Promise<string> {\n const httpClient = getClient(`${managementApiEndpoint}/${resourceId}`, { apiVersion });\n const response = await httpClient\n .pathUnchecked(`/portalSettings/mediaContent/listSecrets?apiVersion=${apiVersion}`) // TODO\n .post({\n headers: {\n \"If-Match\": \"*\",\n \"Content-Type\": \"application/json\",\n Authorization:\n tokenOverride ??\n (await getAccessToken(managementApiEndpoint, interactiveBrowserCredentialOptions)),\n },\n });\n\n if (!response?.body?.containerSasUrl) throw new Error(\"Could not get storage SAS URL\");\n return response.body.containerSasUrl;\n}\n\nexport default getStorageSasUrl;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readdir.d.ts","sourceRoot":"","sources":["../../../src/node/readdir.ts"],"names":[],"mappings":"AAMA,iBAAS,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAapD;AAED,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
7
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
8
|
+
function readdir(dir, root) {
|
|
9
|
+
const results = [];
|
|
10
|
+
node_fs_1.default.readdirSync(root + dir).forEach((file) => {
|
|
11
|
+
const stat = node_fs_1.default.statSync(root + dir + node_path_1.default.sep + file);
|
|
12
|
+
if (stat && stat.isDirectory()) {
|
|
13
|
+
results.push(...readdir(dir + file + node_path_1.default.sep, root));
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
results.push(dir + file);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return results;
|
|
20
|
+
}
|
|
21
|
+
exports.default = readdir;
|
|
22
|
+
//# sourceMappingURL=readdir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readdir.js","sourceRoot":"","sources":["../../../src/node/readdir.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,8DAAyB;AACzB,kEAA6B;AAE7B,SAAS,OAAO,CAAC,GAAW,EAAE,IAAY;IACxC,MAAM,OAAO,GAAa,EAAE,CAAC;IAE7B,iBAAE,CAAC,WAAW,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC1C,MAAM,IAAI,GAAG,iBAAE,CAAC,QAAQ,CAAC,IAAI,GAAG,GAAG,GAAG,mBAAI,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC;QACvD,IAAI,IAAI,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;YAC/B,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,GAAG,IAAI,GAAG,mBAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;QACxD,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,kBAAe,OAAO,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport fs from \"node:fs\";\nimport path from \"node:path\";\n\nfunction readdir(dir: string, root: string): string[] {\n const results: string[] = [];\n\n fs.readdirSync(root + dir).forEach((file) => {\n const stat = fs.statSync(root + dir + path.sep + file);\n if (stat && stat.isDirectory()) {\n results.push(...readdir(dir + file + path.sep, root));\n } else {\n results.push(dir + file);\n }\n });\n\n return results;\n}\n\nexport default readdir;\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { InteractiveBrowserCredentialNodeOptions } from "@azure/identity";
|
|
2
|
+
/**
|
|
3
|
+
* resourceId - resource ID of API Management service "subscriptions/[subscription-id]/resourceGroups/[resource-group-name]/providers/Microsoft.ApiManagement/service/[service-name]"
|
|
4
|
+
* managementApiEndpoint - URL with protocol (e.g. https://management.azure.com)
|
|
5
|
+
* apiVersion - optional to override default (e.g. "2019-01-01")
|
|
6
|
+
* tokenOverride - optional, provides token to use for auth, instead of 'az login' approach
|
|
7
|
+
*/
|
|
8
|
+
export type ServiceInformation = {
|
|
9
|
+
resourceId: string;
|
|
10
|
+
managementApiEndpoint: string;
|
|
11
|
+
apiVersion?: string;
|
|
12
|
+
tokenOverride?: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Optional options object for configuring the deployment function.
|
|
16
|
+
*
|
|
17
|
+
* @param rootLocal - optional, root of the local folder with compiled project to be exported (by default "./dist")
|
|
18
|
+
* @param interactiveBrowserCredentialOptions - options for InteractiveBrowserCredential for Node or InBrowser from \@azure/identity
|
|
19
|
+
*/
|
|
20
|
+
export type DeployConfig = {
|
|
21
|
+
rootLocal?: string;
|
|
22
|
+
interactiveBrowserCredentialOptions?: InteractiveBrowserCredentialNodeOptions;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/node/types.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,uCAAuC,EAAE,MAAM,iBAAiB,CAAC;AAE/E;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mCAAmC,CAAC,EAAE,uCAAuC,CAAC;CAC/E,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/node/types.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { InteractiveBrowserCredentialNodeOptions } from \"@azure/identity\";\n\n/**\n * resourceId - resource ID of API Management service \"subscriptions/[subscription-id]/resourceGroups/[resource-group-name]/providers/Microsoft.ApiManagement/service/[service-name]\"\n * managementApiEndpoint - URL with protocol (e.g. https://management.azure.com)\n * apiVersion - optional to override default (e.g. \"2019-01-01\")\n * tokenOverride - optional, provides token to use for auth, instead of 'az login' approach\n */\nexport type ServiceInformation = {\n resourceId: string;\n managementApiEndpoint: string;\n apiVersion?: string;\n tokenOverride?: string;\n};\n\n/**\n * Optional options object for configuring the deployment function.\n *\n * @param rootLocal - optional, root of the local folder with compiled project to be exported (by default \"./dist\")\n * @param interactiveBrowserCredentialOptions - options for InteractiveBrowserCredential for Node or InBrowser from \\@azure/identity\n */\nexport type DeployConfig = {\n rootLocal?: string;\n interactiveBrowserCredentialOptions?: InteractiveBrowserCredentialNodeOptions;\n};\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** root of the blob storage folder */
|
|
2
|
+
export declare const BLOB_ROOT = "custom-widgets";
|
|
3
|
+
/** name of the blob storage folder with widget implementation */
|
|
4
|
+
export declare const BLOB_DATA_FOLDER = "data";
|
|
5
|
+
/** name of the blob storage folder with widget configs */
|
|
6
|
+
export declare const BLOB_CONFIGS_FOLDER = "configs";
|
|
7
|
+
/** name of the configuration file */
|
|
8
|
+
export declare const APIM_CONFIG_FILE_NAME = "config.msapim.json";
|
|
9
|
+
/**
|
|
10
|
+
* Generate relative path for widgets' data on the blob storage
|
|
11
|
+
*
|
|
12
|
+
* @param name - name of the widget
|
|
13
|
+
*/
|
|
14
|
+
export declare function buildBlobDataPath(name: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Generate relative path for widgets' config on the blob storage
|
|
17
|
+
*
|
|
18
|
+
* @param name - name of the widget
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildBlobConfigPath(name: string): string;
|
|
21
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/paths.ts"],"names":[],"mappings":"AAGA,sCAAsC;AACtC,eAAO,MAAM,SAAS,mBAAmB,CAAC;AAC1C,iEAAiE;AACjE,eAAO,MAAM,gBAAgB,SAAS,CAAC;AACvC,0DAA0D;AAC1D,eAAO,MAAM,mBAAmB,YAAY,CAAC;AAC7C,qCAAqC;AACrC,eAAO,MAAM,qBAAqB,uBAAuB,CAAC;AAE1D;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.APIM_CONFIG_FILE_NAME = exports.BLOB_CONFIGS_FOLDER = exports.BLOB_DATA_FOLDER = exports.BLOB_ROOT = void 0;
|
|
6
|
+
exports.buildBlobDataPath = buildBlobDataPath;
|
|
7
|
+
exports.buildBlobConfigPath = buildBlobConfigPath;
|
|
8
|
+
/** root of the blob storage folder */
|
|
9
|
+
exports.BLOB_ROOT = "custom-widgets";
|
|
10
|
+
/** name of the blob storage folder with widget implementation */
|
|
11
|
+
exports.BLOB_DATA_FOLDER = "data";
|
|
12
|
+
/** name of the blob storage folder with widget configs */
|
|
13
|
+
exports.BLOB_CONFIGS_FOLDER = "configs";
|
|
14
|
+
/** name of the configuration file */
|
|
15
|
+
exports.APIM_CONFIG_FILE_NAME = "config.msapim.json";
|
|
16
|
+
/**
|
|
17
|
+
* Generate relative path for widgets' data on the blob storage
|
|
18
|
+
*
|
|
19
|
+
* @param name - name of the widget
|
|
20
|
+
*/
|
|
21
|
+
function buildBlobDataPath(name) {
|
|
22
|
+
return `${exports.BLOB_ROOT}/${exports.BLOB_DATA_FOLDER}/${name}/`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Generate relative path for widgets' config on the blob storage
|
|
26
|
+
*
|
|
27
|
+
* @param name - name of the widget
|
|
28
|
+
*/
|
|
29
|
+
function buildBlobConfigPath(name) {
|
|
30
|
+
return `${exports.BLOB_ROOT}/${exports.BLOB_CONFIGS_FOLDER}/${name}/${exports.APIM_CONFIG_FILE_NAME}`;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/paths.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAgBlC,8CAEC;AAOD,kDAEC;AAzBD,sCAAsC;AACzB,QAAA,SAAS,GAAG,gBAAgB,CAAC;AAC1C,iEAAiE;AACpD,QAAA,gBAAgB,GAAG,MAAM,CAAC;AACvC,0DAA0D;AAC7C,QAAA,mBAAmB,GAAG,SAAS,CAAC;AAC7C,qCAAqC;AACxB,QAAA,qBAAqB,GAAG,oBAAoB,CAAC;AAE1D;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,IAAY;IAC5C,OAAO,GAAG,iBAAS,IAAI,wBAAgB,IAAI,IAAI,GAAG,CAAC;AACrD,CAAC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,IAAY;IAC9C,OAAO,GAAG,iBAAS,IAAI,2BAAmB,IAAI,IAAI,IAAI,6BAAqB,EAAE,CAAC;AAChF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/** root of the blob storage folder */\nexport const BLOB_ROOT = \"custom-widgets\";\n/** name of the blob storage folder with widget implementation */\nexport const BLOB_DATA_FOLDER = \"data\";\n/** name of the blob storage folder with widget configs */\nexport const BLOB_CONFIGS_FOLDER = \"configs\";\n/** name of the configuration file */\nexport const APIM_CONFIG_FILE_NAME = \"config.msapim.json\";\n\n/**\n * Generate relative path for widgets' data on the blob storage\n *\n * @param name - name of the widget\n */\nexport function buildBlobDataPath(name: string): string {\n return `${BLOB_ROOT}/${BLOB_DATA_FOLDER}/${name}/`;\n}\n\n/**\n * Generate relative path for widgets' config on the blob storage\n *\n * @param name - name of the widget\n */\nexport function buildBlobConfigPath(name: string): string {\n return `${BLOB_ROOT}/${BLOB_CONFIGS_FOLDER}/${name}/${APIM_CONFIG_FILE_NAME}`;\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.52.10"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Key for a search param, from which editor data will be loaded from.
|
|
3
|
+
*/
|
|
4
|
+
export declare const APIM_EDITOR_DATA_KEY = "editorData";
|
|
5
|
+
/**
|
|
6
|
+
* Key for a post message object, it's used to propagate changes from editor to the DevPortal. Used to prevent interference with other applications.
|
|
7
|
+
*/
|
|
8
|
+
export declare const APIM_ON_CHANGE_MESSAGE_KEY = "customInputValueChangedMSAPIM";
|
|
9
|
+
/**
|
|
10
|
+
* Key for a post message object, it's used to request and send secrets - token and user id, from the DevPortal. Used to prevent interference with other applications.
|
|
11
|
+
*/
|
|
12
|
+
export declare const APIM_ASK_FOR_SECRETS_MESSAGE_KEY = "askForSecretsMSAPIM";
|
|
13
|
+
/**
|
|
14
|
+
* Base of a values obj
|
|
15
|
+
*/
|
|
16
|
+
export type ValuesCommon = Record<string, unknown>;
|
|
17
|
+
/**
|
|
18
|
+
* All possible runtime environments
|
|
19
|
+
*/
|
|
20
|
+
export type Environment = "development" | "publishing" | "runtime" | "error";
|
|
21
|
+
/** Information about the widget instance received from the Dev Portal */
|
|
22
|
+
export interface PortalData {
|
|
23
|
+
/** current runtime environment */
|
|
24
|
+
environment: Environment;
|
|
25
|
+
/** ID of this particular instance of the widget */
|
|
26
|
+
instanceId: string;
|
|
27
|
+
}
|
|
28
|
+
/** JSON object with all the data you'll receive from the Dev Portal */
|
|
29
|
+
export interface EditorData<Values extends ValuesCommon> extends PortalData {
|
|
30
|
+
/** values you've set in the admin editor window */
|
|
31
|
+
values: Partial<Values>;
|
|
32
|
+
}
|
|
33
|
+
export declare function getWidgetDataPure<Values extends ValuesCommon>(urlSearchParams: URLSearchParams): EditorData<Values>;
|
|
34
|
+
/**
|
|
35
|
+
* Function to get all data related to the widget including technical values not expected to be needed in most cases.
|
|
36
|
+
* Intended mostly for internal use, API might change. Consider using getValues or getEditorValues instead.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getWidgetData<Values extends ValuesCommon>(): EditorData<Values>;
|
|
39
|
+
export declare function getEditorValuesPure<Values extends ValuesCommon>(urlSearchParams: URLSearchParams): Partial<Values>;
|
|
40
|
+
/**
|
|
41
|
+
* Function to get values you've set in the admin editor window.
|
|
42
|
+
*/
|
|
43
|
+
export declare function getEditorValues<Values extends ValuesCommon>(): Partial<Values>;
|
|
44
|
+
export declare function getValuesPure<Values extends ValuesCommon>(valuesDefault: Values, urlSearchParams: URLSearchParams): Values;
|
|
45
|
+
/**
|
|
46
|
+
* Function to get values you've set in the admin editor window. Undefined/empty values are replaced with default values.
|
|
47
|
+
*
|
|
48
|
+
* @param valuesDefault - object with your default values to use, just import valuesDefault object from values.ts folder
|
|
49
|
+
*/
|
|
50
|
+
export declare function getValues<Values extends ValuesCommon>(valuesDefault: Values): Values;
|
|
51
|
+
/**
|
|
52
|
+
* Type of the onChange function.
|
|
53
|
+
*/
|
|
54
|
+
export type OnChange<Values extends ValuesCommon> = (values: Partial<Values>) => void;
|
|
55
|
+
/**
|
|
56
|
+
* The onChange function itself with 'origin' provided as a param.
|
|
57
|
+
*
|
|
58
|
+
* @param origin - web content's origin (URL) of your Dev Portal to send changes to
|
|
59
|
+
* @param instanceId - ID of this particular instance of the widget
|
|
60
|
+
* @param values - values that changed
|
|
61
|
+
*/
|
|
62
|
+
export declare function onChangeWithOrigin<Values extends ValuesCommon>(origin: string, instanceId: string, values: Values): void;
|
|
63
|
+
/**
|
|
64
|
+
* Build onChange function, which you can use, to send changed data from the editor.
|
|
65
|
+
*/
|
|
66
|
+
export declare function buildOnChange<Values extends ValuesCommon>(): OnChange<Values>;
|
|
67
|
+
/**
|
|
68
|
+
* Possible target modules
|
|
69
|
+
* "app" for main application which is embedded in your Dev Portal
|
|
70
|
+
* "editor" for form in admin panel
|
|
71
|
+
*/
|
|
72
|
+
export type TargetModule = "app" | "editor";
|
|
73
|
+
/**
|
|
74
|
+
* Secrets needed for communication with Dev Portal back-end and other runtime data
|
|
75
|
+
*/
|
|
76
|
+
export type Secrets = {
|
|
77
|
+
managementApiUrl: string;
|
|
78
|
+
apiVersion: string;
|
|
79
|
+
userId?: string;
|
|
80
|
+
token?: string;
|
|
81
|
+
parentLocation: {
|
|
82
|
+
host: string;
|
|
83
|
+
hostname: string;
|
|
84
|
+
href: string;
|
|
85
|
+
origin: string;
|
|
86
|
+
pathname: string;
|
|
87
|
+
port: string;
|
|
88
|
+
protocol: string;
|
|
89
|
+
search: string;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Request secrets - token & userId, from the Dev portal parent window.
|
|
94
|
+
*
|
|
95
|
+
* @param targetModule - is the function invoke from the main "app" window or the admin "editor"?
|
|
96
|
+
*/
|
|
97
|
+
export declare function askForSecrets(targetModule: TargetModule): Promise<Secrets>;
|
|
98
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,oBAAoB,eAAe,CAAC;AACjD;;GAEG;AACH,eAAO,MAAM,0BAA0B,kCAAkC,CAAC;AAC1E;;GAEG;AACH,eAAO,MAAM,gCAAgC,wBAAwB,CAAC;AAEtE;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACnD;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,aAAa,GAAG,YAAY,GAAG,SAAS,GAAG,OAAO,CAAC;AAE7E,yEAAyE;AACzE,MAAM,WAAW,UAAU;IAGzB,kCAAkC;IAClC,WAAW,EAAE,WAAW,CAAC;IACzB,mDAAmD;IACnD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,uEAAuE;AACvE,MAAM,WAAW,UAAU,CAAC,MAAM,SAAS,YAAY,CAAE,SAAQ,UAAU;IACzE,mDAAmD;IACnD,MAAM,EAAE,OAAO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C;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,EAAE;QACd,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAmChF"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.APIM_ASK_FOR_SECRETS_MESSAGE_KEY = exports.APIM_ON_CHANGE_MESSAGE_KEY = exports.APIM_EDITOR_DATA_KEY = void 0;
|
|
6
|
+
exports.getWidgetDataPure = getWidgetDataPure;
|
|
7
|
+
exports.getWidgetData = getWidgetData;
|
|
8
|
+
exports.getEditorValuesPure = getEditorValuesPure;
|
|
9
|
+
exports.getEditorValues = getEditorValues;
|
|
10
|
+
exports.getValuesPure = getValuesPure;
|
|
11
|
+
exports.getValues = getValues;
|
|
12
|
+
exports.onChangeWithOrigin = onChangeWithOrigin;
|
|
13
|
+
exports.buildOnChange = buildOnChange;
|
|
14
|
+
exports.askForSecrets = askForSecrets;
|
|
15
|
+
/**
|
|
16
|
+
* Key for a search param, from which editor data will be loaded from.
|
|
17
|
+
*/
|
|
18
|
+
exports.APIM_EDITOR_DATA_KEY = "editorData";
|
|
19
|
+
/**
|
|
20
|
+
* Key for a post message object, it's used to propagate changes from editor to the DevPortal. Used to prevent interference with other applications.
|
|
21
|
+
*/
|
|
22
|
+
exports.APIM_ON_CHANGE_MESSAGE_KEY = "customInputValueChangedMSAPIM";
|
|
23
|
+
/**
|
|
24
|
+
* Key for a post message object, it's used to request and send secrets - token and user id, from the DevPortal. Used to prevent interference with other applications.
|
|
25
|
+
*/
|
|
26
|
+
exports.APIM_ASK_FOR_SECRETS_MESSAGE_KEY = "askForSecretsMSAPIM";
|
|
27
|
+
function parseWidgetData(urlSearchParams) {
|
|
28
|
+
try {
|
|
29
|
+
const urlEditorParams = JSON.parse(decodeURIComponent(urlSearchParams.get(exports.APIM_EDITOR_DATA_KEY) ?? ""));
|
|
30
|
+
// if (!("origin" in urlEditorParams)) {
|
|
31
|
+
// console.error(
|
|
32
|
+
// "Could not get 'origin' from the search params of the URL:\n" + self.location.href
|
|
33
|
+
// );
|
|
34
|
+
// }
|
|
35
|
+
return urlEditorParams;
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
console.error(`Could not get '${exports.APIM_EDITOR_DATA_KEY}' from the search params of the URL:\n` +
|
|
39
|
+
self.location, e);
|
|
40
|
+
return { values: {}, environment: "error", instanceId: "error" };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function getWidgetDataPure(urlSearchParams) {
|
|
44
|
+
return parseWidgetData(urlSearchParams);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Function to get all data related to the widget including technical values not expected to be needed in most cases.
|
|
48
|
+
* Intended mostly for internal use, API might change. Consider using getValues or getEditorValues instead.
|
|
49
|
+
*/
|
|
50
|
+
function getWidgetData() {
|
|
51
|
+
return getWidgetDataPure(new URLSearchParams(self.location.search));
|
|
52
|
+
}
|
|
53
|
+
function getEditorValuesPure(urlSearchParams) {
|
|
54
|
+
return getWidgetDataPure(urlSearchParams).values;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Function to get values you've set in the admin editor window.
|
|
58
|
+
*/
|
|
59
|
+
function getEditorValues() {
|
|
60
|
+
return getEditorValuesPure(new URLSearchParams(self.location.search));
|
|
61
|
+
}
|
|
62
|
+
function getValuesPure(valuesDefault, urlSearchParams) {
|
|
63
|
+
const values = { ...valuesDefault }; // set Obj to contain all possible values and prefill default value
|
|
64
|
+
const urlValues = parseWidgetData(urlSearchParams).values;
|
|
65
|
+
Object.keys(values).forEach((key) => {
|
|
66
|
+
const value = urlValues[key];
|
|
67
|
+
if (value != null)
|
|
68
|
+
values[key] = value; // if value is specified in the URL, replace the default value
|
|
69
|
+
});
|
|
70
|
+
return values;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Function to get values you've set in the admin editor window. Undefined/empty values are replaced with default values.
|
|
74
|
+
*
|
|
75
|
+
* @param valuesDefault - object with your default values to use, just import valuesDefault object from values.ts folder
|
|
76
|
+
*/
|
|
77
|
+
function getValues(valuesDefault) {
|
|
78
|
+
return getValuesPure(valuesDefault, new URLSearchParams(self.location.search));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The onChange function itself with 'origin' provided as a param.
|
|
82
|
+
*
|
|
83
|
+
* @param origin - web content's origin (URL) of your Dev Portal to send changes to
|
|
84
|
+
* @param instanceId - ID of this particular instance of the widget
|
|
85
|
+
* @param values - values that changed
|
|
86
|
+
*/
|
|
87
|
+
function onChangeWithOrigin(origin, instanceId, values) {
|
|
88
|
+
Object.entries(values).forEach(([key, value]) => {
|
|
89
|
+
self.parent.postMessage({ [exports.APIM_ON_CHANGE_MESSAGE_KEY]: { key, value, instanceId } }, origin);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Build onChange function, which you can use, to send changed data from the editor.
|
|
94
|
+
*/
|
|
95
|
+
function buildOnChange() {
|
|
96
|
+
const { instanceId } = getWidgetData();
|
|
97
|
+
return (values) => onChangeWithOrigin("*", instanceId, values);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Request secrets - token & userId, from the Dev portal parent window.
|
|
101
|
+
*
|
|
102
|
+
* @param targetModule - is the function invoke from the main "app" window or the admin "editor"?
|
|
103
|
+
*/
|
|
104
|
+
async function askForSecrets(targetModule) {
|
|
105
|
+
let receiveSecrets;
|
|
106
|
+
const promise = new Promise((resolve, reject) => {
|
|
107
|
+
const { instanceId, environment } = getWidgetData();
|
|
108
|
+
receiveSecrets = ({ data }) => {
|
|
109
|
+
if (!(exports.APIM_ASK_FOR_SECRETS_MESSAGE_KEY in data))
|
|
110
|
+
return;
|
|
111
|
+
const secrets = data[exports.APIM_ASK_FOR_SECRETS_MESSAGE_KEY];
|
|
112
|
+
if (typeof secrets !== "object" || !("managementApiUrl" in secrets)) {
|
|
113
|
+
reject("Secrets send by Dev Portal are invalid");
|
|
114
|
+
}
|
|
115
|
+
resolve(secrets);
|
|
116
|
+
};
|
|
117
|
+
self.addEventListener("message", receiveSecrets);
|
|
118
|
+
const message = {
|
|
119
|
+
[exports.APIM_ASK_FOR_SECRETS_MESSAGE_KEY]: {
|
|
120
|
+
instanceId,
|
|
121
|
+
origin: self.location.origin,
|
|
122
|
+
targetModule,
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
if (targetModule === "app" && environment === "development") {
|
|
126
|
+
self.parent.parent.postMessage(message, "*");
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
self.parent.postMessage(message, "*");
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
return promise.finally(() => self.removeEventListener("message", receiveSecrets));
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAgElC,8CAIC;AAMD,sCAEC;AAED,kDAIC;AAKD,0CAEC;AAED,sCAYC;AAOD,8BAEC;AAcD,gDAQC;AAKD,sCAGC;AAiCD,sCAmCC;AAhND;;GAEG;AACU,QAAA,oBAAoB,GAAG,YAAY,CAAC;AACjD;;GAEG;AACU,QAAA,0BAA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UAAU,EAAE,WAAW,EAAE,GAAe,aAAa,EAAE,CAAC;QAEhE,cAAc,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;YAC5B,IAAI,CAAC,CAAC,wCAAgC,IAAI,IAAI,CAAC;gBAAE,OAAO;YAExD,MAAM,OAAO,GAAG,IAAI,CAAC,wCAAgC,CAAC,CAAC;YACvD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,CAAC,kBAAkB,IAAI,OAAO,CAAC,EAAE,CAAC;gBACpE,MAAM,CAAC,wCAAwC,CAAC,CAAC;YACnD,CAAC;YAED,OAAO,CAAC,OAAO,CAAC,CAAC;QACnB,CAAC,CAAC;QAEF,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;QAEjD,MAAM,OAAO,GAAG;YACd,CAAC,wCAAgC,CAAC,EAAE;gBAClC,UAAU;gBACV,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM;gBAC5B,YAAY;aACb;SACF,CAAC;QAEF,IAAI,YAAY,KAAK,KAAK,IAAI,WAAW,KAAK,aAAa,EAAE,CAAC;YAC5D,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC/C,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QACxC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC;AACpF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Key for a search param, from which editor data will be loaded from.\n */\nexport const APIM_EDITOR_DATA_KEY = \"editorData\";\n/**\n * Key for a post message object, it's used to propagate changes from editor to the DevPortal. Used to prevent interference with other applications.\n */\nexport const APIM_ON_CHANGE_MESSAGE_KEY = \"customInputValueChangedMSAPIM\";\n/**\n * Key for a post message object, it's used to request and send secrets - token and user id, from the DevPortal. Used to prevent interference with other applications.\n */\nexport const APIM_ASK_FOR_SECRETS_MESSAGE_KEY = \"askForSecretsMSAPIM\";\n\n/**\n * Base of a values obj\n */\nexport type ValuesCommon = Record<string, unknown>;\n/**\n * All possible runtime environments\n */\nexport type Environment = \"development\" | \"publishing\" | \"runtime\" | \"error\";\n\n/** Information about the widget instance received from the Dev Portal */\nexport interface PortalData {\n // /** web content's origin (URL) of your Dev Portal */\n // origin: string;\n /** current runtime environment */\n environment: Environment;\n /** ID of this particular instance of the widget */\n instanceId: string;\n}\n\n/** JSON object with all the data you'll receive from the Dev Portal */\nexport interface EditorData<Values extends ValuesCommon> extends PortalData {\n /** values you've set in the admin editor window */\n values: Partial<Values>;\n}\n\nfunction parseWidgetData<Values extends ValuesCommon>(\n urlSearchParams: URLSearchParams,\n): EditorData<Values> {\n try {\n const urlEditorParams: EditorData<Values> = JSON.parse(\n decodeURIComponent(urlSearchParams.get(APIM_EDITOR_DATA_KEY) ?? \"\"),\n );\n\n // if (!(\"origin\" in urlEditorParams)) {\n // console.error(\n // \"Could not get 'origin' from the search params of the URL:\\n\" + self.location.href\n // );\n // }\n return urlEditorParams;\n } catch (e) {\n console.error(\n `Could not get '${APIM_EDITOR_DATA_KEY}' from the search params of the URL:\\n` +\n self.location,\n e,\n );\n return { values: {}, environment: \"error\", instanceId: \"error\" };\n }\n}\n\nexport function getWidgetDataPure<Values extends ValuesCommon>(\n urlSearchParams: URLSearchParams,\n): EditorData<Values> {\n return parseWidgetData<Values>(urlSearchParams);\n}\n\n/**\n * Function to get all data related to the widget including technical values not expected to be needed in most cases.\n * Intended mostly for internal use, API might change. Consider using getValues or getEditorValues instead.\n */\nexport function getWidgetData<Values extends ValuesCommon>(): EditorData<Values> {\n return getWidgetDataPure(new URLSearchParams(self.location.search));\n}\n\nexport function getEditorValuesPure<Values extends ValuesCommon>(\n urlSearchParams: URLSearchParams,\n): Partial<Values> {\n return getWidgetDataPure<Values>(urlSearchParams).values;\n}\n\n/**\n * Function to get values you've set in the admin editor window.\n */\nexport function getEditorValues<Values extends ValuesCommon>(): Partial<Values> {\n return getEditorValuesPure<Values>(new URLSearchParams(self.location.search));\n}\n\nexport function getValuesPure<Values extends ValuesCommon>(\n valuesDefault: Values,\n urlSearchParams: URLSearchParams,\n): Values {\n const values = { ...valuesDefault }; // set Obj to contain all possible values and prefill default value\n const urlValues = parseWidgetData<Values>(urlSearchParams).values;\n\n Object.keys(values).forEach((key: keyof Values) => {\n const value = urlValues[key];\n if (value != null) values[key] = value as Values[typeof key]; // if value is specified in the URL, replace the default value\n });\n return values;\n}\n\n/**\n * Function to get values you've set in the admin editor window. Undefined/empty values are replaced with default values.\n *\n * @param valuesDefault - object with your default values to use, just import valuesDefault object from values.ts folder\n */\nexport function getValues<Values extends ValuesCommon>(valuesDefault: Values): Values {\n return getValuesPure(valuesDefault, new URLSearchParams(self.location.search));\n}\n\n/**\n * Type of the onChange function.\n */\nexport type OnChange<Values extends ValuesCommon> = (values: Partial<Values>) => void;\n\n/**\n * The onChange function itself with 'origin' provided as a param.\n *\n * @param origin - web content's origin (URL) of your Dev Portal to send changes to\n * @param instanceId - ID of this particular instance of the widget\n * @param values - values that changed\n */\nexport function onChangeWithOrigin<Values extends ValuesCommon>(\n origin: string,\n instanceId: string,\n values: Values,\n): void {\n Object.entries(values).forEach(([key, value]) => {\n self.parent.postMessage({ [APIM_ON_CHANGE_MESSAGE_KEY]: { key, value, instanceId } }, origin);\n });\n}\n\n/**\n * Build onChange function, which you can use, to send changed data from the editor.\n */\nexport function buildOnChange<Values extends ValuesCommon>(): OnChange<Values> {\n const { instanceId } = getWidgetData();\n return (values: Partial<Values>) => onChangeWithOrigin(\"*\", instanceId, values);\n}\n\n/**\n * Possible target modules\n * \"app\" for main application which is embedded in your Dev Portal\n * \"editor\" for form in admin panel\n */\nexport type TargetModule = \"app\" | \"editor\";\n/**\n * Secrets needed for communication with Dev Portal back-end and other runtime data\n */\nexport type Secrets = {\n managementApiUrl: string;\n apiVersion: string;\n userId?: string;\n token?: string;\n parentLocation: {\n host: string;\n hostname: string;\n href: string;\n origin: string;\n pathname: string;\n port: string;\n protocol: string;\n search: string;\n };\n};\n\n/**\n * Request secrets - token & userId, from the Dev portal parent window.\n *\n * @param targetModule - is the function invoke from the main \"app\" window or the admin \"editor\"?\n */\nexport async function askForSecrets(targetModule: TargetModule): Promise<Secrets> {\n let receiveSecrets: (e: MessageEvent) => void;\n\n const promise = new Promise<Secrets>((resolve, reject) => {\n const { instanceId, environment }: PortalData = getWidgetData();\n\n receiveSecrets = ({ data }) => {\n if (!(APIM_ASK_FOR_SECRETS_MESSAGE_KEY in data)) return;\n\n const secrets = data[APIM_ASK_FOR_SECRETS_MESSAGE_KEY];\n if (typeof secrets !== \"object\" || !(\"managementApiUrl\" in secrets)) {\n reject(\"Secrets send by Dev Portal are invalid\");\n }\n\n resolve(secrets);\n };\n\n self.addEventListener(\"message\", receiveSecrets);\n\n const message = {\n [APIM_ASK_FOR_SECRETS_MESSAGE_KEY]: {\n instanceId,\n origin: self.location.origin,\n targetModule,\n },\n };\n\n if (targetModule === \"app\" && environment === \"development\") {\n self.parent.parent.postMessage(message, \"*\");\n } else {\n self.parent.postMessage(message, \"*\");\n }\n });\n\n return promise.finally(() => self.removeEventListener(\"message\", receiveSecrets));\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation https://aka.ms/apimdocs/portal/customwidgets
|
|
3
|
+
*/
|
|
4
|
+
export { APIM_EDITOR_DATA_KEY, APIM_ON_CHANGE_MESSAGE_KEY, APIM_ASK_FOR_SECRETS_MESSAGE_KEY, getWidgetData, getEditorValues, getValues, askForSecrets, buildOnChange, onChangeWithOrigin, } from "./utils.js";
|
|
5
|
+
export type { PortalData, EditorData, OnChange, Secrets, TargetModule, ValuesCommon, Environment, } from "./utils.js";
|
|
6
|
+
export { BLOB_ROOT, APIM_CONFIG_FILE_NAME, BLOB_DATA_FOLDER, BLOB_CONFIGS_FOLDER, buildBlobDataPath, buildBlobConfigPath, } from "./paths.js";
|
|
7
|
+
import deployNodeJS from "./node/deploy.js";
|
|
8
|
+
export { deployNodeJS };
|
|
9
|
+
export type { ServiceInformation, DeployConfig } from "./node/types.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA;;GAEG;AAEH,OAAO,EACL,oBAAoB,EACpB,0BAA0B,EAC1B,gCAAgC,EAChC,aAAa,EACb,eAAe,EACf,SAAS,EACT,aAAa,EACb,aAAa,EACb,kBAAkB,GACnB,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,UAAU,EACV,UAAU,EACV,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,SAAS,EACT,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,YAAY,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,CAAC;AACxB,YAAY,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
/**
|
|
4
|
+
* @packageDocumentation https://aka.ms/apimdocs/portal/customwidgets
|
|
5
|
+
*/
|
|
6
|
+
export { APIM_EDITOR_DATA_KEY, APIM_ON_CHANGE_MESSAGE_KEY, APIM_ASK_FOR_SECRETS_MESSAGE_KEY, getWidgetData, getEditorValues, getValues, askForSecrets, buildOnChange, onChangeWithOrigin, } from "./utils.js";
|
|
7
|
+
export { BLOB_ROOT, APIM_CONFIG_FILE_NAME, BLOB_DATA_FOLDER, BLOB_CONFIGS_FOLDER, buildBlobDataPath, buildBlobConfigPath, } from "./paths.js";
|
|
8
|
+
import deployNodeJS from "./node/deploy.js";
|
|
9
|
+
export { deployNodeJS };
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;GAEG;AAEH,OAAO,EACL,oBAAoB,EACpB,0BAA0B,EAC1B,gCAAgC,EAChC,aAAa,EACb,eAAe,EACf,SAAS,EACT,aAAa,EACb,aAAa,EACb,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAUpB,OAAO,EACL,SAAS,EACT,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,YAAY,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * @packageDocumentation https://aka.ms/apimdocs/portal/customwidgets\n */\n\nexport {\n APIM_EDITOR_DATA_KEY,\n APIM_ON_CHANGE_MESSAGE_KEY,\n APIM_ASK_FOR_SECRETS_MESSAGE_KEY,\n getWidgetData,\n getEditorValues,\n getValues,\n askForSecrets,\n buildOnChange,\n onChangeWithOrigin,\n} from \"./utils.js\";\nexport type {\n PortalData,\n EditorData,\n OnChange,\n Secrets,\n TargetModule,\n ValuesCommon,\n Environment,\n} from \"./utils.js\";\nexport {\n BLOB_ROOT,\n APIM_CONFIG_FILE_NAME,\n BLOB_DATA_FOLDER,\n BLOB_CONFIGS_FOLDER,\n buildBlobDataPath,\n buildBlobConfigPath,\n} from \"./paths.js\";\n\nimport deployNodeJS from \"./node/deploy.js\";\nexport { deployNodeJS };\nexport type { ServiceInformation, DeployConfig } from \"./node/types.js\";\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { BlockBlobUploadResponse } from "@azure/storage-blob";
|
|
2
|
+
export type Config = Record<string, unknown>;
|
|
3
|
+
/**
|
|
4
|
+
* A service wrapping ContainerClient class to simplify blob handling
|
|
5
|
+
*/
|
|
6
|
+
export declare class CustomWidgetBlobService {
|
|
7
|
+
readonly containerClient: import("@azure/storage-blob").ContainerClient;
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly pathWidget: string;
|
|
10
|
+
readonly pathConfig: string;
|
|
11
|
+
/**
|
|
12
|
+
* @param blobStorageUrl - blob storage SAS URL
|
|
13
|
+
* @param name - name of the custom widget to be taken care of
|
|
14
|
+
*/
|
|
15
|
+
constructor(blobStorageUrl: string, name: string);
|
|
16
|
+
private extractFileName;
|
|
17
|
+
blobUpload(absolutePath: string, content: Buffer): Promise<BlockBlobUploadResponse>;
|
|
18
|
+
jsonUpload(absolutePath: string, json: Record<string, unknown>): Promise<BlockBlobUploadResponse>;
|
|
19
|
+
blobDownload(absolutePath: string): Promise<Buffer>;
|
|
20
|
+
dirDelete(absolutePath: string): Promise<void>;
|
|
21
|
+
uploadWidgetDataFile(file: string, content: Buffer): Promise<BlockBlobUploadResponse>;
|
|
22
|
+
cleanDataDir(): Promise<void>;
|
|
23
|
+
getConfig(): Promise<Config>;
|
|
24
|
+
uploadConfig(config: Config): Promise<BlockBlobUploadResponse>;
|
|
25
|
+
}
|
|
26
|
+
export default CustomWidgetBlobService;
|
|
27
|
+
//# sourceMappingURL=CustomWidgetBlobService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomWidgetBlobService.d.ts","sourceRoot":"","sources":["../../../src/node/CustomWidgetBlobService.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAInE,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE7C;;GAEG;AACH,qBAAa,uBAAuB;IAClC,QAAQ,CAAC,eAAe,gDAAC;IACzB,QAAQ,CAAC,IAAI,SAAC;IACd,QAAQ,CAAC,UAAU,SAAC;IACpB,QAAQ,CAAC,UAAU,SAAC;IAEpB;;;OAGG;gBACS,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAShD,OAAO,CAAC,eAAe;IAIjB,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAUnF,UAAU,CACd,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,OAAO,CAAC,uBAAuB,CAAC;IAI7B,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAInD,SAAS,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM9C,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAIrF,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7B,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAK5B,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC;CAGrE;AAED,eAAe,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { BlobServiceClient } from "@azure/storage-blob";
|
|
4
|
+
import { buildBlobConfigPath, buildBlobDataPath } from "../paths.js";
|
|
5
|
+
/**
|
|
6
|
+
* A service wrapping ContainerClient class to simplify blob handling
|
|
7
|
+
*/
|
|
8
|
+
export class CustomWidgetBlobService {
|
|
9
|
+
containerClient;
|
|
10
|
+
name;
|
|
11
|
+
pathWidget;
|
|
12
|
+
pathConfig;
|
|
13
|
+
/**
|
|
14
|
+
* @param blobStorageUrl - blob storage SAS URL
|
|
15
|
+
* @param name - name of the custom widget to be taken care of
|
|
16
|
+
*/
|
|
17
|
+
constructor(blobStorageUrl, name) {
|
|
18
|
+
const container = "content";
|
|
19
|
+
const blobServiceClient = new BlobServiceClient(blobStorageUrl.replace(`/${container}`, ""));
|
|
20
|
+
this.containerClient = blobServiceClient.getContainerClient(container);
|
|
21
|
+
this.name = name;
|
|
22
|
+
this.pathWidget = buildBlobDataPath(name);
|
|
23
|
+
this.pathConfig = buildBlobConfigPath(name);
|
|
24
|
+
}
|
|
25
|
+
extractFileName(path) {
|
|
26
|
+
return path.split("/").pop();
|
|
27
|
+
}
|
|
28
|
+
async blobUpload(absolutePath, content) {
|
|
29
|
+
const mimeImport = await import("mime");
|
|
30
|
+
const mime = mimeImport.default;
|
|
31
|
+
const fileName = this.extractFileName(absolutePath);
|
|
32
|
+
if (!fileName)
|
|
33
|
+
throw new Error("a fileName was not found in the absolutePath");
|
|
34
|
+
return this.containerClient.getBlockBlobClient(absolutePath).upload(content, content.length, {
|
|
35
|
+
blobHTTPHeaders: { blobContentType: mime.getType(fileName) || "application/octet-stream" },
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async jsonUpload(absolutePath, json) {
|
|
39
|
+
return this.blobUpload(absolutePath, Buffer.from(JSON.stringify(json)));
|
|
40
|
+
}
|
|
41
|
+
async blobDownload(absolutePath) {
|
|
42
|
+
return this.containerClient.getBlockBlobClient(absolutePath).downloadToBuffer();
|
|
43
|
+
}
|
|
44
|
+
async dirDelete(absolutePath) {
|
|
45
|
+
for await (const blob of await this.containerClient.listBlobsFlat({ prefix: absolutePath })) {
|
|
46
|
+
await this.containerClient.deleteBlob(blob.name);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async uploadWidgetDataFile(file, content) {
|
|
50
|
+
return this.blobUpload(this.pathWidget + file, content);
|
|
51
|
+
}
|
|
52
|
+
async cleanDataDir() {
|
|
53
|
+
return this.dirDelete(this.pathWidget);
|
|
54
|
+
}
|
|
55
|
+
async getConfig() {
|
|
56
|
+
const buffer = await this.blobDownload(this.pathConfig);
|
|
57
|
+
return JSON.parse(buffer.toString());
|
|
58
|
+
}
|
|
59
|
+
async uploadConfig(config) {
|
|
60
|
+
return this.jsonUpload(this.pathConfig, config);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export default CustomWidgetBlobService;
|
|
64
|
+
//# sourceMappingURL=CustomWidgetBlobService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomWidgetBlobService.js","sourceRoot":"","sources":["../../../src/node/CustomWidgetBlobService.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIrE;;GAEG;AACH,MAAM,OAAO,uBAAuB;IACzB,eAAe,CAAC;IAChB,IAAI,CAAC;IACL,UAAU,CAAC;IACX,UAAU,CAAC;IAEpB;;;OAGG;IACH,YAAY,cAAsB,EAAE,IAAY;QAC9C,MAAM,SAAS,GAAG,SAAS,CAAC;QAC5B,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;QAC7F,IAAI,CAAC,eAAe,GAAG,iBAAiB,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;QACvE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,CAAC,UAAU,GAAG,mBAAmB,CAAC,IAAI,CAA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AI,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,IAAY,EAAE,OAAe;QACtD,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,GAAG,IAAI,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,SAAS;QACb,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACxD,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,MAAc;QAC/B,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAClD,CAAC;CACF;AAED,eAAe,uBAAuB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { BlockBlobUploadResponse } from \"@azure/storage-blob\";\nimport { BlobServiceClient } from \"@azure/storage-blob\";\nimport { buildBlobConfigPath, buildBlobDataPath } from \"../paths.js\";\n\nexport type Config = Record<string, unknown>;\n\n/**\n * A service wrapping ContainerClient class to simplify blob handling\n */\nexport class CustomWidgetBlobService {\n readonly containerClient;\n readonly name;\n readonly pathWidget;\n readonly pathConfig;\n\n /**\n * @param blobStorageUrl - blob storage SAS URL\n * @param name - name of the custom widget to be taken care of\n */\n constructor(blobStorageUrl: string, name: string) {\n const container = \"content\";\n const blobServiceClient = new BlobServiceClient(blobStorageUrl.replace(`/${container}`, \"\"));\n this.containerClient = blobServiceClient.getContainerClient(container);\n this.name = name;\n this.pathWidget = buildBlobDataPath(name);\n this.pathConfig = buildBlobConfigPath(name);\n }\n\n private extractFileName(path: string): string | undefined {\n return path.split(\"/\").pop();\n }\n\n async blobUpload(absolutePath: string, content: Buffer): Promise<BlockBlobUploadResponse> {\n const mimeImport = await import(\"mime\");\n const mime = mimeImport.default;\n const fileName = this.extractFileName(absolutePath);\n if (!fileName) throw new Error(\"a fileName was not found in the absolutePath\");\n return this.containerClient.getBlockBlobClient(absolutePath).upload(content, content.length, {\n blobHTTPHeaders: { blobContentType: mime.getType(fileName) || \"application/octet-stream\" },\n });\n }\n\n async jsonUpload(\n absolutePath: string,\n json: Record<string, unknown>,\n ): Promise<BlockBlobUploadResponse> {\n return this.blobUpload(absolutePath, Buffer.from(JSON.stringify(json)));\n }\n\n async blobDownload(absolutePath: string): Promise<Buffer> {\n return this.containerClient.getBlockBlobClient(absolutePath).downloadToBuffer();\n }\n\n async dirDelete(absolutePath: string): Promise<void> {\n for await (const blob of await this.containerClient.listBlobsFlat({ prefix: absolutePath })) {\n await this.containerClient.deleteBlob(blob.name);\n }\n }\n\n async uploadWidgetDataFile(file: string, content: Buffer): Promise<BlockBlobUploadResponse> {\n return this.blobUpload(this.pathWidget + file, content);\n }\n\n async cleanDataDir(): Promise<void> {\n return this.dirDelete(this.pathWidget);\n }\n\n async getConfig(): Promise<Config> {\n const buffer = await this.blobDownload(this.pathConfig);\n return JSON.parse(buffer.toString());\n }\n\n async uploadConfig(config: Config): Promise<BlockBlobUploadResponse> {\n return this.jsonUpload(this.pathConfig, config);\n }\n}\n\nexport default CustomWidgetBlobService;\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DeployConfig, ServiceInformation } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Deploys everything from /dist folder to the API Management DevPortals' blob storage.
|
|
4
|
+
*
|
|
5
|
+
* @param serviceInformation - service information for deployment
|
|
6
|
+
* @param name - name of the widget to be deployed
|
|
7
|
+
* @param fallbackConfigPath - local path to the config file (by default "./static/config.msapim.json")
|
|
8
|
+
* @param config - optional config object
|
|
9
|
+
*/
|
|
10
|
+
declare function deploy(serviceInformation: ServiceInformation, name: string, fallbackConfigPath?: string, { rootLocal, interactiveBrowserCredentialOptions, }?: DeployConfig): Promise<void>;
|
|
11
|
+
export default deploy;
|
|
12
|
+
//# sourceMappingURL=deploy.d.ts.map
|