@easy-cms/plugin-ecommerce 0.0.0-stage → 0.47.0
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/LICENSE +21 -0
- package/README.md +48 -2
- package/dist/admin.js +62 -0
- package/dist/chunk-5ILURANO.js +1937 -0
- package/dist/chunk-KON3VWC6.js +302 -0
- package/dist/client.d.ts +250 -0
- package/dist/client.js +18 -0
- package/dist/index.d.ts +530 -0
- package/dist/index.js +44 -0
- package/dist/payments-tPD3bTTW.d.ts +213 -0
- package/dist/react.d.ts +95 -0
- package/dist/react.js +170 -0
- package/dist/stripe.d.ts +58 -0
- package/dist/stripe.js +90 -0
- package/dist/vue.d.ts +119 -0
- package/dist/vue.js +179 -0
- package/package.json +84 -4
package/dist/vue.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { ShopClientOptions, ShopClient, Address, CartView, Currency, ShopUser, CheckoutResult, ConfirmResult } from './client.js';
|
|
2
|
+
export { Adjustment, CURRENCIES, CartLine, ORDER_STATUSES, OrderStatus, ShopError, ShopSettings, ShopState, TRANSACTION_STATUSES, TransactionStatus, createShopClient, formatPrice, priceField } from './client.js';
|
|
3
|
+
import * as vue from 'vue';
|
|
4
|
+
import { App } from 'vue';
|
|
5
|
+
|
|
6
|
+
/** A Vue plugin that gives every component the shop: `app.use(shopPlugin({ api }))`. */
|
|
7
|
+
declare function shopPlugin(options?: ShopClientOptions & {
|
|
8
|
+
client?: ShopClient;
|
|
9
|
+
}): {
|
|
10
|
+
install(app: App): void;
|
|
11
|
+
};
|
|
12
|
+
/** Gives the components below this one the shop (instead of `shopPlugin`). */
|
|
13
|
+
declare function provideShop(options?: ShopClientOptions & {
|
|
14
|
+
client?: ShopClient;
|
|
15
|
+
}): ShopClient;
|
|
16
|
+
/** The shop's client, for everything the composables don't cover. */
|
|
17
|
+
declare function useShop(): ShopClient;
|
|
18
|
+
/** The cart and what to do with it. */
|
|
19
|
+
declare function useCart(): {
|
|
20
|
+
cart: vue.ComputedRef<CartView | null>;
|
|
21
|
+
loading: vue.ComputedRef<boolean>;
|
|
22
|
+
busy: vue.ComputedRef<boolean>;
|
|
23
|
+
addItem: (product: string | number, options?: {
|
|
24
|
+
variant?: (string | number) | null;
|
|
25
|
+
quantity?: number;
|
|
26
|
+
}) => Promise<CartView>;
|
|
27
|
+
updateItem: (line: string, quantity: number) => Promise<CartView>;
|
|
28
|
+
incrementItem: (line: string) => Promise<CartView>;
|
|
29
|
+
decrementItem: (line: string) => Promise<CartView>;
|
|
30
|
+
removeItem: (line: string) => Promise<CartView>;
|
|
31
|
+
clearCart: () => Promise<CartView | null>;
|
|
32
|
+
refreshCart: () => Promise<CartView | null>;
|
|
33
|
+
};
|
|
34
|
+
/** The signed-in customer, and signing in, out and up. */
|
|
35
|
+
declare function useCustomer(): {
|
|
36
|
+
user: vue.ComputedRef<ShopUser | null>;
|
|
37
|
+
loading: vue.ComputedRef<boolean>;
|
|
38
|
+
login: (email: string, password: string) => Promise<ShopUser>;
|
|
39
|
+
logout: () => Promise<void>;
|
|
40
|
+
signup: (data: {
|
|
41
|
+
email: string;
|
|
42
|
+
password: string;
|
|
43
|
+
name?: string;
|
|
44
|
+
turnstile?: string;
|
|
45
|
+
}) => Promise<{
|
|
46
|
+
verify: boolean;
|
|
47
|
+
}>;
|
|
48
|
+
verifyEmail: (token: string) => Promise<ShopUser>;
|
|
49
|
+
forgotPassword: (email: string) => Promise<void>;
|
|
50
|
+
resetPassword: (token: string, password: string) => Promise<ShopUser>;
|
|
51
|
+
};
|
|
52
|
+
/** The payment methods, and paying for the cart. */
|
|
53
|
+
declare function usePayments(): {
|
|
54
|
+
paymentMethods: vue.ComputedRef<readonly {
|
|
55
|
+
readonly name: string;
|
|
56
|
+
readonly label: string;
|
|
57
|
+
}[]>;
|
|
58
|
+
checkout: (input: {
|
|
59
|
+
method: string;
|
|
60
|
+
email?: string;
|
|
61
|
+
shippingAddress?: Address;
|
|
62
|
+
address?: string | number;
|
|
63
|
+
}) => Promise<CheckoutResult>;
|
|
64
|
+
confirm: (transaction: string | number, input?: Record<string, unknown>) => Promise<ConfirmResult>;
|
|
65
|
+
};
|
|
66
|
+
/** Currencies, the cart's, and amounts for people. */
|
|
67
|
+
declare function useCurrency(): {
|
|
68
|
+
currency: vue.ComputedRef<Currency | null>;
|
|
69
|
+
currencies: vue.ComputedRef<readonly Currency[]>;
|
|
70
|
+
setCurrency: (code: string) => Promise<CartView>;
|
|
71
|
+
formatPrice: (amount: number, code?: string) => string;
|
|
72
|
+
};
|
|
73
|
+
/** The customer's saved addresses. */
|
|
74
|
+
declare function useAddresses(): {
|
|
75
|
+
addresses: Readonly<vue.Ref<readonly {
|
|
76
|
+
readonly [x: string]: Readonly<unknown>;
|
|
77
|
+
readonly name?: string | null;
|
|
78
|
+
readonly phone?: string | null;
|
|
79
|
+
readonly line1?: string | null;
|
|
80
|
+
readonly line2?: string | null;
|
|
81
|
+
readonly subdistrict?: string | null;
|
|
82
|
+
readonly district?: string | null;
|
|
83
|
+
readonly province?: string | null;
|
|
84
|
+
readonly postalCode?: string | null;
|
|
85
|
+
readonly country?: string | null;
|
|
86
|
+
readonly id: string | number;
|
|
87
|
+
}[], readonly {
|
|
88
|
+
readonly [x: string]: Readonly<unknown>;
|
|
89
|
+
readonly name?: string | null;
|
|
90
|
+
readonly phone?: string | null;
|
|
91
|
+
readonly line1?: string | null;
|
|
92
|
+
readonly line2?: string | null;
|
|
93
|
+
readonly subdistrict?: string | null;
|
|
94
|
+
readonly district?: string | null;
|
|
95
|
+
readonly province?: string | null;
|
|
96
|
+
readonly postalCode?: string | null;
|
|
97
|
+
readonly country?: string | null;
|
|
98
|
+
readonly id: string | number;
|
|
99
|
+
}[]>>;
|
|
100
|
+
loading: Readonly<vue.Ref<boolean, boolean>>;
|
|
101
|
+
reload: () => Promise<void>;
|
|
102
|
+
createAddress: (address: Address) => Promise<Address & {
|
|
103
|
+
id: string | number;
|
|
104
|
+
}>;
|
|
105
|
+
updateAddress: (id: string | number, address: Partial<Address>) => Promise<Address & {
|
|
106
|
+
id: string | number;
|
|
107
|
+
}>;
|
|
108
|
+
deleteAddress: (id: string | number) => Promise<void>;
|
|
109
|
+
};
|
|
110
|
+
/** The customer's orders, newest first. */
|
|
111
|
+
declare function useOrders(options?: {
|
|
112
|
+
page?: number;
|
|
113
|
+
limit?: number;
|
|
114
|
+
}): {
|
|
115
|
+
orders: vue.ComputedRef<Record<string, unknown>[]>;
|
|
116
|
+
totalPages: vue.ComputedRef<number>;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export { Address, CartView, CheckoutResult, ConfirmResult, Currency, ShopClient, ShopClientOptions, ShopUser, provideShop, shopPlugin, useAddresses, useCart, useCurrency, useCustomer, useOrders, usePayments, useShop };
|
package/dist/vue.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CURRENCIES,
|
|
3
|
+
ORDER_STATUSES,
|
|
4
|
+
ShopError,
|
|
5
|
+
TRANSACTION_STATUSES,
|
|
6
|
+
createShopClient,
|
|
7
|
+
formatPrice,
|
|
8
|
+
priceField
|
|
9
|
+
} from "./chunk-KON3VWC6.js";
|
|
10
|
+
|
|
11
|
+
// src/vue.ts
|
|
12
|
+
import {
|
|
13
|
+
computed,
|
|
14
|
+
inject,
|
|
15
|
+
onScopeDispose,
|
|
16
|
+
provide,
|
|
17
|
+
readonly,
|
|
18
|
+
ref,
|
|
19
|
+
shallowRef,
|
|
20
|
+
watch
|
|
21
|
+
} from "vue";
|
|
22
|
+
var KEY = /* @__PURE__ */ Symbol("easy-cms-shop");
|
|
23
|
+
function setup(client) {
|
|
24
|
+
const state = shallowRef(client.getState());
|
|
25
|
+
client.subscribe((next) => {
|
|
26
|
+
state.value = next;
|
|
27
|
+
});
|
|
28
|
+
if (typeof window !== "undefined") void client.load().catch(() => {
|
|
29
|
+
});
|
|
30
|
+
return { client, state };
|
|
31
|
+
}
|
|
32
|
+
function shopPlugin(options = {}) {
|
|
33
|
+
return {
|
|
34
|
+
install(app) {
|
|
35
|
+
app.provide(KEY, setup(options.client ?? createShopClient(options)));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function provideShop(options = {}) {
|
|
40
|
+
const shop = setup(options.client ?? createShopClient(options));
|
|
41
|
+
provide(KEY, shop);
|
|
42
|
+
return shop.client;
|
|
43
|
+
}
|
|
44
|
+
function useShopContext() {
|
|
45
|
+
const shop = inject(KEY, null);
|
|
46
|
+
if (!shop) throw new Error("useShop: install shopPlugin() or call provideShop() first");
|
|
47
|
+
return shop;
|
|
48
|
+
}
|
|
49
|
+
function useShop() {
|
|
50
|
+
return useShopContext().client;
|
|
51
|
+
}
|
|
52
|
+
function useCart() {
|
|
53
|
+
const { client, state } = useShopContext();
|
|
54
|
+
return {
|
|
55
|
+
cart: computed(() => state.value.cart),
|
|
56
|
+
loading: computed(() => state.value.loading),
|
|
57
|
+
busy: computed(() => state.value.busy),
|
|
58
|
+
addItem: client.addItem,
|
|
59
|
+
updateItem: client.updateItem,
|
|
60
|
+
incrementItem: client.incrementItem,
|
|
61
|
+
decrementItem: client.decrementItem,
|
|
62
|
+
removeItem: client.removeItem,
|
|
63
|
+
clearCart: client.clearCart,
|
|
64
|
+
refreshCart: client.refreshCart
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function useCustomer() {
|
|
68
|
+
const { client, state } = useShopContext();
|
|
69
|
+
return {
|
|
70
|
+
user: computed(() => state.value.user),
|
|
71
|
+
loading: computed(() => state.value.loading),
|
|
72
|
+
login: client.login,
|
|
73
|
+
logout: client.logout,
|
|
74
|
+
signup: client.signup,
|
|
75
|
+
verifyEmail: client.verifyEmail,
|
|
76
|
+
forgotPassword: client.forgotPassword,
|
|
77
|
+
resetPassword: client.resetPassword
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function usePayments() {
|
|
81
|
+
const { client, state } = useShopContext();
|
|
82
|
+
return {
|
|
83
|
+
paymentMethods: computed(() => state.value.settings?.paymentMethods ?? []),
|
|
84
|
+
checkout: client.checkout,
|
|
85
|
+
confirm: client.confirm
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function useCurrency() {
|
|
89
|
+
const { client, state } = useShopContext();
|
|
90
|
+
return {
|
|
91
|
+
// Read the state, so they follow the cart's currency.
|
|
92
|
+
currency: computed(() => {
|
|
93
|
+
void state.value;
|
|
94
|
+
return client.currency();
|
|
95
|
+
}),
|
|
96
|
+
currencies: computed(() => state.value.settings?.currencies ?? []),
|
|
97
|
+
setCurrency: client.setCurrency,
|
|
98
|
+
formatPrice: (amount, code) => {
|
|
99
|
+
void state.value;
|
|
100
|
+
return client.formatPrice(amount, code);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function useAddresses() {
|
|
105
|
+
const { client, state } = useShopContext();
|
|
106
|
+
const addresses = ref([]);
|
|
107
|
+
const loading = ref(false);
|
|
108
|
+
const reload = async () => {
|
|
109
|
+
if (!state.value.user) {
|
|
110
|
+
addresses.value = [];
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
loading.value = true;
|
|
114
|
+
try {
|
|
115
|
+
addresses.value = await client.addresses();
|
|
116
|
+
} finally {
|
|
117
|
+
loading.value = false;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const stop = watch(
|
|
121
|
+
() => state.value.user,
|
|
122
|
+
() => void reload(),
|
|
123
|
+
{ immediate: true }
|
|
124
|
+
);
|
|
125
|
+
onScopeDispose(stop);
|
|
126
|
+
return {
|
|
127
|
+
addresses: readonly(addresses),
|
|
128
|
+
loading: readonly(loading),
|
|
129
|
+
reload,
|
|
130
|
+
createAddress: async (...args) => {
|
|
131
|
+
const saved = await client.createAddress(...args);
|
|
132
|
+
await reload();
|
|
133
|
+
return saved;
|
|
134
|
+
},
|
|
135
|
+
updateAddress: async (...args) => {
|
|
136
|
+
const saved = await client.updateAddress(...args);
|
|
137
|
+
await reload();
|
|
138
|
+
return saved;
|
|
139
|
+
},
|
|
140
|
+
deleteAddress: async (...args) => {
|
|
141
|
+
await client.deleteAddress(...args);
|
|
142
|
+
await reload();
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function useOrders(options = {}) {
|
|
147
|
+
const { client, state } = useShopContext();
|
|
148
|
+
const result = shallowRef(null);
|
|
149
|
+
const stop = watch(
|
|
150
|
+
() => state.value.user,
|
|
151
|
+
async (user) => {
|
|
152
|
+
result.value = user ? await client.orders(options).catch(() => null) : null;
|
|
153
|
+
},
|
|
154
|
+
{ immediate: true }
|
|
155
|
+
);
|
|
156
|
+
onScopeDispose(stop);
|
|
157
|
+
return {
|
|
158
|
+
orders: computed(() => result.value?.docs ?? []),
|
|
159
|
+
totalPages: computed(() => result.value?.totalPages ?? 0)
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
export {
|
|
163
|
+
CURRENCIES,
|
|
164
|
+
ORDER_STATUSES,
|
|
165
|
+
ShopError,
|
|
166
|
+
TRANSACTION_STATUSES,
|
|
167
|
+
createShopClient,
|
|
168
|
+
formatPrice,
|
|
169
|
+
priceField,
|
|
170
|
+
provideShop,
|
|
171
|
+
shopPlugin,
|
|
172
|
+
useAddresses,
|
|
173
|
+
useCart,
|
|
174
|
+
useCurrency,
|
|
175
|
+
useCustomer,
|
|
176
|
+
useOrders,
|
|
177
|
+
usePayments,
|
|
178
|
+
useShop
|
|
179
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,86 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easy-cms/plugin-ecommerce",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.47.0",
|
|
4
|
+
"description": "A shop for Easy CMS: products and variants, prices in several currencies, carts (guests too), checkout with Stripe or bank transfer, orders, stock, customer accounts, and React and Vue hooks",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./stripe": {
|
|
14
|
+
"types": "./dist/stripe.d.ts",
|
|
15
|
+
"default": "./dist/stripe.js"
|
|
16
|
+
},
|
|
17
|
+
"./client": {
|
|
18
|
+
"types": "./dist/client.d.ts",
|
|
19
|
+
"default": "./dist/client.js"
|
|
20
|
+
},
|
|
21
|
+
"./react": {
|
|
22
|
+
"types": "./dist/react.d.ts",
|
|
23
|
+
"default": "./dist/react.js"
|
|
24
|
+
},
|
|
25
|
+
"./vue": {
|
|
26
|
+
"types": "./dist/vue.d.ts",
|
|
27
|
+
"default": "./dist/vue.js"
|
|
28
|
+
},
|
|
29
|
+
"./admin": "./dist/admin.js",
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsup",
|
|
37
|
+
"typecheck": "tsc --noEmit",
|
|
38
|
+
"test": "vitest run"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@easy-cms/core": "workspace:^",
|
|
42
|
+
"react": ">=18.0.0",
|
|
43
|
+
"stripe": ">=17.0.0",
|
|
44
|
+
"vue": "^3.4.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependenciesMeta": {
|
|
47
|
+
"react": {
|
|
48
|
+
"optional": true
|
|
49
|
+
},
|
|
50
|
+
"stripe": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"vue": {
|
|
54
|
+
"optional": true
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@easy-cms/core": "workspace:^",
|
|
59
|
+
"@easy-cms/db-sqlite": "workspace:^",
|
|
60
|
+
"@easy-cms/plugin-multi-tenant": "workspace:^",
|
|
61
|
+
"@types/react": "^19.2.0",
|
|
62
|
+
"happy-dom": "^20.14.5",
|
|
63
|
+
"react": "^19.2.0",
|
|
64
|
+
"vue": "^3.5.43"
|
|
65
|
+
},
|
|
66
|
+
"engines": {
|
|
67
|
+
"node": ">=22.12"
|
|
68
|
+
},
|
|
69
|
+
"publishConfig": {
|
|
70
|
+
"access": "public"
|
|
71
|
+
},
|
|
72
|
+
"repository": {
|
|
73
|
+
"type": "git",
|
|
74
|
+
"url": "git+https://github.com/maritonx/easy-cms.git",
|
|
75
|
+
"directory": "packages/plugin-ecommerce"
|
|
76
|
+
},
|
|
77
|
+
"keywords": [
|
|
78
|
+
"easy-cms",
|
|
79
|
+
"easy-cms-plugin",
|
|
80
|
+
"ecommerce",
|
|
81
|
+
"shop",
|
|
82
|
+
"cart",
|
|
83
|
+
"checkout",
|
|
84
|
+
"stripe"
|
|
85
|
+
]
|
|
86
|
+
}
|