From f7282cfd19102e3314c12bdf67a26dbe23b9550d Mon Sep 17 00:00:00 2001 From: Vincent Germain Date: Fri, 8 Jul 2022 13:29:59 +0200 Subject: [PATCH] feat: migrate to GitHub (#1) --- .editorconfig | 13 + .eslintignore | 3 + .eslintrc | 24 + .github/renovate.json | 82 + ...quest_title.yml => check_pull_request.yml} | 2 +- .github/workflows/run_tests.yml | 33 +- .gitignore | 20 + .husky/.gitignore | 1 + .husky/commit-msg | 7 + .husky/pre-commit | 7 + .husky/pre-push | 7 + .prettierignore | 4 + .prettierrc | 6 + CODE_OF_CONDUCT.md | 76 + CONTRIBUTING.md | 90 + LICENSE | 18 +- README.md | 108 + babel.config.json | 6 + examples/.eslintrc | 6 + examples/README.md | 81 + examples/nodejs-minimal/.gitignore | 7 + examples/nodejs-minimal/README.md | 11 + examples/nodejs-minimal/package.json | 18 + examples/nodejs-minimal/pnpm-workspace.yaml | 2 + examples/nodejs-minimal/src/index.ts | 42 + examples/nodejs-minimal/tsconfig.json | 12 + .../serverless-function-minimal/.env.template | 5 + .../serverless-function-minimal/.gitignore | 11 + examples/serverless-function-minimal/.npmrc | 2 + .../serverless-function-minimal/README.md | 15 + .../serverless-function-minimal/package.json | 20 + .../pnpm-workspace.yaml | 2 + .../serverless.yml | 28 + .../serverless-function-minimal/src/index.ts | 26 + .../serverless-function-minimal/tsconfig.json | 12 + lerna.json | 16 + package.json | 104 + packages/clients/.eslintrc.cjs | 10 + packages/clients/.npmignore | 5 + packages/clients/README.md | 46 + packages/clients/package.json | 36 + packages/clients/src/api/.eslintrc | 10 + packages/clients/src/api/account/index.ts | 1 + .../src/api/account/v2alpha1/api.gen.ts | 139 + .../clients/src/api/account/v2alpha1/index.ts | 2 + .../api/account/v2alpha1/marshalling.gen.ts | 92 + .../src/api/account/v2alpha1/types.gen.ts | 83 + .../clients/src/api/applesilicon/index.ts | 1 + .../src/api/applesilicon/v1alpha1/api.gen.ts | 330 + .../api/applesilicon/v1alpha1/content.gen.ts | 13 + .../src/api/applesilicon/v1alpha1/index.ts | 3 + .../applesilicon/v1alpha1/marshalling.gen.ts | 162 + .../api/applesilicon/v1alpha1/types.gen.ts | 213 + packages/clients/src/api/baremetal/index.ts | 1 + .../clients/src/api/baremetal/v1/api.gen.ts | 717 ++ .../clients/src/api/baremetal/v1/api.utils.ts | 51 + .../src/api/baremetal/v1/content.gen.ts | 18 + .../clients/src/api/baremetal/v1/index.ts | 3 + .../src/api/baremetal/v1/marshalling.gen.ts | 550 + .../clients/src/api/baremetal/v1/types.gen.ts | 701 ++ packages/clients/src/api/container/index.ts | 1 + .../src/api/container/v1beta1/api.gen.ts | 778 ++ .../src/api/container/v1beta1/content.gen.ts | 40 + .../src/api/container/v1beta1/index.ts | 3 + .../api/container/v1beta1/marshalling.gen.ts | 379 + .../src/api/container/v1beta1/types.gen.ts | 459 + packages/clients/src/api/domain/index.ts | 1 + .../clients/src/api/domain/v2beta1/api.gen.ts | 1305 +++ .../src/api/domain/v2beta1/content.gen.ts | 6 + .../clients/src/api/domain/v2beta1/index.ts | 6 + .../src/api/domain/v2beta1/marshalling.gen.ts | 1888 ++++ .../src/api/domain/v2beta1/types.gen.ts | 1201 +++ packages/clients/src/api/flexibleip/index.ts | 1 + .../src/api/flexibleip/v1alpha1/api.gen.ts | 315 + .../api/flexibleip/v1alpha1/content.gen.ts | 15 + .../src/api/flexibleip/v1alpha1/index.ts | 3 + .../flexibleip/v1alpha1/marshalling.gen.ts | 162 + .../src/api/flexibleip/v1alpha1/types.gen.ts | 227 + packages/clients/src/api/function/.eslintrc | 6 + packages/clients/src/api/function/index.ts | 1 + .../src/api/function/v1beta1/api.gen.ts | 850 ++ .../src/api/function/v1beta1/content.gen.ts | 40 + .../clients/src/api/function/v1beta1/index.ts | 3 + .../api/function/v1beta1/marshalling.gen.ts | 431 + .../src/api/function/v1beta1/types.gen.ts | 524 + packages/clients/src/api/iam/index.ts | 1 + .../clients/src/api/iam/v1alpha1/api.gen.ts | 851 ++ .../clients/src/api/iam/v1alpha1/index.ts | 2 + .../src/api/iam/v1alpha1/marshalling.gen.ts | 524 + .../clients/src/api/iam/v1alpha1/types.gen.ts | 776 ++ packages/clients/src/api/index.ts | 20 + packages/clients/src/api/instance/index.ts | 1 + .../clients/src/api/instance/v1/api.gen.ts | 1615 +++ .../clients/src/api/instance/v1/api.utils.ts | 469 + .../src/api/instance/v1/content.gen.ts | 54 + packages/clients/src/api/instance/v1/index.ts | 4 + .../src/api/instance/v1/marshalling.gen.ts | 2069 ++++ .../clients/src/api/instance/v1/types.gen.ts | 1549 +++ .../src/api/instance/v1/types.private.gen.ts | 271 + .../src/api/instance/v1/types.utils.ts | 96 + packages/clients/src/api/iot/index.ts | 1 + packages/clients/src/api/iot/v1/api.gen.ts | 916 ++ .../clients/src/api/iot/v1/content.gen.ts | 6 + packages/clients/src/api/iot/v1/index.ts | 3 + .../clients/src/api/iot/v1/marshalling.gen.ts | 725 ++ packages/clients/src/api/iot/v1/types.gen.ts | 921 ++ packages/clients/src/api/k8s/index.ts | 1 + packages/clients/src/api/k8s/v1/api.gen.ts | 644 ++ .../clients/src/api/k8s/v1/content.gen.ts | 25 + packages/clients/src/api/k8s/v1/index.ts | 3 + .../clients/src/api/k8s/v1/marshalling.gen.ts | 571 + packages/clients/src/api/k8s/v1/types.gen.ts | 1016 ++ .../src/api/k8s/v1/types.private.gen.ts | 10 + packages/clients/src/api/lb/index.ts | 1 + packages/clients/src/api/lb/v1/api.gen.ts | 2840 +++++ packages/clients/src/api/lb/v1/api.utils.ts | 165 + packages/clients/src/api/lb/v1/content.gen.ts | 32 + packages/clients/src/api/lb/v1/index.ts | 4 + .../clients/src/api/lb/v1/marshalling.gen.ts | 1641 +++ packages/clients/src/api/lb/v1/types.gen.ts | 2170 ++++ packages/clients/src/api/lb/v1/types.utils.ts | 15 + packages/clients/src/api/marketplace/index.ts | 1 + .../clients/src/api/marketplace/v1/api.gen.ts | 91 + .../clients/src/api/marketplace/v1/index.ts | 2 + .../src/api/marketplace/v1/marshalling.gen.ts | 133 + .../src/api/marketplace/v1/types.gen.ts | 100 + packages/clients/src/api/mnq/index.ts | 1 + .../clients/src/api/mnq/v1alpha1/api.gen.ts | 277 + .../clients/src/api/mnq/v1alpha1/index.ts | 2 + .../src/api/mnq/v1alpha1/marshalling.gen.ts | 220 + .../clients/src/api/mnq/v1alpha1/types.gen.ts | 160 + packages/clients/src/api/rdb/index.ts | 1 + packages/clients/src/api/rdb/v1/api.gen.ts | 1467 +++ .../clients/src/api/rdb/v1/content.gen.ts | 34 + packages/clients/src/api/rdb/v1/index.ts | 3 + .../clients/src/api/rdb/v1/marshalling.gen.ts | 1037 ++ packages/clients/src/api/rdb/v1/types.gen.ts | 1231 +++ packages/clients/src/api/redis/index.ts | 1 + .../clients/src/api/redis/v1alpha1/api.gen.ts | 628 ++ .../src/api/redis/v1alpha1/content.gen.ts | 11 + .../clients/src/api/redis/v1alpha1/index.ts | 3 + .../src/api/redis/v1alpha1/marshalling.gen.ts | 460 + .../src/api/redis/v1alpha1/types.gen.ts | 517 + packages/clients/src/api/registry/index.ts | 1 + .../clients/src/api/registry/v1/api.gen.ts | 405 + .../src/api/registry/v1/content.gen.ts | 12 + packages/clients/src/api/registry/v1/index.ts | 3 + .../src/api/registry/v1/marshalling.gen.ts | 160 + .../clients/src/api/registry/v1/types.gen.ts | 294 + packages/clients/src/api/test/index.ts | 1 + packages/clients/src/api/test/v1/api.gen.ts | 246 + .../clients/src/api/test/v1/content.gen.ts | 6 + packages/clients/src/api/test/v1/index.ts | 2 + .../src/api/test/v1/marshalling.gen.ts | 118 + packages/clients/src/api/test/v1/types.gen.ts | 119 + packages/clients/src/api/vpc/index.ts | 1 + packages/clients/src/api/vpc/v1/api.gen.ts | 167 + packages/clients/src/api/vpc/v1/index.ts | 2 + .../clients/src/api/vpc/v1/marshalling.gen.ts | 70 + packages/clients/src/api/vpc/v1/types.gen.ts | 95 + packages/clients/src/api/vpcgw/index.ts | 1 + packages/clients/src/api/vpcgw/v1/api.gen.ts | 969 ++ .../clients/src/api/vpcgw/v1/content.gen.ts | 19 + packages/clients/src/api/vpcgw/v1/index.ts | 3 + .../src/api/vpcgw/v1/marshalling.gen.ts | 519 + .../clients/src/api/vpcgw/v1/types.gen.ts | 900 ++ packages/clients/src/bridge.ts | 32 + packages/clients/src/fetch.d.ts | 12 + .../src/helpers/__tests__/is-browser.ts | 18 + .../clients/src/helpers/__tests__/json.ts | 40 + .../src/helpers/__tests__/marshalling.ts | 236 + packages/clients/src/helpers/is-browser.ts | 2 + packages/clients/src/helpers/json.ts | 37 + packages/clients/src/helpers/marshalling.ts | 155 + packages/clients/src/index.ts | 25 + .../async/__tests__/interval-retrier.ts | 171 + .../src/internal/async/__tests__/sleep.ts | 20 + .../src/internal/async/interval-retrier.ts | 199 + packages/clients/src/internal/async/sleep.ts | 12 + .../interceptors/__tests__/interceptor.ts | 37 + .../interceptors/__tests__/request.ts | 32 + .../src/internal/interceptors/interceptor.ts | 19 + .../src/internal/interceptors/request.ts | 41 + .../src/internal/interceptors/response.ts | 4 + .../src/internal/logger/__tests__/index.ts | 226 + .../src/internal/logger/console-logger.ts | 39 + packages/clients/src/internal/logger/index.ts | 36 + .../src/internal/logger/level-resolver.ts | 14 + .../clients/src/internal/logger/logger.ts | 14 + .../__tests__/string-validation.ts | 91 + .../internal/validations/string-validation.ts | 42 + packages/clients/src/internals.ts | 26 + packages/clients/src/scw/__tests__/api.ts | 18 + packages/clients/src/scw/__tests__/auth.ts | 98 + .../src/scw/__tests__/client-ini-factory.ts | 240 + .../src/scw/__tests__/client-ini-profile.ts | 79 + .../src/scw/__tests__/client-settings.ts | 58 + packages/clients/src/scw/__tests__/client.ts | 69 + .../src/scw/__tests__/custom-marshalling.ts | 203 + packages/clients/src/scw/api.ts | 10 + packages/clients/src/scw/auth.ts | 87 + .../clients/src/scw/client-ini-factory.ts | 102 + .../clients/src/scw/client-ini-profile.ts | 112 + packages/clients/src/scw/client-settings.ts | 114 + packages/clients/src/scw/client.ts | 102 + packages/clients/src/scw/constants.ts | 3 + .../clients/src/scw/custom-marshalling.ts | 137 + packages/clients/src/scw/custom-types.ts | 69 + .../src/scw/errors/__tests__/scw-error.ts | 75 + .../clients/src/scw/errors/__tests__/types.ts | 19 + .../clients/src/scw/errors/error-parser.ts | 123 + .../errors/non-standard/__tests__/index.ts | 155 + .../non-standard/invalid-request-mapper.ts | 49 + .../non-standard/unknown-resource-mapper.ts | 34 + .../src/scw/errors/scw-error-from-json.ts | 10 + packages/clients/src/scw/errors/scw-error.ts | 65 + .../scw/errors/standard/__tests__/index.ts | 433 + .../errors/standard/already-exists-error.ts | 41 + .../standard/denied-authentication-error.ts | 54 + .../clients/src/scw/errors/standard/index.ts | 20 + .../standard/invalid-arguments-error.ts | 91 + .../scw/errors/standard/out-of-stock-error.ts | 24 + .../standard/permissions-denied-error.ts | 66 + .../standard/precondition-failed-error.ts | 65 + .../errors/standard/quotas-exceeded-error.ts | 98 + .../errors/standard/resource-expired-error.ts | 41 + .../errors/standard/resource-locked-error.ts | 26 + .../standard/resource-not-found-error.ts | 30 + .../standard/too-many-requests-error.ts | 93 + .../errors/standard/transient-state-error.ts | 44 + packages/clients/src/scw/errors/types.ts | 27 + .../src/scw/fetch/__tests__/build-fetcher.ts | 116 + .../src/scw/fetch/__tests__/http-dumper.ts | 72 + .../scw/fetch/__tests__/http-interceptors.ts | 103 + .../scw/fetch/__tests__/resource-paginator.ts | 151 + .../scw/fetch/__tests__/response-parser.ts | 184 + .../clients/src/scw/fetch/build-fetcher.ts | 83 + packages/clients/src/scw/fetch/http-dumper.ts | 69 + .../src/scw/fetch/http-interceptors.ts | 94 + .../src/scw/fetch/resource-paginator.ts | 123 + .../clients/src/scw/fetch/response-parser.ts | 89 + packages/clients/src/scw/fetch/types.ts | 16 + packages/clients/src/scw/locality.ts | 10 + packages/configuration-loader/.eslintrc.cjs | 10 + packages/configuration-loader/.npmignore | 5 + packages/configuration-loader/README.md | 55 + packages/configuration-loader/package.json | 24 + .../src/__tests__/config-loader.ts | 89 + .../src/__tests__/data/scw-config.yaml | 10 + .../src/__tests__/path-resolver.ts | 53 + .../src/__tests__/yml-loader.ts | 54 + .../configuration-loader/src/config-loader.ts | 61 + packages/configuration-loader/src/env.ts | 24 + packages/configuration-loader/src/index.ts | 5 + .../configuration-loader/src/path-resolver.ts | 36 + packages/configuration-loader/src/types.ts | 69 + .../configuration-loader/src/yml-loader.ts | 72 + pnpm-lock.yaml | 9259 +++++++++++++++++ pnpm-workspace.yaml | 2 + rollup.config.mjs | 99 + setupTests.ts | 2 + tsconfig.json | 22 + typedoc.json | 10 + 263 files changed, 59052 insertions(+), 47 deletions(-) create mode 100644 .editorconfig create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .github/renovate.json rename .github/workflows/{check_pull_request_title.yml => check_pull_request.yml} (93%) create mode 100644 .gitignore create mode 100644 .husky/.gitignore create mode 100755 .husky/commit-msg create mode 100755 .husky/pre-commit create mode 100755 .husky/pre-push create mode 100644 .prettierignore create mode 100644 .prettierrc create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 README.md create mode 100644 babel.config.json create mode 100644 examples/.eslintrc create mode 100644 examples/README.md create mode 100644 examples/nodejs-minimal/.gitignore create mode 100644 examples/nodejs-minimal/README.md create mode 100644 examples/nodejs-minimal/package.json create mode 100644 examples/nodejs-minimal/pnpm-workspace.yaml create mode 100644 examples/nodejs-minimal/src/index.ts create mode 100644 examples/nodejs-minimal/tsconfig.json create mode 100644 examples/serverless-function-minimal/.env.template create mode 100644 examples/serverless-function-minimal/.gitignore create mode 100644 examples/serverless-function-minimal/.npmrc create mode 100644 examples/serverless-function-minimal/README.md create mode 100644 examples/serverless-function-minimal/package.json create mode 100644 examples/serverless-function-minimal/pnpm-workspace.yaml create mode 100644 examples/serverless-function-minimal/serverless.yml create mode 100644 examples/serverless-function-minimal/src/index.ts create mode 100644 examples/serverless-function-minimal/tsconfig.json create mode 100644 lerna.json create mode 100644 package.json create mode 100644 packages/clients/.eslintrc.cjs create mode 100644 packages/clients/.npmignore create mode 100644 packages/clients/README.md create mode 100644 packages/clients/package.json create mode 100644 packages/clients/src/api/.eslintrc create mode 100644 packages/clients/src/api/account/index.ts create mode 100644 packages/clients/src/api/account/v2alpha1/api.gen.ts create mode 100644 packages/clients/src/api/account/v2alpha1/index.ts create mode 100644 packages/clients/src/api/account/v2alpha1/marshalling.gen.ts create mode 100644 packages/clients/src/api/account/v2alpha1/types.gen.ts create mode 100644 packages/clients/src/api/applesilicon/index.ts create mode 100644 packages/clients/src/api/applesilicon/v1alpha1/api.gen.ts create mode 100644 packages/clients/src/api/applesilicon/v1alpha1/content.gen.ts create mode 100644 packages/clients/src/api/applesilicon/v1alpha1/index.ts create mode 100644 packages/clients/src/api/applesilicon/v1alpha1/marshalling.gen.ts create mode 100644 packages/clients/src/api/applesilicon/v1alpha1/types.gen.ts create mode 100644 packages/clients/src/api/baremetal/index.ts create mode 100644 packages/clients/src/api/baremetal/v1/api.gen.ts create mode 100644 packages/clients/src/api/baremetal/v1/api.utils.ts create mode 100644 packages/clients/src/api/baremetal/v1/content.gen.ts create mode 100644 packages/clients/src/api/baremetal/v1/index.ts create mode 100644 packages/clients/src/api/baremetal/v1/marshalling.gen.ts create mode 100644 packages/clients/src/api/baremetal/v1/types.gen.ts create mode 100644 packages/clients/src/api/container/index.ts create mode 100644 packages/clients/src/api/container/v1beta1/api.gen.ts create mode 100644 packages/clients/src/api/container/v1beta1/content.gen.ts create mode 100644 packages/clients/src/api/container/v1beta1/index.ts create mode 100644 packages/clients/src/api/container/v1beta1/marshalling.gen.ts create mode 100644 packages/clients/src/api/container/v1beta1/types.gen.ts create mode 100644 packages/clients/src/api/domain/index.ts create mode 100644 packages/clients/src/api/domain/v2beta1/api.gen.ts create mode 100644 packages/clients/src/api/domain/v2beta1/content.gen.ts create mode 100644 packages/clients/src/api/domain/v2beta1/index.ts create mode 100644 packages/clients/src/api/domain/v2beta1/marshalling.gen.ts create mode 100644 packages/clients/src/api/domain/v2beta1/types.gen.ts create mode 100644 packages/clients/src/api/flexibleip/index.ts create mode 100644 packages/clients/src/api/flexibleip/v1alpha1/api.gen.ts create mode 100644 packages/clients/src/api/flexibleip/v1alpha1/content.gen.ts create mode 100644 packages/clients/src/api/flexibleip/v1alpha1/index.ts create mode 100644 packages/clients/src/api/flexibleip/v1alpha1/marshalling.gen.ts create mode 100644 packages/clients/src/api/flexibleip/v1alpha1/types.gen.ts create mode 100644 packages/clients/src/api/function/.eslintrc create mode 100644 packages/clients/src/api/function/index.ts create mode 100644 packages/clients/src/api/function/v1beta1/api.gen.ts create mode 100644 packages/clients/src/api/function/v1beta1/content.gen.ts create mode 100644 packages/clients/src/api/function/v1beta1/index.ts create mode 100644 packages/clients/src/api/function/v1beta1/marshalling.gen.ts create mode 100644 packages/clients/src/api/function/v1beta1/types.gen.ts create mode 100644 packages/clients/src/api/iam/index.ts create mode 100644 packages/clients/src/api/iam/v1alpha1/api.gen.ts create mode 100644 packages/clients/src/api/iam/v1alpha1/index.ts create mode 100644 packages/clients/src/api/iam/v1alpha1/marshalling.gen.ts create mode 100644 packages/clients/src/api/iam/v1alpha1/types.gen.ts create mode 100644 packages/clients/src/api/index.ts create mode 100644 packages/clients/src/api/instance/index.ts create mode 100644 packages/clients/src/api/instance/v1/api.gen.ts create mode 100644 packages/clients/src/api/instance/v1/api.utils.ts create mode 100644 packages/clients/src/api/instance/v1/content.gen.ts create mode 100644 packages/clients/src/api/instance/v1/index.ts create mode 100644 packages/clients/src/api/instance/v1/marshalling.gen.ts create mode 100644 packages/clients/src/api/instance/v1/types.gen.ts create mode 100644 packages/clients/src/api/instance/v1/types.private.gen.ts create mode 100644 packages/clients/src/api/instance/v1/types.utils.ts create mode 100644 packages/clients/src/api/iot/index.ts create mode 100644 packages/clients/src/api/iot/v1/api.gen.ts create mode 100644 packages/clients/src/api/iot/v1/content.gen.ts create mode 100644 packages/clients/src/api/iot/v1/index.ts create mode 100644 packages/clients/src/api/iot/v1/marshalling.gen.ts create mode 100644 packages/clients/src/api/iot/v1/types.gen.ts create mode 100644 packages/clients/src/api/k8s/index.ts create mode 100644 packages/clients/src/api/k8s/v1/api.gen.ts create mode 100644 packages/clients/src/api/k8s/v1/content.gen.ts create mode 100644 packages/clients/src/api/k8s/v1/index.ts create mode 100644 packages/clients/src/api/k8s/v1/marshalling.gen.ts create mode 100644 packages/clients/src/api/k8s/v1/types.gen.ts create mode 100644 packages/clients/src/api/k8s/v1/types.private.gen.ts create mode 100644 packages/clients/src/api/lb/index.ts create mode 100644 packages/clients/src/api/lb/v1/api.gen.ts create mode 100644 packages/clients/src/api/lb/v1/api.utils.ts create mode 100644 packages/clients/src/api/lb/v1/content.gen.ts create mode 100644 packages/clients/src/api/lb/v1/index.ts create mode 100644 packages/clients/src/api/lb/v1/marshalling.gen.ts create mode 100644 packages/clients/src/api/lb/v1/types.gen.ts create mode 100644 packages/clients/src/api/lb/v1/types.utils.ts create mode 100644 packages/clients/src/api/marketplace/index.ts create mode 100644 packages/clients/src/api/marketplace/v1/api.gen.ts create mode 100644 packages/clients/src/api/marketplace/v1/index.ts create mode 100644 packages/clients/src/api/marketplace/v1/marshalling.gen.ts create mode 100644 packages/clients/src/api/marketplace/v1/types.gen.ts create mode 100644 packages/clients/src/api/mnq/index.ts create mode 100644 packages/clients/src/api/mnq/v1alpha1/api.gen.ts create mode 100644 packages/clients/src/api/mnq/v1alpha1/index.ts create mode 100644 packages/clients/src/api/mnq/v1alpha1/marshalling.gen.ts create mode 100644 packages/clients/src/api/mnq/v1alpha1/types.gen.ts create mode 100644 packages/clients/src/api/rdb/index.ts create mode 100644 packages/clients/src/api/rdb/v1/api.gen.ts create mode 100644 packages/clients/src/api/rdb/v1/content.gen.ts create mode 100644 packages/clients/src/api/rdb/v1/index.ts create mode 100644 packages/clients/src/api/rdb/v1/marshalling.gen.ts create mode 100644 packages/clients/src/api/rdb/v1/types.gen.ts create mode 100644 packages/clients/src/api/redis/index.ts create mode 100644 packages/clients/src/api/redis/v1alpha1/api.gen.ts create mode 100644 packages/clients/src/api/redis/v1alpha1/content.gen.ts create mode 100644 packages/clients/src/api/redis/v1alpha1/index.ts create mode 100644 packages/clients/src/api/redis/v1alpha1/marshalling.gen.ts create mode 100644 packages/clients/src/api/redis/v1alpha1/types.gen.ts create mode 100644 packages/clients/src/api/registry/index.ts create mode 100644 packages/clients/src/api/registry/v1/api.gen.ts create mode 100644 packages/clients/src/api/registry/v1/content.gen.ts create mode 100644 packages/clients/src/api/registry/v1/index.ts create mode 100644 packages/clients/src/api/registry/v1/marshalling.gen.ts create mode 100644 packages/clients/src/api/registry/v1/types.gen.ts create mode 100644 packages/clients/src/api/test/index.ts create mode 100644 packages/clients/src/api/test/v1/api.gen.ts create mode 100644 packages/clients/src/api/test/v1/content.gen.ts create mode 100644 packages/clients/src/api/test/v1/index.ts create mode 100644 packages/clients/src/api/test/v1/marshalling.gen.ts create mode 100644 packages/clients/src/api/test/v1/types.gen.ts create mode 100644 packages/clients/src/api/vpc/index.ts create mode 100644 packages/clients/src/api/vpc/v1/api.gen.ts create mode 100644 packages/clients/src/api/vpc/v1/index.ts create mode 100644 packages/clients/src/api/vpc/v1/marshalling.gen.ts create mode 100644 packages/clients/src/api/vpc/v1/types.gen.ts create mode 100644 packages/clients/src/api/vpcgw/index.ts create mode 100644 packages/clients/src/api/vpcgw/v1/api.gen.ts create mode 100644 packages/clients/src/api/vpcgw/v1/content.gen.ts create mode 100644 packages/clients/src/api/vpcgw/v1/index.ts create mode 100644 packages/clients/src/api/vpcgw/v1/marshalling.gen.ts create mode 100644 packages/clients/src/api/vpcgw/v1/types.gen.ts create mode 100644 packages/clients/src/bridge.ts create mode 100644 packages/clients/src/fetch.d.ts create mode 100644 packages/clients/src/helpers/__tests__/is-browser.ts create mode 100644 packages/clients/src/helpers/__tests__/json.ts create mode 100644 packages/clients/src/helpers/__tests__/marshalling.ts create mode 100644 packages/clients/src/helpers/is-browser.ts create mode 100644 packages/clients/src/helpers/json.ts create mode 100644 packages/clients/src/helpers/marshalling.ts create mode 100644 packages/clients/src/index.ts create mode 100644 packages/clients/src/internal/async/__tests__/interval-retrier.ts create mode 100644 packages/clients/src/internal/async/__tests__/sleep.ts create mode 100644 packages/clients/src/internal/async/interval-retrier.ts create mode 100644 packages/clients/src/internal/async/sleep.ts create mode 100644 packages/clients/src/internal/interceptors/__tests__/interceptor.ts create mode 100644 packages/clients/src/internal/interceptors/__tests__/request.ts create mode 100644 packages/clients/src/internal/interceptors/interceptor.ts create mode 100644 packages/clients/src/internal/interceptors/request.ts create mode 100644 packages/clients/src/internal/interceptors/response.ts create mode 100644 packages/clients/src/internal/logger/__tests__/index.ts create mode 100644 packages/clients/src/internal/logger/console-logger.ts create mode 100644 packages/clients/src/internal/logger/index.ts create mode 100644 packages/clients/src/internal/logger/level-resolver.ts create mode 100644 packages/clients/src/internal/logger/logger.ts create mode 100644 packages/clients/src/internal/validations/__tests__/string-validation.ts create mode 100644 packages/clients/src/internal/validations/string-validation.ts create mode 100644 packages/clients/src/internals.ts create mode 100644 packages/clients/src/scw/__tests__/api.ts create mode 100644 packages/clients/src/scw/__tests__/auth.ts create mode 100644 packages/clients/src/scw/__tests__/client-ini-factory.ts create mode 100644 packages/clients/src/scw/__tests__/client-ini-profile.ts create mode 100644 packages/clients/src/scw/__tests__/client-settings.ts create mode 100644 packages/clients/src/scw/__tests__/client.ts create mode 100644 packages/clients/src/scw/__tests__/custom-marshalling.ts create mode 100644 packages/clients/src/scw/api.ts create mode 100644 packages/clients/src/scw/auth.ts create mode 100644 packages/clients/src/scw/client-ini-factory.ts create mode 100644 packages/clients/src/scw/client-ini-profile.ts create mode 100644 packages/clients/src/scw/client-settings.ts create mode 100644 packages/clients/src/scw/client.ts create mode 100644 packages/clients/src/scw/constants.ts create mode 100644 packages/clients/src/scw/custom-marshalling.ts create mode 100644 packages/clients/src/scw/custom-types.ts create mode 100644 packages/clients/src/scw/errors/__tests__/scw-error.ts create mode 100644 packages/clients/src/scw/errors/__tests__/types.ts create mode 100644 packages/clients/src/scw/errors/error-parser.ts create mode 100644 packages/clients/src/scw/errors/non-standard/__tests__/index.ts create mode 100644 packages/clients/src/scw/errors/non-standard/invalid-request-mapper.ts create mode 100644 packages/clients/src/scw/errors/non-standard/unknown-resource-mapper.ts create mode 100644 packages/clients/src/scw/errors/scw-error-from-json.ts create mode 100644 packages/clients/src/scw/errors/scw-error.ts create mode 100644 packages/clients/src/scw/errors/standard/__tests__/index.ts create mode 100644 packages/clients/src/scw/errors/standard/already-exists-error.ts create mode 100644 packages/clients/src/scw/errors/standard/denied-authentication-error.ts create mode 100644 packages/clients/src/scw/errors/standard/index.ts create mode 100644 packages/clients/src/scw/errors/standard/invalid-arguments-error.ts create mode 100644 packages/clients/src/scw/errors/standard/out-of-stock-error.ts create mode 100644 packages/clients/src/scw/errors/standard/permissions-denied-error.ts create mode 100644 packages/clients/src/scw/errors/standard/precondition-failed-error.ts create mode 100644 packages/clients/src/scw/errors/standard/quotas-exceeded-error.ts create mode 100644 packages/clients/src/scw/errors/standard/resource-expired-error.ts create mode 100644 packages/clients/src/scw/errors/standard/resource-locked-error.ts create mode 100644 packages/clients/src/scw/errors/standard/resource-not-found-error.ts create mode 100644 packages/clients/src/scw/errors/standard/too-many-requests-error.ts create mode 100644 packages/clients/src/scw/errors/standard/transient-state-error.ts create mode 100644 packages/clients/src/scw/errors/types.ts create mode 100644 packages/clients/src/scw/fetch/__tests__/build-fetcher.ts create mode 100644 packages/clients/src/scw/fetch/__tests__/http-dumper.ts create mode 100644 packages/clients/src/scw/fetch/__tests__/http-interceptors.ts create mode 100644 packages/clients/src/scw/fetch/__tests__/resource-paginator.ts create mode 100644 packages/clients/src/scw/fetch/__tests__/response-parser.ts create mode 100644 packages/clients/src/scw/fetch/build-fetcher.ts create mode 100644 packages/clients/src/scw/fetch/http-dumper.ts create mode 100644 packages/clients/src/scw/fetch/http-interceptors.ts create mode 100644 packages/clients/src/scw/fetch/resource-paginator.ts create mode 100644 packages/clients/src/scw/fetch/response-parser.ts create mode 100644 packages/clients/src/scw/fetch/types.ts create mode 100644 packages/clients/src/scw/locality.ts create mode 100644 packages/configuration-loader/.eslintrc.cjs create mode 100644 packages/configuration-loader/.npmignore create mode 100644 packages/configuration-loader/README.md create mode 100644 packages/configuration-loader/package.json create mode 100644 packages/configuration-loader/src/__tests__/config-loader.ts create mode 100644 packages/configuration-loader/src/__tests__/data/scw-config.yaml create mode 100644 packages/configuration-loader/src/__tests__/path-resolver.ts create mode 100644 packages/configuration-loader/src/__tests__/yml-loader.ts create mode 100644 packages/configuration-loader/src/config-loader.ts create mode 100644 packages/configuration-loader/src/env.ts create mode 100644 packages/configuration-loader/src/index.ts create mode 100644 packages/configuration-loader/src/path-resolver.ts create mode 100644 packages/configuration-loader/src/types.ts create mode 100644 packages/configuration-loader/src/yml-loader.ts create mode 100644 pnpm-lock.yaml create mode 100644 pnpm-workspace.yaml create mode 100644 rollup.config.mjs create mode 100644 setupTests.ts create mode 100644 tsconfig.json create mode 100644 typedoc.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..435e3c736 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# http://editorconfig.org +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 000000000..e9a84a3f3 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +node_modules/ +dist/ +examples/ diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 000000000..1c5332e2d --- /dev/null +++ b/.eslintrc @@ -0,0 +1,24 @@ +{ + "root": true, + "plugins": [ + "eslint-plugin-tsdoc" + ], + "parserOptions": { + "project": ["tsconfig.json"] + }, + "extends": ["@scaleway/react/typescript"], + "rules": { + "tsdoc/syntax": "warn", + "@typescript-eslint/naming-convention": [ + "error", + { + "selector": "enumMember", + "format": ["PascalCase"] + } + ], + "import/prefer-default-export": "off", + "import/no-default-export": "error", + "no-await-in-loop": "off", + "@typescript-eslint/no-namespace": "off" + } +} diff --git a/.github/renovate.json b/.github/renovate.json new file mode 100644 index 000000000..16503cf47 --- /dev/null +++ b/.github/renovate.json @@ -0,0 +1,82 @@ +{ + "extends": [ + ":combinePatchMinorReleases", + ":separateMultipleMajorReleases", + "group:monorepos", + "group:recommended", + "helpers:disableTypesNodeMajor" + ], + "assignees": ["team:devtools"], + "assigneesSampleSize": 1, + "reviewers": ["team:devtools", "team:console"], + "reviewersSampleSize": 2, + "updateNotScheduled": true, + "lockFileMaintenance": { "enabled": false }, + "enabledManagers": ["github-actions", "npm"], + "prCreation": "not-pending", + "prHourlyLimit": 5, + "prConcurrentLimit": 10, + "automerge": false, + "rangeStrategy": "bump", + "rebaseWhen": "auto", + "dependencyDashboard": true, + "packageRules": [ + { + "automerge": false, + "matchPackagePatterns": ["^@scaleway/"], + "stabilityDays": 0, + "matchUpdateTypes": ["major", "minor", "patch"] + }, + { + "labels": ["UPDATE-MAJOR"], + "stabilityDays": 14, + "matchUpdateTypes": ["major"] + }, + { + "labels": ["UPDATE-MINOR"], + "stabilityDays": 5, + "matchUpdateTypes": ["minor"] + }, + { + "labels": ["UPDATE-PATCH"], + "stabilityDays": 1, + "matchUpdateTypes": ["patch"] + }, + { + "matchPackagePatterns": [ + "^@babel/", + "^@commitlint/", + "^babel-", + "cz-conventional-changelog", + "eslint", + "husky", + "jest", + "lint-staged" + ], + "automerge": true, + "automergeType": "branch", + "semanticCommitScope": "minor-deps", + "stabilityDays": 3, + "matchUpdateTypes": ["minor"] + }, + { + "matchPackagePatterns": [ + "^@babel/", + "^@commitlint/", + "^@semantic-release/", + "^@types/", + "^babel-", + "^eslint", + "cz-conventional-changelog", + "husky", + "jest", + "lint-staged" + ], + "automerge": true, + "automergeType": "branch", + "semanticCommitScope": "patch-deps", + "stabilityDays": 1, + "matchUpdateTypes": ["patch"] + } + ] +} diff --git a/.github/workflows/check_pull_request_title.yml b/.github/workflows/check_pull_request.yml similarity index 93% rename from .github/workflows/check_pull_request_title.yml rename to .github/workflows/check_pull_request.yml index 9feac8e75..d9c137782 100644 --- a/.github/workflows/check_pull_request_title.yml +++ b/.github/workflows/check_pull_request.yml @@ -1,4 +1,4 @@ -name: Check Pull Request Title +name: Check Pull Request on: pull_request: types: ['opened', 'edited', 'reopened', 'synchronize'] diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 8c32a6f51..56987eb5c 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -49,35 +49,4 @@ jobs: - run: pnpm run build - run: pnpm run test:coverage - uses: codecov/codecov-action@v3.1.0 - deploy: - runs-on: ubuntu-20.04 - needs: [test] - if: github.ref == 'refs/heads/main' - steps: - - uses: actions/checkout@v3.0.2 - 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.2 - - name: Use Node.js - uses: actions/setup-node@v3.3.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 --ignore-scripts --no-verify-access - env: - HUSKY: 0 - GH_TOKEN: ${{ secrets.GH_TOKEN }} + \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..4f94b19d2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# dependencies +node_modules/ +yarn.lock + +# misc +.DS_Store + +# lint +.eslintcache + +# test & build +.reports +docs +public +dist +coverage + +# Protobuf definition +protobuf +.bufcache diff --git a/.husky/.gitignore b/.husky/.gitignore new file mode 100644 index 000000000..c9cdc63b0 --- /dev/null +++ b/.husky/.gitignore @@ -0,0 +1 @@ +_ \ No newline at end of file diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100755 index 000000000..b0fa8e5e9 --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,7 @@ +#!/bin/sh + +[ -n "$CI" ] && exit 0 + +. "$(dirname "$0")/_/husky.sh" + +pnpm commitlint --edit $1 diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 000000000..2ca1b9f46 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,7 @@ +#!/bin/sh + +[ -n "$CI" ] && exit 0 + +. "$(dirname "$0")/_/husky.sh" + +pnpm lint-staged diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100755 index 000000000..2ca1b9f46 --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,7 @@ +#!/bin/sh + +[ -n "$CI" ] && exit 0 + +. "$(dirname "$0")/_/husky.sh" + +pnpm lint-staged diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..49619ccb8 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,4 @@ +node_modules/ +dist/ + +package.json \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 000000000..7041ea263 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "singleQuote": true, + "trailingComma": "all", + "semi": false, + "arrowParens": "avoid" +} diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 000000000..d9c88713d --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Gracefully accepting constructive criticism +- Focusing on what is best for the community +- Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +- The use of sexualized language or imagery and unwelcome sexual attention or + advances +- Trolling, insulting/derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or electronic + address, without explicit permission +- Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies within all project spaces, and it also applies when +an individual is representing the project or its community in public spaces. +Examples of representing a project or community include using an official +project e-mail address, posting via an official social media account, or acting +as an appointed representative at an online or offline event. Representation of +a project may be further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at opensource@scaleway.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..1a5acb124 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,90 @@ +# Contribute to `scaleway-sdk-js` + +`scaleway-sdk-js` is Apache 2.0 licensed and accepts contributions via GitHub. +This document will cover how to contribute to the project and report issues. + +## Topics + +- [Reporting Security Issues](#reporting-security-issues) +- [Reporting Issues](#reporting-issues) +- [Suggesting feature](#suggesting-feature) +- [Contributing Code](#contributing-code) +- [Community Guidelines](#community-guidelines) + +## Reporting security issues + +At Scaleway we take security seriously. +If you have any issue regarding security, please notify us by sending an email to [security@scaleway.com](mailto:security@scaleway.com). + +Please _DO NOT_ create a GitHub issue. + +We will follow up with you promptly with more information and a plan for remediation. +We currently do not offer a paid security bounty program, but we would love to send some Scaleway swag your way along with our deepest gratitude for your assistance in making Scaleway a more secure Cloud ecosystem. + +## Reporting issues + +A great way to contribute to the project is to send a detailed report when you encounter a bug. +We always appreciate a well-written, thorough bug report, and will thank you for it! +Before opening a new issue, we appreciate you reviewing open issues to see if there are any similar requests. +If there is a match, thumbs up the issue with a 👍 and leave a comment if you have additional information. + +When reporting an issue, include the following: + +- The version of `scaleway-sdk-js` you are using (e.g. v1.0.0-beta1, v2.0.0, master, ...) +- The environment and its version (e.g. NodeJS v16.10) + +## Suggesting a feature + +When requesting a feature, some of the questions we want to answer are: + +- What value does this feature bring to end users? +- How urgent is the need (nice to have feature or need to have)? +- Does this align with the goals of `scaleway-sdk-js`? + +## Contributing code + +Part of this repo is automatically generated from our [protocol buffer](https://en.wikipedia.org/wiki/Protocol_Buffers) monorepo. This enables us to keep Scaleway toolings up to date with the latest version of our APIs ([developer website](http://developers.scaleway.com), CLI, SDKs, etc). + +Generated files and folders are located in [scaleway-sdk-js/packages/clients/api](./packages/clients/api). They always start with the following line: + +```ts +// This file was automatically generated. DO NOT EDIT. +``` + +### Submit code + +To submit code: + +- Create a fork of the project +- Create a topic branch from where you want to base your work (usually master) +- Add tests to cover contributed code +- Push your commit(s) to your topic branch on your fork +- Open a pull request against `scaleway-sdk-js` master branch that follows [PR guidelines](#pull-request-guidelines) + +The maintainers of `scaleway-sdk-js` use a "Let's Get This Merged" (LGTM) message in the pull request to note that the commits are ready to merge. +After one or more maintainer states LGTM, we will merge. +If you have questions or comments on your code, feel free to correct these in your branch through new commits. + +### Pull Request Guidelines + +The goal of the following guidelines is to have Pull Requests (PRs) that are fairly easy to review and comprehend, and code that is easy to maintain in the future. + +- **Pull Request title should be clear** on what is being fixed or added to the code base. + If you are addressing an open issue, please start the title with "fix(api): #XXX" or "feat: #XXX" +- **Keep it readable for human reviewers** and prefer a subset of functionality (code) with tests and documentation over delivering them separately +- **Don't forget commenting code** to help reviewers understand the modification +- **Notify Work In Progress PRs** by prefixing the title with `Draft:` +- **Please, keep us updated.** + We will try our best to merge your PR, but please notice that PRs may be closed after 30 days of inactivity. + +Your pull request should be rebased against the current master branch. Please do not merge +the current master branch in with your topic branch, nor use the Update Branch button provided +by GitHub on the pull request page. + +Keep in mind only the **Pull Request Title** will be used as commit message as we stash all commits on merge. + +## Community guidelines + +See [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md). + +Thank you for reading through all of this, if you have any question feel free to [reach us](README.md#reach-us)! diff --git a/LICENSE b/LICENSE index 261eeb9e9..2712cc51a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ + Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/ + https://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION @@ -175,24 +176,13 @@ END OF TERMS AND CONDITIONS - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] + Copyright 2019 Scaleway. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/README.md b/README.md new file mode 100644 index 000000000..42534ece6 --- /dev/null +++ b/README.md @@ -0,0 +1,108 @@ +# Scaleway SDK + +This SDK enables you to interact with Scaleway APIs. + +**⚠️  Notes:** +* The project is in beta, but should be fairly stable. +* SDK only works from a node.js runtime, browser calls aren't supported yet. + +**🔗  Important links:** +* Reference documentation (soon) +* [Example projects](./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/docs/console/my-project/how-to/generate-api-key) on how to retrieve them. + +**A minimal setup** would look like this: + +```ts +import { Registry, createClient } 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 a simpler setup**, you could retrieve the profile from either the configuration file or the environment variables: + +```ts +import { + loadProfileFromConfigurationFile, + // loadProfileFromEnvironmentValues, +} from '@scaleway/configuration-loader' + +const profile = loadProfileFromConfigurationFile() // loadProfileFromEnvironmentValues() +const client = createClient(profile) +``` + +**For more advanced needs**, please check the examples. + +## Pagination + +We included some pagination helpers for the methods supporting the feature. Let's take `listNamespaces()` (Registry product) as an example: + +Retrieve the **first page**: + +```ts +const namespaces = await api.listNamespaces(/*{ page: 1 }*/) +``` + +Retrieve **all the pages**: +```ts +const allNamespaces = await api.listNamespaces().all() +``` + +**Iterate** over the pages: +```ts +for await (const page of api.listNamespaces()) { + // +} +``` + +## 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 `Product.version` namespace. For instance, `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 + +This SDK is based on the [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) API and use `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 + +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 + +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). diff --git a/babel.config.json b/babel.config.json new file mode 100644 index 000000000..72563e6d1 --- /dev/null +++ b/babel.config.json @@ -0,0 +1,6 @@ +{ + "presets": [ + "@babel/preset-typescript", + ["@babel/preset-env", { "shippedProposals": true, "targets": { "node": "current" } }] + ] +} \ No newline at end of file diff --git a/examples/.eslintrc b/examples/.eslintrc new file mode 100644 index 000000000..2f6feed6c --- /dev/null +++ b/examples/.eslintrc @@ -0,0 +1,6 @@ +{ + "root": false, + "rules": { + "no-console": "off", + } +} diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 000000000..50f575607 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,81 @@ +# Examples + +## Project Templates + +* [NodeJS](./nodejs-minimal) +* [Serverless Function](./serverless-function-minimal/) + +## Snippets + +Please find below some examples on how to perform basic operations. + +### Instance: create a server and power it on + +```ts +import { loadProfileFromConfigurationFile } from '@scaleway/configuration-loader' +import { Instance, createClient } from '@scaleway/sdk' + +const profile = loadProfileFromConfigurationFile() +const client = createClient(profile) +const api = new Instance.v1.API(client) + +// Create a server. +console.log(`Creating server...`) +let server = await api + .createServer({ + bootType: 'local', + commercialType: 'DEV1-S', + enableIpv6: true, + image: '881d7a33-4cfa-4046-b5cf-c33cb9c62fb6', // ubuntu_focal + zone: 'fr-par-1', + }) + .then(res => res.server!) +console.log(`\tCreated, ID=${server.id} ; State=${server.state}`) + +// Power on the server. +console.log(`Powering on server...`) +server = await api.serverActionAndWait({ + serverId: server.id, + action: 'poweron', +}) +console.log(`\tPowered ON (now ${server.state})`) +``` + +### Instance: reboot all the running servers + +```ts +import { loadProfileFromConfigurationFile } from '@scaleway/configuration-loader' +import { Instance, createClient } from '@scaleway/sdk' + +const profile = loadProfileFromConfigurationFile() +const client = createClient(profile) +const api = new Instance.v1.API(client) + +// List servers. +console.log(`Listing servers...`); +const servers = await api.listServers().then((res) => res.servers!); + +// Check how many servers need a reboot. +const serversToReboot = servers.filter((obj) => obj.state === 'running'); +console.log(`\t${serversToReboot.length}/${servers.length} will be rebooted`); + +// Reboot all servers at once. +console.log( + `Rebooting servers ${serversToReboot.map((obj) => obj.id).join(', ')}...` +) +const updatedServers = await Promise.allSettled( + serversToReboot.map((obj) => + api.serverActionAndWait({ serverId: obj.id, action: 'reboot' }) + ) +) +for (const result of updatedServers) { + switch (result.status) { + case 'fulfilled': + console.log(`\tServer ${result.value.id} rebooted!`) + break + case 'rejected': + console.log(`\tServer failed rebooting`) + break + } +} +``` diff --git a/examples/nodejs-minimal/.gitignore b/examples/nodejs-minimal/.gitignore new file mode 100644 index 000000000..2e6c97630 --- /dev/null +++ b/examples/nodejs-minimal/.gitignore @@ -0,0 +1,7 @@ +# dependencies +node_modules/ +yarn.lock +pnpm-lock.yaml + +# misc +.DS_Store diff --git a/examples/nodejs-minimal/README.md b/examples/nodejs-minimal/README.md new file mode 100644 index 000000000..ba3bf5a76 --- /dev/null +++ b/examples/nodejs-minimal/README.md @@ -0,0 +1,11 @@ +# NodeJS example + +## A. How to run + +**Notes:** depending on the desired authentication method, please update the client init in `src/index.ts`. + +**Steps:** + +1. Install dependencies: `pnpm install`. +2. Build the project: `pnpm run build`. +3. Start the server: `pnpm run start`. diff --git a/examples/nodejs-minimal/package.json b/examples/nodejs-minimal/package.json new file mode 100644 index 000000000..b5ceccf58 --- /dev/null +++ b/examples/nodejs-minimal/package.json @@ -0,0 +1,18 @@ +{ + "name": "nodejs-minimal", + "version": "1.0.0", + "main": "index.ts", + "license": "MIT", + "scripts": { + "build": "tsc -p ./tsconfig.json", + "start": "node ./dist/index" + }, + "dependencies": { + "@scaleway/configuration-loader": "^0.1.0-alpha", + "@scaleway/sdk": "^0.1.0-alpha" + }, + "devDependencies": { + "@types/node": "^17.0.45", + "typescript": "^4.7.4" + } +} diff --git a/examples/nodejs-minimal/pnpm-workspace.yaml b/examples/nodejs-minimal/pnpm-workspace.yaml new file mode 100644 index 000000000..b4356b2e2 --- /dev/null +++ b/examples/nodejs-minimal/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +packages: + - './' diff --git a/examples/nodejs-minimal/src/index.ts b/examples/nodejs-minimal/src/index.ts new file mode 100644 index 000000000..682ddf3c0 --- /dev/null +++ b/examples/nodejs-minimal/src/index.ts @@ -0,0 +1,42 @@ +import { loadProfileFromConfigurationFile } from '@scaleway/configuration-loader' +import { Registry, createClient } from '@scaleway/sdk' +import * as http from 'http' + +const hostname = '127.0.0.1' +const port = 3000 + +const loadedProfile = loadProfileFromConfigurationFile() +const client = createClient(loadedProfile) +const api = new Registry.v1.API(client) + +type Response = http.ServerResponse + +const sendJson = (response: Response, data: object) => { + response.statusCode = 200 + response.setHeader('Content-Type', 'application/json') + response.end(JSON.stringify(data)) +} + +const sendError = (response: Response, status: number, error?: unknown) => { + const errorMessage = `${ + error instanceof Error ? error.message : String(error) + }` + response.statusCode = status + response.setHeader('Content-Type', 'application/json') + response.end(JSON.stringify({ error: errorMessage })) +} + +const server = http.createServer(async ({ url }, response) => { + // Avoid unwanted call: web browser often calls favicon.ico + if (url !== '/') return sendError(response, 404, 'Not found') + + try { + sendJson(response, await api.listNamespaces().all()) + } catch (error) { + sendError(response, 500, error) + } +}) + +server.listen(port, hostname, () => + console.log(`Server running at http://${hostname}:${port}/`), +) diff --git a/examples/nodejs-minimal/tsconfig.json b/examples/nodejs-minimal/tsconfig.json new file mode 100644 index 000000000..8c4906a60 --- /dev/null +++ b/examples/nodejs-minimal/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "target": "ES2019", + "module": "commonjs", + "moduleResolution": "node", + "outDir": "./dist", + "strict": true, + "strictNullChecks": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true + } +} diff --git a/examples/serverless-function-minimal/.env.template b/examples/serverless-function-minimal/.env.template new file mode 100644 index 000000000..69b4827c4 --- /dev/null +++ b/examples/serverless-function-minimal/.env.template @@ -0,0 +1,5 @@ +SCW_ACCESS_KEY= +SCW_SECRET_KEY= +SCW_DEFAULT_PROJECT_ID= +SCW_DEFAULT_REGION=fr-par +SCW_DEFAULT_ZONE=fr-par-1 diff --git a/examples/serverless-function-minimal/.gitignore b/examples/serverless-function-minimal/.gitignore new file mode 100644 index 000000000..6e47b2680 --- /dev/null +++ b/examples/serverless-function-minimal/.gitignore @@ -0,0 +1,11 @@ +# dependencies +node_modules/ +yarn.lock +pnpm-lock.yaml + +# misc +.DS_Store + +# serverless +.serverless +.env diff --git a/examples/serverless-function-minimal/.npmrc b/examples/serverless-function-minimal/.npmrc new file mode 100644 index 000000000..6a3b26f39 --- /dev/null +++ b/examples/serverless-function-minimal/.npmrc @@ -0,0 +1,2 @@ +# Required for serverless environment when using PNPM +node-linker=hoisted diff --git a/examples/serverless-function-minimal/README.md b/examples/serverless-function-minimal/README.md new file mode 100644 index 000000000..57cd478b4 --- /dev/null +++ b/examples/serverless-function-minimal/README.md @@ -0,0 +1,15 @@ +# Function example + +We assume that you have the dependency [serverless](https://www.serverless.com/) installed on your computer. + +## A. How to run + +⚠️ **Important:** this example authenticates using environment variables: please rename `.env.template` to `.env` (git ignored) and update the variables. + * Note: by design, Serverless framework overrides environment variables already defined in your Scaleway account. + +**Steps:** + +1. Install dependencies: `pnpm install`. +2. Build the project: `pnpm run build`. +3. Deploy in production: `SCW_DEFAULT_PROJECT_ID= SCW_SECRET_KEY= serverless deploy` + * Or just `serverless deploy` if you already defined `SCW_DEFAULT_PROJECT_ID` and `SCW_SECRET_KEY` in your bash profile. diff --git a/examples/serverless-function-minimal/package.json b/examples/serverless-function-minimal/package.json new file mode 100644 index 000000000..831578303 --- /dev/null +++ b/examples/serverless-function-minimal/package.json @@ -0,0 +1,20 @@ +{ + "name": "scaleway-serverless-function", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "build": "tsc -p ./tsconfig.json" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "@scaleway/configuration-loader": "^0.1.0-alpha", + "@scaleway/sdk": "^0.1.0-alpha" + }, + "devDependencies": { + "serverless-scaleway-functions": "^0.4.0", + "typescript": "^4.7.4" + }, + "description": "Minimal Typescript template to run Scaleway SDK-JS in a Function." +} diff --git a/examples/serverless-function-minimal/pnpm-workspace.yaml b/examples/serverless-function-minimal/pnpm-workspace.yaml new file mode 100644 index 000000000..b4356b2e2 --- /dev/null +++ b/examples/serverless-function-minimal/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +packages: + - './' diff --git a/examples/serverless-function-minimal/serverless.yml b/examples/serverless-function-minimal/serverless.yml new file mode 100644 index 000000000..099d94b9b --- /dev/null +++ b/examples/serverless-function-minimal/serverless.yml @@ -0,0 +1,28 @@ +service: sdk-js-example +configValidationMode: off +useDotenv: true +provider: + name: scaleway + runtime: node16 + env: + SCW_ACCESS_KEY: ${env:SCW_ACCESS_KEY} + SCW_SECRET_KEY: ${env:SCW_SECRET_KEY} + SCW_DEFAULT_PROJECT_ID: ${env:SCW_DEFAULT_PROJECT_ID} + SCW_DEFAULT_REGION: ${env:SCW_DEFAULT_REGION} + SCW_DEFAULT_ZONE: ${env:SCW_DEFAULT_ZONE} + +plugins: + - serverless-scaleway-functions + +package: + patterns: + - '!./src/**' + - '!.gitignore' + - '!.git/**' + - '!README.md' + +functions: + list-namespaces: + handler: dist/index.list + privacy: public + memoryLimit: 128 diff --git a/examples/serverless-function-minimal/src/index.ts b/examples/serverless-function-minimal/src/index.ts new file mode 100644 index 000000000..7d4cdd5ba --- /dev/null +++ b/examples/serverless-function-minimal/src/index.ts @@ -0,0 +1,26 @@ +import { loadProfileFromEnvironmentValues } from '@scaleway/configuration-loader' +import { Errors, Registry, createClient } from '@scaleway/sdk' + +const loadedProfile = loadProfileFromEnvironmentValues() +const client = createClient(loadedProfile) +const api = new Registry.v1.API(client) + +const buildJsonRes = (data: object) => ({ + body: JSON.stringify(data), + statusCode: 200, +}) + +const buildErrorRes = (error?: unknown) => ({ + body: JSON.stringify({ + message: `${error instanceof Error ? error.message : String(error)}`, + }), + statusCode: error instanceof Errors.ScalewayError ? error.status : 500, +}) + +export const list = async (event: any, context: any, callback: any) => { + try { + return buildJsonRes(await api.listNamespaces().all()) + } catch (error) { + return buildErrorRes(error) + } +} diff --git a/examples/serverless-function-minimal/tsconfig.json b/examples/serverless-function-minimal/tsconfig.json new file mode 100644 index 000000000..8c4906a60 --- /dev/null +++ b/examples/serverless-function-minimal/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "target": "ES2019", + "module": "commonjs", + "moduleResolution": "node", + "outDir": "./dist", + "strict": true, + "strictNullChecks": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true + } +} diff --git a/lerna.json b/lerna.json new file mode 100644 index 000000000..51746246b --- /dev/null +++ b/lerna.json @@ -0,0 +1,16 @@ +{ + "packages": ["packages/*"], + "useWorkspaces": true, + "npmClient": "pnpm", + "version": "independent", + "command": { + "publish": { + "conventionalPrerelease": true, + "conventionalCommits": true, + "changelogPreset": "conventionalcommits" + }, + "version": { + "message": "chore(release): publish" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 000000000..6a3faccc4 --- /dev/null +++ b/package.json @@ -0,0 +1,104 @@ +{ + "name": "root", + "private": true, + "workspaces": [ + "packages/*" + ], + "engines": { + "node": ">=14.13", + "pnpm": ">=7.3.0" + }, + "type": "module", + "scripts": { + "build": "lerna exec --stream -- rollup -c ../../rollup.config.mjs", + "build:profile": "cross-env PROFILE=true pnpm run build", + "commit": "npx git-cz -a", + "doc": "typedoc", + "format": "prettier --write '**/*.ts'", + "lint": "eslint --cache --ext ts .", + "prepare": "husky install", + "test:coverage": "pnpm run test --coverage", + "test": "jest" + }, + "lint-staged": { + "*.ts": [ + "prettier --write", + "eslint --fix --ext ts" + ] + }, + "config": { + "commitizen": { + "path": "./node_modules/cz-conventional-changelog" + } + }, + "commitlint": { + "extends": [ + "@commitlint/config-conventional" + ] + }, + "jest": { + "collectCoverageFrom": [ + "packages/*/src/**/*.{ts,tsx}" + ], + "coverageReporters": [ + "text", + "cobertura" + ], + "modulePathIgnorePatterns": [ + "/examples/", + "/dist/", + "/packages/clients/src/api/" + ], + "reporters": [ + "default", + [ + "jest-junit", + { + "outputDirectory": ".reports", + "outputName": "tests.xml" + } + ] + ], + "transformIgnorePatterns": [ + "node_modules/(?!(.*(@scaleway)))" + ], + "setupFiles": [ + "./setupTests.ts" + ] + }, + "devDependencies": { + "@babel/core": "^7.18.6", + "@babel/plugin-transform-runtime": "^7.18.6", + "@babel/preset-env": "^7.18.6", + "@babel/preset-typescript": "^7.18.6", + "@commitlint/cli": "^17.0.3", + "@commitlint/config-conventional": "^17.0.3", + "@jest/globals": "^28.1.2", + "@rollup/plugin-babel": "^5.3.1", + "@rollup/plugin-commonjs": "^22.0.1", + "@rollup/plugin-inject": "^4.0.4", + "@rollup/plugin-node-resolve": "^13.3.0", + "@scaleway/eslint-config-react": "^3.4.40", + "@types/jest": "^28.1.4", + "babel-plugin-annotate-pure-calls": "^0.4.0", + "cross-env": "^7.0.3", + "cross-fetch": "^3.1.5", + "cz-conventional-changelog": "^3.3.0", + "eslint": "^8.19.0", + "eslint-formatter-gitlab": "^3.0.0", + "eslint-plugin-tsdoc": "^0.2.16", + "husky": "^8.0.1", + "jest": "^28.1.2", + "jest-junit": "^13.2.0", + "lerna": "^5.1.6", + "lint-staged": "^13.0.3", + "prettier": "^2.7.1", + "read-pkg": "^7.1.0", + "rollup": "^2.75.7", + "rollup-plugin-dts": "^4.2.2", + "rollup-plugin-visualizer": "^5.6.0", + "typedoc": "^0.23.5", + "typescript": "^4.7.4" + }, + "packageManager": "pnpm@7.3.0" +} diff --git a/packages/clients/.eslintrc.cjs b/packages/clients/.eslintrc.cjs new file mode 100644 index 000000000..f4bd0a419 --- /dev/null +++ b/packages/clients/.eslintrc.cjs @@ -0,0 +1,10 @@ +const { join } = require('path'); + +module.exports = { + rules: { + 'import/no-extraneous-dependencies': [ + 'error', + { packageDir: [__dirname, join(__dirname, '../../')] } + ] + } +}; diff --git a/packages/clients/.npmignore b/packages/clients/.npmignore new file mode 100644 index 000000000..5600eef5f --- /dev/null +++ b/packages/clients/.npmignore @@ -0,0 +1,5 @@ +**/__tests__/** +examples/ +src +.eslintrc.cjs +!.npmignore diff --git a/packages/clients/README.md b/packages/clients/README.md new file mode 100644 index 000000000..3bc7b1bd2 --- /dev/null +++ b/packages/clients/README.md @@ -0,0 +1,46 @@ +# Scaleway SDK + +This SDK enables you to interact with Scaleway APIs. + +**🔗  Important links:** +* Reference documentation (soon) +* [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/docs/console/my-project/how-to/generate-api-key) on how to retrieve them. + +**A minimal setup** would look like this: + +```ts +import { Registry, createClient } 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 a simpler setup**, you could retrieve the profile from either the configuration file or the environment variables: + +```ts +import { + loadProfileFromConfigurationFile, + // loadProfileFromEnvironmentValues, +} from '@scaleway/configuration-loader' + +const profile = loadProfileFromConfigurationFile() // loadProfileFromEnvironmentValues() +const client = createClient(profile) +``` + +**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). diff --git a/packages/clients/package.json b/packages/clients/package.json new file mode 100644 index 000000000..09cb05c28 --- /dev/null +++ b/packages/clients/package.json @@ -0,0 +1,36 @@ +{ + "name": "@scaleway/sdk", + "version": "0.1.0-beta.0", + "license": "Apache-2.0", + "description": "Scaleway SDK.", + "keywords": [ + "scaleway", + "cloud", + "sdk" + ], + "main": "dist/index.cjs", + "module": "dist/index.js", + "types": "dist/index.d.ts", + "files": [ + "dist" + ], + "publishConfig": { + "access": "public" + }, + "repository": { + "type": "git", + "url": "https://github.com/scaleway/scaleway-sdk-js", + "directory": "packages/clients" + }, + "engines": { + "node": ">=14.13" + }, + "type": "module", + "dependencies": { + "@scaleway/random-name": "^3.0.2", + "cross-fetch": "^3.1.5" + }, + "bundledDependencies": [ + "@scaleway/random-name" + ] +} diff --git a/packages/clients/src/api/.eslintrc b/packages/clients/src/api/.eslintrc new file mode 100644 index 000000000..ac8227856 --- /dev/null +++ b/packages/clients/src/api/.eslintrc @@ -0,0 +1,10 @@ +{ + "root": false, + "rules": { + "@typescript-eslint/no-empty-interface": "off", + "@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "defaults|request" }], + "max-classes-per-file": "off", + "tsdoc/syntax": "off", + "no-underscore-dangle": ["error", { "allowAfterThis": true }] + } +} diff --git a/packages/clients/src/api/account/index.ts b/packages/clients/src/api/account/index.ts new file mode 100644 index 000000000..1c7be627b --- /dev/null +++ b/packages/clients/src/api/account/index.ts @@ -0,0 +1 @@ +export * as v2alpha1 from './v2alpha1' diff --git a/packages/clients/src/api/account/v2alpha1/api.gen.ts b/packages/clients/src/api/account/v2alpha1/api.gen.ts new file mode 100644 index 000000000..89d9d5acb --- /dev/null +++ b/packages/clients/src/api/account/v2alpha1/api.gen.ts @@ -0,0 +1,139 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import { + API, + enrichForPagination, + urlParams, + validatePathParam, +} from '../../../bridge' +import { + marshalCreateSSHKeyRequest, + marshalUpdateSSHKeyRequest, + unmarshalListSSHKeysResponse, + unmarshalSSHKey, +} from './marshalling.gen' +import type { + CreateSSHKeyRequest, + DeleteSSHKeyRequest, + GetSSHKeyRequest, + ListSSHKeysRequest, + ListSSHKeysResponse, + SSHKey, + UpdateSSHKeyRequest, +} from './types.gen' + +const jsonContentHeaders = { + 'Content-Type': 'application/json; charset=utf-8', +} + +/** Account API. */ +export class AccountV2Alpha1GenAPI extends API { + protected pageOfListSSHKeys = (request: Readonly = {}) => + this.client.fetch( + { + method: 'GET', + path: `/account/v2alpha1/ssh-keys`, + urlParams: urlParams( + ['name', request.name], + ['order_by', request.orderBy ?? 'created_at_asc'], + [ + 'organization_id', + request.organizationId ?? + this.client.settings.defaultOrganizationId, + ], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + [ + 'project_id', + request.projectId ?? this.client.settings.defaultProjectId, + ], + ), + }, + unmarshalListSSHKeysResponse, + ) + + /** + * List all SSH keys of your project + * + * @param request - The request {@link ListSSHKeysRequest} + * @returns A Promise of ListSSHKeysResponse + */ + listSSHKeys = (request: Readonly = {}) => + enrichForPagination('sshKeys', this.pageOfListSSHKeys, request) + + /** + * Add an SSH key to your project + * + * @param request - The request {@link CreateSSHKeyRequest} + * @returns A Promise of SSHKey + */ + createSSHKey = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalCreateSSHKeyRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/account/v2alpha1/ssh-keys`, + }, + unmarshalSSHKey, + ) + + /** + * Get an SSH key from your project + * + * @param request - The request {@link GetSSHKeyRequest} + * @returns A Promise of SSHKey + */ + getSSHKey = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/account/v2alpha1/ssh-key/${validatePathParam( + 'sshKeyId', + request.sshKeyId, + )}`, + }, + unmarshalSSHKey, + ) + + /** + * Update an SSH key on your project + * + * @param request - The request {@link UpdateSSHKeyRequest} + * @returns A Promise of SSHKey + */ + updateSSHKey = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpdateSSHKeyRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/account/v2alpha1/ssh-key/${validatePathParam( + 'sshKeyId', + request.sshKeyId, + )}`, + }, + unmarshalSSHKey, + ) + + /** + * Remove an SSH key from your project + * + * @param request - The request {@link DeleteSSHKeyRequest} + */ + deleteSSHKey = (request: Readonly) => + this.client.fetch({ + method: 'DELETE', + path: `/account/v2alpha1/ssh-key/${validatePathParam( + 'sshKeyId', + request.sshKeyId, + )}`, + }) +} diff --git a/packages/clients/src/api/account/v2alpha1/index.ts b/packages/clients/src/api/account/v2alpha1/index.ts new file mode 100644 index 000000000..0a1192e20 --- /dev/null +++ b/packages/clients/src/api/account/v2alpha1/index.ts @@ -0,0 +1,2 @@ +export { AccountV2Alpha1GenAPI as API } from './api.gen' +export * from './types.gen' diff --git a/packages/clients/src/api/account/v2alpha1/marshalling.gen.ts b/packages/clients/src/api/account/v2alpha1/marshalling.gen.ts new file mode 100644 index 000000000..0f2ddda87 --- /dev/null +++ b/packages/clients/src/api/account/v2alpha1/marshalling.gen.ts @@ -0,0 +1,92 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import { + isJSONObject, + resolveOneOf, + unmarshalArrayOfObject, + unmarshalDate, +} from '../../../bridge' +import type { DefaultValues } from '../../../bridge' +import type { + CreateSSHKeyRequest, + ListSSHKeysResponse, + SSHKey, + SSHKeyCreationInfo, + UpdateSSHKeyRequest, +} from './types.gen' + +const unmarshalSSHKeyCreationInfo = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SSHKeyCreationInfo' failed as data isn't a dictionary.`, + ) + } + + return { + address: data.address, + countryCode: data.country_code, + userAgent: data.user_agent, + } as SSHKeyCreationInfo +} + +export const unmarshalSSHKey = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SSHKey' failed as data isn't a dictionary.`, + ) + } + + return { + createdAt: unmarshalDate(data.created_at), + creationInfo: data.creation_info + ? unmarshalSSHKeyCreationInfo(data.creation_info) + : undefined, + fingerprint: data.fingerprint, + id: data.id, + name: data.name, + organizationId: data.organization_id, + projectId: data.project_id, + publicKey: data.public_key, + updatedAt: unmarshalDate(data.updated_at), + } as SSHKey +} + +export const unmarshalListSSHKeysResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListSSHKeysResponse' failed as data isn't a dictionary.`, + ) + } + + return { + sshKeys: unmarshalArrayOfObject(data.ssh_keys, unmarshalSSHKey), + totalCount: data.total_count, + } as ListSSHKeysResponse +} + +export const marshalCreateSSHKeyRequest = ( + request: CreateSSHKeyRequest, + defaults: DefaultValues, +): Record => ({ + name: request.name, + public_key: request.publicKey, + ...resolveOneOf([ + { + default: defaults.defaultProjectId, + param: 'project_id', + value: request.projectId, + }, + { + default: defaults.defaultOrganizationId, + param: 'organization_id', + value: request.organizationId, + }, + ]), +}) + +export const marshalUpdateSSHKeyRequest = ( + request: UpdateSSHKeyRequest, + defaults: DefaultValues, +): Record => ({ + name: request.name, +}) diff --git a/packages/clients/src/api/account/v2alpha1/types.gen.ts b/packages/clients/src/api/account/v2alpha1/types.gen.ts new file mode 100644 index 000000000..302014415 --- /dev/null +++ b/packages/clients/src/api/account/v2alpha1/types.gen.ts @@ -0,0 +1,83 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. + +export type ListSSHKeysRequestOrderBy = + | 'created_at_asc' + | 'created_at_desc' + | 'updated_at_asc' + | 'updated_at_desc' + | 'name_asc' + | 'name_desc' + +/** List ssh keys response */ +export interface ListSSHKeysResponse { + sshKeys: Array + totalCount: number +} + +/** Ssh key */ +export interface SSHKey { + id: string + name: string + publicKey: string + fingerprint: string + createdAt?: Date + updatedAt?: Date + creationInfo?: SSHKeyCreationInfo + organizationId: string + projectId: string +} + +export interface SSHKeyCreationInfo { + address: string + userAgent: string + countryCode: string +} + +export type ListSSHKeysRequest = { + orderBy?: ListSSHKeysRequestOrderBy + page?: number + pageSize?: number + name?: string + organizationId?: string + projectId?: string +} + +export type CreateSSHKeyRequest = { + /** The name of the SSH key */ + name: string + /** + * SSH public key. Currently ssh-rsa, ssh-dss (DSA), ssh-ed25519 and ecdsa + * keys with NIST curves are supported + */ + publicKey: string + /** + * @deprecated Use project_id field instead. + * + * One-of ('projectIdentifier'): at most one of 'organizationId', 'projectId' + * could be set. + */ + organizationId?: string + /** + * Project owning the resource. + * + * One-of ('projectIdentifier'): at most one of 'organizationId', 'projectId' + * could be set. + */ + projectId?: string +} + +export type GetSSHKeyRequest = { + /** The ID of the SSH key */ + sshKeyId: string +} + +export type UpdateSSHKeyRequest = { + sshKeyId: string + /** Name of the SSH key */ + name?: string +} + +export type DeleteSSHKeyRequest = { + sshKeyId: string +} diff --git a/packages/clients/src/api/applesilicon/index.ts b/packages/clients/src/api/applesilicon/index.ts new file mode 100644 index 000000000..e6671523d --- /dev/null +++ b/packages/clients/src/api/applesilicon/index.ts @@ -0,0 +1 @@ +export * as v1alpha1 from './v1alpha1' diff --git a/packages/clients/src/api/applesilicon/v1alpha1/api.gen.ts b/packages/clients/src/api/applesilicon/v1alpha1/api.gen.ts new file mode 100644 index 000000000..9d6d125f2 --- /dev/null +++ b/packages/clients/src/api/applesilicon/v1alpha1/api.gen.ts @@ -0,0 +1,330 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import { + API, + enrichForPagination, + urlParams, + validatePathParam, + waitForResource, +} from '../../../bridge' +import type { WaitForOptions, Zone } from '../../../bridge' +import { SERVER_TRANSIENT_STATUSES } from './content.gen' +import { + marshalCreateServerRequest, + marshalUpdateServerRequest, + unmarshalListOSResponse, + unmarshalListServerTypesResponse, + unmarshalListServersResponse, + unmarshalOS, + unmarshalServer, + unmarshalServerType, +} from './marshalling.gen' +import type { + CreateServerRequest, + DeleteServerRequest, + GetOSRequest, + GetServerRequest, + GetServerTypeRequest, + ListOSRequest, + ListOSResponse, + ListServerTypesRequest, + ListServerTypesResponse, + ListServersRequest, + ListServersResponse, + OS, + RebootServerRequest, + ReinstallServerRequest, + Server, + ServerType, + UpdateServerRequest, +} from './types.gen' + +const jsonContentHeaders = { + 'Content-Type': 'application/json; charset=utf-8', +} + +/** + * Apple silicon. + * + * Scaleway Apple silicon M1 as-a-Service is built using the latest generation + * of Apple Mac mini hardware (fifth generation). + * + * These dedicated Mac mini M1s are designed for developing, building, testing, + * and signing applications for Apple devices, including iPhones, iPads, Mac + * computers and much more. + * + * Get set to explore, learn and build on a dedicated Mac mini M1 with more + * performance and speed than you ever thought possible. + * + * _Apple silicon as a Service comes with a minimum allocation period of 24 hours_*. + * + * Mac mini and macOS are trademarks of Apple Inc., registered in the U.S. and + * other countries and regions. IOS is a trademark or registered trademark of + * Cisco in the U.S. and other countries and is used by Apple under license. + * Scaleway is not affiliated with Apple Inc. + */ +export class ApplesiliconV1Alpha1GenAPI extends API { + /** Lists the available zones of the API. */ + public static readonly LOCALITIES: Zone[] = ['fr-par-3'] + + /** + * List all server types technical details. + * + * @param request - The request {@link ListServerTypesRequest} + * @returns A Promise of ListServerTypesResponse + */ + listServerTypes = (request: Readonly = {}) => + this.client.fetch( + { + method: 'GET', + path: `/apple-silicon/v1alpha1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/server-types`, + }, + unmarshalListServerTypesResponse, + ) + + /** + * Get a server technical details. + * + * @param request - The request {@link GetServerTypeRequest} + * @returns A Promise of ServerType + */ + getServerType = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/apple-silicon/v1alpha1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/server-type/${validatePathParam('serverType', request.serverType)}`, + }, + unmarshalServerType, + ) + + /** + * Create a server. + * + * @param request - The request {@link CreateServerRequest} + * @returns A Promise of Server + */ + createServer = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalCreateServerRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/apple-silicon/v1alpha1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers`, + }, + unmarshalServer, + ) + + protected pageOfListServers = (request: Readonly = {}) => + this.client.fetch( + { + method: 'GET', + path: `/apple-silicon/v1alpha1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers`, + urlParams: urlParams( + ['order_by', request.orderBy ?? 'created_at_asc'], + [ + 'organization_id', + request.organizationId ?? + this.client.settings.defaultOrganizationId, + ], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + [ + 'project_id', + request.projectId ?? this.client.settings.defaultProjectId, + ], + ), + }, + unmarshalListServersResponse, + ) + + /** + * List all servers. + * + * @param request - The request {@link ListServersRequest} + * @returns A Promise of ListServersResponse + */ + listServers = (request: Readonly = {}) => + enrichForPagination('servers', this.pageOfListServers, request) + + protected pageOfListOS = (request: Readonly = {}) => + this.client.fetch( + { + method: 'GET', + path: `/apple-silicon/v1alpha1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/os`, + urlParams: urlParams( + ['name', request.name], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ['server_type', request.serverType], + ), + }, + unmarshalListOSResponse, + ) + + /** + * List all Operating System (OS). + * + * @param request - The request {@link ListOSRequest} + * @returns A Promise of ListOSResponse + */ + listOS = (request: Readonly = {}) => + enrichForPagination('os', this.pageOfListOS, request) + + /** + * Get an Operating System (OS). + * + * @param request - The request {@link GetOSRequest} + * @returns A Promise of OS + */ + getOS = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/apple-silicon/v1alpha1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/os/${validatePathParam('osId', request.osId)}`, + }, + unmarshalOS, + ) + + /** + * Get a server. + * + * @param request - The request {@link GetServerRequest} + * @returns A Promise of Server + */ + getServer = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/apple-silicon/v1alpha1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam('serverId', request.serverId)}`, + }, + unmarshalServer, + ) + + /** + * Waits for {@link Server} to be in a final state. + * + * @param request - The request {@link GetServerRequest} + * @param options - The waiting options + * @returns A Promise of Server + */ + waitForServer = ( + request: Readonly, + options?: Readonly>, + ) => + waitForResource( + options?.stop ?? + (res => + Promise.resolve(!SERVER_TRANSIENT_STATUSES.includes(res.status))), + this.getServer, + request, + options, + ) + + /** + * Update a server. + * + * @param request - The request {@link UpdateServerRequest} + * @returns A Promise of Server + */ + updateServer = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpdateServerRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/apple-silicon/v1alpha1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam('serverId', request.serverId)}`, + }, + unmarshalServer, + ) + + /** + * Delete a server. + * + * @param request - The request {@link DeleteServerRequest} + */ + deleteServer = (request: Readonly) => + this.client.fetch({ + method: 'DELETE', + path: `/apple-silicon/v1alpha1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam('serverId', request.serverId)}`, + }) + + /** + * Reboot a server. + * + * @param request - The request {@link RebootServerRequest} + * @returns A Promise of Server + */ + rebootServer = (request: Readonly) => + this.client.fetch( + { + body: '{}', + headers: jsonContentHeaders, + method: 'POST', + path: `/apple-silicon/v1alpha1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam('serverId', request.serverId)}/reboot`, + }, + unmarshalServer, + ) + + /** + * Reinstall a server. + * + * @param request - The request {@link ReinstallServerRequest} + * @returns A Promise of Server + */ + reinstallServer = (request: Readonly) => + this.client.fetch( + { + body: '{}', + headers: jsonContentHeaders, + method: 'POST', + path: `/apple-silicon/v1alpha1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam( + 'serverId', + request.serverId, + )}/reinstall`, + }, + unmarshalServer, + ) +} diff --git a/packages/clients/src/api/applesilicon/v1alpha1/content.gen.ts b/packages/clients/src/api/applesilicon/v1alpha1/content.gen.ts new file mode 100644 index 000000000..a87c42e93 --- /dev/null +++ b/packages/clients/src/api/applesilicon/v1alpha1/content.gen.ts @@ -0,0 +1,13 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import type { ServerStatus } from './types.gen' + +/** Lists transient statutes of the enum {@link ServerStatus}. */ +export const SERVER_TRANSIENT_STATUSES: ServerStatus[] = [ + 'starting', + 'rebooting', + 'updating', + 'locking', + 'unlocking', + 'reinstalling', +] diff --git a/packages/clients/src/api/applesilicon/v1alpha1/index.ts b/packages/clients/src/api/applesilicon/v1alpha1/index.ts new file mode 100644 index 000000000..2f9dee02d --- /dev/null +++ b/packages/clients/src/api/applesilicon/v1alpha1/index.ts @@ -0,0 +1,3 @@ +export { ApplesiliconV1Alpha1GenAPI as API } from './api.gen' +export * from './content.gen' +export * from './types.gen' diff --git a/packages/clients/src/api/applesilicon/v1alpha1/marshalling.gen.ts b/packages/clients/src/api/applesilicon/v1alpha1/marshalling.gen.ts new file mode 100644 index 000000000..491760f1c --- /dev/null +++ b/packages/clients/src/api/applesilicon/v1alpha1/marshalling.gen.ts @@ -0,0 +1,162 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import randomName from '@scaleway/random-name' +import { + isJSONObject, + unmarshalArrayOfObject, + unmarshalDate, +} from '../../../bridge' +import type { DefaultValues } from '../../../bridge' +import type { + CreateServerRequest, + ListOSResponse, + ListServerTypesResponse, + ListServersResponse, + OS, + Server, + ServerType, + ServerTypeCPU, + ServerTypeDisk, + ServerTypeMemory, + UpdateServerRequest, +} from './types.gen' + +const unmarshalServerTypeCPU = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ServerTypeCPU' failed as data isn't a dictionary.`, + ) + } + + return { coreCount: data.core_count, name: data.name } as ServerTypeCPU +} + +const unmarshalServerTypeDisk = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ServerTypeDisk' failed as data isn't a dictionary.`, + ) + } + + return { capacity: data.capacity, type: data.type } as ServerTypeDisk +} + +const unmarshalServerTypeMemory = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ServerTypeMemory' failed as data isn't a dictionary.`, + ) + } + + return { capacity: data.capacity, type: data.type } as ServerTypeMemory +} + +export const unmarshalOS = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'OS' failed as data isn't a dictionary.`, + ) + } + + return { + compatibleServerTypes: data.compatible_server_types, + id: data.id, + imageUrl: data.image_url, + label: data.label, + name: data.name, + } as OS +} + +export const unmarshalServer = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Server' failed as data isn't a dictionary.`, + ) + } + + return { + createdAt: unmarshalDate(data.created_at), + deletableAt: unmarshalDate(data.deletable_at), + id: data.id, + ip: data.ip, + name: data.name, + organizationId: data.organization_id, + projectId: data.project_id, + status: data.status, + type: data.type, + updatedAt: unmarshalDate(data.updated_at), + vncUrl: data.vnc_url, + zone: data.zone, + } as Server +} + +export const unmarshalServerType = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ServerType' failed as data isn't a dictionary.`, + ) + } + + return { + cpu: data.cpu ? unmarshalServerTypeCPU(data.cpu) : undefined, + disk: data.disk ? unmarshalServerTypeDisk(data.disk) : undefined, + memory: data.memory ? unmarshalServerTypeMemory(data.memory) : undefined, + minimumLeaseDuration: data.minimum_lease_duration, + name: data.name, + stock: data.stock, + } as ServerType +} + +export const unmarshalListOSResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListOSResponse' failed as data isn't a dictionary.`, + ) + } + + return { + os: unmarshalArrayOfObject(data.os, unmarshalOS), + totalCount: data.total_count, + } as ListOSResponse +} + +export const unmarshalListServerTypesResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListServerTypesResponse' failed as data isn't a dictionary.`, + ) + } + + return { + serverTypes: unmarshalArrayOfObject(data.server_types, unmarshalServerType), + } as ListServerTypesResponse +} + +export const unmarshalListServersResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListServersResponse' failed as data isn't a dictionary.`, + ) + } + + return { + servers: unmarshalArrayOfObject(data.servers, unmarshalServer), + totalCount: data.total_count, + } as ListServersResponse +} + +export const marshalCreateServerRequest = ( + request: CreateServerRequest, + defaults: DefaultValues, +): Record => ({ + name: request.name || randomName('as'), + project_id: request.projectId ?? defaults.defaultProjectId, + type: request.type, +}) + +export const marshalUpdateServerRequest = ( + request: UpdateServerRequest, + defaults: DefaultValues, +): Record => ({ + name: request.name, +}) diff --git a/packages/clients/src/api/applesilicon/v1alpha1/types.gen.ts b/packages/clients/src/api/applesilicon/v1alpha1/types.gen.ts new file mode 100644 index 000000000..7e862d66d --- /dev/null +++ b/packages/clients/src/api/applesilicon/v1alpha1/types.gen.ts @@ -0,0 +1,213 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import type { Zone } from '../../../bridge' + +export type ListServersRequestOrderBy = 'created_at_asc' | 'created_at_desc' + +export type ServerStatus = + | 'unknown_status' + | 'starting' + | 'ready' + | 'error' + | 'rebooting' + | 'updating' + | 'locking' + | 'locked' + | 'unlocking' + | 'reinstalling' + +export type ServerTypeStock = + | 'unknown_stock' + | 'no_stock' + | 'low_stock' + | 'high_stock' + +/** List os response */ +export interface ListOSResponse { + /** Total number of os */ + totalCount: number + /** List of OS */ + os: Array +} + +/** List server types response */ +export interface ListServerTypesResponse { + /** The available server types */ + serverTypes: Array +} + +/** List servers response */ +export interface ListServersResponse { + /** The total number of servers */ + totalCount: number + /** The paginated returned servers */ + servers: Array +} + +/** Os */ +export interface OS { + /** The OS unique ID */ + id: string + /** The OS name */ + name: string + /** The OS name as it should be displayed */ + label: string + /** URL of the image */ + imageUrl: string + /** List of compatible server types */ + compatibleServerTypes: Array +} + +/** Server */ +export interface Server { + /** UUID of the server */ + id: string + /** Type of the server */ + type: string + /** Name of the server */ + name: string + /** Project this server is associated with */ + projectId: string + /** Organization this server is associated with */ + organizationId: string + /** IPv4 address of the server */ + ip: string + /** URL of the VNC */ + vncUrl: string + /** Current status of the server */ + status: ServerStatus + /** The date at which the server was created */ + createdAt?: Date + /** The date at which the server was last updated */ + updatedAt?: Date + /** The date at which the server was last deleted */ + deletableAt?: Date + /** The zone of the server */ + zone: Zone +} + +/** Server type */ +export interface ServerType { + /** CPU description */ + cpu?: ServerTypeCPU + /** Size of the local disk of the server */ + disk?: ServerTypeDisk + /** Name of the type */ + name: string + /** Size of memory available */ + memory?: ServerTypeMemory + /** Current stock */ + stock: ServerTypeStock + /** Minimum duration of the lease in seconds (example. 3.4s). */ + minimumLeaseDuration?: string +} + +export interface ServerTypeCPU { + name: string + coreCount: number +} + +export interface ServerTypeDisk { + capacity: number + type: string +} + +export interface ServerTypeMemory { + capacity: number + type: string +} + +export type ListServerTypesRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone +} + +export type GetServerTypeRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** Server type identifier */ + serverType: string +} + +export type CreateServerRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** Create a server with this given name */ + name?: string + /** Create a server in the given project ID */ + projectId?: string + /** Create a server of the given type */ + type: string +} + +export type ListServersRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** The sort order of the returned servers */ + orderBy?: ListServersRequestOrderBy + /** List only servers of this project ID */ + projectId?: string + /** List only servers of this organization ID */ + organizationId?: string + /** A positive integer to choose the page to return */ + page?: number + /** A positive integer lower or equal to 100 to select the number of items to return */ + pageSize?: number +} + +export type ListOSRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** A positive integer to choose the page to return */ + page?: number + /** A positive integer lower or equal to 100 to select the number of items to return */ + pageSize?: number + /** List of compatible server type */ + serverType?: string + /** Filter os by name (for eg. "11.1" will return "11.1.2" and "11.1" but not "12") */ + name?: string +} + +export type GetOSRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the OS you want to get */ + osId: string +} + +export type GetServerRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the server you want to get */ + serverId: string +} + +export type UpdateServerRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the server you want to update */ + serverId: string + /** Updated name for your server */ + name: string +} + +export type DeleteServerRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the server you want to delete */ + serverId: string +} + +export type RebootServerRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the server you want to reboot */ + serverId: string +} + +export type ReinstallServerRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the server you want to reinstall */ + serverId: string +} diff --git a/packages/clients/src/api/baremetal/index.ts b/packages/clients/src/api/baremetal/index.ts new file mode 100644 index 000000000..994706b3e --- /dev/null +++ b/packages/clients/src/api/baremetal/index.ts @@ -0,0 +1 @@ +export * as v1 from './v1' diff --git a/packages/clients/src/api/baremetal/v1/api.gen.ts b/packages/clients/src/api/baremetal/v1/api.gen.ts new file mode 100644 index 000000000..05e8a2052 --- /dev/null +++ b/packages/clients/src/api/baremetal/v1/api.gen.ts @@ -0,0 +1,717 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import { + API, + enrichForPagination, + urlParams, + validatePathParam, + waitForResource, +} from '../../../bridge' +import type { WaitForOptions, Zone } from '../../../bridge' +import { SERVER_TRANSIENT_STATUSES } from './content.gen' +import { + marshalAddOptionServerRequest, + marshalCreateServerRequest, + marshalInstallServerRequest, + marshalRebootServerRequest, + marshalStartBMCAccessRequest, + marshalStartServerRequest, + marshalUpdateIPRequest, + marshalUpdateServerRequest, + marshalUpdateSettingRequest, + unmarshalBMCAccess, + unmarshalGetServerMetricsResponse, + unmarshalIP, + unmarshalListOSResponse, + unmarshalListOffersResponse, + unmarshalListOptionsResponse, + unmarshalListServerEventsResponse, + unmarshalListServersResponse, + unmarshalListSettingsResponse, + unmarshalOS, + unmarshalOffer, + unmarshalOption, + unmarshalServer, + unmarshalSetting, +} from './marshalling.gen' +import type { + AddOptionServerRequest, + BMCAccess, + CreateServerRequest, + DeleteOptionServerRequest, + DeleteServerRequest, + GetBMCAccessRequest, + GetOSRequest, + GetOfferRequest, + GetOptionRequest, + GetServerMetricsRequest, + GetServerMetricsResponse, + GetServerRequest, + IP, + InstallServerRequest, + ListOSRequest, + ListOSResponse, + ListOffersRequest, + ListOffersResponse, + ListOptionsRequest, + ListOptionsResponse, + ListServerEventsRequest, + ListServerEventsResponse, + ListServersRequest, + ListServersResponse, + ListSettingsRequest, + ListSettingsResponse, + OS, + Offer, + Option, + RebootServerRequest, + Server, + Setting, + StartBMCAccessRequest, + StartServerRequest, + StopBMCAccessRequest, + StopServerRequest, + UpdateIPRequest, + UpdateServerRequest, + UpdateSettingRequest, +} from './types.gen' + +const jsonContentHeaders = { + 'Content-Type': 'application/json; charset=utf-8', +} + +/** + * Elastic metal API. + * + * This API allows to manage your Bare metal server. + */ +export class BaremetalV1GenAPI extends API { + /** Lists the available zones of the API. */ + public static readonly LOCALITIES: Zone[] = [ + 'fr-par-1', + 'fr-par-2', + 'nl-ams-1', + ] + + protected pageOfListServers = (request: Readonly = {}) => + this.client.fetch( + { + method: 'GET', + path: `/baremetal/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers`, + urlParams: urlParams( + ['name', request.name], + ['option_id', request.optionId], + ['order_by', request.orderBy ?? 'created_at_asc'], + [ + 'organization_id', + request.organizationId ?? + this.client.settings.defaultOrganizationId, + ], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + [ + 'project_id', + request.projectId ?? this.client.settings.defaultProjectId, + ], + ['status', request.status], + ['tags', request.tags], + ), + }, + unmarshalListServersResponse, + ) + + /** + * List elastic metal servers for organization. + * + * @param request - The request {@link ListServersRequest} + * @returns A Promise of ListServersResponse + */ + listServers = (request: Readonly = {}) => + enrichForPagination('servers', this.pageOfListServers, request) + + /** + * Get the server associated with the given ID. + * + * @param request - The request {@link GetServerRequest} + * @returns A Promise of Server + */ + getServer = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/baremetal/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam('serverId', request.serverId)}`, + }, + unmarshalServer, + ) + + /** + * Waits for {@link Server} to be in a final state. + * + * @param request - The request {@link GetServerRequest} + * @param options - The waiting options + * @returns A Promise of Server + */ + waitForServer = ( + request: Readonly, + options?: Readonly>, + ) => + waitForResource( + options?.stop ?? + (res => + Promise.resolve(!SERVER_TRANSIENT_STATUSES.includes(res.status))), + this.getServer, + request, + options, + ) + + /** + * Create a new elastic metal server. Once the server is created, you probably + * want to install an OS. + * + * @param request - The request {@link CreateServerRequest} + * @returns A Promise of Server + */ + createServer = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalCreateServerRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/baremetal/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers`, + }, + unmarshalServer, + ) + + /** + * Update the server associated with the given ID. + * + * @param request - The request {@link UpdateServerRequest} + * @returns A Promise of Server + */ + updateServer = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpdateServerRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/baremetal/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam('serverId', request.serverId)}`, + }, + unmarshalServer, + ) + + /** + * Install an OS on the server associated with the given ID. + * + * @param request - The request {@link InstallServerRequest} + * @returns A Promise of Server + */ + installServer = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalInstallServerRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/baremetal/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam('serverId', request.serverId)}/install`, + }, + unmarshalServer, + ) + + /** + * Give the ping status on the server associated with the given ID. + * + * @param request - The request {@link GetServerMetricsRequest} + * @returns A Promise of GetServerMetricsResponse + */ + getServerMetrics = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/baremetal/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam('serverId', request.serverId)}/metrics`, + }, + unmarshalGetServerMetricsResponse, + ) + + /** + * Delete the server associated with the given ID. + * + * @param request - The request {@link DeleteServerRequest} + * @returns A Promise of Server + */ + deleteServer = (request: Readonly) => + this.client.fetch( + { + method: 'DELETE', + path: `/baremetal/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam('serverId', request.serverId)}`, + }, + unmarshalServer, + ) + + /** + * Reboot the server associated with the given ID, use boot param to reboot in rescue. + * + * @param request - The request {@link RebootServerRequest} + * @returns A Promise of Server + */ + rebootServer = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalRebootServerRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/baremetal/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam('serverId', request.serverId)}/reboot`, + }, + unmarshalServer, + ) + + /** + * Start the server associated with the given ID. + * + * @param request - The request {@link StartServerRequest} + * @returns A Promise of Server + */ + startServer = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalStartServerRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/baremetal/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam('serverId', request.serverId)}/start`, + }, + unmarshalServer, + ) + + /** + * Stop the server associated with the given ID. + * + * @param request - The request {@link StopServerRequest} + * @returns A Promise of Server + */ + stopServer = (request: Readonly) => + this.client.fetch( + { + body: '{}', + headers: jsonContentHeaders, + method: 'POST', + path: `/baremetal/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam('serverId', request.serverId)}/stop`, + }, + unmarshalServer, + ) + + protected pageOfListServerEvents = ( + request: Readonly, + ) => + this.client.fetch( + { + method: 'GET', + path: `/baremetal/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam('serverId', request.serverId)}/events`, + urlParams: urlParams( + ['order_by', request.orderBy ?? 'created_at_asc'], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ), + }, + unmarshalListServerEventsResponse, + ) + + /** + * List events associated to the given server ID. + * + * @param request - The request {@link ListServerEventsRequest} + * @returns A Promise of ListServerEventsResponse + */ + listServerEvents = (request: Readonly) => + enrichForPagination('events', this.pageOfListServerEvents, request) + + /** + * Start BMC (Baseboard Management Controller) access associated with the + * given ID. The BMC (Baseboard Management Controller) access is available one + * hour after the installation of the server. You need first to create an + * option Remote Access. You will find the ID and the price with a call to + * listOffers + * (https://developers.scaleway.com/en/products/baremetal/api/#get-78db92). + * Then you can add the option + * https://developers.scaleway.com/en/products/baremetal/api/#post-b14abd. Do + * not forget to delete the Option. After start BMC, you need to Get Remote + * Access to get the login/password + * https://developers.scaleway.com/en/products/baremetal/api/#get-cefc0f. + * + * @param request - The request {@link StartBMCAccessRequest} + * @returns A Promise of BMCAccess + */ + startBMCAccess = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalStartBMCAccessRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/baremetal/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam( + 'serverId', + request.serverId, + )}/bmc-access`, + }, + unmarshalBMCAccess, + ) + + /** + * Get the BMC (Baseboard Management Controller) access associated with the given ID. + * + * @param request - The request {@link GetBMCAccessRequest} + * @returns A Promise of BMCAccess + */ + getBMCAccess = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/baremetal/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam( + 'serverId', + request.serverId, + )}/bmc-access`, + }, + unmarshalBMCAccess, + ) + + /** + * Stop BMC (Baseboard Management Controller) access associated with the given ID. + * + * @param request - The request {@link StopBMCAccessRequest} + */ + stopBMCAccess = (request: Readonly) => + this.client.fetch({ + method: 'DELETE', + path: `/baremetal/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam('serverId', request.serverId)}/bmc-access`, + }) + + /** + * Configure ip associated with the given server ID and ipID. You can use this + * method to set a reverse dns for an IP. + * + * @param request - The request {@link UpdateIPRequest} + * @returns A Promise of IP + */ + updateIP = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpdateIPRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/baremetal/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam( + 'serverId', + request.serverId, + )}/ips/${validatePathParam('ipId', request.ipId)}`, + }, + unmarshalIP, + ) + + /** + * Add an option to a specific server. + * + * @param request - The request {@link AddOptionServerRequest} + * @returns A Promise of Server + */ + addOptionServer = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalAddOptionServerRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/baremetal/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam( + 'serverId', + request.serverId, + )}/options/${validatePathParam('optionId', request.optionId)}`, + }, + unmarshalServer, + ) + + /** + * Delete an option from a specific server. + * + * @param request - The request {@link DeleteOptionServerRequest} + * @returns A Promise of Server + */ + deleteOptionServer = (request: Readonly) => + this.client.fetch( + { + method: 'DELETE', + path: `/baremetal/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam( + 'serverId', + request.serverId, + )}/options/${validatePathParam('optionId', request.optionId)}`, + }, + unmarshalServer, + ) + + protected pageOfListOffers = (request: Readonly = {}) => + this.client.fetch( + { + method: 'GET', + path: `/baremetal/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/offers`, + urlParams: urlParams( + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + [ + 'subscription_period', + request.subscriptionPeriod ?? 'unknown_subscription_period', + ], + ), + }, + unmarshalListOffersResponse, + ) + + /** + * List all available server offers. + * + * @param request - The request {@link ListOffersRequest} + * @returns A Promise of ListOffersResponse + */ + listOffers = (request: Readonly = {}) => + enrichForPagination('offers', this.pageOfListOffers, request) + + /** + * Return specific offer for the given ID. + * + * @param request - The request {@link GetOfferRequest} + * @returns A Promise of Offer + */ + getOffer = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/baremetal/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/offers/${validatePathParam('offerId', request.offerId)}`, + }, + unmarshalOffer, + ) + + /** + * Return specific option for the given ID. + * + * @param request - The request {@link GetOptionRequest} + * @returns A Promise of Option + */ + getOption = (request: Readonly) => + this.client.fetch