@plasmicpkgs/commerce 0.0.1 → 0.0.2

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.
Files changed (116) hide show
  1. package/README.md +1 -0
  2. package/dist/api/endpoints/cart.d.ts +4 -0
  3. package/dist/api/endpoints/catalog/products.d.ts +4 -0
  4. package/dist/api/index.d.ts +75 -0
  5. package/dist/api/operations.d.ts +130 -0
  6. package/dist/api/utils/errors.d.ts +10 -0
  7. package/dist/api/utils/is-allowed-method.d.ts +3 -0
  8. package/dist/api/utils/is-allowed-operation.d.ts +6 -0
  9. package/dist/api/utils/types.d.ts +34 -0
  10. package/dist/cart/use-add-item.d.ts +5 -6
  11. package/dist/cart/use-cart.d.ts +5 -6
  12. package/dist/cart/use-remove-item.d.ts +5 -6
  13. package/dist/cart/use-update-item.d.ts +5 -6
  14. package/dist/commerce.cjs.development.js +1851 -0
  15. package/dist/commerce.cjs.development.js.map +1 -0
  16. package/dist/commerce.cjs.production.min.js +2 -0
  17. package/dist/commerce.cjs.production.min.js.map +1 -0
  18. package/dist/commerce.d.ts +37 -0
  19. package/dist/commerce.esm.js +1828 -0
  20. package/dist/commerce.esm.js.map +1 -0
  21. package/dist/contexts.d.ts +10 -7
  22. package/dist/index.d.ts +21 -71
  23. package/dist/index.js +7 -28
  24. package/dist/product/use-price.d.ts +26 -26
  25. package/dist/product/use-search.d.ts +6 -6
  26. package/dist/registerAddToCartButton.d.ts +10 -0
  27. package/dist/registerProductCollection.d.ts +13 -11
  28. package/dist/registerProductMedia.d.ts +12 -0
  29. package/dist/registerProductPrice.d.ts +9 -0
  30. package/dist/registerProductQuantity.d.ts +11 -0
  31. package/dist/registerProductTextField.d.ts +10 -0
  32. package/dist/registerProductVariantPicker.d.ts +9 -0
  33. package/dist/registerUseCart.d.ts +9 -0
  34. package/dist/registerable.d.ts +4 -4
  35. package/dist/types/cart.d.ts +157 -157
  36. package/dist/types/checkout.d.ts +57 -57
  37. package/dist/types/common.d.ts +13 -13
  38. package/dist/types/customer/address.d.ts +110 -110
  39. package/dist/types/customer/card.d.ts +113 -113
  40. package/dist/types/customer/index.d.ts +24 -24
  41. package/dist/types/index.d.ts +12 -12
  42. package/dist/types/login.d.ts +27 -27
  43. package/dist/types/logout.d.ts +17 -17
  44. package/dist/types/page.d.ts +24 -24
  45. package/dist/types/product.d.ts +102 -99
  46. package/dist/types/signup.d.ts +23 -23
  47. package/dist/types/site.d.ts +17 -17
  48. package/dist/types/wishlist.d.ts +83 -83
  49. package/dist/utils/default-fetcher.d.ts +4 -4
  50. package/dist/utils/define-property.d.ts +21 -21
  51. package/dist/utils/errors.d.ts +27 -27
  52. package/dist/utils/get-product-price.d.ts +2 -0
  53. package/dist/utils/types.d.ts +95 -94
  54. package/dist/utils/use-data.d.ts +12 -12
  55. package/dist/utils/use-hook.d.ts +6 -6
  56. package/package.json +13 -13
  57. package/dist/auth/use-login.d.ts +0 -6
  58. package/dist/auth/use-login.js +0 -9
  59. package/dist/auth/use-logout.d.ts +0 -6
  60. package/dist/auth/use-logout.js +0 -9
  61. package/dist/auth/use-signup.d.ts +0 -6
  62. package/dist/auth/use-signup.js +0 -9
  63. package/dist/cart/use-add-item.js +0 -9
  64. package/dist/cart/use-cart.js +0 -18
  65. package/dist/cart/use-remove-item.js +0 -9
  66. package/dist/cart/use-update-item.js +0 -9
  67. package/dist/checkout/use-checkout.d.ts +0 -6
  68. package/dist/checkout/use-checkout.js +0 -18
  69. package/dist/checkout/use-submit-checkout.d.ts +0 -6
  70. package/dist/checkout/use-submit-checkout.js +0 -9
  71. package/dist/contexts.js +0 -46
  72. package/dist/customer/address/use-add-item.d.ts +0 -6
  73. package/dist/customer/address/use-add-item.js +0 -9
  74. package/dist/customer/address/use-addresses.d.ts +0 -6
  75. package/dist/customer/address/use-addresses.js +0 -18
  76. package/dist/customer/address/use-remove-item.d.ts +0 -6
  77. package/dist/customer/address/use-remove-item.js +0 -9
  78. package/dist/customer/address/use-update-item.d.ts +0 -6
  79. package/dist/customer/address/use-update-item.js +0 -9
  80. package/dist/customer/card/use-add-item.d.ts +0 -6
  81. package/dist/customer/card/use-add-item.js +0 -9
  82. package/dist/customer/card/use-cards.d.ts +0 -6
  83. package/dist/customer/card/use-cards.js +0 -18
  84. package/dist/customer/card/use-remove-item.d.ts +0 -6
  85. package/dist/customer/card/use-remove-item.js +0 -9
  86. package/dist/customer/card/use-update-item.d.ts +0 -6
  87. package/dist/customer/card/use-update-item.js +0 -9
  88. package/dist/customer/use-customer.d.ts +0 -6
  89. package/dist/customer/use-customer.js +0 -9
  90. package/dist/product/use-price.js +0 -33
  91. package/dist/product/use-search.js +0 -9
  92. package/dist/registerProductCollection.js +0 -42
  93. package/dist/registerProductImage.d.ts +0 -13
  94. package/dist/registerProductImage.js +0 -37
  95. package/dist/registerable.js +0 -0
  96. package/dist/tsconfig.tsbuildinfo +0 -2970
  97. package/dist/types/cart.js +0 -0
  98. package/dist/types/checkout.js +0 -0
  99. package/dist/types/common.js +0 -0
  100. package/dist/types/customer/address.js +0 -0
  101. package/dist/types/customer/card.js +0 -0
  102. package/dist/types/customer/index.js +0 -2
  103. package/dist/types/index.js +0 -11
  104. package/dist/types/login.js +0 -0
  105. package/dist/types/logout.js +0 -0
  106. package/dist/types/page.js +0 -0
  107. package/dist/types/product.js +0 -0
  108. package/dist/types/signup.js +0 -0
  109. package/dist/types/site.js +0 -0
  110. package/dist/types/wishlist.js +0 -0
  111. package/dist/utils/default-fetcher.js +0 -3
  112. package/dist/utils/define-property.js +0 -4
  113. package/dist/utils/errors.js +0 -24
  114. package/dist/utils/types.js +0 -0
  115. package/dist/utils/use-data.js +0 -43
  116. package/dist/utils/use-hook.js +0 -37
package/README.md CHANGED
@@ -0,0 +1 @@
1
+ Plasmic registration calls for commerce components
@@ -0,0 +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;
@@ -0,0 +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;
@@ -0,0 +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 declare type APISchemas = CartSchema | CustomerSchema | LoginSchema | LogoutSchema | SignupSchema | ProductsSchema | WishlistSchema | CheckoutSchema | CustomerCardSchema | CustomerAddressSchema;
16
+ export declare type GetAPISchema<C extends CommerceAPI<any>, S extends APISchemas = APISchemas> = {
17
+ schema: S;
18
+ endpoint: EndpointContext<C, S['endpoint']>;
19
+ };
20
+ export declare type EndpointContext<C extends CommerceAPI, E extends EndpointSchemaBase> = {
21
+ handler: Endpoint<C, E>;
22
+ handlers: EndpointHandlers<C, E>;
23
+ };
24
+ export declare type EndpointSchemaBase = {
25
+ options: {};
26
+ handlers: {
27
+ [k: string]: {
28
+ data?: any;
29
+ body?: any;
30
+ };
31
+ };
32
+ };
33
+ export declare type Endpoint<C extends CommerceAPI, E extends EndpointSchemaBase> = APIEndpoint<C, EndpointHandlers<C, E>, any, E['options']>;
34
+ export declare 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 declare type APIProvider = {
38
+ config: CommerceAPIConfig;
39
+ operations: APIOperations<any>;
40
+ };
41
+ export declare 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 declare 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
+ }
@@ -0,0 +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 declare type AllowedOperations = typeof OPERATIONS[number];
22
+ export declare 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 declare type APIOperations<P extends APIProvider> = {
115
+ [K in keyof Operations<P>]?: (ctx: OperationContext<P>) => Operations<P>[K];
116
+ };
117
+ export declare 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 declare type OperationContext<P extends APIProvider> = {
121
+ commerce: CommerceAPI<P>;
122
+ };
123
+ export declare type OperationOptions = {
124
+ query: string;
125
+ url?: never;
126
+ } | {
127
+ query?: never;
128
+ url: string;
129
+ };
130
+ export {};
@@ -0,0 +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
+ }
@@ -0,0 +1,3 @@
1
+ import type { NextApiRequest, NextApiResponse } from 'next';
2
+ export declare type HTTP_METHODS = 'OPTIONS' | 'GET' | 'POST' | 'PUT' | 'DELETE';
3
+ export default function isAllowedMethod(req: NextApiRequest, res: NextApiResponse, allowedMethods: HTTP_METHODS[]): boolean;
@@ -0,0 +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;
@@ -0,0 +1,34 @@
1
+ import type { NextApiRequest, NextApiResponse } from 'next';
2
+ import type { CommerceAPI } from '..';
3
+ export declare type ErrorData = {
4
+ message: string;
5
+ code?: string;
6
+ };
7
+ export declare 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 declare 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 declare 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 declare type APIHandlers<C extends CommerceAPI> = {
32
+ [k: string]: APIHandler<C, any, any, any, any>;
33
+ };
34
+ export declare type APIEndpoint<C extends CommerceAPI = CommerceAPI, H extends APIHandlers<C> = {}, Data = any, Options extends {} = {}> = (context: APIHandlerContext<C, H, Data, Options>) => void | Promise<void>;
@@ -1,6 +1,5 @@
1
- import type { HookFetcherFn, MutationHook } from '../utils/types';
2
- import type { AddItemHook } from '../types/cart';
3
- export declare type UseAddItem<H extends MutationHook<AddItemHook<any>> = MutationHook<AddItemHook>> = ReturnType<H['useHook']>;
4
- export declare const fetcher: HookFetcherFn<AddItemHook>;
5
- declare const useAddItem: UseAddItem;
6
- export default useAddItem;
1
+ import type { MutationHook } from '../utils/types';
2
+ import type { AddItemHook } from '../types/cart';
3
+ export declare type UseAddItem<H extends MutationHook<AddItemHook<any>> = MutationHook<AddItemHook>> = ReturnType<H['useHook']>;
4
+ declare const useAddItem: UseAddItem;
5
+ export default useAddItem;
@@ -1,6 +1,5 @@
1
- import type { SWRHook, HookFetcherFn } from '../utils/types';
2
- import type { GetCartHook } from '../types/cart';
3
- export declare type UseCart<H extends SWRHook<GetCartHook<any>> = SWRHook<GetCartHook>> = ReturnType<H['useHook']>;
4
- export declare const fetcher: HookFetcherFn<GetCartHook>;
5
- declare const useCart: UseCart;
6
- export default useCart;
1
+ import type { SWRHook } from '../utils/types';
2
+ import type { GetCartHook } from '../types/cart';
3
+ export declare type UseCart<H extends SWRHook<GetCartHook<any>> = SWRHook<GetCartHook>> = ReturnType<H['useHook']>;
4
+ declare const useCart: UseCart;
5
+ export default useCart;
@@ -1,6 +1,5 @@
1
- import type { HookFetcherFn, MutationHook } from '../utils/types';
2
- import type { RemoveItemHook } from '../types/cart';
3
- export declare type UseRemoveItem<H extends MutationHook<RemoveItemHook<any>> = MutationHook<RemoveItemHook>> = ReturnType<H['useHook']>;
4
- export declare const fetcher: HookFetcherFn<RemoveItemHook>;
5
- declare const useRemoveItem: UseRemoveItem;
6
- export default useRemoveItem;
1
+ import type { MutationHook } from '../utils/types';
2
+ import type { RemoveItemHook } from '../types/cart';
3
+ export declare type UseRemoveItem<H extends MutationHook<RemoveItemHook<any>> = MutationHook<RemoveItemHook>> = ReturnType<H['useHook']>;
4
+ declare const useRemoveItem: UseRemoveItem;
5
+ export default useRemoveItem;
@@ -1,6 +1,5 @@
1
- import type { HookFetcherFn, MutationHook } from '../utils/types';
2
- import type { UpdateItemHook } from '../types/cart';
3
- export declare type UseUpdateItem<H extends MutationHook<UpdateItemHook<any>> = MutationHook<UpdateItemHook>> = ReturnType<H['useHook']>;
4
- export declare const fetcher: HookFetcherFn<UpdateItemHook>;
5
- declare const useUpdateItem: UseUpdateItem;
6
- export default useUpdateItem;
1
+ import type { MutationHook } from '../utils/types';
2
+ import type { UpdateItemHook } from '../types/cart';
3
+ export declare type UseUpdateItem<H extends MutationHook<UpdateItemHook<any>> = MutationHook<UpdateItemHook>> = ReturnType<H['useHook']>;
4
+ declare const useUpdateItem: UseUpdateItem;
5
+ export default useUpdateItem;