UNPKG

mya-cli

Version:

MYA - AI-Powered Stock & Options Analysis CLI Tool

33 lines 1.34 kB
import * as stytch from 'stytch'; /** * Creates a properly configured Stytch client for Cloudflare Workers environment * Handles the User-Agent issues that cause authentication failures in Workers */ export function createStytchClient(env) { // Validate required environment variables if (!env.STYTCH_PROJECT_ID || !env.STYTCH_SECRET) { throw new Error('Missing Stytch project ID or secret'); } // Create the base client (do NOT pass `env` property) const client = new stytch.Client({ project_id: env.STYTCH_PROJECT_ID, secret: env.STYTCH_SECRET, }); const clientWithRequest = client; const originalRequest = clientWithRequest.request; if (originalRequest) { clientWithRequest.request = async function (method, path, data, opts) { const options = { ...opts, headers: { ...(opts?.headers ?? {}), 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36', 'X-Stytch-Client': 'stytch-js/browser', }, }; return originalRequest.call(this, method, path, data, options); }; } return client; } //# sourceMappingURL=stytch-helper.js.map