Skip to content

Commit bcacb28

Browse files
feat: DVC-9055 extract JS Cloud Bucketing SDK from NodeJS SDK (#560)
1 parent dd220c4 commit bcacb28

Some content is hidden

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

53 files changed

+1251
-901
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"devDependencies": {
6767
"@babel/core": "^7.17.7",
6868
"@babel/preset-react": "^7.14.5",
69+
"@cloudflare/workers-types": "^4.20230914.0",
6970
"@commitlint/cli": "^16.2.3",
7071
"@commitlint/config-conventional": "^16.2.1",
7172
"@nrwl/js": "16.3.2",

sdk/js-cloud-server/.babelrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"presets": [
3+
[
4+
"@nx/js/babel",
5+
{
6+
"useBuiltIns": "usage"
7+
}
8+
]
9+
]
10+
}

sdk/js-cloud-server/.eslintrc.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": ["../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*", "node_modules/*", "src/pb-types/compiled*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7+
"rules": {}
8+
},
9+
{
10+
"files": ["*.ts", "*.tsx"],
11+
"rules": {}
12+
},
13+
{
14+
"files": ["*.js", "*.jsx"],
15+
"rules": {}
16+
}
17+
]
18+
}

sdk/js-cloud-server/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
built/*
2+
dist/*
3+
node_modules/*
4+
.npmrc

sdk/js-cloud-server/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# DevCycle Javascript Cloud Bucketing Server SDK
2+
3+
This SDK is used to integrate DevCycle with your Javascript server-side application, where a NodeJS runtime isn't available.
4+
Example use-cases would be Cloudflare Workers and other edge-worker runtimes.
5+
6+
This SDK makes API requests to DevCycle's [Bucketing API](https://docs.devcycle.com/bucketing-api/) to perform bucketing.
7+
See our [System Architecture Documentation](https://docs.devcycle.com/introduction/architecture#cloud-bucketing-server-sdk-architecture) for more details.
8+
9+
### Installation
10+
11+
Our library can be found on npm and installed by the following:
12+
13+
```
14+
npm install @devcycle/js-cloud-server-sdk"
15+
```
16+
17+
### Usage
18+
19+
To find usage documentation, visit our [docs](https://docs.devcycle.com/docs/sdk/server-side-sdks/node#usage).
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const { Request, Response } = jest.requireActual('cross-fetch')
2+
3+
const fetch = jest.fn()
4+
5+
export { Request, Response }
6+
export default fetch
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const fetchWithRetry = (_fetch: unknown): unknown => _fetch
2+
export default fetchWithRetry

sdk/nodejs/__tests__/cloudClient.spec.ts renamed to sdk/js-cloud-server/__tests__/cloudClient.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ describe('DevCycleCloudClient without EdgeDB', () => {
2121
beforeAll(async () => {
2222
client = DVC.initializeDevCycle('dvc_server_token', {
2323
logLevel: 'error',
24-
enableCloudBucketing: true,
2524
})
2625
server.listen()
2726
})
@@ -246,7 +245,6 @@ describe('DevCycleCloudClient with EdgeDB Enabled', () => {
246245
beforeAll(async () => {
247246
client = DVC.initializeDevCycle('dvc_server_token', {
248247
logLevel: 'error',
249-
enableCloudBucketing: true,
250248
enableEdgeDB: true,
251249
})
252250
server.listen()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { DevCycleCloudClient, initializeDevCycle } from '../src/index'
2+
3+
describe('JS Cloud Bucketing Server SDK Initialize', () => {
4+
afterAll(() => {
5+
jest.clearAllMocks()
6+
})
7+
8+
it('successfully calls initialize with no options', async () => {
9+
const client = initializeDevCycle('dvc_server_token')
10+
expect(client).toBeDefined()
11+
})
12+
13+
it('fails to initialize when no token is provided', () => {
14+
expect(() =>
15+
initializeDevCycle(undefined as unknown as string),
16+
).toThrow('Missing SDK key! Call initialize with a valid SDK key')
17+
})
18+
19+
it('fails to initialize when client token is provided', () => {
20+
expect(() => initializeDevCycle('dvc_client_token')).toThrow(
21+
'Invalid SDK key provided. Please call initialize with a valid server SDK key',
22+
)
23+
})
24+
})

sdk/nodejs/__tests__/models/populatedUser.spec.ts renamed to sdk/js-cloud-server/__tests__/models/populatedUser.spec.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ import { DevCycleUser } from '../../src/models/user'
33

44
describe('DVCPopulatedUser Unit Tests', () => {
55
it('should construct DVCPopulatedUser from UserParam', () => {
6-
const requestUser = new DVCPopulatedUser({
7-
user_id: 'user_id',
8-
email: 'email',
9-
name: 'name',
10-
language: 'en',
11-
country: 'ca',
12-
appVersion: 'appVersion',
13-
appBuild: 1,
14-
customData: { custom: 'data' },
15-
privateCustomData: { private: 'customData' },
16-
})
6+
const requestUser = new DVCPopulatedUser(
7+
{
8+
user_id: 'user_id',
9+
email: 'email',
10+
name: 'name',
11+
language: 'en',
12+
country: 'ca',
13+
appVersion: 'appVersion',
14+
appBuild: 1,
15+
customData: { custom: 'data' },
16+
privateCustomData: { private: 'customData' },
17+
},
18+
{},
19+
)
1720
expect(requestUser).toEqual(
1821
expect.objectContaining({
1922
user_id: 'user_id',
@@ -47,7 +50,7 @@ describe('DVCPopulatedUser Unit Tests', () => {
4750
customData: { custom: 'data' },
4851
privateCustomData: { private: 'customData' },
4952
})
50-
const populatedUser = DVCPopulatedUser.fromDVCUser(requestUser)
53+
const populatedUser = DVCPopulatedUser.fromDVCUser(requestUser, {})
5154
expect(populatedUser).toEqual(
5255
expect.objectContaining({
5356
user_id: 'user_id',

0 commit comments

Comments
 (0)