@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.
- package/README.md +1 -0
- package/dist/api/endpoints/cart.d.ts +4 -0
- package/dist/api/endpoints/catalog/products.d.ts +4 -0
- package/dist/api/index.d.ts +75 -0
- package/dist/api/operations.d.ts +130 -0
- package/dist/api/utils/errors.d.ts +10 -0
- package/dist/api/utils/is-allowed-method.d.ts +3 -0
- package/dist/api/utils/is-allowed-operation.d.ts +6 -0
- package/dist/api/utils/types.d.ts +34 -0
- package/dist/cart/use-add-item.d.ts +5 -6
- package/dist/cart/use-cart.d.ts +5 -6
- package/dist/cart/use-remove-item.d.ts +5 -6
- package/dist/cart/use-update-item.d.ts +5 -6
- package/dist/commerce.cjs.development.js +1851 -0
- package/dist/commerce.cjs.development.js.map +1 -0
- package/dist/commerce.cjs.production.min.js +2 -0
- package/dist/commerce.cjs.production.min.js.map +1 -0
- package/dist/commerce.d.ts +37 -0
- package/dist/commerce.esm.js +1828 -0
- package/dist/commerce.esm.js.map +1 -0
- package/dist/contexts.d.ts +10 -7
- package/dist/index.d.ts +21 -71
- package/dist/index.js +7 -28
- package/dist/product/use-price.d.ts +26 -26
- package/dist/product/use-search.d.ts +6 -6
- package/dist/registerAddToCartButton.d.ts +10 -0
- package/dist/registerProductCollection.d.ts +13 -11
- package/dist/registerProductMedia.d.ts +12 -0
- package/dist/registerProductPrice.d.ts +9 -0
- package/dist/registerProductQuantity.d.ts +11 -0
- package/dist/registerProductTextField.d.ts +10 -0
- package/dist/registerProductVariantPicker.d.ts +9 -0
- package/dist/registerUseCart.d.ts +9 -0
- package/dist/registerable.d.ts +4 -4
- 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 +102 -99
- package/dist/types/signup.d.ts +23 -23
- package/dist/types/site.d.ts +17 -17
- package/dist/types/wishlist.d.ts +83 -83
- package/dist/utils/default-fetcher.d.ts +4 -4
- 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 -0
- package/dist/utils/types.d.ts +95 -94
- package/dist/utils/use-data.d.ts +12 -12
- package/dist/utils/use-hook.d.ts +6 -6
- package/package.json +13 -13
- package/dist/auth/use-login.d.ts +0 -6
- package/dist/auth/use-login.js +0 -9
- package/dist/auth/use-logout.d.ts +0 -6
- package/dist/auth/use-logout.js +0 -9
- package/dist/auth/use-signup.d.ts +0 -6
- package/dist/auth/use-signup.js +0 -9
- package/dist/cart/use-add-item.js +0 -9
- package/dist/cart/use-cart.js +0 -18
- package/dist/cart/use-remove-item.js +0 -9
- package/dist/cart/use-update-item.js +0 -9
- package/dist/checkout/use-checkout.d.ts +0 -6
- package/dist/checkout/use-checkout.js +0 -18
- package/dist/checkout/use-submit-checkout.d.ts +0 -6
- package/dist/checkout/use-submit-checkout.js +0 -9
- package/dist/contexts.js +0 -46
- package/dist/customer/address/use-add-item.d.ts +0 -6
- package/dist/customer/address/use-add-item.js +0 -9
- package/dist/customer/address/use-addresses.d.ts +0 -6
- package/dist/customer/address/use-addresses.js +0 -18
- package/dist/customer/address/use-remove-item.d.ts +0 -6
- package/dist/customer/address/use-remove-item.js +0 -9
- package/dist/customer/address/use-update-item.d.ts +0 -6
- package/dist/customer/address/use-update-item.js +0 -9
- package/dist/customer/card/use-add-item.d.ts +0 -6
- package/dist/customer/card/use-add-item.js +0 -9
- package/dist/customer/card/use-cards.d.ts +0 -6
- package/dist/customer/card/use-cards.js +0 -18
- package/dist/customer/card/use-remove-item.d.ts +0 -6
- package/dist/customer/card/use-remove-item.js +0 -9
- package/dist/customer/card/use-update-item.d.ts +0 -6
- package/dist/customer/card/use-update-item.js +0 -9
- package/dist/customer/use-customer.d.ts +0 -6
- package/dist/customer/use-customer.js +0 -9
- package/dist/product/use-price.js +0 -33
- package/dist/product/use-search.js +0 -9
- package/dist/registerProductCollection.js +0 -42
- package/dist/registerProductImage.d.ts +0 -13
- package/dist/registerProductImage.js +0 -37
- package/dist/registerable.js +0 -0
- package/dist/tsconfig.tsbuildinfo +0 -2970
- package/dist/types/cart.js +0 -0
- package/dist/types/checkout.js +0 -0
- package/dist/types/common.js +0 -0
- package/dist/types/customer/address.js +0 -0
- package/dist/types/customer/card.js +0 -0
- package/dist/types/customer/index.js +0 -2
- package/dist/types/index.js +0 -11
- package/dist/types/login.js +0 -0
- package/dist/types/logout.js +0 -0
- package/dist/types/page.js +0 -0
- package/dist/types/product.js +0 -0
- package/dist/types/signup.js +0 -0
- package/dist/types/site.js +0 -0
- package/dist/types/wishlist.js +0 -0
- package/dist/utils/default-fetcher.js +0 -3
- package/dist/utils/define-property.js +0 -4
- package/dist/utils/errors.js +0 -24
- package/dist/utils/types.js +0 -0
- package/dist/utils/use-data.js +0 -43
- package/dist/utils/use-hook.js +0 -37
package/dist/types/signup.d.ts
CHANGED
|
@@ -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
|
+
};
|
package/dist/types/site.d.ts
CHANGED
|
@@ -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
|
+
};
|
package/dist/types/wishlist.d.ts
CHANGED
|
@@ -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 {};
|
package/dist/utils/errors.d.ts
CHANGED
|
@@ -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
|
+
}
|
package/dist/utils/types.d.ts
CHANGED
|
@@ -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;
|
package/dist/utils/use-data.d.ts
CHANGED
|
@@ -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;
|
package/dist/utils/use-hook.d.ts
CHANGED
|
@@ -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.
|
|
4
|
-
"description": "Plasmic
|
|
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": "
|
|
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
|
-
"
|
|
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
|
}
|
package/dist/auth/use-login.d.ts
DELETED
|
@@ -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;
|