@chrt-inc/typescript-sdk 1.562.0 → 1.575.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/cjs/Client.js +2 -2
- package/dist/cjs/api/resources/shipping/resources/docs/client/Client.d.ts +1 -11
- package/dist/cjs/api/resources/shipping/resources/docs/client/Client.js +1 -10
- package/dist/cjs/api/resources/shipping/resources/docs/client/requests/GenerateShippingDocReq.d.ts +2 -2
- package/dist/cjs/api/resources/shipping/resources/orderDrafts/resources/expanded/client/Client.d.ts +3 -3
- package/dist/cjs/api/resources/shipping/resources/orderDrafts/resources/expanded/client/Client.js +7 -7
- package/dist/cjs/api/resources/shipping/resources/orders/resources/expanded/client/Client.d.ts +8 -6
- package/dist/cjs/api/resources/shipping/resources/orders/resources/expanded/client/Client.js +32 -24
- package/dist/cjs/api/resources/shipping/resources/orders/resources/expanded/client/requests/ExpandedListForForwarderOperatorsV1Request.d.ts +2 -0
- package/dist/cjs/api/resources/shipping/resources/orders/resources/expanded/client/requests/ExpandedListForShipperOperatorsV1Request.d.ts +2 -0
- package/dist/cjs/api/resources/shipping/resources/taskGroups/resources/expanded/client/Client.d.ts +2 -0
- package/dist/cjs/api/resources/shipping/resources/taskGroups/resources/expanded/client/Client.js +18 -10
- package/dist/cjs/api/resources/shipping/resources/taskGroups/resources/expanded/client/requests/ExpandedListForCourierDriverV1Request.d.ts +2 -0
- package/dist/cjs/api/resources/shipping/resources/taskGroups/resources/expanded/client/requests/ExpandedListForCourierOperatorsV1Request.d.ts +2 -0
- package/dist/cjs/api/resources/shipping/resources/taskGroups/resources/taskGroupId/client/Client.d.ts +6 -6
- package/dist/cjs/api/resources/shipping/resources/taskGroups/resources/taskGroupId/client/Client.js +14 -14
- package/dist/cjs/api/resources/shipping/resources/tasks/client/Client.d.ts +1 -1
- package/dist/cjs/api/resources/shipping/resources/tasks/client/Client.js +1 -1
- package/dist/cjs/api/resources/tracking/resources/sharingSettings/client/Client.d.ts +4 -4
- package/dist/cjs/api/resources/tracking/resources/sharingSettings/client/Client.js +8 -8
- package/dist/cjs/api/resources/utils/index.d.ts +1 -1
- package/dist/cjs/api/resources/utils/index.js +1 -1
- package/dist/cjs/api/resources/utils/resources/dev/client/Client.d.ts +2 -13
- package/dist/cjs/api/resources/utils/resources/dev/client/Client.js +14 -13
- package/dist/cjs/api/resources/utils/resources/dev/index.d.ts +1 -0
- package/dist/cjs/api/resources/utils/resources/dev/index.js +1 -0
- package/dist/cjs/api/resources/utils/resources/dev/types/OrderBuilderStreamEvent.d.ts +27 -0
- package/dist/cjs/api/resources/utils/resources/dev/types/OrderBuilderStreamEvent.js +14 -0
- package/dist/cjs/api/resources/utils/resources/dev/types/index.d.ts +1 -0
- package/dist/cjs/api/resources/utils/resources/dev/types/index.js +17 -0
- package/dist/cjs/api/resources/utils/resources/index.d.ts +1 -0
- package/dist/cjs/api/resources/utils/resources/index.js +1 -0
- package/dist/cjs/api/types/TaskClientUpdate1.d.ts +2 -0
- package/dist/cjs/core/index.d.ts +1 -0
- package/dist/cjs/core/index.js +1 -0
- package/dist/cjs/core/stream/Stream.d.ts +46 -0
- package/dist/cjs/core/stream/Stream.js +169 -0
- package/dist/cjs/core/stream/index.d.ts +1 -0
- package/dist/cjs/core/stream/index.js +5 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Client.mjs +2 -2
- package/dist/esm/api/resources/shipping/resources/docs/client/Client.d.mts +1 -11
- package/dist/esm/api/resources/shipping/resources/docs/client/Client.mjs +1 -10
- package/dist/esm/api/resources/shipping/resources/docs/client/requests/GenerateShippingDocReq.d.mts +2 -2
- package/dist/esm/api/resources/shipping/resources/orderDrafts/resources/expanded/client/Client.d.mts +3 -3
- package/dist/esm/api/resources/shipping/resources/orderDrafts/resources/expanded/client/Client.mjs +7 -7
- package/dist/esm/api/resources/shipping/resources/orders/resources/expanded/client/Client.d.mts +8 -6
- package/dist/esm/api/resources/shipping/resources/orders/resources/expanded/client/Client.mjs +32 -24
- package/dist/esm/api/resources/shipping/resources/orders/resources/expanded/client/requests/ExpandedListForForwarderOperatorsV1Request.d.mts +2 -0
- package/dist/esm/api/resources/shipping/resources/orders/resources/expanded/client/requests/ExpandedListForShipperOperatorsV1Request.d.mts +2 -0
- package/dist/esm/api/resources/shipping/resources/taskGroups/resources/expanded/client/Client.d.mts +2 -0
- package/dist/esm/api/resources/shipping/resources/taskGroups/resources/expanded/client/Client.mjs +18 -10
- package/dist/esm/api/resources/shipping/resources/taskGroups/resources/expanded/client/requests/ExpandedListForCourierDriverV1Request.d.mts +2 -0
- package/dist/esm/api/resources/shipping/resources/taskGroups/resources/expanded/client/requests/ExpandedListForCourierOperatorsV1Request.d.mts +2 -0
- package/dist/esm/api/resources/shipping/resources/taskGroups/resources/taskGroupId/client/Client.d.mts +6 -6
- package/dist/esm/api/resources/shipping/resources/taskGroups/resources/taskGroupId/client/Client.mjs +14 -14
- package/dist/esm/api/resources/shipping/resources/tasks/client/Client.d.mts +1 -1
- package/dist/esm/api/resources/shipping/resources/tasks/client/Client.mjs +1 -1
- package/dist/esm/api/resources/tracking/resources/sharingSettings/client/Client.d.mts +4 -4
- package/dist/esm/api/resources/tracking/resources/sharingSettings/client/Client.mjs +8 -8
- package/dist/esm/api/resources/utils/index.d.mts +1 -1
- package/dist/esm/api/resources/utils/index.mjs +1 -1
- package/dist/esm/api/resources/utils/resources/dev/client/Client.d.mts +2 -13
- package/dist/esm/api/resources/utils/resources/dev/client/Client.mjs +14 -13
- package/dist/esm/api/resources/utils/resources/dev/index.d.mts +1 -0
- package/dist/esm/api/resources/utils/resources/dev/index.mjs +1 -0
- package/dist/esm/api/resources/utils/resources/dev/types/OrderBuilderStreamEvent.d.mts +27 -0
- package/dist/esm/api/resources/utils/resources/dev/types/OrderBuilderStreamEvent.mjs +11 -0
- package/dist/esm/api/resources/utils/resources/dev/types/index.d.mts +1 -0
- package/dist/esm/api/resources/utils/resources/dev/types/index.mjs +1 -0
- package/dist/esm/api/resources/utils/resources/index.d.mts +1 -0
- package/dist/esm/api/resources/utils/resources/index.mjs +1 -0
- package/dist/esm/api/types/TaskClientUpdate1.d.mts +2 -0
- package/dist/esm/core/index.d.mts +1 -0
- package/dist/esm/core/index.mjs +1 -0
- package/dist/esm/core/stream/Stream.d.mts +46 -0
- package/dist/esm/core/stream/Stream.mjs +164 -0
- package/dist/esm/core/stream/index.d.mts +1 -0
- package/dist/esm/core/stream/index.mjs +1 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +1 -1
- package/reference.md +32 -25
|
@@ -51,7 +51,7 @@ export declare class Tasks {
|
|
|
51
51
|
addToTaskGroupV1(taskGroupId: string, request: Chrt.shipping.AddTaskToGroupReq, requestOptions?: Tasks.RequestOptions): core.HttpResponsePromise<string>;
|
|
52
52
|
private __addToTaskGroupV1;
|
|
53
53
|
/**
|
|
54
|
-
* Updates a task.
|
|
54
|
+
* Updates a task. Operational fields require STAGED status (lig_owner_operators). order_placer_comments can be edited on any non-DRAFT task (order_creator_org_operators). | (TaskClientUpdate1) -> (PydanticObjectId)
|
|
55
55
|
*
|
|
56
56
|
* @param {string} taskId
|
|
57
57
|
* @param {Chrt.TaskClientUpdate1} request
|
|
@@ -89,7 +89,7 @@ export class Tasks {
|
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
|
-
* Updates a task.
|
|
92
|
+
* Updates a task. Operational fields require STAGED status (lig_owner_operators). order_placer_comments can be edited on any non-DRAFT task (order_creator_org_operators). | (TaskClientUpdate1) -> (PydanticObjectId)
|
|
93
93
|
*
|
|
94
94
|
* @param {string} taskId
|
|
95
95
|
* @param {Chrt.TaskClientUpdate1} request
|
|
@@ -84,17 +84,17 @@ export declare class SharingSettings {
|
|
|
84
84
|
cargoByDeviceSettingsV1(request: Chrt.tracking.CargoByDeviceSharingSettingsUpdateReq, requestOptions?: SharingSettings.RequestOptions): core.HttpResponsePromise<Chrt.CargoByDeviceSharingSettings1>;
|
|
85
85
|
private __cargoByDeviceSettingsV1;
|
|
86
86
|
/**
|
|
87
|
-
* Get all tracking datasets and their sharing settings for a given order. If authenticated, returns datasets the user has direct access to plus public datasets. If unauthenticated, returns only datasets with public=True. | () -> (list[TrackingSharingSettingsRes])
|
|
87
|
+
* Get all tracking datasets and their sharing settings for a given order. If authenticated, returns datasets the user has direct access to plus public datasets. If unauthenticated, returns only datasets with public=True. Note: looking up by off_chrt_reference_id requires authentication because it is only org-level unique and needs the caller's org_id to resolve unambiguously. | () -> (list[TrackingSharingSettingsRes])
|
|
88
88
|
*
|
|
89
|
-
* @param {string}
|
|
89
|
+
* @param {string} orderRef - Order ID, short ID, or off-chrt reference ID
|
|
90
90
|
* @param {SharingSettings.RequestOptions} requestOptions - Request-specific configuration.
|
|
91
91
|
*
|
|
92
92
|
* @throws {@link Chrt.UnprocessableEntityError}
|
|
93
93
|
*
|
|
94
94
|
* @example
|
|
95
|
-
* await client.tracking.sharingSettings.getSettingsV1("
|
|
95
|
+
* await client.tracking.sharingSettings.getSettingsV1("order_ref")
|
|
96
96
|
*/
|
|
97
|
-
getSettingsV1(
|
|
97
|
+
getSettingsV1(orderRef: string, requestOptions?: SharingSettings.RequestOptions): core.HttpResponsePromise<Chrt.TrackingSharingSettingsRes[]>;
|
|
98
98
|
private __getSettingsV1;
|
|
99
99
|
protected _getAuthorizationHeader(): Promise<string | undefined>;
|
|
100
100
|
}
|
|
@@ -223,25 +223,25 @@ export class SharingSettings {
|
|
|
223
223
|
});
|
|
224
224
|
}
|
|
225
225
|
/**
|
|
226
|
-
* Get all tracking datasets and their sharing settings for a given order. If authenticated, returns datasets the user has direct access to plus public datasets. If unauthenticated, returns only datasets with public=True. | () -> (list[TrackingSharingSettingsRes])
|
|
226
|
+
* Get all tracking datasets and their sharing settings for a given order. If authenticated, returns datasets the user has direct access to plus public datasets. If unauthenticated, returns only datasets with public=True. Note: looking up by off_chrt_reference_id requires authentication because it is only org-level unique and needs the caller's org_id to resolve unambiguously. | () -> (list[TrackingSharingSettingsRes])
|
|
227
227
|
*
|
|
228
|
-
* @param {string}
|
|
228
|
+
* @param {string} orderRef - Order ID, short ID, or off-chrt reference ID
|
|
229
229
|
* @param {SharingSettings.RequestOptions} requestOptions - Request-specific configuration.
|
|
230
230
|
*
|
|
231
231
|
* @throws {@link Chrt.UnprocessableEntityError}
|
|
232
232
|
*
|
|
233
233
|
* @example
|
|
234
|
-
* await client.tracking.sharingSettings.getSettingsV1("
|
|
234
|
+
* await client.tracking.sharingSettings.getSettingsV1("order_ref")
|
|
235
235
|
*/
|
|
236
|
-
getSettingsV1(
|
|
237
|
-
return core.HttpResponsePromise.fromPromise(this.__getSettingsV1(
|
|
236
|
+
getSettingsV1(orderRef, requestOptions) {
|
|
237
|
+
return core.HttpResponsePromise.fromPromise(this.__getSettingsV1(orderRef, requestOptions));
|
|
238
238
|
}
|
|
239
|
-
__getSettingsV1(
|
|
239
|
+
__getSettingsV1(orderRef, requestOptions) {
|
|
240
240
|
return __awaiter(this, void 0, void 0, function* () {
|
|
241
241
|
var _a, _b, _c, _d;
|
|
242
242
|
let _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
243
243
|
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
|
|
244
|
-
url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.ChrtEnvironment.Local, `tracking/sharing_settings/by_order/v1/${encodeURIComponent(
|
|
244
|
+
url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.ChrtEnvironment.Local, `tracking/sharing_settings/by_order/v1/${encodeURIComponent(orderRef)}`),
|
|
245
245
|
method: "GET",
|
|
246
246
|
headers: _headers,
|
|
247
247
|
queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
|
|
@@ -272,7 +272,7 @@ export class SharingSettings {
|
|
|
272
272
|
rawResponse: _response.rawResponse,
|
|
273
273
|
});
|
|
274
274
|
case "timeout":
|
|
275
|
-
throw new errors.ChrtTimeoutError("Timeout exceeded when calling GET /tracking/sharing_settings/by_order/v1/{
|
|
275
|
+
throw new errors.ChrtTimeoutError("Timeout exceeded when calling GET /tracking/sharing_settings/by_order/v1/{order_ref}.");
|
|
276
276
|
case "unknown":
|
|
277
277
|
throw new errors.ChrtError({
|
|
278
278
|
message: _response.error.errorMessage,
|
|
@@ -75,20 +75,9 @@ export declare class Dev {
|
|
|
75
75
|
postAgentOrderBuilderV1(request: Chrt.OrderBuilderReq, requestOptions?: Dev.RequestOptions): core.HttpResponsePromise<Chrt.OrderBuilderRes>;
|
|
76
76
|
private __postAgentOrderBuilderV1;
|
|
77
77
|
/**
|
|
78
|
-
* Same as /agent/order-builder/v1 but streams progress events via SSE as each workflow step completes. | (OrderBuilderReq) -> SSE stream of
|
|
79
|
-
*
|
|
80
|
-
* @param {Chrt.OrderBuilderReq} request
|
|
81
|
-
* @param {Dev.RequestOptions} requestOptions - Request-specific configuration.
|
|
82
|
-
*
|
|
83
|
-
* @throws {@link Chrt.UnprocessableEntityError}
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* await client.utils.dev.postAgentOrderBuilderStreamV1({
|
|
87
|
-
* order_short_id: "order_short_id",
|
|
88
|
-
* text: "text"
|
|
89
|
-
* })
|
|
78
|
+
* Same as /agent/order-builder/v1 but streams progress events via SSE as each workflow step completes. | (OrderBuilderReq) -> SSE stream of OrderBuilderStreamEvent
|
|
90
79
|
*/
|
|
91
|
-
postAgentOrderBuilderStreamV1(request: Chrt.OrderBuilderReq, requestOptions?: Dev.RequestOptions): core.HttpResponsePromise<
|
|
80
|
+
postAgentOrderBuilderStreamV1(request: Chrt.OrderBuilderReq, requestOptions?: Dev.RequestOptions): core.HttpResponsePromise<core.Stream<Chrt.utils.OrderBuilderStreamEvent>>;
|
|
92
81
|
private __postAgentOrderBuilderStreamV1;
|
|
93
82
|
/**
|
|
94
83
|
* (DEPRECATED) Extracts and returns the user ID from the authenticated request's JWT token. | () -> (str)
|
|
@@ -211,18 +211,7 @@ export class Dev {
|
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
213
|
/**
|
|
214
|
-
* Same as /agent/order-builder/v1 but streams progress events via SSE as each workflow step completes. | (OrderBuilderReq) -> SSE stream of
|
|
215
|
-
*
|
|
216
|
-
* @param {Chrt.OrderBuilderReq} request
|
|
217
|
-
* @param {Dev.RequestOptions} requestOptions - Request-specific configuration.
|
|
218
|
-
*
|
|
219
|
-
* @throws {@link Chrt.UnprocessableEntityError}
|
|
220
|
-
*
|
|
221
|
-
* @example
|
|
222
|
-
* await client.utils.dev.postAgentOrderBuilderStreamV1({
|
|
223
|
-
* order_short_id: "order_short_id",
|
|
224
|
-
* text: "text"
|
|
225
|
-
* })
|
|
214
|
+
* Same as /agent/order-builder/v1 but streams progress events via SSE as each workflow step completes. | (OrderBuilderReq) -> SSE stream of OrderBuilderStreamEvent
|
|
226
215
|
*/
|
|
227
216
|
postAgentOrderBuilderStreamV1(request, requestOptions) {
|
|
228
217
|
return core.HttpResponsePromise.fromPromise(this.__postAgentOrderBuilderStreamV1(request, requestOptions));
|
|
@@ -239,12 +228,24 @@ export class Dev {
|
|
|
239
228
|
queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
|
|
240
229
|
requestType: "json",
|
|
241
230
|
body: request,
|
|
231
|
+
responseType: "sse",
|
|
242
232
|
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
|
|
243
233
|
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
|
|
244
234
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
245
235
|
});
|
|
246
236
|
if (_response.ok) {
|
|
247
|
-
return {
|
|
237
|
+
return {
|
|
238
|
+
data: new core.Stream({
|
|
239
|
+
stream: _response.body,
|
|
240
|
+
parse: (data) => data,
|
|
241
|
+
signal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
242
|
+
eventShape: {
|
|
243
|
+
type: "sse",
|
|
244
|
+
streamTerminator: "[DONE]",
|
|
245
|
+
},
|
|
246
|
+
}),
|
|
247
|
+
rawResponse: _response.rawResponse,
|
|
248
|
+
};
|
|
248
249
|
}
|
|
249
250
|
if (_response.error.reason === "status-code") {
|
|
250
251
|
switch (_response.error.statusCode) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was auto-generated by Fern from our API Definition.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Unified SSE data schema for Fern SDK generation. The SSE `event:` frame
|
|
6
|
+
* carries the discriminator (progress | complete | error); only relevant
|
|
7
|
+
* fields are serialized per event type via exclude_none.
|
|
8
|
+
*/
|
|
9
|
+
export interface OrderBuilderStreamEvent {
|
|
10
|
+
event: OrderBuilderStreamEvent.Event;
|
|
11
|
+
message?: string | null;
|
|
12
|
+
order_id?: string | null;
|
|
13
|
+
order_short_id?: string | null;
|
|
14
|
+
summary?: string | null;
|
|
15
|
+
validation_passed?: boolean | null;
|
|
16
|
+
validation_issues?: string[] | null;
|
|
17
|
+
notes?: string[] | null;
|
|
18
|
+
error?: string | null;
|
|
19
|
+
}
|
|
20
|
+
export declare namespace OrderBuilderStreamEvent {
|
|
21
|
+
type Event = "progress" | "complete" | "error";
|
|
22
|
+
const Event: {
|
|
23
|
+
readonly Progress: "progress";
|
|
24
|
+
readonly Complete: "complete";
|
|
25
|
+
readonly Error: "error";
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was auto-generated by Fern from our API Definition.
|
|
3
|
+
*/
|
|
4
|
+
export var OrderBuilderStreamEvent;
|
|
5
|
+
(function (OrderBuilderStreamEvent) {
|
|
6
|
+
OrderBuilderStreamEvent.Event = {
|
|
7
|
+
Progress: "progress",
|
|
8
|
+
Complete: "complete",
|
|
9
|
+
Error: "error",
|
|
10
|
+
};
|
|
11
|
+
})(OrderBuilderStreamEvent || (OrderBuilderStreamEvent = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./OrderBuilderStreamEvent.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./OrderBuilderStreamEvent.mjs";
|
|
@@ -6,6 +6,8 @@ export interface TaskClientUpdate1 {
|
|
|
6
6
|
location?: Chrt.LocationFeature | null;
|
|
7
7
|
action?: TaskClientUpdate1.Action | null;
|
|
8
8
|
time_windows?: Chrt.TimeWindow1[];
|
|
9
|
+
order_placer_comments?: string | null;
|
|
10
|
+
order_placer_comments__set_to_None?: boolean;
|
|
9
11
|
directory_entry_ids?: string[];
|
|
10
12
|
}
|
|
11
13
|
export declare namespace TaskClientUpdate1 {
|
package/dist/esm/core/index.mjs
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export declare namespace Stream {
|
|
2
|
+
interface Args {
|
|
3
|
+
/**
|
|
4
|
+
* The HTTP response stream to read from.
|
|
5
|
+
*/
|
|
6
|
+
stream: ReadableStream;
|
|
7
|
+
/**
|
|
8
|
+
* The event shape to use for parsing the stream data.
|
|
9
|
+
*/
|
|
10
|
+
eventShape: JsonEvent | SseEvent;
|
|
11
|
+
/**
|
|
12
|
+
* An abort signal to stop the stream.
|
|
13
|
+
*/
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
}
|
|
16
|
+
interface JsonEvent {
|
|
17
|
+
type: "json";
|
|
18
|
+
messageTerminator: string;
|
|
19
|
+
}
|
|
20
|
+
interface SseEvent {
|
|
21
|
+
type: "sse";
|
|
22
|
+
streamTerminator?: string;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export declare class Stream<T> implements AsyncIterable<T> {
|
|
26
|
+
private stream;
|
|
27
|
+
private parse;
|
|
28
|
+
/**
|
|
29
|
+
* The prefix to use for each message. For example,
|
|
30
|
+
* for SSE, the prefix is "data: ".
|
|
31
|
+
*/
|
|
32
|
+
private prefix;
|
|
33
|
+
private messageTerminator;
|
|
34
|
+
private streamTerminator;
|
|
35
|
+
private controller;
|
|
36
|
+
constructor({ stream, parse, eventShape, signal }: Stream.Args & {
|
|
37
|
+
parse: (val: unknown) => Promise<T>;
|
|
38
|
+
});
|
|
39
|
+
private iterMessages;
|
|
40
|
+
[Symbol.asyncIterator](): AsyncIterator<T, void, unknown>;
|
|
41
|
+
private decodeChunk;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Browser polyfill for ReadableStream
|
|
45
|
+
*/
|
|
46
|
+
export declare function readableStreamAsyncIterable<T>(stream: any): AsyncIterableIterator<T>;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
11
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
12
|
+
var m = o[Symbol.asyncIterator], i;
|
|
13
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
14
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
15
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
16
|
+
};
|
|
17
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
18
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
19
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
20
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
21
|
+
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
22
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
23
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
24
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
25
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
26
|
+
function fulfill(value) { resume("next", value); }
|
|
27
|
+
function reject(value) { resume("throw", value); }
|
|
28
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
29
|
+
};
|
|
30
|
+
import { RUNTIME } from "../runtime/index.mjs";
|
|
31
|
+
const DATA_PREFIX = "data:";
|
|
32
|
+
export class Stream {
|
|
33
|
+
constructor({ stream, parse, eventShape, signal }) {
|
|
34
|
+
this.controller = new AbortController();
|
|
35
|
+
this.stream = stream;
|
|
36
|
+
this.parse = parse;
|
|
37
|
+
if (eventShape.type === "sse") {
|
|
38
|
+
this.prefix = DATA_PREFIX;
|
|
39
|
+
this.messageTerminator = "\n";
|
|
40
|
+
this.streamTerminator = eventShape.streamTerminator;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this.messageTerminator = eventShape.messageTerminator;
|
|
44
|
+
}
|
|
45
|
+
signal === null || signal === void 0 ? void 0 : signal.addEventListener("abort", () => this.controller.abort());
|
|
46
|
+
}
|
|
47
|
+
iterMessages() {
|
|
48
|
+
return __asyncGenerator(this, arguments, function* iterMessages_1() {
|
|
49
|
+
var _a, e_1, _b, _c;
|
|
50
|
+
this.controller.signal;
|
|
51
|
+
const stream = readableStreamAsyncIterable(this.stream);
|
|
52
|
+
let buf = "";
|
|
53
|
+
let prefixSeen = false;
|
|
54
|
+
try {
|
|
55
|
+
for (var _d = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield __await(stream_1.next()), _a = stream_1_1.done, !_a; _d = true) {
|
|
56
|
+
_c = stream_1_1.value;
|
|
57
|
+
_d = false;
|
|
58
|
+
const chunk = _c;
|
|
59
|
+
buf += this.decodeChunk(chunk);
|
|
60
|
+
let terminatorIndex;
|
|
61
|
+
while ((terminatorIndex = buf.indexOf(this.messageTerminator)) >= 0) {
|
|
62
|
+
let line = buf.slice(0, terminatorIndex + 1);
|
|
63
|
+
buf = buf.slice(terminatorIndex + this.messageTerminator.length);
|
|
64
|
+
if (!line.trim()) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (!prefixSeen && this.prefix != null) {
|
|
68
|
+
const prefixIndex = line.indexOf(this.prefix);
|
|
69
|
+
if (prefixIndex === -1) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
prefixSeen = true;
|
|
73
|
+
line = line.slice(prefixIndex + this.prefix.length);
|
|
74
|
+
}
|
|
75
|
+
if (this.streamTerminator != null && line.includes(this.streamTerminator)) {
|
|
76
|
+
return yield __await(void 0);
|
|
77
|
+
}
|
|
78
|
+
const message = yield __await(this.parse(JSON.parse(line)));
|
|
79
|
+
yield yield __await(message);
|
|
80
|
+
prefixSeen = false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
85
|
+
finally {
|
|
86
|
+
try {
|
|
87
|
+
if (!_d && !_a && (_b = stream_1.return)) yield __await(_b.call(stream_1));
|
|
88
|
+
}
|
|
89
|
+
finally { if (e_1) throw e_1.error; }
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
[Symbol.asyncIterator]() {
|
|
94
|
+
return __asyncGenerator(this, arguments, function* _a() {
|
|
95
|
+
var _b, e_2, _c, _d;
|
|
96
|
+
try {
|
|
97
|
+
for (var _e = true, _f = __asyncValues(this.iterMessages()), _g; _g = yield __await(_f.next()), _b = _g.done, !_b; _e = true) {
|
|
98
|
+
_d = _g.value;
|
|
99
|
+
_e = false;
|
|
100
|
+
const message = _d;
|
|
101
|
+
yield yield __await(message);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
105
|
+
finally {
|
|
106
|
+
try {
|
|
107
|
+
if (!_e && !_b && (_c = _f.return)) yield __await(_c.call(_f));
|
|
108
|
+
}
|
|
109
|
+
finally { if (e_2) throw e_2.error; }
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
decodeChunk(chunk) {
|
|
114
|
+
let decoded = "";
|
|
115
|
+
// If TextDecoder is present, use it
|
|
116
|
+
if (typeof TextDecoder !== "undefined") {
|
|
117
|
+
const decoder = new TextDecoder("utf8");
|
|
118
|
+
decoded += decoder.decode(chunk);
|
|
119
|
+
}
|
|
120
|
+
// Buffer is present in Node.js environment
|
|
121
|
+
else if (RUNTIME.type === "node" && typeof chunk !== "undefined") {
|
|
122
|
+
decoded += Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
123
|
+
}
|
|
124
|
+
return decoded;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Browser polyfill for ReadableStream
|
|
129
|
+
*/
|
|
130
|
+
// biome-ignore lint/suspicious/noExplicitAny: allow explicit any
|
|
131
|
+
export function readableStreamAsyncIterable(stream) {
|
|
132
|
+
if (stream[Symbol.asyncIterator]) {
|
|
133
|
+
return stream;
|
|
134
|
+
}
|
|
135
|
+
const reader = stream.getReader();
|
|
136
|
+
return {
|
|
137
|
+
next() {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
try {
|
|
140
|
+
const result = yield reader.read();
|
|
141
|
+
if (result === null || result === void 0 ? void 0 : result.done) {
|
|
142
|
+
reader.releaseLock();
|
|
143
|
+
} // release lock when stream becomes closed
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
reader.releaseLock(); // release lock when stream becomes errored
|
|
148
|
+
throw e;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
return() {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
const cancelPromise = reader.cancel();
|
|
155
|
+
reader.releaseLock();
|
|
156
|
+
yield cancelPromise;
|
|
157
|
+
return { done: true, value: undefined };
|
|
158
|
+
});
|
|
159
|
+
},
|
|
160
|
+
[Symbol.asyncIterator]() {
|
|
161
|
+
return this;
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Stream } from "./Stream.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Stream } from "./Stream.mjs";
|
package/dist/esm/version.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.
|
|
1
|
+
export declare const SDK_VERSION = "1.575.0";
|
package/dist/esm/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.
|
|
1
|
+
export const SDK_VERSION = "1.575.0";
|