@moonbase.sh/vue 0.1.40 → 0.1.42

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/dist/index.cjs CHANGED
@@ -32,11 +32,11 @@ __export(src_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(src_exports);
34
34
  var import_api_client2 = require("@moonbase.sh/api-client");
35
+ var import_vue7 = require("vue");
35
36
 
36
37
  // src/context.ts
37
38
  var import_api_client = require("@moonbase.sh/api-client");
38
39
  var import_uuid = require("uuid");
39
- var import_vue = require("vue");
40
40
 
41
41
  // src/symbols.ts
42
42
  var storefrontKey = Symbol("storefront");
@@ -55,35 +55,36 @@ function debounce(func, waitMs = 100) {
55
55
 
56
56
  // src/context.ts
57
57
  var _StorefrontContextImpl = class _StorefrontContextImpl {
58
- constructor(configuration, client) {
58
+ constructor(configuration, client, stateFactory) {
59
59
  this.configuration = configuration;
60
60
  this.client = client;
61
- this.currentUser = (0, import_vue.ref)(null);
62
- this.loadedUser = (0, import_vue.ref)(false);
61
+ this.stateFactory = stateFactory;
63
62
  this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order), 500);
63
+ this.currentUser = stateFactory("moonbase_user", null);
64
+ this.loadedUser = stateFactory("moonbase_loaded_user", false);
64
65
  if (typeof window === "undefined") {
65
- this.currentOrder = (0, import_vue.ref)({
66
+ this.currentOrder = stateFactory("moonbase_current_order", {
66
67
  id: (0, import_uuid.v4)(),
67
68
  status: import_api_client.OrderStatus.Open,
68
69
  currency: "",
69
70
  items: [],
70
71
  couponsApplied: []
71
72
  });
72
- this.storefront = (0, import_vue.ref)({
73
+ this.storefront = stateFactory("moonbase_storefront", {
73
74
  suggestedCurrency: "",
74
75
  bundles: [],
75
76
  products: []
76
77
  });
77
- this.loadedStorefront = (0, import_vue.ref)(false);
78
+ this.loadedStorefront = stateFactory("moonbase_loaded_storefront", false);
78
79
  return;
79
80
  }
80
81
  window.addEventListener("storage", (event) => this.handleStorageUpdate(event));
81
82
  const cachedOrderJson = localStorage.getItem("moonbase_session");
82
83
  if (cachedOrderJson) {
83
- this.currentOrder = (0, import_vue.ref)(JSON.parse(cachedOrderJson));
84
+ this.currentOrder = stateFactory("moonbase_current_order", JSON.parse(cachedOrderJson));
84
85
  const _1 = this.refreshOrder();
85
86
  } else {
86
- this.currentOrder = (0, import_vue.ref)({
87
+ this.currentOrder = stateFactory("moonbase_current_order", {
87
88
  id: (0, import_uuid.v4)(),
88
89
  status: import_api_client.OrderStatus.Open,
89
90
  currency: "",
@@ -94,15 +95,15 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
94
95
  }
95
96
  const cachedStorefrontJson = localStorage.getItem(_StorefrontContextImpl.storefrontKey);
96
97
  if (cachedStorefrontJson) {
97
- this.storefront = (0, import_vue.ref)(JSON.parse(cachedStorefrontJson));
98
- this.loadedStorefront = (0, import_vue.ref)(true);
98
+ this.storefront = stateFactory("moonbase_storefront", JSON.parse(cachedStorefrontJson));
99
+ this.loadedStorefront = stateFactory("moonbase_loaded_storefront", true);
99
100
  } else {
100
- this.storefront = (0, import_vue.ref)({
101
+ this.storefront = stateFactory("moonbase_storefront", {
101
102
  suggestedCurrency: "",
102
103
  bundles: [],
103
104
  products: []
104
105
  });
105
- this.loadedStorefront = (0, import_vue.ref)(false);
106
+ this.loadedStorefront = stateFactory("moonbase_loaded_storefront", false);
106
107
  }
107
108
  const _2 = this.updateStorefront();
108
109
  const _3 = this.updateUser();
@@ -187,51 +188,51 @@ var StorefrontContextImpl = _StorefrontContextImpl;
187
188
  __reExport(src_exports, require("@moonbase.sh/api-client"), module.exports);
188
189
 
189
190
  // src/composables/useBundle.ts
190
- var import_vue2 = require("vue");
191
+ var import_vue = require("vue");
191
192
  function useBundle(bundleId) {
192
- const storefront = (0, import_vue2.inject)(storefrontKey);
193
+ const storefront = (0, import_vue.inject)(storefrontKey);
193
194
  if (!storefront)
194
195
  throw new Error("No storefront configured");
195
- return (0, import_vue2.computed)(() => storefront.storefront.value.bundles.find((b) => b.id === bundleId) || null);
196
+ return (0, import_vue.computed)(() => storefront.storefront.value.bundles.find((b) => b.id === bundleId) || null);
196
197
  }
197
198
 
198
199
  // src/composables/useBundles.ts
199
- var import_vue3 = require("vue");
200
+ var import_vue2 = require("vue");
200
201
  function useBundles() {
201
- const storefront = (0, import_vue3.inject)(storefrontKey);
202
+ const storefront = (0, import_vue2.inject)(storefrontKey);
202
203
  if (!storefront)
203
204
  throw new Error("No storefront configured");
204
- return (0, import_vue3.computed)(() => storefront.storefront.value.bundles);
205
+ return (0, import_vue2.computed)(() => storefront.storefront.value.bundles);
205
206
  }
206
207
 
207
208
  // src/composables/useProduct.ts
208
- var import_vue4 = require("vue");
209
+ var import_vue3 = require("vue");
209
210
  function useProduct(productId) {
210
- const storefront = (0, import_vue4.inject)(storefrontKey);
211
+ const storefront = (0, import_vue3.inject)(storefrontKey);
211
212
  if (!storefront)
212
213
  throw new Error("No storefront configured");
213
- return (0, import_vue4.computed)(() => storefront.storefront.value.products.find((p) => p.id === productId) || null);
214
+ return (0, import_vue3.computed)(() => storefront.storefront.value.products.find((p) => p.id === productId) || null);
214
215
  }
215
216
 
216
217
  // src/composables/useProducts.ts
217
- var import_vue5 = require("vue");
218
+ var import_vue4 = require("vue");
218
219
  function useProducts() {
219
- const storefront = (0, import_vue5.inject)(storefrontKey);
220
+ const storefront = (0, import_vue4.inject)(storefrontKey);
220
221
  if (!storefront)
221
222
  throw new Error("No storefront configured");
222
- return (0, import_vue5.computed)(() => storefront.storefront.value.products);
223
+ return (0, import_vue4.computed)(() => storefront.storefront.value.products);
223
224
  }
224
225
 
225
226
  // src/composables/useCart.ts
226
- var import_vue6 = require("vue");
227
+ var import_vue5 = require("vue");
227
228
  function useCart() {
228
- const storefront = (0, import_vue6.inject)(storefrontKey);
229
+ const storefront = (0, import_vue5.inject)(storefrontKey);
229
230
  if (!storefront)
230
231
  throw new Error("No storefront configured");
231
232
  return {
232
- items: (0, import_vue6.computed)(() => storefront.currentOrder.value.items),
233
- currency: (0, import_vue6.computed)(() => storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency),
234
- total: (0, import_vue6.computed)(() => {
233
+ items: (0, import_vue5.computed)(() => storefront.currentOrder.value.items),
234
+ currency: (0, import_vue5.computed)(() => storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency),
235
+ total: (0, import_vue5.computed)(() => {
235
236
  const currency = storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency;
236
237
  const total = storefront.currentOrder.value.items.reduce((agg, item) => {
237
238
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
@@ -305,9 +306,9 @@ function useCart() {
305
306
  }
306
307
 
307
308
  // src/composables/useAuth.ts
308
- var import_vue7 = require("vue");
309
+ var import_vue6 = require("vue");
309
310
  function useAuth() {
310
- const storefront = (0, import_vue7.inject)(storefrontKey);
311
+ const storefront = (0, import_vue6.inject)(storefrontKey);
311
312
  if (!storefront)
312
313
  throw new Error("No storefront configured");
313
314
  return {
@@ -319,11 +320,12 @@ function useAuth() {
319
320
  const _ = storefront.updateStorefront();
320
321
  return user;
321
322
  },
322
- signUp: async (name, email, password, acceptedPrivacyPolicy, acceptedTermsAndConditions) => {
323
+ signUp: async (name, email, password, address, acceptedPrivacyPolicy, acceptedTermsAndConditions) => {
323
324
  const user = await storefront.client.identity.signUp(
324
325
  name,
325
326
  email,
326
327
  password,
328
+ address,
327
329
  acceptedPrivacyPolicy,
328
330
  acceptedTermsAndConditions
329
331
  );
@@ -356,11 +358,16 @@ function useAuth() {
356
358
  }
357
359
 
358
360
  // src/index.ts
359
- function createStorefront(endpoint) {
361
+ function createStorefront(endpoint, stateFactory) {
360
362
  const configuration = {
361
363
  endpoint
362
364
  };
363
- return new StorefrontContextImpl(configuration, new import_api_client2.MoonbaseClient(configuration));
365
+ return new StorefrontContextImpl(
366
+ configuration,
367
+ new import_api_client2.MoonbaseClient(configuration),
368
+ // Default to vue refs but allow stuff like Nuxt useState wrappers
369
+ stateFactory || ((_, state) => (0, import_vue7.ref)(state))
370
+ );
364
371
  }
365
372
  // Annotate the CommonJS export names for ESM import in node:
366
373
  0 && (module.exports = {
package/dist/index.d.cts CHANGED
@@ -2,6 +2,7 @@ import { Storefront, Order, User, MoonbaseClient, StorefrontBundle, StorefrontPr
2
2
  export * from '@moonbase.sh/api-client';
3
3
  import * as vue from 'vue';
4
4
  import { Ref, App, InjectionKey } from 'vue';
5
+ import { Address } from '@moonbase.sh/api-client/src';
5
6
 
6
7
  interface StorefrontContext {
7
8
  storefront: Ref<Storefront>;
@@ -21,6 +22,7 @@ interface StorefrontContext {
21
22
  */
22
23
  install(app: App): any;
23
24
  }
25
+ type StateFactory = (key: string, state: any) => Ref<typeof state>;
24
26
 
25
27
  declare function useBundle(bundleId: string): Ref<StorefrontBundle | null>;
26
28
 
@@ -49,6 +51,14 @@ declare function useAuth(): {
49
51
  email: string;
50
52
  name: string;
51
53
  tenantId: string;
54
+ address?: {
55
+ countryCode: string;
56
+ streetAddress1: string;
57
+ streetAddress2: string | null;
58
+ locality: string | null;
59
+ region: string | null;
60
+ postCode: string;
61
+ } | undefined;
52
62
  } | null>;
53
63
  loaded: vue.Ref<boolean>;
54
64
  signIn: (email: string, password: string) => Promise<{
@@ -56,12 +66,28 @@ declare function useAuth(): {
56
66
  email: string;
57
67
  name: string;
58
68
  tenantId: string;
69
+ address?: {
70
+ countryCode: string;
71
+ streetAddress1: string;
72
+ streetAddress2: string | null;
73
+ locality: string | null;
74
+ region: string | null;
75
+ postCode: string;
76
+ } | undefined;
59
77
  }>;
60
- signUp: (name: string, email: string, password: string, acceptedPrivacyPolicy: boolean, acceptedTermsAndConditions: boolean) => Promise<{
78
+ signUp: (name: string, email: string, password: string, address: Address | null | undefined, acceptedPrivacyPolicy: boolean, acceptedTermsAndConditions: boolean) => Promise<{
61
79
  id: string;
62
80
  email: string;
63
81
  name: string;
64
82
  tenantId: string;
83
+ address?: {
84
+ countryCode: string;
85
+ streetAddress1: string;
86
+ streetAddress2: string | null;
87
+ locality: string | null;
88
+ region: string | null;
89
+ postCode: string;
90
+ } | undefined;
65
91
  }>;
66
92
  signOut: () => void;
67
93
  update: (name: string, email: string, emailConfirmationToken?: string) => Promise<{
@@ -78,6 +104,6 @@ interface Cart {
78
104
  items: CartItem[];
79
105
  }
80
106
  type CartItem = OpenLineItem & {};
81
- declare function createStorefront(endpoint: string): StorefrontContext;
107
+ declare function createStorefront(endpoint: string, stateFactory?: StateFactory): StorefrontContext;
82
108
 
83
109
  export { Cart, CartItem, createStorefront, storefrontKey, useAuth, useBundle, useBundles, useCart, useProduct, useProducts };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { Storefront, Order, User, MoonbaseClient, StorefrontBundle, StorefrontPr
2
2
  export * from '@moonbase.sh/api-client';
3
3
  import * as vue from 'vue';
4
4
  import { Ref, App, InjectionKey } from 'vue';
5
+ import { Address } from '@moonbase.sh/api-client/src';
5
6
 
6
7
  interface StorefrontContext {
7
8
  storefront: Ref<Storefront>;
@@ -21,6 +22,7 @@ interface StorefrontContext {
21
22
  */
22
23
  install(app: App): any;
23
24
  }
25
+ type StateFactory = (key: string, state: any) => Ref<typeof state>;
24
26
 
25
27
  declare function useBundle(bundleId: string): Ref<StorefrontBundle | null>;
26
28
 
@@ -49,6 +51,14 @@ declare function useAuth(): {
49
51
  email: string;
50
52
  name: string;
51
53
  tenantId: string;
54
+ address?: {
55
+ countryCode: string;
56
+ streetAddress1: string;
57
+ streetAddress2: string | null;
58
+ locality: string | null;
59
+ region: string | null;
60
+ postCode: string;
61
+ } | undefined;
52
62
  } | null>;
53
63
  loaded: vue.Ref<boolean>;
54
64
  signIn: (email: string, password: string) => Promise<{
@@ -56,12 +66,28 @@ declare function useAuth(): {
56
66
  email: string;
57
67
  name: string;
58
68
  tenantId: string;
69
+ address?: {
70
+ countryCode: string;
71
+ streetAddress1: string;
72
+ streetAddress2: string | null;
73
+ locality: string | null;
74
+ region: string | null;
75
+ postCode: string;
76
+ } | undefined;
59
77
  }>;
60
- signUp: (name: string, email: string, password: string, acceptedPrivacyPolicy: boolean, acceptedTermsAndConditions: boolean) => Promise<{
78
+ signUp: (name: string, email: string, password: string, address: Address | null | undefined, acceptedPrivacyPolicy: boolean, acceptedTermsAndConditions: boolean) => Promise<{
61
79
  id: string;
62
80
  email: string;
63
81
  name: string;
64
82
  tenantId: string;
83
+ address?: {
84
+ countryCode: string;
85
+ streetAddress1: string;
86
+ streetAddress2: string | null;
87
+ locality: string | null;
88
+ region: string | null;
89
+ postCode: string;
90
+ } | undefined;
65
91
  }>;
66
92
  signOut: () => void;
67
93
  update: (name: string, email: string, emailConfirmationToken?: string) => Promise<{
@@ -78,6 +104,6 @@ interface Cart {
78
104
  items: CartItem[];
79
105
  }
80
106
  type CartItem = OpenLineItem & {};
81
- declare function createStorefront(endpoint: string): StorefrontContext;
107
+ declare function createStorefront(endpoint: string, stateFactory?: StateFactory): StorefrontContext;
82
108
 
83
109
  export { Cart, CartItem, createStorefront, storefrontKey, useAuth, useBundle, useBundles, useCart, useProduct, useProducts };
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  // src/index.ts
2
2
  import { MoonbaseClient } from "@moonbase.sh/api-client";
3
+ import { ref } from "vue";
3
4
 
4
5
  // src/context.ts
5
6
  import { NotAuthenticatedError, OrderStatus } from "@moonbase.sh/api-client";
6
7
  import { v4 as uuidv4 } from "uuid";
7
- import { ref } from "vue";
8
8
 
9
9
  // src/symbols.ts
10
10
  var storefrontKey = Symbol("storefront");
@@ -23,35 +23,36 @@ function debounce(func, waitMs = 100) {
23
23
 
24
24
  // src/context.ts
25
25
  var _StorefrontContextImpl = class _StorefrontContextImpl {
26
- constructor(configuration, client) {
26
+ constructor(configuration, client, stateFactory) {
27
27
  this.configuration = configuration;
28
28
  this.client = client;
29
- this.currentUser = ref(null);
30
- this.loadedUser = ref(false);
29
+ this.stateFactory = stateFactory;
31
30
  this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order), 500);
31
+ this.currentUser = stateFactory("moonbase_user", null);
32
+ this.loadedUser = stateFactory("moonbase_loaded_user", false);
32
33
  if (typeof window === "undefined") {
33
- this.currentOrder = ref({
34
+ this.currentOrder = stateFactory("moonbase_current_order", {
34
35
  id: uuidv4(),
35
36
  status: OrderStatus.Open,
36
37
  currency: "",
37
38
  items: [],
38
39
  couponsApplied: []
39
40
  });
40
- this.storefront = ref({
41
+ this.storefront = stateFactory("moonbase_storefront", {
41
42
  suggestedCurrency: "",
42
43
  bundles: [],
43
44
  products: []
44
45
  });
45
- this.loadedStorefront = ref(false);
46
+ this.loadedStorefront = stateFactory("moonbase_loaded_storefront", false);
46
47
  return;
47
48
  }
48
49
  window.addEventListener("storage", (event) => this.handleStorageUpdate(event));
49
50
  const cachedOrderJson = localStorage.getItem("moonbase_session");
50
51
  if (cachedOrderJson) {
51
- this.currentOrder = ref(JSON.parse(cachedOrderJson));
52
+ this.currentOrder = stateFactory("moonbase_current_order", JSON.parse(cachedOrderJson));
52
53
  const _1 = this.refreshOrder();
53
54
  } else {
54
- this.currentOrder = ref({
55
+ this.currentOrder = stateFactory("moonbase_current_order", {
55
56
  id: uuidv4(),
56
57
  status: OrderStatus.Open,
57
58
  currency: "",
@@ -62,15 +63,15 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
62
63
  }
63
64
  const cachedStorefrontJson = localStorage.getItem(_StorefrontContextImpl.storefrontKey);
64
65
  if (cachedStorefrontJson) {
65
- this.storefront = ref(JSON.parse(cachedStorefrontJson));
66
- this.loadedStorefront = ref(true);
66
+ this.storefront = stateFactory("moonbase_storefront", JSON.parse(cachedStorefrontJson));
67
+ this.loadedStorefront = stateFactory("moonbase_loaded_storefront", true);
67
68
  } else {
68
- this.storefront = ref({
69
+ this.storefront = stateFactory("moonbase_storefront", {
69
70
  suggestedCurrency: "",
70
71
  bundles: [],
71
72
  products: []
72
73
  });
73
- this.loadedStorefront = ref(false);
74
+ this.loadedStorefront = stateFactory("moonbase_loaded_storefront", false);
74
75
  }
75
76
  const _2 = this.updateStorefront();
76
77
  const _3 = this.updateUser();
@@ -287,11 +288,12 @@ function useAuth() {
287
288
  const _ = storefront.updateStorefront();
288
289
  return user;
289
290
  },
290
- signUp: async (name, email, password, acceptedPrivacyPolicy, acceptedTermsAndConditions) => {
291
+ signUp: async (name, email, password, address, acceptedPrivacyPolicy, acceptedTermsAndConditions) => {
291
292
  const user = await storefront.client.identity.signUp(
292
293
  name,
293
294
  email,
294
295
  password,
296
+ address,
295
297
  acceptedPrivacyPolicy,
296
298
  acceptedTermsAndConditions
297
299
  );
@@ -324,11 +326,16 @@ function useAuth() {
324
326
  }
325
327
 
326
328
  // src/index.ts
327
- function createStorefront(endpoint) {
329
+ function createStorefront(endpoint, stateFactory) {
328
330
  const configuration = {
329
331
  endpoint
330
332
  };
331
- return new StorefrontContextImpl(configuration, new MoonbaseClient(configuration));
333
+ return new StorefrontContextImpl(
334
+ configuration,
335
+ new MoonbaseClient(configuration),
336
+ // Default to vue refs but allow stuff like Nuxt useState wrappers
337
+ stateFactory || ((_, state) => ref(state))
338
+ );
332
339
  }
333
340
  export {
334
341
  createStorefront,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/vue",
3
3
  "type": "module",
4
- "version": "0.1.40",
4
+ "version": "0.1.42",
5
5
  "description": "Package to let you build vue.js storefronts with Moonbase.sh as payment and delivery provider",
6
6
  "author": "Tobias Lønnerød Madsen <m@dsen.tv>",
7
7
  "license": "MIT",
@@ -12,13 +12,13 @@
12
12
  "files": [
13
13
  "dist/**"
14
14
  ],
15
+ "peerDependencies": {
16
+ "vue": "^3.2.0"
17
+ },
15
18
  "dependencies": {
16
19
  "@vue/devtools-api": "^6.5.0",
17
20
  "uuid": "^9.0.0",
18
- "@moonbase.sh/api-client": "0.1.40"
19
- },
20
- "peerDependencies": {
21
- "vue": "^3.2.0"
21
+ "@moonbase.sh/api-client": "0.1.42"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/uuid": "^9.0.1",