UNPKG

firebase-auth-cloudflare-workers

Version:

Zero-dependencies firebase auth library for Cloudflare Workers.

79 lines (78 loc) 3.46 kB
"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 __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AdminAuthApiClient = exports.WorkersKVStoreSingle = exports.Auth = exports.useEmulator = exports.emulatorHost = exports.ServiceAccountCredential = void 0; const auth_1 = require("./auth"); const auth_api_requests_1 = require("./auth-api-requests"); const key_store_1 = require("./key-store"); var credential_1 = require("./credential"); Object.defineProperty(exports, "ServiceAccountCredential", { enumerable: true, get: function () { return credential_1.ServiceAccountCredential; } }); var emulator_1 = require("./emulator"); Object.defineProperty(exports, "emulatorHost", { enumerable: true, get: function () { return emulator_1.emulatorHost; } }); Object.defineProperty(exports, "useEmulator", { enumerable: true, get: function () { return emulator_1.useEmulator; } }); __exportStar(require("./errors"), exports); class Auth extends auth_1.BaseAuth { static instance; static withCredential; constructor(projectId, keyStore, credential) { super(projectId, keyStore, credential); } static getOrInitialize(projectId, keyStore, credential) { if (!Auth.withCredential && credential !== undefined) { Auth.withCredential = new Auth(projectId, keyStore, credential); } if (Auth.withCredential) { return Auth.withCredential; } if (!Auth.instance) { Auth.instance = new Auth(projectId, keyStore); } return Auth.instance; } } exports.Auth = Auth; class WorkersKVStoreSingle extends key_store_1.WorkersKVStore { static instance; constructor(cacheKey, cfKVNamespace) { super(cacheKey, cfKVNamespace); } static getOrInitialize(cacheKey, cfKVNamespace) { if (!WorkersKVStoreSingle.instance) { WorkersKVStoreSingle.instance = new Map(); } const instance = WorkersKVStoreSingle.instance.get(cacheKey); if (instance) { return instance; } const newInstance = new WorkersKVStoreSingle(cacheKey, cfKVNamespace); WorkersKVStoreSingle.instance.set(cacheKey, newInstance); return newInstance; } } exports.WorkersKVStoreSingle = WorkersKVStoreSingle; class AdminAuthApiClient extends auth_api_requests_1.AuthApiClient { static instance; constructor(projectId, credential, retryConfig) { super(projectId, credential, retryConfig); } static getOrInitialize(projectId, credential, retryConfig) { if (!AdminAuthApiClient.instance) { AdminAuthApiClient.instance = new AdminAuthApiClient(projectId, credential, retryConfig); } return AdminAuthApiClient.instance; } } exports.AdminAuthApiClient = AdminAuthApiClient;