@moonbase.sh/vue 0.1.38 → 0.1.40

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
@@ -54,13 +54,29 @@ function debounce(func, waitMs = 100) {
54
54
  }
55
55
 
56
56
  // src/context.ts
57
- var StorefrontContextImpl = class {
57
+ var _StorefrontContextImpl = class _StorefrontContextImpl {
58
58
  constructor(configuration, client) {
59
59
  this.configuration = configuration;
60
60
  this.client = client;
61
61
  this.currentUser = (0, import_vue.ref)(null);
62
62
  this.loadedUser = (0, import_vue.ref)(false);
63
63
  this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order), 500);
64
+ if (typeof window === "undefined") {
65
+ this.currentOrder = (0, import_vue.ref)({
66
+ id: (0, import_uuid.v4)(),
67
+ status: import_api_client.OrderStatus.Open,
68
+ currency: "",
69
+ items: [],
70
+ couponsApplied: []
71
+ });
72
+ this.storefront = (0, import_vue.ref)({
73
+ suggestedCurrency: "",
74
+ bundles: [],
75
+ products: []
76
+ });
77
+ this.loadedStorefront = (0, import_vue.ref)(false);
78
+ return;
79
+ }
64
80
  window.addEventListener("storage", (event) => this.handleStorageUpdate(event));
65
81
  const cachedOrderJson = localStorage.getItem("moonbase_session");
66
82
  if (cachedOrderJson) {
@@ -74,9 +90,9 @@ var StorefrontContextImpl = class {
74
90
  items: [],
75
91
  couponsApplied: []
76
92
  });
77
- localStorage.setItem("moonbase_session", JSON.stringify(this.currentOrder.value));
93
+ localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(this.currentOrder.value));
78
94
  }
79
- const cachedStorefrontJson = localStorage.getItem("moonbase_storefront");
95
+ const cachedStorefrontJson = localStorage.getItem(_StorefrontContextImpl.storefrontKey);
80
96
  if (cachedStorefrontJson) {
81
97
  this.storefront = (0, import_vue.ref)(JSON.parse(cachedStorefrontJson));
82
98
  this.loadedStorefront = (0, import_vue.ref)(true);
@@ -108,7 +124,8 @@ var StorefrontContextImpl = class {
108
124
  async updateStorefront() {
109
125
  const latestStorefront = await this.client.storefront.get();
110
126
  if (latestStorefront) {
111
- localStorage.setItem("moonbase_storefront", JSON.stringify(latestStorefront));
127
+ if (typeof window !== "undefined")
128
+ localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(latestStorefront));
112
129
  this.storefront.value = latestStorefront;
113
130
  this.loadedStorefront.value = true;
114
131
  if (!this.currentOrder.value.currency) {
@@ -118,15 +135,16 @@ var StorefrontContextImpl = class {
118
135
  }
119
136
  }
120
137
  async pushOrderContent() {
121
- localStorage.setItem("moonbase_session", JSON.stringify(this.currentOrder.value));
138
+ if (typeof window !== "undefined")
139
+ localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(this.currentOrder.value));
122
140
  const _ = this.debouncedPushOrderContent(this.currentOrder.value);
123
141
  }
124
142
  handleStorageUpdate(event) {
125
143
  switch (event.key) {
126
- case "moonbase_session":
144
+ case _StorefrontContextImpl.sessionKey:
127
145
  this.currentOrder.value = JSON.parse(event.newValue);
128
146
  break;
129
- case "moonbase_storefront":
147
+ case _StorefrontContextImpl.storefrontKey:
130
148
  this.storefront.value = JSON.parse(event.newValue);
131
149
  break;
132
150
  }
@@ -138,7 +156,8 @@ var StorefrontContextImpl = class {
138
156
  if (latestOrder.status !== import_api_client.OrderStatus.Open) {
139
157
  this.resetOrder();
140
158
  } else {
141
- localStorage.setItem("moonbase_session", JSON.stringify(latestOrder));
159
+ if (typeof window !== "undefined")
160
+ localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(latestOrder));
142
161
  this.currentOrder.value = latestOrder;
143
162
  }
144
163
  }
@@ -156,9 +175,13 @@ var StorefrontContextImpl = class {
156
175
  items: [],
157
176
  couponsApplied: []
158
177
  };
159
- localStorage.setItem("moonbase_session", JSON.stringify(this.currentOrder.value));
178
+ if (typeof window !== "undefined")
179
+ localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(this.currentOrder.value));
160
180
  }
161
181
  };
182
+ _StorefrontContextImpl.sessionKey = "moonbase_session";
183
+ _StorefrontContextImpl.storefrontKey = "moonbase_storefront";
184
+ var StorefrontContextImpl = _StorefrontContextImpl;
162
185
 
163
186
  // src/index.ts
164
187
  __reExport(src_exports, require("@moonbase.sh/api-client"), module.exports);
@@ -273,7 +296,7 @@ function useCart() {
273
296
  returnUrl: absoluteReturnUrl
274
297
  });
275
298
  storefront.currentOrder.value = updatedOrder;
276
- if (updatedOrder.checkoutUrl && (window == null ? void 0 : window.location))
299
+ if (updatedOrder.checkoutUrl && typeof window !== "undefined")
277
300
  window.location.href = updatedOrder.checkoutUrl;
278
301
  else
279
302
  throw new Error("No checkout URL found");
package/dist/index.js CHANGED
@@ -22,13 +22,29 @@ function debounce(func, waitMs = 100) {
22
22
  }
23
23
 
24
24
  // src/context.ts
25
- var StorefrontContextImpl = class {
25
+ var _StorefrontContextImpl = class _StorefrontContextImpl {
26
26
  constructor(configuration, client) {
27
27
  this.configuration = configuration;
28
28
  this.client = client;
29
29
  this.currentUser = ref(null);
30
30
  this.loadedUser = ref(false);
31
31
  this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order), 500);
32
+ if (typeof window === "undefined") {
33
+ this.currentOrder = ref({
34
+ id: uuidv4(),
35
+ status: OrderStatus.Open,
36
+ currency: "",
37
+ items: [],
38
+ couponsApplied: []
39
+ });
40
+ this.storefront = ref({
41
+ suggestedCurrency: "",
42
+ bundles: [],
43
+ products: []
44
+ });
45
+ this.loadedStorefront = ref(false);
46
+ return;
47
+ }
32
48
  window.addEventListener("storage", (event) => this.handleStorageUpdate(event));
33
49
  const cachedOrderJson = localStorage.getItem("moonbase_session");
34
50
  if (cachedOrderJson) {
@@ -42,9 +58,9 @@ var StorefrontContextImpl = class {
42
58
  items: [],
43
59
  couponsApplied: []
44
60
  });
45
- localStorage.setItem("moonbase_session", JSON.stringify(this.currentOrder.value));
61
+ localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(this.currentOrder.value));
46
62
  }
47
- const cachedStorefrontJson = localStorage.getItem("moonbase_storefront");
63
+ const cachedStorefrontJson = localStorage.getItem(_StorefrontContextImpl.storefrontKey);
48
64
  if (cachedStorefrontJson) {
49
65
  this.storefront = ref(JSON.parse(cachedStorefrontJson));
50
66
  this.loadedStorefront = ref(true);
@@ -76,7 +92,8 @@ var StorefrontContextImpl = class {
76
92
  async updateStorefront() {
77
93
  const latestStorefront = await this.client.storefront.get();
78
94
  if (latestStorefront) {
79
- localStorage.setItem("moonbase_storefront", JSON.stringify(latestStorefront));
95
+ if (typeof window !== "undefined")
96
+ localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(latestStorefront));
80
97
  this.storefront.value = latestStorefront;
81
98
  this.loadedStorefront.value = true;
82
99
  if (!this.currentOrder.value.currency) {
@@ -86,15 +103,16 @@ var StorefrontContextImpl = class {
86
103
  }
87
104
  }
88
105
  async pushOrderContent() {
89
- localStorage.setItem("moonbase_session", JSON.stringify(this.currentOrder.value));
106
+ if (typeof window !== "undefined")
107
+ localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(this.currentOrder.value));
90
108
  const _ = this.debouncedPushOrderContent(this.currentOrder.value);
91
109
  }
92
110
  handleStorageUpdate(event) {
93
111
  switch (event.key) {
94
- case "moonbase_session":
112
+ case _StorefrontContextImpl.sessionKey:
95
113
  this.currentOrder.value = JSON.parse(event.newValue);
96
114
  break;
97
- case "moonbase_storefront":
115
+ case _StorefrontContextImpl.storefrontKey:
98
116
  this.storefront.value = JSON.parse(event.newValue);
99
117
  break;
100
118
  }
@@ -106,7 +124,8 @@ var StorefrontContextImpl = class {
106
124
  if (latestOrder.status !== OrderStatus.Open) {
107
125
  this.resetOrder();
108
126
  } else {
109
- localStorage.setItem("moonbase_session", JSON.stringify(latestOrder));
127
+ if (typeof window !== "undefined")
128
+ localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(latestOrder));
110
129
  this.currentOrder.value = latestOrder;
111
130
  }
112
131
  }
@@ -124,9 +143,13 @@ var StorefrontContextImpl = class {
124
143
  items: [],
125
144
  couponsApplied: []
126
145
  };
127
- localStorage.setItem("moonbase_session", JSON.stringify(this.currentOrder.value));
146
+ if (typeof window !== "undefined")
147
+ localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(this.currentOrder.value));
128
148
  }
129
149
  };
150
+ _StorefrontContextImpl.sessionKey = "moonbase_session";
151
+ _StorefrontContextImpl.storefrontKey = "moonbase_storefront";
152
+ var StorefrontContextImpl = _StorefrontContextImpl;
130
153
 
131
154
  // src/index.ts
132
155
  export * from "@moonbase.sh/api-client";
@@ -241,7 +264,7 @@ function useCart() {
241
264
  returnUrl: absoluteReturnUrl
242
265
  });
243
266
  storefront.currentOrder.value = updatedOrder;
244
- if (updatedOrder.checkoutUrl && (window == null ? void 0 : window.location))
267
+ if (updatedOrder.checkoutUrl && typeof window !== "undefined")
245
268
  window.location.href = updatedOrder.checkoutUrl;
246
269
  else
247
270
  throw new Error("No checkout URL found");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/vue",
3
3
  "type": "module",
4
- "version": "0.1.38",
4
+ "version": "0.1.40",
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",
@@ -15,7 +15,7 @@
15
15
  "dependencies": {
16
16
  "@vue/devtools-api": "^6.5.0",
17
17
  "uuid": "^9.0.0",
18
- "@moonbase.sh/api-client": "0.1.38"
18
+ "@moonbase.sh/api-client": "0.1.40"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "vue": "^3.2.0"