@moonbase.sh/vue 0.2.53 → 0.2.54

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
@@ -134,10 +134,9 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
134
134
  this.configuration = configuration;
135
135
  this.client = client;
136
136
  this.stateFactory = stateFactory;
137
- this.hasUtm = (0, import_vue.computed)(() => !!this.utm.value && Object.values(this.utm.value).some((v) => !!v));
138
137
  this.currentUser = (0, import_vue.ref)(null);
139
138
  this.loadedUser = (0, import_vue.ref)(false);
140
- this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order, void 0, this.hasUtm.value ? this.utm.value : void 0), 500);
139
+ this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order, void 0, this.hasUtm ? this.utm.value : void 0), 500);
141
140
  var _a;
142
141
  if (typeof window === "undefined") {
143
142
  this.currentOrder = (0, import_vue.ref)({
@@ -153,11 +152,12 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
153
152
  products: []
154
153
  });
155
154
  this.loadedStorefront = stateFactory(`${_StorefrontContextImpl.storefrontKey}_loaded`, false);
156
- this.utm = stateFactory(`${_StorefrontContextImpl.storefrontKey}_utm`, void 0);
155
+ this.utm = stateFactory(_StorefrontContextImpl.utmKey, void 0);
157
156
  return;
158
157
  }
158
+ window.addEventListener("storage", (event) => this.handleStorageUpdate(event));
159
159
  const urlParams = new URLSearchParams(window.location.search);
160
- this.utm = stateFactory(`${_StorefrontContextImpl.storefrontKey}_utm`, {
160
+ this.utm = stateFactory(_StorefrontContextImpl.utmKey, {
161
161
  referrer: ((_a = window.document.referrer) == null ? void 0 : _a.replace(/https?:\/\//g, "").split("/")[0]) || void 0,
162
162
  source: urlParams.get("utm_source") || void 0,
163
163
  medium: urlParams.get("utm_medium") || void 0,
@@ -165,7 +165,17 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
165
165
  term: urlParams.get("utm_term") || void 0,
166
166
  content: urlParams.get("utm_content") || void 0
167
167
  });
168
- window.addEventListener("storage", (event) => this.handleStorageUpdate(event));
168
+ if (this.hasUtm) {
169
+ localStorage.setItem(_StorefrontContextImpl.utmKey, JSON.stringify(this.utm.value));
170
+ } else {
171
+ const cachedUtm = localStorage.getItem(_StorefrontContextImpl.utmKey);
172
+ if (cachedUtm) {
173
+ try {
174
+ this.utm = stateFactory(_StorefrontContextImpl.utmKey, JSON.parse(cachedUtm));
175
+ } catch (e) {
176
+ }
177
+ }
178
+ }
169
179
  const cachedOrderJson = localStorage.getItem(_StorefrontContextImpl.sessionKey);
170
180
  if (cachedOrderJson) {
171
181
  this.currentOrder = (0, import_vue.ref)(JSON.parse(cachedOrderJson));
@@ -220,6 +230,9 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
220
230
  }, { immediate: true });
221
231
  });
222
232
  }
233
+ get hasUtm() {
234
+ return !!this.utm.value && Object.values(this.utm.value).some((v) => !!v);
235
+ }
223
236
  get loadedUserPromise() {
224
237
  return new Promise((resolve) => {
225
238
  (0, import_vue.watch)(this.loadedUser, (isLoaded) => {
@@ -253,7 +266,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
253
266
  return this.currentUser.value;
254
267
  }
255
268
  async updateStorefront() {
256
- const latestStorefront = await this.client.storefront.get(this.hasUtm.value ? this.utm.value : void 0);
269
+ const latestStorefront = await this.client.storefront.get(this.hasUtm ? this.utm.value : void 0);
257
270
  if (latestStorefront) {
258
271
  if (typeof window !== "undefined")
259
272
  localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(latestStorefront));
@@ -306,8 +319,10 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
306
319
  items: [],
307
320
  couponsApplied: []
308
321
  };
309
- if (typeof window !== "undefined")
322
+ if (typeof window !== "undefined") {
310
323
  localStorage.removeItem(_StorefrontContextImpl.sessionKey);
324
+ localStorage.removeItem(_StorefrontContextImpl.utmKey);
325
+ }
311
326
  }
312
327
  async surrenderOrder() {
313
328
  try {
@@ -323,6 +338,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
323
338
  _StorefrontContextImpl.userKey = "moonbase_user";
324
339
  _StorefrontContextImpl.sessionKey = "moonbase_session";
325
340
  _StorefrontContextImpl.storefrontKey = "moonbase_storefront";
341
+ _StorefrontContextImpl.utmKey = "moonbase_utm";
326
342
  var StorefrontContextImpl = _StorefrontContextImpl;
327
343
 
328
344
  // src/index.ts
@@ -647,7 +663,7 @@ function useCart(context) {
647
663
  const absoluteReturnUrl = new URL((_a = options.returnUrl) != null ? _a : fallbackPath, document.baseURI).href;
648
664
  const updatedOrder = await storefront.client.orders.pushContent(storefront.currentOrder.value, {
649
665
  returnUrl: absoluteReturnUrl
650
- });
666
+ }, storefront.hasUtm ? storefront.utm.value : void 0);
651
667
  if (!options.redirect && updatedOrder.embeddedCheckoutUrl && typeof window !== "undefined") {
652
668
  const embeddedUrl = updatedOrder.embeddedCheckoutUrl;
653
669
  return new Promise((resolve) => {
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _moonbase_sh_storefront_api from '@moonbase.sh/storefront-api';
2
- import { MoonbaseConfiguration, Storefront, Order, User, MoonbaseClient, CompletedOrder, StorefrontBundle, StorefrontProduct, ActivationMethod, Activation, Download, ActivationRequest, PricingVariation, CommunicationPreferences, LineItem } from '@moonbase.sh/storefront-api';
2
+ import { MoonbaseConfiguration, Storefront, Order, User, UrchinTrackingModule, MoonbaseClient, CompletedOrder, StorefrontBundle, StorefrontProduct, ActivationMethod, Activation, Download, ActivationRequest, PricingVariation, CommunicationPreferences, LineItem } from '@moonbase.sh/storefront-api';
3
3
  export * from '@moonbase.sh/storefront-api';
4
4
  import * as vue from 'vue';
5
5
  import { Plugin, Ref, App, UnwrapRef, InjectionKey } from 'vue';
@@ -15,6 +15,8 @@ interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
15
15
  currentUser: Ref<User | null>;
16
16
  loadedUser: Ref<boolean>;
17
17
  loadedUserPromise: Promise<void>;
18
+ utm: Ref<UrchinTrackingModule | undefined>;
19
+ hasUtm: boolean;
18
20
  client: MoonbaseClient;
19
21
  updateUser: () => Promise<User | null>;
20
22
  updateStorefront: () => Promise<Storefront>;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _moonbase_sh_storefront_api from '@moonbase.sh/storefront-api';
2
- import { MoonbaseConfiguration, Storefront, Order, User, MoonbaseClient, CompletedOrder, StorefrontBundle, StorefrontProduct, ActivationMethod, Activation, Download, ActivationRequest, PricingVariation, CommunicationPreferences, LineItem } from '@moonbase.sh/storefront-api';
2
+ import { MoonbaseConfiguration, Storefront, Order, User, UrchinTrackingModule, MoonbaseClient, CompletedOrder, StorefrontBundle, StorefrontProduct, ActivationMethod, Activation, Download, ActivationRequest, PricingVariation, CommunicationPreferences, LineItem } from '@moonbase.sh/storefront-api';
3
3
  export * from '@moonbase.sh/storefront-api';
4
4
  import * as vue from 'vue';
5
5
  import { Plugin, Ref, App, UnwrapRef, InjectionKey } from 'vue';
@@ -15,6 +15,8 @@ interface StorefrontContext extends Pick<Plugin, keyof Plugin> {
15
15
  currentUser: Ref<User | null>;
16
16
  loadedUser: Ref<boolean>;
17
17
  loadedUserPromise: Promise<void>;
18
+ utm: Ref<UrchinTrackingModule | undefined>;
19
+ hasUtm: boolean;
18
20
  client: MoonbaseClient;
19
21
  updateUser: () => Promise<User | null>;
20
22
  updateStorefront: () => Promise<Storefront>;
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 { computed, ref, watch } from "vue";
7
+ import { ref, watch } from "vue";
8
8
  import { NotAuthenticatedError, NotFoundError, OrderStatus } from "@moonbase.sh/storefront-api";
9
9
 
10
10
  // src/symbols.ts
@@ -99,10 +99,9 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
99
99
  this.configuration = configuration;
100
100
  this.client = client;
101
101
  this.stateFactory = stateFactory;
102
- this.hasUtm = computed(() => !!this.utm.value && Object.values(this.utm.value).some((v) => !!v));
103
102
  this.currentUser = ref(null);
104
103
  this.loadedUser = ref(false);
105
- this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order, void 0, this.hasUtm.value ? this.utm.value : void 0), 500);
104
+ this.debouncedPushOrderContent = debounce((order) => this.client.orders.pushContent(order, void 0, this.hasUtm ? this.utm.value : void 0), 500);
106
105
  var _a;
107
106
  if (typeof window === "undefined") {
108
107
  this.currentOrder = ref({
@@ -118,11 +117,12 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
118
117
  products: []
119
118
  });
120
119
  this.loadedStorefront = stateFactory(`${_StorefrontContextImpl.storefrontKey}_loaded`, false);
121
- this.utm = stateFactory(`${_StorefrontContextImpl.storefrontKey}_utm`, void 0);
120
+ this.utm = stateFactory(_StorefrontContextImpl.utmKey, void 0);
122
121
  return;
123
122
  }
123
+ window.addEventListener("storage", (event) => this.handleStorageUpdate(event));
124
124
  const urlParams = new URLSearchParams(window.location.search);
125
- this.utm = stateFactory(`${_StorefrontContextImpl.storefrontKey}_utm`, {
125
+ this.utm = stateFactory(_StorefrontContextImpl.utmKey, {
126
126
  referrer: ((_a = window.document.referrer) == null ? void 0 : _a.replace(/https?:\/\//g, "").split("/")[0]) || void 0,
127
127
  source: urlParams.get("utm_source") || void 0,
128
128
  medium: urlParams.get("utm_medium") || void 0,
@@ -130,7 +130,17 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
130
130
  term: urlParams.get("utm_term") || void 0,
131
131
  content: urlParams.get("utm_content") || void 0
132
132
  });
133
- window.addEventListener("storage", (event) => this.handleStorageUpdate(event));
133
+ if (this.hasUtm) {
134
+ localStorage.setItem(_StorefrontContextImpl.utmKey, JSON.stringify(this.utm.value));
135
+ } else {
136
+ const cachedUtm = localStorage.getItem(_StorefrontContextImpl.utmKey);
137
+ if (cachedUtm) {
138
+ try {
139
+ this.utm = stateFactory(_StorefrontContextImpl.utmKey, JSON.parse(cachedUtm));
140
+ } catch (e) {
141
+ }
142
+ }
143
+ }
134
144
  const cachedOrderJson = localStorage.getItem(_StorefrontContextImpl.sessionKey);
135
145
  if (cachedOrderJson) {
136
146
  this.currentOrder = ref(JSON.parse(cachedOrderJson));
@@ -185,6 +195,9 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
185
195
  }, { immediate: true });
186
196
  });
187
197
  }
198
+ get hasUtm() {
199
+ return !!this.utm.value && Object.values(this.utm.value).some((v) => !!v);
200
+ }
188
201
  get loadedUserPromise() {
189
202
  return new Promise((resolve) => {
190
203
  watch(this.loadedUser, (isLoaded) => {
@@ -218,7 +231,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
218
231
  return this.currentUser.value;
219
232
  }
220
233
  async updateStorefront() {
221
- const latestStorefront = await this.client.storefront.get(this.hasUtm.value ? this.utm.value : void 0);
234
+ const latestStorefront = await this.client.storefront.get(this.hasUtm ? this.utm.value : void 0);
222
235
  if (latestStorefront) {
223
236
  if (typeof window !== "undefined")
224
237
  localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(latestStorefront));
@@ -271,8 +284,10 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
271
284
  items: [],
272
285
  couponsApplied: []
273
286
  };
274
- if (typeof window !== "undefined")
287
+ if (typeof window !== "undefined") {
275
288
  localStorage.removeItem(_StorefrontContextImpl.sessionKey);
289
+ localStorage.removeItem(_StorefrontContextImpl.utmKey);
290
+ }
276
291
  }
277
292
  async surrenderOrder() {
278
293
  try {
@@ -288,6 +303,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
288
303
  _StorefrontContextImpl.userKey = "moonbase_user";
289
304
  _StorefrontContextImpl.sessionKey = "moonbase_session";
290
305
  _StorefrontContextImpl.storefrontKey = "moonbase_storefront";
306
+ _StorefrontContextImpl.utmKey = "moonbase_utm";
291
307
  var StorefrontContextImpl = _StorefrontContextImpl;
292
308
 
293
309
  // src/index.ts
@@ -612,7 +628,7 @@ function useCart(context) {
612
628
  const absoluteReturnUrl = new URL((_a = options.returnUrl) != null ? _a : fallbackPath, document.baseURI).href;
613
629
  const updatedOrder = await storefront.client.orders.pushContent(storefront.currentOrder.value, {
614
630
  returnUrl: absoluteReturnUrl
615
- });
631
+ }, storefront.hasUtm ? storefront.utm.value : void 0);
616
632
  if (!options.redirect && updatedOrder.embeddedCheckoutUrl && typeof window !== "undefined") {
617
633
  const embeddedUrl = updatedOrder.embeddedCheckoutUrl;
618
634
  return new Promise((resolve) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/vue",
3
3
  "type": "module",
4
- "version": "0.2.53",
4
+ "version": "0.2.54",
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.2.53"
22
+ "@moonbase.sh/storefront-api": "0.2.54"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/uuid": "^9.0.8",