@azure-rest/ai-document-intelligence 1.0.0 → 1.1.0
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/CHANGELOG.md +30 -2
- package/LICENSE +4 -4
- package/README.md +169 -94
- package/dist/browser/audience.d.ts +19 -0
- package/dist/browser/audience.d.ts.map +1 -0
- package/dist/browser/audience.js +22 -0
- package/dist/browser/audience.js.map +1 -0
- package/dist/browser/documentIntelligence.d.ts.map +1 -1
- package/dist/browser/documentIntelligence.js +7 -2
- package/dist/browser/documentIntelligence.js.map +1 -1
- package/dist/browser/index.d.ts +1 -0
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +1 -0
- package/dist/browser/index.js.map +1 -1
- package/dist/commonjs/audience.d.ts +19 -0
- package/dist/commonjs/audience.d.ts.map +1 -0
- package/dist/commonjs/audience.js +25 -0
- package/dist/commonjs/audience.js.map +1 -0
- package/dist/commonjs/documentIntelligence.d.ts.map +1 -1
- package/dist/commonjs/documentIntelligence.js +7 -2
- package/dist/commonjs/documentIntelligence.js.map +1 -1
- package/dist/commonjs/index.d.ts +1 -0
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +3 -0
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +1 -1
- package/dist/esm/audience.d.ts +19 -0
- package/dist/esm/audience.d.ts.map +1 -0
- package/dist/esm/audience.js +22 -0
- package/dist/esm/audience.js.map +1 -0
- package/dist/esm/documentIntelligence.d.ts.map +1 -1
- package/dist/esm/documentIntelligence.js +7 -2
- package/dist/esm/documentIntelligence.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/react-native/audience.d.ts +19 -0
- package/dist/react-native/audience.d.ts.map +1 -0
- package/dist/react-native/audience.js +22 -0
- package/dist/react-native/audience.js.map +1 -0
- package/dist/react-native/documentIntelligence.d.ts.map +1 -1
- package/dist/react-native/documentIntelligence.js +7 -2
- package/dist/react-native/documentIntelligence.js.map +1 -1
- package/dist/react-native/index.d.ts +1 -0
- package/dist/react-native/index.d.ts.map +1 -1
- package/dist/react-native/index.js +1 -0
- package/dist/react-native/index.js.map +1 -1
- package/package.json +34 -38
- package/review/ai-document-intelligence.api.md +7 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
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
|
+
|
|
3
26
|
## 1.0.0 (2024-12-16)
|
|
4
27
|
|
|
5
28
|
### Features Added
|
|
@@ -22,7 +45,7 @@
|
|
|
22
45
|
"/documentModels/{modelId}/analyzeResults/{resultId}/figures/{figureId}",
|
|
23
46
|
"prebuilt-layout",
|
|
24
47
|
resultId,
|
|
25
|
-
figureId
|
|
48
|
+
figureId,
|
|
26
49
|
)
|
|
27
50
|
.get()
|
|
28
51
|
.asNodeStream(); // output.body would be NodeJS.ReadableStream
|
|
@@ -61,7 +84,7 @@
|
|
|
61
84
|
.path(
|
|
62
85
|
"/documentModels/{modelId}/analyzeBatchResults/{resultId}",
|
|
63
86
|
"prebuilt-layout",
|
|
64
|
-
batchResultId
|
|
87
|
+
batchResultId,
|
|
65
88
|
)
|
|
66
89
|
.get();
|
|
67
90
|
```
|
|
@@ -108,6 +131,11 @@ The following types are renamed
|
|
|
108
131
|
- `ResourceDetailsOutput` to `DocumentIntelligenceResourceDetailsOutput`
|
|
109
132
|
- `PagedOperationDetailsOutput` to `PagedDocumentIntelligenceOperationDetailsOutput`
|
|
110
133
|
- `GetResourceInfo` to `GetResourceDetails`
|
|
134
|
+
- `AnalyzeResultOperationOutput` to `AnalyzeOperationOutput`
|
|
135
|
+
- `FontWeightOutput` to `DocumentFontWeightOutput`
|
|
136
|
+
- `FontStyleOutput` to `DocumentFontStyleOutput`
|
|
137
|
+
- `DocumentOutput` to `AnalyzedDocumentOutput`
|
|
138
|
+
- `CopyAuthorizationOutput` to `ModelCopyAuthorizationOutput`
|
|
111
139
|
|
|
112
140
|
## 1.0.0-beta.3 (2024-08-20)
|
|
113
141
|
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
Copyright (c) Microsoft Corporation.
|
|
2
2
|
|
|
3
|
-
|
|
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
|
|
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,7 +10,7 @@ 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://
|
|
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)
|
|
@@ -19,19 +19,19 @@ Key links:
|
|
|
19
19
|
|
|
20
20
|
This table shows the relationship between SDK versions and supported API versions of the service:
|
|
21
21
|
|
|
22
|
-
| SDK version
|
|
23
|
-
|
|
|
24
|
-
| 1.0.0
|
|
22
|
+
| SDK version | Supported API version of service |
|
|
23
|
+
| ----------- | -------------------------------- |
|
|
24
|
+
| 1.0.0 | 2024-11-30 |
|
|
25
25
|
|
|
26
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).
|
|
27
27
|
|
|
28
28
|
The below table describes the relationship of each client and its supported API version(s):
|
|
29
29
|
|
|
30
|
-
| Service API version | Supported clients | Package
|
|
31
|
-
| ------------------- | ------------------------------------------------------------ |
|
|
32
|
-
| 2024-11-30 | DocumentIntelligenceClient | `@azure-rest/ai-document-intelligence` version
|
|
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`
|
|
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` |
|
|
35
35
|
|
|
36
36
|
## Getting started
|
|
37
37
|
|
|
@@ -68,18 +68,19 @@ AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
|
|
|
68
68
|
|
|
69
69
|
### Using a Token Credential
|
|
70
70
|
|
|
71
|
-
```ts
|
|
71
|
+
```ts snippet:ReadmeSampleCreateClient_TokenCredential
|
|
72
72
|
import DocumentIntelligence from "@azure-rest/ai-document-intelligence";
|
|
73
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
73
74
|
|
|
74
75
|
const client = DocumentIntelligence(
|
|
75
76
|
process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"],
|
|
76
|
-
new DefaultAzureCredential()
|
|
77
|
+
new DefaultAzureCredential(),
|
|
77
78
|
);
|
|
78
79
|
```
|
|
79
80
|
|
|
80
81
|
### Using an API KEY
|
|
81
82
|
|
|
82
|
-
```ts
|
|
83
|
+
```ts snippet:ReadmeSampleCreateClient_APIKey
|
|
83
84
|
import DocumentIntelligence from "@azure-rest/ai-document-intelligence";
|
|
84
85
|
|
|
85
86
|
const client = DocumentIntelligence(process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"], {
|
|
@@ -87,11 +88,41 @@ const client = DocumentIntelligence(process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"
|
|
|
87
88
|
});
|
|
88
89
|
```
|
|
89
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
|
+
|
|
90
113
|
## Document Models
|
|
91
114
|
|
|
92
115
|
### Analyze prebuilt-layout (urlSource)
|
|
93
116
|
|
|
94
|
-
```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
|
+
|
|
95
126
|
const initialResponse = await client
|
|
96
127
|
.path("/documentModels/{modelId}:analyze", "prebuilt-layout")
|
|
97
128
|
.post({
|
|
@@ -106,12 +137,23 @@ const initialResponse = await client
|
|
|
106
137
|
|
|
107
138
|
### Analyze prebuilt-layout (base64Source)
|
|
108
139
|
|
|
109
|
-
```ts
|
|
110
|
-
import
|
|
111
|
-
|
|
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";
|
|
112
149
|
|
|
113
|
-
const
|
|
114
|
-
|
|
150
|
+
const client = DocumentIntelligence(
|
|
151
|
+
process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"],
|
|
152
|
+
new DefaultAzureCredential(),
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
const filePath = join("./assets", "forms", "Invoice_1.pdf");
|
|
156
|
+
const base64Source = await readFile(filePath, { encoding: "base64" });
|
|
115
157
|
const initialResponse = await client
|
|
116
158
|
.path("/documentModels/{modelId}:analyze", "prebuilt-layout")
|
|
117
159
|
.post({
|
|
@@ -121,41 +163,29 @@ const initialResponse = await client
|
|
|
121
163
|
},
|
|
122
164
|
queryParameters: { locale: "en-IN" },
|
|
123
165
|
});
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
Continue creating the poller from initial response
|
|
127
|
-
|
|
128
|
-
```ts
|
|
129
|
-
import {
|
|
130
|
-
getLongRunningPoller,
|
|
131
|
-
AnalyzeResultOperationOutput,
|
|
132
|
-
isUnexpected,
|
|
133
|
-
} from "@azure-rest/ai-document-intelligence";
|
|
134
166
|
|
|
135
167
|
if (isUnexpected(initialResponse)) {
|
|
136
168
|
throw initialResponse.body.error;
|
|
137
169
|
}
|
|
170
|
+
|
|
138
171
|
const poller = getLongRunningPoller(client, initialResponse);
|
|
139
|
-
const result = (await poller.pollUntilDone()).body as
|
|
172
|
+
const result = (await poller.pollUntilDone()).body as AnalyzeOperationOutput;
|
|
140
173
|
console.log(result);
|
|
141
|
-
// {
|
|
142
|
-
// status: 'succeeded',
|
|
143
|
-
// createdDateTime: '2023-11-10T13:31:31Z',
|
|
144
|
-
// lastUpdatedDateTime: '2023-11-10T13:31:34Z',
|
|
145
|
-
// analyzeResult: {
|
|
146
|
-
// apiVersion: '2023-10-31-preview',
|
|
147
|
-
// .
|
|
148
|
-
// .
|
|
149
|
-
// .
|
|
150
|
-
// contentFormat: 'text'
|
|
151
|
-
// }
|
|
152
|
-
// }
|
|
153
174
|
```
|
|
154
175
|
|
|
155
176
|
## Batch analysis
|
|
156
177
|
|
|
157
|
-
```ts
|
|
158
|
-
import
|
|
178
|
+
```ts snippet:ReadmeSampleAnalyzeBatch
|
|
179
|
+
import DocumentIntelligence, {
|
|
180
|
+
isUnexpected,
|
|
181
|
+
parseResultIdFromResponse,
|
|
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
|
+
);
|
|
159
189
|
|
|
160
190
|
// 1. Analyze a batch of documents
|
|
161
191
|
const initialResponse = await client
|
|
@@ -164,9 +194,10 @@ const initialResponse = await client
|
|
|
164
194
|
contentType: "application/json",
|
|
165
195
|
body: {
|
|
166
196
|
azureBlobSource: {
|
|
167
|
-
containerUrl:
|
|
197
|
+
containerUrl: process.env["DOCUMENT_INTELLIGENCE_BATCH_TRAINING_DATA_CONTAINER_SAS_URL"],
|
|
168
198
|
},
|
|
169
|
-
resultContainerUrl:
|
|
199
|
+
resultContainerUrl:
|
|
200
|
+
process.env["DOCUMENT_INTELLIGENCE_BATCH_TRAINING_DATA_RESULT_CONTAINER_SAS_URL"],
|
|
170
201
|
resultPrefix: "result",
|
|
171
202
|
},
|
|
172
203
|
});
|
|
@@ -174,6 +205,7 @@ const initialResponse = await client
|
|
|
174
205
|
if (isUnexpected(initialResponse)) {
|
|
175
206
|
throw initialResponse.body.error;
|
|
176
207
|
}
|
|
208
|
+
|
|
177
209
|
const resultId = parseResultIdFromResponse(initialResponse);
|
|
178
210
|
console.log("resultId: ", resultId);
|
|
179
211
|
|
|
@@ -194,11 +226,14 @@ Supports output with Markdown content format along with the default plain _text_
|
|
|
194
226
|
|
|
195
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.
|
|
196
228
|
|
|
197
|
-
```ts
|
|
229
|
+
```ts snippet:ReadmeSampleAnalyzeMarkdownContentFormat
|
|
198
230
|
import DocumentIntelligence from "@azure-rest/ai-document-intelligence";
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
231
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
232
|
+
|
|
233
|
+
const client = DocumentIntelligence(
|
|
234
|
+
process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"],
|
|
235
|
+
new DefaultAzureCredential(),
|
|
236
|
+
);
|
|
202
237
|
|
|
203
238
|
const initialResponse = await client
|
|
204
239
|
.path("/documentModels/{modelId}:analyze", "prebuilt-layout")
|
|
@@ -216,7 +251,15 @@ const initialResponse = await client
|
|
|
216
251
|
|
|
217
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.
|
|
218
253
|
|
|
219
|
-
```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
|
+
|
|
220
263
|
await client.path("/documentModels/{modelId}:analyze", "prebuilt-layout").post({
|
|
221
264
|
contentType: "application/json",
|
|
222
265
|
body: { urlSource: "..." },
|
|
@@ -247,18 +290,24 @@ To enable a wider set of scenarios, service introduces a "split" query parameter
|
|
|
247
290
|
|
|
248
291
|
## Document Classifiers #Build
|
|
249
292
|
|
|
250
|
-
```ts
|
|
251
|
-
import {
|
|
252
|
-
DocumentClassifierBuildOperationDetailsOutput,
|
|
253
|
-
getLongRunningPoller,
|
|
293
|
+
```ts snippet:ReadmeSampleDocumentClassifierBuild
|
|
294
|
+
import DocumentIntelligence, {
|
|
254
295
|
isUnexpected,
|
|
296
|
+
getLongRunningPoller,
|
|
297
|
+
DocumentClassifierBuildOperationDetailsOutput,
|
|
255
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
|
+
);
|
|
256
305
|
|
|
257
306
|
const containerSasUrl = (): string =>
|
|
258
307
|
process.env["DOCUMENT_INTELLIGENCE_TRAINING_CONTAINER_SAS_URL"];
|
|
259
308
|
const initialResponse = await client.path("/documentClassifiers:build").post({
|
|
260
309
|
body: {
|
|
261
|
-
classifierId: `customClassifier
|
|
310
|
+
classifierId: `customClassifier-12345`,
|
|
262
311
|
description: "Custom classifier description",
|
|
263
312
|
docTypes: {
|
|
264
313
|
foo: {
|
|
@@ -278,33 +327,34 @@ const initialResponse = await client.path("/documentClassifiers:build").post({
|
|
|
278
327
|
if (isUnexpected(initialResponse)) {
|
|
279
328
|
throw initialResponse.body.error;
|
|
280
329
|
}
|
|
330
|
+
|
|
281
331
|
const poller = getLongRunningPoller(client, initialResponse);
|
|
282
332
|
const response = (await poller.pollUntilDone())
|
|
283
333
|
.body as DocumentClassifierBuildOperationDetailsOutput;
|
|
284
334
|
console.log(response);
|
|
285
|
-
// {
|
|
286
|
-
// operationId: '31466834048_f3ee629e-73fb-48ab-993b-1d55d73ca460',
|
|
287
|
-
// kind: 'documentClassifierBuild',
|
|
288
|
-
// status: 'succeeded',
|
|
289
|
-
// .
|
|
290
|
-
// .
|
|
291
|
-
// result: {
|
|
292
|
-
// classifierId: 'customClassifier10978',
|
|
293
|
-
// createdDateTime: '2023-11-09T12:45:56Z',
|
|
294
|
-
// .
|
|
295
|
-
// .
|
|
296
|
-
// description: 'Custom classifier description'
|
|
297
|
-
// },
|
|
298
|
-
// apiVersion: '2023-10-31-preview'
|
|
299
|
-
// }
|
|
300
335
|
```
|
|
301
336
|
|
|
302
337
|
## Get the generated PDF output from document analysis
|
|
303
338
|
|
|
304
|
-
```ts
|
|
305
|
-
|
|
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
|
+
);
|
|
306
354
|
|
|
307
|
-
const
|
|
355
|
+
const filePath = join("./assets", "layout-pageobject.pdf");
|
|
356
|
+
|
|
357
|
+
const base64Source = await readFile(filePath, { encoding: "base64" });
|
|
308
358
|
|
|
309
359
|
const initialResponse = await client
|
|
310
360
|
.path("/documentModels/{modelId}:analyze", "prebuilt-read")
|
|
@@ -328,7 +378,7 @@ const output = await client
|
|
|
328
378
|
.path(
|
|
329
379
|
"/documentModels/{modelId}/analyzeResults/{resultId}/pdf",
|
|
330
380
|
"prebuilt-read",
|
|
331
|
-
parseResultIdFromResponse(initialResponse)
|
|
381
|
+
parseResultIdFromResponse(initialResponse),
|
|
332
382
|
)
|
|
333
383
|
.get()
|
|
334
384
|
.asNodeStream(); // output.body would be NodeJS.ReadableStream
|
|
@@ -338,16 +388,31 @@ if (output.status !== "200" || !output.body) {
|
|
|
338
388
|
}
|
|
339
389
|
|
|
340
390
|
const pdfData = await streamToUint8Array(output.body);
|
|
341
|
-
|
|
342
|
-
// Or you can consume the NodeJS.ReadableStream directly
|
|
391
|
+
await writeFile(`./output.pdf`, pdfData);
|
|
343
392
|
```
|
|
344
393
|
|
|
345
394
|
## Get the generated cropped image of specified figure from document analysis
|
|
346
395
|
|
|
347
|
-
```ts
|
|
348
|
-
|
|
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";
|
|
349
407
|
|
|
350
|
-
const
|
|
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" });
|
|
351
416
|
|
|
352
417
|
const initialResponse = await client
|
|
353
418
|
.path("/documentModels/{modelId}:analyze", "prebuilt-layout")
|
|
@@ -363,21 +428,18 @@ if (isUnexpected(initialResponse)) {
|
|
|
363
428
|
throw initialResponse.body.error;
|
|
364
429
|
}
|
|
365
430
|
|
|
366
|
-
const poller = getLongRunningPoller(client, initialResponse
|
|
431
|
+
const poller = getLongRunningPoller(client, initialResponse);
|
|
367
432
|
|
|
368
|
-
const result = (await poller.pollUntilDone()).body as
|
|
433
|
+
const result = (await poller.pollUntilDone()).body as AnalyzeOperationOutput;
|
|
369
434
|
const figures = result.analyzeResult?.figures;
|
|
370
|
-
assert.isArray(figures);
|
|
371
|
-
assert.isNotEmpty(figures?.[0]);
|
|
372
435
|
const figureId = figures?.[0].id || "";
|
|
373
|
-
assert.isDefined(figureId);
|
|
374
436
|
|
|
375
437
|
const output = await client
|
|
376
438
|
.path(
|
|
377
439
|
"/documentModels/{modelId}/analyzeResults/{resultId}/figures/{figureId}",
|
|
378
440
|
"prebuilt-layout",
|
|
379
441
|
parseResultIdFromResponse(initialResponse),
|
|
380
|
-
figureId
|
|
442
|
+
figureId,
|
|
381
443
|
)
|
|
382
444
|
.get()
|
|
383
445
|
.asNodeStream(); // output.body would be NodeJS.ReadableStream
|
|
@@ -387,31 +449,44 @@ if (output.status !== "200" || !output.body) {
|
|
|
387
449
|
}
|
|
388
450
|
|
|
389
451
|
const imageData = await streamToUint8Array(output.body);
|
|
390
|
-
|
|
391
|
-
// Or you can consume the NodeJS.ReadableStream directly
|
|
452
|
+
await writeFile(`./figures/${figureId}.png`, imageData);
|
|
392
453
|
```
|
|
393
454
|
|
|
394
455
|
## Get Info
|
|
395
456
|
|
|
396
|
-
```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
|
+
|
|
397
466
|
const response = await client.path("/info").get();
|
|
398
467
|
if (isUnexpected(response)) {
|
|
399
468
|
throw response.body.error;
|
|
400
469
|
}
|
|
470
|
+
|
|
401
471
|
console.log(response.body.customDocumentModels.limit);
|
|
402
|
-
// 20000
|
|
403
472
|
```
|
|
404
473
|
|
|
405
474
|
## List Document Models
|
|
406
475
|
|
|
407
|
-
```ts
|
|
408
|
-
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
|
+
|
|
409
485
|
const response = await client.path("/documentModels").get();
|
|
410
486
|
if (isUnexpected(response)) {
|
|
411
487
|
throw response.body.error;
|
|
412
488
|
}
|
|
413
489
|
|
|
414
|
-
const modelsInAccount: string[] = [];
|
|
415
490
|
for await (const model of paginate(client, response)) {
|
|
416
491
|
console.log(model.modelId);
|
|
417
492
|
}
|
|
@@ -423,8 +498,8 @@ for await (const model of paginate(client, response)) {
|
|
|
423
498
|
|
|
424
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`:
|
|
425
500
|
|
|
426
|
-
```
|
|
427
|
-
|
|
501
|
+
```ts snippet:SetLogLevel
|
|
502
|
+
import { setLogLevel } from "@azure/logger";
|
|
428
503
|
|
|
429
504
|
setLogLevel("info");
|
|
430
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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
/**
|
|
4
|
+
* Defines the known cloud audiences for Document Intelligence.
|
|
5
|
+
*
|
|
6
|
+
* To authenticate with Entra Id (using a `TokenCredential`) in a [Sovereign Cloud](https://learn.microsoft.com/en-us/entra/identity-platform/authentication-national-cloud)
|
|
7
|
+
* environment, provide the appropriate value below as the `audience` option when creating a
|
|
8
|
+
* `Document Intelligence` client.
|
|
9
|
+
*
|
|
10
|
+
* The default value is suitable for Document Intelligence resources created in the Azure Public Cloud, so this value
|
|
11
|
+
* is only required to use Document Intelligence in a different cloud environment.
|
|
12
|
+
*/
|
|
13
|
+
export var KnownDocumentIntelligenceAudience;
|
|
14
|
+
(function (KnownDocumentIntelligenceAudience) {
|
|
15
|
+
/** Azure China */
|
|
16
|
+
KnownDocumentIntelligenceAudience["AzureChina"] = "https://cognitiveservices.azure.cn";
|
|
17
|
+
/** Azure Government */
|
|
18
|
+
KnownDocumentIntelligenceAudience["AzureGovernment"] = "https://cognitiveservices.azure.us";
|
|
19
|
+
/** Azure Public Cloud */
|
|
20
|
+
KnownDocumentIntelligenceAudience["AzurePublicCloud"] = "https://cognitiveservices.azure.com";
|
|
21
|
+
})(KnownDocumentIntelligenceAudience || (KnownDocumentIntelligenceAudience = {}));
|
|
22
|
+
//# sourceMappingURL=audience.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audience.js","sourceRoot":"","sources":["../../src/audience.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;;;;;;;GASG;AACH,MAAM,CAAN,IAAY,iCAOX;AAPD,WAAY,iCAAiC;IAC3C,kBAAkB;IAClB,sFAAiD,CAAA;IACjD,uBAAuB;IACvB,2FAAsD,CAAA;IACtD,yBAAyB;IACzB,6FAAwD,CAAA;AAC1D,CAAC,EAPW,iCAAiC,KAAjC,iCAAiC,QAO5C","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Defines the known cloud audiences for Document Intelligence.\n *\n * To authenticate with Entra Id (using a `TokenCredential`) in a [Sovereign Cloud](https://learn.microsoft.com/en-us/entra/identity-platform/authentication-national-cloud)\n * environment, provide the appropriate value below as the `audience` option when creating a\n * `Document Intelligence` client.\n *\n * The default value is suitable for Document Intelligence resources created in the Azure Public Cloud, so this value\n * is only required to use Document Intelligence in a different cloud environment.\n */\nexport enum KnownDocumentIntelligenceAudience {\n /** Azure China */\n AzureChina = \"https://cognitiveservices.azure.cn\",\n /** Azure Government */\n AzureGovernment = \"https://cognitiveservices.azure.us\",\n /** Azure Public Cloud */\n AzurePublicCloud = \"https://cognitiveservices.azure.com\",\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentIntelligence.d.ts","sourceRoot":"","sources":["../../src/documentIntelligence.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"documentIntelligence.d.ts","sourceRoot":"","sources":["../../src/documentIntelligence.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAGzE,6CAA6C;AAC7C,MAAM,WAAW,iCAAkC,SAAQ,aAAa;IACtE,2CAA2C;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,eAAe,GAAG,aAAa,EAC5C,EAAE,UAAyB,EAAE,GAAG,OAAO,EAAE,GAAE,iCAAsC,GAChF,0BAA0B,CA8C5B"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { __rest } from "tslib";
|
|
4
4
|
import { getClient } from "@azure-rest/core-client";
|
|
5
5
|
import { logger } from "./logger.js";
|
|
6
|
+
import { KnownDocumentIntelligenceAudience } from "./audience.js";
|
|
6
7
|
/**
|
|
7
8
|
* Initialize a new instance of `DocumentIntelligenceClient`
|
|
8
9
|
* @param endpointParam - The Document Intelligence service endpoint.
|
|
@@ -13,7 +14,7 @@ export default function createClient(endpointParam, credentials, _a = {}) {
|
|
|
13
14
|
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
14
15
|
var { apiVersion = "2024-11-30" } = _a, options = __rest(_a, ["apiVersion"]);
|
|
15
16
|
const endpointUrl = (_c = (_b = options.endpoint) !== null && _b !== void 0 ? _b : options.baseUrl) !== null && _c !== void 0 ? _c : `${endpointParam}/documentintelligence`;
|
|
16
|
-
const userAgentInfo = `azsdk-js-ai-document-intelligence-rest/1.
|
|
17
|
+
const userAgentInfo = `azsdk-js-ai-document-intelligence-rest/1.1.0`;
|
|
17
18
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
18
19
|
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
|
|
19
20
|
: `${userAgentInfo}`;
|
|
@@ -22,7 +23,11 @@ export default function createClient(endpointParam, credentials, _a = {}) {
|
|
|
22
23
|
}, loggingOptions: {
|
|
23
24
|
logger: (_e = (_d = options.loggingOptions) === null || _d === void 0 ? void 0 : _d.logger) !== null && _e !== void 0 ? _e : logger.info,
|
|
24
25
|
}, credentials: {
|
|
25
|
-
scopes: (_g = (_f = options.credentials) === null || _f === void 0 ? void 0 : _f.scopes) !== null && _g !== void 0 ? _g : [
|
|
26
|
+
scopes: ((_g = (_f = options.credentials) === null || _f === void 0 ? void 0 : _f.scopes) !== null && _g !== void 0 ? _g : [KnownDocumentIntelligenceAudience.AzurePublicCloud]).map((scope) => {
|
|
27
|
+
if (scope.endsWith("/.default"))
|
|
28
|
+
return scope;
|
|
29
|
+
return `${scope}/.default`;
|
|
30
|
+
}),
|
|
26
31
|
apiKeyHeaderName: (_j = (_h = options.credentials) === null || _h === void 0 ? void 0 : _h.apiKeyHeaderName) !== null && _j !== void 0 ? _j : "Ocp-Apim-Subscription-Key",
|
|
27
32
|
} });
|
|
28
33
|
const client = getClient(endpointUrl, credentials, options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentIntelligence.js","sourceRoot":"","sources":["../../src/documentIntelligence.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"documentIntelligence.js","sourceRoot":"","sources":["../../src/documentIntelligence.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,OAAO,EAAE,iCAAiC,EAAE,MAAM,eAAe,CAAC;AAQlE;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,aAAqB,EACrB,WAA4C,EAC5C,KAA+E,EAAE;;QAAjF,EAAE,UAAU,GAAG,YAAY,OAAsD,EAAjD,OAAO,cAAvC,cAAyC,CAAF;IAEvC,MAAM,WAAW,GACf,MAAA,MAAA,OAAO,CAAC,QAAQ,mCAAI,OAAO,CAAC,OAAO,mCAAI,GAAG,aAAa,uBAAuB,CAAC;IACjF,MAAM,aAAa,GAAG,8CAA8C,CAAC;IACrE,MAAM,eAAe,GACnB,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC,eAAe;QAClE,CAAC,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,eAAe,IAAI,aAAa,EAAE;QAChE,CAAC,CAAC,GAAG,aAAa,EAAE,CAAC;IACzB,OAAO,mCACF,OAAO,KACV,gBAAgB,EAAE;YAChB,eAAe;SAChB,EACD,cAAc,EAAE;YACd,MAAM,EAAE,MAAA,MAAA,OAAO,CAAC,cAAc,0CAAE,MAAM,mCAAI,MAAM,CAAC,IAAI;SACtD,EACD,WAAW,EAAE;YACX,MAAM,EAAE,CACN,MAAA,MAAA,OAAO,CAAC,WAAW,0CAAE,MAAM,mCAAI,CAAC,iCAAiC,CAAC,gBAAgB,CAAC,CACpF,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;gBACd,IAAI,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC;oBAAE,OAAO,KAAK,CAAC;gBAC9C,OAAO,GAAG,KAAK,WAAW,CAAC;YAC7B,CAAC,CAAC;YACF,gBAAgB,EAAE,MAAA,MAAA,OAAO,CAAC,WAAW,0CAAE,gBAAgB,mCAAI,2BAA2B;SACvF,GACF,CAAC;IACF,MAAM,MAAM,GAAG,SAAS,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAA+B,CAAC;IAE1F,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAC3D,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC;QACxB,IAAI,EAAE,wBAAwB;QAC9B,WAAW,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;YACzB,qDAAqD;YACrD,yEAAyE;YACzE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC7B,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,UAAU,EAAE,CAAC;gBACvD,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,GAAG,GAClB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GACzD,eAAe,UAAU,EAAE,CAAC;YAC9B,CAAC;YAED,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ClientOptions } from \"@azure-rest/core-client\";\nimport { getClient } from \"@azure-rest/core-client\";\nimport { logger } from \"./logger.js\";\nimport type { TokenCredential, KeyCredential } from \"@azure/core-auth\";\nimport type { DocumentIntelligenceClient } from \"./clientDefinitions.js\";\nimport { KnownDocumentIntelligenceAudience } from \"./audience.js\";\n\n/** The optional parameters for the client */\nexport interface DocumentIntelligenceClientOptions extends ClientOptions {\n /** The api version option of the client */\n apiVersion?: string;\n}\n\n/**\n * Initialize a new instance of `DocumentIntelligenceClient`\n * @param endpointParam - The Document Intelligence service endpoint.\n * @param credentials - uniquely identify client credential\n * @param options - the parameter for all optional parameters\n */\nexport default function createClient(\n endpointParam: string,\n credentials: TokenCredential | KeyCredential,\n { apiVersion = \"2024-11-30\", ...options }: DocumentIntelligenceClientOptions = {},\n): DocumentIntelligenceClient {\n const endpointUrl =\n options.endpoint ?? options.baseUrl ?? `${endpointParam}/documentintelligence`;\n const userAgentInfo = `azsdk-js-ai-document-intelligence-rest/1.1.0`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`\n : `${userAgentInfo}`;\n options = {\n ...options,\n userAgentOptions: {\n userAgentPrefix,\n },\n loggingOptions: {\n logger: options.loggingOptions?.logger ?? logger.info,\n },\n credentials: {\n scopes: (\n options.credentials?.scopes ?? [KnownDocumentIntelligenceAudience.AzurePublicCloud]\n ).map((scope) => {\n if (scope.endsWith(\"/.default\")) return scope;\n return `${scope}/.default`;\n }),\n apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? \"Ocp-Apim-Subscription-Key\",\n },\n };\n const client = getClient(endpointUrl, credentials, options) as DocumentIntelligenceClient;\n\n client.pipeline.removePolicy({ name: \"ApiVersionPolicy\" });\n client.pipeline.addPolicy({\n name: \"ClientApiVersionPolicy\",\n sendRequest: (req, next) => {\n // Use the apiVersion defined in request url directly\n // Append one if there is no apiVersion and we have one at client options\n const url = new URL(req.url);\n if (!url.searchParams.get(\"api-version\") && apiVersion) {\n req.url = `${req.url}${\n Array.from(url.searchParams.keys()).length > 0 ? \"&\" : \"?\"\n }api-version=${apiVersion}`;\n }\n\n return next(req);\n },\n });\n\n return client;\n}\n"]}
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -9,5 +9,6 @@ export * from "./outputModels.js";
|
|
|
9
9
|
export * from "./paginateHelper.js";
|
|
10
10
|
export * from "./pollingHelper.js";
|
|
11
11
|
export * from "./utils.js";
|
|
12
|
+
export { KnownDocumentIntelligenceAudience } from "./audience.js";
|
|
12
13
|
export default DocumentIntelligence;
|
|
13
14
|
//# sourceMappingURL=index.d.ts.map
|