From 2eb18136502782bc532e80de075aea8e836ad382 Mon Sep 17 00:00:00 2001 From: ademarCardoso Date: Thu, 6 Jul 2023 16:30:42 -0300 Subject: [PATCH 1/4] docs(int-976): change sdk to client in the readme file to a be in the correct standard --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 73f12ce4..914bdb31 100755 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Storyblok Logo -

Universal JavaScript SDK for Storyblok's API

+

Universal JavaScript Client for Storyblok's API

This client is a thin wrapper for the Storyblok API's to use in Node.js and the browser.

From 753076a78f1ce5af8733b34c7a399266e22747cf Mon Sep 17 00:00:00 2001 From: ademarCardoso Date: Thu, 6 Jul 2023 16:32:08 -0300 Subject: [PATCH 2/4] feat(int-976): adding a new way to add `config.headers` in the client headers adding default header to the client to be able to track requests in our infrastructure --- src/constants.ts | 8 ++++++++ src/index.ts | 12 ++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 36f41338..0862029d 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -9,3 +9,11 @@ type ObjectValues = T[keyof T] type Method = ObjectValues export default Method + +export const STORYBLOK_AGENT = 'SB_Agent' + +export const STORYBLOK_JS_CLIENT_AGENT = { + defaultAgentName: 'SB-JS-CLIENT', + defaultAgentVersion: 'SB-Agent-Version', + packageVersion: process.env.npm_package_version || '5.0.0' +} diff --git a/src/index.ts b/src/index.ts index 3babf6a0..372133f7 100755 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,7 @@ import throttledQueue from './throttlePromise' import RichTextResolver from './richTextResolver' import { SbHelpers } from './sbHelpers' import SbFetch from './sbFetch' +import { STORYBLOK_AGENT, STORYBLOK_JS_CLIENT_AGENT } from './constants' import Method from './constants' import { @@ -99,11 +100,14 @@ class Storyblok { headers.set('Content-Type', 'application/json') headers.set('Accept', 'application/json') - headers.forEach((value, key) => { - if (config.headers && config.headers[key]) { - headers.set(key, config.headers[key]) + if (config.headers) { + for (const header in config.headers) { + headers.set(header, config.headers[header]) } - }) + } else if (!headers.has(STORYBLOK_AGENT)) { + headers.set(STORYBLOK_AGENT, STORYBLOK_JS_CLIENT_AGENT.defaultAgentName) + headers.set( STORYBLOK_JS_CLIENT_AGENT.defaultAgentVersion, STORYBLOK_JS_CLIENT_AGENT.packageVersion) + } let rateLimit = 5 // per second for cdn api From 3d2a948326d2bdafa9317f814c7a2906394a3daa Mon Sep 17 00:00:00 2001 From: ademarCardoso Date: Fri, 7 Jul 2023 09:22:34 -0300 Subject: [PATCH 3/4] feat(int-976): changing the default agent name to the correct one --- src/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants.ts b/src/constants.ts index 0862029d..70cb7a46 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -10,7 +10,7 @@ type Method = ObjectValues export default Method -export const STORYBLOK_AGENT = 'SB_Agent' +export const STORYBLOK_AGENT = 'SB-Agent' export const STORYBLOK_JS_CLIENT_AGENT = { defaultAgentName: 'SB-JS-CLIENT', From 61306c76804494abbef4e8d784c2ef714858692c Mon Sep 17 00:00:00 2001 From: ademarCardoso Date: Mon, 10 Jul 2023 18:09:00 -0300 Subject: [PATCH 4/4] feat(int-976): changing conditional to update headers --- src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 372133f7..9ece96fe 100755 --- a/src/index.ts +++ b/src/index.ts @@ -104,7 +104,9 @@ class Storyblok { for (const header in config.headers) { headers.set(header, config.headers[header]) } - } else if (!headers.has(STORYBLOK_AGENT)) { + } + + if (!headers.has(STORYBLOK_AGENT)) { headers.set(STORYBLOK_AGENT, STORYBLOK_JS_CLIENT_AGENT.defaultAgentName) headers.set( STORYBLOK_JS_CLIENT_AGENT.defaultAgentVersion, STORYBLOK_JS_CLIENT_AGENT.packageVersion) }