@moonbase.sh/vue 0.1.93 → 0.1.96

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
@@ -63,9 +63,11 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
63
63
  this.configuration = configuration;
64
64
  this.client = client;
65
65
  this.stateFactory = stateFactory;
66
+ this.hasUtm = (0, import_vue.computed)(() => !!this.utm.value && Object.values(this.utm.value).some((v) => !!v));
66
67
  this.currentUser = (0, import_vue.ref)(null);
67
68
  this.loadedUser = (0, import_vue.ref)(false);
68
- this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order), 500);
69
+ this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order, void 0, this.hasUtm.value ? this.utm.value : void 0), 500);
70
+ var _a;
69
71
  if (typeof window === "undefined") {
70
72
  this.currentOrder = (0, import_vue.ref)({
71
73
  id: (0, import_uuid.v4)(),
@@ -80,8 +82,18 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
80
82
  products: []
81
83
  });
82
84
  this.loadedStorefront = stateFactory(`${_StorefrontContextImpl.storefrontKey}_loaded`, false);
85
+ this.utm = stateFactory(`${_StorefrontContextImpl.storefrontKey}_utm`, void 0);
83
86
  return;
84
87
  }
88
+ const urlParams = new URLSearchParams(window.location.search);
89
+ this.utm = stateFactory(`${_StorefrontContextImpl.storefrontKey}_utm`, {
90
+ referrer: ((_a = window.document.referrer) == null ? void 0 : _a.replace(/https?:\/\//g, "").split("/")[0]) || void 0,
91
+ source: urlParams.get("utm_source") || void 0,
92
+ medium: urlParams.get("utm_medium") || void 0,
93
+ campaign: urlParams.get("utm_campaign") || void 0,
94
+ term: urlParams.get("utm_term") || void 0,
95
+ content: urlParams.get("utm_content") || void 0
96
+ });
85
97
  window.addEventListener("storage", (event) => this.handleStorageUpdate(event));
86
98
  const cachedOrderJson = localStorage.getItem(_StorefrontContextImpl.sessionKey);
87
99
  if (cachedOrderJson) {
@@ -127,7 +139,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
127
139
  }
128
140
  }
129
141
  async updateStorefront() {
130
- const latestStorefront = await this.client.storefront.get();
142
+ const latestStorefront = await this.client.storefront.get(this.hasUtm.value ? this.utm.value : void 0);
131
143
  if (latestStorefront) {
132
144
  if (typeof window !== "undefined")
133
145
  localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(latestStorefront));
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { ref as ref2 } from "vue";
4
4
 
5
5
  // src/context.ts
6
6
  import { v4 as uuidv4 } from "uuid";
7
- import { ref } from "vue";
7
+ import { computed, ref } from "vue";
8
8
  import { NotAuthenticatedError, OrderStatus } from "@moonbase.sh/storefront-api";
9
9
 
10
10
  // src/symbols.ts
@@ -28,9 +28,11 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
28
28
  this.configuration = configuration;
29
29
  this.client = client;
30
30
  this.stateFactory = stateFactory;
31
+ this.hasUtm = computed(() => !!this.utm.value && Object.values(this.utm.value).some((v) => !!v));
31
32
  this.currentUser = ref(null);
32
33
  this.loadedUser = ref(false);
33
- this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order), 500);
34
+ this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order, void 0, this.hasUtm.value ? this.utm.value : void 0), 500);
35
+ var _a;
34
36
  if (typeof window === "undefined") {
35
37
  this.currentOrder = ref({
36
38
  id: uuidv4(),
@@ -45,8 +47,18 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
45
47
  products: []
46
48
  });
47
49
  this.loadedStorefront = stateFactory(`${_StorefrontContextImpl.storefrontKey}_loaded`, false);
50
+ this.utm = stateFactory(`${_StorefrontContextImpl.storefrontKey}_utm`, void 0);
48
51
  return;
49
52
  }
53
+ const urlParams = new URLSearchParams(window.location.search);
54
+ this.utm = stateFactory(`${_StorefrontContextImpl.storefrontKey}_utm`, {
55
+ referrer: ((_a = window.document.referrer) == null ? void 0 : _a.replace(/https?:\/\//g, "").split("/")[0]) || void 0,
56
+ source: urlParams.get("utm_source") || void 0,
57
+ medium: urlParams.get("utm_medium") || void 0,
58
+ campaign: urlParams.get("utm_campaign") || void 0,
59
+ term: urlParams.get("utm_term") || void 0,
60
+ content: urlParams.get("utm_content") || void 0
61
+ });
50
62
  window.addEventListener("storage", (event) => this.handleStorageUpdate(event));
51
63
  const cachedOrderJson = localStorage.getItem(_StorefrontContextImpl.sessionKey);
52
64
  if (cachedOrderJson) {
@@ -92,7 +104,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
92
104
  }
93
105
  }
94
106
  async updateStorefront() {
95
- const latestStorefront = await this.client.storefront.get();
107
+ const latestStorefront = await this.client.storefront.get(this.hasUtm.value ? this.utm.value : void 0);
96
108
  if (latestStorefront) {
97
109
  if (typeof window !== "undefined")
98
110
  localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(latestStorefront));
@@ -158,39 +170,39 @@ var StorefrontContextImpl = _StorefrontContextImpl;
158
170
  export * from "@moonbase.sh/storefront-api";
159
171
 
160
172
  // src/composables/useBundle.ts
161
- import { computed, inject } from "vue";
173
+ import { computed as computed2, inject } from "vue";
162
174
  function useBundle(bundleId) {
163
175
  const storefront = inject(storefrontKey);
164
176
  if (!storefront)
165
177
  throw new Error("No storefront configured");
166
- return computed(() => storefront.storefront.value.bundles.find((b) => b.id === bundleId) || null);
178
+ return computed2(() => storefront.storefront.value.bundles.find((b) => b.id === bundleId) || null);
167
179
  }
168
180
 
169
181
  // src/composables/useBundles.ts
170
- import { computed as computed2, inject as inject2 } from "vue";
182
+ import { computed as computed3, inject as inject2 } from "vue";
171
183
  function useBundles() {
172
184
  const storefront = inject2(storefrontKey);
173
185
  if (!storefront)
174
186
  throw new Error("No storefront configured");
175
- return computed2(() => storefront.storefront.value.bundles);
187
+ return computed3(() => storefront.storefront.value.bundles);
176
188
  }
177
189
 
178
190
  // src/composables/useProduct.ts
179
- import { computed as computed3, inject as inject3 } from "vue";
191
+ import { computed as computed4, inject as inject3 } from "vue";
180
192
  function useProduct(productId) {
181
193
  const storefront = inject3(storefrontKey);
182
194
  if (!storefront)
183
195
  throw new Error("No storefront configured");
184
- return computed3(() => storefront.storefront.value.products.find((p) => p.id === productId) || null);
196
+ return computed4(() => storefront.storefront.value.products.find((p) => p.id === productId) || null);
185
197
  }
186
198
 
187
199
  // src/composables/useProducts.ts
188
- import { computed as computed4, inject as inject4 } from "vue";
200
+ import { computed as computed5, inject as inject4 } from "vue";
189
201
  function useProducts() {
190
202
  const storefront = inject4(storefrontKey);
191
203
  if (!storefront)
192
204
  throw new Error("No storefront configured");
193
- return computed4(() => storefront.storefront.value.products);
205
+ return computed5(() => storefront.storefront.value.products);
194
206
  }
195
207
 
196
208
  // src/composables/useInventory.ts
@@ -226,7 +238,7 @@ function useInventory() {
226
238
 
227
239
  // src/composables/useActivationRequest.ts
228
240
  import { ActivationRequestStatus } from "@moonbase.sh/storefront-api";
229
- import { computed as computed5, inject as inject6, onBeforeUnmount, watch } from "vue";
241
+ import { computed as computed6, inject as inject6, onBeforeUnmount, watch } from "vue";
230
242
  function useActivationRequest(requestId) {
231
243
  const storefront = inject6(storefrontKey);
232
244
  if (!storefront)
@@ -266,7 +278,7 @@ function useActivationRequest(requestId) {
266
278
  activationRequest,
267
279
  loading,
268
280
  error,
269
- isInstalled: computed5(() => {
281
+ isInstalled: computed6(() => {
270
282
  var _a;
271
283
  return activationRequest && ((_a = activationRequest.value) == null ? void 0 : _a.status) === ActivationRequestStatus.Completed;
272
284
  }),
@@ -298,13 +310,13 @@ function useVoucher() {
298
310
  }
299
311
 
300
312
  // src/composables/useCart.ts
301
- import { computed as computed6, inject as inject8, unref } from "vue";
313
+ import { computed as computed7, inject as inject8, unref } from "vue";
302
314
  function useCart() {
303
315
  const storefront = inject8(storefrontKey);
304
316
  if (!storefront)
305
317
  throw new Error("No storefront configured");
306
318
  return {
307
- items: computed6(() => storefront.currentOrder.value.items.map((item) => {
319
+ items: computed7(() => storefront.currentOrder.value.items.map((item) => {
308
320
  if (item.type === "Product") {
309
321
  const product = storefront.storefront.value.products.find((p) => p.id === item.productId);
310
322
  const variations = (product == null ? void 0 : product.variations) || [];
@@ -327,8 +339,8 @@ function useCart() {
327
339
  };
328
340
  }
329
341
  })),
330
- currency: computed6(() => storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency),
331
- total: computed6(() => {
342
+ currency: computed7(() => storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency),
343
+ total: computed7(() => {
332
344
  const currency = storefront.currentOrder.value.currency || storefront.storefront.value.suggestedCurrency;
333
345
  const total = storefront.currentOrder.value.items.reduce((agg, item) => {
334
346
  var _a, _b, _c, _d, _e, _f;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/vue",
3
3
  "type": "module",
4
- "version": "0.1.93",
4
+ "version": "0.1.96",
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",
@@ -18,7 +18,7 @@
18
18
  "dependencies": {
19
19
  "@vue/devtools-api": "^6.5.1",
20
20
  "uuid": "^9.0.1",
21
- "@moonbase.sh/storefront-api": "0.1.93"
21
+ "@moonbase.sh/storefront-api": "0.1.96"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/uuid": "^9.0.7",