@statsig/statsig-node-core 0.15.1-beta.2601310133 → 0.15.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.
package/index.js CHANGED
@@ -22,9 +22,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22
22
  step((generator = generator.apply(thisArg, _arguments || [])).next());
23
23
  });
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
29
  exports.Statsig = void 0;
27
30
  const https_proxy_agent_1 = require("https-proxy-agent");
31
+ const node_fetch_1 = __importDefault(require("node-fetch"));
28
32
  const console_capture_1 = require("./console_capture");
29
33
  const error_boundary_1 = require("./error_boundary");
30
34
  const statsig_generated_1 = require("./statsig-generated");
@@ -54,6 +58,32 @@ function createProxyAgent(options) {
54
58
  }
55
59
  return undefined; // node-fetch agent parameter takes in undefined type instead of null
56
60
  }
61
+ function createFetchFunc(options) {
62
+ const proxyAgent = createProxyAgent(options);
63
+ return (method, url, headers, body) => __awaiter(this, void 0, void 0, function* () {
64
+ try {
65
+ const res = yield (0, node_fetch_1.default)(url, {
66
+ method,
67
+ headers: Object.assign({ 'accept-encoding': 'gzip, deflate, br' }, headers),
68
+ body: body ? Buffer.from(body) : undefined,
69
+ agent: proxyAgent,
70
+ });
71
+ const data = yield res.arrayBuffer();
72
+ const resHeaders = Object.fromEntries(res.headers.entries());
73
+ return {
74
+ status: res.status,
75
+ data: Array.from(new Uint8Array(data)),
76
+ headers: resHeaders,
77
+ };
78
+ }
79
+ catch (err) {
80
+ return {
81
+ status: 0,
82
+ error: 'message' in err ? err.message : 'Unknown Node Fetch Error',
83
+ };
84
+ }
85
+ });
86
+ }
57
87
  class Statsig extends statsig_generated_1.StatsigNapiInternal {
58
88
  static shared() {
59
89
  if (!Statsig.hasShared()) {
@@ -79,7 +109,8 @@ class Statsig extends statsig_generated_1.StatsigNapiInternal {
79
109
  }
80
110
  constructor(sdkKey, options) {
81
111
  var _a;
82
- super(sdkKey, options);
112
+ const fetchFunc = createFetchFunc(options);
113
+ super(fetchFunc, sdkKey, options);
83
114
  error_boundary_1.ErrorBoundary.wrap(this);
84
115
  if ((_a = options === null || options === void 0 ? void 0 : options.consoleCaptureOptions) === null || _a === void 0 ? void 0 : _a.enabled) {
85
116
  (0, console_capture_1.startStatsigConsoleCapture)(sdkKey, options.consoleCaptureOptions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statsig/statsig-node-core",
3
- "version": "0.15.1-beta.2601310133",
3
+ "version": "0.15.1",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "jest --colors"
@@ -55,13 +55,14 @@
55
55
  ]
56
56
  },
57
57
  "optionalDependencies": {
58
- "@statsig/statsig-node-core-linux-x64-musl": "0.15.1-beta.2601310133",
59
- "@statsig/statsig-node-core-linux-x64-gnu": "0.15.1-beta.2601310133",
60
- "@statsig/statsig-node-core-win32-x64-msvc": "0.15.1-beta.2601310133",
61
- "@statsig/statsig-node-core-darwin-x64": "0.15.1-beta.2601310133",
62
- "@statsig/statsig-node-core-win32-ia32-msvc": "0.15.1-beta.2601310133",
63
- "@statsig/statsig-node-core-linux-arm64-musl": "0.15.1-beta.2601310133",
64
- "@statsig/statsig-node-core-linux-arm64-gnu": "0.15.1-beta.2601310133",
65
- "@statsig/statsig-node-core-darwin-arm64": "0.15.1-beta.2601310133"
58
+ "@statsig/statsig-node-core-linux-x64-musl": "0.15.1",
59
+ "@statsig/statsig-node-core-linux-x64-gnu": "0.15.1",
60
+ "@statsig/statsig-node-core-win32-x64-msvc": "0.15.1",
61
+ "@statsig/statsig-node-core-darwin-x64": "0.15.1",
62
+ "@statsig/statsig-node-core-win32-ia32-msvc": "0.15.1",
63
+ "@statsig/statsig-node-core-linux-arm64-musl": "0.15.1",
64
+ "@statsig/statsig-node-core-linux-arm64-gnu": "0.15.1",
65
+ "@statsig/statsig-node-core-win32-arm64-msvc": "0.15.1",
66
+ "@statsig/statsig-node-core-darwin-arm64": "0.15.1"
66
67
  }
67
68
  }
@@ -12,7 +12,7 @@ export declare class StatsigNapiInternal {
12
12
  unsubscribe(eventName: SdkEvent): void
13
13
  unsubscribeById(subscriptionId: string): void
14
14
  unsubscribeAll(): void
15
- constructor(sdkKey: string, options?: StatsigOptions | undefined | null)
15
+ constructor(networkFunc: unknown, sdkKey: string, options?: StatsigOptions | undefined | null)
16
16
  initialize(): Promise<StatsigResult>
17
17
  shutdown(timeoutMs?: number | undefined | null): Promise<StatsigResult>
18
18
  flushEvents(): Promise<StatsigResult>
@@ -160,6 +160,13 @@ export interface LayerEvaluationOptions {
160
160
  userPersistedValues?: Record<string, any>
161
161
  }
162
162
 
163
+ export interface NapiNetworkFuncResult {
164
+ status: number
165
+ data?: Array<number>
166
+ headers?: Record<string, string>
167
+ error?: string
168
+ }
169
+
163
170
  export interface ObservabilityClient {
164
171
  initialize?: () => void
165
172
  increment?: (metricName: string, value: number, tags: Record<string, string>) => void