@omnixhq/ucp-client 1.0.1 → 2.1.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 +35 -3
- 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-H8gObrht.d.ts → catch-errors-hlc4bOF9.d.cts} +23 -72
- package/dist/catch-errors-hlc4bOF9.d.cts.map +1 -0
- package/dist/{catch-errors-CbIHeFvF.d.cts → catch-errors-s9k0IH2E.d.ts} +23 -72
- package/dist/catch-errors-s9k0IH2E.d.ts.map +1 -0
- package/dist/index.cjs +311 -163
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3874 -5648
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +3874 -5648
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +215 -146
- package/dist/index.js.map +1 -1
- package/package.json +2 -4
- package/dist/catch-errors-CbIHeFvF.d.cts.map +0 -1
- package/dist/catch-errors-H8gObrht.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -25,8 +25,25 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
const require_errors = require('./errors-C1XqxNmZ.cjs');
|
|
26
26
|
const zod = __toESM(require("zod"));
|
|
27
27
|
const node_crypto = __toESM(require("node:crypto"));
|
|
28
|
-
const
|
|
28
|
+
const __omnixhq_ucp_js_sdk = __toESM(require("@omnixhq/ucp-js-sdk"));
|
|
29
29
|
|
|
30
|
+
//#region src/schemas.ts
|
|
31
|
+
const CheckoutSessionSchema = __omnixhq_ucp_js_sdk.ExtendedCheckoutResponseSchema.passthrough();
|
|
32
|
+
const UCPProfileSchema = __omnixhq_ucp_js_sdk.UcpDiscoveryProfileSchema.passthrough();
|
|
33
|
+
const CreateCheckoutRequestSchema = __omnixhq_ucp_js_sdk.ExtendedCheckoutCreateRequestSchema.passthrough();
|
|
34
|
+
const UpdateCheckoutRequestSchema = __omnixhq_ucp_js_sdk.ExtendedCheckoutUpdateRequestSchema.passthrough();
|
|
35
|
+
const CompleteCheckoutRequestSchema = __omnixhq_ucp_js_sdk.CheckoutCompleteRequestSchema.passthrough();
|
|
36
|
+
const JWKSchema = zod.z.object({
|
|
37
|
+
kty: zod.z.string(),
|
|
38
|
+
kid: zod.z.string().optional(),
|
|
39
|
+
use: zod.z.string().optional(),
|
|
40
|
+
alg: zod.z.string().optional(),
|
|
41
|
+
crv: zod.z.string().optional(),
|
|
42
|
+
x: zod.z.string().optional(),
|
|
43
|
+
y: zod.z.string().optional()
|
|
44
|
+
}).passthrough();
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
30
47
|
//#region src/http.ts
|
|
31
48
|
var HttpClient = class HttpClient {
|
|
32
49
|
gatewayUrl;
|
|
@@ -106,6 +123,37 @@ function parseMessages(rawMessages) {
|
|
|
106
123
|
return rawMessages.map((m) => {
|
|
107
124
|
const record = m;
|
|
108
125
|
const rawType = String(record["type"] ?? "error");
|
|
126
|
+
if (rawType === "error") {
|
|
127
|
+
const parsed = __omnixhq_ucp_js_sdk.MessageErrorSchema.safeParse(m);
|
|
128
|
+
if (parsed.success) return {
|
|
129
|
+
type: "error",
|
|
130
|
+
code: parsed.data.code,
|
|
131
|
+
content: parsed.data.content,
|
|
132
|
+
severity: parsed.data.severity,
|
|
133
|
+
...parsed.data.path !== void 0 ? { path: parsed.data.path } : {},
|
|
134
|
+
...parsed.data.content_type !== void 0 ? { content_type: parsed.data.content_type } : {}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
if (rawType === "warning") {
|
|
138
|
+
const parsed = __omnixhq_ucp_js_sdk.MessageWarningSchema.safeParse(m);
|
|
139
|
+
if (parsed.success) return {
|
|
140
|
+
type: "warning",
|
|
141
|
+
code: parsed.data.code,
|
|
142
|
+
content: parsed.data.content,
|
|
143
|
+
...parsed.data.path !== void 0 ? { path: parsed.data.path } : {},
|
|
144
|
+
...parsed.data.content_type !== void 0 ? { content_type: parsed.data.content_type } : {}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
if (rawType === "info") {
|
|
148
|
+
const parsed = __omnixhq_ucp_js_sdk.MessageInfoSchema.safeParse(m);
|
|
149
|
+
if (parsed.success) return {
|
|
150
|
+
type: "info",
|
|
151
|
+
content: parsed.data.content,
|
|
152
|
+
...parsed.data.code !== void 0 ? { code: parsed.data.code } : {},
|
|
153
|
+
...parsed.data.path !== void 0 ? { path: parsed.data.path } : {},
|
|
154
|
+
...parsed.data.content_type !== void 0 ? { content_type: parsed.data.content_type } : {}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
109
157
|
const validTypes = [
|
|
110
158
|
"error",
|
|
111
159
|
"warning",
|
|
@@ -123,54 +171,6 @@ function parseMessages(rawMessages) {
|
|
|
123
171
|
});
|
|
124
172
|
}
|
|
125
173
|
|
|
126
|
-
//#endregion
|
|
127
|
-
//#region src/schemas.ts
|
|
128
|
-
const CheckoutSessionSchema = __ucp_js_sdk.ExtendedCheckoutResponseSchema.passthrough();
|
|
129
|
-
const UCPProfileSchema = __ucp_js_sdk.UcpDiscoveryProfileSchema.passthrough();
|
|
130
|
-
const UCPProductSchema = zod.z.object({
|
|
131
|
-
id: zod.z.string(),
|
|
132
|
-
title: zod.z.string(),
|
|
133
|
-
description: zod.z.string().nullable(),
|
|
134
|
-
price_cents: zod.z.number().int(),
|
|
135
|
-
currency: zod.z.string().min(3).max(3),
|
|
136
|
-
in_stock: zod.z.boolean(),
|
|
137
|
-
stock_quantity: zod.z.number().int().min(0),
|
|
138
|
-
images: zod.z.array(zod.z.string().url()),
|
|
139
|
-
variants: zod.z.array(zod.z.object({
|
|
140
|
-
id: zod.z.string(),
|
|
141
|
-
title: zod.z.string(),
|
|
142
|
-
price_cents: zod.z.number().int(),
|
|
143
|
-
in_stock: zod.z.boolean(),
|
|
144
|
-
attributes: zod.z.record(zod.z.string())
|
|
145
|
-
}).passthrough())
|
|
146
|
-
}).passthrough();
|
|
147
|
-
const UCPOrderSchema = zod.z.object({
|
|
148
|
-
id: zod.z.string(),
|
|
149
|
-
status: zod.z.enum([
|
|
150
|
-
"pending",
|
|
151
|
-
"processing",
|
|
152
|
-
"shipped",
|
|
153
|
-
"delivered",
|
|
154
|
-
"canceled"
|
|
155
|
-
]),
|
|
156
|
-
total_cents: zod.z.number().int(),
|
|
157
|
-
currency: zod.z.string().min(3).max(3),
|
|
158
|
-
created_at_iso: zod.z.string().datetime({ offset: true })
|
|
159
|
-
}).passthrough();
|
|
160
|
-
const CreateCheckoutRequestSchema = __ucp_js_sdk.ExtendedCheckoutCreateRequestSchema.passthrough();
|
|
161
|
-
const UpdateCheckoutRequestSchema = __ucp_js_sdk.ExtendedCheckoutUpdateRequestSchema.passthrough();
|
|
162
|
-
const CompleteCheckoutRequestSchema = zod.z.object({ payment: zod.z.object({ instruments: zod.z.array(zod.z.object({
|
|
163
|
-
id: zod.z.string(),
|
|
164
|
-
handler_id: zod.z.string(),
|
|
165
|
-
type: zod.z.string(),
|
|
166
|
-
selected: zod.z.boolean().optional(),
|
|
167
|
-
credential: zod.z.object({
|
|
168
|
-
type: zod.z.string(),
|
|
169
|
-
token: zod.z.string().optional()
|
|
170
|
-
}).optional(),
|
|
171
|
-
billing_address: zod.z.unknown().optional()
|
|
172
|
-
}).passthrough()) }) });
|
|
173
|
-
|
|
174
174
|
//#endregion
|
|
175
175
|
//#region src/capabilities/checkout.ts
|
|
176
176
|
const DEFAULT_METHOD_ID = "default";
|
|
@@ -262,7 +262,12 @@ var OrderCapability = class {
|
|
|
262
262
|
/** Retrieve an order by ID. Returns the UCP spec-compliant Order object. */
|
|
263
263
|
async get(id) {
|
|
264
264
|
const data = await this.http.request("GET", `/orders/${encodeURIComponent(id)}`);
|
|
265
|
-
return this.http.validate(data,
|
|
265
|
+
return this.http.validate(data, __omnixhq_ucp_js_sdk.OrderSchema);
|
|
266
|
+
}
|
|
267
|
+
/** Update an order with fulfillment events, adjustments, or status changes. */
|
|
268
|
+
async update(id, payload) {
|
|
269
|
+
const data = await this.http.request("PUT", `/orders/${encodeURIComponent(id)}`, payload);
|
|
270
|
+
return this.http.validate(data, __omnixhq_ucp_js_sdk.OrderSchema);
|
|
266
271
|
}
|
|
267
272
|
};
|
|
268
273
|
|
|
@@ -344,36 +349,6 @@ function encodeBasicAuth(username, password) {
|
|
|
344
349
|
return `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`;
|
|
345
350
|
}
|
|
346
351
|
|
|
347
|
-
//#endregion
|
|
348
|
-
//#region src/capabilities/products.ts
|
|
349
|
-
/** Product catalog search and retrieval. Always available (gateway-specific, not part of UCP spec). */
|
|
350
|
-
var ProductsCapability = class {
|
|
351
|
-
constructor(http) {
|
|
352
|
-
this.http = http;
|
|
353
|
-
}
|
|
354
|
-
/** Search products by query string with optional filters. */
|
|
355
|
-
async search(query, filters = {}) {
|
|
356
|
-
const params = new URLSearchParams({ q: query });
|
|
357
|
-
const filterEntries = [
|
|
358
|
-
["max_price_cents", filters.max_price_cents],
|
|
359
|
-
["min_price_cents", filters.min_price_cents],
|
|
360
|
-
["in_stock", filters.in_stock],
|
|
361
|
-
["category", filters.category],
|
|
362
|
-
["limit", filters.limit],
|
|
363
|
-
["page", filters.page]
|
|
364
|
-
];
|
|
365
|
-
for (const [key, value] of filterEntries) if (value != null) params.set(key, String(value));
|
|
366
|
-
const res = await this.http.request("GET", `/ucp/products?${params.toString()}`);
|
|
367
|
-
const data = res;
|
|
368
|
-
const products = Array.isArray(data) ? data : data.products ?? [];
|
|
369
|
-
return products.map((p) => this.http.validate(p, UCPProductSchema));
|
|
370
|
-
}
|
|
371
|
-
async get(id) {
|
|
372
|
-
const data = await this.http.request("GET", `/ucp/products/${encodeURIComponent(id)}`);
|
|
373
|
-
return this.http.validate(data, UCPProductSchema);
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
|
|
377
352
|
//#endregion
|
|
378
353
|
//#region src/types/config.ts
|
|
379
354
|
const DEFAULT_UCP_VERSION = "2026-01-23";
|
|
@@ -424,7 +399,7 @@ const UCP_CAPABILITIES = {
|
|
|
424
399
|
* ```
|
|
425
400
|
*/
|
|
426
401
|
function getAgentTools(client) {
|
|
427
|
-
const tools = [
|
|
402
|
+
const tools = [];
|
|
428
403
|
if (client.checkout) {
|
|
429
404
|
tools.push(...checkoutTools(client));
|
|
430
405
|
if (client.checkout.extensions.fulfillment) tools.push(...fulfillmentTools(client));
|
|
@@ -434,58 +409,6 @@ function getAgentTools(client) {
|
|
|
434
409
|
if (client.identityLinking) tools.push(...identityLinkingTools(client));
|
|
435
410
|
return tools;
|
|
436
411
|
}
|
|
437
|
-
function productTools(client) {
|
|
438
|
-
return [{
|
|
439
|
-
name: "search_products",
|
|
440
|
-
description: "Search the product catalog by query string. Returns matching products with prices, availability, and images.",
|
|
441
|
-
parameters: {
|
|
442
|
-
type: "object",
|
|
443
|
-
properties: {
|
|
444
|
-
query: {
|
|
445
|
-
type: "string",
|
|
446
|
-
description: "Search query (e.g., \"running shoes\")"
|
|
447
|
-
},
|
|
448
|
-
max_price_cents: {
|
|
449
|
-
type: "number",
|
|
450
|
-
description: "Maximum price in cents"
|
|
451
|
-
},
|
|
452
|
-
min_price_cents: {
|
|
453
|
-
type: "number",
|
|
454
|
-
description: "Minimum price in cents"
|
|
455
|
-
},
|
|
456
|
-
in_stock: {
|
|
457
|
-
type: "boolean",
|
|
458
|
-
description: "Filter to in-stock items only"
|
|
459
|
-
},
|
|
460
|
-
category: {
|
|
461
|
-
type: "string",
|
|
462
|
-
description: "Product category"
|
|
463
|
-
},
|
|
464
|
-
limit: {
|
|
465
|
-
type: "number",
|
|
466
|
-
description: "Max results to return"
|
|
467
|
-
}
|
|
468
|
-
},
|
|
469
|
-
required: ["query"]
|
|
470
|
-
},
|
|
471
|
-
execute: async (params) => {
|
|
472
|
-
const { query,...filters } = params;
|
|
473
|
-
return client.products.search(query, filters);
|
|
474
|
-
}
|
|
475
|
-
}, {
|
|
476
|
-
name: "get_product",
|
|
477
|
-
description: "Get detailed product information by ID, including variants, images, and stock.",
|
|
478
|
-
parameters: {
|
|
479
|
-
type: "object",
|
|
480
|
-
properties: { id: {
|
|
481
|
-
type: "string",
|
|
482
|
-
description: "Product ID"
|
|
483
|
-
} },
|
|
484
|
-
required: ["id"]
|
|
485
|
-
},
|
|
486
|
-
execute: async (params) => client.products.get(params["id"])
|
|
487
|
-
}];
|
|
488
|
-
}
|
|
489
412
|
function checkoutTools(client) {
|
|
490
413
|
return [
|
|
491
414
|
{
|
|
@@ -769,6 +692,32 @@ function orderTools(client) {
|
|
|
769
692
|
required: ["id"]
|
|
770
693
|
},
|
|
771
694
|
execute: async (params) => client.order.get(params["id"])
|
|
695
|
+
}, {
|
|
696
|
+
name: "update_order",
|
|
697
|
+
description: "Update an order with fulfillment events, adjustments, or status changes.",
|
|
698
|
+
parameters: {
|
|
699
|
+
type: "object",
|
|
700
|
+
properties: {
|
|
701
|
+
id: {
|
|
702
|
+
type: "string",
|
|
703
|
+
description: "Order ID"
|
|
704
|
+
},
|
|
705
|
+
fulfillment: {
|
|
706
|
+
type: "object",
|
|
707
|
+
description: "Fulfillment update data (events, tracking)"
|
|
708
|
+
},
|
|
709
|
+
adjustments: {
|
|
710
|
+
type: "array",
|
|
711
|
+
description: "Order adjustments (refunds, returns)",
|
|
712
|
+
items: { type: "object" }
|
|
713
|
+
}
|
|
714
|
+
},
|
|
715
|
+
required: ["id"]
|
|
716
|
+
},
|
|
717
|
+
execute: async (params) => {
|
|
718
|
+
const { id,...payload } = params;
|
|
719
|
+
return client.order.update(id, payload);
|
|
720
|
+
}
|
|
772
721
|
}];
|
|
773
722
|
}
|
|
774
723
|
function identityLinkingTools(client) {
|
|
@@ -926,14 +875,14 @@ async function connect(config, options) {
|
|
|
926
875
|
const checkout = buildCheckoutCapability(http, capabilityNames);
|
|
927
876
|
const order = capabilityNames.has(UCP_CAPABILITIES.ORDER) ? new OrderCapability(http) : null;
|
|
928
877
|
const identityLinking = await buildIdentityLinking(config, capabilityNames);
|
|
929
|
-
const products = new ProductsCapability(http);
|
|
930
878
|
const paymentHandlers = extractPaymentHandlers(profile);
|
|
879
|
+
const signingKeys = extractSigningKeys(profile);
|
|
931
880
|
const client = {
|
|
932
881
|
profile,
|
|
882
|
+
signingKeys,
|
|
933
883
|
checkout,
|
|
934
884
|
order,
|
|
935
885
|
identityLinking,
|
|
936
|
-
products,
|
|
937
886
|
paymentHandlers,
|
|
938
887
|
describeTools: () => buildToolDescriptors(checkout, order, identityLinking),
|
|
939
888
|
getAgentTools: () => getAgentTools(client)
|
|
@@ -963,8 +912,8 @@ function validateConfig(config) {
|
|
|
963
912
|
}
|
|
964
913
|
function extractCapabilityNames(profile) {
|
|
965
914
|
const capabilities = profile.ucp?.capabilities;
|
|
966
|
-
if (
|
|
967
|
-
return new Set(
|
|
915
|
+
if (typeof capabilities !== "object" || capabilities === null) return new Set();
|
|
916
|
+
return new Set(Object.keys(capabilities));
|
|
968
917
|
}
|
|
969
918
|
const PaymentHandlerInstanceSchema = zod.z.object({
|
|
970
919
|
id: zod.z.string(),
|
|
@@ -981,6 +930,16 @@ function extractPaymentHandlers(profile) {
|
|
|
981
930
|
if (!result.success) return {};
|
|
982
931
|
return result.data;
|
|
983
932
|
}
|
|
933
|
+
function extractSigningKeys(profile) {
|
|
934
|
+
const raw = profile["signing_keys"];
|
|
935
|
+
if (!Array.isArray(raw)) return [];
|
|
936
|
+
const keys = [];
|
|
937
|
+
for (const item of raw) {
|
|
938
|
+
const result = JWKSchema.safeParse(item);
|
|
939
|
+
if (result.success) keys.push(result.data);
|
|
940
|
+
}
|
|
941
|
+
return keys;
|
|
942
|
+
}
|
|
984
943
|
function buildCheckoutCapability(http, capabilityNames) {
|
|
985
944
|
if (!capabilityNames.has(UCP_CAPABILITIES.CHECKOUT)) return null;
|
|
986
945
|
const extensions = {
|
|
@@ -1014,15 +973,7 @@ async function buildIdentityLinking(config, capabilityNames) {
|
|
|
1014
973
|
return new IdentityLinkingCapability(parsed.data);
|
|
1015
974
|
}
|
|
1016
975
|
function buildToolDescriptors(checkout, order, identityLinking) {
|
|
1017
|
-
const tools = [
|
|
1018
|
-
name: "search_products",
|
|
1019
|
-
capability: "products",
|
|
1020
|
-
description: "Search product catalog"
|
|
1021
|
-
}, {
|
|
1022
|
-
name: "get_product",
|
|
1023
|
-
capability: "products",
|
|
1024
|
-
description: "Get product by ID"
|
|
1025
|
-
}];
|
|
976
|
+
const tools = [];
|
|
1026
977
|
if (checkout) {
|
|
1027
978
|
tools.push({
|
|
1028
979
|
name: "create_checkout",
|
|
@@ -1068,6 +1019,10 @@ function buildToolDescriptors(checkout, order, identityLinking) {
|
|
|
1068
1019
|
name: "get_order",
|
|
1069
1020
|
capability: "order",
|
|
1070
1021
|
description: "Get order by ID"
|
|
1022
|
+
}, {
|
|
1023
|
+
name: "update_order",
|
|
1024
|
+
capability: "order",
|
|
1025
|
+
description: "Update an order"
|
|
1071
1026
|
});
|
|
1072
1027
|
if (identityLinking) tools.push({
|
|
1073
1028
|
name: "get_authorization_url",
|
|
@@ -1090,38 +1045,231 @@ function buildToolDescriptors(checkout, order, identityLinking) {
|
|
|
1090
1045
|
}
|
|
1091
1046
|
|
|
1092
1047
|
//#endregion
|
|
1093
|
-
|
|
1048
|
+
//#region src/verify-signature.ts
|
|
1049
|
+
/**
|
|
1050
|
+
* Verifies a `Request-Signature` header (detached JWS per RFC 7797) over a raw request body.
|
|
1051
|
+
*
|
|
1052
|
+
* Per UCP spec, the JWT header MUST include a `kid` claim identifying the signing key.
|
|
1053
|
+
* Returns `false` if `kid` is absent — do not fall back to guessing.
|
|
1054
|
+
*
|
|
1055
|
+
* @returns `true` if the signature is valid, `false` for any verification failure.
|
|
1056
|
+
*/
|
|
1057
|
+
async function verifyRequestSignature(body, signature, signingKeys) {
|
|
1058
|
+
const parts = signature.split(".");
|
|
1059
|
+
if (parts.length !== 3 || parts[1] !== "") return false;
|
|
1060
|
+
const [headerB64, , sigB64] = parts;
|
|
1061
|
+
let header;
|
|
1062
|
+
try {
|
|
1063
|
+
header = JSON.parse(new TextDecoder().decode(base64urlDecode(headerB64)));
|
|
1064
|
+
} catch {
|
|
1065
|
+
return false;
|
|
1066
|
+
}
|
|
1067
|
+
if (typeof header["alg"] !== "undefined" && header["alg"] !== "ES256") return false;
|
|
1068
|
+
if (typeof header["kid"] !== "string") return false;
|
|
1069
|
+
const kid = header["kid"];
|
|
1070
|
+
const key = signingKeys.find((k) => k.kid === kid);
|
|
1071
|
+
if (!key) return false;
|
|
1072
|
+
let cryptoKey;
|
|
1073
|
+
try {
|
|
1074
|
+
cryptoKey = await crypto.subtle.importKey("jwk", key, {
|
|
1075
|
+
name: "ECDSA",
|
|
1076
|
+
namedCurve: "P-256"
|
|
1077
|
+
}, false, ["verify"]);
|
|
1078
|
+
} catch {
|
|
1079
|
+
return false;
|
|
1080
|
+
}
|
|
1081
|
+
let sigBytes;
|
|
1082
|
+
try {
|
|
1083
|
+
sigBytes = base64urlDecode(sigB64);
|
|
1084
|
+
} catch {
|
|
1085
|
+
return false;
|
|
1086
|
+
}
|
|
1087
|
+
const signingInput = `${headerB64}.${Buffer.from(body).toString("base64url")}`;
|
|
1088
|
+
try {
|
|
1089
|
+
return await crypto.subtle.verify({
|
|
1090
|
+
name: "ECDSA",
|
|
1091
|
+
hash: "SHA-256"
|
|
1092
|
+
}, cryptoKey, sigBytes, new TextEncoder().encode(signingInput));
|
|
1093
|
+
} catch {
|
|
1094
|
+
return false;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Creates a {@link WebhookVerifier} bound to a specific business's UCP gateway.
|
|
1099
|
+
*
|
|
1100
|
+
* Signing keys are lazily loaded from `<gatewayUrl>/.well-known/ucp` on the first call
|
|
1101
|
+
* and cached by `kid`. A cache miss triggers a re-fetch to support key rotation.
|
|
1102
|
+
*
|
|
1103
|
+
* @example
|
|
1104
|
+
* ```typescript
|
|
1105
|
+
* import { createWebhookVerifier } from '@omnixhq/ucp-client';
|
|
1106
|
+
*
|
|
1107
|
+
* const verifier = createWebhookVerifier('https://store.example.com');
|
|
1108
|
+
*
|
|
1109
|
+
* // In your webhook handler:
|
|
1110
|
+
* const valid = await verifier.verify(rawBody, req.headers['request-signature']);
|
|
1111
|
+
* if (!valid) return res.status(401).send('Invalid signature');
|
|
1112
|
+
* ```
|
|
1113
|
+
*/
|
|
1114
|
+
function createWebhookVerifier(gatewayUrl) {
|
|
1115
|
+
const baseUrl = gatewayUrl.replace(/\/+$/, "");
|
|
1116
|
+
const keyCache = new Map();
|
|
1117
|
+
let fetched = false;
|
|
1118
|
+
async function loadKeys() {
|
|
1119
|
+
const res = await fetch(`${baseUrl}/.well-known/ucp`);
|
|
1120
|
+
if (!res.ok) return;
|
|
1121
|
+
const profile = await res.json();
|
|
1122
|
+
const rawKeys = profile["signing_keys"];
|
|
1123
|
+
if (!Array.isArray(rawKeys)) return;
|
|
1124
|
+
keyCache.clear();
|
|
1125
|
+
for (const item of rawKeys) {
|
|
1126
|
+
const parsed = JWKSchema.safeParse(item);
|
|
1127
|
+
if (parsed.success && typeof parsed.data.kid === "string") keyCache.set(parsed.data.kid, parsed.data);
|
|
1128
|
+
}
|
|
1129
|
+
fetched = true;
|
|
1130
|
+
}
|
|
1131
|
+
return { async verify(body, signature) {
|
|
1132
|
+
const kid = extractKid(signature);
|
|
1133
|
+
if (kid === null) return false;
|
|
1134
|
+
if (!fetched) await loadKeys();
|
|
1135
|
+
if (!keyCache.has(kid)) await loadKeys();
|
|
1136
|
+
const key = keyCache.get(kid);
|
|
1137
|
+
if (!key) return false;
|
|
1138
|
+
return verifyRequestSignature(body, signature, [key]);
|
|
1139
|
+
} };
|
|
1140
|
+
}
|
|
1141
|
+
/** Extracts the `kid` from a detached JWS header without full verification. */
|
|
1142
|
+
function extractKid(signature) {
|
|
1143
|
+
const parts = signature.split(".");
|
|
1144
|
+
if (parts.length !== 3 || parts[1] !== "") return null;
|
|
1145
|
+
try {
|
|
1146
|
+
const header = JSON.parse(new TextDecoder().decode(base64urlDecode(parts[0])));
|
|
1147
|
+
return typeof header["kid"] === "string" ? header["kid"] : null;
|
|
1148
|
+
} catch {
|
|
1149
|
+
return null;
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
function base64urlDecode(b64url) {
|
|
1153
|
+
const b64 = b64url.replace(/-/g, "+").replace(/_/g, "/");
|
|
1154
|
+
const padded = b64 + "=".repeat((4 - b64.length % 4) % 4);
|
|
1155
|
+
const binaryStr = atob(padded);
|
|
1156
|
+
const result = new Uint8Array(binaryStr.length);
|
|
1157
|
+
for (let i = 0; i < binaryStr.length; i++) result[i] = binaryStr.charCodeAt(i);
|
|
1158
|
+
return result;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
//#endregion
|
|
1162
|
+
exports.AccountInfoSchema = __omnixhq_ucp_js_sdk.AccountInfoSchema
|
|
1163
|
+
exports.AdjustmentSchema = __omnixhq_ucp_js_sdk.AdjustmentSchema
|
|
1164
|
+
exports.Ap2MandateAp2WithCheckoutMandateSchema = __omnixhq_ucp_js_sdk.Ap2MandateAp2WithCheckoutMandateSchema
|
|
1165
|
+
exports.Ap2MandateAp2WithMerchantAuthorizationSchema = __omnixhq_ucp_js_sdk.Ap2MandateAp2WithMerchantAuthorizationSchema
|
|
1166
|
+
exports.Ap2MandateCheckoutMandateSchema = __omnixhq_ucp_js_sdk.Ap2MandateCheckoutMandateSchema
|
|
1167
|
+
exports.Ap2MandateErrorCodeSchema = __omnixhq_ucp_js_sdk.Ap2MandateErrorCodeSchema
|
|
1168
|
+
exports.Ap2MandateMerchantAuthorizationSchema = __omnixhq_ucp_js_sdk.Ap2MandateMerchantAuthorizationSchema
|
|
1169
|
+
exports.BindingSchema = __omnixhq_ucp_js_sdk.BindingSchema
|
|
1170
|
+
exports.BusinessFulfillmentConfigSchema = __omnixhq_ucp_js_sdk.BusinessFulfillmentConfigSchema
|
|
1171
|
+
exports.BuyerConsentBuyerSchema = __omnixhq_ucp_js_sdk.BuyerConsentBuyerSchema
|
|
1172
|
+
exports.BuyerConsentConsentSchema = __omnixhq_ucp_js_sdk.BuyerConsentConsentSchema
|
|
1173
|
+
exports.BuyerSchema = __omnixhq_ucp_js_sdk.BuyerSchema
|
|
1174
|
+
exports.CapabilityBaseSchema = __omnixhq_ucp_js_sdk.CapabilityBaseSchema
|
|
1175
|
+
exports.CapabilityBusinessSchema = __omnixhq_ucp_js_sdk.CapabilityBusinessSchema
|
|
1176
|
+
exports.CapabilityPlatformSchema = __omnixhq_ucp_js_sdk.CapabilityPlatformSchema
|
|
1177
|
+
exports.CapabilityResponseSchema = __omnixhq_ucp_js_sdk.CapabilityResponseSchema
|
|
1178
|
+
exports.CardCredentialSchema = __omnixhq_ucp_js_sdk.CardCredentialSchema
|
|
1179
|
+
exports.CardPaymentInstrumentSchema = __omnixhq_ucp_js_sdk.CardPaymentInstrumentSchema
|
|
1094
1180
|
exports.CheckoutCapability = CheckoutCapability
|
|
1095
|
-
exports.
|
|
1181
|
+
exports.CheckoutCompleteRequestSchema = __omnixhq_ucp_js_sdk.CheckoutCompleteRequestSchema
|
|
1182
|
+
exports.CheckoutCreateRequestSchema = __omnixhq_ucp_js_sdk.CheckoutCreateRequestSchema
|
|
1183
|
+
exports.CheckoutResponseSchema = __omnixhq_ucp_js_sdk.CheckoutResponseSchema
|
|
1184
|
+
exports.CheckoutResponseStatusSchema = __omnixhq_ucp_js_sdk.CheckoutResponseStatusSchema
|
|
1185
|
+
exports.CheckoutSchema = __omnixhq_ucp_js_sdk.CheckoutSchema
|
|
1096
1186
|
exports.CheckoutSessionSchema = CheckoutSessionSchema
|
|
1187
|
+
exports.CheckoutUpdateRequestSchema = __omnixhq_ucp_js_sdk.CheckoutUpdateRequestSchema
|
|
1097
1188
|
exports.CompleteCheckoutRequestSchema = CompleteCheckoutRequestSchema
|
|
1189
|
+
exports.ContextSchema = __omnixhq_ucp_js_sdk.ContextSchema
|
|
1098
1190
|
exports.CreateCheckoutRequestSchema = CreateCheckoutRequestSchema
|
|
1099
1191
|
exports.DEFAULT_UCP_VERSION = DEFAULT_UCP_VERSION
|
|
1100
|
-
exports.
|
|
1101
|
-
exports.
|
|
1192
|
+
exports.DiscountAllocationSchema = __omnixhq_ucp_js_sdk.DiscountAllocationSchema
|
|
1193
|
+
exports.DiscountAppliedDiscountSchema = __omnixhq_ucp_js_sdk.DiscountAppliedDiscountSchema
|
|
1194
|
+
exports.DiscountDiscountsObjectSchema = __omnixhq_ucp_js_sdk.DiscountDiscountsObjectSchema
|
|
1195
|
+
exports.EmbeddedConfigSchema = __omnixhq_ucp_js_sdk.EmbeddedConfigSchema
|
|
1196
|
+
exports.ExpectationSchema = __omnixhq_ucp_js_sdk.ExpectationSchema
|
|
1197
|
+
exports.ExtendedPaymentCredentialSchema = __omnixhq_ucp_js_sdk.ExtendedPaymentCredentialSchema
|
|
1198
|
+
exports.FulfillmentAvailableMethodSchema = __omnixhq_ucp_js_sdk.FulfillmentAvailableMethodSchema
|
|
1199
|
+
exports.FulfillmentDestinationSchema = __omnixhq_ucp_js_sdk.FulfillmentDestinationSchema
|
|
1200
|
+
exports.FulfillmentEventSchema = __omnixhq_ucp_js_sdk.FulfillmentEventSchema
|
|
1201
|
+
exports.FulfillmentExtensionFulfillmentAvailableMethodSchema = __omnixhq_ucp_js_sdk.FulfillmentExtensionFulfillmentAvailableMethodSchema
|
|
1202
|
+
exports.FulfillmentExtensionFulfillmentGroupSchema = __omnixhq_ucp_js_sdk.FulfillmentExtensionFulfillmentGroupSchema
|
|
1203
|
+
exports.FulfillmentExtensionFulfillmentMethodSchema = __omnixhq_ucp_js_sdk.FulfillmentExtensionFulfillmentMethodSchema
|
|
1204
|
+
exports.FulfillmentExtensionFulfillmentOptionSchema = __omnixhq_ucp_js_sdk.FulfillmentExtensionFulfillmentOptionSchema
|
|
1205
|
+
exports.FulfillmentExtensionFulfillmentSchema = __omnixhq_ucp_js_sdk.FulfillmentExtensionFulfillmentSchema
|
|
1206
|
+
exports.FulfillmentGroupSchema = __omnixhq_ucp_js_sdk.FulfillmentGroupSchema
|
|
1207
|
+
exports.FulfillmentGroupUpdateRequestSchema = __omnixhq_ucp_js_sdk.FulfillmentGroupUpdateRequestSchema
|
|
1208
|
+
exports.FulfillmentMethodCreateRequestSchema = __omnixhq_ucp_js_sdk.FulfillmentMethodCreateRequestSchema
|
|
1209
|
+
exports.FulfillmentMethodResponseSchema = __omnixhq_ucp_js_sdk.FulfillmentMethodResponseSchema
|
|
1210
|
+
exports.FulfillmentMethodSchema = __omnixhq_ucp_js_sdk.FulfillmentMethodSchema
|
|
1211
|
+
exports.FulfillmentMethodUpdateRequestSchema = __omnixhq_ucp_js_sdk.FulfillmentMethodUpdateRequestSchema
|
|
1212
|
+
exports.FulfillmentOptionSchema = __omnixhq_ucp_js_sdk.FulfillmentOptionSchema
|
|
1213
|
+
exports.FulfillmentResponseSchema = __omnixhq_ucp_js_sdk.FulfillmentResponseSchema
|
|
1214
|
+
exports.FulfillmentSchema = __omnixhq_ucp_js_sdk.FulfillmentSchema
|
|
1102
1215
|
exports.IdentityLinkingCapability = IdentityLinkingCapability
|
|
1103
|
-
exports.ItemResponseSchema =
|
|
1104
|
-
exports.
|
|
1105
|
-
exports.
|
|
1106
|
-
exports.
|
|
1216
|
+
exports.ItemResponseSchema = __omnixhq_ucp_js_sdk.ItemResponseSchema
|
|
1217
|
+
exports.ItemSchema = __omnixhq_ucp_js_sdk.ItemSchema
|
|
1218
|
+
exports.JWKSchema = JWKSchema
|
|
1219
|
+
exports.LineItemResponseSchema = __omnixhq_ucp_js_sdk.LineItemResponseSchema
|
|
1220
|
+
exports.LineItemSchema = __omnixhq_ucp_js_sdk.LineItemSchema
|
|
1221
|
+
exports.LineItemUpdateRequestSchema = __omnixhq_ucp_js_sdk.LineItemUpdateRequestSchema
|
|
1222
|
+
exports.LinkSchema = __omnixhq_ucp_js_sdk.LinkSchema
|
|
1223
|
+
exports.MerchantFulfillmentConfigSchema = __omnixhq_ucp_js_sdk.MerchantFulfillmentConfigSchema
|
|
1224
|
+
exports.MessageErrorSchema = __omnixhq_ucp_js_sdk.MessageErrorSchema
|
|
1225
|
+
exports.MessageInfoSchema = __omnixhq_ucp_js_sdk.MessageInfoSchema
|
|
1226
|
+
exports.MessageSchema = __omnixhq_ucp_js_sdk.MessageSchema
|
|
1227
|
+
exports.MessageWarningSchema = __omnixhq_ucp_js_sdk.MessageWarningSchema
|
|
1107
1228
|
exports.OrderCapability = OrderCapability
|
|
1108
|
-
exports.
|
|
1109
|
-
exports.
|
|
1110
|
-
exports.
|
|
1111
|
-
exports.
|
|
1112
|
-
exports.
|
|
1113
|
-
exports.
|
|
1229
|
+
exports.OrderConfirmationSchema = __omnixhq_ucp_js_sdk.OrderConfirmationSchema
|
|
1230
|
+
exports.OrderLineItemSchema = __omnixhq_ucp_js_sdk.OrderLineItemSchema
|
|
1231
|
+
exports.OrderUpdateSchema = __omnixhq_ucp_js_sdk.OrderUpdateSchema
|
|
1232
|
+
exports.PaymentCredentialSchema = __omnixhq_ucp_js_sdk.PaymentCredentialSchema
|
|
1233
|
+
exports.PaymentHandlerBaseSchema = __omnixhq_ucp_js_sdk.PaymentHandlerBaseSchema
|
|
1234
|
+
exports.PaymentHandlerBusinessSchema = __omnixhq_ucp_js_sdk.PaymentHandlerBusinessSchema
|
|
1235
|
+
exports.PaymentHandlerPlatformSchema = __omnixhq_ucp_js_sdk.PaymentHandlerPlatformSchema
|
|
1236
|
+
exports.PaymentHandlerResponseSchema = __omnixhq_ucp_js_sdk.PaymentHandlerResponseSchema
|
|
1237
|
+
exports.PaymentIdentitySchema = __omnixhq_ucp_js_sdk.PaymentIdentitySchema
|
|
1238
|
+
exports.PaymentInstrumentResponseSchema = __omnixhq_ucp_js_sdk.PaymentInstrumentResponseSchema
|
|
1239
|
+
exports.PaymentInstrumentSchema = __omnixhq_ucp_js_sdk.PaymentInstrumentSchema
|
|
1240
|
+
exports.PaymentResponseSchema = __omnixhq_ucp_js_sdk.PaymentResponseSchema
|
|
1241
|
+
exports.PaymentSchema = __omnixhq_ucp_js_sdk.PaymentSchema
|
|
1242
|
+
exports.PlatformConfigSchema = __omnixhq_ucp_js_sdk.PlatformConfigSchema
|
|
1243
|
+
exports.PlatformFulfillmentConfigSchema = __omnixhq_ucp_js_sdk.PlatformFulfillmentConfigSchema
|
|
1244
|
+
exports.PostalAddressSchema = __omnixhq_ucp_js_sdk.PostalAddressSchema
|
|
1245
|
+
exports.RetailLocationSchema = __omnixhq_ucp_js_sdk.RetailLocationSchema
|
|
1246
|
+
exports.ServiceBaseSchema = __omnixhq_ucp_js_sdk.ServiceBaseSchema
|
|
1247
|
+
exports.ServiceBusinessSchema = __omnixhq_ucp_js_sdk.ServiceBusinessSchema
|
|
1248
|
+
exports.ServicePlatformSchema = __omnixhq_ucp_js_sdk.ServicePlatformSchema
|
|
1249
|
+
exports.ServiceResponseSchema = __omnixhq_ucp_js_sdk.ServiceResponseSchema
|
|
1250
|
+
exports.ShippingDestinationSchema = __omnixhq_ucp_js_sdk.ShippingDestinationSchema
|
|
1251
|
+
exports.TokenCredentialSchema = __omnixhq_ucp_js_sdk.TokenCredentialSchema
|
|
1252
|
+
exports.TotalResponseSchema = __omnixhq_ucp_js_sdk.TotalResponseSchema
|
|
1253
|
+
exports.TotalSchema = __omnixhq_ucp_js_sdk.TotalSchema
|
|
1114
1254
|
exports.UCPClient = UCPClient
|
|
1115
1255
|
exports.UCPError = require_errors.UCPError
|
|
1116
1256
|
exports.UCPEscalationError = require_errors.UCPEscalationError
|
|
1117
1257
|
exports.UCPIdempotencyConflictError = require_errors.UCPIdempotencyConflictError
|
|
1118
1258
|
exports.UCPOAuthError = require_errors.UCPOAuthError
|
|
1119
|
-
exports.UCPOrderSchema = UCPOrderSchema
|
|
1120
|
-
exports.UCPProductSchema = UCPProductSchema
|
|
1121
1259
|
exports.UCPProfileSchema = UCPProfileSchema
|
|
1122
|
-
exports.UCPSpecOrderSchema =
|
|
1260
|
+
exports.UCPSpecOrderSchema = __omnixhq_ucp_js_sdk.OrderSchema
|
|
1123
1261
|
exports.UCP_CAPABILITIES = UCP_CAPABILITIES
|
|
1262
|
+
exports.UcpBaseSchema = __omnixhq_ucp_js_sdk.UcpBaseSchema
|
|
1263
|
+
exports.UcpBusinessSchema = __omnixhq_ucp_js_sdk.UcpBusinessSchema
|
|
1264
|
+
exports.UcpEntitySchema = __omnixhq_ucp_js_sdk.UcpEntitySchema
|
|
1265
|
+
exports.UcpPlatformSchema = __omnixhq_ucp_js_sdk.UcpPlatformSchema
|
|
1266
|
+
exports.UcpResponseCheckoutSchema = __omnixhq_ucp_js_sdk.UcpResponseCheckoutSchema
|
|
1267
|
+
exports.UcpResponseOrderSchema = __omnixhq_ucp_js_sdk.UcpResponseOrderSchema
|
|
1268
|
+
exports.UcpReverseDomainNameSchema = __omnixhq_ucp_js_sdk.UcpReverseDomainNameSchema
|
|
1269
|
+
exports.UcpVersionSchema = __omnixhq_ucp_js_sdk.UcpVersionSchema
|
|
1124
1270
|
exports.UpdateCheckoutRequestSchema = UpdateCheckoutRequestSchema
|
|
1125
1271
|
exports.connect = connect
|
|
1272
|
+
exports.createWebhookVerifier = createWebhookVerifier
|
|
1126
1273
|
exports.getAgentTools = getAgentTools
|
|
1274
|
+
exports.verifyRequestSignature = verifyRequestSignature
|
|
1127
1275
|
//# sourceMappingURL=index.cjs.map
|