@reactionary/source 0.0.48 → 0.0.52
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/core/package.json +4 -3
- package/core/src/cache/cache.interface.ts +1 -1
- package/core/src/cache/memory-cache.ts +2 -2
- package/core/src/cache/noop-cache.ts +1 -1
- package/core/src/cache/redis-cache.ts +1 -1
- package/core/src/client/client-builder.ts +4 -4
- package/core/src/client/client.ts +12 -12
- package/core/src/decorators/reactionary.decorator.ts +22 -2
- package/core/src/index.ts +14 -14
- package/core/src/initialization.ts +1 -1
- package/core/src/providers/analytics.provider.ts +2 -2
- package/core/src/providers/base.provider.ts +5 -5
- package/core/src/providers/cart.provider.ts +6 -6
- package/core/src/providers/category.provider.ts +4 -9
- package/core/src/providers/checkout.provider.ts +156 -0
- package/core/src/providers/identity.provider.ts +5 -5
- package/core/src/providers/index.ts +13 -12
- package/core/src/providers/inventory.provider.ts +4 -4
- package/core/src/providers/order.provider.ts +31 -0
- package/core/src/providers/price.provider.ts +5 -5
- package/core/src/providers/product.provider.ts +5 -5
- package/core/src/providers/profile.provider.ts +5 -5
- package/core/src/providers/search.provider.ts +4 -4
- package/core/src/providers/store.provider.ts +4 -4
- package/core/src/schemas/capabilities.schema.ts +2 -1
- package/core/src/schemas/models/analytics.model.ts +1 -1
- package/core/src/schemas/models/cart.model.ts +3 -28
- package/core/src/schemas/models/category.model.ts +2 -2
- package/core/src/schemas/models/checkout.model.ts +66 -0
- package/core/src/schemas/models/cost.model.ts +21 -0
- package/core/src/schemas/models/identifiers.model.ts +23 -2
- package/core/src/schemas/models/identity.model.ts +8 -5
- package/core/src/schemas/models/index.ts +19 -15
- package/core/src/schemas/models/inventory.model.ts +2 -2
- package/core/src/schemas/models/order.model.ts +46 -0
- package/core/src/schemas/models/payment.model.ts +5 -12
- package/core/src/schemas/models/price.model.ts +3 -3
- package/core/src/schemas/models/product.model.ts +6 -3
- package/core/src/schemas/models/profile.model.ts +2 -2
- package/core/src/schemas/models/search.model.ts +2 -3
- package/core/src/schemas/models/shipping-method.model.ts +34 -3
- package/core/src/schemas/models/store.model.ts +2 -2
- package/core/src/schemas/mutations/analytics.mutation.ts +2 -2
- package/core/src/schemas/mutations/cart.mutation.ts +5 -5
- package/core/src/schemas/mutations/checkout.mutation.ts +50 -0
- package/core/src/schemas/mutations/identity.mutation.ts +1 -1
- package/core/src/schemas/mutations/index.ts +10 -10
- package/core/src/schemas/mutations/profile.mutation.ts +1 -1
- package/core/src/schemas/queries/cart.query.ts +2 -2
- package/core/src/schemas/queries/category.query.ts +3 -3
- package/core/src/schemas/queries/checkout.query.ts +22 -0
- package/core/src/schemas/queries/identity.query.ts +1 -1
- package/core/src/schemas/queries/index.ts +13 -12
- package/core/src/schemas/queries/inventory.query.ts +2 -2
- package/core/src/schemas/queries/order.query.ts +9 -0
- package/core/src/schemas/queries/price.query.ts +2 -2
- package/core/src/schemas/queries/product.query.ts +9 -2
- package/core/src/schemas/queries/profile.query.ts +1 -1
- package/core/src/schemas/queries/search.query.ts +2 -2
- package/core/src/schemas/queries/store.query.ts +1 -1
- package/core/src/schemas/session.schema.ts +3 -3
- package/core/tsconfig.json +3 -2
- package/examples/next/next.config.js +17 -6
- package/examples/next/src/app/page.tsx +1 -2
- package/examples/node/package.json +2 -1
- package/examples/node/src/basic/basic-node-setup.spec.ts +1 -1
- package/examples/node/tsconfig.json +2 -1
- package/examples/node/tsconfig.spec.json +3 -2
- package/package.json +3 -1
- package/providers/algolia/package.json +2 -1
- package/providers/algolia/src/core/initialize.ts +5 -5
- package/providers/algolia/src/index.ts +5 -5
- package/providers/algolia/src/providers/product.provider.ts +8 -2
- package/providers/algolia/src/providers/search.provider.ts +1 -1
- package/providers/algolia/src/test/search.provider.spec.ts +1 -1
- package/providers/algolia/tsconfig.json +2 -1
- package/providers/algolia/tsconfig.spec.json +3 -2
- package/providers/commercetools/{jest.config.ts → jest.config.cjs} +1 -1
- package/providers/commercetools/package.json +3 -2
- package/providers/commercetools/src/core/client.ts +63 -32
- package/providers/commercetools/src/core/initialize.ts +20 -16
- package/providers/commercetools/src/index.ts +10 -10
- package/providers/commercetools/src/providers/cart.provider.ts +14 -19
- package/providers/commercetools/src/providers/category.provider.ts +3 -12
- package/providers/commercetools/src/providers/checkout.provider.ts +644 -0
- package/providers/commercetools/src/providers/identity.provider.ts +8 -8
- package/providers/commercetools/src/providers/index.ts +12 -9
- package/providers/commercetools/src/providers/inventory.provider.ts +2 -4
- package/providers/commercetools/src/providers/order.provider.ts +163 -0
- package/providers/commercetools/src/providers/price.provider.ts +3 -3
- package/providers/commercetools/src/providers/product.provider.ts +24 -6
- package/providers/commercetools/src/providers/profile.provider.ts +2 -2
- package/providers/commercetools/src/providers/search.provider.ts +3 -5
- package/providers/commercetools/src/providers/store.provider.ts +3 -3
- package/providers/commercetools/src/schema/capabilities.schema.ts +2 -1
- package/providers/commercetools/src/schema/commercetools.schema.ts +7 -5
- package/providers/commercetools/src/schema/configuration.schema.ts +2 -0
- package/providers/commercetools/src/test/cart.provider.spec.ts +24 -4
- package/providers/commercetools/src/test/category.provider.spec.ts +3 -3
- package/providers/commercetools/src/test/checkout.provider.spec.ts +312 -0
- package/providers/commercetools/src/test/identity.provider.spec.ts +3 -3
- package/providers/commercetools/src/test/inventory.provider.spec.ts +2 -2
- package/providers/commercetools/src/test/price.provider.spec.ts +4 -4
- package/providers/commercetools/src/test/product.provider.spec.ts +22 -5
- package/providers/commercetools/src/test/profile.provider.spec.ts +3 -3
- package/providers/commercetools/src/test/search.provider.spec.ts +2 -2
- package/providers/commercetools/src/test/store.provider.spec.ts +2 -2
- package/providers/commercetools/src/test/test-utils.ts +14 -0
- package/providers/commercetools/tsconfig.json +2 -1
- package/providers/commercetools/tsconfig.spec.json +4 -3
- package/providers/fake/{jest.config.ts → jest.config.cjs} +1 -1
- package/providers/fake/package.json +2 -2
- package/providers/fake/src/core/initialize.ts +6 -6
- package/providers/fake/src/index.ts +4 -4
- package/providers/fake/src/providers/analytics.provider.ts +1 -1
- package/providers/fake/src/providers/cart.provider.ts +2 -2
- package/providers/fake/src/providers/category.provider.ts +7 -3
- package/providers/fake/src/providers/identity.provider.ts +1 -1
- package/providers/fake/src/providers/index.ts +9 -9
- package/providers/fake/src/providers/inventory.provider.ts +1 -1
- package/providers/fake/src/providers/price.provider.ts +1 -1
- package/providers/fake/src/providers/product.provider.ts +10 -4
- package/providers/fake/src/providers/search.provider.ts +2 -5
- package/providers/fake/src/providers/store.provider.ts +2 -3
- package/providers/fake/src/test/cart.provider.spec.ts +3 -3
- package/providers/fake/src/test/category.provider.spec.ts +2 -2
- package/providers/fake/src/test/price.provider.spec.ts +2 -2
- package/providers/fake/src/test/product.provider.spec.ts +8 -8
- package/providers/fake/src/test/test-utils.ts +1 -1
- package/providers/fake/tsconfig.json +2 -1
- package/providers/fake/tsconfig.spec.json +1 -3
- package/providers/posthog/package.json +4 -4
- package/providers/posthog/project.json +2 -2
- package/providers/posthog/src/core/initialize.ts +2 -2
- package/providers/posthog/src/index.ts +3 -3
- package/providers/posthog/tsconfig.json +2 -1
- package/tsconfig.base.json +3 -4
- package/.claude/settings.local.json +0 -28
- package/core/src/providers/cart-payment.provider.ts +0 -57
- package/core/src/schemas/mutations/cart-payment.mutation.ts +0 -21
- package/core/src/schemas/queries/cart-payment.query.ts +0 -12
- package/otel/README.md +0 -227
- package/otel/eslint.config.mjs +0 -23
- package/otel/package.json +0 -11
- package/otel/pnpm-lock.yaml +0 -805
- package/otel/project.json +0 -33
- package/otel/src/index.ts +0 -22
- package/otel/src/metrics.ts +0 -76
- package/otel/src/provider-instrumentation.ts +0 -108
- package/otel/src/test/otel.spec.ts +0 -8
- package/otel/src/trace-decorator.ts +0 -226
- package/otel/src/tracer.ts +0 -83
- package/otel/src/trpc-middleware.ts +0 -128
- package/otel/tsconfig.json +0 -23
- package/otel/tsconfig.lib.json +0 -23
- package/otel/tsconfig.spec.json +0 -28
- package/otel/vite.config.ts +0 -24
- package/providers/commercetools/src/providers/cart-payment.provider.ts +0 -193
- package/providers/commercetools/src/test/cart-payment.provider.spec.ts +0 -145
- package/trpc/README.md +0 -7
- package/trpc/__mocks__/superjson.js +0 -25
- package/trpc/eslint.config.mjs +0 -19
- package/trpc/jest.config.ts +0 -14
- package/trpc/package.json +0 -14
- package/trpc/project.json +0 -31
- package/trpc/src/client.ts +0 -175
- package/trpc/src/index.ts +0 -44
- package/trpc/src/integration.spec.ts +0 -223
- package/trpc/src/server.ts +0 -125
- package/trpc/src/test-utils.ts +0 -31
- package/trpc/src/transparent-client.spec.ts +0 -162
- package/trpc/src/types.ts +0 -144
- package/trpc/tsconfig.json +0 -16
- package/trpc/tsconfig.lib.json +0 -10
- package/trpc/tsconfig.spec.json +0 -15
package/core/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { BaseModel } from '../schemas/models';
|
|
2
|
-
import type { Cache, CacheEntryOptions } from './cache.interface';
|
|
1
|
+
import type { BaseModel } from '../schemas/models/index.js';
|
|
2
|
+
import type { Cache, CacheEntryOptions } from './cache.interface.js';
|
|
3
3
|
import type z from 'zod';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Cache } from "../cache/cache.interface";
|
|
2
|
-
import { NoOpCache } from "../cache/noop-cache";
|
|
3
|
-
import type { Client } from "./client";
|
|
4
|
-
import type { AnalyticsProvider } from "../providers/analytics.provider";
|
|
1
|
+
import type { Cache } from "../cache/cache.interface.js";
|
|
2
|
+
import { NoOpCache } from "../cache/noop-cache.js";
|
|
3
|
+
import type { Client } from "./client.js";
|
|
4
|
+
import type { AnalyticsProvider } from "../providers/analytics.provider.js";
|
|
5
5
|
|
|
6
6
|
type CapabilityFactory<T> = (cache: Cache) => T;
|
|
7
7
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type { AnalyticsProvider } from "../providers/analytics.provider";
|
|
2
|
-
import type { ProductProvider } from "../providers/product.provider";
|
|
3
|
-
import type { SearchProvider } from "../providers/search.provider";
|
|
4
|
-
import type { IdentityProvider } from '../providers/identity.provider';
|
|
5
|
-
import type { CartProvider } from "../providers/cart.provider";
|
|
6
|
-
import type { PriceProvider } from "../providers/price.provider";
|
|
7
|
-
import type { InventoryProvider } from "../providers/inventory.provider";
|
|
8
|
-
import type { Cache } from "../cache/cache.interface";
|
|
9
|
-
import { RedisCache } from "../cache/redis-cache";
|
|
10
|
-
import type { CategoryProvider } from "../providers/category.provider";
|
|
11
|
-
import type {
|
|
1
|
+
import type { AnalyticsProvider } from "../providers/analytics.provider.js";
|
|
2
|
+
import type { ProductProvider } from "../providers/product.provider.js";
|
|
3
|
+
import type { SearchProvider } from "../providers/search.provider.js";
|
|
4
|
+
import type { IdentityProvider } from '../providers/identity.provider.js';
|
|
5
|
+
import type { CartProvider } from "../providers/cart.provider.js";
|
|
6
|
+
import type { PriceProvider } from "../providers/price.provider.js";
|
|
7
|
+
import type { InventoryProvider } from "../providers/inventory.provider.js";
|
|
8
|
+
import type { Cache } from "../cache/cache.interface.js";
|
|
9
|
+
import { RedisCache } from "../cache/redis-cache.js";
|
|
10
|
+
import type { CategoryProvider } from "../providers/category.provider.js";
|
|
11
|
+
import type { CheckoutProvider } from "../providers/index.js";
|
|
12
12
|
|
|
13
13
|
export interface Client {
|
|
14
14
|
product: ProductProvider,
|
|
@@ -16,7 +16,7 @@ export interface Client {
|
|
|
16
16
|
identity: IdentityProvider,
|
|
17
17
|
cache: Cache,
|
|
18
18
|
cart: CartProvider,
|
|
19
|
-
|
|
19
|
+
checkout: CheckoutProvider,
|
|
20
20
|
analytics: Array<AnalyticsProvider>,
|
|
21
21
|
price: PriceProvider,
|
|
22
22
|
inventory: InventoryProvider,
|
|
@@ -1,5 +1,25 @@
|
|
|
1
|
-
import type { BaseProvider } from '../providers';
|
|
2
|
-
import {
|
|
1
|
+
import type { BaseProvider } from '../providers/index.js';
|
|
2
|
+
import type {
|
|
3
|
+
Tracer, } from '@opentelemetry/api';
|
|
4
|
+
import {
|
|
5
|
+
trace,
|
|
6
|
+
SpanKind
|
|
7
|
+
} from '@opentelemetry/api';
|
|
8
|
+
|
|
9
|
+
const TRACER_NAME = '@reactionary';
|
|
10
|
+
const TRACER_VERSION = '0.0.1';
|
|
11
|
+
|
|
12
|
+
let globalTracer: Tracer | null = null;
|
|
13
|
+
|
|
14
|
+
export function getTracer(): Tracer {
|
|
15
|
+
if (!globalTracer) {
|
|
16
|
+
// Simply get the tracer from the API
|
|
17
|
+
// If the SDK is not initialized by the host application,
|
|
18
|
+
// this will return a ProxyTracer that produces NonRecordingSpans
|
|
19
|
+
globalTracer = trace.getTracer(TRACER_NAME, TRACER_VERSION);
|
|
20
|
+
}
|
|
21
|
+
return globalTracer;
|
|
22
|
+
}
|
|
3
23
|
|
|
4
24
|
/**
|
|
5
25
|
* The options associated with annotating a provider function and marking
|
package/core/src/index.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export * from './cache/cache.interface';
|
|
2
|
-
export * from './cache/redis-cache';
|
|
3
|
-
export * from './cache/memory-cache';
|
|
4
|
-
export * from './cache/noop-cache';
|
|
1
|
+
export * from './cache/cache.interface.js';
|
|
2
|
+
export * from './cache/redis-cache.js';
|
|
3
|
+
export * from './cache/memory-cache.js';
|
|
4
|
+
export * from './cache/noop-cache.js';
|
|
5
5
|
|
|
6
|
-
export * from './client/client';
|
|
7
|
-
export * from './client/client-builder';
|
|
6
|
+
export * from './client/client.js';
|
|
7
|
+
export * from './client/client-builder.js';
|
|
8
8
|
|
|
9
|
-
export * from './decorators/reactionary.decorator';
|
|
9
|
+
export * from './decorators/reactionary.decorator.js';
|
|
10
10
|
|
|
11
|
-
export * from './providers/'
|
|
11
|
+
export * from './providers/index.js'
|
|
12
12
|
|
|
13
|
-
export * from './schemas/capabilities.schema';
|
|
14
|
-
export * from './schemas/session.schema';
|
|
13
|
+
export * from './schemas/capabilities.schema.js';
|
|
14
|
+
export * from './schemas/session.schema.js';
|
|
15
15
|
|
|
16
|
-
export * from './schemas/models/';
|
|
17
|
-
export * from './schemas/mutations/';
|
|
18
|
-
export * from './schemas/queries';
|
|
19
|
-
export * from './initialization';
|
|
16
|
+
export * from './schemas/models/index.js';
|
|
17
|
+
export * from './schemas/mutations/index.js';
|
|
18
|
+
export * from './schemas/queries/index.js';
|
|
19
|
+
export * from './initialization.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AnalyticsEvent } from '../schemas/models/analytics.model';
|
|
2
|
-
import { BaseProvider } from './base.provider';
|
|
1
|
+
import type { AnalyticsEvent } from '../schemas/models/analytics.model.js';
|
|
2
|
+
import { BaseProvider } from './base.provider.js';
|
|
3
3
|
|
|
4
4
|
export abstract class AnalyticsProvider<
|
|
5
5
|
T extends AnalyticsEvent = AnalyticsEvent
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { z } from 'zod';
|
|
2
2
|
import type {
|
|
3
|
-
BaseModel} from '../schemas/models/base.model';
|
|
3
|
+
BaseModel} from '../schemas/models/base.model.js';
|
|
4
4
|
import {
|
|
5
5
|
createPaginatedResponseSchema,
|
|
6
|
-
} from '../schemas/models/base.model';
|
|
7
|
-
import type { Cache } from '../cache/cache.interface';
|
|
8
|
-
import type { RequestContext, Session } from '../schemas/session.schema';
|
|
9
|
-
import type { IdentifierType } from '../schemas/models/identifiers.model';
|
|
6
|
+
} from '../schemas/models/base.model.js';
|
|
7
|
+
import type { Cache } from '../cache/cache.interface.js';
|
|
8
|
+
import type { RequestContext, Session } from '../schemas/session.schema.js';
|
|
9
|
+
import type { IdentifierType } from '../schemas/models/identifiers.model.js';
|
|
10
10
|
import { hasher } from "node-object-hash";
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { BaseProvider } from "./base.provider";
|
|
2
|
-
import type { Cart } from "../schemas/models/cart.model";
|
|
3
|
-
import type { CartQueryById } from "../schemas/queries/cart.query";
|
|
4
|
-
import type { RequestContext } from "../schemas/session.schema";
|
|
5
|
-
import type { CartMutationApplyCoupon, CartMutationChangeCurrency, CartMutationCheckout, CartMutationDeleteCart, CartMutationItemAdd, CartMutationItemQuantityChange, CartMutationItemRemove, CartMutationRemoveCoupon, CartMutationSetBillingAddress, CartMutationSetShippingInfo } from "../schemas/mutations/cart.mutation";
|
|
6
|
-
import type { CartIdentifier, OrderIdentifier } from "../schemas/models/identifiers.model";
|
|
1
|
+
import { BaseProvider } from "./base.provider.js";
|
|
2
|
+
import type { Cart } from "../schemas/models/cart.model.js";
|
|
3
|
+
import type { CartQueryById } from "../schemas/queries/cart.query.js";
|
|
4
|
+
import type { RequestContext } from "../schemas/session.schema.js";
|
|
5
|
+
import type { CartMutationApplyCoupon, CartMutationChangeCurrency, CartMutationCheckout, CartMutationDeleteCart, CartMutationItemAdd, CartMutationItemQuantityChange, CartMutationItemRemove, CartMutationRemoveCoupon, CartMutationSetBillingAddress, CartMutationSetShippingInfo } from "../schemas/mutations/cart.mutation.js";
|
|
6
|
+
import type { CartIdentifier, OrderIdentifier } from "../schemas/models/identifiers.model.js";
|
|
7
7
|
|
|
8
8
|
export abstract class CartProvider<
|
|
9
9
|
T extends Cart = Cart
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import { CategoryIdentifier } from "../schemas/models/identifiers.model";
|
|
6
|
-
import type { CategoryQueryById, CategoryQueryBySlug, CategoryQueryForBreadcrumb, CategoryQueryForChildCategories, CategoryQueryForTopCategories } from "../schemas/queries/category.query";
|
|
7
|
-
import type { RequestContext} from "../schemas/session.schema";
|
|
8
|
-
import { Session } from "../schemas/session.schema";
|
|
9
|
-
import { BaseProvider } from "./base.provider";
|
|
1
|
+
import type { Category } from "../schemas/models/category.model.js";
|
|
2
|
+
import type { CategoryQueryById, CategoryQueryBySlug, CategoryQueryForBreadcrumb, CategoryQueryForChildCategories, CategoryQueryForTopCategories } from "../schemas/queries/category.query.js";
|
|
3
|
+
import type { RequestContext} from "../schemas/session.schema.js";
|
|
4
|
+
import { BaseProvider } from "./base.provider.js";
|
|
10
5
|
|
|
11
6
|
|
|
12
7
|
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type { Checkout, PaymentMethod, ShippingMethod } from "../schemas/models/index.js";
|
|
2
|
+
import type { RequestContext } from "../schemas/session.schema.js";
|
|
3
|
+
import { BaseProvider } from "./base.provider.js";
|
|
4
|
+
import type { CheckoutMutationFinalizeCheckout, CheckoutMutationInitiateCheckout, CheckoutMutationSetShippingAddress, CheckoutMutationAddPaymentInstruction, CheckoutMutationRemovePaymentInstruction, CheckoutMutationSetShippingInstruction } from "../schemas/mutations/checkout.mutation.js";
|
|
5
|
+
import type { CheckoutQueryById, CheckoutQueryForAvailablePaymentMethods, CheckoutQueryForAvailableShippingMethods } from "../schemas/queries/index.js";
|
|
6
|
+
|
|
7
|
+
export abstract class CheckoutProvider<
|
|
8
|
+
T extends Checkout = Checkout
|
|
9
|
+
> extends BaseProvider<T> {
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* This starts a new checkout session for the given cart. The checkout might duplicate the cart, or just reference it, depending on implementation, but changes to the cart,
|
|
13
|
+
* is not reflected in the checkout, and vice versa. The checkout is a snapshot of the cart at the time of initiation.
|
|
14
|
+
* The checkout will typically copy over addresses from the user profile, if available, or from the anonymous profile in the session.
|
|
15
|
+
*
|
|
16
|
+
* Usecase: User has filled out cart, and is ready to checkout. You call this to create a checkout object, that you can then use to set shipping method, payment method etc.
|
|
17
|
+
* @param cartId The cart you are trying to checkout
|
|
18
|
+
* @param billingAddress the billing/shipping address to start with. This affects available shipping methods, and may be required by some payment providers.
|
|
19
|
+
* @param reqCtx
|
|
20
|
+
*/
|
|
21
|
+
public abstract initiateCheckoutForCart(payload: CheckoutMutationInitiateCheckout, reqCtx: RequestContext): Promise<T>;
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Fetches an existing checkout by its identifier.
|
|
26
|
+
*
|
|
27
|
+
* Usecase: User has navigated to the checkout page, or reloaded on it , or has been redirected back from the payment provider.
|
|
28
|
+
* @param payload
|
|
29
|
+
* @param reqCtx
|
|
30
|
+
*/
|
|
31
|
+
public abstract getById(payload: CheckoutQueryById, reqCtx: RequestContext): Promise<T | null>;
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Updates the shipping address for the checkout and recalculates the shipping methods and totals.
|
|
37
|
+
*
|
|
38
|
+
* Usecase: User has chosen home delivery and you have allowed them to change the address on the checkout page.
|
|
39
|
+
*
|
|
40
|
+
* NOTE: Unsure this is really needed.
|
|
41
|
+
* @param shippingAddress The updated shipping address. Note: This may also be the billing address, if your store does not differentiate.
|
|
42
|
+
*/
|
|
43
|
+
public abstract setShippingAddress(payload: CheckoutMutationSetShippingAddress, reqCtx: RequestContext): Promise<T>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Returns all available shipping methods for the given checkout. This will typically depend on the shipping address, and possibly also the items in the checkout.
|
|
47
|
+
*
|
|
48
|
+
* Usecase: User has filled out shipping address, and you need to show available shipping methods.
|
|
49
|
+
*
|
|
50
|
+
* @param checkoutId The checkout you want to get shipping methods for.
|
|
51
|
+
* @param reqCtx
|
|
52
|
+
*/
|
|
53
|
+
public abstract getAvailableShippingMethods(payload: CheckoutQueryForAvailableShippingMethods, reqCtx: RequestContext): Promise<ShippingMethod[]>;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Returns all available payment methods for the given checkout. This will typically depend mostly on the billing address and jurisdiction.
|
|
57
|
+
*
|
|
58
|
+
* Usecase: User has chosen shipping method, and you need to show available payment methods.
|
|
59
|
+
*
|
|
60
|
+
* @param checkoutId The checkout you want to get payment methods for.
|
|
61
|
+
* @param reqCtx
|
|
62
|
+
*/
|
|
63
|
+
public abstract getAvailablePaymentMethods(payload: CheckoutQueryForAvailablePaymentMethods, reqCtx: RequestContext): Promise<PaymentMethod[]>;
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Adds a payment instruction to the checkout. This will typically create a payment intent in the payment provider, and return whatever is needed to continue the payment process, e.g. a client secret for Stripe, or a redirect URL for PayPal.
|
|
68
|
+
*
|
|
69
|
+
* Usecase: User has chosen a payment method, and you need to start the payment process.
|
|
70
|
+
*/
|
|
71
|
+
public abstract addPaymentInstruction(payload: CheckoutMutationAddPaymentInstruction, reqCtx: RequestContext): Promise<T>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Removes a payment instruction from the checkout. This will typically void the payment intent in the payment provider, and remove the payment instruction from the checkout.
|
|
75
|
+
*
|
|
76
|
+
* Usecase: User has decided to change payment method, or has cancelled the payment process.
|
|
77
|
+
* @param paymentInstructionId
|
|
78
|
+
*/
|
|
79
|
+
public abstract removePaymentInstruction(payload: CheckoutMutationRemovePaymentInstruction, reqCtx: RequestContext): Promise<T>;
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Sets the shipping method and optional pickup point for the checkout. The pickup point can be a physical store, a locker, or similar.
|
|
85
|
+
* If it is unset, it means home delivery to the shipping address.
|
|
86
|
+
*
|
|
87
|
+
*
|
|
88
|
+
* Usecase: record all the users shipping choices, and any special instructions they may have added.
|
|
89
|
+
*
|
|
90
|
+
* @param shippingMethodId
|
|
91
|
+
* @param pickupPoint
|
|
92
|
+
*/
|
|
93
|
+
public abstract setShippingInstruction(payload: CheckoutMutationSetShippingInstruction, reqCtx: RequestContext): Promise<T>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Finalizes the checkout process. This typically involves creating an order from the checkout and processing payment.
|
|
97
|
+
*
|
|
98
|
+
* Usecase: User has completed all necessary steps in the checkout process and is ready to place the order.
|
|
99
|
+
*
|
|
100
|
+
* @param payload
|
|
101
|
+
* @param reqCtx
|
|
102
|
+
*/
|
|
103
|
+
public abstract finalizeCheckout(payload: CheckoutMutationFinalizeCheckout, reqCtx: RequestContext): Promise<T>;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
*
|
|
110
|
+
*
|
|
111
|
+
* How would this be used?
|
|
112
|
+
* // navigated to /payment
|
|
113
|
+
*
|
|
114
|
+
* const cart = await cartProvider.getById({id: 'cart-123'}, reqCtx);
|
|
115
|
+
*
|
|
116
|
+
* let address = null;
|
|
117
|
+
* if (reqCtx.identity.isAuthenticated) {
|
|
118
|
+
* const profile = await profileProvider.getByUserId({userId: reqCtx.identity.userId}, reqCtx);
|
|
119
|
+
* address = profile?.addresses?.[0];
|
|
120
|
+
* }
|
|
121
|
+
* if (!address) {
|
|
122
|
+
* address = reqCtx.session.anonymousProfile?.addresses?.[0];
|
|
123
|
+
* }
|
|
124
|
+
*
|
|
125
|
+
* // ok we are ready for checkout...
|
|
126
|
+
* const checkout = await checkoutProvider.initiateCheckoutForCart(cart.identifier, address, reqCtx);
|
|
127
|
+
*
|
|
128
|
+
* const paymentMethods = await paymentProvider.getAvailablePaymentMethods(checkout, reqCtx);
|
|
129
|
+
* const shippingMethods = await shippingProvider.getAvailableShippingMethods(checkout, reqCtx);
|
|
130
|
+
*
|
|
131
|
+
*
|
|
132
|
+
* onShippingSelected = async (shippingMethodId, pickupPoint) => {
|
|
133
|
+
* const checkout = await checkoutProvider.setShippingMethod(checkout.identifier, shippingMethodId, pickupPoint);
|
|
134
|
+
* return checkout;
|
|
135
|
+
* }
|
|
136
|
+
*
|
|
137
|
+
* onPaymentSelected = async (paymentMethodId) => {
|
|
138
|
+
* const checkout = await checkoutProvider.addPaymentInstruction(checkout.identifier, paymentMethodId);
|
|
139
|
+
* return checkout;
|
|
140
|
+
* }
|
|
141
|
+
*
|
|
142
|
+
* if (checkout.paymentInstructions.length === 0) {
|
|
143
|
+
* // show payment method selection
|
|
144
|
+
* return <PaymentMethodSelection methods={paymentMethods} onSelect={onPaymentSelected} />
|
|
145
|
+
*
|
|
146
|
+
* } else {
|
|
147
|
+
* if (checkout.paymentInstructions[0].status !== 'Authorized') {
|
|
148
|
+
* const pi = checkout.paymentInstructions[0];
|
|
149
|
+
* if (pi.provider === 'stripe') {
|
|
150
|
+
* return new StripeForm(pi.protocolData.find(x => x.key === 'clientSecret').value, onPaymentAuthorized);
|
|
151
|
+
* } else if (pi.provider === 'adyen') {
|
|
152
|
+
* return new RedirectTo(pi.protocolData.find(x => x.key === 'punchoutUrl').value);
|
|
153
|
+
* }
|
|
154
|
+
* }
|
|
155
|
+
* })
|
|
156
|
+
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Identity } from "../schemas/models/identity.model";
|
|
2
|
-
import type { IdentityMutationLogin, IdentityMutationLogout, IdentityMutationRegister } from "../schemas/mutations/identity.mutation";
|
|
3
|
-
import type { IdentityQuerySelf } from "../schemas/queries/identity.query";
|
|
4
|
-
import type { RequestContext} from "../schemas/session.schema";
|
|
5
|
-
import { BaseProvider } from "./base.provider";
|
|
1
|
+
import type { Identity } from "../schemas/models/identity.model.js";
|
|
2
|
+
import type { IdentityMutationLogin, IdentityMutationLogout, IdentityMutationRegister } from "../schemas/mutations/identity.mutation.js";
|
|
3
|
+
import type { IdentityQuerySelf } from "../schemas/queries/identity.query.js";
|
|
4
|
+
import type { RequestContext} from "../schemas/session.schema.js";
|
|
5
|
+
import { BaseProvider } from "./base.provider.js";
|
|
6
6
|
|
|
7
7
|
export abstract class IdentityProvider<
|
|
8
8
|
T extends Identity = Identity,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
export * from './analytics.provider';
|
|
2
|
-
export * from './base.provider';
|
|
3
|
-
export * from './cart
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './identity.provider';
|
|
7
|
-
export * from './inventory.provider';
|
|
8
|
-
export * from './price.provider';
|
|
9
|
-
export * from './product.provider';
|
|
10
|
-
export * from './profile.provider';
|
|
11
|
-
export * from './search.provider';
|
|
12
|
-
export * from './store.provider';
|
|
1
|
+
export * from './analytics.provider.js';
|
|
2
|
+
export * from './base.provider.js';
|
|
3
|
+
export * from './cart.provider.js';
|
|
4
|
+
export * from './category.provider.js';
|
|
5
|
+
export * from './checkout.provider.js';
|
|
6
|
+
export * from './identity.provider.js';
|
|
7
|
+
export * from './inventory.provider.js';
|
|
8
|
+
export * from './price.provider.js';
|
|
9
|
+
export * from './product.provider.js';
|
|
10
|
+
export * from './profile.provider.js';
|
|
11
|
+
export * from './search.provider.js';
|
|
12
|
+
export * from './store.provider.js';
|
|
13
|
+
export * from './order.provider.js'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Inventory } from '../schemas/models/inventory.model';
|
|
2
|
-
import type { InventoryQueryBySKU } from '../schemas/queries/inventory.query';
|
|
3
|
-
import type { RequestContext } from '../schemas/session.schema';
|
|
4
|
-
import { BaseProvider } from './base.provider';
|
|
1
|
+
import type { Inventory } from '../schemas/models/inventory.model.js';
|
|
2
|
+
import type { InventoryQueryBySKU } from '../schemas/queries/inventory.query.js';
|
|
3
|
+
import type { RequestContext } from '../schemas/session.schema.js';
|
|
4
|
+
import { BaseProvider } from './base.provider.js';
|
|
5
5
|
|
|
6
6
|
export abstract class InventoryProvider<
|
|
7
7
|
T extends Inventory = Inventory
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BaseProvider } from "./base.provider.js";
|
|
2
|
+
import type { RequestContext } from "../schemas/session.schema.js";
|
|
3
|
+
import type { Order } from "../schemas/models/index.js";
|
|
4
|
+
import type { OrderQueryById } from "../schemas/queries/index.js";
|
|
5
|
+
|
|
6
|
+
export abstract class OrderProvider<
|
|
7
|
+
T extends Order = Order
|
|
8
|
+
> extends BaseProvider<T> {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get order by ID.
|
|
12
|
+
*
|
|
13
|
+
* Usecase: Fetch order after checkout, to check if we are fully paid and can continue to order confirmation page.
|
|
14
|
+
* @param payload
|
|
15
|
+
* @param session
|
|
16
|
+
*/
|
|
17
|
+
public abstract getById(payload: OrderQueryById, reqCtx: RequestContext): Promise<T>;
|
|
18
|
+
|
|
19
|
+
protected createEmptyOrder(): T {
|
|
20
|
+
const order = this.newModel();
|
|
21
|
+
order.meta = { placeholder: true, cache: { hit: true, key: 'empty-order' } };
|
|
22
|
+
order.identifier = { key: '' };
|
|
23
|
+
return order;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
protected override getResourceName(): string {
|
|
27
|
+
return 'order';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Currency } from '../schemas/models/currency.model';
|
|
2
|
-
import type { Price } from '../schemas/models/price.model';
|
|
3
|
-
import type { PriceQueryBySku } from '../schemas/queries/price.query';
|
|
4
|
-
import type { RequestContext } from '../schemas/session.schema';
|
|
5
|
-
import { BaseProvider } from './base.provider';
|
|
1
|
+
import type { Currency } from '../schemas/models/currency.model.js';
|
|
2
|
+
import type { Price } from '../schemas/models/price.model.js';
|
|
3
|
+
import type { PriceQueryBySku } from '../schemas/queries/price.query.js';
|
|
4
|
+
import type { RequestContext } from '../schemas/session.schema.js';
|
|
5
|
+
import { BaseProvider } from './base.provider.js';
|
|
6
6
|
|
|
7
7
|
export abstract class PriceProvider<
|
|
8
8
|
T extends Price = Price
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type { Product } from '../schemas/models/product.model';
|
|
2
|
-
import { BaseProvider } from './base.provider';
|
|
3
|
-
import type { RequestContext } from '../schemas/session.schema';
|
|
4
|
-
import type { ProductQueryById, ProductQueryBySlug } from '../schemas/queries/product.query';
|
|
1
|
+
import type { Product } from '../schemas/models/product.model.js';
|
|
2
|
+
import { BaseProvider } from './base.provider.js';
|
|
3
|
+
import type { RequestContext } from '../schemas/session.schema.js';
|
|
4
|
+
import type { ProductQueryById, ProductQueryBySKU, ProductQueryBySlug } from '../schemas/queries/product.query.js';
|
|
5
5
|
|
|
6
6
|
export abstract class ProductProvider<
|
|
7
7
|
T extends Product = Product
|
|
8
8
|
> extends BaseProvider<T> {
|
|
9
9
|
public abstract getById(payload: ProductQueryById, reqCtx: RequestContext): Promise<T>;
|
|
10
10
|
public abstract getBySlug(payload: ProductQueryBySlug, reqCtx: RequestContext): Promise<T | null>;
|
|
11
|
-
|
|
11
|
+
public abstract getBySKU(payload: ProductQueryBySKU | ProductQueryBySKU[], reqCtx: RequestContext): Promise<T>;
|
|
12
12
|
|
|
13
13
|
protected createEmptyProduct(id: string): T {
|
|
14
14
|
const product = this.newModel();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Profile } from '../schemas/models';
|
|
2
|
-
import type { ProfileMutationUpdate } from '../schemas/mutations';
|
|
3
|
-
import type { ProfileQuerySelf } from '../schemas/queries';
|
|
4
|
-
import type { RequestContext } from '../schemas/session.schema';
|
|
5
|
-
import { BaseProvider } from './base.provider';
|
|
1
|
+
import type { Profile } from '../schemas/models/index.js';
|
|
2
|
+
import type { ProfileMutationUpdate } from '../schemas/mutations/index.js';
|
|
3
|
+
import type { ProfileQuerySelf } from '../schemas/queries/index.js';
|
|
4
|
+
import type { RequestContext } from '../schemas/session.schema.js';
|
|
5
|
+
import { BaseProvider } from './base.provider.js';
|
|
6
6
|
|
|
7
7
|
export abstract class ProfileProvider<
|
|
8
8
|
T extends Profile = Profile
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { SearchResult } from '../schemas/models/search.model';
|
|
2
|
-
import type { SearchQueryByTerm } from '../schemas/queries/search.query';
|
|
3
|
-
import type { RequestContext } from '../schemas/session.schema';
|
|
4
|
-
import { BaseProvider } from './base.provider';
|
|
1
|
+
import type { SearchResult } from '../schemas/models/search.model.js';
|
|
2
|
+
import type { SearchQueryByTerm } from '../schemas/queries/search.query.js';
|
|
3
|
+
import type { RequestContext } from '../schemas/session.schema.js';
|
|
4
|
+
import { BaseProvider } from './base.provider.js';
|
|
5
5
|
|
|
6
6
|
export abstract class SearchProvider<
|
|
7
7
|
T extends SearchResult = SearchResult
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Store } from '../schemas/models/store.model';
|
|
2
|
-
import type { StoreQueryByProximity } from '../schemas/queries';
|
|
3
|
-
import type { RequestContext } from '../schemas/session.schema';
|
|
4
|
-
import { BaseProvider } from './base.provider';
|
|
1
|
+
import type { Store } from '../schemas/models/store.model.js';
|
|
2
|
+
import type { StoreQueryByProximity } from '../schemas/queries/index.js';
|
|
3
|
+
import type { RequestContext } from '../schemas/session.schema.js';
|
|
4
|
+
import { BaseProvider } from './base.provider.js';
|
|
5
5
|
|
|
6
6
|
export abstract class StoreProvider<
|
|
7
7
|
T extends Store = Store
|
|
@@ -6,7 +6,8 @@ export const CapabilitiesSchema = z.looseObject({
|
|
|
6
6
|
analytics: z.boolean(),
|
|
7
7
|
identity: z.boolean(),
|
|
8
8
|
cart: z.boolean(),
|
|
9
|
-
|
|
9
|
+
checkout: z.boolean(),
|
|
10
|
+
order: z.boolean(),
|
|
10
11
|
inventory: z.boolean(),
|
|
11
12
|
price: z.boolean(),
|
|
12
13
|
category: z.boolean(),
|
|
@@ -1,26 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { CartIdentifierSchema, CartItemIdentifierSchema, IdentityIdentifierSchema, ProductIdentifierSchema, SKUIdentifierSchema } from '../models/identifiers.model';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { AddressSchema } from './profile.model';
|
|
6
|
-
import { ShippingMethodSchema } from './shipping-method.model';
|
|
7
|
-
|
|
8
|
-
export const CostBreakDownSchema = z.looseObject({
|
|
9
|
-
totalTax: MonetaryAmountSchema.default(() => MonetaryAmountSchema.parse({})).describe('The amount of tax paid on the cart. This may include VAT, GST, sales tax, etc.'),
|
|
10
|
-
totalDiscount: MonetaryAmountSchema.default(() => MonetaryAmountSchema.parse({})).describe('The amount of discount applied to the cart.'),
|
|
11
|
-
totalSurcharge: MonetaryAmountSchema.default(() => MonetaryAmountSchema.parse({})).describe('The amount of surcharge applied to the cart.'),
|
|
12
|
-
totalShipping: MonetaryAmountSchema.default(() => MonetaryAmountSchema.parse({})).describe('The amount of shipping fees for the cart.'),
|
|
13
|
-
totalProductPrice: MonetaryAmountSchema.default(() => MonetaryAmountSchema.parse({})).describe('The total price of products in the cart.'),
|
|
14
|
-
grandTotal: MonetaryAmountSchema.default(() => MonetaryAmountSchema.parse({})).describe('The total price for the cart including all taxes, discounts, and shipping.'),
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
export const ItemCostBreakdownSchema = z.looseObject({
|
|
18
|
-
unitPrice: MonetaryAmountSchema.default(() => MonetaryAmountSchema.parse({})).describe('The price per single unit of the item.'),
|
|
19
|
-
unitDiscount: MonetaryAmountSchema.default(() => MonetaryAmountSchema.parse({})).describe('The discount applied per single unit of the item.'),
|
|
20
|
-
totalPrice: MonetaryAmountSchema.default(() => MonetaryAmountSchema.parse({})).describe('The total price for all units of the item.'),
|
|
21
|
-
totalDiscount: MonetaryAmountSchema.default(() => MonetaryAmountSchema.parse({})).describe('The total discount applied to all units of the item.'),
|
|
22
|
-
});
|
|
23
|
-
|
|
2
|
+
import { CartIdentifierSchema, CartItemIdentifierSchema, IdentityIdentifierSchema, ProductIdentifierSchema, SKUIdentifierSchema } from '../models/identifiers.model.js';
|
|
3
|
+
import { CostBreakDownSchema, ItemCostBreakdownSchema } from './cost.model.js';
|
|
4
|
+
import { BaseModelSchema } from './base.model.js';
|
|
24
5
|
|
|
25
6
|
export const CartItemSchema = z.looseObject({
|
|
26
7
|
identifier: CartItemIdentifierSchema.default(() => CartItemIdentifierSchema.parse({})),
|
|
@@ -41,14 +22,8 @@ export const CartSchema = BaseModelSchema.extend({
|
|
|
41
22
|
description: z.string().default(''),
|
|
42
23
|
|
|
43
24
|
|
|
44
|
-
shippingAddress: AddressSchema.optional(),
|
|
45
|
-
billingAddress: AddressSchema.optional(),
|
|
46
|
-
shippingMethod: ShippingMethodSchema.optional(),
|
|
47
25
|
});
|
|
48
26
|
|
|
49
27
|
|
|
50
|
-
|
|
51
|
-
export type CostBreakDown = z.infer<typeof CostBreakDownSchema>;
|
|
52
|
-
export type ItemCostBreakdown = z.infer<typeof ItemCostBreakdownSchema>;
|
|
53
28
|
export type CartItem = z.infer<typeof CartItemSchema>;
|
|
54
29
|
export type Cart = z.infer<typeof CartSchema>;
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
import { z } from 'zod';
|
|
9
|
-
import { BaseModelSchema, createPaginatedResponseSchema, ImageSchema } from './base.model';
|
|
10
|
-
import { CategoryIdentifierSchema } from './identifiers.model';
|
|
9
|
+
import { BaseModelSchema, createPaginatedResponseSchema, ImageSchema } from './base.model.js';
|
|
10
|
+
import { CategoryIdentifierSchema } from './identifiers.model.js';
|
|
11
11
|
export const CategorySchema = BaseModelSchema.extend({
|
|
12
12
|
identifier: CategoryIdentifierSchema.default(() => CategoryIdentifierSchema.parse({})),
|
|
13
13
|
name: z.string().default(''),
|