@moonbase.sh/storefront-api 0.1.122 → 0.2.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/dist/index.cjs +38 -6
- package/dist/index.d.cts +106 -2
- package/dist/index.d.ts +106 -2
- package/dist/index.js +38 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -138,6 +138,7 @@ var storefrontProductSchema = import_zod3.z.object({
|
|
|
138
138
|
name: import_zod3.z.string(),
|
|
139
139
|
tagline: import_zod3.z.string(),
|
|
140
140
|
iconUrl: import_zod3.z.string().nullable(),
|
|
141
|
+
website: import_zod3.z.string().nullish(),
|
|
141
142
|
owned: import_zod3.z.boolean(),
|
|
142
143
|
currentVersion: import_zod3.z.string().optional(),
|
|
143
144
|
downloads: downloadSchema.array().optional(),
|
|
@@ -170,6 +171,7 @@ var ActivationRequestStatus = /* @__PURE__ */ ((ActivationRequestStatus2) => {
|
|
|
170
171
|
ActivationRequestStatus2["Requested"] = "Requested";
|
|
171
172
|
ActivationRequestStatus2["Fulfilled"] = "Fulfilled";
|
|
172
173
|
ActivationRequestStatus2["Completed"] = "Completed";
|
|
174
|
+
ActivationRequestStatus2["Cancelled"] = "Cancelled";
|
|
173
175
|
return ActivationRequestStatus2;
|
|
174
176
|
})(ActivationRequestStatus || {});
|
|
175
177
|
|
|
@@ -211,6 +213,10 @@ var ActivationRequestEndpoints = class {
|
|
|
211
213
|
const response = await this.api.fetch(`/api/customer/activations/${requestId}/trial`, "POST");
|
|
212
214
|
return activationRequestSchema.parse(response.data);
|
|
213
215
|
}
|
|
216
|
+
async cancel(requestId) {
|
|
217
|
+
const response = await this.api.fetch(`/api/customer/activations/${requestId}/cancel`, "POST");
|
|
218
|
+
return activationRequestSchema.parse(response.data);
|
|
219
|
+
}
|
|
214
220
|
};
|
|
215
221
|
|
|
216
222
|
// src/identity/endpoints.ts
|
|
@@ -239,13 +245,18 @@ var NotFoundError = class extends Error {
|
|
|
239
245
|
}
|
|
240
246
|
};
|
|
241
247
|
var MoonbaseError = class extends Error {
|
|
242
|
-
constructor(title, detail, status) {
|
|
248
|
+
constructor(title, detail, status, errors) {
|
|
243
249
|
super();
|
|
244
250
|
this.title = title;
|
|
245
251
|
this.detail = detail;
|
|
246
252
|
this.status = status;
|
|
253
|
+
this.errors = errors;
|
|
247
254
|
this.name = "MoonbaseError";
|
|
248
|
-
|
|
255
|
+
if (errors && Object.values(errors).length === 1) {
|
|
256
|
+
this.message = Object.values(errors)[0];
|
|
257
|
+
} else {
|
|
258
|
+
this.message = detail != null ? detail : title;
|
|
259
|
+
}
|
|
249
260
|
}
|
|
250
261
|
};
|
|
251
262
|
|
|
@@ -254,8 +265,17 @@ var problemDetailsSchema = import_zod6.z.object({
|
|
|
254
265
|
type: import_zod6.z.string(),
|
|
255
266
|
title: import_zod6.z.string(),
|
|
256
267
|
detail: import_zod6.z.string().optional(),
|
|
257
|
-
status: import_zod6.z.number()
|
|
268
|
+
status: import_zod6.z.number(),
|
|
269
|
+
errors: import_zod6.z.record(import_zod6.z.string(), import_zod6.z.string().array()).optional()
|
|
258
270
|
});
|
|
271
|
+
function camelCase(str) {
|
|
272
|
+
return str.split(".").map((word, index) => {
|
|
273
|
+
let [firstLetter, ...restOfLetters] = word;
|
|
274
|
+
firstLetter = index !== 0 ? firstLetter.toUpperCase() : firstLetter.toLowerCase();
|
|
275
|
+
restOfLetters = [restOfLetters.join("").toLowerCase()];
|
|
276
|
+
return firstLetter + restOfLetters[0];
|
|
277
|
+
}).join("");
|
|
278
|
+
}
|
|
259
279
|
async function handleResponseProblem(response) {
|
|
260
280
|
if (response.status === 404)
|
|
261
281
|
throw new NotFoundError();
|
|
@@ -270,7 +290,12 @@ async function handleResponseProblem(response) {
|
|
|
270
290
|
} catch (e) {
|
|
271
291
|
throw new Error("An unknown problem occurred");
|
|
272
292
|
}
|
|
273
|
-
throw new MoonbaseError(
|
|
293
|
+
throw new MoonbaseError(
|
|
294
|
+
problemDetails.title,
|
|
295
|
+
problemDetails.detail,
|
|
296
|
+
problemDetails.status,
|
|
297
|
+
problemDetails.errors ? Object.fromEntries(Object.entries(problemDetails.errors).map(([field, errors]) => [camelCase(field), errors.join(", ")])) : void 0
|
|
298
|
+
);
|
|
274
299
|
}
|
|
275
300
|
|
|
276
301
|
// src/identity/schemas.ts
|
|
@@ -651,8 +676,15 @@ var _TokenStore = class _TokenStore {
|
|
|
651
676
|
handleStorageUpdate(event) {
|
|
652
677
|
switch (event.key) {
|
|
653
678
|
case _TokenStore.storageKey:
|
|
654
|
-
this.tokens = JSON.parse(event.newValue);
|
|
655
|
-
this.
|
|
679
|
+
this.tokens = event.newValue ? JSON.parse(event.newValue) : null;
|
|
680
|
+
if (this.refreshTimeoutId != null)
|
|
681
|
+
window.clearTimeout(this.refreshTimeoutId);
|
|
682
|
+
if (this.tokens) {
|
|
683
|
+
this.tokens.expiresAt = new Date(this.tokens.expiresAt);
|
|
684
|
+
this.refreshTimeoutId = window.setTimeout(() => {
|
|
685
|
+
this.refreshPromise = this.refreshTokens();
|
|
686
|
+
}, 10 * 60 * 1e3 + (Math.random() + 1) * 60 * 1e3);
|
|
687
|
+
}
|
|
656
688
|
break;
|
|
657
689
|
}
|
|
658
690
|
}
|