statsig-node-vercel 0.7.0 → 0.8.1

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.
@@ -10,7 +10,8 @@ export class EdgeConfigDataAdapter implements IDataAdapter {
10
10
  * A fully configured Edge Config client
11
11
  */
12
12
  private edgeConfigClient: EdgeConfigClient;
13
- private supportConfigSpecPolling: boolean = false;
13
+ private edgeConfigIsHydrated: boolean = false;
14
+ private useEdgeConfigForPollingForUpdates: boolean;
14
15
 
15
16
  public constructor(options: {
16
17
  /**
@@ -29,9 +30,14 @@ export class EdgeConfigDataAdapter implements IDataAdapter {
29
30
  * ```
30
31
  */
31
32
  edgeConfigClient: EdgeConfigClient;
33
+ /**
34
+ * Whether to opt out of polling updates from Edge Config.
35
+ */
36
+ useEdgeConfigForPollingForUpdates?: boolean;
32
37
  }) {
33
38
  this.edgeConfigItemKey = options.edgeConfigItemKey;
34
39
  this.edgeConfigClient = options.edgeConfigClient;
40
+ this.useEdgeConfigForPollingForUpdates = options.useEdgeConfigForPollingForUpdates ?? true;
35
41
  }
36
42
 
37
43
  // eslint-disable-next-line @typescript-eslint/require-await
@@ -51,6 +57,7 @@ export class EdgeConfigDataAdapter implements IDataAdapter {
51
57
  error: new Error(`Edge Config value expected to be an object or array`),
52
58
  };
53
59
  }
60
+ this.edgeConfigIsHydrated = true;
54
61
  return { result: data };
55
62
  }
56
63
 
@@ -67,7 +74,7 @@ export class EdgeConfigDataAdapter implements IDataAdapter {
67
74
  const data = await this.edgeConfigClient.get(this.edgeConfigItemKey);
68
75
 
69
76
  if (data) {
70
- this.supportConfigSpecPolling = true;
77
+ this.edgeConfigIsHydrated = true;
71
78
  }
72
79
  }
73
80
 
@@ -75,8 +82,8 @@ export class EdgeConfigDataAdapter implements IDataAdapter {
75
82
  public async shutdown(): Promise<void> {}
76
83
 
77
84
  public supportsPollingUpdatesFor(key: string): boolean {
78
- if (this.isConfgSpecKey(key)) {
79
- return this.supportConfigSpecPolling;
85
+ if (this.isConfgSpecKey(key) && this.useEdgeConfigForPollingForUpdates) {
86
+ return this.edgeConfigIsHydrated;
80
87
  }
81
88
  return false;
82
89
  }
@@ -84,6 +91,11 @@ export class EdgeConfigDataAdapter implements IDataAdapter {
84
91
  private isConfgSpecKey(key: string): boolean {
85
92
  const v2CacheKeyPattern =
86
93
  /^statsig\|\/v[12]\/download_config_specs\|.+\|.+/;
87
- return key === "statsig.cache" || v2CacheKeyPattern.test(key);
94
+ return (
95
+ key === "statsig.cache" ||
96
+ key === '/v1/download_config_specs' ||
97
+ key === '/v2/download_config_specs' ||
98
+ v2CacheKeyPattern.test(key)
99
+ );
88
100
  }
89
101
  }
@@ -9,7 +9,8 @@ export declare class EdgeConfigDataAdapter implements IDataAdapter {
9
9
  * A fully configured Edge Config client
10
10
  */
11
11
  private edgeConfigClient;
12
- private supportConfigSpecPolling;
12
+ private edgeConfigIsHydrated;
13
+ private useEdgeConfigForPollingForUpdates;
13
14
  constructor(options: {
14
15
  /**
15
16
  * The key under which Statsig specs are stored in Edge Config
@@ -27,6 +28,10 @@ export declare class EdgeConfigDataAdapter implements IDataAdapter {
27
28
  * ```
28
29
  */
29
30
  edgeConfigClient: EdgeConfigClient;
31
+ /**
32
+ * Whether to opt out of polling updates from Edge Config.
33
+ */
34
+ useEdgeConfigForPollingForUpdates?: boolean;
30
35
  });
31
36
  get(key: string): Promise<AdapterResponse>;
32
37
  set(key: string, value: string, time?: number | undefined): Promise<void>;
@@ -12,9 +12,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.EdgeConfigDataAdapter = void 0;
13
13
  class EdgeConfigDataAdapter {
14
14
  constructor(options) {
15
- this.supportConfigSpecPolling = false;
15
+ var _a;
16
+ this.edgeConfigIsHydrated = false;
16
17
  this.edgeConfigItemKey = options.edgeConfigItemKey;
17
18
  this.edgeConfigClient = options.edgeConfigClient;
19
+ this.useEdgeConfigForPollingForUpdates = (_a = options.useEdgeConfigForPollingForUpdates) !== null && _a !== void 0 ? _a : true;
18
20
  }
19
21
  // eslint-disable-next-line @typescript-eslint/require-await
20
22
  get(key) {
@@ -33,6 +35,7 @@ class EdgeConfigDataAdapter {
33
35
  error: new Error(`Edge Config value expected to be an object or array`),
34
36
  };
35
37
  }
38
+ this.edgeConfigIsHydrated = true;
36
39
  return { result: data };
37
40
  });
38
41
  }
@@ -46,7 +49,7 @@ class EdgeConfigDataAdapter {
46
49
  return __awaiter(this, void 0, void 0, function* () {
47
50
  const data = yield this.edgeConfigClient.get(this.edgeConfigItemKey);
48
51
  if (data) {
49
- this.supportConfigSpecPolling = true;
52
+ this.edgeConfigIsHydrated = true;
50
53
  }
51
54
  });
52
55
  }
@@ -55,14 +58,17 @@ class EdgeConfigDataAdapter {
55
58
  return __awaiter(this, void 0, void 0, function* () { });
56
59
  }
57
60
  supportsPollingUpdatesFor(key) {
58
- if (this.isConfgSpecKey(key)) {
59
- return this.supportConfigSpecPolling;
61
+ if (this.isConfgSpecKey(key) && this.useEdgeConfigForPollingForUpdates) {
62
+ return this.edgeConfigIsHydrated;
60
63
  }
61
64
  return false;
62
65
  }
63
66
  isConfgSpecKey(key) {
64
67
  const v2CacheKeyPattern = /^statsig\|\/v[12]\/download_config_specs\|.+\|.+/;
65
- return key === "statsig.cache" || v2CacheKeyPattern.test(key);
68
+ return (key === "statsig.cache" ||
69
+ key === '/v1/download_config_specs' ||
70
+ key === '/v2/download_config_specs' ||
71
+ v2CacheKeyPattern.test(key));
66
72
  }
67
73
  }
68
74
  exports.EdgeConfigDataAdapter = EdgeConfigDataAdapter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "statsig-node-vercel",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -11,6 +11,11 @@
11
11
  "keywords": [],
12
12
  "author": "",
13
13
  "license": "ISC",
14
+ "homepage": "https://www.statsig.com/vercel",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "github:statsig-io/vercel-data-adapter-node"
18
+ },
14
19
  "dependencies": {
15
20
  "statsig-node-lite": "^0.4.2"
16
21
  },
@@ -18,13 +23,13 @@
18
23
  "@vercel/edge-config": "^1.0.0"
19
24
  },
20
25
  "devDependencies": {
21
- "@babel/core": "^7.18.13",
22
- "@babel/preset-env": "^7.18.10",
23
- "@babel/preset-typescript": "^7.18.6",
26
+ "@babel/core": "^7.26.10",
27
+ "@babel/preset-env": "^7.26.9",
28
+ "@babel/preset-typescript": "^7.27.0",
24
29
  "@types/jest": "^28.1.8",
25
30
  "@types/node": "^20.14.10",
26
31
  "@vercel/edge-config": "^1.0.0",
27
- "jest": "^29.0.0",
32
+ "jest": "^29.7.0",
28
33
  "jest-fetch-mock": "^3.0.3"
29
34
  }
30
35
  }