@bunnyapp/api-client
Version:
Node.js client for Bunny CRM
37 lines • 1.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = portalSessionCreate;
const query = `mutation portalSessionCreate ($tenantCode: String!, $expiry: Int!, $returnUrl: String!) {
portalSessionCreate (tenantCode: $tenantCode, expiry: $expiry, returnUrl: $returnUrl) {
errors
token
}
}`;
/**
* Generate a session token for customer portal
* @param {string} tenantCode The unique code that represents the tenant
* @param {string} returnUrl A URL to redirect the user back to the original app after using the portal
* @param {number} expiryInHours Length of time in hours before the token expires. Defaults to 24
* @returns {Promise<string>} The session token
*/
async function portalSessionCreate(tenantCode, returnUrl = '', expiryInHours = 24) {
var _a;
const variables = {
tenantCode,
returnUrl,
expiry: expiryInHours,
};
const res = await this.query(query, variables);
const portalSessionCreate = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.portalSessionCreate;
if (res === null || res === void 0 ? void 0 : res.errors) {
throw new Error(Array.isArray(res.errors) ? res.errors.map(e => e.message).join() : res.errors);
}
if (portalSessionCreate === null || portalSessionCreate === void 0 ? void 0 : portalSessionCreate.errors) {
throw new Error(Array.isArray(portalSessionCreate.errors) ? portalSessionCreate.errors.join() : portalSessionCreate.errors);
}
if (!(portalSessionCreate === null || portalSessionCreate === void 0 ? void 0 : portalSessionCreate.token)) {
throw new Error('No token returned from portal session creation');
}
return portalSessionCreate.token;
}
//# sourceMappingURL=portal-session-create.js.map