@dyrected/sdk 2.5.40 → 2.5.41
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/dist/index.cjs +48 -19
- package/dist/index.d.cts +44 -35
- package/dist/index.d.ts +44 -35
- package/dist/index.js +48 -19
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -73,7 +73,8 @@ var QueryBuilder = class {
|
|
|
73
73
|
executor;
|
|
74
74
|
args = {};
|
|
75
75
|
where(where) {
|
|
76
|
-
|
|
76
|
+
const currentWhere = this.args.where;
|
|
77
|
+
this.args.where = currentWhere && typeof currentWhere === "object" ? { ...currentWhere, ...where } : { ...where };
|
|
77
78
|
return this;
|
|
78
79
|
}
|
|
79
80
|
sort(sort) {
|
|
@@ -165,6 +166,15 @@ var DyrectedClient = class {
|
|
|
165
166
|
async getSchemas() {
|
|
166
167
|
return this.request("/api/schemas");
|
|
167
168
|
}
|
|
169
|
+
async getAdminAuthConfig() {
|
|
170
|
+
return this.request("/api/admin/auth/providers");
|
|
171
|
+
}
|
|
172
|
+
async exchangeAdminAuth(providerId, body) {
|
|
173
|
+
return this.request(`/api/admin/auth/${providerId}/exchange`, {
|
|
174
|
+
method: "POST",
|
|
175
|
+
body: JSON.stringify(body)
|
|
176
|
+
});
|
|
177
|
+
}
|
|
168
178
|
async getPreference(key, options) {
|
|
169
179
|
const scopeParam = options?.scope ? `?scope=${options.scope}` : "";
|
|
170
180
|
return this.request(`/api/preferences/${encodeURIComponent(key)}${scopeParam}`);
|
|
@@ -192,8 +202,8 @@ var DyrectedClient = class {
|
|
|
192
202
|
async find(collection, args = {}) {
|
|
193
203
|
const { initialData, ...queryArgs } = args;
|
|
194
204
|
const normalizedArgs = { ...queryArgs };
|
|
195
|
-
if (
|
|
196
|
-
normalizedArgs.where = JSON.stringify(
|
|
205
|
+
if (queryArgs.where && typeof queryArgs.where === "object") {
|
|
206
|
+
normalizedArgs.where = JSON.stringify(queryArgs.where);
|
|
197
207
|
}
|
|
198
208
|
const query = stringifyQuery(normalizedArgs, { addQueryPrefix: true });
|
|
199
209
|
const res = await this.request(`/api/collections/${collection}${query}`);
|
|
@@ -220,9 +230,12 @@ var DyrectedClient = class {
|
|
|
220
230
|
collection(slug) {
|
|
221
231
|
return {
|
|
222
232
|
find: (args) => {
|
|
223
|
-
const qb = new QueryBuilder(
|
|
233
|
+
const qb = new QueryBuilder(
|
|
234
|
+
slug,
|
|
235
|
+
(collectionName, queryArgs) => this.find(collectionName, queryArgs)
|
|
236
|
+
);
|
|
224
237
|
if (args) {
|
|
225
|
-
if (args.where) qb.where(args.where);
|
|
238
|
+
if (args.where && typeof args.where === "object") qb.where(args.where);
|
|
226
239
|
if (args.sort) qb.sort(args.sort);
|
|
227
240
|
if (args.limit) qb.limit(args.limit);
|
|
228
241
|
if (args.page) qb.page(args.page);
|
|
@@ -446,7 +459,8 @@ var DyrectedClient = class {
|
|
|
446
459
|
});
|
|
447
460
|
}
|
|
448
461
|
async listMedia(args = {}, collection = "media") {
|
|
449
|
-
|
|
462
|
+
const query = stringifyQuery(normalizeQueryArgs(args), { addQueryPrefix: true });
|
|
463
|
+
return this.request(`/api/collections/${collection}${query}`);
|
|
450
464
|
}
|
|
451
465
|
/** @deprecated Use client.collection('media').upload(file, data) instead */
|
|
452
466
|
async uploadMedia(file, collection = "media") {
|
|
@@ -466,10 +480,7 @@ var DyrectedClient = class {
|
|
|
466
480
|
const { "Content-Type": _, ...headers } = this.headers;
|
|
467
481
|
return this.request(`/api/collections/${collection}`, {
|
|
468
482
|
method: "POST",
|
|
469
|
-
headers
|
|
470
|
-
...headers,
|
|
471
|
-
"Content-Type": void 0
|
|
472
|
-
},
|
|
483
|
+
headers,
|
|
473
484
|
body: formData
|
|
474
485
|
});
|
|
475
486
|
}
|
|
@@ -478,15 +489,7 @@ var DyrectedClient = class {
|
|
|
478
489
|
}
|
|
479
490
|
async request(path, init) {
|
|
480
491
|
const url = `${this.baseUrl}${path}`;
|
|
481
|
-
const allHeaders =
|
|
482
|
-
...this.headers,
|
|
483
|
-
...init?.headers
|
|
484
|
-
};
|
|
485
|
-
Object.keys(allHeaders).forEach((key) => {
|
|
486
|
-
if (allHeaders[key] === void 0) {
|
|
487
|
-
delete allHeaders[key];
|
|
488
|
-
}
|
|
489
|
-
});
|
|
492
|
+
const allHeaders = mergeHeaders(this.headers, init?.headers);
|
|
490
493
|
const res = await this.fetch(url, {
|
|
491
494
|
...init,
|
|
492
495
|
headers: allHeaders
|
|
@@ -525,6 +528,32 @@ function isFunctionallyEmpty(obj) {
|
|
|
525
528
|
}
|
|
526
529
|
return false;
|
|
527
530
|
}
|
|
531
|
+
function mergeHeaders(baseHeaders, overrideHeaders) {
|
|
532
|
+
const merged = new Headers(baseHeaders);
|
|
533
|
+
if (overrideHeaders instanceof Headers) {
|
|
534
|
+
overrideHeaders.forEach((value, key) => merged.set(key, value));
|
|
535
|
+
} else if (Array.isArray(overrideHeaders)) {
|
|
536
|
+
for (const [key, value] of overrideHeaders) {
|
|
537
|
+
merged.set(key, value);
|
|
538
|
+
}
|
|
539
|
+
} else if (overrideHeaders) {
|
|
540
|
+
for (const [key, value] of Object.entries(overrideHeaders)) {
|
|
541
|
+
if (value === void 0) {
|
|
542
|
+
merged.delete(key);
|
|
543
|
+
} else {
|
|
544
|
+
merged.set(key, String(value));
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return Object.fromEntries(merged.entries());
|
|
549
|
+
}
|
|
550
|
+
function normalizeQueryArgs(args) {
|
|
551
|
+
const normalizedArgs = { ...args };
|
|
552
|
+
if (args.where && typeof args.where === "object") {
|
|
553
|
+
normalizedArgs.where = JSON.stringify(args.where);
|
|
554
|
+
}
|
|
555
|
+
return normalizedArgs;
|
|
556
|
+
}
|
|
528
557
|
// Annotate the CommonJS export names for ESM import in node:
|
|
529
558
|
0 && (module.exports = {
|
|
530
559
|
DyrectedClient,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,29 +1,38 @@
|
|
|
1
|
-
import { PaginatedResult,
|
|
2
|
-
export { AdminIconName, Block, CollectionConfig, Field, FieldType, GlobalConfig, LifecycleEvent, FileData as Media, PaginatedResult, WorkflowMetadata } from '@dyrected/core';
|
|
1
|
+
import { PaginatedResult, CollectionConfig, GlobalConfig, AdminConfig, PublicAdminAuthConfig, FileData, WorkflowMetadata } from '@dyrected/core';
|
|
2
|
+
export { AdminIconName, Block, CollectionConfig, EmailField, Field, FieldType, GlobalConfig, IconField, LifecycleEvent, FileData as Media, NumberField, PaginatedResult, TextField, TextareaField, UrlField, WorkflowMetadata } from '@dyrected/core';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
type UnknownRecord$1 = Record<string, unknown>;
|
|
5
|
+
interface QueryArgs<TDoc = UnknownRecord$1> {
|
|
5
6
|
limit?: number;
|
|
6
7
|
page?: number;
|
|
7
8
|
depth?: number;
|
|
8
|
-
where?:
|
|
9
|
+
where?: UnknownRecord$1 | string;
|
|
9
10
|
sort?: string;
|
|
10
|
-
initialData?:
|
|
11
|
+
initialData?: TDoc[];
|
|
11
12
|
}
|
|
12
|
-
declare class QueryBuilder<T =
|
|
13
|
+
declare class QueryBuilder<T = UnknownRecord$1> {
|
|
13
14
|
private collection;
|
|
14
15
|
private executor;
|
|
15
16
|
private args;
|
|
16
|
-
constructor(collection: string, executor: (collection: string, args: QueryArgs) => Promise<PaginatedResult<T>>);
|
|
17
|
-
where(where:
|
|
17
|
+
constructor(collection: string, executor: (collection: string, args: QueryArgs<T>) => Promise<PaginatedResult<T>>);
|
|
18
|
+
where(where: UnknownRecord$1): this;
|
|
18
19
|
sort(sort: string): this;
|
|
19
20
|
limit(limit: number): this;
|
|
20
21
|
page(page: number): this;
|
|
21
22
|
depth(depth: number): this;
|
|
22
23
|
seed(data: T[]): this;
|
|
23
24
|
exec(): Promise<PaginatedResult<T>>;
|
|
24
|
-
then<TResult1 = PaginatedResult<T>, TResult2 = never>(onfulfilled?: ((value: PaginatedResult<T>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason:
|
|
25
|
+
then<TResult1 = PaginatedResult<T>, TResult2 = never>(onfulfilled?: ((value: PaginatedResult<T>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
type UnknownRecord = Record<string, unknown>;
|
|
29
|
+
type SchemaResponse = {
|
|
30
|
+
collections: CollectionConfig[];
|
|
31
|
+
globals: GlobalConfig[];
|
|
32
|
+
admin?: AdminConfig;
|
|
33
|
+
adminAuth?: PublicAdminAuthConfig;
|
|
34
|
+
};
|
|
35
|
+
|
|
27
36
|
/** Shape of a document returned from a workflow-enabled collection. */
|
|
28
37
|
interface WorkflowDocument {
|
|
29
38
|
id: string;
|
|
@@ -82,7 +91,7 @@ type ExtractDoc<T> = T extends CollectionConfig<infer TDoc> ? TDoc : T extends G
|
|
|
82
91
|
* // client.global('settings').get() → { siteName?: string; ... }
|
|
83
92
|
* ```
|
|
84
93
|
*/
|
|
85
|
-
type InferSchema<TCollections extends Record<string, CollectionConfig<
|
|
94
|
+
type InferSchema<TCollections extends Record<string, CollectionConfig<UnknownRecord>>, TGlobals extends Record<string, GlobalConfig<UnknownRecord>> = Record<never, never>> = {
|
|
86
95
|
collections: {
|
|
87
96
|
[K in keyof TCollections]: ExtractDoc<TCollections[K]>;
|
|
88
97
|
};
|
|
@@ -114,10 +123,10 @@ interface DyrectedClientConfig {
|
|
|
114
123
|
defaultDepth?: number;
|
|
115
124
|
}
|
|
116
125
|
interface BaseSchema {
|
|
117
|
-
collections: Record<string,
|
|
118
|
-
globals: Record<string,
|
|
126
|
+
collections: Record<string, UnknownRecord>;
|
|
127
|
+
globals: Record<string, UnknownRecord>;
|
|
119
128
|
}
|
|
120
|
-
declare class DyrectedClient<TSchema extends BaseSchema =
|
|
129
|
+
declare class DyrectedClient<TSchema extends BaseSchema = BaseSchema> {
|
|
121
130
|
private baseUrl;
|
|
122
131
|
private headers;
|
|
123
132
|
private fetch;
|
|
@@ -140,9 +149,12 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
|
|
|
140
149
|
*/
|
|
141
150
|
getAuthHeaders(): Record<string, string>;
|
|
142
151
|
getBaseUrl(): string;
|
|
143
|
-
getSchemas(): Promise<
|
|
144
|
-
|
|
145
|
-
|
|
152
|
+
getSchemas(): Promise<SchemaResponse>;
|
|
153
|
+
getAdminAuthConfig(): Promise<PublicAdminAuthConfig>;
|
|
154
|
+
exchangeAdminAuth(providerId: string, body: Record<string, unknown>): Promise<{
|
|
155
|
+
token: string;
|
|
156
|
+
collectionSlug: string;
|
|
157
|
+
providerId: string;
|
|
146
158
|
}>;
|
|
147
159
|
getPreference<T = unknown>(key: string, options?: {
|
|
148
160
|
scope?: "personal" | "global";
|
|
@@ -165,19 +177,19 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
|
|
|
165
177
|
* Fetch draft data for a specific preview token.
|
|
166
178
|
* Used in "token" preview mode.
|
|
167
179
|
*/
|
|
168
|
-
getPreviewData(token: string): Promise<
|
|
169
|
-
find<K extends keyof TSchema["collections"]>(collection: K & string, args?: QueryArgs): Promise<PaginatedResult<TSchema["collections"][K]>>;
|
|
180
|
+
getPreviewData<T = unknown>(token: string): Promise<T>;
|
|
181
|
+
find<K extends keyof TSchema["collections"]>(collection: K & string, args?: QueryArgs<TSchema["collections"][K]>): Promise<PaginatedResult<TSchema["collections"][K]>>;
|
|
170
182
|
/**
|
|
171
183
|
* Returns a fluent query builder for a collection.
|
|
172
184
|
*/
|
|
173
185
|
collection<K extends keyof TSchema["collections"]>(slug: K & string): {
|
|
174
|
-
find: (args?: QueryArgs) => QueryBuilder<TSchema["collections"][K]>;
|
|
186
|
+
find: (args?: QueryArgs<TSchema["collections"][K]>) => QueryBuilder<TSchema["collections"][K]>;
|
|
175
187
|
findOne: (id: string, args?: {
|
|
176
188
|
depth?: number;
|
|
177
189
|
initialData?: TSchema["collections"][K];
|
|
178
190
|
}) => Promise<TSchema["collections"][K]>;
|
|
179
|
-
create: (data:
|
|
180
|
-
update: (id: string, data:
|
|
191
|
+
create: (data: Partial<TSchema["collections"][K]>) => Promise<TSchema["collections"][K]>;
|
|
192
|
+
update: (id: string, data: Partial<TSchema["collections"][K]>) => Promise<TSchema["collections"][K]>;
|
|
181
193
|
delete: (id: string) => Promise<{
|
|
182
194
|
message: string;
|
|
183
195
|
}>;
|
|
@@ -189,7 +201,7 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
|
|
|
189
201
|
* @param file - A File or Blob (browser) or Buffer with filename/mimeType (Node.js)
|
|
190
202
|
* @param data - Additional metadata fields to save alongside the file (e.g. alt, caption)
|
|
191
203
|
*/
|
|
192
|
-
upload: (file: File | Blob, data?: Record<string, string>) => Promise<
|
|
204
|
+
upload: (file: File | Blob, data?: Record<string, string>) => Promise<FileData>;
|
|
193
205
|
/**
|
|
194
206
|
* Log in with email + password. Returns a JWT token and the user document.
|
|
195
207
|
* Call `client.setToken(token)` afterwards to authenticate subsequent requests.
|
|
@@ -213,7 +225,7 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
|
|
|
213
225
|
initialized: boolean;
|
|
214
226
|
}>;
|
|
215
227
|
/** Register the very first user in an empty auth collection. */
|
|
216
|
-
registerFirstUser: (data:
|
|
228
|
+
registerFirstUser: (data: UnknownRecord) => Promise<{
|
|
217
229
|
token: string;
|
|
218
230
|
user: TSchema["collections"][K];
|
|
219
231
|
}>;
|
|
@@ -223,7 +235,7 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
|
|
|
223
235
|
message: string;
|
|
224
236
|
}>;
|
|
225
237
|
/** Accept an invitation and create an account. Returns token + user. */
|
|
226
|
-
acceptInvite: (token: string, password: string, extraFields?:
|
|
238
|
+
acceptInvite: (token: string, password: string, extraFields?: UnknownRecord) => Promise<{
|
|
227
239
|
token: string;
|
|
228
240
|
user: TSchema["collections"][K];
|
|
229
241
|
}>;
|
|
@@ -295,14 +307,14 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
|
|
|
295
307
|
depth?: number;
|
|
296
308
|
initialData?: TSchema["globals"][K];
|
|
297
309
|
}) => Promise<TSchema["globals"][K]>;
|
|
298
|
-
update: (data:
|
|
310
|
+
update: (data: Partial<TSchema["globals"][K]>) => Promise<TSchema["globals"][K]>;
|
|
299
311
|
};
|
|
300
|
-
findOne<T =
|
|
312
|
+
findOne<T = UnknownRecord>(collection: string, id: string, args?: {
|
|
301
313
|
depth?: number;
|
|
302
314
|
initialData?: T;
|
|
303
315
|
}): Promise<T>;
|
|
304
|
-
create<T =
|
|
305
|
-
update<T =
|
|
316
|
+
create<T = UnknownRecord>(collection: string, data: Partial<T>): Promise<T>;
|
|
317
|
+
update<T = UnknownRecord>(collection: string, id: string, data: Partial<T>): Promise<T>;
|
|
306
318
|
delete(collection: string, id: string): Promise<{
|
|
307
319
|
message: string;
|
|
308
320
|
}>;
|
|
@@ -336,12 +348,12 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
|
|
|
336
348
|
deleteMany(collection: string, ids: string[]): Promise<{
|
|
337
349
|
message: string;
|
|
338
350
|
}>;
|
|
339
|
-
getGlobal<T =
|
|
351
|
+
getGlobal<T = UnknownRecord>(slug: string, args?: {
|
|
340
352
|
depth?: number;
|
|
341
353
|
initialData?: T;
|
|
342
354
|
}): Promise<T>;
|
|
343
|
-
updateGlobal<T =
|
|
344
|
-
listMedia(args?: QueryArgs
|
|
355
|
+
updateGlobal<T = UnknownRecord>(slug: string, data: Partial<T>): Promise<T>;
|
|
356
|
+
listMedia(args?: QueryArgs<FileData>, collection?: string): Promise<PaginatedResult<FileData>>;
|
|
345
357
|
/** @deprecated Use client.collection('media').upload(file, data) instead */
|
|
346
358
|
uploadMedia(file: File, collection?: string): Promise<FileData>;
|
|
347
359
|
/**
|
|
@@ -353,9 +365,6 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
|
|
|
353
365
|
}>;
|
|
354
366
|
private request;
|
|
355
367
|
}
|
|
356
|
-
declare function createClient<TSchema extends
|
|
357
|
-
collections: any;
|
|
358
|
-
globals: any;
|
|
359
|
-
} = any>(config: DyrectedClientConfig): DyrectedClient<TSchema>;
|
|
368
|
+
declare function createClient<TSchema extends BaseSchema = BaseSchema>(config: DyrectedClientConfig): DyrectedClient<TSchema>;
|
|
360
369
|
|
|
361
370
|
export { type BaseSchema, DyrectedClient, type DyrectedClientConfig, DyrectedError, type InferSchema, type TransitionOptions, type WorkflowDocument, type WorkflowHistoryEntry, createClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,29 +1,38 @@
|
|
|
1
|
-
import { PaginatedResult,
|
|
2
|
-
export { AdminIconName, Block, CollectionConfig, Field, FieldType, GlobalConfig, LifecycleEvent, FileData as Media, PaginatedResult, WorkflowMetadata } from '@dyrected/core';
|
|
1
|
+
import { PaginatedResult, CollectionConfig, GlobalConfig, AdminConfig, PublicAdminAuthConfig, FileData, WorkflowMetadata } from '@dyrected/core';
|
|
2
|
+
export { AdminIconName, Block, CollectionConfig, EmailField, Field, FieldType, GlobalConfig, IconField, LifecycleEvent, FileData as Media, NumberField, PaginatedResult, TextField, TextareaField, UrlField, WorkflowMetadata } from '@dyrected/core';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
type UnknownRecord$1 = Record<string, unknown>;
|
|
5
|
+
interface QueryArgs<TDoc = UnknownRecord$1> {
|
|
5
6
|
limit?: number;
|
|
6
7
|
page?: number;
|
|
7
8
|
depth?: number;
|
|
8
|
-
where?:
|
|
9
|
+
where?: UnknownRecord$1 | string;
|
|
9
10
|
sort?: string;
|
|
10
|
-
initialData?:
|
|
11
|
+
initialData?: TDoc[];
|
|
11
12
|
}
|
|
12
|
-
declare class QueryBuilder<T =
|
|
13
|
+
declare class QueryBuilder<T = UnknownRecord$1> {
|
|
13
14
|
private collection;
|
|
14
15
|
private executor;
|
|
15
16
|
private args;
|
|
16
|
-
constructor(collection: string, executor: (collection: string, args: QueryArgs) => Promise<PaginatedResult<T>>);
|
|
17
|
-
where(where:
|
|
17
|
+
constructor(collection: string, executor: (collection: string, args: QueryArgs<T>) => Promise<PaginatedResult<T>>);
|
|
18
|
+
where(where: UnknownRecord$1): this;
|
|
18
19
|
sort(sort: string): this;
|
|
19
20
|
limit(limit: number): this;
|
|
20
21
|
page(page: number): this;
|
|
21
22
|
depth(depth: number): this;
|
|
22
23
|
seed(data: T[]): this;
|
|
23
24
|
exec(): Promise<PaginatedResult<T>>;
|
|
24
|
-
then<TResult1 = PaginatedResult<T>, TResult2 = never>(onfulfilled?: ((value: PaginatedResult<T>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason:
|
|
25
|
+
then<TResult1 = PaginatedResult<T>, TResult2 = never>(onfulfilled?: ((value: PaginatedResult<T>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
type UnknownRecord = Record<string, unknown>;
|
|
29
|
+
type SchemaResponse = {
|
|
30
|
+
collections: CollectionConfig[];
|
|
31
|
+
globals: GlobalConfig[];
|
|
32
|
+
admin?: AdminConfig;
|
|
33
|
+
adminAuth?: PublicAdminAuthConfig;
|
|
34
|
+
};
|
|
35
|
+
|
|
27
36
|
/** Shape of a document returned from a workflow-enabled collection. */
|
|
28
37
|
interface WorkflowDocument {
|
|
29
38
|
id: string;
|
|
@@ -82,7 +91,7 @@ type ExtractDoc<T> = T extends CollectionConfig<infer TDoc> ? TDoc : T extends G
|
|
|
82
91
|
* // client.global('settings').get() → { siteName?: string; ... }
|
|
83
92
|
* ```
|
|
84
93
|
*/
|
|
85
|
-
type InferSchema<TCollections extends Record<string, CollectionConfig<
|
|
94
|
+
type InferSchema<TCollections extends Record<string, CollectionConfig<UnknownRecord>>, TGlobals extends Record<string, GlobalConfig<UnknownRecord>> = Record<never, never>> = {
|
|
86
95
|
collections: {
|
|
87
96
|
[K in keyof TCollections]: ExtractDoc<TCollections[K]>;
|
|
88
97
|
};
|
|
@@ -114,10 +123,10 @@ interface DyrectedClientConfig {
|
|
|
114
123
|
defaultDepth?: number;
|
|
115
124
|
}
|
|
116
125
|
interface BaseSchema {
|
|
117
|
-
collections: Record<string,
|
|
118
|
-
globals: Record<string,
|
|
126
|
+
collections: Record<string, UnknownRecord>;
|
|
127
|
+
globals: Record<string, UnknownRecord>;
|
|
119
128
|
}
|
|
120
|
-
declare class DyrectedClient<TSchema extends BaseSchema =
|
|
129
|
+
declare class DyrectedClient<TSchema extends BaseSchema = BaseSchema> {
|
|
121
130
|
private baseUrl;
|
|
122
131
|
private headers;
|
|
123
132
|
private fetch;
|
|
@@ -140,9 +149,12 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
|
|
|
140
149
|
*/
|
|
141
150
|
getAuthHeaders(): Record<string, string>;
|
|
142
151
|
getBaseUrl(): string;
|
|
143
|
-
getSchemas(): Promise<
|
|
144
|
-
|
|
145
|
-
|
|
152
|
+
getSchemas(): Promise<SchemaResponse>;
|
|
153
|
+
getAdminAuthConfig(): Promise<PublicAdminAuthConfig>;
|
|
154
|
+
exchangeAdminAuth(providerId: string, body: Record<string, unknown>): Promise<{
|
|
155
|
+
token: string;
|
|
156
|
+
collectionSlug: string;
|
|
157
|
+
providerId: string;
|
|
146
158
|
}>;
|
|
147
159
|
getPreference<T = unknown>(key: string, options?: {
|
|
148
160
|
scope?: "personal" | "global";
|
|
@@ -165,19 +177,19 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
|
|
|
165
177
|
* Fetch draft data for a specific preview token.
|
|
166
178
|
* Used in "token" preview mode.
|
|
167
179
|
*/
|
|
168
|
-
getPreviewData(token: string): Promise<
|
|
169
|
-
find<K extends keyof TSchema["collections"]>(collection: K & string, args?: QueryArgs): Promise<PaginatedResult<TSchema["collections"][K]>>;
|
|
180
|
+
getPreviewData<T = unknown>(token: string): Promise<T>;
|
|
181
|
+
find<K extends keyof TSchema["collections"]>(collection: K & string, args?: QueryArgs<TSchema["collections"][K]>): Promise<PaginatedResult<TSchema["collections"][K]>>;
|
|
170
182
|
/**
|
|
171
183
|
* Returns a fluent query builder for a collection.
|
|
172
184
|
*/
|
|
173
185
|
collection<K extends keyof TSchema["collections"]>(slug: K & string): {
|
|
174
|
-
find: (args?: QueryArgs) => QueryBuilder<TSchema["collections"][K]>;
|
|
186
|
+
find: (args?: QueryArgs<TSchema["collections"][K]>) => QueryBuilder<TSchema["collections"][K]>;
|
|
175
187
|
findOne: (id: string, args?: {
|
|
176
188
|
depth?: number;
|
|
177
189
|
initialData?: TSchema["collections"][K];
|
|
178
190
|
}) => Promise<TSchema["collections"][K]>;
|
|
179
|
-
create: (data:
|
|
180
|
-
update: (id: string, data:
|
|
191
|
+
create: (data: Partial<TSchema["collections"][K]>) => Promise<TSchema["collections"][K]>;
|
|
192
|
+
update: (id: string, data: Partial<TSchema["collections"][K]>) => Promise<TSchema["collections"][K]>;
|
|
181
193
|
delete: (id: string) => Promise<{
|
|
182
194
|
message: string;
|
|
183
195
|
}>;
|
|
@@ -189,7 +201,7 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
|
|
|
189
201
|
* @param file - A File or Blob (browser) or Buffer with filename/mimeType (Node.js)
|
|
190
202
|
* @param data - Additional metadata fields to save alongside the file (e.g. alt, caption)
|
|
191
203
|
*/
|
|
192
|
-
upload: (file: File | Blob, data?: Record<string, string>) => Promise<
|
|
204
|
+
upload: (file: File | Blob, data?: Record<string, string>) => Promise<FileData>;
|
|
193
205
|
/**
|
|
194
206
|
* Log in with email + password. Returns a JWT token and the user document.
|
|
195
207
|
* Call `client.setToken(token)` afterwards to authenticate subsequent requests.
|
|
@@ -213,7 +225,7 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
|
|
|
213
225
|
initialized: boolean;
|
|
214
226
|
}>;
|
|
215
227
|
/** Register the very first user in an empty auth collection. */
|
|
216
|
-
registerFirstUser: (data:
|
|
228
|
+
registerFirstUser: (data: UnknownRecord) => Promise<{
|
|
217
229
|
token: string;
|
|
218
230
|
user: TSchema["collections"][K];
|
|
219
231
|
}>;
|
|
@@ -223,7 +235,7 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
|
|
|
223
235
|
message: string;
|
|
224
236
|
}>;
|
|
225
237
|
/** Accept an invitation and create an account. Returns token + user. */
|
|
226
|
-
acceptInvite: (token: string, password: string, extraFields?:
|
|
238
|
+
acceptInvite: (token: string, password: string, extraFields?: UnknownRecord) => Promise<{
|
|
227
239
|
token: string;
|
|
228
240
|
user: TSchema["collections"][K];
|
|
229
241
|
}>;
|
|
@@ -295,14 +307,14 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
|
|
|
295
307
|
depth?: number;
|
|
296
308
|
initialData?: TSchema["globals"][K];
|
|
297
309
|
}) => Promise<TSchema["globals"][K]>;
|
|
298
|
-
update: (data:
|
|
310
|
+
update: (data: Partial<TSchema["globals"][K]>) => Promise<TSchema["globals"][K]>;
|
|
299
311
|
};
|
|
300
|
-
findOne<T =
|
|
312
|
+
findOne<T = UnknownRecord>(collection: string, id: string, args?: {
|
|
301
313
|
depth?: number;
|
|
302
314
|
initialData?: T;
|
|
303
315
|
}): Promise<T>;
|
|
304
|
-
create<T =
|
|
305
|
-
update<T =
|
|
316
|
+
create<T = UnknownRecord>(collection: string, data: Partial<T>): Promise<T>;
|
|
317
|
+
update<T = UnknownRecord>(collection: string, id: string, data: Partial<T>): Promise<T>;
|
|
306
318
|
delete(collection: string, id: string): Promise<{
|
|
307
319
|
message: string;
|
|
308
320
|
}>;
|
|
@@ -336,12 +348,12 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
|
|
|
336
348
|
deleteMany(collection: string, ids: string[]): Promise<{
|
|
337
349
|
message: string;
|
|
338
350
|
}>;
|
|
339
|
-
getGlobal<T =
|
|
351
|
+
getGlobal<T = UnknownRecord>(slug: string, args?: {
|
|
340
352
|
depth?: number;
|
|
341
353
|
initialData?: T;
|
|
342
354
|
}): Promise<T>;
|
|
343
|
-
updateGlobal<T =
|
|
344
|
-
listMedia(args?: QueryArgs
|
|
355
|
+
updateGlobal<T = UnknownRecord>(slug: string, data: Partial<T>): Promise<T>;
|
|
356
|
+
listMedia(args?: QueryArgs<FileData>, collection?: string): Promise<PaginatedResult<FileData>>;
|
|
345
357
|
/** @deprecated Use client.collection('media').upload(file, data) instead */
|
|
346
358
|
uploadMedia(file: File, collection?: string): Promise<FileData>;
|
|
347
359
|
/**
|
|
@@ -353,9 +365,6 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
|
|
|
353
365
|
}>;
|
|
354
366
|
private request;
|
|
355
367
|
}
|
|
356
|
-
declare function createClient<TSchema extends
|
|
357
|
-
collections: any;
|
|
358
|
-
globals: any;
|
|
359
|
-
} = any>(config: DyrectedClientConfig): DyrectedClient<TSchema>;
|
|
368
|
+
declare function createClient<TSchema extends BaseSchema = BaseSchema>(config: DyrectedClientConfig): DyrectedClient<TSchema>;
|
|
360
369
|
|
|
361
370
|
export { type BaseSchema, DyrectedClient, type DyrectedClientConfig, DyrectedError, type InferSchema, type TransitionOptions, type WorkflowDocument, type WorkflowHistoryEntry, createClient };
|
package/dist/index.js
CHANGED
|
@@ -45,7 +45,8 @@ var QueryBuilder = class {
|
|
|
45
45
|
executor;
|
|
46
46
|
args = {};
|
|
47
47
|
where(where) {
|
|
48
|
-
|
|
48
|
+
const currentWhere = this.args.where;
|
|
49
|
+
this.args.where = currentWhere && typeof currentWhere === "object" ? { ...currentWhere, ...where } : { ...where };
|
|
49
50
|
return this;
|
|
50
51
|
}
|
|
51
52
|
sort(sort) {
|
|
@@ -137,6 +138,15 @@ var DyrectedClient = class {
|
|
|
137
138
|
async getSchemas() {
|
|
138
139
|
return this.request("/api/schemas");
|
|
139
140
|
}
|
|
141
|
+
async getAdminAuthConfig() {
|
|
142
|
+
return this.request("/api/admin/auth/providers");
|
|
143
|
+
}
|
|
144
|
+
async exchangeAdminAuth(providerId, body) {
|
|
145
|
+
return this.request(`/api/admin/auth/${providerId}/exchange`, {
|
|
146
|
+
method: "POST",
|
|
147
|
+
body: JSON.stringify(body)
|
|
148
|
+
});
|
|
149
|
+
}
|
|
140
150
|
async getPreference(key, options) {
|
|
141
151
|
const scopeParam = options?.scope ? `?scope=${options.scope}` : "";
|
|
142
152
|
return this.request(`/api/preferences/${encodeURIComponent(key)}${scopeParam}`);
|
|
@@ -164,8 +174,8 @@ var DyrectedClient = class {
|
|
|
164
174
|
async find(collection, args = {}) {
|
|
165
175
|
const { initialData, ...queryArgs } = args;
|
|
166
176
|
const normalizedArgs = { ...queryArgs };
|
|
167
|
-
if (
|
|
168
|
-
normalizedArgs.where = JSON.stringify(
|
|
177
|
+
if (queryArgs.where && typeof queryArgs.where === "object") {
|
|
178
|
+
normalizedArgs.where = JSON.stringify(queryArgs.where);
|
|
169
179
|
}
|
|
170
180
|
const query = stringifyQuery(normalizedArgs, { addQueryPrefix: true });
|
|
171
181
|
const res = await this.request(`/api/collections/${collection}${query}`);
|
|
@@ -192,9 +202,12 @@ var DyrectedClient = class {
|
|
|
192
202
|
collection(slug) {
|
|
193
203
|
return {
|
|
194
204
|
find: (args) => {
|
|
195
|
-
const qb = new QueryBuilder(
|
|
205
|
+
const qb = new QueryBuilder(
|
|
206
|
+
slug,
|
|
207
|
+
(collectionName, queryArgs) => this.find(collectionName, queryArgs)
|
|
208
|
+
);
|
|
196
209
|
if (args) {
|
|
197
|
-
if (args.where) qb.where(args.where);
|
|
210
|
+
if (args.where && typeof args.where === "object") qb.where(args.where);
|
|
198
211
|
if (args.sort) qb.sort(args.sort);
|
|
199
212
|
if (args.limit) qb.limit(args.limit);
|
|
200
213
|
if (args.page) qb.page(args.page);
|
|
@@ -418,7 +431,8 @@ var DyrectedClient = class {
|
|
|
418
431
|
});
|
|
419
432
|
}
|
|
420
433
|
async listMedia(args = {}, collection = "media") {
|
|
421
|
-
|
|
434
|
+
const query = stringifyQuery(normalizeQueryArgs(args), { addQueryPrefix: true });
|
|
435
|
+
return this.request(`/api/collections/${collection}${query}`);
|
|
422
436
|
}
|
|
423
437
|
/** @deprecated Use client.collection('media').upload(file, data) instead */
|
|
424
438
|
async uploadMedia(file, collection = "media") {
|
|
@@ -438,10 +452,7 @@ var DyrectedClient = class {
|
|
|
438
452
|
const { "Content-Type": _, ...headers } = this.headers;
|
|
439
453
|
return this.request(`/api/collections/${collection}`, {
|
|
440
454
|
method: "POST",
|
|
441
|
-
headers
|
|
442
|
-
...headers,
|
|
443
|
-
"Content-Type": void 0
|
|
444
|
-
},
|
|
455
|
+
headers,
|
|
445
456
|
body: formData
|
|
446
457
|
});
|
|
447
458
|
}
|
|
@@ -450,15 +461,7 @@ var DyrectedClient = class {
|
|
|
450
461
|
}
|
|
451
462
|
async request(path, init) {
|
|
452
463
|
const url = `${this.baseUrl}${path}`;
|
|
453
|
-
const allHeaders =
|
|
454
|
-
...this.headers,
|
|
455
|
-
...init?.headers
|
|
456
|
-
};
|
|
457
|
-
Object.keys(allHeaders).forEach((key) => {
|
|
458
|
-
if (allHeaders[key] === void 0) {
|
|
459
|
-
delete allHeaders[key];
|
|
460
|
-
}
|
|
461
|
-
});
|
|
464
|
+
const allHeaders = mergeHeaders(this.headers, init?.headers);
|
|
462
465
|
const res = await this.fetch(url, {
|
|
463
466
|
...init,
|
|
464
467
|
headers: allHeaders
|
|
@@ -497,6 +500,32 @@ function isFunctionallyEmpty(obj) {
|
|
|
497
500
|
}
|
|
498
501
|
return false;
|
|
499
502
|
}
|
|
503
|
+
function mergeHeaders(baseHeaders, overrideHeaders) {
|
|
504
|
+
const merged = new Headers(baseHeaders);
|
|
505
|
+
if (overrideHeaders instanceof Headers) {
|
|
506
|
+
overrideHeaders.forEach((value, key) => merged.set(key, value));
|
|
507
|
+
} else if (Array.isArray(overrideHeaders)) {
|
|
508
|
+
for (const [key, value] of overrideHeaders) {
|
|
509
|
+
merged.set(key, value);
|
|
510
|
+
}
|
|
511
|
+
} else if (overrideHeaders) {
|
|
512
|
+
for (const [key, value] of Object.entries(overrideHeaders)) {
|
|
513
|
+
if (value === void 0) {
|
|
514
|
+
merged.delete(key);
|
|
515
|
+
} else {
|
|
516
|
+
merged.set(key, String(value));
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return Object.fromEntries(merged.entries());
|
|
521
|
+
}
|
|
522
|
+
function normalizeQueryArgs(args) {
|
|
523
|
+
const normalizedArgs = { ...args };
|
|
524
|
+
if (args.where && typeof args.where === "object") {
|
|
525
|
+
normalizedArgs.where = JSON.stringify(args.where);
|
|
526
|
+
}
|
|
527
|
+
return normalizedArgs;
|
|
528
|
+
}
|
|
500
529
|
export {
|
|
501
530
|
DyrectedClient,
|
|
502
531
|
DyrectedError,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dyrected/sdk",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.41",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"tsup": "^8.5.1",
|
|
31
31
|
"typescript": "^5.4.5",
|
|
32
32
|
"vitest": "^1.0.0",
|
|
33
|
-
"@dyrected/core": "2.5.
|
|
33
|
+
"@dyrected/core": "2.5.41"
|
|
34
34
|
},
|
|
35
35
|
"license": "BSL-1.1",
|
|
36
36
|
"author": "Busola Okeowo <busolaokemoney@gmail.com>",
|