statsig-node-vercel 0.0.2 → 0.0.3-beta.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.
@@ -1,12 +1,14 @@
1
1
  import { AdapterResponse, IDataAdapter } from 'statsig-node';
2
- import { get } from '@vercel/edge-config';
2
+ import { createClient, EdgeConfigClient } from '@vercel/edge-config';
3
3
 
4
4
  export class EdgeConfigDataAdapter implements IDataAdapter {
5
5
  private configSpecsKey: string;
6
+ private edgeConfigClient: EdgeConfigClient;
6
7
  private supportConfigSpecPolling: boolean = false;
7
8
 
8
- public constructor(key: string) {
9
+ public constructor(key: string, connectionString: string = process.env.EDGE_CONFIG!) {
9
10
  this.configSpecsKey = key;
11
+ this.edgeConfigClient = createClient(connectionString);
10
12
  }
11
13
 
12
14
  // eslint-disable-next-line @typescript-eslint/require-await
@@ -15,7 +17,7 @@ export class EdgeConfigDataAdapter implements IDataAdapter {
15
17
  return { error: new Error(`Edge Config Adapter Only Supports Config Specs`) };
16
18
  }
17
19
 
18
- const data = await get(this.configSpecsKey);
20
+ const data = await this.edgeConfigClient.get(this.configSpecsKey);
19
21
  if (data === undefined) {
20
22
  return { error: new Error(`key (${key}) does not exist`) };
21
23
  }
@@ -32,7 +34,7 @@ export class EdgeConfigDataAdapter implements IDataAdapter {
32
34
  }
33
35
 
34
36
  public async initialize(): Promise<void> {
35
- const data = await get(this.configSpecsKey);
37
+ const data = await this.edgeConfigClient.get(this.configSpecsKey);
36
38
 
37
39
  if (data) {
38
40
  this.supportConfigSpecPolling = true;
package/README.md CHANGED
@@ -12,7 +12,7 @@ npm install statsig-node@5.1.0-beta.1
12
12
  ```
13
13
  npm install statsig-node-vercel
14
14
  ```
15
- 3. Install the [Statsig Vercel App](https://vercel.com/integrations/statsig)
15
+ 3. Install the [Statsig Vercel Integration](https://vercel.com/integrations/statsig)
16
16
  4. Import the package
17
17
  ```
18
18
  import { EdgeConfigDataAdapter } from 'statsig-node-vercel'
@@ -1,8 +1,9 @@
1
1
  import { AdapterResponse, IDataAdapter } from 'statsig-node';
2
2
  export declare class EdgeConfigDataAdapter implements IDataAdapter {
3
3
  private configSpecsKey;
4
+ private edgeConfigClient;
4
5
  private supportConfigSpecPolling;
5
- constructor(key: string);
6
+ constructor(key: string, connectionString?: string);
6
7
  get(key: string): Promise<AdapterResponse>;
7
8
  set(key: string, value: string, time?: number | undefined): Promise<void>;
8
9
  initialize(): Promise<void>;
@@ -12,9 +12,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.EdgeConfigDataAdapter = void 0;
13
13
  const edge_config_1 = require("@vercel/edge-config");
14
14
  class EdgeConfigDataAdapter {
15
- constructor(key) {
15
+ constructor(key, connectionString = process.env.EDGE_CONFIG) {
16
16
  this.supportConfigSpecPolling = false;
17
17
  this.configSpecsKey = key;
18
+ this.edgeConfigClient = (0, edge_config_1.createClient)(connectionString);
18
19
  }
19
20
  // eslint-disable-next-line @typescript-eslint/require-await
20
21
  get(key) {
@@ -22,7 +23,7 @@ class EdgeConfigDataAdapter {
22
23
  if (key !== "statsig.cache") {
23
24
  return { error: new Error(`Edge Config Adapter Only Supports Config Specs`) };
24
25
  }
25
- const data = yield (0, edge_config_1.get)(this.configSpecsKey);
26
+ const data = yield this.edgeConfigClient.get(this.configSpecsKey);
26
27
  if (data === undefined) {
27
28
  return { error: new Error(`key (${key}) does not exist`) };
28
29
  }
@@ -37,7 +38,7 @@ class EdgeConfigDataAdapter {
37
38
  }
38
39
  initialize() {
39
40
  return __awaiter(this, void 0, void 0, function* () {
40
- const data = yield (0, edge_config_1.get)(this.configSpecsKey);
41
+ const data = yield this.edgeConfigClient.get(this.configSpecsKey);
41
42
  if (data) {
42
43
  this.supportConfigSpecPolling = true;
43
44
  }
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export { EdgeConfigDataAdapter } from './EdgeConfigDataAdapter';
package/dist/index.js CHANGED
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EdgeConfigDataAdapter = void 0;
3
4
  const EdgeConfigDataAdapter_1 = require("./EdgeConfigDataAdapter");
5
+ var EdgeConfigDataAdapter_2 = require("./EdgeConfigDataAdapter");
6
+ Object.defineProperty(exports, "EdgeConfigDataAdapter", { enumerable: true, get: function () { return EdgeConfigDataAdapter_2.EdgeConfigDataAdapter; } });
4
7
  module.exports = {
5
8
  EdgeConfigDataAdapter: EdgeConfigDataAdapter_1.EdgeConfigDataAdapter,
6
9
  };
package/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { EdgeConfigDataAdapter } from './EdgeConfigDataAdapter';
2
+ export { EdgeConfigDataAdapter} from './EdgeConfigDataAdapter';
2
3
 
3
4
  module.exports = {
4
5
  EdgeConfigDataAdapter,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "statsig-node-vercel",
3
- "version": "0.0.2",
3
+ "version": "0.0.3-beta.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {