@azure/api-management-custom-widgets-tools 1.0.0-beta.2 → 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.
Files changed (113) hide show
  1. package/LICENSE +17 -17
  2. package/README.md +2 -2
  3. package/dist/browser/index.d.ts +10 -0
  4. package/dist/browser/index.d.ts.map +1 -0
  5. package/{dist-esm/src → dist/browser}/index.js +4 -4
  6. package/dist/browser/index.js.map +1 -0
  7. package/dist/browser/node/CustomWidgetBlobService.d.ts +27 -0
  8. package/dist/browser/node/CustomWidgetBlobService.d.ts.map +1 -0
  9. package/{dist-esm/src → dist/browser}/node/CustomWidgetBlobService.js +10 -24
  10. package/dist/browser/node/CustomWidgetBlobService.js.map +1 -0
  11. package/dist/browser/node/deploy-browser.d.mts.map +1 -0
  12. package/dist/browser/node/deploy-browser.mjs.map +1 -0
  13. package/dist/browser/node/deploy.d.ts +3 -0
  14. package/dist/browser/node/deploy.js +7 -0
  15. package/dist/browser/node/getStorageSasUrl.d.ts +10 -0
  16. package/dist/browser/node/getStorageSasUrl.d.ts.map +1 -0
  17. package/{dist-esm/src → dist/browser}/node/getStorageSasUrl.js +5 -5
  18. package/dist/browser/node/getStorageSasUrl.js.map +1 -0
  19. package/dist/browser/node/readdir-browser.d.mts.map +1 -0
  20. package/dist/browser/node/readdir-browser.mjs.map +1 -0
  21. package/dist/browser/node/readdir.d.ts +3 -0
  22. package/dist/browser/node/readdir.js +7 -0
  23. package/dist/browser/node/types.d.ts +24 -0
  24. package/dist/browser/node/types.d.ts.map +1 -0
  25. package/dist/browser/node/types.js +4 -0
  26. package/dist/browser/node/types.js.map +1 -0
  27. package/dist/browser/package.json +3 -0
  28. package/dist/browser/paths.d.ts +21 -0
  29. package/dist/browser/paths.d.ts.map +1 -0
  30. package/{dist-esm/src → dist/browser}/paths.js +1 -1
  31. package/{dist-esm/src → dist/browser}/paths.js.map +1 -1
  32. package/{types/latest/api-management-custom-widgets-tools.d.ts → dist/browser/utils.d.ts} +98 -177
  33. package/dist/browser/utils.d.ts.map +1 -0
  34. package/{dist-esm/src → dist/browser}/utils.js +3 -4
  35. package/dist/browser/utils.js.map +1 -0
  36. package/dist/commonjs/index.d.ts +10 -0
  37. package/dist/commonjs/index.d.ts.map +1 -0
  38. package/dist/commonjs/index.js +29 -0
  39. package/dist/commonjs/index.js.map +1 -0
  40. package/dist/commonjs/node/CustomWidgetBlobService.d.ts +27 -0
  41. package/dist/commonjs/node/CustomWidgetBlobService.d.ts.map +1 -0
  42. package/dist/commonjs/node/CustomWidgetBlobService.js +68 -0
  43. package/dist/commonjs/node/CustomWidgetBlobService.js.map +1 -0
  44. package/dist/commonjs/node/deploy.d.ts +12 -0
  45. package/dist/commonjs/node/deploy.d.ts.map +1 -0
  46. package/dist/commonjs/node/deploy.js +59 -0
  47. package/dist/commonjs/node/deploy.js.map +1 -0
  48. package/dist/commonjs/node/getStorageSasUrl.d.ts +10 -0
  49. package/dist/commonjs/node/getStorageSasUrl.d.ts.map +1 -0
  50. package/dist/commonjs/node/getStorageSasUrl.js +35 -0
  51. package/dist/commonjs/node/getStorageSasUrl.js.map +1 -0
  52. package/dist/commonjs/node/readdir.d.ts +3 -0
  53. package/dist/commonjs/node/readdir.d.ts.map +1 -0
  54. package/dist/commonjs/node/readdir.js +22 -0
  55. package/dist/commonjs/node/readdir.js.map +1 -0
  56. package/dist/commonjs/node/types.d.ts +24 -0
  57. package/dist/commonjs/node/types.d.ts.map +1 -0
  58. package/dist/commonjs/node/types.js +5 -0
  59. package/dist/commonjs/node/types.js.map +1 -0
  60. package/dist/commonjs/package.json +3 -0
  61. package/dist/commonjs/paths.d.ts +21 -0
  62. package/dist/commonjs/paths.d.ts.map +1 -0
  63. package/dist/commonjs/paths.js +32 -0
  64. package/dist/commonjs/paths.js.map +1 -0
  65. package/dist/commonjs/tsdoc-metadata.json +11 -0
  66. package/dist/commonjs/utils.d.ts +98 -0
  67. package/dist/commonjs/utils.d.ts.map +1 -0
  68. package/dist/commonjs/utils.js +134 -0
  69. package/dist/commonjs/utils.js.map +1 -0
  70. package/dist/esm/index.d.ts +10 -0
  71. package/dist/esm/index.d.ts.map +1 -0
  72. package/dist/esm/index.js +10 -0
  73. package/dist/esm/index.js.map +1 -0
  74. package/dist/esm/node/CustomWidgetBlobService.d.ts +27 -0
  75. package/dist/esm/node/CustomWidgetBlobService.d.ts.map +1 -0
  76. package/dist/esm/node/CustomWidgetBlobService.js +64 -0
  77. package/dist/esm/node/CustomWidgetBlobService.js.map +1 -0
  78. package/dist/esm/node/deploy.d.ts +12 -0
  79. package/dist/esm/node/deploy.d.ts.map +1 -0
  80. package/{dist-esm/src → dist/esm}/node/deploy.js +6 -6
  81. package/dist/esm/node/deploy.js.map +1 -0
  82. package/dist/esm/node/getStorageSasUrl.d.ts +10 -0
  83. package/dist/esm/node/getStorageSasUrl.d.ts.map +1 -0
  84. package/dist/esm/node/getStorageSasUrl.js +33 -0
  85. package/dist/esm/node/getStorageSasUrl.js.map +1 -0
  86. package/dist/esm/node/readdir.d.ts +3 -0
  87. package/dist/esm/node/readdir.d.ts.map +1 -0
  88. package/{dist-esm/src → dist/esm}/node/readdir.js +3 -3
  89. package/dist/esm/node/readdir.js.map +1 -0
  90. package/dist/esm/node/types.d.ts +24 -0
  91. package/dist/esm/node/types.d.ts.map +1 -0
  92. package/dist/esm/node/types.js +4 -0
  93. package/dist/esm/node/types.js.map +1 -0
  94. package/dist/esm/package.json +3 -0
  95. package/dist/esm/paths.d.ts +21 -0
  96. package/dist/esm/paths.d.ts.map +1 -0
  97. package/dist/esm/paths.js +27 -0
  98. package/dist/esm/paths.js.map +1 -0
  99. package/dist/esm/utils.d.ts +98 -0
  100. package/dist/esm/utils.d.ts.map +1 -0
  101. package/dist/esm/utils.js +122 -0
  102. package/dist/esm/utils.js.map +1 -0
  103. package/package.json +70 -80
  104. package/dist/index.js +0 -347
  105. package/dist/index.js.map +0 -1
  106. package/dist-esm/src/index.js.map +0 -1
  107. package/dist-esm/src/node/CustomWidgetBlobService.js.map +0 -1
  108. package/dist-esm/src/node/deploy.browser.js +0 -7
  109. package/dist-esm/src/node/deploy.browser.js.map +0 -1
  110. package/dist-esm/src/node/deploy.js.map +0 -1
  111. package/dist-esm/src/node/getStorageSasUrl.js.map +0 -1
  112. package/dist-esm/src/node/readdir.js.map +0 -1
  113. package/dist-esm/src/utils.js.map +0 -1
@@ -1,177 +1,98 @@
1
- /**
2
- * @packageDocumentation https://aka.ms/apimdocs/portal/customwidgets
3
- */
4
-
5
- import { InteractiveBrowserCredentialNodeOptions } from '@azure/identity';
6
-
7
- /**
8
- * 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.
9
- */
10
- export declare const APIM_ASK_FOR_SECRETS_MESSAGE_KEY = "askForSecretsMSAPIM";
11
-
12
- /** name of the configuration file */
13
- export declare const APIM_CONFIG_FILE_NAME = "config.msapim.json";
14
-
15
- /**
16
- * Key for a search param, from which editor data will be loaded from.
17
- */
18
- export declare const APIM_EDITOR_DATA_KEY = "editorData";
19
-
20
- /**
21
- * Key for a post message object, it's used to propagate changes from editor to the DevPortal. Used to prevent interference with other applications.
22
- */
23
- export declare const APIM_ON_CHANGE_MESSAGE_KEY = "customInputValueChangedMSAPIM";
24
-
25
- /**
26
- * Request secrets - token & userId, from the Dev portal parent window.
27
- *
28
- * @param targetModule - is the function invoke from the main "app" window or the admin "editor"?
29
- */
30
- export declare function askForSecrets(targetModule: TargetModule): Promise<Secrets>;
31
-
32
- /** name of the blob storage folder with widget configs */
33
- export declare const BLOB_CONFIGS_FOLDER = "configs";
34
-
35
- /** name of the blob storage folder with widget implementation */
36
- export declare const BLOB_DATA_FOLDER = "data";
37
-
38
- /** root of the blob storage folder */
39
- export declare const BLOB_ROOT = "custom-widgets";
40
-
41
- /**
42
- * Generate relative path for widgets' config on the blob storage
43
- *
44
- * @param name - name of the widget
45
- */
46
- export declare function buildBlobConfigPath(name: string): string;
47
-
48
- /**
49
- * Generate relative path for widgets' data on the blob storage
50
- *
51
- * @param name - name of the widget
52
- */
53
- export declare function buildBlobDataPath(name: string): string;
54
-
55
- /**
56
- * Build onChange function, which you can use, to send changed data from the editor.
57
- */
58
- export declare function buildOnChange<Values extends ValuesCommon>(): OnChange<Values>;
59
-
60
- /**
61
- * Optional options object for configuring the deployment function.
62
- *
63
- * @param rootLocal - optional, root of the local folder with compiled project to be exported (by default "./dist")
64
- * @param interactiveBrowserCredentialOptions - options for InteractiveBrowserCredential for Node or InBrowser from \@azure/identity
65
- */
66
- export declare type DeployConfig = {
67
- rootLocal?: string;
68
- interactiveBrowserCredentialOptions?: InteractiveBrowserCredentialNodeOptions;
69
- };
70
-
71
- /**
72
- * Deploys everything from /dist folder to the API Management DevPortals' blob storage.
73
- *
74
- * @param serviceInformation - service information for deployment
75
- * @param name - name of the widget to be deployed
76
- * @param fallbackConfigPath - local path to the config file (by default "./static/config.msapim.json")
77
- * @param config - optional config object
78
- */
79
- export declare function deployNodeJS(serviceInformation: ServiceInformation, name: string, fallbackConfigPath?: string, { rootLocal, interactiveBrowserCredentialOptions, }?: DeployConfig): Promise<void>;
80
-
81
- /** JSON object with all the data you'll receive from the Dev Portal */
82
- export declare interface EditorData<Values extends ValuesCommon> extends PortalData {
83
- /** values you've set in the admin editor window */
84
- values: Partial<Values>;
85
- }
86
-
87
- /**
88
- * All possible runtime environments
89
- */
90
- export declare type Environment = "development" | "publishing" | "runtime" | "error";
91
-
92
- /**
93
- * Function to get values you've set in the admin editor window.
94
- */
95
- export declare function getEditorValues<Values extends ValuesCommon>(): Partial<Values>;
96
-
97
- /**
98
- * Function to get values you've set in the admin editor window. Undefined/empty values are replaced with default values.
99
- *
100
- * @param valuesDefault - object with your default values to use, just import valuesDefault object from values.ts folder
101
- */
102
- export declare function getValues<Values extends ValuesCommon>(valuesDefault: Values): Values;
103
-
104
- /**
105
- * Function to get all data related to the widget including technical values not expected to be needed in most cases.
106
- * Intended mostly for internal use, API might change. Consider using getValues or getEditorValues instead.
107
- */
108
- export declare function getWidgetData<Values extends ValuesCommon>(): EditorData<Values>;
109
-
110
- /**
111
- * Type of the onChange function.
112
- */
113
- export declare type OnChange<Values extends ValuesCommon> = (values: Partial<Values>) => void;
114
-
115
- /**
116
- * The onChange function itself with 'origin' provided as a param.
117
- *
118
- * @param origin - web content's origin (URL) of your Dev Portal to send changes to
119
- * @param instanceId - ID of this particular instance of the widget
120
- * @param values - values that changed
121
- */
122
- export declare function onChangeWithOrigin<Values extends ValuesCommon>(origin: string, instanceId: string, values: Values): void;
123
-
124
- /** Information about the widget instance received from the Dev Portal */
125
- export declare interface PortalData {
126
- /** current runtime environment */
127
- environment: Environment;
128
- /** ID of this particular instance of the widget */
129
- instanceId: string;
130
- }
131
-
132
- /**
133
- * Secrets needed for communication with Dev Portal back-end and other runtime data
134
- */
135
- export declare type Secrets = {
136
- managementApiUrl: string;
137
- apiVersion: string;
138
- userId?: string;
139
- token?: string;
140
- parentLocation: {
141
- host: string;
142
- hostname: string;
143
- href: string;
144
- origin: string;
145
- pathname: string;
146
- port: string;
147
- protocol: string;
148
- search: string;
149
- };
150
- };
151
-
152
- /**
153
- * resourceId - resource ID of API Management service "subscriptions/[subscription-id]/resourceGroups/[resource-group-name]/providers/Microsoft.ApiManagement/service/[service-name]"
154
- * managementApiEndpoint - URL with protocol (e.g. https://management.azure.com)
155
- * apiVersion - optional to override default (e.g. "2019-01-01")
156
- * tokenOverride - optional, provides token to use for auth, instead of 'az login' approach
157
- */
158
- export declare type ServiceInformation = {
159
- resourceId: string;
160
- managementApiEndpoint: string;
161
- apiVersion?: string;
162
- tokenOverride?: string;
163
- };
164
-
165
- /**
166
- * Possible target modules
167
- * "app" for main application which is embedded in your Dev Portal
168
- * "editor" for form in admin panel
169
- */
170
- export declare type TargetModule = "app" | "editor";
171
-
172
- /**
173
- * Base of a values obj
174
- */
175
- export declare type ValuesCommon = Record<string, unknown>;
176
-
177
- export { }
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;;G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AkB,CAAC,MAAM,SAAS,YAAY,EAC5D,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,IAAI,CAIN;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,SAAS,YAAY,KAAK,QAAQ,CAAC,MAAM,CAAC,CAG7E;AAED;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,QAAQ,CAAC;AAC5C;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;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"}
@@ -1,5 +1,5 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
2
+ // Licensed under the MIT License.
3
3
  /**
4
4
  * Key for a search param, from which editor data will be loaded from.
5
5
  */
@@ -13,9 +13,8 @@ export const APIM_ON_CHANGE_MESSAGE_KEY = "customInputValueChangedMSAPIM";
13
13
  */
14
14
  export const APIM_ASK_FOR_SECRETS_MESSAGE_KEY = "askForSecretsMSAPIM";
15
15
  function parseWidgetData(urlSearchParams) {
16
- var _a;
17
16
  try {
18
- const urlEditorParams = JSON.parse(decodeURIComponent((_a = urlSearchParams.get(APIM_EDITOR_DATA_KEY)) !== null && _a !== void 0 ? _a : ""));
17
+ const urlEditorParams = JSON.parse(decodeURIComponent(urlSearchParams.get(APIM_EDITOR_DATA_KEY) ?? ""));
19
18
  // if (!("origin" in urlEditorParams)) {
20
19
  // console.error(
21
20
  // "Could not get 'origin' from the search params of the URL:\n" + self.location.href
@@ -49,7 +48,7 @@ export function getEditorValues() {
49
48
  return getEditorValuesPure(new URLSearchParams(self.location.search));
50
49
  }
51
50
  export function getValuesPure(valuesDefault, urlSearchParams) {
52
- const values = Object.assign({}, valuesDefault); // set Obj to contain all possible values and prefill default value
51
+ const values = { ...valuesDefault }; // set Obj to contain all possible values and prefill default value
53
52
  const urlValues = parseWidgetData(urlSearchParams).values;
54
53
  Object.keys(values).forEach((key) => {
55
54
  const value = urlValues[key];
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,CAAC;AACjD;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,+BAA+B,CAAC;AAC1E;;GAEG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,qBAAqB,CAAC;AA2BtE,SAAS,eAAe,CACtB,eAAgC;IAEhC,IAAI,CAAC;QACH,MAAM,eAAe,GAAuB,IAAI,CAAC,KAAK,CACpD,kBAAkB,CAAC,eAAe,CAAC,GAAG,CAAC,oBAAoB,CAAC,IAAI,EAAE,CAAC,CACpE,CAAC;QAEF,wCAAwC;QACxC,mBAAmB;QACnB,yFAAyF;QACzF,OAAO;QACP,IAAI;QACJ,OAAO,eAAe,CAAC;IACzB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CACX,kBAAkB,oBAAoB,wCAAwC;YAC5E,IAAI,CAAC,QAAQ,EACf,CAAC,CACF,CAAC;QACF,OAAO,EAAE,MAAM,EAAE,E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AAC,CAAC;QAEjD,MAAM,OAAO,GAAG;YACd,CAAC,gCAAgC,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,29 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.deployNodeJS = exports.buildBlobConfigPath = exports.buildBlobDataPath = exports.BLOB_CONFIGS_FOLDER = exports.BLOB_DATA_FOLDER = exports.APIM_CONFIG_FILE_NAME = exports.BLOB_ROOT = exports.onChangeWithOrigin = exports.buildOnChange = exports.askForSecrets = exports.getValues = exports.getEditorValues = exports.getWidgetData = exports.APIM_ASK_FOR_SECRETS_MESSAGE_KEY = exports.APIM_ON_CHANGE_MESSAGE_KEY = exports.APIM_EDITOR_DATA_KEY = void 0;
6
+ const tslib_1 = require("tslib");
7
+ /**
8
+ * @packageDocumentation https://aka.ms/apimdocs/portal/customwidgets
9
+ */
10
+ var utils_js_1 = require("./utils.js");
11
+ Object.defineProperty(exports, "APIM_EDITOR_DATA_KEY", { enumerable: true, get: function () { return utils_js_1.APIM_EDITOR_DATA_KEY; } });
12
+ Object.defineProperty(exports, "APIM_ON_CHANGE_MESSAGE_KEY", { enumerable: true, get: function () { return utils_js_1.APIM_ON_CHANGE_MESSAGE_KEY; } });
13
+ Object.defineProperty(exports, "APIM_ASK_FOR_SECRETS_MESSAGE_KEY", { enumerable: true, get: function () { return utils_js_1.APIM_ASK_FOR_SECRETS_MESSAGE_KEY; } });
14
+ Object.defineProperty(exports, "getWidgetData", { enumerable: true, get: function () { return utils_js_1.getWidgetData; } });
15
+ Object.defineProperty(exports, "getEditorValues", { enumerable: true, get: function () { return utils_js_1.getEditorValues; } });
16
+ Object.defineProperty(exports, "getValues", { enumerable: true, get: function () { return utils_js_1.getValues; } });
17
+ Object.defineProperty(exports, "askForSecrets", { enumerable: true, get: function () { return utils_js_1.askForSecrets; } });
18
+ Object.defineProperty(exports, "buildOnChange", { enumerable: true, get: function () { return utils_js_1.buildOnChange; } });
19
+ Object.defineProperty(exports, "onChangeWithOrigin", { enumerable: true, get: function () { return utils_js_1.onChangeWithOrigin; } });
20
+ var paths_js_1 = require("./paths.js");
21
+ Object.defineProperty(exports, "BLOB_ROOT", { enumerable: true, get: function () { return paths_js_1.BLOB_ROOT; } });
22
+ Object.defineProperty(exports, "APIM_CONFIG_FILE_NAME", { enumerable: true, get: function () { return paths_js_1.APIM_CONFIG_FILE_NAME; } });
23
+ Object.defineProperty(exports, "BLOB_DATA_FOLDER", { enumerable: true, get: function () { return paths_js_1.BLOB_DATA_FOLDER; } });
24
+ Object.defineProperty(exports, "BLOB_CONFIGS_FOLDER", { enumerable: true, get: function () { return paths_js_1.BLOB_CONFIGS_FOLDER; } });
25
+ Object.defineProperty(exports, "buildBlobDataPath", { enumerable: true, get: function () { return paths_js_1.buildBlobDataPath; } });
26
+ Object.defineProperty(exports, "buildBlobConfigPath", { enumerable: true, get: function () { return paths_js_1.buildBlobConfigPath; } });
27
+ const deploy_js_1 = tslib_1.__importDefault(require("./node/deploy.js"));
28
+ exports.deployNodeJS = deploy_js_1.default;
29
+ //# 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,uCAUoB;AATlB,gHAAA,oBAAoB,OAAA;AACpB,sHAAA,0BAA0B,OAAA;AAC1B,4HAAA,gCAAgC,OAAA;AAChC,yGAAA,aAAa,OAAA;AACb,2GAAA,eAAe,OAAA;AACf,qGAAA,SAAS,OAAA;AACT,yGAAA,aAAa,OAAA;AACb,yGAAA,aAAa,OAAA;AACb,8GAAA,kBAAkB,OAAA;AAWpB,uCAOoB;AANlB,qGAAA,SAAS,OAAA;AACT,iHAAA,qBAAqB,OAAA;AACrB,4GAAA,gBAAgB,OAAA;AAChB,+GAAA,mBAAmB,OAAA;AACnB,6GAAA,iBAAiB,OAAA;AACjB,+GAAA,mBAAmB,OAAA;AAGrB,yEAA4C;AACnC,uBADF,mBAAY,CACE","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,68 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.CustomWidgetBlobService = void 0;
6
+ const storage_blob_1 = require("@azure/storage-blob");
7
+ const paths_js_1 = require("../paths.js");
8
+ /**
9
+ * A service wrapping ContainerClient class to simplify blob handling
10
+ */
11
+ class CustomWidgetBlobService {
12
+ containerClient;
13
+ name;
14
+ pathWidget;
15
+ pathConfig;
16
+ /**
17
+ * @param blobStorageUrl - blob storage SAS URL
18
+ * @param name - name of the custom widget to be taken care of
19
+ */
20
+ constructor(blobStorageUrl, name) {
21
+ const container = "content";
22
+ const blobServiceClient = new storage_blob_1.BlobServiceClient(blobStorageUrl.replace(`/${container}`, ""));
23
+ this.containerClient = blobServiceClient.getContainerClient(container);
24
+ this.name = name;
25
+ this.pathWidget = (0, paths_js_1.buildBlobDataPath)(name);
26
+ this.pathConfig = (0, paths_js_1.buildBlobConfigPath)(name);
27
+ }
28
+ extractFileName(path) {
29
+ return path.split("/").pop();
30
+ }
31
+ async blobUpload(absolutePath, content) {
32
+ const mimeImport = await import("mime");
33
+ const mime = mimeImport.default;
34
+ const fileName = this.extractFileName(absolutePath);
35
+ if (!fileName)
36
+ throw new Error("a fileName was not found in the absolutePath");
37
+ return this.containerClient.getBlockBlobClient(absolutePath).upload(content, content.length, {
38
+ blobHTTPHeaders: { blobContentType: mime.getType(fileName) || "application/octet-stream" },
39
+ });
40
+ }
41
+ async jsonUpload(absolutePath, json) {
42
+ return this.blobUpload(absolutePath, Buffer.from(JSON.stringify(json)));
43
+ }
44
+ async blobDownload(absolutePath) {
45
+ return this.containerClient.getBlockBlobClient(absolutePath).downloadToBuffer();
46
+ }
47
+ async dirDelete(absolutePath) {
48
+ for await (const blob of await this.containerClient.listBlobsFlat({ prefix: absolutePath })) {
49
+ await this.containerClient.deleteBlob(blob.name);
50
+ }
51
+ }
52
+ async uploadWidgetDataFile(file, content) {
53
+ return this.blobUpload(this.pathWidget + file, content);
54
+ }
55
+ async cleanDataDir() {
56
+ return this.dirDelete(this.pathWidget);
57
+ }
58
+ async getConfig() {
59
+ const buffer = await this.blobDownload(this.pathConfig);
60
+ return JSON.parse(buffer.toString());
61
+ }
62
+ async uploadConfig(config) {
63
+ return this.jsonUpload(this.pathConfig, config);
64
+ }
65
+ }
66
+ exports.CustomWidgetBlobService = CustomWidgetBlobService;
67
+ exports.default = CustomWidgetBlobService;
68
+ //# 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,sDAAwD;AACxD,0CAAqE;AAIrE;;GAEG;AACH,MAAa,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,gCAAiB,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;QAC7F,IAAI,CAAC,eAAe,GAAG,iBAAiB,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,CAAC,YAAoB;QAClC,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;YAC5F,MAAM,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,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;AAlED,0DAkEC;AAED,kBAAe,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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/node/deploy.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEnE;;;;;;;GAOG;AACH,iBAAe,MAAM,CACnB,kBAAkB,EAAE,kBAAkB,EACtC,IAAI,EAAE,MAAM,EACZ,kBAAkB,SAAsC,EACxD,EACE,SAAqB,EACrB,mCAA8E,GAC/E,GAAE,YAAiB,GACnB,OAAO,CAAC,IAAI,CAAC,CAiDf;AAED,eAAe,MAAM,CAAC"}
@@ -0,0 +1,59 @@
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 CustomWidgetBlobService_js_1 = tslib_1.__importDefault(require("./CustomWidgetBlobService.js"));
7
+ const paths_js_1 = require("../paths.js");
8
+ const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
9
+ const getStorageSasUrl_js_1 = tslib_1.__importDefault(require("./getStorageSasUrl.js"));
10
+ const readdir_js_1 = tslib_1.__importDefault(require("./readdir.js"));
11
+ /**
12
+ * Deploys everything from /dist folder to the API Management DevPortals' blob storage.
13
+ *
14
+ * @param serviceInformation - service information for deployment
15
+ * @param name - name of the widget to be deployed
16
+ * @param fallbackConfigPath - local path to the config file (by default "./static/config.msapim.json")
17
+ * @param config - optional config object
18
+ */
19
+ async function deploy(serviceInformation, name, fallbackConfigPath = "./static/" + paths_js_1.APIM_CONFIG_FILE_NAME, { rootLocal = "./dist/", interactiveBrowserCredentialOptions = { redirectUri: "http://localhost:1337" }, } = {}) {
20
+ console.log("\n\n");
21
+ console.log("Starting deploy process of custom widget: " + name);
22
+ console.log("Please, sign in to your Azure account when prompted\n");
23
+ const blobStorageUrl = await (0, getStorageSasUrl_js_1.default)(serviceInformation, interactiveBrowserCredentialOptions);
24
+ const customWidgetBlobService = new CustomWidgetBlobService_js_1.default(blobStorageUrl, name);
25
+ let config;
26
+ try {
27
+ console.log("Looking for config file in the Azure blob storage");
28
+ config = await customWidgetBlobService.getConfig();
29
+ }
30
+ catch (e) {
31
+ console.log("Config not found.");
32
+ }
33
+ if (!config) {
34
+ console.log("Looking for a local config file in: " + fallbackConfigPath);
35
+ config = JSON.parse(node_fs_1.default.readFileSync(fallbackConfigPath).toString());
36
+ }
37
+ if (!config) {
38
+ throw new Error("Config file could not be loaded.");
39
+ }
40
+ console.log("Config file loaded\n");
41
+ const files = (0, readdir_js_1.default)("", rootLocal);
42
+ console.log("Starting upload of data files from the '" + rootLocal + "' folder\n");
43
+ await customWidgetBlobService.cleanDataDir();
44
+ const promises = [];
45
+ files.forEach((file) => {
46
+ const content = node_fs_1.default.readFileSync(rootLocal + file);
47
+ const promise = customWidgetBlobService
48
+ .uploadWidgetDataFile(file, content)
49
+ .then(() => console.log("Uploaded file: " + file));
50
+ promises.push(promise);
51
+ });
52
+ await Promise.all(promises);
53
+ console.log(files.length + " files has been uploaded\n");
54
+ config.deployedOn = new Date();
55
+ await customWidgetBlobService.uploadConfig(config);
56
+ console.log("Uploaded updated config");
57
+ }
58
+ exports.default = deploy;
59
+ //# sourceMappingURL=deploy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../../src/node/deploy.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,sGAAmE;AACnE,0CAAoD;AACpD,8DAAyB;AACzB,wF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,SAAS,CAAC,CAAC;IAErC,OAAO,CAAC,GAAG,CAAC,0CAA0C,GAAG,SAAS,GAAG,YAAY,CAAC,CAAC;IAEnF,MAAM,uBAAuB,CAAC,YAAY,EAAE,CAAC;IAE7C,MAAM,QAAQ,GAAoB,EAAE,CAAC;IACrC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACrB,MAAM,OAAO,GAAG,iBAAE,CAAC,YAAY,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;QAClD,MAAM,OAAO,GAAG,uBAAuB;aACpC,oBAAoB,CAAC,IAAI,EAAE,OAAO,CAAC;aACnC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC,CAAC;QACrD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;IACH,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAE5B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,4BAA4B,CAAC,CAAC;IAEzD,MAAM,CAAC,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC;IAC/B,MAAM,uBAAuB,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IACnD,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AACzC,CAAC;AAED,kBAAe,MAAM,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Config } from \"./CustomWidgetBlobService.js\";\nimport CustomWidgetBlobService from \"./CustomWidgetBlobService.js\";\nimport { APIM_CONFIG_FILE_NAME } from \"../paths.js\";\nimport fs from \"node:fs\";\nimport getStorageSasUrl from \"./getStorageSasUrl.js\";\nimport readdir from \"./readdir.js\";\nimport type { DeployConfig, ServiceInformation } from \"./types.js\";\n\n/**\n * Deploys everything from /dist folder to the API Management DevPortals' blob storage.\n *\n * @param serviceInformation - service information for deployment\n * @param name - name of the widget to be deployed\n * @param fallbackConfigPath - local path to the config file (by default \"./static/config.msapim.json\")\n * @param config - optional config object\n */\nasync function deploy(\n serviceInformation: ServiceInformation,\n name: string,\n fallbackConfigPath = \"./static/\" + APIM_CONFIG_FILE_NAME,\n {\n rootLocal = \"./dist/\",\n interactiveBrowserCredentialOptions = { redirectUri: \"http://localhost:1337\" },\n }: DeployConfig = {},\n): Promise<void> {\n console.log(\"\\n\\n\");\n console.log(\"Starting deploy process of custom widget: \" + name);\n console.log(\"Please, sign in to your Azure account when prompted\\n\");\n\n const blobStorageUrl = await getStorageSasUrl(\n serviceInformation,\n interactiveBrowserCredentialOptions,\n );\n const customWidgetBlobService = new CustomWidgetBlobService(blobStorageUrl, name);\n\n let config: Config | undefined;\n try {\n console.log(\"Looking for config file in the Azure blob storage\");\n config = await customWidgetBlobService.getConfig();\n } catch (e) {\n console.log(\"Config not found.\");\n }\n if (!config) {\n console.log(\"Looking for a local config file in: \" + fallbackConfigPath);\n config = JSON.parse(fs.readFileSync(fallbackConfigPath).toString());\n }\n if (!config) {\n throw new Error(\"Config file could not be loaded.\");\n }\n\n console.log(\"Config file loaded\\n\");\n\n const files = readdir(\"\", rootLocal);\n\n console.log(\"Starting upload of data files from the '\" + rootLocal + \"' folder\\n\");\n\n await customWidgetBlobService.cleanDataDir();\n\n const promises: Promise<void>[] = [];\n files.forEach((file) => {\n const content = fs.readFileSync(rootLocal + file);\n const promise = customWidgetBlobService\n .uploadWidgetDataFile(file, content)\n .then(() => console.log(\"Uploaded file: \" + file));\n promises.push(promise);\n });\n await Promise.all(promises);\n\n console.log(files.length + \" files has been uploaded\\n\");\n\n config.deployedOn = new Date();\n await customWidgetBlobService.uploadConfig(config);\n console.log(\"Uploaded updated config\");\n}\n\nexport default deploy;\n"]}
@@ -0,0 +1,10 @@
1
+ import { type InteractiveBrowserCredentialNodeOptions as IBCNOptions } from "@azure/identity";
2
+ import type { ServiceInformation } from "./types.js";
3
+ /**
4
+ * Function to get storage SAS URL.
5
+ *
6
+ * @returns storage SAS URL
7
+ */
8
+ declare function getStorageSasUrl({ managementApiEndpoint, resourceId, apiVersion, tokenOverride, }: ServiceInformation, interactiveBrowserCredentialOptions?: IBCNOptions): Promise<string>;
9
+ export default getStorageSasUrl;
10
+ //# sourceMappingURL=getStorageSasUrl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getStorageSasUrl.d.ts","sourceRoot":"","sources":["../../../src/node/getStorageSasUrl.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,uCAAuC,IAAI,WAAW,EAC5D,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAarD;;;;GAIG;AACH,iBAAe,gBAAgB,CAC7B,EACE,qBAAqB,EACrB,UAAU,EACV,UAAyB,EACzB,aAAa,GACd,EAAE,kBAAkB,EACrB,mCAAmC,CAAC,EAAE,WAAW,GAChD,OAAO,CAAC,MAAM,CAAC,CAgBjB;AAED,eAAe,gBAAgB,CAAC"}