From 6f6557ce0d04197ac2442fbc7d3aa7f19ad24292 Mon Sep 17 00:00:00 2001 From: Constantin Bergatt Date: Wed, 9 Oct 2024 14:09:30 +0200 Subject: [PATCH 01/16] BC-7879 - add `authorization-client-api` generated by openAPI --- openapitools-config.json | 9 + openapitools.json | 7 + package-lock.json | 433 +++++++++++++++++- package.json | 5 +- scripts/generate-client.js | 90 ++++ .../.openapi-generator-ignore | 38 ++ .../.openapi-generator/FILES | 11 + .../.openapi-generator/VERSION | 1 + .../authorization-api-client/api.ts | 18 + .../api/authorization-api.ts | 159 +++++++ .../authorization-api-client/base.ts | 86 ++++ .../authorization-api-client/common.ts | 150 ++++++ .../authorization-api-client/configuration.ts | 110 +++++ .../authorization-api-client/index.ts | 18 + .../authorization-api-client/models/action.ts | 31 ++ .../models/authorization-body-params.ts | 64 +++ .../models/authorization-context-params.ts | 44 ++ .../models/authorized-reponse.ts | 36 ++ .../authorization-api-client/models/index.ts | 281 ++++++++++++ 19 files changed, 1574 insertions(+), 17 deletions(-) create mode 100644 openapitools-config.json create mode 100644 openapitools.json create mode 100644 scripts/generate-client.js create mode 100644 src/infra/authorization-client/authorization-api-client/.openapi-generator-ignore create mode 100644 src/infra/authorization-client/authorization-api-client/.openapi-generator/FILES create mode 100644 src/infra/authorization-client/authorization-api-client/.openapi-generator/VERSION create mode 100644 src/infra/authorization-client/authorization-api-client/api.ts create mode 100644 src/infra/authorization-client/authorization-api-client/api/authorization-api.ts create mode 100644 src/infra/authorization-client/authorization-api-client/base.ts create mode 100644 src/infra/authorization-client/authorization-api-client/common.ts create mode 100644 src/infra/authorization-client/authorization-api-client/configuration.ts create mode 100644 src/infra/authorization-client/authorization-api-client/index.ts create mode 100644 src/infra/authorization-client/authorization-api-client/models/action.ts create mode 100644 src/infra/authorization-client/authorization-api-client/models/authorization-body-params.ts create mode 100644 src/infra/authorization-client/authorization-api-client/models/authorization-context-params.ts create mode 100644 src/infra/authorization-client/authorization-api-client/models/authorized-reponse.ts create mode 100644 src/infra/authorization-client/authorization-api-client/models/index.ts diff --git a/openapitools-config.json b/openapitools-config.json new file mode 100644 index 00000000..3570d978 --- /dev/null +++ b/openapitools-config.json @@ -0,0 +1,9 @@ +{ + "apiPackage": "api", + "enumNameSuffix": "", + "enumPropertyNaming": "UPPERCASE", + "modelPackage": "models", + "supportsES6": true, + "withInterfaces": true, + "withSeparateModelsAndApi": true +} diff --git a/openapitools.json b/openapitools.json new file mode 100644 index 00000000..f80faaa6 --- /dev/null +++ b/openapitools.json @@ -0,0 +1,7 @@ +{ + "$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json", + "spaces": 2, + "generator-cli": { + "version": "7.9.0" + } +} diff --git a/package-lock.json b/package-lock.json index c88406ab..2cbb9c77 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "@nestjs/passport": "^10.0.3", "@nestjs/platform-express": "^10.4.1", "@y/redis": "github:hpi-schul-cloud/y-redis#7d48e08d18ec78c9ab90063a7d867ec7f191319c", + "arg": "^5.0.2", "ioredis": "^5.4.1", "passport": "^0.7.0", "passport-headerapikey": "^1.2.2", @@ -30,6 +31,7 @@ "@nestjs/cli": "^10.4.4", "@nestjs/schematics": "^10.1.3", "@nestjs/testing": "^10.4.1", + "@openapitools/openapi-generator-cli": "^2.14.0", "@types/express": "^4.17.21", "@types/jest": "^29.5.12", "@types/node": "^20.3.1", @@ -674,6 +676,19 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/runtime": { + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.25.7.tgz", + "integrity": "sha512-FjoyLe754PMiYsFaN5C94ttGiOmBNYTf6pLr4xXHAT5uctHb092PBszndLDR5XA/jghQvn4n7JMHl7dmTgbm9w==", + "dev": true, + "license": "MIT", + "dependencies": { + "regenerator-runtime": "^0.14.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, "node_modules/@babel/template": { "version": "7.25.0", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.25.0.tgz", @@ -1538,6 +1553,18 @@ "node": ">=8" } }, + "node_modules/@nestjs/axios": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@nestjs/axios/-/axios-3.0.3.tgz", + "integrity": "sha512-h6TCn3yJwD6OKqqqfmtRS5Zo4E46Ip2n+gK1sqwzNBC+qxQ9xpCu+ODVRFur6V3alHSCSBxb3nNtt73VEdluyA==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "@nestjs/common": "^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0", + "axios": "^1.3.1", + "rxjs": "^6.0.0 || ^7.0.0" + } + }, "node_modules/@nestjs/cli": { "version": "10.4.5", "resolved": "https://registry.npmjs.org/@nestjs/cli/-/cli-10.4.5.tgz", @@ -1597,12 +1624,13 @@ } }, "node_modules/@nestjs/common": { - "version": "10.4.1", - "resolved": "https://registry.npmjs.org/@nestjs/common/-/common-10.4.1.tgz", - "integrity": "sha512-4CkrDx0s4XuWqFjX8WvOFV7Y6RGJd0P2OBblkhZS7nwoctoSuW5pyEa8SWak6YHNGrHRpFb6ymm5Ai4LncwRVA==", + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/@nestjs/common/-/common-10.4.3.tgz", + "integrity": "sha512-4hbLd3XIJubHSylYd/1WSi4VQvG68KM/ECYpMDqA3k3J1/T17SAg40sDoq3ZoO5OZgU0xuNyjuISdOTjs11qVg==", + "license": "MIT", "dependencies": { "iterare": "1.2.1", - "tslib": "2.6.3", + "tslib": "2.7.0", "uid": "2.0.2" }, "funding": { @@ -1624,6 +1652,12 @@ } } }, + "node_modules/@nestjs/common/node_modules/tslib": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", + "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==", + "license": "0BSD" + }, "node_modules/@nestjs/config": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/@nestjs/config/-/config-3.2.3.tgz", @@ -1639,16 +1673,17 @@ } }, "node_modules/@nestjs/core": { - "version": "10.4.1", - "resolved": "https://registry.npmjs.org/@nestjs/core/-/core-10.4.1.tgz", - "integrity": "sha512-9I1WdfOBCCHdUm+ClBJupOuZQS6UxzIWHIq6Vp1brAA5ZKl/Wq6BVwSsbnUJGBy3J3PM2XHmR0EQ4fwX3nR7lA==", + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/@nestjs/core/-/core-10.4.3.tgz", + "integrity": "sha512-6OQz+5C8mT8yRtfvE5pPCq+p6w5jDot+oQku1KzQ24ABn+lay1KGuJwcKZhdVNuselx+8xhdMxknZTA8wrGLIg==", "hasInstallScript": true, + "license": "MIT", "dependencies": { "@nuxtjs/opencollective": "0.3.2", "fast-safe-stringify": "2.1.1", "iterare": "1.2.1", - "path-to-regexp": "3.2.0", - "tslib": "2.6.3", + "path-to-regexp": "3.3.0", + "tslib": "2.7.0", "uid": "2.0.2" }, "funding": { @@ -1675,6 +1710,12 @@ } } }, + "node_modules/@nestjs/core/node_modules/tslib": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", + "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==", + "license": "0BSD" + }, "node_modules/@nestjs/passport": { "version": "10.0.3", "resolved": "https://registry.npmjs.org/@nestjs/passport/-/passport-10.0.3.tgz", @@ -1830,6 +1871,113 @@ "npm": ">=5.0.0" } }, + "node_modules/@openapitools/openapi-generator-cli": { + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/@openapitools/openapi-generator-cli/-/openapi-generator-cli-2.14.0.tgz", + "integrity": "sha512-k+ioQLtXLXgNbhQbp1UOxtaUnnYTWwAPev88hP5qauFA+eq4NyeQGNojknFssXg2x0VT0TUGmU3PZ2DiQ70IVg==", + "dev": true, + "hasInstallScript": true, + "license": "Apache-2.0", + "dependencies": { + "@nestjs/axios": "3.0.3", + "@nestjs/common": "10.4.3", + "@nestjs/core": "10.4.3", + "@nuxtjs/opencollective": "0.3.2", + "axios": "1.7.7", + "chalk": "4.1.2", + "commander": "8.3.0", + "compare-versions": "4.1.4", + "concurrently": "6.5.1", + "console.table": "0.10.0", + "fs-extra": "10.1.0", + "glob": "9.3.5", + "https-proxy-agent": "7.0.5", + "inquirer": "8.2.6", + "lodash": "4.17.21", + "reflect-metadata": "0.1.13", + "rxjs": "7.8.1", + "tslib": "2.7.0" + }, + "bin": { + "openapi-generator-cli": "main.js" + }, + "engines": { + "node": ">=16" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/openapi_generator" + } + }, + "node_modules/@openapitools/openapi-generator-cli/node_modules/commander": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz", + "integrity": "sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 12" + } + }, + "node_modules/@openapitools/openapi-generator-cli/node_modules/glob": { + "version": "9.3.5", + "resolved": "https://registry.npmjs.org/glob/-/glob-9.3.5.tgz", + "integrity": "sha512-e1LleDykUz2Iu+MTYdkSsuWX8lvAjAcs0Xef0lNIu0S2wOAzuTxCJtcd9S3cijlwYF18EsU3rzb8jPVobxDh9Q==", + "dev": true, + "license": "ISC", + "dependencies": { + "fs.realpath": "^1.0.0", + "minimatch": "^8.0.2", + "minipass": "^4.2.4", + "path-scurry": "^1.6.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@openapitools/openapi-generator-cli/node_modules/minimatch": { + "version": "8.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-8.0.4.tgz", + "integrity": "sha512-W0Wvr9HyFXZRGIDgCicunpQ299OKXs9RgZfaukz4qAW/pJhcpUfupc9c+OObPOFueNy8VSrZgEmDtk6Kh4WzDA==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@openapitools/openapi-generator-cli/node_modules/minipass": { + "version": "4.2.8", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-4.2.8.tgz", + "integrity": "sha512-fNzuVyifolSLFL4NzpF+wEF4qrgqaaKX0haXPQEdQ7NKAN+WecoKMHV09YcuL/DHxrUsYQOK3MiuDf7Ip2OXfQ==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=8" + } + }, + "node_modules/@openapitools/openapi-generator-cli/node_modules/reflect-metadata": { + "version": "0.1.13", + "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz", + "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==", + "dev": true, + "license": "Apache-2.0" + }, + "node_modules/@openapitools/openapi-generator-cli/node_modules/tslib": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", + "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==", + "dev": true, + "license": "0BSD" + }, "node_modules/@opentelemetry/api": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.9.0.tgz", @@ -2781,6 +2929,19 @@ "node": ">=0.4.0" } }, + "node_modules/agent-base": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", + "integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==", + "dev": true, + "license": "MIT", + "dependencies": { + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/ajv": { "version": "8.12.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz", @@ -2904,10 +3065,10 @@ "integrity": "sha512-klpgFSWLW1ZEs8svjfb7g4qWY0YS5imI82dTg+QahUvJ8YqAY0P10Uk8tTyh9ZGuYEZEMaeJYCF5BFuX552hsw==" }, "node_modules/arg": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", - "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", - "dev": true + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/arg/-/arg-5.0.2.tgz", + "integrity": "sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==", + "license": "MIT" }, "node_modules/argparse": { "version": "2.0.1", @@ -2968,6 +3129,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/axios": { + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/babel-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.7.0.tgz", @@ -3653,6 +3826,13 @@ "node": ">= 6" } }, + "node_modules/compare-versions": { + "version": "4.1.4", + "resolved": "https://registry.npmjs.org/compare-versions/-/compare-versions-4.1.4.tgz", + "integrity": "sha512-FemMreK9xNyL8gQevsdRMrvO4lFCkQP7qbuktn1q8ndcNk1+0mz7lgE7b/sNvbhVgY4w6tMN1FDp6aADjqw2rw==", + "dev": true, + "license": "MIT" + }, "node_modules/component-emitter": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.1.tgz", @@ -3682,11 +3862,142 @@ "typedarray": "^0.0.6" } }, + "node_modules/concurrently": { + "version": "6.5.1", + "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-6.5.1.tgz", + "integrity": "sha512-FlSwNpGjWQfRwPLXvJ/OgysbBxPkWpiVjy1042b0U7on7S7qwwMIILRj7WTN1mTgqa582bG6NFuScOoh6Zgdag==", + "dev": true, + "license": "MIT", + "dependencies": { + "chalk": "^4.1.0", + "date-fns": "^2.16.1", + "lodash": "^4.17.21", + "rxjs": "^6.6.3", + "spawn-command": "^0.0.2-1", + "supports-color": "^8.1.0", + "tree-kill": "^1.2.2", + "yargs": "^16.2.0" + }, + "bin": { + "concurrently": "bin/concurrently.js" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/concurrently/node_modules/cliui": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", + "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", + "dev": true, + "license": "ISC", + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^7.0.0" + } + }, + "node_modules/concurrently/node_modules/rxjs": { + "version": "6.6.7", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", + "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "tslib": "^1.9.0" + }, + "engines": { + "npm": ">=2.0.0" + } + }, + "node_modules/concurrently/node_modules/supports-color": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", + "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" + } + }, + "node_modules/concurrently/node_modules/tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "dev": true, + "license": "0BSD" + }, + "node_modules/concurrently/node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/concurrently/node_modules/yargs": { + "version": "16.2.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", + "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", + "dev": true, + "license": "MIT", + "dependencies": { + "cliui": "^7.0.2", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.0", + "y18n": "^5.0.5", + "yargs-parser": "^20.2.2" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/concurrently/node_modules/yargs-parser": { + "version": "20.2.9", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz", + "integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=10" + } + }, "node_modules/consola": { "version": "2.15.3", "resolved": "https://registry.npmjs.org/consola/-/consola-2.15.3.tgz", "integrity": "sha512-9vAdYbHj6x2fLKC4+oPH0kFzY/orMZyG2Aj+kNylHxKGJ/Ed4dpNyAQYwJOdqO4zdM7XpVHmyejQDcQHrnuXbw==" }, + "node_modules/console.table": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/console.table/-/console.table-0.10.0.tgz", + "integrity": "sha512-dPyZofqggxuvSf7WXvNjuRfnsOk1YazkVP8FdxH4tcH2c37wc79/Yl6Bhr7Lsu00KMgy2ql/qCMuNu8xctZM8g==", + "dev": true, + "license": "MIT", + "dependencies": { + "easy-table": "1.1.0" + }, + "engines": { + "node": "> 0.10" + } + }, "node_modules/content-disposition": { "version": "0.5.4", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", @@ -3815,6 +4126,23 @@ "node": ">= 8" } }, + "node_modules/date-fns": { + "version": "2.30.0", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz", + "integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.21.0" + }, + "engines": { + "node": ">=0.11" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/date-fns" + } + }, "node_modules/debug": { "version": "4.3.6", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz", @@ -4017,6 +4345,16 @@ "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", "dev": true }, + "node_modules/easy-table": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/easy-table/-/easy-table-1.1.0.tgz", + "integrity": "sha512-oq33hWOSSnl2Hoh00tZWaIPi1ievrD9aFG82/IgjlycAnW9hHx5PkJiXpxPsgEE+H7BsbVQXFVFST8TEXS6/pA==", + "dev": true, + "license": "MIT", + "optionalDependencies": { + "wcwidth": ">=1.0.1" + } + }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -4793,6 +5131,27 @@ "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==", "dev": true }, + "node_modules/follow-redirects": { + "version": "1.15.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -5230,6 +5589,20 @@ "node": ">= 0.8" } }, + "node_modules/https-proxy-agent": { + "version": "7.0.5", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.5.tgz", + "integrity": "sha512-1e4Wqeblerz+tMKPIq2EMGiiWW1dIjZOksyHWSUm1rmuvw/how9hBHZ38lAGj5ID4Ik6EdkOw7NmWPy6LAwalw==", + "dev": true, + "license": "MIT", + "dependencies": { + "agent-base": "^7.0.2", + "debug": "4" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/human-signals": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", @@ -7273,9 +7646,10 @@ "dev": true }, "node_modules/path-to-regexp": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-3.2.0.tgz", - "integrity": "sha512-jczvQbCUS7XmS7o+y1aEO9OBVFeZBQ1MDSEqmO7xSoPgOPoowY/SxLpZ6Vh97/8qHZOteiCKb7gkG9gA2ZUxJA==" + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-3.3.0.tgz", + "integrity": "sha512-qyCH421YQPS2WFDxDjftfc1ZR5WKQzVzqsp4n9M2kQhVOo/ByahFoUNJfl58kOcEGfQ//7weFTDhm+ss8Ecxgw==", + "license": "MIT" }, "node_modules/path-type": { "version": "4.0.0", @@ -7517,6 +7891,13 @@ "node": ">= 0.10" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "dev": true, + "license": "MIT" + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -7714,6 +8095,13 @@ "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.2.2.tgz", "integrity": "sha512-urBwgfrvVP/eAyXx4hluJivBKzuEbSQs9rKWCrCkbSxNv8mxPcUZKeuoF3Uy4mJl3Lwprp6yy5/39VWigZ4K6Q==" }, + "node_modules/regenerator-runtime": { + "version": "0.14.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", + "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==", + "dev": true, + "license": "MIT" + }, "node_modules/repeat-string": { "version": "1.6.1", "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", @@ -8194,6 +8582,12 @@ "node": ">=0.10.0" } }, + "node_modules/spawn-command": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/spawn-command/-/spawn-command-0.0.2.tgz", + "integrity": "sha512-zC8zGoGkmc8J9ndvml8Xksr1Amk9qBujgbF0JAIWO7kXr43w0h/0GJNM/Vustixu+YE8N/MTrQ7N31FvHUACxQ==", + "dev": true + }, "node_modules/split-on-first": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/split-on-first/-/split-on-first-1.1.0.tgz", @@ -8849,6 +9243,13 @@ } } }, + "node_modules/ts-node/node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true, + "license": "MIT" + }, "node_modules/tsconfig-paths": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-4.2.0.tgz", diff --git a/package.json b/package.json index 28e525cc..a6dd4778 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "test": "jest", "test:watch": "jest --watch", "test:cov": "jest --coverage", - "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand" + "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", + "generate-client:authorization": "node ./scripts/generate-client.js -u 'http://localhost:3030/api/v3/docs-json/' -p 'src/infra/authorization-client/authorization-api-client' -c 'openapitools-config.json' -f 'operationId:AuthorizationReferenceController_authorizeByReference'" }, "dependencies": { "@golevelup/ts-jest": "^0.5.4", @@ -35,6 +36,7 @@ "@nestjs/passport": "^10.0.3", "@nestjs/platform-express": "^10.4.1", "@y/redis": "github:hpi-schul-cloud/y-redis#7d48e08d18ec78c9ab90063a7d867ec7f191319c", + "arg": "^5.0.2", "ioredis": "^5.4.1", "passport": "^0.7.0", "passport-headerapikey": "^1.2.2", @@ -49,6 +51,7 @@ "@nestjs/cli": "^10.4.4", "@nestjs/schematics": "^10.1.3", "@nestjs/testing": "^10.4.1", + "@openapitools/openapi-generator-cli": "^2.14.0", "@types/express": "^4.17.21", "@types/jest": "^29.5.12", "@types/node": "^20.3.1", diff --git a/scripts/generate-client.js b/scripts/generate-client.js new file mode 100644 index 00000000..37f5abf3 --- /dev/null +++ b/scripts/generate-client.js @@ -0,0 +1,90 @@ +#!/usr/bin/env node + +import arg from 'arg'; +import { exec } from 'child_process'; +const { log, error } = console; + +const args = arg( + { + '--help': Boolean, + '-h': '--help', + + '--url': String, + '-u': '--url', + + '--path': String, + '-p': '--path', + + '--config': String, + '-c': '--config', + + '--filter': String, + '-f': '--filter', + }, + { + argv: process.argv.slice(2), + }, +); + +if ('--help' in args) { + log(`Usage: node generate-client.js [opts] +OPTIONS: + --help (-h) Show this help. + --path (-p) Path to the newly created client's directory. + --url (-u) URL/path to the spec file in yml/json format. + --config (-c) path to the additional-properties config file in yml/json format + --filter (-f) filter to apply to the openapi spec before generating the client +`); + process.exit(0); +} + +const params = { + /** url to load the open-api definition from */ + url: args._[0] || args['--url'], + /** folder to save the open-api client */ + path: args._[1] || args['--path'], + + config: args._[2] || args['--config'] || '', + + filter: args._[3] || args['--filter'] || '', +}; + +const errorMessageContains = (includedString, error) => + error && error.message && typeof error.message === 'string' && error.message.includes(includedString); + +const getOpenApiCommand = (params) => { + const { url, path, config, filter } = params; + const configFile = config ? `-c ${config}` : ''; + const filterString = filter ? `--openapi-normalizer FILTER="${filter}"` : ''; + const command = `openapi-generator-cli generate -i ${url} -g typescript-axios -o ${path} ${configFile} --skip-validate-spec ${filterString}`; + + return command; +}; + +const asyncExec = (command) => + new Promise((resolve, reject) => { + exec(command, (error, stdout, stderr) => { + if (error) { + return reject(error); + } + return resolve(stdout || stderr); + }); + }); + +const generateClient = () => { + const cmd = getOpenApiCommand(params); + log(`Try updating the openapi client in the folder ${params.path} from ${params.url} ...`); + asyncExec(cmd) + .then((stdout) => log(stdout)) + .catch((stderr) => { + if (errorMessageContains('ConnectException', stderr)) { + error(`Failed to connect to ${params.url}, is the server started at this url?`); + } else error(stderr.message); + }); +}; + +const main = () => { + generateClient(); +}; + +main(); diff --git a/src/infra/authorization-client/authorization-api-client/.openapi-generator-ignore b/src/infra/authorization-client/authorization-api-client/.openapi-generator-ignore new file mode 100644 index 00000000..bbc533d6 --- /dev/null +++ b/src/infra/authorization-client/authorization-api-client/.openapi-generator-ignore @@ -0,0 +1,38 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md + +# ignore some general files +.gitignore +.npmignore +git_push.sh + +# ignore all files in the "models" folder +models/* + +# list of allowed files in the "models" folder +!models/action.ts +!models/authorization-body-params.ts +!models/authorization-context-params.ts +!models/authorized-reponse.ts +!models/index.ts \ No newline at end of file diff --git a/src/infra/authorization-client/authorization-api-client/.openapi-generator/FILES b/src/infra/authorization-client/authorization-api-client/.openapi-generator/FILES new file mode 100644 index 00000000..b0b81500 --- /dev/null +++ b/src/infra/authorization-client/authorization-api-client/.openapi-generator/FILES @@ -0,0 +1,11 @@ +api.ts +api/authorization-api.ts +base.ts +common.ts +configuration.ts +index.ts +models/action.ts +models/authorization-body-params.ts +models/authorization-context-params.ts +models/authorized-reponse.ts +models/index.ts diff --git a/src/infra/authorization-client/authorization-api-client/.openapi-generator/VERSION b/src/infra/authorization-client/authorization-api-client/.openapi-generator/VERSION new file mode 100644 index 00000000..4bc5d618 --- /dev/null +++ b/src/infra/authorization-client/authorization-api-client/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.9.0 diff --git a/src/infra/authorization-client/authorization-api-client/api.ts b/src/infra/authorization-client/authorization-api-client/api.ts new file mode 100644 index 00000000..fc2c3721 --- /dev/null +++ b/src/infra/authorization-client/authorization-api-client/api.ts @@ -0,0 +1,18 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +export * from './api/authorization-api'; + diff --git a/src/infra/authorization-client/authorization-api-client/api/authorization-api.ts b/src/infra/authorization-client/authorization-api-client/api/authorization-api.ts new file mode 100644 index 00000000..cd72a7e6 --- /dev/null +++ b/src/infra/authorization-client/authorization-api-client/api/authorization-api.ts @@ -0,0 +1,159 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import type { Configuration } from '../configuration'; +import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios'; +import globalAxios from 'axios'; +// Some imports not used depending on template conditions +// @ts-ignore +import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from '../common'; +// @ts-ignore +import { BASE_PATH, COLLECTION_FORMATS, type RequestArgs, BaseAPI, RequiredError, operationServerMap } from '../base'; +// @ts-ignore +import type { ApiValidationError } from '../models'; +// @ts-ignore +import type { AuthorizationBodyParams } from '../models'; +// @ts-ignore +import type { AuthorizedReponse } from '../models'; +/** + * AuthorizationApi - axios parameter creator + * @export + */ +export const AuthorizationApiAxiosParamCreator = function (configuration?: Configuration) { + return { + /** + * + * @summary Checks if user is authorized to perform the given operation. + * @param {AuthorizationBodyParams} authorizationBodyParams + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + authorizationReferenceControllerAuthorizeByReference: async (authorizationBodyParams: AuthorizationBodyParams, options: RawAxiosRequestConfig = {}): Promise => { + // verify required parameter 'authorizationBodyParams' is not null or undefined + assertParamExists('authorizationReferenceControllerAuthorizeByReference', 'authorizationBodyParams', authorizationBodyParams) + const localVarPath = `/authorization/by-reference`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication bearer required + // http bearer authentication required + await setBearerAuthToObject(localVarHeaderParameter, configuration) + + + + localVarHeaderParameter['Content-Type'] = 'application/json'; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = serializeDataIfNeeded(authorizationBodyParams, localVarRequestOptions, configuration) + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + } +}; + +/** + * AuthorizationApi - functional programming interface + * @export + */ +export const AuthorizationApiFp = function(configuration?: Configuration) { + const localVarAxiosParamCreator = AuthorizationApiAxiosParamCreator(configuration) + return { + /** + * + * @summary Checks if user is authorized to perform the given operation. + * @param {AuthorizationBodyParams} authorizationBodyParams + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async authorizationReferenceControllerAuthorizeByReference(authorizationBodyParams: AuthorizationBodyParams, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.authorizationReferenceControllerAuthorizeByReference(authorizationBodyParams, options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['AuthorizationApi.authorizationReferenceControllerAuthorizeByReference']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, + } +}; + +/** + * AuthorizationApi - factory interface + * @export + */ +export const AuthorizationApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) { + const localVarFp = AuthorizationApiFp(configuration) + return { + /** + * + * @summary Checks if user is authorized to perform the given operation. + * @param {AuthorizationBodyParams} authorizationBodyParams + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + authorizationReferenceControllerAuthorizeByReference(authorizationBodyParams: AuthorizationBodyParams, options?: RawAxiosRequestConfig): AxiosPromise { + return localVarFp.authorizationReferenceControllerAuthorizeByReference(authorizationBodyParams, options).then((request) => request(axios, basePath)); + }, + }; +}; + +/** + * AuthorizationApi - interface + * @export + * @interface AuthorizationApi + */ +export interface AuthorizationApiInterface { + /** + * + * @summary Checks if user is authorized to perform the given operation. + * @param {AuthorizationBodyParams} authorizationBodyParams + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AuthorizationApiInterface + */ + authorizationReferenceControllerAuthorizeByReference(authorizationBodyParams: AuthorizationBodyParams, options?: RawAxiosRequestConfig): AxiosPromise; + +} + +/** + * AuthorizationApi - object-oriented interface + * @export + * @class AuthorizationApi + * @extends {BaseAPI} + */ +export class AuthorizationApi extends BaseAPI implements AuthorizationApiInterface { + /** + * + * @summary Checks if user is authorized to perform the given operation. + * @param {AuthorizationBodyParams} authorizationBodyParams + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AuthorizationApi + */ + public authorizationReferenceControllerAuthorizeByReference(authorizationBodyParams: AuthorizationBodyParams, options?: RawAxiosRequestConfig) { + return AuthorizationApiFp(this.configuration).authorizationReferenceControllerAuthorizeByReference(authorizationBodyParams, options).then((request) => request(this.axios, this.basePath)); + } +} + diff --git a/src/infra/authorization-client/authorization-api-client/base.ts b/src/infra/authorization-client/authorization-api-client/base.ts new file mode 100644 index 00000000..5bcf014a --- /dev/null +++ b/src/infra/authorization-client/authorization-api-client/base.ts @@ -0,0 +1,86 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import type { Configuration } from './configuration'; +// Some imports not used depending on template conditions +// @ts-ignore +import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios'; +import globalAxios from 'axios'; + +export const BASE_PATH = "http://localhost:3030/api/v3".replace(/\/+$/, ""); + +/** + * + * @export + */ +export const COLLECTION_FORMATS = { + csv: ",", + ssv: " ", + tsv: "\t", + pipes: "|", +}; + +/** + * + * @export + * @interface RequestArgs + */ +export interface RequestArgs { + url: string; + options: RawAxiosRequestConfig; +} + +/** + * + * @export + * @class BaseAPI + */ +export class BaseAPI { + protected configuration: Configuration | undefined; + + constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) { + if (configuration) { + this.configuration = configuration; + this.basePath = configuration.basePath ?? basePath; + } + } +}; + +/** + * + * @export + * @class RequiredError + * @extends {Error} + */ +export class RequiredError extends Error { + constructor(public field: string, msg?: string) { + super(msg); + this.name = "RequiredError" + } +} + +interface ServerMap { + [key: string]: { + url: string, + description: string, + }[]; +} + +/** + * + * @export + */ +export const operationServerMap: ServerMap = { +} diff --git a/src/infra/authorization-client/authorization-api-client/common.ts b/src/infra/authorization-client/authorization-api-client/common.ts new file mode 100644 index 00000000..6c119efb --- /dev/null +++ b/src/infra/authorization-client/authorization-api-client/common.ts @@ -0,0 +1,150 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import type { Configuration } from "./configuration"; +import type { RequestArgs } from "./base"; +import type { AxiosInstance, AxiosResponse } from 'axios'; +import { RequiredError } from "./base"; + +/** + * + * @export + */ +export const DUMMY_BASE_URL = 'https://example.com' + +/** + * + * @throws {RequiredError} + * @export + */ +export const assertParamExists = function (functionName: string, paramName: string, paramValue: unknown) { + if (paramValue === null || paramValue === undefined) { + throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`); + } +} + +/** + * + * @export + */ +export const setApiKeyToObject = async function (object: any, keyParamName: string, configuration?: Configuration) { + if (configuration && configuration.apiKey) { + const localVarApiKeyValue = typeof configuration.apiKey === 'function' + ? await configuration.apiKey(keyParamName) + : await configuration.apiKey; + object[keyParamName] = localVarApiKeyValue; + } +} + +/** + * + * @export + */ +export const setBasicAuthToObject = function (object: any, configuration?: Configuration) { + if (configuration && (configuration.username || configuration.password)) { + object["auth"] = { username: configuration.username, password: configuration.password }; + } +} + +/** + * + * @export + */ +export const setBearerAuthToObject = async function (object: any, configuration?: Configuration) { + if (configuration && configuration.accessToken) { + const accessToken = typeof configuration.accessToken === 'function' + ? await configuration.accessToken() + : await configuration.accessToken; + object["Authorization"] = "Bearer " + accessToken; + } +} + +/** + * + * @export + */ +export const setOAuthToObject = async function (object: any, name: string, scopes: string[], configuration?: Configuration) { + if (configuration && configuration.accessToken) { + const localVarAccessTokenValue = typeof configuration.accessToken === 'function' + ? await configuration.accessToken(name, scopes) + : await configuration.accessToken; + object["Authorization"] = "Bearer " + localVarAccessTokenValue; + } +} + +function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: any, key: string = ""): void { + if (parameter == null) return; + if (typeof parameter === "object") { + if (Array.isArray(parameter)) { + (parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key)); + } + else { + Object.keys(parameter).forEach(currentKey => + setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`) + ); + } + } + else { + if (urlSearchParams.has(key)) { + urlSearchParams.append(key, parameter); + } + else { + urlSearchParams.set(key, parameter); + } + } +} + +/** + * + * @export + */ +export const setSearchParams = function (url: URL, ...objects: any[]) { + const searchParams = new URLSearchParams(url.search); + setFlattenedQueryParams(searchParams, objects); + url.search = searchParams.toString(); +} + +/** + * + * @export + */ +export const serializeDataIfNeeded = function (value: any, requestOptions: any, configuration?: Configuration) { + const nonString = typeof value !== 'string'; + const needsSerialization = nonString && configuration && configuration.isJsonMime + ? configuration.isJsonMime(requestOptions.headers['Content-Type']) + : nonString; + return needsSerialization + ? JSON.stringify(value !== undefined ? value : {}) + : (value || ""); +} + +/** + * + * @export + */ +export const toPathString = function (url: URL) { + return url.pathname + url.search + url.hash +} + +/** + * + * @export + */ +export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) { + return >(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => { + const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url}; + return axios.request(axiosRequestArgs); + }; +} diff --git a/src/infra/authorization-client/authorization-api-client/configuration.ts b/src/infra/authorization-client/authorization-api-client/configuration.ts new file mode 100644 index 00000000..8c97d307 --- /dev/null +++ b/src/infra/authorization-client/authorization-api-client/configuration.ts @@ -0,0 +1,110 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export interface ConfigurationParameters { + apiKey?: string | Promise | ((name: string) => string) | ((name: string) => Promise); + username?: string; + password?: string; + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise); + basePath?: string; + serverIndex?: number; + baseOptions?: any; + formDataCtor?: new () => any; +} + +export class Configuration { + /** + * parameter for apiKey security + * @param name security name + * @memberof Configuration + */ + apiKey?: string | Promise | ((name: string) => string) | ((name: string) => Promise); + /** + * parameter for basic security + * + * @type {string} + * @memberof Configuration + */ + username?: string; + /** + * parameter for basic security + * + * @type {string} + * @memberof Configuration + */ + password?: string; + /** + * parameter for oauth2 security + * @param name security name + * @param scopes oauth2 scope + * @memberof Configuration + */ + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise); + /** + * override base path + * + * @type {string} + * @memberof Configuration + */ + basePath?: string; + /** + * override server index + * + * @type {number} + * @memberof Configuration + */ + serverIndex?: number; + /** + * base options for axios calls + * + * @type {any} + * @memberof Configuration + */ + baseOptions?: any; + /** + * The FormData constructor that will be used to create multipart form data + * requests. You can inject this here so that execution environments that + * do not support the FormData class can still run the generated client. + * + * @type {new () => FormData} + */ + formDataCtor?: new () => any; + + constructor(param: ConfigurationParameters = {}) { + this.apiKey = param.apiKey; + this.username = param.username; + this.password = param.password; + this.accessToken = param.accessToken; + this.basePath = param.basePath; + this.serverIndex = param.serverIndex; + this.baseOptions = param.baseOptions; + this.formDataCtor = param.formDataCtor; + } + + /** + * Check if the given MIME is a JSON MIME. + * JSON MIME examples: + * application/json + * application/json; charset=UTF8 + * APPLICATION/JSON + * application/vnd.company+json + * @param mime - MIME (Multipurpose Internet Mail Extensions) + * @return True if the given MIME is JSON, false otherwise. + */ + public isJsonMime(mime: string): boolean { + const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); + return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); + } +} diff --git a/src/infra/authorization-client/authorization-api-client/index.ts b/src/infra/authorization-client/authorization-api-client/index.ts new file mode 100644 index 00000000..8b762df6 --- /dev/null +++ b/src/infra/authorization-client/authorization-api-client/index.ts @@ -0,0 +1,18 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export * from "./api"; +export * from "./configuration"; +export * from "./models"; diff --git a/src/infra/authorization-client/authorization-api-client/models/action.ts b/src/infra/authorization-client/authorization-api-client/models/action.ts new file mode 100644 index 00000000..c74334d3 --- /dev/null +++ b/src/infra/authorization-client/authorization-api-client/models/action.ts @@ -0,0 +1,31 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +/** + * + * @export + * @enum {string} + */ + +export const Action = { + READ: 'read', + WRITE: 'write' +} as const; + +export type Action = typeof Action[keyof typeof Action]; + + + diff --git a/src/infra/authorization-client/authorization-api-client/models/authorization-body-params.ts b/src/infra/authorization-client/authorization-api-client/models/authorization-body-params.ts new file mode 100644 index 00000000..cea578bd --- /dev/null +++ b/src/infra/authorization-client/authorization-api-client/models/authorization-body-params.ts @@ -0,0 +1,64 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +// May contain unused imports in some cases +// @ts-ignore +import type { AuthorizationContextParams } from './authorization-context-params'; + +/** + * + * @export + * @interface AuthorizationBodyParams + */ +export interface AuthorizationBodyParams { + /** + * + * @type {AuthorizationContextParams} + * @memberof AuthorizationBodyParams + */ + 'context': AuthorizationContextParams; + /** + * The entity or domain object the operation should be performed on. + * @type {string} + * @memberof AuthorizationBodyParams + */ + 'referenceType': AuthorizationBodyParamsReferenceType; + /** + * The id of the entity/domain object of the defined referenceType. + * @type {string} + * @memberof AuthorizationBodyParams + */ + 'referenceId': string; +} + +export const AuthorizationBodyParamsReferenceType = { + USERS: 'users', + SCHOOLS: 'schools', + COURSES: 'courses', + COURSEGROUPS: 'coursegroups', + TASKS: 'tasks', + LESSONS: 'lessons', + TEAMS: 'teams', + SUBMISSIONS: 'submissions', + SCHOOL_EXTERNAL_TOOLS: 'school-external-tools', + BOARDNODES: 'boardnodes', + CONTEXT_EXTERNAL_TOOLS: 'context-external-tools', + EXTERNAL_TOOLS: 'external-tools', + INSTANCES: 'instances' +} as const; + +export type AuthorizationBodyParamsReferenceType = typeof AuthorizationBodyParamsReferenceType[keyof typeof AuthorizationBodyParamsReferenceType]; + + diff --git a/src/infra/authorization-client/authorization-api-client/models/authorization-context-params.ts b/src/infra/authorization-client/authorization-api-client/models/authorization-context-params.ts new file mode 100644 index 00000000..055adfae --- /dev/null +++ b/src/infra/authorization-client/authorization-api-client/models/authorization-context-params.ts @@ -0,0 +1,44 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +// May contain unused imports in some cases +// @ts-ignore +import type { Action } from './action'; +// May contain unused imports in some cases +// @ts-ignore +import type { Permission } from './permission'; + +/** + * + * @export + * @interface AuthorizationContextParams + */ +export interface AuthorizationContextParams { + /** + * + * @type {Action} + * @memberof AuthorizationContextParams + */ + 'action': Action; + /** + * User permissions that are needed to execute the operation. + * @type {Array} + * @memberof AuthorizationContextParams + */ + 'requiredPermissions': Array; +} + + + diff --git a/src/infra/authorization-client/authorization-api-client/models/authorized-reponse.ts b/src/infra/authorization-client/authorization-api-client/models/authorized-reponse.ts new file mode 100644 index 00000000..b69c757a --- /dev/null +++ b/src/infra/authorization-client/authorization-api-client/models/authorized-reponse.ts @@ -0,0 +1,36 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +/** + * + * @export + * @interface AuthorizedReponse + */ +export interface AuthorizedReponse { + /** + * + * @type {string} + * @memberof AuthorizedReponse + */ + 'userId': string; + /** + * + * @type {boolean} + * @memberof AuthorizedReponse + */ + 'isAuthorized': boolean; +} + diff --git a/src/infra/authorization-client/authorization-api-client/models/index.ts b/src/infra/authorization-client/authorization-api-client/models/index.ts new file mode 100644 index 00000000..d441002f --- /dev/null +++ b/src/infra/authorization-client/authorization-api-client/models/index.ts @@ -0,0 +1,281 @@ +export * from './account-by-id-body-params'; +export * from './account-response'; +export * from './account-search-list-response'; +export * from './action'; +export * from './alert-response'; +export * from './api-validation-error'; +export * from './authorization-body-params'; +export * from './authorization-context-params'; +export * from './authorized-reponse'; +export * from './basic-tool-config-params'; +export * from './board-context-response'; +export * from './board-element-response'; +export * from './board-external-reference-type'; +export * from './board-layout'; +export * from './board-parent-type'; +export * from './board-response'; +export * from './board-submission-controller-create-element201-response'; +export * from './card-controller-create-element201-response'; +export * from './card-list-response'; +export * from './card-response'; +export * from './card-response-elements-inner'; +export * from './card-skeleton-response'; +export * from './change-language-params'; +export * from './class-info-response'; +export * from './class-info-search-list-response'; +export * from './class-request-context'; +export * from './class-response'; +export * from './class-sort-query-type'; +export * from './collaborative-text-editor-element-response'; +export * from './collaborative-text-editor-parent-type'; +export * from './collaborative-text-editor-response'; +export * from './collapsable-body-params'; +export * from './color-body-params'; +export * from './column-response'; +export * from './config-response'; +export * from './consent-request-body'; +export * from './consent-response'; +export * from './consent-session-response'; +export * from './consents-response'; +export * from './content-element-type'; +export * from './context-external-tool-body-params'; +export * from './context-external-tool-configuration-status-response'; +export * from './context-external-tool-configuration-template-list-response'; +export * from './context-external-tool-configuration-template-response'; +export * from './context-external-tool-count-per-context-response'; +export * from './context-external-tool-post-params'; +export * from './context-external-tool-response'; +export * from './context-external-tool-search-list-response'; +export * from './copy-api-response'; +export * from './county-response'; +export * from './course-common-cartridge-metadata-response'; +export * from './course-export-body-params'; +export * from './course-info-data-response'; +export * from './course-info-list-response'; +export * from './course-info-response'; +export * from './course-metadata-list-response'; +export * from './course-metadata-response'; +export * from './course-sort-props'; +export * from './course-status'; +export * from './course-sync-body-params'; +export * from './create-board-body-params'; +export * from './create-board-response'; +export * from './create-card-body-params'; +export * from './create-content-element-body-params'; +export * from './create-media-element-body-params'; +export * from './create-news-params'; +export * from './create-room-body-params'; +export * from './create-submission-item-body-params'; +export * from './custom-parameter-entry-param'; +export * from './custom-parameter-entry-response'; +export * from './custom-parameter-post-params'; +export * from './custom-parameter-response'; +export * from './dashboard-grid-element-response'; +export * from './dashboard-grid-sub-element-response'; +export * from './dashboard-response'; +export * from './deleted-element-content'; +export * from './deleted-element-response'; +export * from './drawing-content-body'; +export * from './drawing-element-content'; +export * from './drawing-element-content-body'; +export * from './drawing-element-response'; +export * from './element-controller-update-element201-response'; +export * from './entity-not-found-error'; +export * from './external-source-response'; +export * from './external-tool-bulk-create-params'; +export * from './external-tool-content-body'; +export * from './external-tool-create-params'; +export * from './external-tool-element-content'; +export * from './external-tool-element-content-body'; +export * from './external-tool-element-response'; +export * from './external-tool-medium-params'; +export * from './external-tool-medium-response'; +export * from './external-tool-metadata-response'; +export * from './external-tool-response'; +export * from './external-tool-response-config'; +export * from './external-tool-search-list-response'; +export * from './external-tool-update-params'; +export * from './external-tool-update-params-config'; +export * from './federal-state-response'; +export * from './file-content-body'; +export * from './file-element-content'; +export * from './file-element-content-body'; +export * from './file-element-response'; +export * from './file-storage-type'; +export * from './forbidden-operation-error'; +export * from './force-migration-params'; +export * from './get-meta-tag-data-body'; +export * from './group-list-response'; +export * from './group-response'; +export * from './group-user-response'; +export * from './import-user-list-response'; +export * from './import-user-response'; +export * from './layout-body-params'; +export * from './ldap-authorization-body-params'; +export * from './lesson-content-response'; +export * from './lesson-copy-api-params'; +export * from './lesson-linked-task-response'; +export * from './lesson-metadata-list-response'; +export * from './lesson-metadata-response'; +export * from './lesson-response'; +export * from './link-content-body'; +export * from './link-element-content'; +export * from './link-element-content-body'; +export * from './link-element-response'; +export * from './local-authorization-body-params'; +export * from './login-request-body'; +export * from './login-response'; +export * from './lti11-tool-config-create-params'; +export * from './lti11-tool-config-update-params'; +export * from './lti-message-type'; +export * from './lti-privacy-permission'; +export * from './material-response'; +export * from './me-account-response'; +export * from './me-response'; +export * from './me-role-response'; +export * from './me-school-logo-response'; +export * from './me-school-response'; +export * from './me-user-response'; +export * from './media-available-line-element-response'; +export * from './media-available-line-response'; +export * from './media-board-colors'; +export * from './media-board-layout-type'; +export * from './media-board-response'; +export * from './media-external-tool-element-content'; +export * from './media-external-tool-element-response'; +export * from './media-line-response'; +export * from './media-line-response-elements-inner'; +export * from './message'; +export * from './message-origin'; +export * from './meta-tag-extractor-response'; +export * from './move-card-body-params'; +export * from './move-column-body-params'; +export * from './move-content-element-body'; +export * from './move-element-body-params'; +export * from './move-element-params'; +export * from './move-element-position-params'; +export * from './news-list-response'; +export * from './news-response'; +export * from './news-target-model'; +export * from './oauth-token-dto'; +export * from './oauth2-authorization-body-params'; +export * from './oauth2-migration-params'; +export * from './oauth2-tool-config-create-params'; +export * from './oauth2-tool-config-update-params'; +export * from './oauth-client-create-body'; +export * from './oauth-client-response'; +export * from './oauth-client-update-body'; +export * from './oauth-config-response'; +export * from './oauth-provider-login-response'; +export * from './oidc-context-response'; +export * from './parent-consent-response'; +export * from './patch-group-params'; +export * from './patch-my-account-params'; +export * from './patch-my-password-params'; +export * from './patch-order-params'; +export * from './patch-visibility-params'; +export * from './period-response'; +export * from './provider-config-response'; +export * from './pseudonym-response'; +export * from './public-system-list-response'; +export * from './public-system-response'; +export * from './redirect-response'; +export * from './rename-body-params'; +export * from './resolved-user-response'; +export * from './rich-text'; +export * from './rich-text-content-body'; +export * from './rich-text-element-content'; +export * from './rich-text-element-content-body'; +export * from './rich-text-element-response'; +export * from './role-name'; +export * from './room-color'; +export * from './room-details-response'; +export * from './room-item-response'; +export * from './room-list-response'; +export * from './school-controller-get-provisioning-options200-response'; +export * from './school-exists-response'; +export * from './school-external-tool-configuration-status-response'; +export * from './school-external-tool-configuration-template-list-response'; +export * from './school-external-tool-configuration-template-response'; +export * from './school-external-tool-metadata-response'; +export * from './school-external-tool-post-params'; +export * from './school-external-tool-response'; +export * from './school-external-tool-search-list-response'; +export * from './school-for-external-invite-response'; +export * from './school-for-ldap-login-response'; +export * from './school-info-response'; +export * from './school-logo'; +export * from './school-permissions-params'; +export * from './school-purpose'; +export * from './school-response'; +export * from './school-system-response'; +export * from './school-update-body-params'; +export * from './school-year-query-type'; +export * from './school-year-response'; +export * from './schul-conne-xprovisioning-options-params'; +export * from './schul-conne-xprovisioning-options-response'; +export * from './schulcloud-theme'; +export * from './set-height-body-params'; +export * from './share-token-body-params'; +export * from './share-token-import-body-params'; +export * from './share-token-info-response'; +export * from './share-token-payload-response'; +export * from './share-token-response'; +export * from './single-column-board-response'; +export * from './student-permission-params'; +export * from './submission-container-content-body'; +export * from './submission-container-element-content'; +export * from './submission-container-element-content-body'; +export * from './submission-container-element-response'; +export * from './submission-item-response'; +export * from './submission-item-response-elements-inner'; +export * from './submission-status-list-response'; +export * from './submission-status-response'; +export * from './submissions-response'; +export * from './successful-response'; +export * from './system-for-ldap-login-response'; +export * from './system-type'; +export * from './target-info-response'; +export * from './target-user-id-params'; +export * from './task-copy-api-params'; +export * from './task-list-response'; +export * from './task-response'; +export * from './task-status-response'; +export * from './teacher-permission-params'; +export * from './team-permissions-body'; +export * from './timestamps-response'; +export * from './timezone'; +export * from './tool-config-type'; +export * from './tool-context-type'; +export * from './tool-context-types-list-response'; +export * from './tool-launch-request-response'; +export * from './tool-reference-list-response'; +export * from './tool-reference-response'; +export * from './update-board-title-params'; +export * from './update-element-content-body-params'; +export * from './update-element-content-body-params-data'; +export * from './update-flag-params'; +export * from './update-match-params'; +export * from './update-news-params'; +export * from './update-room-body-params'; +export * from './update-submission-item-body-params'; +export * from './user-consent-response'; +export * from './user-data-response'; +export * from './user-info-response'; +export * from './user-list-response'; +export * from './user-login-migration-mandatory-params'; +export * from './user-login-migration-response'; +export * from './user-login-migration-search-list-response'; +export * from './user-match-list-response'; +export * from './user-match-response'; +export * from './user-response'; +export * from './validation-error'; +export * from './video-conference-create-params'; +export * from './video-conference-info-response'; +export * from './video-conference-join-response'; +export * from './video-conference-options-response'; +export * from './video-conference-scope'; +export * from './video-conference-state-response'; +export * from './visibility-body-params'; +export * from './visibility-settings-response'; +export * from './years-response'; From 01d1b705bfc0cd5c8ba794d17ba47b5ab026be12 Mon Sep 17 00:00:00 2001 From: Constantin Bergatt Date: Thu, 10 Oct 2024 07:20:35 +0200 Subject: [PATCH 02/16] BC-7879 - move generated openAPI client to `src/infra/authorization/authorization-api-client` --- package.json | 2 +- .../authorization-api-client/.openapi-generator-ignore | 0 .../authorization-api-client/.openapi-generator/FILES | 0 .../authorization-api-client/.openapi-generator/VERSION | 0 .../authorization-api-client/api.ts | 0 .../authorization-api-client/api/authorization-api.ts | 0 .../authorization-api-client/base.ts | 0 .../authorization-api-client/common.ts | 0 .../authorization-api-client/configuration.ts | 0 .../authorization-api-client/index.ts | 0 .../authorization-api-client/models/action.ts | 0 .../models/authorization-body-params.ts | 0 .../models/authorization-context-params.ts | 0 .../authorization-api-client/models/authorized-reponse.ts | 0 .../authorization-api-client/models/index.ts | 0 15 files changed, 1 insertion(+), 1 deletion(-) rename src/infra/{authorization-client => authorization}/authorization-api-client/.openapi-generator-ignore (100%) rename src/infra/{authorization-client => authorization}/authorization-api-client/.openapi-generator/FILES (100%) rename src/infra/{authorization-client => authorization}/authorization-api-client/.openapi-generator/VERSION (100%) rename src/infra/{authorization-client => authorization}/authorization-api-client/api.ts (100%) rename src/infra/{authorization-client => authorization}/authorization-api-client/api/authorization-api.ts (100%) rename src/infra/{authorization-client => authorization}/authorization-api-client/base.ts (100%) rename src/infra/{authorization-client => authorization}/authorization-api-client/common.ts (100%) rename src/infra/{authorization-client => authorization}/authorization-api-client/configuration.ts (100%) rename src/infra/{authorization-client => authorization}/authorization-api-client/index.ts (100%) rename src/infra/{authorization-client => authorization}/authorization-api-client/models/action.ts (100%) rename src/infra/{authorization-client => authorization}/authorization-api-client/models/authorization-body-params.ts (100%) rename src/infra/{authorization-client => authorization}/authorization-api-client/models/authorization-context-params.ts (100%) rename src/infra/{authorization-client => authorization}/authorization-api-client/models/authorized-reponse.ts (100%) rename src/infra/{authorization-client => authorization}/authorization-api-client/models/index.ts (100%) diff --git a/package.json b/package.json index a6dd4778..4bda51d0 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "test:watch": "jest --watch", "test:cov": "jest --coverage", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", - "generate-client:authorization": "node ./scripts/generate-client.js -u 'http://localhost:3030/api/v3/docs-json/' -p 'src/infra/authorization-client/authorization-api-client' -c 'openapitools-config.json' -f 'operationId:AuthorizationReferenceController_authorizeByReference'" + "generate-client:authorization": "node ./scripts/generate-client.js -u 'http://localhost:3030/api/v3/docs-json/' -p 'src/infra/authorization/authorization-api-client' -c 'openapitools-config.json' -f 'operationId:AuthorizationReferenceController_authorizeByReference'" }, "dependencies": { "@golevelup/ts-jest": "^0.5.4", diff --git a/src/infra/authorization-client/authorization-api-client/.openapi-generator-ignore b/src/infra/authorization/authorization-api-client/.openapi-generator-ignore similarity index 100% rename from src/infra/authorization-client/authorization-api-client/.openapi-generator-ignore rename to src/infra/authorization/authorization-api-client/.openapi-generator-ignore diff --git a/src/infra/authorization-client/authorization-api-client/.openapi-generator/FILES b/src/infra/authorization/authorization-api-client/.openapi-generator/FILES similarity index 100% rename from src/infra/authorization-client/authorization-api-client/.openapi-generator/FILES rename to src/infra/authorization/authorization-api-client/.openapi-generator/FILES diff --git a/src/infra/authorization-client/authorization-api-client/.openapi-generator/VERSION b/src/infra/authorization/authorization-api-client/.openapi-generator/VERSION similarity index 100% rename from src/infra/authorization-client/authorization-api-client/.openapi-generator/VERSION rename to src/infra/authorization/authorization-api-client/.openapi-generator/VERSION diff --git a/src/infra/authorization-client/authorization-api-client/api.ts b/src/infra/authorization/authorization-api-client/api.ts similarity index 100% rename from src/infra/authorization-client/authorization-api-client/api.ts rename to src/infra/authorization/authorization-api-client/api.ts diff --git a/src/infra/authorization-client/authorization-api-client/api/authorization-api.ts b/src/infra/authorization/authorization-api-client/api/authorization-api.ts similarity index 100% rename from src/infra/authorization-client/authorization-api-client/api/authorization-api.ts rename to src/infra/authorization/authorization-api-client/api/authorization-api.ts diff --git a/src/infra/authorization-client/authorization-api-client/base.ts b/src/infra/authorization/authorization-api-client/base.ts similarity index 100% rename from src/infra/authorization-client/authorization-api-client/base.ts rename to src/infra/authorization/authorization-api-client/base.ts diff --git a/src/infra/authorization-client/authorization-api-client/common.ts b/src/infra/authorization/authorization-api-client/common.ts similarity index 100% rename from src/infra/authorization-client/authorization-api-client/common.ts rename to src/infra/authorization/authorization-api-client/common.ts diff --git a/src/infra/authorization-client/authorization-api-client/configuration.ts b/src/infra/authorization/authorization-api-client/configuration.ts similarity index 100% rename from src/infra/authorization-client/authorization-api-client/configuration.ts rename to src/infra/authorization/authorization-api-client/configuration.ts diff --git a/src/infra/authorization-client/authorization-api-client/index.ts b/src/infra/authorization/authorization-api-client/index.ts similarity index 100% rename from src/infra/authorization-client/authorization-api-client/index.ts rename to src/infra/authorization/authorization-api-client/index.ts diff --git a/src/infra/authorization-client/authorization-api-client/models/action.ts b/src/infra/authorization/authorization-api-client/models/action.ts similarity index 100% rename from src/infra/authorization-client/authorization-api-client/models/action.ts rename to src/infra/authorization/authorization-api-client/models/action.ts diff --git a/src/infra/authorization-client/authorization-api-client/models/authorization-body-params.ts b/src/infra/authorization/authorization-api-client/models/authorization-body-params.ts similarity index 100% rename from src/infra/authorization-client/authorization-api-client/models/authorization-body-params.ts rename to src/infra/authorization/authorization-api-client/models/authorization-body-params.ts diff --git a/src/infra/authorization-client/authorization-api-client/models/authorization-context-params.ts b/src/infra/authorization/authorization-api-client/models/authorization-context-params.ts similarity index 100% rename from src/infra/authorization-client/authorization-api-client/models/authorization-context-params.ts rename to src/infra/authorization/authorization-api-client/models/authorization-context-params.ts diff --git a/src/infra/authorization-client/authorization-api-client/models/authorized-reponse.ts b/src/infra/authorization/authorization-api-client/models/authorized-reponse.ts similarity index 100% rename from src/infra/authorization-client/authorization-api-client/models/authorized-reponse.ts rename to src/infra/authorization/authorization-api-client/models/authorized-reponse.ts diff --git a/src/infra/authorization-client/authorization-api-client/models/index.ts b/src/infra/authorization/authorization-api-client/models/index.ts similarity index 100% rename from src/infra/authorization-client/authorization-api-client/models/index.ts rename to src/infra/authorization/authorization-api-client/models/index.ts From 57ef65ae015081cb05844ee13e040d70d9b59f5e Mon Sep 17 00:00:00 2001 From: Constantin Bergatt Date: Thu, 10 Oct 2024 08:27:03 +0200 Subject: [PATCH 03/16] BC-7879 - refactor authorization service to use generated openAPI client --- .../authorization.service.spec.ts | 56 ++++++++++--------- .../authorization/authorization.service.ts | 48 +++++++--------- 2 files changed, 48 insertions(+), 56 deletions(-) diff --git a/src/infra/authorization/authorization.service.spec.ts b/src/infra/authorization/authorization.service.spec.ts index bac09569..de7c093f 100644 --- a/src/infra/authorization/authorization.service.spec.ts +++ b/src/infra/authorization/authorization.service.spec.ts @@ -1,22 +1,24 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; -import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; +import { AxiosResponse } from 'axios'; import { HttpRequest } from 'uws'; import { Logger } from '../logging/logger.js'; +import { AuthorizationApi } from './authorization-api-client/api/authorization-api.js'; +import { AuthorizedReponse } from './authorization-api-client/models/authorized-reponse.js'; import { AuthorizationService } from './authorization.service.js'; describe(AuthorizationService.name, () => { let module: TestingModule; let service: AuthorizationService; - let configService: DeepMocked; + let authorizationApi: DeepMocked; beforeAll(async () => { module = await Test.createTestingModule({ providers: [ AuthorizationService, { - provide: ConfigService, - useValue: createMock(), + provide: AuthorizationApi, + useValue: createMock(), }, { provide: Logger, @@ -26,7 +28,7 @@ describe(AuthorizationService.name, () => { }).compile(); service = module.get(AuthorizationService); - configService = module.get(ConfigService); + authorizationApi = module.get(AuthorizationApi); }); afterAll(async () => { @@ -41,21 +43,22 @@ describe(AuthorizationService.name, () => { const req: DeepMocked = createMock(); jest.spyOn(req, 'getParameter').mockReturnValue(roomId); jest.spyOn(req, 'getHeader').mockReturnValue(cookies); - configService.getOrThrow.mockReturnValue('API_HOST'); - const fetchSpy = jest.spyOn(global, 'fetch'); - return { req, fetchSpy }; + return { req }; }; describe('hasPermission', () => { describe('when the user request has permission', () => { const setup = () => { - const { req, fetchSpy } = setupRequest(); + const { req } = setupRequest(); - fetchSpy.mockResolvedValue({ - ok: true, - json: () => Promise.resolve({ isAuthorized: true, userId: '123' }), - } as unknown as Promise); + const response = createMock>({ + data: { + isAuthorized: true, + userId: '123', + }, + }); + authorizationApi.authorizationReferenceControllerAuthorizeByReference.mockResolvedValueOnce(response); const expectedResult = { error: null, hasWriteAccess: true, room: 'roomId', userid: '123' }; @@ -73,12 +76,15 @@ describe(AuthorizationService.name, () => { describe('when the user has no permission', () => { const setup = () => { - const { req, fetchSpy } = setupRequest(); + const { req } = setupRequest(); - fetchSpy.mockResolvedValue({ - ok: true, - json: () => Promise.resolve({ isAuthorized: false, userId: '123' }), - } as unknown as Promise); + const response = createMock>({ + data: { + isAuthorized: false, + userId: '123', + }, + }); + authorizationApi.authorizationReferenceControllerAuthorizeByReference.mockResolvedValueOnce(response); const expectedResult = { error: { @@ -155,19 +161,15 @@ describe(AuthorizationService.name, () => { describe('when the roomId not found on server', () => { const setup = () => { - const { req, fetchSpy } = setupRequest(); + const { req } = setupRequest(); - fetchSpy.mockResolvedValue({ - ok: false, - status: 404, - statusText: 'Not Found', - json: () => Promise.resolve({}), - } as unknown as Promise); + const error = new Error('testError'); + authorizationApi.authorizationReferenceControllerAuthorizeByReference.mockRejectedValueOnce(error); const expectedResult = { error: { - code: 4404, - reason: 'Not Found', + code: 4500, + reason: 'testError', }, hasWriteAccess: false, room: null, diff --git a/src/infra/authorization/authorization.service.ts b/src/infra/authorization/authorization.service.ts index 9f50df91..09c2f11f 100644 --- a/src/infra/authorization/authorization.service.ts +++ b/src/infra/authorization/authorization.service.ts @@ -1,14 +1,20 @@ import { Injectable } from '@nestjs/common'; -import { ConfigService } from '@nestjs/config'; +import { RawAxiosRequestConfig } from 'axios'; import { HttpRequest } from 'uws'; import { Logger } from '../logging/logger.js'; +import { AuthorizationApi } from './authorization-api-client/api/authorization-api.js'; +import { Action } from './authorization-api-client/models/action.js'; +import { + AuthorizationBodyParams, + AuthorizationBodyParamsReferenceType, +} from './authorization-api-client/models/authorization-body-params.js'; import { ResponsePayload } from './interfaces/response.payload.js'; import { ResponsePayloadBuilder } from './response.builder.js'; @Injectable() export class AuthorizationService { public constructor( - private configService: ConfigService, + private readonly authorizationApi: AuthorizationApi, private logger: Logger, ) { logger.setContext(AuthorizationService.name); @@ -49,16 +55,20 @@ export class AuthorizationService { } private async fetchAuthorization(room: string, token: string): Promise { - const apiHost = this.configService.getOrThrow('API_HOST'); - const requestOptions = this.createAuthzRequestOptions(room, token); + const params: AuthorizationBodyParams = { + referenceType: AuthorizationBodyParamsReferenceType.BOARDNODES, + referenceId: room, + context: { + action: Action.READ, + requiredPermissions: ['COURSE_VIEW'], + }, + }; - const response = await fetch(`${apiHost}/api/v3/authorization/by-reference`, requestOptions); + const options: RawAxiosRequestConfig = { headers: { authorization: `Bearer ${token}` } }; - if (!response.ok) { - return this.createErrorResponsePayload(4000 + response.status, response.statusText); - } + const response = await this.authorizationApi.authorizationReferenceControllerAuthorizeByReference(params, options); - const { isAuthorized, userId } = await response.json(); + const { isAuthorized, userId } = response.data; if (!isAuthorized) { return this.createErrorResponsePayload(4401, 'Unauthorized'); } @@ -66,26 +76,6 @@ export class AuthorizationService { return this.createResponsePayload(room, userId); } - private createAuthzRequestOptions(room: string, token: string): RequestInit { - const requestOptions = { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - Authorization: 'Bearer ' + token, - }, - body: JSON.stringify({ - context: { - action: 'read', - requiredPermissions: ['COURSE_VIEW'], - }, - referenceType: 'boardnodes', - referenceId: room, - }), - }; - - return requestOptions; - } - private createResponsePayload(room: string, userId: string): ResponsePayload { const response = ResponsePayloadBuilder.build(room, userId, null, true); From 55d58dadfc41e847bc1193f1561de2bfe930df83 Mon Sep 17 00:00:00 2001 From: Constantin Bergatt Date: Thu, 10 Oct 2024 08:50:45 +0200 Subject: [PATCH 04/16] BC-7879 - remove not available models from index file --- .../authorization-api-client/models/index.ts | 285 +----------------- 1 file changed, 4 insertions(+), 281 deletions(-) diff --git a/src/infra/authorization/authorization-api-client/models/index.ts b/src/infra/authorization/authorization-api-client/models/index.ts index d441002f..6e494cd9 100644 --- a/src/infra/authorization/authorization-api-client/models/index.ts +++ b/src/infra/authorization/authorization-api-client/models/index.ts @@ -1,281 +1,4 @@ -export * from './account-by-id-body-params'; -export * from './account-response'; -export * from './account-search-list-response'; -export * from './action'; -export * from './alert-response'; -export * from './api-validation-error'; -export * from './authorization-body-params'; -export * from './authorization-context-params'; -export * from './authorized-reponse'; -export * from './basic-tool-config-params'; -export * from './board-context-response'; -export * from './board-element-response'; -export * from './board-external-reference-type'; -export * from './board-layout'; -export * from './board-parent-type'; -export * from './board-response'; -export * from './board-submission-controller-create-element201-response'; -export * from './card-controller-create-element201-response'; -export * from './card-list-response'; -export * from './card-response'; -export * from './card-response-elements-inner'; -export * from './card-skeleton-response'; -export * from './change-language-params'; -export * from './class-info-response'; -export * from './class-info-search-list-response'; -export * from './class-request-context'; -export * from './class-response'; -export * from './class-sort-query-type'; -export * from './collaborative-text-editor-element-response'; -export * from './collaborative-text-editor-parent-type'; -export * from './collaborative-text-editor-response'; -export * from './collapsable-body-params'; -export * from './color-body-params'; -export * from './column-response'; -export * from './config-response'; -export * from './consent-request-body'; -export * from './consent-response'; -export * from './consent-session-response'; -export * from './consents-response'; -export * from './content-element-type'; -export * from './context-external-tool-body-params'; -export * from './context-external-tool-configuration-status-response'; -export * from './context-external-tool-configuration-template-list-response'; -export * from './context-external-tool-configuration-template-response'; -export * from './context-external-tool-count-per-context-response'; -export * from './context-external-tool-post-params'; -export * from './context-external-tool-response'; -export * from './context-external-tool-search-list-response'; -export * from './copy-api-response'; -export * from './county-response'; -export * from './course-common-cartridge-metadata-response'; -export * from './course-export-body-params'; -export * from './course-info-data-response'; -export * from './course-info-list-response'; -export * from './course-info-response'; -export * from './course-metadata-list-response'; -export * from './course-metadata-response'; -export * from './course-sort-props'; -export * from './course-status'; -export * from './course-sync-body-params'; -export * from './create-board-body-params'; -export * from './create-board-response'; -export * from './create-card-body-params'; -export * from './create-content-element-body-params'; -export * from './create-media-element-body-params'; -export * from './create-news-params'; -export * from './create-room-body-params'; -export * from './create-submission-item-body-params'; -export * from './custom-parameter-entry-param'; -export * from './custom-parameter-entry-response'; -export * from './custom-parameter-post-params'; -export * from './custom-parameter-response'; -export * from './dashboard-grid-element-response'; -export * from './dashboard-grid-sub-element-response'; -export * from './dashboard-response'; -export * from './deleted-element-content'; -export * from './deleted-element-response'; -export * from './drawing-content-body'; -export * from './drawing-element-content'; -export * from './drawing-element-content-body'; -export * from './drawing-element-response'; -export * from './element-controller-update-element201-response'; -export * from './entity-not-found-error'; -export * from './external-source-response'; -export * from './external-tool-bulk-create-params'; -export * from './external-tool-content-body'; -export * from './external-tool-create-params'; -export * from './external-tool-element-content'; -export * from './external-tool-element-content-body'; -export * from './external-tool-element-response'; -export * from './external-tool-medium-params'; -export * from './external-tool-medium-response'; -export * from './external-tool-metadata-response'; -export * from './external-tool-response'; -export * from './external-tool-response-config'; -export * from './external-tool-search-list-response'; -export * from './external-tool-update-params'; -export * from './external-tool-update-params-config'; -export * from './federal-state-response'; -export * from './file-content-body'; -export * from './file-element-content'; -export * from './file-element-content-body'; -export * from './file-element-response'; -export * from './file-storage-type'; -export * from './forbidden-operation-error'; -export * from './force-migration-params'; -export * from './get-meta-tag-data-body'; -export * from './group-list-response'; -export * from './group-response'; -export * from './group-user-response'; -export * from './import-user-list-response'; -export * from './import-user-response'; -export * from './layout-body-params'; -export * from './ldap-authorization-body-params'; -export * from './lesson-content-response'; -export * from './lesson-copy-api-params'; -export * from './lesson-linked-task-response'; -export * from './lesson-metadata-list-response'; -export * from './lesson-metadata-response'; -export * from './lesson-response'; -export * from './link-content-body'; -export * from './link-element-content'; -export * from './link-element-content-body'; -export * from './link-element-response'; -export * from './local-authorization-body-params'; -export * from './login-request-body'; -export * from './login-response'; -export * from './lti11-tool-config-create-params'; -export * from './lti11-tool-config-update-params'; -export * from './lti-message-type'; -export * from './lti-privacy-permission'; -export * from './material-response'; -export * from './me-account-response'; -export * from './me-response'; -export * from './me-role-response'; -export * from './me-school-logo-response'; -export * from './me-school-response'; -export * from './me-user-response'; -export * from './media-available-line-element-response'; -export * from './media-available-line-response'; -export * from './media-board-colors'; -export * from './media-board-layout-type'; -export * from './media-board-response'; -export * from './media-external-tool-element-content'; -export * from './media-external-tool-element-response'; -export * from './media-line-response'; -export * from './media-line-response-elements-inner'; -export * from './message'; -export * from './message-origin'; -export * from './meta-tag-extractor-response'; -export * from './move-card-body-params'; -export * from './move-column-body-params'; -export * from './move-content-element-body'; -export * from './move-element-body-params'; -export * from './move-element-params'; -export * from './move-element-position-params'; -export * from './news-list-response'; -export * from './news-response'; -export * from './news-target-model'; -export * from './oauth-token-dto'; -export * from './oauth2-authorization-body-params'; -export * from './oauth2-migration-params'; -export * from './oauth2-tool-config-create-params'; -export * from './oauth2-tool-config-update-params'; -export * from './oauth-client-create-body'; -export * from './oauth-client-response'; -export * from './oauth-client-update-body'; -export * from './oauth-config-response'; -export * from './oauth-provider-login-response'; -export * from './oidc-context-response'; -export * from './parent-consent-response'; -export * from './patch-group-params'; -export * from './patch-my-account-params'; -export * from './patch-my-password-params'; -export * from './patch-order-params'; -export * from './patch-visibility-params'; -export * from './period-response'; -export * from './provider-config-response'; -export * from './pseudonym-response'; -export * from './public-system-list-response'; -export * from './public-system-response'; -export * from './redirect-response'; -export * from './rename-body-params'; -export * from './resolved-user-response'; -export * from './rich-text'; -export * from './rich-text-content-body'; -export * from './rich-text-element-content'; -export * from './rich-text-element-content-body'; -export * from './rich-text-element-response'; -export * from './role-name'; -export * from './room-color'; -export * from './room-details-response'; -export * from './room-item-response'; -export * from './room-list-response'; -export * from './school-controller-get-provisioning-options200-response'; -export * from './school-exists-response'; -export * from './school-external-tool-configuration-status-response'; -export * from './school-external-tool-configuration-template-list-response'; -export * from './school-external-tool-configuration-template-response'; -export * from './school-external-tool-metadata-response'; -export * from './school-external-tool-post-params'; -export * from './school-external-tool-response'; -export * from './school-external-tool-search-list-response'; -export * from './school-for-external-invite-response'; -export * from './school-for-ldap-login-response'; -export * from './school-info-response'; -export * from './school-logo'; -export * from './school-permissions-params'; -export * from './school-purpose'; -export * from './school-response'; -export * from './school-system-response'; -export * from './school-update-body-params'; -export * from './school-year-query-type'; -export * from './school-year-response'; -export * from './schul-conne-xprovisioning-options-params'; -export * from './schul-conne-xprovisioning-options-response'; -export * from './schulcloud-theme'; -export * from './set-height-body-params'; -export * from './share-token-body-params'; -export * from './share-token-import-body-params'; -export * from './share-token-info-response'; -export * from './share-token-payload-response'; -export * from './share-token-response'; -export * from './single-column-board-response'; -export * from './student-permission-params'; -export * from './submission-container-content-body'; -export * from './submission-container-element-content'; -export * from './submission-container-element-content-body'; -export * from './submission-container-element-response'; -export * from './submission-item-response'; -export * from './submission-item-response-elements-inner'; -export * from './submission-status-list-response'; -export * from './submission-status-response'; -export * from './submissions-response'; -export * from './successful-response'; -export * from './system-for-ldap-login-response'; -export * from './system-type'; -export * from './target-info-response'; -export * from './target-user-id-params'; -export * from './task-copy-api-params'; -export * from './task-list-response'; -export * from './task-response'; -export * from './task-status-response'; -export * from './teacher-permission-params'; -export * from './team-permissions-body'; -export * from './timestamps-response'; -export * from './timezone'; -export * from './tool-config-type'; -export * from './tool-context-type'; -export * from './tool-context-types-list-response'; -export * from './tool-launch-request-response'; -export * from './tool-reference-list-response'; -export * from './tool-reference-response'; -export * from './update-board-title-params'; -export * from './update-element-content-body-params'; -export * from './update-element-content-body-params-data'; -export * from './update-flag-params'; -export * from './update-match-params'; -export * from './update-news-params'; -export * from './update-room-body-params'; -export * from './update-submission-item-body-params'; -export * from './user-consent-response'; -export * from './user-data-response'; -export * from './user-info-response'; -export * from './user-list-response'; -export * from './user-login-migration-mandatory-params'; -export * from './user-login-migration-response'; -export * from './user-login-migration-search-list-response'; -export * from './user-match-list-response'; -export * from './user-match-response'; -export * from './user-response'; -export * from './validation-error'; -export * from './video-conference-create-params'; -export * from './video-conference-info-response'; -export * from './video-conference-join-response'; -export * from './video-conference-options-response'; -export * from './video-conference-scope'; -export * from './video-conference-state-response'; -export * from './visibility-body-params'; -export * from './visibility-settings-response'; -export * from './years-response'; +export * from './action.js'; +export * from './authorization-body-params.js'; +export * from './authorization-context-params.js'; +export * from './authorized-reponse.js'; From 619228d32b302038f6411fc26ea9a090c3c4fd5e Mon Sep 17 00:00:00 2001 From: Constantin Bergatt Date: Mon, 14 Oct 2024 10:39:00 +0200 Subject: [PATCH 05/16] BC-7879 - refactor `authorization-api-client` to use `fetch` and be `node16` compatible --- openapitools-config.json | 3 + scripts/generate-client.js | 2 +- .../.openapi-generator-ignore | 4 +- .../.openapi-generator/FILES | 294 +++++++++++- .../authorization-api-client/api.ts | 18 - .../api/authorization-api.ts | 159 ------- .../apis/authorization-api.ts | 108 +++++ .../authorization-api-client/apis/index.ts | 3 + .../authorization-api-client/base.ts | 86 ---- .../authorization-api-client/common.ts | 150 ------ .../authorization-api-client/configuration.ts | 110 ----- .../authorization-api-client/index.ts | 19 +- .../authorization-api-client/models/action.ts | 30 +- .../models/api-validation-error.ts | 101 +++++ .../models/authorization-body-params.ts | 66 ++- .../models/authorization-context-params.ts | 80 +++- .../models/authorized-reponse.ts | 47 +- .../authorization-api-client/models/index.ts | 4 + .../models/permission.ts | 46 ++ .../authorization-api-client/runtime.ts | 426 ++++++++++++++++++ .../authorization/authorization.module.ts | 3 +- .../authorization.service.spec.ts | 20 +- .../authorization/authorization.service.ts | 30 +- 23 files changed, 1198 insertions(+), 611 deletions(-) delete mode 100644 src/infra/authorization/authorization-api-client/api.ts delete mode 100644 src/infra/authorization/authorization-api-client/api/authorization-api.ts create mode 100644 src/infra/authorization/authorization-api-client/apis/authorization-api.ts create mode 100644 src/infra/authorization/authorization-api-client/apis/index.ts delete mode 100644 src/infra/authorization/authorization-api-client/base.ts delete mode 100644 src/infra/authorization/authorization-api-client/common.ts delete mode 100644 src/infra/authorization/authorization-api-client/configuration.ts create mode 100644 src/infra/authorization/authorization-api-client/models/api-validation-error.ts create mode 100644 src/infra/authorization/authorization-api-client/models/permission.ts create mode 100644 src/infra/authorization/authorization-api-client/runtime.ts diff --git a/openapitools-config.json b/openapitools-config.json index 3570d978..5740f1e6 100644 --- a/openapitools-config.json +++ b/openapitools-config.json @@ -2,6 +2,9 @@ "apiPackage": "api", "enumNameSuffix": "", "enumPropertyNaming": "UPPERCASE", + "fileNaming": "kebab-case", + "generateAliasAsModel": true, + "importFileExtension": ".js", "modelPackage": "models", "supportsES6": true, "withInterfaces": true, diff --git a/scripts/generate-client.js b/scripts/generate-client.js index 37f5abf3..90481cfb 100644 --- a/scripts/generate-client.js +++ b/scripts/generate-client.js @@ -56,7 +56,7 @@ const getOpenApiCommand = (params) => { const { url, path, config, filter } = params; const configFile = config ? `-c ${config}` : ''; const filterString = filter ? `--openapi-normalizer FILTER="${filter}"` : ''; - const command = `openapi-generator-cli generate -i ${url} -g typescript-axios -o ${path} ${configFile} --skip-validate-spec ${filterString}`; + const command = `openapi-generator-cli generate -i ${url} -g typescript-fetch -o ${path} ${configFile} --skip-validate-spec ${filterString}`; return command; }; diff --git a/src/infra/authorization/authorization-api-client/.openapi-generator-ignore b/src/infra/authorization/authorization-api-client/.openapi-generator-ignore index bbc533d6..48fc051b 100644 --- a/src/infra/authorization/authorization-api-client/.openapi-generator-ignore +++ b/src/infra/authorization/authorization-api-client/.openapi-generator-ignore @@ -32,7 +32,9 @@ models/* # list of allowed files in the "models" folder !models/action.ts +!models/api-validation-error.ts !models/authorization-body-params.ts !models/authorization-context-params.ts !models/authorized-reponse.ts -!models/index.ts \ No newline at end of file +!models/index.ts +!models/permission.ts \ No newline at end of file diff --git a/src/infra/authorization/authorization-api-client/.openapi-generator/FILES b/src/infra/authorization/authorization-api-client/.openapi-generator/FILES index b0b81500..f99506fa 100644 --- a/src/infra/authorization/authorization-api-client/.openapi-generator/FILES +++ b/src/infra/authorization/authorization-api-client/.openapi-generator/FILES @@ -1,11 +1,295 @@ -api.ts -api/authorization-api.ts -base.ts -common.ts -configuration.ts +apis/authorization-api.ts +apis/index.ts index.ts +models/account-by-id-body-params.ts +models/account-response.ts +models/account-search-list-response.ts models/action.ts +models/alert-response.ts +models/api-validation-error.ts models/authorization-body-params.ts models/authorization-context-params.ts models/authorized-reponse.ts +models/basic-tool-config-params.ts +models/board-column-board-response.ts +models/board-context-response.ts +models/board-element-response-content.ts +models/board-element-response.ts +models/board-external-reference-type.ts +models/board-layout.ts +models/board-lesson-response.ts +models/board-parent-type.ts +models/board-response.ts +models/board-submission-controller-create-element201-response.ts +models/board-task-response.ts +models/board-task-status-response.ts +models/card-controller-create-element201-response.ts +models/card-list-response.ts +models/card-response-elements-inner.ts +models/card-response.ts +models/card-skeleton-response.ts +models/change-language-params.ts +models/class-info-response.ts +models/class-info-search-list-response.ts +models/class-request-context.ts +models/class-response.ts +models/class-sort-query-type.ts +models/collaborative-text-editor-element-response.ts +models/collaborative-text-editor-parent-type.ts +models/collaborative-text-editor-response.ts +models/collapsable-body-params.ts +models/color-body-params.ts +models/column-response.ts +models/config-response.ts +models/consent-request-body.ts +models/consent-response.ts +models/consent-session-response.ts +models/consents-response.ts +models/content-element-type.ts +models/context-external-tool-body-params.ts +models/context-external-tool-configuration-status-response.ts +models/context-external-tool-configuration-template-list-response.ts +models/context-external-tool-configuration-template-response.ts +models/context-external-tool-count-per-context-response.ts +models/context-external-tool-post-params.ts +models/context-external-tool-response.ts +models/context-external-tool-search-list-response.ts +models/copy-api-response.ts +models/county-response.ts +models/course-common-cartridge-metadata-response.ts +models/course-export-body-params.ts +models/course-info-data-response.ts +models/course-info-list-response.ts +models/course-info-response.ts +models/course-metadata-list-response.ts +models/course-metadata-response.ts +models/course-sort-props.ts +models/course-status.ts +models/course-sync-body-params.ts +models/create-board-body-params.ts +models/create-board-response.ts +models/create-card-body-params.ts +models/create-content-element-body-params.ts +models/create-media-element-body-params.ts +models/create-news-params.ts +models/create-room-body-params.ts +models/create-submission-item-body-params.ts +models/custom-parameter-entry-param.ts +models/custom-parameter-entry-response.ts +models/custom-parameter-post-params.ts +models/custom-parameter-response.ts +models/dashboard-grid-element-response.ts +models/dashboard-grid-sub-element-response.ts +models/dashboard-response.ts +models/deleted-element-content.ts +models/deleted-element-response.ts +models/drawing-content-body.ts +models/drawing-element-content-body.ts +models/drawing-element-content.ts +models/drawing-element-response.ts +models/element-controller-update-element201-response.ts +models/entity-not-found-error.ts +models/external-source-response.ts +models/external-tool-bulk-create-params.ts +models/external-tool-content-body.ts +models/external-tool-create-params.ts +models/external-tool-element-content-body.ts +models/external-tool-element-content.ts +models/external-tool-element-response.ts +models/external-tool-medium-params.ts +models/external-tool-medium-response.ts +models/external-tool-metadata-response.ts +models/external-tool-response-config.ts +models/external-tool-response.ts +models/external-tool-search-list-response.ts +models/external-tool-update-params-config.ts +models/external-tool-update-params.ts +models/federal-state-response.ts +models/file-content-body.ts +models/file-element-content-body.ts +models/file-element-content.ts +models/file-element-response.ts +models/file-storage-type.ts +models/forbidden-operation-error.ts +models/force-migration-params.ts +models/get-meta-tag-data-body.ts +models/group-list-response.ts +models/group-response.ts +models/group-user-response.ts +models/import-user-list-response.ts +models/import-user-response.ts models/index.ts +models/instance-feature.ts +models/language-type.ts +models/layout-body-params.ts +models/ldap-authorization-body-params.ts +models/lesson-content-response.ts +models/lesson-copy-api-params.ts +models/lesson-linked-task-response.ts +models/lesson-metadata-list-response.ts +models/lesson-metadata-response.ts +models/lesson-response.ts +models/link-content-body.ts +models/link-element-content-body.ts +models/link-element-content.ts +models/link-element-response.ts +models/local-authorization-body-params.ts +models/login-request-body.ts +models/login-response.ts +models/lti-message-type.ts +models/lti-privacy-permission.ts +models/lti11-tool-config-create-params.ts +models/lti11-tool-config-update-params.ts +models/material-response.ts +models/me-account-response.ts +models/me-response.ts +models/me-role-response.ts +models/me-school-logo-response.ts +models/me-school-response.ts +models/me-user-response.ts +models/media-available-line-element-response.ts +models/media-available-line-response.ts +models/media-board-colors.ts +models/media-board-layout-type.ts +models/media-board-response.ts +models/media-external-tool-element-content.ts +models/media-external-tool-element-response.ts +models/media-line-response-elements-inner.ts +models/media-line-response.ts +models/message-origin.ts +models/message.ts +models/meta-tag-extractor-response.ts +models/move-card-body-params.ts +models/move-column-body-params.ts +models/move-content-element-body.ts +models/move-element-body-params.ts +models/move-element-params.ts +models/move-element-position-params.ts +models/news-list-response.ts +models/news-response.ts +models/news-target-model.ts +models/o-auth-token-dto.ts +models/oauth-client-create-body.ts +models/oauth-client-response.ts +models/oauth-client-update-body.ts +models/oauth-config-response.ts +models/oauth-provider-login-response.ts +models/oauth2-authorization-body-params.ts +models/oauth2-migration-params.ts +models/oauth2-tool-config-create-params.ts +models/oauth2-tool-config-update-params.ts +models/oidc-context-response.ts +models/parent-consent-response.ts +models/patch-group-params.ts +models/patch-my-account-params.ts +models/patch-my-password-params.ts +models/patch-order-params.ts +models/patch-visibility-params.ts +models/period-response.ts +models/permission.ts +models/provider-config-response.ts +models/pseudonym-response.ts +models/public-system-list-response.ts +models/public-system-response.ts +models/redirect-response.ts +models/rename-body-params.ts +models/resolved-user-response.ts +models/rich-text-content-body.ts +models/rich-text-element-content-body.ts +models/rich-text-element-content.ts +models/rich-text-element-response.ts +models/rich-text.ts +models/role-name.ts +models/room-color.ts +models/room-details-response.ts +models/room-item-response.ts +models/room-list-response.ts +models/school-controller-get-provisioning-options200-response.ts +models/school-exists-response.ts +models/school-external-tool-configuration-status-response.ts +models/school-external-tool-configuration-template-list-response.ts +models/school-external-tool-configuration-template-response.ts +models/school-external-tool-metadata-response.ts +models/school-external-tool-post-params.ts +models/school-external-tool-response.ts +models/school-external-tool-search-list-response.ts +models/school-feature.ts +models/school-for-external-invite-response.ts +models/school-for-ldap-login-response.ts +models/school-info-response.ts +models/school-logo.ts +models/school-permissions-params.ts +models/school-purpose.ts +models/school-response.ts +models/school-system-response.ts +models/school-update-body-params.ts +models/school-year-query-type.ts +models/school-year-response.ts +models/schul-conne-x-provisioning-options-params.ts +models/schul-conne-x-provisioning-options-response.ts +models/schulcloud-theme.ts +models/set-height-body-params.ts +models/share-token-body-params.ts +models/share-token-import-body-params.ts +models/share-token-info-response.ts +models/share-token-payload-response.ts +models/share-token-response.ts +models/single-column-board-response.ts +models/student-permission-params.ts +models/submission-container-content-body.ts +models/submission-container-element-content-body.ts +models/submission-container-element-content.ts +models/submission-container-element-response.ts +models/submission-item-response-elements-inner.ts +models/submission-item-response.ts +models/submission-status-list-response.ts +models/submission-status-response.ts +models/submissions-response.ts +models/successful-response.ts +models/system-for-ldap-login-response.ts +models/system-type.ts +models/target-info-response.ts +models/target-user-id-params.ts +models/task-copy-api-params.ts +models/task-list-response.ts +models/task-response.ts +models/task-status-response.ts +models/teacher-permission-params.ts +models/team-permissions-body.ts +models/timestamps-response.ts +models/timezone.ts +models/tool-config-type.ts +models/tool-context-type.ts +models/tool-context-types-list-response.ts +models/tool-launch-request-response.ts +models/tool-reference-list-response.ts +models/tool-reference-response.ts +models/update-board-title-params.ts +models/update-element-content-body-params-data.ts +models/update-element-content-body-params.ts +models/update-flag-params.ts +models/update-match-params.ts +models/update-news-params.ts +models/update-room-body-params.ts +models/update-submission-item-body-params.ts +models/user-consent-response.ts +models/user-data-response.ts +models/user-info-response.ts +models/user-list-response.ts +models/user-login-migration-mandatory-params.ts +models/user-login-migration-response.ts +models/user-login-migration-search-list-response.ts +models/user-match-list-response.ts +models/user-match-response.ts +models/user-response.ts +models/validation-error.ts +models/video-conference-create-params.ts +models/video-conference-info-response.ts +models/video-conference-join-response.ts +models/video-conference-options-response.ts +models/video-conference-scope.ts +models/video-conference-state-response.ts +models/visibility-body-params.ts +models/visibility-settings-response.ts +models/years-response.ts +runtime.ts diff --git a/src/infra/authorization/authorization-api-client/api.ts b/src/infra/authorization/authorization-api-client/api.ts deleted file mode 100644 index fc2c3721..00000000 --- a/src/infra/authorization/authorization-api-client/api.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Schulcloud-Verbund-Software Server API - * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. - * - * The version of the OpenAPI document: 3.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - - -export * from './api/authorization-api'; - diff --git a/src/infra/authorization/authorization-api-client/api/authorization-api.ts b/src/infra/authorization/authorization-api-client/api/authorization-api.ts deleted file mode 100644 index cd72a7e6..00000000 --- a/src/infra/authorization/authorization-api-client/api/authorization-api.ts +++ /dev/null @@ -1,159 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Schulcloud-Verbund-Software Server API - * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. - * - * The version of the OpenAPI document: 3.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -import type { Configuration } from '../configuration'; -import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios'; -import globalAxios from 'axios'; -// Some imports not used depending on template conditions -// @ts-ignore -import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from '../common'; -// @ts-ignore -import { BASE_PATH, COLLECTION_FORMATS, type RequestArgs, BaseAPI, RequiredError, operationServerMap } from '../base'; -// @ts-ignore -import type { ApiValidationError } from '../models'; -// @ts-ignore -import type { AuthorizationBodyParams } from '../models'; -// @ts-ignore -import type { AuthorizedReponse } from '../models'; -/** - * AuthorizationApi - axios parameter creator - * @export - */ -export const AuthorizationApiAxiosParamCreator = function (configuration?: Configuration) { - return { - /** - * - * @summary Checks if user is authorized to perform the given operation. - * @param {AuthorizationBodyParams} authorizationBodyParams - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - authorizationReferenceControllerAuthorizeByReference: async (authorizationBodyParams: AuthorizationBodyParams, options: RawAxiosRequestConfig = {}): Promise => { - // verify required parameter 'authorizationBodyParams' is not null or undefined - assertParamExists('authorizationReferenceControllerAuthorizeByReference', 'authorizationBodyParams', authorizationBodyParams) - const localVarPath = `/authorization/by-reference`; - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); - let baseOptions; - if (configuration) { - baseOptions = configuration.baseOptions; - } - - const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options}; - const localVarHeaderParameter = {} as any; - const localVarQueryParameter = {} as any; - - // authentication bearer required - // http bearer authentication required - await setBearerAuthToObject(localVarHeaderParameter, configuration) - - - - localVarHeaderParameter['Content-Type'] = 'application/json'; - - setSearchParams(localVarUrlObj, localVarQueryParameter); - let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - localVarRequestOptions.data = serializeDataIfNeeded(authorizationBodyParams, localVarRequestOptions, configuration) - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - }; - }, - } -}; - -/** - * AuthorizationApi - functional programming interface - * @export - */ -export const AuthorizationApiFp = function(configuration?: Configuration) { - const localVarAxiosParamCreator = AuthorizationApiAxiosParamCreator(configuration) - return { - /** - * - * @summary Checks if user is authorized to perform the given operation. - * @param {AuthorizationBodyParams} authorizationBodyParams - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async authorizationReferenceControllerAuthorizeByReference(authorizationBodyParams: AuthorizationBodyParams, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.authorizationReferenceControllerAuthorizeByReference(authorizationBodyParams, options); - const localVarOperationServerIndex = configuration?.serverIndex ?? 0; - const localVarOperationServerBasePath = operationServerMap['AuthorizationApi.authorizationReferenceControllerAuthorizeByReference']?.[localVarOperationServerIndex]?.url; - return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); - }, - } -}; - -/** - * AuthorizationApi - factory interface - * @export - */ -export const AuthorizationApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) { - const localVarFp = AuthorizationApiFp(configuration) - return { - /** - * - * @summary Checks if user is authorized to perform the given operation. - * @param {AuthorizationBodyParams} authorizationBodyParams - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - authorizationReferenceControllerAuthorizeByReference(authorizationBodyParams: AuthorizationBodyParams, options?: RawAxiosRequestConfig): AxiosPromise { - return localVarFp.authorizationReferenceControllerAuthorizeByReference(authorizationBodyParams, options).then((request) => request(axios, basePath)); - }, - }; -}; - -/** - * AuthorizationApi - interface - * @export - * @interface AuthorizationApi - */ -export interface AuthorizationApiInterface { - /** - * - * @summary Checks if user is authorized to perform the given operation. - * @param {AuthorizationBodyParams} authorizationBodyParams - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof AuthorizationApiInterface - */ - authorizationReferenceControllerAuthorizeByReference(authorizationBodyParams: AuthorizationBodyParams, options?: RawAxiosRequestConfig): AxiosPromise; - -} - -/** - * AuthorizationApi - object-oriented interface - * @export - * @class AuthorizationApi - * @extends {BaseAPI} - */ -export class AuthorizationApi extends BaseAPI implements AuthorizationApiInterface { - /** - * - * @summary Checks if user is authorized to perform the given operation. - * @param {AuthorizationBodyParams} authorizationBodyParams - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof AuthorizationApi - */ - public authorizationReferenceControllerAuthorizeByReference(authorizationBodyParams: AuthorizationBodyParams, options?: RawAxiosRequestConfig) { - return AuthorizationApiFp(this.configuration).authorizationReferenceControllerAuthorizeByReference(authorizationBodyParams, options).then((request) => request(this.axios, this.basePath)); - } -} - diff --git a/src/infra/authorization/authorization-api-client/apis/authorization-api.ts b/src/infra/authorization/authorization-api-client/apis/authorization-api.ts new file mode 100644 index 00000000..924ef9af --- /dev/null +++ b/src/infra/authorization/authorization-api-client/apis/authorization-api.ts @@ -0,0 +1,108 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import * as runtime from '../runtime.js'; +import type { + ApiValidationError, + AuthorizationBodyParams, + AuthorizedReponse, +} from '../models/index.js'; +import { + ApiValidationErrorFromJSON, + ApiValidationErrorToJSON, + AuthorizationBodyParamsFromJSON, + AuthorizationBodyParamsToJSON, + AuthorizedReponseFromJSON, + AuthorizedReponseToJSON, +} from '../models/index.js'; + +export interface AuthorizationReferenceControllerAuthorizeByReferenceRequest { + authorizationBodyParams: AuthorizationBodyParams; +} + +/** + * AuthorizationApi - interface + * + * @export + * @interface AuthorizationApiInterface + */ +export interface AuthorizationApiInterface { + /** + * + * @summary Checks if user is authorized to perform the given operation. + * @param {AuthorizationBodyParams} authorizationBodyParams + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof AuthorizationApiInterface + */ + authorizationReferenceControllerAuthorizeByReferenceRaw(requestParameters: AuthorizationReferenceControllerAuthorizeByReferenceRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise>; + + /** + * Checks if user is authorized to perform the given operation. + */ + authorizationReferenceControllerAuthorizeByReference(requestParameters: AuthorizationReferenceControllerAuthorizeByReferenceRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise; + +} + +/** + * + */ +export class AuthorizationApi extends runtime.BaseAPI implements AuthorizationApiInterface { + + /** + * Checks if user is authorized to perform the given operation. + */ + async authorizationReferenceControllerAuthorizeByReferenceRaw(requestParameters: AuthorizationReferenceControllerAuthorizeByReferenceRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { + if (requestParameters['authorizationBodyParams'] == null) { + throw new runtime.RequiredError( + 'authorizationBodyParams', + 'Required parameter "authorizationBodyParams" was null or undefined when calling authorizationReferenceControllerAuthorizeByReference().' + ); + } + + const queryParameters: any = {}; + + const headerParameters: runtime.HTTPHeaders = {}; + + headerParameters['Content-Type'] = 'application/json'; + + if (this.configuration && this.configuration.accessToken) { + const token = this.configuration.accessToken; + const tokenString = await token("bearer", []); + + if (tokenString) { + headerParameters["Authorization"] = `Bearer ${tokenString}`; + } + } + const response = await this.request({ + path: `/authorization/by-reference`, + method: 'POST', + headers: headerParameters, + query: queryParameters, + body: AuthorizationBodyParamsToJSON(requestParameters['authorizationBodyParams']), + }, initOverrides); + + return new runtime.JSONApiResponse(response, (jsonValue) => AuthorizedReponseFromJSON(jsonValue)); + } + + /** + * Checks if user is authorized to perform the given operation. + */ + async authorizationReferenceControllerAuthorizeByReference(requestParameters: AuthorizationReferenceControllerAuthorizeByReferenceRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { + const response = await this.authorizationReferenceControllerAuthorizeByReferenceRaw(requestParameters, initOverrides); + return await response.value(); + } + +} diff --git a/src/infra/authorization/authorization-api-client/apis/index.ts b/src/infra/authorization/authorization-api-client/apis/index.ts new file mode 100644 index 00000000..a1681b8a --- /dev/null +++ b/src/infra/authorization/authorization-api-client/apis/index.ts @@ -0,0 +1,3 @@ +/* tslint:disable */ +/* eslint-disable */ +export * from './authorization-api.js'; diff --git a/src/infra/authorization/authorization-api-client/base.ts b/src/infra/authorization/authorization-api-client/base.ts deleted file mode 100644 index 5bcf014a..00000000 --- a/src/infra/authorization/authorization-api-client/base.ts +++ /dev/null @@ -1,86 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Schulcloud-Verbund-Software Server API - * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. - * - * The version of the OpenAPI document: 3.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -import type { Configuration } from './configuration'; -// Some imports not used depending on template conditions -// @ts-ignore -import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios'; -import globalAxios from 'axios'; - -export const BASE_PATH = "http://localhost:3030/api/v3".replace(/\/+$/, ""); - -/** - * - * @export - */ -export const COLLECTION_FORMATS = { - csv: ",", - ssv: " ", - tsv: "\t", - pipes: "|", -}; - -/** - * - * @export - * @interface RequestArgs - */ -export interface RequestArgs { - url: string; - options: RawAxiosRequestConfig; -} - -/** - * - * @export - * @class BaseAPI - */ -export class BaseAPI { - protected configuration: Configuration | undefined; - - constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) { - if (configuration) { - this.configuration = configuration; - this.basePath = configuration.basePath ?? basePath; - } - } -}; - -/** - * - * @export - * @class RequiredError - * @extends {Error} - */ -export class RequiredError extends Error { - constructor(public field: string, msg?: string) { - super(msg); - this.name = "RequiredError" - } -} - -interface ServerMap { - [key: string]: { - url: string, - description: string, - }[]; -} - -/** - * - * @export - */ -export const operationServerMap: ServerMap = { -} diff --git a/src/infra/authorization/authorization-api-client/common.ts b/src/infra/authorization/authorization-api-client/common.ts deleted file mode 100644 index 6c119efb..00000000 --- a/src/infra/authorization/authorization-api-client/common.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Schulcloud-Verbund-Software Server API - * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. - * - * The version of the OpenAPI document: 3.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -import type { Configuration } from "./configuration"; -import type { RequestArgs } from "./base"; -import type { AxiosInstance, AxiosResponse } from 'axios'; -import { RequiredError } from "./base"; - -/** - * - * @export - */ -export const DUMMY_BASE_URL = 'https://example.com' - -/** - * - * @throws {RequiredError} - * @export - */ -export const assertParamExists = function (functionName: string, paramName: string, paramValue: unknown) { - if (paramValue === null || paramValue === undefined) { - throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`); - } -} - -/** - * - * @export - */ -export const setApiKeyToObject = async function (object: any, keyParamName: string, configuration?: Configuration) { - if (configuration && configuration.apiKey) { - const localVarApiKeyValue = typeof configuration.apiKey === 'function' - ? await configuration.apiKey(keyParamName) - : await configuration.apiKey; - object[keyParamName] = localVarApiKeyValue; - } -} - -/** - * - * @export - */ -export const setBasicAuthToObject = function (object: any, configuration?: Configuration) { - if (configuration && (configuration.username || configuration.password)) { - object["auth"] = { username: configuration.username, password: configuration.password }; - } -} - -/** - * - * @export - */ -export const setBearerAuthToObject = async function (object: any, configuration?: Configuration) { - if (configuration && configuration.accessToken) { - const accessToken = typeof configuration.accessToken === 'function' - ? await configuration.accessToken() - : await configuration.accessToken; - object["Authorization"] = "Bearer " + accessToken; - } -} - -/** - * - * @export - */ -export const setOAuthToObject = async function (object: any, name: string, scopes: string[], configuration?: Configuration) { - if (configuration && configuration.accessToken) { - const localVarAccessTokenValue = typeof configuration.accessToken === 'function' - ? await configuration.accessToken(name, scopes) - : await configuration.accessToken; - object["Authorization"] = "Bearer " + localVarAccessTokenValue; - } -} - -function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: any, key: string = ""): void { - if (parameter == null) return; - if (typeof parameter === "object") { - if (Array.isArray(parameter)) { - (parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key)); - } - else { - Object.keys(parameter).forEach(currentKey => - setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`) - ); - } - } - else { - if (urlSearchParams.has(key)) { - urlSearchParams.append(key, parameter); - } - else { - urlSearchParams.set(key, parameter); - } - } -} - -/** - * - * @export - */ -export const setSearchParams = function (url: URL, ...objects: any[]) { - const searchParams = new URLSearchParams(url.search); - setFlattenedQueryParams(searchParams, objects); - url.search = searchParams.toString(); -} - -/** - * - * @export - */ -export const serializeDataIfNeeded = function (value: any, requestOptions: any, configuration?: Configuration) { - const nonString = typeof value !== 'string'; - const needsSerialization = nonString && configuration && configuration.isJsonMime - ? configuration.isJsonMime(requestOptions.headers['Content-Type']) - : nonString; - return needsSerialization - ? JSON.stringify(value !== undefined ? value : {}) - : (value || ""); -} - -/** - * - * @export - */ -export const toPathString = function (url: URL) { - return url.pathname + url.search + url.hash -} - -/** - * - * @export - */ -export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) { - return >(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => { - const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url}; - return axios.request(axiosRequestArgs); - }; -} diff --git a/src/infra/authorization/authorization-api-client/configuration.ts b/src/infra/authorization/authorization-api-client/configuration.ts deleted file mode 100644 index 8c97d307..00000000 --- a/src/infra/authorization/authorization-api-client/configuration.ts +++ /dev/null @@ -1,110 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Schulcloud-Verbund-Software Server API - * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. - * - * The version of the OpenAPI document: 3.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -export interface ConfigurationParameters { - apiKey?: string | Promise | ((name: string) => string) | ((name: string) => Promise); - username?: string; - password?: string; - accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise); - basePath?: string; - serverIndex?: number; - baseOptions?: any; - formDataCtor?: new () => any; -} - -export class Configuration { - /** - * parameter for apiKey security - * @param name security name - * @memberof Configuration - */ - apiKey?: string | Promise | ((name: string) => string) | ((name: string) => Promise); - /** - * parameter for basic security - * - * @type {string} - * @memberof Configuration - */ - username?: string; - /** - * parameter for basic security - * - * @type {string} - * @memberof Configuration - */ - password?: string; - /** - * parameter for oauth2 security - * @param name security name - * @param scopes oauth2 scope - * @memberof Configuration - */ - accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise); - /** - * override base path - * - * @type {string} - * @memberof Configuration - */ - basePath?: string; - /** - * override server index - * - * @type {number} - * @memberof Configuration - */ - serverIndex?: number; - /** - * base options for axios calls - * - * @type {any} - * @memberof Configuration - */ - baseOptions?: any; - /** - * The FormData constructor that will be used to create multipart form data - * requests. You can inject this here so that execution environments that - * do not support the FormData class can still run the generated client. - * - * @type {new () => FormData} - */ - formDataCtor?: new () => any; - - constructor(param: ConfigurationParameters = {}) { - this.apiKey = param.apiKey; - this.username = param.username; - this.password = param.password; - this.accessToken = param.accessToken; - this.basePath = param.basePath; - this.serverIndex = param.serverIndex; - this.baseOptions = param.baseOptions; - this.formDataCtor = param.formDataCtor; - } - - /** - * Check if the given MIME is a JSON MIME. - * JSON MIME examples: - * application/json - * application/json; charset=UTF8 - * APPLICATION/JSON - * application/vnd.company+json - * @param mime - MIME (Multipurpose Internet Mail Extensions) - * @return True if the given MIME is JSON, false otherwise. - */ - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); - return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); - } -} diff --git a/src/infra/authorization/authorization-api-client/index.ts b/src/infra/authorization/authorization-api-client/index.ts index 8b762df6..89656b95 100644 --- a/src/infra/authorization/authorization-api-client/index.ts +++ b/src/infra/authorization/authorization-api-client/index.ts @@ -1,18 +1,5 @@ /* tslint:disable */ /* eslint-disable */ -/** - * Schulcloud-Verbund-Software Server API - * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. - * - * The version of the OpenAPI document: 3.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -export * from "./api"; -export * from "./configuration"; -export * from "./models"; +export * from './runtime.js'; +export * from './apis/index.js'; +export * from './models/index.js'; diff --git a/src/infra/authorization/authorization-api-client/models/action.ts b/src/infra/authorization/authorization-api-client/models/action.ts index c74334d3..545af1fb 100644 --- a/src/infra/authorization/authorization-api-client/models/action.ts +++ b/src/infra/authorization/authorization-api-client/models/action.ts @@ -13,19 +13,41 @@ */ - /** * * @export - * @enum {string} */ - export const Action = { READ: 'read', WRITE: 'write' } as const; - export type Action = typeof Action[keyof typeof Action]; +export function instanceOfAction(value: any): boolean { + for (const key in Action) { + if (Object.prototype.hasOwnProperty.call(Action, key)) { + if (Action[key as keyof typeof Action] === value) { + return true; + } + } + } + return false; +} + +export function ActionFromJSON(json: any): Action { + return ActionFromJSONTyped(json, false); +} + +export function ActionFromJSONTyped(json: any, ignoreDiscriminator: boolean): Action { + return json as Action; +} + +export function ActionToJSON(value?: Action | null): any { + return value as any; +} + +export function ActionToJSONTyped(value: any, ignoreDiscriminator: boolean): Action { + return value as Action; +} diff --git a/src/infra/authorization/authorization-api-client/models/api-validation-error.ts b/src/infra/authorization/authorization-api-client/models/api-validation-error.ts new file mode 100644 index 00000000..73b8e797 --- /dev/null +++ b/src/infra/authorization/authorization-api-client/models/api-validation-error.ts @@ -0,0 +1,101 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { mapValues } from '../runtime.js'; +/** + * + * @export + * @interface ApiValidationError + */ +export interface ApiValidationError { + /** + * The response status code. + * @type {number} + * @memberof ApiValidationError + */ + code: number; + /** + * The error type. + * @type {string} + * @memberof ApiValidationError + */ + type: string; + /** + * The error title. + * @type {string} + * @memberof ApiValidationError + */ + title: string; + /** + * The error message. + * @type {string} + * @memberof ApiValidationError + */ + message: string; + /** + * The error details. + * @type {object} + * @memberof ApiValidationError + */ + details?: object; +} + +/** + * Check if a given object implements the ApiValidationError interface. + */ +export function instanceOfApiValidationError(value: object): value is ApiValidationError { + if (!('code' in value) || value['code'] === undefined) return false; + if (!('type' in value) || value['type'] === undefined) return false; + if (!('title' in value) || value['title'] === undefined) return false; + if (!('message' in value) || value['message'] === undefined) return false; + return true; +} + +export function ApiValidationErrorFromJSON(json: any): ApiValidationError { + return ApiValidationErrorFromJSONTyped(json, false); +} + +export function ApiValidationErrorFromJSONTyped(json: any, ignoreDiscriminator: boolean): ApiValidationError { + if (json == null) { + return json; + } + return { + + 'code': json['code'], + 'type': json['type'], + 'title': json['title'], + 'message': json['message'], + 'details': json['details'] == null ? undefined : json['details'], + }; +} + + export function ApiValidationErrorToJSON(json: any): ApiValidationError { + return ApiValidationErrorToJSONTyped(json, false); + } + + export function ApiValidationErrorToJSONTyped(value?: ApiValidationError | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'code': value['code'], + 'type': value['type'], + 'title': value['title'], + 'message': value['message'], + 'details': value['details'], + }; +} + diff --git a/src/infra/authorization/authorization-api-client/models/authorization-body-params.ts b/src/infra/authorization/authorization-api-client/models/authorization-body-params.ts index cea578bd..5a3ca960 100644 --- a/src/infra/authorization/authorization-api-client/models/authorization-body-params.ts +++ b/src/infra/authorization/authorization-api-client/models/authorization-body-params.ts @@ -12,10 +12,14 @@ * Do not edit the class manually. */ - -// May contain unused imports in some cases -// @ts-ignore -import type { AuthorizationContextParams } from './authorization-context-params'; +import { mapValues } from '../runtime.js'; +import type { AuthorizationContextParams } from './authorization-context-params.js'; +import { + AuthorizationContextParamsFromJSON, + AuthorizationContextParamsFromJSONTyped, + AuthorizationContextParamsToJSON, + AuthorizationContextParamsToJSONTyped, +} from './authorization-context-params.js'; /** * @@ -28,21 +32,25 @@ export interface AuthorizationBodyParams { * @type {AuthorizationContextParams} * @memberof AuthorizationBodyParams */ - 'context': AuthorizationContextParams; + context: AuthorizationContextParams; /** * The entity or domain object the operation should be performed on. * @type {string} * @memberof AuthorizationBodyParams */ - 'referenceType': AuthorizationBodyParamsReferenceType; + referenceType: AuthorizationBodyParamsReferenceType; /** * The id of the entity/domain object of the defined referenceType. * @type {string} * @memberof AuthorizationBodyParams */ - 'referenceId': string; + referenceId: string; } + +/** + * @export + */ export const AuthorizationBodyParamsReferenceType = { USERS: 'users', SCHOOLS: 'schools', @@ -58,7 +66,49 @@ export const AuthorizationBodyParamsReferenceType = { EXTERNAL_TOOLS: 'external-tools', INSTANCES: 'instances' } as const; - export type AuthorizationBodyParamsReferenceType = typeof AuthorizationBodyParamsReferenceType[keyof typeof AuthorizationBodyParamsReferenceType]; +/** + * Check if a given object implements the AuthorizationBodyParams interface. + */ +export function instanceOfAuthorizationBodyParams(value: object): value is AuthorizationBodyParams { + if (!('context' in value) || value['context'] === undefined) return false; + if (!('referenceType' in value) || value['referenceType'] === undefined) return false; + if (!('referenceId' in value) || value['referenceId'] === undefined) return false; + return true; +} + +export function AuthorizationBodyParamsFromJSON(json: any): AuthorizationBodyParams { + return AuthorizationBodyParamsFromJSONTyped(json, false); +} + +export function AuthorizationBodyParamsFromJSONTyped(json: any, ignoreDiscriminator: boolean): AuthorizationBodyParams { + if (json == null) { + return json; + } + return { + + 'context': AuthorizationContextParamsFromJSON(json['context']), + 'referenceType': json['referenceType'], + 'referenceId': json['referenceId'], + }; +} + + export function AuthorizationBodyParamsToJSON(json: any): AuthorizationBodyParams { + return AuthorizationBodyParamsToJSONTyped(json, false); + } + + export function AuthorizationBodyParamsToJSONTyped(value?: AuthorizationBodyParams | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'context': AuthorizationContextParamsToJSON(value['context']), + 'referenceType': value['referenceType'], + 'referenceId': value['referenceId'], + }; +} + diff --git a/src/infra/authorization/authorization-api-client/models/authorization-context-params.ts b/src/infra/authorization/authorization-api-client/models/authorization-context-params.ts index 055adfae..4233ced7 100644 --- a/src/infra/authorization/authorization-api-client/models/authorization-context-params.ts +++ b/src/infra/authorization/authorization-api-client/models/authorization-context-params.ts @@ -5,40 +5,78 @@ * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. * * The version of the OpenAPI document: 3.0 - * + * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ - -// May contain unused imports in some cases -// @ts-ignore -import type { Action } from './action'; -// May contain unused imports in some cases -// @ts-ignore -import type { Permission } from './permission'; +import type { Action } from './action.js'; +import { ActionFromJSON, ActionToJSON } from './action.js'; +import type { Permission } from './permission.js'; +import { PermissionFromJSON, PermissionToJSON } from './permission.js'; /** - * + * * @export * @interface AuthorizationContextParams */ export interface AuthorizationContextParams { - /** - * - * @type {Action} - * @memberof AuthorizationContextParams - */ - 'action': Action; - /** - * User permissions that are needed to execute the operation. - * @type {Array} - * @memberof AuthorizationContextParams - */ - 'requiredPermissions': Array; + /** + * + * @type {Action} + * @memberof AuthorizationContextParams + */ + action: Action; + /** + * User permissions that are needed to execute the operation. + * @type {Array} + * @memberof AuthorizationContextParams + */ + requiredPermissions: Array; } +/** + * Check if a given object implements the AuthorizationContextParams interface. + */ +export function instanceOfAuthorizationContextParams(value: object): value is AuthorizationContextParams { + if (!('action' in value) || value['action'] === undefined) return false; + if (!('requiredPermissions' in value) || value['requiredPermissions'] === undefined) return false; + return true; +} +export function AuthorizationContextParamsFromJSON(json: any): AuthorizationContextParams { + return AuthorizationContextParamsFromJSONTyped(json, false); +} +export function AuthorizationContextParamsFromJSONTyped( + json: any, + ignoreDiscriminator: boolean, +): AuthorizationContextParams { + if (json == null) { + return json; + } + return { + action: ActionFromJSON(json['action']), + requiredPermissions: (json['requiredPermissions'] as Array).map(PermissionFromJSON), + }; +} + +export function AuthorizationContextParamsToJSON(json: any): AuthorizationContextParams { + return AuthorizationContextParamsToJSONTyped(json, false); +} + +export function AuthorizationContextParamsToJSONTyped( + value?: AuthorizationContextParams | null, + ignoreDiscriminator: boolean = false, +): any { + if (value == null) { + return value; + } + + return { + action: ActionToJSON(value['action']), + requiredPermissions: (value['requiredPermissions'] as Array).map(PermissionToJSON), + }; +} diff --git a/src/infra/authorization/authorization-api-client/models/authorized-reponse.ts b/src/infra/authorization/authorization-api-client/models/authorized-reponse.ts index b69c757a..b0efb4a0 100644 --- a/src/infra/authorization/authorization-api-client/models/authorized-reponse.ts +++ b/src/infra/authorization/authorization-api-client/models/authorized-reponse.ts @@ -12,8 +12,7 @@ * Do not edit the class manually. */ - - +import { mapValues } from '../runtime.js'; /** * * @export @@ -25,12 +24,52 @@ export interface AuthorizedReponse { * @type {string} * @memberof AuthorizedReponse */ - 'userId': string; + userId: string; /** * * @type {boolean} * @memberof AuthorizedReponse */ - 'isAuthorized': boolean; + isAuthorized: boolean; +} + +/** + * Check if a given object implements the AuthorizedReponse interface. + */ +export function instanceOfAuthorizedReponse(value: object): value is AuthorizedReponse { + if (!('userId' in value) || value['userId'] === undefined) return false; + if (!('isAuthorized' in value) || value['isAuthorized'] === undefined) return false; + return true; +} + +export function AuthorizedReponseFromJSON(json: any): AuthorizedReponse { + return AuthorizedReponseFromJSONTyped(json, false); +} + +export function AuthorizedReponseFromJSONTyped(json: any, ignoreDiscriminator: boolean): AuthorizedReponse { + if (json == null) { + return json; + } + return { + + 'userId': json['userId'], + 'isAuthorized': json['isAuthorized'], + }; +} + + export function AuthorizedReponseToJSON(json: any): AuthorizedReponse { + return AuthorizedReponseToJSONTyped(json, false); + } + + export function AuthorizedReponseToJSONTyped(value?: AuthorizedReponse | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'userId': value['userId'], + 'isAuthorized': value['isAuthorized'], + }; } diff --git a/src/infra/authorization/authorization-api-client/models/index.ts b/src/infra/authorization/authorization-api-client/models/index.ts index 6e494cd9..f1293724 100644 --- a/src/infra/authorization/authorization-api-client/models/index.ts +++ b/src/infra/authorization/authorization-api-client/models/index.ts @@ -1,4 +1,8 @@ +/* tslint:disable */ +/* eslint-disable */ export * from './action.js'; +export * from './api-validation-error.js'; export * from './authorization-body-params.js'; export * from './authorization-context-params.js'; export * from './authorized-reponse.js'; +export * from './permission.js'; diff --git a/src/infra/authorization/authorization-api-client/models/permission.ts b/src/infra/authorization/authorization-api-client/models/permission.ts new file mode 100644 index 00000000..51d32db8 --- /dev/null +++ b/src/infra/authorization/authorization-api-client/models/permission.ts @@ -0,0 +1,46 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { mapValues } from '../runtime.js'; +/** + * + * @export + * @interface Permission + */ +export interface Permission extends Array { +} + +/** + * Check if a given object implements the Permission interface. + */ +export function instanceOfPermission(value: object): value is Permission { + return true; +} + +export function PermissionFromJSON(json: any): Permission { + return PermissionFromJSONTyped(json, false); +} + +export function PermissionFromJSONTyped(json: any, ignoreDiscriminator: boolean): Permission { + return json; +} + + export function PermissionToJSON(json: any): Permission { + return PermissionToJSONTyped(json, false); + } + + export function PermissionToJSONTyped(value?: Permission | null, ignoreDiscriminator: boolean = false): any { + return value; +} + diff --git a/src/infra/authorization/authorization-api-client/runtime.ts b/src/infra/authorization/authorization-api-client/runtime.ts new file mode 100644 index 00000000..1a4a0a90 --- /dev/null +++ b/src/infra/authorization/authorization-api-client/runtime.ts @@ -0,0 +1,426 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Schulcloud-Verbund-Software Server API + * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. + * + * The version of the OpenAPI document: 3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export const BASE_PATH = "http://localhost:3030/api/v3".replace(/\/+$/, ""); + +export interface ConfigurationParameters { + basePath?: string; // override base path + fetchApi?: FetchAPI; // override for fetch implementation + middleware?: Middleware[]; // middleware to apply before/after fetch requests + queryParamsStringify?: (params: HTTPQuery) => string; // stringify function for query strings + username?: string; // parameter for basic security + password?: string; // parameter for basic security + apiKey?: string | Promise | ((name: string) => string | Promise); // parameter for apiKey security + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string | Promise); // parameter for oauth2 security + headers?: HTTPHeaders; //header params we want to use on every request + credentials?: RequestCredentials; //value for the credentials param we want to use on each request +} + +export class Configuration { + constructor(private configuration: ConfigurationParameters = {}) {} + + set config(configuration: Configuration) { + this.configuration = configuration; + } + + get basePath(): string { + return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH; + } + + get fetchApi(): FetchAPI | undefined { + return this.configuration.fetchApi; + } + + get middleware(): Middleware[] { + return this.configuration.middleware || []; + } + + get queryParamsStringify(): (params: HTTPQuery) => string { + return this.configuration.queryParamsStringify || querystring; + } + + get username(): string | undefined { + return this.configuration.username; + } + + get password(): string | undefined { + return this.configuration.password; + } + + get apiKey(): ((name: string) => string | Promise) | undefined { + const apiKey = this.configuration.apiKey; + if (apiKey) { + return typeof apiKey === 'function' ? apiKey : () => apiKey; + } + return undefined; + } + + get accessToken(): ((name?: string, scopes?: string[]) => string | Promise) | undefined { + const accessToken = this.configuration.accessToken; + if (accessToken) { + return typeof accessToken === 'function' ? accessToken : async () => accessToken; + } + return undefined; + } + + get headers(): HTTPHeaders | undefined { + return this.configuration.headers; + } + + get credentials(): RequestCredentials | undefined { + return this.configuration.credentials; + } +} + +export const DefaultConfig = new Configuration(); + +/** + * This is the base class for all generated API classes. + */ +export class BaseAPI { + + private static readonly jsonRegex = new RegExp('^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$', 'i'); + private middleware: Middleware[]; + + constructor(protected configuration = DefaultConfig) { + this.middleware = configuration.middleware; + } + + withMiddleware(this: T, ...middlewares: Middleware[]) { + const next = this.clone(); + next.middleware = next.middleware.concat(...middlewares); + return next; + } + + withPreMiddleware(this: T, ...preMiddlewares: Array) { + const middlewares = preMiddlewares.map((pre) => ({ pre })); + return this.withMiddleware(...middlewares); + } + + withPostMiddleware(this: T, ...postMiddlewares: Array) { + const middlewares = postMiddlewares.map((post) => ({ post })); + return this.withMiddleware(...middlewares); + } + + /** + * Check if the given MIME is a JSON MIME. + * JSON MIME examples: + * application/json + * application/json; charset=UTF8 + * APPLICATION/JSON + * application/vnd.company+json + * @param mime - MIME (Multipurpose Internet Mail Extensions) + * @return True if the given MIME is JSON, false otherwise. + */ + protected isJsonMime(mime: string | null | undefined): boolean { + if (!mime) { + return false; + } + return BaseAPI.jsonRegex.test(mime); + } + + protected async request(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction): Promise { + const { url, init } = await this.createFetchParams(context, initOverrides); + const response = await this.fetchApi(url, init); + if (response && (response.status >= 200 && response.status < 300)) { + return response; + } + throw new ResponseError(response, 'Response returned an error code'); + } + + private async createFetchParams(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction) { + let url = this.configuration.basePath + context.path; + if (context.query !== undefined && Object.keys(context.query).length !== 0) { + // only add the querystring to the URL if there are query parameters. + // this is done to avoid urls ending with a "?" character which buggy webservers + // do not handle correctly sometimes. + url += '?' + this.configuration.queryParamsStringify(context.query); + } + + const headers = Object.assign({}, this.configuration.headers, context.headers); + Object.keys(headers).forEach(key => headers[key] === undefined ? delete headers[key] : {}); + + const initOverrideFn = + typeof initOverrides === "function" + ? initOverrides + : async () => initOverrides; + + const initParams = { + method: context.method, + headers, + body: context.body, + credentials: this.configuration.credentials, + }; + + const overriddenInit: RequestInit = { + ...initParams, + ...(await initOverrideFn({ + init: initParams, + context, + })) + }; + + let body: any; + if (isFormData(overriddenInit.body) + || (overriddenInit.body instanceof URLSearchParams) + || isBlob(overriddenInit.body)) { + body = overriddenInit.body; + } else if (this.isJsonMime(headers['Content-Type'])) { + body = JSON.stringify(overriddenInit.body); + } else { + body = overriddenInit.body; + } + + const init: RequestInit = { + ...overriddenInit, + body + }; + + return { url, init }; + } + + private fetchApi = async (url: string, init: RequestInit) => { + let fetchParams = { url, init }; + for (const middleware of this.middleware) { + if (middleware.pre) { + fetchParams = await middleware.pre({ + fetch: this.fetchApi, + ...fetchParams, + }) || fetchParams; + } + } + let response: Response | undefined = undefined; + try { + response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); + } catch (e) { + for (const middleware of this.middleware) { + if (middleware.onError) { + response = await middleware.onError({ + fetch: this.fetchApi, + url: fetchParams.url, + init: fetchParams.init, + error: e, + response: response ? response.clone() : undefined, + }) || response; + } + } + if (response === undefined) { + if (e instanceof Error) { + throw new FetchError(e, 'The request failed and the interceptors did not return an alternative response'); + } else { + throw e; + } + } + } + for (const middleware of this.middleware) { + if (middleware.post) { + response = await middleware.post({ + fetch: this.fetchApi, + url: fetchParams.url, + init: fetchParams.init, + response: response.clone(), + }) || response; + } + } + return response; + } + + /** + * Create a shallow clone of `this` by constructing a new instance + * and then shallow cloning data members. + */ + private clone(this: T): T { + const constructor = this.constructor as any; + const next = new constructor(this.configuration); + next.middleware = this.middleware.slice(); + return next; + } +}; + +function isBlob(value: any): value is Blob { + return typeof Blob !== 'undefined' && value instanceof Blob; +} + +function isFormData(value: any): value is FormData { + return typeof FormData !== "undefined" && value instanceof FormData; +} + +export class ResponseError extends Error { + override name: "ResponseError" = "ResponseError"; + constructor(public response: Response, msg?: string) { + super(msg); + } +} + +export class FetchError extends Error { + override name: "FetchError" = "FetchError"; + constructor(public cause: Error, msg?: string) { + super(msg); + } +} + +export class RequiredError extends Error { + override name: "RequiredError" = "RequiredError"; + constructor(public field: string, msg?: string) { + super(msg); + } +} + +export const COLLECTION_FORMATS = { + csv: ",", + ssv: " ", + tsv: "\t", + pipes: "|", +}; + +export type FetchAPI = WindowOrWorkerGlobalScope['fetch']; + +export type Json = any; +export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD'; +export type HTTPHeaders = { [key: string]: string }; +export type HTTPQuery = { [key: string]: string | number | null | boolean | Array | Set | HTTPQuery }; +export type HTTPBody = Json | FormData | URLSearchParams; +export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody }; +export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original'; + +export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise + +export interface FetchParams { + url: string; + init: RequestInit; +} + +export interface RequestOpts { + path: string; + method: HTTPMethod; + headers: HTTPHeaders; + query?: HTTPQuery; + body?: HTTPBody; +} + +export function querystring(params: HTTPQuery, prefix: string = ''): string { + return Object.keys(params) + .map(key => querystringSingleKey(key, params[key], prefix)) + .filter(part => part.length > 0) + .join('&'); +} + +function querystringSingleKey(key: string, value: string | number | null | undefined | boolean | Array | Set | HTTPQuery, keyPrefix: string = ''): string { + const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key); + if (value instanceof Array) { + const multiValue = value.map(singleValue => encodeURIComponent(String(singleValue))) + .join(`&${encodeURIComponent(fullKey)}=`); + return `${encodeURIComponent(fullKey)}=${multiValue}`; + } + if (value instanceof Set) { + const valueAsArray = Array.from(value); + return querystringSingleKey(key, valueAsArray, keyPrefix); + } + if (value instanceof Date) { + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + } + if (value instanceof Object) { + return querystring(value as HTTPQuery, fullKey); + } + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`; +} + +export function mapValues(data: any, fn: (item: any) => any) { + return Object.keys(data).reduce( + (acc, key) => ({ ...acc, [key]: fn(data[key]) }), + {} + ); +} + +export function canConsumeForm(consumes: Consume[]): boolean { + for (const consume of consumes) { + if ('multipart/form-data' === consume.contentType) { + return true; + } + } + return false; +} + +export interface Consume { + contentType: string; +} + +export interface RequestContext { + fetch: FetchAPI; + url: string; + init: RequestInit; +} + +export interface ResponseContext { + fetch: FetchAPI; + url: string; + init: RequestInit; + response: Response; +} + +export interface ErrorContext { + fetch: FetchAPI; + url: string; + init: RequestInit; + error: unknown; + response?: Response; +} + +export interface Middleware { + pre?(context: RequestContext): Promise; + post?(context: ResponseContext): Promise; + onError?(context: ErrorContext): Promise; +} + +export interface ApiResponse { + raw: Response; + value(): Promise; +} + +export interface ResponseTransformer { + (json: any): T; +} + +export class JSONApiResponse { + constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + + async value(): Promise { + return this.transformer(await this.raw.json()); + } +} + +export class VoidApiResponse { + constructor(public raw: Response) {} + + async value(): Promise { + return undefined; + } +} + +export class BlobApiResponse { + constructor(public raw: Response) {} + + async value(): Promise { + return await this.raw.blob(); + }; +} + +export class TextApiResponse { + constructor(public raw: Response) {} + + async value(): Promise { + return await this.raw.text(); + }; +} diff --git a/src/infra/authorization/authorization.module.ts b/src/infra/authorization/authorization.module.ts index b30dcdd1..b3f88a8f 100644 --- a/src/infra/authorization/authorization.module.ts +++ b/src/infra/authorization/authorization.module.ts @@ -1,10 +1,11 @@ import { Module } from '@nestjs/common'; import { LoggerModule } from '../logging/logger.module.js'; +import { AuthorizationApi } from './authorization-api-client/index.js'; import { AuthorizationService } from './authorization.service.js'; @Module({ imports: [LoggerModule], - providers: [AuthorizationService], + providers: [AuthorizationApi, AuthorizationService], exports: [AuthorizationService], }) export class AuthorizationModule {} diff --git a/src/infra/authorization/authorization.service.spec.ts b/src/infra/authorization/authorization.service.spec.ts index de7c093f..58f76fab 100644 --- a/src/infra/authorization/authorization.service.spec.ts +++ b/src/infra/authorization/authorization.service.spec.ts @@ -1,10 +1,8 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Test, TestingModule } from '@nestjs/testing'; -import { AxiosResponse } from 'axios'; import { HttpRequest } from 'uws'; import { Logger } from '../logging/logger.js'; -import { AuthorizationApi } from './authorization-api-client/api/authorization-api.js'; -import { AuthorizedReponse } from './authorization-api-client/models/authorized-reponse.js'; +import { AuthorizationApi, AuthorizedReponse } from './authorization-api-client/index.js'; import { AuthorizationService } from './authorization.service.js'; describe(AuthorizationService.name, () => { @@ -52,11 +50,9 @@ describe(AuthorizationService.name, () => { const setup = () => { const { req } = setupRequest(); - const response = createMock>({ - data: { - isAuthorized: true, - userId: '123', - }, + const response = createMock({ + isAuthorized: true, + userId: '123', }); authorizationApi.authorizationReferenceControllerAuthorizeByReference.mockResolvedValueOnce(response); @@ -78,11 +74,9 @@ describe(AuthorizationService.name, () => { const setup = () => { const { req } = setupRequest(); - const response = createMock>({ - data: { - isAuthorized: false, - userId: '123', - }, + const response = createMock({ + isAuthorized: false, + userId: '123', }); authorizationApi.authorizationReferenceControllerAuthorizeByReference.mockResolvedValueOnce(response); diff --git a/src/infra/authorization/authorization.service.ts b/src/infra/authorization/authorization.service.ts index 09c2f11f..5fc4e629 100644 --- a/src/infra/authorization/authorization.service.ts +++ b/src/infra/authorization/authorization.service.ts @@ -1,13 +1,12 @@ import { Injectable } from '@nestjs/common'; -import { RawAxiosRequestConfig } from 'axios'; import { HttpRequest } from 'uws'; import { Logger } from '../logging/logger.js'; -import { AuthorizationApi } from './authorization-api-client/api/authorization-api.js'; -import { Action } from './authorization-api-client/models/action.js'; import { - AuthorizationBodyParams, + Action, + AuthorizationApi, AuthorizationBodyParamsReferenceType, -} from './authorization-api-client/models/authorization-body-params.js'; + AuthorizationReferenceControllerAuthorizeByReferenceRequest, +} from './authorization-api-client/index.js'; import { ResponsePayload } from './interfaces/response.payload.js'; import { ResponsePayloadBuilder } from './response.builder.js'; @@ -55,20 +54,23 @@ export class AuthorizationService { } private async fetchAuthorization(room: string, token: string): Promise { - const params: AuthorizationBodyParams = { - referenceType: AuthorizationBodyParamsReferenceType.BOARDNODES, - referenceId: room, - context: { - action: Action.READ, - requiredPermissions: ['COURSE_VIEW'], + const requestParameters: AuthorizationReferenceControllerAuthorizeByReferenceRequest = { + authorizationBodyParams: { + referenceType: AuthorizationBodyParamsReferenceType.BOARDNODES, + referenceId: room, + context: { + action: Action.READ, + requiredPermissions: [['COURSE_VIEW']], + }, }, }; - const options: RawAxiosRequestConfig = { headers: { authorization: `Bearer ${token}` } }; + // this.authorizationApi.configuration.accessToken = token; - const response = await this.authorizationApi.authorizationReferenceControllerAuthorizeByReference(params, options); + const response = + await this.authorizationApi.authorizationReferenceControllerAuthorizeByReference(requestParameters); - const { isAuthorized, userId } = response.data; + const { isAuthorized, userId } = response; if (!isAuthorized) { return this.createErrorResponsePayload(4401, 'Unauthorized'); } From 2b8c824865657fbdb82089ac90d9752d0cee28af Mon Sep 17 00:00:00 2001 From: Constantin Bergatt Date: Mon, 14 Oct 2024 10:46:40 +0200 Subject: [PATCH 06/16] BC-7879 - regenerate client (except `src/infra/authorization/authorization-api-client/models/index.ts`) - ATTENTION! `src/infra/authorization/authorization-api-client/models/index.ts` must not be updated, as it will always include ALL models, although only a selected FEW are required. --- .../.openapi-generator-ignore | 1 - .../.openapi-generator/FILES | 284 ------------------ .../models/authorization-context-params.ts | 100 +++--- 3 files changed, 55 insertions(+), 330 deletions(-) diff --git a/src/infra/authorization/authorization-api-client/.openapi-generator-ignore b/src/infra/authorization/authorization-api-client/.openapi-generator-ignore index 48fc051b..9f7e4d1a 100644 --- a/src/infra/authorization/authorization-api-client/.openapi-generator-ignore +++ b/src/infra/authorization/authorization-api-client/.openapi-generator-ignore @@ -36,5 +36,4 @@ models/* !models/authorization-body-params.ts !models/authorization-context-params.ts !models/authorized-reponse.ts -!models/index.ts !models/permission.ts \ No newline at end of file diff --git a/src/infra/authorization/authorization-api-client/.openapi-generator/FILES b/src/infra/authorization/authorization-api-client/.openapi-generator/FILES index f99506fa..e6ed4f3a 100644 --- a/src/infra/authorization/authorization-api-client/.openapi-generator/FILES +++ b/src/infra/authorization/authorization-api-client/.openapi-generator/FILES @@ -1,295 +1,11 @@ apis/authorization-api.ts apis/index.ts index.ts -models/account-by-id-body-params.ts -models/account-response.ts -models/account-search-list-response.ts models/action.ts -models/alert-response.ts models/api-validation-error.ts models/authorization-body-params.ts models/authorization-context-params.ts models/authorized-reponse.ts -models/basic-tool-config-params.ts -models/board-column-board-response.ts -models/board-context-response.ts -models/board-element-response-content.ts -models/board-element-response.ts -models/board-external-reference-type.ts -models/board-layout.ts -models/board-lesson-response.ts -models/board-parent-type.ts -models/board-response.ts -models/board-submission-controller-create-element201-response.ts -models/board-task-response.ts -models/board-task-status-response.ts -models/card-controller-create-element201-response.ts -models/card-list-response.ts -models/card-response-elements-inner.ts -models/card-response.ts -models/card-skeleton-response.ts -models/change-language-params.ts -models/class-info-response.ts -models/class-info-search-list-response.ts -models/class-request-context.ts -models/class-response.ts -models/class-sort-query-type.ts -models/collaborative-text-editor-element-response.ts -models/collaborative-text-editor-parent-type.ts -models/collaborative-text-editor-response.ts -models/collapsable-body-params.ts -models/color-body-params.ts -models/column-response.ts -models/config-response.ts -models/consent-request-body.ts -models/consent-response.ts -models/consent-session-response.ts -models/consents-response.ts -models/content-element-type.ts -models/context-external-tool-body-params.ts -models/context-external-tool-configuration-status-response.ts -models/context-external-tool-configuration-template-list-response.ts -models/context-external-tool-configuration-template-response.ts -models/context-external-tool-count-per-context-response.ts -models/context-external-tool-post-params.ts -models/context-external-tool-response.ts -models/context-external-tool-search-list-response.ts -models/copy-api-response.ts -models/county-response.ts -models/course-common-cartridge-metadata-response.ts -models/course-export-body-params.ts -models/course-info-data-response.ts -models/course-info-list-response.ts -models/course-info-response.ts -models/course-metadata-list-response.ts -models/course-metadata-response.ts -models/course-sort-props.ts -models/course-status.ts -models/course-sync-body-params.ts -models/create-board-body-params.ts -models/create-board-response.ts -models/create-card-body-params.ts -models/create-content-element-body-params.ts -models/create-media-element-body-params.ts -models/create-news-params.ts -models/create-room-body-params.ts -models/create-submission-item-body-params.ts -models/custom-parameter-entry-param.ts -models/custom-parameter-entry-response.ts -models/custom-parameter-post-params.ts -models/custom-parameter-response.ts -models/dashboard-grid-element-response.ts -models/dashboard-grid-sub-element-response.ts -models/dashboard-response.ts -models/deleted-element-content.ts -models/deleted-element-response.ts -models/drawing-content-body.ts -models/drawing-element-content-body.ts -models/drawing-element-content.ts -models/drawing-element-response.ts -models/element-controller-update-element201-response.ts -models/entity-not-found-error.ts -models/external-source-response.ts -models/external-tool-bulk-create-params.ts -models/external-tool-content-body.ts -models/external-tool-create-params.ts -models/external-tool-element-content-body.ts -models/external-tool-element-content.ts -models/external-tool-element-response.ts -models/external-tool-medium-params.ts -models/external-tool-medium-response.ts -models/external-tool-metadata-response.ts -models/external-tool-response-config.ts -models/external-tool-response.ts -models/external-tool-search-list-response.ts -models/external-tool-update-params-config.ts -models/external-tool-update-params.ts -models/federal-state-response.ts -models/file-content-body.ts -models/file-element-content-body.ts -models/file-element-content.ts -models/file-element-response.ts -models/file-storage-type.ts -models/forbidden-operation-error.ts -models/force-migration-params.ts -models/get-meta-tag-data-body.ts -models/group-list-response.ts -models/group-response.ts -models/group-user-response.ts -models/import-user-list-response.ts -models/import-user-response.ts models/index.ts -models/instance-feature.ts -models/language-type.ts -models/layout-body-params.ts -models/ldap-authorization-body-params.ts -models/lesson-content-response.ts -models/lesson-copy-api-params.ts -models/lesson-linked-task-response.ts -models/lesson-metadata-list-response.ts -models/lesson-metadata-response.ts -models/lesson-response.ts -models/link-content-body.ts -models/link-element-content-body.ts -models/link-element-content.ts -models/link-element-response.ts -models/local-authorization-body-params.ts -models/login-request-body.ts -models/login-response.ts -models/lti-message-type.ts -models/lti-privacy-permission.ts -models/lti11-tool-config-create-params.ts -models/lti11-tool-config-update-params.ts -models/material-response.ts -models/me-account-response.ts -models/me-response.ts -models/me-role-response.ts -models/me-school-logo-response.ts -models/me-school-response.ts -models/me-user-response.ts -models/media-available-line-element-response.ts -models/media-available-line-response.ts -models/media-board-colors.ts -models/media-board-layout-type.ts -models/media-board-response.ts -models/media-external-tool-element-content.ts -models/media-external-tool-element-response.ts -models/media-line-response-elements-inner.ts -models/media-line-response.ts -models/message-origin.ts -models/message.ts -models/meta-tag-extractor-response.ts -models/move-card-body-params.ts -models/move-column-body-params.ts -models/move-content-element-body.ts -models/move-element-body-params.ts -models/move-element-params.ts -models/move-element-position-params.ts -models/news-list-response.ts -models/news-response.ts -models/news-target-model.ts -models/o-auth-token-dto.ts -models/oauth-client-create-body.ts -models/oauth-client-response.ts -models/oauth-client-update-body.ts -models/oauth-config-response.ts -models/oauth-provider-login-response.ts -models/oauth2-authorization-body-params.ts -models/oauth2-migration-params.ts -models/oauth2-tool-config-create-params.ts -models/oauth2-tool-config-update-params.ts -models/oidc-context-response.ts -models/parent-consent-response.ts -models/patch-group-params.ts -models/patch-my-account-params.ts -models/patch-my-password-params.ts -models/patch-order-params.ts -models/patch-visibility-params.ts -models/period-response.ts models/permission.ts -models/provider-config-response.ts -models/pseudonym-response.ts -models/public-system-list-response.ts -models/public-system-response.ts -models/redirect-response.ts -models/rename-body-params.ts -models/resolved-user-response.ts -models/rich-text-content-body.ts -models/rich-text-element-content-body.ts -models/rich-text-element-content.ts -models/rich-text-element-response.ts -models/rich-text.ts -models/role-name.ts -models/room-color.ts -models/room-details-response.ts -models/room-item-response.ts -models/room-list-response.ts -models/school-controller-get-provisioning-options200-response.ts -models/school-exists-response.ts -models/school-external-tool-configuration-status-response.ts -models/school-external-tool-configuration-template-list-response.ts -models/school-external-tool-configuration-template-response.ts -models/school-external-tool-metadata-response.ts -models/school-external-tool-post-params.ts -models/school-external-tool-response.ts -models/school-external-tool-search-list-response.ts -models/school-feature.ts -models/school-for-external-invite-response.ts -models/school-for-ldap-login-response.ts -models/school-info-response.ts -models/school-logo.ts -models/school-permissions-params.ts -models/school-purpose.ts -models/school-response.ts -models/school-system-response.ts -models/school-update-body-params.ts -models/school-year-query-type.ts -models/school-year-response.ts -models/schul-conne-x-provisioning-options-params.ts -models/schul-conne-x-provisioning-options-response.ts -models/schulcloud-theme.ts -models/set-height-body-params.ts -models/share-token-body-params.ts -models/share-token-import-body-params.ts -models/share-token-info-response.ts -models/share-token-payload-response.ts -models/share-token-response.ts -models/single-column-board-response.ts -models/student-permission-params.ts -models/submission-container-content-body.ts -models/submission-container-element-content-body.ts -models/submission-container-element-content.ts -models/submission-container-element-response.ts -models/submission-item-response-elements-inner.ts -models/submission-item-response.ts -models/submission-status-list-response.ts -models/submission-status-response.ts -models/submissions-response.ts -models/successful-response.ts -models/system-for-ldap-login-response.ts -models/system-type.ts -models/target-info-response.ts -models/target-user-id-params.ts -models/task-copy-api-params.ts -models/task-list-response.ts -models/task-response.ts -models/task-status-response.ts -models/teacher-permission-params.ts -models/team-permissions-body.ts -models/timestamps-response.ts -models/timezone.ts -models/tool-config-type.ts -models/tool-context-type.ts -models/tool-context-types-list-response.ts -models/tool-launch-request-response.ts -models/tool-reference-list-response.ts -models/tool-reference-response.ts -models/update-board-title-params.ts -models/update-element-content-body-params-data.ts -models/update-element-content-body-params.ts -models/update-flag-params.ts -models/update-match-params.ts -models/update-news-params.ts -models/update-room-body-params.ts -models/update-submission-item-body-params.ts -models/user-consent-response.ts -models/user-data-response.ts -models/user-info-response.ts -models/user-list-response.ts -models/user-login-migration-mandatory-params.ts -models/user-login-migration-response.ts -models/user-login-migration-search-list-response.ts -models/user-match-list-response.ts -models/user-match-response.ts -models/user-response.ts -models/validation-error.ts -models/video-conference-create-params.ts -models/video-conference-info-response.ts -models/video-conference-join-response.ts -models/video-conference-options-response.ts -models/video-conference-scope.ts -models/video-conference-state-response.ts -models/visibility-body-params.ts -models/visibility-settings-response.ts -models/years-response.ts runtime.ts diff --git a/src/infra/authorization/authorization-api-client/models/authorization-context-params.ts b/src/infra/authorization/authorization-api-client/models/authorization-context-params.ts index 4233ced7..769c5e2f 100644 --- a/src/infra/authorization/authorization-api-client/models/authorization-context-params.ts +++ b/src/infra/authorization/authorization-api-client/models/authorization-context-params.ts @@ -5,78 +5,88 @@ * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. * * The version of the OpenAPI document: 3.0 - * + * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ +import { mapValues } from '../runtime.js'; import type { Action } from './action.js'; -import { ActionFromJSON, ActionToJSON } from './action.js'; +import { + ActionFromJSON, + ActionFromJSONTyped, + ActionToJSON, + ActionToJSONTyped, +} from './action.js'; import type { Permission } from './permission.js'; -import { PermissionFromJSON, PermissionToJSON } from './permission.js'; +import { + PermissionFromJSON, + PermissionFromJSONTyped, + PermissionToJSON, + PermissionToJSONTyped, +} from './permission.js'; /** - * + * * @export * @interface AuthorizationContextParams */ export interface AuthorizationContextParams { - /** - * - * @type {Action} - * @memberof AuthorizationContextParams - */ - action: Action; - /** - * User permissions that are needed to execute the operation. - * @type {Array} - * @memberof AuthorizationContextParams - */ - requiredPermissions: Array; + /** + * + * @type {Action} + * @memberof AuthorizationContextParams + */ + action: Action; + /** + * User permissions that are needed to execute the operation. + * @type {Array} + * @memberof AuthorizationContextParams + */ + requiredPermissions: Array; } + + /** * Check if a given object implements the AuthorizationContextParams interface. */ export function instanceOfAuthorizationContextParams(value: object): value is AuthorizationContextParams { - if (!('action' in value) || value['action'] === undefined) return false; - if (!('requiredPermissions' in value) || value['requiredPermissions'] === undefined) return false; - return true; + if (!('action' in value) || value['action'] === undefined) return false; + if (!('requiredPermissions' in value) || value['requiredPermissions'] === undefined) return false; + return true; } export function AuthorizationContextParamsFromJSON(json: any): AuthorizationContextParams { - return AuthorizationContextParamsFromJSONTyped(json, false); + return AuthorizationContextParamsFromJSONTyped(json, false); } -export function AuthorizationContextParamsFromJSONTyped( - json: any, - ignoreDiscriminator: boolean, -): AuthorizationContextParams { - if (json == null) { - return json; - } - return { - action: ActionFromJSON(json['action']), - requiredPermissions: (json['requiredPermissions'] as Array).map(PermissionFromJSON), - }; +export function AuthorizationContextParamsFromJSONTyped(json: any, ignoreDiscriminator: boolean): AuthorizationContextParams { + if (json == null) { + return json; + } + return { + + 'action': ActionFromJSON(json['action']), + 'requiredPermissions': ((json['requiredPermissions'] as Array).map(PermissionFromJSON)), + }; } -export function AuthorizationContextParamsToJSON(json: any): AuthorizationContextParams { - return AuthorizationContextParamsToJSONTyped(json, false); -} + export function AuthorizationContextParamsToJSON(json: any): AuthorizationContextParams { + return AuthorizationContextParamsToJSONTyped(json, false); + } -export function AuthorizationContextParamsToJSONTyped( - value?: AuthorizationContextParams | null, - ignoreDiscriminator: boolean = false, -): any { - if (value == null) { - return value; - } + export function AuthorizationContextParamsToJSONTyped(value?: AuthorizationContextParams | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } - return { - action: ActionToJSON(value['action']), - requiredPermissions: (value['requiredPermissions'] as Array).map(PermissionToJSON), - }; + return { + + 'action': ActionToJSON(value['action']), + 'requiredPermissions': ((value['requiredPermissions'] as Array).map(PermissionToJSON)), + }; } + From 6ad1ce4132a43ff37f5319b49ef109746e076bbb Mon Sep 17 00:00:00 2001 From: Constantin Bergatt Date: Mon, 14 Oct 2024 10:48:04 +0200 Subject: [PATCH 07/16] BC-7879 - remove `models/index.ts` from `src/infra/authorization/authorization-api-client/.openapi-generator/FILES` --- .../authorization-api-client/.openapi-generator/FILES | 1 - 1 file changed, 1 deletion(-) diff --git a/src/infra/authorization/authorization-api-client/.openapi-generator/FILES b/src/infra/authorization/authorization-api-client/.openapi-generator/FILES index e6ed4f3a..32416841 100644 --- a/src/infra/authorization/authorization-api-client/.openapi-generator/FILES +++ b/src/infra/authorization/authorization-api-client/.openapi-generator/FILES @@ -6,6 +6,5 @@ models/api-validation-error.ts models/authorization-body-params.ts models/authorization-context-params.ts models/authorized-reponse.ts -models/index.ts models/permission.ts runtime.ts From 678379e61f2769aae1af947924187ef8cf174301 Mon Sep 17 00:00:00 2001 From: Constantin Bergatt Date: Mon, 14 Oct 2024 15:18:16 +0200 Subject: [PATCH 08/16] BC-7879 - refactor authorization service to include authorization token in request headers --- src/infra/authorization/authorization.service.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/infra/authorization/authorization.service.ts b/src/infra/authorization/authorization.service.ts index 5fc4e629..e208031f 100644 --- a/src/infra/authorization/authorization.service.ts +++ b/src/infra/authorization/authorization.service.ts @@ -65,10 +65,16 @@ export class AuthorizationService { }, }; - // this.authorizationApi.configuration.accessToken = token; + const initOverrides: RequestInit = { + headers: { + Authorization: `Bearer ${token}`, + }, + }; - const response = - await this.authorizationApi.authorizationReferenceControllerAuthorizeByReference(requestParameters); + const response = await this.authorizationApi.authorizationReferenceControllerAuthorizeByReference( + requestParameters, + initOverrides, + ); const { isAuthorized, userId } = response; if (!isAuthorized) { From 4232f15cb93d241fbea42586964aa19e670abb41 Mon Sep 17 00:00:00 2001 From: Constantin Bergatt Date: Tue, 15 Oct 2024 07:11:45 +0200 Subject: [PATCH 09/16] BC-7879 - fix `AuthorizationContextParams` to handle enum types correctly --- .../.openapi-generator-ignore | 2 - .../.openapi-generator/FILES | 2 - .../authorization-api-client/models/action.ts | 53 ----- .../models/authorization-context-params.ts | 211 ++++++++++++++++-- .../authorization-api-client/models/index.ts | 2 - .../models/permission.ts | 46 ---- 6 files changed, 187 insertions(+), 129 deletions(-) delete mode 100644 src/infra/authorization/authorization-api-client/models/action.ts delete mode 100644 src/infra/authorization/authorization-api-client/models/permission.ts diff --git a/src/infra/authorization/authorization-api-client/.openapi-generator-ignore b/src/infra/authorization/authorization-api-client/.openapi-generator-ignore index 9f7e4d1a..a32205e7 100644 --- a/src/infra/authorization/authorization-api-client/.openapi-generator-ignore +++ b/src/infra/authorization/authorization-api-client/.openapi-generator-ignore @@ -31,9 +31,7 @@ git_push.sh models/* # list of allowed files in the "models" folder -!models/action.ts !models/api-validation-error.ts !models/authorization-body-params.ts !models/authorization-context-params.ts !models/authorized-reponse.ts -!models/permission.ts \ No newline at end of file diff --git a/src/infra/authorization/authorization-api-client/.openapi-generator/FILES b/src/infra/authorization/authorization-api-client/.openapi-generator/FILES index 32416841..38162f8b 100644 --- a/src/infra/authorization/authorization-api-client/.openapi-generator/FILES +++ b/src/infra/authorization/authorization-api-client/.openapi-generator/FILES @@ -1,10 +1,8 @@ apis/authorization-api.ts apis/index.ts index.ts -models/action.ts models/api-validation-error.ts models/authorization-body-params.ts models/authorization-context-params.ts models/authorized-reponse.ts -models/permission.ts runtime.ts diff --git a/src/infra/authorization/authorization-api-client/models/action.ts b/src/infra/authorization/authorization-api-client/models/action.ts deleted file mode 100644 index 545af1fb..00000000 --- a/src/infra/authorization/authorization-api-client/models/action.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Schulcloud-Verbund-Software Server API - * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. - * - * The version of the OpenAPI document: 3.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -/** - * - * @export - */ -export const Action = { - READ: 'read', - WRITE: 'write' -} as const; -export type Action = typeof Action[keyof typeof Action]; - - -export function instanceOfAction(value: any): boolean { - for (const key in Action) { - if (Object.prototype.hasOwnProperty.call(Action, key)) { - if (Action[key as keyof typeof Action] === value) { - return true; - } - } - } - return false; -} - -export function ActionFromJSON(json: any): Action { - return ActionFromJSONTyped(json, false); -} - -export function ActionFromJSONTyped(json: any, ignoreDiscriminator: boolean): Action { - return json as Action; -} - -export function ActionToJSON(value?: Action | null): any { - return value as any; -} - -export function ActionToJSONTyped(value: any, ignoreDiscriminator: boolean): Action { - return value as Action; -} - diff --git a/src/infra/authorization/authorization-api-client/models/authorization-context-params.ts b/src/infra/authorization/authorization-api-client/models/authorization-context-params.ts index 769c5e2f..7a0daee3 100644 --- a/src/infra/authorization/authorization-api-client/models/authorization-context-params.ts +++ b/src/infra/authorization/authorization-api-client/models/authorization-context-params.ts @@ -13,21 +13,6 @@ */ import { mapValues } from '../runtime.js'; -import type { Action } from './action.js'; -import { - ActionFromJSON, - ActionFromJSONTyped, - ActionToJSON, - ActionToJSONTyped, -} from './action.js'; -import type { Permission } from './permission.js'; -import { - PermissionFromJSON, - PermissionFromJSONTyped, - PermissionToJSON, - PermissionToJSONTyped, -} from './permission.js'; - /** * * @export @@ -35,20 +20,198 @@ import { */ export interface AuthorizationContextParams { /** - * - * @type {Action} + * Define for which action the operation should be performend. + * @type {string} * @memberof AuthorizationContextParams */ - action: Action; + action: AuthorizationContextParamsAction; /** * User permissions that are needed to execute the operation. - * @type {Array} + * @type {Array} * @memberof AuthorizationContextParams */ - requiredPermissions: Array; + requiredPermissions: Array; } +/** + * @export + */ +export const AuthorizationContextParamsAction = { + READ: 'read', + WRITE: 'write' +} as const; +export type AuthorizationContextParamsAction = typeof AuthorizationContextParamsAction[keyof typeof AuthorizationContextParamsAction]; + +/** + * @export + */ +export const AuthorizationContextParamsRequiredPermissions = { + ACCOUNT_CREATE: 'ACCOUNT_CREATE', + ACCOUNT_DELETE: 'ACCOUNT_DELETE', + ACCOUNT_EDIT: 'ACCOUNT_EDIT', + ACCOUNT_VIEW: 'ACCOUNT_VIEW', + ADD_SCHOOL_MEMBERS: 'ADD_SCHOOL_MEMBERS', + ADMIN_EDIT: 'ADMIN_EDIT', + ADMIN_VIEW: 'ADMIN_VIEW', + BASE_VIEW: 'BASE_VIEW', + CALENDAR_CREATE: 'CALENDAR_CREATE', + CALENDAR_EDIT: 'CALENDAR_EDIT', + CALENDAR_VIEW: 'CALENDAR_VIEW', + CHANGE_TEAM_ROLES: 'CHANGE_TEAM_ROLES', + CLASS_CREATE: 'CLASS_CREATE', + CLASS_EDIT: 'CLASS_EDIT', + CLASS_FULL_ADMIN: 'CLASS_FULL_ADMIN', + CLASS_LIST: 'CLASS_LIST', + CLASS_REMOVE: 'CLASS_REMOVE', + CLASS_VIEW: 'CLASS_VIEW', + COMMENTS_CREATE: 'COMMENTS_CREATE', + COMMENTS_EDIT: 'COMMENTS_EDIT', + COMMENTS_VIEW: 'COMMENTS_VIEW', + CONTENT_NON_OER_VIEW: 'CONTENT_NON_OER_VIEW', + CONTENT_VIEW: 'CONTENT_VIEW', + CONTEXT_TOOL_ADMIN: 'CONTEXT_TOOL_ADMIN', + CONTEXT_TOOL_USER: 'CONTEXT_TOOL_USER', + COURSEGROUP_CREATE: 'COURSEGROUP_CREATE', + COURSEGROUP_EDIT: 'COURSEGROUP_EDIT', + COURSE_ADMINISTRATION: 'COURSE_ADMINISTRATION', + COURSE_CREATE: 'COURSE_CREATE', + COURSE_DELETE: 'COURSE_DELETE', + COURSE_EDIT: 'COURSE_EDIT', + COURSE_REMOVE: 'COURSE_REMOVE', + COURSE_VIEW: 'COURSE_VIEW', + CREATE_SUPPORT_JWT: 'CREATE_SUPPORT_JWT', + CREATE_TOPICS_AND_TASKS: 'CREATE_TOPICS_AND_TASKS', + DASHBOARD_VIEW: 'DASHBOARD_VIEW', + DATASOURCES_CREATE: 'DATASOURCES_CREATE', + DATASOURCES_DELETE: 'DATASOURCES_DELETE', + DATASOURCES_EDIT: 'DATASOURCES_EDIT', + DATASOURCES_RUN: 'DATASOURCES_RUN', + DATASOURCES_RUN_VIEW: 'DATASOURCES_RUN_VIEW', + DATASOURCES_VIEW: 'DATASOURCES_VIEW', + DEFAULT_FILE_PERMISSIONS: 'DEFAULT_FILE_PERMISSIONS', + DELETE_TEAM: 'DELETE_TEAM', + EDIT_ALL_FILES: 'EDIT_ALL_FILES', + ENTERTHECLOUD_START: 'ENTERTHECLOUD_START', + FEDERALSTATE_CREATE: 'FEDERALSTATE_CREATE', + FEDERALSTATE_EDIT: 'FEDERALSTATE_EDIT', + FEDERALSTATE_VIEW: 'FEDERALSTATE_VIEW', + FILESTORAGE_CREATE: 'FILESTORAGE_CREATE', + FILESTORAGE_EDIT: 'FILESTORAGE_EDIT', + FILESTORAGE_REMOVE: 'FILESTORAGE_REMOVE', + FILESTORAGE_VIEW: 'FILESTORAGE_VIEW', + FILE_CREATE: 'FILE_CREATE', + FILE_DELETE: 'FILE_DELETE', + FILE_MOVE: 'FILE_MOVE', + FOLDER_CREATE: 'FOLDER_CREATE', + FOLDER_DELETE: 'FOLDER_DELETE', + GROUP_LIST: 'GROUP_LIST', + GROUP_FULL_ADMIN: 'GROUP_FULL_ADMIN', + GROUP_VIEW: 'GROUP_VIEW', + HELPDESK_CREATE: 'HELPDESK_CREATE', + HELPDESK_EDIT: 'HELPDESK_EDIT', + HELPDESK_VIEW: 'HELPDESK_VIEW', + HOMEWORK_CREATE: 'HOMEWORK_CREATE', + HOMEWORK_EDIT: 'HOMEWORK_EDIT', + HOMEWORK_VIEW: 'HOMEWORK_VIEW', + IMPORT_USER_MIGRATE: 'IMPORT_USER_MIGRATE', + IMPORT_USER_UPDATE: 'IMPORT_USER_UPDATE', + IMPORT_USER_VIEW: 'IMPORT_USER_VIEW', + INSTANCE_VIEW: 'INSTANCE_VIEW', + INVITE_ADMINISTRATORS: 'INVITE_ADMINISTRATORS', + INVITE_EXPERTS: 'INVITE_EXPERTS', + JOIN_MEETING: 'JOIN_MEETING', + LEAVE_TEAM: 'LEAVE_TEAM', + LERNSTORE_VIEW: 'LERNSTORE_VIEW', + LESSONS_CREATE: 'LESSONS_CREATE', + LESSONS_VIEW: 'LESSONS_VIEW', + LINK_CREATE: 'LINK_CREATE', + NEWS_CREATE: 'NEWS_CREATE', + NEWS_EDIT: 'NEWS_EDIT', + NEWS_VIEW: 'NEWS_VIEW', + NEXTCLOUD_USER: 'NEXTCLOUD_USER', + NOTIFICATION_CREATE: 'NOTIFICATION_CREATE', + NOTIFICATION_EDIT: 'NOTIFICATION_EDIT', + NOTIFICATION_VIEW: 'NOTIFICATION_VIEW', + OAUTH_CLIENT_EDIT: 'OAUTH_CLIENT_EDIT', + OAUTH_CLIENT_VIEW: 'OAUTH_CLIENT_VIEW', + PASSWORD_EDIT: 'PASSWORD_EDIT', + PWRECOVERY_CREATE: 'PWRECOVERY_CREATE', + PWRECOVERY_EDIT: 'PWRECOVERY_EDIT', + PWRECOVERY_VIEW: 'PWRECOVERY_VIEW', + RELEASES_CREATE: 'RELEASES_CREATE', + RELEASES_EDIT: 'RELEASES_EDIT', + RELEASES_VIEW: 'RELEASES_VIEW', + REMOVE_MEMBERS: 'REMOVE_MEMBERS', + RENAME_TEAM: 'RENAME_TEAM', + REQUEST_CONSENTS: 'REQUEST_CONSENTS', + ROLE_CREATE: 'ROLE_CREATE', + ROLE_EDIT: 'ROLE_EDIT', + ROLE_VIEW: 'ROLE_VIEW', + SCHOOL_CHAT_MANAGE: 'SCHOOL_CHAT_MANAGE', + SCHOOL_CREATE: 'SCHOOL_CREATE', + SCHOOL_EDIT: 'SCHOOL_EDIT', + SCHOOL_EDIT_ALL: 'SCHOOL_EDIT_ALL', + SCHOOL_LOGO_MANAGE: 'SCHOOL_LOGO_MANAGE', + SCHOOL_NEWS_EDIT: 'SCHOOL_NEWS_EDIT', + SCHOOL_PERMISSION_CHANGE: 'SCHOOL_PERMISSION_CHANGE', + SCHOOL_PERMISSION_VIEW: 'SCHOOL_PERMISSION_VIEW', + SCHOOL_STUDENT_TEAM_MANAGE: 'SCHOOL_STUDENT_TEAM_MANAGE', + SCHOOL_SYSTEM_EDIT: 'SCHOOL_SYSTEM_EDIT', + SCHOOL_SYSTEM_VIEW: 'SCHOOL_SYSTEM_VIEW', + SCHOOL_TOOL_ADMIN: 'SCHOOL_TOOL_ADMIN', + SCOPE_PERMISSIONS_VIEW: 'SCOPE_PERMISSIONS_VIEW', + START_MEETING: 'START_MEETING', + STUDENT_CREATE: 'STUDENT_CREATE', + STUDENT_DELETE: 'STUDENT_DELETE', + STUDENT_EDIT: 'STUDENT_EDIT', + STUDENT_LIST: 'STUDENT_LIST', + STUDENT_SKIP_REGISTRATION: 'STUDENT_SKIP_REGISTRATION', + SUBMISSIONS_CREATE: 'SUBMISSIONS_CREATE', + SUBMISSIONS_EDIT: 'SUBMISSIONS_EDIT', + SUBMISSIONS_SCHOOL_VIEW: 'SUBMISSIONS_SCHOOL_VIEW', + SUBMISSIONS_VIEW: 'SUBMISSIONS_VIEW', + SYNC_START: 'SYNC_START', + SYSTEM_CREATE: 'SYSTEM_CREATE', + SYSTEM_EDIT: 'SYSTEM_EDIT', + SYSTEM_VIEW: 'SYSTEM_VIEW', + TASK_DASHBOARD_TEACHER_VIEW_V3: 'TASK_DASHBOARD_TEACHER_VIEW_V3', + TASK_DASHBOARD_VIEW_V3: 'TASK_DASHBOARD_VIEW_V3', + TEACHER_CREATE: 'TEACHER_CREATE', + TEACHER_DELETE: 'TEACHER_DELETE', + TEACHER_EDIT: 'TEACHER_EDIT', + TEACHER_LIST: 'TEACHER_LIST', + TEACHER_SKIP_REGISTRATION: 'TEACHER_SKIP_REGISTRATION', + TEAM_CREATE: 'TEAM_CREATE', + TOOL_CREATE_ETHERPAD: 'TOOL_CREATE_ETHERPAD', + TEAM_EDIT: 'TEAM_EDIT', + TEAM_INVITE_EXTERNAL: 'TEAM_INVITE_EXTERNAL', + TEAM_VIEW: 'TEAM_VIEW', + TOOL_ADMIN: 'TOOL_ADMIN', + TOOL_CREATE: 'TOOL_CREATE', + TOOL_EDIT: 'TOOL_EDIT', + TOOL_NEW_VIEW: 'TOOL_NEW_VIEW', + TOOL_VIEW: 'TOOL_VIEW', + TOPIC_CREATE: 'TOPIC_CREATE', + TOPIC_EDIT: 'TOPIC_EDIT', + TOPIC_VIEW: 'TOPIC_VIEW', + UPLOAD_FILES: 'UPLOAD_FILES', + USE_LIBREOFFICE: 'USE_LIBREOFFICE', + USE_ROCKETCHAT: 'USE_ROCKETCHAT', + USERGROUP_CREATE: 'USERGROUP_CREATE', + USERGROUP_EDIT: 'USERGROUP_EDIT', + USERGROUP_VIEW: 'USERGROUP_VIEW', + USER_CHANGE_OWN_NAME: 'USER_CHANGE_OWN_NAME', + USER_CREATE: 'USER_CREATE', + USER_LOGIN_MIGRATION_ADMIN: 'USER_LOGIN_MIGRATION_ADMIN', + USER_LOGIN_MIGRATION_ROLLBACK: 'USER_LOGIN_MIGRATION_ROLLBACK', + USER_LOGIN_MIGRATION_FORCE: 'USER_LOGIN_MIGRATION_FORCE', + USER_MIGRATE: 'USER_MIGRATE', + USER_UPDATE: 'USER_UPDATE', + YEARS_EDIT: 'YEARS_EDIT' +} as const; +export type AuthorizationContextParamsRequiredPermissions = typeof AuthorizationContextParamsRequiredPermissions[keyof typeof AuthorizationContextParamsRequiredPermissions]; + /** * Check if a given object implements the AuthorizationContextParams interface. @@ -69,8 +232,8 @@ export function AuthorizationContextParamsFromJSONTyped(json: any, ignoreDiscrim } return { - 'action': ActionFromJSON(json['action']), - 'requiredPermissions': ((json['requiredPermissions'] as Array).map(PermissionFromJSON)), + 'action': json['action'], + 'requiredPermissions': json['requiredPermissions'], }; } @@ -85,8 +248,8 @@ export function AuthorizationContextParamsFromJSONTyped(json: any, ignoreDiscrim return { - 'action': ActionToJSON(value['action']), - 'requiredPermissions': ((value['requiredPermissions'] as Array).map(PermissionToJSON)), + 'action': value['action'], + 'requiredPermissions': value['requiredPermissions'], }; } diff --git a/src/infra/authorization/authorization-api-client/models/index.ts b/src/infra/authorization/authorization-api-client/models/index.ts index f1293724..967c7957 100644 --- a/src/infra/authorization/authorization-api-client/models/index.ts +++ b/src/infra/authorization/authorization-api-client/models/index.ts @@ -1,8 +1,6 @@ /* tslint:disable */ /* eslint-disable */ -export * from './action.js'; export * from './api-validation-error.js'; export * from './authorization-body-params.js'; export * from './authorization-context-params.js'; export * from './authorized-reponse.js'; -export * from './permission.js'; diff --git a/src/infra/authorization/authorization-api-client/models/permission.ts b/src/infra/authorization/authorization-api-client/models/permission.ts deleted file mode 100644 index 51d32db8..00000000 --- a/src/infra/authorization/authorization-api-client/models/permission.ts +++ /dev/null @@ -1,46 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Schulcloud-Verbund-Software Server API - * This is v3 of Schulcloud-Verbund-Software Server. Checkout /docs for v1. - * - * The version of the OpenAPI document: 3.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -import { mapValues } from '../runtime.js'; -/** - * - * @export - * @interface Permission - */ -export interface Permission extends Array { -} - -/** - * Check if a given object implements the Permission interface. - */ -export function instanceOfPermission(value: object): value is Permission { - return true; -} - -export function PermissionFromJSON(json: any): Permission { - return PermissionFromJSONTyped(json, false); -} - -export function PermissionFromJSONTyped(json: any, ignoreDiscriminator: boolean): Permission { - return json; -} - - export function PermissionToJSON(json: any): Permission { - return PermissionToJSONTyped(json, false); - } - - export function PermissionToJSONTyped(value?: Permission | null, ignoreDiscriminator: boolean = false): any { - return value; -} - From 99e825d6f44c6e03a121d33774de598b2a3777bf Mon Sep 17 00:00:00 2001 From: Constantin Bergatt Date: Tue, 15 Oct 2024 07:18:34 +0200 Subject: [PATCH 10/16] BC-7879 - refactor authorization service to handle enum types correctly and include authorization token in request headers --- src/infra/authorization/authorization.service.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/infra/authorization/authorization.service.ts b/src/infra/authorization/authorization.service.ts index e208031f..dc209e70 100644 --- a/src/infra/authorization/authorization.service.ts +++ b/src/infra/authorization/authorization.service.ts @@ -2,9 +2,10 @@ import { Injectable } from '@nestjs/common'; import { HttpRequest } from 'uws'; import { Logger } from '../logging/logger.js'; import { - Action, AuthorizationApi, AuthorizationBodyParamsReferenceType, + AuthorizationContextParamsAction, + AuthorizationContextParamsRequiredPermissions, AuthorizationReferenceControllerAuthorizeByReferenceRequest, } from './authorization-api-client/index.js'; import { ResponsePayload } from './interfaces/response.payload.js'; @@ -59,14 +60,15 @@ export class AuthorizationService { referenceType: AuthorizationBodyParamsReferenceType.BOARDNODES, referenceId: room, context: { - action: Action.READ, - requiredPermissions: [['COURSE_VIEW']], + action: AuthorizationContextParamsAction.READ, + requiredPermissions: [AuthorizationContextParamsRequiredPermissions.COURSE_VIEW], }, }, }; const initOverrides: RequestInit = { headers: { + 'Content-Type': 'application/json', Authorization: `Bearer ${token}`, }, }; From 4063ab119f4c1ee10f8bebd3fa5b2825e182241c Mon Sep 17 00:00:00 2001 From: Constantin Bergatt Date: Tue, 15 Oct 2024 10:42:29 +0200 Subject: [PATCH 11/16] BC-7879 - add `ConfigService` to `AuthorizationModule` and exclude `authorization-api-client` from code coverage --- sonar-project.properties | 4 ++-- .../authorization/authorization.module.ts | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/sonar-project.properties b/sonar-project.properties index 277da143..83a99cc8 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -3,8 +3,8 @@ sonar.projectKey=hpi-schul-cloud_tldraw-server sonar.sources=. sonar.tests=. sonar.test.inclusions=**/*.spec.ts -sonar.exclusions=**/*.app.ts, -sonar.coverage.exclusions=**/*.factory.ts +sonar.exclusions=**/*.app.ts,**/authorization-api-client/*.* +sonar.coverage.exclusions=**/*.factory.ts,**/authorization-api-client/*.* sonar.cpd.exclusions=**/controller/dto/*.ts sonar.javascript.lcov.reportPaths=merged-lcov.info sonar.typescript.tsconfigPaths=tsconfig.json diff --git a/src/infra/authorization/authorization.module.ts b/src/infra/authorization/authorization.module.ts index b3f88a8f..e79664cc 100644 --- a/src/infra/authorization/authorization.module.ts +++ b/src/infra/authorization/authorization.module.ts @@ -1,11 +1,25 @@ import { Module } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; import { LoggerModule } from '../logging/logger.module.js'; -import { AuthorizationApi } from './authorization-api-client/index.js'; +import { AuthorizationApi, Configuration } from './authorization-api-client/index.js'; import { AuthorizationService } from './authorization.service.js'; @Module({ imports: [LoggerModule], - providers: [AuthorizationApi, AuthorizationService], + providers: [ + { + provide: AuthorizationApi, + useFactory: (configService: ConfigService): AuthorizationApi => { + const apiHost = configService.getOrThrow('API_HOST'); + const configuration = new Configuration({ basePath: apiHost }); + const authorizationApi = new AuthorizationApi(configuration); + + return authorizationApi; + }, + inject: [ConfigService], + }, + AuthorizationService, + ], exports: [AuthorizationService], }) export class AuthorizationModule {} From dcb1527665ee3f806172ce0d2d23aeaa823c1d56 Mon Sep 17 00:00:00 2001 From: Constantin Bergatt Date: Tue, 15 Oct 2024 10:47:39 +0200 Subject: [PATCH 12/16] BC-7879 - exclude authorization-api-client from code formatting and linting --- .eslintignore | 7 +++++++ .prettierignore | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..be095918 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,7 @@ +# used by codacy and npm run lint but not local prettier +# keep in sync with .prettierignore + +# ignore database dumps, keep format from export +ansible +.github +**/authorization-api-client/*.* diff --git a/.prettierignore b/.prettierignore index 64c7a53a..5c1c0124 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,2 +1,3 @@ ansible -.github \ No newline at end of file +.github +**/authorization-api-client/*.* \ No newline at end of file From 2880478f133c205d61b07cf911b4887c0c915ef7 Mon Sep 17 00:00:00 2001 From: Constantin Bergatt Date: Tue, 15 Oct 2024 13:27:10 +0200 Subject: [PATCH 13/16] BC-7879 - refactor authorization module to include `api/v3` in base path --- src/infra/authorization/authorization.module.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/infra/authorization/authorization.module.ts b/src/infra/authorization/authorization.module.ts index e79664cc..d95fa489 100644 --- a/src/infra/authorization/authorization.module.ts +++ b/src/infra/authorization/authorization.module.ts @@ -11,7 +11,7 @@ import { AuthorizationService } from './authorization.service.js'; provide: AuthorizationApi, useFactory: (configService: ConfigService): AuthorizationApi => { const apiHost = configService.getOrThrow('API_HOST'); - const configuration = new Configuration({ basePath: apiHost }); + const configuration = new Configuration({ basePath: `${apiHost}/api/v3` }); const authorizationApi = new AuthorizationApi(configuration); return authorizationApi; From 321edbd8f94c61786e5681b378c224f021ff76dd Mon Sep 17 00:00:00 2001 From: Constantin Bergatt Date: Tue, 15 Oct 2024 14:43:14 +0200 Subject: [PATCH 14/16] BC-7879 - refactor package-lock.json and package.json to include arg@5.0.2 as a dev dependency --- package-lock.json | 3 ++- package.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2cbb9c77..d6b20fda 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,6 @@ "@nestjs/passport": "^10.0.3", "@nestjs/platform-express": "^10.4.1", "@y/redis": "github:hpi-schul-cloud/y-redis#7d48e08d18ec78c9ab90063a7d867ec7f191319c", - "arg": "^5.0.2", "ioredis": "^5.4.1", "passport": "^0.7.0", "passport-headerapikey": "^1.2.2", @@ -40,6 +39,7 @@ "@types/supertest": "^6.0.0", "@typescript-eslint/eslint-plugin": "^7.0.0", "@typescript-eslint/parser": "^7.0.0", + "arg": "^5.0.2", "eslint": "^8.0.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-jest": "^28.8.3", @@ -3068,6 +3068,7 @@ "version": "5.0.2", "resolved": "https://registry.npmjs.org/arg/-/arg-5.0.2.tgz", "integrity": "sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==", + "dev": true, "license": "MIT" }, "node_modules/argparse": { diff --git a/package.json b/package.json index 4bda51d0..4d59e053 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ "@nestjs/passport": "^10.0.3", "@nestjs/platform-express": "^10.4.1", "@y/redis": "github:hpi-schul-cloud/y-redis#7d48e08d18ec78c9ab90063a7d867ec7f191319c", - "arg": "^5.0.2", "ioredis": "^5.4.1", "passport": "^0.7.0", "passport-headerapikey": "^1.2.2", @@ -60,6 +59,7 @@ "@types/supertest": "^6.0.0", "@typescript-eslint/eslint-plugin": "^7.0.0", "@typescript-eslint/parser": "^7.0.0", + "arg": "^5.0.2", "eslint": "^8.0.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-jest": "^28.8.3", From 4547b8f8623033cef4eb003ec567a29e644463dc Mon Sep 17 00:00:00 2001 From: Constantin Bergatt Date: Wed, 16 Oct 2024 13:40:39 +0200 Subject: [PATCH 15/16] BC-7879 - exclude authorization-api-client from code from eslint --- .eslintignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintignore b/.eslintignore index be095918..d320ffde 100644 --- a/.eslintignore +++ b/.eslintignore @@ -4,4 +4,4 @@ # ignore database dumps, keep format from export ansible .github -**/authorization-api-client/*.* +src/infra/authorization/authorization-api-client From 4cf6f5f8e69f69c05b685d06fa6e4952519eb390 Mon Sep 17 00:00:00 2001 From: Constantin Bergatt Date: Thu, 17 Oct 2024 07:57:33 +0200 Subject: [PATCH 16/16] BC-7879 - fix `sonar.exclusions` and `sonar.coverage.exclusions` to exclude `authorization-api-client` subfolder --- sonar-project.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonar-project.properties b/sonar-project.properties index 83a99cc8..1b2f9eff 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -3,8 +3,8 @@ sonar.projectKey=hpi-schul-cloud_tldraw-server sonar.sources=. sonar.tests=. sonar.test.inclusions=**/*.spec.ts -sonar.exclusions=**/*.app.ts,**/authorization-api-client/*.* -sonar.coverage.exclusions=**/*.factory.ts,**/authorization-api-client/*.* +sonar.exclusions=**/*.app.ts,**/authorization-api-client/**/*.ts +sonar.coverage.exclusions=**/*.factory.ts,**/authorization-api-client/**/*.ts sonar.cpd.exclusions=**/controller/dto/*.ts sonar.javascript.lcov.reportPaths=merged-lcov.info sonar.typescript.tsconfigPaths=tsconfig.json