@azure/ai-form-recognizer 5.0.0-alpha.20250311.1 → 5.0.0-alpha.20250331.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -638,7 +638,7 @@ If you'd like to contribute to this library, please read the [contributing guide
638
638
  [register_aad_app]: https://learn.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal
639
639
  [defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential
640
640
  [fr-build-model]: https://aka.ms/azsdk/formrecognizer/buildmodel
641
- [build_sample]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/formrecognizer/ai-form-recognizer/samples/v4-beta/typescript/src/buildModel.ts
641
+ [build_sample]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/formrecognizer/ai-form-recognizer/samples/v5/typescript/src/buildModel.ts
642
642
  [multi_and_single_service]: https://learn.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account?tabs=multiservice%2Cwindows
643
643
  [azure_portal_create_fr_resource]: https://ms.portal.azure.com/#create/Microsoft.CognitiveServicesFormRecognizer
644
644
  [azure_cli_create_fr_resource]: https://learn.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account-cli?tabs=windows
@@ -646,7 +646,7 @@ If you'd like to contribute to this library, please read the [contributing guide
646
646
  [fr-studio]: https://formrecognizer.appliedai.azure.com/studio
647
647
  [fr-build-training-set]: https://aka.ms/azsdk/formrecognizer/buildtrainingset
648
648
  [fr-models]: https://aka.ms/azsdk/formrecognizer/models
649
- [sample-build-classifier]: https://github.com/azure/azure-sdk-for-js/blob/main/sdk/formrecognizer/ai-form-recognizer/samples/v4-beta/typescript/src/buildClassifier.ts
649
+ [sample-build-classifier]: https://github.com/azure/azure-sdk-for-js/blob/main/sdk/formrecognizer/ai-form-recognizer/samples/v5/typescript/src/buildClassifier.ts
650
650
  [samples-prebuilt]: https://github.com/azure/azure-sdk-for-js/tree/main/sdk/formrecognizer/ai-form-recognizer/samples-dev/prebuilt/
651
651
  [samples-prebuilt-businesscard]: https://github.com/azure/azure-sdk-for-js/blob/main/sdk/formrecognizer/ai-form-recognizer/samples-dev/prebuilt/prebuilt-businessCard.ts
652
652
  [samples-prebuilt-document]: https://github.com/azure/azure-sdk-for-js/blob/main/sdk/formrecognizer/ai-form-recognizer/samples-dev/prebuilt/prebuilt-document.ts
@@ -1,7 +1,7 @@
1
1
  #!/bin/env node
2
2
  // Copyright (c) Microsoft Corporation.
3
3
  // Licensed under the MIT License.
4
- import { AzureKeyCredential } from "@azure/core-auth";
4
+ // This file is ignored by the linter because it is impossible to move the copyright header above the shebang line.
5
5
  import { DefaultAzureCredential } from "@azure/identity";
6
6
  import { writeFile } from "node:fs/promises";
7
7
  import { DocumentModelAdministrationClient } from "../documentModelAdministrationClient.js";
@@ -23,32 +23,18 @@ Options:
23
23
  -o, --output\tdetermines where to output the model
24
24
 
25
25
  --endpoint <endpoint>\tthe Form Recognizer resource's endpoint
26
- --api-key <api-key> \tthe Form Recognizer resource's API key
27
26
 
28
27
  Default values:
29
28
 
30
- If the \`--endpoint\` or \`--api-key\` options are not provided, then the values
31
- of the \`FORM_RECOGNIZER_ENDPOINT\` and \`FORM_RECOGNIZER_API_KEY\` environment
32
- variables will be used as defaults, respectively.
29
+ If the \`--endpoint\` option is not provided, then the value
30
+ of the \`FORM_RECOGNIZER_ENDPOINT\` environment
31
+ variable will be used as default.
33
32
 
34
33
  Authentication:
35
34
 
36
- If an API key is available (via. the \`--api-key\` option or \`FORM_RECOGNIZER_API_KEY\`
37
- environment variable), then it will be used to authenticate requests to the Form
38
- Recognizer service.
39
-
40
- Otherwise, if the \`@azure/identity\` package is installed, the \`DefaultAzureCredential\`
35
+ If the \`@azure/identity\` package is installed, the \`DefaultAzureCredential\`
41
36
  from that package will be used.
42
-
43
- One of these methods must be available to authenticate with the service.`);
44
- }
45
- function tryAad() {
46
- try {
47
- return new DefaultAzureCredential();
48
- }
49
- catch (_a) {
50
- throw new Error();
51
- }
37
+ `);
52
38
  }
53
39
  /**
54
40
  * @internal
@@ -58,7 +44,6 @@ async function main() {
58
44
  const args = process.argv.slice(2);
59
45
  let modelId = undefined;
60
46
  let endpoint = process.env.FORM_RECOGNIZER_ENDPOINT;
61
- let apiKey = process.env.FORM_RECOGNIZER_API_KEY;
62
47
  let output = undefined;
63
48
  let test = false;
64
49
  console.error("gen-model - create strong TypeScript types for models");
@@ -72,9 +57,6 @@ async function main() {
72
57
  case "--endpoint":
73
58
  endpoint = args[(idx += 1)];
74
59
  break;
75
- case "--api-key":
76
- apiKey = args[(idx += 1)];
77
- break;
78
60
  case "-o":
79
61
  case "--output":
80
62
  output = args[(idx += 1)];
@@ -97,26 +79,7 @@ async function main() {
97
79
  if (!endpoint) {
98
80
  throw new Error("no endpoint provided");
99
81
  }
100
- // We try API key-based authentication first, then AAD. If neither works, then we throw an error.
101
- let credential;
102
- if (apiKey) {
103
- console.error("Using API key authentication.");
104
- credential = new AzureKeyCredential(apiKey);
105
- }
106
- else {
107
- try {
108
- credential = tryAad();
109
- console.error("Using Azure Active Directory authentication (DefaultAzureCredential).");
110
- }
111
- catch (_a) {
112
- throw new Error([
113
- "no authentication method is available;",
114
- "provide an API key or install and configure the `@azure/identity` package",
115
- "(`npm i --save-dev @azure/identity`)",
116
- ].join(" "));
117
- }
118
- }
119
- const client = new DocumentModelAdministrationClient(endpoint, credential);
82
+ const client = new DocumentModelAdministrationClient(endpoint, new DefaultAzureCredential());
120
83
  const modelInfo = await client.getDocumentModel(modelId);
121
84
  console.error("Generating model code for:", modelInfo.modelId);
122
85
  const file = await writeModelCode(modelInfo, test);
@@ -1 +1 @@
1
- {"version":3,"file":"gen-model.js","sourceRoot":"","sources":["../../../src/bin/gen-model.ts"],"names":[],"mappings":";AAEA,uCAAuC;AACvC,kCAAkC;AAKlC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAA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E,CAAC,CAAC;QACzF,CAAC;QAAC,WAAM,CAAC;YACP,MAAM,IAAI,KAAK,CACb;gBACE,wCAAwC;gBACxC,2EAA2E;gBAC3E,sCAAsC;aACvC,CAAC,IAAI,CAAC,GAAG,CAAC,CACZ,CAAC;QACJ,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,iCAAiC,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAE3E,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAEzD,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAE/D,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAEnD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,MAAM,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IAEhF,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,mFAAmF;QACnF,MAAM,IAAI,GAAG,MAAM,CAAC;QAEpB,MAAM,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,OAAO,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAC7D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC","sourcesContent":["#!/bin/env node\n\n// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n// This file is ignored by the linter because it is impossible to move the copyright header above the shebang line.\n\nimport type { KeyCredential, TokenCredential } from \"@azure/core-auth\";\nimport { AzureKeyCredential } from \"@azure/core-auth\";\nimport { DefaultAzureCredential } from \"@azure/identity\";\nimport { writeFile } from \"node:fs/promises\";\nimport { DocumentModelAdministrationClient } from \"../documentModelAdministrationClient.js\";\nimport { writeModelCode } from \"./writeModelCode.js\";\nimport { format } from \"prettier\";\n\n/**\n * @internal\n * Prints a help message for the gen-model command.\n */\nfunction printHelp(): void {\n console.error(`\nUsage:\n gen-model [options] <model-id>\n \nCreate a strongly-typed DocumentModel for the Azure Document Intelligence SDK for JavaScript.\n\nOptions:\n -h, --help \\tshow this help message\n -o, --output\\tdetermines where to output the model\n\n --endpoint <endpoint>\\tthe Form Recognizer resource's endpoint\n --api-key <api-key> \\tthe Form Recognizer resource's API key\n\nDefault values:\n\nIf the \\`--endpoint\\` or \\`--api-key\\` options are not provided, then the values\nof the \\`FORM_RECOGNIZER_ENDPOINT\\` and \\`FORM_RECOGNIZER_API_KEY\\` environment\nvariables will be used as defaults, respectively.\n\nAuthentication:\n\nIf an API key is available (via. the \\`--api-key\\` option or \\`FORM_RECOGNIZER_API_KEY\\`\nenvironment variable), then it will be used to authenticate requests to the Form\nRecognizer service.\n\nOtherwise, if the \\`@azure/identity\\` package is installed, the \\`DefaultAzureCredential\\`\nfrom that package will be used.\n\nOne of these methods must be available to authenticate with the service.`);\n}\n\nfunction tryAad(): DefaultAzureCredential {\n try {\n return new DefaultAzureCredential();\n } catch {\n throw new Error();\n }\n}\n\n/**\n * @internal\n * The main function of the gen-model command.\n */\nasync function main(): Promise<void> {\n const args = process.argv.slice(2);\n\n let modelId: string | undefined = undefined;\n let endpoint = process.env.FORM_RECOGNIZER_ENDPOINT;\n let apiKey = process.env.FORM_RECOGNIZER_API_KEY;\n let output: string | undefined = undefined;\n let test: boolean = false;\n\n console.error(\"gen-model - create strong TypeScript types for models\");\n\n if (args.some((arg) => arg === \"--help\" || arg === \"-h\")) {\n printHelp();\n return;\n }\n\n let idx = 0;\n while (idx < args.length) {\n switch (args[idx]) {\n case \"--endpoint\":\n endpoint = args[(idx += 1)];\n break;\n case \"--api-key\":\n apiKey = args[(idx += 1)];\n break;\n case \"-o\":\n case \"--output\":\n output = args[(idx += 1)];\n break;\n case \"--test\":\n test = true;\n break;\n default:\n modelId = args[idx];\n break;\n }\n idx += 1;\n }\n\n if (idx + 1 <= args.length) {\n console.error(\"warning: unused arguments:\", args.slice(idx + 1).join(\" \"));\n }\n\n if (!modelId) {\n throw new Error(\"no model ID provided\");\n }\n\n if (!endpoint) {\n throw new Error(\"no endpoint provided\");\n }\n\n // We try API key-based authentication first, then AAD. If neither works, then we throw an error.\n let credential: KeyCredential | TokenCredential;\n\n if (apiKey) {\n console.error(\"Using API key authentication.\");\n credential = new AzureKeyCredential(apiKey);\n } else {\n try {\n credential = tryAad();\n console.error(\"Using Azure Active Directory authentication (DefaultAzureCredential).\");\n } catch {\n throw new Error(\n [\n \"no authentication method is available;\",\n \"provide an API key or install and configure the `@azure/identity` package\",\n \"(`npm i --save-dev @azure/identity`)\",\n ].join(\" \"),\n );\n }\n }\n\n const client = new DocumentModelAdministrationClient(endpoint, credential);\n\n const modelInfo = await client.getDocumentModel(modelId);\n\n console.error(\"Generating model code for:\", modelInfo.modelId);\n\n const file = await writeModelCode(modelInfo, test);\n\n const data = Buffer.from(await format(file, { parser: \"typescript\" }), \"utf-8\");\n\n if (output !== undefined) {\n // output is only refined in this context, so assigning it to \"path\" preserves that\n const path = output;\n\n await writeFile(path, data);\n } else {\n process.stdout.write(data);\n }\n}\n\nmain().catch((e) => {\n console.error(e);\n console.error(\"see `gen-model --help` for more information\");\n process.exit(1);\n});\n"]}
1
+ {"version":3,"file":"gen-model.js","sourceRoot":"","sources":["../../../src/bin/gen-model.ts"],"names":[],"mappings":";AAEA,uCAAuC;AACvC,kCAAkC;AAElC,mHAAmH;AAEnH,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MA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AC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,OAAO,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAC7D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC","sourcesContent":["#!/bin/env node\n\n// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n// This file is ignored by the linter because it is impossible to move the copyright header above the shebang line.\n\nimport { DefaultAzureCredential } from \"@azure/identity\";\nimport { writeFile } from \"node:fs/promises\";\nimport { DocumentModelAdministrationClient } from \"../documentModelAdministrationClient.js\";\nimport { writeModelCode } from \"./writeModelCode.js\";\nimport { format } from \"prettier\";\n\n/**\n * @internal\n * Prints a help message for the gen-model command.\n */\nfunction printHelp(): void {\n console.error(`\nUsage:\n gen-model [options] <model-id>\n \nCreate a strongly-typed DocumentModel for the Azure Document Intelligence SDK for JavaScript.\n\nOptions:\n -h, --help \\tshow this help message\n -o, --output\\tdetermines where to output the model\n\n --endpoint <endpoint>\\tthe Form Recognizer resource's endpoint\n\nDefault values:\n\nIf the \\`--endpoint\\` option is not provided, then the value\nof the \\`FORM_RECOGNIZER_ENDPOINT\\` environment\nvariable will be used as default.\n\nAuthentication:\n\nIf the \\`@azure/identity\\` package is installed, the \\`DefaultAzureCredential\\`\nfrom that package will be used.\n`);\n}\n\n/**\n * @internal\n * The main function of the gen-model command.\n */\nasync function main(): Promise<void> {\n const args = process.argv.slice(2);\n\n let modelId: string | undefined = undefined;\n let endpoint = process.env.FORM_RECOGNIZER_ENDPOINT;\n let output: string | undefined = undefined;\n let test: boolean = false;\n\n console.error(\"gen-model - create strong TypeScript types for models\");\n\n if (args.some((arg) => arg === \"--help\" || arg === \"-h\")) {\n printHelp();\n return;\n }\n\n let idx = 0;\n while (idx < args.length) {\n switch (args[idx]) {\n case \"--endpoint\":\n endpoint = args[(idx += 1)];\n break;\n case \"-o\":\n case \"--output\":\n output = args[(idx += 1)];\n break;\n case \"--test\":\n test = true;\n break;\n default:\n modelId = args[idx];\n break;\n }\n idx += 1;\n }\n\n if (idx + 1 <= args.length) {\n console.error(\"warning: unused arguments:\", args.slice(idx + 1).join(\" \"));\n }\n\n if (!modelId) {\n throw new Error(\"no model ID provided\");\n }\n\n if (!endpoint) {\n throw new Error(\"no endpoint provided\");\n }\n\n const client = new DocumentModelAdministrationClient(endpoint, new DefaultAzureCredential());\n\n const modelInfo = await client.getDocumentModel(modelId);\n\n console.error(\"Generating model code for:\", modelInfo.modelId);\n\n const file = await writeModelCode(modelInfo, test);\n\n const data = Buffer.from(await format(file, { parser: \"typescript\" }), \"utf-8\");\n\n if (output !== undefined) {\n // output is only refined in this context, so assigning it to \"path\" preserves that\n const path = output;\n\n await writeFile(path, data);\n } else {\n process.stdout.write(data);\n }\n}\n\nmain().catch((e) => {\n console.error(e);\n console.error(\"see `gen-model --help` for more information\");\n process.exit(1);\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAKvE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,OAAO,KAAK,OAAO,MAAM,+BAA+B,CAAC;AAEzD,OAAO,EAAE,OAAO,EAAE,CAAC;AAGnB,eAAO,MAAM,UAAU,yCAAmC,CAAC;AAE3D;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,MAAM,cAAc,MAAM,KAAG,YAAY,CAAC,CAAC,CACX,CAAC;AAExE;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,MAAM,cAAc,CAAC,KAAG,UAAU,CAAC,CAA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E,KAAG,EAAE,GAAG,SACpC,CAAC;AAE7C;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,aAAa,GAAG,eAAe,EAC3C,OAAO,EAAE,6BAA6B,GACrC,eAAe,CAiBjB"}
@@ -3,7 +3,7 @@
3
3
  // Copyright (c) Microsoft Corporation.
4
4
  // Licensed under the MIT License.
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const core_auth_1 = require("@azure/core-auth");
6
+ // This file is ignored by the linter because it is impossible to move the copyright header above the shebang line.
7
7
  const identity_1 = require("@azure/identity");
8
8
  const promises_1 = require("node:fs/promises");
9
9
  const documentModelAdministrationClient_js_1 = require("../documentModelAdministrationClient.js");
@@ -25,32 +25,18 @@ Options:
25
25
  -o, --output\tdetermines where to output the model
26
26
 
27
27
  --endpoint <endpoint>\tthe Form Recognizer resource's endpoint
28
- --api-key <api-key> \tthe Form Recognizer resource's API key
29
28
 
30
29
  Default values:
31
30
 
32
- If the \`--endpoint\` or \`--api-key\` options are not provided, then the values
33
- of the \`FORM_RECOGNIZER_ENDPOINT\` and \`FORM_RECOGNIZER_API_KEY\` environment
34
- variables will be used as defaults, respectively.
31
+ If the \`--endpoint\` option is not provided, then the value
32
+ of the \`FORM_RECOGNIZER_ENDPOINT\` environment
33
+ variable will be used as default.
35
34
 
36
35
  Authentication:
37
36
 
38
- If an API key is available (via. the \`--api-key\` option or \`FORM_RECOGNIZER_API_KEY\`
39
- environment variable), then it will be used to authenticate requests to the Form
40
- Recognizer service.
41
-
42
- Otherwise, if the \`@azure/identity\` package is installed, the \`DefaultAzureCredential\`
37
+ If the \`@azure/identity\` package is installed, the \`DefaultAzureCredential\`
43
38
  from that package will be used.
44
-
45
- One of these methods must be available to authenticate with the service.`);
46
- }
47
- function tryAad() {
48
- try {
49
- return new identity_1.DefaultAzureCredential();
50
- }
51
- catch (_a) {
52
- throw new Error();
53
- }
39
+ `);
54
40
  }
55
41
  /**
56
42
  * @internal
@@ -60,7 +46,6 @@ async function main() {
60
46
  const args = process.argv.slice(2);
61
47
  let modelId = undefined;
62
48
  let endpoint = process.env.FORM_RECOGNIZER_ENDPOINT;
63
- let apiKey = process.env.FORM_RECOGNIZER_API_KEY;
64
49
  let output = undefined;
65
50
  let test = false;
66
51
  console.error("gen-model - create strong TypeScript types for models");
@@ -74,9 +59,6 @@ async function main() {
74
59
  case "--endpoint":
75
60
  endpoint = args[(idx += 1)];
76
61
  break;
77
- case "--api-key":
78
- apiKey = args[(idx += 1)];
79
- break;
80
62
  case "-o":
81
63
  case "--output":
82
64
  output = args[(idx += 1)];
@@ -99,26 +81,7 @@ async function main() {
99
81
  if (!endpoint) {
100
82
  throw new Error("no endpoint provided");
101
83
  }
102
- // We try API key-based authentication first, then AAD. If neither works, then we throw an error.
103
- let credential;
104
- if (apiKey) {
105
- console.error("Using API key authentication.");
106
- credential = new core_auth_1.AzureKeyCredential(apiKey);
107
- }
108
- else {
109
- try {
110
- credential = tryAad();
111
- console.error("Using Azure Active Directory authentication (DefaultAzureCredential).");
112
- }
113
- catch (_a) {
114
- throw new Error([
115
- "no authentication method is available;",
116
- "provide an API key or install and configure the `@azure/identity` package",
117
- "(`npm i --save-dev @azure/identity`)",
118
- ].join(" "));
119
- }
120
- }
121
- const client = new documentModelAdministrationClient_js_1.DocumentModelAdministrationClient(endpoint, credential);
84
+ const client = new documentModelAdministrationClient_js_1.DocumentModelAdministrationClient(endpoint, new identity_1.DefaultAzureCredential());
122
85
  const modelInfo = await client.getDocumentModel(modelId);
123
86
  console.error("Generating model code for:", modelInfo.modelId);
124
87
  const file = await (0, writeModelCode_js_1.writeModelCode)(modelInfo, test);
@@ -1 +1 @@
1
- {"version":3,"file":"gen-model.js","sourceRoot":"","sources":["../../../src/bin/gen-model.ts"],"names":[],"mappings":";;AAEA,uCAAuC;AACvC,kCAAkC;;AAKlC,gDAAsD;AACtD,8CAAyD;AACzD,+CAA6C;AAC7C,kGAA4F;AAC5F,2DA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AiC,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAE3E,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAEzD,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAE/D,MAAM,IAAI,GAAG,MAAM,IAAA,kCAAc,EAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAEnD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,IAAA,iBAAM,EAAC,IAAI,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IAEhF,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,mFAAmF;QACnF,MAAM,IAAI,GAAG,MAAM,CAAC;QAEpB,MAAM,IAAA,oBAAS,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,OAAO,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAC7D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC","sourcesContent":["#!/bin/env node\n\n// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n// This file is ignored by the linter because it is impossible to move the copyright header above the shebang line.\n\nimport type { KeyCredential, TokenCredential } from \"@azure/core-auth\";\nimport { AzureKeyCredential } from \"@azure/core-auth\";\nimport { DefaultAzureCredential } from \"@azure/identity\";\nimport { writeFile } from \"node:fs/promises\";\nimport { DocumentModelAdministrationClient } from \"../documentModelAdministrationClient.js\";\nimport { writeModelCode } from \"./writeModelCode.js\";\nimport { format } from \"prettier\";\n\n/**\n * @internal\n * Prints a help message for the gen-model command.\n */\nfunction printHelp(): void {\n console.error(`\nUsage:\n gen-model [options] <model-id>\n \nCreate a strongly-typed DocumentModel for the Azure Document Intelligence SDK for JavaScript.\n\nOptions:\n -h, --help \\tshow this help message\n -o, --output\\tdetermines where to output the model\n\n --endpoint <endpoint>\\tthe Form Recognizer resource's endpoint\n --api-key <api-key> \\tthe Form Recognizer resource's API key\n\nDefault values:\n\nIf the \\`--endpoint\\` or \\`--api-key\\` options are not provided, then the values\nof the \\`FORM_RECOGNIZER_ENDPOINT\\` and \\`FORM_RECOGNIZER_API_KEY\\` environment\nvariables will be used as defaults, respectively.\n\nAuthentication:\n\nIf an API key is available (via. the \\`--api-key\\` option or \\`FORM_RECOGNIZER_API_KEY\\`\nenvironment variable), then it will be used to authenticate requests to the Form\nRecognizer service.\n\nOtherwise, if the \\`@azure/identity\\` package is installed, the \\`DefaultAzureCredential\\`\nfrom that package will be used.\n\nOne of these methods must be available to authenticate with the service.`);\n}\n\nfunction tryAad(): DefaultAzureCredential {\n try {\n return new DefaultAzureCredential();\n } catch {\n throw new Error();\n }\n}\n\n/**\n * @internal\n * The main function of the gen-model command.\n */\nasync function main(): Promise<void> {\n const args = process.argv.slice(2);\n\n let modelId: string | undefined = undefined;\n let endpoint = process.env.FORM_RECOGNIZER_ENDPOINT;\n let apiKey = process.env.FORM_RECOGNIZER_API_KEY;\n let output: string | undefined = undefined;\n let test: boolean = false;\n\n console.error(\"gen-model - create strong TypeScript types for models\");\n\n if (args.some((arg) => arg === \"--help\" || arg === \"-h\")) {\n printHelp();\n return;\n }\n\n let idx = 0;\n while (idx < args.length) {\n switch (args[idx]) {\n case \"--endpoint\":\n endpoint = args[(idx += 1)];\n break;\n case \"--api-key\":\n apiKey = args[(idx += 1)];\n break;\n case \"-o\":\n case \"--output\":\n output = args[(idx += 1)];\n break;\n case \"--test\":\n test = true;\n break;\n default:\n modelId = args[idx];\n break;\n }\n idx += 1;\n }\n\n if (idx + 1 <= args.length) {\n console.error(\"warning: unused arguments:\", args.slice(idx + 1).join(\" \"));\n }\n\n if (!modelId) {\n throw new Error(\"no model ID provided\");\n }\n\n if (!endpoint) {\n throw new Error(\"no endpoint provided\");\n }\n\n // We try API key-based authentication first, then AAD. If neither works, then we throw an error.\n let credential: KeyCredential | TokenCredential;\n\n if (apiKey) {\n console.error(\"Using API key authentication.\");\n credential = new AzureKeyCredential(apiKey);\n } else {\n try {\n credential = tryAad();\n console.error(\"Using Azure Active Directory authentication (DefaultAzureCredential).\");\n } catch {\n throw new Error(\n [\n \"no authentication method is available;\",\n \"provide an API key or install and configure the `@azure/identity` package\",\n \"(`npm i --save-dev @azure/identity`)\",\n ].join(\" \"),\n );\n }\n }\n\n const client = new DocumentModelAdministrationClient(endpoint, credential);\n\n const modelInfo = await client.getDocumentModel(modelId);\n\n console.error(\"Generating model code for:\", modelInfo.modelId);\n\n const file = await writeModelCode(modelInfo, test);\n\n const data = Buffer.from(await format(file, { parser: \"typescript\" }), \"utf-8\");\n\n if (output !== undefined) {\n // output is only refined in this context, so assigning it to \"path\" preserves that\n const path = output;\n\n await writeFile(path, data);\n } else {\n process.stdout.write(data);\n }\n}\n\nmain().catch((e) => {\n console.error(e);\n console.error(\"see `gen-model --help` for more information\");\n process.exit(1);\n});\n"]}
1
+ {"version":3,"file":"gen-model.js","sourceRoot":"","sources":["../../../src/bin/gen-model.ts"],"names":[],"mappings":";;AAEA,uCAAuC;AACvC,kCAAkC;;AAElC,mHAAmH;AAEnH,8CAAyD;AACzD,+CAA6C;AAC7C,kGAA4F;AAC5F,2DAAqD;AACrD,uCAAkC;AAElC;;;GAGG;AACH,SAAS,SAAS;IAChB,OAAO,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;CAsBf,CAAC,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,IAAI;IACjB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CA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AM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,wEAAiC,CAAC,QAAQ,EAAE,IAAI,iCAAsB,EAAE,CAAC,CAAC;IAE7F,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAEzD,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAE/D,MAAM,IAAI,GAAG,MAAM,IAAA,kCAAc,EAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAEnD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,IAAA,iBAAM,EAAC,IAAI,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IAEhF,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,mFAAmF;QACnF,MAAM,IAAI,GAAG,MAAM,CAAC;QAEpB,MAAM,IAAA,oBAAS,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,OAAO,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAC7D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC","sourcesContent":["#!/bin/env node\n\n// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n// This file is ignored by the linter because it is impossible to move the copyright header above the shebang line.\n\nimport { DefaultAzureCredential } from \"@azure/identity\";\nimport { writeFile } from \"node:fs/promises\";\nimport { DocumentModelAdministrationClient } from \"../documentModelAdministrationClient.js\";\nimport { writeModelCode } from \"./writeModelCode.js\";\nimport { format } from \"prettier\";\n\n/**\n * @internal\n * Prints a help message for the gen-model command.\n */\nfunction printHelp(): void {\n console.error(`\nUsage:\n gen-model [options] <model-id>\n \nCreate a strongly-typed DocumentModel for the Azure Document Intelligence SDK for JavaScript.\n\nOptions:\n -h, --help \\tshow this help message\n -o, --output\\tdetermines where to output the model\n\n --endpoint <endpoint>\\tthe Form Recognizer resource's endpoint\n\nDefault values:\n\nIf the \\`--endpoint\\` option is not provided, then the value\nof the \\`FORM_RECOGNIZER_ENDPOINT\\` environment\nvariable will be used as default.\n\nAuthentication:\n\nIf the \\`@azure/identity\\` package is installed, the \\`DefaultAzureCredential\\`\nfrom that package will be used.\n`);\n}\n\n/**\n * @internal\n * The main function of the gen-model command.\n */\nasync function main(): Promise<void> {\n const args = process.argv.slice(2);\n\n let modelId: string | undefined = undefined;\n let endpoint = process.env.FORM_RECOGNIZER_ENDPOINT;\n let output: string | undefined = undefined;\n let test: boolean = false;\n\n console.error(\"gen-model - create strong TypeScript types for models\");\n\n if (args.some((arg) => arg === \"--help\" || arg === \"-h\")) {\n printHelp();\n return;\n }\n\n let idx = 0;\n while (idx < args.length) {\n switch (args[idx]) {\n case \"--endpoint\":\n endpoint = args[(idx += 1)];\n break;\n case \"-o\":\n case \"--output\":\n output = args[(idx += 1)];\n break;\n case \"--test\":\n test = true;\n break;\n default:\n modelId = args[idx];\n break;\n }\n idx += 1;\n }\n\n if (idx + 1 <= args.length) {\n console.error(\"warning: unused arguments:\", args.slice(idx + 1).join(\" \"));\n }\n\n if (!modelId) {\n throw new Error(\"no model ID provided\");\n }\n\n if (!endpoint) {\n throw new Error(\"no endpoint provided\");\n }\n\n const client = new DocumentModelAdministrationClient(endpoint, new DefaultAzureCredential());\n\n const modelInfo = await client.getDocumentModel(modelId);\n\n console.error(\"Generating model code for:\", modelInfo.modelId);\n\n const file = await writeModelCode(modelInfo, test);\n\n const data = Buffer.from(await format(file, { parser: \"typescript\" }), \"utf-8\");\n\n if (output !== undefined) {\n // output is only refined in this context, so assigning it to \"path\" preserves that\n const path = output;\n\n await writeFile(path, data);\n } else {\n process.stdout.write(data);\n }\n}\n\nmain().catch((e) => {\n console.error(e);\n console.error(\"see `gen-model --help` for more information\");\n process.exit(1);\n});\n"]}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.50.1"
8
+ "packageVersion": "7.52.2"
9
9
  }
10
10
  ]
11
11
  }
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAKvE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,OAAO,KAAK,OAAO,MAAM,+BAA+B,CAAC;AAEzD,OAAO,EAAE,OAAO,EAAE,CAAC;AAGnB,eAAO,MAAM,UAAU,yCAAmC,CAAC;AAE3D;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,MAAM,cAAc,MAAM,KAAG,YAAY,CAAC,CAAC,CACX,CAAC;AAExE;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,MAAM,cAAc,CAAC,KAAG,UAAU,CAAC,CAAC,CACJ,CAAC;AAEtE;;;GAGG;AACH,eAAO,MAAM,WAAW,MAAO,MAAM,KAAG,OAEvC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAI,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,SAAS,KAAK,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,KA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env node
2
2
  // Copyright (c) Microsoft Corporation.
3
3
  // Licensed under the MIT License.
4
- import { AzureKeyCredential } from "@azure/core-auth";
4
+ // This file is ignored by the linter because it is impossible to move the copyright header above the shebang line.
5
5
  import { DefaultAzureCredential } from "@azure/identity";
6
6
  import { writeFile } from "node:fs/promises";
7
7
  import { DocumentModelAdministrationClient } from "../documentModelAdministrationClient.js";
@@ -23,32 +23,18 @@ Options:
23
23
  -o, --output\tdetermines where to output the model
24
24
 
25
25
  --endpoint <endpoint>\tthe Form Recognizer resource's endpoint
26
- --api-key <api-key> \tthe Form Recognizer resource's API key
27
26
 
28
27
  Default values:
29
28
 
30
- If the \`--endpoint\` or \`--api-key\` options are not provided, then the values
31
- of the \`FORM_RECOGNIZER_ENDPOINT\` and \`FORM_RECOGNIZER_API_KEY\` environment
32
- variables will be used as defaults, respectively.
29
+ If the \`--endpoint\` option is not provided, then the value
30
+ of the \`FORM_RECOGNIZER_ENDPOINT\` environment
31
+ variable will be used as default.
33
32
 
34
33
  Authentication:
35
34
 
36
- If an API key is available (via. the \`--api-key\` option or \`FORM_RECOGNIZER_API_KEY\`
37
- environment variable), then it will be used to authenticate requests to the Form
38
- Recognizer service.
39
-
40
- Otherwise, if the \`@azure/identity\` package is installed, the \`DefaultAzureCredential\`
35
+ If the \`@azure/identity\` package is installed, the \`DefaultAzureCredential\`
41
36
  from that package will be used.
42
-
43
- One of these methods must be available to authenticate with the service.`);
44
- }
45
- function tryAad() {
46
- try {
47
- return new DefaultAzureCredential();
48
- }
49
- catch (_a) {
50
- throw new Error();
51
- }
37
+ `);
52
38
  }
53
39
  /**
54
40
  * @internal
@@ -58,7 +44,6 @@ async function main() {
58
44
  const args = process.argv.slice(2);
59
45
  let modelId = undefined;
60
46
  let endpoint = process.env.FORM_RECOGNIZER_ENDPOINT;
61
- let apiKey = process.env.FORM_RECOGNIZER_API_KEY;
62
47
  let output = undefined;
63
48
  let test = false;
64
49
  console.error("gen-model - create strong TypeScript types for models");
@@ -72,9 +57,6 @@ async function main() {
72
57
  case "--endpoint":
73
58
  endpoint = args[(idx += 1)];
74
59
  break;
75
- case "--api-key":
76
- apiKey = args[(idx += 1)];
77
- break;
78
60
  case "-o":
79
61
  case "--output":
80
62
  output = args[(idx += 1)];
@@ -97,26 +79,7 @@ async function main() {
97
79
  if (!endpoint) {
98
80
  throw new Error("no endpoint provided");
99
81
  }
100
- // We try API key-based authentication first, then AAD. If neither works, then we throw an error.
101
- let credential;
102
- if (apiKey) {
103
- console.error("Using API key authentication.");
104
- credential = new AzureKeyCredential(apiKey);
105
- }
106
- else {
107
- try {
108
- credential = tryAad();
109
- console.error("Using Azure Active Directory authentication (DefaultAzureCredential).");
110
- }
111
- catch (_a) {
112
- throw new Error([
113
- "no authentication method is available;",
114
- "provide an API key or install and configure the `@azure/identity` package",
115
- "(`npm i --save-dev @azure/identity`)",
116
- ].join(" "));
117
- }
118
- }
119
- const client = new DocumentModelAdministrationClient(endpoint, credential);
82
+ const client = new DocumentModelAdministrationClient(endpoint, new DefaultAzureCredential());
120
83
  const modelInfo = await client.getDocumentModel(modelId);
121
84
  console.error("Generating model code for:", modelInfo.modelId);
122
85
  const file = await writeModelCode(modelInfo, test);
@@ -1 +1 @@
1
- {"version":3,"file":"gen-model.js","sourceRoot":"","sources":["../../../src/bin/gen-model.ts"],"names":[],"mappings":";AAEA,uCAAuC;AACvC,kCAAkC;AAKlC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,iCAAiC,EAAE,MAAM,yCAAyC,CAAC;AAC5F,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;GAGG;AACH,SAAS,SAAS;IAChB,OAAO,CAAC,KAAK,CAAC;;;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C,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAEzD,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAE/D,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAEnD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,MAAM,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IAEhF,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,mFAAmF;QACnF,MAAM,IAAI,GAAG,MAAM,CAAC;QAEpB,MAAM,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,OAAO,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAC7D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC","sourcesContent":["#!/bin/env node\n\n// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n// This file is ignored by the linter because it is impossible to move the copyright header above the shebang line.\n\nimport type { KeyCredential, TokenCredential } from \"@azure/core-auth\";\nimport { AzureKeyCredential } from \"@azure/core-auth\";\nimport { DefaultAzureCredential } from \"@azure/identity\";\nimport { writeFile } from \"node:fs/promises\";\nimport { DocumentModelAdministrationClient } from \"../documentModelAdministrationClient.js\";\nimport { writeModelCode } from \"./writeModelCode.js\";\nimport { format } from \"prettier\";\n\n/**\n * @internal\n * Prints a help message for the gen-model command.\n */\nfunction printHelp(): void {\n console.error(`\nUsage:\n gen-model [options] <model-id>\n \nCreate a strongly-typed DocumentModel for the Azure Document Intelligence SDK for JavaScript.\n\nOptions:\n -h, --help \\tshow this help message\n -o, --output\\tdetermines where to output the model\n\n --endpoint <endpoint>\\tthe Form Recognizer resource's endpoint\n --api-key <api-key> \\tthe Form Recognizer resource's API key\n\nDefault values:\n\nIf the \\`--endpoint\\` or \\`--api-key\\` options are not provided, then the values\nof the \\`FORM_RECOGNIZER_ENDPOINT\\` and \\`FORM_RECOGNIZER_API_KEY\\` environment\nvariables will be used as defaults, respectively.\n\nAuthentication:\n\nIf an API key is available (via. the \\`--api-key\\` option or \\`FORM_RECOGNIZER_API_KEY\\`\nenvironment variable), then it will be used to authenticate requests to the Form\nRecognizer service.\n\nOtherwise, if the \\`@azure/identity\\` package is installed, the \\`DefaultAzureCredential\\`\nfrom that package will be used.\n\nOne of these methods must be available to authenticate with the service.`);\n}\n\nfunction tryAad(): DefaultAzureCredential {\n try {\n return new DefaultAzureCredential();\n } catch {\n throw new Error();\n }\n}\n\n/**\n * @internal\n * The main function of the gen-model command.\n */\nasync function main(): Promise<void> {\n const args = process.argv.slice(2);\n\n let modelId: string | undefined = undefined;\n let endpoint = process.env.FORM_RECOGNIZER_ENDPOINT;\n let apiKey = process.env.FORM_RECOGNIZER_API_KEY;\n let output: string | undefined = undefined;\n let test: boolean = false;\n\n console.error(\"gen-model - create strong TypeScript types for models\");\n\n if (args.some((arg) => arg === \"--help\" || arg === \"-h\")) {\n printHelp();\n return;\n }\n\n let idx = 0;\n while (idx < args.length) {\n switch (args[idx]) {\n case \"--endpoint\":\n endpoint = args[(idx += 1)];\n break;\n case \"--api-key\":\n apiKey = args[(idx += 1)];\n break;\n case \"-o\":\n case \"--output\":\n output = args[(idx += 1)];\n break;\n case \"--test\":\n test = true;\n break;\n default:\n modelId = args[idx];\n break;\n }\n idx += 1;\n }\n\n if (idx + 1 <= args.length) {\n console.error(\"warning: unused arguments:\", args.slice(idx + 1).join(\" \"));\n }\n\n if (!modelId) {\n throw new Error(\"no model ID provided\");\n }\n\n if (!endpoint) {\n throw new Error(\"no endpoint provided\");\n }\n\n // We try API key-based authentication first, then AAD. If neither works, then we throw an error.\n let credential: KeyCredential | TokenCredential;\n\n if (apiKey) {\n console.error(\"Using API key authentication.\");\n credential = new AzureKeyCredential(apiKey);\n } else {\n try {\n credential = tryAad();\n console.error(\"Using Azure Active Directory authentication (DefaultAzureCredential).\");\n } catch {\n throw new Error(\n [\n \"no authentication method is available;\",\n \"provide an API key or install and configure the `@azure/identity` package\",\n \"(`npm i --save-dev @azure/identity`)\",\n ].join(\" \"),\n );\n }\n }\n\n const client = new DocumentModelAdministrationClient(endpoint, credential);\n\n const modelInfo = await client.getDocumentModel(modelId);\n\n console.error(\"Generating model code for:\", modelInfo.modelId);\n\n const file = await writeModelCode(modelInfo, test);\n\n const data = Buffer.from(await format(file, { parser: \"typescript\" }), \"utf-8\");\n\n if (output !== undefined) {\n // output is only refined in this context, so assigning it to \"path\" preserves that\n const path = output;\n\n await writeFile(path, data);\n } else {\n process.stdout.write(data);\n }\n}\n\nmain().catch((e) => {\n console.error(e);\n console.error(\"see `gen-model --help` for more information\");\n process.exit(1);\n});\n"]}
1
+ {"version":3,"file":"gen-model.js","sourceRoot":"","sources":["../../../src/bin/gen-model.ts"],"names":[],"mappings":";AAEA,uCAAuC;AACvC,kCAAkC;AAElC,mHAAmH;AAEnH,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,iCAAiC,EAAE,MAAM,yCAAyC,CAAC;AAC5F,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;GAGG;AACH,SAAS,SAAS;IAChB,OAAO,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;CAsBf,CAAC,CAAC;AACH,CAAC;AAED;;;GAGG;AACH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License.\n\n// This file is ignored by the linter because it is impossible to move the copyright header above the shebang line.\n\nimport { DefaultAzureCredential } from \"@azure/identity\";\nimport { writeFile } from \"node:fs/promises\";\nimport { DocumentModelAdministrationClient } from \"../documentModelAdministrationClient.js\";\nimport { writeModelCode } from \"./writeModelCode.js\";\nimport { format } from \"prettier\";\n\n/**\n * @internal\n * Prints a help message for the gen-model command.\n */\nfunction printHelp(): void {\n console.error(`\nUsage:\n gen-model [options] <model-id>\n \nCreate a strongly-typed DocumentModel for the Azure Document Intelligence SDK for JavaScript.\n\nOptions:\n -h, --help \\tshow this help message\n -o, --output\\tdetermines where to output the model\n\n --endpoint <endpoint>\\tthe Form Recognizer resource's endpoint\n\nDefault values:\n\nIf the \\`--endpoint\\` option is not provided, then the value\nof the \\`FORM_RECOGNIZER_ENDPOINT\\` environment\nvariable will be used as default.\n\nAuthentication:\n\nIf the \\`@azure/identity\\` package is installed, the \\`DefaultAzureCredential\\`\nfrom that package will be used.\n`);\n}\n\n/**\n * @internal\n * The main function of the gen-model command.\n */\nasync function main(): Promise<void> {\n const args = process.argv.slice(2);\n\n let modelId: string | undefined = undefined;\n let endpoint = process.env.FORM_RECOGNIZER_ENDPOINT;\n let output: string | undefined = undefined;\n let test: boolean = false;\n\n console.error(\"gen-model - create strong TypeScript types for models\");\n\n if (args.some((arg) => arg === \"--help\" || arg === \"-h\")) {\n printHelp();\n return;\n }\n\n let idx = 0;\n while (idx < args.length) {\n switch (args[idx]) {\n case \"--endpoint\":\n endpoint = args[(idx += 1)];\n break;\n case \"-o\":\n case \"--output\":\n output = args[(idx += 1)];\n break;\n case \"--test\":\n test = true;\n break;\n default:\n modelId = args[idx];\n break;\n }\n idx += 1;\n }\n\n if (idx + 1 <= args.length) {\n console.error(\"warning: unused arguments:\", args.slice(idx + 1).join(\" \"));\n }\n\n if (!modelId) {\n throw new Error(\"no model ID provided\");\n }\n\n if (!endpoint) {\n throw new Error(\"no endpoint provided\");\n }\n\n const client = new DocumentModelAdministrationClient(endpoint, new DefaultAzureCredential());\n\n const modelInfo = await client.getDocumentModel(modelId);\n\n console.error(\"Generating model code for:\", modelInfo.modelId);\n\n const file = await writeModelCode(modelInfo, test);\n\n const data = Buffer.from(await format(file, { parser: \"typescript\" }), \"utf-8\");\n\n if (output !== undefined) {\n // output is only refined in this context, so assigning it to \"path\" preserves that\n const path = output;\n\n await writeFile(path, data);\n } else {\n process.stdout.write(data);\n }\n}\n\nmain().catch((e) => {\n console.error(e);\n console.error(\"see `gen-model --help` for more information\");\n process.exit(1);\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAKvE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,OAAO,KAAK,OAAO,MAAM,+BAA+B,CAAC;AAEzD,OAAO,EAAE,OAAO,EAAE,CAAC;AAGnB,eAAO,MAAM,UAAU,yCAAmC,CAAC;AAE3D;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,MAAM,cAAc,MAAM,KAAG,YAAY,CAAC,CAAC,CACX,CAAC;AAExE;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,MAAM,cAAc,CAAC,KAAG,UAAU,CAAC,CAAC,CACJ,CAAC;AAEtE;;;GAGG;AACH,eAAO,MAAM,WAAW,MAAO,MAAM,KAAG,OAEvC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAI,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,SAAS,KAAK,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,KAAG,EAAE,GAAG,SACpC,CAAC;AAE7C;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,aAAa,GAAG,eAAe,EAC3C,OAAO,EAAE,6BAA6B,GACrC,eAAe,CAiBjB"}
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAKvE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,OAAO,KAAK,OAAO,MAAM,+BAA+B,CAAC;AAEzD,OAAO,EAAE,OAAO,EAAE,CAAC;AAGnB,eAAO,MAAM,UAAU,yCAAmC,CAAC;AAE3D;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,YAAY,CAAC,CAAC,CACX,CAAC;AAExE;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,KAAG,UAAU,CAAC,CAAC,CACJ,CAAC;AAEtE;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,GAAG,MAAM,KAAG,OAEvC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAI,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,SAAS,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,KAAG,EAAE,GAAG,SACpC,CAAC;AAE7C;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,aAAa,GAAG,eAAe,EAC3C,OAAO,EAAE,6BAA6B,GACrC,eAAe,CAiBjB"}
@@ -1,7 +1,7 @@
1
1
  #!/bin/env node
2
2
  // Copyright (c) Microsoft Corporation.
3
3
  // Licensed under the MIT License.
4
- import { AzureKeyCredential } from "@azure/core-auth";
4
+ // This file is ignored by the linter because it is impossible to move the copyright header above the shebang line.
5
5
  import { DefaultAzureCredential } from "@azure/identity";
6
6
  import { writeFile } from "node:fs/promises";
7
7
  import { DocumentModelAdministrationClient } from "../documentModelAdministrationClient.js";
@@ -23,32 +23,18 @@ Options:
23
23
  -o, --output\tdetermines where to output the model
24
24
 
25
25
  --endpoint <endpoint>\tthe Form Recognizer resource's endpoint
26
- --api-key <api-key> \tthe Form Recognizer resource's API key
27
26
 
28
27
  Default values:
29
28
 
30
- If the \`--endpoint\` or \`--api-key\` options are not provided, then the values
31
- of the \`FORM_RECOGNIZER_ENDPOINT\` and \`FORM_RECOGNIZER_API_KEY\` environment
32
- variables will be used as defaults, respectively.
29
+ If the \`--endpoint\` option is not provided, then the value
30
+ of the \`FORM_RECOGNIZER_ENDPOINT\` environment
31
+ variable will be used as default.
33
32
 
34
33
  Authentication:
35
34
 
36
- If an API key is available (via. the \`--api-key\` option or \`FORM_RECOGNIZER_API_KEY\`
37
- environment variable), then it will be used to authenticate requests to the Form
38
- Recognizer service.
39
-
40
- Otherwise, if the \`@azure/identity\` package is installed, the \`DefaultAzureCredential\`
35
+ If the \`@azure/identity\` package is installed, the \`DefaultAzureCredential\`
41
36
  from that package will be used.
42
-
43
- One of these methods must be available to authenticate with the service.`);
44
- }
45
- function tryAad() {
46
- try {
47
- return new DefaultAzureCredential();
48
- }
49
- catch (_a) {
50
- throw new Error();
51
- }
37
+ `);
52
38
  }
53
39
  /**
54
40
  * @internal
@@ -58,7 +44,6 @@ async function main() {
58
44
  const args = process.argv.slice(2);
59
45
  let modelId = undefined;
60
46
  let endpoint = process.env.FORM_RECOGNIZER_ENDPOINT;
61
- let apiKey = process.env.FORM_RECOGNIZER_API_KEY;
62
47
  let output = undefined;
63
48
  let test = false;
64
49
  console.error("gen-model - create strong TypeScript types for models");
@@ -72,9 +57,6 @@ async function main() {
72
57
  case "--endpoint":
73
58
  endpoint = args[(idx += 1)];
74
59
  break;
75
- case "--api-key":
76
- apiKey = args[(idx += 1)];
77
- break;
78
60
  case "-o":
79
61
  case "--output":
80
62
  output = args[(idx += 1)];
@@ -97,26 +79,7 @@ async function main() {
97
79
  if (!endpoint) {
98
80
  throw new Error("no endpoint provided");
99
81
  }
100
- // We try API key-based authentication first, then AAD. If neither works, then we throw an error.
101
- let credential;
102
- if (apiKey) {
103
- console.error("Using API key authentication.");
104
- credential = new AzureKeyCredential(apiKey);
105
- }
106
- else {
107
- try {
108
- credential = tryAad();
109
- console.error("Using Azure Active Directory authentication (DefaultAzureCredential).");
110
- }
111
- catch (_a) {
112
- throw new Error([
113
- "no authentication method is available;",
114
- "provide an API key or install and configure the `@azure/identity` package",
115
- "(`npm i --save-dev @azure/identity`)",
116
- ].join(" "));
117
- }
118
- }
119
- const client = new DocumentModelAdministrationClient(endpoint, credential);
82
+ const client = new DocumentModelAdministrationClient(endpoint, new DefaultAzureCredential());
120
83
  const modelInfo = await client.getDocumentModel(modelId);
121
84
  console.error("Generating model code for:", modelInfo.modelId);
122
85
  const file = await writeModelCode(modelInfo, test);
@@ -1 +1 @@
1
- {"version":3,"file":"gen-model.js","sourceRoot":"","sources":["../../../src/bin/gen-model.ts"],"names":[],"mappings":";AAEA,uCAAuC;AACvC,kCAAkC;AAKlC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,iCAAiC,EAAE,MAAM,yCAAyC,CAAC;AAC5F,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;GAGG;AACH,SAAS,SAAS;IAChB,OAAO,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;yEA4ByD,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS,MAAM;IACb,IAA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C,OAAO,CAAC,CAAC;IAE/D,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAEnD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,MAAM,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IAEhF,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,mFAAmF;QACnF,MAAM,IAAI,GAAG,MAAM,CAAC;QAEpB,MAAM,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,OAAO,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAC7D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC","sourcesContent":["#!/bin/env node\n\n// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n// This file is ignored by the linter because it is impossible to move the copyright header above the shebang line.\n\nimport type { KeyCredential, TokenCredential } from \"@azure/core-auth\";\nimport { AzureKeyCredential } from \"@azure/core-auth\";\nimport { DefaultAzureCredential } from \"@azure/identity\";\nimport { writeFile } from \"node:fs/promises\";\nimport { DocumentModelAdministrationClient } from \"../documentModelAdministrationClient.js\";\nimport { writeModelCode } from \"./writeModelCode.js\";\nimport { format } from \"prettier\";\n\n/**\n * @internal\n * Prints a help message for the gen-model command.\n */\nfunction printHelp(): void {\n console.error(`\nUsage:\n gen-model [options] <model-id>\n \nCreate a strongly-typed DocumentModel for the Azure Document Intelligence SDK for JavaScript.\n\nOptions:\n -h, --help \\tshow this help message\n -o, --output\\tdetermines where to output the model\n\n --endpoint <endpoint>\\tthe Form Recognizer resource's endpoint\n --api-key <api-key> \\tthe Form Recognizer resource's API key\n\nDefault values:\n\nIf the \\`--endpoint\\` or \\`--api-key\\` options are not provided, then the values\nof the \\`FORM_RECOGNIZER_ENDPOINT\\` and \\`FORM_RECOGNIZER_API_KEY\\` environment\nvariables will be used as defaults, respectively.\n\nAuthentication:\n\nIf an API key is available (via. the \\`--api-key\\` option or \\`FORM_RECOGNIZER_API_KEY\\`\nenvironment variable), then it will be used to authenticate requests to the Form\nRecognizer service.\n\nOtherwise, if the \\`@azure/identity\\` package is installed, the \\`DefaultAzureCredential\\`\nfrom that package will be used.\n\nOne of these methods must be available to authenticate with the service.`);\n}\n\nfunction tryAad(): DefaultAzureCredential {\n try {\n return new DefaultAzureCredential();\n } catch {\n throw new Error();\n }\n}\n\n/**\n * @internal\n * The main function of the gen-model command.\n */\nasync function main(): Promise<void> {\n const args = process.argv.slice(2);\n\n let modelId: string | undefined = undefined;\n let endpoint = process.env.FORM_RECOGNIZER_ENDPOINT;\n let apiKey = process.env.FORM_RECOGNIZER_API_KEY;\n let output: string | undefined = undefined;\n let test: boolean = false;\n\n console.error(\"gen-model - create strong TypeScript types for models\");\n\n if (args.some((arg) => arg === \"--help\" || arg === \"-h\")) {\n printHelp();\n return;\n }\n\n let idx = 0;\n while (idx < args.length) {\n switch (args[idx]) {\n case \"--endpoint\":\n endpoint = args[(idx += 1)];\n break;\n case \"--api-key\":\n apiKey = args[(idx += 1)];\n break;\n case \"-o\":\n case \"--output\":\n output = args[(idx += 1)];\n break;\n case \"--test\":\n test = true;\n break;\n default:\n modelId = args[idx];\n break;\n }\n idx += 1;\n }\n\n if (idx + 1 <= args.length) {\n console.error(\"warning: unused arguments:\", args.slice(idx + 1).join(\" \"));\n }\n\n if (!modelId) {\n throw new Error(\"no model ID provided\");\n }\n\n if (!endpoint) {\n throw new Error(\"no endpoint provided\");\n }\n\n // We try API key-based authentication first, then AAD. If neither works, then we throw an error.\n let credential: KeyCredential | TokenCredential;\n\n if (apiKey) {\n console.error(\"Using API key authentication.\");\n credential = new AzureKeyCredential(apiKey);\n } else {\n try {\n credential = tryAad();\n console.error(\"Using Azure Active Directory authentication (DefaultAzureCredential).\");\n } catch {\n throw new Error(\n [\n \"no authentication method is available;\",\n \"provide an API key or install and configure the `@azure/identity` package\",\n \"(`npm i --save-dev @azure/identity`)\",\n ].join(\" \"),\n );\n }\n }\n\n const client = new DocumentModelAdministrationClient(endpoint, credential);\n\n const modelInfo = await client.getDocumentModel(modelId);\n\n console.error(\"Generating model code for:\", modelInfo.modelId);\n\n const file = await writeModelCode(modelInfo, test);\n\n const data = Buffer.from(await format(file, { parser: \"typescript\" }), \"utf-8\");\n\n if (output !== undefined) {\n // output is only refined in this context, so assigning it to \"path\" preserves that\n const path = output;\n\n await writeFile(path, data);\n } else {\n process.stdout.write(data);\n }\n}\n\nmain().catch((e) => {\n console.error(e);\n console.error(\"see `gen-model --help` for more information\");\n process.exit(1);\n});\n"]}
1
+ {"version":3,"file":"gen-model.js","sourceRoot":"","sources":["../../../src/bin/gen-model.ts"],"names":[],"mappings":";AAEA,uCAAuC;AACvC,kCAAkC;AAElC,mHAAmH;AAEnH,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,iCAAiC,EAAE,MAAM,yCAAyC,CAAC;AAC5F,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;GAGG;AACH,SAAS,SAAS;IAChB,OAAO,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;CAsBf,CAAC,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,IAAI;IACjB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC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,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,iCAAiC,CAAC,QAAQ,EAAE,IAAI,sBAAsB,EAAE,CAAC,CAAC;IAE7F,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAEzD,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAE/D,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAEnD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,MAAM,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IAEhF,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,mFAAmF;QACnF,MAAM,IAAI,GAAG,MAAM,CAAC;QAEpB,MAAM,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,OAAO,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAC7D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC","sourcesContent":["#!/bin/env node\n\n// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n// This file is ignored by the linter because it is impossible to move the copyright header above the shebang line.\n\nimport { DefaultAzureCredential } from \"@azure/identity\";\nimport { writeFile } from \"node:fs/promises\";\nimport { DocumentModelAdministrationClient } from \"../documentModelAdministrationClient.js\";\nimport { writeModelCode } from \"./writeModelCode.js\";\nimport { format } from \"prettier\";\n\n/**\n * @internal\n * Prints a help message for the gen-model command.\n */\nfunction printHelp(): void {\n console.error(`\nUsage:\n gen-model [options] <model-id>\n \nCreate a strongly-typed DocumentModel for the Azure Document Intelligence SDK for JavaScript.\n\nOptions:\n -h, --help \\tshow this help message\n -o, --output\\tdetermines where to output the model\n\n --endpoint <endpoint>\\tthe Form Recognizer resource's endpoint\n\nDefault values:\n\nIf the \\`--endpoint\\` option is not provided, then the value\nof the \\`FORM_RECOGNIZER_ENDPOINT\\` environment\nvariable will be used as default.\n\nAuthentication:\n\nIf the \\`@azure/identity\\` package is installed, the \\`DefaultAzureCredential\\`\nfrom that package will be used.\n`);\n}\n\n/**\n * @internal\n * The main function of the gen-model command.\n */\nasync function main(): Promise<void> {\n const args = process.argv.slice(2);\n\n let modelId: string | undefined = undefined;\n let endpoint = process.env.FORM_RECOGNIZER_ENDPOINT;\n let output: string | undefined = undefined;\n let test: boolean = false;\n\n console.error(\"gen-model - create strong TypeScript types for models\");\n\n if (args.some((arg) => arg === \"--help\" || arg === \"-h\")) {\n printHelp();\n return;\n }\n\n let idx = 0;\n while (idx < args.length) {\n switch (args[idx]) {\n case \"--endpoint\":\n endpoint = args[(idx += 1)];\n break;\n case \"-o\":\n case \"--output\":\n output = args[(idx += 1)];\n break;\n case \"--test\":\n test = true;\n break;\n default:\n modelId = args[idx];\n break;\n }\n idx += 1;\n }\n\n if (idx + 1 <= args.length) {\n console.error(\"warning: unused arguments:\", args.slice(idx + 1).join(\" \"));\n }\n\n if (!modelId) {\n throw new Error(\"no model ID provided\");\n }\n\n if (!endpoint) {\n throw new Error(\"no endpoint provided\");\n }\n\n const client = new DocumentModelAdministrationClient(endpoint, new DefaultAzureCredential());\n\n const modelInfo = await client.getDocumentModel(modelId);\n\n console.error(\"Generating model code for:\", modelInfo.modelId);\n\n const file = await writeModelCode(modelInfo, test);\n\n const data = Buffer.from(await format(file, { parser: \"typescript\" }), \"utf-8\");\n\n if (output !== undefined) {\n // output is only refined in this context, so assigning it to \"path\" preserves that\n const path = output;\n\n await writeFile(path, data);\n } else {\n process.stdout.write(data);\n }\n}\n\nmain().catch((e) => {\n console.error(e);\n console.error(\"see `gen-model --help` for more information\");\n process.exit(1);\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAKvE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,OAAO,KAAK,OAAO,MAAM,+BAA+B,CAAC;AAEzD,OAAO,EAAE,OAAO,EAAE,CAAC;AAGnB,eAAO,MAAM,UAAU,yCAAmC,CAAC;AAE3D;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,MAAM,cAAc,MAAM,KAAG,YAAY,CAAC,CAAC,CACX,CAAC;AAExE;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,MAAM,cAAc,CAAC,KAAG,UAAU,CAAC,CAAC,CACJ,CAAC;AAEtE;;;GAGG;AACH,eAAO,MAAM,WAAW,MAAO,MAAM,KAAG,OAEvC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAI,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,SAAS,KAAK,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,KAAG,EAAE,GAAG,SACpC,CAAC;AAE7C;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,aAAa,GAAG,eAAe,EAC3C,OAAO,EAAE,6BAA6B,GACrC,eAAe,CAiBjB"}
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAKvE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,OAAO,KAAK,OAAO,MAAM,+BAA+B,CAAC;AAEzD,OAAO,EAAE,OAAO,EAAE,CAAC;AAGnB,eAAO,MAAM,UAAU,yCAAmC,CAAC;AAE3D;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,YAAY,CAAC,CAAC,CACX,CAAC;AAExE;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,KAAG,UAAU,CAAC,CAAC,CACJ,CAAC;AAEtE;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,GAAG,MAAM,KAAG,OAEvC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAI,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,SAAS,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,KAAG,EAAE,GAAG,SACpC,CAAC;AAE7C;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,aAAa,GAAG,eAAe,EAC3C,OAAO,EAAE,6BAA6B,GACrC,eAAe,CAiBjB"}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "sdk-type": "client",
4
4
  "author": "Microsoft Corporation",
5
5
  "description": "An isomorphic client library for the Azure Document Intelligence service.",
6
- "version": "5.0.0-alpha.20250311.1",
6
+ "version": "5.0.0-alpha.20250331.1",
7
7
  "keywords": [
8
8
  "node",
9
9
  "azure",
@@ -88,21 +88,23 @@
88
88
  "@azure-tools/test-credential": "^2.0.0",
89
89
  "@azure-tools/test-recorder": ">=4.1.0-alpha <4.1.0-alphb",
90
90
  "@azure-tools/test-utils-vitest": ">=1.0.0-alpha <1.0.0-alphb",
91
+ "@azure/arm-cognitiveservices": ">=7.6.0-alpha <7.6.0-alphb",
92
+ "@azure/arm-storage": ">=18.4.0-alpha <18.4.0-alphb",
91
93
  "@azure/dev-tool": ">=1.0.0-alpha <1.0.0-alphb",
92
94
  "@azure/eslint-plugin-azure-sdk": ">=3.0.0-alpha <3.0.0-alphb",
93
95
  "@azure/identity": "^4.7.0",
94
96
  "@rollup/plugin-node-resolve": "^15.0.0",
95
97
  "@types/node": "^18.0.0",
96
- "@vitest/browser": "^3.0.6",
97
- "@vitest/coverage-istanbul": "^3.0.6",
98
+ "@vitest/browser": "^3.0.9",
99
+ "@vitest/coverage-istanbul": "^3.0.9",
98
100
  "dotenv": "^16.0.0",
99
101
  "eslint": "^9.9.0",
100
102
  "magic-string": "~0.30.10",
101
103
  "playwright": "^1.50.1",
102
104
  "prettier": "^3.3.3",
103
105
  "rollup": "^4.0.0",
104
- "typescript": "~5.7.2",
105
- "vitest": "^3.0.6"
106
+ "typescript": "~5.8.2",
107
+ "vitest": "^3.0.9"
106
108
  },
107
109
  "//sampleConfiguration": {
108
110
  "skip": [