@moonbase.sh/storefront-api 0.3.19 → 0.3.20
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 +10 -12
- package/dist/index.d.cts +1407 -1402
- package/dist/index.d.ts +1407 -1402
- package/dist/index.js +10 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -333,7 +333,7 @@ var schemas_exports = {};
|
|
|
333
333
|
__export(schemas_exports, {
|
|
334
334
|
addressSchema: () => addressSchema,
|
|
335
335
|
communicationPreferencesSchema: () => communicationPreferencesSchema,
|
|
336
|
-
|
|
336
|
+
identitySchema: () => identitySchema,
|
|
337
337
|
userAccountConfirmedSchema: () => userAccountConfirmedSchema,
|
|
338
338
|
userSchema: () => userSchema
|
|
339
339
|
});
|
|
@@ -362,7 +362,7 @@ var userSchema = z7.object({
|
|
|
362
362
|
hasProducts: z7.boolean().nullish(),
|
|
363
363
|
hasSubscriptions: z7.boolean().nullish()
|
|
364
364
|
});
|
|
365
|
-
var
|
|
365
|
+
var identitySchema = userSchema.and(z7.object({
|
|
366
366
|
accessToken: z7.string(),
|
|
367
367
|
refreshToken: z7.string()
|
|
368
368
|
}));
|
|
@@ -399,7 +399,7 @@ var IdentityEndpoints = class {
|
|
|
399
399
|
await handleResponseProblem(response);
|
|
400
400
|
try {
|
|
401
401
|
const data = await response.json();
|
|
402
|
-
const user =
|
|
402
|
+
const user = identitySchema.parse(data);
|
|
403
403
|
this.tokenStore.setUser(user);
|
|
404
404
|
return userSchema.parse(user);
|
|
405
405
|
} catch (err) {
|
|
@@ -408,7 +408,7 @@ var IdentityEndpoints = class {
|
|
|
408
408
|
}
|
|
409
409
|
}
|
|
410
410
|
async signUp(name, email, password, address, acceptedPrivacyPolicy, acceptedTermsAndConditions, communicationOptIn) {
|
|
411
|
-
const response = await this.api.fetch(`/api/customer/identity/sign-up?scheme=JWT&communicationOptIn=${communicationOptIn ? "true" : "false"}`,
|
|
411
|
+
const response = await this.api.fetch(`/api/customer/identity/sign-up?scheme=JWT&communicationOptIn=${communicationOptIn ? "true" : "false"}`, identitySchema, {
|
|
412
412
|
method: "POST",
|
|
413
413
|
body: {
|
|
414
414
|
name,
|
|
@@ -854,7 +854,7 @@ var MoonbaseApi = class {
|
|
|
854
854
|
this.tokenStore = tokenStore;
|
|
855
855
|
}
|
|
856
856
|
async authenticatedFetch(path, schema, options) {
|
|
857
|
-
if (!this.tokenStore.
|
|
857
|
+
if (!this.tokenStore.user)
|
|
858
858
|
throw new NotAuthenticatedError();
|
|
859
859
|
return await this.fetch(path, schema, options);
|
|
860
860
|
}
|
|
@@ -909,7 +909,7 @@ var MoonbaseApi = class {
|
|
|
909
909
|
}
|
|
910
910
|
async reportParsingProblem(path, err, body) {
|
|
911
911
|
try {
|
|
912
|
-
await fetch2(this.baseUrl
|
|
912
|
+
await fetch2(`${this.baseUrl}/api/customer/insights/error`, {
|
|
913
913
|
mode: "cors",
|
|
914
914
|
method: "POST",
|
|
915
915
|
headers: {
|
|
@@ -931,7 +931,7 @@ var MoonbaseApi = class {
|
|
|
931
931
|
}
|
|
932
932
|
async reportRequestProblem(path, request, response, err) {
|
|
933
933
|
try {
|
|
934
|
-
await fetch2(this.baseUrl
|
|
934
|
+
await fetch2(`${this.baseUrl}/api/customer/insights/warn`, {
|
|
935
935
|
mode: "cors",
|
|
936
936
|
method: "POST",
|
|
937
937
|
headers: {
|
|
@@ -979,9 +979,6 @@ var _TokenStore = class _TokenStore {
|
|
|
979
979
|
return this.tokens;
|
|
980
980
|
return null;
|
|
981
981
|
}
|
|
982
|
-
get hasAccessToken() {
|
|
983
|
-
return !!this.tokens;
|
|
984
|
-
}
|
|
985
982
|
async getAccessToken() {
|
|
986
983
|
var _a, _b, _c;
|
|
987
984
|
if (this.isExpired) {
|
|
@@ -1040,7 +1037,7 @@ var _TokenStore = class _TokenStore {
|
|
|
1040
1037
|
}
|
|
1041
1038
|
throw new MoonbaseError("Unexpected result", `Could not refresh access token, status code ${response.status}`, response.status);
|
|
1042
1039
|
}
|
|
1043
|
-
const result =
|
|
1040
|
+
const result = identitySchema.parse(await response.json());
|
|
1044
1041
|
return this.setUser(result);
|
|
1045
1042
|
}
|
|
1046
1043
|
handleStorageUpdate(event) {
|
|
@@ -1121,9 +1118,10 @@ __export(schemas_exports3, {
|
|
|
1121
1118
|
// src/index.ts
|
|
1122
1119
|
var MoonbaseClient = class {
|
|
1123
1120
|
constructor(configuration) {
|
|
1121
|
+
var _a;
|
|
1124
1122
|
this.configuration = configuration;
|
|
1125
1123
|
this.configuration.endpoint = this.configuration.endpoint.replace(/\/$/, "");
|
|
1126
|
-
this.tokenStore = new TokenStore(configuration);
|
|
1124
|
+
this.tokenStore = (_a = configuration.tokenStore) != null ? _a : new TokenStore(configuration);
|
|
1127
1125
|
this.api = new MoonbaseApi(this.configuration.endpoint, this.tokenStore);
|
|
1128
1126
|
this.storefront = new StorefrontEndpoints(this.api, this.configuration);
|
|
1129
1127
|
this.identity = new IdentityEndpoints(this.api, this.tokenStore);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonbase.sh/storefront-api",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.20",
|
|
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",
|