@moonbase.sh/vue 0.3.28 → 0.3.31

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
@@ -142,7 +142,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
142
142
  this.currentUser = (0, import_vue.ref)(null);
143
143
  this.loadedUser = (0, import_vue.ref)(false);
144
144
  this.refreshOrderAbortController = new AbortController();
145
- this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order, void 0, this.hasUtm ? this.utm.value : void 0), 500);
145
+ this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order, void 0, this.hasUtmOrReferrer ? this.utm.value : void 0), 500);
146
146
  var _a;
147
147
  if (typeof window === "undefined") {
148
148
  this.currentOrder = (0, import_vue.ref)({
@@ -171,14 +171,17 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
171
171
  term: urlParams.get("utm_term") || void 0,
172
172
  content: urlParams.get("utm_content") || void 0
173
173
  });
174
- if (this.hasUtm && configuration.persistUtm) {
175
- localStorage.setItem(_StorefrontContextImpl.utmKey, JSON.stringify(this.utm.value));
176
- } else if (configuration.persistUtm) {
177
- const cachedUtm = localStorage.getItem(_StorefrontContextImpl.utmKey);
174
+ if (this.hasUtm) {
175
+ (configuration.persistUtm ? localStorage : sessionStorage).setItem(_StorefrontContextImpl.utmKey, JSON.stringify(this.utm.value));
176
+ console.log("Caching given UTM parameters:", (0, import_vue.toRaw)(this.utm.value));
177
+ } else {
178
+ const cachedUtm = (configuration.persistUtm ? localStorage : sessionStorage).getItem(_StorefrontContextImpl.utmKey);
178
179
  if (cachedUtm) {
179
180
  try {
180
181
  this.utm = stateFactory(_StorefrontContextImpl.utmKey, JSON.parse(cachedUtm));
181
- } catch (e) {
182
+ console.log("Using cached UTM parameters:", (0, import_vue.toRaw)(this.utm.value));
183
+ } catch (err) {
184
+ console.warn(`Could not parse cached UTM from ${_StorefrontContextImpl.utmKey}`, err);
182
185
  }
183
186
  }
184
187
  }
@@ -194,7 +197,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
194
197
  items: [],
195
198
  couponsApplied: []
196
199
  });
197
- if (this.hasUtm) {
200
+ if (this.hasUtmOrReferrer) {
198
201
  this.pushOrderContent();
199
202
  }
200
203
  }
@@ -247,6 +250,9 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
247
250
  get hasUtm() {
248
251
  return !!this.utm.value && !!(this.utm.value.source || this.utm.value.medium || this.utm.value.campaign || this.utm.value.term || this.utm.value.content);
249
252
  }
253
+ get hasUtmOrReferrer() {
254
+ return !!this.utm.value && Object.values(this.utm.value).some((v) => !!v);
255
+ }
250
256
  get loadedUserPromise() {
251
257
  return new Promise((resolve) => {
252
258
  (0, import_vue.watch)(this.loadedUser, (isLoaded) => {
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  TokenStore
13
13
  } from "@moonbase.sh/storefront-api";
14
14
  import { v4 as uuidv4 } from "uuid";
15
- import { ref, watch } from "vue";
15
+ import { ref, toRaw, watch } from "vue";
16
16
 
17
17
  // src/symbols.ts
18
18
  var storefrontKey = Symbol("storefront");
@@ -112,7 +112,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
112
112
  this.currentUser = ref(null);
113
113
  this.loadedUser = ref(false);
114
114
  this.refreshOrderAbortController = new AbortController();
115
- this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order, void 0, this.hasUtm ? this.utm.value : void 0), 500);
115
+ this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order, void 0, this.hasUtmOrReferrer ? this.utm.value : void 0), 500);
116
116
  var _a;
117
117
  if (typeof window === "undefined") {
118
118
  this.currentOrder = ref({
@@ -141,14 +141,17 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
141
141
  term: urlParams.get("utm_term") || void 0,
142
142
  content: urlParams.get("utm_content") || void 0
143
143
  });
144
- if (this.hasUtm && configuration.persistUtm) {
145
- localStorage.setItem(_StorefrontContextImpl.utmKey, JSON.stringify(this.utm.value));
146
- } else if (configuration.persistUtm) {
147
- const cachedUtm = localStorage.getItem(_StorefrontContextImpl.utmKey);
144
+ if (this.hasUtm) {
145
+ (configuration.persistUtm ? localStorage : sessionStorage).setItem(_StorefrontContextImpl.utmKey, JSON.stringify(this.utm.value));
146
+ console.log("Caching given UTM parameters:", toRaw(this.utm.value));
147
+ } else {
148
+ const cachedUtm = (configuration.persistUtm ? localStorage : sessionStorage).getItem(_StorefrontContextImpl.utmKey);
148
149
  if (cachedUtm) {
149
150
  try {
150
151
  this.utm = stateFactory(_StorefrontContextImpl.utmKey, JSON.parse(cachedUtm));
151
- } catch (e) {
152
+ console.log("Using cached UTM parameters:", toRaw(this.utm.value));
153
+ } catch (err) {
154
+ console.warn(`Could not parse cached UTM from ${_StorefrontContextImpl.utmKey}`, err);
152
155
  }
153
156
  }
154
157
  }
@@ -164,7 +167,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
164
167
  items: [],
165
168
  couponsApplied: []
166
169
  });
167
- if (this.hasUtm) {
170
+ if (this.hasUtmOrReferrer) {
168
171
  this.pushOrderContent();
169
172
  }
170
173
  }
@@ -217,6 +220,9 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
217
220
  get hasUtm() {
218
221
  return !!this.utm.value && !!(this.utm.value.source || this.utm.value.medium || this.utm.value.campaign || this.utm.value.term || this.utm.value.content);
219
222
  }
223
+ get hasUtmOrReferrer() {
224
+ return !!this.utm.value && Object.values(this.utm.value).some((v) => !!v);
225
+ }
220
226
  get loadedUserPromise() {
221
227
  return new Promise((resolve) => {
222
228
  watch(this.loadedUser, (isLoaded) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/vue",
3
3
  "type": "module",
4
- "version": "0.3.28",
4
+ "version": "0.3.31",
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",
@@ -19,7 +19,7 @@
19
19
  "@vue/devtools-api": "^6.6.3",
20
20
  "uuid": "^9.0.1",
21
21
  "zod": "^3.23.8",
22
- "@moonbase.sh/storefront-api": "0.3.28"
22
+ "@moonbase.sh/storefront-api": "0.3.31"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/uuid": "^9.0.8",