From 1509195fe6e022b63a530f8b7f1c741d6389fdbf Mon Sep 17 00:00:00 2001 From: Marco Montalbano Date: Tue, 3 Sep 2024 22:01:43 +0200 Subject: [PATCH 1/4] feat: add 'getCoreApiEndpoint' helper --- .../js-auth/src/getCoreApiEndpoint.test.ts | 39 +++++++++++++++++++ packages/js-auth/src/getCoreApiEndpoint.ts | 24 ++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 packages/js-auth/src/getCoreApiEndpoint.test.ts create mode 100644 packages/js-auth/src/getCoreApiEndpoint.ts diff --git a/packages/js-auth/src/getCoreApiEndpoint.test.ts b/packages/js-auth/src/getCoreApiEndpoint.test.ts new file mode 100644 index 0000000..1c0ee39 --- /dev/null +++ b/packages/js-auth/src/getCoreApiEndpoint.test.ts @@ -0,0 +1,39 @@ +import { InvalidTokenError } from './errors/InvalidTokenError.js' +import { TokenError } from './errors/TokenError.js' +import { getCoreApiEndpoint } from './getCoreApiEndpoint.js' + +describe('getCoreApiEndpoint', () => { + it('should throw when the access token does not have an "organization".', () => { + const accessToken = + 'eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCIsImtpZCI6ImFiYTRjYzYyOGQxZmNlM2ZiOTNhM2VlNTU4MjZlNDFjZmFmMThkYzJkZmYzYjA3MjIyNzQwMzgwZTkxOTlkNWQifQ.eyJ1c2VyIjp7ImlkIjoiZ2Jsb3dTeVZlcSJ9LCJhcHBsaWNhdGlvbiI6eyJpZCI6Im5HVnFhaWxWeU4iLCJraW5kIjoiZGFzaGJvYXJkIiwicHVibGljIjpmYWxzZX0sInNjb3BlIjoicHJvdmlzaW9uaW5nLWFwaSBtZXRyaWNzLWFwaSIsImV4cCI6MTcxMDk3NjY5NSwidGVzdCI6ZmFsc2UsInJhbmQiOjAuNzY1MjgwMDc2MDY1MjMwNywiaWF0IjoxNzEwOTY5NDk1LCJpc3MiOiJodHRwczovL2NvbW1lcmNlbGF5ZXIuaW8ifQ.YYk1PRFa8zcAlus8uaDFcJF7FRBtXYz-h--OYyuxJ0pc_qG0jdZ7lNgKxZC0Xnb4f9QmO3nHC4b4leGm6aAw8Yw4atZZaEDEkPrlG-ZegtdM4_X2Wbeul_Swkxo91PCIkYRMue0tl-zwl3dH_bS48IGOgOCbNWIcuHFvILaN_oXOHaeGfbVY5zXFfMK8P77TWZEoK0BYvmXIv2o_x_uYQZVcev7sSy1aX2zkikMFu54PIDl-II94ETT2g51QgNglDVh64qIFRvb24uPZo3woEBtd4ogupMRY5c3BvbxtfKHeASjT2NMxSkg-J55V7L4Wv5Q3Oh5p7ePz-95n7lG7uQ' + + expect(() => getCoreApiEndpoint(accessToken)).toThrow(InvalidTokenError) + expect(() => getCoreApiEndpoint(accessToken)).toThrow(TokenError) + expect(() => getCoreApiEndpoint(accessToken)).toThrow( + 'Invalid token format' + ) + }) + + it('should return the core api endpoint when access token contains an "organization".', () => { + expect( + getCoreApiEndpoint( + 'eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCIsImtpZCI6ImFiYTRjYzYyOGQxZmNlM2ZiOTNhM2VlNTU4MjZlNDFjZmFmMThkYzJkZmYzYjA3MjIyNzQwMzgwZTkxOTlkNWQifQ.eyJvcmdhbml6YXRpb24iOnsiaWQiOiJlbldveEZNT25wIiwic2x1ZyI6InRoZS1ibHVlLWJyYW5kLTMiLCJlbnRlcnByaXNlIjpmYWxzZSwicmVnaW9uIjoiZXUtd2VzdC0xIn0sImFwcGxpY2F0aW9uIjp7ImlkIjoibkdWcWFpRVlOQSIsImNsaWVudF9pZCI6IjF1bEs3ZXdkUUZyak90LVlxZ0RQeXBRRzFYSmVtUGdaUDFvd3NpSG9tRDQiLCJraW5kIjoic2FsZXNfY2hhbm5lbCIsInB1YmxpYyI6dHJ1ZX0sInNjb3BlIjoibWFya2V0OmFsbCIsImV4cCI6MTcyNTM5OTc3OCwidGVzdCI6dHJ1ZSwicmFuZCI6MC4yMTIzMDUzMTE1NDg3Njk5NywiaWF0IjoxNzI1MzkyNTc4LCJpc3MiOiJodHRwczovL2F1dGguY29tbWVyY2VsYXllci5jbyJ9.aOjfJXPDQ-jY__XlZuaAhpboDCGPuaszSMjgBlGJ7ubjWmmHGIvgOewNusTKRcrvhgWsUPeGeBii9SdkxP0tHMejXb0qS8RZ7lAxhvfHlekytdhizLrTUoqAwGckgX9FJTzRh0rA57cFXLSuXXUvB5aUtFZ3CfxZ_YIRWUNSvbAsknYmH1WAy54QjpvM9jFD3iXv3ak9Q9DnxC80N98lgWfgjEgoW67jQSLHQT0r-cgbT8dbVUDOkUp4PnUQkjLWHcoejRFMlORTlQTSGjW8pYsYJyKhUa8FJ9UWcRGp55xIJLmdqbVcdYo0R2ESz32ek-Uu3OTO-JAbABSC-oN5Dzo_BHxS7ct_TcZV9Qxr-fGdZXD0C5PljMqmAQMeSRoZjdSLSLLKq5dyUx714NT9urE_BVLTkZ-jU-15iyS3aWy0qgmMKu3NOBmF_j-P7ohNNjDsdMz2ofZ8r2E_0QBgpC1LwdWt4r0S4eabiTskM4r-wrQSbctZae0veIrKQ4C3k1Wr1wR9b6CvZXr-IqaYg1VilMiffmVhbYl60iWg3IK5REKJFJ2hNm18A78OiBO4A5KiL6lk3N_26C9dJa9HolUbpopiIVgZxXUXRw6EohnU0e5IBnQES-3q9T_37lNgAKlbHpqDKKEWjdwqb3GRMdxzMj0rxELyBRBbx-W8_9s' + ) + ).toEqual('https://the-blue-brand-3.commercelayer.co') + + expect( + getCoreApiEndpoint( + 'eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCIsImtpZCI6ImFiYTRjYzYyOGQxZmNlM2ZiOTNhM2VlNTU4MjZlNDFjZmFmMThkYzJkZmYzYjA3MjIyNzQwMzgwZTkxOTlkNWQifQ.eyJvcmdhbml6YXRpb24iOnsiaWQiOiJlbldveEZNT25wIiwic2x1ZyI6InRoZS1ibHVlLWJyYW5kLTMiLCJlbnRlcnByaXNlIjpmYWxzZSwicmVnaW9uIjoiZXUtd2VzdC0xIn0sImFwcGxpY2F0aW9uIjp7ImlkIjoibkdWcWFpRVlOQSIsImNsaWVudF9pZCI6IjF1bEs3ZXdkUUZyak90LVlxZ0RQeXBRRzFYSmVtUGdaUDFvd3NpSG9tRDQiLCJraW5kIjoic2FsZXNfY2hhbm5lbCIsInB1YmxpYyI6dHJ1ZX0sInNjb3BlIjoibWFya2V0OmFsbCIsImV4cCI6MTcyNTM5OTc3OCwidGVzdCI6dHJ1ZSwicmFuZCI6MC4yMTIzMDUzMTE1NDg3Njk5NywiaWF0IjoxNzI1MzkyNTc4LCJpc3MiOiJodHRwczovL2F1dGguc3RnMS5jb21tZXJjZWxheWVyLmNvIn0.oQRimLI0JHMnNtm_j-VwtqIjR-IafvukM8XB5RlxOmhfKvEAyCRbVDKQqk09n9p5cVBiOFbbiXxg8hSHXVqx-FfD14tDO7OgYzB9V7uWVrkOrof2kUTdy15IubpSDGk_X9qlwq1Rv5CgofCPRCvTlEI4Es2LcS6WLj-Q2pjqe6aP3tP6_Ne_bHz0oue5vXgs_noNLYPsYs4IIcwvPMU6R0EXnBJ5BdEplBiGhRyoQ_LUtUNKFQnoLeGk5_rKK6soP72w-Xi-tlR7rNw--fDbrTYH5XrkoD-QGiyMUk2Y-Vi6xpKNQ1wHky7WnuhOtJAy_-C90Zq6wfncQ5pBXT4rQ1HyNzzNgj9EpkkZTgNqy5fp8e62JKxpQRTz8es_4uVGLq_rn8CZZ7HX-C9-87AgebckDIWO9SCTtn8EOTMsu-wqzf3EQjFE35e78sNrVMqHMToW7QnCnellq4tdHp3oIiOHgIDjEQCQQytipH8cYIHqGxG-oUUatG77elFOvNH-9K38l1W0pfdgyfl27cnYbEDFWAf3yicrfiVlX77_PkTuE2dC910rNQ3Eg4XY7BxWMgoVSeBD2Bf1OjvyFCoxZEBfuC_7U7i5VR88pPGSF2dU9DGVwe-KhPasjv_p2O0lboL48ic7Icdvhy7c-MvGUTV5O8bxNjN0MJ39MYrwaUQ' + ) + ).toEqual('https://the-blue-brand-3.stg1.commercelayer.co') + }) + + it('should fallback to "commercelayer.io" when "iss" is expressed in an old format.', () => { + const accessToken = + 'eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCIsImtpZCI6ImFiYTRjYzYyOGQxZmNlM2ZiOTNhM2VlNTU4MjZlNDFjZmFmMThkYzJkZmYzYjA3MjIyNzQwMzgwZTkxOTlkNWQifQ.eyJvcmdhbml6YXRpb24iOnsiaWQiOiJlbldveEZNT25wIiwic2x1ZyI6InRoZS1ibHVlLWJyYW5kLTMiLCJlbnRlcnByaXNlIjpmYWxzZSwicmVnaW9uIjoiZXUtd2VzdC0xIn0sImFwcGxpY2F0aW9uIjp7ImlkIjoibkdWcWFpRVlOQSIsImtpbmQiOiJzYWxlc19jaGFubmVsIiwicHVibGljIjp0cnVlfSwic2NvcGUiOiJtYXJrZXQ6YWxsIiwiZXhwIjoxNzEwOTU3NjMwLCJ0ZXN0Ijp0cnVlLCJyYW5kIjowLjM0Nzg4MjA0NDE1NDI0Njk1LCJpYXQiOjE3MTA5NDMyMzAsImlzcyI6Imh0dHBzOi8vY29tbWVyY2VsYXllci5pbyJ9.XhcMqwVwAh5wP2rbNyODBuPpTicwJjvK09KPmhe3nM1Lg0Hp0bIEQIOS81ohLyLE9ecaRH_7CsfLkAqYmRtdOTAKu9m4xvWw-Z_hBQpY67FTaikInMVltNffLvNDe5qmleNi5jnXtJl_yEGhtlDydpFBx1x8u3ofgtZSPFWm3Tl4KQoxFxT8CnnxPd2LTW_PfvnqS3QEGgvVnEXSTnJ41EU4dB8c9cZmmJY6e9SeH9fHVd469N_ipP4bymIL7kLPpkBBDuxxZ0787dOblGI31geAW-hHGbCpnj4_i5WJAVVsj_ImBtqt9Bihc-O-iHIMJlVOzWWXTAnmWGsHiwL5Ag' + + expect(getCoreApiEndpoint(accessToken)).toEqual( + 'https://the-blue-brand-3.commercelayer.io' + ) + }) +}) diff --git a/packages/js-auth/src/getCoreApiEndpoint.ts b/packages/js-auth/src/getCoreApiEndpoint.ts new file mode 100644 index 0000000..ec214bf --- /dev/null +++ b/packages/js-auth/src/getCoreApiEndpoint.ts @@ -0,0 +1,24 @@ +import { InvalidTokenError } from './errors/InvalidTokenError.js' +import { jwtDecode } from './jwtDecode.js' + +/** + * Derive the [Core API base endpoint](https://docs.commercelayer.io/core/api-specification#base-endpoint) given a valid access token. + * @example + * ```ts + * getCoreApiEndpoint('eyJhbGciOiJS...') //= "https://yourdomain.commercelayer.io" + * ``` + */ +export function getCoreApiEndpoint(accessToken: string): string { + const decodedJWT = jwtDecode(accessToken) + + if (!('organization' in decodedJWT.payload)) { + throw new InvalidTokenError('Invalid token format') + } + + return decodedJWT.payload.iss.startsWith('https://auth.') + ? decodedJWT.payload.iss.replace( + 'auth', + decodedJWT.payload.organization.slug + ) + : `https://${decodedJWT.payload.organization.slug}.commercelayer.io` +} From 2d3d037aae34ff8b0b5b14d86231286033f0c314 Mon Sep 17 00:00:00 2001 From: Marco Montalbano Date: Tue, 10 Sep 2024 16:00:56 +0200 Subject: [PATCH 2/4] docs: update documentation --- packages/js-auth/README.md | 15 +++++++++++++++ packages/js-auth/package.json | 2 +- ...nt.test.ts => getCoreApiBaseEndpoint.test.ts} | 16 ++++++++-------- ...eApiEndpoint.ts => getCoreApiBaseEndpoint.ts} | 8 ++++++-- packages/js-auth/src/index.ts | 3 +++ 5 files changed, 33 insertions(+), 11 deletions(-) rename packages/js-auth/src/{getCoreApiEndpoint.test.ts => getCoreApiBaseEndpoint.test.ts} (91%) rename packages/js-auth/src/{getCoreApiEndpoint.ts => getCoreApiBaseEndpoint.ts} (65%) diff --git a/packages/js-auth/README.md b/packages/js-auth/README.md index fedc33f..be0efd6 100644 --- a/packages/js-auth/README.md +++ b/packages/js-auth/README.md @@ -24,6 +24,7 @@ It works everywhere. On your browser, server, or at the edge. - [Utilities](#utilities) - [Decode an access token](#decode-an-access-token) - [Verify an access token](#verify-an-access-token) + - [Get Core API base endpoint](#get-core-api-base-endpoint) - [Contributors guide](#contributors-guide) - [Need help?](#need-help) - [License](#license) @@ -77,6 +78,8 @@ Based on the authorization flow and application you want to use, you can get you - [Integration application with client credentials flow](#integration-client-credentials) - [Webapp application with authorization code flow](#webapp-authorization-code) - [Provisioning application](#provisioning) +- [JWT bearer](#jwt-bearer) +- [Revoking a token](#revoking-a-token) ### Sales channel (client credentials) @@ -324,6 +327,18 @@ if (jwtIsSalesChannel(decodedJWT.payload)) { } ``` +### Get Core API base endpoint + +Derive the [Core API base endpoint](https://docs.commercelayer.io/core/api-specification#base-endpoint) given a valid access token. + +```ts +import { getCoreApiBaseEndpoint } from '@commercelayer/js-auth' + +getCoreApiBaseEndpoint('a-valid-access-token') //= "https://yourdomain.commercelayer.io" +``` + +The method requires a valid access token with an `organization` in the payload. When the organization is not set (e.g., provisioning token), it throws an `InvalidTokenError` exception. + --- ## Contributors guide diff --git a/packages/js-auth/package.json b/packages/js-auth/package.json index 3196a33..4e8e033 100644 --- a/packages/js-auth/package.json +++ b/packages/js-auth/package.json @@ -35,7 +35,7 @@ "scripts": { "lint": "eslint src --ext .ts,.tsx", "lint:fix": "eslint src --ext .ts,.tsx --fix", - "test": "pnpm run lint && vitest run", + "test": "pnpm run lint:fix && vitest run", "test:watch": "vitest", "build": "tsup", "jsr:publish": "npx jsr publish" diff --git a/packages/js-auth/src/getCoreApiEndpoint.test.ts b/packages/js-auth/src/getCoreApiBaseEndpoint.test.ts similarity index 91% rename from packages/js-auth/src/getCoreApiEndpoint.test.ts rename to packages/js-auth/src/getCoreApiBaseEndpoint.test.ts index 1c0ee39..2429fb8 100644 --- a/packages/js-auth/src/getCoreApiEndpoint.test.ts +++ b/packages/js-auth/src/getCoreApiBaseEndpoint.test.ts @@ -1,28 +1,28 @@ import { InvalidTokenError } from './errors/InvalidTokenError.js' import { TokenError } from './errors/TokenError.js' -import { getCoreApiEndpoint } from './getCoreApiEndpoint.js' +import { getCoreApiBaseEndpoint } from './getCoreApiBaseEndpoint.js' -describe('getCoreApiEndpoint', () => { +describe('getCoreApiBaseEndpoint', () => { it('should throw when the access token does not have an "organization".', () => { const accessToken = 'eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCIsImtpZCI6ImFiYTRjYzYyOGQxZmNlM2ZiOTNhM2VlNTU4MjZlNDFjZmFmMThkYzJkZmYzYjA3MjIyNzQwMzgwZTkxOTlkNWQifQ.eyJ1c2VyIjp7ImlkIjoiZ2Jsb3dTeVZlcSJ9LCJhcHBsaWNhdGlvbiI6eyJpZCI6Im5HVnFhaWxWeU4iLCJraW5kIjoiZGFzaGJvYXJkIiwicHVibGljIjpmYWxzZX0sInNjb3BlIjoicHJvdmlzaW9uaW5nLWFwaSBtZXRyaWNzLWFwaSIsImV4cCI6MTcxMDk3NjY5NSwidGVzdCI6ZmFsc2UsInJhbmQiOjAuNzY1MjgwMDc2MDY1MjMwNywiaWF0IjoxNzEwOTY5NDk1LCJpc3MiOiJodHRwczovL2NvbW1lcmNlbGF5ZXIuaW8ifQ.YYk1PRFa8zcAlus8uaDFcJF7FRBtXYz-h--OYyuxJ0pc_qG0jdZ7lNgKxZC0Xnb4f9QmO3nHC4b4leGm6aAw8Yw4atZZaEDEkPrlG-ZegtdM4_X2Wbeul_Swkxo91PCIkYRMue0tl-zwl3dH_bS48IGOgOCbNWIcuHFvILaN_oXOHaeGfbVY5zXFfMK8P77TWZEoK0BYvmXIv2o_x_uYQZVcev7sSy1aX2zkikMFu54PIDl-II94ETT2g51QgNglDVh64qIFRvb24uPZo3woEBtd4ogupMRY5c3BvbxtfKHeASjT2NMxSkg-J55V7L4Wv5Q3Oh5p7ePz-95n7lG7uQ' - expect(() => getCoreApiEndpoint(accessToken)).toThrow(InvalidTokenError) - expect(() => getCoreApiEndpoint(accessToken)).toThrow(TokenError) - expect(() => getCoreApiEndpoint(accessToken)).toThrow( + expect(() => getCoreApiBaseEndpoint(accessToken)).toThrow(InvalidTokenError) + expect(() => getCoreApiBaseEndpoint(accessToken)).toThrow(TokenError) + expect(() => getCoreApiBaseEndpoint(accessToken)).toThrow( 'Invalid token format' ) }) it('should return the core api endpoint when access token contains an "organization".', () => { expect( - getCoreApiEndpoint( + getCoreApiBaseEndpoint( 'eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCIsImtpZCI6ImFiYTRjYzYyOGQxZmNlM2ZiOTNhM2VlNTU4MjZlNDFjZmFmMThkYzJkZmYzYjA3MjIyNzQwMzgwZTkxOTlkNWQifQ.eyJvcmdhbml6YXRpb24iOnsiaWQiOiJlbldveEZNT25wIiwic2x1ZyI6InRoZS1ibHVlLWJyYW5kLTMiLCJlbnRlcnByaXNlIjpmYWxzZSwicmVnaW9uIjoiZXUtd2VzdC0xIn0sImFwcGxpY2F0aW9uIjp7ImlkIjoibkdWcWFpRVlOQSIsImNsaWVudF9pZCI6IjF1bEs3ZXdkUUZyak90LVlxZ0RQeXBRRzFYSmVtUGdaUDFvd3NpSG9tRDQiLCJraW5kIjoic2FsZXNfY2hhbm5lbCIsInB1YmxpYyI6dHJ1ZX0sInNjb3BlIjoibWFya2V0OmFsbCIsImV4cCI6MTcyNTM5OTc3OCwidGVzdCI6dHJ1ZSwicmFuZCI6MC4yMTIzMDUzMTE1NDg3Njk5NywiaWF0IjoxNzI1MzkyNTc4LCJpc3MiOiJodHRwczovL2F1dGguY29tbWVyY2VsYXllci5jbyJ9.aOjfJXPDQ-jY__XlZuaAhpboDCGPuaszSMjgBlGJ7ubjWmmHGIvgOewNusTKRcrvhgWsUPeGeBii9SdkxP0tHMejXb0qS8RZ7lAxhvfHlekytdhizLrTUoqAwGckgX9FJTzRh0rA57cFXLSuXXUvB5aUtFZ3CfxZ_YIRWUNSvbAsknYmH1WAy54QjpvM9jFD3iXv3ak9Q9DnxC80N98lgWfgjEgoW67jQSLHQT0r-cgbT8dbVUDOkUp4PnUQkjLWHcoejRFMlORTlQTSGjW8pYsYJyKhUa8FJ9UWcRGp55xIJLmdqbVcdYo0R2ESz32ek-Uu3OTO-JAbABSC-oN5Dzo_BHxS7ct_TcZV9Qxr-fGdZXD0C5PljMqmAQMeSRoZjdSLSLLKq5dyUx714NT9urE_BVLTkZ-jU-15iyS3aWy0qgmMKu3NOBmF_j-P7ohNNjDsdMz2ofZ8r2E_0QBgpC1LwdWt4r0S4eabiTskM4r-wrQSbctZae0veIrKQ4C3k1Wr1wR9b6CvZXr-IqaYg1VilMiffmVhbYl60iWg3IK5REKJFJ2hNm18A78OiBO4A5KiL6lk3N_26C9dJa9HolUbpopiIVgZxXUXRw6EohnU0e5IBnQES-3q9T_37lNgAKlbHpqDKKEWjdwqb3GRMdxzMj0rxELyBRBbx-W8_9s' ) ).toEqual('https://the-blue-brand-3.commercelayer.co') expect( - getCoreApiEndpoint( + getCoreApiBaseEndpoint( 'eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCIsImtpZCI6ImFiYTRjYzYyOGQxZmNlM2ZiOTNhM2VlNTU4MjZlNDFjZmFmMThkYzJkZmYzYjA3MjIyNzQwMzgwZTkxOTlkNWQifQ.eyJvcmdhbml6YXRpb24iOnsiaWQiOiJlbldveEZNT25wIiwic2x1ZyI6InRoZS1ibHVlLWJyYW5kLTMiLCJlbnRlcnByaXNlIjpmYWxzZSwicmVnaW9uIjoiZXUtd2VzdC0xIn0sImFwcGxpY2F0aW9uIjp7ImlkIjoibkdWcWFpRVlOQSIsImNsaWVudF9pZCI6IjF1bEs3ZXdkUUZyak90LVlxZ0RQeXBRRzFYSmVtUGdaUDFvd3NpSG9tRDQiLCJraW5kIjoic2FsZXNfY2hhbm5lbCIsInB1YmxpYyI6dHJ1ZX0sInNjb3BlIjoibWFya2V0OmFsbCIsImV4cCI6MTcyNTM5OTc3OCwidGVzdCI6dHJ1ZSwicmFuZCI6MC4yMTIzMDUzMTE1NDg3Njk5NywiaWF0IjoxNzI1MzkyNTc4LCJpc3MiOiJodHRwczovL2F1dGguc3RnMS5jb21tZXJjZWxheWVyLmNvIn0.oQRimLI0JHMnNtm_j-VwtqIjR-IafvukM8XB5RlxOmhfKvEAyCRbVDKQqk09n9p5cVBiOFbbiXxg8hSHXVqx-FfD14tDO7OgYzB9V7uWVrkOrof2kUTdy15IubpSDGk_X9qlwq1Rv5CgofCPRCvTlEI4Es2LcS6WLj-Q2pjqe6aP3tP6_Ne_bHz0oue5vXgs_noNLYPsYs4IIcwvPMU6R0EXnBJ5BdEplBiGhRyoQ_LUtUNKFQnoLeGk5_rKK6soP72w-Xi-tlR7rNw--fDbrTYH5XrkoD-QGiyMUk2Y-Vi6xpKNQ1wHky7WnuhOtJAy_-C90Zq6wfncQ5pBXT4rQ1HyNzzNgj9EpkkZTgNqy5fp8e62JKxpQRTz8es_4uVGLq_rn8CZZ7HX-C9-87AgebckDIWO9SCTtn8EOTMsu-wqzf3EQjFE35e78sNrVMqHMToW7QnCnellq4tdHp3oIiOHgIDjEQCQQytipH8cYIHqGxG-oUUatG77elFOvNH-9K38l1W0pfdgyfl27cnYbEDFWAf3yicrfiVlX77_PkTuE2dC910rNQ3Eg4XY7BxWMgoVSeBD2Bf1OjvyFCoxZEBfuC_7U7i5VR88pPGSF2dU9DGVwe-KhPasjv_p2O0lboL48ic7Icdvhy7c-MvGUTV5O8bxNjN0MJ39MYrwaUQ' ) ).toEqual('https://the-blue-brand-3.stg1.commercelayer.co') @@ -32,7 +32,7 @@ describe('getCoreApiEndpoint', () => { const accessToken = 'eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCIsImtpZCI6ImFiYTRjYzYyOGQxZmNlM2ZiOTNhM2VlNTU4MjZlNDFjZmFmMThkYzJkZmYzYjA3MjIyNzQwMzgwZTkxOTlkNWQifQ.eyJvcmdhbml6YXRpb24iOnsiaWQiOiJlbldveEZNT25wIiwic2x1ZyI6InRoZS1ibHVlLWJyYW5kLTMiLCJlbnRlcnByaXNlIjpmYWxzZSwicmVnaW9uIjoiZXUtd2VzdC0xIn0sImFwcGxpY2F0aW9uIjp7ImlkIjoibkdWcWFpRVlOQSIsImtpbmQiOiJzYWxlc19jaGFubmVsIiwicHVibGljIjp0cnVlfSwic2NvcGUiOiJtYXJrZXQ6YWxsIiwiZXhwIjoxNzEwOTU3NjMwLCJ0ZXN0Ijp0cnVlLCJyYW5kIjowLjM0Nzg4MjA0NDE1NDI0Njk1LCJpYXQiOjE3MTA5NDMyMzAsImlzcyI6Imh0dHBzOi8vY29tbWVyY2VsYXllci5pbyJ9.XhcMqwVwAh5wP2rbNyODBuPpTicwJjvK09KPmhe3nM1Lg0Hp0bIEQIOS81ohLyLE9ecaRH_7CsfLkAqYmRtdOTAKu9m4xvWw-Z_hBQpY67FTaikInMVltNffLvNDe5qmleNi5jnXtJl_yEGhtlDydpFBx1x8u3ofgtZSPFWm3Tl4KQoxFxT8CnnxPd2LTW_PfvnqS3QEGgvVnEXSTnJ41EU4dB8c9cZmmJY6e9SeH9fHVd469N_ipP4bymIL7kLPpkBBDuxxZ0787dOblGI31geAW-hHGbCpnj4_i5WJAVVsj_ImBtqt9Bihc-O-iHIMJlVOzWWXTAnmWGsHiwL5Ag' - expect(getCoreApiEndpoint(accessToken)).toEqual( + expect(getCoreApiBaseEndpoint(accessToken)).toEqual( 'https://the-blue-brand-3.commercelayer.io' ) }) diff --git a/packages/js-auth/src/getCoreApiEndpoint.ts b/packages/js-auth/src/getCoreApiBaseEndpoint.ts similarity index 65% rename from packages/js-auth/src/getCoreApiEndpoint.ts rename to packages/js-auth/src/getCoreApiBaseEndpoint.ts index ec214bf..ba8b03e 100644 --- a/packages/js-auth/src/getCoreApiEndpoint.ts +++ b/packages/js-auth/src/getCoreApiBaseEndpoint.ts @@ -3,12 +3,16 @@ import { jwtDecode } from './jwtDecode.js' /** * Derive the [Core API base endpoint](https://docs.commercelayer.io/core/api-specification#base-endpoint) given a valid access token. + * * @example * ```ts - * getCoreApiEndpoint('eyJhbGciOiJS...') //= "https://yourdomain.commercelayer.io" + * getCoreApiBaseEndpoint('eyJhbGciOiJS...') //= "https://yourdomain.commercelayer.io" * ``` + * + * The method requires a valid access token with an `organization` in the payload. + * When the organization is not set (e.g., provisioning token), it throws an `InvalidTokenError` exception. */ -export function getCoreApiEndpoint(accessToken: string): string { +export function getCoreApiBaseEndpoint(accessToken: string): string { const decodedJWT = jwtDecode(accessToken) if (!('organization' in decodedJWT.payload)) { diff --git a/packages/js-auth/src/index.ts b/packages/js-auth/src/index.ts index 6554a12..a2dc88f 100644 --- a/packages/js-auth/src/index.ts +++ b/packages/js-auth/src/index.ts @@ -27,6 +27,9 @@ export type { RevokeReturn } from './types/index.js' +export { getCoreApiBaseEndpoint } from './getCoreApiBaseEndpoint.js' + export { InvalidTokenError } from './errors/InvalidTokenError.js' export { TokenError } from './errors/TokenError.js' export { TokenExpiredError } from './errors/TokenExpiredError.js' + From 13f4b4700b3748e259b2bf86881c51131bae2145 Mon Sep 17 00:00:00 2001 From: Marco Montalbano Date: Tue, 10 Sep 2024 16:13:06 +0200 Subject: [PATCH 3/4] chore: update examples --- .ncurc.js | 15 ++ examples/bun/bun.lockb | Bin 99368 -> 99368 bytes examples/bun/index.ts | 3 +- examples/cjs/index.js | 3 +- examples/cjs/pnpm-lock.yaml | 16 +- examples/cloudflare-workers/package.json | 8 +- examples/cloudflare-workers/pnpm-lock.yaml | 169 ++++++++---------- examples/cloudflare-workers/src/index.ts | 4 +- examples/deno/index.ts | 3 +- examples/esm/index.js | 3 +- examples/esm/pnpm-lock.yaml | 16 +- examples/nextjs/package.json | 2 +- examples/nextjs/pnpm-lock.yaml | 107 +++++------ examples/nextjs/src/app/api/test/route.ts | 5 +- examples/nextjs/src/app/page.tsx | 6 +- .../src/middlewares/withCommerceLayer.ts | 5 +- package.json | 4 +- packages/js-auth/package.json | 2 +- packages/js-auth/src/index.ts | 1 - pnpm-lock.yaml | 138 +++++++------- 20 files changed, 261 insertions(+), 249 deletions(-) create mode 100644 .ncurc.js 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 b76637dc190862642ac63cb7dba68436c22239fd..cf8ed5e23b3d46f6deef5d05e818568347ba7e46 100755 GIT binary patch delta 160 zcmV;R0AK&8hz6*L29PcwK=$v>b%ats12hbnruc3lwQ`KDFouC*$>kOn&173nu}-Ed z0S1#X5-XEn5eTy=EX`X$HE#jRheAluux02WjNRz?mH9YP^g1{?v8Q7YrZ|S?dD%Lf zB{F9Yj($%Me3dM^+}3Z4iT-;&X4>vu;Q1NLvo(n9hXXb)GPfiU0f9vWHZC%^s8sARc<1M5|#G8wG{c~%Zpvpn|u}-Ed z0R@wR#VeCw5eTy=EX`X$GTOHG!h--t5ACUAMhj0mlC@5A2;CFlv`2>P zU-6X65z=|a$1qaO1h)ww`+c5YavPM{*9V9Bvo(n9hXXY(G`A!W0f9vWH7+!_s8s=5 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.tsx b/examples/nextjs/src/app/page.tsx index 994f270..c68ee58 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,8 +42,8 @@ export default async function Home() {
-
organization slug
-
{decodedJWT.payload.organization.slug}
+
organization slug: {decodedJWT.payload.organization.slug}
+
base endpoint: {getCoreApiBaseEndpoint(auth.accessToken)}
diff --git a/examples/nextjs/src/middlewares/withCommerceLayer.ts b/examples/nextjs/src/middlewares/withCommerceLayer.ts index e8da885..17f904c 100644 --- a/examples/nextjs/src/middlewares/withCommerceLayer.ts +++ b/examples/nextjs/src/middlewares/withCommerceLayer.ts @@ -1,6 +1,6 @@ import { NextResponse } from 'next/server' import type { WithMiddleware } from './types' -import { authenticate, jwtVerify } from '@commercelayer/js-auth' +import { authenticate, getCoreApiBaseEndpoint, jwtVerify } from '@commercelayer/js-auth' export const withCommerceLayer: WithMiddleware = (next = () => NextResponse.next()) => { return async (request, event) => { @@ -22,7 +22,8 @@ export const withCommerceLayer: WithMiddleware = (next = () => NextResponse.next return NextResponse.json({ from: 'middleware', - orgSlug: decodedJWT.payload.organization.slug + orgSlug: decodedJWT.payload.organization.slug, + baseEndpoint: getCoreApiBaseEndpoint(auth.accessToken) }) } diff --git a/package.json b/package.json index d32c0bd..d625d6f 100644 --- a/package.json +++ b/package.json @@ -19,10 +19,10 @@ }, "devDependencies": { "@commercelayer/eslint-config-ts": "^1.4.5", - "husky": "^9.1.4", + "husky": "^9.1.5", "lerna": "^8.1.8", "replace-in-file": "^8.1.0", - "typescript": "^5.5.4" + "typescript": "^5.6.2" }, "resolutions": { "tar": "^6.2.1" diff --git a/packages/js-auth/package.json b/packages/js-auth/package.json index 4e8e033..f7090b7 100644 --- a/packages/js-auth/package.json +++ b/packages/js-auth/package.json @@ -49,7 +49,7 @@ "@types/node": "^20", "jsonwebtoken": "^9.0.2", "tsup": "^8.2.4", - "typescript": "^5.5.4", + "typescript": "^5.6.2", "vitest": "^2.0.5", "vitest-fetch-mock": "^0.3.0" }, diff --git a/packages/js-auth/src/index.ts b/packages/js-auth/src/index.ts index a2dc88f..618f8ec 100644 --- a/packages/js-auth/src/index.ts +++ b/packages/js-auth/src/index.ts @@ -32,4 +32,3 @@ export { getCoreApiBaseEndpoint } from './getCoreApiBaseEndpoint.js' export { InvalidTokenError } from './errors/InvalidTokenError.js' export { TokenError } from './errors/TokenError.js' export { TokenExpiredError } from './errors/TokenExpiredError.js' - diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fbe9db1..a30a7dd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -13,10 +13,10 @@ importers: devDependencies: '@commercelayer/eslint-config-ts': specifier: ^1.4.5 - version: 1.4.5(eslint@8.57.0)(typescript@5.5.4) + version: 1.4.5(eslint@8.57.0)(typescript@5.6.2) husky: - specifier: ^9.1.4 - version: 9.1.4 + specifier: ^9.1.5 + version: 9.1.5 lerna: specifier: ^8.1.8 version: 8.1.8(encoding@0.1.13) @@ -24,8 +24,8 @@ importers: specifier: ^8.1.0 version: 8.1.0 typescript: - specifier: ^5.5.4 - version: 5.5.4 + specifier: ^5.6.2 + version: 5.6.2 packages/js-auth: devDependencies: @@ -40,10 +40,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) @@ -2040,8 +2040,8 @@ packages: resolution: {integrity: sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==} engines: {node: '>=16.17.0'} - husky@9.1.4: - resolution: {integrity: sha512-bho94YyReb4JV7LYWRWxZ/xr6TtOTt8cMfmQ39MQYJ7f/YE268s3GdghGwi+y4zAeqewE5zYLvuhV0M0ijsDEA==} + husky@9.1.5: + resolution: {integrity: sha512-rowAVRUBfI0b4+niA4SJMhfQwc107VLkBUgEYYAOQAbqDCnra1nYh83hF/MDmhYs9t9n1E3DuKOrs2LYNC+0Ag==} engines: {node: '>=18'} hasBin: true @@ -3575,8 +3575,8 @@ packages: typedarray@0.0.6: resolution: {integrity: sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==} - 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 @@ -3823,19 +3823,19 @@ snapshots: js-tokens: 4.0.0 picocolors: 1.0.1 - '@commercelayer/eslint-config-ts@1.4.5(eslint@8.57.0)(typescript@5.5.4)': + '@commercelayer/eslint-config-ts@1.4.5(eslint@8.57.0)(typescript@5.6.2)': dependencies: - '@typescript-eslint/eslint-plugin': 7.9.0(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4) - '@typescript-eslint/parser': 7.9.0(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/eslint-plugin': 7.9.0(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0)(typescript@5.6.2) + '@typescript-eslint/parser': 7.9.0(eslint@8.57.0)(typescript@5.6.2) eslint: 8.57.0 - eslint-config-love: 43.1.0(@typescript-eslint/eslint-plugin@7.9.0(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0))(eslint-plugin-n@16.6.2(eslint@8.57.0))(eslint-plugin-promise@6.1.1(eslint@8.57.0))(eslint@8.57.0)(typescript@5.5.4) + eslint-config-love: 43.1.0(@typescript-eslint/eslint-plugin@7.9.0(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0)(typescript@5.6.2))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0))(eslint-plugin-n@16.6.2(eslint@8.57.0))(eslint-plugin-promise@6.1.1(eslint@8.57.0))(eslint@8.57.0)(typescript@5.6.2) eslint-config-prettier: 9.1.0(eslint@8.57.0) - eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0) + eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0) eslint-plugin-n: 16.6.2(eslint@8.57.0) eslint-plugin-prettier: 5.1.3(eslint-config-prettier@9.1.0(eslint@8.57.0))(eslint@8.57.0)(prettier@3.2.5) eslint-plugin-promise: 6.1.1(eslint@8.57.0) prettier: 3.2.5 - typescript: 5.5.4 + typescript: 5.6.2 transitivePeerDependencies: - '@types/eslint' - eslint-import-resolver-typescript @@ -4052,7 +4052,7 @@ snapshots: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.4.15 - '@lerna/create@8.1.8(encoding@0.1.13)(typescript@5.5.4)': + '@lerna/create@8.1.8(encoding@0.1.13)(typescript@5.6.2)': dependencies: '@npmcli/arborist': 7.5.4 '@npmcli/package-json': 5.2.0 @@ -4070,7 +4070,7 @@ snapshots: console-control-strings: 1.1.0 conventional-changelog-core: 5.0.1 conventional-recommended-bump: 7.0.1 - cosmiconfig: 8.3.6(typescript@5.5.4) + cosmiconfig: 8.3.6(typescript@5.6.2) dedent: 1.5.3 execa: 5.0.0 fs-extra: 11.2.0 @@ -4577,47 +4577,47 @@ snapshots: '@types/normalize-package-data@2.4.4': {} - '@typescript-eslint/eslint-plugin@7.9.0(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4)': + '@typescript-eslint/eslint-plugin@7.9.0(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0)(typescript@5.6.2)': dependencies: '@eslint-community/regexpp': 4.10.0 - '@typescript-eslint/parser': 7.9.0(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/parser': 7.9.0(eslint@8.57.0)(typescript@5.6.2) '@typescript-eslint/scope-manager': 7.9.0 - '@typescript-eslint/type-utils': 7.9.0(eslint@8.57.0)(typescript@5.5.4) - '@typescript-eslint/utils': 7.9.0(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/type-utils': 7.9.0(eslint@8.57.0)(typescript@5.6.2) + '@typescript-eslint/utils': 7.9.0(eslint@8.57.0)(typescript@5.6.2) '@typescript-eslint/visitor-keys': 7.9.0 eslint: 8.57.0 graphemer: 1.4.0 ignore: 5.3.1 natural-compare: 1.4.0 - ts-api-utils: 1.3.0(typescript@5.5.4) + ts-api-utils: 1.3.0(typescript@5.6.2) optionalDependencies: - typescript: 5.5.4 + typescript: 5.6.2 transitivePeerDependencies: - supports-color - '@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.5.4)': + '@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.2)': dependencies: '@typescript-eslint/scope-manager': 6.21.0 '@typescript-eslint/types': 6.21.0 - '@typescript-eslint/typescript-estree': 6.21.0(typescript@5.5.4) + '@typescript-eslint/typescript-estree': 6.21.0(typescript@5.6.2) '@typescript-eslint/visitor-keys': 6.21.0 debug: 4.3.4 eslint: 8.57.0 optionalDependencies: - typescript: 5.5.4 + typescript: 5.6.2 transitivePeerDependencies: - supports-color - '@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.5.4)': + '@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.6.2)': dependencies: '@typescript-eslint/scope-manager': 7.9.0 '@typescript-eslint/types': 7.9.0 - '@typescript-eslint/typescript-estree': 7.9.0(typescript@5.5.4) + '@typescript-eslint/typescript-estree': 7.9.0(typescript@5.6.2) '@typescript-eslint/visitor-keys': 7.9.0 debug: 4.3.4 eslint: 8.57.0 optionalDependencies: - typescript: 5.5.4 + typescript: 5.6.2 transitivePeerDependencies: - supports-color @@ -4631,15 +4631,15 @@ snapshots: '@typescript-eslint/types': 7.9.0 '@typescript-eslint/visitor-keys': 7.9.0 - '@typescript-eslint/type-utils@7.9.0(eslint@8.57.0)(typescript@5.5.4)': + '@typescript-eslint/type-utils@7.9.0(eslint@8.57.0)(typescript@5.6.2)': dependencies: - '@typescript-eslint/typescript-estree': 7.9.0(typescript@5.5.4) - '@typescript-eslint/utils': 7.9.0(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/typescript-estree': 7.9.0(typescript@5.6.2) + '@typescript-eslint/utils': 7.9.0(eslint@8.57.0)(typescript@5.6.2) debug: 4.3.4 eslint: 8.57.0 - ts-api-utils: 1.3.0(typescript@5.5.4) + ts-api-utils: 1.3.0(typescript@5.6.2) optionalDependencies: - typescript: 5.5.4 + typescript: 5.6.2 transitivePeerDependencies: - supports-color @@ -4647,7 +4647,7 @@ snapshots: '@typescript-eslint/types@7.9.0': {} - '@typescript-eslint/typescript-estree@6.21.0(typescript@5.5.4)': + '@typescript-eslint/typescript-estree@6.21.0(typescript@5.6.2)': dependencies: '@typescript-eslint/types': 6.21.0 '@typescript-eslint/visitor-keys': 6.21.0 @@ -4656,13 +4656,13 @@ snapshots: is-glob: 4.0.3 minimatch: 9.0.3 semver: 7.6.2 - ts-api-utils: 1.3.0(typescript@5.5.4) + ts-api-utils: 1.3.0(typescript@5.6.2) optionalDependencies: - typescript: 5.5.4 + typescript: 5.6.2 transitivePeerDependencies: - supports-color - '@typescript-eslint/typescript-estree@7.9.0(typescript@5.5.4)': + '@typescript-eslint/typescript-estree@7.9.0(typescript@5.6.2)': dependencies: '@typescript-eslint/types': 7.9.0 '@typescript-eslint/visitor-keys': 7.9.0 @@ -4671,18 +4671,18 @@ snapshots: is-glob: 4.0.3 minimatch: 9.0.4 semver: 7.6.2 - ts-api-utils: 1.3.0(typescript@5.5.4) + ts-api-utils: 1.3.0(typescript@5.6.2) optionalDependencies: - typescript: 5.5.4 + typescript: 5.6.2 transitivePeerDependencies: - supports-color - '@typescript-eslint/utils@7.9.0(eslint@8.57.0)(typescript@5.5.4)': + '@typescript-eslint/utils@7.9.0(eslint@8.57.0)(typescript@5.6.2)': dependencies: '@eslint-community/eslint-utils': 4.4.0(eslint@8.57.0) '@typescript-eslint/scope-manager': 7.9.0 '@typescript-eslint/types': 7.9.0 - '@typescript-eslint/typescript-estree': 7.9.0(typescript@5.5.4) + '@typescript-eslint/typescript-estree': 7.9.0(typescript@5.6.2) eslint: 8.57.0 transitivePeerDependencies: - supports-color @@ -5162,14 +5162,14 @@ snapshots: core-util-is@1.0.3: {} - cosmiconfig@8.3.6(typescript@5.5.4): + cosmiconfig@8.3.6(typescript@5.6.2): dependencies: import-fresh: 3.3.0 js-yaml: 4.1.0 parse-json: 5.2.0 path-type: 4.0.0 optionalDependencies: - typescript: 5.5.4 + typescript: 5.6.2 cross-fetch@4.0.0(encoding@0.1.13): dependencies: @@ -5456,16 +5456,16 @@ snapshots: eslint: 8.57.0 semver: 7.6.2 - eslint-config-love@43.1.0(@typescript-eslint/eslint-plugin@7.9.0(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0))(eslint-plugin-n@16.6.2(eslint@8.57.0))(eslint-plugin-promise@6.1.1(eslint@8.57.0))(eslint@8.57.0)(typescript@5.5.4): + eslint-config-love@43.1.0(@typescript-eslint/eslint-plugin@7.9.0(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0)(typescript@5.6.2))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0))(eslint-plugin-n@16.6.2(eslint@8.57.0))(eslint-plugin-promise@6.1.1(eslint@8.57.0))(eslint@8.57.0)(typescript@5.6.2): dependencies: - '@typescript-eslint/eslint-plugin': 7.9.0(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4) - '@typescript-eslint/parser': 6.21.0(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/eslint-plugin': 7.9.0(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0)(typescript@5.6.2) + '@typescript-eslint/parser': 6.21.0(eslint@8.57.0)(typescript@5.6.2) eslint: 8.57.0 - eslint-config-standard: 17.1.0(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0))(eslint-plugin-n@16.6.2(eslint@8.57.0))(eslint-plugin-promise@6.1.1(eslint@8.57.0))(eslint@8.57.0) - eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0) + eslint-config-standard: 17.1.0(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0))(eslint-plugin-n@16.6.2(eslint@8.57.0))(eslint-plugin-promise@6.1.1(eslint@8.57.0))(eslint@8.57.0) + eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0) eslint-plugin-n: 16.6.2(eslint@8.57.0) eslint-plugin-promise: 6.1.1(eslint@8.57.0) - typescript: 5.5.4 + typescript: 5.6.2 transitivePeerDependencies: - supports-color @@ -5473,10 +5473,10 @@ snapshots: dependencies: eslint: 8.57.0 - eslint-config-standard@17.1.0(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0))(eslint-plugin-n@16.6.2(eslint@8.57.0))(eslint-plugin-promise@6.1.1(eslint@8.57.0))(eslint@8.57.0): + eslint-config-standard@17.1.0(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0))(eslint-plugin-n@16.6.2(eslint@8.57.0))(eslint-plugin-promise@6.1.1(eslint@8.57.0))(eslint@8.57.0): dependencies: eslint: 8.57.0 - eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0) + eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0) eslint-plugin-n: 16.6.2(eslint@8.57.0) eslint-plugin-promise: 6.1.1(eslint@8.57.0) @@ -5488,11 +5488,11 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-module-utils@2.8.1(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.5.4))(eslint-import-resolver-node@0.3.9)(eslint@8.57.0): + eslint-module-utils@2.8.1(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.6.2))(eslint-import-resolver-node@0.3.9)(eslint@8.57.0): dependencies: debug: 3.2.7 optionalDependencies: - '@typescript-eslint/parser': 7.9.0(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/parser': 7.9.0(eslint@8.57.0)(typescript@5.6.2) eslint: 8.57.0 eslint-import-resolver-node: 0.3.9 transitivePeerDependencies: @@ -5505,7 +5505,7 @@ snapshots: eslint: 8.57.0 eslint-compat-utils: 0.5.0(eslint@8.57.0) - eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0): + eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.6.2))(eslint@8.57.0): dependencies: array-includes: 3.1.8 array.prototype.findlastindex: 1.2.5 @@ -5515,7 +5515,7 @@ snapshots: doctrine: 2.1.0 eslint: 8.57.0 eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.5.4))(eslint-import-resolver-node@0.3.9)(eslint@8.57.0) + eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.9.0(eslint@8.57.0)(typescript@5.6.2))(eslint-import-resolver-node@0.3.9)(eslint@8.57.0) hasown: 2.0.2 is-core-module: 2.13.1 is-glob: 4.0.3 @@ -5526,7 +5526,7 @@ snapshots: semver: 6.3.1 tsconfig-paths: 3.15.0 optionalDependencies: - '@typescript-eslint/parser': 7.9.0(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/parser': 7.9.0(eslint@8.57.0)(typescript@5.6.2) transitivePeerDependencies: - eslint-import-resolver-typescript - eslint-import-resolver-webpack @@ -5979,7 +5979,7 @@ snapshots: human-signals@5.0.0: {} - husky@9.1.4: {} + husky@9.1.5: {} iconv-lite@0.4.24: dependencies: @@ -6298,7 +6298,7 @@ snapshots: lerna@8.1.8(encoding@0.1.13): dependencies: - '@lerna/create': 8.1.8(encoding@0.1.13)(typescript@5.5.4) + '@lerna/create': 8.1.8(encoding@0.1.13)(typescript@5.6.2) '@npmcli/arborist': 7.5.4 '@npmcli/package-json': 5.2.0 '@npmcli/run-script': 8.1.0 @@ -6316,7 +6316,7 @@ snapshots: conventional-changelog-angular: 7.0.0 conventional-changelog-core: 5.0.1 conventional-recommended-bump: 7.0.1 - cosmiconfig: 8.3.6(typescript@5.5.4) + cosmiconfig: 8.3.6(typescript@5.6.2) dedent: 1.5.3 envinfo: 7.13.0 execa: 5.0.0 @@ -6369,7 +6369,7 @@ snapshots: strong-log-transformer: 2.1.0 tar: 6.2.1 temp-dir: 1.0.0 - typescript: 5.5.4 + typescript: 5.6.2 upath: 2.0.1 uuid: 10.0.0 validate-npm-package-license: 3.0.4 @@ -7585,9 +7585,9 @@ snapshots: trim-newlines@3.0.1: {} - ts-api-utils@1.3.0(typescript@5.5.4): + ts-api-utils@1.3.0(typescript@5.6.2): dependencies: - typescript: 5.5.4 + typescript: 5.6.2 ts-interface-checker@0.1.13: {} @@ -7606,7 +7606,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 @@ -7626,7 +7626,7 @@ snapshots: tree-kill: 1.2.2 optionalDependencies: postcss: 8.4.38 - typescript: 5.5.4 + typescript: 5.6.2 transitivePeerDependencies: - jiti - supports-color @@ -7691,7 +7691,7 @@ snapshots: typedarray@0.0.6: {} - typescript@5.5.4: {} + typescript@5.6.2: {} uglify-js@3.17.4: optional: true From 321ef5566a4ccc67d69e83ed6d297d5131d40a48 Mon Sep 17 00:00:00 2001 From: Marco Montalbano Date: Tue, 10 Sep 2024 16:17:00 +0200 Subject: [PATCH 4/4] chore: update nextjs example with links to middleware and api --- examples/nextjs/src/app/page.module.css | 1 + examples/nextjs/src/app/page.tsx | 38 ++++--------------------- 2 files changed, 7 insertions(+), 32 deletions(-) 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 c68ee58..28a898e 100644 --- a/examples/nextjs/src/app/page.tsx +++ b/examples/nextjs/src/app/page.tsx @@ -48,53 +48,27 @@ export default async function Home() {