@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
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,2 +0,0 @@
1
- export * as Card from './card';
2
- export * as Address from './address';
@@ -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';
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,3 +0,0 @@
1
- export const SWRFetcher = ({ options, fetch }) => fetch(options);
2
- export const mutationFetcher = ({ input, options, fetch, }) => fetch({ ...options, body: input });
3
- export default SWRFetcher;
@@ -1,4 +0,0 @@
1
- // Taken from https://fettblog.eu/typescript-assertion-signatures/
2
- export default function defineProperty(obj, prop, val) {
3
- Object.defineProperty(obj, prop, val);
4
- }
@@ -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
- }
File without changes
@@ -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;
@@ -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
- }