@scaleway/auth-scw 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,7 +16,7 @@ pnpm add @scaleway/auth-scw
16
16
 
17
17
  ### Prerequisites
18
18
 
19
- ```
19
+ ```text
20
20
  cd packages/auth-scw
21
21
  ```
22
22
 
@@ -27,15 +27,15 @@ pnpm build # Build the package
27
27
  pnpm watch # Build the package and watch for changes
28
28
  ```
29
29
 
30
- # Repo pattern
30
+ ## Repo pattern
31
31
 
32
- ## How does renew token works? Single or multiple organisation
32
+ ### How does renew token works? Single or multiple organisation
33
33
 
34
34
  **Reminder:** A COOKIE is used to syncronise jwt between tabs
35
35
 
36
36
  When users open severals tabs, syncronoisation of token between tabs can become tedious, here are the scenarios:
37
37
 
38
- ### Single organisation
38
+ #### Single organisation
39
39
 
40
40
  Let say you have 2 tabs on the same organisation, `tab1`, `tab2` with the same JWT, let's call it, `JWT_A`
41
41
 
@@ -56,7 +56,7 @@ Let say you have 2 tabs on the same organisation, `tab1`, `tab2` with the same J
56
56
  1. A renew request on `tab1` is attempted with the last JWT from cookie (so JWT_B) and also because both tabs are on the same organisation therefore, the same jwt can be used for both.
57
57
  2. the renew happen without issue and both tabs can be used without problems
58
58
 
59
- ### Multiple organisation
59
+ #### Multiple organisation
60
60
 
61
61
  Alright, read the Single organisation scenario if you haven't.
62
62
  Here let's consider we have `tab1` and `tab2` on `Orga_A` with `JWT_A` and `tab3` on `Orga_B` with `JWT_B`:
@@ -1,5 +1,4 @@
1
1
  import { EncodedJWT } from "./types/index.js";
2
-
3
2
  //#region src/constants.d.ts
4
3
  declare const EmptySession: NonNullable<EncodedJWT>;
5
4
  //#endregion
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { AudienceIdType, AuthScwContextType, EncodedJWT } from "./types/index.js";
2
2
  import { EmptySession } from "./constants.js";
3
3
  import { AuthScwProvider, useAuthScw } from "./useAuthScw/AuthScwProvider.js";
4
+ import "./useAuthScw/index.js";
4
5
  import { AuthStoreManager } from "./useAuthScw/authStoreManager.js";
5
6
  export { type AudienceIdType, type AuthScwContextType, AuthScwProvider, AuthStoreManager, EmptySession, type EncodedJWT, useAuthScw };
@@ -1,5 +1,4 @@
1
1
  import { API, DeleteJWTRequest, EncodedJWT, JWT, UnauthenticatedAPI, UnauthenticatedApiRenewJWTRequest } from "./types.js";
2
-
3
2
  //#region src/types/iam/index.d.ts
4
3
  declare namespace Iamv1alpha1 {
5
4
  export type { API, UnauthenticatedAPI };
@@ -1,6 +1,5 @@
1
1
  import { API } from "@scaleway/sdk-client";
2
2
  import { Iamv1alpha1 } from "@scaleway/sdk-iam";
3
-
4
3
  //#region src/types/iam/types.d.ts
5
4
  type JWT = Iamv1alpha1.JWT;
6
5
  type EncodedJWT = Iamv1alpha1.EncodedJWT;
@@ -2,7 +2,6 @@ import { Iamv1alpha1 } from "./iam/index.js";
2
2
  import { audienceIdSchema, jwtSchema } from "../zodSchemas.js";
3
3
  import { z } from "zod";
4
4
  import { API, Client, Settings } from "@scaleway/sdk-client";
5
-
6
5
  //#region src/types/index.d.ts
7
6
  type EncodedJWT = z.infer<typeof jwtSchema>;
8
7
  type AudienceIdType = z.infer<typeof audienceIdSchema>;
@@ -34,12 +33,8 @@ declare class IamV1alpha1UnauthenticatedAPI extends API {
34
33
  renewJWT: Iamv1alpha1.UnauthenticatedAPI['renewJWT'];
35
34
  }
36
35
  type ConfigurationClientAPIs = {
37
- IamV1Alpha1: {
38
- new (client: Client): IamV1alpha1API;
39
- };
40
- IamUnauthenticatedV1Alpha1: {
41
- new (client: Client): IamV1alpha1UnauthenticatedAPI;
42
- };
36
+ IamV1Alpha1: new (client: Client) => IamV1alpha1API;
37
+ IamUnauthenticatedV1Alpha1: new (client: Client) => IamV1alpha1UnauthenticatedAPI;
43
38
  };
44
39
  type ConfigAuthProvider = {
45
40
  clientSettings: Settings;
@@ -1,6 +1,5 @@
1
1
  import { AuthScwContextType, ConfigAuthProvider, CookieConfigType, OnError } from "../types/index.js";
2
2
  import { ReactNode } from "react";
3
-
4
3
  //#region src/useAuthScw/AuthScwProvider.d.ts
5
4
  type AuthProviderParamType = ConfigAuthProvider & {
6
5
  children: ReactNode;
@@ -10,15 +9,6 @@ type AuthProviderParamType = ConfigAuthProvider & {
10
9
  cookieConfig?: CookieConfigType;
11
10
  };
12
11
  declare const useAuthScw: () => AuthScwContextType;
13
- declare const AuthScwProvider: ({
14
- clientSettings,
15
- IamV1Alpha1,
16
- IamUnauthenticatedV1Alpha1,
17
- children,
18
- cookieSuffix,
19
- cookieConfig,
20
- urlParamTokenName,
21
- onError
22
- }: AuthProviderParamType) => import("react").JSX.Element;
12
+ declare const AuthScwProvider: ({ clientSettings, IamV1Alpha1, IamUnauthenticatedV1Alpha1, children, cookieSuffix, cookieConfig, urlParamTokenName, onError }: AuthProviderParamType) => import("react").JSX.Element;
23
13
  //#endregion
24
14
  export { AuthProviderParamType, AuthScwProvider, useAuthScw };
@@ -1,6 +1,6 @@
1
1
  import { AudienceIdType, EncodedJWT } from "../types/index.js";
2
-
3
2
  //#region src/useAuthScw/authStoreManager.d.ts
3
+ declare const getUniqueHostnameString: (inputString: string) => string;
4
4
  declare const AuthStoreManager: {
5
5
  COOKIE_AGE: number;
6
6
  DOMAIN: string;
@@ -11,13 +11,10 @@ declare const AuthStoreManager: {
11
11
  getJwt(audienceId: string): EncodedJWT | null;
12
12
  getKeyAudienceId(): string;
13
13
  getKeySession(audienceId: string): string;
14
- getUniqueHostnameString: (inputString: string) => string;
14
+ getUniqueHostnameString: typeof getUniqueHostnameString;
15
15
  SUFFIX_KEY: string;
16
16
  setAudienceId(audienceId: string): void;
17
- setJwt({
18
- jwtInfo,
19
- setAudienceId
20
- }: {
17
+ setJwt({ jwtInfo, setAudienceId }: {
21
18
  jwtInfo: EncodedJWT;
22
19
  setAudienceId?: boolean;
23
20
  }): void;
@@ -5,7 +5,7 @@ import { parseCookie, stringifySetCookie } from "cookie";
5
5
  const KEY_SESSION = "_scw_session";
6
6
  const KEY_AUDIENCE_ID = "_scw_audience_id";
7
7
  const DEFAULT_SUFFIX_KEY = "";
8
- const COOKIE_AGE = 3600 * 24 * 31;
8
+ const COOKIE_AGE = 2678400;
9
9
  let cookieConfig = COOKIE_CONFIG;
10
10
  const DOMAIN = typeof window !== "undefined" ? globalThis.location.hostname : "";
11
11
  const getUniqueHostnameString = (inputString) => inputString.replaceAll(".", "_").replaceAll("-", "_");
@@ -1,6 +1,5 @@
1
1
  import { Iamv1alpha1 } from "./types/iam/index.js";
2
2
  import { z } from "zod";
3
-
4
3
  //#region src/zodSchemas.d.ts
5
4
  type TransformJWT = Omit<Iamv1alpha1.JWT, 'createdAt' | 'updatedAt' | 'expiresAt'> & {
6
5
  createdAt?: string | Date;
@@ -12,7 +11,7 @@ type ValidateJWTSchema = {
12
11
  token: string;
13
12
  renewToken: string;
14
13
  };
15
- declare const jwtSchema: z.ZodType<ValidateJWTSchema>;
14
+ declare const jwtSchema: z.ZodType<ValidateJWTSchema, unknown, z.core.$ZodTypeInternals<ValidateJWTSchema, unknown>>;
16
15
  declare const audienceIdSchema: z.ZodObject<{
17
16
  audienceId: z.ZodString;
18
17
  }, z.core.$strip>;
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  //#region src/zodSchemas.ts
3
- const jwtSchema = z.object({
3
+ const rawJwtSchema = z.object({
4
4
  jwt: z.object({
5
5
  audienceId: z.string().min(1),
6
6
  createdAt: z.union([z.string().min(1), z.date()]).optional(),
@@ -14,6 +14,7 @@ const jwtSchema = z.object({
14
14
  renewToken: z.string().min(1),
15
15
  token: z.string().min(1)
16
16
  });
17
- const audienceIdSchema = z.object({ audienceId: z.string().min(1) });
17
+ const jwtSchema = z.compile(rawJwtSchema);
18
+ const audienceIdSchema = z.compile(z.object({ audienceId: z.string().min(1) }));
18
19
  //#endregion
19
20
  export { audienceIdSchema, jwtSchema };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scaleway/auth-scw",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Auth Scaleway",
5
5
  "homepage": "https://github.com/scaleway/scaleway-lib/tree/main/packages/auth-scw",
6
6
  "bugs": {
@@ -28,17 +28,17 @@
28
28
  "dependencies": {
29
29
  "cookie": "2.0.1",
30
30
  "date-fns": "4.4.0",
31
- "zod": "4.4.3"
31
+ "zod": "4.5.4"
32
32
  },
33
33
  "devDependencies": {
34
- "@scaleway/sdk-client": "2.4.1",
35
- "@scaleway/sdk-iam": "2.9.4",
36
- "@types/react": "19.2.17",
37
- "react": "19.2.7"
34
+ "@scaleway/sdk-client": "2.6.0",
35
+ "@scaleway/sdk-iam": "2.14.0",
36
+ "@types/react": "19.2.18",
37
+ "react": "19.2.8"
38
38
  },
39
39
  "peerDependencies": {
40
- "@scaleway/sdk-client": "2.4.1",
41
- "@scaleway/sdk-iam": "2.9.4",
40
+ "@scaleway/sdk-client": "2.6.0",
41
+ "@scaleway/sdk-iam": "2.14.0",
42
42
  "react": ">=18.0"
43
43
  },
44
44
  "scripts": {