@meistrari/tela-sdk-js 2.11.0 → 2.12.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/dist/index.cjs +43 -17
- package/dist/index.d.cts +30 -1
- package/dist/index.d.mts +30 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.mjs +43 -17
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -23,7 +23,7 @@ const changeCase__namespace = /*#__PURE__*/_interopNamespaceCompat(changeCase);
|
|
|
23
23
|
const z__default = /*#__PURE__*/_interopDefaultCompat(z);
|
|
24
24
|
const Emittery__default = /*#__PURE__*/_interopDefaultCompat(Emittery);
|
|
25
25
|
|
|
26
|
-
const version = "2.
|
|
26
|
+
const version = "2.12.0";
|
|
27
27
|
|
|
28
28
|
var __defProp$a = Object.defineProperty;
|
|
29
29
|
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -2574,6 +2574,40 @@ var __publicField$4 = (obj, key, value) => {
|
|
|
2574
2574
|
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2575
2575
|
return value;
|
|
2576
2576
|
};
|
|
2577
|
+
function resolveBatchQueue(queue) {
|
|
2578
|
+
if (!queue) {
|
|
2579
|
+
return void 0;
|
|
2580
|
+
}
|
|
2581
|
+
const type = queue.type === void 0 ? "customer" : queue.type;
|
|
2582
|
+
if (type !== "internal" && type !== "customer") {
|
|
2583
|
+
throw new Error('Batch queue type must be either "internal" or "customer"');
|
|
2584
|
+
}
|
|
2585
|
+
if (typeof queue.application !== "string" || queue.application.trim().length === 0) {
|
|
2586
|
+
throw new Error("Batch queue application is required when queue is provided");
|
|
2587
|
+
}
|
|
2588
|
+
return {
|
|
2589
|
+
type,
|
|
2590
|
+
application: queue.application.trim()
|
|
2591
|
+
};
|
|
2592
|
+
}
|
|
2593
|
+
function createBatchRequestHeaders(params) {
|
|
2594
|
+
const headers = new Headers();
|
|
2595
|
+
let hasHeaders = false;
|
|
2596
|
+
const queue = resolveBatchQueue(params.queue);
|
|
2597
|
+
if (queue) {
|
|
2598
|
+
headers.set("x-batch-source", queue.type);
|
|
2599
|
+
headers.set("x-batch-source-application", queue.application);
|
|
2600
|
+
hasHeaders = true;
|
|
2601
|
+
}
|
|
2602
|
+
if (params.webhook?.headers) {
|
|
2603
|
+
for (const [key, value] of Object.entries(params.webhook.headers)) {
|
|
2604
|
+
const headerKey = key.toLowerCase().startsWith("x-tela-forward-") ? key : `x-tela-forward-${key}`;
|
|
2605
|
+
headers.set(headerKey, value);
|
|
2606
|
+
hasHeaders = true;
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
2609
|
+
return hasHeaders ? headers : void 0;
|
|
2610
|
+
}
|
|
2577
2611
|
const BatchResultItem = z__default.looseObject({
|
|
2578
2612
|
reference_id: z__default.string(),
|
|
2579
2613
|
status: z__default.string(),
|
|
@@ -3304,6 +3338,7 @@ class Batch {
|
|
|
3304
3338
|
const client = this._client;
|
|
3305
3339
|
const params = this._params;
|
|
3306
3340
|
async function execute() {
|
|
3341
|
+
const headers = createBatchRequestHeaders(params);
|
|
3307
3342
|
const { fileUrl } = await uploadFile(file, client);
|
|
3308
3343
|
const webhookUrl = params.webhook?.url ?? params.webhookUrl;
|
|
3309
3344
|
const body = {
|
|
@@ -3311,31 +3346,22 @@ class Batch {
|
|
|
3311
3346
|
inputFile: fileUrl,
|
|
3312
3347
|
webhookUrl
|
|
3313
3348
|
};
|
|
3314
|
-
const forwardHeaders = {};
|
|
3315
|
-
if (params.webhook?.headers) {
|
|
3316
|
-
for (const [key, value] of Object.entries(params.webhook.headers)) {
|
|
3317
|
-
const headerKey = key.toLowerCase().startsWith("x-tela-forward-") ? key : `x-tela-forward-${key}`;
|
|
3318
|
-
forwardHeaders[headerKey] = value;
|
|
3319
|
-
}
|
|
3320
|
-
}
|
|
3321
|
-
let headers;
|
|
3322
|
-
if (Object.keys(forwardHeaders).length > 0) {
|
|
3323
|
-
headers = new Headers();
|
|
3324
|
-
for (const [key, value] of Object.entries(forwardHeaders)) {
|
|
3325
|
-
headers.set(key, value);
|
|
3326
|
-
}
|
|
3327
|
-
}
|
|
3328
3349
|
return client.post("/_services/batch/batches", {
|
|
3329
3350
|
body,
|
|
3330
3351
|
...headers && { headers }
|
|
3331
3352
|
}).then((response) => new BatchExecution(response.id, client, params, response));
|
|
3332
3353
|
}
|
|
3354
|
+
let executionPromise;
|
|
3355
|
+
function getExecution() {
|
|
3356
|
+
executionPromise ?? (executionPromise = execute());
|
|
3357
|
+
return executionPromise;
|
|
3358
|
+
}
|
|
3333
3359
|
return {
|
|
3334
3360
|
then(onfulfilled, onrejected) {
|
|
3335
|
-
return
|
|
3361
|
+
return getExecution().then((execution) => onfulfilled?.(execution) ?? execution).catch(onrejected);
|
|
3336
3362
|
},
|
|
3337
3363
|
get result() {
|
|
3338
|
-
return
|
|
3364
|
+
return getExecution().then((execution) => execution.result);
|
|
3339
3365
|
}
|
|
3340
3366
|
};
|
|
3341
3367
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1947,6 +1947,27 @@ interface BatchWebhookConfig {
|
|
|
1947
1947
|
*/
|
|
1948
1948
|
headers?: Record<string, string>;
|
|
1949
1949
|
}
|
|
1950
|
+
/**
|
|
1951
|
+
* Source type for routing batch executions.
|
|
1952
|
+
*
|
|
1953
|
+
* @category Canvas
|
|
1954
|
+
*/
|
|
1955
|
+
type BatchQueueType = 'internal' | 'customer';
|
|
1956
|
+
/**
|
|
1957
|
+
* Queue/source metadata sent as headers when creating a batch execution.
|
|
1958
|
+
*
|
|
1959
|
+
* @category Canvas
|
|
1960
|
+
*/
|
|
1961
|
+
interface BatchQueueConfig {
|
|
1962
|
+
/**
|
|
1963
|
+
* Source type for the batch. Defaults to `customer` when omitted.
|
|
1964
|
+
*/
|
|
1965
|
+
type?: BatchQueueType;
|
|
1966
|
+
/**
|
|
1967
|
+
* Name of the application creating the batch. Required when `queue` is provided.
|
|
1968
|
+
*/
|
|
1969
|
+
application: string;
|
|
1970
|
+
}
|
|
1950
1971
|
/**
|
|
1951
1972
|
* Configuration options for batch execution.
|
|
1952
1973
|
*
|
|
@@ -2007,6 +2028,14 @@ interface BatchParams extends Omit<BaseExecutionParams, ExcludedParams> {
|
|
|
2007
2028
|
* ```
|
|
2008
2029
|
*/
|
|
2009
2030
|
webhook?: BatchWebhookConfig;
|
|
2031
|
+
/**
|
|
2032
|
+
* Optional queue/source metadata sent as headers when creating the batch.
|
|
2033
|
+
*
|
|
2034
|
+
* Sends:
|
|
2035
|
+
* - `x-batch-source`: `queue.type` or `customer` by default.
|
|
2036
|
+
* - `x-batch-source-application`: `queue.application`.
|
|
2037
|
+
*/
|
|
2038
|
+
queue?: BatchQueueConfig;
|
|
2010
2039
|
}
|
|
2011
2040
|
/**
|
|
2012
2041
|
* Promise-like wrapper for batch execution that provides direct result access.
|
|
@@ -4280,4 +4309,4 @@ declare class TelaSDK extends BaseClient {
|
|
|
4280
4309
|
*/
|
|
4281
4310
|
declare function createTelaClient(opts: TelaSDKOptions): TelaSDK;
|
|
4282
4311
|
|
|
4283
|
-
export { APIError, AuthenticationError, AuthorizationError, BadRequestError, BaseClient, type BaseClientOptions, type BaseTelaFileOptions, BatchExecutionFailedError, ConflictApiKeyAndJWTError, ConflictAuthMethodsError, ConflictError, ConnectionError, ConnectionTimeout, EmptyFileError, ExecutionFailedError, ExecutionNotStartedError, FileUploadError, type HTTPMethods, InternalServerError, InvalidExecutionModeError, InvalidFileURL, MissingApiKeyOrJWTError, MissingAuthError, type NormalizedTaskStatus, NotFoundError, RateLimitError, type RequestOptions, type SchemaBuilder, type Task, type TaskDeleteBulkResult, type TaskDeleteResult, TaskFailedError, type TaskInputContent, type TaskInputFile, type TaskListItem, type TaskListQuery, type TaskListResult, type TaskOrderBy, type TaskOutputContent, type TaskRerunResult, type TaskStatus, type TaskUndoApprovalBulkResult, type TaskUpdatePayload, Tasks, TelaError, TelaFile, type TelaFileInput, type TelaFileOptions, type TelaFileOptionsWithMimeType, TelaFileSchema, TelaSDK, type TelaSDKOptions, UnprocessableEntityError, UserAbortError, Vault, createTelaClient, extractTaskOutput, isTelaFile, isTelaFileArray, normalizeTaskStatus, toError };
|
|
4312
|
+
export { APIError, AuthenticationError, AuthorizationError, BadRequestError, BaseClient, type BaseClientOptions, type BaseTelaFileOptions, BatchExecutionFailedError, type BatchParams, type BatchQueueConfig, type BatchQueueType, type BatchWebhookConfig, ConflictApiKeyAndJWTError, ConflictAuthMethodsError, ConflictError, ConnectionError, ConnectionTimeout, EmptyFileError, ExecutionFailedError, ExecutionNotStartedError, FileUploadError, type HTTPMethods, InternalServerError, InvalidExecutionModeError, InvalidFileURL, MissingApiKeyOrJWTError, MissingAuthError, type NormalizedTaskStatus, NotFoundError, RateLimitError, type RequestOptions, type SchemaBuilder, type Task, type TaskDeleteBulkResult, type TaskDeleteResult, TaskFailedError, type TaskInputContent, type TaskInputFile, type TaskListItem, type TaskListQuery, type TaskListResult, type TaskOrderBy, type TaskOutputContent, type TaskRerunResult, type TaskStatus, type TaskUndoApprovalBulkResult, type TaskUpdatePayload, Tasks, TelaError, TelaFile, type TelaFileInput, type TelaFileOptions, type TelaFileOptionsWithMimeType, TelaFileSchema, TelaSDK, type TelaSDKOptions, UnprocessableEntityError, UserAbortError, Vault, createTelaClient, extractTaskOutput, isTelaFile, isTelaFileArray, normalizeTaskStatus, toError };
|
package/dist/index.d.mts
CHANGED
|
@@ -1947,6 +1947,27 @@ interface BatchWebhookConfig {
|
|
|
1947
1947
|
*/
|
|
1948
1948
|
headers?: Record<string, string>;
|
|
1949
1949
|
}
|
|
1950
|
+
/**
|
|
1951
|
+
* Source type for routing batch executions.
|
|
1952
|
+
*
|
|
1953
|
+
* @category Canvas
|
|
1954
|
+
*/
|
|
1955
|
+
type BatchQueueType = 'internal' | 'customer';
|
|
1956
|
+
/**
|
|
1957
|
+
* Queue/source metadata sent as headers when creating a batch execution.
|
|
1958
|
+
*
|
|
1959
|
+
* @category Canvas
|
|
1960
|
+
*/
|
|
1961
|
+
interface BatchQueueConfig {
|
|
1962
|
+
/**
|
|
1963
|
+
* Source type for the batch. Defaults to `customer` when omitted.
|
|
1964
|
+
*/
|
|
1965
|
+
type?: BatchQueueType;
|
|
1966
|
+
/**
|
|
1967
|
+
* Name of the application creating the batch. Required when `queue` is provided.
|
|
1968
|
+
*/
|
|
1969
|
+
application: string;
|
|
1970
|
+
}
|
|
1950
1971
|
/**
|
|
1951
1972
|
* Configuration options for batch execution.
|
|
1952
1973
|
*
|
|
@@ -2007,6 +2028,14 @@ interface BatchParams extends Omit<BaseExecutionParams, ExcludedParams> {
|
|
|
2007
2028
|
* ```
|
|
2008
2029
|
*/
|
|
2009
2030
|
webhook?: BatchWebhookConfig;
|
|
2031
|
+
/**
|
|
2032
|
+
* Optional queue/source metadata sent as headers when creating the batch.
|
|
2033
|
+
*
|
|
2034
|
+
* Sends:
|
|
2035
|
+
* - `x-batch-source`: `queue.type` or `customer` by default.
|
|
2036
|
+
* - `x-batch-source-application`: `queue.application`.
|
|
2037
|
+
*/
|
|
2038
|
+
queue?: BatchQueueConfig;
|
|
2010
2039
|
}
|
|
2011
2040
|
/**
|
|
2012
2041
|
* Promise-like wrapper for batch execution that provides direct result access.
|
|
@@ -4280,4 +4309,4 @@ declare class TelaSDK extends BaseClient {
|
|
|
4280
4309
|
*/
|
|
4281
4310
|
declare function createTelaClient(opts: TelaSDKOptions): TelaSDK;
|
|
4282
4311
|
|
|
4283
|
-
export { APIError, AuthenticationError, AuthorizationError, BadRequestError, BaseClient, type BaseClientOptions, type BaseTelaFileOptions, BatchExecutionFailedError, ConflictApiKeyAndJWTError, ConflictAuthMethodsError, ConflictError, ConnectionError, ConnectionTimeout, EmptyFileError, ExecutionFailedError, ExecutionNotStartedError, FileUploadError, type HTTPMethods, InternalServerError, InvalidExecutionModeError, InvalidFileURL, MissingApiKeyOrJWTError, MissingAuthError, type NormalizedTaskStatus, NotFoundError, RateLimitError, type RequestOptions, type SchemaBuilder, type Task, type TaskDeleteBulkResult, type TaskDeleteResult, TaskFailedError, type TaskInputContent, type TaskInputFile, type TaskListItem, type TaskListQuery, type TaskListResult, type TaskOrderBy, type TaskOutputContent, type TaskRerunResult, type TaskStatus, type TaskUndoApprovalBulkResult, type TaskUpdatePayload, Tasks, TelaError, TelaFile, type TelaFileInput, type TelaFileOptions, type TelaFileOptionsWithMimeType, TelaFileSchema, TelaSDK, type TelaSDKOptions, UnprocessableEntityError, UserAbortError, Vault, createTelaClient, extractTaskOutput, isTelaFile, isTelaFileArray, normalizeTaskStatus, toError };
|
|
4312
|
+
export { APIError, AuthenticationError, AuthorizationError, BadRequestError, BaseClient, type BaseClientOptions, type BaseTelaFileOptions, BatchExecutionFailedError, type BatchParams, type BatchQueueConfig, type BatchQueueType, type BatchWebhookConfig, ConflictApiKeyAndJWTError, ConflictAuthMethodsError, ConflictError, ConnectionError, ConnectionTimeout, EmptyFileError, ExecutionFailedError, ExecutionNotStartedError, FileUploadError, type HTTPMethods, InternalServerError, InvalidExecutionModeError, InvalidFileURL, MissingApiKeyOrJWTError, MissingAuthError, type NormalizedTaskStatus, NotFoundError, RateLimitError, type RequestOptions, type SchemaBuilder, type Task, type TaskDeleteBulkResult, type TaskDeleteResult, TaskFailedError, type TaskInputContent, type TaskInputFile, type TaskListItem, type TaskListQuery, type TaskListResult, type TaskOrderBy, type TaskOutputContent, type TaskRerunResult, type TaskStatus, type TaskUndoApprovalBulkResult, type TaskUpdatePayload, Tasks, TelaError, TelaFile, type TelaFileInput, type TelaFileOptions, type TelaFileOptionsWithMimeType, TelaFileSchema, TelaSDK, type TelaSDKOptions, UnprocessableEntityError, UserAbortError, Vault, createTelaClient, extractTaskOutput, isTelaFile, isTelaFileArray, normalizeTaskStatus, toError };
|
package/dist/index.d.ts
CHANGED
|
@@ -1947,6 +1947,27 @@ interface BatchWebhookConfig {
|
|
|
1947
1947
|
*/
|
|
1948
1948
|
headers?: Record<string, string>;
|
|
1949
1949
|
}
|
|
1950
|
+
/**
|
|
1951
|
+
* Source type for routing batch executions.
|
|
1952
|
+
*
|
|
1953
|
+
* @category Canvas
|
|
1954
|
+
*/
|
|
1955
|
+
type BatchQueueType = 'internal' | 'customer';
|
|
1956
|
+
/**
|
|
1957
|
+
* Queue/source metadata sent as headers when creating a batch execution.
|
|
1958
|
+
*
|
|
1959
|
+
* @category Canvas
|
|
1960
|
+
*/
|
|
1961
|
+
interface BatchQueueConfig {
|
|
1962
|
+
/**
|
|
1963
|
+
* Source type for the batch. Defaults to `customer` when omitted.
|
|
1964
|
+
*/
|
|
1965
|
+
type?: BatchQueueType;
|
|
1966
|
+
/**
|
|
1967
|
+
* Name of the application creating the batch. Required when `queue` is provided.
|
|
1968
|
+
*/
|
|
1969
|
+
application: string;
|
|
1970
|
+
}
|
|
1950
1971
|
/**
|
|
1951
1972
|
* Configuration options for batch execution.
|
|
1952
1973
|
*
|
|
@@ -2007,6 +2028,14 @@ interface BatchParams extends Omit<BaseExecutionParams, ExcludedParams> {
|
|
|
2007
2028
|
* ```
|
|
2008
2029
|
*/
|
|
2009
2030
|
webhook?: BatchWebhookConfig;
|
|
2031
|
+
/**
|
|
2032
|
+
* Optional queue/source metadata sent as headers when creating the batch.
|
|
2033
|
+
*
|
|
2034
|
+
* Sends:
|
|
2035
|
+
* - `x-batch-source`: `queue.type` or `customer` by default.
|
|
2036
|
+
* - `x-batch-source-application`: `queue.application`.
|
|
2037
|
+
*/
|
|
2038
|
+
queue?: BatchQueueConfig;
|
|
2010
2039
|
}
|
|
2011
2040
|
/**
|
|
2012
2041
|
* Promise-like wrapper for batch execution that provides direct result access.
|
|
@@ -4280,4 +4309,4 @@ declare class TelaSDK extends BaseClient {
|
|
|
4280
4309
|
*/
|
|
4281
4310
|
declare function createTelaClient(opts: TelaSDKOptions): TelaSDK;
|
|
4282
4311
|
|
|
4283
|
-
export { APIError, AuthenticationError, AuthorizationError, BadRequestError, BaseClient, type BaseClientOptions, type BaseTelaFileOptions, BatchExecutionFailedError, ConflictApiKeyAndJWTError, ConflictAuthMethodsError, ConflictError, ConnectionError, ConnectionTimeout, EmptyFileError, ExecutionFailedError, ExecutionNotStartedError, FileUploadError, type HTTPMethods, InternalServerError, InvalidExecutionModeError, InvalidFileURL, MissingApiKeyOrJWTError, MissingAuthError, type NormalizedTaskStatus, NotFoundError, RateLimitError, type RequestOptions, type SchemaBuilder, type Task, type TaskDeleteBulkResult, type TaskDeleteResult, TaskFailedError, type TaskInputContent, type TaskInputFile, type TaskListItem, type TaskListQuery, type TaskListResult, type TaskOrderBy, type TaskOutputContent, type TaskRerunResult, type TaskStatus, type TaskUndoApprovalBulkResult, type TaskUpdatePayload, Tasks, TelaError, TelaFile, type TelaFileInput, type TelaFileOptions, type TelaFileOptionsWithMimeType, TelaFileSchema, TelaSDK, type TelaSDKOptions, UnprocessableEntityError, UserAbortError, Vault, createTelaClient, extractTaskOutput, isTelaFile, isTelaFileArray, normalizeTaskStatus, toError };
|
|
4312
|
+
export { APIError, AuthenticationError, AuthorizationError, BadRequestError, BaseClient, type BaseClientOptions, type BaseTelaFileOptions, BatchExecutionFailedError, type BatchParams, type BatchQueueConfig, type BatchQueueType, type BatchWebhookConfig, ConflictApiKeyAndJWTError, ConflictAuthMethodsError, ConflictError, ConnectionError, ConnectionTimeout, EmptyFileError, ExecutionFailedError, ExecutionNotStartedError, FileUploadError, type HTTPMethods, InternalServerError, InvalidExecutionModeError, InvalidFileURL, MissingApiKeyOrJWTError, MissingAuthError, type NormalizedTaskStatus, NotFoundError, RateLimitError, type RequestOptions, type SchemaBuilder, type Task, type TaskDeleteBulkResult, type TaskDeleteResult, TaskFailedError, type TaskInputContent, type TaskInputFile, type TaskListItem, type TaskListQuery, type TaskListResult, type TaskOrderBy, type TaskOutputContent, type TaskRerunResult, type TaskStatus, type TaskUndoApprovalBulkResult, type TaskUpdatePayload, Tasks, TelaError, TelaFile, type TelaFileInput, type TelaFileOptions, type TelaFileOptionsWithMimeType, TelaFileSchema, TelaSDK, type TelaSDKOptions, UnprocessableEntityError, UserAbortError, Vault, createTelaClient, extractTaskOutput, isTelaFile, isTelaFileArray, normalizeTaskStatus, toError };
|
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { Minimatch } from 'minimatch';
|
|
|
3
3
|
import z, { z as z$1, ZodError } from 'zod';
|
|
4
4
|
import Emittery from 'emittery';
|
|
5
5
|
|
|
6
|
-
const version = "2.
|
|
6
|
+
const version = "2.12.0";
|
|
7
7
|
|
|
8
8
|
var __defProp$a = Object.defineProperty;
|
|
9
9
|
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -2554,6 +2554,40 @@ var __publicField$4 = (obj, key, value) => {
|
|
|
2554
2554
|
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2555
2555
|
return value;
|
|
2556
2556
|
};
|
|
2557
|
+
function resolveBatchQueue(queue) {
|
|
2558
|
+
if (!queue) {
|
|
2559
|
+
return void 0;
|
|
2560
|
+
}
|
|
2561
|
+
const type = queue.type === void 0 ? "customer" : queue.type;
|
|
2562
|
+
if (type !== "internal" && type !== "customer") {
|
|
2563
|
+
throw new Error('Batch queue type must be either "internal" or "customer"');
|
|
2564
|
+
}
|
|
2565
|
+
if (typeof queue.application !== "string" || queue.application.trim().length === 0) {
|
|
2566
|
+
throw new Error("Batch queue application is required when queue is provided");
|
|
2567
|
+
}
|
|
2568
|
+
return {
|
|
2569
|
+
type,
|
|
2570
|
+
application: queue.application.trim()
|
|
2571
|
+
};
|
|
2572
|
+
}
|
|
2573
|
+
function createBatchRequestHeaders(params) {
|
|
2574
|
+
const headers = new Headers();
|
|
2575
|
+
let hasHeaders = false;
|
|
2576
|
+
const queue = resolveBatchQueue(params.queue);
|
|
2577
|
+
if (queue) {
|
|
2578
|
+
headers.set("x-batch-source", queue.type);
|
|
2579
|
+
headers.set("x-batch-source-application", queue.application);
|
|
2580
|
+
hasHeaders = true;
|
|
2581
|
+
}
|
|
2582
|
+
if (params.webhook?.headers) {
|
|
2583
|
+
for (const [key, value] of Object.entries(params.webhook.headers)) {
|
|
2584
|
+
const headerKey = key.toLowerCase().startsWith("x-tela-forward-") ? key : `x-tela-forward-${key}`;
|
|
2585
|
+
headers.set(headerKey, value);
|
|
2586
|
+
hasHeaders = true;
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
return hasHeaders ? headers : void 0;
|
|
2590
|
+
}
|
|
2557
2591
|
const BatchResultItem = z.looseObject({
|
|
2558
2592
|
reference_id: z.string(),
|
|
2559
2593
|
status: z.string(),
|
|
@@ -3284,6 +3318,7 @@ class Batch {
|
|
|
3284
3318
|
const client = this._client;
|
|
3285
3319
|
const params = this._params;
|
|
3286
3320
|
async function execute() {
|
|
3321
|
+
const headers = createBatchRequestHeaders(params);
|
|
3287
3322
|
const { fileUrl } = await uploadFile(file, client);
|
|
3288
3323
|
const webhookUrl = params.webhook?.url ?? params.webhookUrl;
|
|
3289
3324
|
const body = {
|
|
@@ -3291,31 +3326,22 @@ class Batch {
|
|
|
3291
3326
|
inputFile: fileUrl,
|
|
3292
3327
|
webhookUrl
|
|
3293
3328
|
};
|
|
3294
|
-
const forwardHeaders = {};
|
|
3295
|
-
if (params.webhook?.headers) {
|
|
3296
|
-
for (const [key, value] of Object.entries(params.webhook.headers)) {
|
|
3297
|
-
const headerKey = key.toLowerCase().startsWith("x-tela-forward-") ? key : `x-tela-forward-${key}`;
|
|
3298
|
-
forwardHeaders[headerKey] = value;
|
|
3299
|
-
}
|
|
3300
|
-
}
|
|
3301
|
-
let headers;
|
|
3302
|
-
if (Object.keys(forwardHeaders).length > 0) {
|
|
3303
|
-
headers = new Headers();
|
|
3304
|
-
for (const [key, value] of Object.entries(forwardHeaders)) {
|
|
3305
|
-
headers.set(key, value);
|
|
3306
|
-
}
|
|
3307
|
-
}
|
|
3308
3329
|
return client.post("/_services/batch/batches", {
|
|
3309
3330
|
body,
|
|
3310
3331
|
...headers && { headers }
|
|
3311
3332
|
}).then((response) => new BatchExecution(response.id, client, params, response));
|
|
3312
3333
|
}
|
|
3334
|
+
let executionPromise;
|
|
3335
|
+
function getExecution() {
|
|
3336
|
+
executionPromise ?? (executionPromise = execute());
|
|
3337
|
+
return executionPromise;
|
|
3338
|
+
}
|
|
3313
3339
|
return {
|
|
3314
3340
|
then(onfulfilled, onrejected) {
|
|
3315
|
-
return
|
|
3341
|
+
return getExecution().then((execution) => onfulfilled?.(execution) ?? execution).catch(onrejected);
|
|
3316
3342
|
},
|
|
3317
3343
|
get result() {
|
|
3318
|
-
return
|
|
3344
|
+
return getExecution().then((execution) => execution.result);
|
|
3319
3345
|
}
|
|
3320
3346
|
};
|
|
3321
3347
|
}
|