Skip to content

Commit

Permalink
feat: Upgrade edgekv bundled files to 0.6.3 (#610)
Browse files Browse the repository at this point in the history
**Requirements**

- [ ] I have added test coverage for new or changed functionality
- [x] I have followed the repository's [pull request submission
guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests)
- [x] I have validated my changes against all supported platform
versions

**Related issues**

Provide links to any issues in this repository or elsewhere relating to
this pull request.

**Describe the solution you've provided**

Provide a clear and concise description of what you expect to happen.

**Describe alternatives you've considered**

Provide a clear and concise description of any alternative solutions or
features you've considered.

**Additional context**

Add any other context about the pull request here.

---------

Co-authored-by: Ryan Lamb <[email protected]>
  • Loading branch information
ctawiah and kinyoklion authored Nov 14, 2024
1 parent aafd1a5 commit 58dfec6
Show file tree
Hide file tree
Showing 4 changed files with 371 additions and 414 deletions.
13 changes: 11 additions & 2 deletions packages/sdk/akamai-edgekv/__tests__/edgekv/edgeKVProvider.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { LDLogger } from '@launchdarkly/js-server-sdk-common';

import { EdgeKV } from '../../src/edgekv/edgekv';
import EdgeKVProvider from '../../src/edgekv/edgeKVProvider';

Expand All @@ -11,14 +13,21 @@ const NAMESPACE = 'namespace';
const GROUP = 'group';

describe('EdgeKVProvider', () => {
let logger: LDLogger;
beforeEach(() => {
mockEdgeKV.mockImplementation(() => ({
getText: jest.fn().mockResolvedValue('some-text'),
}));
logger = {
debug: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
};
});

it('get string from edgeKV', async () => {
const edgeKVProvider = new EdgeKVProvider({ namespace: NAMESPACE, group: GROUP });
const edgeKVProvider = new EdgeKVProvider({ namespace: NAMESPACE, group: GROUP, logger });
expect(await edgeKVProvider.get('rootKey')).toEqual('some-text');
});

Expand All @@ -28,7 +37,7 @@ describe('EdgeKVProvider', () => {
getText: jest.fn().mockRejectedValueOnce(expectedError),
}));

const edgeKVProvider = new EdgeKVProvider({ namespace: NAMESPACE, group: GROUP });
const edgeKVProvider = new EdgeKVProvider({ namespace: NAMESPACE, group: GROUP, logger });
const result = await edgeKVProvider.get('rootKey');
expect(result).toBe(undefined);
});
Expand Down
8 changes: 6 additions & 2 deletions packages/sdk/akamai-edgekv/src/edgekv/edgeKVProvider.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import { EdgeProvider } from '@launchdarkly/akamai-edgeworker-sdk-common';
import { LDLogger } from '@launchdarkly/js-server-sdk-common';

import { EdgeKV } from './edgekv';

type EdgeKVProviderParams = {
namespace: string;
group: string;
logger: LDLogger;
};

export default class EdgeKVProvider implements EdgeProvider {
private _edgeKv: EdgeKV;
private _logger: LDLogger;

constructor({ namespace, group }: EdgeKVProviderParams) {
constructor({ namespace, group, logger }: EdgeKVProviderParams) {
this._edgeKv = new EdgeKV({ namespace, group } as any);
this._logger = logger;
}

async get(rootKey: string): Promise<string | null | undefined> {
try {
return await this._edgeKv.getText({ item: rootKey } as any);
} catch (e) {
/* empty */
this._logger?.error(`Error getting value from EdgeKV: ${e}`);
}
return undefined;
}
Expand Down
Loading

0 comments on commit 58dfec6

Please sign in to comment.