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
22 changes: 11 additions & 11 deletions .github/workflows/check-pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
name: Check Pull Request
on:
pull_request:
types: ['opened', 'edited', 'reopened', 'synchronize']
types: ["opened", "edited", "reopened", "synchronize"]

jobs:
check-title:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3.3.0
- uses: pnpm/action-setup@v2.2.4
- name: Use Node.js
uses: actions/setup-node@v3.6.0
with:
node-version: 17
check-latest: true
cache: 'pnpm'
- run: pnpm install
- run: echo '${{ github.event.pull_request.title }}' | pnpm commitlint
- uses: actions/checkout@v3.3.0
- uses: pnpm/action-setup@v2.2.4
- name: Use Node.js
uses: actions/setup-node@v3.6.0
with:
node-version: 18
check-latest: true
cache: "pnpm"
- run: pnpm install
- run: echo '${{ github.event.pull_request.title }}' | pnpm commitlint
6 changes: 3 additions & 3 deletions .github/workflows/deploy-doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
# Runs on tags
push:
tags:
- '**'
- "**"

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down Expand Up @@ -39,9 +39,9 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v3.6.0
with:
node-version: 17
node-version: 18
check-latest: true
cache: 'pnpm'
cache: "pnpm"
- name: Setup Pages
id: pages
uses: actions/configure-pages@v2
Expand Down
54 changes: 27 additions & 27 deletions .github/workflows/deploy-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ jobs:
runs-on: ubuntu-20.04
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3.3.0
with:
fetch-depth: "0"
persist-credentials: false
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Git Identity
run: |
git config --global user.name 'scaleway-bot'
git config --global user.email 'github@scaleway.com'
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/$GITHUB_REPOSITORY
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- uses: pnpm/action-setup@v2.2.4
- name: Use Node.js
uses: actions/setup-node@v3.6.0
with:
node-version: 17
check-latest: true
- run: pnpm install
- run: pnpm run build
- run: echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: pnpm lerna publish -y --create-release github
env:
HUSKY: 0
GH_TOKEN: ${{ secrets.GH_TOKEN }}
- uses: actions/checkout@v3.3.0
with:
fetch-depth: "0"
persist-credentials: false
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Git Identity
run: |
git config --global user.name 'scaleway-bot'
git config --global user.email 'github@scaleway.com'
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/$GITHUB_REPOSITORY
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- uses: pnpm/action-setup@v2.2.4
- name: Use Node.js
uses: actions/setup-node@v3.6.0
with:
node-version: 18
check-latest: true
- run: pnpm install
- run: pnpm run build
- run: echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: pnpm lerna publish -y --create-release github
env:
HUSKY: 0
GH_TOKEN: ${{ secrets.GH_TOKEN }}
76 changes: 40 additions & 36 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,51 @@ jobs:
typecheck:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3.3.0
- uses: pnpm/action-setup@v2.2.4
- name: Use Node.js
uses: actions/setup-node@v3.6.0
with:
node-version: 17
check-latest: true
cache: 'pnpm'
- run: pnpm install
- run: pnpm run build
- run: pnpm tsc --noEmit
- uses: actions/checkout@v3.3.0
- uses: pnpm/action-setup@v2.2.4
- name: Use Node.js
uses: actions/setup-node@v3.6.0
with:
node-version: 17
check-latest: true
cache: "pnpm"
- run: pnpm install
- run: pnpm run build
- run: pnpm tsc --noEmit
lint:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3.3.0
- uses: pnpm/action-setup@v2.2.4
- name: Use Node.js
uses: actions/setup-node@v3.6.0
with:
node-version: 17
check-latest: true
cache: 'pnpm'
- run: pnpm install
- run: pnpm run build
- run: pnpm run lint
- uses: actions/checkout@v3.3.0
- uses: pnpm/action-setup@v2.2.4
- name: Use Node.js
uses: actions/setup-node@v3.6.0
with:
node-version: 18
check-latest: true
cache: "pnpm"
- run: pnpm install
- run: pnpm run build
- run: pnpm run lint
test:
runs-on: ubuntu-20.04
strategy:
matrix:
node: [ '14', '16', '17' ]
test-environment:
- node
- jsdom
node:
- "18"
- "19"
steps:
- uses: actions/checkout@v3.3.0
- uses: pnpm/action-setup@v2.2.4
- name: Use Node.js
uses: actions/setup-node@v3.6.0
with:
node-version: ${{ matrix.node }}
check-latest: true
cache: 'pnpm'
- run: pnpm install
- run: pnpm run build
- run: pnpm run test:coverage
- uses: codecov/codecov-action@v3.1.1

- uses: actions/checkout@v3.3.0
- uses: pnpm/action-setup@v2.2.4
- name: Use Node.js
uses: actions/setup-node@v3.6.0
with:
node-version: ${{ matrix.node }}
check-latest: true
cache: "pnpm"
- run: pnpm install
- run: pnpm run build
- run: pnpm run test:coverage --testEnvironment ${{ matrix.test-environment }}
- uses: codecov/codecov-action@v3.1.1
31 changes: 5 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const client = createClient(profile)

**For more advanced needs**, please check the examples.

## Pagination
### Pagination

We included some pagination helpers for the methods supporting the feature. Let's take `listNamespaces()` (Registry product) as an example:

Expand All @@ -67,42 +67,21 @@ for await (const page of api.listNamespaces()) {
}
```

## Types
### Types

The project is coded with Typescript, so don't hesitate to take advantage of it.

1. All **types of a product** are stored in the `Product.version` namespace. For instance, the `Image` interface of Registry v1 can be accessed with `Registry.v1.Image`.

2. We export **errors** in the namespace `Errors`, allowing you to differentiate the cases (e.g. `Errors.PermissionsDeniedError`).

## Dependencies
## Notes

This SDK is based on the [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) API and uses `Request`, `Response` & `Headers` interfaces. Those interfaces are native in modern browsers, node >=18 & [deno](https://deno.land/) environments.

For `node` < 18 & `React Native` environments, the commonJS build requires [cross-fetch](https://www.npmjs.com/package/cross-fetch) package, it is listed in `dependencies` but not used in esm build.

**Troubleshooting**

In node environment, the commonJS module defined in `dist/index.cjs` entry file is used by default, thanks to the "main" `package.json` field.

If you want to use the ES module from `dist/index.js` with node < 18 & `React Native` environments, we recommend you to explicitly import [cross-fetch](https://www.npmjs.com/package/cross-fetch) polyfill:

```ts
import 'cross-fetch/polyfill'
import {...} from '@scaleway/sdk'
```

or

```bash
node -r cross-fetch/polyfill ./script-using-sdk.mjs
```

## Development
### Contributing Guidelines

This repository is at its early stage and is still in active development.
If you are looking for a way to contribute please read [CONTRIBUTING.md](./CONTRIBUTING.md).

## Reach us
### 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).
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/nodejs-minimal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@scaleway/sdk": "^0.1.0-beta"
},
"devDependencies": {
"@types/node": "^17.0.45",
"@types/node": "^18.11.18",
"typescript": "^4.9.4"
}
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"packages/*"
],
"engines": {
"node": ">=14.13",
"node": ">=18.0",
"pnpm": ">=7.25.1"
},
"type": "module",
Expand Down Expand Up @@ -37,6 +37,9 @@
]
},
"jest": {
"setupFiles": [
"./env-setup.ts"
],
"collectCoverageFrom": [
"packages/*/src/**/*.{ts,tsx}"
],
Expand All @@ -61,9 +64,6 @@
],
"transformIgnorePatterns": [
"node_modules/(?!(.*(@scaleway)))"
],
"setupFiles": [
"./setupTests.ts"
]
},
"devDependencies": {
Expand All @@ -76,7 +76,6 @@
"@jest/globals": "^29.3.1",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-inject": "^5.0.3",
"@rollup/plugin-node-resolve": "^15.0.1",
"@scaleway/eslint-config-react": "^3.14.1",
"@types/jest": "^29.2.6",
Expand All @@ -88,6 +87,7 @@
"eslint-plugin-tsdoc": "^0.2.17",
"husky": "^8.0.3",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.4.0",
"jest-junit": "^15.0.0",
"lerna": "^6.4.1",
"lint-staged": "^13.1.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/clients/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
},
"type": "module",
"dependencies": {
"@scaleway/random-name": "^4.0.1",
"cross-fetch": "^3.1.5"
"@scaleway/random-name": "^4.0.1"
},
"bundledDependencies": [
"@scaleway/random-name"
Expand Down
13 changes: 0 additions & 13 deletions packages/clients/src/fetch.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/clients/src/helpers/__tests__/is-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isBrowser } from '../is-browser'

describe('isBrowser', () => {
it('returns false by default', () => {
expect(isBrowser()).toBe(false)
expect(isBrowser()).toBe(!!global.window)
})

it('returns true after defining a window', () => {
Expand Down
16 changes: 12 additions & 4 deletions packages/clients/src/scw/fetch/__tests__/build-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { afterAll, describe, expect, it, jest } from '@jest/globals'
import { isBrowser } from '../../../helpers/is-browser'
import type { Settings } from '../../client-settings'
import { buildFetcher, buildRequest } from '../build-fetcher'
import type { ScwRequest } from '../types'
Expand Down Expand Up @@ -30,10 +31,17 @@ describe(`buildRequest`, () => {
expect(fReq.headers.get('accept')).toBe(`application/json`)
})

it(`has the default header "User-Agent: 'scaleway-sdk-js/v1.0.0'"`, () => {
const fReq = buildRequest(SCW_POST_REQUEST, DEFAULT_SETTINGS)
expect(fReq.headers.get('User-Agent')).toBe(DEFAULT_SETTINGS.userAgent)
})
if (!isBrowser()) {
it(`has the default header "User-Agent: 'scaleway-sdk-js/v1.0.0'"`, () => {
const fReq = buildRequest(SCW_POST_REQUEST, DEFAULT_SETTINGS)
expect(fReq.headers.get('User-Agent')).toBe(DEFAULT_SETTINGS.userAgent)
})
} else {
it(`has NOT the default header "User-Agent: 'scaleway-sdk-js/v1.0.0'"`, () => {
const fReq = buildRequest(SCW_POST_REQUEST, DEFAULT_SETTINGS)
expect(fReq.headers.get('User-Agent')).toBeNull()
})
}

it(`has NOT the header "User-Agent" when browser is detected`, () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down
Loading