@azure/ai-form-recognizer 5.0.0-alpha.20250227.1 → 5.0.0-alpha.20250228.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.
Files changed (46) hide show
  1. package/README.md +292 -330
  2. package/dist/browser/documentAnalysisClient.d.ts +220 -131
  3. package/dist/browser/documentAnalysisClient.d.ts.map +1 -1
  4. package/dist/browser/documentAnalysisClient.js +57 -35
  5. package/dist/browser/documentAnalysisClient.js.map +1 -1
  6. package/dist/browser/documentModelAdministrationClient.d.ts +291 -123
  7. package/dist/browser/documentModelAdministrationClient.d.ts.map +1 -1
  8. package/dist/browser/documentModelAdministrationClient.js +184 -82
  9. package/dist/browser/documentModelAdministrationClient.js.map +1 -1
  10. package/dist/browser/lro/util/delayMs.d.ts +1 -1
  11. package/dist/browser/lro/util/delayMs.js +1 -1
  12. package/dist/browser/lro/util/delayMs.js.map +1 -1
  13. package/dist/commonjs/documentAnalysisClient.d.ts +220 -131
  14. package/dist/commonjs/documentAnalysisClient.d.ts.map +1 -1
  15. package/dist/commonjs/documentAnalysisClient.js +57 -35
  16. package/dist/commonjs/documentAnalysisClient.js.map +1 -1
  17. package/dist/commonjs/documentModelAdministrationClient.d.ts +291 -123
  18. package/dist/commonjs/documentModelAdministrationClient.d.ts.map +1 -1
  19. package/dist/commonjs/documentModelAdministrationClient.js +184 -82
  20. package/dist/commonjs/documentModelAdministrationClient.js.map +1 -1
  21. package/dist/commonjs/lro/util/delayMs.d.ts +1 -1
  22. package/dist/commonjs/lro/util/delayMs.js +1 -1
  23. package/dist/commonjs/lro/util/delayMs.js.map +1 -1
  24. package/dist/esm/documentAnalysisClient.d.ts +220 -131
  25. package/dist/esm/documentAnalysisClient.d.ts.map +1 -1
  26. package/dist/esm/documentAnalysisClient.js +57 -35
  27. package/dist/esm/documentAnalysisClient.js.map +1 -1
  28. package/dist/esm/documentModelAdministrationClient.d.ts +291 -123
  29. package/dist/esm/documentModelAdministrationClient.d.ts.map +1 -1
  30. package/dist/esm/documentModelAdministrationClient.js +184 -82
  31. package/dist/esm/documentModelAdministrationClient.js.map +1 -1
  32. package/dist/esm/lro/util/delayMs.d.ts +1 -1
  33. package/dist/esm/lro/util/delayMs.js +1 -1
  34. package/dist/esm/lro/util/delayMs.js.map +1 -1
  35. package/dist/react-native/documentAnalysisClient.d.ts +220 -131
  36. package/dist/react-native/documentAnalysisClient.d.ts.map +1 -1
  37. package/dist/react-native/documentAnalysisClient.js +57 -35
  38. package/dist/react-native/documentAnalysisClient.js.map +1 -1
  39. package/dist/react-native/documentModelAdministrationClient.d.ts +291 -123
  40. package/dist/react-native/documentModelAdministrationClient.d.ts.map +1 -1
  41. package/dist/react-native/documentModelAdministrationClient.js +184 -82
  42. package/dist/react-native/documentModelAdministrationClient.js.map +1 -1
  43. package/dist/react-native/lro/util/delayMs.d.ts +1 -1
  44. package/dist/react-native/lro/util/delayMs.js +1 -1
  45. package/dist/react-native/lro/util/delayMs.js.map +1 -1
  46. package/package.json +19 -18
@@ -13,25 +13,27 @@ import type { ClassifyDocumentOptions } from "./options/ClassifyDocumentOptions.
13
13
  *
14
14
  * #### Azure Active Directory
15
15
  *
16
- * ```javascript
17
- * import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
16
+ * ```ts snippet:ReadmeSampleCreateClient_TokenCredential
18
17
  * import { DefaultAzureCredential } from "@azure/identity";
18
+ * import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
19
19
  *
20
- * const endpoint = "https://<resource name>.cognitiveservices.azure.com";
21
20
  * const credential = new DefaultAzureCredential();
22
- *
23
- * const client = new DocumentAnalysisClient(endpoint, credential);
21
+ * const client = new DocumentAnalysisClient(
22
+ * "https://<resource name>.cognitiveservices.azure.com",
23
+ * credential,
24
+ * );
24
25
  * ```
25
26
  *
26
27
  * #### API Key (Subscription Key)
27
28
  *
28
- * ```javascript
29
- * import { DocumentAnalysisClient, AzureKeyCredential } from "@azure/ai-form-recognizer";
30
- *
31
- * const endpoint = "https://<resource name>.cognitiveservices.azure.com";
32
- * const credential = new AzureKeyCredential("<api key>");
29
+ * ```ts snippet:ReadmeSampleCreateClient_KeyCredential
30
+ * import { AzureKeyCredential, DocumentAnalysisClient } from "@azure/ai-form-recognizer";
33
31
  *
34
- * const client = new DocumentAnalysisClient(endpoint, credential);
32
+ * const credential = new AzureKeyCredential("<API key>");
33
+ * const client = new DocumentAnalysisClient(
34
+ * "https://<resource name>.cognitiveservices.azure.com",
35
+ * credential,
36
+ * );
35
37
  * ```
36
38
  */
37
39
  export declare class DocumentAnalysisClient {
@@ -45,14 +47,15 @@ export declare class DocumentAnalysisClient {
45
47
  *
46
48
  * ### Example:
47
49
  *
48
- * ```javascript
49
- * import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
50
+ * ```ts snippet:ReadmeSampleCreateClient_TokenCredential
50
51
  * import { DefaultAzureCredential } from "@azure/identity";
52
+ * import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
51
53
  *
52
- * const endpoint = "https://<resource name>.cognitiveservices.azure.com";
53
54
  * const credential = new DefaultAzureCredential();
54
- *
55
- * const client = new DocumentAnalysisClient(endpoint, credential);
55
+ * const client = new DocumentAnalysisClient(
56
+ * "https://<resource name>.cognitiveservices.azure.com",
57
+ * credential,
58
+ * );
56
59
  * ```
57
60
  *
58
61
  * @param endpoint - the endpoint URL of an Azure Cognitive Services instance
@@ -65,13 +68,14 @@ export declare class DocumentAnalysisClient {
65
68
  *
66
69
  * ### Example:
67
70
  *
68
- * ```javascript
69
- * import { DocumentAnalysisClient, AzureKeyCredential } from "@azure/ai-form-recognizer";
70
- *
71
- * const endpoint = "https://<resource name>.cognitiveservices.azure.com";
72
- * const credential = new AzureKeyCredential("<api key>");
71
+ * ```ts snippet:ReadmeSampleCreateClient_KeyCredential
72
+ * import { AzureKeyCredential, DocumentAnalysisClient } from "@azure/ai-form-recognizer";
73
73
  *
74
- * const client = new DocumentAnalysisClient(endpoint, credential);
74
+ * const credential = new AzureKeyCredential("<API key>");
75
+ * const client = new DocumentAnalysisClient(
76
+ * "https://<resource name>.cognitiveservices.azure.com",
77
+ * credential,
78
+ * );
75
79
  * ```
76
80
  *
77
81
  * @param endpoint - the endpoint URL of an Azure Cognitive Services instance
@@ -99,32 +103,52 @@ export declare class DocumentAnalysisClient {
99
103
  * This method supports streamable request bodies ({@link FormRecognizerRequestBody}) such as Node.JS `ReadableStream`
100
104
  * objects, browser `Blob`s, and `ArrayBuffer`s. The contents of the body will be uploaded to the service for analysis.
101
105
  *
102
- * ```javascript
103
- * import * as fs from "fs";
106
+ * ```ts snippet:ReadmeSamplePrebuiltReceipt
107
+ * import { DefaultAzureCredential } from "@azure/identity";
108
+ * import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
109
+ * import { createReadStream } from "node:fs";
110
+ * import { PrebuiltReceiptModel } from "../samples-dev/prebuilt/prebuilt-receipt.js";
111
+ *
112
+ * const credential = new DefaultAzureCredential();
113
+ * const client = new DocumentAnalysisClient(
114
+ * "https://<resource name>.cognitiveservices.azure.com",
115
+ * credential,
116
+ * );
104
117
  *
105
- * const file = fs.createReadStream("path/to/receipt.pdf");
118
+ * const path = "<path to a document>";
119
+ * const readStream = createReadStream(path);
106
120
  *
107
- * // The model that is passed to the following function call determines the type of the eventual result. In the
108
- * // example, we will use the prebuilt receipt model, but you could use a custom model ID/name instead.
109
- * const poller = await client.beginAnalyzeDocument("prebuilt-receipt", file);
121
+ * // The PrebuiltReceiptModel `DocumentModel` instance encodes both the model ID and a stronger return type for the operation
122
+ * const poller = await client.beginAnalyzeDocument(PrebuiltReceiptModel, readStream, {
123
+ * onProgress: ({ status }) => {
124
+ * console.log(`status: ${status}`);
125
+ * },
126
+ * });
110
127
  *
111
- * // The result is a long-running operation (poller), which must itself be polled until the operation completes
112
128
  * const {
113
- * pages, // pages extracted from the document, which contain lines and words
114
- * tables, // extracted tables, organized into cells that contain their contents
115
- * styles, // text styles (ex. handwriting) that were observed in the document
116
- * keyValuePairs, // extracted pairs of elements (directed associations from one element in the input to another)
117
- * entities, // extracted entities in the input's content, which are categorized (ex. "Location" or "Organization")
118
- * documents // extracted documents (instances of one of the model's document types and its field schema)
129
+ * documents: [receiptDocument],
119
130
  * } = await poller.pollUntilDone();
120
131
  *
121
- * // Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
122
- * const [{ fields: receipt }] = documents;
132
+ * // The fields of the document constitute the extracted receipt data.
133
+ * const receipt = receiptDocument.fields;
134
+ *
135
+ * if (receipt === undefined) {
136
+ * throw new Error("Expected at least one receipt in analysis result.");
137
+ * }
138
+ *
139
+ * console.log(`Receipt data (${receiptDocument.docType})`);
140
+ * console.log(" Merchant Name:", receipt.merchantName?.value);
123
141
  *
124
- * // The fields correspond to the model's document types and their field schemas. Refer to the Form Recognizer
125
- * // documentation for information about the document types and field schemas within a model, or use the `getModel`
126
- * // operation to view this information programmatically.
127
- * console.log("The type of this receipt is:", receipt?.["ReceiptType"]?.value);
142
+ * // The items of the receipt are an example of a `DocumentArrayValue`
143
+ * if (receipt.items !== undefined) {
144
+ * console.log("Items:");
145
+ * for (const { properties: item } of receipt.items.values) {
146
+ * console.log("- Description:", item.description?.value);
147
+ * console.log(" Total Price:", item.totalPrice?.value);
148
+ * }
149
+ * }
150
+ *
151
+ * console.log(" Total:", receipt.total?.value);
128
152
  * ```
129
153
  *
130
154
  *
@@ -149,35 +173,52 @@ export declare class DocumentAnalysisClient {
149
173
  * {@link beginAnalyzeDocumentFromUrl} method for more information. Use of that method is preferred when using URLs,
150
174
  * and URL support is only provided in this method for backwards compatibility.
151
175
  *
152
- * ```typescript
153
- * import * as fs from "fs";
176
+ * ```ts snippet:ReadmeSamplePrebuiltReceipt
177
+ * import { DefaultAzureCredential } from "@azure/identity";
178
+ * import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
179
+ * import { createReadStream } from "node:fs";
180
+ * import { PrebuiltReceiptModel } from "../samples-dev/prebuilt/prebuilt-receipt.js";
154
181
  *
155
- * // See the `prebuilt` folder in the SDK samples (http://aka.ms/azsdk/formrecognizer/js/samples) for examples of
156
- * // DocumentModels for known prebuilts.
157
- * import { PrebuiltReceiptModel } from "./prebuilt-receipt.ts";
182
+ * const credential = new DefaultAzureCredential();
183
+ * const client = new DocumentAnalysisClient(
184
+ * "https://<resource name>.cognitiveservices.azure.com",
185
+ * credential,
186
+ * );
158
187
  *
159
- * const file = fs.createReadStream("path/to/receipt.pdf");
188
+ * const path = "<path to a document>";
189
+ * const readStream = createReadStream(path);
160
190
  *
161
- * // The model that is passed to the following function call determines the type of the eventual result. In the
162
- * // example, we will use the prebuilt receipt model.
163
- * const poller = await client.beginAnalyzeDocument(PrebuiltReceiptModel, file);
191
+ * // The PrebuiltReceiptModel `DocumentModel` instance encodes both the model ID and a stronger return type for the operation
192
+ * const poller = await client.beginAnalyzeDocument(PrebuiltReceiptModel, readStream, {
193
+ * onProgress: ({ status }) => {
194
+ * console.log(`status: ${status}`);
195
+ * },
196
+ * });
164
197
  *
165
- * // The result is a long-running operation (poller), which must itself be polled until the operation completes
166
198
  * const {
167
- * pages, // pages extracted from the document, which contain lines and words
168
- * tables, // extracted tables, organized into cells that contain their contents
169
- * styles, // text styles (ex. handwriting) that were observed in the document
170
- * keyValuePairs, // extracted pairs of elements (directed associations from one element in the input to another)
171
- *
172
- * documents // extracted documents (instances of one of the model's document types and its field schema)
199
+ * documents: [receiptDocument],
173
200
  * } = await poller.pollUntilDone();
174
201
  *
175
- * // Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
176
- * const [{ fields: receipt }] = documents;
202
+ * // The fields of the document constitute the extracted receipt data.
203
+ * const receipt = receiptDocument.fields;
204
+ *
205
+ * if (receipt === undefined) {
206
+ * throw new Error("Expected at least one receipt in analysis result.");
207
+ * }
177
208
  *
178
- * // Since we used the strongly-typed PrebuiltReceiptModel object instead of the "prebuilt-receipt" model ID
179
- * // string, the fields of the receipt are strongly-typed and have camelCase names (as opposed to PascalCase).
180
- * console.log("The type of this receipt is:", receipt.receiptType?.value);
209
+ * console.log(`Receipt data (${receiptDocument.docType})`);
210
+ * console.log(" Merchant Name:", receipt.merchantName?.value);
211
+ *
212
+ * // The items of the receipt are an example of a `DocumentArrayValue`
213
+ * if (receipt.items !== undefined) {
214
+ * console.log("Items:");
215
+ * for (const { properties: item } of receipt.items.values) {
216
+ * console.log("- Description:", item.description?.value);
217
+ * console.log(" Total Price:", item.totalPrice?.value);
218
+ * }
219
+ * }
220
+ *
221
+ * console.log(" Total:", receipt.total?.value);
181
222
  * ```
182
223
  *
183
224
  * @param model - a {@link DocumentModel} representing the model to use for analysis and the expected output type
@@ -205,31 +246,46 @@ export declare class DocumentAnalysisClient {
205
246
  * token can be used to grant read access to a blob in Azure Storage, and the service will use the SAS-encoded URL to
206
247
  * request the file.
207
248
  *
208
- * ```javascript
209
- * // the URL must be publicly accessible
210
- * const url = "<receipt document url>";
211
- *
212
- * // The model that is passed to the following function call determines the type of the eventual result. In the
213
- * // example, we will use the prebuilt receipt model, but you could use a custom model ID/name instead.
214
- * const poller = await client.beginAnalyzeDocument("prebuilt-receipt", url);
215
- *
216
- * // The result is a long-running operation (poller), which must itself be polled until the operation completes
217
- * const {
218
- * pages, // pages extracted from the document, which contain lines and words
219
- * tables, // extracted tables, organized into cells that contain their contents
220
- * styles, // text styles (ex. handwriting) that were observed in the document
221
- * keyValuePairs, // extracted pairs of elements (directed associations from one element in the input to another)
222
- *
223
- * documents // extracted documents (instances of one of the model's document types and its field schema)
224
- * } = await poller.pollUntilDone();
225
- *
226
- * // Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
227
- * const [{ fields: receipt }] = documents;
249
+ * ```ts snippet:ReadmeSampleReceiptModelID_URL
250
+ * import { DefaultAzureCredential } from "@azure/identity";
251
+ * import {
252
+ * DocumentAnalysisClient,
253
+ * DocumentStringField,
254
+ * DocumentArrayField,
255
+ * DocumentObjectField,
256
+ * } from "@azure/ai-form-recognizer";
228
257
  *
229
- * // The fields correspond to the model's document types and their field schemas. Refer to the Form Recognizer
230
- * // documentation for information about the document types and field schemas within a model, or use the `getModel`
231
- * // operation to view this information programmatically.
232
- * console.log("The type of this receipt is:", receipt?.["ReceiptType"]?.value);
258
+ * const credential = new DefaultAzureCredential();
259
+ * const client = new DocumentAnalysisClient(
260
+ * "https://<resource name>.cognitiveservices.azure.com",
261
+ * credential,
262
+ * );
263
+ *
264
+ * const poller = await client.beginAnalyzeDocumentFromUrl(
265
+ * "prebuilt-receipt",
266
+ * // The Document Intelligence service will access the following URL to a receipt image and extract data from it
267
+ * "https://raw.githubusercontent.com/Azure/azure-sdk-for-js/main/sdk/formrecognizer/ai-form-recognizer/assets/receipt/contoso-receipt.png",
268
+ * );
269
+ * poller.onProgress((state) => console.log("Operation:", state.modelId, state.status));
270
+ *
271
+ * const { documents } = await poller.pollUntilDone();
272
+ *
273
+ * const result = documents && documents[0];
274
+ * if (result) {
275
+ * const receipt = result.fields;
276
+ * console.log("=== Receipt Information ===");
277
+ * console.log("Type:", result.docType);
278
+ * console.log("Merchant:", (receipt["MerchantName"] as DocumentStringField).value);
279
+ *
280
+ * console.log("Items:");
281
+ * for (const { properties: item } of ((receipt["Items"] as DocumentArrayField).values ||
282
+ * []) as DocumentObjectField[]) {
283
+ * console.log("- Description:", (item["Description"] as DocumentStringField).value);
284
+ * console.log(" Total Price:", (item["TotalPrice"] as DocumentStringField).value);
285
+ * }
286
+ * } else {
287
+ * throw new Error("Expected at least one receipt in the result.");
288
+ * }
233
289
  * ```
234
290
  *
235
291
  * @param modelId - the unique ID (name) of the model within this client's resource
@@ -251,34 +307,47 @@ export declare class DocumentAnalysisClient {
251
307
  * token can be used to grant read access to a blob in Azure Storage, and the service will use the SAS-encoded URL to
252
308
  * request the file.
253
309
  *
254
- * ```typescript
255
- * // See the `prebuilt` folder in the SDK samples (http://aka.ms/azsdk/formrecognizer/js/samples) for examples of
256
- * // DocumentModels for known prebuilts.
257
- * import { PrebuiltReceiptModel } from "./prebuilt-receipt.ts";
310
+ * ```ts snippet:ReadmeSampleReceiptPrebuilt_URL
311
+ * import { DefaultAzureCredential } from "@azure/identity";
312
+ * import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
313
+ * import { PrebuiltReceiptModel } from "../samples-dev/prebuilt/prebuilt-receipt.js";
258
314
  *
259
- * // the URL must be publicly accessible
260
- * const url = "<receipt document url>";
315
+ * const credential = new DefaultAzureCredential();
316
+ * const client = new DocumentAnalysisClient(
317
+ * "https://<resource name>.cognitiveservices.azure.com",
318
+ * credential,
319
+ * );
261
320
  *
262
- * // The model that is passed to the following function call determines the type of the eventual result. In the
263
- * // example, we will use the prebuilt receipt model.
264
- * const poller = await client.beginAnalyzeDocument(PrebuiltReceiptModel, url);
321
+ * const poller = await client.beginAnalyzeDocumentFromUrl(
322
+ * PrebuiltReceiptModel,
323
+ * // The Document Intelligence service will access the following URL to a receipt image and extract data from it
324
+ * "https://raw.githubusercontent.com/Azure/azure-sdk-for-js/main/sdk/formrecognizer/ai-form-recognizer/assets/receipt/contoso-receipt.png",
325
+ * );
265
326
  *
266
- * // The result is a long-running operation (poller), which must itself be polled until the operation completes
267
327
  * const {
268
- * pages, // pages extracted from the document, which contain lines and words
269
- * tables, // extracted tables, organized into cells that contain their contents
270
- * styles, // text styles (ex. handwriting) that were observed in the document
271
- * keyValuePairs, // extracted pairs of elements (directed associations from one element in the input to another)
272
- *
273
- * documents // extracted documents (instances of one of the model's document types and its field schema)
328
+ * documents: [document],
274
329
  * } = await poller.pollUntilDone();
275
330
  *
276
- * // Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
277
- * const [{ fields: receipt }] = documents;
331
+ * // Use of PrebuiltModels.Receipt above (rather than the raw model ID), as it adds strong typing of the model's output
332
+ * if (document) {
333
+ * const { merchantName, items, total } = document.fields;
334
+ *
335
+ * console.log("=== Receipt Information ===");
336
+ * console.log("Type:", document.docType);
337
+ * console.log("Merchant:", merchantName && merchantName.value);
338
+ *
339
+ * console.log("Items:");
340
+ * for (const item of (items && items.values) || []) {
341
+ * const { description, totalPrice } = item.properties;
342
+ *
343
+ * console.log("- Description:", description && description.value);
344
+ * console.log(" Total Price:", totalPrice && totalPrice.value);
345
+ * }
278
346
  *
279
- * // Since we used the strongly-typed PrebuiltReceiptModel object instead of the "prebuilt-receipt" model ID
280
- * // string, the fields of the receipt are strongly-typed and have camelCase names (as opposed to PascalCase).
281
- * console.log("The type of this receipt is:", receipt.receiptType?.value);
347
+ * console.log("Total:", total && total.value);
348
+ * } else {
349
+ * throw new Error("Expected at least one receipt in the result.");
350
+ * }
282
351
  * ```
283
352
  *
284
353
  * @param model - a {@link DocumentModel} representing the model to use for analysis and the expected output type
@@ -310,22 +379,32 @@ export declare class DocumentAnalysisClient {
310
379
  * This method supports streamable request bodies ({@link FormRecognizerRequestBody}) such as Node.JS `ReadableStream`
311
380
  * objects, browser `Blob`s, and `ArrayBuffer`s. The contents of the body will be uploaded to the service for analysis.
312
381
  *
313
- * ```typescript
314
- * import * as fs from "fs";
382
+ * ```ts snippet:ReadmeSampleClassifyDocument_File
383
+ * import { DefaultAzureCredential } from "@azure/identity";
384
+ * import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
385
+ * import { createReadStream } from "node:fs";
386
+ *
387
+ * const credential = new DefaultAzureCredential();
388
+ * const client = new DocumentAnalysisClient(
389
+ * "https://<resource name>.cognitiveservices.azure.com",
390
+ * credential,
391
+ * );
315
392
  *
316
- * const file = fs.createReadStream("path/to/file.pdf");
393
+ * const path = "<path to a document>";
394
+ * const readStream = createReadStream(path);
317
395
  *
318
- * const poller = await client.beginClassifyDocument("<classifier ID>", file);
396
+ * const poller = await client.beginClassifyDocument("<classifier id>", readStream);
319
397
  *
320
- * // The result is a long-running operation (poller), which must itself be polled until the operation completes
321
- * const {
322
- * pages, // pages extracted from the document, which contain only basic information for classifiers
323
- * documents // extracted documents and their types
324
- * } = await poller.pollUntilDone();
398
+ * const result = await poller.pollUntilDone();
325
399
  *
326
- * // We'll print the documents and their types
327
- * for (const { docType } of documents) {
328
- * console.log("The type of this document is:", docType);
400
+ * if (result?.documents?.length === 0) {
401
+ * throw new Error("Failed to extract any documents.");
402
+ * }
403
+ *
404
+ * for (const document of result.documents) {
405
+ * console.log(
406
+ * `Extracted a document with type '${document.docType}' on page ${document.boundingRegions?.[0].pageNumber} (confidence: ${document.confidence})`,
407
+ * );
329
408
  * }
330
409
  * ```
331
410
  *
@@ -351,21 +430,31 @@ export declare class DocumentAnalysisClient {
351
430
  * token can be used to grant read access to a blob in Azure Storage, and the service will use the SAS-encoded URL to
352
431
  * request the file.
353
432
  *
354
- * ```typescript
355
- * // the URL must be publicly accessible
356
- * const url = "<file url>";
433
+ * ```ts snippet:ReadmeSampleClassifyDocument
434
+ * import { DefaultAzureCredential } from "@azure/identity";
435
+ * import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
357
436
  *
358
- * const poller = await client.beginClassifyDocument("<classifier ID>", url);
437
+ * const credential = new DefaultAzureCredential();
438
+ * const client = new DocumentAnalysisClient(
439
+ * "https://<resource name>.cognitiveservices.azure.com",
440
+ * credential,
441
+ * );
359
442
  *
360
- * // The result is a long-running operation (poller), which must itself be polled until the operation completes
361
- * const {
362
- * pages, // pages extracted from the document, which contain only basic information for classifiers
363
- * documents // extracted documents and their types
364
- * } = await poller.pollUntilDone();
443
+ * const documentUrl =
444
+ * "https://raw.githubusercontent.com/Azure/azure-sdk-for-js/main/sdk/formrecognizer/ai-form-recognizer/assets/invoice/Invoice_1.pdf";
445
+ *
446
+ * const poller = await client.beginClassifyDocumentFromUrl("<classifier id>", documentUrl);
447
+ *
448
+ * const result = await poller.pollUntilDone();
449
+ *
450
+ * if (result?.documents?.length === 0) {
451
+ * throw new Error("Failed to extract any documents.");
452
+ * }
365
453
  *
366
- * // We'll print the documents and their types
367
- * for (const { docType } of documents) {
368
- * console.log("The type of this document is:", docType);
454
+ * for (const document of result.documents) {
455
+ * console.log(
456
+ * `Extracted a document with type '${document.docType}' on page ${document.boundingRegions?.[0].pageNumber} (confidence: ${document.confidence})`,
457
+ * );
369
458
  * }
370
459
  * ```
371
460
  * @param classifierId - the ID of the custom classifier to use for analysis
@@ -1 +1 @@
1
- {"version":3,"file":"documentAnalysisClient.d.ts","sourceRoot":"","sources":["../../src/documentAnalysisClient.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAUvE,OAAO,KAAK,EAEV,cAAc,EAGd,yBAAyB,EAC1B,MAAM,mBAAmB,CAAC;AAO3B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AAC9F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAEpF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,sBAAsB;IACjC,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,QAAQ,CAAgB;IAEhC;;;;;;;;;;;;;;;;;;;;;OAqBG;gBAED,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,eAAe,EAC3B,OAAO,CAAC,EAAE,6BAA6B;IAEzC;;;;;;;;;;;;;;;;;OAiBG;gBAED,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,aAAa,EACzB,OAAO,CAAC,EAAE,6BAA6B;IAEzC;;OAEG;gBAED,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,aAAa,GAAG,eAAe,EAC3C,OAAO,CAAC,EAAE,6BAA6B;IAiBzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiDG;IACU,oBAAoB,CAC/B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,yBAAyB,EAEnC,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,cAAc,CAA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JlC"}
@@ -15,25 +15,27 @@ import { makeServiceClient, Mappers, SERIALIZER } from "./util.js";
15
15
  *
16
16
  * #### Azure Active Directory
17
17
  *
18
- * ```javascript
19
- * import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
18
+ * ```ts snippet:ReadmeSampleCreateClient_TokenCredential
20
19
  * import { DefaultAzureCredential } from "@azure/identity";
20
+ * import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
21
21
  *
22
- * const endpoint = "https://<resource name>.cognitiveservices.azure.com";
23
22
  * const credential = new DefaultAzureCredential();
24
- *
25
- * const client = new DocumentAnalysisClient(endpoint, credential);
23
+ * const client = new DocumentAnalysisClient(
24
+ * "https://<resource name>.cognitiveservices.azure.com",
25
+ * credential,
26
+ * );
26
27
  * ```
27
28
  *
28
29
  * #### API Key (Subscription Key)
29
30
  *
30
- * ```javascript
31
- * import { DocumentAnalysisClient, AzureKeyCredential } from "@azure/ai-form-recognizer";
31
+ * ```ts snippet:ReadmeSampleCreateClient_KeyCredential
32
+ * import { AzureKeyCredential, DocumentAnalysisClient } from "@azure/ai-form-recognizer";
32
33
  *
33
- * const endpoint = "https://<resource name>.cognitiveservices.azure.com";
34
- * const credential = new AzureKeyCredential("<api key>");
35
- *
36
- * const client = new DocumentAnalysisClient(endpoint, credential);
34
+ * const credential = new AzureKeyCredential("<API key>");
35
+ * const client = new DocumentAnalysisClient(
36
+ * "https://<resource name>.cognitiveservices.azure.com",
37
+ * credential,
38
+ * );
37
39
  * ```
38
40
  */
39
41
  export class DocumentAnalysisClient {
@@ -107,22 +109,32 @@ export class DocumentAnalysisClient {
107
109
  * This method supports streamable request bodies ({@link FormRecognizerRequestBody}) such as Node.JS `ReadableStream`
108
110
  * objects, browser `Blob`s, and `ArrayBuffer`s. The contents of the body will be uploaded to the service for analysis.
109
111
  *
110
- * ```typescript
111
- * import * as fs from "fs";
112
+ * ```ts snippet:ReadmeSampleClassifyDocument_File
113
+ * import { DefaultAzureCredential } from "@azure/identity";
114
+ * import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
115
+ * import { createReadStream } from "node:fs";
116
+ *
117
+ * const credential = new DefaultAzureCredential();
118
+ * const client = new DocumentAnalysisClient(
119
+ * "https://<resource name>.cognitiveservices.azure.com",
120
+ * credential,
121
+ * );
112
122
  *
113
- * const file = fs.createReadStream("path/to/file.pdf");
123
+ * const path = "<path to a document>";
124
+ * const readStream = createReadStream(path);
114
125
  *
115
- * const poller = await client.beginClassifyDocument("<classifier ID>", file);
126
+ * const poller = await client.beginClassifyDocument("<classifier id>", readStream);
116
127
  *
117
- * // The result is a long-running operation (poller), which must itself be polled until the operation completes
118
- * const {
119
- * pages, // pages extracted from the document, which contain only basic information for classifiers
120
- * documents // extracted documents and their types
121
- * } = await poller.pollUntilDone();
128
+ * const result = await poller.pollUntilDone();
122
129
  *
123
- * // We'll print the documents and their types
124
- * for (const { docType } of documents) {
125
- * console.log("The type of this document is:", docType);
130
+ * if (result?.documents?.length === 0) {
131
+ * throw new Error("Failed to extract any documents.");
132
+ * }
133
+ *
134
+ * for (const document of result.documents) {
135
+ * console.log(
136
+ * `Extracted a document with type '${document.docType}' on page ${document.boundingRegions?.[0].pageNumber} (confidence: ${document.confidence})`,
137
+ * );
126
138
  * }
127
139
  * ```
128
140
  *
@@ -152,21 +164,31 @@ export class DocumentAnalysisClient {
152
164
  * token can be used to grant read access to a blob in Azure Storage, and the service will use the SAS-encoded URL to
153
165
  * request the file.
154
166
  *
155
- * ```typescript
156
- * // the URL must be publicly accessible
157
- * const url = "<file url>";
167
+ * ```ts snippet:ReadmeSampleClassifyDocument
168
+ * import { DefaultAzureCredential } from "@azure/identity";
169
+ * import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
170
+ *
171
+ * const credential = new DefaultAzureCredential();
172
+ * const client = new DocumentAnalysisClient(
173
+ * "https://<resource name>.cognitiveservices.azure.com",
174
+ * credential,
175
+ * );
176
+ *
177
+ * const documentUrl =
178
+ * "https://raw.githubusercontent.com/Azure/azure-sdk-for-js/main/sdk/formrecognizer/ai-form-recognizer/assets/invoice/Invoice_1.pdf";
158
179
  *
159
- * const poller = await client.beginClassifyDocument("<classifier ID>", url);
180
+ * const poller = await client.beginClassifyDocumentFromUrl("<classifier id>", documentUrl);
160
181
  *
161
- * // The result is a long-running operation (poller), which must itself be polled until the operation completes
162
- * const {
163
- * pages, // pages extracted from the document, which contain only basic information for classifiers
164
- * documents // extracted documents and their types
165
- * } = await poller.pollUntilDone();
182
+ * const result = await poller.pollUntilDone();
183
+ *
184
+ * if (result?.documents?.length === 0) {
185
+ * throw new Error("Failed to extract any documents.");
186
+ * }
166
187
  *
167
- * // We'll print the documents and their types
168
- * for (const { docType } of documents) {
169
- * console.log("The type of this document is:", docType);
188
+ * for (const document of result.documents) {
189
+ * console.log(
190
+ * `Extracted a document with type '${document.docType}' on page ${document.boundingRegions?.[0].pageNumber} (confidence: ${document.confidence})`,
191
+ * );
170
192
  * }
171
193
  * ```
172
194
  * @param classifierId - the ID of the custom classifier to use for analysis