@azure-rest/ai-document-intelligence 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +224 -0
- package/dist/index.js +252 -0
- package/dist/index.js.map +1 -0
- package/dist-esm/src/clientDefinitions.js +4 -0
- package/dist-esm/src/clientDefinitions.js.map +1 -0
- package/dist-esm/src/documentIntelligence.js +30 -0
- package/dist-esm/src/documentIntelligence.js.map +1 -0
- package/dist-esm/src/index.js +14 -0
- package/dist-esm/src/index.js.map +1 -0
- package/dist-esm/src/isUnexpected.js +93 -0
- package/dist-esm/src/isUnexpected.js.map +1 -0
- package/dist-esm/src/logger.js +5 -0
- package/dist-esm/src/logger.js.map +1 -0
- package/dist-esm/src/models.js +4 -0
- package/dist-esm/src/models.js.map +1 -0
- package/dist-esm/src/outputModels.js +4 -0
- package/dist-esm/src/outputModels.js.map +1 -0
- package/dist-esm/src/paginateHelper.js +70 -0
- package/dist-esm/src/paginateHelper.js.map +1 -0
- package/dist-esm/src/parameters.js +4 -0
- package/dist-esm/src/parameters.js.map +1 -0
- package/dist-esm/src/pollingHelper.js +43 -0
- package/dist-esm/src/pollingHelper.js.map +1 -0
- package/dist-esm/src/responses.js +4 -0
- package/dist-esm/src/responses.js.map +1 -0
- package/package.json +127 -0
- package/review/ai-document-intelligence.api.md +1411 -0
- package/types/ai-document-intelligence.d.ts +1782 -0
package/README.md
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# Azure DocumentIntelligence (formerly FormRecognizer) REST client library for JavaScript
|
|
2
|
+
|
|
3
|
+
Extracts content, layout, and structured data from documents.
|
|
4
|
+
|
|
5
|
+
**Please rely heavily on our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library**
|
|
6
|
+
|
|
7
|
+
Key links:
|
|
8
|
+
|
|
9
|
+
- [Source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/documentintelligence/ai-document-intelligence-rest)
|
|
10
|
+
- [Package (NPM)](https://www.npmjs.com/package/@azure-rest/ai-document-intelligence)
|
|
11
|
+
- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/documentintelligence/ai-document-intelligence-rest/samples)
|
|
12
|
+
|
|
13
|
+
## Getting started
|
|
14
|
+
|
|
15
|
+
### Currently supported environments
|
|
16
|
+
|
|
17
|
+
- LTS versions of Node.js
|
|
18
|
+
|
|
19
|
+
### Prerequisites
|
|
20
|
+
|
|
21
|
+
- You must have an [Azure subscription](https://azure.microsoft.com/free/) to use this package.
|
|
22
|
+
|
|
23
|
+
### Install the `@azure-rest/ai-document-intelligence` package
|
|
24
|
+
|
|
25
|
+
Install the Azure DocumentIntelligence(formerlyFormRecognizer) REST client REST client library for JavaScript with `npm`:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install @azure-rest/ai-document-intelligence
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Create and authenticate a `DocumentIntelligenceClient`
|
|
32
|
+
|
|
33
|
+
To use an [Azure Active Directory (AAD) token credential](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token),
|
|
34
|
+
provide an instance of the desired credential type obtained from the
|
|
35
|
+
[@azure/identity](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) library.
|
|
36
|
+
|
|
37
|
+
To authenticate with AAD, you must first `npm` install [`@azure/identity`](https://www.npmjs.com/package/@azure/identity)
|
|
38
|
+
|
|
39
|
+
After setup, you can choose which type of [credential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) from `@azure/identity` to use.
|
|
40
|
+
As an example, [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential)
|
|
41
|
+
can be used to authenticate the client.
|
|
42
|
+
|
|
43
|
+
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
|
|
44
|
+
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
|
|
45
|
+
|
|
46
|
+
### Using a Token Credential
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import DocumentIntelligence from "@azure-rest/ai-document-intelligence";
|
|
50
|
+
|
|
51
|
+
const client = DocumentIntelligence(
|
|
52
|
+
process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"],
|
|
53
|
+
new DefaultAzureCredential()
|
|
54
|
+
);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Using an API KEY
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import DocumentIntelligence from "@azure-rest/ai-document-intelligence";
|
|
61
|
+
|
|
62
|
+
const client = DocumentIntelligence(process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"], {
|
|
63
|
+
key: process.env["DOCUMENT_INTELLIGENCE_API_KEY"],
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Get Info
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
const response = await client.path("/info").get();
|
|
71
|
+
if (isUnexpected(response)) {
|
|
72
|
+
throw response.body.error;
|
|
73
|
+
}
|
|
74
|
+
console.log(response.body.customDocumentModels.limit);
|
|
75
|
+
// 20000
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## List Document Models
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import { paginate } from "@azure-rest/ai-document-intelligence";
|
|
82
|
+
const response = await client.path("/documentModels").get();
|
|
83
|
+
if (isUnexpected(response)) {
|
|
84
|
+
throw response.body.error;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const modelsInAccount: string[] = [];
|
|
88
|
+
for await (const model of paginate(client, response)) {
|
|
89
|
+
console.log(model.modelId);
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Document Models
|
|
94
|
+
|
|
95
|
+
### Analyze prebuilt-layout (urlSource)
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
const initialResponse = await client
|
|
99
|
+
.path("/documentModels/{modelId}:analyze", "prebuilt-layout")
|
|
100
|
+
.post({
|
|
101
|
+
contentType: "application/json",
|
|
102
|
+
body: {
|
|
103
|
+
urlSource:
|
|
104
|
+
"https://raw.githubusercontent.com/Azure/azure-sdk-for-js/6704eff082aaaf2d97c1371a28461f512f8d748a/sdk/formrecognizer/ai-form-recognizer/assets/forms/Invoice_1.pdf",
|
|
105
|
+
},
|
|
106
|
+
queryParameters: { locale: "en-IN" },
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Analyze prebuilt-layout (base64Source)
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
import fs from "fs";
|
|
114
|
+
import path from "path";
|
|
115
|
+
|
|
116
|
+
const filePath = path.join(ASSET_PATH, "forms", "Invoice_1.pdf");
|
|
117
|
+
const base64Source = fs.readFileSync(filePath, { encoding: "base64" });
|
|
118
|
+
const initialResponse = await client
|
|
119
|
+
.path("/documentModels/{modelId}:analyze", "prebuilt-layout")
|
|
120
|
+
.post({
|
|
121
|
+
contentType: "application/json",
|
|
122
|
+
body: {
|
|
123
|
+
base64Source,
|
|
124
|
+
},
|
|
125
|
+
queryParameters: { locale: "en-IN" },
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Continue creating the poller from initial response
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import {
|
|
133
|
+
getLongRunningPoller,
|
|
134
|
+
AnalyzeResultOperationOutput,
|
|
135
|
+
isUnexpected,
|
|
136
|
+
} from "@azure-rest/ai-document-intelligence";
|
|
137
|
+
|
|
138
|
+
if (isUnexpected(initialResponse)) {
|
|
139
|
+
throw initialResponse.body.error;
|
|
140
|
+
}
|
|
141
|
+
const poller = await getLongRunningPoller(client, initialResponse);
|
|
142
|
+
const result = (await poller.pollUntilDone()).body as AnalyzeResultOperationOutput;
|
|
143
|
+
console.log(result);
|
|
144
|
+
// {
|
|
145
|
+
// status: 'succeeded',
|
|
146
|
+
// createdDateTime: '2023-11-10T13:31:31Z',
|
|
147
|
+
// lastUpdatedDateTime: '2023-11-10T13:31:34Z',
|
|
148
|
+
// analyzeResult: {
|
|
149
|
+
// apiVersion: '2023-10-31-preview',
|
|
150
|
+
// .
|
|
151
|
+
// .
|
|
152
|
+
// .
|
|
153
|
+
// contentFormat: 'text'
|
|
154
|
+
// }
|
|
155
|
+
// }
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Document Classifiers #Build
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
import {
|
|
162
|
+
DocumentClassifierBuildOperationDetailsOutput,
|
|
163
|
+
getLongRunningPoller,
|
|
164
|
+
isUnexpected,
|
|
165
|
+
} from "@azure-rest/ai-document-intelligence";
|
|
166
|
+
|
|
167
|
+
const containerSasUrl = (): string =>
|
|
168
|
+
process.env["DOCUMENT_INTELLIGENCE_TRAINING_CONTAINER_SAS_URL"];
|
|
169
|
+
const initialResponse = await client.path("/documentClassifiers:build").post({
|
|
170
|
+
body: {
|
|
171
|
+
classifierId: `customClassifier${getRandomNumber()}`,
|
|
172
|
+
description: "Custom classifier description",
|
|
173
|
+
docTypes: {
|
|
174
|
+
foo: {
|
|
175
|
+
azureBlobSource: {
|
|
176
|
+
containerUrl: containerSasUrl(),
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
bar: {
|
|
180
|
+
azureBlobSource: {
|
|
181
|
+
containerUrl: containerSasUrl(),
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
if (isUnexpected(initialResponse)) {
|
|
189
|
+
throw initialResponse.body.error;
|
|
190
|
+
}
|
|
191
|
+
const poller = await getLongRunningPoller(client, initialResponse);
|
|
192
|
+
const response = (await poller.pollUntilDone())
|
|
193
|
+
.body as DocumentClassifierBuildOperationDetailsOutput;
|
|
194
|
+
console.log(response);
|
|
195
|
+
// {
|
|
196
|
+
// operationId: '31466834048_f3ee629e-73fb-48ab-993b-1d55d73ca460',
|
|
197
|
+
// kind: 'documentClassifierBuild',
|
|
198
|
+
// status: 'succeeded',
|
|
199
|
+
// .
|
|
200
|
+
// .
|
|
201
|
+
// result: {
|
|
202
|
+
// classifierId: 'customClassifier10978',
|
|
203
|
+
// createdDateTime: '2023-11-09T12:45:56Z',
|
|
204
|
+
// .
|
|
205
|
+
// .
|
|
206
|
+
// description: 'Custom classifier description'
|
|
207
|
+
// },
|
|
208
|
+
// apiVersion: '2023-10-31-preview'
|
|
209
|
+
// }
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Troubleshooting
|
|
213
|
+
|
|
214
|
+
### Logging
|
|
215
|
+
|
|
216
|
+
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`:
|
|
217
|
+
|
|
218
|
+
```javascript
|
|
219
|
+
const { setLogLevel } = require("@azure/logger");
|
|
220
|
+
|
|
221
|
+
setLogLevel("info");
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var coreClient = require('@azure-rest/core-client');
|
|
6
|
+
var logger$1 = require('@azure/logger');
|
|
7
|
+
var corePaging = require('@azure/core-paging');
|
|
8
|
+
var coreLro = require('@azure/core-lro');
|
|
9
|
+
|
|
10
|
+
// Copyright (c) Microsoft Corporation.
|
|
11
|
+
// Licensed under the MIT license.
|
|
12
|
+
const logger = logger$1.createClientLogger("ai-document-intelligence");
|
|
13
|
+
|
|
14
|
+
// Copyright (c) Microsoft Corporation.
|
|
15
|
+
// Licensed under the MIT license.
|
|
16
|
+
/**
|
|
17
|
+
* Initialize a new instance of `DocumentIntelligenceClient`
|
|
18
|
+
* @param endpoint - The Document Intelligence service endpoint.
|
|
19
|
+
* @param credentials - uniquely identify client credential
|
|
20
|
+
* @param options - the parameter for all optional parameters
|
|
21
|
+
*/
|
|
22
|
+
function createClient(endpoint, credentials, options = {}) {
|
|
23
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
24
|
+
const baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : `${endpoint}/documentintelligence`;
|
|
25
|
+
options.apiVersion = (_b = options.apiVersion) !== null && _b !== void 0 ? _b : "2023-10-31-preview";
|
|
26
|
+
const userAgentInfo = `azsdk-js-ai-document-intelligence-rest/1.0.0-beta.1`;
|
|
27
|
+
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
28
|
+
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
|
|
29
|
+
: `${userAgentInfo}`;
|
|
30
|
+
options = Object.assign(Object.assign({}, options), { userAgentOptions: {
|
|
31
|
+
userAgentPrefix,
|
|
32
|
+
}, loggingOptions: {
|
|
33
|
+
logger: (_d = (_c = options.loggingOptions) === null || _c === void 0 ? void 0 : _c.logger) !== null && _d !== void 0 ? _d : logger.info,
|
|
34
|
+
}, credentials: {
|
|
35
|
+
scopes: (_f = (_e = options.credentials) === null || _e === void 0 ? void 0 : _e.scopes) !== null && _f !== void 0 ? _f : ["https://cognitiveservices.azure.com/.default"],
|
|
36
|
+
apiKeyHeaderName: (_h = (_g = options.credentials) === null || _g === void 0 ? void 0 : _g.apiKeyHeaderName) !== null && _h !== void 0 ? _h : "Ocp-Apim-Subscription-Key",
|
|
37
|
+
} });
|
|
38
|
+
const client = coreClient.getClient(baseUrl, credentials, options);
|
|
39
|
+
return client;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Copyright (c) Microsoft Corporation.
|
|
43
|
+
// Licensed under the MIT license.
|
|
44
|
+
const responseMap = {
|
|
45
|
+
"GET /operations": ["200"],
|
|
46
|
+
"GET /operations/{operationId}": ["200"],
|
|
47
|
+
"GET /info": ["200"],
|
|
48
|
+
"GET /documentModels/{modelId}/analyzeResults/{resultId}": ["200"],
|
|
49
|
+
"POST /documentModels/{modelId}:analyze": ["202"],
|
|
50
|
+
"GET /documentModels/{modelId}:analyze": ["200", "202"],
|
|
51
|
+
"GET /documentModels/{modelId}": ["200"],
|
|
52
|
+
"DELETE /documentModels/{modelId}": ["204"],
|
|
53
|
+
"POST /documentModels:build": ["202"],
|
|
54
|
+
"GET /documentModels:build": ["200", "202"],
|
|
55
|
+
"POST /documentModels:compose": ["202"],
|
|
56
|
+
"GET /documentModels:compose": ["200", "202"],
|
|
57
|
+
"POST /documentModels:authorizeCopy": ["200"],
|
|
58
|
+
"POST /documentModels/{modelId}:copyTo": ["202"],
|
|
59
|
+
"GET /documentModels/{modelId}:copyTo": ["200", "202"],
|
|
60
|
+
"GET /documentModels": ["200"],
|
|
61
|
+
"POST /documentClassifiers:build": ["202"],
|
|
62
|
+
"GET /documentClassifiers:build": ["200", "202"],
|
|
63
|
+
"GET /documentClassifiers": ["200"],
|
|
64
|
+
"GET /documentClassifiers/{classifierId}": ["200"],
|
|
65
|
+
"DELETE /documentClassifiers/{classifierId}": ["204"],
|
|
66
|
+
"POST /documentClassifiers/{classifierId}:analyze": ["202"],
|
|
67
|
+
"GET /documentClassifiers/{classifierId}:analyze": ["200", "202"],
|
|
68
|
+
"GET /documentClassifiers/{classifierId}/analyzeResults/{resultId}": ["200"],
|
|
69
|
+
};
|
|
70
|
+
function isUnexpected(response) {
|
|
71
|
+
const lroOriginal = response.headers["x-ms-original-url"];
|
|
72
|
+
const url = new URL(lroOriginal !== null && lroOriginal !== void 0 ? lroOriginal : response.request.url);
|
|
73
|
+
const method = response.request.method;
|
|
74
|
+
let pathDetails = responseMap[`${method} ${url.pathname}`];
|
|
75
|
+
if (!pathDetails) {
|
|
76
|
+
pathDetails = getParametrizedPathSuccess(method, url.pathname);
|
|
77
|
+
}
|
|
78
|
+
return !pathDetails.includes(response.status);
|
|
79
|
+
}
|
|
80
|
+
function getParametrizedPathSuccess(method, path) {
|
|
81
|
+
var _a, _b, _c, _d;
|
|
82
|
+
const pathParts = path.split("/");
|
|
83
|
+
// Traverse list to match the longest candidate
|
|
84
|
+
// matchedLen: the length of candidate path
|
|
85
|
+
// matchedValue: the matched status code array
|
|
86
|
+
let matchedLen = -1, matchedValue = [];
|
|
87
|
+
// Iterate the responseMap to find a match
|
|
88
|
+
for (const [key, value] of Object.entries(responseMap)) {
|
|
89
|
+
// Extracting the path from the map key which is in format
|
|
90
|
+
// GET /path/foo
|
|
91
|
+
if (!key.startsWith(method)) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const candidatePath = getPathFromMapKey(key);
|
|
95
|
+
// Get each part of the url path
|
|
96
|
+
const candidateParts = candidatePath.split("/");
|
|
97
|
+
// track if we have found a match to return the values found.
|
|
98
|
+
let found = true;
|
|
99
|
+
for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
|
|
100
|
+
if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) && ((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.indexOf("}")) !== -1) {
|
|
101
|
+
const start = candidateParts[i].indexOf("}") + 1, end = (_c = candidateParts[i]) === null || _c === void 0 ? void 0 : _c.length;
|
|
102
|
+
// If the current part of the candidate is a "template" part
|
|
103
|
+
// Try to use the suffix of pattern to match the path
|
|
104
|
+
// {guid} ==> $
|
|
105
|
+
// {guid}:export ==> :export$
|
|
106
|
+
const isMatched = new RegExp(`${(_d = candidateParts[i]) === null || _d === void 0 ? void 0 : _d.slice(start, end)}`).test(pathParts[j] || "");
|
|
107
|
+
if (!isMatched) {
|
|
108
|
+
found = false;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
// If the candidate part is not a template and
|
|
114
|
+
// the parts don't match mark the candidate as not found
|
|
115
|
+
// to move on with the next candidate path.
|
|
116
|
+
if (candidateParts[i] !== pathParts[j]) {
|
|
117
|
+
found = false;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// We finished evaluating the current candidate parts
|
|
122
|
+
// Update the matched value if and only if we found the longer pattern
|
|
123
|
+
if (found && candidatePath.length > matchedLen) {
|
|
124
|
+
matchedLen = candidatePath.length;
|
|
125
|
+
matchedValue = value;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return matchedValue;
|
|
129
|
+
}
|
|
130
|
+
function getPathFromMapKey(mapKey) {
|
|
131
|
+
const pathStart = mapKey.indexOf("/");
|
|
132
|
+
return mapKey.slice(pathStart);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Copyright (c) Microsoft Corporation.
|
|
136
|
+
// Licensed under the MIT license.
|
|
137
|
+
/**
|
|
138
|
+
* Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension
|
|
139
|
+
* @param client - Client to use for sending the next page requests
|
|
140
|
+
* @param initialResponse - Initial response containing the nextLink and current page of elements
|
|
141
|
+
* @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results
|
|
142
|
+
* @returns - PagedAsyncIterableIterator to iterate the elements
|
|
143
|
+
*/
|
|
144
|
+
function paginate(client, initialResponse, options = {}) {
|
|
145
|
+
let firstRun = true;
|
|
146
|
+
const itemName = "value";
|
|
147
|
+
const nextLinkName = "nextLink";
|
|
148
|
+
const { customGetPage } = options;
|
|
149
|
+
const pagedResult = {
|
|
150
|
+
firstPageLink: "",
|
|
151
|
+
getPage: typeof customGetPage === "function"
|
|
152
|
+
? customGetPage
|
|
153
|
+
: async (pageLink) => {
|
|
154
|
+
const result = firstRun ? initialResponse : await client.pathUnchecked(pageLink).get();
|
|
155
|
+
firstRun = false;
|
|
156
|
+
checkPagingRequest(result);
|
|
157
|
+
const nextLink = getNextLink(result.body, nextLinkName);
|
|
158
|
+
const values = getElements(result.body, itemName);
|
|
159
|
+
return {
|
|
160
|
+
page: values,
|
|
161
|
+
nextPageLink: nextLink,
|
|
162
|
+
};
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
return corePaging.getPagedAsyncIterator(pagedResult);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Gets for the value of nextLink in the body
|
|
169
|
+
*/
|
|
170
|
+
function getNextLink(body, nextLinkName) {
|
|
171
|
+
if (!nextLinkName) {
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
174
|
+
const nextLink = body[nextLinkName];
|
|
175
|
+
if (typeof nextLink !== "string" && typeof nextLink !== "undefined") {
|
|
176
|
+
throw new Error(`Body Property ${nextLinkName} should be a string or undefined`);
|
|
177
|
+
}
|
|
178
|
+
return nextLink;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Gets the elements of the current request in the body.
|
|
182
|
+
*/
|
|
183
|
+
function getElements(body, itemName) {
|
|
184
|
+
const value = body[itemName];
|
|
185
|
+
// value has to be an array according to the x-ms-pageable extension.
|
|
186
|
+
// The fact that this must be an array is used above to calculate the
|
|
187
|
+
// type of elements in the page in PaginateReturn
|
|
188
|
+
if (!Array.isArray(value)) {
|
|
189
|
+
throw new Error(`Couldn't paginate response\n Body doesn't contain an array property with name: ${itemName}`);
|
|
190
|
+
}
|
|
191
|
+
return value !== null && value !== void 0 ? value : [];
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Checks if a request failed
|
|
195
|
+
*/
|
|
196
|
+
function checkPagingRequest(response) {
|
|
197
|
+
const Http2xxStatusCodes = ["200", "201", "202", "203", "204", "205", "206", "207", "208", "226"];
|
|
198
|
+
if (!Http2xxStatusCodes.includes(response.status)) {
|
|
199
|
+
throw coreClient.createRestError(`Pagination failed with unexpected statusCode ${response.status}`, response);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Copyright (c) Microsoft Corporation.
|
|
204
|
+
// Licensed under the MIT license.
|
|
205
|
+
async function getLongRunningPoller(client, initialResponse, options = {}) {
|
|
206
|
+
var _a;
|
|
207
|
+
const poller = {
|
|
208
|
+
requestMethod: initialResponse.request.method,
|
|
209
|
+
requestPath: initialResponse.request.url,
|
|
210
|
+
sendInitialRequest: async () => {
|
|
211
|
+
// In the case of Rest Clients we are building the LRO poller object from a response that's the reason
|
|
212
|
+
// we are not triggering the initial request here, just extracting the information from the
|
|
213
|
+
// response we were provided.
|
|
214
|
+
return getLroResponse(initialResponse);
|
|
215
|
+
},
|
|
216
|
+
sendPollRequest: async (path) => {
|
|
217
|
+
// This is the callback that is going to be called to poll the service
|
|
218
|
+
// to get the latest status. We use the client provided and the polling path
|
|
219
|
+
// which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location
|
|
220
|
+
// depending on the lro pattern that the service implements. If non is provided we default to the initial path.
|
|
221
|
+
const response = await client.pathUnchecked(path !== null && path !== void 0 ? path : initialResponse.request.url).get();
|
|
222
|
+
const lroResponse = getLroResponse(response);
|
|
223
|
+
lroResponse.rawResponse.headers["x-ms-original-url"] = initialResponse.request.url;
|
|
224
|
+
return lroResponse;
|
|
225
|
+
},
|
|
226
|
+
};
|
|
227
|
+
options.resolveOnUnsuccessful = (_a = options.resolveOnUnsuccessful) !== null && _a !== void 0 ? _a : true;
|
|
228
|
+
return coreLro.createHttpPoller(poller, options);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Converts a Rest Client response to a response that the LRO implementation understands
|
|
232
|
+
* @param response - a rest client http response
|
|
233
|
+
* @returns - An LRO response that the LRO implementation understands
|
|
234
|
+
*/
|
|
235
|
+
function getLroResponse(response) {
|
|
236
|
+
if (Number.isNaN(response.status)) {
|
|
237
|
+
throw new TypeError(`Status code of the response is not a number. Value: ${response.status}`);
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
flatResponse: response,
|
|
241
|
+
rawResponse: Object.assign(Object.assign({}, response), { statusCode: Number.parseInt(response.status), body: response.body }),
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Copyright (c) Microsoft Corporation.
|
|
246
|
+
// Licensed under the MIT license.
|
|
247
|
+
|
|
248
|
+
exports.default = createClient;
|
|
249
|
+
exports.getLongRunningPoller = getLongRunningPoller;
|
|
250
|
+
exports.isUnexpected = isUnexpected;
|
|
251
|
+
exports.paginate = paginate;
|
|
252
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/logger.ts","../src/documentIntelligence.ts","../src/isUnexpected.ts","../src/paginateHelper.ts","../src/pollingHelper.ts","../src/index.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createClientLogger } from \"@azure/logger\";\nexport const logger = createClientLogger(\"ai-document-intelligence\");\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { getClient, ClientOptions } from \"@azure-rest/core-client\";\nimport { logger } from \"./logger\";\nimport { TokenCredential, KeyCredential } from \"@azure/core-auth\";\nimport { DocumentIntelligenceClient } from \"./clientDefinitions\";\n\n/**\n * Initialize a new instance of `DocumentIntelligenceClient`\n * @param endpoint - 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 endpoint: string,\n credentials: TokenCredential | KeyCredential,\n options: ClientOptions = {}\n): DocumentIntelligenceClient {\n const baseUrl = options.baseUrl ?? `${endpoint}/documentintelligence`;\n options.apiVersion = options.apiVersion ?? \"2023-10-31-preview\";\n const userAgentInfo = `azsdk-js-ai-document-intelligence-rest/1.0.0-beta.1`;\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: options.credentials?.scopes ?? [\"https://cognitiveservices.azure.com/.default\"],\n apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? \"Ocp-Apim-Subscription-Key\",\n },\n };\n\n const client = getClient(baseUrl, credentials, options) as DocumentIntelligenceClient;\n\n return client;\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n ListOperations200Response,\n ListOperationsDefaultResponse,\n GetDocumentModelBuildOperation200Response,\n GetDocumentModelBuildOperationDefaultResponse,\n GetResourceInfo200Response,\n GetResourceInfoDefaultResponse,\n GetAnalyzeResult200Response,\n GetAnalyzeResultDefaultResponse,\n AnalyzeDocumentFromStream202Response,\n AnalyzeDocumentFromStreamLogicalResponse,\n AnalyzeDocumentFromStreamDefaultResponse,\n GetModel200Response,\n GetModelDefaultResponse,\n DeleteModel204Response,\n DeleteModelDefaultResponse,\n BuildModel202Response,\n BuildModelLogicalResponse,\n BuildModelDefaultResponse,\n ComposeModel202Response,\n ComposeModelLogicalResponse,\n ComposeModelDefaultResponse,\n AuthorizeModelCopy200Response,\n AuthorizeModelCopyDefaultResponse,\n CopyModelTo202Response,\n CopyModelToLogicalResponse,\n CopyModelToDefaultResponse,\n ListModels200Response,\n ListModelsDefaultResponse,\n BuildClassifier202Response,\n BuildClassifierLogicalResponse,\n BuildClassifierDefaultResponse,\n ListClassifiers200Response,\n ListClassifiersDefaultResponse,\n GetClassifier200Response,\n GetClassifierDefaultResponse,\n DeleteClassifier204Response,\n DeleteClassifierDefaultResponse,\n ClassifyDocumentFromStream202Response,\n ClassifyDocumentFromStreamLogicalResponse,\n ClassifyDocumentFromStreamDefaultResponse,\n GetClassifyResult200Response,\n GetClassifyResultDefaultResponse,\n} from \"./responses\";\n\nconst responseMap: Record<string, string[]> = {\n \"GET /operations\": [\"200\"],\n \"GET /operations/{operationId}\": [\"200\"],\n \"GET /info\": [\"200\"],\n \"GET /documentModels/{modelId}/analyzeResults/{resultId}\": [\"200\"],\n \"POST /documentModels/{modelId}:analyze\": [\"202\"],\n \"GET /documentModels/{modelId}:analyze\": [\"200\", \"202\"],\n \"GET /documentModels/{modelId}\": [\"200\"],\n \"DELETE /documentModels/{modelId}\": [\"204\"],\n \"POST /documentModels:build\": [\"202\"],\n \"GET /documentModels:build\": [\"200\", \"202\"],\n \"POST /documentModels:compose\": [\"202\"],\n \"GET /documentModels:compose\": [\"200\", \"202\"],\n \"POST /documentModels:authorizeCopy\": [\"200\"],\n \"POST /documentModels/{modelId}:copyTo\": [\"202\"],\n \"GET /documentModels/{modelId}:copyTo\": [\"200\", \"202\"],\n \"GET /documentModels\": [\"200\"],\n \"POST /documentClassifiers:build\": [\"202\"],\n \"GET /documentClassifiers:build\": [\"200\", \"202\"],\n \"GET /documentClassifiers\": [\"200\"],\n \"GET /documentClassifiers/{classifierId}\": [\"200\"],\n \"DELETE /documentClassifiers/{classifierId}\": [\"204\"],\n \"POST /documentClassifiers/{classifierId}:analyze\": [\"202\"],\n \"GET /documentClassifiers/{classifierId}:analyze\": [\"200\", \"202\"],\n \"GET /documentClassifiers/{classifierId}/analyzeResults/{resultId}\": [\"200\"],\n};\n\nexport function isUnexpected(\n response: ListOperations200Response | ListOperationsDefaultResponse\n): response is ListOperationsDefaultResponse;\nexport function isUnexpected(\n response:\n | GetDocumentModelBuildOperation200Response\n | GetDocumentModelBuildOperationDefaultResponse\n): response is GetDocumentModelBuildOperationDefaultResponse;\nexport function isUnexpected(\n response: GetResourceInfo200Response | GetResourceInfoDefaultResponse\n): response is GetResourceInfoDefaultResponse;\nexport function isUnexpected(\n response: GetAnalyzeResult200Response | GetAnalyzeResultDefaultResponse\n): response is GetAnalyzeResultDefaultResponse;\nexport function isUnexpected(\n response:\n | AnalyzeDocumentFromStream202Response\n | AnalyzeDocumentFromStreamLogicalResponse\n | AnalyzeDocumentFromStreamDefaultResponse\n): response is AnalyzeDocumentFromStreamDefaultResponse;\nexport function isUnexpected(\n response: GetModel200Response | GetModelDefaultResponse\n): response is GetModelDefaultResponse;\nexport function isUnexpected(\n response: DeleteModel204Response | DeleteModelDefaultResponse\n): response is DeleteModelDefaultResponse;\nexport function isUnexpected(\n response: BuildModel202Response | BuildModelLogicalResponse | BuildModelDefaultResponse\n): response is BuildModelDefaultResponse;\nexport function isUnexpected(\n response: ComposeModel202Response | ComposeModelLogicalResponse | ComposeModelDefaultResponse\n): response is ComposeModelDefaultResponse;\nexport function isUnexpected(\n response: AuthorizeModelCopy200Response | AuthorizeModelCopyDefaultResponse\n): response is AuthorizeModelCopyDefaultResponse;\nexport function isUnexpected(\n response: CopyModelTo202Response | CopyModelToLogicalResponse | CopyModelToDefaultResponse\n): response is CopyModelToDefaultResponse;\nexport function isUnexpected(\n response: ListModels200Response | ListModelsDefaultResponse\n): response is ListModelsDefaultResponse;\nexport function isUnexpected(\n response:\n | BuildClassifier202Response\n | BuildClassifierLogicalResponse\n | BuildClassifierDefaultResponse\n): response is BuildClassifierDefaultResponse;\nexport function isUnexpected(\n response: ListClassifiers200Response | ListClassifiersDefaultResponse\n): response is ListClassifiersDefaultResponse;\nexport function isUnexpected(\n response: GetClassifier200Response | GetClassifierDefaultResponse\n): response is GetClassifierDefaultResponse;\nexport function isUnexpected(\n response: DeleteClassifier204Response | DeleteClassifierDefaultResponse\n): response is DeleteClassifierDefaultResponse;\nexport function isUnexpected(\n response:\n | ClassifyDocumentFromStream202Response\n | ClassifyDocumentFromStreamLogicalResponse\n | ClassifyDocumentFromStreamDefaultResponse\n): response is ClassifyDocumentFromStreamDefaultResponse;\nexport function isUnexpected(\n response: GetClassifyResult200Response | GetClassifyResultDefaultResponse\n): response is GetClassifyResultDefaultResponse;\nexport function isUnexpected(\n response:\n | ListOperations200Response\n | ListOperationsDefaultResponse\n | GetDocumentModelBuildOperation200Response\n | GetDocumentModelBuildOperationDefaultResponse\n | GetResourceInfo200Response\n | GetResourceInfoDefaultResponse\n | GetAnalyzeResult200Response\n | GetAnalyzeResultDefaultResponse\n | AnalyzeDocumentFromStream202Response\n | AnalyzeDocumentFromStreamLogicalResponse\n | AnalyzeDocumentFromStreamDefaultResponse\n | GetModel200Response\n | GetModelDefaultResponse\n | DeleteModel204Response\n | DeleteModelDefaultResponse\n | BuildModel202Response\n | BuildModelLogicalResponse\n | BuildModelDefaultResponse\n | ComposeModel202Response\n | ComposeModelLogicalResponse\n | ComposeModelDefaultResponse\n | AuthorizeModelCopy200Response\n | AuthorizeModelCopyDefaultResponse\n | CopyModelTo202Response\n | CopyModelToLogicalResponse\n | CopyModelToDefaultResponse\n | ListModels200Response\n | ListModelsDefaultResponse\n | BuildClassifier202Response\n | BuildClassifierLogicalResponse\n | BuildClassifierDefaultResponse\n | ListClassifiers200Response\n | ListClassifiersDefaultResponse\n | GetClassifier200Response\n | GetClassifierDefaultResponse\n | DeleteClassifier204Response\n | DeleteClassifierDefaultResponse\n | ClassifyDocumentFromStream202Response\n | ClassifyDocumentFromStreamLogicalResponse\n | ClassifyDocumentFromStreamDefaultResponse\n | GetClassifyResult200Response\n | GetClassifyResultDefaultResponse\n): response is\n | ListOperationsDefaultResponse\n | GetDocumentModelBuildOperationDefaultResponse\n | GetResourceInfoDefaultResponse\n | GetAnalyzeResultDefaultResponse\n | AnalyzeDocumentFromStreamDefaultResponse\n | GetModelDefaultResponse\n | DeleteModelDefaultResponse\n | BuildModelDefaultResponse\n | ComposeModelDefaultResponse\n | AuthorizeModelCopyDefaultResponse\n | CopyModelToDefaultResponse\n | ListModelsDefaultResponse\n | BuildClassifierDefaultResponse\n | ListClassifiersDefaultResponse\n | GetClassifierDefaultResponse\n | DeleteClassifierDefaultResponse\n | ClassifyDocumentFromStreamDefaultResponse\n | GetClassifyResultDefaultResponse {\n const lroOriginal = response.headers[\"x-ms-original-url\"];\n const url = new URL(lroOriginal ?? response.request.url);\n const method = response.request.method;\n let pathDetails = responseMap[`${method} ${url.pathname}`];\n if (!pathDetails) {\n pathDetails = getParametrizedPathSuccess(method, url.pathname);\n }\n return !pathDetails.includes(response.status);\n}\n\nfunction getParametrizedPathSuccess(method: string, path: string): string[] {\n const pathParts = path.split(\"/\");\n\n // Traverse list to match the longest candidate\n // matchedLen: the length of candidate path\n // matchedValue: the matched status code array\n let matchedLen = -1,\n matchedValue: string[] = [];\n\n // Iterate the responseMap to find a match\n for (const [key, value] of Object.entries(responseMap)) {\n // Extracting the path from the map key which is in format\n // GET /path/foo\n if (!key.startsWith(method)) {\n continue;\n }\n const candidatePath = getPathFromMapKey(key);\n // Get each part of the url path\n const candidateParts = candidatePath.split(\"/\");\n\n // track if we have found a match to return the values found.\n let found = true;\n for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {\n if (candidateParts[i]?.startsWith(\"{\") && candidateParts[i]?.indexOf(\"}\") !== -1) {\n const start = candidateParts[i]!.indexOf(\"}\") + 1,\n end = candidateParts[i]?.length;\n // If the current part of the candidate is a \"template\" part\n // Try to use the suffix of pattern to match the path\n // {guid} ==> $\n // {guid}:export ==> :export$\n const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(\n pathParts[j] || \"\"\n );\n\n if (!isMatched) {\n found = false;\n break;\n }\n continue;\n }\n\n // If the candidate part is not a template and\n // the parts don't match mark the candidate as not found\n // to move on with the next candidate path.\n if (candidateParts[i] !== pathParts[j]) {\n found = false;\n break;\n }\n }\n\n // We finished evaluating the current candidate parts\n // Update the matched value if and only if we found the longer pattern\n if (found && candidatePath.length > matchedLen) {\n matchedLen = candidatePath.length;\n matchedValue = value;\n }\n }\n\n return matchedValue;\n}\n\nfunction getPathFromMapKey(mapKey: string): string {\n const pathStart = mapKey.indexOf(\"/\");\n return mapKey.slice(pathStart);\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { getPagedAsyncIterator, PagedAsyncIterableIterator, PagedResult } from \"@azure/core-paging\";\nimport { Client, createRestError, PathUncheckedResponse } from \"@azure-rest/core-client\";\n\n/**\n * Helper type to extract the type of an array\n */\nexport type GetArrayType<T> = T extends Array<infer TData> ? TData : never;\n\n/**\n * The type of a custom function that defines how to get a page and a link to the next one if any.\n */\nexport type GetPage<TPage> = (\n pageLink: string,\n maxPageSize?: number\n) => Promise<{\n page: TPage;\n nextPageLink?: string;\n}>;\n\n/**\n * Options for the paging helper\n */\nexport interface PagingOptions<TResponse> {\n /**\n * Custom function to extract pagination details for crating the PagedAsyncIterableIterator\n */\n customGetPage?: GetPage<PaginateReturn<TResponse>[]>;\n}\n\n/**\n * Helper type to infer the Type of the paged elements from the response type\n * This type is generated based on the swagger information for x-ms-pageable\n * specifically on the itemName property which indicates the property of the response\n * where the page items are found. The default value is `value`.\n * This type will allow us to provide strongly typed Iterator based on the response we get as second parameter\n */\nexport type PaginateReturn<TResult> = TResult extends {\n body: { value?: infer TPage };\n}\n ? GetArrayType<TPage>\n : Array<unknown>;\n\n/**\n * Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension\n * @param client - Client to use for sending the next page requests\n * @param initialResponse - Initial response containing the nextLink and current page of elements\n * @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results\n * @returns - PagedAsyncIterableIterator to iterate the elements\n */\nexport function paginate<TResponse extends PathUncheckedResponse>(\n client: Client,\n initialResponse: TResponse,\n options: PagingOptions<TResponse> = {}\n): PagedAsyncIterableIterator<PaginateReturn<TResponse>> {\n // Extract element type from initial response\n type TElement = PaginateReturn<TResponse>;\n let firstRun = true;\n const itemName = \"value\";\n const nextLinkName = \"nextLink\";\n const { customGetPage } = options;\n const pagedResult: PagedResult<TElement[]> = {\n firstPageLink: \"\",\n getPage:\n typeof customGetPage === \"function\"\n ? customGetPage\n : async (pageLink: string) => {\n const result = firstRun ? initialResponse : await client.pathUnchecked(pageLink).get();\n firstRun = false;\n checkPagingRequest(result);\n const nextLink = getNextLink(result.body, nextLinkName);\n const values = getElements<TElement>(result.body, itemName);\n return {\n page: values,\n nextPageLink: nextLink,\n };\n },\n };\n\n return getPagedAsyncIterator(pagedResult);\n}\n\n/**\n * Gets for the value of nextLink in the body\n */\nfunction getNextLink(body: unknown, nextLinkName?: string): string | undefined {\n if (!nextLinkName) {\n return undefined;\n }\n\n const nextLink = (body as Record<string, unknown>)[nextLinkName];\n\n if (typeof nextLink !== \"string\" && typeof nextLink !== \"undefined\") {\n throw new Error(`Body Property ${nextLinkName} should be a string or undefined`);\n }\n\n return nextLink;\n}\n\n/**\n * Gets the elements of the current request in the body.\n */\nfunction getElements<T = unknown>(body: unknown, itemName: string): T[] {\n const value = (body as Record<string, unknown>)[itemName] as T[];\n\n // value has to be an array according to the x-ms-pageable extension.\n // The fact that this must be an array is used above to calculate the\n // type of elements in the page in PaginateReturn\n if (!Array.isArray(value)) {\n throw new Error(\n `Couldn't paginate response\\n Body doesn't contain an array property with name: ${itemName}`\n );\n }\n\n return value ?? [];\n}\n\n/**\n * Checks if a request failed\n */\nfunction checkPagingRequest(response: PathUncheckedResponse): void {\n const Http2xxStatusCodes = [\"200\", \"201\", \"202\", \"203\", \"204\", \"205\", \"206\", \"207\", \"208\", \"226\"];\n if (!Http2xxStatusCodes.includes(response.status)) {\n throw createRestError(\n `Pagination failed with unexpected statusCode ${response.status}`,\n response\n );\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Client, HttpResponse } from \"@azure-rest/core-client\";\nimport {\n CreateHttpPollerOptions,\n LongRunningOperation,\n LroResponse,\n OperationState,\n SimplePollerLike,\n createHttpPoller,\n} from \"@azure/core-lro\";\nimport {\n AnalyzeDocumentFromStream202Response,\n AnalyzeDocumentFromStreamDefaultResponse,\n AnalyzeDocumentFromStreamLogicalResponse,\n BuildModel202Response,\n BuildModelDefaultResponse,\n BuildModelLogicalResponse,\n ComposeModel202Response,\n ComposeModelDefaultResponse,\n ComposeModelLogicalResponse,\n CopyModelTo202Response,\n CopyModelToDefaultResponse,\n CopyModelToLogicalResponse,\n BuildClassifier202Response,\n BuildClassifierDefaultResponse,\n BuildClassifierLogicalResponse,\n ClassifyDocumentFromStream202Response,\n ClassifyDocumentFromStreamDefaultResponse,\n ClassifyDocumentFromStreamLogicalResponse,\n} from \"./responses\";\n/**\n * Helper function that builds a Poller object to help polling a long running operation.\n * @param client - Client to use for sending the request to get additional pages.\n * @param initialResponse - The initial response.\n * @param options - Options to set a resume state or custom polling interval.\n * @returns - A poller object to poll for operation state updates and eventually get the final response.\n */\nexport async function getLongRunningPoller<\n TResult extends BuildModelLogicalResponse | BuildModelDefaultResponse\n>(\n client: Client,\n initialResponse: BuildModel202Response | BuildModelDefaultResponse,\n options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>\n): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;\nexport async function getLongRunningPoller<\n TResult extends ComposeModelLogicalResponse | ComposeModelDefaultResponse\n>(\n client: Client,\n initialResponse: ComposeModel202Response | ComposeModelDefaultResponse,\n options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>\n): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;\nexport async function getLongRunningPoller<\n TResult extends CopyModelToLogicalResponse | CopyModelToDefaultResponse\n>(\n client: Client,\n initialResponse: CopyModelTo202Response | CopyModelToDefaultResponse,\n options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>\n): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;\nexport async function getLongRunningPoller<\n TResult extends BuildClassifierLogicalResponse | BuildClassifierDefaultResponse\n>(\n client: Client,\n initialResponse: BuildClassifier202Response | BuildClassifierDefaultResponse,\n options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>\n): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;\nexport async function getLongRunningPoller<\n TResult extends\n | AnalyzeDocumentFromStreamLogicalResponse\n | AnalyzeDocumentFromStreamDefaultResponse\n>(\n client: Client,\n initialResponse: AnalyzeDocumentFromStream202Response | AnalyzeDocumentFromStreamDefaultResponse,\n options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>\n): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;\nexport async function getLongRunningPoller<\n TResult extends\n | ClassifyDocumentFromStreamLogicalResponse\n | ClassifyDocumentFromStreamDefaultResponse\n>(\n client: Client,\n initialResponse:\n | ClassifyDocumentFromStream202Response\n | ClassifyDocumentFromStreamDefaultResponse,\n options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>\n): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;\nexport async function getLongRunningPoller<TResult extends HttpResponse>(\n client: Client,\n initialResponse: TResult,\n options: CreateHttpPollerOptions<TResult, OperationState<TResult>> = {}\n): Promise<SimplePollerLike<OperationState<TResult>, TResult>> {\n const poller: LongRunningOperation<TResult> = {\n requestMethod: initialResponse.request.method,\n requestPath: initialResponse.request.url,\n sendInitialRequest: async () => {\n // In the case of Rest Clients we are building the LRO poller object from a response that's the reason\n // we are not triggering the initial request here, just extracting the information from the\n // response we were provided.\n return getLroResponse(initialResponse);\n },\n sendPollRequest: async (path) => {\n // This is the callback that is going to be called to poll the service\n // to get the latest status. We use the client provided and the polling path\n // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location\n // depending on the lro pattern that the service implements. If non is provided we default to the initial path.\n const response = await client.pathUnchecked(path ?? initialResponse.request.url).get();\n const lroResponse = getLroResponse(response as TResult);\n lroResponse.rawResponse.headers[\"x-ms-original-url\"] = initialResponse.request.url;\n return lroResponse;\n },\n };\n\n options.resolveOnUnsuccessful = options.resolveOnUnsuccessful ?? true;\n return createHttpPoller(poller, options);\n}\n\n/**\n * Converts a Rest Client response to a response that the LRO implementation understands\n * @param response - a rest client http response\n * @returns - An LRO response that the LRO implementation understands\n */\nfunction getLroResponse<TResult extends HttpResponse>(response: TResult): LroResponse<TResult> {\n if (Number.isNaN(response.status)) {\n throw new TypeError(`Status code of the response is not a number. Value: ${response.status}`);\n }\n\n return {\n flatResponse: response,\n rawResponse: {\n ...response,\n statusCode: Number.parseInt(response.status),\n body: response.body,\n },\n };\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport DocumentIntelligence from \"./documentIntelligence\";\n\nexport * from \"./documentIntelligence\";\nexport * from \"./parameters\";\nexport * from \"./responses\";\nexport * from \"./clientDefinitions\";\nexport * from \"./isUnexpected\";\nexport * from \"./models\";\nexport * from \"./outputModels\";\nexport * from \"./paginateHelper\";\nexport * from \"./pollingHelper\";\n\nexport default DocumentIntelligence;\n"],"names":["createClientLogger","getClient","getPagedAsyncIterator","createRestError","createHttpPoller"],"mappings":";;;;;;;;;AAAA;AACA;AAGO,MAAM,MAAM,GAAGA,2BAAkB,CAAC,0BAA0B,CAAC;;ACJpE;AACA;AAOA;;;;;AAKG;AACW,SAAU,YAAY,CAClC,QAAgB,EAChB,WAA4C,EAC5C,OAAA,GAAyB,EAAE,EAAA;;IAE3B,MAAM,OAAO,GAAG,CAAA,EAAA,GAAA,OAAO,CAAC,OAAO,MAAI,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAA,CAAA,EAAG,QAAQ,CAAA,qBAAA,CAAuB,CAAC;IACtE,OAAO,CAAC,UAAU,GAAG,CAAA,EAAA,GAAA,OAAO,CAAC,UAAU,MAAI,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAA,oBAAoB,CAAC;IAChE,MAAM,aAAa,GAAG,CAAA,mDAAA,CAAqD,CAAC;IAC5E,MAAM,eAAe,GACnB,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC,eAAe;UAChE,GAAG,OAAO,CAAC,gBAAgB,CAAC,eAAe,CAAI,CAAA,EAAA,aAAa,CAAE,CAAA;AAChE,UAAE,CAAA,EAAG,aAAa,CAAA,CAAE,CAAC;AACzB,IAAA,OAAO,GACF,MAAA,CAAA,MAAA,CAAA,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
|
+
{"version":3,"file":"clientDefinitions.js","sourceRoot":"","sources":["../../src/clientDefinitions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n ListOperationsParameters,\n GetDocumentModelBuildOperationParameters,\n GetDocumentModelComposeOperationParameters,\n GetDocumentModelCopyToOperationParameters,\n GetDocumentClassifierBuildOperationParameters,\n GetOperationParameters,\n GetResourceInfoParameters,\n GetAnalyzeResultParameters,\n AnalyzeDocumentFromStreamParameters,\n AnalyzeDocumentParameters,\n GetModelParameters,\n DeleteModelParameters,\n BuildModelParameters,\n ComposeModelParameters,\n AuthorizeModelCopyParameters,\n CopyModelToParameters,\n ListModelsParameters,\n BuildClassifierParameters,\n ListClassifiersParameters,\n GetClassifierParameters,\n DeleteClassifierParameters,\n ClassifyDocumentFromStreamParameters,\n ClassifyDocumentParameters,\n GetClassifyResultParameters,\n} from \"./parameters\";\nimport {\n ListOperations200Response,\n ListOperationsDefaultResponse,\n GetDocumentModelBuildOperation200Response,\n GetDocumentModelBuildOperationDefaultResponse,\n GetDocumentModelComposeOperation200Response,\n GetDocumentModelComposeOperationDefaultResponse,\n GetDocumentModelCopyToOperation200Response,\n GetDocumentModelCopyToOperationDefaultResponse,\n GetDocumentClassifierBuildOperation200Response,\n GetDocumentClassifierBuildOperationDefaultResponse,\n GetOperation200Response,\n GetOperationDefaultResponse,\n GetResourceInfo200Response,\n GetResourceInfoDefaultResponse,\n GetAnalyzeResult200Response,\n GetAnalyzeResultDefaultResponse,\n AnalyzeDocumentFromStream202Response,\n AnalyzeDocumentFromStreamDefaultResponse,\n AnalyzeDocument202Response,\n AnalyzeDocumentDefaultResponse,\n GetModel200Response,\n GetModelDefaultResponse,\n DeleteModel204Response,\n DeleteModelDefaultResponse,\n BuildModel202Response,\n BuildModelDefaultResponse,\n ComposeModel202Response,\n ComposeModelDefaultResponse,\n AuthorizeModelCopy200Response,\n AuthorizeModelCopyDefaultResponse,\n CopyModelTo202Response,\n CopyModelToDefaultResponse,\n ListModels200Response,\n ListModelsDefaultResponse,\n BuildClassifier202Response,\n BuildClassifierDefaultResponse,\n ListClassifiers200Response,\n ListClassifiersDefaultResponse,\n GetClassifier200Response,\n GetClassifierDefaultResponse,\n DeleteClassifier204Response,\n DeleteClassifierDefaultResponse,\n ClassifyDocumentFromStream202Response,\n ClassifyDocumentFromStreamDefaultResponse,\n ClassifyDocument202Response,\n ClassifyDocumentDefaultResponse,\n GetClassifyResult200Response,\n GetClassifyResultDefaultResponse,\n} from \"./responses\";\nimport { Client, StreamableMethod } from \"@azure-rest/core-client\";\n\nexport interface ListOperations {\n /** Lists all operations. */\n get(\n options?: ListOperationsParameters\n ): StreamableMethod<ListOperations200Response | ListOperationsDefaultResponse>;\n}\n\nexport interface GetDocumentModelBuildOperation {\n /** Gets operation info. */\n get(\n options?: GetDocumentModelBuildOperationParameters\n ): StreamableMethod<\n GetDocumentModelBuildOperation200Response | GetDocumentModelBuildOperationDefaultResponse\n >;\n /** Gets operation info. */\n get(\n options?: GetDocumentModelComposeOperationParameters\n ): StreamableMethod<\n GetDocumentModelComposeOperation200Response | GetDocumentModelComposeOperationDefaultResponse\n >;\n /** Gets operation info. */\n get(\n options?: GetDocumentModelCopyToOperationParameters\n ): StreamableMethod<\n GetDocumentModelCopyToOperation200Response | GetDocumentModelCopyToOperationDefaultResponse\n >;\n /** Gets operation info. */\n get(\n options?: GetDocumentClassifierBuildOperationParameters\n ): StreamableMethod<\n | GetDocumentClassifierBuildOperation200Response\n | GetDocumentClassifierBuildOperationDefaultResponse\n >;\n /** Gets operation info. */\n get(\n options?: GetOperationParameters\n ): StreamableMethod<GetOperation200Response | GetOperationDefaultResponse>;\n}\n\nexport interface GetResourceInfo {\n /** Return information about the current resource. */\n get(\n options?: GetResourceInfoParameters\n ): StreamableMethod<GetResourceInfo200Response | GetResourceInfoDefaultResponse>;\n}\n\nexport interface GetAnalyzeResult {\n /** Gets the result of document analysis. */\n get(\n options?: GetAnalyzeResultParameters\n ): StreamableMethod<GetAnalyzeResult200Response | GetAnalyzeResultDefaultResponse>;\n}\n\nexport interface AnalyzeDocumentFromStream {\n /** Analyzes document with document model. */\n post(\n options: AnalyzeDocumentFromStreamParameters\n ): StreamableMethod<\n AnalyzeDocumentFromStream202Response | AnalyzeDocumentFromStreamDefaultResponse\n >;\n /** Analyzes document with document model. */\n post(\n options: AnalyzeDocumentParameters\n ): StreamableMethod<AnalyzeDocument202Response | AnalyzeDocumentDefaultResponse>;\n}\n\nexport interface GetModel {\n /** Gets detailed document model information. */\n get(\n options?: GetModelParameters\n ): StreamableMethod<GetModel200Response | GetModelDefaultResponse>;\n /** Deletes document model. */\n delete(\n options?: DeleteModelParameters\n ): StreamableMethod<DeleteModel204Response | DeleteModelDefaultResponse>;\n}\n\nexport interface BuildModel {\n /** Builds a custom document analysis model. */\n post(\n options: BuildModelParameters\n ): StreamableMethod<BuildModel202Response | BuildModelDefaultResponse>;\n}\n\nexport interface ComposeModel {\n /** Creates a new document model from document types of existing document models. */\n post(\n options: ComposeModelParameters\n ): StreamableMethod<ComposeModel202Response | ComposeModelDefaultResponse>;\n}\n\nexport interface AuthorizeModelCopy {\n /**\n * Generates authorization to copy a document model to this location with\n * specified modelId and optional description.\n */\n post(\n options: AuthorizeModelCopyParameters\n ): StreamableMethod<AuthorizeModelCopy200Response | AuthorizeModelCopyDefaultResponse>;\n}\n\nexport interface CopyModelTo {\n /** Copies document model to the target resource, region, and modelId. */\n post(\n options: CopyModelToParameters\n ): StreamableMethod<CopyModelTo202Response | CopyModelToDefaultResponse>;\n}\n\nexport interface ListModels {\n /** List all document models */\n get(\n options?: ListModelsParameters\n ): StreamableMethod<ListModels200Response | ListModelsDefaultResponse>;\n}\n\nexport interface BuildClassifier {\n /** Builds a custom document classifier. */\n post(\n options: BuildClassifierParameters\n ): StreamableMethod<BuildClassifier202Response | BuildClassifierDefaultResponse>;\n}\n\nexport interface ListClassifiers {\n /** List all document classifiers. */\n get(\n options?: ListClassifiersParameters\n ): StreamableMethod<ListClassifiers200Response | ListClassifiersDefaultResponse>;\n}\n\nexport interface GetClassifier {\n /** Gets detailed document classifier information. */\n get(\n options?: GetClassifierParameters\n ): StreamableMethod<GetClassifier200Response | GetClassifierDefaultResponse>;\n /** Deletes document classifier. */\n delete(\n options?: DeleteClassifierParameters\n ): StreamableMethod<DeleteClassifier204Response | DeleteClassifierDefaultResponse>;\n}\n\nexport interface ClassifyDocumentFromStream {\n /** Classifies document with document classifier. */\n post(\n options: ClassifyDocumentFromStreamParameters\n ): StreamableMethod<\n ClassifyDocumentFromStream202Response | ClassifyDocumentFromStreamDefaultResponse\n >;\n /** Classifies document with document classifier. */\n post(\n options: ClassifyDocumentParameters\n ): StreamableMethod<ClassifyDocument202Response | ClassifyDocumentDefaultResponse>;\n}\n\nexport interface GetClassifyResult {\n /** Gets the result of document classifier. */\n get(\n options?: GetClassifyResultParameters\n ): StreamableMethod<GetClassifyResult200Response | GetClassifyResultDefaultResponse>;\n}\n\nexport interface Routes {\n /** Resource for '/operations' has methods for the following verbs: get */\n (path: \"/operations\"): ListOperations;\n /** Resource for '/operations/\\{operationId\\}' has methods for the following verbs: get */\n (path: \"/operations/{operationId}\", operationId: string): GetDocumentModelBuildOperation;\n /** Resource for '/info' has methods for the following verbs: get */\n (path: \"/info\"): GetResourceInfo;\n /** Resource for '/documentModels/\\{modelId\\}/analyzeResults/\\{resultId\\}' has methods for the following verbs: get */\n (\n path: \"/documentModels/{modelId}/analyzeResults/{resultId}\",\n modelId: string,\n resultId: string\n ): GetAnalyzeResult;\n /** Resource for '/documentModels/\\{modelId\\}:analyze' has methods for the following verbs: post */\n (path: \"/documentModels/{modelId}:analyze\", modelId: string): AnalyzeDocumentFromStream;\n /** Resource for '/documentModels/\\{modelId\\}' has methods for the following verbs: get, delete */\n (path: \"/documentModels/{modelId}\", modelId: string): GetModel;\n /** Resource for '/documentModels:build' has methods for the following verbs: post */\n (path: \"/documentModels:build\"): BuildModel;\n /** Resource for '/documentModels:compose' has methods for the following verbs: post */\n (path: \"/documentModels:compose\"): ComposeModel;\n /** Resource for '/documentModels:authorizeCopy' has methods for the following verbs: post */\n (path: \"/documentModels:authorizeCopy\"): AuthorizeModelCopy;\n /** Resource for '/documentModels/\\{modelId\\}:copyTo' has methods for the following verbs: post */\n (path: \"/documentModels/{modelId}:copyTo\", modelId: string): CopyModelTo;\n /** Resource for '/documentModels' has methods for the following verbs: get */\n (path: \"/documentModels\"): ListModels;\n /** Resource for '/documentClassifiers:build' has methods for the following verbs: post */\n (path: \"/documentClassifiers:build\"): BuildClassifier;\n /** Resource for '/documentClassifiers' has methods for the following verbs: get */\n (path: \"/documentClassifiers\"): ListClassifiers;\n /** Resource for '/documentClassifiers/\\{classifierId\\}' has methods for the following verbs: get, delete */\n (path: \"/documentClassifiers/{classifierId}\", classifierId: string): GetClassifier;\n /** Resource for '/documentClassifiers/\\{classifierId\\}:analyze' has methods for the following verbs: post */\n (\n path: \"/documentClassifiers/{classifierId}:analyze\",\n classifierId: string\n ): ClassifyDocumentFromStream;\n /** Resource for '/documentClassifiers/\\{classifierId\\}/analyzeResults/\\{resultId\\}' has methods for the following verbs: get */\n (\n path: \"/documentClassifiers/{classifierId}/analyzeResults/{resultId}\",\n classifierId: string,\n resultId: string\n ): GetClassifyResult;\n}\n\nexport type DocumentIntelligenceClient = Client & {\n path: Routes;\n};\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
import { getClient } from "@azure-rest/core-client";
|
|
4
|
+
import { logger } from "./logger";
|
|
5
|
+
/**
|
|
6
|
+
* Initialize a new instance of `DocumentIntelligenceClient`
|
|
7
|
+
* @param endpoint - The Document Intelligence service endpoint.
|
|
8
|
+
* @param credentials - uniquely identify client credential
|
|
9
|
+
* @param options - the parameter for all optional parameters
|
|
10
|
+
*/
|
|
11
|
+
export default function createClient(endpoint, credentials, options = {}) {
|
|
12
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
13
|
+
const baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : `${endpoint}/documentintelligence`;
|
|
14
|
+
options.apiVersion = (_b = options.apiVersion) !== null && _b !== void 0 ? _b : "2023-10-31-preview";
|
|
15
|
+
const userAgentInfo = `azsdk-js-ai-document-intelligence-rest/1.0.0-beta.1`;
|
|
16
|
+
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
17
|
+
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
|
|
18
|
+
: `${userAgentInfo}`;
|
|
19
|
+
options = Object.assign(Object.assign({}, options), { userAgentOptions: {
|
|
20
|
+
userAgentPrefix,
|
|
21
|
+
}, loggingOptions: {
|
|
22
|
+
logger: (_d = (_c = options.loggingOptions) === null || _c === void 0 ? void 0 : _c.logger) !== null && _d !== void 0 ? _d : logger.info,
|
|
23
|
+
}, credentials: {
|
|
24
|
+
scopes: (_f = (_e = options.credentials) === null || _e === void 0 ? void 0 : _e.scopes) !== null && _f !== void 0 ? _f : ["https://cognitiveservices.azure.com/.default"],
|
|
25
|
+
apiKeyHeaderName: (_h = (_g = options.credentials) === null || _g === void 0 ? void 0 : _g.apiKeyHeaderName) !== null && _h !== void 0 ? _h : "Ocp-Apim-Subscription-Key",
|
|
26
|
+
} });
|
|
27
|
+
const client = getClient(baseUrl, credentials, options);
|
|
28
|
+
return client;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=documentIntelligence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documentIntelligence.js","sourceRoot":"","sources":["../../src/documentIntelligence.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,SAAS,EAAiB,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAIlC;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,QAAgB,EAChB,WAA4C,EAC5C,UAAyB,EAAE;;IAE3B,MAAM,OAAO,GAAG,MAAA,OAAO,CAAC,OAAO,mCAAI,GAAG,QAAQ,uBAAuB,CAAC;IACtE,OAAO,CAAC,UAAU,GAAG,MAAA,OAAO,CAAC,UAAU,mCAAI,oBAAoB,CAAC;IAChE,MAAM,aAAa,GAAG,qDAAqD,CAAC;IAC5E,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,MAAA,MAAA,OAAO,CAAC,WAAW,0CAAE,MAAM,mCAAI,CAAC,8CAA8C,CAAC;YACvF,gBAAgB,EAAE,MAAA,MAAA,OAAO,CAAC,WAAW,0CAAE,gBAAgB,mCAAI,2BAA2B;SACvF,GACF,CAAC;IAEF,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAA+B,CAAC;IAEtF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { getClient, ClientOptions } from \"@azure-rest/core-client\";\nimport { logger } from \"./logger\";\nimport { TokenCredential, KeyCredential } from \"@azure/core-auth\";\nimport { DocumentIntelligenceClient } from \"./clientDefinitions\";\n\n/**\n * Initialize a new instance of `DocumentIntelligenceClient`\n * @param endpoint - 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 endpoint: string,\n credentials: TokenCredential | KeyCredential,\n options: ClientOptions = {}\n): DocumentIntelligenceClient {\n const baseUrl = options.baseUrl ?? `${endpoint}/documentintelligence`;\n options.apiVersion = options.apiVersion ?? \"2023-10-31-preview\";\n const userAgentInfo = `azsdk-js-ai-document-intelligence-rest/1.0.0-beta.1`;\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: options.credentials?.scopes ?? [\"https://cognitiveservices.azure.com/.default\"],\n apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? \"Ocp-Apim-Subscription-Key\",\n },\n };\n\n const client = getClient(baseUrl, credentials, options) as DocumentIntelligenceClient;\n\n return client;\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
import DocumentIntelligence from "./documentIntelligence";
|
|
4
|
+
export * from "./documentIntelligence";
|
|
5
|
+
export * from "./parameters";
|
|
6
|
+
export * from "./responses";
|
|
7
|
+
export * from "./clientDefinitions";
|
|
8
|
+
export * from "./isUnexpected";
|
|
9
|
+
export * from "./models";
|
|
10
|
+
export * from "./outputModels";
|
|
11
|
+
export * from "./paginateHelper";
|
|
12
|
+
export * from "./pollingHelper";
|
|
13
|
+
export default DocumentIntelligence;
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,oBAAoB,MAAM,wBAAwB,CAAC;AAE1D,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAEhC,eAAe,oBAAoB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport DocumentIntelligence from \"./documentIntelligence\";\n\nexport * from \"./documentIntelligence\";\nexport * from \"./parameters\";\nexport * from \"./responses\";\nexport * from \"./clientDefinitions\";\nexport * from \"./isUnexpected\";\nexport * from \"./models\";\nexport * from \"./outputModels\";\nexport * from \"./paginateHelper\";\nexport * from \"./pollingHelper\";\n\nexport default DocumentIntelligence;\n"]}
|