@azure-rest/ai-document-intelligence 1.0.0-beta.3 → 1.1.0-alpha.20250513.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.
Files changed (206) hide show
  1. package/CHANGELOG.md +137 -0
  2. package/LICENSE +4 -4
  3. package/README.md +274 -75
  4. package/dist/browser/audience.d.ts +19 -0
  5. package/dist/browser/audience.d.ts.map +1 -0
  6. package/dist/browser/audience.js +22 -0
  7. package/dist/browser/audience.js.map +1 -0
  8. package/dist/browser/clientDefinitions.d.ts +18 -8
  9. package/dist/browser/clientDefinitions.d.ts.map +1 -1
  10. package/dist/browser/clientDefinitions.js +1 -1
  11. package/dist/browser/clientDefinitions.js.map +1 -1
  12. package/dist/browser/documentIntelligence.d.ts +3 -3
  13. package/dist/browser/documentIntelligence.d.ts.map +1 -1
  14. package/dist/browser/documentIntelligence.js +9 -4
  15. package/dist/browser/documentIntelligence.js.map +1 -1
  16. package/dist/browser/index.d.ts +2 -0
  17. package/dist/browser/index.d.ts.map +1 -1
  18. package/dist/browser/index.js +3 -1
  19. package/dist/browser/index.js.map +1 -1
  20. package/dist/browser/isUnexpected.d.ts +5 -2
  21. package/dist/browser/isUnexpected.d.ts.map +1 -1
  22. package/dist/browser/isUnexpected.js +4 -1
  23. package/dist/browser/isUnexpected.js.map +1 -1
  24. package/dist/browser/logger.js +1 -1
  25. package/dist/browser/logger.js.map +1 -1
  26. package/dist/browser/models.d.ts +5 -5
  27. package/dist/browser/models.d.ts.map +1 -1
  28. package/dist/browser/models.js +1 -1
  29. package/dist/browser/models.js.map +1 -1
  30. package/dist/browser/outputModels.d.ts +85 -58
  31. package/dist/browser/outputModels.d.ts.map +1 -1
  32. package/dist/browser/outputModels.js +1 -1
  33. package/dist/browser/outputModels.js.map +1 -1
  34. package/dist/browser/paginateHelper.d.ts +28 -3
  35. package/dist/browser/paginateHelper.d.ts.map +1 -1
  36. package/dist/browser/paginateHelper.js +99 -2
  37. package/dist/browser/paginateHelper.js.map +1 -1
  38. package/dist/browser/parameters.d.ts +108 -24
  39. package/dist/browser/parameters.d.ts.map +1 -1
  40. package/dist/browser/parameters.js +1 -1
  41. package/dist/browser/parameters.js.map +1 -1
  42. package/dist/browser/pollingHelper.d.ts +25 -73
  43. package/dist/browser/pollingHelper.d.ts.map +1 -1
  44. package/dist/browser/pollingHelper.js +13 -51
  45. package/dist/browser/pollingHelper.js.map +1 -1
  46. package/dist/browser/responses.d.ts +68 -43
  47. package/dist/browser/responses.d.ts.map +1 -1
  48. package/dist/browser/responses.js +1 -1
  49. package/dist/browser/responses.js.map +1 -1
  50. package/dist/browser/utils.d.ts +5 -0
  51. package/dist/browser/utils.d.ts.map +1 -0
  52. package/dist/browser/utils.js +33 -0
  53. package/dist/browser/utils.js.map +1 -0
  54. package/dist/commonjs/audience.d.ts +19 -0
  55. package/dist/commonjs/audience.d.ts.map +1 -0
  56. package/dist/commonjs/audience.js +25 -0
  57. package/dist/commonjs/audience.js.map +1 -0
  58. package/dist/commonjs/clientDefinitions.d.ts +18 -8
  59. package/dist/commonjs/clientDefinitions.d.ts.map +1 -1
  60. package/dist/commonjs/clientDefinitions.js +1 -1
  61. package/dist/commonjs/clientDefinitions.js.map +1 -1
  62. package/dist/commonjs/documentIntelligence.d.ts +3 -3
  63. package/dist/commonjs/documentIntelligence.d.ts.map +1 -1
  64. package/dist/commonjs/documentIntelligence.js +9 -4
  65. package/dist/commonjs/documentIntelligence.js.map +1 -1
  66. package/dist/commonjs/index.d.ts +2 -0
  67. package/dist/commonjs/index.d.ts.map +1 -1
  68. package/dist/commonjs/index.js +5 -1
  69. package/dist/commonjs/index.js.map +1 -1
  70. package/dist/commonjs/isUnexpected.d.ts +5 -2
  71. package/dist/commonjs/isUnexpected.d.ts.map +1 -1
  72. package/dist/commonjs/isUnexpected.js +4 -1
  73. package/dist/commonjs/isUnexpected.js.map +1 -1
  74. package/dist/commonjs/logger.js +1 -1
  75. package/dist/commonjs/logger.js.map +1 -1
  76. package/dist/commonjs/models.d.ts +5 -5
  77. package/dist/commonjs/models.d.ts.map +1 -1
  78. package/dist/commonjs/models.js +1 -1
  79. package/dist/commonjs/models.js.map +1 -1
  80. package/dist/commonjs/outputModels.d.ts +85 -58
  81. package/dist/commonjs/outputModels.d.ts.map +1 -1
  82. package/dist/commonjs/outputModels.js +1 -1
  83. package/dist/commonjs/outputModels.js.map +1 -1
  84. package/dist/commonjs/paginateHelper.d.ts +28 -3
  85. package/dist/commonjs/paginateHelper.d.ts.map +1 -1
  86. package/dist/commonjs/paginateHelper.js +100 -3
  87. package/dist/commonjs/paginateHelper.js.map +1 -1
  88. package/dist/commonjs/parameters.d.ts +108 -24
  89. package/dist/commonjs/parameters.d.ts.map +1 -1
  90. package/dist/commonjs/parameters.js +1 -1
  91. package/dist/commonjs/parameters.js.map +1 -1
  92. package/dist/commonjs/pollingHelper.d.ts +25 -73
  93. package/dist/commonjs/pollingHelper.d.ts.map +1 -1
  94. package/dist/commonjs/pollingHelper.js +13 -50
  95. package/dist/commonjs/pollingHelper.js.map +1 -1
  96. package/dist/commonjs/responses.d.ts +68 -43
  97. package/dist/commonjs/responses.d.ts.map +1 -1
  98. package/dist/commonjs/responses.js +1 -1
  99. package/dist/commonjs/responses.js.map +1 -1
  100. package/dist/commonjs/tsdoc-metadata.json +1 -1
  101. package/dist/commonjs/utils.d.ts +5 -0
  102. package/dist/commonjs/utils.d.ts.map +1 -0
  103. package/dist/commonjs/utils.js +36 -0
  104. package/dist/commonjs/utils.js.map +1 -0
  105. package/dist/esm/audience.d.ts +19 -0
  106. package/dist/esm/audience.d.ts.map +1 -0
  107. package/dist/esm/audience.js +22 -0
  108. package/dist/esm/audience.js.map +1 -0
  109. package/dist/esm/clientDefinitions.d.ts +18 -8
  110. package/dist/esm/clientDefinitions.d.ts.map +1 -1
  111. package/dist/esm/clientDefinitions.js +1 -1
  112. package/dist/esm/clientDefinitions.js.map +1 -1
  113. package/dist/esm/documentIntelligence.d.ts +3 -3
  114. package/dist/esm/documentIntelligence.d.ts.map +1 -1
  115. package/dist/esm/documentIntelligence.js +9 -4
  116. package/dist/esm/documentIntelligence.js.map +1 -1
  117. package/dist/esm/index.d.ts +2 -0
  118. package/dist/esm/index.d.ts.map +1 -1
  119. package/dist/esm/index.js +3 -1
  120. package/dist/esm/index.js.map +1 -1
  121. package/dist/esm/isUnexpected.d.ts +5 -2
  122. package/dist/esm/isUnexpected.d.ts.map +1 -1
  123. package/dist/esm/isUnexpected.js +4 -1
  124. package/dist/esm/isUnexpected.js.map +1 -1
  125. package/dist/esm/logger.js +1 -1
  126. package/dist/esm/logger.js.map +1 -1
  127. package/dist/esm/models.d.ts +5 -5
  128. package/dist/esm/models.d.ts.map +1 -1
  129. package/dist/esm/models.js +1 -1
  130. package/dist/esm/models.js.map +1 -1
  131. package/dist/esm/outputModels.d.ts +85 -58
  132. package/dist/esm/outputModels.d.ts.map +1 -1
  133. package/dist/esm/outputModels.js +1 -1
  134. package/dist/esm/outputModels.js.map +1 -1
  135. package/dist/esm/paginateHelper.d.ts +28 -3
  136. package/dist/esm/paginateHelper.d.ts.map +1 -1
  137. package/dist/esm/paginateHelper.js +99 -2
  138. package/dist/esm/paginateHelper.js.map +1 -1
  139. package/dist/esm/parameters.d.ts +108 -24
  140. package/dist/esm/parameters.d.ts.map +1 -1
  141. package/dist/esm/parameters.js +1 -1
  142. package/dist/esm/parameters.js.map +1 -1
  143. package/dist/esm/pollingHelper.d.ts +25 -73
  144. package/dist/esm/pollingHelper.d.ts.map +1 -1
  145. package/dist/esm/pollingHelper.js +13 -51
  146. package/dist/esm/pollingHelper.js.map +1 -1
  147. package/dist/esm/responses.d.ts +68 -43
  148. package/dist/esm/responses.d.ts.map +1 -1
  149. package/dist/esm/responses.js +1 -1
  150. package/dist/esm/responses.js.map +1 -1
  151. package/dist/esm/utils.d.ts +5 -0
  152. package/dist/esm/utils.d.ts.map +1 -0
  153. package/dist/esm/utils.js +33 -0
  154. package/dist/esm/utils.js.map +1 -0
  155. package/dist/react-native/audience.d.ts +19 -0
  156. package/dist/react-native/audience.d.ts.map +1 -0
  157. package/dist/react-native/audience.js +22 -0
  158. package/dist/react-native/audience.js.map +1 -0
  159. package/dist/react-native/clientDefinitions.d.ts +18 -8
  160. package/dist/react-native/clientDefinitions.d.ts.map +1 -1
  161. package/dist/react-native/clientDefinitions.js +1 -1
  162. package/dist/react-native/clientDefinitions.js.map +1 -1
  163. package/dist/react-native/documentIntelligence.d.ts +3 -3
  164. package/dist/react-native/documentIntelligence.d.ts.map +1 -1
  165. package/dist/react-native/documentIntelligence.js +9 -4
  166. package/dist/react-native/documentIntelligence.js.map +1 -1
  167. package/dist/react-native/index.d.ts +2 -0
  168. package/dist/react-native/index.d.ts.map +1 -1
  169. package/dist/react-native/index.js +3 -1
  170. package/dist/react-native/index.js.map +1 -1
  171. package/dist/react-native/isUnexpected.d.ts +5 -2
  172. package/dist/react-native/isUnexpected.d.ts.map +1 -1
  173. package/dist/react-native/isUnexpected.js +4 -1
  174. package/dist/react-native/isUnexpected.js.map +1 -1
  175. package/dist/react-native/logger.js +1 -1
  176. package/dist/react-native/logger.js.map +1 -1
  177. package/dist/react-native/models.d.ts +5 -5
  178. package/dist/react-native/models.d.ts.map +1 -1
  179. package/dist/react-native/models.js +1 -1
  180. package/dist/react-native/models.js.map +1 -1
  181. package/dist/react-native/outputModels.d.ts +85 -58
  182. package/dist/react-native/outputModels.d.ts.map +1 -1
  183. package/dist/react-native/outputModels.js +1 -1
  184. package/dist/react-native/outputModels.js.map +1 -1
  185. package/dist/react-native/paginateHelper.d.ts +28 -3
  186. package/dist/react-native/paginateHelper.d.ts.map +1 -1
  187. package/dist/react-native/paginateHelper.js +99 -2
  188. package/dist/react-native/paginateHelper.js.map +1 -1
  189. package/dist/react-native/parameters.d.ts +108 -24
  190. package/dist/react-native/parameters.d.ts.map +1 -1
  191. package/dist/react-native/parameters.js +1 -1
  192. package/dist/react-native/parameters.js.map +1 -1
  193. package/dist/react-native/pollingHelper.d.ts +25 -73
  194. package/dist/react-native/pollingHelper.d.ts.map +1 -1
  195. package/dist/react-native/pollingHelper.js +13 -51
  196. package/dist/react-native/pollingHelper.js.map +1 -1
  197. package/dist/react-native/responses.d.ts +68 -43
  198. package/dist/react-native/responses.d.ts.map +1 -1
  199. package/dist/react-native/responses.js +1 -1
  200. package/dist/react-native/responses.js.map +1 -1
  201. package/dist/react-native/utils.d.ts +5 -0
  202. package/dist/react-native/utils.d.ts.map +1 -0
  203. package/dist/react-native/utils.js +33 -0
  204. package/dist/react-native/utils.js.map +1 -0
  205. package/package.json +44 -58
  206. package/review/ai-document-intelligence.api.md +380 -221
package/CHANGELOG.md CHANGED
@@ -1,5 +1,142 @@
1
+ <!-- dev-tool snippets ignore -->
2
+
1
3
  # Release History
2
4
 
5
+ ## 1.1.0 (2025-05-08)
6
+
7
+ ### Features Added
8
+
9
+ - Supports alternative cloud environments (Azure United States Government and Azure China Cloud). To use an alternative cloud environment, provide a value for the `scopes` field of `DocumentIntelligenceClientOptions#credentials` to configure the client to authenticate within a [Sovereign Cloud](https://learn.microsoft.com/entra/identity-platform/authentication-national-cloud).
10
+ Import and use `KnownDocumentIntelligenceAudience` to get the correct values for a given cloud environment. The currently supported cloud environments are:
11
+
12
+ - `KnownDocumentIntelligenceAudience.AzureChina` (`"https://cognitiveservices.azure.cn"`),
13
+ - `KnownDocumentIntelligenceAudience.AzureGovernment` (`"https://cognitiveservices.azure.us"`),
14
+ - `KnownDocumentIntelligenceAudience.AzurePublicCloud` (`"https://cognitiveservices.azure.com"`),
15
+
16
+ ```js
17
+ const client = DocumentIntelligence(
18
+ "<cognitive services endpoint>",
19
+ <--credential-->,
20
+ { credentials: { scopes: [ KnownDocumentIntelligenceAudience.AzureGovernment ] } }
21
+ );
22
+ ```
23
+
24
+ If `scopes` is undefined, the default value is suitable for the Azure Public Cloud `https://cognitiveservices.azure.com`.
25
+
26
+ ## 1.0.0 (2024-12-16)
27
+
28
+ ### Features Added
29
+
30
+ - Adds `streamToUint8Array`, a convenience function that buffers a `NodeJS.ReadableStream` in a `Uint8Array`. It can be used to read the pdf and png responses from the results of an analysis.
31
+
32
+ ```ts
33
+ import DocumentIntelligence from "@azure-rest/ai-document-intelligence";
34
+ import { streamToUint8Array } from "@azure-rest/ai-document-intelligence";
35
+
36
+ const client = DocumentIntelligence("<DOCUMENT_INTELLIGENCE_ENDPOINT>", {
37
+ key: "<DOCUMENT_INTELLIGENCE_API_KEY>",
38
+ });
39
+
40
+ // Do analysis on you document and get the resultId, figureId
41
+
42
+ // Example for the figures api that provides an image output
43
+ const output = await client
44
+ .path(
45
+ "/documentModels/{modelId}/analyzeResults/{resultId}/figures/{figureId}",
46
+ "prebuilt-layout",
47
+ resultId,
48
+ figureId,
49
+ )
50
+ .get()
51
+ .asNodeStream(); // output.body would be NodeJS.ReadableStream
52
+
53
+ if (output.status !== "200" || !output.body) {
54
+ throw new Error("The response was unexpected, expected NodeJS.ReadableStream in the body.");
55
+ }
56
+
57
+ const imageData = await streamToUint8Array(output.body);
58
+ fs.promises.writeFile(`./figures/${figureId}.png`, imageData); // Or you can consume the NodeJS.ReadableStream directly
59
+ ```
60
+
61
+ - Adds `parseResultIdFromResponse`, a convenience function that extracts the `operationId` from the batch analysis response.
62
+
63
+ ```js
64
+ // Example
65
+ const initialResponse = await client
66
+ .path("/documentModels/{modelId}:analyzeBatch", "prebuilt-layout")
67
+ .post({
68
+ contentType: "application/json",
69
+ body: {
70
+ azureBlobSource: {
71
+ containerUrl: batchTrainingFilesContainerUrl(),
72
+ },
73
+ resultContainerUrl: batchTrainingFilesResultContainerUrl(),
74
+ resultPrefix: "result",
75
+ },
76
+ });
77
+
78
+ if (isUnexpected(initialResponse)) {
79
+ throw initialResponse.body.error;
80
+ }
81
+ const batchResultId = parseResultIdFromResponse(initialResponse);
82
+
83
+ const response = await client
84
+ .path(
85
+ "/documentModels/{modelId}/analyzeBatchResults/{resultId}",
86
+ "prebuilt-layout",
87
+ batchResultId,
88
+ )
89
+ .get();
90
+ ```
91
+
92
+ - Changes the following interfaces as follows:
93
+
94
+ - `AnalyzeBatchDocumentsBodyParam`:
95
+ - Updates `body` to be required.
96
+ - `AnalyzeBatchOperationOutput`:
97
+ - Adds `resultId`.
98
+ - `AnalyzeDocumentBodyParam`:
99
+ - Changes `body` from optional to required.
100
+ - `DocumentClassifierDetailsOutput`:
101
+ - Adds `modifiedDateTime`.
102
+ - `DocumentModelDetailsOutput`:
103
+ - Adds `modifiedDateTime`.
104
+
105
+ - Introduces new interfaces to define query parameters for document analysis requests, allowing customizable `style` and `explode` options:
106
+ - **AnalyzeBatchDocumentsFeaturesQueryParam**: Accepts DocumentAnalysisFeature[] values.
107
+ - **AnalyzeBatchDocumentsOutputQueryParam**: Accepts AnalyzeOutputOption[] values.
108
+ - **AnalyzeBatchDocumentsQueryFieldsQueryParam**: Accepts string[] values.
109
+ - **AnalyzeDocumentFeaturesQueryParam**: Accepts DocumentAnalysisFeature[] values.
110
+ - **AnalyzeDocumentFromStreamFeaturesQueryParam**: Accepts DocumentAnalysisFeature[] values.
111
+
112
+ ### Breaking Changes
113
+
114
+ - Removes the `poller.getOperationId()` for a given polling operation. Use `parseResultIdFromResponse` to extract the `operationId` directly.
115
+ - `getLongRunningPoller` function is not async anymore, do not `await` on it.
116
+
117
+ ### Other Changes
118
+
119
+ The following types are renamed
120
+
121
+ - `CopyAuthorization` to `ModelCopyAuthorization`
122
+ - `ErrorResponseOutput` to `DocumentIntelligenceErrorResponseOutput`
123
+ - `ErrorModelOutput` to `DocumentIntelligenceErrorOutput`
124
+ - `InnerErrorOutput` to `DocumentIntelligenceInnerErrorOutput`
125
+ - `WarningOutput` to `DocumentIntelligenceWarningOutput`
126
+ - `ContentFormat` to `DocumentContentFormat`
127
+ - `ContentFormatOutput` to `DocumentContentFormatOutput`
128
+ - `OperationDetailsOutputParent` to `DocumentIntelligenceOperationDetailsOutputParent`
129
+ - `OperationDetailsOutput` to `DocumentIntelligenceOperationDetailsOutput`
130
+ - `OperationStatusOutput` to `DocumentIntelligenceOperationStatusOutput`
131
+ - `ResourceDetailsOutput` to `DocumentIntelligenceResourceDetailsOutput`
132
+ - `PagedOperationDetailsOutput` to `PagedDocumentIntelligenceOperationDetailsOutput`
133
+ - `GetResourceInfo` to `GetResourceDetails`
134
+ - `AnalyzeResultOperationOutput` to `AnalyzeOperationOutput`
135
+ - `FontWeightOutput` to `DocumentFontWeightOutput`
136
+ - `FontStyleOutput` to `DocumentFontStyleOutput`
137
+ - `DocumentOutput` to `AnalyzedDocumentOutput`
138
+ - `CopyAuthorizationOutput` to `ModelCopyAuthorizationOutput`
139
+
3
140
  ## 1.0.0-beta.3 (2024-08-20)
4
141
 
5
142
  ### Features Added
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
- The MIT License (MIT)
1
+ Copyright (c) Microsoft Corporation.
2
2
 
3
- Copyright (c) 2024 Microsoft
3
+ MIT License
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -12,10 +12,10 @@ furnished to do so, subject to the following conditions:
12
12
  The above copyright notice and this permission notice shall be included in all
13
13
  copies or substantial portions of the Software.
14
14
 
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
16
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
17
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
package/README.md CHANGED
@@ -10,32 +10,28 @@ Key links:
10
10
 
11
11
  - [Source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/documentintelligence/ai-document-intelligence-rest)
12
12
  - [Package (NPM)](https://www.npmjs.com/package/@azure-rest/ai-document-intelligence)
13
- - [API reference documentation](https://docs.microsoft.com/javascript/api/@azure-rest/ai-document-intelligence?view=azure-node-preview)
13
+ - [API reference documentation](https://learn.microsoft.com/javascript/api/@azure-rest/ai-document-intelligence?view=azure-node-preview)
14
14
  - [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/documentintelligence/ai-document-intelligence-rest/samples)
15
15
  - [Changelog](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/documentintelligence/ai-document-intelligence-rest/CHANGELOG.md)
16
16
  - [Migration Guide from Form Recognizer](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/documentintelligence/ai-document-intelligence-rest/MIGRATION-FR_v4-DI_v1.md)
17
17
 
18
- > This version of the client library defaults to the `"2024-07-31-preview"` version of the service.
18
+ > This version of the client library defaults to the `"2024-11-30"` version of the service.
19
19
 
20
20
  This table shows the relationship between SDK versions and supported API versions of the service:
21
21
 
22
- | SDK version | Supported API version of service |
23
- | ------------ | -------------------------------- |
24
- | 1.0.0-beta.3 | 2024-07-31-preview |
25
- | 1.0.0-beta.2 | 2024-02-29-preview |
26
- | 1.0.0-beta.1 | 2023-10-31-preview |
22
+ | SDK version | Supported API version of service |
23
+ | ----------- | -------------------------------- |
24
+ | 1.0.0 | 2024-11-30 |
27
25
 
28
26
  > Please rely on the older `@azure/ai-form-recognizer` library through the older service API versions for retired models, such as `"prebuilt-businessCard"` and `"prebuilt-document"`. For more information, see [Changelog](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/documentintelligence/ai-document-intelligence-rest/CHANGELOG.md).
29
27
 
30
28
  The below table describes the relationship of each client and its supported API version(s):
31
29
 
32
- | Service API version | Supported clients | Package |
33
- | ------------------- | ------------------------------------------------------------ | ------------------------------------------------------------- |
34
- | 2024-07-31-preview | DocumentIntelligenceClient | `@azure-rest/ai-document-intelligence` version `1.0.0-beta.3` |
35
- | 2024-02-29-preview | DocumentIntelligenceClient | `@azure-rest/ai-document-intelligence` version `1.0.0-beta.2` |
36
- | 2023-10-31-preview | DocumentIntelligenceClient | `@azure-rest/ai-document-intelligence` version `1.0.0-beta.1` |
37
- | 2023-07-31 | DocumentAnalysisClient and DocumentModelAdministrationClient | `@azure/ai-form-recognizer` version `^5.0.0` |
38
- | 2022-08-01 | DocumentAnalysisClient and DocumentModelAdministrationClient | `@azure/ai-form-recognizer` version `^4.0.0` |
30
+ | Service API version | Supported clients | Package |
31
+ | ------------------- | ------------------------------------------------------------ | ------------------------------------------------------ |
32
+ | 2024-11-30 | DocumentIntelligenceClient | `@azure-rest/ai-document-intelligence` version `^1.0.0` |
33
+ | 2023-07-31 | DocumentAnalysisClient and DocumentModelAdministrationClient | `@azure/ai-form-recognizer` version `^5.0.0` |
34
+ | 2022-08-01 | DocumentAnalysisClient and DocumentModelAdministrationClient | `@azure/ai-form-recognizer` version `^4.0.0` |
39
35
 
40
36
  ## Getting started
41
37
 
@@ -72,8 +68,9 @@ AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
72
68
 
73
69
  ### Using a Token Credential
74
70
 
75
- ```ts
71
+ ```ts snippet:ReadmeSampleCreateClient_TokenCredential
76
72
  import DocumentIntelligence from "@azure-rest/ai-document-intelligence";
73
+ import { DefaultAzureCredential } from "@azure/identity";
77
74
 
78
75
  const client = DocumentIntelligence(
79
76
  process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"],
@@ -83,7 +80,7 @@ const client = DocumentIntelligence(
83
80
 
84
81
  ### Using an API KEY
85
82
 
86
- ```ts
83
+ ```ts snippet:ReadmeSampleCreateClient_APIKey
87
84
  import DocumentIntelligence from "@azure-rest/ai-document-intelligence";
88
85
 
89
86
  const client = DocumentIntelligence(process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"], {
@@ -91,11 +88,41 @@ const client = DocumentIntelligence(process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"
91
88
  });
92
89
  ```
93
90
 
91
+ ### Sovereign Clouds
92
+
93
+ Connect to alternative Azure cloud environments (such as Azure China or Azure Government) by specifying the `scopes` field in the `credentials` option and use the appropriate value from `KnownDocumentIntelligenceAudience`.
94
+
95
+ ```ts
96
+ import DocumentIntelligence, { KnownDocumentIntelligenceAudience } from "@azure-rest/ai-document-intelligence";
97
+ import { DefaultAzureCredential } from "@azure/identity";
98
+
99
+ const client = DocumentIntelligence(
100
+ process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"],
101
+ new DefaultAzureCredential(),
102
+ {
103
+ credentials: {
104
+ // Use the correct audience for your cloud environment
105
+ scopes: [KnownDocumentIntelligenceAudience.AzureGovernment]
106
+ }
107
+ }
108
+ );
109
+ ```
110
+
111
+ If you do not specify `scopes`, the client will default to the Azure Public Cloud (`https://cognitiveservices.azure.com`).
112
+
94
113
  ## Document Models
95
114
 
96
115
  ### Analyze prebuilt-layout (urlSource)
97
116
 
98
- ```ts
117
+ ```ts snippet:ReadmeSampleAnalyzePrebuiltLayoutUrlSource
118
+ import DocumentIntelligence from "@azure-rest/ai-document-intelligence";
119
+ import { DefaultAzureCredential } from "@azure/identity";
120
+
121
+ const client = DocumentIntelligence(
122
+ process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"],
123
+ new DefaultAzureCredential(),
124
+ );
125
+
99
126
  const initialResponse = await client
100
127
  .path("/documentModels/{modelId}:analyze", "prebuilt-layout")
101
128
  .post({
@@ -110,12 +137,23 @@ const initialResponse = await client
110
137
 
111
138
  ### Analyze prebuilt-layout (base64Source)
112
139
 
113
- ```ts
114
- import fs from "fs";
115
- import path from "path";
140
+ ```ts snippet:ReadmeSampleAnalyzePrebuiltLayoutBase64Source
141
+ import DocumentIntelligence, {
142
+ isUnexpected,
143
+ getLongRunningPoller,
144
+ AnalyzeOperationOutput,
145
+ } from "@azure-rest/ai-document-intelligence";
146
+ import { DefaultAzureCredential } from "@azure/identity";
147
+ import { join } from "node:path";
148
+ import { readFile } from "node:fs/promises";
149
+
150
+ const client = DocumentIntelligence(
151
+ process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"],
152
+ new DefaultAzureCredential(),
153
+ );
116
154
 
117
- const filePath = path.join(ASSET_PATH, "forms", "Invoice_1.pdf");
118
- const base64Source = fs.readFileSync(filePath, { encoding: "base64" });
155
+ const filePath = join("./assets", "forms", "Invoice_1.pdf");
156
+ const base64Source = await readFile(filePath, { encoding: "base64" });
119
157
  const initialResponse = await client
120
158
  .path("/documentModels/{modelId}:analyze", "prebuilt-layout")
121
159
  .post({
@@ -125,35 +163,61 @@ const initialResponse = await client
125
163
  },
126
164
  queryParameters: { locale: "en-IN" },
127
165
  });
166
+
167
+ if (isUnexpected(initialResponse)) {
168
+ throw initialResponse.body.error;
169
+ }
170
+
171
+ const poller = getLongRunningPoller(client, initialResponse);
172
+ const result = (await poller.pollUntilDone()).body as AnalyzeOperationOutput;
173
+ console.log(result);
128
174
  ```
129
175
 
130
- Continue creating the poller from initial response
176
+ ## Batch analysis
131
177
 
132
- ```ts
133
- import {
134
- getLongRunningPoller,
135
- AnalyzeResultOperationOutput,
178
+ ```ts snippet:ReadmeSampleAnalyzeBatch
179
+ import DocumentIntelligence, {
136
180
  isUnexpected,
181
+ parseResultIdFromResponse,
137
182
  } from "@azure-rest/ai-document-intelligence";
183
+ import { DefaultAzureCredential } from "@azure/identity";
184
+
185
+ const client = DocumentIntelligence(
186
+ process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"],
187
+ new DefaultAzureCredential(),
188
+ );
189
+
190
+ // 1. Analyze a batch of documents
191
+ const initialResponse = await client
192
+ .path("/documentModels/{modelId}:analyzeBatch", "prebuilt-layout")
193
+ .post({
194
+ contentType: "application/json",
195
+ body: {
196
+ azureBlobSource: {
197
+ containerUrl: process.env["DOCUMENT_INTELLIGENCE_BATCH_TRAINING_DATA_CONTAINER_SAS_URL"],
198
+ },
199
+ resultContainerUrl:
200
+ process.env["DOCUMENT_INTELLIGENCE_BATCH_TRAINING_DATA_RESULT_CONTAINER_SAS_URL"],
201
+ resultPrefix: "result",
202
+ },
203
+ });
138
204
 
139
205
  if (isUnexpected(initialResponse)) {
140
206
  throw initialResponse.body.error;
141
207
  }
142
- const poller = await getLongRunningPoller(client, initialResponse);
143
- const result = (await poller.pollUntilDone()).body as AnalyzeResultOperationOutput;
144
- console.log(result);
145
- // {
146
- // status: 'succeeded',
147
- // createdDateTime: '2023-11-10T13:31:31Z',
148
- // lastUpdatedDateTime: '2023-11-10T13:31:34Z',
149
- // analyzeResult: {
150
- // apiVersion: '2023-10-31-preview',
151
- // .
152
- // .
153
- // .
154
- // contentFormat: 'text'
155
- // }
156
- // }
208
+
209
+ const resultId = parseResultIdFromResponse(initialResponse);
210
+ console.log("resultId: ", resultId);
211
+
212
+ // (Optional) You can poll for the batch analysis result but be aware that a job may take unexpectedly long time, and polling could incur additional costs.
213
+ // const poller = getLongRunningPoller(client, initialResponse);
214
+ // await poller.pollUntilDone();
215
+
216
+ // 2. At a later time, you can retrieve the operation result using the resultId
217
+ const output = await client
218
+ .path("/documentModels/{modelId}/analyzeResults/{resultId}", "prebuilt-layout", resultId)
219
+ .get();
220
+ console.log(output);
157
221
  ```
158
222
 
159
223
  ### Markdown content format
@@ -162,11 +226,14 @@ Supports output with Markdown content format along with the default plain _text_
162
226
 
163
227
  Service follows the GFM spec ([GitHub Flavored Markdown](https://github.github.com/gfm/)) for the Markdown format. Also introduces a new _contentFormat_ property with value "text" or "markdown" to indicate the result content format.
164
228
 
165
- ```ts
229
+ ```ts snippet:ReadmeSampleAnalyzeMarkdownContentFormat
166
230
  import DocumentIntelligence from "@azure-rest/ai-document-intelligence";
167
- const client = DocumentIntelligence(process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"], {
168
- key: process.env["DOCUMENT_INTELLIGENCE_API_KEY"],
169
- });
231
+ import { DefaultAzureCredential } from "@azure/identity";
232
+
233
+ const client = DocumentIntelligence(
234
+ process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"],
235
+ new DefaultAzureCredential(),
236
+ );
170
237
 
171
238
  const initialResponse = await client
172
239
  .path("/documentModels/{modelId}:analyze", "prebuilt-layout")
@@ -184,7 +251,15 @@ const initialResponse = await client
184
251
 
185
252
  When this feature flag is specified, the service will further extract the values of the fields specified via the queryFields query parameter to supplement any existing fields defined by the model as fallback.
186
253
 
187
- ```ts
254
+ ```ts snippet:ReadmeSampleAnalyzeQueryFields
255
+ import DocumentIntelligence from "@azure-rest/ai-document-intelligence";
256
+ import { DefaultAzureCredential } from "@azure/identity";
257
+
258
+ const client = DocumentIntelligence(
259
+ process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"],
260
+ new DefaultAzureCredential(),
261
+ );
262
+
188
263
  await client.path("/documentModels/{modelId}:analyze", "prebuilt-layout").post({
189
264
  contentType: "application/json",
190
265
  body: { urlSource: "..." },
@@ -215,18 +290,24 @@ To enable a wider set of scenarios, service introduces a "split" query parameter
215
290
 
216
291
  ## Document Classifiers #Build
217
292
 
218
- ```ts
219
- import {
220
- DocumentClassifierBuildOperationDetailsOutput,
221
- getLongRunningPoller,
293
+ ```ts snippet:ReadmeSampleDocumentClassifierBuild
294
+ import DocumentIntelligence, {
222
295
  isUnexpected,
296
+ getLongRunningPoller,
297
+ DocumentClassifierBuildOperationDetailsOutput,
223
298
  } from "@azure-rest/ai-document-intelligence";
299
+ import { DefaultAzureCredential } from "@azure/identity";
300
+
301
+ const client = DocumentIntelligence(
302
+ process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"],
303
+ new DefaultAzureCredential(),
304
+ );
224
305
 
225
306
  const containerSasUrl = (): string =>
226
307
  process.env["DOCUMENT_INTELLIGENCE_TRAINING_CONTAINER_SAS_URL"];
227
308
  const initialResponse = await client.path("/documentClassifiers:build").post({
228
309
  body: {
229
- classifierId: `customClassifier${getRandomNumber()}`,
310
+ classifierId: `customClassifier-12345`,
230
311
  description: "Custom classifier description",
231
312
  docTypes: {
232
313
  foo: {
@@ -246,48 +327,166 @@ const initialResponse = await client.path("/documentClassifiers:build").post({
246
327
  if (isUnexpected(initialResponse)) {
247
328
  throw initialResponse.body.error;
248
329
  }
249
- const poller = await getLongRunningPoller(client, initialResponse);
330
+
331
+ const poller = getLongRunningPoller(client, initialResponse);
250
332
  const response = (await poller.pollUntilDone())
251
333
  .body as DocumentClassifierBuildOperationDetailsOutput;
252
334
  console.log(response);
253
- // {
254
- // operationId: '31466834048_f3ee629e-73fb-48ab-993b-1d55d73ca460',
255
- // kind: 'documentClassifierBuild',
256
- // status: 'succeeded',
257
- // .
258
- // .
259
- // result: {
260
- // classifierId: 'customClassifier10978',
261
- // createdDateTime: '2023-11-09T12:45:56Z',
262
- // .
263
- // .
264
- // description: 'Custom classifier description'
265
- // },
266
- // apiVersion: '2023-10-31-preview'
267
- // }
335
+ ```
336
+
337
+ ## Get the generated PDF output from document analysis
338
+
339
+ ```ts snippet:ReadmeSampleGetPdfOutput
340
+ import DocumentIntelligence, {
341
+ isUnexpected,
342
+ getLongRunningPoller,
343
+ parseResultIdFromResponse,
344
+ streamToUint8Array,
345
+ } from "@azure-rest/ai-document-intelligence";
346
+ import { DefaultAzureCredential } from "@azure/identity";
347
+ import { join } from "node:path";
348
+ import { readFile, writeFile } from "node:fs/promises";
349
+
350
+ const client = DocumentIntelligence(
351
+ process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"],
352
+ new DefaultAzureCredential(),
353
+ );
354
+
355
+ const filePath = join("./assets", "layout-pageobject.pdf");
356
+
357
+ const base64Source = await readFile(filePath, { encoding: "base64" });
358
+
359
+ const initialResponse = await client
360
+ .path("/documentModels/{modelId}:analyze", "prebuilt-read")
361
+ .post({
362
+ contentType: "application/json",
363
+ body: {
364
+ base64Source,
365
+ },
366
+ queryParameters: { output: ["pdf"] },
367
+ });
368
+
369
+ if (isUnexpected(initialResponse)) {
370
+ throw initialResponse.body.error;
371
+ }
372
+
373
+ const poller = getLongRunningPoller(client, initialResponse);
374
+
375
+ await poller.pollUntilDone();
376
+
377
+ const output = await client
378
+ .path(
379
+ "/documentModels/{modelId}/analyzeResults/{resultId}/pdf",
380
+ "prebuilt-read",
381
+ parseResultIdFromResponse(initialResponse),
382
+ )
383
+ .get()
384
+ .asNodeStream(); // output.body would be NodeJS.ReadableStream
385
+
386
+ if (output.status !== "200" || !output.body) {
387
+ throw new Error("The response was unexpected, expected NodeJS.ReadableStream in the body.");
388
+ }
389
+
390
+ const pdfData = await streamToUint8Array(output.body);
391
+ await writeFile(`./output.pdf`, pdfData);
392
+ ```
393
+
394
+ ## Get the generated cropped image of specified figure from document analysis
395
+
396
+ ```ts snippet:ReadmeSampleGetFigureImage
397
+ import DocumentIntelligence, {
398
+ isUnexpected,
399
+ getLongRunningPoller,
400
+ AnalyzeOperationOutput,
401
+ parseResultIdFromResponse,
402
+ streamToUint8Array,
403
+ } from "@azure-rest/ai-document-intelligence";
404
+ import { DefaultAzureCredential } from "@azure/identity";
405
+ import { join } from "node:path";
406
+ import { readFile, writeFile } from "node:fs/promises";
407
+
408
+ const client = DocumentIntelligence(
409
+ process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"],
410
+ new DefaultAzureCredential(),
411
+ );
412
+
413
+ const filePath = join("./assets", "layout-pageobject.pdf");
414
+
415
+ const base64Source = await readFile(filePath, { encoding: "base64" });
416
+
417
+ const initialResponse = await client
418
+ .path("/documentModels/{modelId}:analyze", "prebuilt-layout")
419
+ .post({
420
+ contentType: "application/json",
421
+ body: {
422
+ base64Source,
423
+ },
424
+ queryParameters: { output: ["figures"] },
425
+ });
426
+
427
+ if (isUnexpected(initialResponse)) {
428
+ throw initialResponse.body.error;
429
+ }
430
+
431
+ const poller = getLongRunningPoller(client, initialResponse);
432
+
433
+ const result = (await poller.pollUntilDone()).body as AnalyzeOperationOutput;
434
+ const figures = result.analyzeResult?.figures;
435
+ const figureId = figures?.[0].id || "";
436
+
437
+ const output = await client
438
+ .path(
439
+ "/documentModels/{modelId}/analyzeResults/{resultId}/figures/{figureId}",
440
+ "prebuilt-layout",
441
+ parseResultIdFromResponse(initialResponse),
442
+ figureId,
443
+ )
444
+ .get()
445
+ .asNodeStream(); // output.body would be NodeJS.ReadableStream
446
+
447
+ if (output.status !== "200" || !output.body) {
448
+ throw new Error("The response was unexpected, expected NodeJS.ReadableStream in the body.");
449
+ }
450
+
451
+ const imageData = await streamToUint8Array(output.body);
452
+ await writeFile(`./figures/${figureId}.png`, imageData);
268
453
  ```
269
454
 
270
455
  ## Get Info
271
456
 
272
- ```ts
457
+ ```ts snippet:ReadmeSampleGetInfo
458
+ import DocumentIntelligence, { isUnexpected } from "@azure-rest/ai-document-intelligence";
459
+ import { DefaultAzureCredential } from "@azure/identity";
460
+
461
+ const client = DocumentIntelligence(
462
+ process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"],
463
+ new DefaultAzureCredential(),
464
+ );
465
+
273
466
  const response = await client.path("/info").get();
274
467
  if (isUnexpected(response)) {
275
468
  throw response.body.error;
276
469
  }
470
+
277
471
  console.log(response.body.customDocumentModels.limit);
278
- // 20000
279
472
  ```
280
473
 
281
474
  ## List Document Models
282
475
 
283
- ```ts
284
- import { paginate } from "@azure-rest/ai-document-intelligence";
476
+ ```ts snippet:ReadmeSampleListDocumentModels
477
+ import DocumentIntelligence, { isUnexpected, paginate } from "@azure-rest/ai-document-intelligence";
478
+ import { DefaultAzureCredential } from "@azure/identity";
479
+
480
+ const client = DocumentIntelligence(
481
+ process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"],
482
+ new DefaultAzureCredential(),
483
+ );
484
+
285
485
  const response = await client.path("/documentModels").get();
286
486
  if (isUnexpected(response)) {
287
487
  throw response.body.error;
288
488
  }
289
489
 
290
- const modelsInAccount: string[] = [];
291
490
  for await (const model of paginate(client, response)) {
292
491
  console.log(model.modelId);
293
492
  }
@@ -299,8 +498,8 @@ for await (const model of paginate(client, response)) {
299
498
 
300
499
  Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
301
500
 
302
- ```javascript
303
- const { setLogLevel } = require("@azure/logger");
501
+ ```ts snippet:SetLogLevel
502
+ import { setLogLevel } from "@azure/logger";
304
503
 
305
504
  setLogLevel("info");
306
505
  ```
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Defines the known cloud audiences for Document Intelligence.
3
+ *
4
+ * To authenticate with Entra Id (using a `TokenCredential`) in a [Sovereign Cloud](https://learn.microsoft.com/en-us/entra/identity-platform/authentication-national-cloud)
5
+ * environment, provide the appropriate value below as the `audience` option when creating a
6
+ * `Document Intelligence` client.
7
+ *
8
+ * The default value is suitable for Document Intelligence resources created in the Azure Public Cloud, so this value
9
+ * is only required to use Document Intelligence in a different cloud environment.
10
+ */
11
+ export declare enum KnownDocumentIntelligenceAudience {
12
+ /** Azure China */
13
+ AzureChina = "https://cognitiveservices.azure.cn",
14
+ /** Azure Government */
15
+ AzureGovernment = "https://cognitiveservices.azure.us",
16
+ /** Azure Public Cloud */
17
+ AzurePublicCloud = "https://cognitiveservices.azure.com"
18
+ }
19
+ //# sourceMappingURL=audience.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audience.d.ts","sourceRoot":"","sources":["../../src/audience.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,oBAAY,iCAAiC;IAC3C,kBAAkB;IAClB,UAAU,uCAAuC;IACjD,uBAAuB;IACvB,eAAe,uCAAuC;IACtD,yBAAyB;IACzB,gBAAgB,wCAAwC;CACzD"}