@moonbase.sh/api 0.1.109
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 +393 -0
- package/dist/index.d.cts +721 -0
- package/dist/index.d.ts +721 -0
- package/dist/index.js +346 -0
- package/package.json +30 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
ActivationMethod: () => ActivationMethod,
|
|
34
|
+
ActivationRequestStatus: () => ActivationRequestStatus,
|
|
35
|
+
ActivationStatus: () => ActivationStatus,
|
|
36
|
+
LicenseStatus: () => LicenseStatus,
|
|
37
|
+
MoonbaseClient: () => MoonbaseClient,
|
|
38
|
+
MoonbaseError: () => MoonbaseError,
|
|
39
|
+
NotAuthenticatedError: () => NotAuthenticatedError,
|
|
40
|
+
NotAuthorizedError: () => NotAuthorizedError,
|
|
41
|
+
NotFoundError: () => NotFoundError,
|
|
42
|
+
ProductStatus: () => ProductStatus,
|
|
43
|
+
TrialStatus: () => TrialStatus
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(src_exports);
|
|
46
|
+
|
|
47
|
+
// src/activationRequests/schemas.ts
|
|
48
|
+
var import_zod5 = require("zod");
|
|
49
|
+
|
|
50
|
+
// src/customers/schemas.ts
|
|
51
|
+
var import_zod = require("zod");
|
|
52
|
+
var addressSchema = import_zod.z.object({
|
|
53
|
+
countryCode: import_zod.z.string(),
|
|
54
|
+
streetAddress1: import_zod.z.string(),
|
|
55
|
+
streetAddress2: import_zod.z.string().nullable(),
|
|
56
|
+
locality: import_zod.z.string().nullable(),
|
|
57
|
+
region: import_zod.z.string().nullable(),
|
|
58
|
+
postCode: import_zod.z.string()
|
|
59
|
+
});
|
|
60
|
+
var communicationPreferencesSchema = import_zod.z.object({
|
|
61
|
+
newsletterOptIn: import_zod.z.boolean()
|
|
62
|
+
// productUpdatesOptIn: z.boolean(), // TODO: Enable when relevant
|
|
63
|
+
});
|
|
64
|
+
var customerSchema = import_zod.z.object({
|
|
65
|
+
id: import_zod.z.string(),
|
|
66
|
+
name: import_zod.z.string(),
|
|
67
|
+
businessName: import_zod.z.string().nullable(),
|
|
68
|
+
taxId: import_zod.z.string().nullable(),
|
|
69
|
+
email: import_zod.z.string(),
|
|
70
|
+
numberOfLicenses: import_zod.z.number(),
|
|
71
|
+
numberOfTrials: import_zod.z.number(),
|
|
72
|
+
emailConfirmed: import_zod.z.boolean(),
|
|
73
|
+
hasPassword: import_zod.z.boolean(),
|
|
74
|
+
isDeleted: import_zod.z.boolean(),
|
|
75
|
+
ownedProducts: import_zod.z.string().array(),
|
|
76
|
+
address: addressSchema.nullable(),
|
|
77
|
+
communicationPreferences: communicationPreferencesSchema
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// src/licenses/schemas.ts
|
|
81
|
+
var import_zod2 = require("zod");
|
|
82
|
+
|
|
83
|
+
// src/licenses/models.ts
|
|
84
|
+
var LicenseStatus = /* @__PURE__ */ ((LicenseStatus2) => {
|
|
85
|
+
LicenseStatus2["Active"] = "Active";
|
|
86
|
+
LicenseStatus2["Revoked"] = "Revoked";
|
|
87
|
+
return LicenseStatus2;
|
|
88
|
+
})(LicenseStatus || {});
|
|
89
|
+
var ActivationStatus = /* @__PURE__ */ ((ActivationStatus2) => {
|
|
90
|
+
ActivationStatus2["Active"] = "Active";
|
|
91
|
+
ActivationStatus2["Revoked"] = "Revoked";
|
|
92
|
+
return ActivationStatus2;
|
|
93
|
+
})(ActivationStatus || {});
|
|
94
|
+
var ActivationMethod = /* @__PURE__ */ ((ActivationMethod2) => {
|
|
95
|
+
ActivationMethod2["Online"] = "Online";
|
|
96
|
+
ActivationMethod2["Offline"] = "Offline";
|
|
97
|
+
return ActivationMethod2;
|
|
98
|
+
})(ActivationMethod || {});
|
|
99
|
+
|
|
100
|
+
// src/licenses/schemas.ts
|
|
101
|
+
var licenseSchema = import_zod2.z.object({
|
|
102
|
+
id: import_zod2.z.string(),
|
|
103
|
+
status: import_zod2.z.nativeEnum(LicenseStatus),
|
|
104
|
+
activeNumberOfActivations: import_zod2.z.number(),
|
|
105
|
+
maxNumberOfActivations: import_zod2.z.number()
|
|
106
|
+
});
|
|
107
|
+
var licenseActivationSchema = import_zod2.z.object({
|
|
108
|
+
id: import_zod2.z.string(),
|
|
109
|
+
name: import_zod2.z.string(),
|
|
110
|
+
status: import_zod2.z.nativeEnum(ActivationStatus),
|
|
111
|
+
activationMethod: import_zod2.z.nativeEnum(ActivationMethod),
|
|
112
|
+
lastValidatedAt: import_zod2.z.coerce.date(),
|
|
113
|
+
license: licenseSchema
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// src/products/schemas.ts
|
|
117
|
+
var import_zod3 = require("zod");
|
|
118
|
+
|
|
119
|
+
// src/products/models.ts
|
|
120
|
+
var ProductStatus = /* @__PURE__ */ ((ProductStatus2) => {
|
|
121
|
+
ProductStatus2["Active"] = "Active";
|
|
122
|
+
ProductStatus2["Inactive"] = "Inactive";
|
|
123
|
+
return ProductStatus2;
|
|
124
|
+
})(ProductStatus || {});
|
|
125
|
+
|
|
126
|
+
// src/products/schemas.ts
|
|
127
|
+
var productSchema = import_zod3.z.object({
|
|
128
|
+
id: import_zod3.z.string(),
|
|
129
|
+
name: import_zod3.z.string(),
|
|
130
|
+
tagline: import_zod3.z.string(),
|
|
131
|
+
description: import_zod3.z.string(),
|
|
132
|
+
website: import_zod3.z.string().nullable(),
|
|
133
|
+
iconUrl: import_zod3.z.string().nullable(),
|
|
134
|
+
status: import_zod3.z.nativeEnum(ProductStatus),
|
|
135
|
+
purchasable: import_zod3.z.boolean(),
|
|
136
|
+
currentReleaseVersion: import_zod3.z.string().nullable()
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// src/trials/schemas.ts
|
|
140
|
+
var import_zod4 = require("zod");
|
|
141
|
+
|
|
142
|
+
// src/trials/models.ts
|
|
143
|
+
var TrialStatus = /* @__PURE__ */ ((TrialStatus2) => {
|
|
144
|
+
TrialStatus2["Active"] = "Active";
|
|
145
|
+
TrialStatus2["Expired"] = "Expired";
|
|
146
|
+
return TrialStatus2;
|
|
147
|
+
})(TrialStatus || {});
|
|
148
|
+
|
|
149
|
+
// src/trials/schemas.ts
|
|
150
|
+
var trialSchema = import_zod4.z.object({
|
|
151
|
+
id: import_zod4.z.string(),
|
|
152
|
+
status: import_zod4.z.nativeEnum(TrialStatus),
|
|
153
|
+
expiresAt: import_zod4.z.coerce.date(),
|
|
154
|
+
lastValidatedAt: import_zod4.z.coerce.date(),
|
|
155
|
+
ownerId: import_zod4.z.string().optional()
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// src/activationRequests/models.ts
|
|
159
|
+
var ActivationRequestStatus = /* @__PURE__ */ ((ActivationRequestStatus2) => {
|
|
160
|
+
ActivationRequestStatus2["Requested"] = "Requested";
|
|
161
|
+
ActivationRequestStatus2["Fulfilled"] = "Fulfilled";
|
|
162
|
+
ActivationRequestStatus2["Completed"] = "Completed";
|
|
163
|
+
return ActivationRequestStatus2;
|
|
164
|
+
})(ActivationRequestStatus || {});
|
|
165
|
+
|
|
166
|
+
// src/activationRequests/schemas.ts
|
|
167
|
+
var activationRequestSchema = import_zod5.z.object({
|
|
168
|
+
id: import_zod5.z.string(),
|
|
169
|
+
status: import_zod5.z.nativeEnum(ActivationRequestStatus),
|
|
170
|
+
product: productSchema,
|
|
171
|
+
activation: licenseActivationSchema.optional(),
|
|
172
|
+
trial: trialSchema.optional(),
|
|
173
|
+
customer: customerSchema.optional()
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// src/activationRequests/endpoints.ts
|
|
177
|
+
var ActivationRequestEndpoints = class {
|
|
178
|
+
constructor(api) {
|
|
179
|
+
this.api = api;
|
|
180
|
+
}
|
|
181
|
+
async get(requestId) {
|
|
182
|
+
const response = await this.api.fetch(`/api/activations/${requestId}`);
|
|
183
|
+
return activationRequestSchema.parse(response.data);
|
|
184
|
+
}
|
|
185
|
+
async request(productId) {
|
|
186
|
+
const response = await this.api.fetch(`/api/activations/${productId}/request`);
|
|
187
|
+
return activationRequestSchema.parse(response.data);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// src/customers/endpoints.ts
|
|
192
|
+
var CustomerEndpoints = class {
|
|
193
|
+
constructor(api) {
|
|
194
|
+
this.api = api;
|
|
195
|
+
}
|
|
196
|
+
async get(idOrEmail) {
|
|
197
|
+
const response = await this.api.fetch(`/api/customers/${idOrEmail}`);
|
|
198
|
+
return customerSchema.parse(response.data);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// src/licenses/endpoints.ts
|
|
203
|
+
var LicenseEndpoints = class {
|
|
204
|
+
constructor(api) {
|
|
205
|
+
this.api = api;
|
|
206
|
+
}
|
|
207
|
+
async validate(licenseId, activationId) {
|
|
208
|
+
const response = await this.api.fetch(`/api/licenses/${licenseId}/activations/${activationId}/validate`, "POST");
|
|
209
|
+
return licenseActivationSchema.parse(response.data);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// src/globalSchemas.ts
|
|
214
|
+
var import_zod6 = require("zod");
|
|
215
|
+
var priceCollectionSchema = import_zod6.z.record(import_zod6.z.number());
|
|
216
|
+
var percentageOffDiscountSchema = import_zod6.z.object({
|
|
217
|
+
type: import_zod6.z.literal("PercentageOffDiscount"),
|
|
218
|
+
name: import_zod6.z.string(),
|
|
219
|
+
description: import_zod6.z.string().optional(),
|
|
220
|
+
percentage: import_zod6.z.number(),
|
|
221
|
+
total: priceCollectionSchema
|
|
222
|
+
});
|
|
223
|
+
var flatAmountOffDiscountSchema = import_zod6.z.object({
|
|
224
|
+
type: import_zod6.z.literal("FlatAmountOffDiscount"),
|
|
225
|
+
name: import_zod6.z.string(),
|
|
226
|
+
description: import_zod6.z.string().optional(),
|
|
227
|
+
total: priceCollectionSchema
|
|
228
|
+
});
|
|
229
|
+
var discountSchema = import_zod6.z.discriminatedUnion("type", [
|
|
230
|
+
percentageOffDiscountSchema,
|
|
231
|
+
flatAmountOffDiscountSchema
|
|
232
|
+
]);
|
|
233
|
+
var pricingVariationSchema = import_zod6.z.object({
|
|
234
|
+
id: import_zod6.z.string(),
|
|
235
|
+
name: import_zod6.z.string(),
|
|
236
|
+
originalPrice: priceCollectionSchema,
|
|
237
|
+
price: priceCollectionSchema,
|
|
238
|
+
hasDiscount: import_zod6.z.boolean(),
|
|
239
|
+
discount: discountSchema.optional()
|
|
240
|
+
});
|
|
241
|
+
function paged(itemSchema) {
|
|
242
|
+
return import_zod6.z.object({
|
|
243
|
+
items: import_zod6.z.array(itemSchema),
|
|
244
|
+
hasMore: import_zod6.z.boolean(),
|
|
245
|
+
next: import_zod6.z.string().nullable()
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// src/utils/api.ts
|
|
250
|
+
var import_cross_fetch = __toESM(require("cross-fetch"), 1);
|
|
251
|
+
|
|
252
|
+
// src/utils/problemHandler.ts
|
|
253
|
+
var import_zod7 = require("zod");
|
|
254
|
+
|
|
255
|
+
// src/utils/errors.ts
|
|
256
|
+
var NotAuthorizedError = class extends Error {
|
|
257
|
+
constructor() {
|
|
258
|
+
super();
|
|
259
|
+
this.name = "NotAuthorizedError";
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
var NotAuthenticatedError = class extends Error {
|
|
263
|
+
constructor() {
|
|
264
|
+
super();
|
|
265
|
+
this.name = "NotAuthenticatedError";
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
var NotFoundError = class extends Error {
|
|
269
|
+
constructor() {
|
|
270
|
+
super();
|
|
271
|
+
this.name = "NotFoundError";
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
var MoonbaseError = class extends Error {
|
|
275
|
+
constructor(title, detail, status) {
|
|
276
|
+
super();
|
|
277
|
+
this.title = title;
|
|
278
|
+
this.detail = detail;
|
|
279
|
+
this.status = status;
|
|
280
|
+
this.name = "MoonbaseError";
|
|
281
|
+
this.message = detail != null ? detail : title;
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// src/utils/problemHandler.ts
|
|
286
|
+
var problemDetailsSchema = import_zod7.z.object({
|
|
287
|
+
type: import_zod7.z.string(),
|
|
288
|
+
title: import_zod7.z.string(),
|
|
289
|
+
detail: import_zod7.z.string().optional(),
|
|
290
|
+
status: import_zod7.z.number()
|
|
291
|
+
});
|
|
292
|
+
async function handleResponseProblem(response) {
|
|
293
|
+
if (response.status === 404)
|
|
294
|
+
throw new NotFoundError();
|
|
295
|
+
if (response.status === 401)
|
|
296
|
+
throw new NotAuthenticatedError();
|
|
297
|
+
if (response.status === 403)
|
|
298
|
+
throw new NotAuthorizedError();
|
|
299
|
+
let problemDetails;
|
|
300
|
+
try {
|
|
301
|
+
const json = await response.json();
|
|
302
|
+
problemDetails = problemDetailsSchema.parse(json);
|
|
303
|
+
} catch (e) {
|
|
304
|
+
throw new Error("An unknown problem occurred");
|
|
305
|
+
}
|
|
306
|
+
throw new MoonbaseError(problemDetails.title, problemDetails.detail, problemDetails.status);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// src/utils/api.ts
|
|
310
|
+
function objectToQuery(obj) {
|
|
311
|
+
return Object.entries(obj != null ? obj : {}).filter(([_, value]) => value !== void 0).map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join("&");
|
|
312
|
+
}
|
|
313
|
+
var MoonbaseApi = class {
|
|
314
|
+
constructor(baseUrl, apiKey) {
|
|
315
|
+
this.baseUrl = baseUrl;
|
|
316
|
+
this.apiKey = apiKey;
|
|
317
|
+
}
|
|
318
|
+
async fetch(path, method, body, contentType) {
|
|
319
|
+
contentType != null ? contentType : contentType = "application/json";
|
|
320
|
+
const response = await (0, import_cross_fetch.default)(this.baseUrl + path, {
|
|
321
|
+
method: method || "GET",
|
|
322
|
+
mode: "cors",
|
|
323
|
+
headers: {
|
|
324
|
+
"Accept": "application/json",
|
|
325
|
+
"Content-Type": contentType,
|
|
326
|
+
"Api-Key": this.apiKey
|
|
327
|
+
},
|
|
328
|
+
body: body ? contentType !== "application/json" ? body : JSON.stringify(body) : void 0
|
|
329
|
+
});
|
|
330
|
+
if (response.status >= 400)
|
|
331
|
+
await handleResponseProblem(response);
|
|
332
|
+
const contentLength = Number(response.headers.get("Content-Length")) || 0;
|
|
333
|
+
return {
|
|
334
|
+
data: contentLength > 0 ? await response.json() : null,
|
|
335
|
+
headers: response.headers,
|
|
336
|
+
status: response.status
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
// src/products/endpoints.ts
|
|
342
|
+
var ProductEndpoints = class {
|
|
343
|
+
constructor(api) {
|
|
344
|
+
this.api = api;
|
|
345
|
+
}
|
|
346
|
+
async query(opts) {
|
|
347
|
+
const response = await this.api.fetch(`/api/products?${objectToQuery(opts)}`);
|
|
348
|
+
return paged(productSchema).parse(response.data);
|
|
349
|
+
}
|
|
350
|
+
async get(id) {
|
|
351
|
+
const response = await this.api.fetch(`/api/products/${id}`);
|
|
352
|
+
return productSchema.parse(response.data);
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
// src/trials/endpoints.ts
|
|
357
|
+
var TrialEndpoints = class {
|
|
358
|
+
constructor(api) {
|
|
359
|
+
this.api = api;
|
|
360
|
+
}
|
|
361
|
+
async request(productId, target) {
|
|
362
|
+
const response = await this.api.fetch(`/api/trials/${productId}/request`, "POST", target);
|
|
363
|
+
return trialSchema.parse(response.data);
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
// src/index.ts
|
|
368
|
+
var MoonbaseClient = class {
|
|
369
|
+
constructor(configuration) {
|
|
370
|
+
this.configuration = configuration;
|
|
371
|
+
this.configuration.endpoint = this.configuration.endpoint.replace(/\/$/, "");
|
|
372
|
+
const api = new MoonbaseApi(this.configuration.endpoint, this.configuration.apiKey);
|
|
373
|
+
this.activationRequests = new ActivationRequestEndpoints(api);
|
|
374
|
+
this.customers = new CustomerEndpoints(api);
|
|
375
|
+
this.licenses = new LicenseEndpoints(api);
|
|
376
|
+
this.products = new ProductEndpoints(api);
|
|
377
|
+
this.trials = new TrialEndpoints(api);
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
381
|
+
0 && (module.exports = {
|
|
382
|
+
ActivationMethod,
|
|
383
|
+
ActivationRequestStatus,
|
|
384
|
+
ActivationStatus,
|
|
385
|
+
LicenseStatus,
|
|
386
|
+
MoonbaseClient,
|
|
387
|
+
MoonbaseError,
|
|
388
|
+
NotAuthenticatedError,
|
|
389
|
+
NotAuthorizedError,
|
|
390
|
+
NotFoundError,
|
|
391
|
+
ProductStatus,
|
|
392
|
+
TrialStatus
|
|
393
|
+
});
|