@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.js
CHANGED
|
@@ -1,35 +1,19 @@
|
|
|
1
1
|
import { UCPError, UCPEscalationError, UCPIdempotencyConflictError, UCPOAuthError } from "./errors-DX7yw6Gl.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
|
-
import { AccountInfoSchema, AdjustmentSchema, Ap2MandateAp2WithCheckoutMandateSchema, Ap2MandateAp2WithMerchantAuthorizationSchema, Ap2MandateCheckoutMandateSchema, Ap2MandateErrorCodeSchema, Ap2MandateMerchantAuthorizationSchema, BindingSchema, BusinessFulfillmentConfigSchema, BuyerConsentBuyerSchema, BuyerConsentConsentSchema, BuyerSchema, CapabilityBaseSchema, CapabilityBusinessSchema, CapabilityPlatformSchema, CapabilityResponseSchema, CardCredentialSchema, CardPaymentInstrumentSchema, CheckoutCompleteRequestSchema, CheckoutCreateRequestSchema, CheckoutResponseSchema, CheckoutResponseStatusSchema, CheckoutSchema, CheckoutUpdateRequestSchema, ContextSchema, DiscountAllocationSchema, DiscountAppliedDiscountSchema, DiscountDiscountsObjectSchema, EmbeddedConfigSchema, ExpectationSchema, FulfillmentAvailableMethodSchema, FulfillmentDestinationSchema, FulfillmentEventSchema, FulfillmentExtensionFulfillmentAvailableMethodSchema, FulfillmentExtensionFulfillmentGroupSchema, FulfillmentExtensionFulfillmentMethodSchema, FulfillmentExtensionFulfillmentOptionSchema, FulfillmentExtensionFulfillmentSchema, FulfillmentGroupSchema, FulfillmentGroupUpdateRequestSchema, FulfillmentMethodCreateRequestSchema, FulfillmentMethodResponseSchema, FulfillmentMethodSchema, FulfillmentMethodUpdateRequestSchema, FulfillmentOptionSchema, FulfillmentResponseSchema, FulfillmentSchema, ItemResponseSchema, ItemSchema, LineItemResponseSchema, LineItemSchema, LineItemUpdateRequestSchema, LinkSchema, MerchantFulfillmentConfigSchema, MessageErrorSchema, MessageInfoSchema, MessageSchema, MessageWarningSchema, OrderConfirmationSchema, OrderLineItemSchema, OrderSchema, OrderUpdateSchema, PaymentCredentialSchema, PaymentHandlerBaseSchema, PaymentHandlerBusinessSchema, PaymentHandlerPlatformSchema, PaymentHandlerResponseSchema, PaymentIdentitySchema, PaymentInstrumentResponseSchema, PaymentInstrumentSchema, PaymentResponseSchema, PaymentSchema, PlatformFulfillmentConfigSchema, PostalAddressSchema, RetailLocationSchema, ServiceBaseSchema, ServiceBusinessSchema, ServicePlatformSchema, ServiceResponseSchema, ShippingDestinationSchema, TokenCredentialSchema, TotalResponseSchema, TotalSchema, UcpBaseSchema, UcpBusinessSchema, UcpDiscoveryProfileSchema, UcpEntitySchema, UcpPlatformSchema, UcpResponseCheckoutSchema, UcpResponseOrderSchema, UcpReverseDomainNameSchema, UcpVersionSchema } from "@omnixhq/ucp-js-sdk";
|
|
4
|
+
import { AccountInfoSchema, AdjustmentSchema, AdjustmentStatusEnumSchema, Ap2MandateAp2WithCheckoutMandateSchema, Ap2MandateAp2WithMerchantAuthorizationSchema, Ap2MandateCheckoutMandateSchema, Ap2MandateErrorCodeSchema, Ap2MandateMerchantAuthorizationSchema, BindingSchema, BusinessFulfillmentConfigSchema, BuyerConsentBuyerSchema, BuyerConsentConsentSchema, BuyerSchema, CapabilityBaseSchema, CapabilityBusinessSchema, CapabilityPlatformSchema, CapabilityResponseSchema, CardCredentialCardNumberTypeEnumSchema, CardCredentialSchema, CardPaymentInstrumentSchema, CheckoutCompleteRequestSchema, CheckoutCreateRequestSchema, CheckoutResponseSchema, CheckoutResponseStatusSchema, CheckoutSchema, CheckoutStatusEnumSchema, CheckoutUpdateRequestSchema, ContextSchema, DiscountAllocationSchema, DiscountAppliedDiscountMethodEnumSchema, DiscountAppliedDiscountSchema, DiscountDiscountsObjectSchema, EmbeddedConfigSchema, ExpectationMethodTypeEnumSchema, ExpectationSchema, FulfillmentAvailableMethodSchema, FulfillmentAvailableMethodTypeEnumSchema, FulfillmentDestinationSchema, FulfillmentEventSchema, FulfillmentExtensionFulfillmentAvailableMethodSchema, FulfillmentExtensionFulfillmentGroupSchema, FulfillmentExtensionFulfillmentMethodSchema, FulfillmentExtensionFulfillmentOptionSchema, FulfillmentExtensionFulfillmentSchema, FulfillmentGroupSchema, FulfillmentGroupUpdateRequestSchema, FulfillmentMethodCreateRequestSchema, FulfillmentMethodResponseSchema, FulfillmentMethodSchema, FulfillmentMethodTypeEnumSchema, FulfillmentMethodUpdateRequestSchema, FulfillmentOptionSchema, FulfillmentResponseSchema, FulfillmentSchema, ItemResponseSchema, ItemSchema, LineItemResponseSchema, LineItemSchema, LineItemUpdateRequestSchema, LinkSchema, MerchantFulfillmentConfigSchema, MessageErrorContentTypeEnumSchema, MessageErrorSchema, MessageErrorSeverityEnumSchema, MessageInfoContentTypeEnumSchema, MessageInfoSchema, MessageSchema, MessageWarningContentTypeEnumSchema, MessageWarningSchema, OrderConfirmationSchema, OrderLineItemSchema, OrderLineItemStatusEnumSchema, OrderSchema, OrderUpdateSchema, PaymentCredentialSchema, PaymentHandlerBaseSchema, PaymentHandlerBusinessSchema, PaymentHandlerPlatformSchema, PaymentHandlerResponseSchema, PaymentIdentitySchema, PaymentInstrumentResponseSchema, PaymentInstrumentSchema, PaymentResponseSchema, PaymentSchema, PlatformFulfillmentConfigSchema, PostalAddressSchema, ProfileSchemaBaseSchema, ProfileSchemaBusinessProfileSchema, ProfileSchemaPlatformProfileSchema, ProfileSchemaSigningKeySchema, ProfileSchemaSigningKeyUseEnumSchema, RetailLocationSchema, ServiceBaseSchema, ServiceBaseTransportEnumSchema, ServiceBusinessSchema, ServicePlatformSchema, ServiceResponseSchema, ShippingDestinationSchema, TokenCredentialSchema, TotalResponseSchema, TotalSchema, TotalTypeEnumSchema, UcpBaseSchema, UcpBusinessSchema, UcpDiscoveryBusinessProfileSchema, UcpDiscoveryPlatformProfileSchema, UcpDiscoveryProfileSchema, UcpEntitySchema, UcpPlatformSchema, UcpResponseCheckoutSchema, UcpResponseOrderSchema, UcpReverseDomainNameSchema, UcpSigningKeySchema, UcpVersionSchema } from "@omnixhq/ucp-js-sdk";
|
|
5
5
|
|
|
6
6
|
//#region src/schemas.ts
|
|
7
|
-
const CheckoutSessionSchema = CheckoutResponseSchema
|
|
8
|
-
const UCPProfileSchema = UcpDiscoveryProfileSchema
|
|
9
|
-
const CreateCheckoutRequestSchema = CheckoutCreateRequestSchema
|
|
10
|
-
const UpdateCheckoutRequestSchema = CheckoutUpdateRequestSchema
|
|
11
|
-
const CompleteCheckoutRequestSchema = CheckoutCompleteRequestSchema
|
|
12
|
-
/** @deprecated Removed from ucp-js-sdk 1.0.2. Use PaymentCredentialSchema instead. */
|
|
13
|
-
const ExtendedPaymentCredentialSchema = z.object({
|
|
14
|
-
type: z.string(),
|
|
15
|
-
token: z.string().optional()
|
|
16
|
-
}).passthrough();
|
|
17
|
-
/** @deprecated Removed from ucp-js-sdk 1.0.2. Will be removed in a future major version. */
|
|
18
|
-
const PlatformConfigSchema = z.object({ webhook_url: z.string().optional() }).passthrough();
|
|
7
|
+
const CheckoutSessionSchema = CheckoutResponseSchema;
|
|
8
|
+
const UCPProfileSchema = UcpDiscoveryProfileSchema;
|
|
9
|
+
const CreateCheckoutRequestSchema = CheckoutCreateRequestSchema;
|
|
10
|
+
const UpdateCheckoutRequestSchema = CheckoutUpdateRequestSchema;
|
|
11
|
+
const CompleteCheckoutRequestSchema = CheckoutCompleteRequestSchema;
|
|
19
12
|
const WebhookEventSchema = z.object({
|
|
20
13
|
event_id: z.string(),
|
|
21
14
|
created_time: z.string(),
|
|
22
|
-
order: OrderSchema
|
|
23
|
-
})
|
|
24
|
-
const JWKSchema = z.object({
|
|
25
|
-
kty: z.string(),
|
|
26
|
-
kid: z.string().optional(),
|
|
27
|
-
use: z.string().optional(),
|
|
28
|
-
alg: z.string().optional(),
|
|
29
|
-
crv: z.string().optional(),
|
|
30
|
-
x: z.string().optional(),
|
|
31
|
-
y: z.string().optional()
|
|
32
|
-
}).passthrough();
|
|
15
|
+
order: OrderSchema
|
|
16
|
+
});
|
|
33
17
|
|
|
34
18
|
//#endregion
|
|
35
19
|
//#region src/http.ts
|
|
@@ -46,7 +30,7 @@ var HttpClient = class HttpClient {
|
|
|
46
30
|
this.ucpVersion = config.ucpVersion;
|
|
47
31
|
this.requestSignature = config.requestSignature;
|
|
48
32
|
this.accessToken = config.accessToken;
|
|
49
|
-
this.onValidationWarning = config.onValidationWarning ?? ((
|
|
33
|
+
this.onValidationWarning = config.onValidationWarning ?? (() => void 0);
|
|
50
34
|
}
|
|
51
35
|
withAccessToken(token) {
|
|
52
36
|
return new HttpClient({
|
|
@@ -87,21 +71,18 @@ var HttpClient = class HttpClient {
|
|
|
87
71
|
return result.data;
|
|
88
72
|
}
|
|
89
73
|
throwFromResponse(data, statusCode) {
|
|
90
|
-
if (typeof data
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
...first.content_type !== void 0 ? { contentType: first.content_type } : {},
|
|
103
|
-
messages: allMessages
|
|
104
|
-
});
|
|
74
|
+
if (typeof data === "object" && data !== null && Array.isArray(data["messages"])) {
|
|
75
|
+
const rawMessages = data["messages"];
|
|
76
|
+
if (rawMessages.length > 0) {
|
|
77
|
+
const allMessages = parseMessages(rawMessages);
|
|
78
|
+
const first = allMessages[0];
|
|
79
|
+
const code = first.code ?? "UNKNOWN";
|
|
80
|
+
throw new UCPError(code, first.content, first.type, statusCode, {
|
|
81
|
+
...first.path !== void 0 ? { path: first.path } : {},
|
|
82
|
+
...first.content_type !== void 0 ? { contentType: first.content_type } : {},
|
|
83
|
+
messages: allMessages
|
|
84
|
+
});
|
|
85
|
+
}
|
|
105
86
|
}
|
|
106
87
|
if (statusCode === 409) throw new UCPIdempotencyConflictError();
|
|
107
88
|
throw new UCPError("HTTP_ERROR", `Gateway returned ${statusCode}`, "error", statusCode);
|
|
@@ -151,10 +132,7 @@ function parseMessages(rawMessages) {
|
|
|
151
132
|
return {
|
|
152
133
|
type,
|
|
153
134
|
content: String(record["content"] ?? "Unknown error"),
|
|
154
|
-
...record["code"] !== void 0 ? { code: String(record["code"]) } : {}
|
|
155
|
-
...record["severity"] !== void 0 ? { severity: String(record["severity"]) } : {},
|
|
156
|
-
...record["path"] !== void 0 ? { path: String(record["path"]) } : {},
|
|
157
|
-
...record["content_type"] !== void 0 ? { content_type: String(record["content_type"]) } : {}
|
|
135
|
+
...record["code"] !== void 0 ? { code: String(record["code"]) } : {}
|
|
158
136
|
};
|
|
159
137
|
});
|
|
160
138
|
}
|
|
@@ -194,44 +172,48 @@ var CheckoutCapability = class {
|
|
|
194
172
|
const data = await this.http.request("POST", `/checkout-sessions/${encodeURIComponent(id)}/cancel`);
|
|
195
173
|
return this.validateSession(data);
|
|
196
174
|
}
|
|
197
|
-
async setFulfillment(id, type
|
|
198
|
-
return this.
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
type
|
|
203
|
-
}] }
|
|
204
|
-
});
|
|
175
|
+
async setFulfillment(id, type) {
|
|
176
|
+
return this.patchFulfillmentDiscount(id, { fulfillment: { methods: [{
|
|
177
|
+
id: DEFAULT_METHOD_ID,
|
|
178
|
+
type
|
|
179
|
+
}] } });
|
|
205
180
|
}
|
|
206
|
-
async selectDestination(id, destinationId, fulfillmentType = "shipping"
|
|
207
|
-
return this.
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
selected_destination_id: destinationId
|
|
213
|
-
}] }
|
|
214
|
-
});
|
|
181
|
+
async selectDestination(id, destinationId, fulfillmentType = "shipping") {
|
|
182
|
+
return this.patchFulfillmentDiscount(id, { fulfillment: { methods: [{
|
|
183
|
+
id: DEFAULT_METHOD_ID,
|
|
184
|
+
type: fulfillmentType,
|
|
185
|
+
selected_destination_id: destinationId
|
|
186
|
+
}] } });
|
|
215
187
|
}
|
|
216
|
-
async selectFulfillmentOption(id, optionId, destinationId, fulfillmentType = "shipping"
|
|
217
|
-
return this.
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}]
|
|
227
|
-
}] }
|
|
228
|
-
});
|
|
188
|
+
async selectFulfillmentOption(id, optionId, destinationId, fulfillmentType = "shipping") {
|
|
189
|
+
return this.patchFulfillmentDiscount(id, { fulfillment: { methods: [{
|
|
190
|
+
id: DEFAULT_METHOD_ID,
|
|
191
|
+
type: fulfillmentType,
|
|
192
|
+
...destinationId !== void 0 ? { selected_destination_id: destinationId } : {},
|
|
193
|
+
groups: [{
|
|
194
|
+
id: DEFAULT_GROUP_ID,
|
|
195
|
+
selected_option_id: optionId
|
|
196
|
+
}]
|
|
197
|
+
}] } });
|
|
229
198
|
}
|
|
230
|
-
async applyDiscountCodes(id, codes
|
|
231
|
-
return this.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
});
|
|
199
|
+
async applyDiscountCodes(id, codes) {
|
|
200
|
+
return this.patchFulfillmentDiscount(id, { discounts: { codes: [...codes] } });
|
|
201
|
+
}
|
|
202
|
+
async createFulfillmentMethod(id, payload) {
|
|
203
|
+
const data = await this.http.request("POST", `/checkout-sessions/${encodeURIComponent(id)}/fulfillment/methods`, payload);
|
|
204
|
+
return this.validateSession(data);
|
|
205
|
+
}
|
|
206
|
+
async updateFulfillmentMethod(id, methodId, payload) {
|
|
207
|
+
const data = await this.http.request("PUT", `/checkout-sessions/${encodeURIComponent(id)}/fulfillment/methods/${encodeURIComponent(methodId)}`, payload);
|
|
208
|
+
return this.validateSession(data);
|
|
209
|
+
}
|
|
210
|
+
async updateFulfillmentGroup(id, methodId, groupId, payload) {
|
|
211
|
+
const data = await this.http.request("PUT", `/checkout-sessions/${encodeURIComponent(id)}/fulfillment/methods/${encodeURIComponent(methodId)}/groups/${encodeURIComponent(groupId)}`, payload);
|
|
212
|
+
return this.validateSession(data);
|
|
213
|
+
}
|
|
214
|
+
async patchFulfillmentDiscount(id, patch) {
|
|
215
|
+
const data = await this.http.request("PUT", `/checkout-sessions/${encodeURIComponent(id)}`, patch);
|
|
216
|
+
return this.validateSession(data);
|
|
235
217
|
}
|
|
236
218
|
validateSession(data) {
|
|
237
219
|
const session = this.http.validate(data, CheckoutSessionSchema);
|
|
@@ -255,7 +237,12 @@ var OrderCapability = class {
|
|
|
255
237
|
/** Update an order with fulfillment events, adjustments, or status changes. */
|
|
256
238
|
async update(id, payload) {
|
|
257
239
|
const data = await this.http.request("PUT", `/orders/${encodeURIComponent(id)}`, payload);
|
|
258
|
-
return this.http.validate(data,
|
|
240
|
+
return this.http.validate(data, OrderUpdateSchema);
|
|
241
|
+
}
|
|
242
|
+
/** Update a single line item within an order (e.g. set parent for grouping). */
|
|
243
|
+
async updateLineItem(id, lineItemId, payload) {
|
|
244
|
+
const data = await this.http.request("PUT", `/orders/${encodeURIComponent(id)}/line-items/${encodeURIComponent(lineItemId)}`, payload);
|
|
245
|
+
return this.http.validate(data, OrderUpdateSchema);
|
|
259
246
|
}
|
|
260
247
|
};
|
|
261
248
|
|
|
@@ -642,6 +629,97 @@ function fulfillmentTools(client) {
|
|
|
642
629
|
required: ["id", "option_id"]
|
|
643
630
|
},
|
|
644
631
|
execute: async (params) => client.checkout.selectFulfillmentOption(params["id"], params["option_id"], params["destination_id"], params["fulfillment_type"] ?? "shipping")
|
|
632
|
+
},
|
|
633
|
+
{
|
|
634
|
+
name: "create_fulfillment_method",
|
|
635
|
+
description: "Add a new fulfillment method (shipping or pickup) to a checkout session.",
|
|
636
|
+
parameters: {
|
|
637
|
+
type: "object",
|
|
638
|
+
properties: {
|
|
639
|
+
id: {
|
|
640
|
+
type: "string",
|
|
641
|
+
description: "Checkout session ID"
|
|
642
|
+
},
|
|
643
|
+
type: {
|
|
644
|
+
type: "string",
|
|
645
|
+
enum: ["shipping", "pickup"],
|
|
646
|
+
description: "Fulfillment method type"
|
|
647
|
+
},
|
|
648
|
+
line_item_ids: {
|
|
649
|
+
type: "array",
|
|
650
|
+
items: { type: "string" },
|
|
651
|
+
description: "Line item IDs to associate with this method (optional)"
|
|
652
|
+
}
|
|
653
|
+
},
|
|
654
|
+
required: ["id", "type"]
|
|
655
|
+
},
|
|
656
|
+
execute: async (params) => {
|
|
657
|
+
const { id,...payload } = params;
|
|
658
|
+
return client.checkout.createFulfillmentMethod(id, payload);
|
|
659
|
+
}
|
|
660
|
+
},
|
|
661
|
+
{
|
|
662
|
+
name: "update_fulfillment_method",
|
|
663
|
+
description: "Update an existing fulfillment method on a checkout session.",
|
|
664
|
+
parameters: {
|
|
665
|
+
type: "object",
|
|
666
|
+
properties: {
|
|
667
|
+
id: {
|
|
668
|
+
type: "string",
|
|
669
|
+
description: "Checkout session ID"
|
|
670
|
+
},
|
|
671
|
+
method_id: {
|
|
672
|
+
type: "string",
|
|
673
|
+
description: "Fulfillment method ID to update"
|
|
674
|
+
},
|
|
675
|
+
type: {
|
|
676
|
+
type: "string",
|
|
677
|
+
enum: ["shipping", "pickup"],
|
|
678
|
+
description: "Updated fulfillment method type (optional)"
|
|
679
|
+
},
|
|
680
|
+
line_item_ids: {
|
|
681
|
+
type: "array",
|
|
682
|
+
items: { type: "string" },
|
|
683
|
+
description: "Updated line item IDs to associate with this method"
|
|
684
|
+
}
|
|
685
|
+
},
|
|
686
|
+
required: [
|
|
687
|
+
"id",
|
|
688
|
+
"method_id",
|
|
689
|
+
"line_item_ids"
|
|
690
|
+
]
|
|
691
|
+
},
|
|
692
|
+
execute: async (params) => {
|
|
693
|
+
const { id, method_id,...payload } = params;
|
|
694
|
+
return client.checkout.updateFulfillmentMethod(id, method_id, payload);
|
|
695
|
+
}
|
|
696
|
+
},
|
|
697
|
+
{
|
|
698
|
+
name: "update_fulfillment_group",
|
|
699
|
+
description: "Update a fulfillment group within a fulfillment method on a checkout session.",
|
|
700
|
+
parameters: {
|
|
701
|
+
type: "object",
|
|
702
|
+
properties: {
|
|
703
|
+
id: {
|
|
704
|
+
type: "string",
|
|
705
|
+
description: "Checkout session ID"
|
|
706
|
+
},
|
|
707
|
+
method_id: {
|
|
708
|
+
type: "string",
|
|
709
|
+
description: "Fulfillment method ID"
|
|
710
|
+
},
|
|
711
|
+
group_id: {
|
|
712
|
+
type: "string",
|
|
713
|
+
description: "Fulfillment group ID to update"
|
|
714
|
+
}
|
|
715
|
+
},
|
|
716
|
+
required: [
|
|
717
|
+
"id",
|
|
718
|
+
"method_id",
|
|
719
|
+
"group_id"
|
|
720
|
+
]
|
|
721
|
+
},
|
|
722
|
+
execute: async (params) => client.checkout.updateFulfillmentGroup(params["id"], params["method_id"], params["group_id"], { id: params["group_id"] })
|
|
645
723
|
}
|
|
646
724
|
];
|
|
647
725
|
}
|
|
@@ -668,45 +746,74 @@ function discountTools(client) {
|
|
|
668
746
|
}];
|
|
669
747
|
}
|
|
670
748
|
function orderTools(client) {
|
|
671
|
-
return [
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
description: "Order ID"
|
|
679
|
-
} },
|
|
680
|
-
required: ["id"]
|
|
681
|
-
},
|
|
682
|
-
execute: async (params) => client.order.get(params["id"])
|
|
683
|
-
}, {
|
|
684
|
-
name: "update_order",
|
|
685
|
-
description: "Update an order with fulfillment events, adjustments, or status changes.",
|
|
686
|
-
parameters: {
|
|
687
|
-
type: "object",
|
|
688
|
-
properties: {
|
|
689
|
-
id: {
|
|
749
|
+
return [
|
|
750
|
+
{
|
|
751
|
+
name: "get_order",
|
|
752
|
+
description: "Get order details by ID, including line items, fulfillment status, and tracking information.",
|
|
753
|
+
parameters: {
|
|
754
|
+
type: "object",
|
|
755
|
+
properties: { id: {
|
|
690
756
|
type: "string",
|
|
691
757
|
description: "Order ID"
|
|
758
|
+
} },
|
|
759
|
+
required: ["id"]
|
|
760
|
+
},
|
|
761
|
+
execute: async (params) => client.order.get(params["id"])
|
|
762
|
+
},
|
|
763
|
+
{
|
|
764
|
+
name: "update_order",
|
|
765
|
+
description: "Update an order with fulfillment events, adjustments, or status changes.",
|
|
766
|
+
parameters: {
|
|
767
|
+
type: "object",
|
|
768
|
+
properties: {
|
|
769
|
+
id: {
|
|
770
|
+
type: "string",
|
|
771
|
+
description: "Order ID"
|
|
772
|
+
},
|
|
773
|
+
fulfillment: {
|
|
774
|
+
type: "object",
|
|
775
|
+
description: "Fulfillment update data (events, tracking)"
|
|
776
|
+
},
|
|
777
|
+
adjustments: {
|
|
778
|
+
type: "array",
|
|
779
|
+
description: "Order adjustments (refunds, returns)",
|
|
780
|
+
items: { type: "object" }
|
|
781
|
+
}
|
|
692
782
|
},
|
|
693
|
-
|
|
694
|
-
type: "object",
|
|
695
|
-
description: "Fulfillment update data (events, tracking)"
|
|
696
|
-
},
|
|
697
|
-
adjustments: {
|
|
698
|
-
type: "array",
|
|
699
|
-
description: "Order adjustments (refunds, returns)",
|
|
700
|
-
items: { type: "object" }
|
|
701
|
-
}
|
|
783
|
+
required: ["id"]
|
|
702
784
|
},
|
|
703
|
-
|
|
785
|
+
execute: async (params) => {
|
|
786
|
+
const { id,...payload } = params;
|
|
787
|
+
return client.order.update(id, payload);
|
|
788
|
+
}
|
|
704
789
|
},
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
790
|
+
{
|
|
791
|
+
name: "update_order_line_item",
|
|
792
|
+
description: "Update a line item within an order, such as setting a parent line item for grouping.",
|
|
793
|
+
parameters: {
|
|
794
|
+
type: "object",
|
|
795
|
+
properties: {
|
|
796
|
+
id: {
|
|
797
|
+
type: "string",
|
|
798
|
+
description: "Order ID"
|
|
799
|
+
},
|
|
800
|
+
line_item_id: {
|
|
801
|
+
type: "string",
|
|
802
|
+
description: "Line item ID to update"
|
|
803
|
+
},
|
|
804
|
+
parent_id: {
|
|
805
|
+
type: "string",
|
|
806
|
+
description: "Parent line item ID for grouping (optional)"
|
|
807
|
+
}
|
|
808
|
+
},
|
|
809
|
+
required: ["id", "line_item_id"]
|
|
810
|
+
},
|
|
811
|
+
execute: async (params) => {
|
|
812
|
+
const { id, line_item_id,...payload } = params;
|
|
813
|
+
return client.order.updateLineItem(id, line_item_id, payload);
|
|
814
|
+
}
|
|
708
815
|
}
|
|
709
|
-
|
|
816
|
+
];
|
|
710
817
|
}
|
|
711
818
|
function identityLinkingTools(client) {
|
|
712
819
|
return [
|
|
@@ -833,21 +940,6 @@ function identityLinkingTools(client) {
|
|
|
833
940
|
|
|
834
941
|
//#endregion
|
|
835
942
|
//#region src/UCPClient.ts
|
|
836
|
-
/**
|
|
837
|
-
* Connect to a UCP server, discover its capabilities, and return a {@link ConnectedClient}.
|
|
838
|
-
*
|
|
839
|
-
* @example
|
|
840
|
-
* ```typescript
|
|
841
|
-
* const client = await connect({
|
|
842
|
-
* gatewayUrl: 'https://store.example.com/ucp',
|
|
843
|
-
* agentProfileUrl: 'https://platform.example.com/.well-known/ucp',
|
|
844
|
-
* });
|
|
845
|
-
*
|
|
846
|
-
* if (client.checkout) {
|
|
847
|
-
* const session = await client.checkout.create({ line_items: [...] });
|
|
848
|
-
* }
|
|
849
|
-
* ```
|
|
850
|
-
*/
|
|
851
943
|
async function connect(config, options) {
|
|
852
944
|
validateConfig(config);
|
|
853
945
|
const http = new HttpClient({
|
|
@@ -877,40 +969,29 @@ async function connect(config, options) {
|
|
|
877
969
|
};
|
|
878
970
|
return Object.freeze(client);
|
|
879
971
|
}
|
|
880
|
-
/**
|
|
881
|
-
* UCP client entry point. Use `UCPClient.connect()` to discover server capabilities
|
|
882
|
-
* and get a {@link ConnectedClient}.
|
|
883
|
-
*
|
|
884
|
-
* @example
|
|
885
|
-
* ```typescript
|
|
886
|
-
* const client = await UCPClient.connect({
|
|
887
|
-
* gatewayUrl: 'https://store.example.com/ucp',
|
|
888
|
-
* agentProfileUrl: 'https://platform.example.com/.well-known/ucp',
|
|
889
|
-
* });
|
|
890
|
-
* ```
|
|
891
|
-
*/
|
|
892
972
|
var UCPClient = class {
|
|
893
973
|
constructor() {}
|
|
894
974
|
static connect = connect;
|
|
895
975
|
};
|
|
896
976
|
function validateConfig(config) {
|
|
897
|
-
|
|
977
|
+
try {
|
|
978
|
+
new URL(config.gatewayUrl);
|
|
979
|
+
} catch {
|
|
980
|
+
throw new Error(`UCPClient: gatewayUrl is not a valid URL: "${config.gatewayUrl}"`);
|
|
981
|
+
}
|
|
898
982
|
if (config.agentProfileUrl.includes("\"") || config.agentProfileUrl.includes("\n")) throw new Error("agentProfileUrl must not contain double quotes or newlines");
|
|
899
|
-
|
|
983
|
+
try {
|
|
984
|
+
new URL(config.agentProfileUrl);
|
|
985
|
+
} catch {
|
|
986
|
+
throw new Error(`UCPClient: agentProfileUrl is not a valid URL: "${config.agentProfileUrl}"`);
|
|
987
|
+
}
|
|
900
988
|
}
|
|
901
989
|
function extractCapabilityNames(profile) {
|
|
902
990
|
const capabilities = profile.ucp?.capabilities;
|
|
903
991
|
if (typeof capabilities !== "object" || capabilities === null) return new Set();
|
|
904
992
|
return new Set(Object.keys(capabilities));
|
|
905
993
|
}
|
|
906
|
-
const
|
|
907
|
-
id: z.string(),
|
|
908
|
-
version: z.string(),
|
|
909
|
-
spec: z.string(),
|
|
910
|
-
schema: z.string(),
|
|
911
|
-
config: z.record(z.unknown()).optional()
|
|
912
|
-
}).passthrough();
|
|
913
|
-
const PaymentHandlerMapSchema = z.record(z.array(PaymentHandlerInstanceSchema));
|
|
994
|
+
const PaymentHandlerMapSchema = z.record(z.array(PaymentHandlerBaseSchema));
|
|
914
995
|
function extractPaymentHandlers(profile) {
|
|
915
996
|
const raw = profile["payment_handlers"];
|
|
916
997
|
if (typeof raw !== "object" || raw === null) return {};
|
|
@@ -923,7 +1004,7 @@ function extractSigningKeys(profile) {
|
|
|
923
1004
|
if (!Array.isArray(raw)) return [];
|
|
924
1005
|
const keys = [];
|
|
925
1006
|
for (const item of raw) {
|
|
926
|
-
const result =
|
|
1007
|
+
const result = UcpSigningKeySchema.safeParse(item);
|
|
927
1008
|
if (result.success) keys.push(result.data);
|
|
928
1009
|
}
|
|
929
1010
|
return keys;
|
|
@@ -996,6 +1077,18 @@ function buildToolDescriptors(checkout, order, identityLinking) {
|
|
|
996
1077
|
name: "select_fulfillment_option",
|
|
997
1078
|
capability: "checkout.fulfillment",
|
|
998
1079
|
description: "Select fulfillment option (e.g., express shipping)"
|
|
1080
|
+
}, {
|
|
1081
|
+
name: "create_fulfillment_method",
|
|
1082
|
+
capability: "checkout.fulfillment",
|
|
1083
|
+
description: "Add a new fulfillment method to a checkout session"
|
|
1084
|
+
}, {
|
|
1085
|
+
name: "update_fulfillment_method",
|
|
1086
|
+
capability: "checkout.fulfillment",
|
|
1087
|
+
description: "Update an existing fulfillment method on a checkout session"
|
|
1088
|
+
}, {
|
|
1089
|
+
name: "update_fulfillment_group",
|
|
1090
|
+
capability: "checkout.fulfillment",
|
|
1091
|
+
description: "Update a fulfillment group within a fulfillment method"
|
|
999
1092
|
});
|
|
1000
1093
|
if (checkout.extensions.discount) tools.push({
|
|
1001
1094
|
name: "apply_discount_codes",
|
|
@@ -1011,6 +1104,10 @@ function buildToolDescriptors(checkout, order, identityLinking) {
|
|
|
1011
1104
|
name: "update_order",
|
|
1012
1105
|
capability: "order",
|
|
1013
1106
|
description: "Update an order"
|
|
1107
|
+
}, {
|
|
1108
|
+
name: "update_order_line_item",
|
|
1109
|
+
capability: "order",
|
|
1110
|
+
description: "Update a line item within an order"
|
|
1014
1111
|
});
|
|
1015
1112
|
if (identityLinking) tools.push({
|
|
1016
1113
|
name: "get_authorization_url",
|
|
@@ -1103,24 +1200,43 @@ function createWebhookVerifier(gatewayUrl) {
|
|
|
1103
1200
|
const baseUrl = gatewayUrl.replace(/\/+$/, "");
|
|
1104
1201
|
const keyCache = new Map();
|
|
1105
1202
|
let fetched = false;
|
|
1203
|
+
let loadingPromise = null;
|
|
1106
1204
|
async function loadKeys() {
|
|
1107
1205
|
const res = await fetch(`${baseUrl}/.well-known/ucp`);
|
|
1108
|
-
if (!res.ok)
|
|
1109
|
-
|
|
1206
|
+
if (!res.ok) {
|
|
1207
|
+
fetched = true;
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1210
|
+
let profile;
|
|
1211
|
+
try {
|
|
1212
|
+
profile = await res.json();
|
|
1213
|
+
} catch {
|
|
1214
|
+
fetched = true;
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1110
1217
|
const rawKeys = profile["signing_keys"];
|
|
1111
|
-
if (!Array.isArray(rawKeys))
|
|
1218
|
+
if (!Array.isArray(rawKeys)) {
|
|
1219
|
+
fetched = true;
|
|
1220
|
+
return;
|
|
1221
|
+
}
|
|
1112
1222
|
keyCache.clear();
|
|
1113
1223
|
for (const item of rawKeys) {
|
|
1114
|
-
const parsed =
|
|
1224
|
+
const parsed = UcpSigningKeySchema.safeParse(item);
|
|
1115
1225
|
if (parsed.success && typeof parsed.data.kid === "string") keyCache.set(parsed.data.kid, parsed.data);
|
|
1116
1226
|
}
|
|
1117
1227
|
fetched = true;
|
|
1118
1228
|
}
|
|
1229
|
+
function ensureKeys() {
|
|
1230
|
+
loadingPromise ??= loadKeys().finally(() => {
|
|
1231
|
+
loadingPromise = null;
|
|
1232
|
+
});
|
|
1233
|
+
return loadingPromise;
|
|
1234
|
+
}
|
|
1119
1235
|
return { async verify(body, signature) {
|
|
1120
1236
|
const kid = extractKid(signature);
|
|
1121
1237
|
if (kid === null) return false;
|
|
1122
|
-
if (!fetched) await
|
|
1123
|
-
if (!keyCache.has(kid)) await
|
|
1238
|
+
if (!fetched) await ensureKeys();
|
|
1239
|
+
if (!keyCache.has(kid)) await ensureKeys();
|
|
1124
1240
|
const key = keyCache.get(kid);
|
|
1125
1241
|
if (!key) return false;
|
|
1126
1242
|
return verifyRequestSignature(body, signature, [key]);
|
|
@@ -1184,5 +1300,5 @@ function parseWebhookEvent(body) {
|
|
|
1184
1300
|
}
|
|
1185
1301
|
|
|
1186
1302
|
//#endregion
|
|
1187
|
-
export { AccountInfoSchema, AdjustmentSchema, Ap2MandateAp2WithCheckoutMandateSchema, Ap2MandateAp2WithMerchantAuthorizationSchema, Ap2MandateCheckoutMandateSchema, Ap2MandateErrorCodeSchema, Ap2MandateMerchantAuthorizationSchema, BindingSchema, BusinessFulfillmentConfigSchema, BuyerConsentBuyerSchema, BuyerConsentConsentSchema, BuyerSchema, CapabilityBaseSchema, CapabilityBusinessSchema, CapabilityPlatformSchema, CapabilityResponseSchema, CardCredentialSchema, CardPaymentInstrumentSchema, CheckoutCapability, CheckoutCompleteRequestSchema, CheckoutCreateRequestSchema, CheckoutResponseSchema, CheckoutResponseStatusSchema, CheckoutSchema, CheckoutSessionSchema, CheckoutUpdateRequestSchema, CompleteCheckoutRequestSchema, ContextSchema, CreateCheckoutRequestSchema, DEFAULT_UCP_VERSION, DiscountAllocationSchema, DiscountAppliedDiscountSchema, DiscountDiscountsObjectSchema, EmbeddedConfigSchema,
|
|
1303
|
+
export { AccountInfoSchema, AdjustmentSchema, AdjustmentStatusEnumSchema, Ap2MandateAp2WithCheckoutMandateSchema, Ap2MandateAp2WithMerchantAuthorizationSchema, Ap2MandateCheckoutMandateSchema, Ap2MandateErrorCodeSchema, Ap2MandateMerchantAuthorizationSchema, BindingSchema, BusinessFulfillmentConfigSchema, BuyerConsentBuyerSchema, BuyerConsentConsentSchema, BuyerSchema, CapabilityBaseSchema, CapabilityBusinessSchema, CapabilityPlatformSchema, CapabilityResponseSchema, CardCredentialCardNumberTypeEnumSchema, CardCredentialSchema, CardPaymentInstrumentSchema, CheckoutCapability, CheckoutCompleteRequestSchema, CheckoutCreateRequestSchema, CheckoutResponseSchema, CheckoutResponseStatusSchema, CheckoutSchema, CheckoutSessionSchema, CheckoutStatusEnumSchema, CheckoutUpdateRequestSchema, CompleteCheckoutRequestSchema, ContextSchema, CreateCheckoutRequestSchema, DEFAULT_UCP_VERSION, DiscountAllocationSchema, DiscountAppliedDiscountMethodEnumSchema, DiscountAppliedDiscountSchema, DiscountDiscountsObjectSchema, EmbeddedConfigSchema, ExpectationMethodTypeEnumSchema, ExpectationSchema, FulfillmentAvailableMethodSchema, FulfillmentAvailableMethodTypeEnumSchema, FulfillmentDestinationSchema, FulfillmentEventSchema, FulfillmentExtensionFulfillmentAvailableMethodSchema, FulfillmentExtensionFulfillmentGroupSchema, FulfillmentExtensionFulfillmentMethodSchema, FulfillmentExtensionFulfillmentOptionSchema, FulfillmentExtensionFulfillmentSchema, FulfillmentGroupSchema, FulfillmentGroupUpdateRequestSchema, FulfillmentMethodCreateRequestSchema, FulfillmentMethodResponseSchema, FulfillmentMethodSchema, FulfillmentMethodTypeEnumSchema, FulfillmentMethodUpdateRequestSchema, FulfillmentOptionSchema, FulfillmentResponseSchema, FulfillmentSchema, IdentityLinkingCapability, ItemResponseSchema, ItemSchema, UcpSigningKeySchema as JWKSchema, LineItemResponseSchema, LineItemSchema, LineItemUpdateRequestSchema, LinkSchema, MerchantFulfillmentConfigSchema, MessageErrorContentTypeEnumSchema, MessageErrorSchema, MessageErrorSeverityEnumSchema, MessageInfoContentTypeEnumSchema, MessageInfoSchema, MessageSchema, MessageWarningContentTypeEnumSchema, MessageWarningSchema, OrderCapability, OrderConfirmationSchema, OrderLineItemSchema, OrderLineItemStatusEnumSchema, OrderUpdateSchema, PaymentCredentialSchema, PaymentHandlerBaseSchema, PaymentHandlerBusinessSchema, PaymentHandlerPlatformSchema, PaymentHandlerResponseSchema, PaymentIdentitySchema, PaymentInstrumentResponseSchema, PaymentInstrumentSchema, PaymentResponseSchema, PaymentSchema, PlatformFulfillmentConfigSchema, PostalAddressSchema, ProfileSchemaBaseSchema, ProfileSchemaBusinessProfileSchema, ProfileSchemaPlatformProfileSchema, ProfileSchemaSigningKeySchema, ProfileSchemaSigningKeyUseEnumSchema, RetailLocationSchema, ServiceBaseSchema, ServiceBaseTransportEnumSchema, ServiceBusinessSchema, ServicePlatformSchema, ServiceResponseSchema, ShippingDestinationSchema, TokenCredentialSchema, TotalResponseSchema, TotalSchema, TotalTypeEnumSchema, UCPClient, UCPError, UCPEscalationError, UCPIdempotencyConflictError, UCPOAuthError, UCPProfileSchema, OrderSchema as UCPSpecOrderSchema, UCP_CAPABILITIES, UcpBaseSchema, UcpBusinessSchema, UcpDiscoveryBusinessProfileSchema, UcpDiscoveryPlatformProfileSchema, UcpEntitySchema, UcpPlatformSchema, UcpResponseCheckoutSchema, UcpResponseOrderSchema, UcpReverseDomainNameSchema, UcpVersionSchema, UpdateCheckoutRequestSchema, WebhookEventSchema, connect, createWebhookVerifier, getAgentTools, parseWebhookEvent, verifyRequestSignature };
|
|
1188
1304
|
//# sourceMappingURL=index.js.map
|