@tenxyte/core 0.9.0 → 0.9.3
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/LICENSE +21 -0
- package/README.md +362 -102
- package/dist/index.cjs +966 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1073 -15
- package/dist/index.d.ts +1073 -15
- package/dist/index.js +946 -35
- package/dist/index.js.map +1 -1
- package/package.json +15 -3
- package/patched-schema.json +0 -11388
- package/src/client.ts +0 -50
- package/src/config.ts +0 -0
- package/src/http/client.ts +0 -162
- package/src/http/index.ts +0 -1
- package/src/http/interceptors.ts +0 -117
- package/src/index.ts +0 -7
- package/src/modules/ai.ts +0 -178
- package/src/modules/auth.ts +0 -116
- package/src/modules/b2b.ts +0 -177
- package/src/modules/rbac.ts +0 -207
- package/src/modules/security.ts +0 -313
- package/src/modules/user.ts +0 -95
- package/src/storage/cookie.ts +0 -39
- package/src/storage/index.ts +0 -29
- package/src/storage/localStorage.ts +0 -75
- package/src/storage/memory.ts +0 -30
- package/src/types/api-schema.d.ts +0 -6590
- package/src/types/index.ts +0 -152
- package/src/utils/base64url.ts +0 -25
- package/src/utils/device_info.ts +0 -94
- package/src/utils/events.ts +0 -71
- package/src/utils/jwt.ts +0 -51
- package/tests/http.test.ts +0 -144
- package/tests/modules/auth.test.ts +0 -93
- package/tests/modules/rbac.test.ts +0 -95
- package/tests/modules/security.test.ts +0 -85
- package/tests/modules/user.test.ts +0 -76
- package/tests/storage.test.ts +0 -96
- package/tests/utils.test.ts +0 -71
- package/tsconfig.json +0 -26
- package/tsup.config.ts +0 -10
- package/vitest.config.ts +0 -7
package/src/modules/user.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { TenxyteHttpClient } from '../http/client';
|
|
2
|
-
|
|
3
|
-
export interface UpdateProfileParams {
|
|
4
|
-
first_name?: string;
|
|
5
|
-
last_name?: string;
|
|
6
|
-
[key: string]: any; // Allow custom metadata updates
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface AdminUpdateUserParams {
|
|
10
|
-
first_name?: string;
|
|
11
|
-
last_name?: string;
|
|
12
|
-
is_active?: boolean;
|
|
13
|
-
is_locked?: boolean;
|
|
14
|
-
max_sessions?: number;
|
|
15
|
-
max_devices?: number;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class UserModule {
|
|
19
|
-
constructor(private client: TenxyteHttpClient) { }
|
|
20
|
-
|
|
21
|
-
// --- Standard Profile Actions --- //
|
|
22
|
-
|
|
23
|
-
/** Retrieve your current comprehensive Profile metadata matching the active network bearer token. */
|
|
24
|
-
async getProfile(): Promise<any> {
|
|
25
|
-
return this.client.get('/api/v1/auth/me/');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** Modify your active profile core details or injected application metadata. */
|
|
29
|
-
async updateProfile(data: UpdateProfileParams): Promise<any> {
|
|
30
|
-
return this.client.patch('/api/v1/auth/me/', data);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Upload an avatar using FormData.
|
|
35
|
-
* Ensure the environment supports FormData (browser or Node.js v18+).
|
|
36
|
-
* @param formData The FormData object containing the 'avatar' field.
|
|
37
|
-
*/
|
|
38
|
-
async uploadAvatar(formData: FormData): Promise<any> {
|
|
39
|
-
return this.client.patch('/api/v1/auth/me/', formData);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Trigger self-deletion of an entire account data boundary.
|
|
44
|
-
* @param password - Requires the active system password as destructive proof of intent.
|
|
45
|
-
* @param otpCode - (Optional) If an OTP was queried prior to attempting account deletion.
|
|
46
|
-
*/
|
|
47
|
-
async deleteAccount(password: string, otpCode?: string): Promise<void> {
|
|
48
|
-
return this.client.post<void>('/api/v1/auth/request-account-deletion/', {
|
|
49
|
-
password,
|
|
50
|
-
otp_code: otpCode
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// --- Admin Actions Mapping --- //
|
|
55
|
-
|
|
56
|
-
/** (Admin only) Lists users paginated matching criteria. */
|
|
57
|
-
async listUsers(params?: Record<string, any>): Promise<any[]> {
|
|
58
|
-
return this.client.get<any[]>('/api/v1/auth/admin/users/', { params });
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** (Admin only) Gets deterministic data related to a remote unassociated user. */
|
|
62
|
-
async getUser(userId: string): Promise<any> {
|
|
63
|
-
return this.client.get(`/api/v1/auth/admin/users/${userId}/`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** (Admin only) Modifies configuration/details or capacity bounds related to a remote unassociated user. */
|
|
67
|
-
async adminUpdateUser(userId: string, data: AdminUpdateUserParams): Promise<any> {
|
|
68
|
-
return this.client.patch(`/api/v1/auth/admin/users/${userId}/`, data);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** (Admin only) Force obliterate a User boundary. Can affect relational database stability if not bound carefully. */
|
|
72
|
-
async adminDeleteUser(userId: string): Promise<void> {
|
|
73
|
-
return this.client.delete<void>(`/api/v1/auth/admin/users/${userId}/`);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** (Admin only) Apply a permanent suspension / ban state globally on a user token footprint. */
|
|
77
|
-
async banUser(userId: string, reason: string = ''): Promise<void> {
|
|
78
|
-
return this.client.post<void>(`/api/v1/auth/admin/users/${userId}/ban/`, { reason });
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** (Admin only) Recover a user footprint from a global ban state. */
|
|
82
|
-
async unbanUser(userId: string): Promise<void> {
|
|
83
|
-
return this.client.post<void>(`/api/v1/auth/admin/users/${userId}/unban/`);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/** (Admin only) Apply a temporary lock bounding block on a user interaction footprint. */
|
|
87
|
-
async lockUser(userId: string, durationMinutes: number = 30, reason: string = ''): Promise<void> {
|
|
88
|
-
return this.client.post<void>(`/api/v1/auth/admin/users/${userId}/lock/`, { duration_minutes: durationMinutes, reason });
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/** (Admin only) Releases an arbitrary temporary system lock placed on a user bounds. */
|
|
92
|
-
async unlockUser(userId: string): Promise<void> {
|
|
93
|
-
return this.client.post<void>(`/api/v1/auth/admin/users/${userId}/unlock/`);
|
|
94
|
-
}
|
|
95
|
-
}
|
package/src/storage/cookie.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { TenxyteStorage } from './index';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* CookieStorage implementation
|
|
5
|
-
* Note: To be secure, tokens should be HttpOnly where possible.
|
|
6
|
-
* This class handles client-side cookies if necessary.
|
|
7
|
-
*/
|
|
8
|
-
export class CookieStorage implements TenxyteStorage {
|
|
9
|
-
private defaultOptions: string;
|
|
10
|
-
|
|
11
|
-
constructor(options: { secure?: boolean; sameSite?: 'Strict' | 'Lax' | 'None' } = {}) {
|
|
12
|
-
const secure = options.secure ?? true;
|
|
13
|
-
const sameSite = options.sameSite ?? 'Lax';
|
|
14
|
-
this.defaultOptions = `path=/; SameSite=${sameSite}${secure ? '; Secure' : ''}`;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
getItem(key: string): string | null {
|
|
18
|
-
if (typeof document === 'undefined') return null;
|
|
19
|
-
const match = document.cookie.match(new RegExp(`(^| )${key}=([^;]+)`));
|
|
20
|
-
return match ? decodeURIComponent(match[2]) : null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
setItem(key: string, value: string): void {
|
|
24
|
-
if (typeof document === 'undefined') return;
|
|
25
|
-
document.cookie = `${key}=${encodeURIComponent(value)}; ${this.defaultOptions}`;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
removeItem(key: string): void {
|
|
29
|
-
if (typeof document === 'undefined') return;
|
|
30
|
-
document.cookie = `${key}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
clear(): void {
|
|
34
|
-
// Cannot easily clear all cookies securely because we don't know them all
|
|
35
|
-
// Usually auth keys are known, e.g., tx_access, tx_refresh
|
|
36
|
-
this.removeItem('tx_access');
|
|
37
|
-
this.removeItem('tx_refresh');
|
|
38
|
-
}
|
|
39
|
-
}
|
package/src/storage/index.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export interface TenxyteStorage {
|
|
2
|
-
/**
|
|
3
|
-
* Retrieves a value from storage.
|
|
4
|
-
* @param key The key to retrieve
|
|
5
|
-
*/
|
|
6
|
-
getItem(key: string): string | null | Promise<string | null>;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Saves a value to storage.
|
|
10
|
-
* @param key The key to store
|
|
11
|
-
* @param value The string value
|
|
12
|
-
*/
|
|
13
|
-
setItem(key: string, value: string): void | Promise<void>;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Removes a specific key from storage.
|
|
17
|
-
* @param key The key to remove
|
|
18
|
-
*/
|
|
19
|
-
removeItem(key: string): void | Promise<void>;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Clears all storage keys managed by the SDK.
|
|
23
|
-
*/
|
|
24
|
-
clear(): void | Promise<void>;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export * from './memory';
|
|
28
|
-
export * from './localStorage';
|
|
29
|
-
export * from './cookie';
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { TenxyteStorage } from './index';
|
|
2
|
-
import { MemoryStorage } from './memory';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* LocalStorage wrapper for the browser.
|
|
6
|
-
* Degrades gracefully to MemoryStorage if localStorage is unavailable
|
|
7
|
-
* (e.g., SSR, Private Browsing mode strictness).
|
|
8
|
-
*/
|
|
9
|
-
export class LocalStorage implements TenxyteStorage {
|
|
10
|
-
private fallbackMemoryStore: MemoryStorage | null = null;
|
|
11
|
-
private isAvailable: boolean;
|
|
12
|
-
|
|
13
|
-
constructor() {
|
|
14
|
-
this.isAvailable = this.checkAvailability();
|
|
15
|
-
if (!this.isAvailable) {
|
|
16
|
-
this.fallbackMemoryStore = new MemoryStorage();
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
private checkAvailability(): boolean {
|
|
21
|
-
try {
|
|
22
|
-
if (typeof window === 'undefined' || !window.localStorage) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
const testKey = '__tenxyte_test__';
|
|
26
|
-
window.localStorage.setItem(testKey, '1');
|
|
27
|
-
window.localStorage.removeItem(testKey);
|
|
28
|
-
return true;
|
|
29
|
-
} catch (e) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
getItem(key: string): string | null {
|
|
35
|
-
if (!this.isAvailable && this.fallbackMemoryStore) {
|
|
36
|
-
return this.fallbackMemoryStore.getItem(key);
|
|
37
|
-
}
|
|
38
|
-
return window.localStorage.getItem(key);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
setItem(key: string, value: string): void {
|
|
42
|
-
if (!this.isAvailable && this.fallbackMemoryStore) {
|
|
43
|
-
this.fallbackMemoryStore.setItem(key, value);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
try {
|
|
47
|
-
window.localStorage.setItem(key, value);
|
|
48
|
-
} catch (e) {
|
|
49
|
-
// Storage quota exceeded or similar error
|
|
50
|
-
console.warn(`[Tenxyte SDK] Warning: failed to write to localStorage for key ${key}`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
removeItem(key: string): void {
|
|
55
|
-
if (!this.isAvailable && this.fallbackMemoryStore) {
|
|
56
|
-
this.fallbackMemoryStore.removeItem(key);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
window.localStorage.removeItem(key);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
clear(): void {
|
|
63
|
-
if (!this.isAvailable && this.fallbackMemoryStore) {
|
|
64
|
-
this.fallbackMemoryStore.clear();
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
// We ideally only clear tenxyte specific keys if needed,
|
|
68
|
-
// but standard clear() removes everything.
|
|
69
|
-
// If the library only ever writes specific keys,
|
|
70
|
-
// we could keep track of them and iterate, but for now clear() is standard.
|
|
71
|
-
// For safer implementation we could just let the caller do removeItems() individually
|
|
72
|
-
// but let's conform to the clear API.
|
|
73
|
-
window.localStorage.clear();
|
|
74
|
-
}
|
|
75
|
-
}
|
package/src/storage/memory.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { TenxyteStorage } from './index';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* MemoryStorage implementation primarily used in Node.js (SSR)
|
|
5
|
-
* environments or as a fallback when browser storage is unavailable.
|
|
6
|
-
*/
|
|
7
|
-
export class MemoryStorage implements TenxyteStorage {
|
|
8
|
-
private store: Map<string, string>;
|
|
9
|
-
|
|
10
|
-
constructor() {
|
|
11
|
-
this.store = new Map<string, string>();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
getItem(key: string): string | null {
|
|
15
|
-
const value = this.store.get(key);
|
|
16
|
-
return value !== undefined ? value : null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
setItem(key: string, value: string): void {
|
|
20
|
-
this.store.set(key, value);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
removeItem(key: string): void {
|
|
24
|
-
this.store.delete(key);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
clear(): void {
|
|
28
|
-
this.store.clear();
|
|
29
|
-
}
|
|
30
|
-
}
|