@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.js
CHANGED
|
@@ -91,6 +91,7 @@ var storefrontProductSchema = z3.object({
|
|
|
91
91
|
name: z3.string(),
|
|
92
92
|
tagline: z3.string(),
|
|
93
93
|
iconUrl: z3.string().nullable(),
|
|
94
|
+
website: z3.string().nullish(),
|
|
94
95
|
owned: z3.boolean(),
|
|
95
96
|
currentVersion: z3.string().optional(),
|
|
96
97
|
downloads: downloadSchema.array().optional(),
|
|
@@ -123,6 +124,7 @@ var ActivationRequestStatus = /* @__PURE__ */ ((ActivationRequestStatus2) => {
|
|
|
123
124
|
ActivationRequestStatus2["Requested"] = "Requested";
|
|
124
125
|
ActivationRequestStatus2["Fulfilled"] = "Fulfilled";
|
|
125
126
|
ActivationRequestStatus2["Completed"] = "Completed";
|
|
127
|
+
ActivationRequestStatus2["Cancelled"] = "Cancelled";
|
|
126
128
|
return ActivationRequestStatus2;
|
|
127
129
|
})(ActivationRequestStatus || {});
|
|
128
130
|
|
|
@@ -164,6 +166,10 @@ var ActivationRequestEndpoints = class {
|
|
|
164
166
|
const response = await this.api.fetch(`/api/customer/activations/${requestId}/trial`, "POST");
|
|
165
167
|
return activationRequestSchema.parse(response.data);
|
|
166
168
|
}
|
|
169
|
+
async cancel(requestId) {
|
|
170
|
+
const response = await this.api.fetch(`/api/customer/activations/${requestId}/cancel`, "POST");
|
|
171
|
+
return activationRequestSchema.parse(response.data);
|
|
172
|
+
}
|
|
167
173
|
};
|
|
168
174
|
|
|
169
175
|
// src/identity/endpoints.ts
|
|
@@ -192,13 +198,18 @@ var NotFoundError = class extends Error {
|
|
|
192
198
|
}
|
|
193
199
|
};
|
|
194
200
|
var MoonbaseError = class extends Error {
|
|
195
|
-
constructor(title, detail, status) {
|
|
201
|
+
constructor(title, detail, status, errors) {
|
|
196
202
|
super();
|
|
197
203
|
this.title = title;
|
|
198
204
|
this.detail = detail;
|
|
199
205
|
this.status = status;
|
|
206
|
+
this.errors = errors;
|
|
200
207
|
this.name = "MoonbaseError";
|
|
201
|
-
|
|
208
|
+
if (errors && Object.values(errors).length === 1) {
|
|
209
|
+
this.message = Object.values(errors)[0];
|
|
210
|
+
} else {
|
|
211
|
+
this.message = detail != null ? detail : title;
|
|
212
|
+
}
|
|
202
213
|
}
|
|
203
214
|
};
|
|
204
215
|
|
|
@@ -207,8 +218,17 @@ var problemDetailsSchema = z6.object({
|
|
|
207
218
|
type: z6.string(),
|
|
208
219
|
title: z6.string(),
|
|
209
220
|
detail: z6.string().optional(),
|
|
210
|
-
status: z6.number()
|
|
221
|
+
status: z6.number(),
|
|
222
|
+
errors: z6.record(z6.string(), z6.string().array()).optional()
|
|
211
223
|
});
|
|
224
|
+
function camelCase(str) {
|
|
225
|
+
return str.split(".").map((word, index) => {
|
|
226
|
+
let [firstLetter, ...restOfLetters] = word;
|
|
227
|
+
firstLetter = index !== 0 ? firstLetter.toUpperCase() : firstLetter.toLowerCase();
|
|
228
|
+
restOfLetters = [restOfLetters.join("").toLowerCase()];
|
|
229
|
+
return firstLetter + restOfLetters[0];
|
|
230
|
+
}).join("");
|
|
231
|
+
}
|
|
212
232
|
async function handleResponseProblem(response) {
|
|
213
233
|
if (response.status === 404)
|
|
214
234
|
throw new NotFoundError();
|
|
@@ -223,7 +243,12 @@ async function handleResponseProblem(response) {
|
|
|
223
243
|
} catch (e) {
|
|
224
244
|
throw new Error("An unknown problem occurred");
|
|
225
245
|
}
|
|
226
|
-
throw new MoonbaseError(
|
|
246
|
+
throw new MoonbaseError(
|
|
247
|
+
problemDetails.title,
|
|
248
|
+
problemDetails.detail,
|
|
249
|
+
problemDetails.status,
|
|
250
|
+
problemDetails.errors ? Object.fromEntries(Object.entries(problemDetails.errors).map(([field, errors]) => [camelCase(field), errors.join(", ")])) : void 0
|
|
251
|
+
);
|
|
227
252
|
}
|
|
228
253
|
|
|
229
254
|
// src/identity/schemas.ts
|
|
@@ -604,8 +629,15 @@ var _TokenStore = class _TokenStore {
|
|
|
604
629
|
handleStorageUpdate(event) {
|
|
605
630
|
switch (event.key) {
|
|
606
631
|
case _TokenStore.storageKey:
|
|
607
|
-
this.tokens = JSON.parse(event.newValue);
|
|
608
|
-
this.
|
|
632
|
+
this.tokens = event.newValue ? JSON.parse(event.newValue) : null;
|
|
633
|
+
if (this.refreshTimeoutId != null)
|
|
634
|
+
window.clearTimeout(this.refreshTimeoutId);
|
|
635
|
+
if (this.tokens) {
|
|
636
|
+
this.tokens.expiresAt = new Date(this.tokens.expiresAt);
|
|
637
|
+
this.refreshTimeoutId = window.setTimeout(() => {
|
|
638
|
+
this.refreshPromise = this.refreshTokens();
|
|
639
|
+
}, 10 * 60 * 1e3 + (Math.random() + 1) * 60 * 1e3);
|
|
640
|
+
}
|
|
609
641
|
break;
|
|
610
642
|
}
|
|
611
643
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonbase.sh/storefront-api",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.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",
|