@moonbase.sh/vue 0.1.38 → 0.1.39

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,15 +54,18 @@ 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
- window.addEventListener("storage", (event) => this.handleStorageUpdate(event));
65
- const cachedOrderJson = localStorage.getItem("moonbase_session");
64
+ if (typeof window !== "undefined")
65
+ window.addEventListener("storage", (event) => this.handleStorageUpdate(event));
66
+ let cachedOrderJson = null;
67
+ if (typeof window !== "undefined")
68
+ cachedOrderJson = localStorage.getItem("moonbase_session");
66
69
  if (cachedOrderJson) {
67
70
  this.currentOrder = (0, import_vue.ref)(JSON.parse(cachedOrderJson));
68
71
  const _1 = this.refreshOrder();
@@ -74,9 +77,12 @@ var StorefrontContextImpl = class {
74
77
  items: [],
75
78
  couponsApplied: []
76
79
  });
77
- localStorage.setItem("moonbase_session", JSON.stringify(this.currentOrder.value));
80
+ if (typeof window !== "undefined")
81
+ localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(this.currentOrder.value));
78
82
  }
79
- const cachedStorefrontJson = localStorage.getItem("moonbase_storefront");
83
+ let cachedStorefrontJson = null;
84
+ if (typeof window !== "undefined")
85
+ cachedStorefrontJson = localStorage.getItem(_StorefrontContextImpl.storefrontKey);
80
86
  if (cachedStorefrontJson) {
81
87
  this.storefront = (0, import_vue.ref)(JSON.parse(cachedStorefrontJson));
82
88
  this.loadedStorefront = (0, import_vue.ref)(true);
@@ -108,7 +114,8 @@ var StorefrontContextImpl = class {
108
114
  async updateStorefront() {
109
115
  const latestStorefront = await this.client.storefront.get();
110
116
  if (latestStorefront) {
111
- localStorage.setItem("moonbase_storefront", JSON.stringify(latestStorefront));
117
+ if (typeof window !== "undefined")
118
+ localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(latestStorefront));
112
119
  this.storefront.value = latestStorefront;
113
120
  this.loadedStorefront.value = true;
114
121
  if (!this.currentOrder.value.currency) {
@@ -118,15 +125,16 @@ var StorefrontContextImpl = class {
118
125
  }
119
126
  }
120
127
  async pushOrderContent() {
121
- localStorage.setItem("moonbase_session", JSON.stringify(this.currentOrder.value));
128
+ if (typeof window !== "undefined")
129
+ localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(this.currentOrder.value));
122
130
  const _ = this.debouncedPushOrderContent(this.currentOrder.value);
123
131
  }
124
132
  handleStorageUpdate(event) {
125
133
  switch (event.key) {
126
- case "moonbase_session":
134
+ case _StorefrontContextImpl.sessionKey:
127
135
  this.currentOrder.value = JSON.parse(event.newValue);
128
136
  break;
129
- case "moonbase_storefront":
137
+ case _StorefrontContextImpl.storefrontKey:
130
138
  this.storefront.value = JSON.parse(event.newValue);
131
139
  break;
132
140
  }
@@ -138,7 +146,8 @@ var StorefrontContextImpl = class {
138
146
  if (latestOrder.status !== import_api_client.OrderStatus.Open) {
139
147
  this.resetOrder();
140
148
  } else {
141
- localStorage.setItem("moonbase_session", JSON.stringify(latestOrder));
149
+ if (typeof window !== "undefined")
150
+ localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(latestOrder));
142
151
  this.currentOrder.value = latestOrder;
143
152
  }
144
153
  }
@@ -156,9 +165,13 @@ var StorefrontContextImpl = class {
156
165
  items: [],
157
166
  couponsApplied: []
158
167
  };
159
- localStorage.setItem("moonbase_session", JSON.stringify(this.currentOrder.value));
168
+ if (typeof window !== "undefined")
169
+ localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(this.currentOrder.value));
160
170
  }
161
171
  };
172
+ _StorefrontContextImpl.sessionKey = "moonbase_session";
173
+ _StorefrontContextImpl.storefrontKey = "moonbase_storefront";
174
+ var StorefrontContextImpl = _StorefrontContextImpl;
162
175
 
163
176
  // src/index.ts
164
177
  __reExport(src_exports, require("@moonbase.sh/api-client"), module.exports);
@@ -273,7 +286,7 @@ function useCart() {
273
286
  returnUrl: absoluteReturnUrl
274
287
  });
275
288
  storefront.currentOrder.value = updatedOrder;
276
- if (updatedOrder.checkoutUrl && (window == null ? void 0 : window.location))
289
+ if (updatedOrder.checkoutUrl && typeof window !== "undefined")
277
290
  window.location.href = updatedOrder.checkoutUrl;
278
291
  else
279
292
  throw new Error("No checkout URL found");
package/dist/index.js CHANGED
@@ -22,15 +22,18 @@ 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
- window.addEventListener("storage", (event) => this.handleStorageUpdate(event));
33
- const cachedOrderJson = localStorage.getItem("moonbase_session");
32
+ if (typeof window !== "undefined")
33
+ window.addEventListener("storage", (event) => this.handleStorageUpdate(event));
34
+ let cachedOrderJson = null;
35
+ if (typeof window !== "undefined")
36
+ cachedOrderJson = localStorage.getItem("moonbase_session");
34
37
  if (cachedOrderJson) {
35
38
  this.currentOrder = ref(JSON.parse(cachedOrderJson));
36
39
  const _1 = this.refreshOrder();
@@ -42,9 +45,12 @@ var StorefrontContextImpl = class {
42
45
  items: [],
43
46
  couponsApplied: []
44
47
  });
45
- localStorage.setItem("moonbase_session", JSON.stringify(this.currentOrder.value));
48
+ if (typeof window !== "undefined")
49
+ localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(this.currentOrder.value));
46
50
  }
47
- const cachedStorefrontJson = localStorage.getItem("moonbase_storefront");
51
+ let cachedStorefrontJson = null;
52
+ if (typeof window !== "undefined")
53
+ cachedStorefrontJson = localStorage.getItem(_StorefrontContextImpl.storefrontKey);
48
54
  if (cachedStorefrontJson) {
49
55
  this.storefront = ref(JSON.parse(cachedStorefrontJson));
50
56
  this.loadedStorefront = ref(true);
@@ -76,7 +82,8 @@ var StorefrontContextImpl = class {
76
82
  async updateStorefront() {
77
83
  const latestStorefront = await this.client.storefront.get();
78
84
  if (latestStorefront) {
79
- localStorage.setItem("moonbase_storefront", JSON.stringify(latestStorefront));
85
+ if (typeof window !== "undefined")
86
+ localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(latestStorefront));
80
87
  this.storefront.value = latestStorefront;
81
88
  this.loadedStorefront.value = true;
82
89
  if (!this.currentOrder.value.currency) {
@@ -86,15 +93,16 @@ var StorefrontContextImpl = class {
86
93
  }
87
94
  }
88
95
  async pushOrderContent() {
89
- localStorage.setItem("moonbase_session", JSON.stringify(this.currentOrder.value));
96
+ if (typeof window !== "undefined")
97
+ localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(this.currentOrder.value));
90
98
  const _ = this.debouncedPushOrderContent(this.currentOrder.value);
91
99
  }
92
100
  handleStorageUpdate(event) {
93
101
  switch (event.key) {
94
- case "moonbase_session":
102
+ case _StorefrontContextImpl.sessionKey:
95
103
  this.currentOrder.value = JSON.parse(event.newValue);
96
104
  break;
97
- case "moonbase_storefront":
105
+ case _StorefrontContextImpl.storefrontKey:
98
106
  this.storefront.value = JSON.parse(event.newValue);
99
107
  break;
100
108
  }
@@ -106,7 +114,8 @@ var StorefrontContextImpl = class {
106
114
  if (latestOrder.status !== OrderStatus.Open) {
107
115
  this.resetOrder();
108
116
  } else {
109
- localStorage.setItem("moonbase_session", JSON.stringify(latestOrder));
117
+ if (typeof window !== "undefined")
118
+ localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(latestOrder));
110
119
  this.currentOrder.value = latestOrder;
111
120
  }
112
121
  }
@@ -124,9 +133,13 @@ var StorefrontContextImpl = class {
124
133
  items: [],
125
134
  couponsApplied: []
126
135
  };
127
- localStorage.setItem("moonbase_session", JSON.stringify(this.currentOrder.value));
136
+ if (typeof window !== "undefined")
137
+ localStorage.setItem(_StorefrontContextImpl.sessionKey, JSON.stringify(this.currentOrder.value));
128
138
  }
129
139
  };
140
+ _StorefrontContextImpl.sessionKey = "moonbase_session";
141
+ _StorefrontContextImpl.storefrontKey = "moonbase_storefront";
142
+ var StorefrontContextImpl = _StorefrontContextImpl;
130
143
 
131
144
  // src/index.ts
132
145
  export * from "@moonbase.sh/api-client";
@@ -241,7 +254,7 @@ function useCart() {
241
254
  returnUrl: absoluteReturnUrl
242
255
  });
243
256
  storefront.currentOrder.value = updatedOrder;
244
- if (updatedOrder.checkoutUrl && (window == null ? void 0 : window.location))
257
+ if (updatedOrder.checkoutUrl && typeof window !== "undefined")
245
258
  window.location.href = updatedOrder.checkoutUrl;
246
259
  else
247
260
  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.39",
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.39"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "vue": "^3.2.0"