UNPKG

@clerk/nextjs

Version:

Clerk SDK for NextJS

1 lines 3.36 kB
{"version":3,"sources":["../../../src/server/keyless-log-cache.ts"],"sourcesContent":["import type { AccountlessApplication } from '@clerk/backend';\nimport { isDevelopmentEnvironment } from '@clerk/shared/utils';\n// 10 minutes in milliseconds\nconst THROTTLE_DURATION_MS = 10 * 60 * 1000;\n\nfunction createClerkDevCache() {\n if (!isDevelopmentEnvironment()) {\n return;\n }\n\n if (!global.__clerk_internal_keyless_logger) {\n global.__clerk_internal_keyless_logger = {\n __cache: new Map<string, { expiresAt: number; data?: unknown }>(),\n\n log: function ({ cacheKey, msg }) {\n if (this.__cache.has(cacheKey) && Date.now() < (this.__cache.get(cacheKey)?.expiresAt || 0)) {\n return;\n }\n\n console.log(msg);\n\n this.__cache.set(cacheKey, {\n expiresAt: Date.now() + THROTTLE_DURATION_MS,\n });\n },\n run: async function (\n callback,\n { cacheKey, onSuccessStale = THROTTLE_DURATION_MS, onErrorStale = THROTTLE_DURATION_MS },\n ) {\n if (this.__cache.has(cacheKey) && Date.now() < (this.__cache.get(cacheKey)?.expiresAt || 0)) {\n return this.__cache.get(cacheKey)?.data;\n }\n\n try {\n const result = await callback();\n\n this.__cache.set(cacheKey, {\n expiresAt: Date.now() + onSuccessStale,\n data: result,\n });\n return result;\n } catch (e) {\n this.__cache.set(cacheKey, {\n expiresAt: Date.now() + onErrorStale,\n });\n\n throw e;\n }\n },\n };\n }\n\n return globalThis.__clerk_internal_keyless_logger;\n}\n\nexport const createKeylessModeMessage = (keys: AccountlessApplication) => {\n return `\\n\\x1b[35m\\n[Clerk]:\\x1b[0m You are running in keyless mode.\\nYou can \\x1b[35mclaim your keys\\x1b[0m by visiting ${keys.claimUrl}\\n`;\n};\n\nexport const createConfirmationMessage = () => {\n return `\\n\\x1b[35m\\n[Clerk]:\\x1b[0m Your application is running with your claimed keys.\\nYou can safely remove the \\x1b[35m.clerk/\\x1b[0m from your project.\\n`;\n};\n\nexport const clerkDevelopmentCache = createCl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