@tanglemedia/svelte-starter-directus-api 6.0.2 → 9.0.0-next.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/dist/adapter/api-adapter.d.ts +30 -24
- package/dist/adapter/api-adapter.js +117 -68
- package/dist/provider/api-adapter.provider.d.ts +4 -4
- package/dist/provider/api-references-functions.provider.d.ts +10 -1
- package/dist/provider/api-references-functions.provider.js +18 -3
- package/dist/provider/directus.factory.d.ts +2 -2
- package/dist/services/auth.d.ts +3 -2
- package/dist/services/auth.js +13 -5
- package/dist/types/adapter.types.d.ts +5 -3
- package/dist/types/adapter.types.js +1 -1
- package/package.json +12 -12
- package/src/adapter/api-adapter.ts +232 -112
- package/src/provider/api-adapter.provider.ts +11 -3
- package/src/provider/api-references-functions.provider.ts +261 -200
- package/src/provider/directus.factory.ts +7 -7
- package/src/services/auth.ts +21 -11
- package/src/types/adapter.types.ts +26 -9
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { ApiAdapterAbstract, type AnyObject, type ApiAdapterHandle, type ApiAdapterRequestConfig, type ApiAggregateQuery, type ApiCreateManyQuery, type ApiDeleteManyQuery, type ApiFindQuery, type ApiId, type ApiResponse, type ApiUpdateManyQuery, type BaseApiMethods, type HandleEvent } from '@tanglemedia/svelte-starter-core';
|
|
3
|
-
import type { DirectusConfig, SchemaShape } from '../types/adapter.types';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
export declare class DirectusApiAdapter<Schema extends SchemaShape = SchemaShape, Path extends RegularCollections<Schema> = RegularCollections<Schema>> extends ApiAdapterAbstract<DirectusConfig, ApiAdapterRequestConfig, Path, AdapterClient> implements ApiAdapterHandle {
|
|
1
|
+
import { type RegularCollections } from '@directus/sdk';
|
|
2
|
+
import { ApiAdapterAbstract, type AnyObject, type ApiAdapterHandle, type ApiAdapterRequestConfig, type ApiAggregateQuery, type ApiCreateManyQuery, type ApiDeleteManyQuery, type ApiFindQuery, type ApiId, type ApiPatchQuery, type ApiPostQuery, type ApiPutQuery, type ApiResponse, type ApiUpdateManyQuery, type BaseApiMethods, type HandleEvent } from '@tanglemedia/svelte-starter-core';
|
|
3
|
+
import type { DirectusAdapterClient, DirectusConfig, SchemaShape } from '../types/adapter.types';
|
|
4
|
+
type PathKey<Schema extends SchemaShape> = Extract<RegularCollections<Schema>, string>;
|
|
5
|
+
export type AdapterClient<Schema extends SchemaShape = SchemaShape> = DirectusAdapterClient<Schema>;
|
|
6
|
+
type Q = Record<string, unknown>;
|
|
7
|
+
export declare class DirectusApiAdapter<Schema extends SchemaShape = SchemaShape, Path extends PathKey<Schema> = PathKey<Schema>> extends ApiAdapterAbstract<DirectusConfig, ApiAdapterRequestConfig, Path, AdapterClient<Schema>> implements ApiAdapterHandle {
|
|
10
8
|
protected config: DirectusConfig;
|
|
11
9
|
private readonly directus;
|
|
12
10
|
constructor(config: DirectusConfig, directus: AdapterClient<Schema>);
|
|
@@ -19,22 +17,30 @@ export declare class DirectusApiAdapter<Schema extends SchemaShape = SchemaShape
|
|
|
19
17
|
total: number;
|
|
20
18
|
displayed: number;
|
|
21
19
|
};
|
|
22
|
-
includeTotals(collection:
|
|
20
|
+
includeTotals(collection: Path, query?: ApiFindQuery<any>): Promise<number | null>;
|
|
23
21
|
transformResponse<T, M extends object = AnyObject>(res: {
|
|
24
22
|
data: T;
|
|
25
23
|
meta?: AnyObject;
|
|
26
|
-
}, status?: number): Promise<ApiResponse<T,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
}, status?: number): Promise<ApiResponse<T, null, M>>;
|
|
25
|
+
normalizeQuery(config?: ApiAdapterRequestConfig, merge?: Q): {
|
|
26
|
+
[x: string]: unknown;
|
|
27
|
+
};
|
|
28
|
+
getId(data: object, config?: ApiAdapterRequestConfig): ApiId | null;
|
|
29
|
+
stripId(config?: ApiAdapterRequestConfig): ApiAdapterRequestConfig | undefined;
|
|
30
|
+
request<T, R = T>(method: BaseApiMethods, url: Path, query?: ApiAdapterRequestConfig): Promise<ApiResponse<R>>;
|
|
31
|
+
find<T, F = T, R = T>(collection: Path, query: ApiFindQuery<F>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R[]>>;
|
|
32
|
+
findOne<T, R = T>(collection: Path, key: ApiId, query?: ApiAdapterRequestConfig): Promise<ApiResponse<R>>;
|
|
33
|
+
aggregate<T, F = T, R = T>(collection: Path, query: ApiAggregateQuery<F>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R>>;
|
|
34
|
+
patch<T extends object, R = T>(collection: Path, key: ApiId, data: ApiPatchQuery<T>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R>>;
|
|
35
|
+
post<T extends object, R = T>(collection: Path, data: ApiPostQuery<T>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R>>;
|
|
36
|
+
delete<T, R = T>(collection: Path, key: ApiId, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R>>;
|
|
37
|
+
put<T extends object, R = T>(collection: Path, data: ApiPutQuery<T>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R>>;
|
|
38
|
+
put<T extends object, R = T>(collection: Path, key: ApiId, data?: AnyObject, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R>>;
|
|
39
|
+
upload<T, R = T>(path: Path, data: FormData, config?: ApiAdapterRequestConfig & {
|
|
40
|
+
method?: BaseApiMethods;
|
|
41
|
+
}): Promise<ApiResponse<R>>;
|
|
42
|
+
createMany<T, R = T>(path: Path, body: ApiCreateManyQuery<T>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R[]>>;
|
|
43
|
+
updateMany<T, R = T>(path: Path, body: ApiUpdateManyQuery<T>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R[]>>;
|
|
44
|
+
deleteMany<R>(path: Path, body: ApiDeleteManyQuery<ApiId>, config?: ApiAdapterRequestConfig): Promise<ApiResponse<R[]>>;
|
|
40
45
|
}
|
|
46
|
+
export {};
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import { aggregate, createItem, createItems, deleteItem, deleteItems, readItem, readItems, updateItem, updateItems, uploadFiles } from '@directus/sdk';
|
|
2
2
|
import { ApiAdapterAbstract } from '@tanglemedia/svelte-starter-core';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const allowedQueryKeys = [
|
|
4
|
+
'fields',
|
|
5
|
+
'sort',
|
|
6
|
+
'filter',
|
|
7
|
+
'limit',
|
|
8
|
+
'offset',
|
|
9
|
+
'page',
|
|
10
|
+
'search',
|
|
11
|
+
'version',
|
|
12
|
+
'versionRaw',
|
|
13
|
+
'export',
|
|
14
|
+
'group',
|
|
15
|
+
'aggregate',
|
|
16
|
+
'deep',
|
|
17
|
+
'alias'
|
|
18
|
+
];
|
|
7
19
|
export class DirectusApiAdapter extends ApiAdapterAbstract {
|
|
8
20
|
config;
|
|
9
21
|
directus;
|
|
@@ -13,24 +25,18 @@ export class DirectusApiAdapter extends ApiAdapterAbstract {
|
|
|
13
25
|
this.directus = directus;
|
|
14
26
|
}
|
|
15
27
|
async handle(event) {
|
|
16
|
-
|
|
17
|
-
this.directus.globals.fetch = f;
|
|
28
|
+
this.directus.globals.fetch = event.fetch;
|
|
18
29
|
}
|
|
19
30
|
getAdapterClient() {
|
|
20
31
|
return this.directus;
|
|
21
32
|
}
|
|
22
33
|
normalizeMeta(response) {
|
|
23
34
|
const payload = response.data, meta = response.meta;
|
|
24
|
-
if (!meta) {
|
|
25
|
-
return {};
|
|
26
|
-
}
|
|
27
|
-
if (typeof meta.total === 'undefined') {
|
|
35
|
+
if (!meta || typeof meta.total === 'undefined') {
|
|
28
36
|
return {};
|
|
29
37
|
}
|
|
30
38
|
const displayed = Array.isArray(payload) ? payload.length : 0;
|
|
31
39
|
const total = Number(meta.total);
|
|
32
|
-
// todo: Transform or attempt to get meta information
|
|
33
|
-
// consider pulling count based on existing filters in order to determine pagination
|
|
34
40
|
return { total, displayed };
|
|
35
41
|
}
|
|
36
42
|
async includeTotals(collection, query) {
|
|
@@ -59,103 +65,146 @@ export class DirectusApiAdapter extends ApiAdapterAbstract {
|
|
|
59
65
|
}
|
|
60
66
|
async transformResponse(res, status = 200) {
|
|
61
67
|
return {
|
|
62
|
-
body: await this.envelopeResponse(res.data, (res.meta ? this.normalizeMeta(res) : {})),
|
|
63
|
-
status
|
|
68
|
+
body: (await this.envelopeResponse(res.data, (res.meta ? this.normalizeMeta(res) : {}))),
|
|
69
|
+
status,
|
|
64
70
|
statusText: 'OK',
|
|
65
71
|
headers: {},
|
|
66
72
|
adapterResponse: null
|
|
67
73
|
};
|
|
68
74
|
}
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
normalizeQuery(config = {}, merge) {
|
|
76
|
+
const q = { ...(config?.params || {}) };
|
|
77
|
+
const c = { ...config };
|
|
78
|
+
const r = allowedQueryKeys.reduce((acc, k) => (typeof c[k] !== 'undefined' ? ((acc[k] = c[k]), acc) : acc), {});
|
|
79
|
+
return {
|
|
80
|
+
...q,
|
|
81
|
+
...r,
|
|
82
|
+
...(merge || {})
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
getId(data, config) {
|
|
86
|
+
const d = data;
|
|
87
|
+
const q = config?.params;
|
|
88
|
+
if (typeof d.id === 'string' || typeof d.id === 'number') {
|
|
89
|
+
return d.id;
|
|
90
|
+
}
|
|
91
|
+
if (q && (typeof q.id === 'string' || typeof q.id === 'number')) {
|
|
92
|
+
return q.id;
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
stripId(config) {
|
|
97
|
+
const q = config?.params;
|
|
98
|
+
if (!q || typeof q.id === 'undefined') {
|
|
99
|
+
return config;
|
|
100
|
+
}
|
|
101
|
+
const { id: _id, ...params } = q;
|
|
102
|
+
return {
|
|
103
|
+
...config,
|
|
104
|
+
params
|
|
75
105
|
};
|
|
76
|
-
return Object.assign(client, config);
|
|
77
106
|
}
|
|
78
107
|
async request(method, url, query) {
|
|
79
108
|
try {
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
109
|
+
const { body, headers } = query || {};
|
|
110
|
+
const params = this.normalizeQuery(query);
|
|
111
|
+
const data = await this.directus.request((() => ({
|
|
112
|
+
path: url,
|
|
113
|
+
method,
|
|
114
|
+
headers,
|
|
115
|
+
params,
|
|
116
|
+
...(typeof body === 'undefined'
|
|
117
|
+
? {}
|
|
118
|
+
: {
|
|
119
|
+
body: body instanceof FormData || typeof body === 'string'
|
|
120
|
+
? body
|
|
121
|
+
: JSON.stringify(body)
|
|
122
|
+
})
|
|
123
|
+
})));
|
|
124
|
+
return this.transformResponse({ data }, method === 'POST' ? 201 : method === 'DELETE' ? 202 : 200);
|
|
88
125
|
}
|
|
89
126
|
catch (error) {
|
|
90
127
|
console.error(`Error request:`, error);
|
|
91
128
|
throw error;
|
|
92
129
|
}
|
|
93
130
|
}
|
|
94
|
-
async find(collection, query) {
|
|
95
|
-
const
|
|
131
|
+
async find(collection, query, config) {
|
|
132
|
+
const q = this.normalizeQuery(config, query);
|
|
133
|
+
const data = await this.directus.request(readItems(collection, q));
|
|
96
134
|
const total = await this.includeTotals(collection, query);
|
|
97
135
|
if (null === total) {
|
|
98
|
-
return this.transformResponse({ data
|
|
136
|
+
return this.transformResponse({ data });
|
|
99
137
|
}
|
|
100
|
-
|
|
101
|
-
return this.transformResponse({ data: response, meta: { total } });
|
|
138
|
+
return this.transformResponse({ data, meta: { total } });
|
|
102
139
|
}
|
|
103
140
|
async findOne(collection, key, query) {
|
|
104
|
-
const
|
|
141
|
+
const q = this.normalizeQuery(query);
|
|
142
|
+
const data = await this.directus.request(readItem(collection, key, q));
|
|
105
143
|
return this.transformResponse({ data });
|
|
106
144
|
}
|
|
107
|
-
async aggregate(collection, query) {
|
|
108
|
-
const { aggregate:
|
|
145
|
+
async aggregate(collection, query, config) {
|
|
146
|
+
const { aggregate: a, ...rest } = this.normalizeQuery(config, query);
|
|
109
147
|
const data = await this.directus.request(aggregate(collection, {
|
|
110
|
-
aggregate:
|
|
111
|
-
? aggregate_
|
|
112
|
-
: {
|
|
113
|
-
count: 'id'
|
|
114
|
-
},
|
|
148
|
+
aggregate: a ? a : { count: 'id' },
|
|
115
149
|
query: rest
|
|
116
150
|
}));
|
|
117
151
|
return this.transformResponse({ data });
|
|
118
152
|
}
|
|
119
|
-
async patch(collection, key,
|
|
120
|
-
const
|
|
121
|
-
|
|
153
|
+
async patch(collection, key, data, config) {
|
|
154
|
+
const q = this.normalizeQuery(config);
|
|
155
|
+
const res = await this.directus.request(updateItem(collection, key, data, q));
|
|
156
|
+
return this.transformResponse({ data: res });
|
|
122
157
|
}
|
|
123
|
-
async post(collection, data,
|
|
124
|
-
const
|
|
125
|
-
|
|
158
|
+
async post(collection, data, config) {
|
|
159
|
+
const q = this.normalizeQuery(config);
|
|
160
|
+
const res = await this.directus.request(createItem(collection, data, q));
|
|
161
|
+
return this.transformResponse({ data: res }, 201);
|
|
126
162
|
}
|
|
127
|
-
async delete(collection, key) {
|
|
163
|
+
async delete(collection, key, config) {
|
|
164
|
+
void config;
|
|
128
165
|
const data = await this.directus.request(deleteItem(collection, key));
|
|
129
166
|
return this.transformResponse({ data }, 202);
|
|
130
167
|
}
|
|
131
|
-
async put(collection,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
168
|
+
async put(collection, keyOrData, dataOrConfig, config) {
|
|
169
|
+
const key = typeof keyOrData === 'string' || typeof keyOrData === 'number'
|
|
170
|
+
? keyOrData
|
|
171
|
+
: this.getId(keyOrData, dataOrConfig);
|
|
172
|
+
const data = typeof keyOrData === 'string' || typeof keyOrData === 'number'
|
|
173
|
+
? dataOrConfig
|
|
174
|
+
: keyOrData;
|
|
175
|
+
const q = typeof keyOrData === 'string' || typeof keyOrData === 'number'
|
|
176
|
+
? config
|
|
177
|
+
: dataOrConfig;
|
|
178
|
+
if (!key) {
|
|
138
179
|
throw new Error('No key specified');
|
|
139
180
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
181
|
+
const res = await this.directus.request(updateItem(collection, key, data, this.normalizeQuery(this.stripId(q))));
|
|
182
|
+
return this.transformResponse({ data: res }, 201);
|
|
183
|
+
}
|
|
184
|
+
async upload(path, data, config) {
|
|
185
|
+
void path;
|
|
186
|
+
void config;
|
|
187
|
+
const res = await this.directus.request(uploadFiles(data));
|
|
188
|
+
return this.transformResponse({ data: res }, 201);
|
|
189
|
+
}
|
|
190
|
+
async createMany(path, body, config) {
|
|
191
|
+
const q = this.normalizeQuery(config, body.query || {});
|
|
192
|
+
const data = await this.directus.request(createItems(path, body.data, q));
|
|
148
193
|
return this.transformResponse({ data }, 200);
|
|
149
194
|
}
|
|
150
|
-
async updateMany(path, body) {
|
|
195
|
+
async updateMany(path, body, config) {
|
|
151
196
|
if (!body.ids) {
|
|
152
197
|
throw Error('You must provide an array of keys to update');
|
|
153
198
|
}
|
|
154
|
-
const
|
|
199
|
+
const q = this.normalizeQuery(config, body.query || {});
|
|
200
|
+
const ids = body.ids;
|
|
201
|
+
const data = await this.directus.request(updateItems(path, ids, body.data, q));
|
|
155
202
|
return this.transformResponse({ data }, 200);
|
|
156
203
|
}
|
|
157
|
-
async deleteMany(path, body) {
|
|
158
|
-
|
|
204
|
+
async deleteMany(path, body, config) {
|
|
205
|
+
void config;
|
|
206
|
+
const ids = body.ids;
|
|
207
|
+
const data = await this.directus.request(deleteItems(path, ids));
|
|
159
208
|
return this.transformResponse({ data }, 201);
|
|
160
209
|
}
|
|
161
210
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { AdapterProviderRegister, ApiAdapterInterface, ApiAdapterProviderInterface } from '@tanglemedia/svelte-starter-core';
|
|
2
|
-
import type { DirectusConfig } from '../types/adapter.types';
|
|
1
|
+
import type { AdapterProviderRegister, ApiAdapterRequestConfig, ApiAdapterInterface, ApiAdapterProviderInterface } from '@tanglemedia/svelte-starter-core';
|
|
2
|
+
import type { DirectusAdapterClient, DirectusConfig, SchemaShape } from '../types/adapter.types';
|
|
3
3
|
export declare class DirectusApiProvider implements ApiAdapterProviderInterface<DirectusConfig> {
|
|
4
|
-
loadAdapter(key?: string, config?: DirectusConfig): Promise<ApiAdapterInterface<DirectusConfig
|
|
5
|
-
createDirectusClient<T extends
|
|
4
|
+
loadAdapter(key?: string, config?: DirectusConfig): Promise<ApiAdapterInterface<DirectusConfig, ApiAdapterRequestConfig, string, DirectusAdapterClient<SchemaShape>>>;
|
|
5
|
+
createDirectusClient<T extends SchemaShape>(config: DirectusConfig): DirectusAdapterClient<T>;
|
|
6
6
|
}
|
|
7
7
|
export declare const registerDirectusProvider: () => AdapterProviderRegister;
|
|
@@ -1 +1,10 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { authentication, createDirectus, memoryStorage, rest, staticToken } from '@directus/sdk';
|
|
2
|
+
export { login, logout, passwordRequest, passwordReset, readProviders, refresh, } from '@directus/sdk';
|
|
3
|
+
export { createCollection, createComment, createComments, createContentVersion, createContentVersions, createDashboard, createDashboards, createField, createFlow, createFlows, createFolder, createFolders, createItem, createItems, createNotification, createNotifications, createOperation, createOperations, createPanel, createPanels, createPermission, createPermissions, createPolicies, createPolicy, createPreset, createPresets, createRelation, createRole, createRoles, createShare, createShares, createTranslation, createTranslations, createUser, createUsers, importFile, uploadFiles, } from '@directus/sdk';
|
|
4
|
+
export { aggregate, downloadFilesZip, downloadFolderZip, readActivities, readActivity, readAssetArrayBuffer, readAssetBlob, readAssetRaw, readCollection, readCollections, readComment, readComments, readContentVersion, readContentVersions, readDashboard, readDashboards, readExtensions, readField, readFields, readFieldsByCollection, readFile, readFiles, readFlow, readFlows, readFolder, readFolders, readGraphqlSdl, readItem, readItemPermissions, readItems, readMe, readNotification, readNotifications, readOpenApiSpec, readOperation, readOperations, readPanel, readPanels, readPermission, readPermissions, readPolicies, readPolicy, readPolicyGlobals, readPreset, readPresets, readRelation, readRelationByCollection, readRelations, readRevision, readRevisions, readRole, readRoles, readRolesMe, readSettings, readShare, readShareInfo, readShares, readSingleton, readTranslation, readTranslations, readUser, readUserPermissions, readUsers, } from '@directus/sdk';
|
|
5
|
+
export { updateCollection, updateCollectionsBatch, updateComment, updateComments, updateCommentsBatch, updateContentVersion, updateContentVersions, updateContentVersionsBatch, updateDashboard, updateDashboards, updateDashboardsBatch, updateExtension, updateField, updateFields, updateFile, updateFiles, updateFilesBatch, updateFlow, updateFlows, updateFlowsBatch, updateFolder, updateFolders, updateFoldersBatch, updateItem, updateItems, updateItemsBatch, updateMe, updateNotification, updateNotifications, updateNotificationsBatch, updateOperation, updateOperations, updateOperationsBatch, updatePanel, updatePanels, updatePanelsBatch, updatePermission, updatePermissions, updatePermissionsBatch, updatePolicies, updatePoliciesBatch, updatePolicy, updatePreset, updatePresets, updatePresetsBatch, updateRelation, updateRole, updateRoles, updateRolesBatch, updateSettings, updateShare, updateShares, updateSharesBatch, updateSingleton, updateTranslation, updateTranslations, updateTranslationsBatch, updateUser, updateUsers, updateUsersBatch, } from '@directus/sdk';
|
|
6
|
+
export { deleteCollection, deleteComment, deleteComments, deleteContentVersion, deleteContentVersions, deleteDashboard, deleteDashboards, deleteField, deleteFile, deleteFiles, deleteFlow, deleteFlows, deleteFolder, deleteFolders, deleteItem, deleteItems, deleteNotification, deleteNotifications, deleteOperation, deleteOperations, deletePanel, deletePanels, deletePermission, deletePermissions, deletePolicies, deletePolicy, deletePreset, deletePresets, deleteRelation, deleteRole, deleteRoles, deleteShare, deleteShares, deleteTranslation, deleteTranslations, deleteUser, deleteUsers, } from '@directus/sdk';
|
|
7
|
+
export { schemaApply, schemaDiff, schemaSnapshot } from '@directus/sdk';
|
|
8
|
+
export { serverHealth, serverInfo, serverPing } from '@directus/sdk';
|
|
9
|
+
export { acceptUserInvite, authenticateShare, clearCache, compareContentVersion, customEndpoint, disableTwoFactor, enableTwoFactor, generateHash, generateTwoFactorSecret, inviteShare, inviteUser, isDirectusError, promoteContentVersion, randomString, registerUser, registerUserVerify, saveToContentVersion, triggerFlow, utilitySort, utilsExport, utilsImport, verifyHash, withOptions, withSearch, withToken, } from '@directus/sdk';
|
|
10
|
+
export type { DirectusClient, RestClient, RestCommand } from '@directus/sdk';
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// Client setup
|
|
2
|
+
export { authentication, createDirectus, memoryStorage, rest, staticToken } from '@directus/sdk';
|
|
3
|
+
// Auth commands
|
|
4
|
+
export { login, logout, passwordRequest, passwordReset, readProviders, refresh, } from '@directus/sdk';
|
|
5
|
+
// Create commands
|
|
6
|
+
export { createCollection, createComment, createComments, createContentVersion, createContentVersions, createDashboard, createDashboards, createField, createFlow, createFlows, createFolder, createFolders, createItem, createItems, createNotification, createNotifications, createOperation, createOperations, createPanel, createPanels, createPermission, createPermissions, createPolicies, createPolicy, createPreset, createPresets, createRelation, createRole, createRoles, createShare, createShares, createTranslation, createTranslations, createUser, createUsers, importFile, uploadFiles, } from '@directus/sdk';
|
|
7
|
+
// Read commands
|
|
8
|
+
export { aggregate, downloadFilesZip, downloadFolderZip, readActivities, readActivity, readAssetArrayBuffer, readAssetBlob, readAssetRaw, readCollection, readCollections, readComment, readComments, readContentVersion, readContentVersions, readDashboard, readDashboards, readExtensions, readField, readFields, readFieldsByCollection, readFile, readFiles, readFlow, readFlows, readFolder, readFolders, readGraphqlSdl, readItem, readItemPermissions, readItems, readMe, readNotification, readNotifications, readOpenApiSpec, readOperation, readOperations, readPanel, readPanels, readPermission, readPermissions, readPolicies, readPolicy, readPolicyGlobals, readPreset, readPresets, readRelation, readRelationByCollection, readRelations, readRevision, readRevisions, readRole, readRoles, readRolesMe, readSettings, readShare, readShareInfo, readShares, readSingleton, readTranslation, readTranslations, readUser, readUserPermissions, readUsers, } from '@directus/sdk';
|
|
9
|
+
// Update commands
|
|
10
|
+
export { updateCollection, updateCollectionsBatch, updateComment, updateComments, updateCommentsBatch, updateContentVersion, updateContentVersions, updateContentVersionsBatch, updateDashboard, updateDashboards, updateDashboardsBatch, updateExtension, updateField, updateFields, updateFile, updateFiles, updateFilesBatch, updateFlow, updateFlows, updateFlowsBatch, updateFolder, updateFolders, updateFoldersBatch, updateItem, updateItems, updateItemsBatch, updateMe, updateNotification, updateNotifications, updateNotificationsBatch, updateOperation, updateOperations, updateOperationsBatch, updatePanel, updatePanels, updatePanelsBatch, updatePermission, updatePermissions, updatePermissionsBatch, updatePolicies, updatePoliciesBatch, updatePolicy, updatePreset, updatePresets, updatePresetsBatch, updateRelation, updateRole, updateRoles, updateRolesBatch, updateSettings, updateShare, updateShares, updateSharesBatch, updateSingleton, updateTranslation, updateTranslations, updateTranslationsBatch, updateUser, updateUsers, updateUsersBatch, } from '@directus/sdk';
|
|
11
|
+
// Delete commands
|
|
12
|
+
export { deleteCollection, deleteComment, deleteComments, deleteContentVersion, deleteContentVersions, deleteDashboard, deleteDashboards, deleteField, deleteFile, deleteFiles, deleteFlow, deleteFlows, deleteFolder, deleteFolders, deleteItem, deleteItems, deleteNotification, deleteNotifications, deleteOperation, deleteOperations, deletePanel, deletePanels, deletePermission, deletePermissions, deletePolicies, deletePolicy, deletePreset, deletePresets, deleteRelation, deleteRole, deleteRoles, deleteShare, deleteShares, deleteTranslation, deleteTranslations, deleteUser, deleteUsers, } from '@directus/sdk';
|
|
13
|
+
// Schema commands
|
|
14
|
+
export { schemaApply, schemaDiff, schemaSnapshot } from '@directus/sdk';
|
|
15
|
+
// Server commands
|
|
16
|
+
export { serverHealth, serverInfo, serverPing } from '@directus/sdk';
|
|
17
|
+
// Utility functions
|
|
18
|
+
export { acceptUserInvite, authenticateShare, clearCache, compareContentVersion, customEndpoint, disableTwoFactor, enableTwoFactor, generateHash, generateTwoFactorSecret, inviteShare, inviteUser, isDirectusError, promoteContentVersion, randomString, registerUser, registerUserVerify, saveToContentVersion, triggerFlow, utilitySort, utilsExport, utilsImport, verifyHash, withOptions, withSearch, withToken, } from '@directus/sdk';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ClientOptions } from '@directus/sdk';
|
|
2
|
-
import type { DirectusConfig } from '../types/adapter.types';
|
|
2
|
+
import type { DirectusAdapterClient, DirectusConfig, SchemaShape } from '../types/adapter.types';
|
|
3
3
|
/**
|
|
4
4
|
* Creates a directus client based on the application configuration
|
|
5
5
|
*/
|
|
6
|
-
export declare const createDirectusClientFactory: <T extends
|
|
6
|
+
export declare const createDirectusClientFactory: <T extends SchemaShape>({ baseUrl, configuration: { protocol, host, auth, staticToken: token, graphql: gql, rest: rs } }: DirectusConfig, options?: ClientOptions) => DirectusAdapterClient<T>;
|
package/dist/services/auth.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { AuthenticationClient, DirectusClient, RestClient } from '@directus/sdk';
|
|
2
1
|
import { ServiceAbstract } from '@tanglemedia/svelte-starter-core';
|
|
2
|
+
import type { DirectusAdapterClient, SchemaShape } from '../types';
|
|
3
3
|
declare class DirectusAuthServices extends ServiceAbstract {
|
|
4
|
-
getDirectus(): Promise<
|
|
4
|
+
getDirectus(): Promise<DirectusAdapterClient<SchemaShape>>;
|
|
5
|
+
private getAuthenticatedDirectus;
|
|
5
6
|
refresh(): Promise<import("@directus/sdk").AuthenticationData>;
|
|
6
7
|
getToken(): Promise<string | null>;
|
|
7
8
|
login(email: string, password: string): Promise<import("@directus/sdk").AuthenticationData>;
|
package/dist/services/auth.js
CHANGED
|
@@ -4,12 +4,19 @@ class DirectusAuthServices extends ServiceAbstract {
|
|
|
4
4
|
getDirectus() {
|
|
5
5
|
return this.getAdapterClient();
|
|
6
6
|
}
|
|
7
|
+
async getAuthenticatedDirectus() {
|
|
8
|
+
const directus = await this.getDirectus();
|
|
9
|
+
if (!directus.refresh || !directus.getToken || !directus.login || !directus.logout) {
|
|
10
|
+
throw new Error('Directus client is missing authentication methods');
|
|
11
|
+
}
|
|
12
|
+
return directus;
|
|
13
|
+
}
|
|
7
14
|
// public getConfig<T extends object>(): DirectusClient<T> & RestClient<object> {
|
|
8
15
|
// return this.directus as DirectusClient<T> & RestClient<object>;
|
|
9
16
|
// }
|
|
10
17
|
async refresh() {
|
|
11
18
|
try {
|
|
12
|
-
const response = await (await this.
|
|
19
|
+
const response = await (await this.getAuthenticatedDirectus()).refresh();
|
|
13
20
|
return response;
|
|
14
21
|
}
|
|
15
22
|
catch (error) {
|
|
@@ -19,7 +26,7 @@ class DirectusAuthServices extends ServiceAbstract {
|
|
|
19
26
|
}
|
|
20
27
|
async getToken() {
|
|
21
28
|
try {
|
|
22
|
-
const response = await (await this.
|
|
29
|
+
const response = await (await this.getAuthenticatedDirectus()).getToken();
|
|
23
30
|
return response;
|
|
24
31
|
}
|
|
25
32
|
catch (error) {
|
|
@@ -29,7 +36,7 @@ class DirectusAuthServices extends ServiceAbstract {
|
|
|
29
36
|
}
|
|
30
37
|
async login(email, password) {
|
|
31
38
|
try {
|
|
32
|
-
const response = await (await this.
|
|
39
|
+
const response = await (await this.getAuthenticatedDirectus()).login({ email, password });
|
|
33
40
|
return response;
|
|
34
41
|
}
|
|
35
42
|
catch (error) {
|
|
@@ -39,7 +46,7 @@ class DirectusAuthServices extends ServiceAbstract {
|
|
|
39
46
|
}
|
|
40
47
|
async logout() {
|
|
41
48
|
try {
|
|
42
|
-
const response = await (await this.
|
|
49
|
+
const response = await (await this.getAuthenticatedDirectus()).logout();
|
|
43
50
|
return response;
|
|
44
51
|
}
|
|
45
52
|
catch (error) {
|
|
@@ -51,7 +58,8 @@ class DirectusAuthServices extends ServiceAbstract {
|
|
|
51
58
|
try {
|
|
52
59
|
if (!(await this.getToken()))
|
|
53
60
|
await this.refresh();
|
|
54
|
-
const
|
|
61
|
+
const queryFields = (fields ?? ['*', 'roles.*']);
|
|
62
|
+
const response = await (await this.getDirectus()).request(readMe({ fields: queryFields }));
|
|
55
63
|
return response;
|
|
56
64
|
}
|
|
57
65
|
catch (error) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { AuthenticationMode, GraphqlConfig } from '@directus/sdk';
|
|
1
|
+
import type { AuthenticationClient, AuthenticationMode, DirectusClient, GraphqlClient, GraphqlConfig, RestClient, StaticTokenClient } from '@directus/sdk';
|
|
2
2
|
import type { BaseApiAdapterConfig } from '@tanglemedia/svelte-starter-core';
|
|
3
|
-
export {
|
|
3
|
+
export type { AllCollections, RegularCollections, DirectusClient, RestClient, StaticTokenClient, AuthenticationClient } from '@directus/sdk';
|
|
4
|
+
export type * from '@directus/types';
|
|
4
5
|
export type DirectusApiAuthOptions = {
|
|
5
6
|
mode: AuthenticationMode;
|
|
6
7
|
config?: Partial<{
|
|
@@ -24,4 +25,5 @@ export type DirectusApiAdapterOptions = {
|
|
|
24
25
|
totalField?: string;
|
|
25
26
|
};
|
|
26
27
|
export type DirectusConfig = BaseApiAdapterConfig<DirectusApiAdapterOptions>;
|
|
27
|
-
export type SchemaShape = Record<string, object>;
|
|
28
|
+
export type SchemaShape = Record<string, object | object[]>;
|
|
29
|
+
export type DirectusAdapterClient<Schema extends SchemaShape = SchemaShape> = DirectusClient<Schema> & RestClient<Schema> & Partial<AuthenticationClient<Schema>> & Partial<StaticTokenClient<Schema>> & Partial<GraphqlClient<Schema>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {}
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanglemedia/svelte-starter-directus-api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-next.0",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"types": "src/index.ts",
|
|
6
6
|
"description": "directus API wrapper for all the directus sdk functionality",
|
|
@@ -22,31 +22,31 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@directus/types": "
|
|
26
|
-
"@sveltejs/adapter-auto": "^
|
|
27
|
-
"@sveltejs/package": "^2.
|
|
28
|
-
"@sveltejs/vite-plugin-svelte": "^
|
|
25
|
+
"@directus/types": "15.0.1",
|
|
26
|
+
"@sveltejs/adapter-auto": "^7.0.1",
|
|
27
|
+
"@sveltejs/package": "^2.5.7",
|
|
28
|
+
"@sveltejs/vite-plugin-svelte": "^7.0.0",
|
|
29
29
|
"@testing-library/jest-dom": "^6.6.3",
|
|
30
30
|
"@testing-library/svelte": "^5.2.7",
|
|
31
31
|
"@vitest/coverage-v8": "^3.0.8",
|
|
32
32
|
"jsdom": "^26.0.0",
|
|
33
33
|
"msw": "^2.7.3",
|
|
34
|
-
"svelte": "^5.
|
|
35
|
-
"svelte-check": "^4.
|
|
36
|
-
"vite": "^
|
|
37
|
-
"vitest": "^
|
|
34
|
+
"svelte": "^5.55.3",
|
|
35
|
+
"svelte-check": "^4.4.6",
|
|
36
|
+
"vite": "^8.0.8",
|
|
37
|
+
"vitest": "^4.1.4",
|
|
38
38
|
"@internal/eslint-config": "0.0.0",
|
|
39
|
-
"@tanglemedia/svelte-starter-core": "
|
|
39
|
+
"@tanglemedia/svelte-starter-core": "4.0.0-next.0"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@directus/sdk": "
|
|
42
|
+
"@directus/sdk": "21.2.2",
|
|
43
43
|
"@types/js-cookie": "^3.0.6",
|
|
44
44
|
"esm-env": "^1.2.2",
|
|
45
45
|
"js-cookie": "^3.0.5"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@sveltejs/kit": ">=2 <3",
|
|
49
|
-
"@tanglemedia/svelte-starter-core": ">=
|
|
49
|
+
"@tanglemedia/svelte-starter-core": ">=4.0.0-next.0",
|
|
50
50
|
"svelte": "^4.0.0 || >=5.0.0"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|