@lokalise/harmony 1.16.0 → 1.17.0-exp-jwtheaderfactorysharedauth.1

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.
Files changed (44) hide show
  1. package/README.md +31 -21
  2. package/dist/harmony.cjs +1 -1
  3. package/dist/harmony.mjs +915 -762
  4. package/dist/types/src/features/auth/core/headers/headerBuilder.d.ts +199 -0
  5. package/dist/types/src/features/auth/core/middleware/jwtAuthHeaderBuilderMiddleware.d.ts +10 -0
  6. package/dist/types/src/features/auth/core/middleware/publicApiHeaderBuilderMiddleware.d.ts +3 -0
  7. package/dist/types/src/features/auth/core/types/jwtTokenPayload.d.ts +2 -2
  8. package/dist/types/src/features/auth/core/types/jwtTokenPayload.fixture.d.ts +3 -3
  9. package/dist/types/src/features/auth/core/utils/makeAuthHeader.d.ts +2 -2
  10. package/dist/types/src/features/auth/errors/UnauthorizedError.d.ts +4 -0
  11. package/dist/types/src/features/auth/frontend/hooks/useAuthenticatedProjectContributor.d.ts +4 -1
  12. package/dist/types/src/features/auth/frontend/hooks/useAuthenticatedSessionPayload.d.ts +1 -1
  13. package/dist/types/src/features/auth/frontend/hooks/useAuthenticatedUser.d.ts +4 -1
  14. package/dist/types/src/features/auth/frontend/hooks/useGetPromotedClassicSessionJwtQuery.d.ts +4 -2
  15. package/dist/types/src/features/auth/frontend/services/generateTokenFromClassicSession.d.ts +5 -0
  16. package/dist/types/src/features/auth/frontend/services/refreshExpiredToken.d.ts +6 -0
  17. package/dist/types/src/features/auth/frontend/utils/cookieTokenUtils.d.ts +2 -2
  18. package/dist/types/src/features/auth/node.d.ts +6 -4
  19. package/dist/types/src/features/publicApi/contributors.d.ts +19 -1
  20. package/dist/types/src/features/publicApi/hooks/useCreateProjectMutation.d.ts +4 -2
  21. package/dist/types/src/features/publicApi/hooks/useGetTeamUsersQuery.d.ts +4 -2
  22. package/dist/types/src/features/publicApi/hooks/useGetUserTokenQuery.d.ts +6 -5
  23. package/dist/types/src/features/publicApi/hooks/useListProjectLanguagesQuery.d.ts +10 -1
  24. package/dist/types/src/features/publicApi/hooks/useListProjectsQuery.d.ts +4 -2
  25. package/dist/types/src/features/publicApi/hooks/useRetrieveContributorQuery.d.ts +4 -2
  26. package/dist/types/src/features/publicApi/hooks/useRetrieveProjectQuery.d.ts +4 -2
  27. package/dist/types/src/features/publicApi/hooks/useUpdateProjectMutation.d.ts +4 -2
  28. package/dist/types/src/features/publicApi/languages.d.ts +19 -1
  29. package/dist/types/src/features/publicApi/node.d.ts +1 -1
  30. package/dist/types/src/features/publicApi/projects.d.ts +76 -4
  31. package/dist/types/src/features/publicApi/teamUsers.d.ts +22 -4
  32. package/dist/types/src/features/publicApi/types/contributorTypes.d.ts +20 -0
  33. package/dist/types/src/features/publicApi/types/projectTypes.d.ts +20 -0
  34. package/dist/types/src/features/publicApi/types/sharedTypes.d.ts +57 -0
  35. package/dist/types/src/features/publicApi/types/teamUserTypes.d.ts +20 -0
  36. package/dist/types/src/features/publicApi/types/userTokenTypes.d.ts +2 -2
  37. package/dist/types/src/features/publicApi/userToken.d.ts +1 -1
  38. package/package.json +1 -1
  39. package/dist/types/src/features/auth/core/middleware/jwtAuthMiddleware.d.ts +0 -17
  40. package/dist/types/src/features/auth/core/middleware/publicApiHeadersMiddleware.d.ts +0 -5
  41. package/dist/types/src/features/auth/frontend/middleware/clientSideJwtAuthMiddleware.d.ts +0 -9
  42. package/dist/types/src/features/auth/frontend/middleware/promoteClassicSessionToJwtMiddleware.d.ts +0 -14
  43. package/dist/types/src/features/auth/frontend/middleware/promoteClassicSessionToJwtMiddleware.test.d.ts +0 -1
  44. /package/dist/types/src/features/auth/core/{middleware/jwtAuthMiddleware.test.d.ts → headers/headerBuilder.test.d.ts} +0 -0
@@ -331,7 +331,25 @@ export declare const createProject: import('@lokalise/universal-ts-utils/node').
331
331
  unbalanced_brackets: number;
332
332
  };
333
333
  } | undefined;
334
- }>, undefined, undefined, undefined, false, false>;
334
+ }>, undefined, undefined, import('zod').ZodIntersection<import('zod').ZodUnion<[import('zod').ZodObject<{
335
+ Authorization: import('zod').ZodString;
336
+ }, "strip", import('zod').ZodTypeAny, {
337
+ Authorization: string;
338
+ }, {
339
+ Authorization: string;
340
+ }>, import('zod').ZodObject<{
341
+ 'X-API-Token': import('zod').ZodString;
342
+ }, "strip", import('zod').ZodTypeAny, {
343
+ 'X-API-Token': string;
344
+ }, {
345
+ 'X-API-Token': string;
346
+ }>]>, import('zod').ZodObject<{
347
+ 'X-Lokalise-Plugin': import('zod').ZodString;
348
+ }, "strip", import('zod').ZodTypeAny, {
349
+ 'X-Lokalise-Plugin': string;
350
+ }, {
351
+ 'X-Lokalise-Plugin': string;
352
+ }>>, false, false>;
335
353
  /**
336
354
  * Public API router definition for listing all projects
337
355
  */
@@ -771,7 +789,25 @@ export declare const listProjects: import('@lokalise/universal-ts-utils/node').G
771
789
  include_statistics?: 0 | 1 | undefined;
772
790
  include_settings?: 0 | 1 | undefined;
773
791
  limit?: number | undefined;
774
- }>, undefined, false, false>;
792
+ }>, import('zod').ZodIntersection<import('zod').ZodUnion<[import('zod').ZodObject<{
793
+ Authorization: import('zod').ZodString;
794
+ }, "strip", import('zod').ZodTypeAny, {
795
+ Authorization: string;
796
+ }, {
797
+ Authorization: string;
798
+ }>, import('zod').ZodObject<{
799
+ 'X-API-Token': import('zod').ZodString;
800
+ }, "strip", import('zod').ZodTypeAny, {
801
+ 'X-API-Token': string;
802
+ }, {
803
+ 'X-API-Token': string;
804
+ }>]>, import('zod').ZodObject<{
805
+ 'X-Lokalise-Plugin': import('zod').ZodString;
806
+ }, "strip", import('zod').ZodTypeAny, {
807
+ 'X-Lokalise-Plugin': string;
808
+ }, {
809
+ 'X-Lokalise-Plugin': string;
810
+ }>>, false, false>;
775
811
  /**
776
812
  * Public API router definition for retrieving a project
777
813
  */
@@ -1077,7 +1113,25 @@ export declare const retrieveProject: import('@lokalise/universal-ts-utils/node'
1077
1113
  project_id: string;
1078
1114
  }, {
1079
1115
  project_id: string;
1080
- }>, undefined, undefined, false, false>;
1116
+ }>, undefined, import('zod').ZodIntersection<import('zod').ZodUnion<[import('zod').ZodObject<{
1117
+ Authorization: import('zod').ZodString;
1118
+ }, "strip", import('zod').ZodTypeAny, {
1119
+ Authorization: string;
1120
+ }, {
1121
+ Authorization: string;
1122
+ }>, import('zod').ZodObject<{
1123
+ 'X-API-Token': import('zod').ZodString;
1124
+ }, "strip", import('zod').ZodTypeAny, {
1125
+ 'X-API-Token': string;
1126
+ }, {
1127
+ 'X-API-Token': string;
1128
+ }>]>, import('zod').ZodObject<{
1129
+ 'X-Lokalise-Plugin': import('zod').ZodString;
1130
+ }, "strip", import('zod').ZodTypeAny, {
1131
+ 'X-Lokalise-Plugin': string;
1132
+ }, {
1133
+ 'X-Lokalise-Plugin': string;
1134
+ }>>, false, false>;
1081
1135
  /**
1082
1136
  * Public API router definition for updating a project
1083
1137
  */
@@ -1392,4 +1446,22 @@ export declare const updateProject: import('@lokalise/universal-ts-utils/node').
1392
1446
  project_id: string;
1393
1447
  }, {
1394
1448
  project_id: string;
1395
- }>, undefined, undefined, false, false>;
1449
+ }>, undefined, import('zod').ZodIntersection<import('zod').ZodUnion<[import('zod').ZodObject<{
1450
+ Authorization: import('zod').ZodString;
1451
+ }, "strip", import('zod').ZodTypeAny, {
1452
+ Authorization: string;
1453
+ }, {
1454
+ Authorization: string;
1455
+ }>, import('zod').ZodObject<{
1456
+ 'X-API-Token': import('zod').ZodString;
1457
+ }, "strip", import('zod').ZodTypeAny, {
1458
+ 'X-API-Token': string;
1459
+ }, {
1460
+ 'X-API-Token': string;
1461
+ }>]>, import('zod').ZodObject<{
1462
+ 'X-Lokalise-Plugin': import('zod').ZodString;
1463
+ }, "strip", import('zod').ZodTypeAny, {
1464
+ 'X-Lokalise-Plugin': string;
1465
+ }, {
1466
+ 'X-Lokalise-Plugin': string;
1467
+ }>>, false, false>;
@@ -3,8 +3,8 @@ import { z } from 'zod';
3
3
  * Public API router definition for getting the details of a team user
4
4
  */
5
5
  export declare const getTeamUser: import('@lokalise/universal-ts-utils/node').GetRouteDefinition<{
6
- teamId: number;
7
6
  userId: number;
7
+ teamId: number;
8
8
  }, z.ZodObject<{
9
9
  team_id: z.ZodNumber;
10
10
  team_user: z.ZodObject<{
@@ -53,9 +53,27 @@ export declare const getTeamUser: import('@lokalise/universal-ts-utils/node').Ge
53
53
  teamId: z.ZodNumber;
54
54
  userId: z.ZodNumber;
55
55
  }, "strip", z.ZodTypeAny, {
56
- teamId: number;
57
56
  userId: number;
58
- }, {
59
57
  teamId: number;
58
+ }, {
60
59
  userId: number;
61
- }>, undefined, undefined, false, false>;
60
+ teamId: number;
61
+ }>, undefined, z.ZodIntersection<z.ZodUnion<[z.ZodObject<{
62
+ Authorization: z.ZodString;
63
+ }, "strip", z.ZodTypeAny, {
64
+ Authorization: string;
65
+ }, {
66
+ Authorization: string;
67
+ }>, z.ZodObject<{
68
+ 'X-API-Token': z.ZodString;
69
+ }, "strip", z.ZodTypeAny, {
70
+ 'X-API-Token': string;
71
+ }, {
72
+ 'X-API-Token': string;
73
+ }>]>, z.ZodObject<{
74
+ 'X-Lokalise-Plugin': z.ZodString;
75
+ }, "strip", z.ZodTypeAny, {
76
+ 'X-Lokalise-Plugin': string;
77
+ }, {
78
+ 'X-Lokalise-Plugin': string;
79
+ }>>, false, false>;
@@ -1,4 +1,24 @@
1
1
  import { z } from 'zod';
2
+ export declare const CONTRIBUTOR_API_BASE_HEADER_SCHEMA: z.ZodIntersection<z.ZodUnion<[z.ZodObject<{
3
+ Authorization: z.ZodString;
4
+ }, "strip", z.ZodTypeAny, {
5
+ Authorization: string;
6
+ }, {
7
+ Authorization: string;
8
+ }>, z.ZodObject<{
9
+ 'X-API-Token': z.ZodString;
10
+ }, "strip", z.ZodTypeAny, {
11
+ 'X-API-Token': string;
12
+ }, {
13
+ 'X-API-Token': string;
14
+ }>]>, z.ZodObject<{
15
+ 'X-Lokalise-Plugin': z.ZodString;
16
+ }, "strip", z.ZodTypeAny, {
17
+ 'X-Lokalise-Plugin': string;
18
+ }, {
19
+ 'X-Lokalise-Plugin': string;
20
+ }>>;
21
+ export type ContributorApiBaseHeader = z.infer<typeof CONTRIBUTOR_API_BASE_HEADER_SCHEMA>;
2
22
  export declare const CONTRIBUTOR_LANGUAGE_SCHEMA: z.ZodObject<{
3
23
  lang_id: z.ZodNumber;
4
24
  lang_iso: z.ZodString;
@@ -1,4 +1,24 @@
1
1
  import { z } from 'zod';
2
+ export declare const PROJECT_API_BASE_HEADERS_SCHEMA: z.ZodIntersection<z.ZodUnion<[z.ZodObject<{
3
+ Authorization: z.ZodString;
4
+ }, "strip", z.ZodTypeAny, {
5
+ Authorization: string;
6
+ }, {
7
+ Authorization: string;
8
+ }>, z.ZodObject<{
9
+ 'X-API-Token': z.ZodString;
10
+ }, "strip", z.ZodTypeAny, {
11
+ 'X-API-Token': string;
12
+ }, {
13
+ 'X-API-Token': string;
14
+ }>]>, z.ZodObject<{
15
+ 'X-Lokalise-Plugin': z.ZodString;
16
+ }, "strip", z.ZodTypeAny, {
17
+ 'X-Lokalise-Plugin': string;
18
+ }, {
19
+ 'X-Lokalise-Plugin': string;
20
+ }>>;
21
+ export type ProjectApiBaseHeaders = z.infer<typeof PROJECT_API_BASE_HEADERS_SCHEMA>;
2
22
  export declare const PROJECT_TYPE_SCHEMA: z.ZodUnion<[z.ZodLiteral<"localization_files">, z.ZodLiteral<"paged_documents">, z.ZodLiteral<"marketing">]>;
3
23
  export type ProjectType = z.infer<typeof PROJECT_TYPE_SCHEMA>;
4
24
  export declare const PROJECT_SETTINGS_SCHEMA: z.ZodObject<{
@@ -0,0 +1,57 @@
1
+ import { z } from 'zod';
2
+ export declare const AUTHORIZATION_HEADER_SCHEMA: z.ZodObject<{
3
+ Authorization: z.ZodString;
4
+ }, "strip", z.ZodTypeAny, {
5
+ Authorization: string;
6
+ }, {
7
+ Authorization: string;
8
+ }>;
9
+ export declare const APU_TOKEN_AUTH_HEADER_SCHEMA: z.ZodObject<{
10
+ 'X-API-Token': z.ZodString;
11
+ }, "strip", z.ZodTypeAny, {
12
+ 'X-API-Token': string;
13
+ }, {
14
+ 'X-API-Token': string;
15
+ }>;
16
+ export declare const AUTHENTICATION_HEADERS_SCHEMA: z.ZodUnion<[z.ZodObject<{
17
+ Authorization: z.ZodString;
18
+ }, "strip", z.ZodTypeAny, {
19
+ Authorization: string;
20
+ }, {
21
+ Authorization: string;
22
+ }>, z.ZodObject<{
23
+ 'X-API-Token': z.ZodString;
24
+ }, "strip", z.ZodTypeAny, {
25
+ 'X-API-Token': string;
26
+ }, {
27
+ 'X-API-Token': string;
28
+ }>]>;
29
+ export type AuthenticationHeaders = z.infer<typeof AUTHENTICATION_HEADERS_SCHEMA>;
30
+ export declare const API_PLUGIN_HEADER_SCHEMA: z.ZodObject<{
31
+ 'X-Lokalise-Plugin': z.ZodString;
32
+ }, "strip", z.ZodTypeAny, {
33
+ 'X-Lokalise-Plugin': string;
34
+ }, {
35
+ 'X-Lokalise-Plugin': string;
36
+ }>;
37
+ export type ApiPluginHeader = z.infer<typeof API_PLUGIN_HEADER_SCHEMA>;
38
+ export declare const BASE_API_ENDPOINT_HEADER_SCHEMA: z.ZodIntersection<z.ZodUnion<[z.ZodObject<{
39
+ Authorization: z.ZodString;
40
+ }, "strip", z.ZodTypeAny, {
41
+ Authorization: string;
42
+ }, {
43
+ Authorization: string;
44
+ }>, z.ZodObject<{
45
+ 'X-API-Token': z.ZodString;
46
+ }, "strip", z.ZodTypeAny, {
47
+ 'X-API-Token': string;
48
+ }, {
49
+ 'X-API-Token': string;
50
+ }>]>, z.ZodObject<{
51
+ 'X-Lokalise-Plugin': z.ZodString;
52
+ }, "strip", z.ZodTypeAny, {
53
+ 'X-Lokalise-Plugin': string;
54
+ }, {
55
+ 'X-Lokalise-Plugin': string;
56
+ }>>;
57
+ export type BaseApiEndpointHeader = z.infer<typeof BASE_API_ENDPOINT_HEADER_SCHEMA>;
@@ -1,4 +1,24 @@
1
1
  import { z } from 'zod';
2
+ export declare const TEAM_USER_API_BASE_HEADERS_SCHEMA: z.ZodIntersection<z.ZodUnion<[z.ZodObject<{
3
+ Authorization: z.ZodString;
4
+ }, "strip", z.ZodTypeAny, {
5
+ Authorization: string;
6
+ }, {
7
+ Authorization: string;
8
+ }>, z.ZodObject<{
9
+ 'X-API-Token': z.ZodString;
10
+ }, "strip", z.ZodTypeAny, {
11
+ 'X-API-Token': string;
12
+ }, {
13
+ 'X-API-Token': string;
14
+ }>]>, z.ZodObject<{
15
+ 'X-Lokalise-Plugin': z.ZodString;
16
+ }, "strip", z.ZodTypeAny, {
17
+ 'X-Lokalise-Plugin': string;
18
+ }, {
19
+ 'X-Lokalise-Plugin': string;
20
+ }>>;
21
+ export type TeamUserApiBaseHeaders = z.infer<typeof TEAM_USER_API_BASE_HEADERS_SCHEMA>;
2
22
  export declare const TEAM_USER_SCHEMA: z.ZodObject<{
3
23
  user_id: z.ZodNumber;
4
24
  email: z.ZodString;
@@ -10,7 +10,7 @@ export declare const JWT_TOKEN_SCHEMA: z.ZodObject<{
10
10
  refreshToken: string;
11
11
  }>;
12
12
  export type JwtToken = z.infer<typeof JWT_TOKEN_SCHEMA>;
13
- export declare const AUTHENTICATED_REQUEST_HEADER: z.ZodUnion<[z.ZodObject<{
13
+ export declare const USER_TOKEN_REQUEST_HEADER_SCHEMA: z.ZodUnion<[z.ZodObject<{
14
14
  Authorization: z.ZodString;
15
15
  }, "strip", z.ZodTypeAny, {
16
16
  Authorization: string;
@@ -23,4 +23,4 @@ export declare const AUTHENTICATED_REQUEST_HEADER: z.ZodUnion<[z.ZodObject<{
23
23
  }, {
24
24
  'x-csrf-token': string;
25
25
  }>]>;
26
- export type AuthenticatedRequestHeader = z.infer<typeof AUTHENTICATED_REQUEST_HEADER>;
26
+ export type UserTokenRequestHeader = z.infer<typeof USER_TOKEN_REQUEST_HEADER_SCHEMA>;
@@ -32,4 +32,4 @@ export declare const getUserToken: import('@lokalise/universal-ts-utils/node').P
32
32
  'x-csrf-token': string;
33
33
  }, {
34
34
  'x-csrf-token': string;
35
- }>]>, false, false>;
35
+ }>]>, false, true>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lokalise/harmony",
3
- "version": "1.16.0",
3
+ "version": "1.17.0-exp-jwtheaderfactorysharedauth.1",
4
4
  "author": {
5
5
  "name": "Lokalise",
6
6
  "url": "https://lokalise.com/"
@@ -1,17 +0,0 @@
1
- import { JwtToken } from '../../../publicApi/types/userTokenTypes';
2
- import { ConfiguredMiddleware, Wretch } from 'wretch';
3
- export type JwtAuthProps<T> = {
4
- /**
5
- * A configured Wretch client that is used to make requests to the authentication provider.
6
- */
7
- authProviderWretchClient: Wretch<T>;
8
- /**
9
- * This function should return the current JWT token if it exists.
10
- */
11
- getCachedJwtToken: () => Promise<JwtToken | undefined>;
12
- /**
13
- * This function is called when a new JWT token is issued or if/when the token is refreshed.
14
- */
15
- onNewJwtTokenIssued?: (jwtToken: JwtToken) => Promise<void>;
16
- };
17
- export declare function jwtAuthMiddleware<T>(props: JwtAuthProps<T>): ConfiguredMiddleware;
@@ -1,5 +0,0 @@
1
- import { ConfiguredMiddleware } from 'wretch';
2
- /**
3
- * Adds the required headers to make requests to the public API.
4
- */
5
- export declare function publicApiHeadersMiddleware(): ConfiguredMiddleware;
@@ -1,9 +0,0 @@
1
- import { JwtAuthProps } from '../../core/middleware/jwtAuthMiddleware';
2
- export type ClientSideJwtAuthProps<T> = Omit<JwtAuthProps<T>, 'getCachedJwtToken'> & {
3
- /**
4
- * The browser implementation makes this optional, as it can be inferred from the cookie.
5
- * You can still provide a custom implementation if you want to.
6
- */
7
- getCachedJwtToken?: JwtAuthProps<T>['getCachedJwtToken'];
8
- };
9
- export declare function clientSideJwtAuthMiddleware<T>(props: ClientSideJwtAuthProps<T>): import('wretch').ConfiguredMiddleware;
@@ -1,14 +0,0 @@
1
- import { ClientSideJwtAuthProps } from './clientSideJwtAuthMiddleware';
2
- import { ConfiguredMiddleware } from 'wretch';
3
- export type PromoteAuthProps<T> = ClientSideJwtAuthProps<T> & {
4
- /**
5
- * Team ID is required to issue a new JWT token.
6
- */
7
- getTeamId: () => Promise<number>;
8
- /**
9
- * The current CSRF token is required to issue a new JWT token.
10
- * So this function should return the CSRF token for the current session.
11
- */
12
- getCsrfToken?: () => Promise<string | undefined>;
13
- };
14
- export declare function promoteClassicSessionToJwtMiddleware<T>(overrides: PromoteAuthProps<T>): ConfiguredMiddleware;