@statsig/vercel-edge 3.29.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.
- package/LICENSE +14 -0
- package/README.md +49 -0
- package/package.json +24 -0
- package/src/StatsigVercelClient.d.ts +18 -0
- package/src/StatsigVercelClient.js +78 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +6 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
ISC License (ISC)
|
|
2
|
+
Copyright (c) 2021, Statsig, Inc.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose
|
|
5
|
+
with or without fee is hereby granted, provided that the above copyright notice
|
|
6
|
+
and this permission notice appear in all copies.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
9
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
10
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
11
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
12
|
+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
13
|
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
|
14
|
+
THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Statsig helps you move faster with feature gates (feature flags), and/or dynamic configs. It also allows you to run A/B/n tests to validate your new features and understand their impact on your KPIs. If you're new to Statsig, check out our product and create an account at [statsig.com](https://www.statsig.com/?ref=gh_jsm).
|
|
2
|
+
|
|
3
|
+
<h1 align="center">
|
|
4
|
+
<a href="https://statsig.com/?ref=gh_jsm">
|
|
5
|
+
<img src="https://github.com/statsig-io/js-client-monorepo/assets/95646168/ae5499ed-20ff-4584-bf21-8857f800d485" />
|
|
6
|
+
</a>
|
|
7
|
+
<div />
|
|
8
|
+
<a href="https://statsig.com/?ref=gh_jsm">Statsig</a>
|
|
9
|
+
</h1>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://github.com/statsig-io/js-client-monorepo/blob/main/LICENSE">
|
|
13
|
+
<img src="https://img.shields.io/badge/license-ISC-blue.svg?colorA=1b2528&colorB=ccfbc7&style=for-the-badge">
|
|
14
|
+
</a>
|
|
15
|
+
<a href="https://www.npmjs.com/package/@statsig/js-client">
|
|
16
|
+
<img src="https://img.shields.io/npm/v/@statsig/js-client.svg?colorA=1b2528&colorB=b2d3ff&style=for-the-badge">
|
|
17
|
+
</a>
|
|
18
|
+
<a href="https://statsig.com/community?ref=gh_jsm">
|
|
19
|
+
<img src="https://img.shields.io/badge/slack-statsig-brightgreen.svg?logo=slack&colorA=1b2528&colorB=FFF8BA&style=for-the-badge">
|
|
20
|
+
</a>
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
## Getting Started
|
|
24
|
+
|
|
25
|
+
Read through the [Documentation](https://docs.statsig.com/client/javascript-sdk?ref=gh_jsm) or check out the [Samples](samples/).
|
|
26
|
+
|
|
27
|
+
## Packages
|
|
28
|
+
|
|
29
|
+
Clients
|
|
30
|
+
|
|
31
|
+
- Precomputed Evaluations (Recommended) [[npm](https://www.npmjs.com/package/@statsig/js-client)] [[source](https://github.com/statsig-io/js-client-monorepo/tree/main/packages/js-client)]
|
|
32
|
+
- On Device Evaluations [[npm](https://www.npmjs.com/package/@statsig/js-on-device-eval-client)] [[source](https://github.com/statsig-io/js-client-monorepo/tree/main/packages/js-on-device-eval-client)]
|
|
33
|
+
|
|
34
|
+
Product Bundles
|
|
35
|
+
|
|
36
|
+
- Session Replay [[npm](https://www.npmjs.com/package/@statsig/session-replay)] [[source](https://github.com/statsig-io/js-client-monorepo/tree/main/packages/session-replay)]
|
|
37
|
+
- Web Analytics [[npm](https://www.npmjs.com/package/@statsig/web-analytics)] [[source](https://github.com/statsig-io/js-client-monorepo/tree/main/packages/web-analytics)]
|
|
38
|
+
|
|
39
|
+
Framework Specific Bindings
|
|
40
|
+
|
|
41
|
+
- React [[npm](https://www.npmjs.com/package/@statsig/react-bindings)] [[source](https://github.com/statsig-io/js-client-monorepo/tree/main/packages/react-bindings)]
|
|
42
|
+
|
|
43
|
+
- React Native [[npm](https://www.npmjs.com/package/@statsig/react-native-bindings)] [[source](https://github.com/statsig-io/js-client-monorepo/tree/main/packages/react-native-bindings)]
|
|
44
|
+
|
|
45
|
+
- React Native (Expo) [[npm](https://www.npmjs.com/package/@statsig/expo-bindings)] [[source](https://github.com/statsig-io/js-client-monorepo/tree/main/packages/expo-bindings)]
|
|
46
|
+
|
|
47
|
+
## Community
|
|
48
|
+
|
|
49
|
+
If you need any assistance or just have a question, feel free to reach out to us on [Slack](https://statsig.com/community?ref=gh_jsm).
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@statsig/vercel-edge",
|
|
3
|
+
"version": "3.29.0",
|
|
4
|
+
"license": "ISC",
|
|
5
|
+
"homepage": "https://github.com/statsig-io/js-client-monorepo",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "github:statsig-io/js-client-monorepo",
|
|
9
|
+
"directory": "packages/vercel-edge"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@statsig/client-core": "3.29.0",
|
|
13
|
+
"@statsig/js-on-device-eval-client": "3.29.0",
|
|
14
|
+
"@statsig/serverless-client": "3.29.0",
|
|
15
|
+
"@vercel/edge-config": "^1.4.2",
|
|
16
|
+
"@vercel/functions": "^3.1.4"
|
|
17
|
+
},
|
|
18
|
+
"type": "commonjs",
|
|
19
|
+
"main": "./src/index.js",
|
|
20
|
+
"typings": "./src/index.d.ts",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"ts-node": "^10.9.1"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { StatsigUpdateDetails } from '@statsig/client-core';
|
|
2
|
+
import type { StatsigOptions } from '@statsig/js-on-device-eval-client';
|
|
3
|
+
import { StatsigServerlessClient } from '@statsig/serverless-client';
|
|
4
|
+
export declare class StatsigVercelClient extends StatsigServerlessClient {
|
|
5
|
+
initializeFromEdgeConfig(ConfigKey: string): Promise<StatsigUpdateDetails>;
|
|
6
|
+
}
|
|
7
|
+
export interface statsig {
|
|
8
|
+
(request: Request, client: StatsigVercelClient): Promise<Response> | Response;
|
|
9
|
+
}
|
|
10
|
+
interface VercelWrapperExport {
|
|
11
|
+
(request: Request): Promise<Response>;
|
|
12
|
+
}
|
|
13
|
+
export declare function handleWithStatsig(handler: statsig, params: {
|
|
14
|
+
configKey: string;
|
|
15
|
+
statsigSdkKey: string;
|
|
16
|
+
statsigOptions?: StatsigOptions;
|
|
17
|
+
}): VercelWrapperExport;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.handleWithStatsig = exports.StatsigVercelClient = void 0;
|
|
13
|
+
const edge_config_1 = require("@vercel/edge-config");
|
|
14
|
+
const functions_1 = require("@vercel/functions");
|
|
15
|
+
const client_core_1 = require("@statsig/client-core");
|
|
16
|
+
const serverless_client_1 = require("@statsig/serverless-client");
|
|
17
|
+
class StatsigVercelClient extends serverless_client_1.StatsigServerlessClient {
|
|
18
|
+
initializeFromEdgeConfig(ConfigKey) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const startTime = performance.now();
|
|
21
|
+
try {
|
|
22
|
+
const specs = yield (0, edge_config_1.get)(ConfigKey);
|
|
23
|
+
if (!specs) {
|
|
24
|
+
client_core_1.Log.error(`Failed to fetch specs from Vercel Edge Config with key: ${ConfigKey}`);
|
|
25
|
+
return {
|
|
26
|
+
duration: performance.now() - startTime,
|
|
27
|
+
source: 'Bootstrap',
|
|
28
|
+
success: false,
|
|
29
|
+
error: {
|
|
30
|
+
message: `Failed to fetch specs from Vercel Edge Config with key: ${ConfigKey}`,
|
|
31
|
+
},
|
|
32
|
+
sourceUrl: null,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
let specsData;
|
|
36
|
+
if (typeof specs === 'string') {
|
|
37
|
+
specsData = specs;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
specsData = JSON.stringify(specs);
|
|
41
|
+
}
|
|
42
|
+
this.dataAdapter.setData(specsData);
|
|
43
|
+
return this.initializeSync({
|
|
44
|
+
disableBackgroundCacheRefresh: true,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
catch (_a) {
|
|
48
|
+
client_core_1.Log.error(`Failed to fetch specs from Vercel Edge Config`);
|
|
49
|
+
return {
|
|
50
|
+
duration: performance.now() - startTime,
|
|
51
|
+
source: 'Bootstrap',
|
|
52
|
+
success: false,
|
|
53
|
+
error: {
|
|
54
|
+
message: `Failed to fetch specs from Vercel Edge Config`,
|
|
55
|
+
},
|
|
56
|
+
sourceUrl: null,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.StatsigVercelClient = StatsigVercelClient;
|
|
63
|
+
function handleWithStatsig(handler, params) {
|
|
64
|
+
return (request) => __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
if (!params.configKey || typeof params.configKey !== 'string') {
|
|
66
|
+
client_core_1.Log.error(`Invalid configKey`);
|
|
67
|
+
}
|
|
68
|
+
if (!params.statsigSdkKey || typeof params.statsigSdkKey !== 'string') {
|
|
69
|
+
client_core_1.Log.error(`Invalid statsigSdkKey`);
|
|
70
|
+
}
|
|
71
|
+
const client = new StatsigVercelClient(params.statsigSdkKey, params.statsigOptions);
|
|
72
|
+
yield client.initializeFromEdgeConfig(params.configKey);
|
|
73
|
+
const response = yield handler(request, client);
|
|
74
|
+
(0, functions_1.waitUntil)(client.flush());
|
|
75
|
+
return response;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
exports.handleWithStatsig = handleWithStatsig;
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { StatsigVercelClient, handleWithStatsig } from './StatsigVercelClient';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleWithStatsig = exports.StatsigVercelClient = void 0;
|
|
4
|
+
var StatsigVercelClient_1 = require("./StatsigVercelClient");
|
|
5
|
+
Object.defineProperty(exports, "StatsigVercelClient", { enumerable: true, get: function () { return StatsigVercelClient_1.StatsigVercelClient; } });
|
|
6
|
+
Object.defineProperty(exports, "handleWithStatsig", { enumerable: true, get: function () { return StatsigVercelClient_1.handleWithStatsig; } });
|