diff --git a/.gitignore b/.gitignore index 271a844..1cc9e16 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,6 @@ dist .idea build/ processor/.env -processor/junit-report.xml \ No newline at end of file +processor/junit-report.xml +application/.env +application/*/.env \ No newline at end of file diff --git a/connect.yaml b/connect.yaml index 3e275aa..ba65192 100644 --- a/connect.yaml +++ b/connect.yaml @@ -26,6 +26,10 @@ deployAs: - key: MOLLIE_BANK_TRANSFER_DUE_DATE description: Payment method Bank Transfer due date (1d -> 100d) default: "14d" + - key: CTP_AUTHENTICATION_MODE + description: To enable secure mode for connector requests using JWT authentication (0 or 1) + required: true + default: "0" securedConfiguration: - key: MOLLIE_API_TEST_KEY description: Mollie PSP test API key diff --git a/processor/.env.example b/processor/.env.example index ccdf7a9..5b3afe9 100644 --- a/processor/.env.example +++ b/processor/.env.example @@ -4,6 +4,7 @@ CTP_CLIENT_SECRET= CTP_PROJECT_KEY= CTP_SCOPE= CTP_REGION= +CTP_AUTHENTICATION_MODE= ## Commercetools API URLs CTP_AUTH_URL=https://auth..commercetools.com diff --git a/processor/.env.jest b/processor/.env.jest index 1e299f9..a6f0569 100644 --- a/processor/.env.jest +++ b/processor/.env.jest @@ -5,6 +5,7 @@ CTP_CLIENT_SECRET=12345678901234567890123456789012 CTP_PROJECT_KEY=TEST CTP_SCOPE=TEST CTP_REGION=europe-west1.gcp +CTP_AUTHENTICATION_MODE=0 ## MOLLIE vars MOLLIE_PROFILE_ID=pfl_12345 DEBUG=0 diff --git a/processor/package-lock.json b/processor/package-lock.json index 8b01a13..6493072 100644 --- a/processor/package-lock.json +++ b/processor/package-lock.json @@ -1,16 +1,17 @@ { "name": "shopmacher-mollie-processor", - "version": "1.0.2", + "version": "1.0.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "shopmacher-mollie-processor", - "version": "1.0.2", + "version": "1.0.3", "hasInstallScript": true, "license": "MIT", "dependencies": { "@commercetools-backend/loggers": "^21.25.2", + "@commercetools/connect-payments-sdk": "^0.10.0", "@commercetools/platform-sdk": "^4.11.0", "@commercetools/sdk-client-v2": "^2.5.0", "@mollie/api-client": "^3.7.0", @@ -188,6 +189,16 @@ "ms": "2.0.0" } }, + "node_modules/jwa": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz", + "integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==", + "dependencies": { + "buffer-equal-constant-time": "1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, "node_modules/expect": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/expect/-/expect-29.7.0.tgz", @@ -496,6 +507,11 @@ } } }, + "node_modules/lru-memoizer/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, "node_modules/merge-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", @@ -916,6 +932,27 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/@commercetools/connect-payments-sdk/node_modules/winston": { + "version": "3.13.0", + "resolved": "https://registry.npmjs.org/winston/-/winston-3.13.0.tgz", + "integrity": "sha512-rwidmA1w3SE4j0E5MuIufFhyJPBDG7Nu71RkZor1p2+qHvJSZ9GYDA81AyleQcZbh/+V6HjeBdfnTZJm9rSeQQ==", + "dependencies": { + "@colors/colors": "^1.6.0", + "@dabh/diagnostics": "^2.0.2", + "async": "^3.2.3", + "is-stream": "^2.0.0", + "logform": "^2.4.0", + "one-time": "^1.0.0", + "readable-stream": "^3.4.0", + "safe-stable-stringify": "^2.3.1", + "stack-trace": "0.0.x", + "triple-beam": "^1.3.0", + "winston-transport": "^4.7.0" + }, + "engines": { + "node": ">= 12.0.0" + } + }, "node_modules/one-time": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/one-time/-/one-time-1.0.0.tgz", @@ -941,6 +978,11 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==" + }, "node_modules/@babel/helper-validator-identifier": { "version": "7.24.7", "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.7.tgz", @@ -1225,6 +1267,11 @@ "node": ">= 0.4" } }, + "node_modules/lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==" + }, "node_modules/jackspeak": { "version": "3.4.3", "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.3.tgz", @@ -1355,8 +1402,7 @@ "node_modules/@types/mime": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.5.tgz", - "integrity": "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==", - "dev": true + "integrity": "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==" }, "node_modules/shebang-regex": { "version": "3.0.0", @@ -1923,6 +1969,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==" + }, "node_modules/eslint-config-prettier": { "version": "9.1.0", "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz", @@ -2039,11 +2090,6 @@ "node": ">=0.10.0" } }, - "node_modules/color/node_modules/color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==" - }, "node_modules/jest-validate": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-validate/-/jest-validate-29.7.0.tgz", @@ -2100,18 +2146,6 @@ "integrity": "sha512-xiNMgCuoy4mCL4JTywk9XFs5xpRUcKxtWEcMR6FNMtsgewYTIgIR+nvlP4A4iRCAzRsHMnPhvTRrzp4AGcRTEA==", "dev": true }, - "node_modules/pkg-dir/node_modules/locate-path": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", - "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", - "dev": true, - "dependencies": { - "p-locate": "^4.1.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/update-browserslist-db": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.0.tgz", @@ -2237,15 +2271,6 @@ "node": ">=10" } }, - "node_modules/@istanbuljs/load-nyc-config/node_modules/argparse": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", - "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", - "dev": true, - "dependencies": { - "sprintf-js": "~1.0.2" - } - }, "node_modules/jest-cli": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-cli/-/jest-cli-29.7.0.tgz", @@ -2344,6 +2369,22 @@ "pend": "~1.2.0" } }, + "node_modules/@commercetools/connect-payments-sdk/node_modules/@commercetools-backend/loggers/node_modules/logform": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/logform/-/logform-2.6.0.tgz", + "integrity": "sha512-1ulHeNPp6k/LD8H91o7VYFBng5i1BDE7HoKxVbZiGFidS1Rj65qcywLxX+pVfAPoQJEjRdvKcusKwOupHCVOVQ==", + "dependencies": { + "@colors/colors": "1.6.0", + "@types/triple-beam": "^1.3.2", + "fecha": "^4.2.0", + "ms": "^2.1.1", + "safe-stable-stringify": "^2.3.1", + "triple-beam": "^1.3.0" + }, + "engines": { + "node": ">= 12.0.0" + } + }, "node_modules/@typescript-eslint/typescript-estree": { "version": "7.13.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.13.1.tgz", @@ -2494,6 +2535,23 @@ "node": ">=8" } }, + "node_modules/@commercetools/connect-payments-sdk/node_modules/@commercetools-backend/loggers": { + "version": "22.32.2", + "resolved": "https://registry.npmjs.org/@commercetools-backend/loggers/-/loggers-22.32.2.tgz", + "integrity": "sha512-z2AwV1PStfAUGnYNfJHIkV2NekSSHjIDWEVj44x2yDFIJDjgj7l3E094QKA95aZmDb6zEGEFdfJO3n+24iMHtg==", + "dependencies": { + "@babel/runtime": "^7.22.15", + "@babel/runtime-corejs3": "^7.22.15", + "@types/lodash": "^4.14.198", + "@types/triple-beam": "1.3.5", + "express-winston": "4.2.0", + "fast-safe-stringify": "2.1.1", + "lodash": "4.17.21", + "logform": "2.6.0", + "triple-beam": "1.4.1", + "winston": "3.13.0" + } + }, "node_modules/debug": { "version": "4.3.5", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.5.tgz", @@ -2613,6 +2671,22 @@ "dev": true, "optional": true }, + "node_modules/jwks-rsa": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/jwks-rsa/-/jwks-rsa-3.1.0.tgz", + "integrity": "sha512-v7nqlfezb9YfHHzYII3ef2a2j1XnGeSE/bK3WfumaYCqONAIstJbrEGapz4kadScZzEt7zYCN7bucj8C0Mv/Rg==", + "dependencies": { + "@types/express": "^4.17.17", + "@types/jsonwebtoken": "^9.0.2", + "debug": "^4.3.4", + "jose": "^4.14.6", + "limiter": "^1.1.5", + "lru-memoizer": "^2.2.0" + }, + "engines": { + "node": ">=14" + } + }, "node_modules/express-winston/node_modules/escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", @@ -2884,7 +2958,6 @@ "version": "4.17.21", "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.21.tgz", "integrity": "sha512-ejlPM315qwLpaQlQDTjPdsUFSc6ZsP4AN6AlWnogPjQ7CVi7PYF3YVz+CY3jE2pwYf7E/7HlDAN0rV2GxTG0HQ==", - "dev": true, "dependencies": { "@types/body-parser": "*", "@types/express-serve-static-core": "^4.17.33", @@ -3070,8 +3143,7 @@ "node_modules/@types/http-errors": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/@types/http-errors/-/http-errors-2.0.4.tgz", - "integrity": "sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA==", - "dev": true + "integrity": "sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA==" }, "node_modules/methods": { "version": "1.1.2", @@ -3175,6 +3247,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/@commercetools/connect-payments-sdk/node_modules/@colors/colors": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.6.0.tgz", + "integrity": "sha512-Ir+AOibqzrIsL6ajt3Rz3LskB7OiMVHqltZmspbW/TJuTVuyOMirVqAkjfY6JISiLHgyNqicAC8AyHHGzNd/dA==", + "engines": { + "node": ">=0.1.90" + } + }, "node_modules/gopd": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", @@ -3207,14 +3287,6 @@ "semver": "bin/semver.js" } }, - "node_modules/winston-transport/node_modules/@colors/colors": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.6.0.tgz", - "integrity": "sha512-Ir+AOibqzrIsL6ajt3Rz3LskB7OiMVHqltZmspbW/TJuTVuyOMirVqAkjfY6JISiLHgyNqicAC8AyHHGzNd/dA==", - "engines": { - "node": ">=0.1.90" - } - }, "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", @@ -3282,6 +3354,22 @@ "node": ">=0.4.0" } }, + "node_modules/@commercetools/connect-payments-sdk/node_modules/logform": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/logform/-/logform-2.6.1.tgz", + "integrity": "sha512-CdaO738xRapbKIMVn2m4F6KTj4j7ooJ8POVnebSgKo3KBz5axNXRAL7ZdRjIV6NOr2Uf4vjtRkxrFETOioCqSA==", + "dependencies": { + "@colors/colors": "1.6.0", + "@types/triple-beam": "^1.3.2", + "fecha": "^4.2.0", + "ms": "^2.1.1", + "safe-stable-stringify": "^2.3.1", + "triple-beam": "^1.3.0" + }, + "engines": { + "node": ">= 12.0.0" + } + }, "node_modules/@szmarczak/http-timer": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.6.tgz", @@ -3499,7 +3587,6 @@ "version": "4.19.5", "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.19.5.tgz", "integrity": "sha512-y6W03tvrACO72aijJ5uF02FRq5cgDR9lUxddQ8vyF+GvmjJQqbzDcJngEjURc+ZsG31VI3hODNZJ2URj86pzmg==", - "dev": true, "dependencies": { "@types/node": "*", "@types/qs": "*", @@ -3555,7 +3642,6 @@ "version": "1.15.7", "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.15.7.tgz", "integrity": "sha512-W8Ym+h8nhuRwaKPaDw34QUkwsGi6Rc4yYqvKFo5rm2FUEhCFbzVWrxXUxuKK8TASjWsysJY0nsmNCGhCOIsrOw==", - "dev": true, "dependencies": { "@types/http-errors": "*", "@types/node": "*", @@ -3571,6 +3657,11 @@ "node": ">=8" } }, + "node_modules/lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==" + }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -3964,7 +4055,6 @@ "version": "18.19.40", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.40.tgz", "integrity": "sha512-MIxieZHrm4Ee8XArBIc+Or9HINt2StOmCbgRcXGSJl8q14svRvkZPe7LJq9HKtTI1SK3wU8b91TjntUm7T69Pg==", - "dev": true, "dependencies": { "undici-types": "~5.26.4" } @@ -4074,11 +4164,15 @@ "node": ">= 0.6" } }, + "node_modules/lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==" + }, "node_modules/@types/qs": { "version": "6.9.15", "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.15.tgz", - "integrity": "sha512-uXHQKES6DQKKCLh441Xv/dwxOq1TVS3JPUMlEqoEglvlhR6Mxnlew/Xq/LRVHpLyk7iK3zODe1qYHIMltO7XGg==", - "dev": true + "integrity": "sha512-uXHQKES6DQKKCLh441Xv/dwxOq1TVS3JPUMlEqoEglvlhR6Mxnlew/Xq/LRVHpLyk7iK3zODe1qYHIMltO7XGg==" }, "node_modules/tsconfig-paths/node_modules/json5": { "version": "1.0.2", @@ -4222,6 +4316,14 @@ "node": ">=6.9.0" } }, + "node_modules/@types/jsonwebtoken": { + "version": "9.0.7", + "resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-9.0.7.tgz", + "integrity": "sha512-ugo316mmTYBl2g81zDFnZ7cfxlut3o+/EQdaP7J8QN2kY6lJ22hmQYCK5EHcJHbrW+dkCGSCPgbG8JtYj6qSrg==", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/flat-cache": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.2.0.tgz", @@ -4288,8 +4390,12 @@ "node_modules/lodash.clonedeep": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", - "integrity": "sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==", - "dev": true + "integrity": "sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==" + }, + "node_modules/buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==" }, "node_modules/@types/yargs": { "version": "17.0.32", @@ -4317,6 +4423,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/@commercetools/connect-payments-sdk/node_modules/@types/triple-beam": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/@types/triple-beam/-/triple-beam-1.3.5.tgz", + "integrity": "sha512-6WaYesThRMCl19iryMYP7/x2OVgCtbIVflDGFpWnb9irXI3UjYE4AzmYuiUKY1AJstGijoY+MgUszMgRxIYTYw==" + }, "node_modules/shell-quote": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.1.tgz", @@ -4375,6 +4486,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/ecdsa-sig-formatter": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", + "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", + "dependencies": { + "safe-buffer": "^5.0.1" + } + }, "node_modules/core-js-pure": { "version": "3.37.1", "resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.37.1.tgz", @@ -4548,6 +4667,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==" + }, "node_modules/walker": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/walker/-/walker-1.0.8.tgz", @@ -4596,11 +4720,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/express/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" - }, "node_modules/define-properties": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.1.tgz", @@ -4883,6 +5002,17 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, + "node_modules/lru-memoizer/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/path-key": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", @@ -4904,18 +5034,6 @@ "@babel/core": "^7.0.0-0" } }, - "node_modules/pkg-dir/node_modules/p-locate": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", - "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", - "dev": true, - "dependencies": { - "p-limit": "^2.2.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -5203,8 +5321,7 @@ "node_modules/@types/range-parser": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.7.tgz", - "integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==", - "dev": true + "integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==" }, "node_modules/json5": { "version": "2.2.3", @@ -5260,6 +5377,21 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@commercetools/ts-client": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@commercetools/ts-client/-/ts-client-2.0.5.tgz", + "integrity": "sha512-v1hdwMdyGV/ja+pdgTvnA/qLiZ67Zepbaj1WzucHa/ub9V78ZuezZTExTFKhSMFm5c+mMzLwq0UpacAYlu4nmA==", + "dependencies": { + "abort-controller": "3.0.0", + "async-mutex": "^0.5.0", + "buffer": "^6.0.3", + "node-fetch": "^2.6.1", + "uuid": "10.0.0" + }, + "engines": { + "node": ">=14" + } + }, "node_modules/@babel/helper-environment-visitor": { "version": "7.24.7", "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.24.7.tgz", @@ -5329,6 +5461,15 @@ "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.3.0.tgz", "integrity": "sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==" }, + "node_modules/lru-memoizer": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/lru-memoizer/-/lru-memoizer-2.3.0.tgz", + "integrity": "sha512-GXn7gyHAMhO13WSKrIiNfztwxodVsP8IoZ3XfrJV4yH2x0/OeTO/FIaAHTY5YekdGgW94njfuKmyyt1E0mR6Ug==", + "dependencies": { + "lodash.clonedeep": "^4.5.0", + "lru-cache": "6.0.0" + } + }, "node_modules/@nodelib/fs.stat": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", @@ -5452,7 +5593,6 @@ "version": "1.19.5", "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.5.tgz", "integrity": "sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg==", - "dev": true, "dependencies": { "@types/connect": "*", "@types/node": "*" @@ -5492,6 +5632,17 @@ "yallist": "^3.0.2" } }, + "node_modules/abort-controller": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", + "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "dependencies": { + "event-target-shim": "^5.0.0" + }, + "engines": { + "node": ">=6.5" + } + }, "node_modules/express/node_modules/cookie": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz", @@ -5554,6 +5705,15 @@ "node": ">= 6" } }, + "node_modules/jws": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz", + "integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==", + "dependencies": { + "jwa": "^1.4.1", + "safe-buffer": "^5.0.1" + } + }, "node_modules/supports-preserve-symlinks-flag": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", @@ -5780,7 +5940,6 @@ "version": "7.6.3", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", - "dev": true, "bin": { "semver": "bin/semver.js" }, @@ -5990,6 +6149,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/limiter": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/limiter/-/limiter-1.1.5.tgz", + "integrity": "sha512-FWWMIEOxz3GwUI4Ts/IvgVy6LPvoMPgjMdQ185nN6psJyBJ4yOpzqm695/h5umdLJg2vW3GR5iG11MAkR2AzJA==" + }, "node_modules/eslint-plugin-import/node_modules/doctrine": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", @@ -6082,6 +6246,11 @@ "integrity": "sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==", "dev": true }, + "node_modules/async-mutex/node_modules/tslib": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", + "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==" + }, "node_modules/@babel/runtime": { "version": "7.24.8", "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.24.8.tgz", @@ -6490,6 +6659,11 @@ "node": ">=4" } }, + "node_modules/lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==" + }, "node_modules/jest-junit": { "version": "16.0.0", "resolved": "https://registry.npmjs.org/jest-junit/-/jest-junit-16.0.0.tgz", @@ -6579,6 +6753,27 @@ "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==", "dev": true }, + "node_modules/jsonwebtoken": { + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.2.tgz", + "integrity": "sha512-PRp66vJ865SSqOlgqS8hujT5U4AOgMfhrwYIuIhfKaoSCZcirrmASQr8CX7cUg+RMih+hgznrjp99o+W4pJLHQ==", + "dependencies": { + "jws": "^3.2.2", + "lodash.includes": "^4.3.0", + "lodash.isboolean": "^3.0.3", + "lodash.isinteger": "^4.0.4", + "lodash.isnumber": "^3.0.3", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.once": "^4.0.0", + "ms": "^2.1.1", + "semver": "^7.5.4" + }, + "engines": { + "node": ">=12", + "npm": ">=6" + } + }, "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -6591,21 +6786,6 @@ "node": ">= 0.6" } }, - "node_modules/pkg-dir/node_modules/p-limit": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", - "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", - "dev": true, - "dependencies": { - "p-try": "^2.0.0" - }, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/ngrok": { "version": "5.0.0-beta.2", "resolved": "https://registry.npmjs.org/ngrok/-/ngrok-5.0.0-beta.2.tgz", @@ -6651,6 +6831,14 @@ "node": ">= 0.8" } }, + "node_modules/jose": { + "version": "4.15.9", + "resolved": "https://registry.npmjs.org/jose/-/jose-4.15.9.tgz", + "integrity": "sha512-1vUQX+IdDMVPj4k8kOxgUqlcK518yluMuGZwqlr44FS1ppZB/5GWh4rZG89erpOBOJjU/OBsnCVFfapsRz6nEA==", + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, "node_modules/is-generator-fn": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-generator-fn/-/is-generator-fn-2.1.0.tgz", @@ -6942,6 +7130,20 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/@commercetools/connect-payments-sdk": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/@commercetools/connect-payments-sdk/-/connect-payments-sdk-0.10.0.tgz", + "integrity": "sha512-WLOF3nK1ppipiYkNXdKOAL8eS5WHMkgVBrEocKpZR4JlQyTkXXApVUb1La/evB7MlDuba1tt/YBhQwwRhyJSQw==", + "dependencies": { + "@commercetools-backend/loggers": "22.32.2", + "@commercetools/platform-sdk": "7.14.0", + "@commercetools/sdk-client-v2": "2.5.0", + "jsonwebtoken": "9.0.2", + "jwks-rsa": "3.1.0", + "lodash": "4.17.21", + "logform": "2.6.1" + } + }, "node_modules/nodemon/node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -7069,7 +7271,6 @@ "version": "3.4.38", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", "integrity": "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==", - "dev": true, "dependencies": { "@types/node": "*" } @@ -7401,6 +7602,11 @@ "node": ">= 0.8" } }, + "node_modules/@types/lodash": { + "version": "4.17.10", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.10.tgz", + "integrity": "sha512-YpS0zzoduEhuOWjAotS6A5AVCva7X4lVlYLF0FYHAY9sdraBfnatttHItlWeZdGhuEkf+OzMNg2ZYAx8t+52uQ==" + }, "node_modules/@babel/helper-validator-option": { "version": "7.24.8", "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.24.8.tgz", @@ -7521,6 +7727,14 @@ "node": ">= 0.6" } }, + "node_modules/event-target-shim": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", + "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", + "engines": { + "node": ">=6" + } + }, "node_modules/micromatch": { "version": "4.0.7", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.7.tgz", @@ -7766,12 +7980,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/sprintf-js": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==", - "dev": true - }, "node_modules/supports-color": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", @@ -8204,6 +8412,21 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/@commercetools/connect-payments-sdk/node_modules/@commercetools/platform-sdk": { + "version": "7.14.0", + "resolved": "https://registry.npmjs.org/@commercetools/platform-sdk/-/platform-sdk-7.14.0.tgz", + "integrity": "sha512-08/7yAxZFa6s5iKWw+67x17wa4pqiG8WHAW3dECWhkMpTME65qTHz5eyDfcCq8Tayo1rp46g67/2mWxrqapRAA==", + "dependencies": { + "@commercetools/sdk-client-v2": "^2.5.0", + "@commercetools/sdk-middleware-auth": "^7.0.0", + "@commercetools/sdk-middleware-http": "^7.0.0", + "@commercetools/sdk-middleware-logger": "^3.0.0", + "@commercetools/ts-client": "^2.0.5" + }, + "engines": { + "node": ">=14" + } + }, "node_modules/jest-haste-map": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-haste-map/-/jest-haste-map-29.7.0.tgz", @@ -8492,8 +8715,7 @@ "node_modules/undici-types": { "version": "5.26.5", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", - "dev": true + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" }, "node_modules/string.prototype.trimend": { "version": "1.0.8", @@ -8759,6 +8981,14 @@ } } }, + "node_modules/async-mutex": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/async-mutex/-/async-mutex-0.5.0.tgz", + "integrity": "sha512-1A94B18jkJ3DYq284ohPxoXbfTA5HsQ7/Mf4DEhcyLx3Bz27Rh59iScbB6EPiP+B+joue6YCxcMXSbFC1tZKwA==", + "dependencies": { + "tslib": "^2.4.0" + } + }, "node_modules/string-length": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/string-length/-/string-length-4.0.2.tgz", @@ -8784,7 +9014,6 @@ "version": "0.17.4", "resolved": "https://registry.npmjs.org/@types/send/-/send-0.17.4.tgz", "integrity": "sha512-x2EM6TJOybec7c52BX0ZspPodMsQUd5L6PRwOunVyVUhXiBSKf3AezDL8Dgvgt5o0UfKNfuA0eMLr2wLT4AiBA==", - "dev": true, "dependencies": { "@types/mime": "^1", "@types/node": "*" @@ -8924,4 +9153,4 @@ } } } -} +} \ No newline at end of file diff --git a/processor/package.json b/processor/package.json index 98e4a1d..77ae64f 100644 --- a/processor/package.json +++ b/processor/package.json @@ -1,7 +1,7 @@ { "name": "shopmacher-mollie-processor", "description": "Integration between commercetools and mollie payment service provider", - "version": "1.0.2", + "version": "1.0.3", "main": "index.js", "private": true, "scripts": { @@ -62,6 +62,7 @@ "dependencies": { "@commercetools-backend/loggers": "^21.25.2", "@commercetools/platform-sdk": "^4.11.0", + "@commercetools/connect-payments-sdk": "^0.10.0", "@commercetools/sdk-client-v2": "^2.5.0", "@mollie/api-client": "^3.7.0", "@types/uuid": "^10.0.0", diff --git a/processor/src/commercetools/extensions.commercetools.ts b/processor/src/commercetools/extensions.commercetools.ts index 31ec4c7..6331d47 100644 --- a/processor/src/commercetools/extensions.commercetools.ts +++ b/processor/src/commercetools/extensions.commercetools.ts @@ -20,6 +20,10 @@ export async function createPaymentExtension(applicationUrl: string): Promise { + await paymentSdk.jwtAuthHookFn + .authenticate()(req) + .then(() => next()) + .catch(() => { + res.status(403).send('Access denied: You do not have the necessary permissions to access this resource.'); + }); +}; diff --git a/processor/src/routes/processor.route.ts b/processor/src/routes/processor.route.ts index 8af5427..a0fecd2 100644 --- a/processor/src/routes/processor.route.ts +++ b/processor/src/routes/processor.route.ts @@ -1,17 +1,24 @@ import { Router } from 'express'; import { post } from '../controllers/processor.controller'; import { install, healthCheck, uninstall, mollieStatus } from '../controllers/connector.controller'; +import { readConfiguration } from '../utils/config.utils'; +import { jwtMiddleware } from '../middleware/jwt.middleware'; const serviceRouter = Router(); - -serviceRouter.post('/', post); +const AUTH_MODE = readConfiguration().commerceTools.authMode === '1'; serviceRouter.get('/health-check', healthCheck); serviceRouter.get('/mollie/status', mollieStatus); -serviceRouter.post('/install', install); - -serviceRouter.post('/uninstall', uninstall); +if (AUTH_MODE) { + serviceRouter.post('/', jwtMiddleware, post); + serviceRouter.post('/install', jwtMiddleware, install); + serviceRouter.post('/uninstall', jwtMiddleware, uninstall); +} else { + serviceRouter.post('/', post); + serviceRouter.post('/install', install); + serviceRouter.post('/uninstall', uninstall); +} export default serviceRouter; diff --git a/processor/src/sdk/payment.sdk.ts b/processor/src/sdk/payment.sdk.ts new file mode 100644 index 0000000..7cbf238 --- /dev/null +++ b/processor/src/sdk/payment.sdk.ts @@ -0,0 +1,22 @@ +import { readConfiguration } from '../utils/config.utils'; +import { RequestContextData, setupPaymentSDK } from '@commercetools/connect-payments-sdk'; + +const config = readConfiguration().commerceTools; + +export const paymentSdk = setupPaymentSDK({ + projectKey: config.projectKey, + clientId: config.clientId, + clientSecret: config.clientId, + authUrl: `https://auth.${config.region}.commercetools.com`, + apiUrl: `https://api.${config.region}.commercetools.com`, + sessionUrl: `https://session.${config.region}.commercetools.com`, + jwksUrl: `https://mc-api.${config.region}.commercetools.com/.well-known/jwks.json`, + jwtIssuer: `https://mc-api.${config.region}.commercetools.com`, + getContextFn: (): RequestContextData => { + return { + correlationId: '', + requestId: '', + }; + }, + updateContextFn: () => {}, +}); diff --git a/processor/src/types/index.types.ts b/processor/src/types/index.types.ts index 49c0ce2..f435a68 100644 --- a/processor/src/types/index.types.ts +++ b/processor/src/types/index.types.ts @@ -21,6 +21,7 @@ export type ConnectorEnvVars = { projectKey: string; scope: string; region: string; + authMode: string; }; mollie: { testApiKey: string; diff --git a/processor/src/utils/config.utils.ts b/processor/src/utils/config.utils.ts index 828230e..515271f 100644 --- a/processor/src/utils/config.utils.ts +++ b/processor/src/utils/config.utils.ts @@ -16,6 +16,7 @@ export const readConfiguration = () => { projectKey: process.env.CTP_PROJECT_KEY as string, scope: process.env.CTP_SCOPE as string, region: process.env.CTP_REGION as string, + authMode: process.env.CTP_AUTHENTICATION_MODE as string, }, mollie: { testApiKey: process.env.MOLLIE_API_TEST_KEY as string, diff --git a/processor/src/validators/env.validators.ts b/processor/src/validators/env.validators.ts index 3d4e434..d0cc9f1 100644 --- a/processor/src/validators/env.validators.ts +++ b/processor/src/validators/env.validators.ts @@ -108,6 +108,19 @@ const envValidators = [ 'Bank transfer due date must be from 1d to 100d, the number must be an integer. If it was not set, the default will be 14d', referencedBy: 'environmentVariables', }), + + standardString( + ['commerceTools', 'authMode'], + { + code: 'InvalidAuthMode', + message: 'AuthMode should be a valid string of either "0" or "1".', + referencedBy: 'environmentVariables', + }, + { + min: 1, + max: 1, + }, + ), ]; export default envValidators; diff --git a/processor/tests/commercetools/extension.commercetools.spec.ts b/processor/tests/commercetools/extension.commercetools.spec.ts index a1f99ed..09ee528 100644 --- a/processor/tests/commercetools/extension.commercetools.spec.ts +++ b/processor/tests/commercetools/extension.commercetools.spec.ts @@ -27,6 +27,10 @@ describe('Test extension.commercetools', () => { destination: { type: 'HTTP', url: mockUrl, + authentication: { + type: 'AuthorizationHeader', + headerValue: 'Bearer _token_', + }, }, triggers: [ { @@ -184,6 +188,10 @@ describe('Test extension.commercetools', () => { destination: { type: 'HTTP', url: mockUrl, + authentication: { + type: 'AuthorizationHeader', + headerValue: 'Bearer _token_', + }, }, triggers: [ { @@ -215,6 +223,10 @@ describe('Test extension.commercetools', () => { destination: { type: 'HTTP', url: mockUrl, + authentication: { + type: 'AuthorizationHeader', + headerValue: 'Bearer _token_', + }, }, triggers: [ { diff --git a/processor/tests/utils/config.utils.spec.ts b/processor/tests/utils/config.utils.spec.ts index e7ff99f..94ac196 100644 --- a/processor/tests/utils/config.utils.spec.ts +++ b/processor/tests/utils/config.utils.spec.ts @@ -12,6 +12,7 @@ describe('Test src/utils/config.utils.ts', () => { projectKey: process.env.CTP_PROJECT_KEY, scope: process.env.CTP_SCOPE, region: process.env.CTP_REGION, + authMode: process.env.CTP_AUTHENTICATION_MODE, }, mollie: { liveApiKey: process.env.MOLLIE_API_LIVE_KEY, @@ -79,4 +80,9 @@ describe('Test src/utils/config.utils.ts', () => { process.env.MOLLIE_BANK_TRANSFER_DUE_DATE = 'dummy'; expect(() => readConfiguration()).toThrow(CustomError); }); + + test('should throw an error when CTP_AUTHENTICATION_MODE is invalid', () => { + process.env.CTP_AUTHENTICATION_MODE = 'dummy'; + expect(() => readConfiguration()).toThrow(CustomError); + }); }); diff --git a/processor/tests/validators/env.validators.spec.ts b/processor/tests/validators/env.validators.spec.ts index 4dcdfa7..8a1f848 100644 --- a/processor/tests/validators/env.validators.spec.ts +++ b/processor/tests/validators/env.validators.spec.ts @@ -135,6 +135,30 @@ describe('Test env.validators.ts', () => { }, condition: { min: 1, max: 4 }, }, + { + index1: 11, + index2: 0, + field1: 'mollie', + field2: 'bankTransferDueDate', + error: { + code: 'InvalidBankTransferDueDate', + message: + 'Bank transfer due date must be from 1d to 100d, the number must be an integer. If it was not set, the default will be 14d', + referencedBy: 'environmentVariables', + }, + }, + { + index1: 12, + index2: 0, + field1: 'commerceTools', + field2: 'authMode', + error: { + code: 'InvalidAuthMode', + message: 'AuthMode should be a valid string of either "0" or "1".', + referencedBy: 'environmentVariables', + }, + condition: { min: 1, max: 1 }, + }, ])( 'should return the correct validation array contains [%s, %s]', async ({ index1, index2, field1, field2, error, condition }) => { diff --git a/processor/tests/validators/helpers.validators.spec.ts b/processor/tests/validators/helpers.validators.spec.ts index 8ee84bf..4071461 100644 --- a/processor/tests/validators/helpers.validators.spec.ts +++ b/processor/tests/validators/helpers.validators.spec.ts @@ -255,6 +255,7 @@ describe('Test helpers.validators.ts', () => { projectKey: process.env.CTP_PROJECT_KEY as string, scope: process.env.CTP_SCOPE as string, region: process.env.CTP_REGION as string, + authMode: process.env.CTP_AUTHENTICATION_MODE as string, }, mollie: { liveApiKey: process.env.MOLLIE_API_LIVE_KEY as string, @@ -279,6 +280,7 @@ describe('Test helpers.validators.ts', () => { projectKey: process.env.CTP_PROJECT_KEY as string, scope: process.env.CTP_SCOPE as string, region: process.env.CTP_REGION as string, + authMode: process.env.CTP_AUTHENTICATION_MODE as string, }, mollie: { liveApiKey: process.env.MOLLIE_API_LIVE_KEY as string, @@ -343,6 +345,7 @@ describe('test getValidateMessages', () => { projectKey: process.env.CTP_PROJECT_KEY as string, scope: process.env.CTP_SCOPE as string, region: process.env.CTP_REGION as string, + authMode: process.env.CTP_AUTHENTICATION_MODE as string, }, mollie: { testApiKey: process.env.MOLLIE_API_TEST_KEY as string, @@ -375,6 +378,7 @@ describe('test getValidateMessages', () => { projectKey: process.env.CTP_PROJECT_KEY as string, scope: process.env.CTP_SCOPE as string, region: process.env.CTP_REGION as string, + authMode: process.env.CTP_AUTHENTICATION_MODE as string, }, mollie: { testApiKey: process.env.MOLLIE_API_TEST_KEY as string, @@ -407,6 +411,7 @@ describe('test getValidateMessages', () => { projectKey: process.env.CTP_PROJECT_KEY as string, scope: process.env.CTP_SCOPE as string, region: process.env.CTP_REGION as string, + authMode: process.env.CTP_AUTHENTICATION_MODE as string, }, mollie: { testApiKey: process.env.MOLLIE_API_TEST_KEY as string,