From 49512146980fac92085233bde3a7caffed41a41e Mon Sep 17 00:00:00 2001 From: Henry Barrow Date: Mon, 31 Jul 2023 14:00:35 +0100 Subject: [PATCH 01/12] Enable the option to send events in Vercel SDK --- packages/sdk/vercel/src/createPlatformInfo.ts | 2 ++ packages/sdk/vercel/src/index.ts | 16 ++++++++++------ .../shared/sdk-server-edge/src/api/LDClient.ts | 5 ++--- packages/shared/sdk-server-edge/src/index.ts | 7 ++++--- .../sdk-server-edge/src/utils/validateOptions.ts | 13 +++++++++++-- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/packages/sdk/vercel/src/createPlatformInfo.ts b/packages/sdk/vercel/src/createPlatformInfo.ts index cbd8874c5..88888ea68 100644 --- a/packages/sdk/vercel/src/createPlatformInfo.ts +++ b/packages/sdk/vercel/src/createPlatformInfo.ts @@ -11,6 +11,8 @@ class VercelPlatformInfo implements Info { return { name: '@launchdarkly/vercel-server-sdk', version: '__LD_VERSION__', + wrapperName: 'VercelEdgeSDK', + wrapperVersion: '__LD_VERSION__', }; } } diff --git a/packages/sdk/vercel/src/index.ts b/packages/sdk/vercel/src/index.ts index fafb432be..632daa2e1 100644 --- a/packages/sdk/vercel/src/index.ts +++ b/packages/sdk/vercel/src/index.ts @@ -36,17 +36,21 @@ export type { LDClient }; * (`new LDClient()/new LDClientImpl()/new LDClient()`); the SDK does not currently support * this. * - * @param sdkKey - * The client side SDK key. This is only used to query the edgeConfig above, + * @param clientSideID + * The client-side ID. This is only used to query the edgeConfig above, * not to connect with LaunchDarkly servers. * @param edgeConfig * The Vercel Edge Config client configured for LaunchDarkly. * @param options - * Optional configuration settings. The only supported option is logger. + * Optional configuration settings. * @return * The new {@link LDClient} instance. */ -export const init = (sdkKey: string, edgeConfig: EdgeConfigClient, options: LDOptions = {}) => { +export const init = ( + clientSideID: string, + edgeConfig: EdgeConfigClient, + options: LDOptions = {}, +) => { const logger = options.logger ?? BasicLogger.get(); // vercel does not support string gets so we have to stringify it @@ -57,8 +61,8 @@ export const init = (sdkKey: string, edgeConfig: EdgeConfigClient, options: LDOp }, }; - return initEdge(sdkKey, createPlatformInfo(), { - featureStore: new EdgeFeatureStore(edgeProvider, sdkKey, 'Vercel', logger), + return initEdge(clientSideID, createPlatformInfo(), { + featureStore: new EdgeFeatureStore(edgeProvider, clientSideID, 'Vercel', logger), logger, ...options, }); diff --git a/packages/shared/sdk-server-edge/src/api/LDClient.ts b/packages/shared/sdk-server-edge/src/api/LDClient.ts index d2b4e821b..21d8bec4b 100644 --- a/packages/shared/sdk-server-edge/src/api/LDClient.ts +++ b/packages/shared/sdk-server-edge/src/api/LDClient.ts @@ -12,11 +12,10 @@ import createOptions from './createOptions'; export class LDClient extends LDClientImpl { emitter: EventEmitter; - // sdkKey is only used to query featureStore, not to initialize with LD servers - constructor(sdkKey: string, platformInfo: Info, options: LDOptions) { + constructor(serverSideKey: string, platformInfo: Info, options: LDOptions) { const em = new EventEmitter(); const platform = new EdgePlatform(platformInfo); - super('n/a', platform, createOptions(options), createCallbacks(em)); + super(serverSideKey, platform, createOptions(options), createCallbacks(em)); this.emitter = em; } } diff --git a/packages/shared/sdk-server-edge/src/index.ts b/packages/shared/sdk-server-edge/src/index.ts index 60d9785e8..8427f5940 100644 --- a/packages/shared/sdk-server-edge/src/index.ts +++ b/packages/shared/sdk-server-edge/src/index.ts @@ -19,9 +19,10 @@ export type { LDClient, LDOptions, EdgeProvider }; * * This is an internal API to be used directly only by LaunchDarkly Edge SDKs. */ -export const init = (sdkKey: string, platformInfo: Info, options: LDOptionsInternal) => { +export const init = (clientSideID: string, platformInfo: Info, options: LDOptionsInternal) => { // this throws if options are invalid - validateOptions(sdkKey, options); + validateOptions(clientSideID, options); - return new LDClient(sdkKey, platformInfo, options); + const { serverSideKey, ...allOtherOptions } = options; + return new LDClient(serverSideKey || 'n/a', platformInfo, allOtherOptions); }; diff --git a/packages/shared/sdk-server-edge/src/utils/validateOptions.ts b/packages/shared/sdk-server-edge/src/utils/validateOptions.ts index c65fa083a..5413af95c 100644 --- a/packages/shared/sdk-server-edge/src/utils/validateOptions.ts +++ b/packages/shared/sdk-server-edge/src/utils/validateOptions.ts @@ -1,11 +1,16 @@ import { LDOptions as LDOptionsCommon } from '@launchdarkly/js-server-sdk-common'; +type EdgeOptions = { + // The LaunchDarkly server-side key. This option is required if sendEvents is enabled. + serverSideKey?: string; +}; + /** * The Launchdarkly Edge SDKs configuration options. Only logger is officially * supported. sendEvents is unsupported and is only included as a beta * preview. */ -export type LDOptions = Pick; +export type LDOptions = EdgeOptions & Pick; /** * The internal options include featureStore because that's how the LDClient @@ -14,7 +19,7 @@ export type LDOptions = Pick; export type LDOptionsInternal = LDOptions & Pick; const validateOptions = (sdkKey: string, options: LDOptionsInternal) => { - const { featureStore, logger, sendEvents, ...rest } = options; + const { featureStore, logger, sendEvents, serverSideKey, eventsUri, ...rest } = options; if (!sdkKey) { throw new Error('You must configure the client with a client key'); } @@ -27,6 +32,10 @@ const validateOptions = (sdkKey: string, options: LDOptionsInternal) => { throw new Error('You must configure the client with a logger'); } + if (sendEvents && !serverSideKey) { + throw new Error('You must provide the serverSideKey to enable events'); + } + if (JSON.stringify(rest) !== '{}') { throw new Error(`Invalid configuration: ${Object.keys(rest).toString()} not supported`); } From e294d878fdaec983ba9ed38201d6b6b737449364 Mon Sep 17 00:00:00 2001 From: Henry Barrow Date: Mon, 31 Jul 2023 14:25:12 +0100 Subject: [PATCH 02/12] Set alpha version --- .release-please-manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index b1b60e631..5b74a370c 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -4,7 +4,7 @@ "packages/sdk/server-node": "8.1.0", "packages/sdk/cloudflare": "2.0.7", "packages/shared/sdk-server-edge": "1.0.6", - "packages/sdk/vercel": "1.0.1", + "packages/sdk/vercel": "1.1.0-alpha.0", "packages/sdk/akamai-base": "1.0.0", "packages/sdk/akamai-edgekv": "1.0.0", "packages/shared/akamai-edgeworker-sdk": "0.2.5", From 15b91e2b3cea9353e3a084eaa2ba9ffc37349573 Mon Sep 17 00:00:00 2001 From: Henry Barrow Date: Mon, 31 Jul 2023 14:30:01 +0100 Subject: [PATCH 03/12] Bump sdk-server-edge version --- .release-please-manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 5b74a370c..fa6201835 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -3,7 +3,7 @@ "packages/shared/sdk-server": "1.0.6", "packages/sdk/server-node": "8.1.0", "packages/sdk/cloudflare": "2.0.7", - "packages/shared/sdk-server-edge": "1.0.6", + "packages/shared/sdk-server-edge": "1.1.0-alpha.0", "packages/sdk/vercel": "1.1.0-alpha.0", "packages/sdk/akamai-base": "1.0.0", "packages/sdk/akamai-edgekv": "1.0.0", From 1e13ede3ed88b67daaf4bba5119192a63413f4d1 Mon Sep 17 00:00:00 2001 From: Henry Barrow Date: Mon, 31 Jul 2023 14:38:56 +0100 Subject: [PATCH 04/12] Update versions in package.json --- .release-please-manifest.json | 4 ++-- packages/sdk/vercel/package.json | 2 +- packages/shared/sdk-server-edge/package.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index fa6201835..24c657b2e 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -3,8 +3,8 @@ "packages/shared/sdk-server": "1.0.6", "packages/sdk/server-node": "8.1.0", "packages/sdk/cloudflare": "2.0.7", - "packages/shared/sdk-server-edge": "1.1.0-alpha.0", - "packages/sdk/vercel": "1.1.0-alpha.0", + "packages/shared/sdk-server-edge": "1.0.6", + "packages/sdk/vercel": "1.0.2", "packages/sdk/akamai-base": "1.0.0", "packages/sdk/akamai-edgekv": "1.0.0", "packages/shared/akamai-edgeworker-sdk": "0.2.5", diff --git a/packages/sdk/vercel/package.json b/packages/sdk/vercel/package.json index e12812c0a..58ccf8f40 100644 --- a/packages/sdk/vercel/package.json +++ b/packages/sdk/vercel/package.json @@ -1,6 +1,6 @@ { "name": "@launchdarkly/vercel-server-sdk", - "version": "1.0.1", + "version": "1.1.0-alpha.0", "description": "LaunchDarkly Server-Side SDK for Vercel Edge", "homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/sdk/vercel", "repository": { diff --git a/packages/shared/sdk-server-edge/package.json b/packages/shared/sdk-server-edge/package.json index bfd02b667..7892fdbb1 100644 --- a/packages/shared/sdk-server-edge/package.json +++ b/packages/shared/sdk-server-edge/package.json @@ -1,6 +1,6 @@ { "name": "@launchdarkly/js-server-sdk-common-edge", - "version": "1.0.6", + "version": "1.1.0-alpha.0", "homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/shared/sdk-server-edge", "repository": { "type": "git", From 1b33895e16bcf796915197e1e50a11d908f456df Mon Sep 17 00:00:00 2001 From: Henry Barrow Date: Mon, 31 Jul 2023 14:48:46 +0100 Subject: [PATCH 05/12] Update dep version --- packages/sdk/vercel/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk/vercel/package.json b/packages/sdk/vercel/package.json index 58ccf8f40..7e156f3da 100644 --- a/packages/sdk/vercel/package.json +++ b/packages/sdk/vercel/package.json @@ -37,7 +37,7 @@ "check": "yarn prettier && yarn lint && yarn build && yarn test && yarn doc" }, "dependencies": { - "@launchdarkly/js-server-sdk-common-edge": "1.0.6", + "@launchdarkly/js-server-sdk-common-edge": "1.1.0-alpha.0", "@vercel/edge-config": "^0.1.8", "crypto-js": "^4.1.1" }, From d89af0a64be392e6fe2ffe67c584715a9b11b399 Mon Sep 17 00:00:00 2001 From: Henry Barrow Date: Mon, 31 Jul 2023 15:22:09 +0100 Subject: [PATCH 06/12] revert change to release please manifest --- .release-please-manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 24c657b2e..b1b60e631 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -4,7 +4,7 @@ "packages/sdk/server-node": "8.1.0", "packages/sdk/cloudflare": "2.0.7", "packages/shared/sdk-server-edge": "1.0.6", - "packages/sdk/vercel": "1.0.2", + "packages/sdk/vercel": "1.0.1", "packages/sdk/akamai-base": "1.0.0", "packages/sdk/akamai-edgekv": "1.0.0", "packages/shared/akamai-edgeworker-sdk": "0.2.5", From 92d98527743c5aace2c03a7bdf1a0f69f9fcadb0 Mon Sep 17 00:00:00 2001 From: Henry Barrow Date: Mon, 31 Jul 2023 15:37:00 +0100 Subject: [PATCH 07/12] bump version --- .release-please-manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index b1b60e631..24c657b2e 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -4,7 +4,7 @@ "packages/sdk/server-node": "8.1.0", "packages/sdk/cloudflare": "2.0.7", "packages/shared/sdk-server-edge": "1.0.6", - "packages/sdk/vercel": "1.0.1", + "packages/sdk/vercel": "1.0.2", "packages/sdk/akamai-base": "1.0.0", "packages/sdk/akamai-edgekv": "1.0.0", "packages/shared/akamai-edgeworker-sdk": "0.2.5", From cafe4f9dbba3d2da7c495093a4316bda08c9bf2f Mon Sep 17 00:00:00 2001 From: Henry Barrow Date: Mon, 31 Jul 2023 15:37:21 +0100 Subject: [PATCH 08/12] Revert version bump --- .release-please-manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 24c657b2e..b1b60e631 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -4,7 +4,7 @@ "packages/sdk/server-node": "8.1.0", "packages/sdk/cloudflare": "2.0.7", "packages/shared/sdk-server-edge": "1.0.6", - "packages/sdk/vercel": "1.0.2", + "packages/sdk/vercel": "1.0.1", "packages/sdk/akamai-base": "1.0.0", "packages/sdk/akamai-edgekv": "1.0.0", "packages/shared/akamai-edgeworker-sdk": "0.2.5", From bf64c61a5c126691bbc8dd1bf2baeb6e11d44746 Mon Sep 17 00:00:00 2001 From: Henry Barrow Date: Mon, 31 Jul 2023 17:13:21 +0100 Subject: [PATCH 09/12] revert changes to package.json --- packages/sdk/vercel/package.json | 2 +- packages/shared/sdk-server-edge/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/sdk/vercel/package.json b/packages/sdk/vercel/package.json index 7e156f3da..ca99e17f2 100644 --- a/packages/sdk/vercel/package.json +++ b/packages/sdk/vercel/package.json @@ -1,6 +1,6 @@ { "name": "@launchdarkly/vercel-server-sdk", - "version": "1.1.0-alpha.0", + "version": "1.0.1", "description": "LaunchDarkly Server-Side SDK for Vercel Edge", "homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/sdk/vercel", "repository": { diff --git a/packages/shared/sdk-server-edge/package.json b/packages/shared/sdk-server-edge/package.json index 7892fdbb1..bfd02b667 100644 --- a/packages/shared/sdk-server-edge/package.json +++ b/packages/shared/sdk-server-edge/package.json @@ -1,6 +1,6 @@ { "name": "@launchdarkly/js-server-sdk-common-edge", - "version": "1.1.0-alpha.0", + "version": "1.0.6", "homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/shared/sdk-server-edge", "repository": { "type": "git", From 9fa4a6e0b1b54c3a0f4cb210b2be1e785159fbe0 Mon Sep 17 00:00:00 2001 From: Henry Barrow Date: Mon, 31 Jul 2023 17:14:37 +0100 Subject: [PATCH 10/12] Revert change to package.json --- packages/sdk/vercel/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk/vercel/package.json b/packages/sdk/vercel/package.json index ca99e17f2..e12812c0a 100644 --- a/packages/sdk/vercel/package.json +++ b/packages/sdk/vercel/package.json @@ -37,7 +37,7 @@ "check": "yarn prettier && yarn lint && yarn build && yarn test && yarn doc" }, "dependencies": { - "@launchdarkly/js-server-sdk-common-edge": "1.1.0-alpha.0", + "@launchdarkly/js-server-sdk-common-edge": "1.0.6", "@vercel/edge-config": "^0.1.8", "crypto-js": "^4.1.1" }, From 99c09d44c13464b67587df259524f83e69d5aa63 Mon Sep 17 00:00:00 2001 From: Henry Barrow Date: Tue, 15 Aug 2023 13:54:59 +0100 Subject: [PATCH 11/12] Prep for release --- packages/sdk/vercel/package.json | 4 ++-- packages/shared/sdk-server-edge/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/sdk/vercel/package.json b/packages/sdk/vercel/package.json index 24f571c6d..7f909d1ac 100644 --- a/packages/sdk/vercel/package.json +++ b/packages/sdk/vercel/package.json @@ -1,6 +1,6 @@ { "name": "@launchdarkly/vercel-server-sdk", - "version": "1.1.0", + "version": "1.2.0-alpha.0", "description": "LaunchDarkly Server-Side SDK for Vercel Edge", "homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/sdk/vercel", "repository": { @@ -37,7 +37,7 @@ "check": "yarn prettier && yarn lint && yarn build && yarn test && yarn doc" }, "dependencies": { - "@launchdarkly/js-server-sdk-common-edge": "1.0.9", + "@launchdarkly/js-server-sdk-common-edge": "1.1.0-alpha.0", "@vercel/edge-config": "^0.1.8", "crypto-js": "^4.1.1" }, diff --git a/packages/shared/sdk-server-edge/package.json b/packages/shared/sdk-server-edge/package.json index acb02a812..6f7ce3483 100644 --- a/packages/shared/sdk-server-edge/package.json +++ b/packages/shared/sdk-server-edge/package.json @@ -1,6 +1,6 @@ { "name": "@launchdarkly/js-server-sdk-common-edge", - "version": "1.0.9", + "version": "1.1.0-alpha.1", "homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/shared/sdk-server-edge", "repository": { "type": "git", From 281b77e8389250eb72381f452dae2abb8cace995 Mon Sep 17 00:00:00 2001 From: Henry Barrow Date: Tue, 15 Aug 2023 14:04:33 +0100 Subject: [PATCH 12/12] Fix version string --- packages/sdk/vercel/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk/vercel/package.json b/packages/sdk/vercel/package.json index 7f909d1ac..ae09baa23 100644 --- a/packages/sdk/vercel/package.json +++ b/packages/sdk/vercel/package.json @@ -37,7 +37,7 @@ "check": "yarn prettier && yarn lint && yarn build && yarn test && yarn doc" }, "dependencies": { - "@launchdarkly/js-server-sdk-common-edge": "1.1.0-alpha.0", + "@launchdarkly/js-server-sdk-common-edge": "1.1.0-alpha.1", "@vercel/edge-config": "^0.1.8", "crypto-js": "^4.1.1" },