"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; 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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { apiDefinition: () => apiDefinition, configApi: () => configApi, error: () => error, error404: () => error404, getMysqlFormattedDateTime: () => getMysqlFormattedDateTime, noContentResult: () => noContentResult, productConfiguration: () => productConfiguration, publisherConfiguration: () => publisherConfiguration, reservation: () => reservation, seat: () => seat, seatingConfiguration: () => seatingConfiguration, seats: () => seats, seatsApi: () => seatsApi, sqlDateRegex: () => sqlDateRegex, sqlDateString: () => sqlDateString, subscription: () => subscription, subscriptionApi: () => subscriptionApi, subscriptionPatch: () => subscriptionPatch, subscriptionStates: () => subscriptionStates, user: () => user, validateSeatRequest: () => validateSeatRequest, validateSeatReservation: () => validateSeatReservation, validateSubscriptionPatch: () => validateSubscriptionPatch }); module.exports = __toCommonJS(src_exports); // src/common/config.ts var import_core = require("@zodios/core"); var import_zod2 = require("zod"); // src/common/shared.ts var import_zod = require("zod"); var import_date_fns = require("date-fns"); var error404 = import_zod.z.object({ code: import_zod.z.number(), message: import_zod.z.string(), id: import_zod.z.number().or(import_zod.z.string()) }); var error = import_zod.z.object({ code: import_zod.z.number(), message: import_zod.z.string() }); var sqlDateRegex = /([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]) (0[0-9]|1[0-9]|2[0-4]):(0[0-9]|[1-5][0-9]):(0[0-9]|[1-5][0-9]))/; var sqlDateString = import_zod.z.string().regex(sqlDateRegex); var getMysqlFormattedDateTime = (date = new Date()) => { return (0, import_date_fns.format)(date, "yyyy-MM-dd HH:mm:ss"); }; // src/common/config.ts var seatingConfiguration = import_zod2.z.object({ defaultLowSeatWarningLevelPercent: import_zod2.z.number().optional(), seating_strategy_name: import_zod2.z.enum(["monthly_active_user", "first_come_first_served"]).nullable(), low_seat_warning_level_pct: import_zod2.z.number().gt(0, { message: `if provided, seating configuration [low_seat_warning_level_pct] must be > 0 (0%) and < 1 (100%).` }).max(1, { message: `if provided, seating configuration [low_seat_warning_level_pct] must be > 0 (0%) and < 1 (100%).` }).nullish(), limited_overflow_seating_enabled: import_zod2.z.boolean().nullish(), seat_reservation_expiry_in_days: import_zod2.z.number().min(1).default(1).optional(), default_seat_expiry_in_days: import_zod2.z.number().min(1).default(1).optional() }); var productConfiguration = import_zod2.z.object({ on_access_denied_url: import_zod2.z.string().nullable(), on_access_granted_url: import_zod2.z.string(), on_no_seat_available_url: import_zod2.z.string().nullable(), on_subscription_not_ready_url: import_zod2.z.string().nullable(), on_subscription_canceled_url: import_zod2.z.string().nullable(), on_subscription_suspended_url: import_zod2.z.string().nullable(), on_subscription_not_found_url: import_zod2.z.string().nullable(), on_no_subscriptions_found_url: import_zod2.z.string().nullable() }); var publisherConfiguration = import_zod2.z.object({ id: import_zod2.z.string(), product_name: import_zod2.z.string(), publisher_name: import_zod2.z.string(), home_page_url: import_zod2.z.string().nullable(), contact_page_url: import_zod2.z.string().nullable(), privacy_notice_page_url: import_zod2.z.string().nullable(), contact_sales_email: import_zod2.z.string().nullable(), contact_sales_url: import_zod2.z.string().nullable(), contact_support_email: import_zod2.z.string().nullable(), contact_support_url: import_zod2.z.string().nullable(), mona_base_storage_url: import_zod2.z.string().nullable(), mona_subscription_state: import_zod2.z.string().nullable(), mona_subscription_is_being_configured: import_zod2.z.boolean(), is_setup_complete: import_zod2.z.boolean(), default_seating_config: seatingConfiguration, product_config: productConfiguration }); var configApi = (0, import_core.makeApi)([ { method: "get", alias: "publisherConfigurationById", path: "/publisher/:publisherId/configuration", parameters: [ { name: "publisherId", type: "Path", schema: import_zod2.z.string() } ], errors: [ { status: 404, schema: error404 }, { status: "default", schema: error } ], response: publisherConfiguration }, { method: "get", alias: "publisherConfigurations", path: "/publishers", errors: [ { status: "default", schema: error } ], response: import_zod2.z.array(publisherConfiguration) }, { method: "put", alias: "updatePublisherConfiguration", path: "/publisher/:publisherId/configuration", parameters: [ { name: "publisherConfiguration", schema: publisherConfiguration, type: "Body" }, { name: "publisherId", type: "Path", schema: import_zod2.z.string() } ], errors: [ { status: "default", schema: error } ], response: publisherConfiguration }, { method: "post", alias: "publisherConfiguration", path: "/publisher", parameters: [ { name: "publisherConfiguration", schema: publisherConfiguration, type: "Body" } ], errors: [ { status: "default", schema: error } ], response: publisherConfiguration } ]); // src/common/seats.ts var import_core2 = require("@zodios/core"); var import_zod4 = require("zod"); // src/common/users.ts var import_zod3 = __toESM(require("zod"), 1); var user = import_zod3.default.object({ user_id: import_zod3.default.string(), user_name: import_zod3.default.string().optional(), tenant_id: import_zod3.default.string(), email: import_zod3.default.string().optional() }); // src/common/seats.ts var noContentResult = import_zod4.z.object({}); var reservation = import_zod4.z.object({ identifier: import_zod4.z.union([ import_zod4.z.object({ user_id: import_zod4.z.string(), tenant_id: import_zod4.z.string() }), import_zod4.z.object({ email: import_zod4.z.string() }) ]), invite_url: import_zod4.z.string().nullish() }); var validateSeatReservation = (reservation2, inSubscription) => { if ("email" in reservation2.identifier && !reservation2.identifier.email || "tenant_id" in reservation2.identifier && (!reservation2.identifier.tenant_id || !reservation2.identifier.user_id)) { return "Reservation ([user_id] and [tenant_id]) or [email] is required."; } if (inSubscription.state != "active") return `Subscription [${inSubscription.subscription_id}] is currently [${inSubscription.state}]; seats can be reserved only in ['active'] subscriptions.`; return void 0; }; var validateSeatRequest = (inSubscription) => { if (inSubscription.state != "active") return `Subscription [${inSubscription.subscription_id}] is currently [${inSubscription.state}]; seats can be reserved only in ['active'] subscriptions.`; return void 0; }; var seat = import_zod4.z.object({ seat_id: import_zod4.z.string(), subscription_id: import_zod4.z.string().nullable(), occupant: user.nullable(), seating_strategy_name: import_zod4.z.string().nullable(), seat_type: import_zod4.z.enum(["standard", "limited"]), reservation: reservation.nullable(), expires_utc: sqlDateString.nullable(), created_utc: sqlDateString.nullable(), redeemed_utc: sqlDateString.nullable() }); var seats = import_zod4.z.array(seat); var seatsApi = (0, import_core2.makeApi)([ { method: "get", alias: "seatById", path: "/subscriptions/:subscriptionId/seats/:seatId", response: seat, parameters: [ { name: "subscriptionId", type: "Path", schema: import_zod4.z.string() }, { name: "seatId", type: "Path", schema: import_zod4.z.string() } ], errors: [ { status: 404, schema: error404 }, { status: "default", schema: error } ] }, { method: "get", alias: "seats", path: "/subscriptions/:subscriptionId/seats", parameters: [ { name: "subscriptionId", type: "Path", schema: import_zod4.z.string() }, { name: "userId", type: "Query", schema: import_zod4.z.string().optional() }, { name: "userEmail", type: "Query", schema: import_zod4.z.string().optional() } ], response: seats, errors: [ { status: 404, schema: import_zod4.z.object({ code: import_zod4.z.number(), message: import_zod4.z.string(), id: import_zod4.z.number().or(import_zod4.z.string()) }) }, { status: "default", schema: import_zod4.z.object({ code: import_zod4.z.number(), message: import_zod4.z.string() }) } ] }, { alias: "userSeat", method: "get", path: "/subscriptions/:subscriptionId/user-seat/:tenantId/:userId", parameters: [ { name: "subscriptionId", type: "Path", schema: import_zod4.z.string() }, { name: "userId", type: "Path", schema: import_zod4.z.string() }, { name: "tenantId", type: "Path", schema: import_zod4.z.string() } ], errors: [ { status: 404, schema: import_zod4.z.object({ code: import_zod4.z.number(), message: import_zod4.z.string(), id: import_zod4.z.number().or(import_zod4.z.string()) }) }, { status: "default", schema: import_zod4.z.object({ code: import_zod4.z.number(), message: import_zod4.z.string() }) } ], response: seat }, { alias: "userOccupant", method: "patch", path: "/subscriptions/:subscriptionId/seats/:seatId", parameters: [ { name: "user", type: "Body", schema: user }, { name: "subscriptionId", type: "Path", schema: import_zod4.z.string() }, { name: "seatId", type: "Path", schema: import_zod4.z.string() } ], errors: [ { status: 404, schema: import_zod4.z.object({ code: import_zod4.z.number(), message: import_zod4.z.string(), id: import_zod4.z.number().or(import_zod4.z.string()) }) }, { status: "default", schema: import_zod4.z.object({ code: import_zod4.z.number(), message: import_zod4.z.string() }) } ], response: seat }, { alias: "redeemSeat", method: "post", path: "/subscriptions/:subscriptionId/seats/:seatId/redeem", parameters: [ { name: "user", type: "Body", schema: user }, { name: "subscriptionId", type: "Path", schema: import_zod4.z.string() }, { name: "seatId", type: "Path", schema: import_zod4.z.string() } ], errors: [ { status: 404, schema: import_zod4.z.object({ code: import_zod4.z.number(), message: import_zod4.z.string(), id: import_zod4.z.number().or(import_zod4.z.string()) }) }, { status: "default", schema: import_zod4.z.object({ code: import_zod4.z.number(), message: import_zod4.z.string() }) } ], response: seat }, { alias: "releaseSeat", method: "delete", path: "/subscriptions/:subscriptionId/seats/:seatId", parameters: [ { name: "subscriptionId", type: "Path", schema: import_zod4.z.string() }, { name: "seatId", type: "Path", schema: import_zod4.z.string() } ], errors: [ { status: "default", schema: import_zod4.z.object({ code: import_zod4.z.number(), message: import_zod4.z.string() }) } ], response: noContentResult }, { alias: "requestSeat", method: "post", path: "/subscriptions/:subscriptionId/seats/:seatId/request", parameters: [ { name: "user", type: "Body", schema: user }, { name: "subscriptionId", type: "Path", schema: import_zod4.z.string() }, { name: "seatId", type: "Path", schema: import_zod4.z.string() } ], errors: [ { status: 404, schema: import_zod4.z.object({ code: import_zod4.z.number(), message: import_zod4.z.string(), id: import_zod4.z.number().or(import_zod4.z.string()) }) }, { status: "default", schema: import_zod4.z.object({ code: import_zod4.z.number(), message: import_zod4.z.string() }) } ], response: seat }, { alias: "reserveSeat", method: "post", path: "/subscriptions/:subscriptionId/seats/:seatId/reserve", parameters: [ { name: "reservation", type: "Body", schema: reservation }, { name: "subscriptionId", type: "Path", schema: import_zod4.z.string() }, { name: "seatId", type: "Path", schema: import_zod4.z.string() } ], errors: [ { status: 404, schema: import_zod4.z.object({ code: import_zod4.z.number(), message: import_zod4.z.string(), id: import_zod4.z.number().or(import_zod4.z.string()) }) }, { status: "default", schema: import_zod4.z.object({ code: import_zod4.z.number(), message: import_zod4.z.string() }) } ], response: seat } ]); // src/common/subscriptions.ts var import_core3 = require("@zodios/core"); var import_zod5 = require("zod"); var subscriptionStates = import_zod5.z.enum([ "purchased", "active", "suspended", "canceled" ]); var subscription = import_zod5.z.object({ subscription_id: import_zod5.z.string(), subscription_name: import_zod5.z.string().optional(), tenant_id: import_zod5.z.string(), tenant_name: import_zod5.z.string().optional(), offer_id: import_zod5.z.string(), plan_id: import_zod5.z.string(), state: subscriptionStates, admin_role_name: import_zod5.z.string().optional(), user_role_name: import_zod5.z.string().optional(), management_urls: import_zod5.z.record(import_zod5.z.string()).optional(), admin_name: import_zod5.z.string().optional(), admin_email: import_zod5.z.string().optional(), total_seats: import_zod5.z.number().optional(), is_being_configured: import_zod5.z.boolean().optional(), is_free_trial: import_zod5.z.boolean(), is_setup_complete: import_zod5.z.boolean().optional(), is_test_subscription: import_zod5.z.boolean(), created_utc: sqlDateString.optional(), state_last_updated_utc: sqlDateString.optional(), seating_config: seatingConfiguration.optional(), subscriber_info: import_zod5.z.record(import_zod5.z.string()).optional(), source_subscription: import_zod5.z.record(import_zod5.z.string()).optional() }); var subscriptionPatch = subscription.pick({ subscription_id: true }).and( subscription.omit({ offer_id: true, tenant_id: true }).partial() ); var validateSubscriptionPatch = (sub, patch) => { if (!patch.subscription_name && !patch.plan_id && !patch.state && !patch.admin_role_name && !patch.user_role_name && !patch.admin_name && !patch.admin_email && !patch.management_urls && !patch.total_seats && patch.is_being_configured === void 0 && patch.is_setup_complete === void 0 && !patch.seating_config && !patch.subscriber_info && !patch.tenant_name && !patch.source_subscription) { return `No subscription properties have been patched; patchable subscription properties are [subscription_name], [plan_id], [state] (must be ${subscriptionStates.Values}), [tenant_name], [admin_role_name], [user_role_name], [management_urls], [total_seats] (if [total_seats] has already been set), [is_being_configured], [is_setup_complete], [seating_config], [subscriber_info], [source_subscription], [admin_name], and [admin_email].`; } else { if (patch.total_seats != null) { if (sub.total_seats == null) { return "[total_seats] can be patched only on subscriptions that already have [total_seats] configured."; } else if (patch.total_seats <= sub.total_seats) { return `Patched [total_seats] (${patch.total_seats}) must be > existing total seats (${sub.total_seats}).`; } } } return void 0; }; var subscriptionApi = (0, import_core3.makeApi)([ { method: "get", alias: "subscriptionById", path: "/subscriptions/:subscriptionId", parameters: [ { name: "subscriptionId", type: "Path", schema: import_zod5.z.string() } ], errors: [ { status: 404, schema: error404 }, { status: "default", schema: error } ], response: subscription }, { method: "get", alias: "subscriptions", path: "/subscriptions", parameters: [ { name: "publisherId", type: "Query", schema: import_zod5.z.string() } ], errors: [ { status: "default", schema: error } ], response: import_zod5.z.array(subscription) }, { method: "patch", alias: "updateSubscription", path: "/subscriptions/:subscriptionId", parameters: [ { name: "subscription", schema: subscriptionPatch, type: "Body" }, { name: "subscriptionId", type: "Path", schema: import_zod5.z.string() } ], errors: [ { status: "default", schema: error }, { status: 404, schema: error404 } ], response: subscription }, { method: "post", alias: "createSubscription", path: "/subscriptions/:publisherId/:subscriptionId", parameters: [ { name: "subscription", schema: subscription, type: "Body" }, { name: "publisherId", type: "Path", schema: import_zod5.z.string() }, { name: "subscriptionId", type: "Path", schema: import_zod5.z.string() } ], errors: [ { status: "default", schema: error } ], response: subscription } ]); // src/common/api.ts var import_openapi = require("@zodios/openapi"); var import_openapi_merge = require("openapi-merge"); var configOAS = (0, import_openapi.toOpenApi)(configApi, { info: { title: "Bouncer API", version: "1.0.0", description: "SaaS seat management API" }, servers: [ { url: "/api/v1" } ] }); var seatsOAS = (0, import_openapi.toOpenApi)(seatsApi, { info: { title: "Bouncer API", version: "1.0.0", description: "SaaS seat management API" }, servers: [ { url: "/api/v1" } ] }); var subscriptionsOAS = (0, import_openapi.toOpenApi)(subscriptionApi, { info: { title: "Bouncer API", version: "1.0.0", description: "SaaS seat management API" }, servers: [ { url: "/api/v1" } ] }); var mergedApi = (0, import_openapi_merge.merge)([ { oas: configOAS }, { oas: seatsOAS }, { oas: subscriptionsOAS } ]); if ((0, import_openapi_merge.isErrorResult)(mergedApi)) { throw new Error("cannot compile API definition"); } var apiDefinition = mergedApi.output; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { apiDefinition, configApi, error, error404, getMysqlFormattedDateTime, noContentResult, productConfiguration, publisherConfiguration, reservation, seat, seatingConfiguration, seats, seatsApi, sqlDateRegex, sqlDateString, subscription, subscriptionApi, subscriptionPatch, subscriptionStates, user, validateSeatRequest, validateSeatReservation, validateSubscriptionPatch });