UNPKG

signicat-client-ts

Version:

Community TypeScript client for Signicat Authentication REST API with automatic token management

69 lines (68 loc) 3.66 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SignicatClient = void 0; const AxiosHttpRequest_1 = require("./core/AxiosHttpRequest"); const AuthenticationSessionService_1 = require("./services/AuthenticationSessionService"); const OpenAPI_1 = require("./core/OpenAPI"); const EncryptionService_1 = require("./services/EncryptionService"); class SignicatClient { constructor(config, HttpRequest = AxiosHttpRequest_1.AxiosHttpRequest) { var _a, _b, _c, _d; this.request = new HttpRequest({ BASE: (_a = config === null || config === void 0 ? void 0 : config.BASE) !== null && _a !== void 0 ? _a : "https://api.signicat.com/auth/rest", VERSION: (_b = config === null || config === void 0 ? void 0 : config.VERSION) !== null && _b !== void 0 ? _b : "1", WITH_CREDENTIALS: (_c = config === null || config === void 0 ? void 0 : config.WITH_CREDENTIALS) !== null && _c !== void 0 ? _c : false, CREDENTIALS: (_d = config === null || config === void 0 ? void 0 : config.CREDENTIALS) !== null && _d !== void 0 ? _d : "include", TOKEN: config === null || config === void 0 ? void 0 : config.TOKEN, USERNAME: config === null || config === void 0 ? void 0 : config.USERNAME, PASSWORD: config === null || config === void 0 ? void 0 : config.PASSWORD, HEADERS: config === null || config === void 0 ? void 0 : config.HEADERS, ENCODE_PATH: config === null || config === void 0 ? void 0 : config.ENCODE_PATH, }); this.authenticationSession = new AuthenticationSessionService_1.AuthenticationSessionService(this.request); } /** * Configure the client to automatically manage tokens. * Call this method to enable automatic token management. * * @param authConfig - The authentication configuration to use. */ static configureAuth(authConfig) { (0, OpenAPI_1.configureSignicatAuth)(authConfig); } /** * Enable encryption for this client instance * @param privateKey The private key in JWK format for decrypting responses */ enableEncryption(privateKey) { this.authenticationSession.setEncryptionPrivateKey(privateKey); } /** * Generate RSA key pair for encryption * @param keySize Key size in bits (2048 or 4096) * @returns Promise containing public and private keys */ static generateEncryptionKeyPair() { return __awaiter(this, arguments, void 0, function* (keySize = 2048) { return EncryptionService_1.EncryptionService.generateRSAKeyPair(keySize); }); } /** * Validate encryption key format * @param key The encryption key to validate * @returns True if the key is valid */ static validateEncryptionKey(key) { return EncryptionService_1.EncryptionService.validateEncryptionKey(key); } } exports.SignicatClient = SignicatClient;