Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ export default [
"**/examples/",
"**/vite.config.ts",
"packages/clients/.eslintrc.cjs",
"packages/client/.eslintrc.cjs",
"eslint.config.mjs",
"packages/clients/src/vendor/base64/index.js",
"packages/client/src/vendor/base64/index.js",
"packages/configuration-loader/.eslintrc.cjs",

],
Expand Down
10 changes: 10 additions & 0 deletions packages/client/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { join } = require('path');

module.exports = {
rules: {
'import/no-extraneous-dependencies': [
'error',
{ packageDir: [__dirname, join(__dirname, '../../')] }
]
}
};
5 changes: 5 additions & 0 deletions packages/client/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/__tests__/**
examples/
src
.eslintrc.cjs
!.npmignore
4 changes: 4 additions & 0 deletions packages/client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
35 changes: 35 additions & 0 deletions packages/client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Scaleway SDK Client

This SDK Client enables you to interact with Scaleway APIs.

**🔗  Important links:**
* [Reference documentation](https://scaleway.github.io/scaleway-sdk-js)
* [Example projects](https://github.com/scaleway/scaleway-sdk-js/tree/master/examples)
* [Developers website](https://developers.scaleway.com) (API documentation)

## Getting Started

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.

**A minimal setup** would look like this:

```ts
import { createClient } from '@scaleway/sdk-client'
import { Registry } from '@scaleway/sdk'

const client = createClient({
accessKey: 'SCWXXXXXXXXXXXXXXXXX',
secretKey: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
defaultProjectId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
defaultRegion: 'fr-par',
defaultZone: 'fr-par-1',
})

const api = new Registry.v1.API(client)
```

**For more information**, please check the [GitHub project](https://github.com/scaleway/scaleway-sdk-js).

## Reach us

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).
37 changes: 37 additions & 0 deletions packages/client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@scaleway/sdk-client",
"version": "1.0.0",
"license": "Apache-2.0",
"description": "Scaleway SDK Client",
"keywords": [
"scaleway",
"cloud",
"sdk",
"client"
],
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"version": "./scripts/update-constants-file.sh",
"typecheck": "tsc --noEmit",
"type:generate": "tsc --declaration -p tsconfig.build.json",
"build": "vite build --config ../../vite.config.ts && pnpm run type:generate && tsc-alias -p tsconfig.build.json",
"build:profile": "npx vite-bundle-visualizer -c ../../vite.config.ts"
},
"files": [
"dist"
],
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/scaleway/scaleway-sdk-js",
"directory": "packages/clients"
},
"engines": {
"node": ">=18.0"
},
"type": "module"
}
36 changes: 36 additions & 0 deletions packages/client/src/bridge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/** List all helpers required by APIs */
export { isJSONObject } from './helpers/json'
export { waitForResource } from './internal/async/interval-retrier'
export type { WaitForOptions } from './internal/async/interval-retrier'
export { API } from './scw/api'
export type { DefaultValues } from './scw/client-settings'
export type {
Money,
ServiceInfo,
ScwFile,
TimeSeries,
} from './scw/custom-types'
export { Decimal } from './scw/custom-types'
export {
marshalScwFile,
marshalMoney,
marshalTimeSeries,
marshalDecimal,
marshalBlobToScwFile,
unmarshalMoney,
unmarshalScwFile,
unmarshalServiceInfo,
unmarshalTimeSeries,
unmarshalTimeSeriesPoint,
unmarshalDecimal,
} from './scw/custom-marshalling'
export { enrichForPagination } from './scw/fetch/resource-paginator'
export type { Region, Zone } from './scw/locality'
export {
resolveOneOf,
unmarshalDate,
unmarshalArrayOfObject,
unmarshalMapOfObject,
urlParams,
validatePathParam,
} from './helpers/marshalling'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @vitest-environment jsdom
import { describe, expect, it } from 'vitest'
import { isBrowser } from '../is-browser'

describe('isBrowser', () => {
it('returns true by default', () => {
expect(isBrowser()).toBe(true)
})
})
10 changes: 10 additions & 0 deletions packages/client/src/helpers/__tests__/is-browser.node.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @vitest-environment node

import { describe, expect, it } from 'vitest'
import { isBrowser } from '../is-browser'

describe('isBrowser', () => {
it('returns false by default', () => {
expect(isBrowser()).toBe(false)
})
})
40 changes: 40 additions & 0 deletions packages/client/src/helpers/__tests__/json.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { describe, expect, test } from 'vitest'
import { isJSON, isJSONObject } from '../json'

describe('isJSON', () => {
test.each(['str', 200, true, null, [true, 'two', 3], { key: 'value' }])(
`accepts %s as a valid JSON value`,
obj => {
expect(isJSON(obj)).toBeTruthy()
},
)

test.each([undefined, () => {}, Symbol(42)])(
`rejects %s as a valid JSON value`,
obj => {
expect(isJSON(obj)).toBeFalsy()
},
)
})

describe('isJSONObject', () => {
test.each([{ key: 'value' }])(
`accepts %s as a valid JSONObject value`,
obj => {
expect(isJSONObject(obj)).toBeTruthy()
},
)

test.each([
'str',
200,
true,
null,
[true, 'two', 3],
undefined,
() => {},
Symbol(42),
])(`rejects %s as a valid JSONObject value`, obj => {
expect(isJSONObject(obj)).toBeFalsy()
})
})
Loading
Loading