/** * Fireblocks API * Fireblocks provides a suite of applications to manage digital asset operations and a complete development platform to build your business on the blockchain. - Visit our website for more information: [Fireblocks Website](https://fireblocks.com) - Visit our developer docs: [Fireblocks DevPortal](https://developers.fireblocks.com) * * The version of the OpenAPI document: 1.6.2 * Contact: developers@fireblocks.com * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ /** Set (e.g. to 1) to suppress lifecycle warnings entirely; 0 and false do not suppress. */ export const SUPPRESS_ENV_VAR = 'FIREBLOCKS_SDK_SUPPRESS_LIFECYCLE_WARNING'; export const LIFECYCLE_STATE_HEADER = 'fireblocks-lifecycle-state'; export const SUNSET_HEADER = 'sunset'; export const LINK_HEADER = 'link'; /** Key under which the param creator stamps the operation onto the request config. */ export const OPERATION_ID_CONFIG_KEY = 'fireblocksOperationId'; export const EA_STATE = 'ea'; /** @deprecated Use EA_STATE. The beta lifecycle state was renamed to ea and no longer warns. */ export const BETA_STATE = 'beta'; export const DEPRECATED_STATE = 'deprecated'; export const CLOSED_STATE = 'closed'; export const WARNING_STATES: ReadonlySet = new Set([EA_STATE, DEPRECATED_STATE, CLOSED_STATE]); // The gateway answers a closed operation with 410 Gone to every caller without a // temporary exception. That response already says what happened, so no warning. export const GONE_STATUS = 410; export const REL_DEPRECATION = 'deprecation'; export const REL_SUCCESSOR_VERSION = 'successor-version'; // RFC 8288. Anchored on the angle brackets rather than split on commas, because a // comma is legal inside a URI and axios joins repeated headers with ", ". // `rel` may follow other parameters (`; type="text/html"; rel="deprecation"`), // which [^<]*? allows without running into the next link, and its value may list // several space-separated relation types. const LINK_PATTERN = /<([^>]*)>[^<]*?;\s*rel\s*=\s*(?:"([^"]*)"|([^\s;,]+))/gi; function getHeader(headers: unknown, name: string): string | undefined { if (!headers || typeof headers !== 'object') { return undefined; } const lowered = name.toLowerCase(); for (const [key, value] of Object.entries(headers as Record)) { if (key.toLowerCase() !== lowered) { continue; } if (typeof value === 'string') { return value; } if (Array.isArray(value)) { return value.filter((entry) => typeof entry === 'string').join(', '); } if (value !== null && value !== undefined) { return String(value); } } return undefined; } /** Map link relation -> URL, first occurrence wins. */ function parseLinks(headers: unknown): Record { const raw = getHeader(headers, LINK_HEADER); const links: Record = {}; if (!raw) { return links; } LINK_PATTERN.lastIndex = 0; let match: RegExpExecArray | null = LINK_PATTERN.exec(raw); while (match !== null) { const url = match[1].trim(); for (const relation of (match[2] ?? match[3]).toLowerCase().split(/\s+/)) { if (relation && !(relation in links)) { links[relation] = url; } } match = LINK_PATTERN.exec(raw); } return links; } /** * Build the warning for a response, or undefined when nothing should be logged. * Silent on: absent or empty header, an unrecognised state, `ga`, and a `closed` * operation answered with 410 Gone. An unknown status counts as "not 410". * * Header values are emitted as received. They are gateway-authored - the gateway * strips any downstream-supplied lifecycle headers and reapplies its own, derived * from the deployed specification, which is validated by the OpenAPI lint rules. */ export function buildLifecycleWarning( headers: unknown, operationId: string, status?: number, ): string | undefined { const rawState = getHeader(headers, LIFECYCLE_STATE_HEADER); if (!rawState) { return undefined; } const state = rawState.trim().toLowerCase(); if (!WARNING_STATES.has(state)) { return undefined; } if (state === EA_STATE) { return `Operation '${operationId}' is in EA (Early Availability) and is not generally available.` + ' It may change or break before it reaches GA.'; } if (state === CLOSED_STATE) { if (status === GONE_STATUS) { return undefined; } return `Operation '${operationId}' has been closed and is no longer supported.` + ' Your access is provided under a temporary exception and may be revoked.' + ' Contact your Customer Success Manager for migration support'; } const sunset = getHeader(headers, SUNSET_HEADER)?.trim(); let message = sunset ? `Operation '${operationId}' is deprecated and will stop working after ${sunset}.` : `Operation '${operationId}' is deprecated.`; const links = parseLinks(headers); const successor = links[REL_SUCCESSOR_VERSION]; if (successor) { message += ` Use ${successor} instead.`; } const migrationGuide = links[REL_DEPRECATION]; if (migrationGuide) { message += ` Migration guide: ${migrationGuide}`; } return message; } /** True when the suppression env var is set to anything other than 0 or false. */ export function isSuppressed(value: string | undefined): boolean { return !!value && value !== '0' && value !== 'false'; } /** * Emit one warning per execution when the response reports a non-GA state. * * Suppressed when FIREBLOCKS_SDK_SUPPRESS_LIFECYCLE_WARNING is set to anything * other than 0 or false. * * Never throws: a malformed header must not break a caller's request. */ export function warnOnLifecycleState( headers: unknown, operationId: string | undefined, status?: number, ): void { if (!operationId || isSuppressed(process.env[SUPPRESS_ENV_VAR])) { return; } try { const message = buildLifecycleWarning(headers, operationId, status); if (message) { console.warn(message); } } catch { // Defensive: never break the request because of a warning. } } /** Read the operation stamped onto the request config by the param creator. */ export function operationIdFromConfig(config: unknown): string | undefined { if (!config || typeof config !== 'object') { return undefined; } const value = (config as Record)[OPERATION_ID_CONFIG_KEY]; return typeof value === 'string' && value ? value : undefined; }