@plasmicpkgs/commerce 0.0.246 → 0.0.248
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/dist/api/endpoints/cart.d.ts +4 -4
- package/dist/api/endpoints/catalog/products.d.ts +4 -4
- package/dist/api/index.d.ts +75 -75
- package/dist/api/operations.d.ts +130 -130
- package/dist/api/utils/errors.d.ts +10 -10
- package/dist/api/utils/is-allowed-method.d.ts +3 -3
- package/dist/api/utils/is-allowed-operation.d.ts +6 -6
- package/dist/api/utils/types.d.ts +34 -34
- package/dist/cart/use-add-item.d.ts +5 -5
- package/dist/cart/use-cart.d.ts +5 -5
- package/dist/cart/use-remove-item.d.ts +5 -5
- package/dist/cart/use-update-item.d.ts +5 -5
- package/dist/commerce.cjs.development.js +23 -20
- package/dist/commerce.cjs.development.js.map +1 -1
- package/dist/commerce.cjs.production.min.js +1 -1
- package/dist/commerce.cjs.production.min.js.map +1 -1
- package/dist/commerce.d.ts +43 -43
- package/dist/commerce.esm.js +23 -20
- package/dist/commerce.esm.js.map +1 -1
- package/dist/contexts.d.ts +26 -26
- package/dist/index.d.ts +46 -46
- package/dist/product/use-price.d.ts +26 -26
- package/dist/product/use-product.d.ts +5 -5
- package/dist/product/use-search.d.ts +6 -6
- package/dist/registerAddToCartButton.d.ts +10 -10
- package/dist/registerCart.d.ts +12 -12
- package/dist/registerCartProvider.d.ts +6 -6
- package/dist/registerCategoryCollection.d.ts +20 -20
- package/dist/registerCategoryField.d.ts +11 -11
- package/dist/registerCategoryLink.d.ts +12 -12
- package/dist/registerCategoryMedia.d.ts +11 -11
- package/dist/registerProductBox.d.ts +18 -18
- package/dist/registerProductCollection.d.ts +29 -29
- package/dist/registerProductLink.d.ts +12 -12
- package/dist/registerProductMedia.d.ts +14 -14
- package/dist/registerProductMediaCollection.d.ts +11 -11
- package/dist/registerProductPrice.d.ts +10 -10
- package/dist/registerProductQuantity.d.ts +11 -11
- package/dist/registerProductSlider.d.ts +14 -14
- package/dist/registerProductTextField.d.ts +11 -11
- package/dist/registerProductVariantPicker.d.ts +10 -10
- package/dist/registerable.d.ts +4 -4
- package/dist/site/use-brands.d.ts +5 -5
- package/dist/site/use-categories.d.ts +5 -5
- package/dist/types/cart.d.ts +157 -157
- package/dist/types/checkout.d.ts +57 -57
- package/dist/types/common.d.ts +13 -13
- package/dist/types/customer/address.d.ts +110 -110
- package/dist/types/customer/card.d.ts +113 -113
- package/dist/types/customer/index.d.ts +24 -24
- package/dist/types/index.d.ts +12 -12
- package/dist/types/login.d.ts +27 -27
- package/dist/types/logout.d.ts +17 -17
- package/dist/types/page.d.ts +24 -24
- package/dist/types/product.d.ts +117 -117
- package/dist/types/signup.d.ts +23 -23
- package/dist/types/site.d.ts +55 -55
- package/dist/types/wishlist.d.ts +83 -83
- package/dist/utils/default-fetcher.d.ts +4 -4
- package/dist/utils/default-product.d.ts +2 -2
- package/dist/utils/define-property.d.ts +21 -21
- package/dist/utils/errors.d.ts +27 -27
- package/dist/utils/get-product-price.d.ts +2 -2
- package/dist/utils/types.d.ts +99 -99
- package/dist/utils/use-data.d.ts +13 -13
- package/dist/utils/use-extra-features.d.ts +1 -1
- package/dist/utils/use-hook.d.ts +7 -7
- package/package.json +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CartSchema } from '../../types/cart';
|
|
2
|
-
import type { GetAPISchema } from '..';
|
|
3
|
-
declare const cartEndpoint: GetAPISchema<any, CartSchema<any>>['endpoint']['handler'];
|
|
4
|
-
export default cartEndpoint;
|
|
1
|
+
import type { CartSchema } from '../../types/cart';
|
|
2
|
+
import type { GetAPISchema } from '..';
|
|
3
|
+
declare const cartEndpoint: GetAPISchema<any, CartSchema<any>>['endpoint']['handler'];
|
|
4
|
+
export default cartEndpoint;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ProductsSchema } from '../../../types/product';
|
|
2
|
-
import type { GetAPISchema } from '../..';
|
|
3
|
-
declare const productsEndpoint: GetAPISchema<any, ProductsSchema>['endpoint']['handler'];
|
|
4
|
-
export default productsEndpoint;
|
|
1
|
+
import type { ProductsSchema } from '../../../types/product';
|
|
2
|
+
import type { GetAPISchema } from '../..';
|
|
3
|
+
declare const productsEndpoint: GetAPISchema<any, ProductsSchema>['endpoint']['handler'];
|
|
4
|
+
export default productsEndpoint;
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
import type { NextApiHandler } from 'next';
|
|
2
|
-
import type { FetchOptions, Response } from '@vercel/fetch';
|
|
3
|
-
import type { APIEndpoint, APIHandler } from './utils/types';
|
|
4
|
-
import type { CartSchema } from '../types/cart';
|
|
5
|
-
import type { CustomerSchema } from '../types/customer';
|
|
6
|
-
import type { LoginSchema } from '../types/login';
|
|
7
|
-
import type { LogoutSchema } from '../types/logout';
|
|
8
|
-
import type { SignupSchema } from '../types/signup';
|
|
9
|
-
import type { ProductsSchema } from '../types/product';
|
|
10
|
-
import type { WishlistSchema } from '../types/wishlist';
|
|
11
|
-
import type { CheckoutSchema } from '../types/checkout';
|
|
12
|
-
import type { CustomerCardSchema } from '../types/customer/card';
|
|
13
|
-
import type { CustomerAddressSchema } from '../types/customer/address';
|
|
14
|
-
import { AllOperations, APIOperations } from './operations';
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
schema: S;
|
|
18
|
-
endpoint: EndpointContext<C, S['endpoint']>;
|
|
19
|
-
};
|
|
20
|
-
export
|
|
21
|
-
handler: Endpoint<C, E>;
|
|
22
|
-
handlers: EndpointHandlers<C, E>;
|
|
23
|
-
};
|
|
24
|
-
export
|
|
25
|
-
options: {};
|
|
26
|
-
handlers: {
|
|
27
|
-
[k: string]: {
|
|
28
|
-
data?: any;
|
|
29
|
-
body?: any;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
export
|
|
34
|
-
export
|
|
35
|
-
[H in keyof E['handlers']]: APIHandler<C, EndpointHandlers<C, E>, NonNullable<E['handlers'][H]>['data'], NonNullable<E['handlers'][H]>['body'], E['options']>;
|
|
36
|
-
};
|
|
37
|
-
export
|
|
38
|
-
config: CommerceAPIConfig;
|
|
39
|
-
operations: APIOperations<any>;
|
|
40
|
-
};
|
|
41
|
-
export
|
|
42
|
-
export declare class CommerceAPICore<P extends APIProvider = APIProvider> {
|
|
43
|
-
readonly provider: P;
|
|
44
|
-
constructor(provider: P);
|
|
45
|
-
getConfig(userConfig?: Partial<P['config']>): P['config'];
|
|
46
|
-
setConfig(newConfig: Partial<P['config']>): void;
|
|
47
|
-
}
|
|
48
|
-
export declare function getCommerceApi<P extends APIProvider>(customProvider: P): CommerceAPI<P>;
|
|
49
|
-
export declare function getEndpoint<P extends APIProvider, T extends GetAPISchema<any, any>>(commerce: CommerceAPI<P>, context: T['endpoint'] & {
|
|
50
|
-
config?: P['config'];
|
|
51
|
-
options?: T['schema']['endpoint']['options'];
|
|
52
|
-
}): NextApiHandler;
|
|
53
|
-
export declare const createEndpoint: <API extends GetAPISchema<any, any>>(endpoint: API["endpoint"]) => <P extends APIProvider>(commerce: CommerceAPI<P>, context?: (Partial<API["endpoint"]> & {
|
|
54
|
-
config?: P["config"] | undefined;
|
|
55
|
-
options?: API["schema"]["endpoint"]["options"] | undefined;
|
|
56
|
-
}) | undefined) => NextApiHandler;
|
|
57
|
-
export interface CommerceAPIConfig {
|
|
58
|
-
locale?: string;
|
|
59
|
-
locales?: string[];
|
|
60
|
-
commerceUrl: string;
|
|
61
|
-
apiToken: string;
|
|
62
|
-
cartCookie: string;
|
|
63
|
-
cartCookieMaxAge: number;
|
|
64
|
-
customerCookie: string;
|
|
65
|
-
fetch<Data = any, Variables = any>(query: string, queryData?: CommerceAPIFetchOptions<Variables>, fetchOptions?: FetchOptions): Promise<GraphQLFetcherResult<Data>>;
|
|
66
|
-
}
|
|
67
|
-
export
|
|
68
|
-
export interface GraphQLFetcherResult<Data = any> {
|
|
69
|
-
data: Data;
|
|
70
|
-
res: Response;
|
|
71
|
-
}
|
|
72
|
-
export interface CommerceAPIFetchOptions<Variables> {
|
|
73
|
-
variables?: Variables;
|
|
74
|
-
preview?: boolean;
|
|
75
|
-
}
|
|
1
|
+
import type { NextApiHandler } from 'next';
|
|
2
|
+
import type { FetchOptions, Response } from '@vercel/fetch';
|
|
3
|
+
import type { APIEndpoint, APIHandler } from './utils/types';
|
|
4
|
+
import type { CartSchema } from '../types/cart';
|
|
5
|
+
import type { CustomerSchema } from '../types/customer';
|
|
6
|
+
import type { LoginSchema } from '../types/login';
|
|
7
|
+
import type { LogoutSchema } from '../types/logout';
|
|
8
|
+
import type { SignupSchema } from '../types/signup';
|
|
9
|
+
import type { ProductsSchema } from '../types/product';
|
|
10
|
+
import type { WishlistSchema } from '../types/wishlist';
|
|
11
|
+
import type { CheckoutSchema } from '../types/checkout';
|
|
12
|
+
import type { CustomerCardSchema } from '../types/customer/card';
|
|
13
|
+
import type { CustomerAddressSchema } from '../types/customer/address';
|
|
14
|
+
import { AllOperations, APIOperations } from './operations';
|
|
15
|
+
export type APISchemas = CartSchema | CustomerSchema | LoginSchema | LogoutSchema | SignupSchema | ProductsSchema | WishlistSchema | CheckoutSchema | CustomerCardSchema | CustomerAddressSchema;
|
|
16
|
+
export type GetAPISchema<C extends CommerceAPI<any>, S extends APISchemas = APISchemas> = {
|
|
17
|
+
schema: S;
|
|
18
|
+
endpoint: EndpointContext<C, S['endpoint']>;
|
|
19
|
+
};
|
|
20
|
+
export type EndpointContext<C extends CommerceAPI, E extends EndpointSchemaBase> = {
|
|
21
|
+
handler: Endpoint<C, E>;
|
|
22
|
+
handlers: EndpointHandlers<C, E>;
|
|
23
|
+
};
|
|
24
|
+
export type EndpointSchemaBase = {
|
|
25
|
+
options: {};
|
|
26
|
+
handlers: {
|
|
27
|
+
[k: string]: {
|
|
28
|
+
data?: any;
|
|
29
|
+
body?: any;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export type Endpoint<C extends CommerceAPI, E extends EndpointSchemaBase> = APIEndpoint<C, EndpointHandlers<C, E>, any, E['options']>;
|
|
34
|
+
export type EndpointHandlers<C extends CommerceAPI, E extends EndpointSchemaBase> = {
|
|
35
|
+
[H in keyof E['handlers']]: APIHandler<C, EndpointHandlers<C, E>, NonNullable<E['handlers'][H]>['data'], NonNullable<E['handlers'][H]>['body'], E['options']>;
|
|
36
|
+
};
|
|
37
|
+
export type APIProvider = {
|
|
38
|
+
config: CommerceAPIConfig;
|
|
39
|
+
operations: APIOperations<any>;
|
|
40
|
+
};
|
|
41
|
+
export type CommerceAPI<P extends APIProvider = APIProvider> = CommerceAPICore<P> & AllOperations<P>;
|
|
42
|
+
export declare class CommerceAPICore<P extends APIProvider = APIProvider> {
|
|
43
|
+
readonly provider: P;
|
|
44
|
+
constructor(provider: P);
|
|
45
|
+
getConfig(userConfig?: Partial<P['config']>): P['config'];
|
|
46
|
+
setConfig(newConfig: Partial<P['config']>): void;
|
|
47
|
+
}
|
|
48
|
+
export declare function getCommerceApi<P extends APIProvider>(customProvider: P): CommerceAPI<P>;
|
|
49
|
+
export declare function getEndpoint<P extends APIProvider, T extends GetAPISchema<any, any>>(commerce: CommerceAPI<P>, context: T['endpoint'] & {
|
|
50
|
+
config?: P['config'];
|
|
51
|
+
options?: T['schema']['endpoint']['options'];
|
|
52
|
+
}): NextApiHandler;
|
|
53
|
+
export declare const createEndpoint: <API extends GetAPISchema<any, any>>(endpoint: API["endpoint"]) => <P extends APIProvider>(commerce: CommerceAPI<P>, context?: (Partial<API["endpoint"]> & {
|
|
54
|
+
config?: P["config"] | undefined;
|
|
55
|
+
options?: API["schema"]["endpoint"]["options"] | undefined;
|
|
56
|
+
}) | undefined) => NextApiHandler;
|
|
57
|
+
export interface CommerceAPIConfig {
|
|
58
|
+
locale?: string;
|
|
59
|
+
locales?: string[];
|
|
60
|
+
commerceUrl: string;
|
|
61
|
+
apiToken: string;
|
|
62
|
+
cartCookie: string;
|
|
63
|
+
cartCookieMaxAge: number;
|
|
64
|
+
customerCookie: string;
|
|
65
|
+
fetch<Data = any, Variables = any>(query: string, queryData?: CommerceAPIFetchOptions<Variables>, fetchOptions?: FetchOptions): Promise<GraphQLFetcherResult<Data>>;
|
|
66
|
+
}
|
|
67
|
+
export type GraphQLFetcher<Data extends GraphQLFetcherResult = GraphQLFetcherResult, Variables = any> = (query: string, queryData?: CommerceAPIFetchOptions<Variables>, fetchOptions?: FetchOptions) => Promise<Data>;
|
|
68
|
+
export interface GraphQLFetcherResult<Data = any> {
|
|
69
|
+
data: Data;
|
|
70
|
+
res: Response;
|
|
71
|
+
}
|
|
72
|
+
export interface CommerceAPIFetchOptions<Variables> {
|
|
73
|
+
variables?: Variables;
|
|
74
|
+
preview?: boolean;
|
|
75
|
+
}
|
package/dist/api/operations.d.ts
CHANGED
|
@@ -1,130 +1,130 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { ServerResponse } from 'http';
|
|
3
|
-
import type { LoginOperation } from '../types/login';
|
|
4
|
-
import type { GetAllPagesOperation, GetPageOperation } from '../types/page';
|
|
5
|
-
import type { GetSiteInfoOperation } from '../types/site';
|
|
6
|
-
import type { GetCustomerWishlistOperation } from '../types/wishlist';
|
|
7
|
-
import type { GetAllProductPathsOperation, GetAllProductsOperation, GetProductOperation } from '../types/product';
|
|
8
|
-
import type { APIProvider, CommerceAPI } from '.';
|
|
9
|
-
declare const noop: () => never;
|
|
10
|
-
export declare const OPERATIONS: readonly ["login", "getAllPages", "getPage", "getSiteInfo", "getCustomerWishlist", "getAllProductPaths", "getAllProducts", "getProduct"];
|
|
11
|
-
export declare const defaultOperations: {
|
|
12
|
-
login: () => never;
|
|
13
|
-
getAllPages: () => never;
|
|
14
|
-
getPage: () => never;
|
|
15
|
-
getSiteInfo: () => never;
|
|
16
|
-
getCustomerWishlist: () => never;
|
|
17
|
-
getAllProductPaths: () => never;
|
|
18
|
-
getAllProducts: () => never;
|
|
19
|
-
getProduct: () => never;
|
|
20
|
-
};
|
|
21
|
-
export
|
|
22
|
-
export
|
|
23
|
-
login: {
|
|
24
|
-
<T extends LoginOperation>(opts: {
|
|
25
|
-
variables: T['variables'];
|
|
26
|
-
config?: P['config'];
|
|
27
|
-
res: ServerResponse;
|
|
28
|
-
}): Promise<T['data']>;
|
|
29
|
-
<T extends LoginOperation>(opts: {
|
|
30
|
-
variables: T['variables'];
|
|
31
|
-
config?: P['config'];
|
|
32
|
-
res: ServerResponse;
|
|
33
|
-
} & OperationOptions): Promise<T['data']>;
|
|
34
|
-
};
|
|
35
|
-
getAllPages: {
|
|
36
|
-
<T extends GetAllPagesOperation>(opts?: {
|
|
37
|
-
config?: P['config'];
|
|
38
|
-
preview?: boolean;
|
|
39
|
-
}): Promise<T['data']>;
|
|
40
|
-
<T extends GetAllPagesOperation>(opts: {
|
|
41
|
-
config?: P['config'];
|
|
42
|
-
preview?: boolean;
|
|
43
|
-
} & OperationOptions): Promise<T['data']>;
|
|
44
|
-
};
|
|
45
|
-
getPage: {
|
|
46
|
-
<T extends GetPageOperation>(opts: {
|
|
47
|
-
variables: T['variables'];
|
|
48
|
-
config?: P['config'];
|
|
49
|
-
preview?: boolean;
|
|
50
|
-
}): Promise<T['data']>;
|
|
51
|
-
<T extends GetPageOperation>(opts: {
|
|
52
|
-
variables: T['variables'];
|
|
53
|
-
config?: P['config'];
|
|
54
|
-
preview?: boolean;
|
|
55
|
-
} & OperationOptions): Promise<T['data']>;
|
|
56
|
-
};
|
|
57
|
-
getSiteInfo: {
|
|
58
|
-
<T extends GetSiteInfoOperation>(opts: {
|
|
59
|
-
config?: P['config'];
|
|
60
|
-
preview?: boolean;
|
|
61
|
-
}): Promise<T['data']>;
|
|
62
|
-
<T extends GetSiteInfoOperation>(opts: {
|
|
63
|
-
config?: P['config'];
|
|
64
|
-
preview?: boolean;
|
|
65
|
-
} & OperationOptions): Promise<T['data']>;
|
|
66
|
-
};
|
|
67
|
-
getCustomerWishlist: {
|
|
68
|
-
<T extends GetCustomerWishlistOperation>(opts: {
|
|
69
|
-
variables: T['variables'];
|
|
70
|
-
config?: P['config'];
|
|
71
|
-
includeProducts?: boolean;
|
|
72
|
-
}): Promise<T['data']>;
|
|
73
|
-
<T extends GetCustomerWishlistOperation>(opts: {
|
|
74
|
-
variables: T['variables'];
|
|
75
|
-
config?: P['config'];
|
|
76
|
-
includeProducts?: boolean;
|
|
77
|
-
} & OperationOptions): Promise<T['data']>;
|
|
78
|
-
};
|
|
79
|
-
getAllProductPaths: {
|
|
80
|
-
<T extends GetAllProductPathsOperation>(opts: {
|
|
81
|
-
variables?: T['variables'];
|
|
82
|
-
config?: P['config'];
|
|
83
|
-
}): Promise<T['data']>;
|
|
84
|
-
<T extends GetAllProductPathsOperation>(opts: {
|
|
85
|
-
variables?: T['variables'];
|
|
86
|
-
config?: P['config'];
|
|
87
|
-
} & OperationOptions): Promise<T['data']>;
|
|
88
|
-
};
|
|
89
|
-
getAllProducts: {
|
|
90
|
-
<T extends GetAllProductsOperation>(opts: {
|
|
91
|
-
variables?: T['variables'];
|
|
92
|
-
config?: P['config'];
|
|
93
|
-
preview?: boolean;
|
|
94
|
-
}): Promise<T['data']>;
|
|
95
|
-
<T extends GetAllProductsOperation>(opts: {
|
|
96
|
-
variables?: T['variables'];
|
|
97
|
-
config?: P['config'];
|
|
98
|
-
preview?: boolean;
|
|
99
|
-
} & OperationOptions): Promise<T['data']>;
|
|
100
|
-
};
|
|
101
|
-
getProduct: {
|
|
102
|
-
<T extends GetProductOperation>(opts: {
|
|
103
|
-
variables: T['variables'];
|
|
104
|
-
config?: P['config'];
|
|
105
|
-
preview?: boolean;
|
|
106
|
-
}): Promise<T['data']>;
|
|
107
|
-
<T extends GetProductOperation>(opts: {
|
|
108
|
-
variables: T['variables'];
|
|
109
|
-
config?: P['config'];
|
|
110
|
-
preview?: boolean;
|
|
111
|
-
} & OperationOptions): Promise<T['data']>;
|
|
112
|
-
};
|
|
113
|
-
};
|
|
114
|
-
export
|
|
115
|
-
[K in keyof Operations<P>]?: (ctx: OperationContext<P>) => Operations<P>[K];
|
|
116
|
-
};
|
|
117
|
-
export
|
|
118
|
-
[K in keyof APIOperations<P>]-?: P['operations'][K] extends (...args: any) => any ? ReturnType<P['operations'][K]> : typeof noop;
|
|
119
|
-
};
|
|
120
|
-
export
|
|
121
|
-
commerce: CommerceAPI<P>;
|
|
122
|
-
};
|
|
123
|
-
export
|
|
124
|
-
query: string;
|
|
125
|
-
url?: never;
|
|
126
|
-
} | {
|
|
127
|
-
query?: never;
|
|
128
|
-
url: string;
|
|
129
|
-
};
|
|
130
|
-
export {};
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { ServerResponse } from 'http';
|
|
3
|
+
import type { LoginOperation } from '../types/login';
|
|
4
|
+
import type { GetAllPagesOperation, GetPageOperation } from '../types/page';
|
|
5
|
+
import type { GetSiteInfoOperation } from '../types/site';
|
|
6
|
+
import type { GetCustomerWishlistOperation } from '../types/wishlist';
|
|
7
|
+
import type { GetAllProductPathsOperation, GetAllProductsOperation, GetProductOperation } from '../types/product';
|
|
8
|
+
import type { APIProvider, CommerceAPI } from '.';
|
|
9
|
+
declare const noop: () => never;
|
|
10
|
+
export declare const OPERATIONS: readonly ["login", "getAllPages", "getPage", "getSiteInfo", "getCustomerWishlist", "getAllProductPaths", "getAllProducts", "getProduct"];
|
|
11
|
+
export declare const defaultOperations: {
|
|
12
|
+
login: () => never;
|
|
13
|
+
getAllPages: () => never;
|
|
14
|
+
getPage: () => never;
|
|
15
|
+
getSiteInfo: () => never;
|
|
16
|
+
getCustomerWishlist: () => never;
|
|
17
|
+
getAllProductPaths: () => never;
|
|
18
|
+
getAllProducts: () => never;
|
|
19
|
+
getProduct: () => never;
|
|
20
|
+
};
|
|
21
|
+
export type AllowedOperations = typeof OPERATIONS[number];
|
|
22
|
+
export type Operations<P extends APIProvider> = {
|
|
23
|
+
login: {
|
|
24
|
+
<T extends LoginOperation>(opts: {
|
|
25
|
+
variables: T['variables'];
|
|
26
|
+
config?: P['config'];
|
|
27
|
+
res: ServerResponse;
|
|
28
|
+
}): Promise<T['data']>;
|
|
29
|
+
<T extends LoginOperation>(opts: {
|
|
30
|
+
variables: T['variables'];
|
|
31
|
+
config?: P['config'];
|
|
32
|
+
res: ServerResponse;
|
|
33
|
+
} & OperationOptions): Promise<T['data']>;
|
|
34
|
+
};
|
|
35
|
+
getAllPages: {
|
|
36
|
+
<T extends GetAllPagesOperation>(opts?: {
|
|
37
|
+
config?: P['config'];
|
|
38
|
+
preview?: boolean;
|
|
39
|
+
}): Promise<T['data']>;
|
|
40
|
+
<T extends GetAllPagesOperation>(opts: {
|
|
41
|
+
config?: P['config'];
|
|
42
|
+
preview?: boolean;
|
|
43
|
+
} & OperationOptions): Promise<T['data']>;
|
|
44
|
+
};
|
|
45
|
+
getPage: {
|
|
46
|
+
<T extends GetPageOperation>(opts: {
|
|
47
|
+
variables: T['variables'];
|
|
48
|
+
config?: P['config'];
|
|
49
|
+
preview?: boolean;
|
|
50
|
+
}): Promise<T['data']>;
|
|
51
|
+
<T extends GetPageOperation>(opts: {
|
|
52
|
+
variables: T['variables'];
|
|
53
|
+
config?: P['config'];
|
|
54
|
+
preview?: boolean;
|
|
55
|
+
} & OperationOptions): Promise<T['data']>;
|
|
56
|
+
};
|
|
57
|
+
getSiteInfo: {
|
|
58
|
+
<T extends GetSiteInfoOperation>(opts: {
|
|
59
|
+
config?: P['config'];
|
|
60
|
+
preview?: boolean;
|
|
61
|
+
}): Promise<T['data']>;
|
|
62
|
+
<T extends GetSiteInfoOperation>(opts: {
|
|
63
|
+
config?: P['config'];
|
|
64
|
+
preview?: boolean;
|
|
65
|
+
} & OperationOptions): Promise<T['data']>;
|
|
66
|
+
};
|
|
67
|
+
getCustomerWishlist: {
|
|
68
|
+
<T extends GetCustomerWishlistOperation>(opts: {
|
|
69
|
+
variables: T['variables'];
|
|
70
|
+
config?: P['config'];
|
|
71
|
+
includeProducts?: boolean;
|
|
72
|
+
}): Promise<T['data']>;
|
|
73
|
+
<T extends GetCustomerWishlistOperation>(opts: {
|
|
74
|
+
variables: T['variables'];
|
|
75
|
+
config?: P['config'];
|
|
76
|
+
includeProducts?: boolean;
|
|
77
|
+
} & OperationOptions): Promise<T['data']>;
|
|
78
|
+
};
|
|
79
|
+
getAllProductPaths: {
|
|
80
|
+
<T extends GetAllProductPathsOperation>(opts: {
|
|
81
|
+
variables?: T['variables'];
|
|
82
|
+
config?: P['config'];
|
|
83
|
+
}): Promise<T['data']>;
|
|
84
|
+
<T extends GetAllProductPathsOperation>(opts: {
|
|
85
|
+
variables?: T['variables'];
|
|
86
|
+
config?: P['config'];
|
|
87
|
+
} & OperationOptions): Promise<T['data']>;
|
|
88
|
+
};
|
|
89
|
+
getAllProducts: {
|
|
90
|
+
<T extends GetAllProductsOperation>(opts: {
|
|
91
|
+
variables?: T['variables'];
|
|
92
|
+
config?: P['config'];
|
|
93
|
+
preview?: boolean;
|
|
94
|
+
}): Promise<T['data']>;
|
|
95
|
+
<T extends GetAllProductsOperation>(opts: {
|
|
96
|
+
variables?: T['variables'];
|
|
97
|
+
config?: P['config'];
|
|
98
|
+
preview?: boolean;
|
|
99
|
+
} & OperationOptions): Promise<T['data']>;
|
|
100
|
+
};
|
|
101
|
+
getProduct: {
|
|
102
|
+
<T extends GetProductOperation>(opts: {
|
|
103
|
+
variables: T['variables'];
|
|
104
|
+
config?: P['config'];
|
|
105
|
+
preview?: boolean;
|
|
106
|
+
}): Promise<T['data']>;
|
|
107
|
+
<T extends GetProductOperation>(opts: {
|
|
108
|
+
variables: T['variables'];
|
|
109
|
+
config?: P['config'];
|
|
110
|
+
preview?: boolean;
|
|
111
|
+
} & OperationOptions): Promise<T['data']>;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
export type APIOperations<P extends APIProvider> = {
|
|
115
|
+
[K in keyof Operations<P>]?: (ctx: OperationContext<P>) => Operations<P>[K];
|
|
116
|
+
};
|
|
117
|
+
export type AllOperations<P extends APIProvider> = {
|
|
118
|
+
[K in keyof APIOperations<P>]-?: P['operations'][K] extends (...args: any) => any ? ReturnType<P['operations'][K]> : typeof noop;
|
|
119
|
+
};
|
|
120
|
+
export type OperationContext<P extends APIProvider> = {
|
|
121
|
+
commerce: CommerceAPI<P>;
|
|
122
|
+
};
|
|
123
|
+
export type OperationOptions = {
|
|
124
|
+
query: string;
|
|
125
|
+
url?: never;
|
|
126
|
+
} | {
|
|
127
|
+
query?: never;
|
|
128
|
+
url: string;
|
|
129
|
+
};
|
|
130
|
+
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { Response } from '@vercel/fetch';
|
|
2
|
-
export declare class CommerceAPIError extends Error {
|
|
3
|
-
status: number;
|
|
4
|
-
res: Response;
|
|
5
|
-
data: any;
|
|
6
|
-
constructor(msg: string, res: Response, data?: any);
|
|
7
|
-
}
|
|
8
|
-
export declare class CommerceNetworkError extends Error {
|
|
9
|
-
constructor(msg: string);
|
|
10
|
-
}
|
|
1
|
+
import type { Response } from '@vercel/fetch';
|
|
2
|
+
export declare class CommerceAPIError extends Error {
|
|
3
|
+
status: number;
|
|
4
|
+
res: Response;
|
|
5
|
+
data: any;
|
|
6
|
+
constructor(msg: string, res: Response, data?: any);
|
|
7
|
+
}
|
|
8
|
+
export declare class CommerceNetworkError extends Error {
|
|
9
|
+
constructor(msg: string);
|
|
10
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
-
export
|
|
3
|
-
export default function isAllowedMethod(req: NextApiRequest, res: NextApiResponse, allowedMethods: HTTP_METHODS[]): boolean;
|
|
1
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
+
export type HTTP_METHODS = 'OPTIONS' | 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
3
|
+
export default function isAllowedMethod(req: NextApiRequest, res: NextApiResponse, allowedMethods: HTTP_METHODS[]): boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
-
import { HTTP_METHODS } from './is-allowed-method';
|
|
3
|
-
import { APIHandler } from './types';
|
|
4
|
-
export default function isAllowedOperation(req: NextApiRequest, res: NextApiResponse, allowedOperations: {
|
|
5
|
-
[k in HTTP_METHODS]?: APIHandler<any, any>;
|
|
6
|
-
}): boolean;
|
|
1
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
+
import { HTTP_METHODS } from './is-allowed-method';
|
|
3
|
+
import { APIHandler } from './types';
|
|
4
|
+
export default function isAllowedOperation(req: NextApiRequest, res: NextApiResponse, allowedOperations: {
|
|
5
|
+
[k in HTTP_METHODS]?: APIHandler<any, any>;
|
|
6
|
+
}): boolean;
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
-
import type { CommerceAPI } from '..';
|
|
3
|
-
export
|
|
4
|
-
message: string;
|
|
5
|
-
code?: string;
|
|
6
|
-
};
|
|
7
|
-
export
|
|
8
|
-
data: Data;
|
|
9
|
-
errors?: ErrorData[];
|
|
10
|
-
} | (Data extends null ? {
|
|
11
|
-
data: null;
|
|
12
|
-
errors?: ErrorData[];
|
|
13
|
-
} : {
|
|
14
|
-
data: null;
|
|
15
|
-
errors: ErrorData[];
|
|
16
|
-
});
|
|
17
|
-
export
|
|
18
|
-
req: NextApiRequest;
|
|
19
|
-
res: NextApiResponse<APIResponse<Data>>;
|
|
20
|
-
commerce: C;
|
|
21
|
-
config: C['provider']['config'];
|
|
22
|
-
handlers: H;
|
|
23
|
-
/**
|
|
24
|
-
* Custom configs that may be used by a particular handler
|
|
25
|
-
*/
|
|
26
|
-
options: Options;
|
|
27
|
-
};
|
|
28
|
-
export
|
|
29
|
-
body: Body;
|
|
30
|
-
}) => void | Promise<void>;
|
|
31
|
-
export
|
|
32
|
-
[k: string]: APIHandler<C, any, any, any, any>;
|
|
33
|
-
};
|
|
34
|
-
export
|
|
1
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
+
import type { CommerceAPI } from '..';
|
|
3
|
+
export type ErrorData = {
|
|
4
|
+
message: string;
|
|
5
|
+
code?: string;
|
|
6
|
+
};
|
|
7
|
+
export type APIResponse<Data = any> = {
|
|
8
|
+
data: Data;
|
|
9
|
+
errors?: ErrorData[];
|
|
10
|
+
} | (Data extends null ? {
|
|
11
|
+
data: null;
|
|
12
|
+
errors?: ErrorData[];
|
|
13
|
+
} : {
|
|
14
|
+
data: null;
|
|
15
|
+
errors: ErrorData[];
|
|
16
|
+
});
|
|
17
|
+
export type APIHandlerContext<C extends CommerceAPI, H extends APIHandlers<C> = {}, Data = any, Options extends {} = {}> = {
|
|
18
|
+
req: NextApiRequest;
|
|
19
|
+
res: NextApiResponse<APIResponse<Data>>;
|
|
20
|
+
commerce: C;
|
|
21
|
+
config: C['provider']['config'];
|
|
22
|
+
handlers: H;
|
|
23
|
+
/**
|
|
24
|
+
* Custom configs that may be used by a particular handler
|
|
25
|
+
*/
|
|
26
|
+
options: Options;
|
|
27
|
+
};
|
|
28
|
+
export type APIHandler<C extends CommerceAPI, H extends APIHandlers<C> = {}, Data = any, Body = any, Options extends {} = {}> = (context: APIHandlerContext<C, H, Data, Options> & {
|
|
29
|
+
body: Body;
|
|
30
|
+
}) => void | Promise<void>;
|
|
31
|
+
export type APIHandlers<C extends CommerceAPI> = {
|
|
32
|
+
[k: string]: APIHandler<C, any, any, any, any>;
|
|
33
|
+
};
|
|
34
|
+
export type APIEndpoint<C extends CommerceAPI = CommerceAPI, H extends APIHandlers<C> = {}, Data = any, Options extends {} = {}> = (context: APIHandlerContext<C, H, Data, Options>) => void | Promise<void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { MutationHook } from '../utils/types';
|
|
2
|
-
import type { AddItemHook } from '../types/cart';
|
|
3
|
-
export
|
|
4
|
-
declare const useAddItem: UseAddItem;
|
|
5
|
-
export default useAddItem;
|
|
1
|
+
import type { MutationHook } from '../utils/types';
|
|
2
|
+
import type { AddItemHook } from '../types/cart';
|
|
3
|
+
export type UseAddItem<H extends MutationHook<AddItemHook<any>> = MutationHook<AddItemHook>> = ReturnType<H['useHook']>;
|
|
4
|
+
declare const useAddItem: UseAddItem;
|
|
5
|
+
export default useAddItem;
|
package/dist/cart/use-cart.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SWRHook } from '../utils/types';
|
|
2
|
-
import type { GetCartHook } from '../types/cart';
|
|
3
|
-
export
|
|
4
|
-
declare const useCart: UseCart;
|
|
5
|
-
export default useCart;
|
|
1
|
+
import type { SWRHook } from '../utils/types';
|
|
2
|
+
import type { GetCartHook } from '../types/cart';
|
|
3
|
+
export type UseCart<H extends SWRHook<GetCartHook<any>> = SWRHook<GetCartHook>> = ReturnType<H['useHook']>;
|
|
4
|
+
declare const useCart: UseCart;
|
|
5
|
+
export default useCart;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { MutationHook } from '../utils/types';
|
|
2
|
-
import type { RemoveItemHook } from '../types/cart';
|
|
3
|
-
export
|
|
4
|
-
declare const useRemoveItem: UseRemoveItem;
|
|
5
|
-
export default useRemoveItem;
|
|
1
|
+
import type { MutationHook } from '../utils/types';
|
|
2
|
+
import type { RemoveItemHook } from '../types/cart';
|
|
3
|
+
export type UseRemoveItem<H extends MutationHook<RemoveItemHook<any>> = MutationHook<RemoveItemHook>> = ReturnType<H['useHook']>;
|
|
4
|
+
declare const useRemoveItem: UseRemoveItem;
|
|
5
|
+
export default useRemoveItem;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { MutationHook } from '../utils/types';
|
|
2
|
-
import type { UpdateItemHook } from '../types/cart';
|
|
3
|
-
export
|
|
4
|
-
declare const useUpdateItem: UseUpdateItem;
|
|
5
|
-
export default useUpdateItem;
|
|
1
|
+
import type { MutationHook } from '../utils/types';
|
|
2
|
+
import type { UpdateItemHook } from '../types/cart';
|
|
3
|
+
export type UseUpdateItem<H extends MutationHook<UpdateItemHook<any>> = MutationHook<UpdateItemHook>> = ReturnType<H['useHook']>;
|
|
4
|
+
declare const useUpdateItem: UseUpdateItem;
|
|
5
|
+
export default useUpdateItem;
|