nodestack-client 1.0.0
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 +248 -0
- package/dist/Client.d.ts +55 -0
- package/dist/Client.d.ts.map +1 -0
- package/dist/auth/BaseAuthStore.d.ts +38 -0
- package/dist/auth/BaseAuthStore.d.ts.map +1 -0
- package/dist/auth/LocalAuthStore.d.ts +21 -0
- package/dist/auth/LocalAuthStore.d.ts.map +1 -0
- package/dist/auth/MemoryAuthStore.d.ts +8 -0
- package/dist/auth/MemoryAuthStore.d.ts.map +1 -0
- package/dist/errors/ClientResponseError.d.ts +29 -0
- package/dist/errors/ClientResponseError.d.ts.map +1 -0
- package/dist/index.cjs +971 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +948 -0
- package/dist/index.mjs.map +7 -0
- package/dist/services/AdminService.d.ts +26 -0
- package/dist/services/AdminService.d.ts.map +1 -0
- package/dist/services/BaseService.d.ts +16 -0
- package/dist/services/BaseService.d.ts.map +1 -0
- package/dist/services/CollectionService.d.ts +27 -0
- package/dist/services/CollectionService.d.ts.map +1 -0
- package/dist/services/FileService.d.ts +25 -0
- package/dist/services/FileService.d.ts.map +1 -0
- package/dist/services/RealtimeService.d.ts +66 -0
- package/dist/services/RealtimeService.d.ts.map +1 -0
- package/dist/services/RecordService.d.ts +81 -0
- package/dist/services/RecordService.d.ts.map +1 -0
- package/dist/types.d.ts +78 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# ð nodestack-client
|
|
2
|
+
|
|
3
|
+
> **The Official Lightweight, Type-Safe JavaScript & TypeScript Client SDK for [NodeStack](https://github.com/satya-jugran/nodebase)**
|
|
4
|
+
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
A zero-dependency, isomorphic JavaScript and TypeScript client for NodeStack with out-of-the-box support for:
|
|
9
|
+
- ⥠**Zero runtime dependencies**: Built purely on standard Web APIs (`fetch`, `FormData`, `AbortController`, `EventSource`).
|
|
10
|
+
- ðŠķ **Ultra-lightweight footprint**: `< 10 KB` minified + gzipped.
|
|
11
|
+
- ð **Pluggable & Reactive Auth**: `LocalAuthStore` (localStorage), `MemoryAuthStore` (Node/SSR/testing), and reactive `onChange` state subscriptions.
|
|
12
|
+
- ðĶ **Fluent Record CRUD & Batch Pagination**: `getList`, `getFullList`, `getFirstListItem`, `create`, `update`, `delete`, `export`, and `import`.
|
|
13
|
+
- ð **File Uploads & Protected File URLs**: Seamless `FormData` file uploads and URL generation with automatic token appending.
|
|
14
|
+
- ðĄ **Multiplexed Realtime SSE**: Single persistent connection with auto-handshake (`NS_CONNECT`), dynamic subscription sync, and automatic reconnection.
|
|
15
|
+
- ðŊ **100% Type Safety**: Works seamlessly with `nodestack typegen` and `GET /api/types.d.ts` for autocompleted collection names and typed record returns.
|
|
16
|
+
- ð **Isomorphic**: Modern Browsers, React / Next.js (SSR + Client), Vue, Svelte, Node.js (18+ / 22+), Bun, Deno, and React Native.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## ðĶ Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install nodestack-client
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or using Yarn / PNPM / Bun:
|
|
27
|
+
```bash
|
|
28
|
+
pnpm add nodestack-client
|
|
29
|
+
# or
|
|
30
|
+
bun add nodestack-client
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## ⥠Quick Start
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { NodeStackClient } from 'nodestack-client';
|
|
39
|
+
|
|
40
|
+
// Initialize client
|
|
41
|
+
const client = new NodeStackClient('http://127.0.0.1:8090');
|
|
42
|
+
|
|
43
|
+
// Fetch paginated records
|
|
44
|
+
const result = await client.collection('posts').getList(1, 20, {
|
|
45
|
+
filter: "status = 'published' && views >= 10",
|
|
46
|
+
sort: '-created',
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
console.log(`Found ${result.totalItems} posts:`, result.items);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## ð Authentication
|
|
55
|
+
|
|
56
|
+
### Authenticate as an Auth Collection User (e.g. `users`)
|
|
57
|
+
```typescript
|
|
58
|
+
const authData = await client.collection('users').authWithPassword('alice@example.com', 'password123');
|
|
59
|
+
|
|
60
|
+
console.log('Logged in user:', client.authStore.model);
|
|
61
|
+
console.log('JWT Token:', client.authStore.token);
|
|
62
|
+
console.log('Is valid:', client.authStore.isValid);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Authenticate as a Superuser / Admin
|
|
66
|
+
```typescript
|
|
67
|
+
const adminAuth = await client.admins.authWithPassword('admin@nodestack.io', 'MySecretAdminPassword');
|
|
68
|
+
console.log('Logged in superuser:', adminAuth.admin.email);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Reactive Auth State Changes
|
|
72
|
+
```typescript
|
|
73
|
+
// Subscribe to login / logout events (ideal for React, Vue, Svelte stores)
|
|
74
|
+
const unbind = client.authStore.onChange((token, model) => {
|
|
75
|
+
console.log('Auth state changed:', { token, model });
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Logout
|
|
79
|
+
client.authStore.clear();
|
|
80
|
+
|
|
81
|
+
// Unsubscribe listener
|
|
82
|
+
unbind();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### SSR & Node.js Environments (`MemoryAuthStore`)
|
|
86
|
+
In Node.js scripts or server-side rendering where `window.localStorage` is unavailable:
|
|
87
|
+
```typescript
|
|
88
|
+
import { NodeStackClient, MemoryAuthStore } from 'nodestack-client';
|
|
89
|
+
|
|
90
|
+
const serverClient = new NodeStackClient('http://127.0.0.1:8090', {
|
|
91
|
+
authStore: new MemoryAuthStore(),
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## ð Record Operations (CRUD)
|
|
98
|
+
|
|
99
|
+
### 1. Fetch Paginated Records (`getList`)
|
|
100
|
+
```typescript
|
|
101
|
+
const result = await client.collection('posts').getList(1, 10, {
|
|
102
|
+
filter: "category = 'Tech' && price <= 50",
|
|
103
|
+
sort: '-created,title',
|
|
104
|
+
expand: 'author,comments',
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
console.log(result.page, result.totalPages, result.items);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 2. Fetch All Records Across Pages (`getFullList`)
|
|
111
|
+
Auto-paginates in batches and returns all matching records as a single array:
|
|
112
|
+
```typescript
|
|
113
|
+
const allPosts = await client.collection('posts').getFullList({
|
|
114
|
+
batch: 200,
|
|
115
|
+
filter: "published = true",
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### 3. Find First Matching Record (`getFirstListItem`)
|
|
120
|
+
```typescript
|
|
121
|
+
// Throws ClientResponseError(404) if no match is found
|
|
122
|
+
const post = await client.collection('posts').getFirstListItem("slug = 'hello-world'");
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### 4. Create Record (JSON or File Uploads)
|
|
126
|
+
```typescript
|
|
127
|
+
// Plain JSON
|
|
128
|
+
const newPost = await client.collection('posts').create({
|
|
129
|
+
title: 'My First Post',
|
|
130
|
+
published: true,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// Multipart Form Data (File Upload)
|
|
134
|
+
const formData = new FormData();
|
|
135
|
+
formData.append('title', 'Post with Cover Photo');
|
|
136
|
+
formData.append('coverImage', fileInput.files[0]);
|
|
137
|
+
|
|
138
|
+
const postWithImage = await client.collection('posts').create(formData);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 5. Update & Delete Records
|
|
142
|
+
```typescript
|
|
143
|
+
// Update
|
|
144
|
+
const updated = await client.collection('posts').update('rec_123', {
|
|
145
|
+
title: 'Updated Title',
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Delete
|
|
149
|
+
await client.collection('posts').delete('rec_123');
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## ð File URLs Helper
|
|
155
|
+
|
|
156
|
+
NodeStack provides protected and public file serving at `/api/files/:collection/:recordId/:filename`. Construct fully-qualified URLs easily:
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
const record = await client.collection('posts').getOne('rec_123');
|
|
160
|
+
|
|
161
|
+
// 1. Standard URL for <img> tags
|
|
162
|
+
const imageUrl = client.files.getUrl(record, record.coverImage);
|
|
163
|
+
|
|
164
|
+
// 2. Trigger browser download dialog
|
|
165
|
+
const downloadUrl = client.files.getUrl(record, record.attachment, {
|
|
166
|
+
download: true,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// 3. Attach authentication token for protected files
|
|
170
|
+
const protectedUrl = client.files.getUrl(record, record.secretDoc, {
|
|
171
|
+
token: true, // Uses active authStore token
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## ðĄ Realtime Subscriptions (SSE)
|
|
178
|
+
|
|
179
|
+
NodeStack uses Server-Sent Events (SSE) with an initial `NS_CONNECT` handshake and multiplexed collection channels. `nodestack-client` manages this with automatic reconnection and topic synchronization:
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
// 1. Subscribe to all changes in a collection
|
|
183
|
+
const unsubscribe = await client.collection('posts').subscribe('*', (event) => {
|
|
184
|
+
console.log(`Action: ${event.action}`); // 'create' | 'update' | 'delete'
|
|
185
|
+
console.log('Record:', event.record);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// 2. Subscribe to a specific record by ID
|
|
189
|
+
const unbindRecord = await client.collection('posts').subscribe('rec_123', (event) => {
|
|
190
|
+
console.log('Record updated:', event.record);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// 3. Clean up subscriptions when unmounting
|
|
194
|
+
await unsubscribe();
|
|
195
|
+
await unbindRecord();
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## ðŊ End-to-End Type Safety
|
|
201
|
+
|
|
202
|
+
Pair `nodestack-client` with `nodestack typegen`:
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
# Generate TypeScript definitions from your running server
|
|
206
|
+
npx nodestack typegen > src/types/nodestack.ts
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Then supply your `SchemaCollections` dictionary to `NodeStackClient`:
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
import { NodeStackClient } from 'nodestack-client';
|
|
213
|
+
import { SchemaCollections } from './types/nodestack';
|
|
214
|
+
|
|
215
|
+
const client = new NodeStackClient<SchemaCollections>('http://127.0.0.1:8090');
|
|
216
|
+
|
|
217
|
+
// Autocomplete for collection names: 'posts' | 'users' | 'orders'
|
|
218
|
+
// Return types are automatically inferred as PostRecord, UserRecord, etc.
|
|
219
|
+
const posts = await client.collection('posts').getList();
|
|
220
|
+
posts.items[0].title; // Fully typed!
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## ðĄïļ Error Handling
|
|
226
|
+
|
|
227
|
+
When NodeStack returns an error (4xx or 5xx), a `ClientResponseError` is thrown:
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
import { ClientResponseError } from 'nodestack-client';
|
|
231
|
+
|
|
232
|
+
try {
|
|
233
|
+
await client.collection('posts').getOne('missing_id');
|
|
234
|
+
} catch (err) {
|
|
235
|
+
if (err instanceof ClientResponseError) {
|
|
236
|
+
console.error('Status:', err.status); // e.g. 404
|
|
237
|
+
console.error('Message:', err.message); // e.g. "Record not found"
|
|
238
|
+
console.error('Data:', err.data); // Raw response JSON
|
|
239
|
+
console.error('Is Aborted:', err.isAbort);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## ð License
|
|
247
|
+
|
|
248
|
+
MIT ÂĐ NodeStack Contributors
|
package/dist/Client.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { BaseAuthStore } from './auth/BaseAuthStore';
|
|
2
|
+
import { RecordService } from './services/RecordService';
|
|
3
|
+
import { FileService } from './services/FileService';
|
|
4
|
+
import { RealtimeService } from './services/RealtimeService';
|
|
5
|
+
import { AdminService } from './services/AdminService';
|
|
6
|
+
import { CollectionService } from './services/CollectionService';
|
|
7
|
+
import type { ClientOptions, SendOptions, RecordModel } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* Main NodeStack Client SDK entry point.
|
|
10
|
+
*/
|
|
11
|
+
export declare class NodeStackClient<TCollections extends Record<string, any> = Record<string, RecordModel>> {
|
|
12
|
+
readonly baseUrl: string;
|
|
13
|
+
readonly authStore: BaseAuthStore;
|
|
14
|
+
readonly files: FileService;
|
|
15
|
+
readonly realtime: RealtimeService;
|
|
16
|
+
readonly admins: AdminService;
|
|
17
|
+
readonly collections: CollectionService;
|
|
18
|
+
private customFetch?;
|
|
19
|
+
private defaultHeaders;
|
|
20
|
+
private defaultTimeout;
|
|
21
|
+
private recordServices;
|
|
22
|
+
constructor(baseUrl?: string, options?: ClientOptions);
|
|
23
|
+
/**
|
|
24
|
+
* Returns a RecordService for interacting with a specific collection.
|
|
25
|
+
* If a schema map type is provided to NodeStackClient, collection names
|
|
26
|
+
* and record response types are automatically inferred and type-safe.
|
|
27
|
+
*/
|
|
28
|
+
collection<K extends keyof TCollections>(name: K): RecordService<TCollections[K]>;
|
|
29
|
+
collection<T = RecordModel>(name: string): RecordService<T>;
|
|
30
|
+
/**
|
|
31
|
+
* Sends an HTTP request to NodeStack with automatic authentication,
|
|
32
|
+
* header injection, query serialization, and standardized error handling.
|
|
33
|
+
*/
|
|
34
|
+
send<T = any>(path: string, options?: SendOptions): Promise<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Checks backend system health.
|
|
37
|
+
*/
|
|
38
|
+
health(): Promise<{
|
|
39
|
+
status: string;
|
|
40
|
+
[key: string]: any;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* Retrieves server runtime settings.
|
|
44
|
+
*/
|
|
45
|
+
settings(): Promise<any>;
|
|
46
|
+
/**
|
|
47
|
+
* Fetches request logs (Admin only).
|
|
48
|
+
*/
|
|
49
|
+
logs(page?: number, perPage?: number): Promise<any>;
|
|
50
|
+
/**
|
|
51
|
+
* Fetches system metrics & analytics (Admin only).
|
|
52
|
+
*/
|
|
53
|
+
metrics(): Promise<any>;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=Client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../src/Client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,qBAAa,eAAe,CAAC,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC;IACjG,SAAgB,OAAO,EAAE,MAAM,CAAC;IAChC,SAAgB,SAAS,EAAE,aAAa,CAAC;IACzC,SAAgB,KAAK,EAAE,WAAW,CAAC;IACnC,SAAgB,QAAQ,EAAE,eAAe,CAAC;IAC1C,SAAgB,MAAM,EAAE,YAAY,CAAC;IACrC,SAAgB,WAAW,EAAE,iBAAiB,CAAC;IAE/C,OAAO,CAAC,WAAW,CAAC,CAAe;IACnC,OAAO,CAAC,cAAc,CAAyB;IAC/C,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,cAAc,CAA8C;gBAExD,OAAO,GAAE,MAAY,EAAE,OAAO,GAAE,aAAkB;IAa9D;;;;OAIG;IACI,UAAU,CAAC,CAAC,SAAS,MAAM,YAAY,EAAE,IAAI,EAAE,CAAC,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IACjF,UAAU,CAAC,CAAC,GAAG,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC;IAWlE;;;OAGG;IACU,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,CAAC,CAAC;IA4H/E;;OAEG;IACU,MAAM,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;IAItE;;OAEG;IACU,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC;IAIrC;;OAEG;IACU,IAAI,CAAC,IAAI,SAAI,EAAE,OAAO,SAAK,GAAG,OAAO,CAAC,GAAG,CAAC;IAOvD;;OAEG;IACU,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC;CAGrC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { RecordModel, AdminModel } from '../types';
|
|
2
|
+
export type AuthChangeListener = (token: string, model: RecordModel | AdminModel | null) => void;
|
|
3
|
+
/**
|
|
4
|
+
* Lightweight helper to decode JWT payload without external dependencies.
|
|
5
|
+
*/
|
|
6
|
+
export declare function decodeJwtPayload(token: string): Record<string, any> | null;
|
|
7
|
+
/**
|
|
8
|
+
* Base abstract class for authentication stores.
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class BaseAuthStore {
|
|
11
|
+
protected _token: string;
|
|
12
|
+
protected _model: RecordModel | AdminModel | null;
|
|
13
|
+
private _listeners;
|
|
14
|
+
get token(): string;
|
|
15
|
+
get model(): RecordModel | AdminModel | null;
|
|
16
|
+
/**
|
|
17
|
+
* Returns true if a token exists and has not yet expired.
|
|
18
|
+
*/
|
|
19
|
+
get isValid(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Saves the token and associated user or admin model.
|
|
22
|
+
*/
|
|
23
|
+
save(token: string, model?: RecordModel | AdminModel | null): void;
|
|
24
|
+
/**
|
|
25
|
+
* Clears the current authentication state.
|
|
26
|
+
*/
|
|
27
|
+
clear(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Subscribes to changes in authentication state (token or model).
|
|
30
|
+
* Returns an unbind function.
|
|
31
|
+
*/
|
|
32
|
+
onChange(callback: AuthChangeListener, fireImmediately?: boolean): () => void;
|
|
33
|
+
/**
|
|
34
|
+
* Triggers all subscribed change listeners.
|
|
35
|
+
*/
|
|
36
|
+
protected notify(): void;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=BaseAuthStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseAuthStore.d.ts","sourceRoot":"","sources":["../../src/auth/BaseAuthStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAExD,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,UAAU,GAAG,IAAI,KAAK,IAAI,CAAC;AAEjG;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAqC1E;AAED;;GAEG;AACH,8BAAsB,aAAa;IACjC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAM;IAC9B,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,UAAU,GAAG,IAAI,CAAQ;IACzD,OAAO,CAAC,UAAU,CAAsC;IAExD,IAAW,KAAK,IAAI,MAAM,CAEzB;IAED,IAAW,KAAK,IAAI,WAAW,GAAG,UAAU,GAAG,IAAI,CAElD;IAED;;OAEG;IACH,IAAW,OAAO,IAAI,OAAO,CAgB5B;IAED;;OAEG;IACI,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,UAAU,GAAG,IAAI,GAAG,IAAI;IAMzE;;OAEG;IACI,KAAK,IAAI,IAAI;IAMpB;;;OAGG;IACI,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,EAAE,eAAe,UAAQ,GAAG,MAAM,IAAI;IAelF;;OAEG;IACH,SAAS,CAAC,MAAM,IAAI,IAAI;CASzB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BaseAuthStore } from './BaseAuthStore';
|
|
2
|
+
import type { RecordModel, AdminModel } from '../types';
|
|
3
|
+
export interface StorageLike {
|
|
4
|
+
getItem(key: string): string | null;
|
|
5
|
+
setItem(key: string, value: string): void;
|
|
6
|
+
removeItem(key: string): void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Storage-backed AuthStore that syncs token and model with localStorage
|
|
10
|
+
* (or any custom StorageLike object, such as sessionStorage or AsyncStorage).
|
|
11
|
+
* Safely degrades to memory if storage is not available.
|
|
12
|
+
*/
|
|
13
|
+
export declare class LocalAuthStore extends BaseAuthStore {
|
|
14
|
+
private storageKey;
|
|
15
|
+
private storage?;
|
|
16
|
+
constructor(storageKey?: string, customStorage?: StorageLike);
|
|
17
|
+
private loadInitial;
|
|
18
|
+
save(token: string, model?: RecordModel | AdminModel | null): void;
|
|
19
|
+
clear(): void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=LocalAuthStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalAuthStore.d.ts","sourceRoot":"","sources":["../../src/auth/LocalAuthStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAExD,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACpC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAID;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,aAAa;IAC/C,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,OAAO,CAAC,CAAc;gBAElB,UAAU,GAAE,MAA4B,EAAE,aAAa,CAAC,EAAE,WAAW;IAajF,OAAO,CAAC,WAAW;IAiBH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,UAAU,GAAG,IAAI,GAAG,IAAI;IAkBlE,KAAK,IAAI,IAAI;CAW9B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseAuthStore } from './BaseAuthStore';
|
|
2
|
+
/**
|
|
3
|
+
* In-memory authentication store.
|
|
4
|
+
* Ideal for Node.js scripts, server-side rendering (SSR), and testing environments.
|
|
5
|
+
*/
|
|
6
|
+
export declare class MemoryAuthStore extends BaseAuthStore {
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=MemoryAuthStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryAuthStore.d.ts","sourceRoot":"","sources":["../../src/auth/MemoryAuthStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,aAAa;CAEjD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface ClientResponseErrorOptions {
|
|
2
|
+
url?: string;
|
|
3
|
+
status?: number;
|
|
4
|
+
data?: any;
|
|
5
|
+
isAbort?: boolean;
|
|
6
|
+
originalError?: any;
|
|
7
|
+
message?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Standardized client response error representing failed HTTP requests
|
|
11
|
+
* or network exceptions when interacting with NodeStack.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ClientResponseError extends Error {
|
|
14
|
+
readonly url: string;
|
|
15
|
+
readonly status: number;
|
|
16
|
+
readonly data: any;
|
|
17
|
+
readonly isAbort: boolean;
|
|
18
|
+
readonly originalError?: any;
|
|
19
|
+
constructor(options?: ClientResponseErrorOptions);
|
|
20
|
+
toJSON(): {
|
|
21
|
+
name: string;
|
|
22
|
+
message: string;
|
|
23
|
+
url: string;
|
|
24
|
+
status: number;
|
|
25
|
+
data: any;
|
|
26
|
+
isAbort: boolean;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=ClientResponseError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientResponseError.d.ts","sourceRoot":"","sources":["../../src/errors/ClientResponseError.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,0BAA0B;IACzC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,IAAI,EAAE,GAAG,CAAC;IAC1B,SAAgB,OAAO,EAAE,OAAO,CAAC;IACjC,SAAgB,aAAa,CAAC,EAAE,GAAG,CAAC;gBAExB,OAAO,GAAE,0BAA+B;IAmB7C,MAAM;;;;;;;;CAUd"}
|