diff --git a/.ncurc.js b/.ncurc.js new file mode 100644 index 0000000..9b02b1c --- /dev/null +++ b/.ncurc.js @@ -0,0 +1,15 @@ +module.exports = { + reject: [ + 'pnpm' + ], + filterResults: (name, { upgradedVersionSemver }) => { + if ( + name === '@types/node' && parseInt(upgradedVersionSemver?.major) >= 22 || + name === 'eslint' && parseInt(upgradedVersionSemver?.major) >= 9 + ) { + return false + } + + return true + } +} diff --git a/examples/bun/bun.lockb b/examples/bun/bun.lockb index b76637d..cf8ed5e 100755 Binary files a/examples/bun/bun.lockb and b/examples/bun/bun.lockb differ diff --git a/examples/bun/index.ts b/examples/bun/index.ts index cf79568..791785e 100644 --- a/examples/bun/index.ts +++ b/examples/bun/index.ts @@ -1,4 +1,4 @@ -import { authenticate, AuthenticateOptions, GrantType, jwtVerify } from '@commercelayer/js-auth' +import { authenticate, AuthenticateOptions, getCoreApiBaseEndpoint, GrantType, jwtVerify } from '@commercelayer/js-auth' const grantType: GrantType = 'client_credentials' @@ -15,4 +15,5 @@ const decodedJWT = await jwtVerify(auth.accessToken) if ('organization' in decodedJWT.payload) { console.log('organization slug is', decodedJWT.payload.organization.slug) + console.log('base endpoint is', getCoreApiBaseEndpoint(auth.accessToken)) } diff --git a/examples/cjs/index.js b/examples/cjs/index.js index 06b72c5..d4e236f 100644 --- a/examples/cjs/index.js +++ b/examples/cjs/index.js @@ -1,6 +1,6 @@ // @ts-check -const { authenticate, jwtVerify, jwtIsSalesChannel } = require('@commercelayer/js-auth') +const { authenticate, jwtVerify, jwtIsSalesChannel, getCoreApiBaseEndpoint } = require('@commercelayer/js-auth') async function run() { const auth = await authenticate('client_credentials', { @@ -14,6 +14,7 @@ async function run() { if (jwtIsSalesChannel(decodedJWT.payload)) { console.log('organization slug is', decodedJWT.payload.organization.slug) + console.log('base endpoint is', getCoreApiBaseEndpoint(auth.accessToken)) } } diff --git a/examples/cjs/pnpm-lock.yaml b/examples/cjs/pnpm-lock.yaml index a2a13a4..6fef533 100644 --- a/examples/cjs/pnpm-lock.yaml +++ b/examples/cjs/pnpm-lock.yaml @@ -25,10 +25,10 @@ importers: version: 9.0.2 tsup: specifier: ^8.2.4 - version: 8.2.4(postcss@8.4.38)(typescript@5.5.4) + version: 8.2.4(postcss@8.4.38)(typescript@5.6.2) typescript: - specifier: ^5.5.4 - version: 5.5.4 + specifier: ^5.6.2 + version: 5.6.2 vitest: specifier: ^2.0.5 version: 2.0.5(@types/node@20.14.9) @@ -1141,8 +1141,8 @@ packages: typescript: optional: true - typescript@5.5.4: - resolution: {integrity: sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==} + typescript@5.6.2: + resolution: {integrity: sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==} engines: {node: '>=14.17'} hasBin: true @@ -2150,7 +2150,7 @@ snapshots: ts-interface-checker@0.1.13: {} - tsup@8.2.4(postcss@8.4.38)(typescript@5.5.4): + tsup@8.2.4(postcss@8.4.38)(typescript@5.6.2): dependencies: bundle-require: 5.0.0(esbuild@0.23.1) cac: 6.7.14 @@ -2170,14 +2170,14 @@ snapshots: tree-kill: 1.2.2 optionalDependencies: postcss: 8.4.38 - typescript: 5.5.4 + typescript: 5.6.2 transitivePeerDependencies: - jiti - supports-color - tsx - yaml - typescript@5.5.4: {} + typescript@5.6.2: {} undici-types@5.26.5: {} diff --git a/examples/cloudflare-workers/package.json b/examples/cloudflare-workers/package.json index 5be2f1d..83200c7 100644 --- a/examples/cloudflare-workers/package.json +++ b/examples/cloudflare-workers/package.json @@ -12,10 +12,10 @@ "@commercelayer/js-auth": "workspace:*" }, "devDependencies": { - "@cloudflare/vitest-pool-workers": "^0.4.23", - "@cloudflare/workers-types": "^4.20240815.0", - "typescript": "^5.5.4", + "@cloudflare/vitest-pool-workers": "^0.4.29", + "@cloudflare/workers-types": "^4.20240909.0", + "typescript": "^5.6.2", "vitest": "2.0.5", - "wrangler": "^3.72.0" + "wrangler": "^3.75.0" } } diff --git a/examples/cloudflare-workers/pnpm-lock.yaml b/examples/cloudflare-workers/pnpm-lock.yaml index e43c6d5..6ea68f3 100644 --- a/examples/cloudflare-workers/pnpm-lock.yaml +++ b/examples/cloudflare-workers/pnpm-lock.yaml @@ -13,20 +13,20 @@ importers: version: link:../../packages/js-auth devDependencies: '@cloudflare/vitest-pool-workers': - specifier: ^0.4.23 - version: 0.4.23(@cloudflare/workers-types@4.20240815.0)(@vitest/runner@2.0.5)(@vitest/snapshot@2.0.5)(vitest@2.0.5(@types/node@20.14.9)) + specifier: ^0.4.29 + version: 0.4.29(@cloudflare/workers-types@4.20240909.0)(@vitest/runner@2.0.5)(@vitest/snapshot@2.0.5)(vitest@2.0.5(@types/node@20.14.9)) '@cloudflare/workers-types': - specifier: ^4.20240815.0 - version: 4.20240815.0 + specifier: ^4.20240909.0 + version: 4.20240909.0 typescript: - specifier: ^5.5.4 - version: 5.5.4 + specifier: ^5.6.2 + version: 5.6.2 vitest: specifier: 2.0.5 version: 2.0.5(@types/node@20.14.9) wrangler: - specifier: ^3.72.0 - version: 3.72.0(@cloudflare/workers-types@4.20240815.0) + specifier: ^3.75.0 + version: 3.75.0(@cloudflare/workers-types@4.20240909.0) ../../packages/js-auth: devDependencies: @@ -41,10 +41,10 @@ importers: version: 9.0.2 tsup: specifier: ^8.2.4 - version: 8.2.4(postcss@8.4.38)(typescript@5.5.4) + version: 8.2.4(postcss@8.4.38)(typescript@5.6.2) typescript: - specifier: ^5.5.4 - version: 5.5.4 + specifier: ^5.6.2 + version: 5.6.2 vitest: specifier: ^2.0.5 version: 2.0.5(@types/node@20.14.9) @@ -62,49 +62,49 @@ packages: resolution: {integrity: sha512-YLPHc8yASwjNkmcDMQMY35yiWjoKAKnhUbPRszBRS0YgH+IXtsMp61j+yTcnCE3oO2DgP0U3iejLC8FTtKDC8Q==} engines: {node: '>=16.13'} - '@cloudflare/vitest-pool-workers@0.4.23': - resolution: {integrity: sha512-oRRnotzP75mNITQvAURuok1ti9P7XEpy/E7KxSMaXa4A6ltOgTHbWG9dpdxY/dU0o7RgHP4ixNOn5DY4Cf4T1Q==} + '@cloudflare/vitest-pool-workers@0.4.29': + resolution: {integrity: sha512-bfZ6+1nLV6agn9a2K75xIDGF52/aVmOvzveAx7kbahSDIS7PR4xXd+PkGlOuvD0Bh3Y3eLR+JCzalL0kEwdSWg==} peerDependencies: '@vitest/runner': 1.3.x - 1.5.x '@vitest/snapshot': 1.3.x - 1.5.x vitest: 1.3.x - 1.5.x - '@cloudflare/workerd-darwin-64@1.20240806.0': - resolution: {integrity: sha512-FqcVBBCO//I39K5F+HqE/v+UkqY1UrRnS653Jv+XsNNH9TpX5fTs7VCKG4kDSnmxlAaKttyIN5sMEt7lpuNExQ==} + '@cloudflare/workerd-darwin-64@1.20240821.1': + resolution: {integrity: sha512-CDBpfZKrSy4YrIdqS84z67r3Tzal2pOhjCsIb63IuCnvVes59/ft1qhczBzk9EffeOE2iTCrA4YBT7Sbn7USew==} engines: {node: '>=16'} cpu: [x64] os: [darwin] - '@cloudflare/workerd-darwin-arm64@1.20240806.0': - resolution: {integrity: sha512-8c3KvmzYp/wg+82KHSOzDetJK+pThH4MTrU1OsjmsR2cUfedm5dk5Lah9/0Ld68+6A0umFACi4W2xJHs/RoBpA==} + '@cloudflare/workerd-darwin-arm64@1.20240821.1': + resolution: {integrity: sha512-Q+9RedvNbPcEt/dKni1oN94OxbvuNAeJkgHmrLFTGF8zu21wzOhVkQeRNxcYxrMa9mfStc457NAg13OVCj2kHQ==} engines: {node: '>=16'} cpu: [arm64] os: [darwin] - '@cloudflare/workerd-linux-64@1.20240806.0': - resolution: {integrity: sha512-/149Bpxw4e2p5QqnBc06g0mx+4sZYh9j0doilnt0wk/uqYkLp0DdXGMQVRB74sBLg2UD3wW8amn1w3KyFhK2tQ==} + '@cloudflare/workerd-linux-64@1.20240821.1': + resolution: {integrity: sha512-j6z3KsPtawrscoLuP985LbqFrmsJL6q1mvSXOXTqXGODAHIzGBipHARdOjms3UQqovzvqB2lQaQsZtLBwCZxtA==} engines: {node: '>=16'} cpu: [x64] os: [linux] - '@cloudflare/workerd-linux-arm64@1.20240806.0': - resolution: {integrity: sha512-lacDWY3S1rKL/xT6iMtTQJEKmTTKrBavPczInEuBFXElmrS6IwVjZwv8hhVm32piyNt/AuFu9BYoJALi9D85/g==} + '@cloudflare/workerd-linux-arm64@1.20240821.1': + resolution: {integrity: sha512-I9bHgZOxJQW0CV5gTdilyxzTG7ILzbTirehQWgfPx9X77E/7eIbR9sboOMgyeC69W4he0SKtpx0sYZuTJu4ERw==} engines: {node: '>=16'} cpu: [arm64] os: [linux] - '@cloudflare/workerd-windows-64@1.20240806.0': - resolution: {integrity: sha512-hC6JEfTSQK6//Lg+D54TLVn1ceTPY+fv4MXqDZIYlPP53iN+dL8Xd0utn2SG57UYdlL5FRAhm/EWHcATZg1RgA==} + '@cloudflare/workerd-windows-64@1.20240821.1': + resolution: {integrity: sha512-keC97QPArs6LWbPejQM7/Y8Jy8QqyaZow4/ZdsGo+QjlOLiZRDpAenfZx3CBUoWwEeFwQTl2FLO+8hV1SWFFYw==} engines: {node: '>=16'} cpu: [x64] os: [win32] - '@cloudflare/workers-shared@0.2.0': - resolution: {integrity: sha512-tIWLooWkBMuoKRk72lr6YrEtVlVdUTtAGVmPOnUroMrnri/9YLx+mVawL0/egDgSGmPbmvkdBFsUGRuI+aZmxg==} + '@cloudflare/workers-shared@0.4.1': + resolution: {integrity: sha512-nYh4r8JwOOjYIdH2zub++CmIKlkYFlpxI1nBHimoiHcytJXD/b7ldJ21TtfzUZMCgI78mxVlymMHA/ReaOxKlA==} engines: {node: '>=16.7.0'} - '@cloudflare/workers-types@4.20240815.0': - resolution: {integrity: sha512-H/IXCOahT1lr4RKzsiCkyjM7+LCPLtl2wjxyLG8xMTNERR0XuD1Vcfns6TraE0cd5+IcKe7j3rpzBlSCjZ+61A==} + '@cloudflare/workers-types@4.20240909.0': + resolution: {integrity: sha512-4knwtX6efxIsIxawdmPyynU9+S8A78wntU8eUIEldStWP4gNgxGkeWcfCMXulTx8oxr3DU4aevHyld9HGV8VKQ==} '@cspotcode/source-map-support@0.8.1': resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==} @@ -895,15 +895,6 @@ packages: date-fns@3.6.0: resolution: {integrity: sha512-fRHTG8g/Gif+kSh50gaGEdToemgfj74aRX3swtiouboip5JDLAyDE9F11nHMIcvOaXeOC6D7SpNhi7uFyB7Uww==} - debug@4.3.4: - resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} - engines: {node: '>=6.0'} - peerDependencies: - supports-color: '*' - peerDependenciesMeta: - supports-color: - optional: true - debug@4.3.6: resolution: {integrity: sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==} engines: {node: '>=6.0'} @@ -1173,8 +1164,8 @@ packages: resolution: {integrity: sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==} engines: {node: '>=12'} - miniflare@3.20240806.1: - resolution: {integrity: sha512-wJq3YQYx9k83L2CNYtxvwWvXSi+uHrC6aFoXYSbzhxIDlUWvMEqippj+3HeKLgsggC31nHJab3b1Pifg9IxIFQ==} + miniflare@3.20240821.1: + resolution: {integrity: sha512-81qdiryDG7VXzZuoa0EwhkaIYYrn7+StRIrd/2i7SPqPUNICUBjbhFFKqTnvE1+fqIPPB6l8ShKFaFvmnZOASg==} engines: {node: '>=16.13'} hasBin: true @@ -1204,9 +1195,6 @@ packages: engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} hasBin: true - node-fetch-native@1.6.4: - resolution: {integrity: sha512-IhOigYzAKHd244OC0JIMIUrjzctirCmPkaIfhDeGcEETWof5zKYUW7e7MYvChGWh/4CJeXEgsRyGzuF334rOOQ==} - node-fetch@2.7.0: resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==} engines: {node: 4.x || >=6.0.0} @@ -1236,6 +1224,9 @@ packages: resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==} engines: {node: '>=0.10.0'} + ohash@1.1.3: + resolution: {integrity: sha512-zuHHiGTYTA1sYJ/wZN+t5HKZaH23i4yI1HMwbuXm24Nid7Dv0KcuRlKoNKS9UNfAVSBlnGLcuQrnOKWOZoEGaw==} + onetime@5.1.2: resolution: {integrity: sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==} engines: {node: '>=6'} @@ -1521,13 +1512,13 @@ packages: typescript: optional: true - typescript@5.5.4: - resolution: {integrity: sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==} + typescript@5.6.2: + resolution: {integrity: sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==} engines: {node: '>=14.17'} hasBin: true - ufo@1.5.3: - resolution: {integrity: sha512-Y7HYmWaFwPUmkoQCUIAYpKqkOf+SbVj/2fJJZ4RJMCfZp0rTGwRbzQD+HghfnhKOjL9E01okqz+ncJskGYfBNw==} + ufo@1.5.4: + resolution: {integrity: sha512-UsUk3byDzKd04EyoZ7U4DOlxQaD14JUKQl6/P7wiX4FNvUfm3XL246n9W5AmqwW5RSFJ27NAuM0iLscAOYUiGQ==} undici-types@5.26.5: resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} @@ -1536,8 +1527,8 @@ packages: resolution: {integrity: sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==} engines: {node: '>=14.0'} - unenv-nightly@1.10.0-1717606461.a117952: - resolution: {integrity: sha512-u3TfBX02WzbHTpaEfWEKwDijDSFAHcgXkayUZ+MVDrjhLFvgAJzFGTSTmwlEhwWi2exyRQey23ah9wELMM6etg==} + unenv-nightly@2.0.0-1724863496.70db6f1: + resolution: {integrity: sha512-r+VIl1gnsI4WQxluruSQhy8alpAf1AsLRLm4sEKp3otCyTIVD6I6wHEYzeQnwsyWgaD4+3BD4A/eqrgOpdTzhw==} vite-node@2.0.5: resolution: {integrity: sha512-LdsW4pxj0Ot69FAoXZ1yTnA9bjGohr2yNBU7QKRxpz8ITSkhuDl6h3zS/tvgz4qrNjeRnvrWeXQ8ZF7Um4W00Q==} @@ -1625,17 +1616,17 @@ packages: engines: {node: '>=8'} hasBin: true - workerd@1.20240806.0: - resolution: {integrity: sha512-yyNtyzTMgVY0sgYijHBONqZFVXsOFGj2jDjS8MF/RbO2ZdGROvs4Hkc/9QnmqFWahE0STxXeJ1yW1yVotdF0UQ==} + workerd@1.20240821.1: + resolution: {integrity: sha512-y4phjCnEG96u8ZkgkkHB+gSw0i6uMNo23rBmixylWpjxDklB+LWD8dztasvsu7xGaZbLoTxQESdEw956F7VJDA==} engines: {node: '>=16'} hasBin: true - wrangler@3.72.0: - resolution: {integrity: sha512-9sryHTCtCj48vUC5y/M3Dsx02U1bT6mK9E41TXBCpSJgWh8UvWG/xgmu2dY93Mqj9aJIvK/kwwIBRlNFRwF7Hw==} + wrangler@3.75.0: + resolution: {integrity: sha512-CitNuNj0O1z6qbonUXmpUbxeWpU3nx28Kc4ZT33tMdeooQssb063Ie7+ZCdfS3kPhRHSwGdtOV22xFYytHON8w==} engines: {node: '>=16.17.0'} hasBin: true peerDependencies: - '@cloudflare/workers-types': ^4.20240806.0 + '@cloudflare/workers-types': ^4.20240821.1 peerDependenciesMeta: '@cloudflare/workers-types': optional: true @@ -1683,7 +1674,7 @@ snapshots: dependencies: mime: 3.0.0 - '@cloudflare/vitest-pool-workers@0.4.23(@cloudflare/workers-types@4.20240815.0)(@vitest/runner@2.0.5)(@vitest/snapshot@2.0.5)(vitest@2.0.5(@types/node@20.14.9))': + '@cloudflare/vitest-pool-workers@0.4.29(@cloudflare/workers-types@4.20240909.0)(@vitest/runner@2.0.5)(@vitest/snapshot@2.0.5)(vitest@2.0.5(@types/node@20.14.9))': dependencies: '@vitest/runner': 2.0.5 '@vitest/snapshot': 2.0.5 @@ -1691,10 +1682,10 @@ snapshots: cjs-module-lexer: 1.3.1 devalue: 4.3.3 esbuild: 0.17.19 - miniflare: 3.20240806.1 + miniflare: 3.20240821.1 semver: 7.6.2 vitest: 2.0.5(@types/node@20.14.9) - wrangler: 3.72.0(@cloudflare/workers-types@4.20240815.0) + wrangler: 3.75.0(@cloudflare/workers-types@4.20240909.0) zod: 3.23.8 transitivePeerDependencies: - '@cloudflare/workers-types' @@ -1702,24 +1693,24 @@ snapshots: - supports-color - utf-8-validate - '@cloudflare/workerd-darwin-64@1.20240806.0': + '@cloudflare/workerd-darwin-64@1.20240821.1': optional: true - '@cloudflare/workerd-darwin-arm64@1.20240806.0': + '@cloudflare/workerd-darwin-arm64@1.20240821.1': optional: true - '@cloudflare/workerd-linux-64@1.20240806.0': + '@cloudflare/workerd-linux-64@1.20240821.1': optional: true - '@cloudflare/workerd-linux-arm64@1.20240806.0': + '@cloudflare/workerd-linux-arm64@1.20240821.1': optional: true - '@cloudflare/workerd-windows-64@1.20240806.0': + '@cloudflare/workerd-windows-64@1.20240821.1': optional: true - '@cloudflare/workers-shared@0.2.0': {} + '@cloudflare/workers-shared@0.4.1': {} - '@cloudflare/workers-types@4.20240815.0': {} + '@cloudflare/workers-types@4.20240909.0': {} '@cspotcode/source-map-support@0.8.1': dependencies: @@ -2189,7 +2180,7 @@ snapshots: capnp-ts@0.7.0: dependencies: - debug: 4.3.4 + debug: 4.3.6 tslib: 2.6.2 transitivePeerDependencies: - supports-color @@ -2246,10 +2237,6 @@ snapshots: date-fns@3.6.0: {} - debug@4.3.4: - dependencies: - ms: 2.1.2 - debug@4.3.6: dependencies: ms: 2.1.2 @@ -2567,7 +2554,7 @@ snapshots: mimic-fn@4.0.0: {} - miniflare@3.20240806.1: + miniflare@3.20240821.1: dependencies: '@cspotcode/source-map-support': 0.8.1 acorn: 8.11.3 @@ -2577,7 +2564,7 @@ snapshots: glob-to-regexp: 0.4.1 stoppable: 1.1.0 undici: 5.28.4 - workerd: 1.20240806.0 + workerd: 1.20240821.1 ws: 8.18.0 youch: 3.3.3 zod: 3.23.8 @@ -2606,8 +2593,6 @@ snapshots: nanoid@3.3.7: {} - node-fetch-native@1.6.4: {} - node-fetch@2.7.0: dependencies: whatwg-url: 5.0.0 @@ -2626,6 +2611,8 @@ snapshots: object-assign@4.1.1: {} + ohash@1.1.3: {} + onetime@5.1.2: dependencies: mimic-fn: 2.1.0 @@ -2871,7 +2858,7 @@ snapshots: tslib@2.6.2: {} - tsup@8.2.4(postcss@8.4.38)(typescript@5.5.4): + tsup@8.2.4(postcss@8.4.38)(typescript@5.6.2): dependencies: bundle-require: 5.0.0(esbuild@0.23.1) cac: 6.7.14 @@ -2891,16 +2878,16 @@ snapshots: tree-kill: 1.2.2 optionalDependencies: postcss: 8.4.38 - typescript: 5.5.4 + typescript: 5.6.2 transitivePeerDependencies: - jiti - supports-color - tsx - yaml - typescript@5.5.4: {} + typescript@5.6.2: {} - ufo@1.5.3: {} + ufo@1.5.4: {} undici-types@5.26.5: {} @@ -2908,14 +2895,12 @@ snapshots: dependencies: '@fastify/busboy': 2.1.1 - unenv-nightly@1.10.0-1717606461.a117952: + unenv-nightly@2.0.0-1724863496.70db6f1: dependencies: - consola: 3.2.3 defu: 6.1.4 - mime: 3.0.0 - node-fetch-native: 1.6.4 + ohash: 1.1.3 pathe: 1.1.2 - ufo: 1.5.3 + ufo: 1.5.4 vite-node@2.0.5(@types/node@20.14.9): dependencies: @@ -3006,36 +2991,36 @@ snapshots: siginfo: 2.0.0 stackback: 0.0.2 - workerd@1.20240806.0: + workerd@1.20240821.1: optionalDependencies: - '@cloudflare/workerd-darwin-64': 1.20240806.0 - '@cloudflare/workerd-darwin-arm64': 1.20240806.0 - '@cloudflare/workerd-linux-64': 1.20240806.0 - '@cloudflare/workerd-linux-arm64': 1.20240806.0 - '@cloudflare/workerd-windows-64': 1.20240806.0 + '@cloudflare/workerd-darwin-64': 1.20240821.1 + '@cloudflare/workerd-darwin-arm64': 1.20240821.1 + '@cloudflare/workerd-linux-64': 1.20240821.1 + '@cloudflare/workerd-linux-arm64': 1.20240821.1 + '@cloudflare/workerd-windows-64': 1.20240821.1 - wrangler@3.72.0(@cloudflare/workers-types@4.20240815.0): + wrangler@3.75.0(@cloudflare/workers-types@4.20240909.0): dependencies: '@cloudflare/kv-asset-handler': 0.3.4 - '@cloudflare/workers-shared': 0.2.0 + '@cloudflare/workers-shared': 0.4.1 '@esbuild-plugins/node-globals-polyfill': 0.2.3(esbuild@0.17.19) '@esbuild-plugins/node-modules-polyfill': 0.2.2(esbuild@0.17.19) blake3-wasm: 2.1.5 chokidar: 3.6.0 date-fns: 3.6.0 esbuild: 0.17.19 - miniflare: 3.20240806.1 + miniflare: 3.20240821.1 nanoid: 3.3.7 path-to-regexp: 6.2.2 resolve: 1.22.8 resolve.exports: 2.0.2 selfsigned: 2.4.1 source-map: 0.6.1 - unenv: unenv-nightly@1.10.0-1717606461.a117952 - workerd: 1.20240806.0 + unenv: unenv-nightly@2.0.0-1724863496.70db6f1 + workerd: 1.20240821.1 xxhash-wasm: 1.0.2 optionalDependencies: - '@cloudflare/workers-types': 4.20240815.0 + '@cloudflare/workers-types': 4.20240909.0 fsevents: 2.3.3 transitivePeerDependencies: - bufferutil diff --git a/examples/cloudflare-workers/src/index.ts b/examples/cloudflare-workers/src/index.ts index 5fec4f5..de19369 100644 --- a/examples/cloudflare-workers/src/index.ts +++ b/examples/cloudflare-workers/src/index.ts @@ -8,7 +8,7 @@ * Learn more at https://developers.cloudflare.com/workers/ */ -import { authenticate, jwtVerify } from '@commercelayer/js-auth' +import { authenticate, getCoreApiBaseEndpoint, jwtVerify } from '@commercelayer/js-auth' export interface Env { // Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/ @@ -37,7 +37,7 @@ export default { const decodedJWT = await jwtVerify(auth.accessToken) if ('organization' in decodedJWT.payload) { - return new Response(`Hello World!\n\nThe organization slug is: ${decodedJWT.payload.organization.slug}`); + return new Response(`Hello World!\n\nThe organization slug is: ${decodedJWT.payload.organization.slug}\nThe base endpoint is: ${getCoreApiBaseEndpoint(auth.accessToken)}`); } return new Response('Cannot find the organization', { status: 404 }) diff --git a/examples/deno/index.ts b/examples/deno/index.ts index 7b73852..368eded 100644 --- a/examples/deno/index.ts +++ b/examples/deno/index.ts @@ -1,5 +1,5 @@ // @deno-types="../../packages/js-auth/dist/index.d.ts" -import { authenticate, jwtVerify } from '../../packages/js-auth/dist/index.js' +import { authenticate, getCoreApiBaseEndpoint, jwtVerify } from '../../packages/js-auth/dist/index.js' const auth = await authenticate('client_credentials', { clientId: 'BISG8bb3GWpC8_D7Nt1SuWWdieS5bJq831A50LgB_Ig', @@ -12,4 +12,5 @@ const decodedJWT = await jwtVerify(auth.accessToken) if ('organization' in decodedJWT.payload) { console.log('organization slug is', decodedJWT.payload.organization.slug) + console.log('base endpoint is', getCoreApiBaseEndpoint(auth.accessToken)) } diff --git a/examples/esm/index.js b/examples/esm/index.js index 3f63ab6..67173e7 100644 --- a/examples/esm/index.js +++ b/examples/esm/index.js @@ -1,6 +1,6 @@ // @ts-check -import { authenticate, jwtVerify } from '@commercelayer/js-auth' +import { authenticate, getCoreApiBaseEndpoint, jwtVerify } from '@commercelayer/js-auth' const auth = await authenticate('client_credentials', { clientId: 'BISG8bb3GWpC8_D7Nt1SuWWdieS5bJq831A50LgB_Ig', @@ -13,4 +13,5 @@ const decodedJWT = await jwtVerify(auth.accessToken) if ('organization' in decodedJWT.payload) { console.log('organization slug is', decodedJWT.payload.organization.slug) + console.log('base endpoint is', getCoreApiBaseEndpoint(auth.accessToken)) } diff --git a/examples/esm/pnpm-lock.yaml b/examples/esm/pnpm-lock.yaml index a2a13a4..6fef533 100644 --- a/examples/esm/pnpm-lock.yaml +++ b/examples/esm/pnpm-lock.yaml @@ -25,10 +25,10 @@ importers: version: 9.0.2 tsup: specifier: ^8.2.4 - version: 8.2.4(postcss@8.4.38)(typescript@5.5.4) + version: 8.2.4(postcss@8.4.38)(typescript@5.6.2) typescript: - specifier: ^5.5.4 - version: 5.5.4 + specifier: ^5.6.2 + version: 5.6.2 vitest: specifier: ^2.0.5 version: 2.0.5(@types/node@20.14.9) @@ -1141,8 +1141,8 @@ packages: typescript: optional: true - typescript@5.5.4: - resolution: {integrity: sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==} + typescript@5.6.2: + resolution: {integrity: sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==} engines: {node: '>=14.17'} hasBin: true @@ -2150,7 +2150,7 @@ snapshots: ts-interface-checker@0.1.13: {} - tsup@8.2.4(postcss@8.4.38)(typescript@5.5.4): + tsup@8.2.4(postcss@8.4.38)(typescript@5.6.2): dependencies: bundle-require: 5.0.0(esbuild@0.23.1) cac: 6.7.14 @@ -2170,14 +2170,14 @@ snapshots: tree-kill: 1.2.2 optionalDependencies: postcss: 8.4.38 - typescript: 5.5.4 + typescript: 5.6.2 transitivePeerDependencies: - jiti - supports-color - tsx - yaml - typescript@5.5.4: {} + typescript@5.6.2: {} undici-types@5.26.5: {} diff --git a/examples/nextjs/package.json b/examples/nextjs/package.json index 3623e72..62183fb 100644 --- a/examples/nextjs/package.json +++ b/examples/nextjs/package.json @@ -12,7 +12,7 @@ "@commercelayer/js-auth": "workspace:*", "react": "^18", "react-dom": "^18", - "next": "14.2.5" + "next": "14.2.9" }, "devDependencies": { "typescript": "^5", diff --git a/examples/nextjs/pnpm-lock.yaml b/examples/nextjs/pnpm-lock.yaml index 91973cd..fcf252e 100644 --- a/examples/nextjs/pnpm-lock.yaml +++ b/examples/nextjs/pnpm-lock.yaml @@ -12,8 +12,8 @@ importers: specifier: workspace:* version: link:../../packages/js-auth next: - specifier: 14.2.5 - version: 14.2.5(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + specifier: 14.2.9 + version: 14.2.9(react-dom@18.3.1(react@18.3.1))(react@18.3.1) react: specifier: ^18 version: 18.3.1 @@ -47,10 +47,10 @@ importers: version: 9.0.2 tsup: specifier: ^8.2.4 - version: 8.2.4(postcss@8.4.39)(typescript@5.5.4)(yaml@2.4.5) + version: 8.2.4(postcss@8.4.39)(typescript@5.6.2)(yaml@2.4.5) typescript: - specifier: ^5.5.4 - version: 5.5.4 + specifier: ^5.6.2 + version: 5.6.2 vitest: specifier: ^2.0.5 version: 2.0.5(@types/node@20.14.10) @@ -368,59 +368,59 @@ packages: '@jridgewell/trace-mapping@0.3.25': resolution: {integrity: sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==} - '@next/env@14.2.5': - resolution: {integrity: sha512-/zZGkrTOsraVfYjGP8uM0p6r0BDT6xWpkjdVbcz66PJVSpwXX3yNiRycxAuDfBKGWBrZBXRuK/YVlkNgxHGwmA==} + '@next/env@14.2.9': + resolution: {integrity: sha512-hnDAoDPMii31V0ivibI8p6b023jOF1XblWTVjsDUoZKwnZlaBtJFZKDwFqi22R8r9i6W08dThUWU7Bsh2Rg8Ww==} - '@next/swc-darwin-arm64@14.2.5': - resolution: {integrity: sha512-/9zVxJ+K9lrzSGli1///ujyRfon/ZneeZ+v4ptpiPoOU+GKZnm8Wj8ELWU1Pm7GHltYRBklmXMTUqM/DqQ99FQ==} + '@next/swc-darwin-arm64@14.2.9': + resolution: {integrity: sha512-/kfQifl3uLYi3DlwFlzCkgxe6fprJNLzzTUFknq3M5wGYicDIbdGlxUl6oHpVLJpBB/CBY3Y//gO6alz/K4NWA==} engines: {node: '>= 10'} cpu: [arm64] os: [darwin] - '@next/swc-darwin-x64@14.2.5': - resolution: {integrity: sha512-vXHOPCwfDe9qLDuq7U1OYM2wUY+KQ4Ex6ozwsKxp26BlJ6XXbHleOUldenM67JRyBfVjv371oneEvYd3H2gNSA==} + '@next/swc-darwin-x64@14.2.9': + resolution: {integrity: sha512-tK/RyhCmOCiXQ9IVdFrBbZOf4/1+0RSuJkebXU2uMEsusS51TjIJO4l8ZmEijH9gZa0pJClvmApRHi7JuBqsRw==} engines: {node: '>= 10'} cpu: [x64] os: [darwin] - '@next/swc-linux-arm64-gnu@14.2.5': - resolution: {integrity: sha512-vlhB8wI+lj8q1ExFW8lbWutA4M2ZazQNvMWuEDqZcuJJc78iUnLdPPunBPX8rC4IgT6lIx/adB+Cwrl99MzNaA==} + '@next/swc-linux-arm64-gnu@14.2.9': + resolution: {integrity: sha512-tS5eqwsp2nO7mzywRUuFYmefNZsUKM/mTG3exK2jIHv9TEVklE1SByB1KMhFkqlit1PxS9YK1tV8BOV90Wpbrw==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] - '@next/swc-linux-arm64-musl@14.2.5': - resolution: {integrity: sha512-NpDB9NUR2t0hXzJJwQSGu1IAOYybsfeB+LxpGsXrRIb7QOrYmidJz3shzY8cM6+rO4Aojuef0N/PEaX18pi9OA==} + '@next/swc-linux-arm64-musl@14.2.9': + resolution: {integrity: sha512-8svpeTFNAMTUMKQbEzE8qRAwl9o7mNBv7LR1bmSkQvo1oy4WrNyZbhWsldOiKrc4mZ5dfQkGYsI9T75mIFMfeA==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] - '@next/swc-linux-x64-gnu@14.2.5': - resolution: {integrity: sha512-8XFikMSxWleYNryWIjiCX+gU201YS+erTUidKdyOVYi5qUQo/gRxv/3N1oZFCgqpesN6FPeqGM72Zve+nReVXQ==} + '@next/swc-linux-x64-gnu@14.2.9': + resolution: {integrity: sha512-0HNulLWpKTB7H5BhHCkEhcRAnWUHeAYCftrrGw3QC18+ZywTdAoPv/zEqKy/0adqt+ks4JDdlgSQ1lNKOKjo0A==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - '@next/swc-linux-x64-musl@14.2.5': - resolution: {integrity: sha512-6QLwi7RaYiQDcRDSU/os40r5o06b5ue7Jsk5JgdRBGGp8l37RZEh9JsLSM8QF0YDsgcosSeHjglgqi25+m04IQ==} + '@next/swc-linux-x64-musl@14.2.9': + resolution: {integrity: sha512-hhVFViPHLAVUJRNtwwm609p9ozWajOmRvzOZzzKXgiVGwx/CALxlMUeh+M+e0Zj6orENhWLZeilOPHpptuENsA==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - '@next/swc-win32-arm64-msvc@14.2.5': - resolution: {integrity: sha512-1GpG2VhbspO+aYoMOQPQiqc/tG3LzmsdBH0LhnDS3JrtDx2QmzXe0B6mSZZiN3Bq7IOMXxv1nlsjzoS1+9mzZw==} + '@next/swc-win32-arm64-msvc@14.2.9': + resolution: {integrity: sha512-p/v6XlOdrk06xfN9z4evLNBqftVQUWiyduQczCwSj7hNh8fWTbzdVxsEiNOcajMXJbQiaX/ZzZdFgKVmmJnnGQ==} engines: {node: '>= 10'} cpu: [arm64] os: [win32] - '@next/swc-win32-ia32-msvc@14.2.5': - resolution: {integrity: sha512-Igh9ZlxwvCDsu6438FXlQTHlRno4gFpJzqPjSIBZooD22tKeI4fE/YMRoHVJHmrQ2P5YL1DoZ0qaOKkbeFWeMg==} + '@next/swc-win32-ia32-msvc@14.2.9': + resolution: {integrity: sha512-IcW9dynWDjMK/0M05E3zopbRen7v0/yEaMZbHFOSS1J/w+8YG3jKywOGZWNp/eCUVtUUXs0PW+7Lpz8uLu+KQA==} engines: {node: '>= 10'} cpu: [ia32] os: [win32] - '@next/swc-win32-x64-msvc@14.2.5': - resolution: {integrity: sha512-tEQ7oinq1/CjSG9uSTerca3v4AZ+dFa+4Yu6ihaG8Ud8ddqLQgFGcnwYls13H5X5CPDPZJdYxyeMui6muOLd4g==} + '@next/swc-win32-x64-msvc@14.2.9': + resolution: {integrity: sha512-gcbpoXyWZdVOBgNa5BRzynrL5UR1nb2ZT38yKgnphYU9UHjeecnylMHntrQiMg/QtONDcJPFC/PmsS47xIRYoA==} engines: {node: '>= 10'} cpu: [x64] os: [win32] @@ -999,8 +999,8 @@ packages: engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} hasBin: true - next@14.2.5: - resolution: {integrity: sha512-0f8aRfBVL+mpzfBjYfQuLWh2WyAwtJXCRfkPF4UJ5qd2YwrHczsrSzXU4tRMV0OAxR8ZJZWPFn6uhSC56UTsLA==} + next@14.2.9: + resolution: {integrity: sha512-3CzBNo6BuJnRjcQvRw+irnU1WiuJNZEp+dkzkt91y4jeIDN/Emg95F+takSYiLpJ/HkxClVQRyqiTwYce5IVqw==} engines: {node: '>=18.17.0'} hasBin: true peerDependencies: @@ -1313,6 +1313,11 @@ packages: engines: {node: '>=14.17'} hasBin: true + typescript@5.6.2: + resolution: {integrity: sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==} + engines: {node: '>=14.17'} + hasBin: true + undici-types@5.26.5: resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} @@ -1592,33 +1597,33 @@ snapshots: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.5.0 - '@next/env@14.2.5': {} + '@next/env@14.2.9': {} - '@next/swc-darwin-arm64@14.2.5': + '@next/swc-darwin-arm64@14.2.9': optional: true - '@next/swc-darwin-x64@14.2.5': + '@next/swc-darwin-x64@14.2.9': optional: true - '@next/swc-linux-arm64-gnu@14.2.5': + '@next/swc-linux-arm64-gnu@14.2.9': optional: true - '@next/swc-linux-arm64-musl@14.2.5': + '@next/swc-linux-arm64-musl@14.2.9': optional: true - '@next/swc-linux-x64-gnu@14.2.5': + '@next/swc-linux-x64-gnu@14.2.9': optional: true - '@next/swc-linux-x64-musl@14.2.5': + '@next/swc-linux-x64-musl@14.2.9': optional: true - '@next/swc-win32-arm64-msvc@14.2.5': + '@next/swc-win32-arm64-msvc@14.2.9': optional: true - '@next/swc-win32-ia32-msvc@14.2.5': + '@next/swc-win32-ia32-msvc@14.2.9': optional: true - '@next/swc-win32-x64-msvc@14.2.5': + '@next/swc-win32-x64-msvc@14.2.9': optional: true '@nodelib/fs.scandir@2.1.5': @@ -2175,9 +2180,9 @@ snapshots: nanoid@3.3.7: {} - next@14.2.5(react-dom@18.3.1(react@18.3.1))(react@18.3.1): + next@14.2.9(react-dom@18.3.1(react@18.3.1))(react@18.3.1): dependencies: - '@next/env': 14.2.5 + '@next/env': 14.2.9 '@swc/helpers': 0.5.5 busboy: 1.6.0 caniuse-lite: 1.0.30001651 @@ -2187,15 +2192,15 @@ snapshots: react-dom: 18.3.1(react@18.3.1) styled-jsx: 5.1.1(react@18.3.1) optionalDependencies: - '@next/swc-darwin-arm64': 14.2.5 - '@next/swc-darwin-x64': 14.2.5 - '@next/swc-linux-arm64-gnu': 14.2.5 - '@next/swc-linux-arm64-musl': 14.2.5 - '@next/swc-linux-x64-gnu': 14.2.5 - '@next/swc-linux-x64-musl': 14.2.5 - '@next/swc-win32-arm64-msvc': 14.2.5 - '@next/swc-win32-ia32-msvc': 14.2.5 - '@next/swc-win32-x64-msvc': 14.2.5 + '@next/swc-darwin-arm64': 14.2.9 + '@next/swc-darwin-x64': 14.2.9 + '@next/swc-linux-arm64-gnu': 14.2.9 + '@next/swc-linux-arm64-musl': 14.2.9 + '@next/swc-linux-x64-gnu': 14.2.9 + '@next/swc-linux-x64-musl': 14.2.9 + '@next/swc-win32-arm64-msvc': 14.2.9 + '@next/swc-win32-ia32-msvc': 14.2.9 + '@next/swc-win32-x64-msvc': 14.2.9 transitivePeerDependencies: - '@babel/core' - babel-plugin-macros @@ -2441,7 +2446,7 @@ snapshots: tslib@2.6.3: {} - tsup@8.2.4(postcss@8.4.39)(typescript@5.5.4)(yaml@2.4.5): + tsup@8.2.4(postcss@8.4.39)(typescript@5.6.2)(yaml@2.4.5): dependencies: bundle-require: 5.0.0(esbuild@0.23.1) cac: 6.7.14 @@ -2461,7 +2466,7 @@ snapshots: tree-kill: 1.2.2 optionalDependencies: postcss: 8.4.39 - typescript: 5.5.4 + typescript: 5.6.2 transitivePeerDependencies: - jiti - supports-color @@ -2470,6 +2475,8 @@ snapshots: typescript@5.5.4: {} + typescript@5.6.2: {} + undici-types@5.26.5: {} undici-types@6.19.8: {} diff --git a/examples/nextjs/src/app/api/test/route.ts b/examples/nextjs/src/app/api/test/route.ts index 134feaa..56bec32 100644 --- a/examples/nextjs/src/app/api/test/route.ts +++ b/examples/nextjs/src/app/api/test/route.ts @@ -1,4 +1,4 @@ -import { authenticate, jwtVerify } from "@commercelayer/js-auth" +import { authenticate, getCoreApiBaseEndpoint, jwtVerify } from "@commercelayer/js-auth" import { NextResponse, type NextRequest } from "next/server" export async function GET(_request: NextRequest) { @@ -17,6 +17,7 @@ export async function GET(_request: NextRequest) { return NextResponse.json({ from: 'api', - orgSlug: decodedJWT.payload.organization.slug + orgSlug: decodedJWT.payload.organization.slug, + baseEndpoint: getCoreApiBaseEndpoint(auth.accessToken) }) } diff --git a/examples/nextjs/src/app/page.module.css b/examples/nextjs/src/app/page.module.css index 2c455c1..0b7311a 100644 --- a/examples/nextjs/src/app/page.module.css +++ b/examples/nextjs/src/app/page.module.css @@ -44,6 +44,7 @@ grid-template-columns: repeat(4, minmax(25%, auto)); max-width: 100%; width: var(--max-width); + gap: 12px; } .card { diff --git a/examples/nextjs/src/app/page.tsx b/examples/nextjs/src/app/page.tsx index 994f270..28a898e 100644 --- a/examples/nextjs/src/app/page.tsx +++ b/examples/nextjs/src/app/page.tsx @@ -1,6 +1,6 @@ import Image from "next/image" import styles from "./page.module.css" -import { authenticate, jwtVerify } from '@commercelayer/js-auth' +import { authenticate, getCoreApiBaseEndpoint, jwtVerify } from '@commercelayer/js-auth' export default async function Home() { @@ -42,59 +42,33 @@ export default async function Home() {
Find in-depth information about Next.js features and API.
+auth.js
within a middleware.
Learn about Next.js in an interactive course with quizzes!
- - - -Explore starter templates for Next.js.
- - - -- Instantly deploy your Next.js site to a shareable URL with Vercel. -
+auth.js
within an api.