Skip to content

Commit 5c116fa

Browse files
authored
fix: vercel edge config adapter to calls class-transform (#1009)
1 parent dadf523 commit 5c116fa

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

lib/shared/vercel-edge-config/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"@devcycle/types": "*",
66
"@vercel/edge-config": "^1.2.0"
77
},
8+
"dependencies": {
9+
"class-transformer": "^0.5.1"
10+
},
811
"type": "commonjs",
912
"main": "./src/index.js",
1013
"typings": "./src/index.d.ts"

lib/shared/vercel-edge-config/src/edge-config.spec.ts

+57
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,63 @@ describe('EdgeConfigSource', () => {
3030
})
3131
})
3232

33+
it('transforms raw data into a valid ConfigBody', async () => {
34+
const get = jest.fn()
35+
const edgeConfigSource = new EdgeConfigSource(
36+
fromPartial({
37+
get,
38+
}),
39+
)
40+
41+
get.mockResolvedValue({
42+
key: 'value',
43+
features: [
44+
{
45+
configuration: {
46+
targets: [
47+
{
48+
rollout: {
49+
startDate: '2024-12-05T20:36:26.086Z',
50+
},
51+
},
52+
],
53+
},
54+
},
55+
],
56+
lastModified: 'some date',
57+
})
58+
59+
const result = await edgeConfigSource.getConfig(
60+
'sdk-key',
61+
'server',
62+
false,
63+
)
64+
65+
expect(result).toEqual({
66+
config: {
67+
key: 'value',
68+
lastModified: 'some date',
69+
features: [
70+
{
71+
configuration: {
72+
targets: [
73+
{
74+
rollout: {
75+
startDate: new Date(
76+
'2024-12-05T20:36:26.086Z',
77+
),
78+
},
79+
},
80+
],
81+
},
82+
},
83+
],
84+
},
85+
lastModified: 'some date',
86+
metaData: { resLastModified: 'some date' },
87+
})
88+
})
89+
3390
it('returns null when the existing config date is newer', async () => {
3491
const get = jest.fn()
3592
const edgeConfigSource = new EdgeConfigSource(

lib/shared/vercel-edge-config/src/edge-config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { EdgeConfigClient, EdgeConfigValue } from '@vercel/edge-config'
22
import { ConfigBody, ConfigSource, UserError } from '@devcycle/types'
3+
import { plainToInstance } from 'class-transformer'
34

45
export class EdgeConfigSource extends ConfigSource {
56
constructor(private edgeConfigClient: EdgeConfigClient) {
@@ -44,7 +45,7 @@ export class EdgeConfigSource extends ConfigSource {
4445
this.configLastModified = config['lastModified'] as string
4546

4647
return {
47-
config: config as unknown as ConfigBody,
48+
config: plainToInstance(ConfigBody, config),
4849
metaData: { resLastModified: this.configLastModified },
4950
lastModified: this.configLastModified,
5051
}

yarn.lock

+2
Original file line numberDiff line numberDiff line change
@@ -4829,6 +4829,8 @@ __metadata:
48294829
"@devcycle/vercel-edge-config@workspace:lib/shared/vercel-edge-config":
48304830
version: 0.0.0-use.local
48314831
resolution: "@devcycle/vercel-edge-config@workspace:lib/shared/vercel-edge-config"
4832+
dependencies:
4833+
class-transformer: ^0.5.1
48324834
peerDependencies:
48334835
"@devcycle/types": "*"
48344836
"@vercel/edge-config": ^1.2.0

0 commit comments

Comments
 (0)