@moonbase.sh/storefront-api 3.5.0 → 3.6.0
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/README.md +62 -0
- package/dist/index.cjs +52 -12
- package/dist/index.d.cts +121 -3
- package/dist/index.d.ts +121 -3
- package/dist/index.js +51 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -110,6 +110,68 @@ another tenant's) arrives as the same `NotFoundError`, so that a signed-in
|
|
|
110
110
|
customer cannot use it to enumerate a merchant's group IDs. Joining twice
|
|
111
111
|
succeeds and changes nothing.
|
|
112
112
|
|
|
113
|
+
### Captchas on sign-up
|
|
114
|
+
|
|
115
|
+
A merchant can ask customers to solve a captcha before they sign up. The vendor
|
|
116
|
+
says whether this store does:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
const vendor = await client.vendor.get()
|
|
120
|
+
const captcha = vendor.features?.captcha // { url } when it does, null or undefined when not
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`captcha.url` is a page on the store's own `<account-id>.moonbase.sh` that draws
|
|
124
|
+
the challenge. Embed it in an iframe with `action=signup`, and it hands you the
|
|
125
|
+
solution with `postMessage`:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
const src = new URL(captcha.url)
|
|
129
|
+
src.searchParams.set('action', 'signup') // optional: theme=light|dark|auto, size=normal|compact
|
|
130
|
+
|
|
131
|
+
const frame = document.createElement('iframe')
|
|
132
|
+
frame.src = src.href
|
|
133
|
+
frame.title = 'Captcha'
|
|
134
|
+
frame.style.cssText = 'border: none; color-scheme: normal; width: 300px; height: 65px'
|
|
135
|
+
form.append(frame)
|
|
136
|
+
|
|
137
|
+
let captchaToken: string | undefined
|
|
138
|
+
window.addEventListener('message', (event) => {
|
|
139
|
+
if (event.source !== frame.contentWindow || event.origin !== src.origin || event.data?.source !== 'moonbase-captcha')
|
|
140
|
+
return
|
|
141
|
+
if (event.data.event === 'resize')
|
|
142
|
+
Object.assign(frame.style, { width: `${event.data.width}px`, height: `${event.data.height}px` })
|
|
143
|
+
else if (event.data.event === 'token')
|
|
144
|
+
captchaToken = event.data.token
|
|
145
|
+
else // 'expired', or 'error' with a `code` ('load-failed' when the challenge could not load)
|
|
146
|
+
captchaToken = undefined
|
|
147
|
+
})
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Then pass the solution along, and reset the frame after every attempt, since a
|
|
151
|
+
solution is good for one:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
try {
|
|
155
|
+
await client.identity.signUp('Jane', 'jane@example.com', 'password', null, true, true, true, {
|
|
156
|
+
captchaToken,
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
catch (err) {
|
|
160
|
+
if (err instanceof CaptchaRequiredError)
|
|
161
|
+
showError(err.message) // the API's own copy, safe to show
|
|
162
|
+
throw err
|
|
163
|
+
}
|
|
164
|
+
finally {
|
|
165
|
+
captchaToken = undefined
|
|
166
|
+
frame.contentWindow?.postMessage({ source: 'moonbase-captcha', command: 'reset' }, src.origin)
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Without a solution, or with one that is expired or already used, the sign-up is
|
|
171
|
+
refused with `CaptchaRequiredError` (a `MoonbaseError`). A site with a
|
|
172
|
+
Content-Security-Policy has to allow the store's `https://<account-id>.moonbase.sh`
|
|
173
|
+
in `frame-src`.
|
|
174
|
+
|
|
113
175
|
## Inventory flow
|
|
114
176
|
|
|
115
177
|
Most inventory endpoints require an authenticated user:
|
package/dist/index.cjs
CHANGED
|
@@ -25,6 +25,7 @@ __export(index_exports, {
|
|
|
25
25
|
ActivationRequestStatus: () => ActivationRequestStatus,
|
|
26
26
|
ActivationStatus: () => ActivationStatus,
|
|
27
27
|
Architecture: () => Architecture,
|
|
28
|
+
CaptchaRequiredError: () => CaptchaRequiredError,
|
|
28
29
|
CartUtils: () => CartUtils,
|
|
29
30
|
ConnectableAccountProvider: () => ConnectableAccountProvider,
|
|
30
31
|
ConsoleLogger: () => ConsoleLogger,
|
|
@@ -657,6 +658,12 @@ var MoonbaseError = class extends Error {
|
|
|
657
658
|
}
|
|
658
659
|
}
|
|
659
660
|
};
|
|
661
|
+
var CaptchaRequiredError = class extends MoonbaseError {
|
|
662
|
+
constructor(detail, title) {
|
|
663
|
+
super(title != null ? title : "Captcha required", detail != null ? detail : "Please confirm you're not a robot.", 400);
|
|
664
|
+
this.name = "CaptchaRequiredError";
|
|
665
|
+
}
|
|
666
|
+
};
|
|
660
667
|
|
|
661
668
|
// src/utils/problemDetails.ts
|
|
662
669
|
var import_zod7 = require("zod");
|
|
@@ -699,6 +706,8 @@ async function handleResponseProblem(response, logger) {
|
|
|
699
706
|
logger.debug("The response indicates a problem", problemDetails);
|
|
700
707
|
if (problemDetails.errorType === "StoreClosed")
|
|
701
708
|
throw new StoreClosedError(problemDetails.detail);
|
|
709
|
+
if (problemDetails.errorType === "CaptchaRequired")
|
|
710
|
+
throw new CaptchaRequiredError(problemDetails.detail, problemDetails.title);
|
|
702
711
|
throw new MoonbaseError(
|
|
703
712
|
problemDetails.title,
|
|
704
713
|
problemDetails.detail,
|
|
@@ -808,7 +817,8 @@ var IdentityEndpoints = class {
|
|
|
808
817
|
headers: {
|
|
809
818
|
"Accept": "application/json",
|
|
810
819
|
"Content-Type": "text/plain",
|
|
811
|
-
"x-mb-cors": "1"
|
|
820
|
+
"x-mb-cors": "1",
|
|
821
|
+
"x-mb-client": this.api.clientHeader
|
|
812
822
|
},
|
|
813
823
|
body: password
|
|
814
824
|
});
|
|
@@ -833,7 +843,9 @@ var IdentityEndpoints = class {
|
|
|
833
843
|
headers: {
|
|
834
844
|
"Accept": "application/json",
|
|
835
845
|
"Content-Type": "application/json",
|
|
836
|
-
"x-mb-cors": "1"
|
|
846
|
+
"x-mb-cors": "1",
|
|
847
|
+
"x-mb-client": this.api.clientHeader,
|
|
848
|
+
...(options == null ? void 0 : options.captchaToken) ? { "X-MB-CAPTCHA": options.captchaToken } : {}
|
|
837
849
|
},
|
|
838
850
|
body: JSON.stringify({
|
|
839
851
|
name,
|
|
@@ -899,7 +911,8 @@ var IdentityEndpoints = class {
|
|
|
899
911
|
headers: {
|
|
900
912
|
"Accept": "application/json",
|
|
901
913
|
"Content-Type": "text/plain",
|
|
902
|
-
"x-mb-cors": "1"
|
|
914
|
+
"x-mb-cors": "1",
|
|
915
|
+
"x-mb-client": this.api.clientHeader
|
|
903
916
|
},
|
|
904
917
|
body: newPassword
|
|
905
918
|
});
|
|
@@ -1065,8 +1078,8 @@ var ProductEndpoints = class {
|
|
|
1065
1078
|
this.api = api;
|
|
1066
1079
|
this.configuration = configuration;
|
|
1067
1080
|
}
|
|
1068
|
-
async get(productId,
|
|
1069
|
-
const response = await this.api.fetch(`/api/customer/inventory/products/${productId}${
|
|
1081
|
+
async get(productId, version2) {
|
|
1082
|
+
const response = await this.api.fetch(`/api/customer/inventory/products/${productId}${version2 ? `?version=${version2}${this.configuration.includeManifests ? "&includeManifests=true" : ""}` : this.configuration.includeManifests ? "?includeManifests=true" : ""}`, productSummarySchema);
|
|
1070
1083
|
return response.data;
|
|
1071
1084
|
}
|
|
1072
1085
|
async getOwned(nextUrl) {
|
|
@@ -1094,15 +1107,24 @@ var ProductEndpoints = class {
|
|
|
1094
1107
|
// src/inventory/subscriptions/endpoints.ts
|
|
1095
1108
|
var import_zod14 = require("zod");
|
|
1096
1109
|
|
|
1110
|
+
// package.json
|
|
1111
|
+
var version = "3.6.0";
|
|
1112
|
+
|
|
1113
|
+
// src/utils/client.ts
|
|
1114
|
+
function buildClientHeader(sdk) {
|
|
1115
|
+
return `${sdk != null ? sdk : ""} @moonbase.sh/storefront-api/${version}`.trim().replace(/\s+/g, " ");
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1097
1118
|
// src/utils/api.ts
|
|
1098
1119
|
function objectToQuery(obj) {
|
|
1099
1120
|
return Object.entries(obj != null ? obj : {}).filter(([_, value]) => value !== void 0).map(([key, value]) => `${key}=${encodeURIComponent(value instanceof Date ? value.toISOString() : value)}`).join("&");
|
|
1100
1121
|
}
|
|
1101
1122
|
var MoonbaseApi = class {
|
|
1102
|
-
constructor(baseUrl, tokenStore, logger) {
|
|
1123
|
+
constructor(baseUrl, tokenStore, logger, sdk) {
|
|
1103
1124
|
this.baseUrl = baseUrl;
|
|
1104
1125
|
this.tokenStore = tokenStore;
|
|
1105
1126
|
this.logger = logger;
|
|
1127
|
+
this.clientHeader = buildClientHeader(sdk);
|
|
1106
1128
|
}
|
|
1107
1129
|
async authenticatedFetch(path, schema, options) {
|
|
1108
1130
|
if (!this.tokenStore.user)
|
|
@@ -1127,7 +1149,8 @@ var MoonbaseApi = class {
|
|
|
1127
1149
|
// While this fetch can be anonymous, we add the token if we have it
|
|
1128
1150
|
...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
|
|
1129
1151
|
// Force CORS on all calls
|
|
1130
|
-
"x-mb-cors": "1"
|
|
1152
|
+
"x-mb-cors": "1",
|
|
1153
|
+
"x-mb-client": this.clientHeader
|
|
1131
1154
|
},
|
|
1132
1155
|
body: (options == null ? void 0 : options.body) ? contentType !== "application/json" ? options.body : JSON.stringify(options.body) : void 0,
|
|
1133
1156
|
signal: options == null ? void 0 : options.abort,
|
|
@@ -1186,7 +1209,8 @@ var MoonbaseApi = class {
|
|
|
1186
1209
|
method: "POST",
|
|
1187
1210
|
headers: {
|
|
1188
1211
|
"Accept": "application/json",
|
|
1189
|
-
"Content-Type": "application/json"
|
|
1212
|
+
"Content-Type": "application/json",
|
|
1213
|
+
"x-mb-client": this.clientHeader
|
|
1190
1214
|
},
|
|
1191
1215
|
body: JSON.stringify({
|
|
1192
1216
|
title: "Parse error",
|
|
@@ -1208,7 +1232,8 @@ var MoonbaseApi = class {
|
|
|
1208
1232
|
method: "POST",
|
|
1209
1233
|
headers: {
|
|
1210
1234
|
"Accept": "application/json",
|
|
1211
|
-
"Content-Type": "application/json"
|
|
1235
|
+
"Content-Type": "application/json",
|
|
1236
|
+
"x-mb-client": this.clientHeader
|
|
1212
1237
|
},
|
|
1213
1238
|
body: JSON.stringify({
|
|
1214
1239
|
title: "Request error",
|
|
@@ -1860,7 +1885,8 @@ var _TokenStore = class _TokenStore {
|
|
|
1860
1885
|
headers: {
|
|
1861
1886
|
"Accept": "application/json",
|
|
1862
1887
|
"Content-Type": "text/plain",
|
|
1863
|
-
"x-mb-cors": "1"
|
|
1888
|
+
"x-mb-cors": "1",
|
|
1889
|
+
"x-mb-client": buildClientHeader(this.configuration.sdk)
|
|
1864
1890
|
},
|
|
1865
1891
|
body: this.tokens.accessToken
|
|
1866
1892
|
});
|
|
@@ -1896,13 +1922,26 @@ var TokenStore = _TokenStore;
|
|
|
1896
1922
|
// src/vendor/schemas.ts
|
|
1897
1923
|
var schemas_exports9 = {};
|
|
1898
1924
|
__export(schemas_exports9, {
|
|
1925
|
+
vendorCaptchaSchema: () => vendorCaptchaSchema,
|
|
1926
|
+
vendorFeaturesSchema: () => vendorFeaturesSchema,
|
|
1899
1927
|
vendorSchema: () => vendorSchema
|
|
1900
1928
|
});
|
|
1901
1929
|
var import_zod15 = require("zod");
|
|
1930
|
+
var vendorCaptchaSchema = import_zod15.z.object({
|
|
1931
|
+
url: import_zod15.z.string()
|
|
1932
|
+
});
|
|
1933
|
+
var vendorFeaturesSchema = import_zod15.z.object({
|
|
1934
|
+
customerPortal: import_zod15.z.boolean().optional(),
|
|
1935
|
+
phoneNumber: import_zod15.z.boolean().optional(),
|
|
1936
|
+
marketingConsent: import_zod15.z.nativeEnum(MarketingConsentType).optional().catch(void 0),
|
|
1937
|
+
// Absent on backends from before captchas, which never ask for one.
|
|
1938
|
+
captcha: vendorCaptchaSchema.nullish()
|
|
1939
|
+
});
|
|
1902
1940
|
var vendorSchema = import_zod15.z.object({
|
|
1903
1941
|
id: import_zod15.z.string(),
|
|
1904
1942
|
name: import_zod15.z.string(),
|
|
1905
|
-
logoUrl: import_zod15.z.string().nullable()
|
|
1943
|
+
logoUrl: import_zod15.z.string().nullable(),
|
|
1944
|
+
features: vendorFeaturesSchema.optional()
|
|
1906
1945
|
});
|
|
1907
1946
|
|
|
1908
1947
|
// src/vendor/endpoints.ts
|
|
@@ -2579,7 +2618,7 @@ var MoonbaseClient = class {
|
|
|
2579
2618
|
this.configuration.endpoint = this.configuration.endpoint.replace(/\/$/, "");
|
|
2580
2619
|
this.logger = (_a = this.configuration.logger) != null ? _a : new ConsoleLogger();
|
|
2581
2620
|
this.tokenStore = new TokenStore(configuration);
|
|
2582
|
-
this.api = new MoonbaseApi(this.configuration.endpoint, this.tokenStore, this.logger);
|
|
2621
|
+
this.api = new MoonbaseApi(this.configuration.endpoint, this.tokenStore, this.logger, this.configuration.sdk);
|
|
2583
2622
|
this.storefront = new StorefrontEndpoints(this.api, this.configuration);
|
|
2584
2623
|
this.identity = new IdentityEndpoints(this.api, this.tokenStore, this.logger);
|
|
2585
2624
|
this.communications = new CommunicationsEndpoints(this.api);
|
|
@@ -2598,6 +2637,7 @@ var MoonbaseClient = class {
|
|
|
2598
2637
|
ActivationRequestStatus,
|
|
2599
2638
|
ActivationStatus,
|
|
2600
2639
|
Architecture,
|
|
2640
|
+
CaptchaRequiredError,
|
|
2601
2641
|
CartUtils,
|
|
2602
2642
|
ConnectableAccountProvider,
|
|
2603
2643
|
ConsoleLogger,
|
package/dist/index.d.cts
CHANGED
|
@@ -132,7 +132,13 @@ declare class MoonbaseApi {
|
|
|
132
132
|
baseUrl: string;
|
|
133
133
|
private tokenStore;
|
|
134
134
|
private logger;
|
|
135
|
-
|
|
135
|
+
/**
|
|
136
|
+
* The `x-mb-client` header this client sends with every request.
|
|
137
|
+
*
|
|
138
|
+
* @internal
|
|
139
|
+
*/
|
|
140
|
+
readonly clientHeader: string;
|
|
141
|
+
constructor(baseUrl: string, tokenStore: ITokenStore, logger: ILogger, sdk?: string);
|
|
136
142
|
authenticatedFetch<T extends ZodTypeAny>(path: string, schema: T | null, options?: FetchOptions): Promise<Response<z.infer<T>>>;
|
|
137
143
|
fetch<T extends ZodTypeAny>(path: string, schema: T | null, options?: FetchOptions): Promise<Response<z.infer<T>>>;
|
|
138
144
|
private reportParsingProblem;
|
|
@@ -1671,6 +1677,15 @@ interface SignUpOptions {
|
|
|
1671
1677
|
* ID left in a form can never fail a registration.
|
|
1672
1678
|
*/
|
|
1673
1679
|
groupIds?: string[];
|
|
1680
|
+
/**
|
|
1681
|
+
* The customer's solution to the store's captcha, for stores that ask for one
|
|
1682
|
+
* (`vendor.features.captcha`). Sent in the `X-MB-CAPTCHA` header.
|
|
1683
|
+
*
|
|
1684
|
+
* Without it (or with one that does not check out) such a store refuses the
|
|
1685
|
+
* sign-up with a `CaptchaRequiredError`. Solutions are single-use and expire
|
|
1686
|
+
* after about two minutes, so reset the captcha after every attempt.
|
|
1687
|
+
*/
|
|
1688
|
+
captchaToken?: string;
|
|
1674
1689
|
}
|
|
1675
1690
|
|
|
1676
1691
|
declare class IdentityEndpoints {
|
|
@@ -24983,26 +24998,110 @@ declare class StorefrontEndpoints {
|
|
|
24983
24998
|
}>;
|
|
24984
24999
|
}
|
|
24985
25000
|
|
|
25001
|
+
/**
|
|
25002
|
+
* The captcha a store asks customers to solve before signing up and checking out. `url` is a
|
|
25003
|
+
* page on the store's own `<account-id>.moonbase.sh` that draws the challenge: embed it in an
|
|
25004
|
+
* iframe, and it hands the solution to its parent with `postMessage`.
|
|
25005
|
+
*/
|
|
25006
|
+
declare const vendorCaptchaSchema: z.ZodObject<{
|
|
25007
|
+
url: z.ZodString;
|
|
25008
|
+
}, "strip", z.ZodTypeAny, {
|
|
25009
|
+
url: string;
|
|
25010
|
+
}, {
|
|
25011
|
+
url: string;
|
|
25012
|
+
}>;
|
|
25013
|
+
declare const vendorFeaturesSchema: z.ZodObject<{
|
|
25014
|
+
customerPortal: z.ZodOptional<z.ZodBoolean>;
|
|
25015
|
+
phoneNumber: z.ZodOptional<z.ZodBoolean>;
|
|
25016
|
+
marketingConsent: z.ZodCatch<z.ZodOptional<z.ZodNativeEnum<typeof MarketingConsentType>>>;
|
|
25017
|
+
captcha: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
25018
|
+
url: z.ZodString;
|
|
25019
|
+
}, "strip", z.ZodTypeAny, {
|
|
25020
|
+
url: string;
|
|
25021
|
+
}, {
|
|
25022
|
+
url: string;
|
|
25023
|
+
}>>>;
|
|
25024
|
+
}, "strip", z.ZodTypeAny, {
|
|
25025
|
+
customerPortal?: boolean | undefined;
|
|
25026
|
+
phoneNumber?: boolean | undefined;
|
|
25027
|
+
marketingConsent?: MarketingConsentType | undefined;
|
|
25028
|
+
captcha?: {
|
|
25029
|
+
url: string;
|
|
25030
|
+
} | null | undefined;
|
|
25031
|
+
}, {
|
|
25032
|
+
customerPortal?: boolean | undefined;
|
|
25033
|
+
phoneNumber?: boolean | undefined;
|
|
25034
|
+
marketingConsent?: unknown;
|
|
25035
|
+
captcha?: {
|
|
25036
|
+
url: string;
|
|
25037
|
+
} | null | undefined;
|
|
25038
|
+
}>;
|
|
24986
25039
|
declare const vendorSchema: z.ZodObject<{
|
|
24987
25040
|
id: z.ZodString;
|
|
24988
25041
|
name: z.ZodString;
|
|
24989
25042
|
logoUrl: z.ZodNullable<z.ZodString>;
|
|
25043
|
+
features: z.ZodOptional<z.ZodObject<{
|
|
25044
|
+
customerPortal: z.ZodOptional<z.ZodBoolean>;
|
|
25045
|
+
phoneNumber: z.ZodOptional<z.ZodBoolean>;
|
|
25046
|
+
marketingConsent: z.ZodCatch<z.ZodOptional<z.ZodNativeEnum<typeof MarketingConsentType>>>;
|
|
25047
|
+
captcha: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
25048
|
+
url: z.ZodString;
|
|
25049
|
+
}, "strip", z.ZodTypeAny, {
|
|
25050
|
+
url: string;
|
|
25051
|
+
}, {
|
|
25052
|
+
url: string;
|
|
25053
|
+
}>>>;
|
|
25054
|
+
}, "strip", z.ZodTypeAny, {
|
|
25055
|
+
customerPortal?: boolean | undefined;
|
|
25056
|
+
phoneNumber?: boolean | undefined;
|
|
25057
|
+
marketingConsent?: MarketingConsentType | undefined;
|
|
25058
|
+
captcha?: {
|
|
25059
|
+
url: string;
|
|
25060
|
+
} | null | undefined;
|
|
25061
|
+
}, {
|
|
25062
|
+
customerPortal?: boolean | undefined;
|
|
25063
|
+
phoneNumber?: boolean | undefined;
|
|
25064
|
+
marketingConsent?: unknown;
|
|
25065
|
+
captcha?: {
|
|
25066
|
+
url: string;
|
|
25067
|
+
} | null | undefined;
|
|
25068
|
+
}>>;
|
|
24990
25069
|
}, "strip", z.ZodTypeAny, {
|
|
24991
25070
|
id: string;
|
|
24992
25071
|
name: string;
|
|
24993
25072
|
logoUrl: string | null;
|
|
25073
|
+
features?: {
|
|
25074
|
+
customerPortal?: boolean | undefined;
|
|
25075
|
+
phoneNumber?: boolean | undefined;
|
|
25076
|
+
marketingConsent?: MarketingConsentType | undefined;
|
|
25077
|
+
captcha?: {
|
|
25078
|
+
url: string;
|
|
25079
|
+
} | null | undefined;
|
|
25080
|
+
} | undefined;
|
|
24994
25081
|
}, {
|
|
24995
25082
|
id: string;
|
|
24996
25083
|
name: string;
|
|
24997
25084
|
logoUrl: string | null;
|
|
25085
|
+
features?: {
|
|
25086
|
+
customerPortal?: boolean | undefined;
|
|
25087
|
+
phoneNumber?: boolean | undefined;
|
|
25088
|
+
marketingConsent?: unknown;
|
|
25089
|
+
captcha?: {
|
|
25090
|
+
url: string;
|
|
25091
|
+
} | null | undefined;
|
|
25092
|
+
} | undefined;
|
|
24998
25093
|
}>;
|
|
24999
25094
|
|
|
25095
|
+
declare const schemas$4_vendorCaptchaSchema: typeof vendorCaptchaSchema;
|
|
25096
|
+
declare const schemas$4_vendorFeaturesSchema: typeof vendorFeaturesSchema;
|
|
25000
25097
|
declare const schemas$4_vendorSchema: typeof vendorSchema;
|
|
25001
25098
|
declare namespace schemas$4 {
|
|
25002
|
-
export { schemas$4_vendorSchema as vendorSchema };
|
|
25099
|
+
export { schemas$4_vendorCaptchaSchema as vendorCaptchaSchema, schemas$4_vendorFeaturesSchema as vendorFeaturesSchema, schemas$4_vendorSchema as vendorSchema };
|
|
25003
25100
|
}
|
|
25004
25101
|
|
|
25005
25102
|
type Vendor = z.infer<typeof vendorSchema>;
|
|
25103
|
+
type VendorFeatures = z.infer<typeof vendorFeaturesSchema>;
|
|
25104
|
+
type VendorCaptcha = z.infer<typeof vendorCaptchaSchema>;
|
|
25006
25105
|
|
|
25007
25106
|
declare class VendorEndpoints {
|
|
25008
25107
|
private api;
|
|
@@ -47020,6 +47119,17 @@ declare class MoonbaseError extends Error {
|
|
|
47020
47119
|
readonly errors?: Record<string, string> | undefined;
|
|
47021
47120
|
constructor(title: string, detail: string | undefined, status?: number | undefined, errors?: Record<string, string> | undefined);
|
|
47022
47121
|
}
|
|
47122
|
+
/**
|
|
47123
|
+
* The store asks customers to solve a captcha (see `Vendor.features.captcha`), and the request
|
|
47124
|
+
* carried none, or one that did not check out: unsolved, expired, already used, or solved on a
|
|
47125
|
+
* site that is not one of the store's. `message` is the API's own copy for the customer, safe to
|
|
47126
|
+
* show as is. Solutions are single-use, so reset the captcha and let them try again.
|
|
47127
|
+
*
|
|
47128
|
+
* A `MoonbaseError` like any other refusal, so code that already handles those keeps working.
|
|
47129
|
+
*/
|
|
47130
|
+
declare class CaptchaRequiredError extends MoonbaseError {
|
|
47131
|
+
constructor(detail?: string, title?: string);
|
|
47132
|
+
}
|
|
47023
47133
|
|
|
47024
47134
|
/**
|
|
47025
47135
|
* Cleans up merchant-authored group IDs before they go on the wire.
|
|
@@ -47174,6 +47284,14 @@ interface MoonbaseConfiguration {
|
|
|
47174
47284
|
includeManifests?: boolean;
|
|
47175
47285
|
store?: IStore;
|
|
47176
47286
|
logger?: ILogger;
|
|
47287
|
+
/**
|
|
47288
|
+
* Product tokens (`name/version`) of an SDK wrapping this one, such as
|
|
47289
|
+
* `@moonbase.sh/vue/3.6.1`, sent ahead of this package's own token in the
|
|
47290
|
+
* `x-mb-client` header.
|
|
47291
|
+
*
|
|
47292
|
+
* @internal
|
|
47293
|
+
*/
|
|
47294
|
+
sdk?: string;
|
|
47177
47295
|
}
|
|
47178
47296
|
declare class MoonbaseClient {
|
|
47179
47297
|
private readonly configuration;
|
|
@@ -47192,4 +47310,4 @@ declare class MoonbaseClient {
|
|
|
47192
47310
|
orders: OrderEndpoints;
|
|
47193
47311
|
}
|
|
47194
47312
|
|
|
47195
|
-
export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, Architecture, type BundleLineItem, type CartCatalog, type CartOrder, type CartTotal, type CartTotalCondition, CartUtils, type CommunicationPreferences, type CommunicationPreferencesInput, type CommunicationPreferencesView, type CompletedOrder, ConnectableAccountProvider, type ConnectedAccount, ConsoleLogger, CycleLength, type Discount, DiscountUtils, type Download, type DownloadManifest, type ILogger, type IRecurrence, type IStore, type ITokenStore, type Identity, type ImageFit, type ImageFormat, type ImageTransform, ImageUtils, InMemoryStore, type License, LicenseStatus, type LineItem, type LineItemTotal, LocalStorageStore, LogLevel, MarketingConsentType, type MilestoneProgress, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, type OfferConditionContext, type OfferProgress, type OfferScope, OfferUtils, type OpenOrder, type Order, OrderStatus, type OrderTotal, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type PromotionDisplay, type Quantifiable, type RawPropertyArray, type RawPropertyObject, type RawPropertyValue, type SignUpOptions, type SignUpResult, type SingleOrMultiple, StoreClosedError, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontOfferTarget, type StorefrontProduct, type StorefrontPromotion, type StorefrontPromotionCta, type StorefrontPromotionTarget, type SubscribeInput, type SubscribeResponse, type Subscription, type SubscriptionCancellationFeedback, SubscriptionCancellationReason, SubscriptionStatus, type TaxEstimate, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type UserAccountConfirmedStatus, type Vendor, type Voucher, imageWidths, isLocalStorageAvailable, isPromotionDisplay, isTransformableImageUrl, maxImageDimension, normalizeGroupIds, objectToQuery, parseOffSiteReferrer, problemDetailsSchema, promotionDisplays, resolveUtm, schemas, utmToObject };
|
|
47313
|
+
export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, Architecture, type BundleLineItem, CaptchaRequiredError, type CartCatalog, type CartOrder, type CartTotal, type CartTotalCondition, CartUtils, type CommunicationPreferences, type CommunicationPreferencesInput, type CommunicationPreferencesView, type CompletedOrder, ConnectableAccountProvider, type ConnectedAccount, ConsoleLogger, CycleLength, type Discount, DiscountUtils, type Download, type DownloadManifest, type ILogger, type IRecurrence, type IStore, type ITokenStore, type Identity, type ImageFit, type ImageFormat, type ImageTransform, ImageUtils, InMemoryStore, type License, LicenseStatus, type LineItem, type LineItemTotal, LocalStorageStore, LogLevel, MarketingConsentType, type MilestoneProgress, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, type OfferConditionContext, type OfferProgress, type OfferScope, OfferUtils, type OpenOrder, type Order, OrderStatus, type OrderTotal, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type PromotionDisplay, type Quantifiable, type RawPropertyArray, type RawPropertyObject, type RawPropertyValue, type SignUpOptions, type SignUpResult, type SingleOrMultiple, StoreClosedError, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontOfferTarget, type StorefrontProduct, type StorefrontPromotion, type StorefrontPromotionCta, type StorefrontPromotionTarget, type SubscribeInput, type SubscribeResponse, type Subscription, type SubscriptionCancellationFeedback, SubscriptionCancellationReason, SubscriptionStatus, type TaxEstimate, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type UserAccountConfirmedStatus, type Vendor, type VendorCaptcha, type VendorFeatures, type Voucher, imageWidths, isLocalStorageAvailable, isPromotionDisplay, isTransformableImageUrl, maxImageDimension, normalizeGroupIds, objectToQuery, parseOffSiteReferrer, problemDetailsSchema, promotionDisplays, resolveUtm, schemas, utmToObject };
|
package/dist/index.d.ts
CHANGED
|
@@ -132,7 +132,13 @@ declare class MoonbaseApi {
|
|
|
132
132
|
baseUrl: string;
|
|
133
133
|
private tokenStore;
|
|
134
134
|
private logger;
|
|
135
|
-
|
|
135
|
+
/**
|
|
136
|
+
* The `x-mb-client` header this client sends with every request.
|
|
137
|
+
*
|
|
138
|
+
* @internal
|
|
139
|
+
*/
|
|
140
|
+
readonly clientHeader: string;
|
|
141
|
+
constructor(baseUrl: string, tokenStore: ITokenStore, logger: ILogger, sdk?: string);
|
|
136
142
|
authenticatedFetch<T extends ZodTypeAny>(path: string, schema: T | null, options?: FetchOptions): Promise<Response<z.infer<T>>>;
|
|
137
143
|
fetch<T extends ZodTypeAny>(path: string, schema: T | null, options?: FetchOptions): Promise<Response<z.infer<T>>>;
|
|
138
144
|
private reportParsingProblem;
|
|
@@ -1671,6 +1677,15 @@ interface SignUpOptions {
|
|
|
1671
1677
|
* ID left in a form can never fail a registration.
|
|
1672
1678
|
*/
|
|
1673
1679
|
groupIds?: string[];
|
|
1680
|
+
/**
|
|
1681
|
+
* The customer's solution to the store's captcha, for stores that ask for one
|
|
1682
|
+
* (`vendor.features.captcha`). Sent in the `X-MB-CAPTCHA` header.
|
|
1683
|
+
*
|
|
1684
|
+
* Without it (or with one that does not check out) such a store refuses the
|
|
1685
|
+
* sign-up with a `CaptchaRequiredError`. Solutions are single-use and expire
|
|
1686
|
+
* after about two minutes, so reset the captcha after every attempt.
|
|
1687
|
+
*/
|
|
1688
|
+
captchaToken?: string;
|
|
1674
1689
|
}
|
|
1675
1690
|
|
|
1676
1691
|
declare class IdentityEndpoints {
|
|
@@ -24983,26 +24998,110 @@ declare class StorefrontEndpoints {
|
|
|
24983
24998
|
}>;
|
|
24984
24999
|
}
|
|
24985
25000
|
|
|
25001
|
+
/**
|
|
25002
|
+
* The captcha a store asks customers to solve before signing up and checking out. `url` is a
|
|
25003
|
+
* page on the store's own `<account-id>.moonbase.sh` that draws the challenge: embed it in an
|
|
25004
|
+
* iframe, and it hands the solution to its parent with `postMessage`.
|
|
25005
|
+
*/
|
|
25006
|
+
declare const vendorCaptchaSchema: z.ZodObject<{
|
|
25007
|
+
url: z.ZodString;
|
|
25008
|
+
}, "strip", z.ZodTypeAny, {
|
|
25009
|
+
url: string;
|
|
25010
|
+
}, {
|
|
25011
|
+
url: string;
|
|
25012
|
+
}>;
|
|
25013
|
+
declare const vendorFeaturesSchema: z.ZodObject<{
|
|
25014
|
+
customerPortal: z.ZodOptional<z.ZodBoolean>;
|
|
25015
|
+
phoneNumber: z.ZodOptional<z.ZodBoolean>;
|
|
25016
|
+
marketingConsent: z.ZodCatch<z.ZodOptional<z.ZodNativeEnum<typeof MarketingConsentType>>>;
|
|
25017
|
+
captcha: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
25018
|
+
url: z.ZodString;
|
|
25019
|
+
}, "strip", z.ZodTypeAny, {
|
|
25020
|
+
url: string;
|
|
25021
|
+
}, {
|
|
25022
|
+
url: string;
|
|
25023
|
+
}>>>;
|
|
25024
|
+
}, "strip", z.ZodTypeAny, {
|
|
25025
|
+
customerPortal?: boolean | undefined;
|
|
25026
|
+
phoneNumber?: boolean | undefined;
|
|
25027
|
+
marketingConsent?: MarketingConsentType | undefined;
|
|
25028
|
+
captcha?: {
|
|
25029
|
+
url: string;
|
|
25030
|
+
} | null | undefined;
|
|
25031
|
+
}, {
|
|
25032
|
+
customerPortal?: boolean | undefined;
|
|
25033
|
+
phoneNumber?: boolean | undefined;
|
|
25034
|
+
marketingConsent?: unknown;
|
|
25035
|
+
captcha?: {
|
|
25036
|
+
url: string;
|
|
25037
|
+
} | null | undefined;
|
|
25038
|
+
}>;
|
|
24986
25039
|
declare const vendorSchema: z.ZodObject<{
|
|
24987
25040
|
id: z.ZodString;
|
|
24988
25041
|
name: z.ZodString;
|
|
24989
25042
|
logoUrl: z.ZodNullable<z.ZodString>;
|
|
25043
|
+
features: z.ZodOptional<z.ZodObject<{
|
|
25044
|
+
customerPortal: z.ZodOptional<z.ZodBoolean>;
|
|
25045
|
+
phoneNumber: z.ZodOptional<z.ZodBoolean>;
|
|
25046
|
+
marketingConsent: z.ZodCatch<z.ZodOptional<z.ZodNativeEnum<typeof MarketingConsentType>>>;
|
|
25047
|
+
captcha: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
25048
|
+
url: z.ZodString;
|
|
25049
|
+
}, "strip", z.ZodTypeAny, {
|
|
25050
|
+
url: string;
|
|
25051
|
+
}, {
|
|
25052
|
+
url: string;
|
|
25053
|
+
}>>>;
|
|
25054
|
+
}, "strip", z.ZodTypeAny, {
|
|
25055
|
+
customerPortal?: boolean | undefined;
|
|
25056
|
+
phoneNumber?: boolean | undefined;
|
|
25057
|
+
marketingConsent?: MarketingConsentType | undefined;
|
|
25058
|
+
captcha?: {
|
|
25059
|
+
url: string;
|
|
25060
|
+
} | null | undefined;
|
|
25061
|
+
}, {
|
|
25062
|
+
customerPortal?: boolean | undefined;
|
|
25063
|
+
phoneNumber?: boolean | undefined;
|
|
25064
|
+
marketingConsent?: unknown;
|
|
25065
|
+
captcha?: {
|
|
25066
|
+
url: string;
|
|
25067
|
+
} | null | undefined;
|
|
25068
|
+
}>>;
|
|
24990
25069
|
}, "strip", z.ZodTypeAny, {
|
|
24991
25070
|
id: string;
|
|
24992
25071
|
name: string;
|
|
24993
25072
|
logoUrl: string | null;
|
|
25073
|
+
features?: {
|
|
25074
|
+
customerPortal?: boolean | undefined;
|
|
25075
|
+
phoneNumber?: boolean | undefined;
|
|
25076
|
+
marketingConsent?: MarketingConsentType | undefined;
|
|
25077
|
+
captcha?: {
|
|
25078
|
+
url: string;
|
|
25079
|
+
} | null | undefined;
|
|
25080
|
+
} | undefined;
|
|
24994
25081
|
}, {
|
|
24995
25082
|
id: string;
|
|
24996
25083
|
name: string;
|
|
24997
25084
|
logoUrl: string | null;
|
|
25085
|
+
features?: {
|
|
25086
|
+
customerPortal?: boolean | undefined;
|
|
25087
|
+
phoneNumber?: boolean | undefined;
|
|
25088
|
+
marketingConsent?: unknown;
|
|
25089
|
+
captcha?: {
|
|
25090
|
+
url: string;
|
|
25091
|
+
} | null | undefined;
|
|
25092
|
+
} | undefined;
|
|
24998
25093
|
}>;
|
|
24999
25094
|
|
|
25095
|
+
declare const schemas$4_vendorCaptchaSchema: typeof vendorCaptchaSchema;
|
|
25096
|
+
declare const schemas$4_vendorFeaturesSchema: typeof vendorFeaturesSchema;
|
|
25000
25097
|
declare const schemas$4_vendorSchema: typeof vendorSchema;
|
|
25001
25098
|
declare namespace schemas$4 {
|
|
25002
|
-
export { schemas$4_vendorSchema as vendorSchema };
|
|
25099
|
+
export { schemas$4_vendorCaptchaSchema as vendorCaptchaSchema, schemas$4_vendorFeaturesSchema as vendorFeaturesSchema, schemas$4_vendorSchema as vendorSchema };
|
|
25003
25100
|
}
|
|
25004
25101
|
|
|
25005
25102
|
type Vendor = z.infer<typeof vendorSchema>;
|
|
25103
|
+
type VendorFeatures = z.infer<typeof vendorFeaturesSchema>;
|
|
25104
|
+
type VendorCaptcha = z.infer<typeof vendorCaptchaSchema>;
|
|
25006
25105
|
|
|
25007
25106
|
declare class VendorEndpoints {
|
|
25008
25107
|
private api;
|
|
@@ -47020,6 +47119,17 @@ declare class MoonbaseError extends Error {
|
|
|
47020
47119
|
readonly errors?: Record<string, string> | undefined;
|
|
47021
47120
|
constructor(title: string, detail: string | undefined, status?: number | undefined, errors?: Record<string, string> | undefined);
|
|
47022
47121
|
}
|
|
47122
|
+
/**
|
|
47123
|
+
* The store asks customers to solve a captcha (see `Vendor.features.captcha`), and the request
|
|
47124
|
+
* carried none, or one that did not check out: unsolved, expired, already used, or solved on a
|
|
47125
|
+
* site that is not one of the store's. `message` is the API's own copy for the customer, safe to
|
|
47126
|
+
* show as is. Solutions are single-use, so reset the captcha and let them try again.
|
|
47127
|
+
*
|
|
47128
|
+
* A `MoonbaseError` like any other refusal, so code that already handles those keeps working.
|
|
47129
|
+
*/
|
|
47130
|
+
declare class CaptchaRequiredError extends MoonbaseError {
|
|
47131
|
+
constructor(detail?: string, title?: string);
|
|
47132
|
+
}
|
|
47023
47133
|
|
|
47024
47134
|
/**
|
|
47025
47135
|
* Cleans up merchant-authored group IDs before they go on the wire.
|
|
@@ -47174,6 +47284,14 @@ interface MoonbaseConfiguration {
|
|
|
47174
47284
|
includeManifests?: boolean;
|
|
47175
47285
|
store?: IStore;
|
|
47176
47286
|
logger?: ILogger;
|
|
47287
|
+
/**
|
|
47288
|
+
* Product tokens (`name/version`) of an SDK wrapping this one, such as
|
|
47289
|
+
* `@moonbase.sh/vue/3.6.1`, sent ahead of this package's own token in the
|
|
47290
|
+
* `x-mb-client` header.
|
|
47291
|
+
*
|
|
47292
|
+
* @internal
|
|
47293
|
+
*/
|
|
47294
|
+
sdk?: string;
|
|
47177
47295
|
}
|
|
47178
47296
|
declare class MoonbaseClient {
|
|
47179
47297
|
private readonly configuration;
|
|
@@ -47192,4 +47310,4 @@ declare class MoonbaseClient {
|
|
|
47192
47310
|
orders: OrderEndpoints;
|
|
47193
47311
|
}
|
|
47194
47312
|
|
|
47195
|
-
export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, Architecture, type BundleLineItem, type CartCatalog, type CartOrder, type CartTotal, type CartTotalCondition, CartUtils, type CommunicationPreferences, type CommunicationPreferencesInput, type CommunicationPreferencesView, type CompletedOrder, ConnectableAccountProvider, type ConnectedAccount, ConsoleLogger, CycleLength, type Discount, DiscountUtils, type Download, type DownloadManifest, type ILogger, type IRecurrence, type IStore, type ITokenStore, type Identity, type ImageFit, type ImageFormat, type ImageTransform, ImageUtils, InMemoryStore, type License, LicenseStatus, type LineItem, type LineItemTotal, LocalStorageStore, LogLevel, MarketingConsentType, type MilestoneProgress, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, type OfferConditionContext, type OfferProgress, type OfferScope, OfferUtils, type OpenOrder, type Order, OrderStatus, type OrderTotal, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type PromotionDisplay, type Quantifiable, type RawPropertyArray, type RawPropertyObject, type RawPropertyValue, type SignUpOptions, type SignUpResult, type SingleOrMultiple, StoreClosedError, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontOfferTarget, type StorefrontProduct, type StorefrontPromotion, type StorefrontPromotionCta, type StorefrontPromotionTarget, type SubscribeInput, type SubscribeResponse, type Subscription, type SubscriptionCancellationFeedback, SubscriptionCancellationReason, SubscriptionStatus, type TaxEstimate, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type UserAccountConfirmedStatus, type Vendor, type Voucher, imageWidths, isLocalStorageAvailable, isPromotionDisplay, isTransformableImageUrl, maxImageDimension, normalizeGroupIds, objectToQuery, parseOffSiteReferrer, problemDetailsSchema, promotionDisplays, resolveUtm, schemas, utmToObject };
|
|
47313
|
+
export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, Architecture, type BundleLineItem, CaptchaRequiredError, type CartCatalog, type CartOrder, type CartTotal, type CartTotalCondition, CartUtils, type CommunicationPreferences, type CommunicationPreferencesInput, type CommunicationPreferencesView, type CompletedOrder, ConnectableAccountProvider, type ConnectedAccount, ConsoleLogger, CycleLength, type Discount, DiscountUtils, type Download, type DownloadManifest, type ILogger, type IRecurrence, type IStore, type ITokenStore, type Identity, type ImageFit, type ImageFormat, type ImageTransform, ImageUtils, InMemoryStore, type License, LicenseStatus, type LineItem, type LineItemTotal, LocalStorageStore, LogLevel, MarketingConsentType, type MilestoneProgress, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, type OfferConditionContext, type OfferProgress, type OfferScope, OfferUtils, type OpenOrder, type Order, OrderStatus, type OrderTotal, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type PromotionDisplay, type Quantifiable, type RawPropertyArray, type RawPropertyObject, type RawPropertyValue, type SignUpOptions, type SignUpResult, type SingleOrMultiple, StoreClosedError, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontOfferTarget, type StorefrontProduct, type StorefrontPromotion, type StorefrontPromotionCta, type StorefrontPromotionTarget, type SubscribeInput, type SubscribeResponse, type Subscription, type SubscriptionCancellationFeedback, SubscriptionCancellationReason, SubscriptionStatus, type TaxEstimate, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type UserAccountConfirmedStatus, type Vendor, type VendorCaptcha, type VendorFeatures, type Voucher, imageWidths, isLocalStorageAvailable, isPromotionDisplay, isTransformableImageUrl, maxImageDimension, normalizeGroupIds, objectToQuery, parseOffSiteReferrer, problemDetailsSchema, promotionDisplays, resolveUtm, schemas, utmToObject };
|
package/dist/index.js
CHANGED
|
@@ -595,6 +595,12 @@ var MoonbaseError = class extends Error {
|
|
|
595
595
|
}
|
|
596
596
|
}
|
|
597
597
|
};
|
|
598
|
+
var CaptchaRequiredError = class extends MoonbaseError {
|
|
599
|
+
constructor(detail, title) {
|
|
600
|
+
super(title != null ? title : "Captcha required", detail != null ? detail : "Please confirm you're not a robot.", 400);
|
|
601
|
+
this.name = "CaptchaRequiredError";
|
|
602
|
+
}
|
|
603
|
+
};
|
|
598
604
|
|
|
599
605
|
// src/utils/problemDetails.ts
|
|
600
606
|
import { z as z7 } from "zod";
|
|
@@ -637,6 +643,8 @@ async function handleResponseProblem(response, logger) {
|
|
|
637
643
|
logger.debug("The response indicates a problem", problemDetails);
|
|
638
644
|
if (problemDetails.errorType === "StoreClosed")
|
|
639
645
|
throw new StoreClosedError(problemDetails.detail);
|
|
646
|
+
if (problemDetails.errorType === "CaptchaRequired")
|
|
647
|
+
throw new CaptchaRequiredError(problemDetails.detail, problemDetails.title);
|
|
640
648
|
throw new MoonbaseError(
|
|
641
649
|
problemDetails.title,
|
|
642
650
|
problemDetails.detail,
|
|
@@ -746,7 +754,8 @@ var IdentityEndpoints = class {
|
|
|
746
754
|
headers: {
|
|
747
755
|
"Accept": "application/json",
|
|
748
756
|
"Content-Type": "text/plain",
|
|
749
|
-
"x-mb-cors": "1"
|
|
757
|
+
"x-mb-cors": "1",
|
|
758
|
+
"x-mb-client": this.api.clientHeader
|
|
750
759
|
},
|
|
751
760
|
body: password
|
|
752
761
|
});
|
|
@@ -771,7 +780,9 @@ var IdentityEndpoints = class {
|
|
|
771
780
|
headers: {
|
|
772
781
|
"Accept": "application/json",
|
|
773
782
|
"Content-Type": "application/json",
|
|
774
|
-
"x-mb-cors": "1"
|
|
783
|
+
"x-mb-cors": "1",
|
|
784
|
+
"x-mb-client": this.api.clientHeader,
|
|
785
|
+
...(options == null ? void 0 : options.captchaToken) ? { "X-MB-CAPTCHA": options.captchaToken } : {}
|
|
775
786
|
},
|
|
776
787
|
body: JSON.stringify({
|
|
777
788
|
name,
|
|
@@ -837,7 +848,8 @@ var IdentityEndpoints = class {
|
|
|
837
848
|
headers: {
|
|
838
849
|
"Accept": "application/json",
|
|
839
850
|
"Content-Type": "text/plain",
|
|
840
|
-
"x-mb-cors": "1"
|
|
851
|
+
"x-mb-cors": "1",
|
|
852
|
+
"x-mb-client": this.api.clientHeader
|
|
841
853
|
},
|
|
842
854
|
body: newPassword
|
|
843
855
|
});
|
|
@@ -1003,8 +1015,8 @@ var ProductEndpoints = class {
|
|
|
1003
1015
|
this.api = api;
|
|
1004
1016
|
this.configuration = configuration;
|
|
1005
1017
|
}
|
|
1006
|
-
async get(productId,
|
|
1007
|
-
const response = await this.api.fetch(`/api/customer/inventory/products/${productId}${
|
|
1018
|
+
async get(productId, version2) {
|
|
1019
|
+
const response = await this.api.fetch(`/api/customer/inventory/products/${productId}${version2 ? `?version=${version2}${this.configuration.includeManifests ? "&includeManifests=true" : ""}` : this.configuration.includeManifests ? "?includeManifests=true" : ""}`, productSummarySchema);
|
|
1008
1020
|
return response.data;
|
|
1009
1021
|
}
|
|
1010
1022
|
async getOwned(nextUrl) {
|
|
@@ -1032,15 +1044,24 @@ var ProductEndpoints = class {
|
|
|
1032
1044
|
// src/inventory/subscriptions/endpoints.ts
|
|
1033
1045
|
import { z as z14 } from "zod";
|
|
1034
1046
|
|
|
1047
|
+
// package.json
|
|
1048
|
+
var version = "3.6.0";
|
|
1049
|
+
|
|
1050
|
+
// src/utils/client.ts
|
|
1051
|
+
function buildClientHeader(sdk) {
|
|
1052
|
+
return `${sdk != null ? sdk : ""} @moonbase.sh/storefront-api/${version}`.trim().replace(/\s+/g, " ");
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1035
1055
|
// src/utils/api.ts
|
|
1036
1056
|
function objectToQuery(obj) {
|
|
1037
1057
|
return Object.entries(obj != null ? obj : {}).filter(([_, value]) => value !== void 0).map(([key, value]) => `${key}=${encodeURIComponent(value instanceof Date ? value.toISOString() : value)}`).join("&");
|
|
1038
1058
|
}
|
|
1039
1059
|
var MoonbaseApi = class {
|
|
1040
|
-
constructor(baseUrl, tokenStore, logger) {
|
|
1060
|
+
constructor(baseUrl, tokenStore, logger, sdk) {
|
|
1041
1061
|
this.baseUrl = baseUrl;
|
|
1042
1062
|
this.tokenStore = tokenStore;
|
|
1043
1063
|
this.logger = logger;
|
|
1064
|
+
this.clientHeader = buildClientHeader(sdk);
|
|
1044
1065
|
}
|
|
1045
1066
|
async authenticatedFetch(path, schema, options) {
|
|
1046
1067
|
if (!this.tokenStore.user)
|
|
@@ -1065,7 +1086,8 @@ var MoonbaseApi = class {
|
|
|
1065
1086
|
// While this fetch can be anonymous, we add the token if we have it
|
|
1066
1087
|
...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
|
|
1067
1088
|
// Force CORS on all calls
|
|
1068
|
-
"x-mb-cors": "1"
|
|
1089
|
+
"x-mb-cors": "1",
|
|
1090
|
+
"x-mb-client": this.clientHeader
|
|
1069
1091
|
},
|
|
1070
1092
|
body: (options == null ? void 0 : options.body) ? contentType !== "application/json" ? options.body : JSON.stringify(options.body) : void 0,
|
|
1071
1093
|
signal: options == null ? void 0 : options.abort,
|
|
@@ -1124,7 +1146,8 @@ var MoonbaseApi = class {
|
|
|
1124
1146
|
method: "POST",
|
|
1125
1147
|
headers: {
|
|
1126
1148
|
"Accept": "application/json",
|
|
1127
|
-
"Content-Type": "application/json"
|
|
1149
|
+
"Content-Type": "application/json",
|
|
1150
|
+
"x-mb-client": this.clientHeader
|
|
1128
1151
|
},
|
|
1129
1152
|
body: JSON.stringify({
|
|
1130
1153
|
title: "Parse error",
|
|
@@ -1146,7 +1169,8 @@ var MoonbaseApi = class {
|
|
|
1146
1169
|
method: "POST",
|
|
1147
1170
|
headers: {
|
|
1148
1171
|
"Accept": "application/json",
|
|
1149
|
-
"Content-Type": "application/json"
|
|
1172
|
+
"Content-Type": "application/json",
|
|
1173
|
+
"x-mb-client": this.clientHeader
|
|
1150
1174
|
},
|
|
1151
1175
|
body: JSON.stringify({
|
|
1152
1176
|
title: "Request error",
|
|
@@ -1798,7 +1822,8 @@ var _TokenStore = class _TokenStore {
|
|
|
1798
1822
|
headers: {
|
|
1799
1823
|
"Accept": "application/json",
|
|
1800
1824
|
"Content-Type": "text/plain",
|
|
1801
|
-
"x-mb-cors": "1"
|
|
1825
|
+
"x-mb-cors": "1",
|
|
1826
|
+
"x-mb-client": buildClientHeader(this.configuration.sdk)
|
|
1802
1827
|
},
|
|
1803
1828
|
body: this.tokens.accessToken
|
|
1804
1829
|
});
|
|
@@ -1834,13 +1859,26 @@ var TokenStore = _TokenStore;
|
|
|
1834
1859
|
// src/vendor/schemas.ts
|
|
1835
1860
|
var schemas_exports9 = {};
|
|
1836
1861
|
__export(schemas_exports9, {
|
|
1862
|
+
vendorCaptchaSchema: () => vendorCaptchaSchema,
|
|
1863
|
+
vendorFeaturesSchema: () => vendorFeaturesSchema,
|
|
1837
1864
|
vendorSchema: () => vendorSchema
|
|
1838
1865
|
});
|
|
1839
1866
|
import { z as z15 } from "zod";
|
|
1867
|
+
var vendorCaptchaSchema = z15.object({
|
|
1868
|
+
url: z15.string()
|
|
1869
|
+
});
|
|
1870
|
+
var vendorFeaturesSchema = z15.object({
|
|
1871
|
+
customerPortal: z15.boolean().optional(),
|
|
1872
|
+
phoneNumber: z15.boolean().optional(),
|
|
1873
|
+
marketingConsent: z15.nativeEnum(MarketingConsentType).optional().catch(void 0),
|
|
1874
|
+
// Absent on backends from before captchas, which never ask for one.
|
|
1875
|
+
captcha: vendorCaptchaSchema.nullish()
|
|
1876
|
+
});
|
|
1840
1877
|
var vendorSchema = z15.object({
|
|
1841
1878
|
id: z15.string(),
|
|
1842
1879
|
name: z15.string(),
|
|
1843
|
-
logoUrl: z15.string().nullable()
|
|
1880
|
+
logoUrl: z15.string().nullable(),
|
|
1881
|
+
features: vendorFeaturesSchema.optional()
|
|
1844
1882
|
});
|
|
1845
1883
|
|
|
1846
1884
|
// src/vendor/endpoints.ts
|
|
@@ -2517,7 +2555,7 @@ var MoonbaseClient = class {
|
|
|
2517
2555
|
this.configuration.endpoint = this.configuration.endpoint.replace(/\/$/, "");
|
|
2518
2556
|
this.logger = (_a = this.configuration.logger) != null ? _a : new ConsoleLogger();
|
|
2519
2557
|
this.tokenStore = new TokenStore(configuration);
|
|
2520
|
-
this.api = new MoonbaseApi(this.configuration.endpoint, this.tokenStore, this.logger);
|
|
2558
|
+
this.api = new MoonbaseApi(this.configuration.endpoint, this.tokenStore, this.logger, this.configuration.sdk);
|
|
2521
2559
|
this.storefront = new StorefrontEndpoints(this.api, this.configuration);
|
|
2522
2560
|
this.identity = new IdentityEndpoints(this.api, this.tokenStore, this.logger);
|
|
2523
2561
|
this.communications = new CommunicationsEndpoints(this.api);
|
|
@@ -2535,6 +2573,7 @@ export {
|
|
|
2535
2573
|
ActivationRequestStatus,
|
|
2536
2574
|
ActivationStatus,
|
|
2537
2575
|
Architecture,
|
|
2576
|
+
CaptchaRequiredError,
|
|
2538
2577
|
CartUtils,
|
|
2539
2578
|
ConnectableAccountProvider,
|
|
2540
2579
|
ConsoleLogger,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonbase.sh/storefront-api",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.6.0",
|
|
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",
|