"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.usage = exports.verifyDomainDns = exports.detachDomain = exports.attachDomain = exports.listAppDomains = exports.mintMailboxCredentials = exports.mintTurnCredentials = exports.updateApp = exports.deleteApp = exports.getApp = exports.createApp = exports.listApps = void 0;
const gate_js_1 = require("./gate.js");
const http = __importStar(require("./http.js"));
/** GET /p2p/apps — List your p2p apps. */
const listApps = (client) => http.get(client, '/p2p/apps');
exports.listApps = listApps;
/** POST /p2p/apps — Create a p2p app (the offline mailbox is off by default). */
const createApp = (client, body) => http.post(client, '/p2p/apps', { body });
exports.createApp = createApp;
/** GET /p2p/apps/{id} — P2P app detail. */
const getApp = (client, id) => http.get(client, '/p2p/apps/{id}', { params: { id } });
exports.getApp = getApp;
/** DELETE /p2p/apps/{id} — Delete a p2p app. */
const deleteApp = (client, id) => http.del(client, '/p2p/apps/{id}', { params: { id } });
exports.deleteApp = deleteApp;
/** PATCH /p2p/apps/{id} — Update app origins/settings/relay/mailbox. */
const updateApp = (client, id, body) => http.patch(client, '/p2p/apps/{id}', { params: { id }, body });
exports.updateApp = updateApp;
/** POST /p2p/apps/{id}/turn-credentials — Mint TURN credentials. */
const mintTurnCredentials = (client, id, body) => http.post(client, '/p2p/apps/{id}/turn-credentials', { params: { id }, body });
exports.mintTurnCredentials = mintTurnCredentials;
/**
* POST /p2p/apps/{id}/mailbox-credentials — Mint a short-lived bearer token
* for the app's offline mailbox (requires `mailbox_enabled`). The response's
* `credentials` carry the token and the endpoint to send it to; see
* `mailbox`.
*/
const mintMailboxCredentials = (client, id, body) => http.post(client, '/p2p/apps/{id}/mailbox-credentials', { params: { id }, body });
exports.mintMailboxCredentials = mintMailboxCredentials;
/** GET /p2p/apps/{id}/domains — List an app's custom domains. */
const listAppDomains = (client, id) => http.get(client, '/p2p/apps/{id}/domains', { params: { id } });
exports.listAppDomains = listAppDomains;
/** POST /p2p/apps/{id}/domains — Attach a custom domain. Gated on `hostname`. */
const attachDomain = async (client, id, body) => {
await (0, gate_js_1.checkGate)(client, 'POST /p2p/apps/{id}/domains', { domain: body.hostname });
return http.post(client, '/p2p/apps/{id}/domains', { params: { id }, body });
};
exports.attachDomain = attachDomain;
/**
* DELETE /p2p/apps/{id}/domains/{domain-id} — Detach a custom domain. Gated
* on the domain's hostname (resolved via `listAppDomains` when a gate is set).
*/
const detachDomain = async (client, id, domainId) => {
if (client.gate) {
const { domains } = await (0, exports.listAppDomains)(client, id);
const hostname = domains?.find((d) => String(d.id) === domainId)?.hostname;
await (0, gate_js_1.checkGate)(client, 'DELETE /p2p/apps/{id}/domains/{domain-id}', { domain: hostname });
}
return http.del(client, '/p2p/apps/{id}/domains/{domain-id}', { params: { id, 'domain-id': domainId } });
};
exports.detachDomain = detachDomain;
/** POST /p2p/apps/{id}/domains/{domain-id}/verify-dns — Re-check a domain's DNS. */
const verifyDomainDns = (client, id, domainId) => http.post(client, '/p2p/apps/{id}/domains/{domain-id}/verify-dns', { params: { id, 'domain-id': domainId } });
exports.verifyDomainDns = verifyDomainDns;
/** GET /p2p/usage — P2P usage and cost. */
const usage = (client) => http.get(client, '/p2p/usage');
exports.usage = usage;