@ph-cms/client-sdk 0.1.6 → 0.1.8
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 +266 -160
- package/dist/auth/base-provider.d.ts +151 -0
- package/dist/auth/base-provider.js +210 -0
- package/dist/auth/firebase-provider.d.ts +46 -12
- package/dist/auth/firebase-provider.js +54 -42
- package/dist/auth/interfaces.d.ts +25 -2
- package/dist/auth/jwt-utils.d.ts +53 -0
- package/dist/auth/jwt-utils.js +85 -0
- package/dist/auth/local-provider.d.ts +34 -17
- package/dist/auth/local-provider.js +45 -39
- package/dist/client.d.ts +23 -0
- package/dist/client.js +116 -26
- package/dist/context.d.ts +12 -0
- package/dist/context.js +19 -7
- package/dist/hooks/useAuth.d.ts +26 -29
- package/dist/hooks/useAuth.js +6 -6
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/modules/auth.d.ts +2 -2
- package/dist/modules/auth.js +11 -20
- package/dist/types.d.ts +15 -1
- package/dist/types.js +7 -15
- package/package.json +1 -1
package/dist/modules/auth.js
CHANGED
|
@@ -9,7 +9,7 @@ class AuthModule {
|
|
|
9
9
|
this.provider = provider;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
* Logs in the user and updates the AuthProvider
|
|
12
|
+
* Logs in the user and updates the AuthProvider tokens automatically.
|
|
13
13
|
*/
|
|
14
14
|
async login(data) {
|
|
15
15
|
const validation = api_contract_1.LoginSchema.safeParse(data);
|
|
@@ -17,17 +17,8 @@ class AuthModule {
|
|
|
17
17
|
throw new errors_1.ValidationError("Invalid login data", validation.error.errors);
|
|
18
18
|
}
|
|
19
19
|
const response = await this.client.post('/api/auth/login', data);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// We need to cast to LocalAuthProvider to access setTokens,
|
|
23
|
-
// but strictly speaking we shouldn't assume implementation details here.
|
|
24
|
-
// However, for this SDK, it's a practical coupling.
|
|
25
|
-
// Or we assume the user handles it.
|
|
26
|
-
// Let's assume the user handles it via the response for now,
|
|
27
|
-
// OR we can try to update it if the method exists.
|
|
28
|
-
if ('setTokens' in this.provider) {
|
|
29
|
-
this.provider.setTokens(response.accessToken, response.refreshToken);
|
|
30
|
-
}
|
|
20
|
+
if (this.provider) {
|
|
21
|
+
this.provider.setTokens(response.accessToken, response.refreshToken);
|
|
31
22
|
}
|
|
32
23
|
return response;
|
|
33
24
|
}
|
|
@@ -40,8 +31,7 @@ class AuthModule {
|
|
|
40
31
|
throw new errors_1.ValidationError("Invalid Firebase token data", validation.error.errors);
|
|
41
32
|
}
|
|
42
33
|
const response = await this.client.post('/api/auth/firebase/exchange', data);
|
|
43
|
-
|
|
44
|
-
if (this.provider && ('setTokens' in this.provider)) {
|
|
34
|
+
if (this.provider) {
|
|
45
35
|
this.provider.setTokens(response.accessToken, response.refreshToken);
|
|
46
36
|
}
|
|
47
37
|
return response;
|
|
@@ -51,23 +41,24 @@ class AuthModule {
|
|
|
51
41
|
if (!validation.success) {
|
|
52
42
|
throw new errors_1.ValidationError("Invalid register data", validation.error.errors);
|
|
53
43
|
}
|
|
54
|
-
|
|
44
|
+
const response = await this.client.post('/api/auth/register', data);
|
|
45
|
+
if (this.provider) {
|
|
46
|
+
this.provider.setTokens(response.accessToken, response.refreshToken);
|
|
47
|
+
}
|
|
48
|
+
return response;
|
|
55
49
|
}
|
|
56
50
|
async me() {
|
|
57
51
|
return this.client.get('/api/auth/me');
|
|
58
52
|
}
|
|
59
53
|
async refresh(refreshToken) {
|
|
60
|
-
// Validate refreshToken string? It's just a string.
|
|
61
54
|
return this.client.post('/api/auth/refresh', { refreshToken });
|
|
62
55
|
}
|
|
63
56
|
async logout() {
|
|
64
57
|
if (this.provider) {
|
|
65
58
|
await this.provider.logout();
|
|
66
59
|
}
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
// But if we want to invalidate on server (blacklist), we call endpoint.
|
|
70
|
-
// Routes has /api/auth/logout.
|
|
60
|
+
// Call the server endpoint to invalidate the session if applicable.
|
|
61
|
+
// JWT-based auth is stateless, but the server may implement a blacklist.
|
|
71
62
|
await this.client.post('/api/auth/logout').catch(() => { }); // Ignore error on logout
|
|
72
63
|
}
|
|
73
64
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1 +1,15 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type { AuthProvider } from './auth/interfaces';
|
|
2
|
+
export type { JwtPayload } from './auth/jwt-utils';
|
|
3
|
+
export type { PHCMSClientConfig } from './client';
|
|
4
|
+
export type { AuthStatus, PHCMSContextType, PHCMSProviderProps } from './context';
|
|
5
|
+
export type { FirebaseAuthSyncProps, UseFirebaseAuthSyncOptions, UseFirebaseAuthSyncReturn } from './hooks/useFirebaseAuthSync';
|
|
6
|
+
export type { AuthResponse, FirebaseExchangeRequest, LoginRequest, RefreshTokenRequest, RegisterRequest } from '@ph-cms/api-contract';
|
|
7
|
+
export type { UserDto } from '@ph-cms/api-contract';
|
|
8
|
+
export type { ChannelDto, CheckHierarchyQuery, CreateChannelDto, ListChannelQuery, PagedChannelListResponse } from '@ph-cms/api-contract';
|
|
9
|
+
export type { ContentDto, ContentMediaDto, CreateContentRequest, ListContentQuery, PagedContentListResponse, UpdateContentRequest } from '@ph-cms/api-contract';
|
|
10
|
+
export type { HierarchySetDto } from '@ph-cms/api-contract';
|
|
11
|
+
export type { PermissionPolicySetDto } from '@ph-cms/api-contract';
|
|
12
|
+
export type { ListTermsQuery, PagedTermListResponse, TermDto } from '@ph-cms/api-contract';
|
|
13
|
+
export type { BoundsQuery, GeoJSON } from '@ph-cms/api-contract';
|
|
14
|
+
export type { MediaUploadTicketBatchRequest, MediaUploadTicketBatchResponse, MediaUploadTicketRequest, MediaUploadTicketResponse } from '@ph-cms/api-contract';
|
|
15
|
+
export type { PagedResponse } from '@ph-cms/api-contract';
|
package/dist/types.js
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
2
|
+
// =============================================================================
|
|
3
|
+
// PH-CMS Client SDK — Centralized Type Exports
|
|
4
|
+
//
|
|
5
|
+
// This file re-exports all types used across the SDK so that consumers can
|
|
6
|
+
// import them from a single entry point (`@ph-cms/client-sdk`) without needing
|
|
7
|
+
// to dig into `@ph-cms/api-contract` (which ships as a pre-built dependency).
|
|
8
|
+
// =============================================================================
|
|
16
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("@ph-cms/api-contract"), exports);
|