From d5f304fc69966dfd0f821dc070f43beec89e5b31 Mon Sep 17 00:00:00 2001 From: David Walsh <5778036+rhinodavid@users.noreply.github.com> Date: Fri, 7 Apr 2023 18:58:07 -0600 Subject: [PATCH] [swap] Parse zippo headers --- apps-node/api/src/handlers/swap_handlers.ts | 24 +++++++++++++++------ apps-node/api/src/utils/parse_utils.ts | 12 ----------- apps-node/api/test/parse_utils_test.ts | 3 --- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/apps-node/api/src/handlers/swap_handlers.ts b/apps-node/api/src/handlers/swap_handlers.ts index 38476cda9b..fd7b975dc6 100644 --- a/apps-node/api/src/handlers/swap_handlers.ts +++ b/apps-node/api/src/handlers/swap_handlers.ts @@ -361,11 +361,24 @@ const parseSwapQuoteRequestParams = (req: express.Request, endpoint: 'price' | ' // HACK typescript typing does not allow this valid json-schema // eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO: fix me! schemaUtils.validateSchema(req.query, schemas.swapQuoteRequestSchema as any); - const apiKey: string | undefined = req.header('0x-api-key'); const origin: string | undefined = req.header('origin'); + + // With zippo and the developer dashboard, we'll get: + // - 0x-App-Id (instead of an integrator id) + // - 0x-Affiliate-Address + // For now, we'll use the app id in place of the integrator id, as long as the + // app ID exists. + // Also, we'll prefer the zippo affiliate address over any passed in the header. let integratorId: string | undefined; - if (apiKey) { - integratorId = getIntegratorIdForApiKey(apiKey); + const zippoAppId = req.header('0x-App-Id'); + const zippoAffiliateAddress = req.header('0x-Affiliate-Address'); + if (zippoAppId) { + integratorId = zippoAppId; + } else { + const apiKey: string | undefined = req.header('0x-api-key'); + if (apiKey) { + integratorId = getIntegratorIdForApiKey(apiKey); + } } // Parse string params @@ -475,7 +488,6 @@ const parseSwapQuoteRequestParams = (req: express.Request, endpoint: 'price' | ' includedSources: req.query.includedSources as string | undefined, intentOnFilling: req.query.intentOnFilling as string | undefined, takerAddress: takerAddress as string, - apiKey, }, endpoint, ); @@ -492,7 +504,7 @@ const parseSwapQuoteRequestParams = (req: express.Request, endpoint: 'price' | ' } const rfqt: Pick | undefined = (() => { - if (apiKey) { + if (integratorId !== undefined) { if (endpoint === 'quote' && takerAddress) { return { intentOnFilling: req.query.intentOnFilling === 'true', @@ -528,7 +540,6 @@ const parseSwapQuoteRequestParams = (req: express.Request, endpoint: 'price' | ' apiKey: integratorId || 'N/A', integratorId: integratorId || 'N/A', integratorLabel: integrator?.label || 'N/A', - rawApiKey: apiKey || 'N/A', enableSlippageProtection, priceImpactProtectionPercentage, }); @@ -536,7 +547,6 @@ const parseSwapQuoteRequestParams = (req: express.Request, endpoint: 'price' | ' return { affiliateAddress: affiliateAddress as string, affiliateFee, - apiKey, buyAmount, buyToken, endpoint, diff --git a/apps-node/api/src/utils/parse_utils.ts b/apps-node/api/src/utils/parse_utils.ts index d33de1b3a9..d8e32b2a25 100644 --- a/apps-node/api/src/utils/parse_utils.ts +++ b/apps-node/api/src/utils/parse_utils.ts @@ -10,7 +10,6 @@ interface ParseRequestForExcludedSourcesParams { excludedSources?: string; includedSources?: string; intentOnFilling?: string; - apiKey?: string; } interface ParseRequestForExcludedSourcesResult { @@ -68,17 +67,6 @@ export const parseUtils = { ]); } - // We enforce a valid API key - we don't want to fail silently. - if (request.apiKey === undefined) { - throw new ValidationError([ - { - field: '0x-api-key', - code: ValidationErrorCodes.RequiredField, - reason: ValidationErrorReasons.InvalidApiKey, - }, - ]); - } - // If the user is requesting a firm quote, we want to make sure that `intentOnFilling` is set to "true". if (endpoint === 'quote' && request.intentOnFilling !== 'true') { throw new ValidationError([ diff --git a/apps-node/api/test/parse_utils_test.ts b/apps-node/api/test/parse_utils_test.ts index c9c1ad8bf6..1afbaa139f 100644 --- a/apps-node/api/test/parse_utils_test.ts +++ b/apps-node/api/test/parse_utils_test.ts @@ -46,7 +46,6 @@ describe(SUITE_NAME, () => { { includedSources: 'RFQT', takerAddress: NULL_ADDRESS, - apiKey: 'ipsum', }, 'price', ); @@ -60,7 +59,6 @@ describe(SUITE_NAME, () => { { includedSources: 'RFQT,Native', takerAddress: NULL_ADDRESS, - apiKey: 'ipsum', }, 'price', ); @@ -87,7 +85,6 @@ describe(SUITE_NAME, () => { { includedSources: 'RFQT', takerAddress: NULL_ADDRESS, - apiKey: 'ipsum', }, 'quote', );