Skip to content

Commit c6ff3d5

Browse files
authored
Add support for Cloudflare Workers and Bun (#3)
* Implement experimental support for Cloudflare Workers * Implement experimental support for Bun * Add sample app for Bun * Add sample app for Cloudflare Workers * Remove proxy from common client options * Improve debug logging * Update README.md * Bump version * npm audit fix * Temporary disable tests on ubuntu-latest and macOS-latest for Bun
1 parent 9e67406 commit c6ff3d5

File tree

105 files changed

+2077
-11225
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+2077
-11225
lines changed

.github/workflows/js-sdk-ci.yml

Lines changed: 77 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,6 @@ jobs:
2828
- name: Run check
2929
run: npm run check:ts-compat
3030

31-
test-node:
32-
runs-on: ${{ matrix.os }}
33-
strategy:
34-
matrix:
35-
node-version: [14.x, 16.x, 18.x, 20.x, 22.x]
36-
os: [ubuntu-latest, windows-latest, macOS-latest]
37-
exclude:
38-
- node-version: 14.x
39-
os: macOS-latest
40-
name: Node.js ${{ matrix.node-version }} (${{ matrix.os }}) test
41-
steps:
42-
- uses: actions/checkout@v4
43-
44-
- uses: actions/setup-node@v4
45-
with:
46-
node-version: ${{ matrix.node-version }}
47-
48-
- name: Install dependencies & build
49-
run: npm install
50-
51-
- name: Test
52-
run: npm run test:node
53-
5431
test-browser-chrome:
5532
runs-on: ubuntu-latest
5633
strategy:
@@ -62,7 +39,7 @@ jobs:
6239

6340
- uses: actions/setup-node@v4
6441
with:
65-
node-version: 14
42+
node-version: 18
6643

6744
- name: Setup chrome
6845
uses: browser-actions/setup-chrome@latest
@@ -86,7 +63,7 @@ jobs:
8663

8764
- uses: actions/setup-node@v4
8865
with:
89-
node-version: 14
66+
node-version: 18
9067

9168
- name: Setup chrome
9269
uses: browser-actions/setup-chrome@latest
@@ -110,7 +87,7 @@ jobs:
11087

11188
- uses: actions/setup-node@v4
11289
with:
113-
node-version: 14
90+
node-version: 18
11491

11592
- name: Setup firefox
11693
uses: browser-actions/setup-firefox@latest
@@ -123,6 +100,30 @@ jobs:
123100
- name: Test
124101
run: npm run test:browser:firefox
125102

103+
test-bun:
104+
runs-on: ${{ matrix.os }}
105+
strategy:
106+
matrix:
107+
bun-version: ["1.1.0", "1.1.34"]
108+
# Bun fails to run tests on ubuntu-latest and macOS-latest.
109+
# It may not be possible at all for now: https://github.com/oven-sh/bun/issues/10001
110+
# Bun version "latest" (1.1.36) seems to have a regression,
111+
# so we use 1.1.34 until it fixed.
112+
os: [windows-latest]
113+
name: Bun ${{ matrix.bun-version }} (${{ matrix.os }}) test
114+
steps:
115+
- uses: actions/checkout@v4
116+
117+
- uses: oven-sh/setup-bun@v2
118+
with:
119+
bun-version: ${{ matrix.bun-version }}
120+
121+
- name: Install dependencies & build
122+
run: npm install
123+
124+
- name: Test
125+
run: npm run test:bun
126+
126127
test-chromium-extension-chrome:
127128
runs-on: ubuntu-latest
128129
strategy:
@@ -134,7 +135,7 @@ jobs:
134135

135136
- uses: actions/setup-node@v4
136137
with:
137-
node-version: 14
138+
node-version: 18
138139

139140
- name: Setup chrome
140141
uses: browser-actions/setup-chrome@latest
@@ -158,7 +159,7 @@ jobs:
158159

159160
- uses: actions/setup-node@v4
160161
with:
161-
node-version: 14
162+
node-version: 18
162163

163164
- name: Setup chrome
164165
uses: browser-actions/setup-chrome@latest
@@ -171,6 +172,25 @@ jobs:
171172
- name: Test
172173
run: CHROMIUM_BIN=$(which chrome) npm run test:chromium-extension:chromium
173174

175+
test-cloudflare-worker:
176+
runs-on: ${{ matrix.os }}
177+
strategy:
178+
matrix:
179+
os: [ubuntu-latest]
180+
name: Cloudflare Worker (${{ matrix.os }}) test
181+
steps:
182+
- uses: actions/checkout@v4
183+
184+
- uses: actions/setup-node@v4
185+
with:
186+
node-version: 18
187+
188+
- name: Install dependencies & build
189+
run: npm install
190+
191+
- name: Test
192+
run: npm run test:cloudflare-worker
193+
174194
test-deno:
175195
runs-on: ${{ matrix.os }}
176196
strategy:
@@ -196,13 +216,38 @@ jobs:
196216
- name: Test
197217
run: npm run test:deno
198218

219+
test-node:
220+
runs-on: ${{ matrix.os }}
221+
strategy:
222+
matrix:
223+
node-version: [14.x, 16.x, 18.x, 20.x, 22.x]
224+
os: [ubuntu-latest, windows-latest, macOS-latest]
225+
exclude:
226+
- node-version: 14.x
227+
os: macOS-latest
228+
name: Node.js ${{ matrix.node-version }} (${{ matrix.os }}) test
229+
steps:
230+
- uses: actions/checkout@v4
231+
232+
- uses: actions/setup-node@v4
233+
with:
234+
node-version: ${{ matrix.node-version }}
235+
236+
- name: Install dependencies & build
237+
run: npm install
238+
239+
- name: Test
240+
run: npm run test:node
241+
199242
coverage:
200243
needs: [
201244
check-ts-compat,
202-
test-node,
203245
test-browser-chrome, test-browser-chromium, test-browser-firefox,
246+
test-bun,
204247
test-chromium-extension-chrome, test-chromium-extension-chromium,
205-
test-deno
248+
test-cloudflare-worker,
249+
test-deno,
250+
test-node
206251
]
207252
runs-on: ubuntu-latest
208253
steps:
@@ -211,7 +256,7 @@ jobs:
211256
fetch-depth: 0
212257
- uses: actions/setup-node@v4
213258
with:
214-
node-version: 14
259+
node-version: 18
215260

216261
- name: Install dependencies & build
217262
run: npm install
@@ -240,7 +285,7 @@ jobs:
240285

241286
- uses: actions/setup-node@v4
242287
with:
243-
node-version: 14
288+
node-version: 18
244289
registry-url: 'https://registry.npmjs.org'
245290

246291
- name: Install dependencies

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,6 @@ lib/
6161
dist/
6262
.idea/
6363
.parcel-cache/
64+
bun.lockb
6465
deno.lock
65-
deno.import-map.json
66+
deno.import-map.json

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ lib/**/*.map
2626
test/
2727
tsconfig*.json
2828
types/
29-
webpack.*.config.js
29+
webpack.*.config.js
30+
workerd.config.capnp

.vscode/launch.json

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,45 @@
3030
"/base/": "${workspaceRoot}/"
3131
}
3232
},
33+
{
34+
// This configuration needs the `oven.bun-vscode` extension to be installed.
35+
"type": "bun",
36+
"name": "Run tests (Bun)",
37+
"request": "launch",
38+
"cwd": "${workspaceFolder}",
39+
"runtime": "bun",
40+
"runtimeArgs": ["--tsconfig-override ./tsconfig.mocha.bun.json"],
41+
"program": "./node_modules/mocha/bin/mocha.js",
42+
"args": [
43+
"test/bun/index.ts",
44+
"--fgrep",
45+
"",
46+
"--color",
47+
"--exit",
48+
"--timeout",
49+
"30000"
50+
],
51+
"noDebug": false,
52+
},
53+
{
54+
"type": "node",
55+
"name": "Run tests (Deno)",
56+
"request": "launch",
57+
"cwd": "${workspaceFolder}",
58+
"runtimeExecutable": "deno",
59+
"runtimeArgs": [
60+
"run",
61+
"--inspect",
62+
"-A",
63+
"test/deno/index.ts",
64+
"--fgrep",
65+
"",
66+
"--timeout",
67+
"30000"
68+
],
69+
"attachSimplePort": 9229,
70+
"outputCapture": "std"
71+
},
3372
{
3473
"type": "node",
3574
"request": "launch",
@@ -62,25 +101,6 @@
62101
"skipFiles": [
63102
"<node_internals>/**/*.js"
64103
]
65-
},
66-
{
67-
"type": "node",
68-
"name": "Run tests (Deno)",
69-
"request": "launch",
70-
"cwd": "${workspaceFolder}",
71-
"runtimeExecutable": "deno",
72-
"runtimeArgs": [
73-
"run",
74-
"--inspect-brk",
75-
"-A",
76-
"test/deno/index.ts",
77-
"--fgrep",
78-
"",
79-
"--timeout",
80-
"30000"
81-
],
82-
"attachSimplePort": 9229,
83-
"outputCapture": "std"
84104
}
85105
]
86106
}

README.md

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@
1111

1212
ConfigCat SDK for JavaScript provides easy integration for your application to [ConfigCat](https://configcat.com).
1313

14+
This repository hosts the next generation of the ConfigCat SDK for JavaScript platforms. It ships in the form of a single, unified NPM package for
15+
different JS platforms, as opposed to the one package per platform model used before.
16+
17+
The new SDK combines and, thus, supersedes these packages:
18+
* [configcat-common](https://www.npmjs.com/package/configcat-common)
19+
* [configcat-js](https://www.npmjs.com/package/configcat-js)
20+
* [configcat-js-ssr](https://www.npmjs.com/package/configcat-js-ssr)
21+
* [configcat-js-chromium-extension](https://www.npmjs.com/package/configcat-js-chromium-extension)
22+
* [configcat-node](https://www.npmjs.com/package/configcat-node)
23+
24+
The new SDK maintains backward compatibility, so it can be used as a drop-in replacement for the packages listed above. In most cases you just need to
25+
replace the old package with the new and adjust the import specifiers (as shown [here](#1-install-and-import-package)).
26+
27+
> [!CAUTION]
28+
> Please note that the SDK is still under development and is currently in beta phase. Use it at your own risk.
29+
1430
## Getting Started
1531

1632
### 1. Install and import package:
@@ -25,7 +41,7 @@ npm i @configcat/sdk
2541

2642
Then import it into your application:
2743

28-
* Frontend applications running in the browser:
44+
* Frontend applications and Web Workers running in the browser:
2945
```js
3046
import * as configcat from "@configcat/sdk/browser";
3147
```
@@ -35,13 +51,23 @@ Then import it into your application:
3551
import * as configcat from "@configcat/sdk/node";
3652
```
3753

54+
* Bun backend applications:
55+
```js
56+
import * as configcat from "@configcat/sdk/bun";
57+
```
58+
3859
* Deno backend applications:
3960
```js
4061
import * as configcat from "npm:@configcat/sdk/deno";
4162
```
4263

4364
(To make this work, you may need to enable the [unstable-byonm](https://docs.deno.com/runtime/manual/tools/unstable_flags/#--unstable-byonm) feature or adjust your [import map](https://docs.deno.com/runtime/manual/basics/import_maps/).)
4465

66+
* Cloudflare Workers:
67+
```js
68+
import * as configcat from "@configcat/sdk/cloudflare-worker";
69+
```
70+
4571
* Extensions for Chromium-based browsers (Chrome, Edge, etc.):
4672
```js
4773
import * as configcat from "@configcat/sdk/chromium-extension";
@@ -53,7 +79,7 @@ Then import it into your application:
5379

5480
Import the package directly from a CDN server into your application:
5581

56-
* Frontend applications running in the browser:
82+
* Frontend applications and Web Workers running in the browser:
5783

5884
```html
5985
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@configcat/sdk@latest/dist/configcat.browser.umd.min.js"></script>
@@ -74,7 +100,7 @@ Import the package directly from a CDN server into your application:
74100
```
75101

76102
### 2. Go to the <a href="https://app.configcat.com/sdkkey" target="_blank">ConfigCat Dashboard</a> to get your *SDK Key*:
77-
![SDK-KEY](https://raw.githubusercontent.com/ConfigCat/js-sdk/master/media/readme02-3.png "SDK-KEY")
103+
![SDK-KEY](https://raw.githubusercontent.com/configcat/js-unified-sdk/master/media/readme02-3.png "SDK-KEY")
78104

79105
### 3. Create a *ConfigCat* client instance:
80106
```js
@@ -131,7 +157,7 @@ if (value) {
131157
## Sample/Demo apps
132158
- [Plain HTML + JS](https://github.com/configcat/js-unified-sdk/tree/master/samples/html)
133159
- [Plain HTML + JS using ECMAScript module system](https://github.com/configcat/js-unified-sdk/tree/master/samples/html-esm)
134-
- [Plain HTML + bundled TS running the SDK in a Web Worker](https://github.com/configcat/js-unified-sdk/tree/master/samples/web-worker)
160+
- [Plain HTML + TS running the SDK in a Web Worker](https://github.com/configcat/js-unified-sdk/tree/master/samples/web-worker)
135161
- [Sample Angular web application](https://github.com/configcat/js-unified-sdk/tree/master/samples/angular-sample)
136162
- [Sample React web application](https://github.com/configcat/js-unified-sdk/tree/master/samples/react-sample)
137163
- [Sample React Native application](https://github.com/configcat/js-unified-sdk/tree/master/samples/react-native-sample)
@@ -142,7 +168,9 @@ if (value) {
142168
- [Sample Node.js console application using TypeScript and ECMAScript module system](https://github.com/configcat/js-unified-sdk/tree/master/samples/ts-node-console-esm)
143169
- [Sample Node.js application using Express and Docker](https://github.com/configcat/js-unified-sdk/tree/master/samples/node-expresswithdocker)
144170
- [Sample Node.js application on how to get real time updates on feature flag changes](https://github.com/configcat/js-unified-sdk/tree/master/samples/node-realtimeupdate)
171+
- [Sample Bun console application](https://github.com/configcat/js-unified-sdk/tree/master/samples/bun-console)
145172
- [Sample Deno console application](https://github.com/configcat/js-unified-sdk/tree/master/samples/deno-console)
173+
- [Sample Cloudflare Worker](https://github.com/configcat/js-unified-sdk/tree/master/samples/cloudflare-worker)
146174
- [Sample Chrome extension](https://github.com/configcat/js-unified-sdk/tree/master/samples/chrome-extension)
147175

148176
## Polling Modes
@@ -193,13 +221,17 @@ The SDK is [tested](https://github.com/configcat/js-unified-sdk/blob/master/.git
193221
- Chrome (stable, latest, beta)
194222
- Chromium (64.0.3282.0, 72.0.3626.0, 80.0.3987.0)
195223
- Firefox (latest, latest-beta, 84.0)
196-
- @configcat/sdk/chromium-extension:
197-
- Chrome (stable, latest, beta)
198-
- Chromium (72.0.3626.0, 80.0.3987.0)
224+
- @configcat/sdk/bun:
225+
- Bun (v1.1.0, v1.1.34) on Windows
199226
- @configcat/sdk/deno:
200227
- Deno (v1.31, v1.46, latest stable) on Windows / Ubuntu / macOS
201228
- @configcat/sdk/node:
202229
- Node.js (v14.x, v16.x, v18.x, v20.x, v22.x) on Windows / Ubuntu / macOS
230+
- @configcat/sdk/cloudflare-worker:
231+
- Workerd (2023-02-28)
232+
- @configcat/sdk/chromium-extension:
233+
- Chrome (stable, latest, beta)
234+
- Chromium (72.0.3626.0, 80.0.3987.0)
203235

204236
The SDK should be compatible with TypeScript v4.0.2 or newer. Earlier versions may work but those are not tested, thus, not supported officially.
205237

media/readme02-3.png

32.6 KB
Loading

0 commit comments

Comments
 (0)