Skip to content

Commit 9a640f5

Browse files
authored
Merge branch 'main' into main
2 parents 83abbf5 + 3db2700 commit 9a640f5

File tree

14 files changed

+187
-175
lines changed

14 files changed

+187
-175
lines changed

.release-please-manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"packages/shared/sdk-server": "2.16.1",
44
"packages/sdk/server-node": "9.10.1",
55
"packages/sdk/cloudflare": "2.7.9",
6-
"packages/sdk/fastly": "0.1.9",
6+
"packages/sdk/fastly": "0.2.0",
77
"packages/shared/sdk-server-edge": "2.6.8",
88
"packages/sdk/vercel": "1.3.32",
99
"packages/sdk/akamai-base": "3.0.9",
@@ -15,7 +15,7 @@
1515
"packages/sdk/react-native": "10.10.5",
1616
"packages/telemetry/node-server-sdk-otel": "1.3.1",
1717
"packages/sdk/browser": "0.8.1",
18-
"packages/sdk/server-ai": "0.10.1",
18+
"packages/sdk/server-ai": "0.11.0",
1919
"packages/telemetry/browser-telemetry": "1.0.11",
2020
"packages/tooling/jest": "0.1.10",
2121
"packages/sdk/combined-browser": "0.0.0"

packages/sdk/fastly/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [0.2.0](https://github.com/launchdarkly/js-core/compare/fastly-server-sdk-v0.1.9...fastly-server-sdk-v0.2.0) (2025-08-01)
4+
5+
6+
### Features
7+
8+
* Improve KV data caching and deserialization ([#903](https://github.com/launchdarkly/js-core/issues/903)) ([ae47860](https://github.com/launchdarkly/js-core/commit/ae4786096c34829745070ed2a69a6d964be46e4d))
9+
310
## [0.1.9](https://github.com/launchdarkly/js-core/compare/fastly-server-sdk-v0.1.8...fastly-server-sdk-v0.1.9) (2025-07-23)
411

512

packages/sdk/fastly/__tests__/createPlatformInfo.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import createPlatformInfo from '../src/createPlatformInfo';
22

3-
const version = '0.1.9'; // x-release-please-version
3+
const version = '0.2.0'; // x-release-please-version
44

55
describe('Fastly Platform Info', () => {
66
it('platformData shows correct information', () => {

packages/sdk/fastly/example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"dependencies": {
1414
"@fastly/js-compute": "^3.30.1",
15-
"@launchdarkly/fastly-server-sdk": "0.1.9"
15+
"@launchdarkly/fastly-server-sdk": "0.2.0"
1616
},
1717
"scripts": {
1818
"clean": "rimraf build && rimraf bin",

packages/sdk/fastly/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@launchdarkly/fastly-server-sdk",
3-
"version": "0.1.9",
3+
"version": "0.2.0",
44
"packageManager": "[email protected]",
55
"description": "Fastly LaunchDarkly SDK",
66
"homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/sdk/fastly",

packages/sdk/fastly/src/api/EdgeFeatureStore.ts

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface EdgeProvider {
1414

1515
export class EdgeFeatureStore implements LDFeatureStore {
1616
private readonly _rootKey: string;
17-
private _kvData: string | null = null;
17+
private _deserializedPromise: Promise<LDFeatureStoreDataStorage | null> | null = null;
1818

1919
constructor(
2020
private readonly _edgeProvider: EdgeProvider,
@@ -30,11 +30,36 @@ export class EdgeFeatureStore implements LDFeatureStore {
3030
* has a limit of 32 backend requests (including requests to fetch the KV data).
3131
* https://docs.fastly.com/products/compute-resource-limits
3232
*/
33-
private async _getKVData(): Promise<string | null | undefined> {
34-
if (!this._kvData) {
35-
this._kvData = await this._edgeProvider.get(this._rootKey);
33+
private async _getKVData(): Promise<LDFeatureStoreDataStorage | null> {
34+
if (!this._deserializedPromise) {
35+
this._deserializedPromise = (async (): Promise<LDFeatureStoreDataStorage | null> => {
36+
this._logger.debug('No cached data found, loading from KV store');
37+
const kvData = await this._edgeProvider.get(this._rootKey);
38+
if (!kvData) {
39+
this._logger.debug('No data found in KV store');
40+
return null;
41+
}
42+
43+
this._logger.debug('Deserializing KV store data');
44+
const deserialized = deserializePoll(kvData);
45+
if (!deserialized) {
46+
this._logger.debug('Failed to deserialize KV store data');
47+
return null;
48+
}
49+
50+
// Convert FlagsAndSegments to LDFeatureStoreDataStorage format
51+
const deserializedData: LDFeatureStoreDataStorage = {
52+
features: deserialized.flags,
53+
segments: deserialized.segments,
54+
};
55+
this._logger.debug('Successfully cached deserialized data');
56+
57+
return deserializedData;
58+
})();
59+
} else {
60+
this._logger.debug('Using cached deserialized data');
3661
}
37-
return this._kvData;
62+
return this._deserializedPromise;
3863
}
3964

4065
async get(
@@ -47,23 +72,18 @@ export class EdgeFeatureStore implements LDFeatureStore {
4772
this._logger.debug(`Requesting ${dataKey} from ${this._rootKey}.${kindKey}`);
4873

4974
try {
50-
const i = await this._getKVData();
75+
const data = await this._getKVData();
5176

52-
if (!i) {
77+
if (!data) {
5378
throw new Error(`${this._rootKey}.${kindKey} is not found in KV.`);
5479
}
5580

56-
const item = deserializePoll(i);
57-
if (!item) {
58-
throw new Error(`Error deserializing ${kindKey}`);
59-
}
60-
6181
switch (namespace) {
6282
case 'features':
63-
callback(item.flags[dataKey]);
83+
callback(data.features[dataKey]);
6484
break;
6585
case 'segments':
66-
callback(item.segments[dataKey]);
86+
callback(data.segments[dataKey]);
6787
break;
6888
default:
6989
callback(null);
@@ -79,22 +99,17 @@ export class EdgeFeatureStore implements LDFeatureStore {
7999
const kindKey = namespace === 'features' ? 'flags' : namespace;
80100
this._logger.debug(`Requesting all from ${this._rootKey}.${kindKey}`);
81101
try {
82-
const i = await this._getKVData();
83-
if (!i) {
102+
const data = await this._getKVData();
103+
if (!data) {
84104
throw new Error(`${this._rootKey}.${kindKey} is not found in KV.`);
85105
}
86106

87-
const item = deserializePoll(i);
88-
if (!item) {
89-
throw new Error(`Error deserializing ${kindKey}`);
90-
}
91-
92107
switch (namespace) {
93108
case 'features':
94-
callback(item.flags);
109+
callback(data.features);
95110
break;
96111
case 'segments':
97-
callback(item.segments);
112+
callback(data.segments);
98113
break;
99114
default:
100115
callback({});
@@ -106,13 +121,22 @@ export class EdgeFeatureStore implements LDFeatureStore {
106121
}
107122

108123
async initialized(callback: (isInitialized: boolean) => void = noop): Promise<void> {
109-
const config = await this._getKVData();
110-
const result = config !== null;
111-
this._logger.debug(`Is ${this._rootKey} initialized? ${result}`);
112-
callback(result);
124+
try {
125+
const deserialized = await this._getKVData();
126+
const result = deserialized !== null;
127+
this._logger.debug(`Is ${this._rootKey} initialized? ${result}`);
128+
callback(result);
129+
} catch (err) {
130+
this._logger.error(err);
131+
this._logger.debug(`Is ${this._rootKey} initialized? false`);
132+
callback(false);
133+
}
113134
}
114135

115136
init(allData: LDFeatureStoreDataStorage, callback: () => void): void {
137+
this._getKVData().catch((err) => {
138+
this._logger.error(err);
139+
});
116140
callback();
117141
}
118142

packages/sdk/fastly/src/createPlatformInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Info, PlatformData, SdkData } from '@launchdarkly/js-server-sdk-common';
22

33
const name = '@launchdarkly/fastly-server-sdk';
4-
const version = '0.1.9'; // x-release-please-version
4+
const version = '0.2.0'; // x-release-please-version
55

66
class FastlyPlatformInfo implements Info {
77
platformData(): PlatformData {

packages/sdk/server-ai/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## [0.11.0](https://github.com/launchdarkly/js-core/compare/server-sdk-ai-v0.10.1...server-sdk-ai-v0.11.0) (2025-08-01)
4+
5+
6+
### Features
7+
8+
* Adding agent support for AI Configs ([#893](https://github.com/launchdarkly/js-core/issues/893)) ([bf95b92](https://github.com/launchdarkly/js-core/commit/bf95b92946e93b54e1eda7ffef96039b2b42b9aa))
9+
* Update AI tracker to include model & provider name for metrics generation ([#901](https://github.com/launchdarkly/js-core/issues/901)) ([9474862](https://github.com/launchdarkly/js-core/commit/94748621034ed6b1a74060ee0c536bf96a3cd43d))
10+
11+
12+
### Bug Fixes
13+
14+
* Remove deprecated track generation event ([#902](https://github.com/launchdarkly/js-core/issues/902)) ([40f8593](https://github.com/launchdarkly/js-core/commit/40f859386087a443948214e9b535527f125ffa39))
15+
316
## [0.10.1](https://github.com/launchdarkly/js-core/compare/server-sdk-ai-v0.10.0...server-sdk-ai-v0.10.1) (2025-07-23)
417

518

0 commit comments

Comments
 (0)