@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
@@ -1,23 +1,23 @@
1
- export declare type SignupBody = {
2
- firstName: string;
3
- lastName: string;
4
- email: string;
5
- password: string;
6
- };
7
- export declare type SignupTypes = {
8
- body: SignupBody;
9
- };
10
- export declare type SignupHook<T extends SignupTypes = SignupTypes> = {
11
- data: null;
12
- body: T['body'];
13
- actionInput: T['body'];
14
- fetcherInput: T['body'];
15
- };
16
- export declare type SignupSchema<T extends SignupTypes = SignupTypes> = {
17
- endpoint: {
18
- options: {};
19
- handlers: {
20
- signup: SignupHook<T>;
21
- };
22
- };
23
- };
1
+ export declare type SignupBody = {
2
+ firstName: string;
3
+ lastName: string;
4
+ email: string;
5
+ password: string;
6
+ };
7
+ export declare type SignupTypes = {
8
+ body: SignupBody;
9
+ };
10
+ export declare type SignupHook<T extends SignupTypes = SignupTypes> = {
11
+ data: null;
12
+ body: T['body'];
13
+ actionInput: T['body'];
14
+ fetcherInput: T['body'];
15
+ };
16
+ export declare type SignupSchema<T extends SignupTypes = SignupTypes> = {
17
+ endpoint: {
18
+ options: {};
19
+ handlers: {
20
+ signup: SignupHook<T>;
21
+ };
22
+ };
23
+ };
@@ -1,17 +1,17 @@
1
- export declare type Category = {
2
- id: string;
3
- name: string;
4
- slug: string;
5
- path: string;
6
- };
7
- export declare type Brand = any;
8
- export declare type SiteTypes = {
9
- category: Category;
10
- brand: Brand;
11
- };
12
- export declare type GetSiteInfoOperation<T extends SiteTypes = SiteTypes> = {
13
- data: {
14
- categories: T['category'][];
15
- brands: T['brand'][];
16
- };
17
- };
1
+ export declare type Category = {
2
+ id: string;
3
+ name: string;
4
+ slug: string;
5
+ path: string;
6
+ };
7
+ export declare type Brand = any;
8
+ export declare type SiteTypes = {
9
+ category: Category;
10
+ brand: Brand;
11
+ };
12
+ export declare type GetSiteInfoOperation<T extends SiteTypes = SiteTypes> = {
13
+ data: {
14
+ categories: T['category'][];
15
+ brands: T['brand'][];
16
+ };
17
+ };
@@ -1,83 +1,83 @@
1
- export declare type Wishlist = any;
2
- export declare type WishlistItemBody = {
3
- variantId: string | number;
4
- productId: string;
5
- };
6
- export declare type WishlistTypes = {
7
- wishlist: Wishlist;
8
- itemBody: WishlistItemBody;
9
- };
10
- export declare type GetWishlistHook<T extends WishlistTypes = WishlistTypes> = {
11
- data: T['wishlist'] | null;
12
- body: {
13
- includeProducts?: boolean;
14
- };
15
- input: {
16
- includeProducts?: boolean;
17
- };
18
- fetcherInput: {
19
- customerId: string;
20
- includeProducts?: boolean;
21
- };
22
- swrState: {
23
- isEmpty: boolean;
24
- };
25
- };
26
- export declare type AddItemHook<T extends WishlistTypes = WishlistTypes> = {
27
- data: T['wishlist'];
28
- body: {
29
- item: T['itemBody'];
30
- };
31
- fetcherInput: {
32
- item: T['itemBody'];
33
- };
34
- actionInput: T['itemBody'];
35
- };
36
- export declare type RemoveItemHook<T extends WishlistTypes = WishlistTypes> = {
37
- data: T['wishlist'] | null;
38
- body: {
39
- itemId: string;
40
- };
41
- fetcherInput: {
42
- itemId: string;
43
- };
44
- actionInput: {
45
- id: string;
46
- };
47
- input: {
48
- wishlist?: {
49
- includeProducts?: boolean;
50
- };
51
- };
52
- };
53
- export declare type WishlistSchema<T extends WishlistTypes = WishlistTypes> = {
54
- endpoint: {
55
- options: {};
56
- handlers: {
57
- getWishlist: GetWishlistHook<T> & {
58
- data: T['wishlist'] | null;
59
- body: {
60
- customerToken?: string;
61
- };
62
- };
63
- addItem: AddItemHook<T> & {
64
- body: {
65
- customerToken?: string;
66
- };
67
- };
68
- removeItem: RemoveItemHook<T> & {
69
- body: {
70
- customerToken?: string;
71
- };
72
- };
73
- };
74
- };
75
- };
76
- export declare type GetCustomerWishlistOperation<T extends WishlistTypes = WishlistTypes> = {
77
- data: {
78
- wishlist?: T['wishlist'];
79
- };
80
- variables: {
81
- customerId: string;
82
- };
83
- };
1
+ export declare type Wishlist = any;
2
+ export declare type WishlistItemBody = {
3
+ variantId: string | number;
4
+ productId: string;
5
+ };
6
+ export declare type WishlistTypes = {
7
+ wishlist: Wishlist;
8
+ itemBody: WishlistItemBody;
9
+ };
10
+ export declare type GetWishlistHook<T extends WishlistTypes = WishlistTypes> = {
11
+ data: T['wishlist'] | null;
12
+ body: {
13
+ includeProducts?: boolean;
14
+ };
15
+ input: {
16
+ includeProducts?: boolean;
17
+ };
18
+ fetcherInput: {
19
+ customerId: string;
20
+ includeProducts?: boolean;
21
+ };
22
+ swrState: {
23
+ isEmpty: boolean;
24
+ };
25
+ };
26
+ export declare type AddItemHook<T extends WishlistTypes = WishlistTypes> = {
27
+ data: T['wishlist'];
28
+ body: {
29
+ item: T['itemBody'];
30
+ };
31
+ fetcherInput: {
32
+ item: T['itemBody'];
33
+ };
34
+ actionInput: T['itemBody'];
35
+ };
36
+ export declare type RemoveItemHook<T extends WishlistTypes = WishlistTypes> = {
37
+ data: T['wishlist'] | null;
38
+ body: {
39
+ itemId: string;
40
+ };
41
+ fetcherInput: {
42
+ itemId: string;
43
+ };
44
+ actionInput: {
45
+ id: string;
46
+ };
47
+ input: {
48
+ wishlist?: {
49
+ includeProducts?: boolean;
50
+ };
51
+ };
52
+ };
53
+ export declare type WishlistSchema<T extends WishlistTypes = WishlistTypes> = {
54
+ endpoint: {
55
+ options: {};
56
+ handlers: {
57
+ getWishlist: GetWishlistHook<T> & {
58
+ data: T['wishlist'] | null;
59
+ body: {
60
+ customerToken?: string;
61
+ };
62
+ };
63
+ addItem: AddItemHook<T> & {
64
+ body: {
65
+ customerToken?: string;
66
+ };
67
+ };
68
+ removeItem: RemoveItemHook<T> & {
69
+ body: {
70
+ customerToken?: string;
71
+ };
72
+ };
73
+ };
74
+ };
75
+ };
76
+ export declare type GetCustomerWishlistOperation<T extends WishlistTypes = WishlistTypes> = {
77
+ data: {
78
+ wishlist?: T['wishlist'];
79
+ };
80
+ variables: {
81
+ customerId: string;
82
+ };
83
+ };
@@ -1,4 +1,4 @@
1
- import type { HookFetcherFn } from './types';
2
- export declare const SWRFetcher: HookFetcherFn<any>;
3
- export declare const mutationFetcher: HookFetcherFn<any>;
4
- export default SWRFetcher;
1
+ import type { HookFetcherFn } from './types';
2
+ export declare const SWRFetcher: HookFetcherFn<any>;
3
+ export declare const mutationFetcher: HookFetcherFn<any>;
4
+ export default SWRFetcher;
@@ -1,21 +1,21 @@
1
- declare type InferValue<Prop extends PropertyKey, Desc> = Desc extends {
2
- get(): any;
3
- value: any;
4
- } ? never : Desc extends {
5
- value: infer T;
6
- } ? Record<Prop, T> : Desc extends {
7
- get(): infer T;
8
- } ? Record<Prop, T> : never;
9
- declare type DefineProperty<Prop extends PropertyKey, Desc extends PropertyDescriptor> = Desc extends {
10
- writable: any;
11
- set(val: any): any;
12
- } ? never : Desc extends {
13
- writable: any;
14
- get(): any;
15
- } ? never : Desc extends {
16
- writable: false;
17
- } ? Readonly<InferValue<Prop, Desc>> : Desc extends {
18
- writable: true;
19
- } ? InferValue<Prop, Desc> : Readonly<InferValue<Prop, Desc>>;
20
- export default function defineProperty<Obj extends object, Key extends PropertyKey, PDesc extends PropertyDescriptor>(obj: Obj, prop: Key, val: PDesc): asserts obj is Obj & DefineProperty<Key, PDesc>;
21
- export {};
1
+ declare type InferValue<Prop extends PropertyKey, Desc> = Desc extends {
2
+ get(): any;
3
+ value: any;
4
+ } ? never : Desc extends {
5
+ value: infer T;
6
+ } ? Record<Prop, T> : Desc extends {
7
+ get(): infer T;
8
+ } ? Record<Prop, T> : never;
9
+ declare type DefineProperty<Prop extends PropertyKey, Desc extends PropertyDescriptor> = Desc extends {
10
+ writable: any;
11
+ set(val: any): any;
12
+ } ? never : Desc extends {
13
+ writable: any;
14
+ get(): any;
15
+ } ? never : Desc extends {
16
+ writable: false;
17
+ } ? Readonly<InferValue<Prop, Desc>> : Desc extends {
18
+ writable: true;
19
+ } ? InferValue<Prop, Desc> : Readonly<InferValue<Prop, Desc>>;
20
+ export default function defineProperty<Obj extends object, Key extends PropertyKey, PDesc extends PropertyDescriptor>(obj: Obj, prop: Key, val: PDesc): asserts obj is Obj & DefineProperty<Key, PDesc>;
21
+ export {};
@@ -1,27 +1,27 @@
1
- export declare type ErrorData = {
2
- message: string;
3
- code?: string;
4
- };
5
- export declare type ErrorProps = {
6
- code?: string;
7
- } & ({
8
- message: string;
9
- errors?: never;
10
- } | {
11
- message?: never;
12
- errors: ErrorData[];
13
- });
14
- export declare class CommerceError extends Error {
15
- code?: string;
16
- errors: ErrorData[];
17
- constructor({ message, code, errors }: ErrorProps);
18
- }
19
- export declare class ValidationError extends CommerceError {
20
- constructor(options: ErrorProps);
21
- }
22
- export declare class FetcherError extends CommerceError {
23
- status: number;
24
- constructor(options: {
25
- status: number;
26
- } & ErrorProps);
27
- }
1
+ export declare type ErrorData = {
2
+ message: string;
3
+ code?: string;
4
+ };
5
+ export declare type ErrorProps = {
6
+ code?: string;
7
+ } & ({
8
+ message: string;
9
+ errors?: never;
10
+ } | {
11
+ message?: never;
12
+ errors: ErrorData[];
13
+ });
14
+ export declare class CommerceError extends Error {
15
+ code?: string;
16
+ errors: ErrorData[];
17
+ constructor({ message, code, errors }: ErrorProps);
18
+ }
19
+ export declare class ValidationError extends CommerceError {
20
+ constructor(options: ErrorProps);
21
+ }
22
+ export declare class FetcherError extends CommerceError {
23
+ status: number;
24
+ constructor(options: {
25
+ status: number;
26
+ } & ErrorProps);
27
+ }
@@ -0,0 +1,2 @@
1
+ import { Product } from "../types/product";
2
+ export declare const getProductPrice: (product: Product, variantId: string) => number;
@@ -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.2",
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;