@plasmicpkgs/commerce 0.0.1 → 0.0.5

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 (118) 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 +1933 -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 +41 -0
  19. package/dist/commerce.esm.js +1908 -0
  20. package/dist/commerce.esm.js.map +1 -0
  21. package/dist/contexts.d.ts +10 -7
  22. package/dist/index.d.ts +25 -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 +9 -0
  27. package/dist/registerProductCollection.d.ts +18 -11
  28. package/dist/registerProductMedia.d.ts +10 -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/site/use-brands.d.ts +5 -0
  36. package/dist/site/use-categories.d.ts +5 -0
  37. package/dist/types/cart.d.ts +157 -157
  38. package/dist/types/checkout.d.ts +57 -57
  39. package/dist/types/common.d.ts +13 -13
  40. package/dist/types/customer/address.d.ts +110 -110
  41. package/dist/types/customer/card.d.ts +113 -113
  42. package/dist/types/customer/index.d.ts +24 -24
  43. package/dist/types/index.d.ts +12 -12
  44. package/dist/types/login.d.ts +27 -27
  45. package/dist/types/logout.d.ts +17 -17
  46. package/dist/types/page.d.ts +24 -24
  47. package/dist/types/product.d.ts +102 -99
  48. package/dist/types/signup.d.ts +23 -23
  49. package/dist/types/site.d.ts +41 -17
  50. package/dist/types/wishlist.d.ts +83 -83
  51. package/dist/utils/default-fetcher.d.ts +4 -4
  52. package/dist/utils/define-property.d.ts +21 -21
  53. package/dist/utils/errors.d.ts +27 -27
  54. package/dist/utils/get-product-price.d.ts +2 -0
  55. package/dist/utils/types.d.ts +95 -94
  56. package/dist/utils/use-data.d.ts +12 -12
  57. package/dist/utils/use-hook.d.ts +6 -6
  58. package/package.json +13 -13
  59. package/dist/auth/use-login.d.ts +0 -6
  60. package/dist/auth/use-login.js +0 -9
  61. package/dist/auth/use-logout.d.ts +0 -6
  62. package/dist/auth/use-logout.js +0 -9
  63. package/dist/auth/use-signup.d.ts +0 -6
  64. package/dist/auth/use-signup.js +0 -9
  65. package/dist/cart/use-add-item.js +0 -9
  66. package/dist/cart/use-cart.js +0 -18
  67. package/dist/cart/use-remove-item.js +0 -9
  68. package/dist/cart/use-update-item.js +0 -9
  69. package/dist/checkout/use-checkout.d.ts +0 -6
  70. package/dist/checkout/use-checkout.js +0 -18
  71. package/dist/checkout/use-submit-checkout.d.ts +0 -6
  72. package/dist/checkout/use-submit-checkout.js +0 -9
  73. package/dist/contexts.js +0 -46
  74. package/dist/customer/address/use-add-item.d.ts +0 -6
  75. package/dist/customer/address/use-add-item.js +0 -9
  76. package/dist/customer/address/use-addresses.d.ts +0 -6
  77. package/dist/customer/address/use-addresses.js +0 -18
  78. package/dist/customer/address/use-remove-item.d.ts +0 -6
  79. package/dist/customer/address/use-remove-item.js +0 -9
  80. package/dist/customer/address/use-update-item.d.ts +0 -6
  81. package/dist/customer/address/use-update-item.js +0 -9
  82. package/dist/customer/card/use-add-item.d.ts +0 -6
  83. package/dist/customer/card/use-add-item.js +0 -9
  84. package/dist/customer/card/use-cards.d.ts +0 -6
  85. package/dist/customer/card/use-cards.js +0 -18
  86. package/dist/customer/card/use-remove-item.d.ts +0 -6
  87. package/dist/customer/card/use-remove-item.js +0 -9
  88. package/dist/customer/card/use-update-item.d.ts +0 -6
  89. package/dist/customer/card/use-update-item.js +0 -9
  90. package/dist/customer/use-customer.d.ts +0 -6
  91. package/dist/customer/use-customer.js +0 -9
  92. package/dist/product/use-price.js +0 -33
  93. package/dist/product/use-search.js +0 -9
  94. package/dist/registerProductCollection.js +0 -42
  95. package/dist/registerProductImage.d.ts +0 -13
  96. package/dist/registerProductImage.js +0 -37
  97. package/dist/registerable.js +0 -0
  98. package/dist/tsconfig.tsbuildinfo +0 -2970
  99. package/dist/types/cart.js +0 -0
  100. package/dist/types/checkout.js +0 -0
  101. package/dist/types/common.js +0 -0
  102. package/dist/types/customer/address.js +0 -0
  103. package/dist/types/customer/card.js +0 -0
  104. package/dist/types/customer/index.js +0 -2
  105. package/dist/types/index.js +0 -11
  106. package/dist/types/login.js +0 -0
  107. package/dist/types/logout.js +0 -0
  108. package/dist/types/page.js +0 -0
  109. package/dist/types/product.js +0 -0
  110. package/dist/types/signup.js +0 -0
  111. package/dist/types/site.js +0 -0
  112. package/dist/types/wishlist.js +0 -0
  113. package/dist/utils/default-fetcher.js +0 -3
  114. package/dist/utils/define-property.js +0 -4
  115. package/dist/utils/errors.js +0 -24
  116. package/dist/utils/types.js +0 -0
  117. package/dist/utils/use-data.js +0 -43
  118. package/dist/utils/use-hook.js +0 -37
@@ -1,94 +1,95 @@
1
- import type { SWRConfiguration } from 'swr';
2
- import type { CommerceError } from './errors';
3
- import type { ResponseState } from './use-data';
4
- /**
5
- * Returns the properties in T with the properties in type K, overriding properties defined in T
6
- */
7
- export declare type Override<T, K> = Omit<T, keyof K> & K;
8
- /**
9
- * Returns the properties in T with the properties in type K changed from optional to required
10
- */
11
- export declare type PickRequired<T, K extends keyof T> = Omit<T, K> & {
12
- [P in K]-?: NonNullable<T[P]>;
13
- };
14
- /**
15
- * Core fetcher added by CommerceProvider
16
- */
17
- export declare type Fetcher<T = any, B = any> = (options: FetcherOptions<B>) => T | Promise<T>;
18
- export declare type FetcherOptions<Body = any> = {
19
- url?: string;
20
- query?: string;
21
- method?: string;
22
- variables?: any;
23
- body?: Body;
24
- };
25
- export declare type HookFetcher<Data, Input = null, Result = any> = (options: HookFetcherOptions | null, input: Input, fetch: <T = Result, Body = any>(options: FetcherOptions<Body>) => Promise<T>) => Data | Promise<Data>;
26
- export declare type HookFetcherFn<H extends HookSchemaBase> = (context: HookFetcherContext<H>) => H['data'] | Promise<H['data']>;
27
- export declare type HookFetcherContext<H extends HookSchemaBase> = {
28
- options: HookFetcherOptions;
29
- input: H['fetcherInput'];
30
- fetch: <T = H['fetchData'] extends {} | null ? H['fetchData'] : any, B = H['body']>(options: FetcherOptions<B>) => Promise<T>;
31
- };
32
- export declare type HookFetcherOptions = {
33
- method?: string;
34
- } & ({
35
- query: string;
36
- url?: string;
37
- } | {
38
- query?: string;
39
- url: string;
40
- });
41
- export declare type HookInputValue = string | number | boolean | undefined;
42
- export declare type HookSWRInput = [string, HookInputValue][];
43
- export declare type HookFetchInput = {
44
- [k: string]: HookInputValue;
45
- };
46
- export declare type HookFunction<Input extends {
47
- [k: string]: unknown;
48
- } | undefined, T> = keyof Input extends never ? () => T : Partial<Input> extends Input ? (input?: Input) => T : (input: Input) => T;
49
- export declare type HookSchemaBase = {
50
- data: any;
51
- input?: {};
52
- fetcherInput?: {};
53
- body?: {};
54
- fetchData?: any;
55
- };
56
- export declare type SWRHookSchemaBase = HookSchemaBase & {
57
- swrState?: {};
58
- mutations?: Record<string, ReturnType<MutationHook<any>['useHook']>>;
59
- };
60
- export declare type MutationSchemaBase = HookSchemaBase & {
61
- actionInput?: {};
62
- };
63
- /**
64
- * Generates a SWR hook handler based on the schema of a hook
65
- */
66
- export declare type SWRHook<H extends SWRHookSchemaBase> = {
67
- useHook(context: SWRHookContext<H>): HookFunction<H['input'] & {
68
- swrOptions?: SwrOptions<H['data'], H['fetcherInput']>;
69
- }, ResponseState<H['data']> & H['swrState'] & H['mutations']>;
70
- fetchOptions: HookFetcherOptions;
71
- fetcher?: HookFetcherFn<H>;
72
- };
73
- export declare type SWRHookContext<H extends SWRHookSchemaBase> = {
74
- useData(context?: {
75
- input?: HookFetchInput | HookSWRInput;
76
- swrOptions?: SwrOptions<H['data'], H['fetcherInput']>;
77
- }): ResponseState<H['data']>;
78
- };
79
- /**
80
- * Generates a mutation hook handler based on the schema of a hook
81
- */
82
- export declare type MutationHook<H extends MutationSchemaBase> = {
83
- useHook(context: MutationHookContext<H>): HookFunction<H['input'], HookFunction<H['actionInput'], H['data'] | Promise<H['data']>>>;
84
- fetchOptions: HookFetcherOptions;
85
- fetcher?: HookFetcherFn<H>;
86
- };
87
- export declare type MutationHookContext<H extends MutationSchemaBase> = {
88
- fetch: keyof H['fetcherInput'] extends never ? () => H['data'] | Promise<H['data']> : Partial<H['fetcherInput']> extends H['fetcherInput'] ? (context?: {
89
- input?: H['fetcherInput'];
90
- }) => H['data'] | Promise<H['data']> : (context: {
91
- input: H['fetcherInput'];
92
- }) => H['data'] | Promise<H['data']>;
93
- };
94
- export declare type SwrOptions<Data, Input = null, Result = any> = SWRConfiguration<Data, CommerceError, HookFetcher<Data, Input, Result>>;
1
+ import type { SWRConfiguration } from 'swr';
2
+ import type { CommerceError } from './errors';
3
+ import type { ResponseState } from './use-data';
4
+ /**
5
+ * Returns the properties in T with the properties in type K, overriding properties defined in T
6
+ */
7
+ export declare type Override<T, K> = Omit<T, keyof K> & K;
8
+ /**
9
+ * Returns the properties in T with the properties in type K changed from optional to required
10
+ */
11
+ export declare type PickRequired<T, K extends keyof T> = Omit<T, K> & {
12
+ [P in K]-?: NonNullable<T[P]>;
13
+ };
14
+ /**
15
+ * Core fetcher added by CommerceProvider
16
+ */
17
+ export declare type Fetcher<T = any, B = any> = (options: FetcherOptions<B>) => T | Promise<T>;
18
+ export declare type FetcherOptions<Body = any> = {
19
+ url?: string;
20
+ query?: string;
21
+ method?: string;
22
+ variables?: any;
23
+ body?: Body;
24
+ };
25
+ export declare type HookFetcher<Data, Input = null, Result = any> = (options: HookFetcherOptions | null, input: Input, fetch: <T = Result, Body = any>(options: FetcherOptions<Body>) => Promise<T>) => Data | Promise<Data>;
26
+ export declare type HookFetcherFn<H extends HookSchemaBase> = (context: HookFetcherContext<H>) => H['data'] | Promise<H['data']>;
27
+ export declare type HookFetcherContext<H extends HookSchemaBase> = {
28
+ options: HookFetcherOptions;
29
+ input: H['fetcherInput'];
30
+ fetch: <T = H['fetchData'] extends {} | null ? H['fetchData'] : any, B = H['body']>(options: FetcherOptions<B>) => Promise<T>;
31
+ };
32
+ export declare type HookFetcherOptions = {
33
+ method?: string;
34
+ } & ({
35
+ query: string;
36
+ url?: string;
37
+ } | {
38
+ query?: string;
39
+ url: string;
40
+ });
41
+ export declare type HookInputValue = string | number | boolean | undefined;
42
+ export declare type HookSWRInput = [string, HookInputValue][];
43
+ export declare type HookFetchInput = {
44
+ [k: string]: HookInputValue;
45
+ };
46
+ export declare type HookFunction<Input extends {
47
+ [k: string]: unknown;
48
+ } | undefined, T> = keyof Input extends never ? () => T : Partial<Input> extends Input ? (input?: Input) => T : (input: Input) => T;
49
+ export declare type HookSchemaBase = {
50
+ data: any;
51
+ input?: {};
52
+ fetcherInput?: {};
53
+ body?: {};
54
+ fetchData?: any;
55
+ };
56
+ export declare type SWRHookSchemaBase = HookSchemaBase & {
57
+ swrState?: {};
58
+ mutations?: Record<string, ReturnType<MutationHook<any>['useHook']>>;
59
+ };
60
+ export declare type MutationSchemaBase = HookSchemaBase & {
61
+ actionInput?: {};
62
+ };
63
+ /**
64
+ * Generates a SWR hook handler based on the schema of a hook
65
+ */
66
+ export declare type SWRHook<H extends SWRHookSchemaBase> = {
67
+ useHook(context: SWRHookContext<H>): HookFunction<H['input'] & {
68
+ swrOptions?: SwrOptions<H['data'], H['fetcherInput']>;
69
+ }, ResponseState<H['data']> & H['swrState'] & H['mutations']>;
70
+ fetchOptions: HookFetcherOptions;
71
+ fetcher?: HookFetcherFn<H>;
72
+ };
73
+ export declare type SWRHookContext<H extends SWRHookSchemaBase> = {
74
+ useData(context?: {
75
+ input?: HookFetchInput | HookSWRInput;
76
+ swrOptions?: SwrOptions<H['data'], H['fetcherInput']>;
77
+ }): ResponseState<H['data']>;
78
+ };
79
+ /**
80
+ * Generates a mutation hook handler based on the schema of a hook
81
+ */
82
+ export declare type MutationHook<H extends MutationSchemaBase> = {
83
+ useHook(context: MutationHookContext<H>): HookFunction<H['input'], HookFunction<H['actionInput'], H['data'] | Promise<H['data']>>>;
84
+ fetchOptions: HookFetcherOptions;
85
+ fetcher?: HookFetcherFn<H>;
86
+ };
87
+ export declare type MutationHookContext<H extends MutationSchemaBase> = {
88
+ fetch: keyof H['fetcherInput'] extends never ? () => H['data'] | Promise<H['data']> : Partial<H['fetcherInput']> extends H['fetcherInput'] ? (context?: {
89
+ input?: H['fetcherInput'];
90
+ }) => H['data'] | Promise<H['data']> : (context: {
91
+ input: H['fetcherInput'];
92
+ }) => H['data'] | Promise<H['data']>;
93
+ };
94
+ export declare type SwrOptions<Data, Input = null, Result = any> = SWRConfiguration<Data, CommerceError, HookFetcher<Data, Input, Result>>;
95
+ export declare const x: () => number;
@@ -1,12 +1,12 @@
1
- import { SWRResponse } from 'swr';
2
- import type { HookSWRInput, HookFetchInput, HookFetcherOptions, HookFetcherFn, Fetcher, SwrOptions, SWRHookSchemaBase } from './types';
3
- import { CommerceError } from './errors';
4
- export declare type ResponseState<Result> = SWRResponse<Result, CommerceError> & {
5
- isLoading: boolean;
6
- };
7
- export declare type UseData = <H extends SWRHookSchemaBase>(options: {
8
- fetchOptions: HookFetcherOptions;
9
- fetcher: HookFetcherFn<H>;
10
- }, input: HookFetchInput | HookSWRInput, fetcherFn: Fetcher, swrOptions?: SwrOptions<H['data'], H['fetcherInput']>) => ResponseState<H['data']>;
11
- declare const useData: UseData;
12
- export default useData;
1
+ import { SWRResponse } from 'swr';
2
+ import type { HookSWRInput, HookFetchInput, HookFetcherOptions, HookFetcherFn, Fetcher, SwrOptions, SWRHookSchemaBase } from './types';
3
+ import { CommerceError } from './errors';
4
+ export declare type ResponseState<Result> = SWRResponse<Result, CommerceError> & {
5
+ isLoading: boolean;
6
+ };
7
+ export declare type UseData = <H extends SWRHookSchemaBase>(options: {
8
+ fetchOptions: HookFetcherOptions;
9
+ fetcher: HookFetcherFn<H>;
10
+ }, input: HookFetchInput | HookSWRInput, fetcherFn: Fetcher, swrOptions?: SwrOptions<H['data'], H['fetcherInput']>) => ResponseState<H['data']>;
11
+ declare const useData: UseData;
12
+ export default useData;
@@ -1,6 +1,6 @@
1
- import { Provider } from '..';
2
- import type { MutationHook, PickRequired, SWRHook } from './types';
3
- export declare function useFetcher(): import("./types").Fetcher<any, any>;
4
- export declare function useHook<P extends Provider, H extends MutationHook<any> | SWRHook<any>>(fn: (provider: P) => H): H;
5
- export declare function useSWRHook<H extends SWRHook<any>>(hook: PickRequired<H, 'fetcher'>): (input?: any) => any;
6
- export declare function useMutationHook<H extends MutationHook<any>>(hook: PickRequired<H, 'fetcher'>): (input?: any) => (input?: any) => any;
1
+ import { Provider } from '../commerce';
2
+ import type { MutationHook, PickRequired, SWRHook } from './types';
3
+ export declare function useFetcher(): import("./types").Fetcher<any, any>;
4
+ export declare function useHook<P extends Provider, H extends MutationHook<any> | SWRHook<any>>(fn: (provider: P) => H): H;
5
+ export declare function useSWRHook<H extends SWRHook<any>>(hook: PickRequired<H, 'fetcher'>): (input?: any) => any;
6
+ export declare function useMutationHook<H extends MutationHook<any>>(hook: PickRequired<H, 'fetcher'>): (input?: any) => (input?: any) => any;
package/package.json CHANGED
@@ -1,42 +1,42 @@
1
1
  {
2
2
  "name": "@plasmicpkgs/commerce",
3
- "version": "0.0.1",
4
- "description": "Plasmic components and registration calls for commerce providers",
3
+ "version": "0.0.5",
4
+ "description": "Plasmic registration calls for commerce components",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "module": "dist/commerce.esm.js",
8
- "type": "module",
9
8
  "files": [
10
9
  "dist"
11
10
  ],
12
- "exports": {
13
- ".": "./dist/index.js",
14
- "./*": [
15
- "./dist/*.js",
16
- "./dist/*/index.js"
17
- ]
18
- },
19
11
  "scripts": {
20
12
  "build": "tsdx build",
21
13
  "start": "tsdx watch",
22
14
  "test": "tsdx test --passWithNoTests",
23
15
  "lint": "tsdx lint",
24
- "prepare": "tsc",
16
+ "prepare": "tsdx build",
25
17
  "size": "size-limit",
26
18
  "analyze": "size-limit --why"
27
19
  },
28
20
  "devDependencies": {
21
+ "@plasmicapp/host": "1.0.21",
29
22
  "@size-limit/preset-small-lib": "^4.11.0",
30
23
  "@types/js-cookie": "^3.0.1",
31
24
  "@types/node": "^14.0.26",
25
+ "react": "^17.0.2",
26
+ "react-dom": "^17.0.2",
32
27
  "size-limit": "^4.11.0",
33
28
  "tsdx": "^0.14.1",
34
- "tslib": "^2.2.0",
35
29
  "typescript": "^3.9.7"
36
30
  },
31
+ "peerDependencies": {
32
+ "@plasmicapp/host": "^1.0.0",
33
+ "react": ">=16.8.0"
34
+ },
37
35
  "dependencies": {
38
- "antd": "^4.19.1",
36
+ "@types/react": "^17.0.40",
37
+ "@vercel/fetch": "^6.2.0",
39
38
  "js-cookie": "^3.0.1",
39
+ "react-hook-form": "^7.28.0",
40
40
  "swr": "^1.2.2"
41
41
  }
42
42
  }
@@ -1,6 +0,0 @@
1
- import type { MutationHook, HookFetcherFn } from '../utils/types';
2
- import type { LoginHook } from '../types/login';
3
- export declare type UseLogin<H extends MutationHook<LoginHook<any>> = MutationHook<LoginHook>> = ReturnType<H['useHook']>;
4
- export declare const fetcher: HookFetcherFn<LoginHook>;
5
- declare const useLogin: UseLogin;
6
- export default useLogin;
@@ -1,9 +0,0 @@
1
- import { useHook, useMutationHook } from '../utils/use-hook';
2
- import { mutationFetcher } from '../utils/default-fetcher';
3
- export const fetcher = mutationFetcher;
4
- const fn = (provider) => provider.auth?.useLogin;
5
- const useLogin = (...args) => {
6
- const hook = useHook(fn);
7
- return useMutationHook({ fetcher, ...hook })(...args);
8
- };
9
- export default useLogin;
@@ -1,6 +0,0 @@
1
- import type { HookFetcherFn, MutationHook } from '../utils/types';
2
- import type { LogoutHook } from '../types/logout';
3
- export declare type UseLogout<H extends MutationHook<LogoutHook<any>> = MutationHook<LogoutHook>> = ReturnType<H['useHook']>;
4
- export declare const fetcher: HookFetcherFn<LogoutHook>;
5
- declare const useLogout: UseLogout;
6
- export default useLogout;
@@ -1,9 +0,0 @@
1
- import { useHook, useMutationHook } from '../utils/use-hook';
2
- import { mutationFetcher } from '../utils/default-fetcher';
3
- export const fetcher = mutationFetcher;
4
- const fn = (provider) => provider.auth?.useLogout;
5
- const useLogout = (...args) => {
6
- const hook = useHook(fn);
7
- return useMutationHook({ fetcher, ...hook })(...args);
8
- };
9
- export default useLogout;
@@ -1,6 +0,0 @@
1
- import type { HookFetcherFn, MutationHook } from '../utils/types';
2
- import type { SignupHook } from '../types/signup';
3
- export declare type UseSignup<H extends MutationHook<SignupHook<any>> = MutationHook<SignupHook>> = ReturnType<H['useHook']>;
4
- export declare const fetcher: HookFetcherFn<SignupHook>;
5
- declare const useSignup: UseSignup;
6
- export default useSignup;
@@ -1,9 +0,0 @@
1
- import { useHook, useMutationHook } from '../utils/use-hook';
2
- import { mutationFetcher } from '../utils/default-fetcher';
3
- export const fetcher = mutationFetcher;
4
- const fn = (provider) => provider.auth?.useSignup;
5
- const useSignup = (...args) => {
6
- const hook = useHook(fn);
7
- return useMutationHook({ fetcher, ...hook })(...args);
8
- };
9
- export default useSignup;
@@ -1,9 +0,0 @@
1
- import { useHook, useMutationHook } from '../utils/use-hook';
2
- import { mutationFetcher } from '../utils/default-fetcher';
3
- export const fetcher = mutationFetcher;
4
- const fn = (provider) => provider.cart?.useAddItem;
5
- const useAddItem = (...args) => {
6
- const hook = useHook(fn);
7
- return useMutationHook({ fetcher, ...hook })(...args);
8
- };
9
- export default useAddItem;
@@ -1,18 +0,0 @@
1
- import Cookies from 'js-cookie';
2
- import { useHook, useSWRHook } from '../utils/use-hook';
3
- import { useCommerce } from '..';
4
- export const fetcher = async ({ options, input: { cartId }, fetch, }) => {
5
- return cartId ? await fetch(options) : null;
6
- };
7
- const fn = (provider) => provider.cart?.useCart;
8
- const useCart = (input) => {
9
- const hook = useHook(fn);
10
- const { cartCookie } = useCommerce();
11
- const fetcherFn = hook.fetcher ?? fetcher;
12
- const wrapper = (context) => {
13
- context.input.cartId = Cookies.get(cartCookie);
14
- return fetcherFn(context);
15
- };
16
- return useSWRHook({ ...hook, fetcher: wrapper })(input);
17
- };
18
- export default useCart;
@@ -1,9 +0,0 @@
1
- import { useHook, useMutationHook } from '../utils/use-hook';
2
- import { mutationFetcher } from '../utils/default-fetcher';
3
- export const fetcher = mutationFetcher;
4
- const fn = (provider) => provider.cart?.useRemoveItem;
5
- const useRemoveItem = (input) => {
6
- const hook = useHook(fn);
7
- return useMutationHook({ fetcher, ...hook })(input);
8
- };
9
- export default useRemoveItem;
@@ -1,9 +0,0 @@
1
- import { useHook, useMutationHook } from '../utils/use-hook';
2
- import { mutationFetcher } from '../utils/default-fetcher';
3
- export const fetcher = mutationFetcher;
4
- const fn = (provider) => provider.cart?.useUpdateItem;
5
- const useUpdateItem = (input) => {
6
- const hook = useHook(fn);
7
- return useMutationHook({ fetcher, ...hook })(input);
8
- };
9
- export default useUpdateItem;
@@ -1,6 +0,0 @@
1
- import type { SWRHook, HookFetcherFn } from '../utils/types';
2
- import type { GetCheckoutHook } from '../types/checkout';
3
- export declare type UseCheckout<H extends SWRHook<GetCheckoutHook<any>> = SWRHook<GetCheckoutHook>> = ReturnType<H['useHook']>;
4
- export declare const fetcher: HookFetcherFn<GetCheckoutHook>;
5
- declare const useCheckout: UseCheckout;
6
- export default useCheckout;
@@ -1,18 +0,0 @@
1
- import Cookies from 'js-cookie';
2
- import { useHook, useSWRHook } from '../utils/use-hook';
3
- import { useCommerce } from '..';
4
- export const fetcher = async ({ options, input: { cartId }, fetch, }) => {
5
- return cartId ? await fetch(options) : null;
6
- };
7
- const fn = (provider) => provider.checkout?.useCheckout;
8
- const useCheckout = (input) => {
9
- const hook = useHook(fn);
10
- const { cartCookie } = useCommerce();
11
- const fetcherFn = hook.fetcher ?? fetcher;
12
- const wrapper = (context) => {
13
- context.input.cartId = Cookies.get(cartCookie);
14
- return fetcherFn(context);
15
- };
16
- return useSWRHook({ ...hook, fetcher: wrapper })(input);
17
- };
18
- export default useCheckout;
@@ -1,6 +0,0 @@
1
- import type { HookFetcherFn, MutationHook } from '../utils/types';
2
- import type { SubmitCheckoutHook } from '../types/checkout';
3
- export declare type UseSubmitCheckout<H extends MutationHook<SubmitCheckoutHook<any>> = MutationHook<SubmitCheckoutHook>> = ReturnType<H['useHook']>;
4
- export declare const fetcher: HookFetcherFn<SubmitCheckoutHook>;
5
- declare const useSubmitCheckout: UseSubmitCheckout;
6
- export default useSubmitCheckout;
@@ -1,9 +0,0 @@
1
- import { useHook, useMutationHook } from '../utils/use-hook';
2
- import { mutationFetcher } from '../utils/default-fetcher';
3
- export const fetcher = mutationFetcher;
4
- const fn = (provider) => provider.checkout?.useSubmitCheckout;
5
- const useSubmitCheckout = (...args) => {
6
- const hook = useHook(fn);
7
- return useMutationHook({ fetcher, ...hook })(...args);
8
- };
9
- export default useSubmitCheckout;
package/dist/contexts.js DELETED
@@ -1,46 +0,0 @@
1
- import React, { useContext } from "react";
2
- export const ProductContext = React.createContext(undefined);
3
- function useProductPlaceholder() {
4
- const [product, setProduct] = React.useState();
5
- React.useEffect(() => {
6
- (async () => {
7
- const response = await fetch(`/api/catalog/products`);
8
- const { products } = await response.json();
9
- setProduct(products[2]);
10
- })();
11
- }, []);
12
- return product;
13
- }
14
- export function useProduct(_useProductPlaceholder) {
15
- const product = useContext(ProductContext);
16
- if (product) {
17
- return product;
18
- }
19
- if (_useProductPlaceholder) {
20
- return useProductPlaceholder();
21
- }
22
- return undefined;
23
- }
24
- export const ProductCollectionContext = React.createContext(undefined);
25
- function useProductCollectionPlaceholder() {
26
- const [collection, setCollection] = React.useState();
27
- React.useEffect(() => {
28
- (async () => {
29
- const response = await fetch(`/api/catalog/products`);
30
- const { products } = await response.json();
31
- setCollection(products);
32
- })();
33
- }, []);
34
- return collection;
35
- }
36
- export function useProductCollection(_useProductCollectionPlaceholder) {
37
- const collection = useContext(ProductCollectionContext);
38
- if (collection) {
39
- return collection;
40
- }
41
- if (_useProductCollectionPlaceholder) {
42
- return useProductCollectionPlaceholder();
43
- }
44
- return undefined;
45
- }
46
- export const CommerceProviderContext = React.createContext(undefined);
@@ -1,6 +0,0 @@
1
- import type { HookFetcherFn, MutationHook } from '../../utils/types';
2
- import type { AddItemHook } from '../../types/customer/address';
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,9 +0,0 @@
1
- import { useHook, useMutationHook } from '../../utils/use-hook';
2
- import { mutationFetcher } from '../../utils/default-fetcher';
3
- export const fetcher = mutationFetcher;
4
- const fn = (provider) => provider.customer?.address?.useAddItem;
5
- const useAddItem = (...args) => {
6
- const hook = useHook(fn);
7
- return useMutationHook({ fetcher, ...hook })(...args);
8
- };
9
- export default useAddItem;
@@ -1,6 +0,0 @@
1
- import type { SWRHook, HookFetcherFn } from '../../utils/types';
2
- import type { GetAddressesHook } from '../../types/customer/address';
3
- export declare type UseAddresses<H extends SWRHook<GetAddressesHook<any>> = SWRHook<GetAddressesHook>> = ReturnType<H['useHook']>;
4
- export declare const fetcher: HookFetcherFn<GetAddressesHook>;
5
- declare const useAddresses: UseAddresses;
6
- export default useAddresses;
@@ -1,18 +0,0 @@
1
- import Cookies from 'js-cookie';
2
- import { useHook, useSWRHook } from '../../utils/use-hook';
3
- import { useCommerce } from '../..';
4
- export const fetcher = async ({ options, input: { cartId }, fetch, }) => {
5
- return cartId ? await fetch(options) : null;
6
- };
7
- const fn = (provider) => provider.customer?.address?.useAddresses;
8
- const useAddresses = (input) => {
9
- const hook = useHook(fn);
10
- const { cartCookie } = useCommerce();
11
- const fetcherFn = hook.fetcher ?? fetcher;
12
- const wrapper = (context) => {
13
- context.input.cartId = Cookies.get(cartCookie);
14
- return fetcherFn(context);
15
- };
16
- return useSWRHook({ ...hook, fetcher: wrapper })(input);
17
- };
18
- export default useAddresses;
@@ -1,6 +0,0 @@
1
- import type { HookFetcherFn, MutationHook } from '../../utils/types';
2
- import type { RemoveItemHook } from '../../types/customer/address';
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,9 +0,0 @@
1
- import { useHook, useMutationHook } from '../../utils/use-hook';
2
- import { mutationFetcher } from '../../utils/default-fetcher';
3
- export const fetcher = mutationFetcher;
4
- const fn = (provider) => provider.customer?.address?.useRemoveItem;
5
- const useRemoveItem = (input) => {
6
- const hook = useHook(fn);
7
- return useMutationHook({ fetcher, ...hook })(input);
8
- };
9
- export default useRemoveItem;
@@ -1,6 +0,0 @@
1
- import type { HookFetcherFn, MutationHook } from '../../utils/types';
2
- import type { UpdateItemHook } from '../../types/customer/address';
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,9 +0,0 @@
1
- import { useHook, useMutationHook } from '../../utils/use-hook';
2
- import { mutationFetcher } from '../../utils/default-fetcher';
3
- export const fetcher = mutationFetcher;
4
- const fn = (provider) => provider.customer?.address?.useUpdateItem;
5
- const useUpdateItem = (input) => {
6
- const hook = useHook(fn);
7
- return useMutationHook({ fetcher, ...hook })(input);
8
- };
9
- export default useUpdateItem;
@@ -1,6 +0,0 @@
1
- import type { HookFetcherFn, MutationHook } from '../../utils/types';
2
- import type { AddItemHook } from '../../types/customer/card';
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,9 +0,0 @@
1
- import { useHook, useMutationHook } from '../../utils/use-hook';
2
- import { mutationFetcher } from '../../utils/default-fetcher';
3
- export const fetcher = mutationFetcher;
4
- const fn = (provider) => provider.customer?.card?.useAddItem;
5
- const useAddItem = (...args) => {
6
- const hook = useHook(fn);
7
- return useMutationHook({ fetcher, ...hook })(...args);
8
- };
9
- export default useAddItem;
@@ -1,6 +0,0 @@
1
- import type { SWRHook, HookFetcherFn } from '../../utils/types';
2
- import type { GetCardsHook } from '../../types/customer/card';
3
- export declare type UseCards<H extends SWRHook<GetCardsHook<any>> = SWRHook<GetCardsHook>> = ReturnType<H['useHook']>;
4
- export declare const fetcher: HookFetcherFn<GetCardsHook>;
5
- declare const useCards: UseCards;
6
- export default useCards;
@@ -1,18 +0,0 @@
1
- import Cookies from 'js-cookie';
2
- import { useHook, useSWRHook } from '../../utils/use-hook';
3
- import { useCommerce } from '../..';
4
- export const fetcher = async ({ options, input: { cartId }, fetch, }) => {
5
- return cartId ? await fetch(options) : null;
6
- };
7
- const fn = (provider) => provider.customer?.card?.useCards;
8
- const useCards = (input) => {
9
- const hook = useHook(fn);
10
- const { cartCookie } = useCommerce();
11
- const fetcherFn = hook.fetcher ?? fetcher;
12
- const wrapper = (context) => {
13
- context.input.cartId = Cookies.get(cartCookie);
14
- return fetcherFn(context);
15
- };
16
- return useSWRHook({ ...hook, fetcher: wrapper })(input);
17
- };
18
- export default useCards;
@@ -1,6 +0,0 @@
1
- import type { HookFetcherFn, MutationHook } from '../../utils/types';
2
- import type { RemoveItemHook } from '../../types/customer/card';
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,9 +0,0 @@
1
- import { useHook, useMutationHook } from '../../utils/use-hook';
2
- import { mutationFetcher } from '../../utils/default-fetcher';
3
- export const fetcher = mutationFetcher;
4
- const fn = (provider) => provider.customer?.card?.useRemoveItem;
5
- const useRemoveItem = (input) => {
6
- const hook = useHook(fn);
7
- return useMutationHook({ fetcher, ...hook })(input);
8
- };
9
- export default useRemoveItem;