UNPKG

@vulog/aima-promocode

Version:

```bash npm i @vulog/aima-client @vulog/aima-promocode ```

120 lines (114 loc) 4.11 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var index_exports = {}; __export(index_exports, { checkInvitationCode: () => checkInvitationCode, getPromoCodeById: () => getPromoCodeById, getPromoCodeByReference: () => getPromoCodeByReference, submitPromoCode: () => submitPromoCode, submitReferral: () => submitReferral }); module.exports = __toCommonJS(index_exports); // src/checkInvitationCode.ts var import_zod = require("zod"); var checkInvitationCode = async (client, referralCode) => { const result = import_zod.z.string().trim().min(1).safeParse(referralCode); if (!result.success) { throw new TypeError("Invalid referralCode", { cause: result.error.issues }); } return client.get(`boapi/proxy/user/fleets/${client.clientOptions.fleetId}/invitation/check/${referralCode}`).then(({ data }) => data).catch((error) => { if (error.formattedError?.status === 404) { return void 0; } throw error; }); }; // src/getPromoCode.ts var import_zod2 = require("zod"); var getPromoCodeByReference = async (client, reference) => { const result = import_zod2.z.string().trim().min(1).safeParse(reference); if (!result.success) { throw new TypeError("Invalid reference", { cause: result.error.issues }); } return client.get(`boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/promoCodes?reference=${reference}`).then(({ data: [r] }) => r); }; var getPromoCodeById = async (client, id) => { const result = import_zod2.z.number().positive().safeParse(id); if (!result.success) { throw new TypeError("Invalid id", { cause: result.error.issues }); } return client.get(`boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/promoCodes/${id}`).then(({ data }) => data).catch((error) => { if (error.formattedError?.status === 404) { return void 0; } throw error; }); }; // src/submitPromoCode.ts var import_zod3 = require("zod"); var schema = import_zod3.z.object({ userId: import_zod3.z.string().uuid(), entityId: import_zod3.z.string().uuid(), code: import_zod3.z.string().min(1) }); var submitPromoCode = async (client, userId, entityId, code) => { const result = schema.safeParse({ userId, entityId, code }); if (!result.success) { throw new TypeError("Invalid args", { cause: result.error.issues }); } return client.put(`boapi/proxy/user/billing/fleets/${client.clientOptions.fleetId}/promoCodes/redeem/${code}`, { userId, entityId }).then(({ data }) => data); }; // src/submitReferral.ts var import_zod4 = require("zod"); var schema2 = import_zod4.z.object({ userId: import_zod4.z.string().uuid(), entityId: import_zod4.z.string().uuid(), code: import_zod4.z.string().min(1) }); var submitReferral = async (client, userId, entityId, code) => { const result = schema2.safeParse({ userId, entityId, code }); if (!result.success) { throw new TypeError("Invalid args", { cause: result.error.issues }); } await client.post( `boapi/proxy/user/fleets/${client.clientOptions.fleetId}/invitation/users/${userId}/entity/${entityId}/redeem/${code}` ); }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { checkInvitationCode, getPromoCodeById, getPromoCodeByReference, submitPromoCode, submitReferral });