@azure/api-management-custom-widgets-scaffolder 1.0.0-beta.1 → 1.0.0-beta.2

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/bin/execute.js CHANGED
@@ -54,7 +54,7 @@ const fieldIdToName = {
54
54
  displayName: "Widget display name",
55
55
  technology: "Technology",
56
56
  iconUrl: "iconUrl",
57
- resourceId: "Azure API Management resource ID",
57
+ resourceId: "Azure API Management resource ID (following format: subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.ApiManagement/service/<api-management service-name>)",
58
58
  managementApiEndpoint: "Management API hostname",
59
59
  apiVersion: "Management API version",
60
60
  openUrl: "Developer portal URL",
@@ -95,12 +95,7 @@ const validateDeployConfig = {
95
95
  ? true
96
96
  : "Resource ID needs to be a valid Azure resource ID. For example, subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/contoso-group/providers/Microsoft.ApiManagement/service/contoso-apis.";
97
97
  },
98
- managementApiEndpoint: (input) => {
99
- const required = validateRequired(fieldIdToName.managementApiEndpoint)(input);
100
- if (required !== true)
101
- return required;
102
- return validateUrl(fieldIdToName.managementApiEndpoint)(input);
103
- },
98
+ managementApiEndpoint: (input) => validateRequired(fieldIdToName.managementApiEndpoint)(input),
104
99
  };
105
100
  const validateMiscConfig = {
106
101
  openUrl: (input) => {
@@ -136,9 +131,16 @@ const promptDeployConfig = (partial) => inquirer__default["default"].prompt([
136
131
  },
137
132
  {
138
133
  name: "managementApiEndpoint",
139
- type: "input",
134
+ type: "list",
140
135
  message: fieldIdToName.managementApiEndpoint,
141
- default: "management.azure.com",
136
+ choices: [
137
+ {
138
+ name: "management.azure.com (if you're not sure what to select, use this option)",
139
+ value: "management.azure.com",
140
+ },
141
+ { name: "management.usgovcloudapi.net", value: "management.usgovcloudapi.net" },
142
+ { name: "management.chinacloudapi.cn", value: "management.chinacloudapi.cn" },
143
+ ],
142
144
  transformer: prefixUrlProtocol,
143
145
  validate: validateDeployConfig.managementApiEndpoint,
144
146
  },
@@ -47,6 +47,7 @@ body {
47
47
  padding: 9px 50px;
48
48
  background-color: rgba(254, 213, 60, 1);
49
49
  border-radius: 3px;
50
+ cursor: pointer;
50
51
  }
51
52
  }
52
53
 
@@ -12,16 +12,15 @@
12
12
  "dependencies": {
13
13
  "@azure/api-management-custom-widgets-tools": "^1.0.0-beta.1",
14
14
  "react": "^18.2.0",
15
- "react-dom": "^18.2.0",
16
- "react-helmet-async": "^1.3.0"
15
+ "react-dom": "^18.2.0"
17
16
  },
18
17
  "devDependencies": {
19
- "@types/react": "^18.0.15",
18
+ "@types/react": "^18.0.17",
20
19
  "@types/react-dom": "^18.0.6",
21
- "@vitejs/plugin-react": "^2.0.0",
20
+ "@vitejs/plugin-react": "^2.0.1",
22
21
  "prettier": "^2.7.1",
23
- "sass": "^1.53.0",
22
+ "sass": "^1.54.4",
24
23
  "typescript": "^4.7.4",
25
- "vite": "^3.0.0"
24
+ "vite": "^3.0.7"
26
25
  }
27
26
  }
@@ -14,7 +14,7 @@ const App = () => {
14
14
  return
15
15
  }
16
16
 
17
- request(`/subscriptions/000/resourceGroups/000/providers/Microsoft.ApiManagement/service/000/users/${userId}`)
17
+ request(`/users/${userId}`)
18
18
  .then(e => e.json())
19
19
  .then(({properties}) => setDefaultEmail(properties.email))
20
20
  .catch(e => {
@@ -1,5 +1,5 @@
1
1
  import {defineConfig} from "vite"
2
- import react from '@vitejs/plugin-react'
2
+ import react from "@vitejs/plugin-react"
3
3
 
4
4
  // https://vitejs.dev/config/
5
5
  export default defineConfig(() => ({
@@ -13,9 +13,9 @@
13
13
  "@azure/api-management-custom-widgets-tools": "^1.0.0-beta.1"
14
14
  },
15
15
  "devDependencies": {
16
- "prettier": "^2.5.1",
17
- "sass": "^1.53.0",
18
- "typescript": "^4.5.4",
19
- "vite": "^2.8.3"
16
+ "prettier": "^2.7.1",
17
+ "sass": "^1.54.4",
18
+ "typescript": "^4.7.4",
19
+ "vite": "^3.0.7"
20
20
  }
21
21
  }
@@ -14,7 +14,7 @@
14
14
  const appInstance = new App(secrets)
15
15
  if (!secrets.userId) return
16
16
 
17
- appInstance.request(`/subscriptions/000/resourceGroups/000/providers/Microsoft.ApiManagement/service/000/users/${secrets.userId}`)
17
+ appInstance.request(`/users/${secrets.userId}`)
18
18
  .then(e => e.json())
19
19
  .then(({properties}) => {
20
20
  if (properties.email) document.getElementById("email").value = properties.email
@@ -3,7 +3,7 @@
3
3
  "module": "ESNext",
4
4
  "target": "es6",
5
5
  "useDefineForClassFields": true,
6
- "lib": ["ESNext", "ES6", "DOM.Iterable"],
6
+ "lib": ["ESNext", "ES6", "DOM", "DOM.Iterable"],
7
7
  "moduleResolution": "Node",
8
8
  "strict": true,
9
9
  "sourceMap": true,
@@ -14,10 +14,10 @@
14
14
  "vue": "^3.2.37"
15
15
  },
16
16
  "devDependencies": {
17
- "@vitejs/plugin-vue": "^3.0.1",
17
+ "@vitejs/plugin-vue": "^3.0.3",
18
18
  "prettier": "^2.7.1",
19
- "sass": "^1.53.0",
19
+ "sass": "^1.54.4",
20
20
  "typescript": "^4.7.4",
21
- "vite": "^3.0.3"
21
+ "vite": "^3.0.7"
22
22
  }
23
23
  }
@@ -50,7 +50,7 @@ export default {
50
50
  return
51
51
  }
52
52
 
53
- request(`/subscriptions/000/resourceGroups/000/providers/Microsoft.ApiManagement/service/000/users/${secrets.userId}`)
53
+ request(`/users/${secrets.userId}`)
54
54
  .then(e => e.json())
55
55
  .then(({properties}) => this.defaultEmail = properties.email)
56
56
  .catch(e => {
@@ -6,7 +6,7 @@ export const fieldIdToName = {
6
6
  displayName: "Widget display name",
7
7
  technology: "Technology",
8
8
  iconUrl: "iconUrl",
9
- resourceId: "Azure API Management resource ID",
9
+ resourceId: "Azure API Management resource ID (following format: subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.ApiManagement/service/<api-management service-name>)",
10
10
  managementApiEndpoint: "Management API hostname",
11
11
  apiVersion: "Management API version",
12
12
  openUrl: "Developer portal URL",
@@ -47,12 +47,7 @@ export const validateDeployConfig = {
47
47
  ? true
48
48
  : "Resource ID needs to be a valid Azure resource ID. For example, subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/contoso-group/providers/Microsoft.ApiManagement/service/contoso-apis.";
49
49
  },
50
- managementApiEndpoint: (input) => {
51
- const required = validateRequired(fieldIdToName.managementApiEndpoint)(input);
52
- if (required !== true)
53
- return required;
54
- return validateUrl(fieldIdToName.managementApiEndpoint)(input);
55
- },
50
+ managementApiEndpoint: (input) => validateRequired(fieldIdToName.managementApiEndpoint)(input),
56
51
  };
57
52
  export const validateMiscConfig = {
58
53
  openUrl: (input) => {
@@ -88,9 +83,16 @@ export const promptDeployConfig = (partial) => inquirer.prompt([
88
83
  },
89
84
  {
90
85
  name: "managementApiEndpoint",
91
- type: "input",
86
+ type: "list",
92
87
  message: fieldIdToName.managementApiEndpoint,
93
- default: "management.azure.com",
88
+ choices: [
89
+ {
90
+ name: "management.azure.com (if you're not sure what to select, use this option)",
91
+ value: "management.azure.com",
92
+ },
93
+ { name: "management.usgovcloudapi.net", value: "management.usgovcloudapi.net" },
94
+ { name: "management.chinacloudapi.cn", value: "management.chinacloudapi.cn" },
95
+ ],
94
96
  transformer: prefixUrlProtocol,
95
97
  validate: validateDeployConfig.managementApiEndpoint,
96
98
  },
@@ -1 +1 @@
1
- {"version":3,"file":"execute-configs.js","sourceRoot":"","sources":["../../../src/bin/execute-configs.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAsC,YAAY,EAAgB,MAAM,gBAAgB,CAAC;AAEhG,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,MAAM,CAAC,MAAM,aAAa,GAGtB;IACF,WAAW,EAAE,qBAAqB;IAClC,UAAU,EAAE,YAAY;IACxB,OAAO,EAAE,SAAS;IAElB,UAAU,EAAE,kCAAkC;IAC9C,qBAAqB,EAAE,yBAAyB;IAChD,UAAU,EAAE,wB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AAI,EAAE,MAAM;QACZ,OAAO,EAAE,aAAa,CAAC,UAAU;QACjC,OAAO,EAAE;YACP,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE;YACjC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE;YAC7B,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE;SAC5C;KACF;CACF,EACD,OAAO,CACR,CAAC;AAEJ,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAkC,EAA6B,EAAE,CAClG,QAAQ,CAAC,MAAM,CACb;IACE;QACE,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,aAAa,CAAC,UAAU;QACjC,QAAQ,EAAE,oBAAoB,CAAC,UAAU;KAC1C;IACD;QACE,IAAI,EAAE,uBAAuB;QAC7B,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,aAAa,CAAC,qBAAqB;QAC5C,OAAO,EAAE,sBAAsB;QAC/B,WAAW,EAAE,iBAAiB;QAC9B,QAAQ,EAAE,oBAAoB,CAAC,qBAAqB;KACrD;IACD;QACE,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,aAAa,CAAC,UAAU,GAAG,+BAA+B;KACpE;CACF,EACD,OAAO,CACR,CAAC;AAEJ,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAyB,EAAoB,EAAE,CAC9E,QAAQ,CAAC,MAAM,CACb;IACE;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,OAAO;QACb,OAAO,EACL,aAAa,CAAC,OAAO;YACrB,yHAAyH;QAC3H,WAAW,EAAE,iBAAiB;QAC9B,QAAQ,EAAE,kBAAkB,CAAC,OAAO;KACrC;CACF,EACD,OAAO,CACR,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Configs, DeploymentConfig, Options, TECHNOLOGIES, WidgetConfig } from \"../scaffolding\";\n\nimport inquirer from \"inquirer\";\n\nexport const fieldIdToName: Record<\n keyof (WidgetConfig & DeploymentConfig & Options) | string,\n string\n> = {\n displayName: \"Widget display name\",\n technology: \"Technology\",\n iconUrl: \"iconUrl\",\n\n resourceId: \"Azure API Management resource ID\",\n managementApiEndpoint: \"Management API hostname\",\n apiVersion: \"Management API version\",\n\n openUrl: \"Developer portal URL\",\n};\n\nexport const prefixUrlProtocol = (value: string): string =>\n /https?:\\/\\//.test(value) ? value : `https://${value}`;\n\nconst validateRequired =\n (name: string, msg: string = `The “${name}” parameter is required.`) =>\n (input: unknown) =>\n (input != null && input !== \"\") || msg;\n\nconst validateUrl =\n (\n name: string,\n msg = (input: string) =>\n `Provided “${name}” parameter value (“${prefixUrlProtocol(\n input\n )}”) isn’t a valid URL. Use the correct URL format, e.g., https://contoso.com.`\n ) =>\n (input: string) => {\n try {\n new URL(prefixUrlProtocol(input));\n return true;\n } catch (e) {\n return msg(prefixUrlProtocol(input));\n }\n };\n\nexport type ReplaceTypesPreserveOptional<T extends Record<any, any>, V> = {\n [Key in keyof T]: T[Key] extends undefined ? V | undefined : V;\n};\n\nexport type ValidateFnc = (input: string) => boolean | string;\nexport type Validate<C extends Configs> = ReplaceTypesPreserveOptional<C, ValidateFnc>;\n\nexport const validateWidgetConfig: Validate<WidgetConfig> = {\n displayName: validateRequired(fieldIdToName.displayName),\n technology: (input) => {\n const required = validateRequired(fieldIdToName.technology)(input);\n if (required !== true) return required;\n\n if (TECHNOLOGIES.includes(input as any)) {\n return true;\n } else {\n return (\n \"Provided “technology” parameter value isn’t correct. Use one of the following: \" +\n TECHNOLOGIES.join(\", \")\n );\n }\n },\n};\n\nexport const validateDeployConfig: Validate<DeploymentConfig> = {\n resourceId: (input) => {\n const required = validateRequired(fieldIdToName.resourceId)(input);\n if (required !== true) return required;\n\n const regex =\n /^\\/?subscriptions\\/[^/]+\\/resourceGroups\\/[^/]+\\/providers\\/Microsoft\\.ApiManagement\\/service\\/[^/]+\\/?$/;\n return input === \"test\" || regex.test(input)\n ? true\n : \"Resource ID needs to be a valid Azure resource ID. For example, subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/contoso-group/providers/Microsoft.ApiManagement/service/contoso-apis.\";\n },\n managementApiEndpoint: (input) => {\n const required = validateRequired(fieldIdToName.managementApiEndpoint)(input);\n if (required !== true) return required;\n\n return validateUrl(fieldIdToName.managementApiEndpoint)(input);\n },\n};\n\nexport const validateMiscConfig: Validate<Options> = {\n openUrl: (input) => {\n if (!input) return true;\n return validateUrl(fieldIdToName.openUrl)(input);\n },\n};\n\nexport const promptWidgetConfig = (partial: Partial<WidgetConfig>): Promise<WidgetConfig> =>\n inquirer.prompt(\n [\n {\n name: \"displayName\",\n type: \"input\",\n message: fieldIdToName.displayName,\n validate: validateWidgetConfig.displayName,\n },\n {\n name: \"technology\",\n type: \"list\",\n message: fieldIdToName.technology,\n choices: [\n { name: \"React\", value: \"react\" },\n { name: \"Vue\", value: \"vue\" },\n { name: \"TypeScript\", value: \"typescript\" },\n ],\n },\n ],\n partial\n );\n\nexport const promptDeployConfig = (partial: Partial<DeploymentConfig>): Promise<DeploymentConfig> =>\n inquirer.prompt(\n [\n {\n name: \"resourceId\",\n type: \"input\",\n message: fieldIdToName.resourceId,\n validate: validateDeployConfig.resourceId,\n },\n {\n name: \"managementApiEndpoint\",\n type: \"input\",\n message: fieldIdToName.managementApiEndpoint, // (e.g., management.azure.com for the public Azure cloud)\n default: \"management.azure.com\",\n transformer: prefixUrlProtocol,\n validate: validateDeployConfig.managementApiEndpoint,\n },\n {\n name: \"apiVersion\",\n type: \"input\",\n message: fieldIdToName.apiVersion + \" (optional; e.g., 2021-08-01)\",\n },\n ],\n partial\n );\n\nexport const promptMiscConfig = (partial: Partial<Options>): Promise<Options> =>\n inquirer.prompt(\n [\n {\n name: \"openUrl\",\n type: \"input\",\n message:\n fieldIdToName.openUrl +\n \" for widget development and testing (optional; e.g., https://contoso.developer.azure-api.net/ or http://localhost:8080)\",\n transformer: prefixUrlProtocol,\n validate: validateMiscConfig.openUrl,\n },\n ],\n partial\n );\n"]}
1
+ {"version":3,"file":"execute-configs.js","sourceRoot":"","sources":["../../../src/bin/execute-configs.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAsC,YAAY,EAAgB,MAAM,gBAAgB,CAAC;AAEhG,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,MAAM,CAAC,MAAM,aAAa,GAGtB;IACF,WAAW,EAAE,qBAAqB;IAClC,UAAU,EAAE,YAAY;IACxB,OAAO,EAAE,SAAS;IAElB,UAAU,EACR,mMAAmM;IACrM,qBAAqB,EAAE,yBAAyB;IAChD,UAAU,EAAE,wBAAwB;IAEpC,OAAO,EAAE,sBAAsB;CAChC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAa,EAAU,EAAE,CACzD,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,KAAK,EAAE,CAAC;AAEzD,MAAM,gBAAgB,GACpB,CAAC,IAAY,EAAE,MAAc,QAAQ,IAAI,0BAA0B,EAAE,EAAE,CACvE,CAAC,KAAc,EAAE,EAAE,CACjB,CAAC,KAAK,IAAI,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC,IAAI,GAAG,CAAC;AAE3C,MAAM,WAAW,GACf,CACE,IAAY,EACZ,MAAM,CAAC,KAAa,EAAE,EAAE,CACtB,aAAa,IAAI,uBAAuB,iBAAiB,CACvD,KAAK,CACN,8EAA8E,EACjF,EAAE,CACJ,CAAC,KAAa,EAAE,EAAE;IAChB,IAAI;QACF,IAAI,GAAG,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;QAClC,OAAO,IAAI,CAAC;KACb;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,GAAG,CAAC,iBAAiB,CAAC,KAAK,CAAC,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AE,YAAY;QAClB,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,aAAa,CAAC,UAAU,GAAG,+BAA+B;KACpE;CACF,EACD,OAAO,CACR,CAAC;AAEJ,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAyB,EAAoB,EAAE,CAC9E,QAAQ,CAAC,MAAM,CACb;IACE;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,OAAO;QACb,OAAO,EACL,aAAa,CAAC,OAAO;YACrB,yHAAyH;QAC3H,WAAW,EAAE,iBAAiB;QAC9B,QAAQ,EAAE,kBAAkB,CAAC,OAAO;KACrC;CACF,EACD,OAAO,CACR,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Configs, DeploymentConfig, Options, TECHNOLOGIES, WidgetConfig } from \"../scaffolding\";\n\nimport inquirer from \"inquirer\";\n\nexport const fieldIdToName: Record<\n keyof (WidgetConfig & DeploymentConfig & Options) | string,\n string\n> = {\n displayName: \"Widget display name\",\n technology: \"Technology\",\n iconUrl: \"iconUrl\",\n\n resourceId:\n \"Azure API Management resource ID (following format: subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.ApiManagement/service/<api-management service-name>)\",\n managementApiEndpoint: \"Management API hostname\",\n apiVersion: \"Management API version\",\n\n openUrl: \"Developer portal URL\",\n};\n\nexport const prefixUrlProtocol = (value: string): string =>\n /https?:\\/\\//.test(value) ? value : `https://${value}`;\n\nconst validateRequired =\n (name: string, msg: string = `The “${name}” parameter is required.`) =>\n (input: unknown) =>\n (input != null && input !== \"\") || msg;\n\nconst validateUrl =\n (\n name: string,\n msg = (input: string) =>\n `Provided “${name}” parameter value (“${prefixUrlProtocol(\n input\n )}”) isn’t a valid URL. Use the correct URL format, e.g., https://contoso.com.`\n ) =>\n (input: string) => {\n try {\n new URL(prefixUrlProtocol(input));\n return true;\n } catch (e) {\n return msg(prefixUrlProtocol(input));\n }\n };\n\nexport type ReplaceTypesPreserveOptional<T extends Record<any, any>, V> = {\n [Key in keyof T]: T[Key] extends undefined ? V | undefined : V;\n};\n\nexport type ValidateFnc = (input: string) => boolean | string;\nexport type Validate<C extends Configs> = ReplaceTypesPreserveOptional<C, ValidateFnc>;\n\nexport const validateWidgetConfig: Validate<WidgetConfig> = {\n displayName: validateRequired(fieldIdToName.displayName),\n technology: (input) => {\n const required = validateRequired(fieldIdToName.technology)(input);\n if (required !== true) return required;\n\n if (TECHNOLOGIES.includes(input as any)) {\n return true;\n } else {\n return (\n \"Provided “technology” parameter value isn’t correct. Use one of the following: \" +\n TECHNOLOGIES.join(\", \")\n );\n }\n },\n};\n\nexport const validateDeployConfig: Validate<DeploymentConfig> = {\n resourceId: (input) => {\n const required = validateRequired(fieldIdToName.resourceId)(input);\n if (required !== true) return required;\n\n const regex =\n /^\\/?subscriptions\\/[^/]+\\/resourceGroups\\/[^/]+\\/providers\\/Microsoft\\.ApiManagement\\/service\\/[^/]+\\/?$/;\n return input === \"test\" || regex.test(input)\n ? true\n : \"Resource ID needs to be a valid Azure resource ID. For example, subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/contoso-group/providers/Microsoft.ApiManagement/service/contoso-apis.\";\n },\n managementApiEndpoint: (input) => validateRequired(fieldIdToName.managementApiEndpoint)(input),\n};\n\nexport const validateMiscConfig: Validate<Options> = {\n openUrl: (input) => {\n if (!input) return true;\n return validateUrl(fieldIdToName.openUrl)(input);\n },\n};\n\nexport const promptWidgetConfig = (partial: Partial<WidgetConfig>): Promise<WidgetConfig> =>\n inquirer.prompt(\n [\n {\n name: \"displayName\",\n type: \"input\",\n message: fieldIdToName.displayName,\n validate: validateWidgetConfig.displayName,\n },\n {\n name: \"technology\",\n type: \"list\",\n message: fieldIdToName.technology,\n choices: [\n { name: \"React\", value: \"react\" },\n { name: \"Vue\", value: \"vue\" },\n { name: \"TypeScript\", value: \"typescript\" },\n ],\n },\n ],\n partial\n );\n\nexport const promptDeployConfig = (partial: Partial<DeploymentConfig>): Promise<DeploymentConfig> =>\n inquirer.prompt(\n [\n {\n name: \"resourceId\",\n type: \"input\",\n message: fieldIdToName.resourceId,\n validate: validateDeployConfig.resourceId,\n },\n {\n name: \"managementApiEndpoint\",\n type: \"list\",\n message: fieldIdToName.managementApiEndpoint,\n choices: [\n {\n name: \"management.azure.com (if you're not sure what to select, use this option)\",\n value: \"management.azure.com\",\n },\n { name: \"management.usgovcloudapi.net\", value: \"management.usgovcloudapi.net\" },\n { name: \"management.chinacloudapi.cn\", value: \"management.chinacloudapi.cn\" },\n ],\n transformer: prefixUrlProtocol,\n validate: validateDeployConfig.managementApiEndpoint,\n },\n {\n name: \"apiVersion\",\n type: \"input\",\n message: fieldIdToName.apiVersion + \" (optional; e.g., 2021-08-01)\",\n },\n ],\n partial\n );\n\nexport const promptMiscConfig = (partial: Partial<Options>): Promise<Options> =>\n inquirer.prompt(\n [\n {\n name: \"openUrl\",\n type: \"input\",\n message:\n fieldIdToName.openUrl +\n \" for widget development and testing (optional; e.g., https://contoso.developer.azure-api.net/ or http://localhost:8080)\",\n transformer: prefixUrlProtocol,\n validate: validateMiscConfig.openUrl,\n },\n ],\n partial\n );\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure/api-management-custom-widgets-scaffolder",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.2",
4
4
  "author": "Microsoft Corporation",
5
5
  "license": "MIT",
6
6
  "sdk-type": "client",