forked from Universal-Commerce-Protocol/js-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextensions.ts
More file actions
75 lines (68 loc) · 2.5 KB
/
extensions.ts
File metadata and controls
75 lines (68 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { z } from "zod";
import {
CheckoutCreateRequestSchema,
CheckoutResponseSchema,
CheckoutUpdateRequestSchema,
CheckoutWithBuyerConsentCreateRequestSchema,
CheckoutWithBuyerConsentResponseSchema,
CheckoutWithBuyerConsentUpdateRequestSchema,
CheckoutWithDiscountCreateRequestSchema,
CheckoutWithDiscountResponseSchema,
CheckoutWithDiscountUpdateRequestSchema,
CheckoutWithFulfillmentCreateRequestSchema,
CheckoutWithFulfillmentResponseSchema,
CheckoutWithFulfillmentUpdateRequestSchema,
OrderSchema,
PaymentCredentialSchema,
} from "./spec_generated";
export const ExtendedPaymentCredentialSchema = PaymentCredentialSchema.extend({
token: z.string().optional(),
});
export type ExtendedPaymentCredential = z.infer<
typeof ExtendedPaymentCredentialSchema
>;
export const PlatformConfigSchema = z.object({
webhook_url: z.string().url().optional(),
});
export type PlatformConfig = z.infer<typeof PlatformConfigSchema>;
export const ExtendedCheckoutResponseSchema = CheckoutResponseSchema.extend(
CheckoutWithFulfillmentResponseSchema.pick({ fulfillment: true }).shape
)
.extend(CheckoutWithDiscountResponseSchema.pick({ discounts: true }).shape)
.extend(CheckoutWithBuyerConsentResponseSchema.pick({ buyer: true }).shape)
.extend({
order_id: z.string().optional(),
order_permalink_url: z.string().optional(),
platform: PlatformConfigSchema.optional(),
});
export type ExtendedCheckoutResponse = z.infer<
typeof ExtendedCheckoutResponseSchema
>;
export const ExtendedCheckoutCreateRequestSchema =
CheckoutCreateRequestSchema.extend(
CheckoutWithFulfillmentCreateRequestSchema.pick({ fulfillment: true }).shape
)
.extend(
CheckoutWithDiscountCreateRequestSchema.pick({ discounts: true }).shape
)
.extend(
CheckoutWithBuyerConsentCreateRequestSchema.pick({ buyer: true }).shape
);
export type ExtendedCheckoutCreateRequest = z.infer<
typeof ExtendedCheckoutCreateRequestSchema
>;
export const ExtendedCheckoutUpdateRequestSchema =
CheckoutUpdateRequestSchema.extend(
CheckoutWithFulfillmentUpdateRequestSchema.pick({ fulfillment: true }).shape
)
.extend(
CheckoutWithDiscountUpdateRequestSchema.pick({ discounts: true }).shape
)
.extend(
CheckoutWithBuyerConsentUpdateRequestSchema.pick({ buyer: true }).shape
);
export type ExtendedCheckoutUpdateRequest = z.infer<
typeof ExtendedCheckoutUpdateRequestSchema
>;
export const OrderUpdateSchema = OrderSchema;
export type OrderUpdate = z.infer<typeof OrderUpdateSchema>;