@omnixhq/ucp-client 2.3.0 → 2.5.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/README.md +40 -8
- package/dist/adapters/anthropic.d.cts +1 -1
- package/dist/adapters/anthropic.d.ts +1 -1
- package/dist/adapters/langchain.d.cts +1 -1
- package/dist/adapters/langchain.d.ts +1 -1
- package/dist/adapters/mcp.d.cts +1 -1
- package/dist/adapters/mcp.d.ts +1 -1
- package/dist/adapters/openai.d.cts +1 -1
- package/dist/adapters/openai.d.ts +1 -1
- package/dist/adapters/vercel-ai.d.cts +1 -1
- package/dist/adapters/vercel-ai.d.ts +1 -1
- package/dist/catch-errors-DRxDkLOW.d.cts +4775 -0
- package/dist/catch-errors-DRxDkLOW.d.cts.map +1 -0
- package/dist/catch-errors-DkF9AMDo.d.ts +4775 -0
- package/dist/catch-errors-DkF9AMDo.d.ts.map +1 -0
- package/dist/errors-C1XqxNmZ.cjs.map +1 -1
- package/dist/errors-DX7yw6Gl.js.map +1 -1
- package/dist/index.cjs +294 -159
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -9405
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +3 -9405
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +274 -158
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/catch-errors-B2FSGjMS.d.cts +0 -446
- package/dist/catch-errors-B2FSGjMS.d.cts.map +0 -1
- package/dist/catch-errors-dZ2dwGey.d.ts +0 -446
- package/dist/catch-errors-dZ2dwGey.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -28,32 +28,16 @@ const node_crypto = __toESM(require("node:crypto"));
|
|
|
28
28
|
const __omnixhq_ucp_js_sdk = __toESM(require("@omnixhq/ucp-js-sdk"));
|
|
29
29
|
|
|
30
30
|
//#region src/schemas.ts
|
|
31
|
-
const CheckoutSessionSchema = __omnixhq_ucp_js_sdk.CheckoutResponseSchema
|
|
32
|
-
const UCPProfileSchema = __omnixhq_ucp_js_sdk.UcpDiscoveryProfileSchema
|
|
33
|
-
const CreateCheckoutRequestSchema = __omnixhq_ucp_js_sdk.CheckoutCreateRequestSchema
|
|
34
|
-
const UpdateCheckoutRequestSchema = __omnixhq_ucp_js_sdk.CheckoutUpdateRequestSchema
|
|
35
|
-
const CompleteCheckoutRequestSchema = __omnixhq_ucp_js_sdk.CheckoutCompleteRequestSchema
|
|
36
|
-
/** @deprecated Removed from ucp-js-sdk 1.0.2. Use PaymentCredentialSchema instead. */
|
|
37
|
-
const ExtendedPaymentCredentialSchema = zod.z.object({
|
|
38
|
-
type: zod.z.string(),
|
|
39
|
-
token: zod.z.string().optional()
|
|
40
|
-
}).passthrough();
|
|
41
|
-
/** @deprecated Removed from ucp-js-sdk 1.0.2. Will be removed in a future major version. */
|
|
42
|
-
const PlatformConfigSchema = zod.z.object({ webhook_url: zod.z.string().optional() }).passthrough();
|
|
31
|
+
const CheckoutSessionSchema = __omnixhq_ucp_js_sdk.CheckoutResponseSchema;
|
|
32
|
+
const UCPProfileSchema = __omnixhq_ucp_js_sdk.UcpDiscoveryProfileSchema;
|
|
33
|
+
const CreateCheckoutRequestSchema = __omnixhq_ucp_js_sdk.CheckoutCreateRequestSchema;
|
|
34
|
+
const UpdateCheckoutRequestSchema = __omnixhq_ucp_js_sdk.CheckoutUpdateRequestSchema;
|
|
35
|
+
const CompleteCheckoutRequestSchema = __omnixhq_ucp_js_sdk.CheckoutCompleteRequestSchema;
|
|
43
36
|
const WebhookEventSchema = zod.z.object({
|
|
44
37
|
event_id: zod.z.string(),
|
|
45
38
|
created_time: zod.z.string(),
|
|
46
|
-
order: __omnixhq_ucp_js_sdk.OrderSchema
|
|
47
|
-
})
|
|
48
|
-
const JWKSchema = zod.z.object({
|
|
49
|
-
kty: zod.z.string(),
|
|
50
|
-
kid: zod.z.string().optional(),
|
|
51
|
-
use: zod.z.string().optional(),
|
|
52
|
-
alg: zod.z.string().optional(),
|
|
53
|
-
crv: zod.z.string().optional(),
|
|
54
|
-
x: zod.z.string().optional(),
|
|
55
|
-
y: zod.z.string().optional()
|
|
56
|
-
}).passthrough();
|
|
39
|
+
order: __omnixhq_ucp_js_sdk.OrderSchema
|
|
40
|
+
});
|
|
57
41
|
|
|
58
42
|
//#endregion
|
|
59
43
|
//#region src/http.ts
|
|
@@ -70,7 +54,7 @@ var HttpClient = class HttpClient {
|
|
|
70
54
|
this.ucpVersion = config.ucpVersion;
|
|
71
55
|
this.requestSignature = config.requestSignature;
|
|
72
56
|
this.accessToken = config.accessToken;
|
|
73
|
-
this.onValidationWarning = config.onValidationWarning ?? ((
|
|
57
|
+
this.onValidationWarning = config.onValidationWarning ?? (() => void 0);
|
|
74
58
|
}
|
|
75
59
|
withAccessToken(token) {
|
|
76
60
|
return new HttpClient({
|
|
@@ -111,21 +95,18 @@ var HttpClient = class HttpClient {
|
|
|
111
95
|
return result.data;
|
|
112
96
|
}
|
|
113
97
|
throwFromResponse(data, statusCode) {
|
|
114
|
-
if (typeof data
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
...first.content_type !== void 0 ? { contentType: first.content_type } : {},
|
|
127
|
-
messages: allMessages
|
|
128
|
-
});
|
|
98
|
+
if (typeof data === "object" && data !== null && Array.isArray(data["messages"])) {
|
|
99
|
+
const rawMessages = data["messages"];
|
|
100
|
+
if (rawMessages.length > 0) {
|
|
101
|
+
const allMessages = parseMessages(rawMessages);
|
|
102
|
+
const first = allMessages[0];
|
|
103
|
+
const code = first.code ?? "UNKNOWN";
|
|
104
|
+
throw new require_errors.UCPError(code, first.content, first.type, statusCode, {
|
|
105
|
+
...first.path !== void 0 ? { path: first.path } : {},
|
|
106
|
+
...first.content_type !== void 0 ? { contentType: first.content_type } : {},
|
|
107
|
+
messages: allMessages
|
|
108
|
+
});
|
|
109
|
+
}
|
|
129
110
|
}
|
|
130
111
|
if (statusCode === 409) throw new require_errors.UCPIdempotencyConflictError();
|
|
131
112
|
throw new require_errors.UCPError("HTTP_ERROR", `Gateway returned ${statusCode}`, "error", statusCode);
|
|
@@ -175,10 +156,7 @@ function parseMessages(rawMessages) {
|
|
|
175
156
|
return {
|
|
176
157
|
type,
|
|
177
158
|
content: String(record["content"] ?? "Unknown error"),
|
|
178
|
-
...record["code"] !== void 0 ? { code: String(record["code"]) } : {}
|
|
179
|
-
...record["severity"] !== void 0 ? { severity: String(record["severity"]) } : {},
|
|
180
|
-
...record["path"] !== void 0 ? { path: String(record["path"]) } : {},
|
|
181
|
-
...record["content_type"] !== void 0 ? { content_type: String(record["content_type"]) } : {}
|
|
159
|
+
...record["code"] !== void 0 ? { code: String(record["code"]) } : {}
|
|
182
160
|
};
|
|
183
161
|
});
|
|
184
162
|
}
|
|
@@ -218,44 +196,48 @@ var CheckoutCapability = class {
|
|
|
218
196
|
const data = await this.http.request("POST", `/checkout-sessions/${encodeURIComponent(id)}/cancel`);
|
|
219
197
|
return this.validateSession(data);
|
|
220
198
|
}
|
|
221
|
-
async setFulfillment(id, type
|
|
222
|
-
return this.
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
type
|
|
227
|
-
}] }
|
|
228
|
-
});
|
|
199
|
+
async setFulfillment(id, type) {
|
|
200
|
+
return this.patchFulfillmentDiscount(id, { fulfillment: { methods: [{
|
|
201
|
+
id: DEFAULT_METHOD_ID,
|
|
202
|
+
type
|
|
203
|
+
}] } });
|
|
229
204
|
}
|
|
230
|
-
async selectDestination(id, destinationId, fulfillmentType = "shipping"
|
|
231
|
-
return this.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
selected_destination_id: destinationId
|
|
237
|
-
}] }
|
|
238
|
-
});
|
|
205
|
+
async selectDestination(id, destinationId, fulfillmentType = "shipping") {
|
|
206
|
+
return this.patchFulfillmentDiscount(id, { fulfillment: { methods: [{
|
|
207
|
+
id: DEFAULT_METHOD_ID,
|
|
208
|
+
type: fulfillmentType,
|
|
209
|
+
selected_destination_id: destinationId
|
|
210
|
+
}] } });
|
|
239
211
|
}
|
|
240
|
-
async selectFulfillmentOption(id, optionId, destinationId, fulfillmentType = "shipping"
|
|
241
|
-
return this.
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}]
|
|
251
|
-
}] }
|
|
252
|
-
});
|
|
212
|
+
async selectFulfillmentOption(id, optionId, destinationId, fulfillmentType = "shipping") {
|
|
213
|
+
return this.patchFulfillmentDiscount(id, { fulfillment: { methods: [{
|
|
214
|
+
id: DEFAULT_METHOD_ID,
|
|
215
|
+
type: fulfillmentType,
|
|
216
|
+
...destinationId !== void 0 ? { selected_destination_id: destinationId } : {},
|
|
217
|
+
groups: [{
|
|
218
|
+
id: DEFAULT_GROUP_ID,
|
|
219
|
+
selected_option_id: optionId
|
|
220
|
+
}]
|
|
221
|
+
}] } });
|
|
253
222
|
}
|
|
254
|
-
async applyDiscountCodes(id, codes
|
|
255
|
-
return this.
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
});
|
|
223
|
+
async applyDiscountCodes(id, codes) {
|
|
224
|
+
return this.patchFulfillmentDiscount(id, { discounts: { codes: [...codes] } });
|
|
225
|
+
}
|
|
226
|
+
async createFulfillmentMethod(id, payload) {
|
|
227
|
+
const data = await this.http.request("POST", `/checkout-sessions/${encodeURIComponent(id)}/fulfillment/methods`, payload);
|
|
228
|
+
return this.validateSession(data);
|
|
229
|
+
}
|
|
230
|
+
async updateFulfillmentMethod(id, methodId, payload) {
|
|
231
|
+
const data = await this.http.request("PUT", `/checkout-sessions/${encodeURIComponent(id)}/fulfillment/methods/${encodeURIComponent(methodId)}`, payload);
|
|
232
|
+
return this.validateSession(data);
|
|
233
|
+
}
|
|
234
|
+
async updateFulfillmentGroup(id, methodId, groupId, payload) {
|
|
235
|
+
const data = await this.http.request("PUT", `/checkout-sessions/${encodeURIComponent(id)}/fulfillment/methods/${encodeURIComponent(methodId)}/groups/${encodeURIComponent(groupId)}`, payload);
|
|
236
|
+
return this.validateSession(data);
|
|
237
|
+
}
|
|
238
|
+
async patchFulfillmentDiscount(id, patch) {
|
|
239
|
+
const data = await this.http.request("PUT", `/checkout-sessions/${encodeURIComponent(id)}`, patch);
|
|
240
|
+
return this.validateSession(data);
|
|
259
241
|
}
|
|
260
242
|
validateSession(data) {
|
|
261
243
|
const session = this.http.validate(data, CheckoutSessionSchema);
|
|
@@ -279,7 +261,12 @@ var OrderCapability = class {
|
|
|
279
261
|
/** Update an order with fulfillment events, adjustments, or status changes. */
|
|
280
262
|
async update(id, payload) {
|
|
281
263
|
const data = await this.http.request("PUT", `/orders/${encodeURIComponent(id)}`, payload);
|
|
282
|
-
return this.http.validate(data, __omnixhq_ucp_js_sdk.
|
|
264
|
+
return this.http.validate(data, __omnixhq_ucp_js_sdk.OrderUpdateSchema);
|
|
265
|
+
}
|
|
266
|
+
/** Update a single line item within an order (e.g. set parent for grouping). */
|
|
267
|
+
async updateLineItem(id, lineItemId, payload) {
|
|
268
|
+
const data = await this.http.request("PUT", `/orders/${encodeURIComponent(id)}/line-items/${encodeURIComponent(lineItemId)}`, payload);
|
|
269
|
+
return this.http.validate(data, __omnixhq_ucp_js_sdk.OrderUpdateSchema);
|
|
283
270
|
}
|
|
284
271
|
};
|
|
285
272
|
|
|
@@ -666,6 +653,97 @@ function fulfillmentTools(client) {
|
|
|
666
653
|
required: ["id", "option_id"]
|
|
667
654
|
},
|
|
668
655
|
execute: async (params) => client.checkout.selectFulfillmentOption(params["id"], params["option_id"], params["destination_id"], params["fulfillment_type"] ?? "shipping")
|
|
656
|
+
},
|
|
657
|
+
{
|
|
658
|
+
name: "create_fulfillment_method",
|
|
659
|
+
description: "Add a new fulfillment method (shipping or pickup) to a checkout session.",
|
|
660
|
+
parameters: {
|
|
661
|
+
type: "object",
|
|
662
|
+
properties: {
|
|
663
|
+
id: {
|
|
664
|
+
type: "string",
|
|
665
|
+
description: "Checkout session ID"
|
|
666
|
+
},
|
|
667
|
+
type: {
|
|
668
|
+
type: "string",
|
|
669
|
+
enum: ["shipping", "pickup"],
|
|
670
|
+
description: "Fulfillment method type"
|
|
671
|
+
},
|
|
672
|
+
line_item_ids: {
|
|
673
|
+
type: "array",
|
|
674
|
+
items: { type: "string" },
|
|
675
|
+
description: "Line item IDs to associate with this method (optional)"
|
|
676
|
+
}
|
|
677
|
+
},
|
|
678
|
+
required: ["id", "type"]
|
|
679
|
+
},
|
|
680
|
+
execute: async (params) => {
|
|
681
|
+
const { id,...payload } = params;
|
|
682
|
+
return client.checkout.createFulfillmentMethod(id, payload);
|
|
683
|
+
}
|
|
684
|
+
},
|
|
685
|
+
{
|
|
686
|
+
name: "update_fulfillment_method",
|
|
687
|
+
description: "Update an existing fulfillment method on a checkout session.",
|
|
688
|
+
parameters: {
|
|
689
|
+
type: "object",
|
|
690
|
+
properties: {
|
|
691
|
+
id: {
|
|
692
|
+
type: "string",
|
|
693
|
+
description: "Checkout session ID"
|
|
694
|
+
},
|
|
695
|
+
method_id: {
|
|
696
|
+
type: "string",
|
|
697
|
+
description: "Fulfillment method ID to update"
|
|
698
|
+
},
|
|
699
|
+
type: {
|
|
700
|
+
type: "string",
|
|
701
|
+
enum: ["shipping", "pickup"],
|
|
702
|
+
description: "Updated fulfillment method type (optional)"
|
|
703
|
+
},
|
|
704
|
+
line_item_ids: {
|
|
705
|
+
type: "array",
|
|
706
|
+
items: { type: "string" },
|
|
707
|
+
description: "Updated line item IDs to associate with this method"
|
|
708
|
+
}
|
|
709
|
+
},
|
|
710
|
+
required: [
|
|
711
|
+
"id",
|
|
712
|
+
"method_id",
|
|
713
|
+
"line_item_ids"
|
|
714
|
+
]
|
|
715
|
+
},
|
|
716
|
+
execute: async (params) => {
|
|
717
|
+
const { id, method_id,...payload } = params;
|
|
718
|
+
return client.checkout.updateFulfillmentMethod(id, method_id, payload);
|
|
719
|
+
}
|
|
720
|
+
},
|
|
721
|
+
{
|
|
722
|
+
name: "update_fulfillment_group",
|
|
723
|
+
description: "Update a fulfillment group within a fulfillment method on a checkout session.",
|
|
724
|
+
parameters: {
|
|
725
|
+
type: "object",
|
|
726
|
+
properties: {
|
|
727
|
+
id: {
|
|
728
|
+
type: "string",
|
|
729
|
+
description: "Checkout session ID"
|
|
730
|
+
},
|
|
731
|
+
method_id: {
|
|
732
|
+
type: "string",
|
|
733
|
+
description: "Fulfillment method ID"
|
|
734
|
+
},
|
|
735
|
+
group_id: {
|
|
736
|
+
type: "string",
|
|
737
|
+
description: "Fulfillment group ID to update"
|
|
738
|
+
}
|
|
739
|
+
},
|
|
740
|
+
required: [
|
|
741
|
+
"id",
|
|
742
|
+
"method_id",
|
|
743
|
+
"group_id"
|
|
744
|
+
]
|
|
745
|
+
},
|
|
746
|
+
execute: async (params) => client.checkout.updateFulfillmentGroup(params["id"], params["method_id"], params["group_id"], { id: params["group_id"] })
|
|
669
747
|
}
|
|
670
748
|
];
|
|
671
749
|
}
|
|
@@ -692,45 +770,74 @@ function discountTools(client) {
|
|
|
692
770
|
}];
|
|
693
771
|
}
|
|
694
772
|
function orderTools(client) {
|
|
695
|
-
return [
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
description: "Order ID"
|
|
703
|
-
} },
|
|
704
|
-
required: ["id"]
|
|
705
|
-
},
|
|
706
|
-
execute: async (params) => client.order.get(params["id"])
|
|
707
|
-
}, {
|
|
708
|
-
name: "update_order",
|
|
709
|
-
description: "Update an order with fulfillment events, adjustments, or status changes.",
|
|
710
|
-
parameters: {
|
|
711
|
-
type: "object",
|
|
712
|
-
properties: {
|
|
713
|
-
id: {
|
|
773
|
+
return [
|
|
774
|
+
{
|
|
775
|
+
name: "get_order",
|
|
776
|
+
description: "Get order details by ID, including line items, fulfillment status, and tracking information.",
|
|
777
|
+
parameters: {
|
|
778
|
+
type: "object",
|
|
779
|
+
properties: { id: {
|
|
714
780
|
type: "string",
|
|
715
781
|
description: "Order ID"
|
|
782
|
+
} },
|
|
783
|
+
required: ["id"]
|
|
784
|
+
},
|
|
785
|
+
execute: async (params) => client.order.get(params["id"])
|
|
786
|
+
},
|
|
787
|
+
{
|
|
788
|
+
name: "update_order",
|
|
789
|
+
description: "Update an order with fulfillment events, adjustments, or status changes.",
|
|
790
|
+
parameters: {
|
|
791
|
+
type: "object",
|
|
792
|
+
properties: {
|
|
793
|
+
id: {
|
|
794
|
+
type: "string",
|
|
795
|
+
description: "Order ID"
|
|
796
|
+
},
|
|
797
|
+
fulfillment: {
|
|
798
|
+
type: "object",
|
|
799
|
+
description: "Fulfillment update data (events, tracking)"
|
|
800
|
+
},
|
|
801
|
+
adjustments: {
|
|
802
|
+
type: "array",
|
|
803
|
+
description: "Order adjustments (refunds, returns)",
|
|
804
|
+
items: { type: "object" }
|
|
805
|
+
}
|
|
716
806
|
},
|
|
717
|
-
|
|
718
|
-
type: "object",
|
|
719
|
-
description: "Fulfillment update data (events, tracking)"
|
|
720
|
-
},
|
|
721
|
-
adjustments: {
|
|
722
|
-
type: "array",
|
|
723
|
-
description: "Order adjustments (refunds, returns)",
|
|
724
|
-
items: { type: "object" }
|
|
725
|
-
}
|
|
807
|
+
required: ["id"]
|
|
726
808
|
},
|
|
727
|
-
|
|
809
|
+
execute: async (params) => {
|
|
810
|
+
const { id,...payload } = params;
|
|
811
|
+
return client.order.update(id, payload);
|
|
812
|
+
}
|
|
728
813
|
},
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
814
|
+
{
|
|
815
|
+
name: "update_order_line_item",
|
|
816
|
+
description: "Update a line item within an order, such as setting a parent line item for grouping.",
|
|
817
|
+
parameters: {
|
|
818
|
+
type: "object",
|
|
819
|
+
properties: {
|
|
820
|
+
id: {
|
|
821
|
+
type: "string",
|
|
822
|
+
description: "Order ID"
|
|
823
|
+
},
|
|
824
|
+
line_item_id: {
|
|
825
|
+
type: "string",
|
|
826
|
+
description: "Line item ID to update"
|
|
827
|
+
},
|
|
828
|
+
parent_id: {
|
|
829
|
+
type: "string",
|
|
830
|
+
description: "Parent line item ID for grouping (optional)"
|
|
831
|
+
}
|
|
832
|
+
},
|
|
833
|
+
required: ["id", "line_item_id"]
|
|
834
|
+
},
|
|
835
|
+
execute: async (params) => {
|
|
836
|
+
const { id, line_item_id,...payload } = params;
|
|
837
|
+
return client.order.updateLineItem(id, line_item_id, payload);
|
|
838
|
+
}
|
|
732
839
|
}
|
|
733
|
-
|
|
840
|
+
];
|
|
734
841
|
}
|
|
735
842
|
function identityLinkingTools(client) {
|
|
736
843
|
return [
|
|
@@ -857,21 +964,6 @@ function identityLinkingTools(client) {
|
|
|
857
964
|
|
|
858
965
|
//#endregion
|
|
859
966
|
//#region src/UCPClient.ts
|
|
860
|
-
/**
|
|
861
|
-
* Connect to a UCP server, discover its capabilities, and return a {@link ConnectedClient}.
|
|
862
|
-
*
|
|
863
|
-
* @example
|
|
864
|
-
* ```typescript
|
|
865
|
-
* const client = await connect({
|
|
866
|
-
* gatewayUrl: 'https://store.example.com/ucp',
|
|
867
|
-
* agentProfileUrl: 'https://platform.example.com/.well-known/ucp',
|
|
868
|
-
* });
|
|
869
|
-
*
|
|
870
|
-
* if (client.checkout) {
|
|
871
|
-
* const session = await client.checkout.create({ line_items: [...] });
|
|
872
|
-
* }
|
|
873
|
-
* ```
|
|
874
|
-
*/
|
|
875
967
|
async function connect(config, options) {
|
|
876
968
|
validateConfig(config);
|
|
877
969
|
const http = new HttpClient({
|
|
@@ -901,40 +993,29 @@ async function connect(config, options) {
|
|
|
901
993
|
};
|
|
902
994
|
return Object.freeze(client);
|
|
903
995
|
}
|
|
904
|
-
/**
|
|
905
|
-
* UCP client entry point. Use `UCPClient.connect()` to discover server capabilities
|
|
906
|
-
* and get a {@link ConnectedClient}.
|
|
907
|
-
*
|
|
908
|
-
* @example
|
|
909
|
-
* ```typescript
|
|
910
|
-
* const client = await UCPClient.connect({
|
|
911
|
-
* gatewayUrl: 'https://store.example.com/ucp',
|
|
912
|
-
* agentProfileUrl: 'https://platform.example.com/.well-known/ucp',
|
|
913
|
-
* });
|
|
914
|
-
* ```
|
|
915
|
-
*/
|
|
916
996
|
var UCPClient = class {
|
|
917
997
|
constructor() {}
|
|
918
998
|
static connect = connect;
|
|
919
999
|
};
|
|
920
1000
|
function validateConfig(config) {
|
|
921
|
-
|
|
1001
|
+
try {
|
|
1002
|
+
new URL(config.gatewayUrl);
|
|
1003
|
+
} catch {
|
|
1004
|
+
throw new Error(`UCPClient: gatewayUrl is not a valid URL: "${config.gatewayUrl}"`);
|
|
1005
|
+
}
|
|
922
1006
|
if (config.agentProfileUrl.includes("\"") || config.agentProfileUrl.includes("\n")) throw new Error("agentProfileUrl must not contain double quotes or newlines");
|
|
923
|
-
|
|
1007
|
+
try {
|
|
1008
|
+
new URL(config.agentProfileUrl);
|
|
1009
|
+
} catch {
|
|
1010
|
+
throw new Error(`UCPClient: agentProfileUrl is not a valid URL: "${config.agentProfileUrl}"`);
|
|
1011
|
+
}
|
|
924
1012
|
}
|
|
925
1013
|
function extractCapabilityNames(profile) {
|
|
926
1014
|
const capabilities = profile.ucp?.capabilities;
|
|
927
1015
|
if (typeof capabilities !== "object" || capabilities === null) return new Set();
|
|
928
1016
|
return new Set(Object.keys(capabilities));
|
|
929
1017
|
}
|
|
930
|
-
const
|
|
931
|
-
id: zod.z.string(),
|
|
932
|
-
version: zod.z.string(),
|
|
933
|
-
spec: zod.z.string(),
|
|
934
|
-
schema: zod.z.string(),
|
|
935
|
-
config: zod.z.record(zod.z.unknown()).optional()
|
|
936
|
-
}).passthrough();
|
|
937
|
-
const PaymentHandlerMapSchema = zod.z.record(zod.z.array(PaymentHandlerInstanceSchema));
|
|
1018
|
+
const PaymentHandlerMapSchema = zod.z.record(zod.z.array(__omnixhq_ucp_js_sdk.PaymentHandlerBaseSchema));
|
|
938
1019
|
function extractPaymentHandlers(profile) {
|
|
939
1020
|
const raw = profile["payment_handlers"];
|
|
940
1021
|
if (typeof raw !== "object" || raw === null) return {};
|
|
@@ -947,7 +1028,7 @@ function extractSigningKeys(profile) {
|
|
|
947
1028
|
if (!Array.isArray(raw)) return [];
|
|
948
1029
|
const keys = [];
|
|
949
1030
|
for (const item of raw) {
|
|
950
|
-
const result =
|
|
1031
|
+
const result = __omnixhq_ucp_js_sdk.UcpSigningKeySchema.safeParse(item);
|
|
951
1032
|
if (result.success) keys.push(result.data);
|
|
952
1033
|
}
|
|
953
1034
|
return keys;
|
|
@@ -1020,6 +1101,18 @@ function buildToolDescriptors(checkout, order, identityLinking) {
|
|
|
1020
1101
|
name: "select_fulfillment_option",
|
|
1021
1102
|
capability: "checkout.fulfillment",
|
|
1022
1103
|
description: "Select fulfillment option (e.g., express shipping)"
|
|
1104
|
+
}, {
|
|
1105
|
+
name: "create_fulfillment_method",
|
|
1106
|
+
capability: "checkout.fulfillment",
|
|
1107
|
+
description: "Add a new fulfillment method to a checkout session"
|
|
1108
|
+
}, {
|
|
1109
|
+
name: "update_fulfillment_method",
|
|
1110
|
+
capability: "checkout.fulfillment",
|
|
1111
|
+
description: "Update an existing fulfillment method on a checkout session"
|
|
1112
|
+
}, {
|
|
1113
|
+
name: "update_fulfillment_group",
|
|
1114
|
+
capability: "checkout.fulfillment",
|
|
1115
|
+
description: "Update a fulfillment group within a fulfillment method"
|
|
1023
1116
|
});
|
|
1024
1117
|
if (checkout.extensions.discount) tools.push({
|
|
1025
1118
|
name: "apply_discount_codes",
|
|
@@ -1035,6 +1128,10 @@ function buildToolDescriptors(checkout, order, identityLinking) {
|
|
|
1035
1128
|
name: "update_order",
|
|
1036
1129
|
capability: "order",
|
|
1037
1130
|
description: "Update an order"
|
|
1131
|
+
}, {
|
|
1132
|
+
name: "update_order_line_item",
|
|
1133
|
+
capability: "order",
|
|
1134
|
+
description: "Update a line item within an order"
|
|
1038
1135
|
});
|
|
1039
1136
|
if (identityLinking) tools.push({
|
|
1040
1137
|
name: "get_authorization_url",
|
|
@@ -1127,24 +1224,43 @@ function createWebhookVerifier(gatewayUrl) {
|
|
|
1127
1224
|
const baseUrl = gatewayUrl.replace(/\/+$/, "");
|
|
1128
1225
|
const keyCache = new Map();
|
|
1129
1226
|
let fetched = false;
|
|
1227
|
+
let loadingPromise = null;
|
|
1130
1228
|
async function loadKeys() {
|
|
1131
1229
|
const res = await fetch(`${baseUrl}/.well-known/ucp`);
|
|
1132
|
-
if (!res.ok)
|
|
1133
|
-
|
|
1230
|
+
if (!res.ok) {
|
|
1231
|
+
fetched = true;
|
|
1232
|
+
return;
|
|
1233
|
+
}
|
|
1234
|
+
let profile;
|
|
1235
|
+
try {
|
|
1236
|
+
profile = await res.json();
|
|
1237
|
+
} catch {
|
|
1238
|
+
fetched = true;
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1134
1241
|
const rawKeys = profile["signing_keys"];
|
|
1135
|
-
if (!Array.isArray(rawKeys))
|
|
1242
|
+
if (!Array.isArray(rawKeys)) {
|
|
1243
|
+
fetched = true;
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1136
1246
|
keyCache.clear();
|
|
1137
1247
|
for (const item of rawKeys) {
|
|
1138
|
-
const parsed =
|
|
1248
|
+
const parsed = __omnixhq_ucp_js_sdk.UcpSigningKeySchema.safeParse(item);
|
|
1139
1249
|
if (parsed.success && typeof parsed.data.kid === "string") keyCache.set(parsed.data.kid, parsed.data);
|
|
1140
1250
|
}
|
|
1141
1251
|
fetched = true;
|
|
1142
1252
|
}
|
|
1253
|
+
function ensureKeys() {
|
|
1254
|
+
loadingPromise ??= loadKeys().finally(() => {
|
|
1255
|
+
loadingPromise = null;
|
|
1256
|
+
});
|
|
1257
|
+
return loadingPromise;
|
|
1258
|
+
}
|
|
1143
1259
|
return { async verify(body, signature) {
|
|
1144
1260
|
const kid = extractKid(signature);
|
|
1145
1261
|
if (kid === null) return false;
|
|
1146
|
-
if (!fetched) await
|
|
1147
|
-
if (!keyCache.has(kid)) await
|
|
1262
|
+
if (!fetched) await ensureKeys();
|
|
1263
|
+
if (!keyCache.has(kid)) await ensureKeys();
|
|
1148
1264
|
const key = keyCache.get(kid);
|
|
1149
1265
|
if (!key) return false;
|
|
1150
1266
|
return verifyRequestSignature(body, signature, [key]);
|
|
@@ -1210,6 +1326,7 @@ function parseWebhookEvent(body) {
|
|
|
1210
1326
|
//#endregion
|
|
1211
1327
|
exports.AccountInfoSchema = __omnixhq_ucp_js_sdk.AccountInfoSchema
|
|
1212
1328
|
exports.AdjustmentSchema = __omnixhq_ucp_js_sdk.AdjustmentSchema
|
|
1329
|
+
exports.AdjustmentStatusEnumSchema = __omnixhq_ucp_js_sdk.AdjustmentStatusEnumSchema
|
|
1213
1330
|
exports.Ap2MandateAp2WithCheckoutMandateSchema = __omnixhq_ucp_js_sdk.Ap2MandateAp2WithCheckoutMandateSchema
|
|
1214
1331
|
exports.Ap2MandateAp2WithMerchantAuthorizationSchema = __omnixhq_ucp_js_sdk.Ap2MandateAp2WithMerchantAuthorizationSchema
|
|
1215
1332
|
exports.Ap2MandateCheckoutMandateSchema = __omnixhq_ucp_js_sdk.Ap2MandateCheckoutMandateSchema
|
|
@@ -1224,6 +1341,7 @@ exports.CapabilityBaseSchema = __omnixhq_ucp_js_sdk.CapabilityBaseSchema
|
|
|
1224
1341
|
exports.CapabilityBusinessSchema = __omnixhq_ucp_js_sdk.CapabilityBusinessSchema
|
|
1225
1342
|
exports.CapabilityPlatformSchema = __omnixhq_ucp_js_sdk.CapabilityPlatformSchema
|
|
1226
1343
|
exports.CapabilityResponseSchema = __omnixhq_ucp_js_sdk.CapabilityResponseSchema
|
|
1344
|
+
exports.CardCredentialCardNumberTypeEnumSchema = __omnixhq_ucp_js_sdk.CardCredentialCardNumberTypeEnumSchema
|
|
1227
1345
|
exports.CardCredentialSchema = __omnixhq_ucp_js_sdk.CardCredentialSchema
|
|
1228
1346
|
exports.CardPaymentInstrumentSchema = __omnixhq_ucp_js_sdk.CardPaymentInstrumentSchema
|
|
1229
1347
|
exports.CheckoutCapability = CheckoutCapability
|
|
@@ -1233,18 +1351,21 @@ exports.CheckoutResponseSchema = __omnixhq_ucp_js_sdk.CheckoutResponseSchema
|
|
|
1233
1351
|
exports.CheckoutResponseStatusSchema = __omnixhq_ucp_js_sdk.CheckoutResponseStatusSchema
|
|
1234
1352
|
exports.CheckoutSchema = __omnixhq_ucp_js_sdk.CheckoutSchema
|
|
1235
1353
|
exports.CheckoutSessionSchema = CheckoutSessionSchema
|
|
1354
|
+
exports.CheckoutStatusEnumSchema = __omnixhq_ucp_js_sdk.CheckoutStatusEnumSchema
|
|
1236
1355
|
exports.CheckoutUpdateRequestSchema = __omnixhq_ucp_js_sdk.CheckoutUpdateRequestSchema
|
|
1237
1356
|
exports.CompleteCheckoutRequestSchema = CompleteCheckoutRequestSchema
|
|
1238
1357
|
exports.ContextSchema = __omnixhq_ucp_js_sdk.ContextSchema
|
|
1239
1358
|
exports.CreateCheckoutRequestSchema = CreateCheckoutRequestSchema
|
|
1240
1359
|
exports.DEFAULT_UCP_VERSION = DEFAULT_UCP_VERSION
|
|
1241
1360
|
exports.DiscountAllocationSchema = __omnixhq_ucp_js_sdk.DiscountAllocationSchema
|
|
1361
|
+
exports.DiscountAppliedDiscountMethodEnumSchema = __omnixhq_ucp_js_sdk.DiscountAppliedDiscountMethodEnumSchema
|
|
1242
1362
|
exports.DiscountAppliedDiscountSchema = __omnixhq_ucp_js_sdk.DiscountAppliedDiscountSchema
|
|
1243
1363
|
exports.DiscountDiscountsObjectSchema = __omnixhq_ucp_js_sdk.DiscountDiscountsObjectSchema
|
|
1244
1364
|
exports.EmbeddedConfigSchema = __omnixhq_ucp_js_sdk.EmbeddedConfigSchema
|
|
1365
|
+
exports.ExpectationMethodTypeEnumSchema = __omnixhq_ucp_js_sdk.ExpectationMethodTypeEnumSchema
|
|
1245
1366
|
exports.ExpectationSchema = __omnixhq_ucp_js_sdk.ExpectationSchema
|
|
1246
|
-
exports.ExtendedPaymentCredentialSchema = ExtendedPaymentCredentialSchema
|
|
1247
1367
|
exports.FulfillmentAvailableMethodSchema = __omnixhq_ucp_js_sdk.FulfillmentAvailableMethodSchema
|
|
1368
|
+
exports.FulfillmentAvailableMethodTypeEnumSchema = __omnixhq_ucp_js_sdk.FulfillmentAvailableMethodTypeEnumSchema
|
|
1248
1369
|
exports.FulfillmentDestinationSchema = __omnixhq_ucp_js_sdk.FulfillmentDestinationSchema
|
|
1249
1370
|
exports.FulfillmentEventSchema = __omnixhq_ucp_js_sdk.FulfillmentEventSchema
|
|
1250
1371
|
exports.FulfillmentExtensionFulfillmentAvailableMethodSchema = __omnixhq_ucp_js_sdk.FulfillmentExtensionFulfillmentAvailableMethodSchema
|
|
@@ -1257,6 +1378,7 @@ exports.FulfillmentGroupUpdateRequestSchema = __omnixhq_ucp_js_sdk.FulfillmentGr
|
|
|
1257
1378
|
exports.FulfillmentMethodCreateRequestSchema = __omnixhq_ucp_js_sdk.FulfillmentMethodCreateRequestSchema
|
|
1258
1379
|
exports.FulfillmentMethodResponseSchema = __omnixhq_ucp_js_sdk.FulfillmentMethodResponseSchema
|
|
1259
1380
|
exports.FulfillmentMethodSchema = __omnixhq_ucp_js_sdk.FulfillmentMethodSchema
|
|
1381
|
+
exports.FulfillmentMethodTypeEnumSchema = __omnixhq_ucp_js_sdk.FulfillmentMethodTypeEnumSchema
|
|
1260
1382
|
exports.FulfillmentMethodUpdateRequestSchema = __omnixhq_ucp_js_sdk.FulfillmentMethodUpdateRequestSchema
|
|
1261
1383
|
exports.FulfillmentOptionSchema = __omnixhq_ucp_js_sdk.FulfillmentOptionSchema
|
|
1262
1384
|
exports.FulfillmentResponseSchema = __omnixhq_ucp_js_sdk.FulfillmentResponseSchema
|
|
@@ -1264,19 +1386,24 @@ exports.FulfillmentSchema = __omnixhq_ucp_js_sdk.FulfillmentSchema
|
|
|
1264
1386
|
exports.IdentityLinkingCapability = IdentityLinkingCapability
|
|
1265
1387
|
exports.ItemResponseSchema = __omnixhq_ucp_js_sdk.ItemResponseSchema
|
|
1266
1388
|
exports.ItemSchema = __omnixhq_ucp_js_sdk.ItemSchema
|
|
1267
|
-
exports.JWKSchema =
|
|
1389
|
+
exports.JWKSchema = __omnixhq_ucp_js_sdk.UcpSigningKeySchema
|
|
1268
1390
|
exports.LineItemResponseSchema = __omnixhq_ucp_js_sdk.LineItemResponseSchema
|
|
1269
1391
|
exports.LineItemSchema = __omnixhq_ucp_js_sdk.LineItemSchema
|
|
1270
1392
|
exports.LineItemUpdateRequestSchema = __omnixhq_ucp_js_sdk.LineItemUpdateRequestSchema
|
|
1271
1393
|
exports.LinkSchema = __omnixhq_ucp_js_sdk.LinkSchema
|
|
1272
1394
|
exports.MerchantFulfillmentConfigSchema = __omnixhq_ucp_js_sdk.MerchantFulfillmentConfigSchema
|
|
1395
|
+
exports.MessageErrorContentTypeEnumSchema = __omnixhq_ucp_js_sdk.MessageErrorContentTypeEnumSchema
|
|
1273
1396
|
exports.MessageErrorSchema = __omnixhq_ucp_js_sdk.MessageErrorSchema
|
|
1397
|
+
exports.MessageErrorSeverityEnumSchema = __omnixhq_ucp_js_sdk.MessageErrorSeverityEnumSchema
|
|
1398
|
+
exports.MessageInfoContentTypeEnumSchema = __omnixhq_ucp_js_sdk.MessageInfoContentTypeEnumSchema
|
|
1274
1399
|
exports.MessageInfoSchema = __omnixhq_ucp_js_sdk.MessageInfoSchema
|
|
1275
1400
|
exports.MessageSchema = __omnixhq_ucp_js_sdk.MessageSchema
|
|
1401
|
+
exports.MessageWarningContentTypeEnumSchema = __omnixhq_ucp_js_sdk.MessageWarningContentTypeEnumSchema
|
|
1276
1402
|
exports.MessageWarningSchema = __omnixhq_ucp_js_sdk.MessageWarningSchema
|
|
1277
1403
|
exports.OrderCapability = OrderCapability
|
|
1278
1404
|
exports.OrderConfirmationSchema = __omnixhq_ucp_js_sdk.OrderConfirmationSchema
|
|
1279
1405
|
exports.OrderLineItemSchema = __omnixhq_ucp_js_sdk.OrderLineItemSchema
|
|
1406
|
+
exports.OrderLineItemStatusEnumSchema = __omnixhq_ucp_js_sdk.OrderLineItemStatusEnumSchema
|
|
1280
1407
|
exports.OrderUpdateSchema = __omnixhq_ucp_js_sdk.OrderUpdateSchema
|
|
1281
1408
|
exports.PaymentCredentialSchema = __omnixhq_ucp_js_sdk.PaymentCredentialSchema
|
|
1282
1409
|
exports.PaymentHandlerBaseSchema = __omnixhq_ucp_js_sdk.PaymentHandlerBaseSchema
|
|
@@ -1288,11 +1415,16 @@ exports.PaymentInstrumentResponseSchema = __omnixhq_ucp_js_sdk.PaymentInstrument
|
|
|
1288
1415
|
exports.PaymentInstrumentSchema = __omnixhq_ucp_js_sdk.PaymentInstrumentSchema
|
|
1289
1416
|
exports.PaymentResponseSchema = __omnixhq_ucp_js_sdk.PaymentResponseSchema
|
|
1290
1417
|
exports.PaymentSchema = __omnixhq_ucp_js_sdk.PaymentSchema
|
|
1291
|
-
exports.PlatformConfigSchema = PlatformConfigSchema
|
|
1292
1418
|
exports.PlatformFulfillmentConfigSchema = __omnixhq_ucp_js_sdk.PlatformFulfillmentConfigSchema
|
|
1293
1419
|
exports.PostalAddressSchema = __omnixhq_ucp_js_sdk.PostalAddressSchema
|
|
1420
|
+
exports.ProfileSchemaBaseSchema = __omnixhq_ucp_js_sdk.ProfileSchemaBaseSchema
|
|
1421
|
+
exports.ProfileSchemaBusinessProfileSchema = __omnixhq_ucp_js_sdk.ProfileSchemaBusinessProfileSchema
|
|
1422
|
+
exports.ProfileSchemaPlatformProfileSchema = __omnixhq_ucp_js_sdk.ProfileSchemaPlatformProfileSchema
|
|
1423
|
+
exports.ProfileSchemaSigningKeySchema = __omnixhq_ucp_js_sdk.ProfileSchemaSigningKeySchema
|
|
1424
|
+
exports.ProfileSchemaSigningKeyUseEnumSchema = __omnixhq_ucp_js_sdk.ProfileSchemaSigningKeyUseEnumSchema
|
|
1294
1425
|
exports.RetailLocationSchema = __omnixhq_ucp_js_sdk.RetailLocationSchema
|
|
1295
1426
|
exports.ServiceBaseSchema = __omnixhq_ucp_js_sdk.ServiceBaseSchema
|
|
1427
|
+
exports.ServiceBaseTransportEnumSchema = __omnixhq_ucp_js_sdk.ServiceBaseTransportEnumSchema
|
|
1296
1428
|
exports.ServiceBusinessSchema = __omnixhq_ucp_js_sdk.ServiceBusinessSchema
|
|
1297
1429
|
exports.ServicePlatformSchema = __omnixhq_ucp_js_sdk.ServicePlatformSchema
|
|
1298
1430
|
exports.ServiceResponseSchema = __omnixhq_ucp_js_sdk.ServiceResponseSchema
|
|
@@ -1300,6 +1432,7 @@ exports.ShippingDestinationSchema = __omnixhq_ucp_js_sdk.ShippingDestinationSche
|
|
|
1300
1432
|
exports.TokenCredentialSchema = __omnixhq_ucp_js_sdk.TokenCredentialSchema
|
|
1301
1433
|
exports.TotalResponseSchema = __omnixhq_ucp_js_sdk.TotalResponseSchema
|
|
1302
1434
|
exports.TotalSchema = __omnixhq_ucp_js_sdk.TotalSchema
|
|
1435
|
+
exports.TotalTypeEnumSchema = __omnixhq_ucp_js_sdk.TotalTypeEnumSchema
|
|
1303
1436
|
exports.UCPClient = UCPClient
|
|
1304
1437
|
exports.UCPError = require_errors.UCPError
|
|
1305
1438
|
exports.UCPEscalationError = require_errors.UCPEscalationError
|
|
@@ -1310,6 +1443,8 @@ exports.UCPSpecOrderSchema = __omnixhq_ucp_js_sdk.OrderSchema
|
|
|
1310
1443
|
exports.UCP_CAPABILITIES = UCP_CAPABILITIES
|
|
1311
1444
|
exports.UcpBaseSchema = __omnixhq_ucp_js_sdk.UcpBaseSchema
|
|
1312
1445
|
exports.UcpBusinessSchema = __omnixhq_ucp_js_sdk.UcpBusinessSchema
|
|
1446
|
+
exports.UcpDiscoveryBusinessProfileSchema = __omnixhq_ucp_js_sdk.UcpDiscoveryBusinessProfileSchema
|
|
1447
|
+
exports.UcpDiscoveryPlatformProfileSchema = __omnixhq_ucp_js_sdk.UcpDiscoveryPlatformProfileSchema
|
|
1313
1448
|
exports.UcpEntitySchema = __omnixhq_ucp_js_sdk.UcpEntitySchema
|
|
1314
1449
|
exports.UcpPlatformSchema = __omnixhq_ucp_js_sdk.UcpPlatformSchema
|
|
1315
1450
|
exports.UcpResponseCheckoutSchema = __omnixhq_ucp_js_sdk.UcpResponseCheckoutSchema
|