@reactionary/core 0.0.41 → 0.0.42
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/index.js +3 -26
- package/package.json +1 -1
- package/providers/cart-payment.provider.js +9 -0
- package/providers/cart.provider.js +6 -0
- package/providers/index.js +10 -0
- package/providers/price.provider.js +1 -1
- package/providers/product.provider.js +10 -0
- package/schemas/capabilities.schema.js +1 -0
- package/schemas/models/cart.model.js +9 -2
- package/schemas/models/identifiers.model.js +30 -0
- package/schemas/models/identity.model.js +17 -2
- package/schemas/models/index.js +14 -0
- package/schemas/models/payment.model.js +37 -0
- package/schemas/models/profile.model.js +29 -0
- package/schemas/models/shipping-method.model.js +15 -0
- package/schemas/mutations/cart-payment.mutation.js +15 -0
- package/schemas/mutations/cart.mutation.js +52 -3
- package/schemas/mutations/index.js +9 -0
- package/schemas/queries/cart-payment.query.js +11 -0
- package/schemas/queries/index.js +1 -0
- package/src/client/client.d.ts +2 -0
- package/src/index.d.ts +3 -26
- package/src/providers/cart-payment.provider.d.ts +42 -0
- package/src/providers/cart.provider.d.ts +100 -1
- package/src/providers/index.d.ts +10 -0
- package/src/providers/price.provider.d.ts +1 -1
- package/src/providers/product.provider.d.ts +6 -1
- package/src/schemas/capabilities.schema.d.ts +1 -0
- package/src/schemas/models/cart.model.d.ts +237 -2
- package/src/schemas/models/identifiers.model.d.ts +31 -1
- package/src/schemas/models/identity.model.d.ts +19 -1
- package/src/schemas/models/index.d.ts +14 -0
- package/src/schemas/models/payment.model.d.ts +692 -0
- package/src/schemas/models/profile.model.d.ts +66 -0
- package/src/schemas/models/shipping-method.model.d.ts +201 -0
- package/src/schemas/mutations/cart-payment.mutation.d.ts +213 -0
- package/src/schemas/mutations/cart.mutation.d.ts +463 -2
- package/src/schemas/mutations/index.d.ts +9 -0
- package/src/schemas/queries/cart-payment.query.d.ts +16 -0
- package/src/schemas/queries/index.d.ts +1 -0
- package/src/schemas/session.schema.d.ts +13 -1
package/index.js
CHANGED
|
@@ -5,32 +5,9 @@ export * from "./cache/noop-cache";
|
|
|
5
5
|
export * from "./client/client";
|
|
6
6
|
export * from "./client/client-builder";
|
|
7
7
|
export * from "./decorators/reactionary.decorator";
|
|
8
|
-
export * from "./providers/
|
|
9
|
-
export * from "./providers/base.provider";
|
|
10
|
-
export * from "./providers/cart.provider";
|
|
11
|
-
export * from "./providers/identity.provider";
|
|
12
|
-
export * from "./providers/inventory.provider";
|
|
13
|
-
export * from "./providers/price.provider";
|
|
14
|
-
export * from "./providers/product.provider";
|
|
15
|
-
export * from "./providers/search.provider";
|
|
16
|
-
export * from "./providers/category.provider";
|
|
8
|
+
export * from "./providers/";
|
|
17
9
|
export * from "./schemas/capabilities.schema";
|
|
18
10
|
export * from "./schemas/session.schema";
|
|
19
|
-
export * from "./schemas/models/
|
|
20
|
-
export * from "./schemas/
|
|
21
|
-
export * from "./schemas/models/currency.model";
|
|
22
|
-
export * from "./schemas/models/identifiers.model";
|
|
23
|
-
export * from "./schemas/models/identity.model";
|
|
24
|
-
export * from "./schemas/models/inventory.model";
|
|
25
|
-
export * from "./schemas/models/price.model";
|
|
26
|
-
export * from "./schemas/models/product.model";
|
|
27
|
-
export * from "./schemas/models/search.model";
|
|
28
|
-
export * from "./schemas/models/category.model";
|
|
29
|
-
export * from "./schemas/mutations/base.mutation";
|
|
30
|
-
export * from "./schemas/mutations/cart.mutation";
|
|
31
|
-
export * from "./schemas/mutations/identity.mutation";
|
|
32
|
-
export * from "./schemas/mutations/inventory.mutation";
|
|
33
|
-
export * from "./schemas/mutations/price.mutation";
|
|
34
|
-
export * from "./schemas/mutations/product.mutation";
|
|
35
|
-
export * from "./schemas/mutations/search.mutation";
|
|
11
|
+
export * from "./schemas/models/";
|
|
12
|
+
export * from "./schemas/mutations/";
|
|
36
13
|
export * from "./schemas/queries";
|
package/package.json
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { BaseProvider } from "./base.provider";
|
|
2
2
|
class CartProvider extends BaseProvider {
|
|
3
|
+
createEmptyCart() {
|
|
4
|
+
const cart = this.newModel();
|
|
5
|
+
cart.meta = { placeholder: true, cache: { hit: true, key: "empty-cart" } };
|
|
6
|
+
cart.identifier = { key: "" };
|
|
7
|
+
return cart;
|
|
8
|
+
}
|
|
3
9
|
getResourceName() {
|
|
4
10
|
return "cart";
|
|
5
11
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./analytics.provider";
|
|
2
|
+
export * from "./base.provider";
|
|
3
|
+
export * from "./cart-payment.provider";
|
|
4
|
+
export * from "./cart.provider";
|
|
5
|
+
export * from "./category.provider";
|
|
6
|
+
export * from "./identity.provider";
|
|
7
|
+
export * from "./inventory.provider";
|
|
8
|
+
export * from "./price.provider";
|
|
9
|
+
export * from "./product.provider";
|
|
10
|
+
export * from "./search.provider";
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { BaseProvider } from "./base.provider";
|
|
2
2
|
class ProductProvider extends BaseProvider {
|
|
3
|
+
createEmptyProduct(id) {
|
|
4
|
+
const product = this.newModel();
|
|
5
|
+
product.identifier = { key: id };
|
|
6
|
+
product.meta.placeholder = true;
|
|
7
|
+
return product;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The resource name, used for caching and logging.
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
3
13
|
getResourceName() {
|
|
4
14
|
return "product";
|
|
5
15
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { CartIdentifierSchema, CartItemIdentifierSchema, ProductIdentifierSchema } from "../models/identifiers.model";
|
|
2
|
+
import { CartIdentifierSchema, CartItemIdentifierSchema, IdentityIdentifierSchema, ProductIdentifierSchema, SKUIdentifierSchema } from "../models/identifiers.model";
|
|
3
3
|
import { BaseModelSchema } from "./base.model";
|
|
4
4
|
import { MonetaryAmountSchema } from "./price.model";
|
|
5
|
+
import { AddressSchema } from "./profile.model";
|
|
6
|
+
import { ShippingMethodSchema } from "./shipping-method.model";
|
|
5
7
|
const CostBreakDownSchema = z.looseObject({
|
|
6
8
|
totalTax: MonetaryAmountSchema.default(() => MonetaryAmountSchema.parse({})).describe("The amount of tax paid on the cart. This may include VAT, GST, sales tax, etc."),
|
|
7
9
|
totalDiscount: MonetaryAmountSchema.default(() => MonetaryAmountSchema.parse({})).describe("The amount of discount applied to the cart."),
|
|
@@ -19,15 +21,20 @@ const ItemCostBreakdownSchema = z.looseObject({
|
|
|
19
21
|
const CartItemSchema = z.looseObject({
|
|
20
22
|
identifier: CartItemIdentifierSchema.default(() => CartItemIdentifierSchema.parse({})),
|
|
21
23
|
product: ProductIdentifierSchema.default(() => ProductIdentifierSchema.parse({})),
|
|
24
|
+
sku: SKUIdentifierSchema.default(() => SKUIdentifierSchema.parse({})),
|
|
22
25
|
quantity: z.number().default(0),
|
|
23
26
|
price: ItemCostBreakdownSchema.default(() => ItemCostBreakdownSchema.parse({}))
|
|
24
27
|
});
|
|
25
28
|
const CartSchema = BaseModelSchema.extend({
|
|
26
29
|
identifier: CartIdentifierSchema.default(() => CartIdentifierSchema.parse({})),
|
|
30
|
+
userId: IdentityIdentifierSchema.default(() => IdentityIdentifierSchema.parse({})),
|
|
27
31
|
items: z.array(CartItemSchema).default(() => []),
|
|
28
32
|
price: CostBreakDownSchema.default(() => CostBreakDownSchema.parse({})),
|
|
29
33
|
name: z.string().default(""),
|
|
30
|
-
description: z.string().default("")
|
|
34
|
+
description: z.string().default(""),
|
|
35
|
+
shippingAddress: AddressSchema.optional(),
|
|
36
|
+
billingAddress: AddressSchema.optional(),
|
|
37
|
+
shippingMethod: ShippingMethodSchema.optional()
|
|
31
38
|
});
|
|
32
39
|
export {
|
|
33
40
|
CartItemSchema,
|
|
@@ -30,6 +30,12 @@ const PriceIdentifierSchema = z.looseObject({
|
|
|
30
30
|
const CategoryIdentifierSchema = z.looseObject({
|
|
31
31
|
key: z.string().default("").nonoptional()
|
|
32
32
|
});
|
|
33
|
+
const OrderIdentifierSchema = z.looseObject({
|
|
34
|
+
key: z.string().default("").nonoptional()
|
|
35
|
+
});
|
|
36
|
+
const OrderItemIdentifierSchema = z.looseObject({
|
|
37
|
+
key: z.string().default("").nonoptional()
|
|
38
|
+
});
|
|
33
39
|
const WebStoreIdentifierSchema = z.looseObject({
|
|
34
40
|
key: z.string().default("").nonoptional()
|
|
35
41
|
});
|
|
@@ -40,17 +46,41 @@ const InventoryIdentifierSchema = z.looseObject({
|
|
|
40
46
|
sku: SKUIdentifierSchema.default(() => SKUIdentifierSchema.parse({})),
|
|
41
47
|
channelId: InventoryChannelIdentifierSchema.default(() => InventoryChannelIdentifierSchema.parse({}))
|
|
42
48
|
});
|
|
49
|
+
const IdentityIdentifierSchema = z.looseObject({
|
|
50
|
+
userId: z.string().default("").nonoptional()
|
|
51
|
+
});
|
|
52
|
+
const ShippingMethodIdentifier = z.looseObject({
|
|
53
|
+
key: z.string().default("").nonoptional()
|
|
54
|
+
});
|
|
55
|
+
const PaymentMethodIdentifierSchema = z.looseObject({
|
|
56
|
+
method: z.string().default("").nonoptional(),
|
|
57
|
+
name: z.string().default("").nonoptional(),
|
|
58
|
+
paymentProcessor: z.string().default("").nonoptional()
|
|
59
|
+
});
|
|
60
|
+
const AddressIdentifierSchema = z.looseObject({
|
|
61
|
+
nickName: z.string().default("").nonoptional()
|
|
62
|
+
});
|
|
63
|
+
const PaymentInstructionIdentifierSchema = z.looseObject({
|
|
64
|
+
key: z.string().default("").nonoptional()
|
|
65
|
+
});
|
|
43
66
|
export {
|
|
67
|
+
AddressIdentifierSchema,
|
|
44
68
|
CartIdentifierSchema,
|
|
45
69
|
CartItemIdentifierSchema,
|
|
46
70
|
CategoryIdentifierSchema,
|
|
47
71
|
FacetIdentifierSchema,
|
|
48
72
|
FacetValueIdentifierSchema,
|
|
73
|
+
IdentityIdentifierSchema,
|
|
49
74
|
InventoryChannelIdentifierSchema,
|
|
50
75
|
InventoryIdentifierSchema,
|
|
76
|
+
OrderIdentifierSchema,
|
|
77
|
+
OrderItemIdentifierSchema,
|
|
78
|
+
PaymentInstructionIdentifierSchema,
|
|
79
|
+
PaymentMethodIdentifierSchema,
|
|
51
80
|
PriceIdentifierSchema,
|
|
52
81
|
ProductIdentifierSchema,
|
|
53
82
|
SKUIdentifierSchema,
|
|
54
83
|
SearchIdentifierSchema,
|
|
84
|
+
ShippingMethodIdentifier,
|
|
55
85
|
WebStoreIdentifierSchema
|
|
56
86
|
};
|
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { BaseModelSchema } from "./base.model";
|
|
3
|
+
import { IdentityIdentifierSchema } from "./identifiers.model";
|
|
3
4
|
const IdentityTypeSchema = z.enum(["Anonymous", "Guest", "Registered"]);
|
|
5
|
+
const ServiceTokenSchema = z.object({
|
|
6
|
+
service: z.string().default(""),
|
|
7
|
+
token: z.string().default(""),
|
|
8
|
+
issued: z.coerce.date().default(/* @__PURE__ */ new Date()),
|
|
9
|
+
expiry: z.coerce.date().default(/* @__PURE__ */ new Date())
|
|
10
|
+
});
|
|
4
11
|
const IdentitySchema = BaseModelSchema.extend({
|
|
5
|
-
id:
|
|
12
|
+
id: IdentityIdentifierSchema.default(() => IdentityIdentifierSchema.parse({})),
|
|
6
13
|
type: IdentityTypeSchema.default("Anonymous"),
|
|
14
|
+
logonId: z.string().default(""),
|
|
15
|
+
createdAt: z.string().default(() => (/* @__PURE__ */ new Date()).toISOString()),
|
|
16
|
+
updatedAt: z.string().default(() => (/* @__PURE__ */ new Date()).toISOString()),
|
|
17
|
+
// Tokens for various services
|
|
18
|
+
keyring: z.array(ServiceTokenSchema).default(() => []),
|
|
19
|
+
// Deprecated - use serviceTokens map instead
|
|
20
|
+
currentService: z.string().optional(),
|
|
7
21
|
token: z.string().optional(),
|
|
8
22
|
issued: z.coerce.date().default(/* @__PURE__ */ new Date()),
|
|
9
23
|
expiry: z.coerce.date().default(/* @__PURE__ */ new Date())
|
|
10
24
|
});
|
|
11
25
|
export {
|
|
12
26
|
IdentitySchema,
|
|
13
|
-
IdentityTypeSchema
|
|
27
|
+
IdentityTypeSchema,
|
|
28
|
+
ServiceTokenSchema
|
|
14
29
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./analytics.model";
|
|
2
|
+
export * from "./base.model";
|
|
3
|
+
export * from "./cart.model";
|
|
4
|
+
export * from "./category.model";
|
|
5
|
+
export * from "./currency.model";
|
|
6
|
+
export * from "./identifiers.model";
|
|
7
|
+
export * from "./identity.model";
|
|
8
|
+
export * from "./inventory.model";
|
|
9
|
+
export * from "./payment.model";
|
|
10
|
+
export * from "./price.model";
|
|
11
|
+
export * from "./product.model";
|
|
12
|
+
export * from "./profile.model";
|
|
13
|
+
export * from "./search.model";
|
|
14
|
+
export * from "./shipping-method.model";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { BaseModelSchema, ImageSchema } from "./base.model";
|
|
3
|
+
import { CartIdentifierSchema, PaymentInstructionIdentifierSchema, PaymentMethodIdentifierSchema } from "./identifiers.model";
|
|
4
|
+
import { MonetaryAmountSchema } from "./price.model";
|
|
5
|
+
const PaymentStatusSchema = z.enum(["pending", "authorized", "canceled", "capture", "partial_capture", "refunded", "partial_refund"]);
|
|
6
|
+
const PaymentProtocolDataSchema = z.looseObject({
|
|
7
|
+
key: z.string().default(""),
|
|
8
|
+
value: z.string().default("")
|
|
9
|
+
});
|
|
10
|
+
const PaymentMethodSchema = BaseModelSchema.extend({
|
|
11
|
+
identifier: PaymentMethodIdentifierSchema.default(() => PaymentMethodIdentifierSchema.parse({})),
|
|
12
|
+
logo: ImageSchema.optional(),
|
|
13
|
+
description: z.string().default(""),
|
|
14
|
+
isPunchOut: z.boolean().default(true)
|
|
15
|
+
});
|
|
16
|
+
const PaymentInstructionSchema = BaseModelSchema.extend({
|
|
17
|
+
identifier: PaymentInstructionIdentifierSchema.default(() => PaymentInstructionIdentifierSchema.parse({})),
|
|
18
|
+
amount: MonetaryAmountSchema.default(() => MonetaryAmountSchema.parse({})),
|
|
19
|
+
paymentMethod: PaymentMethodIdentifierSchema.default(() => PaymentMethodIdentifierSchema.parse({})),
|
|
20
|
+
protocolData: z.array(PaymentProtocolDataSchema).default(() => []).describe("Additional protocol-specific data for processing the payment."),
|
|
21
|
+
status: PaymentStatusSchema.default("pending")
|
|
22
|
+
});
|
|
23
|
+
const CartPaymentInstructionSchema = PaymentInstructionSchema.extend({
|
|
24
|
+
cart: CartIdentifierSchema.default(() => CartIdentifierSchema.parse({}))
|
|
25
|
+
});
|
|
26
|
+
const OrderPaymentInstructionSchema = PaymentInstructionSchema.extend({
|
|
27
|
+
order: z.string().default("")
|
|
28
|
+
// OrderIdentifierSchema
|
|
29
|
+
});
|
|
30
|
+
export {
|
|
31
|
+
CartPaymentInstructionSchema,
|
|
32
|
+
OrderPaymentInstructionSchema,
|
|
33
|
+
PaymentInstructionSchema,
|
|
34
|
+
PaymentMethodSchema,
|
|
35
|
+
PaymentProtocolDataSchema,
|
|
36
|
+
PaymentStatusSchema
|
|
37
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import { AddressIdentifierSchema, IdentityIdentifierSchema } from "./identifiers.model";
|
|
3
|
+
const AddressSchema = z.looseObject({
|
|
4
|
+
identifier: AddressIdentifierSchema.default(() => AddressIdentifierSchema.parse({})),
|
|
5
|
+
firstName: z.string().default(""),
|
|
6
|
+
lastName: z.string().default(""),
|
|
7
|
+
streetAddress: z.string().default(""),
|
|
8
|
+
streetNumber: z.string().default(""),
|
|
9
|
+
city: z.string().default(""),
|
|
10
|
+
region: z.string().default(""),
|
|
11
|
+
postalCode: z.string().default(""),
|
|
12
|
+
countryCode: z.string().default("US")
|
|
13
|
+
});
|
|
14
|
+
const ProfileSchema = z.looseObject({
|
|
15
|
+
identifier: IdentityIdentifierSchema.default(() => IdentityIdentifierSchema.parse({})),
|
|
16
|
+
email: z.string().email().default(""),
|
|
17
|
+
phone: z.string().default(""),
|
|
18
|
+
emailVerified: z.boolean().default(false),
|
|
19
|
+
phoneVerified: z.boolean().default(false),
|
|
20
|
+
createdAt: z.string().default(() => (/* @__PURE__ */ new Date()).toISOString()),
|
|
21
|
+
updatedAt: z.string().default(() => (/* @__PURE__ */ new Date()).toISOString()),
|
|
22
|
+
shippingAddress: AddressSchema.optional(),
|
|
23
|
+
billingAddress: AddressSchema.optional(),
|
|
24
|
+
alternateShippingAddresses: z.array(AddressSchema).default(() => [])
|
|
25
|
+
});
|
|
26
|
+
export {
|
|
27
|
+
AddressSchema,
|
|
28
|
+
ProfileSchema
|
|
29
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import { ShippingMethodIdentifier } from "./identifiers.model";
|
|
3
|
+
import { MonetaryAmountSchema } from "./price.model";
|
|
4
|
+
import { ImageSchema } from "./base.model";
|
|
5
|
+
const ShippingMethodSchema = z.looseObject({
|
|
6
|
+
identifier: ShippingMethodIdentifier.default(() => ShippingMethodIdentifier.parse({})),
|
|
7
|
+
name: z.string().default(""),
|
|
8
|
+
description: z.string().default(""),
|
|
9
|
+
logo: ImageSchema.optional(),
|
|
10
|
+
price: MonetaryAmountSchema.default(() => MonetaryAmountSchema.parse({})),
|
|
11
|
+
deliveryTime: z.string().default("")
|
|
12
|
+
});
|
|
13
|
+
export {
|
|
14
|
+
ShippingMethodSchema
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CartIdentifierSchema, PaymentInstructionIdentifierSchema } from "../models/identifiers.model";
|
|
2
|
+
import { PaymentInstructionSchema } from "../models/payment.model";
|
|
3
|
+
import { BaseMutationSchema } from "./base.mutation";
|
|
4
|
+
const CartPaymentMutationAddPayment = BaseMutationSchema.extend({
|
|
5
|
+
paymentInstruction: PaymentInstructionSchema.omit({ meta: true, status: true, identifier: true }).required(),
|
|
6
|
+
cart: CartIdentifierSchema.required()
|
|
7
|
+
});
|
|
8
|
+
const CartPaymentMutationCancelPayment = BaseMutationSchema.extend({
|
|
9
|
+
paymentInstruction: PaymentInstructionIdentifierSchema.required(),
|
|
10
|
+
cart: CartIdentifierSchema.required()
|
|
11
|
+
});
|
|
12
|
+
export {
|
|
13
|
+
CartPaymentMutationAddPayment,
|
|
14
|
+
CartPaymentMutationCancelPayment
|
|
15
|
+
};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { BaseMutationSchema } from "./base.mutation";
|
|
3
|
-
import { CartIdentifierSchema, CartItemIdentifierSchema,
|
|
3
|
+
import { CartIdentifierSchema, CartItemIdentifierSchema, PaymentMethodIdentifierSchema, ShippingMethodIdentifier, SKUIdentifierSchema } from "../models/identifiers.model";
|
|
4
|
+
import { AddressSchema } from "../models/profile.model";
|
|
5
|
+
import { CurrencySchema } from "../models/currency.model";
|
|
6
|
+
import { MonetaryAmountSchema } from "../models/price.model";
|
|
4
7
|
const CartMutationItemAddSchema = BaseMutationSchema.extend({
|
|
5
8
|
cart: CartIdentifierSchema.nonoptional(),
|
|
6
|
-
|
|
9
|
+
sku: SKUIdentifierSchema.nonoptional(),
|
|
7
10
|
quantity: z.number()
|
|
8
11
|
});
|
|
9
12
|
const CartMutationItemRemoveSchema = BaseMutationSchema.extend({
|
|
@@ -15,8 +18,54 @@ const CartMutationItemQuantityChangeSchema = BaseMutationSchema.extend({
|
|
|
15
18
|
item: CartItemIdentifierSchema.nonoptional(),
|
|
16
19
|
quantity: z.number()
|
|
17
20
|
});
|
|
21
|
+
const CartMutationDeleteCartSchema = BaseMutationSchema.extend({
|
|
22
|
+
cart: CartIdentifierSchema.required()
|
|
23
|
+
});
|
|
24
|
+
const CartMutationSetShippingInfoSchema = BaseMutationSchema.extend({
|
|
25
|
+
cart: CartIdentifierSchema.required(),
|
|
26
|
+
shippingMethod: ShippingMethodIdentifier.optional(),
|
|
27
|
+
shippingAddress: AddressSchema.optional()
|
|
28
|
+
});
|
|
29
|
+
const CartMutationSetBillingAddressSchema = BaseMutationSchema.extend({
|
|
30
|
+
cart: CartIdentifierSchema.required(),
|
|
31
|
+
billingAddress: AddressSchema.required(),
|
|
32
|
+
notificationEmailAddress: z.string().optional(),
|
|
33
|
+
notificationPhoneNumber: z.string().optional()
|
|
34
|
+
});
|
|
35
|
+
const CartMutationApplyCouponSchema = BaseMutationSchema.extend({
|
|
36
|
+
cart: CartIdentifierSchema.required(),
|
|
37
|
+
couponCode: z.string().default("").nonoptional()
|
|
38
|
+
});
|
|
39
|
+
const CartMutationRemoveCouponSchema = BaseMutationSchema.extend({
|
|
40
|
+
cart: CartIdentifierSchema.required(),
|
|
41
|
+
couponCode: z.string().default("").nonoptional()
|
|
42
|
+
});
|
|
43
|
+
const CartMutationCheckoutSchema = BaseMutationSchema.extend({
|
|
44
|
+
cart: CartIdentifierSchema.required()
|
|
45
|
+
});
|
|
46
|
+
const CartMutationAddPaymentMethodSchema = BaseMutationSchema.extend({
|
|
47
|
+
cart: CartIdentifierSchema.required(),
|
|
48
|
+
paymentMethodId: PaymentMethodIdentifierSchema.required(),
|
|
49
|
+
amount: MonetaryAmountSchema.optional().describe("The amount to authorize for the payment method. If not provided, the full remaining balance of the cart will be authorized.")
|
|
50
|
+
});
|
|
51
|
+
const CartMutationRemovePaymentMethodSchema = BaseMutationSchema.extend({
|
|
52
|
+
cart: CartIdentifierSchema.required()
|
|
53
|
+
});
|
|
54
|
+
const CartMutationChangeCurrencySchema = BaseMutationSchema.extend({
|
|
55
|
+
cart: CartIdentifierSchema.required(),
|
|
56
|
+
newCurrency: CurrencySchema.default(() => CurrencySchema.parse({})).describe("The new currency to set for the cart.")
|
|
57
|
+
});
|
|
18
58
|
export {
|
|
59
|
+
CartMutationAddPaymentMethodSchema,
|
|
60
|
+
CartMutationApplyCouponSchema,
|
|
61
|
+
CartMutationChangeCurrencySchema,
|
|
62
|
+
CartMutationCheckoutSchema,
|
|
63
|
+
CartMutationDeleteCartSchema,
|
|
19
64
|
CartMutationItemAddSchema,
|
|
20
65
|
CartMutationItemQuantityChangeSchema,
|
|
21
|
-
CartMutationItemRemoveSchema
|
|
66
|
+
CartMutationItemRemoveSchema,
|
|
67
|
+
CartMutationRemoveCouponSchema,
|
|
68
|
+
CartMutationRemovePaymentMethodSchema,
|
|
69
|
+
CartMutationSetBillingAddressSchema,
|
|
70
|
+
CartMutationSetShippingInfoSchema
|
|
22
71
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./analytics.mutation";
|
|
2
|
+
export * from "./base.mutation";
|
|
3
|
+
export * from "./cart-payment.mutation";
|
|
4
|
+
export * from "./cart.mutation";
|
|
5
|
+
export * from "./identity.mutation";
|
|
6
|
+
export * from "./inventory.mutation";
|
|
7
|
+
export * from "./price.mutation";
|
|
8
|
+
export * from "./product.mutation";
|
|
9
|
+
export * from "./search.mutation";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import { CartIdentifierSchema } from "../models/identifiers.model";
|
|
3
|
+
import { PaymentStatusSchema } from "../models/payment.model";
|
|
4
|
+
import { BaseQuerySchema } from "./base.query";
|
|
5
|
+
const CartPaymentQueryByCartSchema = BaseQuerySchema.extend({
|
|
6
|
+
cart: CartIdentifierSchema.required(),
|
|
7
|
+
status: z.array(PaymentStatusSchema).optional().describe("Optional status to filter payment instructions by")
|
|
8
|
+
});
|
|
9
|
+
export {
|
|
10
|
+
CartPaymentQueryByCartSchema
|
|
11
|
+
};
|
package/schemas/queries/index.js
CHANGED
package/src/client/client.d.ts
CHANGED
|
@@ -7,12 +7,14 @@ import { PriceProvider } from "../providers/price.provider";
|
|
|
7
7
|
import { InventoryProvider } from "../providers/inventory.provider";
|
|
8
8
|
import { Cache } from "../cache/cache.interface";
|
|
9
9
|
import { CategoryProvider } from "../providers/category.provider";
|
|
10
|
+
import { CartPaymentProvider } from "../providers";
|
|
10
11
|
export interface Client {
|
|
11
12
|
product: ProductProvider;
|
|
12
13
|
search: SearchProvider;
|
|
13
14
|
identity: IdentityProvider;
|
|
14
15
|
cache: Cache;
|
|
15
16
|
cart: CartProvider;
|
|
17
|
+
cartPayment: CartPaymentProvider;
|
|
16
18
|
analytics: Array<AnalyticsProvider>;
|
|
17
19
|
price: PriceProvider;
|
|
18
20
|
inventory: InventoryProvider;
|
package/src/index.d.ts
CHANGED
|
@@ -5,32 +5,9 @@ export * from './cache/noop-cache';
|
|
|
5
5
|
export * from './client/client';
|
|
6
6
|
export * from './client/client-builder';
|
|
7
7
|
export * from './decorators/reactionary.decorator';
|
|
8
|
-
export * from './providers/
|
|
9
|
-
export * from './providers/base.provider';
|
|
10
|
-
export * from './providers/cart.provider';
|
|
11
|
-
export * from './providers/identity.provider';
|
|
12
|
-
export * from './providers/inventory.provider';
|
|
13
|
-
export * from './providers/price.provider';
|
|
14
|
-
export * from './providers/product.provider';
|
|
15
|
-
export * from './providers/search.provider';
|
|
16
|
-
export * from './providers/category.provider';
|
|
8
|
+
export * from './providers/';
|
|
17
9
|
export * from './schemas/capabilities.schema';
|
|
18
10
|
export * from './schemas/session.schema';
|
|
19
|
-
export * from './schemas/models/
|
|
20
|
-
export * from './schemas/
|
|
21
|
-
export * from './schemas/models/currency.model';
|
|
22
|
-
export * from './schemas/models/identifiers.model';
|
|
23
|
-
export * from './schemas/models/identity.model';
|
|
24
|
-
export * from './schemas/models/inventory.model';
|
|
25
|
-
export * from './schemas/models/price.model';
|
|
26
|
-
export * from './schemas/models/product.model';
|
|
27
|
-
export * from './schemas/models/search.model';
|
|
28
|
-
export * from './schemas/models/category.model';
|
|
29
|
-
export * from './schemas/mutations/base.mutation';
|
|
30
|
-
export * from './schemas/mutations/cart.mutation';
|
|
31
|
-
export * from './schemas/mutations/identity.mutation';
|
|
32
|
-
export * from './schemas/mutations/inventory.mutation';
|
|
33
|
-
export * from './schemas/mutations/price.mutation';
|
|
34
|
-
export * from './schemas/mutations/product.mutation';
|
|
35
|
-
export * from './schemas/mutations/search.mutation';
|
|
11
|
+
export * from './schemas/models/';
|
|
12
|
+
export * from './schemas/mutations/';
|
|
36
13
|
export * from './schemas/queries';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { CartPaymentInstruction } from '../schemas/models/payment.model';
|
|
2
|
+
import { CartPaymentMutationAddPayment, CartPaymentMutationCancelPayment } from '../schemas/mutations/cart-payment.mutation';
|
|
3
|
+
import { CartPaymentQueryByCart } from '../schemas/queries/cart-payment.query';
|
|
4
|
+
import { Session } from '../schemas/session.schema';
|
|
5
|
+
import { BaseProvider } from './base.provider';
|
|
6
|
+
export declare abstract class CartPaymentProvider<T extends CartPaymentInstruction = CartPaymentInstruction> extends BaseProvider<T> {
|
|
7
|
+
/**
|
|
8
|
+
* Returns all payment instructions associated with a given cart, optionally filtered by status
|
|
9
|
+
*
|
|
10
|
+
* Usecase: Fetch all registered payment instructions to show on checkout page, in case you support multiple payments in your storefront,
|
|
11
|
+
* and need to show how far the user has come in the payment process. Also useful if user reloads page, or goes back to site or otherwise breaks the flow.
|
|
12
|
+
*
|
|
13
|
+
* Only returns payment instructions in status 'pending' or 'authorized'
|
|
14
|
+
* @param cartIdentifier
|
|
15
|
+
* @param session
|
|
16
|
+
*/
|
|
17
|
+
abstract getByCartIdentifier(payload: CartPaymentQueryByCart, session: Session): Promise<T[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Calls payment provider to set up a new payment intent. Returns whatever is needed to continue the payment process, e.g. a client secret for Stripe, or a redirect URL for PayPal.
|
|
20
|
+
*
|
|
21
|
+
* Usecase: User has filled out checkout form, and is ready to pay. You call this to get the payment process started.
|
|
22
|
+
*
|
|
23
|
+
* Note: The payment provider MAY change the cart during the payment process, so be sure to reload the cart object after this call.
|
|
24
|
+
*
|
|
25
|
+
* @param payload
|
|
26
|
+
* @param session
|
|
27
|
+
*/
|
|
28
|
+
abstract initiatePaymentForCart(payload: CartPaymentMutationAddPayment, session: Session): Promise<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Cancel a payment instruction. This will typically void the payment intent in the payment provider, and set the status of the payment instruction to 'canceled'.
|
|
31
|
+
*
|
|
32
|
+
* Usecase: User has decided to cancel the payment, e.g. by going back in the checkout process, or by closing the browser window. You call this to clean up the payment instruction.
|
|
33
|
+
*
|
|
34
|
+
* Note: The payment provider MAY change the cart during the cancellation process, so be sure to reload the cart object after this call.
|
|
35
|
+
*
|
|
36
|
+
* @param payload
|
|
37
|
+
* @param session
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
abstract cancelPaymentInstruction(payload: CartPaymentMutationCancelPayment, session: Session): Promise<T>;
|
|
41
|
+
protected getResourceName(): string;
|
|
42
|
+
}
|