@moonbase.sh/vue 0.2.53 → 0.2.56
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 +24 -7
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +25 -8
- package/package.json +2 -2
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
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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));
|
|
@@ -178,6 +188,9 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
178
188
|
items: [],
|
|
179
189
|
couponsApplied: []
|
|
180
190
|
});
|
|
191
|
+
if (this.hasUtm) {
|
|
192
|
+
const _ = this.pushOrderContent();
|
|
193
|
+
}
|
|
181
194
|
}
|
|
182
195
|
const cachedStorefrontJson = localStorage.getItem(_StorefrontContextImpl.storefrontKey);
|
|
183
196
|
if (cachedStorefrontJson) {
|
|
@@ -220,6 +233,9 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
220
233
|
}, { immediate: true });
|
|
221
234
|
});
|
|
222
235
|
}
|
|
236
|
+
get hasUtm() {
|
|
237
|
+
return !!this.utm.value && Object.values(this.utm.value).some((v) => !!v);
|
|
238
|
+
}
|
|
223
239
|
get loadedUserPromise() {
|
|
224
240
|
return new Promise((resolve) => {
|
|
225
241
|
(0, import_vue.watch)(this.loadedUser, (isLoaded) => {
|
|
@@ -253,7 +269,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
253
269
|
return this.currentUser.value;
|
|
254
270
|
}
|
|
255
271
|
async updateStorefront() {
|
|
256
|
-
const latestStorefront = await this.client.storefront.get(this.hasUtm
|
|
272
|
+
const latestStorefront = await this.client.storefront.get(this.hasUtm ? this.utm.value : void 0);
|
|
257
273
|
if (latestStorefront) {
|
|
258
274
|
if (typeof window !== "undefined")
|
|
259
275
|
localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(latestStorefront));
|
|
@@ -323,6 +339,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
323
339
|
_StorefrontContextImpl.userKey = "moonbase_user";
|
|
324
340
|
_StorefrontContextImpl.sessionKey = "moonbase_session";
|
|
325
341
|
_StorefrontContextImpl.storefrontKey = "moonbase_storefront";
|
|
342
|
+
_StorefrontContextImpl.utmKey = "moonbase_utm";
|
|
326
343
|
var StorefrontContextImpl = _StorefrontContextImpl;
|
|
327
344
|
|
|
328
345
|
// src/index.ts
|
|
@@ -647,7 +664,7 @@ function useCart(context) {
|
|
|
647
664
|
const absoluteReturnUrl = new URL((_a = options.returnUrl) != null ? _a : fallbackPath, document.baseURI).href;
|
|
648
665
|
const updatedOrder = await storefront.client.orders.pushContent(storefront.currentOrder.value, {
|
|
649
666
|
returnUrl: absoluteReturnUrl
|
|
650
|
-
});
|
|
667
|
+
}, storefront.hasUtm ? storefront.utm.value : void 0);
|
|
651
668
|
if (!options.redirect && updatedOrder.embeddedCheckoutUrl && typeof window !== "undefined") {
|
|
652
669
|
const embeddedUrl = updatedOrder.embeddedCheckoutUrl;
|
|
653
670
|
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 {
|
|
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
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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));
|
|
@@ -143,6 +153,9 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
143
153
|
items: [],
|
|
144
154
|
couponsApplied: []
|
|
145
155
|
});
|
|
156
|
+
if (this.hasUtm) {
|
|
157
|
+
const _ = this.pushOrderContent();
|
|
158
|
+
}
|
|
146
159
|
}
|
|
147
160
|
const cachedStorefrontJson = localStorage.getItem(_StorefrontContextImpl.storefrontKey);
|
|
148
161
|
if (cachedStorefrontJson) {
|
|
@@ -185,6 +198,9 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
185
198
|
}, { immediate: true });
|
|
186
199
|
});
|
|
187
200
|
}
|
|
201
|
+
get hasUtm() {
|
|
202
|
+
return !!this.utm.value && Object.values(this.utm.value).some((v) => !!v);
|
|
203
|
+
}
|
|
188
204
|
get loadedUserPromise() {
|
|
189
205
|
return new Promise((resolve) => {
|
|
190
206
|
watch(this.loadedUser, (isLoaded) => {
|
|
@@ -218,7 +234,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
218
234
|
return this.currentUser.value;
|
|
219
235
|
}
|
|
220
236
|
async updateStorefront() {
|
|
221
|
-
const latestStorefront = await this.client.storefront.get(this.hasUtm
|
|
237
|
+
const latestStorefront = await this.client.storefront.get(this.hasUtm ? this.utm.value : void 0);
|
|
222
238
|
if (latestStorefront) {
|
|
223
239
|
if (typeof window !== "undefined")
|
|
224
240
|
localStorage.setItem(_StorefrontContextImpl.storefrontKey, JSON.stringify(latestStorefront));
|
|
@@ -288,6 +304,7 @@ var _StorefrontContextImpl = class _StorefrontContextImpl {
|
|
|
288
304
|
_StorefrontContextImpl.userKey = "moonbase_user";
|
|
289
305
|
_StorefrontContextImpl.sessionKey = "moonbase_session";
|
|
290
306
|
_StorefrontContextImpl.storefrontKey = "moonbase_storefront";
|
|
307
|
+
_StorefrontContextImpl.utmKey = "moonbase_utm";
|
|
291
308
|
var StorefrontContextImpl = _StorefrontContextImpl;
|
|
292
309
|
|
|
293
310
|
// src/index.ts
|
|
@@ -612,7 +629,7 @@ function useCart(context) {
|
|
|
612
629
|
const absoluteReturnUrl = new URL((_a = options.returnUrl) != null ? _a : fallbackPath, document.baseURI).href;
|
|
613
630
|
const updatedOrder = await storefront.client.orders.pushContent(storefront.currentOrder.value, {
|
|
614
631
|
returnUrl: absoluteReturnUrl
|
|
615
|
-
});
|
|
632
|
+
}, storefront.hasUtm ? storefront.utm.value : void 0);
|
|
616
633
|
if (!options.redirect && updatedOrder.embeddedCheckoutUrl && typeof window !== "undefined") {
|
|
617
634
|
const embeddedUrl = updatedOrder.embeddedCheckoutUrl;
|
|
618
635
|
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.
|
|
4
|
+
"version": "0.2.56",
|
|
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.
|
|
22
|
+
"@moonbase.sh/storefront-api": "0.2.56"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/uuid": "^9.0.8",
|