@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.cjs
CHANGED
|
@@ -381,7 +381,7 @@ var schemas_exports = {};
|
|
|
381
381
|
__export(schemas_exports, {
|
|
382
382
|
addressSchema: () => addressSchema,
|
|
383
383
|
communicationPreferencesSchema: () => communicationPreferencesSchema,
|
|
384
|
-
|
|
384
|
+
identitySchema: () => identitySchema,
|
|
385
385
|
userAccountConfirmedSchema: () => userAccountConfirmedSchema,
|
|
386
386
|
userSchema: () => userSchema
|
|
387
387
|
});
|
|
@@ -410,7 +410,7 @@ var userSchema = import_zod7.z.object({
|
|
|
410
410
|
hasProducts: import_zod7.z.boolean().nullish(),
|
|
411
411
|
hasSubscriptions: import_zod7.z.boolean().nullish()
|
|
412
412
|
});
|
|
413
|
-
var
|
|
413
|
+
var identitySchema = userSchema.and(import_zod7.z.object({
|
|
414
414
|
accessToken: import_zod7.z.string(),
|
|
415
415
|
refreshToken: import_zod7.z.string()
|
|
416
416
|
}));
|
|
@@ -447,7 +447,7 @@ var IdentityEndpoints = class {
|
|
|
447
447
|
await handleResponseProblem(response);
|
|
448
448
|
try {
|
|
449
449
|
const data = await response.json();
|
|
450
|
-
const user =
|
|
450
|
+
const user = identitySchema.parse(data);
|
|
451
451
|
this.tokenStore.setUser(user);
|
|
452
452
|
return userSchema.parse(user);
|
|
453
453
|
} catch (err) {
|
|
@@ -456,7 +456,7 @@ var IdentityEndpoints = class {
|
|
|
456
456
|
}
|
|
457
457
|
}
|
|
458
458
|
async signUp(name, email, password, address, acceptedPrivacyPolicy, acceptedTermsAndConditions, communicationOptIn) {
|
|
459
|
-
const response = await this.api.fetch(`/api/customer/identity/sign-up?scheme=JWT&communicationOptIn=${communicationOptIn ? "true" : "false"}`,
|
|
459
|
+
const response = await this.api.fetch(`/api/customer/identity/sign-up?scheme=JWT&communicationOptIn=${communicationOptIn ? "true" : "false"}`, identitySchema, {
|
|
460
460
|
method: "POST",
|
|
461
461
|
body: {
|
|
462
462
|
name,
|
|
@@ -902,7 +902,7 @@ var MoonbaseApi = class {
|
|
|
902
902
|
this.tokenStore = tokenStore;
|
|
903
903
|
}
|
|
904
904
|
async authenticatedFetch(path, schema, options) {
|
|
905
|
-
if (!this.tokenStore.
|
|
905
|
+
if (!this.tokenStore.user)
|
|
906
906
|
throw new NotAuthenticatedError();
|
|
907
907
|
return await this.fetch(path, schema, options);
|
|
908
908
|
}
|
|
@@ -957,7 +957,7 @@ var MoonbaseApi = class {
|
|
|
957
957
|
}
|
|
958
958
|
async reportParsingProblem(path, err, body) {
|
|
959
959
|
try {
|
|
960
|
-
await (0, import_cross_fetch2.default)(this.baseUrl
|
|
960
|
+
await (0, import_cross_fetch2.default)(`${this.baseUrl}/api/customer/insights/error`, {
|
|
961
961
|
mode: "cors",
|
|
962
962
|
method: "POST",
|
|
963
963
|
headers: {
|
|
@@ -979,7 +979,7 @@ var MoonbaseApi = class {
|
|
|
979
979
|
}
|
|
980
980
|
async reportRequestProblem(path, request, response, err) {
|
|
981
981
|
try {
|
|
982
|
-
await (0, import_cross_fetch2.default)(this.baseUrl
|
|
982
|
+
await (0, import_cross_fetch2.default)(`${this.baseUrl}/api/customer/insights/warn`, {
|
|
983
983
|
mode: "cors",
|
|
984
984
|
method: "POST",
|
|
985
985
|
headers: {
|
|
@@ -1027,9 +1027,6 @@ var _TokenStore = class _TokenStore {
|
|
|
1027
1027
|
return this.tokens;
|
|
1028
1028
|
return null;
|
|
1029
1029
|
}
|
|
1030
|
-
get hasAccessToken() {
|
|
1031
|
-
return !!this.tokens;
|
|
1032
|
-
}
|
|
1033
1030
|
async getAccessToken() {
|
|
1034
1031
|
var _a, _b, _c;
|
|
1035
1032
|
if (this.isExpired) {
|
|
@@ -1088,7 +1085,7 @@ var _TokenStore = class _TokenStore {
|
|
|
1088
1085
|
}
|
|
1089
1086
|
throw new MoonbaseError("Unexpected result", `Could not refresh access token, status code ${response.status}`, response.status);
|
|
1090
1087
|
}
|
|
1091
|
-
const result =
|
|
1088
|
+
const result = identitySchema.parse(await response.json());
|
|
1092
1089
|
return this.setUser(result);
|
|
1093
1090
|
}
|
|
1094
1091
|
handleStorageUpdate(event) {
|
|
@@ -1169,9 +1166,10 @@ __export(schemas_exports3, {
|
|
|
1169
1166
|
// src/index.ts
|
|
1170
1167
|
var MoonbaseClient = class {
|
|
1171
1168
|
constructor(configuration) {
|
|
1169
|
+
var _a;
|
|
1172
1170
|
this.configuration = configuration;
|
|
1173
1171
|
this.configuration.endpoint = this.configuration.endpoint.replace(/\/$/, "");
|
|
1174
|
-
this.tokenStore = new TokenStore(configuration);
|
|
1172
|
+
this.tokenStore = (_a = configuration.tokenStore) != null ? _a : new TokenStore(configuration);
|
|
1175
1173
|
this.api = new MoonbaseApi(this.configuration.endpoint, this.tokenStore);
|
|
1176
1174
|
this.storefront = new StorefrontEndpoints(this.api, this.configuration);
|
|
1177
1175
|
this.identity = new IdentityEndpoints(this.api, this.tokenStore);
|