@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/cart.js
DELETED
|
File without changes
|
package/dist/types/checkout.js
DELETED
|
File without changes
|
package/dist/types/common.js
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/types/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as Cart from './cart';
|
|
2
|
-
import * as Checkout from './checkout';
|
|
3
|
-
import * as Common from './common';
|
|
4
|
-
import * as Customer from './customer';
|
|
5
|
-
import * as Login from './login';
|
|
6
|
-
import * as Logout from './logout';
|
|
7
|
-
import * as Page from './page';
|
|
8
|
-
import * as Product from './product';
|
|
9
|
-
import * as Signup from './signup';
|
|
10
|
-
import * as Site from './site';
|
|
11
|
-
import * as Wishlist from './wishlist';
|
package/dist/types/login.js
DELETED
|
File without changes
|
package/dist/types/logout.js
DELETED
|
File without changes
|
package/dist/types/page.js
DELETED
|
File without changes
|
package/dist/types/product.js
DELETED
|
File without changes
|
package/dist/types/signup.js
DELETED
|
File without changes
|
package/dist/types/site.js
DELETED
|
File without changes
|
package/dist/types/wishlist.js
DELETED
|
File without changes
|
package/dist/utils/errors.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export class CommerceError extends Error {
|
|
2
|
-
constructor({ message, code, errors }) {
|
|
3
|
-
const error = message
|
|
4
|
-
? { message, ...(code ? { code } : {}) }
|
|
5
|
-
: errors[0];
|
|
6
|
-
super(error.message);
|
|
7
|
-
this.errors = message ? [error] : errors;
|
|
8
|
-
if (error.code)
|
|
9
|
-
this.code = error.code;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
// Used for errors that come from a bad implementation of the hooks
|
|
13
|
-
export class ValidationError extends CommerceError {
|
|
14
|
-
constructor(options) {
|
|
15
|
-
super(options);
|
|
16
|
-
this.code = 'validation_error';
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
export class FetcherError extends CommerceError {
|
|
20
|
-
constructor(options) {
|
|
21
|
-
super(options);
|
|
22
|
-
this.status = options.status;
|
|
23
|
-
}
|
|
24
|
-
}
|
package/dist/utils/types.js
DELETED
|
File without changes
|
package/dist/utils/use-data.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import useSWR from 'swr';
|
|
2
|
-
import defineProperty from './define-property';
|
|
3
|
-
import { CommerceError } from './errors';
|
|
4
|
-
const useData = (options, input, fetcherFn, swrOptions) => {
|
|
5
|
-
const hookInput = Array.isArray(input) ? input : Object.entries(input);
|
|
6
|
-
const fetcher = async (url, query, method, ...args) => {
|
|
7
|
-
try {
|
|
8
|
-
return await options.fetcher({
|
|
9
|
-
options: { url, query, method },
|
|
10
|
-
// Transform the input array into an object
|
|
11
|
-
input: args.reduce((obj, val, i) => {
|
|
12
|
-
obj[hookInput[i][0]] = val;
|
|
13
|
-
return obj;
|
|
14
|
-
}, {}),
|
|
15
|
-
fetch: fetcherFn,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
// SWR will not log errors, but any error that's not an instance
|
|
20
|
-
// of CommerceError is not welcomed by this hook
|
|
21
|
-
if (!(error instanceof CommerceError)) {
|
|
22
|
-
console.error(error);
|
|
23
|
-
}
|
|
24
|
-
throw error;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
const response = useSWR(() => {
|
|
28
|
-
const opts = options.fetchOptions;
|
|
29
|
-
return opts
|
|
30
|
-
? [opts.url, opts.query, opts.method, ...hookInput.map((e) => e[1])]
|
|
31
|
-
: null;
|
|
32
|
-
}, fetcher, swrOptions);
|
|
33
|
-
if (!('isLoading' in response)) {
|
|
34
|
-
defineProperty(response, 'isLoading', {
|
|
35
|
-
get() {
|
|
36
|
-
return response.data === undefined;
|
|
37
|
-
},
|
|
38
|
-
enumerable: true,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
return response;
|
|
42
|
-
};
|
|
43
|
-
export default useData;
|
package/dist/utils/use-hook.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
import { useCommerce } from '..';
|
|
3
|
-
import useData from './use-data';
|
|
4
|
-
export function useFetcher() {
|
|
5
|
-
const { providerRef, fetcherRef } = useCommerce();
|
|
6
|
-
return providerRef.current.fetcher ?? fetcherRef.current;
|
|
7
|
-
}
|
|
8
|
-
export function useHook(fn) {
|
|
9
|
-
console.log("oi?");
|
|
10
|
-
const x = useCommerce();
|
|
11
|
-
console.log("test", x);
|
|
12
|
-
const { providerRef } = useCommerce();
|
|
13
|
-
console.log("dale", providerRef);
|
|
14
|
-
const provider = providerRef.current;
|
|
15
|
-
return fn(provider);
|
|
16
|
-
}
|
|
17
|
-
export function useSWRHook(hook) {
|
|
18
|
-
const fetcher = useFetcher();
|
|
19
|
-
return hook.useHook({
|
|
20
|
-
useData(ctx) {
|
|
21
|
-
const response = useData(hook, ctx?.input ?? [], fetcher, ctx?.swrOptions);
|
|
22
|
-
return response;
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
export function useMutationHook(hook) {
|
|
27
|
-
const fetcher = useFetcher();
|
|
28
|
-
return hook.useHook({
|
|
29
|
-
fetch: useCallback(({ input } = {}) => {
|
|
30
|
-
return hook.fetcher({
|
|
31
|
-
input,
|
|
32
|
-
options: hook.fetchOptions,
|
|
33
|
-
fetch: fetcher,
|
|
34
|
-
});
|
|
35
|
-
}, [fetcher, hook.fetchOptions]),
|
|
36
|
-
});
|
|
37
|
-
}
|