@moonbase.sh/storefront-api 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 +44 -11
- package/dist/index.d.cts +18 -3
- package/dist/index.d.ts +18 -3
- package/dist/index.js +41 -10
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -35,11 +35,13 @@ __export(src_exports, {
|
|
|
35
35
|
ActivationStatus: () => ActivationStatus,
|
|
36
36
|
LicenseStatus: () => LicenseStatus,
|
|
37
37
|
MoonbaseClient: () => MoonbaseClient,
|
|
38
|
+
MoonbaseError: () => MoonbaseError,
|
|
38
39
|
NotAuthenticatedError: () => NotAuthenticatedError,
|
|
39
40
|
NotAuthorizedError: () => NotAuthorizedError,
|
|
40
41
|
NotFoundError: () => NotFoundError,
|
|
41
42
|
OrderStatus: () => OrderStatus,
|
|
42
|
-
Platform: () => Platform
|
|
43
|
+
Platform: () => Platform,
|
|
44
|
+
utmToObject: () => utmToObject
|
|
43
45
|
});
|
|
44
46
|
module.exports = __toCommonJS(src_exports);
|
|
45
47
|
|
|
@@ -236,6 +238,16 @@ var NotFoundError = class extends Error {
|
|
|
236
238
|
this.name = "NotFoundError";
|
|
237
239
|
}
|
|
238
240
|
};
|
|
241
|
+
var MoonbaseError = class extends Error {
|
|
242
|
+
constructor(title, detail, status) {
|
|
243
|
+
super();
|
|
244
|
+
this.title = title;
|
|
245
|
+
this.detail = detail;
|
|
246
|
+
this.status = status;
|
|
247
|
+
this.name = "MoonbaseError";
|
|
248
|
+
this.message = detail != null ? detail : title;
|
|
249
|
+
}
|
|
250
|
+
};
|
|
239
251
|
|
|
240
252
|
// src/utils/problemHandler.ts
|
|
241
253
|
var problemDetailsSchema = import_zod6.z.object({
|
|
@@ -258,11 +270,7 @@ async function handleResponseProblem(response) {
|
|
|
258
270
|
} catch (e) {
|
|
259
271
|
throw new Error("An unknown problem occurred");
|
|
260
272
|
}
|
|
261
|
-
|
|
262
|
-
throw new Error(problemDetails.detail);
|
|
263
|
-
if (problemDetails.title)
|
|
264
|
-
throw new Error(problemDetails.title);
|
|
265
|
-
throw new Error("An unknown problem occurred");
|
|
273
|
+
throw new MoonbaseError(problemDetails.title, problemDetails.detail, problemDetails.status);
|
|
266
274
|
}
|
|
267
275
|
|
|
268
276
|
// src/identity/schemas.ts
|
|
@@ -511,9 +519,16 @@ var OrderEndpoints = class {
|
|
|
511
519
|
const response = await this.api.fetch(`/api/customer/orders/${orderId}`);
|
|
512
520
|
return orderSchema.parse(response.data);
|
|
513
521
|
}
|
|
514
|
-
async pushContent(order, checkout) {
|
|
522
|
+
async pushContent(order, checkout, utm) {
|
|
523
|
+
const query = {
|
|
524
|
+
...utmToObject(utm)
|
|
525
|
+
};
|
|
526
|
+
if (checkout) {
|
|
527
|
+
query.checkout = "true";
|
|
528
|
+
query.returnUrl = checkout.returnUrl;
|
|
529
|
+
}
|
|
515
530
|
const response = await this.api.fetch(
|
|
516
|
-
`/api/customer/orders/${order.id}
|
|
531
|
+
`/api/customer/orders/${order.id}?${new URLSearchParams(query).toString()}`,
|
|
517
532
|
"PATCH",
|
|
518
533
|
{
|
|
519
534
|
currency: order.currency,
|
|
@@ -551,13 +566,29 @@ var ProductEndpoints = class {
|
|
|
551
566
|
}
|
|
552
567
|
};
|
|
553
568
|
|
|
569
|
+
// src/globalModels.ts
|
|
570
|
+
function utmToObject(utm) {
|
|
571
|
+
return Object.entries({
|
|
572
|
+
utm_source: utm == null ? void 0 : utm.source,
|
|
573
|
+
utm_medium: utm == null ? void 0 : utm.medium,
|
|
574
|
+
utm_campaign: utm == null ? void 0 : utm.campaign,
|
|
575
|
+
utm_term: utm == null ? void 0 : utm.term,
|
|
576
|
+
utm_content: utm == null ? void 0 : utm.content,
|
|
577
|
+
utm_referrer: utm == null ? void 0 : utm.referrer
|
|
578
|
+
}).filter(([_, value]) => value !== void 0).reduce((obj, [key, value]) => ({
|
|
579
|
+
...obj,
|
|
580
|
+
[key]: value
|
|
581
|
+
}), {});
|
|
582
|
+
}
|
|
583
|
+
|
|
554
584
|
// src/storefront/endpoints.ts
|
|
555
585
|
var StorefrontEndpoints = class {
|
|
556
586
|
constructor(api) {
|
|
557
587
|
this.api = api;
|
|
558
588
|
}
|
|
559
|
-
async get() {
|
|
560
|
-
const
|
|
589
|
+
async get(utm) {
|
|
590
|
+
const query = new URLSearchParams(utmToObject(utm));
|
|
591
|
+
const response = await this.api.fetch(`/api/customer/storefront?${query.toString()}`);
|
|
561
592
|
return storefrontSchema.parse(response.data);
|
|
562
593
|
}
|
|
563
594
|
};
|
|
@@ -752,9 +783,11 @@ var MoonbaseClient = class {
|
|
|
752
783
|
ActivationStatus,
|
|
753
784
|
LicenseStatus,
|
|
754
785
|
MoonbaseClient,
|
|
786
|
+
MoonbaseError,
|
|
755
787
|
NotAuthenticatedError,
|
|
756
788
|
NotAuthorizedError,
|
|
757
789
|
NotFoundError,
|
|
758
790
|
OrderStatus,
|
|
759
|
-
Platform
|
|
791
|
+
Platform,
|
|
792
|
+
utmToObject
|
|
760
793
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -783,6 +783,15 @@ interface Quantifiable<T> {
|
|
|
783
783
|
value: T;
|
|
784
784
|
quantity: number;
|
|
785
785
|
}
|
|
786
|
+
interface UrchinTrackingModule {
|
|
787
|
+
source?: string;
|
|
788
|
+
medium?: string;
|
|
789
|
+
campaign?: string;
|
|
790
|
+
term?: string;
|
|
791
|
+
content?: string;
|
|
792
|
+
referrer?: string;
|
|
793
|
+
}
|
|
794
|
+
declare function utmToObject(utm?: UrchinTrackingModule): Record<string, string>;
|
|
786
795
|
|
|
787
796
|
declare const licenseSchema: z.ZodObject<{
|
|
788
797
|
id: z.ZodString;
|
|
@@ -8952,7 +8961,7 @@ declare class OrderEndpoints {
|
|
|
8952
8961
|
}>;
|
|
8953
8962
|
pushContent(order: Order, checkout?: {
|
|
8954
8963
|
returnUrl: string;
|
|
8955
|
-
}): Promise<OpenOrder>;
|
|
8964
|
+
}, utm?: UrchinTrackingModule): Promise<OpenOrder>;
|
|
8956
8965
|
}
|
|
8957
8966
|
|
|
8958
8967
|
declare const downloadSchema: z.ZodObject<{
|
|
@@ -9072,7 +9081,7 @@ declare class ProductEndpoints {
|
|
|
9072
9081
|
declare class StorefrontEndpoints {
|
|
9073
9082
|
private api;
|
|
9074
9083
|
constructor(api: MoonbaseApi);
|
|
9075
|
-
get(): Promise<{
|
|
9084
|
+
get(utm?: UrchinTrackingModule): Promise<{
|
|
9076
9085
|
products: {
|
|
9077
9086
|
type: "product";
|
|
9078
9087
|
id: string;
|
|
@@ -13099,6 +13108,12 @@ declare class NotAuthenticatedError extends Error {
|
|
|
13099
13108
|
declare class NotFoundError extends Error {
|
|
13100
13109
|
constructor();
|
|
13101
13110
|
}
|
|
13111
|
+
declare class MoonbaseError extends Error {
|
|
13112
|
+
readonly title: string;
|
|
13113
|
+
readonly detail: string | undefined;
|
|
13114
|
+
readonly status: number;
|
|
13115
|
+
constructor(title: string, detail: string | undefined, status: number);
|
|
13116
|
+
}
|
|
13102
13117
|
|
|
13103
13118
|
interface MoonbaseConfiguration {
|
|
13104
13119
|
endpoint: string;
|
|
@@ -13116,4 +13131,4 @@ declare class MoonbaseClient {
|
|
|
13116
13131
|
orders: OrderEndpoints;
|
|
13117
13132
|
}
|
|
13118
13133
|
|
|
13119
|
-
export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestStatus, ActivationStatus, type Address, type BundleLineItem, type CommunicationPreferences, type Download, type License, LicenseStatus, type LineItem, MoonbaseClient, type MoonbaseConfiguration, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingVariation, type ProductLineItem, type Quantifiable, type Storefront, type StorefrontBundle, type StorefrontProduct, type User, type Voucher };
|
|
13134
|
+
export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestStatus, ActivationStatus, type Address, type BundleLineItem, type CommunicationPreferences, type Download, type License, LicenseStatus, type LineItem, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingVariation, type ProductLineItem, type Quantifiable, type Storefront, type StorefrontBundle, type StorefrontProduct, type UrchinTrackingModule, type User, type Voucher, utmToObject };
|
package/dist/index.d.ts
CHANGED
|
@@ -783,6 +783,15 @@ interface Quantifiable<T> {
|
|
|
783
783
|
value: T;
|
|
784
784
|
quantity: number;
|
|
785
785
|
}
|
|
786
|
+
interface UrchinTrackingModule {
|
|
787
|
+
source?: string;
|
|
788
|
+
medium?: string;
|
|
789
|
+
campaign?: string;
|
|
790
|
+
term?: string;
|
|
791
|
+
content?: string;
|
|
792
|
+
referrer?: string;
|
|
793
|
+
}
|
|
794
|
+
declare function utmToObject(utm?: UrchinTrackingModule): Record<string, string>;
|
|
786
795
|
|
|
787
796
|
declare const licenseSchema: z.ZodObject<{
|
|
788
797
|
id: z.ZodString;
|
|
@@ -8952,7 +8961,7 @@ declare class OrderEndpoints {
|
|
|
8952
8961
|
}>;
|
|
8953
8962
|
pushContent(order: Order, checkout?: {
|
|
8954
8963
|
returnUrl: string;
|
|
8955
|
-
}): Promise<OpenOrder>;
|
|
8964
|
+
}, utm?: UrchinTrackingModule): Promise<OpenOrder>;
|
|
8956
8965
|
}
|
|
8957
8966
|
|
|
8958
8967
|
declare const downloadSchema: z.ZodObject<{
|
|
@@ -9072,7 +9081,7 @@ declare class ProductEndpoints {
|
|
|
9072
9081
|
declare class StorefrontEndpoints {
|
|
9073
9082
|
private api;
|
|
9074
9083
|
constructor(api: MoonbaseApi);
|
|
9075
|
-
get(): Promise<{
|
|
9084
|
+
get(utm?: UrchinTrackingModule): Promise<{
|
|
9076
9085
|
products: {
|
|
9077
9086
|
type: "product";
|
|
9078
9087
|
id: string;
|
|
@@ -13099,6 +13108,12 @@ declare class NotAuthenticatedError extends Error {
|
|
|
13099
13108
|
declare class NotFoundError extends Error {
|
|
13100
13109
|
constructor();
|
|
13101
13110
|
}
|
|
13111
|
+
declare class MoonbaseError extends Error {
|
|
13112
|
+
readonly title: string;
|
|
13113
|
+
readonly detail: string | undefined;
|
|
13114
|
+
readonly status: number;
|
|
13115
|
+
constructor(title: string, detail: string | undefined, status: number);
|
|
13116
|
+
}
|
|
13102
13117
|
|
|
13103
13118
|
interface MoonbaseConfiguration {
|
|
13104
13119
|
endpoint: string;
|
|
@@ -13116,4 +13131,4 @@ declare class MoonbaseClient {
|
|
|
13116
13131
|
orders: OrderEndpoints;
|
|
13117
13132
|
}
|
|
13118
13133
|
|
|
13119
|
-
export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestStatus, ActivationStatus, type Address, type BundleLineItem, type CommunicationPreferences, type Download, type License, LicenseStatus, type LineItem, MoonbaseClient, type MoonbaseConfiguration, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingVariation, type ProductLineItem, type Quantifiable, type Storefront, type StorefrontBundle, type StorefrontProduct, type User, type Voucher };
|
|
13134
|
+
export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestStatus, ActivationStatus, type Address, type BundleLineItem, type CommunicationPreferences, type Download, type License, LicenseStatus, type LineItem, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingVariation, type ProductLineItem, type Quantifiable, type Storefront, type StorefrontBundle, type StorefrontProduct, type UrchinTrackingModule, type User, type Voucher, utmToObject };
|
package/dist/index.js
CHANGED
|
@@ -191,6 +191,16 @@ var NotFoundError = class extends Error {
|
|
|
191
191
|
this.name = "NotFoundError";
|
|
192
192
|
}
|
|
193
193
|
};
|
|
194
|
+
var MoonbaseError = class extends Error {
|
|
195
|
+
constructor(title, detail, status) {
|
|
196
|
+
super();
|
|
197
|
+
this.title = title;
|
|
198
|
+
this.detail = detail;
|
|
199
|
+
this.status = status;
|
|
200
|
+
this.name = "MoonbaseError";
|
|
201
|
+
this.message = detail != null ? detail : title;
|
|
202
|
+
}
|
|
203
|
+
};
|
|
194
204
|
|
|
195
205
|
// src/utils/problemHandler.ts
|
|
196
206
|
var problemDetailsSchema = z6.object({
|
|
@@ -213,11 +223,7 @@ async function handleResponseProblem(response) {
|
|
|
213
223
|
} catch (e) {
|
|
214
224
|
throw new Error("An unknown problem occurred");
|
|
215
225
|
}
|
|
216
|
-
|
|
217
|
-
throw new Error(problemDetails.detail);
|
|
218
|
-
if (problemDetails.title)
|
|
219
|
-
throw new Error(problemDetails.title);
|
|
220
|
-
throw new Error("An unknown problem occurred");
|
|
226
|
+
throw new MoonbaseError(problemDetails.title, problemDetails.detail, problemDetails.status);
|
|
221
227
|
}
|
|
222
228
|
|
|
223
229
|
// src/identity/schemas.ts
|
|
@@ -466,9 +472,16 @@ var OrderEndpoints = class {
|
|
|
466
472
|
const response = await this.api.fetch(`/api/customer/orders/${orderId}`);
|
|
467
473
|
return orderSchema.parse(response.data);
|
|
468
474
|
}
|
|
469
|
-
async pushContent(order, checkout) {
|
|
475
|
+
async pushContent(order, checkout, utm) {
|
|
476
|
+
const query = {
|
|
477
|
+
...utmToObject(utm)
|
|
478
|
+
};
|
|
479
|
+
if (checkout) {
|
|
480
|
+
query.checkout = "true";
|
|
481
|
+
query.returnUrl = checkout.returnUrl;
|
|
482
|
+
}
|
|
470
483
|
const response = await this.api.fetch(
|
|
471
|
-
`/api/customer/orders/${order.id}
|
|
484
|
+
`/api/customer/orders/${order.id}?${new URLSearchParams(query).toString()}`,
|
|
472
485
|
"PATCH",
|
|
473
486
|
{
|
|
474
487
|
currency: order.currency,
|
|
@@ -506,13 +519,29 @@ var ProductEndpoints = class {
|
|
|
506
519
|
}
|
|
507
520
|
};
|
|
508
521
|
|
|
522
|
+
// src/globalModels.ts
|
|
523
|
+
function utmToObject(utm) {
|
|
524
|
+
return Object.entries({
|
|
525
|
+
utm_source: utm == null ? void 0 : utm.source,
|
|
526
|
+
utm_medium: utm == null ? void 0 : utm.medium,
|
|
527
|
+
utm_campaign: utm == null ? void 0 : utm.campaign,
|
|
528
|
+
utm_term: utm == null ? void 0 : utm.term,
|
|
529
|
+
utm_content: utm == null ? void 0 : utm.content,
|
|
530
|
+
utm_referrer: utm == null ? void 0 : utm.referrer
|
|
531
|
+
}).filter(([_, value]) => value !== void 0).reduce((obj, [key, value]) => ({
|
|
532
|
+
...obj,
|
|
533
|
+
[key]: value
|
|
534
|
+
}), {});
|
|
535
|
+
}
|
|
536
|
+
|
|
509
537
|
// src/storefront/endpoints.ts
|
|
510
538
|
var StorefrontEndpoints = class {
|
|
511
539
|
constructor(api) {
|
|
512
540
|
this.api = api;
|
|
513
541
|
}
|
|
514
|
-
async get() {
|
|
515
|
-
const
|
|
542
|
+
async get(utm) {
|
|
543
|
+
const query = new URLSearchParams(utmToObject(utm));
|
|
544
|
+
const response = await this.api.fetch(`/api/customer/storefront?${query.toString()}`);
|
|
516
545
|
return storefrontSchema.parse(response.data);
|
|
517
546
|
}
|
|
518
547
|
};
|
|
@@ -706,9 +735,11 @@ export {
|
|
|
706
735
|
ActivationStatus,
|
|
707
736
|
LicenseStatus,
|
|
708
737
|
MoonbaseClient,
|
|
738
|
+
MoonbaseError,
|
|
709
739
|
NotAuthenticatedError,
|
|
710
740
|
NotAuthorizedError,
|
|
711
741
|
NotFoundError,
|
|
712
742
|
OrderStatus,
|
|
713
|
-
Platform
|
|
743
|
+
Platform,
|
|
744
|
+
utmToObject
|
|
714
745
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonbase.sh/storefront-api",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.96",
|
|
5
5
|
"description": "Package to let you build storefronts with Moonbase.sh as payment and delivery provider",
|
|
6
6
|
"author": "Tobias Lønnerød Madsen <m@dsen.tv>",
|
|
7
7
|
"license": "MIT",
|