Skip to content

Commit cd3b131

Browse files
philibearemyleone
andauthored
feat(sdk): add client package (#1943)
Signed-off-by: Alexandre Philibeaux <[email protected]> Co-authored-by: Rémy Léone <[email protected]>
1 parent 63b65bd commit cd3b131

File tree

92 files changed

+6911
-0
lines changed

Some content is hidden

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

92 files changed

+6911
-0
lines changed

eslint.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ export default [
1515
"**/examples/",
1616
"**/vite.config.ts",
1717
"packages/clients/.eslintrc.cjs",
18+
"packages/client/.eslintrc.cjs",
1819
"eslint.config.mjs",
1920
"packages/clients/src/vendor/base64/index.js",
21+
"packages/client/src/vendor/base64/index.js",
2022
"packages/configuration-loader/.eslintrc.cjs",
2123

2224
],

packages/client/.eslintrc.cjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { join } = require('path');
2+
3+
module.exports = {
4+
rules: {
5+
'import/no-extraneous-dependencies': [
6+
'error',
7+
{ packageDir: [__dirname, join(__dirname, '../../')] }
8+
]
9+
}
10+
};

packages/client/.npmignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
**/__tests__/**
2+
examples/
3+
src
4+
.eslintrc.cjs
5+
!.npmignore

packages/client/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

packages/client/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Scaleway SDK Client
2+
3+
This SDK Client enables you to interact with Scaleway APIs.
4+
5+
**🔗  Important links:**
6+
* [Reference documentation](https://scaleway.github.io/scaleway-sdk-js)
7+
* [Example projects](https://github.com/scaleway/scaleway-sdk-js/tree/master/examples)
8+
* [Developers website](https://developers.scaleway.com) (API documentation)
9+
10+
## Getting Started
11+
12+
You'll need a pair of access and secret keys to connect to Scaleway API. Please check the [documentation](https://www.scaleway.com/en/docs/identity-and-access-management/iam/how-to/create-api-keys/) on how to retrieve them.
13+
14+
**A minimal setup** would look like this:
15+
16+
```ts
17+
import { createClient } from '@scaleway/sdk-client'
18+
import { Registry } from '@scaleway/sdk'
19+
20+
const client = createClient({
21+
accessKey: 'SCWXXXXXXXXXXXXXXXXX',
22+
secretKey: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
23+
defaultProjectId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
24+
defaultRegion: 'fr-par',
25+
defaultZone: 'fr-par-1',
26+
})
27+
28+
const api = new Registry.v1.API(client)
29+
```
30+
31+
**For more information**, please check the [GitHub project](https://github.com/scaleway/scaleway-sdk-js).
32+
33+
## Reach us
34+
35+
We love feedback. Feel free to reach us on [Scaleway Slack community](https://slack.scaleway.com/), we are waiting for you on [#opensource](https://scaleway-community.slack.com/app_redirect?channel=opensource).

packages/client/package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "@scaleway/sdk-client",
3+
"version": "1.0.0",
4+
"license": "Apache-2.0",
5+
"description": "Scaleway SDK Client",
6+
"keywords": [
7+
"scaleway",
8+
"cloud",
9+
"sdk",
10+
"client"
11+
],
12+
"main": "dist/index.cjs",
13+
"module": "dist/index.js",
14+
"types": "dist/index.d.ts",
15+
"scripts": {
16+
"version": "./scripts/update-constants-file.sh",
17+
"typecheck": "tsc --noEmit",
18+
"type:generate": "tsc --declaration -p tsconfig.build.json",
19+
"build": "vite build --config ../../vite.config.ts && pnpm run type:generate && tsc-alias -p tsconfig.build.json",
20+
"build:profile": "npx vite-bundle-visualizer -c ../../vite.config.ts"
21+
},
22+
"files": [
23+
"dist"
24+
],
25+
"publishConfig": {
26+
"access": "public"
27+
},
28+
"repository": {
29+
"type": "git",
30+
"url": "https://github.com/scaleway/scaleway-sdk-js",
31+
"directory": "packages/clients"
32+
},
33+
"engines": {
34+
"node": ">=18.0"
35+
},
36+
"type": "module"
37+
}

packages/client/src/bridge.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/** List all helpers required by APIs */
2+
export { isJSONObject } from './helpers/json'
3+
export { waitForResource } from './internal/async/interval-retrier'
4+
export type { WaitForOptions } from './internal/async/interval-retrier'
5+
export { API } from './scw/api'
6+
export type { DefaultValues } from './scw/client-settings'
7+
export type {
8+
Money,
9+
ServiceInfo,
10+
ScwFile,
11+
TimeSeries,
12+
} from './scw/custom-types'
13+
export { Decimal } from './scw/custom-types'
14+
export {
15+
marshalScwFile,
16+
marshalMoney,
17+
marshalTimeSeries,
18+
marshalDecimal,
19+
marshalBlobToScwFile,
20+
unmarshalMoney,
21+
unmarshalScwFile,
22+
unmarshalServiceInfo,
23+
unmarshalTimeSeries,
24+
unmarshalTimeSeriesPoint,
25+
unmarshalDecimal,
26+
} from './scw/custom-marshalling'
27+
export { enrichForPagination } from './scw/fetch/resource-paginator'
28+
export type { Region, Zone } from './scw/locality'
29+
export {
30+
resolveOneOf,
31+
unmarshalDate,
32+
unmarshalArrayOfObject,
33+
unmarshalMapOfObject,
34+
urlParams,
35+
validatePathParam,
36+
} from './helpers/marshalling'
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @vitest-environment jsdom
2+
import { describe, expect, it } from 'vitest'
3+
import { isBrowser } from '../is-browser'
4+
5+
describe('isBrowser', () => {
6+
it('returns true by default', () => {
7+
expect(isBrowser()).toBe(true)
8+
})
9+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @vitest-environment node
2+
3+
import { describe, expect, it } from 'vitest'
4+
import { isBrowser } from '../is-browser'
5+
6+
describe('isBrowser', () => {
7+
it('returns false by default', () => {
8+
expect(isBrowser()).toBe(false)
9+
})
10+
})
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { describe, expect, test } from 'vitest'
2+
import { isJSON, isJSONObject } from '../json'
3+
4+
describe('isJSON', () => {
5+
test.each(['str', 200, true, null, [true, 'two', 3], { key: 'value' }])(
6+
`accepts %s as a valid JSON value`,
7+
obj => {
8+
expect(isJSON(obj)).toBeTruthy()
9+
},
10+
)
11+
12+
test.each([undefined, () => {}, Symbol(42)])(
13+
`rejects %s as a valid JSON value`,
14+
obj => {
15+
expect(isJSON(obj)).toBeFalsy()
16+
},
17+
)
18+
})
19+
20+
describe('isJSONObject', () => {
21+
test.each([{ key: 'value' }])(
22+
`accepts %s as a valid JSONObject value`,
23+
obj => {
24+
expect(isJSONObject(obj)).toBeTruthy()
25+
},
26+
)
27+
28+
test.each([
29+
'str',
30+
200,
31+
true,
32+
null,
33+
[true, 'two', 3],
34+
undefined,
35+
() => {},
36+
Symbol(42),
37+
])(`rejects %s as a valid JSONObject value`, obj => {
38+
expect(isJSONObject(obj)).toBeFalsy()
39+
})
40+
})

0 commit comments

Comments
 (0)