zone4code-sdk 1.0.2 → 1.0.4
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 +94 -16
- package/dist/index.cjs +415 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +166 -31
- package/dist/index.d.ts +166 -31
- package/dist/index.js +415 -65
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -51,6 +51,8 @@ interface EntityRecord<T = Record<string, any>> {
|
|
|
51
51
|
updated_at?: string;
|
|
52
52
|
deleted_at?: string | null;
|
|
53
53
|
data: T;
|
|
54
|
+
relations?: Record<string, any[]>;
|
|
55
|
+
[key: string]: any;
|
|
54
56
|
}
|
|
55
57
|
interface EntityListResponse<T = Record<string, any>> {
|
|
56
58
|
data: Array<EntityRecord<T> | (T & {
|
|
@@ -80,21 +82,52 @@ interface EntitySchemaDefinition {
|
|
|
80
82
|
};
|
|
81
83
|
}
|
|
82
84
|
type FilterOperator = 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'in' | 'null';
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
interface UserProfileWithWallet {
|
|
86
|
+
id: string;
|
|
87
|
+
name: string;
|
|
88
|
+
email?: string;
|
|
89
|
+
profile?: Record<string, any>;
|
|
90
|
+
wallet?: {
|
|
91
|
+
total_points: number;
|
|
92
|
+
points_used: number;
|
|
93
|
+
available_points: number;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
interface EntityRevision<T = Record<string, any>> {
|
|
97
|
+
id: string;
|
|
98
|
+
entity_id: string;
|
|
99
|
+
entity_definition_id?: string;
|
|
100
|
+
data: T;
|
|
101
|
+
actor_id?: string;
|
|
102
|
+
created_at: string;
|
|
103
|
+
}
|
|
104
|
+
interface EntityRelationPayload {
|
|
105
|
+
targetTypeName: string;
|
|
106
|
+
targetId: string;
|
|
107
|
+
relationName: string;
|
|
108
|
+
}
|
|
109
|
+
interface EntityReplaceRelationsPayload {
|
|
110
|
+
targetTypeName: string;
|
|
111
|
+
targetIds: string[];
|
|
112
|
+
relationName: string;
|
|
113
|
+
}
|
|
114
|
+
interface EntityRelationRecord {
|
|
115
|
+
id?: string;
|
|
116
|
+
source_id: string;
|
|
117
|
+
target_id: string;
|
|
118
|
+
relation_name: string;
|
|
119
|
+
target_type_name?: string;
|
|
120
|
+
target?: EntityRecord<any>;
|
|
89
121
|
}
|
|
90
|
-
declare function getDefaultStorage(): StorageAdapter;
|
|
91
122
|
|
|
92
123
|
declare class AuthClient {
|
|
93
124
|
private gatewayUrl;
|
|
94
125
|
private tenantId;
|
|
95
126
|
private storage;
|
|
96
127
|
private storageKey;
|
|
128
|
+
private refreshStorageKey;
|
|
97
129
|
private token;
|
|
130
|
+
private refreshTokenValue;
|
|
98
131
|
private fetchFn;
|
|
99
132
|
private static TOKEN_KEY_PREFIX;
|
|
100
133
|
constructor(options: {
|
|
@@ -106,7 +139,9 @@ declare class AuthClient {
|
|
|
106
139
|
fetchFn?: typeof fetch;
|
|
107
140
|
});
|
|
108
141
|
getToken(): string | null;
|
|
142
|
+
getRefreshToken(): string | null;
|
|
109
143
|
setToken(token: string | null): void;
|
|
144
|
+
setRefreshToken(token: string | null): void;
|
|
110
145
|
isAuthenticated(): boolean;
|
|
111
146
|
/**
|
|
112
147
|
* Synchronously parse and return current authenticated user from JWT token
|
|
@@ -136,34 +171,55 @@ declare class AuthClient {
|
|
|
136
171
|
password: string;
|
|
137
172
|
}): Promise<AuthResponse>;
|
|
138
173
|
/**
|
|
139
|
-
*
|
|
174
|
+
* Authenticate via Google OAuth ID token
|
|
140
175
|
*/
|
|
141
|
-
|
|
176
|
+
loginWithGoogle(token: string): Promise<AuthResponse>;
|
|
142
177
|
/**
|
|
143
|
-
*
|
|
178
|
+
* Renew expired access token using stored or provided refresh token
|
|
144
179
|
*/
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
declare class SchemaClient {
|
|
149
|
-
private gatewayUrl;
|
|
150
|
-
private tenantId;
|
|
151
|
-
private getToken;
|
|
152
|
-
private fetchFn;
|
|
153
|
-
constructor(options: {
|
|
154
|
-
gatewayUrl: string;
|
|
155
|
-
tenantId: string;
|
|
156
|
-
getToken: () => string | null;
|
|
157
|
-
fetchFn?: typeof fetch;
|
|
158
|
-
});
|
|
159
|
-
private getHeaders;
|
|
180
|
+
refreshToken(refreshToken?: string): Promise<AuthResponse>;
|
|
160
181
|
/**
|
|
161
|
-
*
|
|
182
|
+
* Request password reset email
|
|
162
183
|
*/
|
|
163
|
-
|
|
184
|
+
forgotPassword(data: {
|
|
185
|
+
email: string;
|
|
186
|
+
frontendUrl?: string;
|
|
187
|
+
} | string): Promise<{
|
|
164
188
|
success: boolean;
|
|
165
|
-
|
|
189
|
+
message: string;
|
|
190
|
+
}>;
|
|
191
|
+
/**
|
|
192
|
+
* Complete password reset using action token
|
|
193
|
+
*/
|
|
194
|
+
resetPassword(data: {
|
|
195
|
+
token: string;
|
|
196
|
+
newPassword: string;
|
|
197
|
+
}): Promise<{
|
|
198
|
+
success: boolean;
|
|
199
|
+
message: string;
|
|
166
200
|
}>;
|
|
201
|
+
/**
|
|
202
|
+
* Change password for current or specified user
|
|
203
|
+
*/
|
|
204
|
+
changePassword(data: {
|
|
205
|
+
oldPassword: string;
|
|
206
|
+
newPassword: string;
|
|
207
|
+
}, userId?: string): Promise<{
|
|
208
|
+
success: boolean;
|
|
209
|
+
message?: string;
|
|
210
|
+
}>;
|
|
211
|
+
/**
|
|
212
|
+
* Update profile attributes for current or specified user
|
|
213
|
+
*/
|
|
214
|
+
updateProfile(data: Partial<AuthUser> & Record<string, any>, userId?: string): Promise<AuthUser>;
|
|
215
|
+
/**
|
|
216
|
+
* Fetch current authenticated user profile
|
|
217
|
+
*/
|
|
218
|
+
getProfile(): Promise<AuthUser>;
|
|
219
|
+
/**
|
|
220
|
+
* Log out and clear saved tokens
|
|
221
|
+
*/
|
|
222
|
+
logout(): void;
|
|
167
223
|
}
|
|
168
224
|
|
|
169
225
|
declare class EntityQueryBuilder<T = Record<string, any>> {
|
|
@@ -201,6 +257,11 @@ declare class EntityQueryBuilder<T = Record<string, any>> {
|
|
|
201
257
|
* Filter entities connected by graph relationship
|
|
202
258
|
*/
|
|
203
259
|
related(relationName: string, entityIds: string | string[]): this;
|
|
260
|
+
/**
|
|
261
|
+
* Declaratively expand graph relations (Supabase-style join expansion)
|
|
262
|
+
* Example: .include('placed_by', 'payment', 'items')
|
|
263
|
+
*/
|
|
264
|
+
include(...relations: string[]): this;
|
|
204
265
|
orderBy(field: string, direction?: 'asc' | 'desc'): this;
|
|
205
266
|
limit(limit: number): this;
|
|
206
267
|
page(page: number, limit?: number): this;
|
|
@@ -212,9 +273,12 @@ declare class EntityQueryBuilder<T = Record<string, any>> {
|
|
|
212
273
|
*/
|
|
213
274
|
list(): Promise<EntityListResponse<T>>;
|
|
214
275
|
/**
|
|
215
|
-
* Fetch a single entity by ID
|
|
276
|
+
* Fetch a single entity by ID with optional expansion and flattening
|
|
216
277
|
*/
|
|
217
|
-
get(id: string
|
|
278
|
+
get(id: string, options?: {
|
|
279
|
+
flat?: boolean;
|
|
280
|
+
include?: string[];
|
|
281
|
+
}): Promise<EntityRecord<T>>;
|
|
218
282
|
/**
|
|
219
283
|
* Create a new entity record matching schema
|
|
220
284
|
*/
|
|
@@ -229,6 +293,65 @@ declare class EntityQueryBuilder<T = Record<string, any>> {
|
|
|
229
293
|
delete(id: string): Promise<{
|
|
230
294
|
success: boolean;
|
|
231
295
|
}>;
|
|
296
|
+
/**
|
|
297
|
+
* Fetch revision history for an entity record
|
|
298
|
+
*/
|
|
299
|
+
revisions(id: string): Promise<EntityRevision<T>[]>;
|
|
300
|
+
/**
|
|
301
|
+
* Fetch all graph relations for this entity record
|
|
302
|
+
*/
|
|
303
|
+
getRelations(id: string, lang?: string): Promise<EntityRelationRecord[]>;
|
|
304
|
+
/**
|
|
305
|
+
* Link this record to another entity record
|
|
306
|
+
*/
|
|
307
|
+
link(id: string, payload: EntityRelationPayload): Promise<{
|
|
308
|
+
success: boolean;
|
|
309
|
+
}>;
|
|
310
|
+
/**
|
|
311
|
+
* Replace the full set of relations of one relation name
|
|
312
|
+
*/
|
|
313
|
+
setLinks(id: string, payload: EntityReplaceRelationsPayload): Promise<{
|
|
314
|
+
success: boolean;
|
|
315
|
+
}>;
|
|
316
|
+
/**
|
|
317
|
+
* Remove one graph link between two records
|
|
318
|
+
*/
|
|
319
|
+
unlink(id: string, relationName: string, targetId: string, targetTypeName: string): Promise<{
|
|
320
|
+
success: boolean;
|
|
321
|
+
}>;
|
|
322
|
+
/**
|
|
323
|
+
* Execute a type-level workflow plugin action (e.g. checkout, batch-process)
|
|
324
|
+
*/
|
|
325
|
+
action<R = any>(actionName: string, payload?: object): Promise<R>;
|
|
326
|
+
/**
|
|
327
|
+
* Execute an instance-level workflow plugin action (e.g. cancel order, approve)
|
|
328
|
+
*/
|
|
329
|
+
instanceAction<R = any>(id: string, actionName: string, payload?: object): Promise<R>;
|
|
330
|
+
/**
|
|
331
|
+
* Export matching entity records to CSV format with active filters
|
|
332
|
+
*/
|
|
333
|
+
exportCsv(): Promise<string>;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
declare class SchemaClient {
|
|
337
|
+
private gatewayUrl;
|
|
338
|
+
private tenantId;
|
|
339
|
+
private getToken;
|
|
340
|
+
private fetchFn;
|
|
341
|
+
constructor(options: {
|
|
342
|
+
gatewayUrl: string;
|
|
343
|
+
tenantId: string;
|
|
344
|
+
getToken: () => string | null;
|
|
345
|
+
fetchFn?: typeof fetch;
|
|
346
|
+
});
|
|
347
|
+
private getHeaders;
|
|
348
|
+
/**
|
|
349
|
+
* Define a new JSON Schema or alter an existing schema for an entity type in real-time
|
|
350
|
+
*/
|
|
351
|
+
define(definition: EntitySchemaDefinition): Promise<{
|
|
352
|
+
success: boolean;
|
|
353
|
+
version?: number;
|
|
354
|
+
}>;
|
|
232
355
|
}
|
|
233
356
|
|
|
234
357
|
declare class Zone4CodeClient {
|
|
@@ -247,6 +370,10 @@ declare class Zone4CodeClient {
|
|
|
247
370
|
* Alias for .from(typeName)
|
|
248
371
|
*/
|
|
249
372
|
entities<T = Record<string, any>>(typeName: string): EntityQueryBuilder<T>;
|
|
373
|
+
/**
|
|
374
|
+
* Get current authenticated user profile and platform wallet
|
|
375
|
+
*/
|
|
376
|
+
getMe(): Promise<UserProfileWithWallet>;
|
|
250
377
|
/**
|
|
251
378
|
* Check gateway connectivity & health
|
|
252
379
|
*/
|
|
@@ -260,4 +387,12 @@ declare class Zone4CodeClient {
|
|
|
260
387
|
*/
|
|
261
388
|
declare function createClient(config: Zone4CodeConfig): Zone4CodeClient;
|
|
262
389
|
|
|
263
|
-
|
|
390
|
+
declare class MemoryStorage implements StorageAdapter {
|
|
391
|
+
private store;
|
|
392
|
+
getItem(key: string): string | null;
|
|
393
|
+
setItem(key: string, value: string): void;
|
|
394
|
+
removeItem(key: string): void;
|
|
395
|
+
}
|
|
396
|
+
declare function getDefaultStorage(): StorageAdapter;
|
|
397
|
+
|
|
398
|
+
export { AuthClient, type AuthResponse, type AuthUser, type EntityListResponse, EntityQueryBuilder, type EntityRecord, type EntityRelationPayload, type EntityRelationRecord, type EntityReplaceRelationsPayload, type EntityRevision, type EntitySchemaDefinition, type FilterOperator, MemoryStorage, SchemaClient, type SchemaProperty, type StorageAdapter, type UserProfileWithWallet, Zone4CodeClient, type Zone4CodeConfig, createClient, createClient as default, getDefaultStorage };
|