statsig-node-vercel 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,7 +36,7 @@ export class EdgeConfigDataAdapter implements IDataAdapter {
36
36
 
37
37
  // eslint-disable-next-line @typescript-eslint/require-await
38
38
  public async get(key: string): Promise<AdapterResponse> {
39
- if (key !== "statsig.cache") {
39
+ if (!this.isConfgSpecKey(key)) {
40
40
  return {
41
41
  error: new Error(`Edge Config Adapter Only Supports Config Specs`),
42
42
  };
@@ -75,9 +75,14 @@ export class EdgeConfigDataAdapter implements IDataAdapter {
75
75
  public async shutdown(): Promise<void> {}
76
76
 
77
77
  public supportsPollingUpdatesFor(key: string): boolean {
78
- if (key === "statsig.cache") {
78
+ if (this.isConfgSpecKey(key)) {
79
79
  return this.supportConfigSpecPolling;
80
80
  }
81
81
  return false;
82
82
  }
83
+
84
+ private isConfgSpecKey(key: string): boolean {
85
+ const v2CacheKeyPattern = /^statsig\|\/v[12]\/download_config_specs\|.+\|.+/;
86
+ return key === "statsig.cache" || v2CacheKeyPattern.test(key);
87
+ }
83
88
  }
@@ -11,7 +11,7 @@ describe("Validate edge config adapter functionality", () => {
11
11
 
12
12
  beforeEach(async () => {
13
13
  fetchMock.enableMocks();
14
- fetchMock.mockResponse('"test123"');
14
+ fetchMock.mockResponse('{"a":1}');
15
15
  await dataAdapter.initialize();
16
16
  });
17
17
 
@@ -21,9 +21,16 @@ describe("Validate edge config adapter functionality", () => {
21
21
 
22
22
  test("Simple get", async () => {
23
23
  const { result: gates } = await dataAdapter.get("statsig.cache");
24
- if (gates == null) {
25
- return;
26
- }
27
- expect(gates).toEqual('"test123"');
24
+ expect(gates).toEqual({a: 1});
25
+ });
26
+
27
+ test('Simple get v2 key', async () => {
28
+ const { result: gates } = await dataAdapter.get("statsig|/v1/download_config_specs|plain_text|1234");
29
+ expect(gates).toEqual({a: 1});
30
+ });
31
+
32
+ test('Simple get v2 key with dcs v2', async () => {
33
+ const { result: gates } = await dataAdapter.get("statsig|/v2/download_config_specs|plain_text|1234");
34
+ expect(gates).toEqual({a: 1});
28
35
  });
29
36
  });
@@ -33,4 +33,5 @@ export declare class EdgeConfigDataAdapter implements IDataAdapter {
33
33
  initialize(): Promise<void>;
34
34
  shutdown(): Promise<void>;
35
35
  supportsPollingUpdatesFor(key: string): boolean;
36
+ private isConfgSpecKey;
36
37
  }
@@ -19,7 +19,7 @@ class EdgeConfigDataAdapter {
19
19
  // eslint-disable-next-line @typescript-eslint/require-await
20
20
  get(key) {
21
21
  return __awaiter(this, void 0, void 0, function* () {
22
- if (key !== "statsig.cache") {
22
+ if (!this.isConfgSpecKey(key)) {
23
23
  return {
24
24
  error: new Error(`Edge Config Adapter Only Supports Config Specs`),
25
25
  };
@@ -55,10 +55,14 @@ class EdgeConfigDataAdapter {
55
55
  return __awaiter(this, void 0, void 0, function* () { });
56
56
  }
57
57
  supportsPollingUpdatesFor(key) {
58
- if (key === "statsig.cache") {
58
+ if (this.isConfgSpecKey(key)) {
59
59
  return this.supportConfigSpecPolling;
60
60
  }
61
61
  return false;
62
62
  }
63
+ isConfgSpecKey(key) {
64
+ const v2CacheKeyPattern = /^statsig\|\/v[12]\/download_config_specs\|.+\|.+/;
65
+ return key === "statsig.cache" || v2CacheKeyPattern.test(key);
66
+ }
63
67
  }
64
68
  exports.EdgeConfigDataAdapter = EdgeConfigDataAdapter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "statsig-node-vercel",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -27,4 +27,4 @@
27
27
  "jest": "^29.0.0",
28
28
  "jest-fetch-mock": "^3.0.3"
29
29
  }
30
- }
30
+ }