@webiny/api-core-ddb 0.0.0-unstable.0d717d18dd
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/ApiCoreDdbFeature.d.ts +12 -0
- package/ApiCoreDdbFeature.js +16 -0
- package/ApiCoreDdbFeature.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/adminUsers/definitions/entities.d.ts +3 -0
- package/adminUsers/definitions/entities.js +9 -0
- package/adminUsers/definitions/entities.js.map +1 -0
- package/adminUsers/definitions/types.d.ts +5 -0
- package/adminUsers/definitions/types.js +0 -0
- package/adminUsers/index.d.ts +2 -0
- package/adminUsers/index.js +144 -0
- package/adminUsers/index.js.map +1 -0
- package/adminUsers/types.d.ts +22 -0
- package/adminUsers/types.js +8 -0
- package/adminUsers/types.js.map +1 -0
- package/createApiCoreDdb.d.ts +7 -0
- package/createApiCoreDdb.js +26 -0
- package/createApiCoreDdb.js.map +1 -0
- package/index.d.ts +4 -0
- package/index.js +3 -0
- package/keyValueStore/KeyValueStoreDynamoTable.d.ts +15 -0
- package/keyValueStore/KeyValueStoreDynamoTable.js +28 -0
- package/keyValueStore/KeyValueStoreDynamoTable.js.map +1 -0
- package/keyValueStore/KeyValueStoreStorageOperations.d.ts +17 -0
- package/keyValueStore/KeyValueStoreStorageOperations.js +83 -0
- package/keyValueStore/KeyValueStoreStorageOperations.js.map +1 -0
- package/keyValueStore/index.d.ts +8 -0
- package/keyValueStore/index.js +5 -0
- package/keyValueStore/index.js.map +1 -0
- package/package.json +45 -0
- package/security/definitions/entities.d.ts +5 -0
- package/security/definitions/entities.js +23 -0
- package/security/definitions/entities.js.map +1 -0
- package/security/definitions/types.d.ts +14 -0
- package/security/definitions/types.js +0 -0
- package/security/index.d.ts +3 -0
- package/security/index.js +401 -0
- package/security/index.js.map +1 -0
- package/security/types.d.ts +10 -0
- package/security/types.js +9 -0
- package/security/types.js.map +1 -0
- package/serviceDiscovery/DdbServiceManifestLoader.d.ts +7 -0
- package/serviceDiscovery/DdbServiceManifestLoader.js +27 -0
- package/serviceDiscovery/DdbServiceManifestLoader.js.map +1 -0
- package/serviceDiscovery/index.d.ts +1 -0
- package/serviceDiscovery/index.js +1 -0
- package/tenancy/definitions/tenantEntity.d.ts +8 -0
- package/tenancy/definitions/tenantEntity.js +8 -0
- package/tenancy/definitions/tenantEntity.js.map +1 -0
- package/tenancy/definitions/types.d.ts +6 -0
- package/tenancy/definitions/types.js +0 -0
- package/tenancy/index.d.ts +2 -0
- package/tenancy/index.js +115 -0
- package/tenancy/index.js.map +1 -0
- package/tenancy/types.d.ts +10 -0
- package/tenancy/types.js +7 -0
- package/tenancy/types.js.map +1 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IEntity, IStandardEntityAttributes } from "@webiny/db-dynamodb";
|
|
2
|
+
import type { StorageApiKey, StorageRole, StorageTeam } from "@webiny/api-core/types/security.js";
|
|
3
|
+
export interface IRoleEntityAttributes extends IStandardEntityAttributes<StorageRole> {
|
|
4
|
+
TYPE: string;
|
|
5
|
+
}
|
|
6
|
+
export type IRoleEntity = IEntity<IRoleEntityAttributes>;
|
|
7
|
+
export interface ITeamEntityAttributes extends IStandardEntityAttributes<StorageTeam> {
|
|
8
|
+
TYPE: string;
|
|
9
|
+
}
|
|
10
|
+
export type ITeamEntity = IEntity<ITeamEntityAttributes>;
|
|
11
|
+
export interface IApiKeyEntityAttributes extends IStandardEntityAttributes<StorageApiKey> {
|
|
12
|
+
TYPE: string;
|
|
13
|
+
}
|
|
14
|
+
export type IApiKeyEntity = IEntity<IApiKeyEntityAttributes>;
|
|
File without changes
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
import { createApiKeyEntity, createRoleEntity, createTeamEntity } from "./definitions/entities.js";
|
|
3
|
+
import { createTable, sortItems } from "@webiny/db-dynamodb";
|
|
4
|
+
const createStorageOperations = (params)=>{
|
|
5
|
+
const { table: tableName, documentClient } = params;
|
|
6
|
+
const table = createTable({
|
|
7
|
+
name: tableName || process.env.DB_TABLE,
|
|
8
|
+
documentClient
|
|
9
|
+
});
|
|
10
|
+
const entities = {
|
|
11
|
+
apiKeys: createApiKeyEntity(table.table),
|
|
12
|
+
roles: createRoleEntity(table.table),
|
|
13
|
+
teams: createTeamEntity(table.table)
|
|
14
|
+
};
|
|
15
|
+
const createApiKeyKeys = ({ id, tenant })=>({
|
|
16
|
+
PK: `T#${tenant}#API_KEY#${id}`,
|
|
17
|
+
SK: "A",
|
|
18
|
+
GSI_TENANT: tenant,
|
|
19
|
+
TYPE: "security.apiKey"
|
|
20
|
+
});
|
|
21
|
+
const createApiKeyGsiKeys = ({ slug, token, tenant })=>({
|
|
22
|
+
GSI1_PK: `T#${tenant}#API_KEYS`,
|
|
23
|
+
GSI1_SK: token,
|
|
24
|
+
GSI2_PK: `T#${tenant}#API_KEYS`,
|
|
25
|
+
GSI2_SK: slug
|
|
26
|
+
});
|
|
27
|
+
const createRoleKeys = (role)=>({
|
|
28
|
+
PK: `T#${role.tenant}#ROLE#${role.id}`,
|
|
29
|
+
SK: "A"
|
|
30
|
+
});
|
|
31
|
+
const createRoleGsiKeys = (role)=>({
|
|
32
|
+
GSI1_PK: `T#${role.tenant}#ROLES`,
|
|
33
|
+
GSI1_SK: role.slug,
|
|
34
|
+
GSI_TENANT: role.tenant,
|
|
35
|
+
TYPE: "security.role"
|
|
36
|
+
});
|
|
37
|
+
const createTeamKeys = (team)=>({
|
|
38
|
+
PK: `T#${team.tenant}#TEAM#${team.id}`,
|
|
39
|
+
SK: "A"
|
|
40
|
+
});
|
|
41
|
+
const createTeamGsiKeys = (team)=>({
|
|
42
|
+
GSI1_PK: `T#${team.tenant}#TEAMS`,
|
|
43
|
+
GSI1_SK: team.slug,
|
|
44
|
+
GSI_TENANT: team.tenant,
|
|
45
|
+
TYPE: "security.team"
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
async createApiKey ({ apiKey }) {
|
|
49
|
+
const keys = {
|
|
50
|
+
...createApiKeyKeys(apiKey),
|
|
51
|
+
...createApiKeyGsiKeys(apiKey)
|
|
52
|
+
};
|
|
53
|
+
try {
|
|
54
|
+
await entities.apiKeys.put({
|
|
55
|
+
data: apiKey,
|
|
56
|
+
...keys
|
|
57
|
+
});
|
|
58
|
+
} catch (err) {
|
|
59
|
+
throw error.from(err, {
|
|
60
|
+
message: "Could not create api key.",
|
|
61
|
+
code: "CREATE_API_KEY_ERROR",
|
|
62
|
+
data: {
|
|
63
|
+
keys
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
async createRole ({ role }) {
|
|
69
|
+
const keys = {
|
|
70
|
+
...createRoleKeys(role),
|
|
71
|
+
...createRoleGsiKeys(role)
|
|
72
|
+
};
|
|
73
|
+
try {
|
|
74
|
+
await entities.roles.put({
|
|
75
|
+
data: role,
|
|
76
|
+
...keys
|
|
77
|
+
});
|
|
78
|
+
} catch (err) {
|
|
79
|
+
throw error.from(err, {
|
|
80
|
+
message: "Could not create role.",
|
|
81
|
+
code: "CREATE_ROLE_ERROR",
|
|
82
|
+
data: {
|
|
83
|
+
keys
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
async createTeam ({ team }) {
|
|
89
|
+
const keys = {
|
|
90
|
+
...createTeamKeys(team),
|
|
91
|
+
...createTeamGsiKeys(team)
|
|
92
|
+
};
|
|
93
|
+
try {
|
|
94
|
+
await entities.teams.put({
|
|
95
|
+
data: team,
|
|
96
|
+
...keys
|
|
97
|
+
});
|
|
98
|
+
} catch (err) {
|
|
99
|
+
throw error.from(err, {
|
|
100
|
+
message: "Could not create team.",
|
|
101
|
+
code: "CREATE_TEAM_ERROR",
|
|
102
|
+
data: {
|
|
103
|
+
keys
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
async deleteApiKey ({ apiKey }) {
|
|
109
|
+
const keys = createApiKeyKeys(apiKey);
|
|
110
|
+
try {
|
|
111
|
+
await entities.apiKeys.delete(keys);
|
|
112
|
+
} catch (err) {
|
|
113
|
+
throw error.from(err, {
|
|
114
|
+
message: "Could not update api key.",
|
|
115
|
+
code: "UPDATE_API_KEY_ERROR",
|
|
116
|
+
data: {
|
|
117
|
+
keys
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
async deleteRole ({ role }) {
|
|
123
|
+
const keys = createRoleKeys(role);
|
|
124
|
+
try {
|
|
125
|
+
await entities.roles.delete(keys);
|
|
126
|
+
} catch (err) {
|
|
127
|
+
throw error.from(err, {
|
|
128
|
+
message: "Could not delete role.",
|
|
129
|
+
code: "CREATE_DELETE_ERROR",
|
|
130
|
+
data: {
|
|
131
|
+
keys,
|
|
132
|
+
role
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
async deleteTeam ({ team }) {
|
|
138
|
+
const keys = createTeamKeys(team);
|
|
139
|
+
try {
|
|
140
|
+
await entities.teams.delete(keys);
|
|
141
|
+
} catch (err) {
|
|
142
|
+
throw error.from(err, {
|
|
143
|
+
message: "Could not delete team.",
|
|
144
|
+
code: "CREATE_DELETE_ERROR",
|
|
145
|
+
data: {
|
|
146
|
+
keys,
|
|
147
|
+
team
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
async getApiKey ({ id, tenant }) {
|
|
153
|
+
const keys = createApiKeyKeys({
|
|
154
|
+
id,
|
|
155
|
+
tenant
|
|
156
|
+
});
|
|
157
|
+
try {
|
|
158
|
+
const response = await entities.apiKeys.get(keys);
|
|
159
|
+
return response?.data || null;
|
|
160
|
+
} catch (err) {
|
|
161
|
+
throw error.from(err, {
|
|
162
|
+
message: "Could not load api key.",
|
|
163
|
+
code: "GET_API_KEY_ERROR",
|
|
164
|
+
data: {
|
|
165
|
+
id,
|
|
166
|
+
keys
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
async getApiKeyByToken ({ tenant, token }) {
|
|
172
|
+
const queryParams = {
|
|
173
|
+
partitionKey: `T#${tenant}#API_KEYS`,
|
|
174
|
+
options: {
|
|
175
|
+
eq: token,
|
|
176
|
+
index: "GSI1"
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
try {
|
|
180
|
+
const result = await entities.apiKeys.queryOne(queryParams);
|
|
181
|
+
return result?.data || null;
|
|
182
|
+
} catch (err) {
|
|
183
|
+
throw error.from(err, {
|
|
184
|
+
message: "Could not load api key by token.",
|
|
185
|
+
code: "GET_BY_TOKEN_API_KEY_ERROR",
|
|
186
|
+
data: {
|
|
187
|
+
partitionKey: queryParams.partitionKey,
|
|
188
|
+
options: queryParams.options
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
async getApiKeyBySlug ({ tenant, slug }) {
|
|
194
|
+
const queryParams = {
|
|
195
|
+
partitionKey: `T#${tenant}#API_KEYS`,
|
|
196
|
+
options: {
|
|
197
|
+
eq: slug,
|
|
198
|
+
index: "GSI2"
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
try {
|
|
202
|
+
const result = await entities.apiKeys.queryOne(queryParams);
|
|
203
|
+
return result?.data || null;
|
|
204
|
+
} catch (err) {
|
|
205
|
+
throw error.from(err, {
|
|
206
|
+
message: "Could not load api key by slug.",
|
|
207
|
+
code: "GET_BY_SLUG_API_KEY_ERROR",
|
|
208
|
+
data: {
|
|
209
|
+
partitionKey: queryParams.partitionKey,
|
|
210
|
+
options: queryParams.options
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
async getRole ({ where: { tenant, id, slug } }) {
|
|
216
|
+
try {
|
|
217
|
+
if (id) {
|
|
218
|
+
const result = await entities.roles.get(createRoleKeys({
|
|
219
|
+
tenant,
|
|
220
|
+
id
|
|
221
|
+
}));
|
|
222
|
+
return result?.data || null;
|
|
223
|
+
}
|
|
224
|
+
const result = await entities.roles.queryOne({
|
|
225
|
+
partitionKey: `T#${tenant}#ROLES`,
|
|
226
|
+
options: {
|
|
227
|
+
index: "GSI1",
|
|
228
|
+
eq: slug
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
return result?.data || null;
|
|
232
|
+
} catch (err) {
|
|
233
|
+
throw error.from(err, {
|
|
234
|
+
message: "Could not load role.",
|
|
235
|
+
code: "GET_ROLE_ERROR",
|
|
236
|
+
data: {
|
|
237
|
+
id,
|
|
238
|
+
slug
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
async getTeam ({ where: { tenant, id, slug } }) {
|
|
244
|
+
try {
|
|
245
|
+
if (id) {
|
|
246
|
+
const result = await entities.teams.get(createTeamKeys({
|
|
247
|
+
tenant,
|
|
248
|
+
id
|
|
249
|
+
}));
|
|
250
|
+
return result?.data || null;
|
|
251
|
+
}
|
|
252
|
+
const result = await entities.teams.queryOne({
|
|
253
|
+
partitionKey: `T#${tenant}#TEAMS`,
|
|
254
|
+
options: {
|
|
255
|
+
index: "GSI1",
|
|
256
|
+
eq: slug
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
return result?.data || null;
|
|
260
|
+
} catch (err) {
|
|
261
|
+
throw error.from(err, {
|
|
262
|
+
message: "Could not load team.",
|
|
263
|
+
code: "GET_TEAM_ERROR",
|
|
264
|
+
data: {
|
|
265
|
+
id,
|
|
266
|
+
slug
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
async listApiKeys ({ where: { tenant }, sort }) {
|
|
272
|
+
let items;
|
|
273
|
+
try {
|
|
274
|
+
items = await entities.apiKeys.queryAll({
|
|
275
|
+
partitionKey: `T#${tenant}#API_KEYS`,
|
|
276
|
+
options: {
|
|
277
|
+
index: "GSI1"
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
} catch (err) {
|
|
281
|
+
throw error.from(err, {
|
|
282
|
+
message: "Could not list api keys.",
|
|
283
|
+
code: "LIST_API_KEY_ERROR"
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
return sortItems({
|
|
287
|
+
items,
|
|
288
|
+
sort
|
|
289
|
+
}).map((item)=>item.data);
|
|
290
|
+
},
|
|
291
|
+
async listRoles ({ where: { tenant, id_in, slug_in }, sort }) {
|
|
292
|
+
let items;
|
|
293
|
+
try {
|
|
294
|
+
const ddbItems = await entities.roles.queryAll({
|
|
295
|
+
partitionKey: `T#${tenant}#ROLES`,
|
|
296
|
+
options: {
|
|
297
|
+
index: "GSI1"
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
items = ddbItems.map((item)=>item.data);
|
|
301
|
+
} catch (err) {
|
|
302
|
+
throw error.from(err, {
|
|
303
|
+
message: "Could not list roles.",
|
|
304
|
+
code: "LIST_ROLE_ERROR"
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
items = sortItems({
|
|
308
|
+
items,
|
|
309
|
+
sort
|
|
310
|
+
});
|
|
311
|
+
if (Array.isArray(id_in)) return items.filter((item)=>id_in.includes(item.id));
|
|
312
|
+
if (Array.isArray(slug_in)) return items.filter((item)=>slug_in.includes(item.slug));
|
|
313
|
+
return items;
|
|
314
|
+
},
|
|
315
|
+
async listTeams ({ where: { tenant, id_in, slug_in }, sort }) {
|
|
316
|
+
let items;
|
|
317
|
+
try {
|
|
318
|
+
const ddbRecords = await entities.teams.queryAll({
|
|
319
|
+
partitionKey: `T#${tenant}#TEAMS`,
|
|
320
|
+
options: {
|
|
321
|
+
index: "GSI1"
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
items = ddbRecords.map((item)=>item.data);
|
|
325
|
+
} catch (err) {
|
|
326
|
+
throw error.from(err, {
|
|
327
|
+
message: "Could not list teams.",
|
|
328
|
+
code: "LIST_TEAM_ERROR"
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
items = sortItems({
|
|
332
|
+
items,
|
|
333
|
+
sort
|
|
334
|
+
});
|
|
335
|
+
if (Array.isArray(id_in)) return items.filter((item)=>id_in.includes(item.id));
|
|
336
|
+
if (Array.isArray(slug_in)) return items.filter((item)=>slug_in.includes(item.slug));
|
|
337
|
+
return items;
|
|
338
|
+
},
|
|
339
|
+
async updateApiKey ({ apiKey }) {
|
|
340
|
+
const keys = {
|
|
341
|
+
...createApiKeyKeys(apiKey),
|
|
342
|
+
...createApiKeyGsiKeys(apiKey)
|
|
343
|
+
};
|
|
344
|
+
try {
|
|
345
|
+
await entities.apiKeys.put({
|
|
346
|
+
data: apiKey,
|
|
347
|
+
...keys
|
|
348
|
+
});
|
|
349
|
+
} catch (err) {
|
|
350
|
+
throw error.from(err, {
|
|
351
|
+
message: "Could not update api key.",
|
|
352
|
+
code: "UPDATE_API_KEY_ERROR",
|
|
353
|
+
data: {
|
|
354
|
+
keys
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
async updateRole ({ role }) {
|
|
360
|
+
const keys = createRoleKeys(role);
|
|
361
|
+
try {
|
|
362
|
+
await entities.roles.put({
|
|
363
|
+
data: role,
|
|
364
|
+
...keys,
|
|
365
|
+
...createRoleGsiKeys(role)
|
|
366
|
+
});
|
|
367
|
+
} catch (err) {
|
|
368
|
+
throw error.from(err, {
|
|
369
|
+
message: "Could not update role.",
|
|
370
|
+
code: "UPDATE_ROLE_ERROR",
|
|
371
|
+
data: {
|
|
372
|
+
keys,
|
|
373
|
+
role
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
async updateTeam ({ team }) {
|
|
379
|
+
const keys = createTeamKeys(team);
|
|
380
|
+
try {
|
|
381
|
+
await entities.teams.put({
|
|
382
|
+
data: team,
|
|
383
|
+
...keys,
|
|
384
|
+
...createTeamGsiKeys(team)
|
|
385
|
+
});
|
|
386
|
+
} catch (err) {
|
|
387
|
+
throw error.from(err, {
|
|
388
|
+
message: "Could not update team.",
|
|
389
|
+
code: "UPDATE_TEAM_ERROR",
|
|
390
|
+
data: {
|
|
391
|
+
keys,
|
|
392
|
+
team
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
};
|
|
399
|
+
export { createStorageOperations };
|
|
400
|
+
|
|
401
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security/index.js","sources":["../../src/security/index.ts"],"sourcesContent":["import type { SecurityStorageParams } from \"./types.js\";\nimport type {\n StorageApiKey,\n StorageRole,\n SecurityStorageOperations,\n StorageTeam\n} from \"@webiny/api-core/types/security.js\";\nimport WebinyError from \"@webiny/error\";\nimport { createApiKeyEntity, createRoleEntity, createTeamEntity } from \"./definitions/entities.js\";\nimport { createTable, type IEntityQueryOneParams, sortItems } from \"@webiny/db-dynamodb\";\n\nexport const createStorageOperations = (\n params: SecurityStorageParams\n): SecurityStorageOperations => {\n const { table: tableName, documentClient } = params;\n\n const table = createTable({\n name: tableName || (process.env.DB_TABLE as string),\n documentClient\n });\n\n const entities = {\n apiKeys: createApiKeyEntity(table.table),\n roles: createRoleEntity(table.table),\n teams: createTeamEntity(table.table)\n };\n\n const createApiKeyKeys = ({ id, tenant }: Pick<StorageApiKey, \"id\" | \"tenant\">) => ({\n PK: `T#${tenant}#API_KEY#${id}`,\n SK: `A`,\n GSI_TENANT: tenant,\n TYPE: \"security.apiKey\"\n });\n\n const createApiKeyGsiKeys = ({\n slug,\n token,\n tenant\n }: Pick<StorageApiKey, \"slug\" | \"tenant\" | \"token\">) => ({\n GSI1_PK: `T#${tenant}#API_KEYS`,\n GSI1_SK: token,\n GSI2_PK: `T#${tenant}#API_KEYS`,\n GSI2_SK: slug\n });\n\n const createRoleKeys = (role: Pick<StorageRole, \"tenant\" | \"id\">) => ({\n PK: `T#${role.tenant}#ROLE#${role.id}`,\n SK: `A`\n });\n\n const createRoleGsiKeys = (role: Pick<StorageRole, \"tenant\" | \"slug\">) => ({\n GSI1_PK: `T#${role.tenant}#ROLES`,\n GSI1_SK: role.slug,\n GSI_TENANT: role.tenant as string,\n TYPE: \"security.role\"\n });\n\n const createTeamKeys = (team: Pick<StorageTeam, \"tenant\" | \"id\">) => ({\n PK: `T#${team.tenant}#TEAM#${team.id}`,\n SK: `A`\n });\n\n const createTeamGsiKeys = (team: Pick<StorageTeam, \"tenant\" | \"slug\">) => ({\n GSI1_PK: `T#${team.tenant}#TEAMS`,\n GSI1_SK: team.slug,\n GSI_TENANT: team.tenant as string,\n TYPE: \"security.team\"\n });\n\n return {\n async createApiKey({ apiKey }): Promise<void> {\n const keys = {\n ...createApiKeyKeys(apiKey),\n ...createApiKeyGsiKeys(apiKey)\n };\n\n try {\n await entities.apiKeys.put({\n data: apiKey,\n ...keys\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create api key.\",\n code: \"CREATE_API_KEY_ERROR\",\n data: { keys }\n });\n }\n },\n async createRole({ role }): Promise<void> {\n const keys = {\n ...createRoleKeys(role),\n ...createRoleGsiKeys(role)\n };\n\n try {\n await entities.roles.put({\n data: role,\n ...keys\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create role.\",\n code: \"CREATE_ROLE_ERROR\",\n data: { keys }\n });\n }\n },\n async createTeam({ team }): Promise<void> {\n const keys = {\n ...createTeamKeys(team),\n ...createTeamGsiKeys(team)\n };\n\n try {\n await entities.teams.put({\n data: team,\n ...keys\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create team.\",\n code: \"CREATE_TEAM_ERROR\",\n data: { keys }\n });\n }\n },\n async deleteApiKey({ apiKey }) {\n const keys = createApiKeyKeys(apiKey);\n\n try {\n await entities.apiKeys.delete(keys);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update api key.\",\n code: \"UPDATE_API_KEY_ERROR\",\n data: { keys }\n });\n }\n },\n async deleteRole({ role }) {\n const keys = createRoleKeys(role);\n\n try {\n await entities.roles.delete(keys);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not delete role.\",\n code: \"CREATE_DELETE_ERROR\",\n data: { keys, role }\n });\n }\n },\n async deleteTeam({ team }) {\n const keys = createTeamKeys(team);\n\n try {\n await entities.teams.delete(keys);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not delete team.\",\n code: \"CREATE_DELETE_ERROR\",\n data: { keys, team }\n });\n }\n },\n async getApiKey({ id, tenant }) {\n const keys = createApiKeyKeys({ id, tenant });\n\n try {\n const response = await entities.apiKeys.get(keys);\n\n return response?.data || null;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load api key.\",\n code: \"GET_API_KEY_ERROR\",\n data: { id, keys }\n });\n }\n },\n async getApiKeyByToken({ tenant, token }) {\n const queryParams: IEntityQueryOneParams = {\n partitionKey: `T#${tenant}#API_KEYS`,\n options: {\n eq: token,\n index: \"GSI1\"\n }\n };\n\n try {\n const result = await entities.apiKeys.queryOne(queryParams);\n return result?.data || null;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load api key by token.\",\n code: \"GET_BY_TOKEN_API_KEY_ERROR\",\n data: { partitionKey: queryParams.partitionKey, options: queryParams.options }\n });\n }\n },\n async getApiKeyBySlug({ tenant, slug }) {\n const queryParams: IEntityQueryOneParams = {\n partitionKey: `T#${tenant}#API_KEYS`,\n options: {\n eq: slug,\n index: \"GSI2\"\n }\n };\n\n try {\n const result = await entities.apiKeys.queryOne(queryParams);\n return result?.data || null;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load api key by slug.\",\n code: \"GET_BY_SLUG_API_KEY_ERROR\",\n data: { partitionKey: queryParams.partitionKey, options: queryParams.options }\n });\n }\n },\n async getRole({ where: { tenant, id, slug } }) {\n try {\n if (id) {\n const result = await entities.roles.get(createRoleKeys({ tenant, id }));\n return result?.data || null;\n }\n const result = await entities.roles.queryOne({\n partitionKey: `T#${tenant}#ROLES`,\n options: {\n index: \"GSI1\",\n eq: slug\n }\n });\n\n return result?.data || null;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load role.\",\n code: \"GET_ROLE_ERROR\",\n data: { id, slug }\n });\n }\n },\n async getTeam({ where: { tenant, id, slug } }) {\n try {\n if (id) {\n const result = await entities.teams.get(createTeamKeys({ tenant, id }));\n\n return result?.data || null;\n }\n\n const result = await entities.teams.queryOne({\n partitionKey: `T#${tenant}#TEAMS`,\n options: {\n index: \"GSI1\",\n eq: slug\n }\n });\n\n return result?.data || null;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load team.\",\n code: \"GET_TEAM_ERROR\",\n data: { id, slug }\n });\n }\n },\n async listApiKeys({ where: { tenant }, sort }): Promise<StorageApiKey[]> {\n let items;\n try {\n items = await entities.apiKeys.queryAll({\n partitionKey: `T#${tenant}#API_KEYS`,\n options: {\n index: \"GSI1\"\n }\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list api keys.\",\n code: \"LIST_API_KEY_ERROR\"\n });\n }\n\n return sortItems({ items, sort }).map(item => item.data);\n },\n async listRoles({ where: { tenant, id_in, slug_in }, sort }): Promise<StorageRole[]> {\n let items: StorageRole[];\n try {\n const ddbItems = await entities.roles.queryAll({\n partitionKey: `T#${tenant}#ROLES`,\n options: {\n index: \"GSI1\"\n }\n });\n items = ddbItems.map(item => item.data);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list roles.\",\n code: \"LIST_ROLE_ERROR\"\n });\n }\n\n items = sortItems({ items, sort });\n\n if (Array.isArray(id_in)) {\n return items.filter(item => id_in.includes(item.id));\n }\n\n if (Array.isArray(slug_in)) {\n return items.filter(item => slug_in.includes(item.slug));\n }\n\n return items;\n },\n async listTeams({ where: { tenant, id_in, slug_in }, sort }): Promise<StorageTeam[]> {\n let items: StorageTeam[];\n try {\n const ddbRecords = await entities.teams.queryAll({\n partitionKey: `T#${tenant}#TEAMS`,\n options: {\n index: \"GSI1\"\n }\n });\n\n items = ddbRecords.map(item => item.data);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list teams.\",\n code: \"LIST_TEAM_ERROR\"\n });\n }\n\n items = sortItems({ items, sort });\n\n if (Array.isArray(id_in)) {\n return items.filter(item => id_in.includes(item.id));\n }\n\n if (Array.isArray(slug_in)) {\n return items.filter(item => slug_in.includes(item.slug));\n }\n return items;\n },\n async updateApiKey({ apiKey }): Promise<void> {\n const keys = {\n ...createApiKeyKeys(apiKey),\n ...createApiKeyGsiKeys(apiKey)\n };\n\n try {\n await entities.apiKeys.put({\n data: apiKey,\n ...keys\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update api key.\",\n code: \"UPDATE_API_KEY_ERROR\",\n data: { keys }\n });\n }\n },\n async updateRole({ role }): Promise<void> {\n const keys = createRoleKeys(role);\n\n try {\n await entities.roles.put({\n data: role,\n ...keys,\n ...createRoleGsiKeys(role)\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update role.\",\n code: \"UPDATE_ROLE_ERROR\",\n data: { keys, role }\n });\n }\n },\n async updateTeam({ team }): Promise<void> {\n const keys = createTeamKeys(team);\n\n try {\n await entities.teams.put({\n data: team,\n ...keys,\n ...createTeamGsiKeys(team)\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update team.\",\n code: \"UPDATE_TEAM_ERROR\",\n data: { keys, team }\n });\n }\n }\n };\n};\n"],"names":["createStorageOperations","params","tableName","documentClient","table","createTable","process","entities","createApiKeyEntity","createRoleEntity","createTeamEntity","createApiKeyKeys","id","tenant","createApiKeyGsiKeys","slug","token","createRoleKeys","role","createRoleGsiKeys","createTeamKeys","team","createTeamGsiKeys","apiKey","keys","err","WebinyError","response","queryParams","result","sort","items","sortItems","item","id_in","slug_in","ddbItems","Array","ddbRecords"],"mappings":";;;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YAE1D,OAAOF;QACX;QACA,MAAM,cAAa,EAAER,MAAM,EAAE;YACzB,MAAMC,OAAO;gBACT,GAAGb,iBAAiBY,OAAO;gBAC3B,GAAGT,oBAAoBS,OAAO;YAClC;YAEA,IAAI;gBACA,MAAMhB,SAAS,OAAO,CAAC,GAAG,CAAC;oBACvB,MAAMgB;oBACN,GAAGC,IAAI;gBACX;YACJ,EAAE,OAAOC,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAED;oBAAK;gBACjB;YACJ;QACJ;QACA,MAAM,YAAW,EAAEN,IAAI,EAAE;YACrB,MAAMM,OAAOP,eAAeC;YAE5B,IAAI;gBACA,MAAMX,SAAS,KAAK,CAAC,GAAG,CAAC;oBACrB,MAAMW;oBACN,GAAGM,IAAI;oBACP,GAAGL,kBAAkBD,KAAK;gBAC9B;YACJ,EAAE,OAAOO,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAED;wBAAMN;oBAAK;gBACvB;YACJ;QACJ;QACA,MAAM,YAAW,EAAEG,IAAI,EAAE;YACrB,MAAMG,OAAOJ,eAAeC;YAE5B,IAAI;gBACA,MAAMd,SAAS,KAAK,CAAC,GAAG,CAAC;oBACrB,MAAMc;oBACN,GAAGG,IAAI;oBACP,GAAGF,kBAAkBD,KAAK;gBAC9B;YACJ,EAAE,OAAOI,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAED;wBAAMH;oBAAK;gBACvB;YACJ;QACJ;IACJ;AACJ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
+
export declare enum ENTITIES {
|
|
3
|
+
API_KEY = "SecurityApiKey",
|
|
4
|
+
ROLE = "SecurityRole",
|
|
5
|
+
TEAM = "SecurityTeam"
|
|
6
|
+
}
|
|
7
|
+
export interface SecurityStorageParams {
|
|
8
|
+
documentClient: DynamoDBDocument;
|
|
9
|
+
table?: string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var types_ENTITIES = /*#__PURE__*/ function(ENTITIES) {
|
|
2
|
+
ENTITIES["API_KEY"] = "SecurityApiKey";
|
|
3
|
+
ENTITIES["ROLE"] = "SecurityRole";
|
|
4
|
+
ENTITIES["TEAM"] = "SecurityTeam";
|
|
5
|
+
return ENTITIES;
|
|
6
|
+
}({});
|
|
7
|
+
export { types_ENTITIES as ENTITIES };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security/types.js","sources":["../../src/security/types.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\n\nexport enum ENTITIES {\n API_KEY = \"SecurityApiKey\",\n ROLE = \"SecurityRole\",\n TEAM = \"SecurityTeam\"\n}\n\nexport interface SecurityStorageParams {\n documentClient: DynamoDBDocument;\n table?: string;\n}\n"],"names":["ENTITIES"],"mappings":"AAEO,IAAKA,iBAAQA,WAAAA,GAAAA,SAARA,QAAQ;;;;WAARA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
+
import type { IServiceManifestLoader } from "@webiny/api-core/features/serviceDiscovery/index.js";
|
|
3
|
+
export declare class DdbServiceManifestLoader implements IServiceManifestLoader {
|
|
4
|
+
private readonly client;
|
|
5
|
+
constructor(client: Pick<DynamoDBDocument, "send">);
|
|
6
|
+
load(): Promise<any[] | undefined>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { QueryCommand, unmarshall } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
+
class DdbServiceManifestLoader {
|
|
3
|
+
constructor(client){
|
|
4
|
+
this.client = client;
|
|
5
|
+
}
|
|
6
|
+
async load() {
|
|
7
|
+
const result = await this.client.send(new QueryCommand({
|
|
8
|
+
TableName: String(process.env.DB_TABLE),
|
|
9
|
+
IndexName: "GSI1",
|
|
10
|
+
KeyConditionExpression: "GSI1_PK = :GSI1_PK AND GSI1_SK > :GSI1_SK",
|
|
11
|
+
ExpressionAttributeValues: {
|
|
12
|
+
":GSI1_PK": {
|
|
13
|
+
S: "SERVICE_MANIFESTS"
|
|
14
|
+
},
|
|
15
|
+
":GSI1_SK": {
|
|
16
|
+
S: " "
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}));
|
|
20
|
+
const items = result.Items;
|
|
21
|
+
if (!Array.isArray(items)) return;
|
|
22
|
+
return items.map((item)=>unmarshall(item).data);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export { DdbServiceManifestLoader };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=DdbServiceManifestLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serviceDiscovery/DdbServiceManifestLoader.js","sources":["../../src/serviceDiscovery/DdbServiceManifestLoader.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { QueryCommand } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { unmarshall } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { IServiceManifestLoader } from \"@webiny/api-core/features/serviceDiscovery/index.js\";\n\nexport class DdbServiceManifestLoader implements IServiceManifestLoader {\n private readonly client: Pick<DynamoDBDocument, \"send\">;\n\n constructor(client: Pick<DynamoDBDocument, \"send\">) {\n this.client = client;\n }\n\n async load() {\n const result = await this.client.send(\n new QueryCommand({\n TableName: String(process.env.DB_TABLE),\n IndexName: \"GSI1\",\n KeyConditionExpression: \"GSI1_PK = :GSI1_PK AND GSI1_SK > :GSI1_SK\",\n ExpressionAttributeValues: {\n \":GSI1_PK\": { S: \"SERVICE_MANIFESTS\" },\n \":GSI1_SK\": { S: \" \" }\n }\n })\n );\n\n const items = result.Items;\n\n if (!Array.isArray(items)) {\n return undefined;\n }\n\n return items.map(item => unmarshall(item).data);\n }\n}\n"],"names":["DdbServiceManifestLoader","client","result","QueryCommand","String","process","items","Array","item","unmarshall"],"mappings":";AAKO,MAAMA;IAGT,YAAYC,MAAsC,CAAE;QAChD,IAAI,CAAC,MAAM,GAAGA;IAClB;IAEA,MAAM,OAAO;QACT,MAAMC,SAAS,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CACjC,IAAIC,aAAa;YACb,WAAWC,OAAOC,QAAQ,GAAG,CAAC,QAAQ;YACtC,WAAW;YACX,wBAAwB;YACxB,2BAA2B;gBACvB,YAAY;oBAAE,GAAG;gBAAoB;gBACrC,YAAY;oBAAE,GAAG;gBAAI;YACzB;QACJ;QAGJ,MAAMC,QAAQJ,OAAO,KAAK;QAE1B,IAAI,CAACK,MAAM,OAAO,CAACD,QACf;QAGJ,OAAOA,MAAM,GAAG,CAACE,CAAAA,OAAQC,WAAWD,MAAM,IAAI;IAClD;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DdbServiceManifestLoader } from "./DdbServiceManifestLoader.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DdbServiceManifestLoader } from "./DdbServiceManifestLoader.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Table } from "@webiny/db-dynamodb/toolbox.js";
|
|
2
|
+
import type { ITenantEntity } from "../../tenancy/definitions/types.js";
|
|
3
|
+
interface Params {
|
|
4
|
+
entityName: string;
|
|
5
|
+
table: Table<string, string, string>;
|
|
6
|
+
}
|
|
7
|
+
export declare const createTenantEntity: ({ entityName, table }: Params) => ITenantEntity;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenancy/definitions/tenantEntity.js","sources":["../../../src/tenancy/definitions/tenantEntity.ts"],"sourcesContent":["import type { Table } from \"@webiny/db-dynamodb/toolbox.js\";\nimport { createStandardEntity } from \"@webiny/db-dynamodb\";\nimport type { ITenantEntity } from \"~/tenancy/definitions/types.js\";\nimport type { Tenant } from \"@webiny/api-core/types/tenancy.js\";\n\ninterface Params {\n entityName: string;\n table: Table<string, string, string>;\n}\nexport const createTenantEntity = ({ entityName, table }: Params): ITenantEntity => {\n return createStandardEntity<Tenant>({\n name: entityName,\n table\n });\n};\n"],"names":["createTenantEntity","entityName","table","createStandardEntity"],"mappings":";AASO,MAAMA,qBAAqB,CAAC,EAAEC,UAAU,EAAEC,KAAK,EAAU,GACrDC,qBAA6B;QAChC,MAAMF;QACNC;IACJ"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { IEntity, IStandardEntityAttributes } from "@webiny/db-dynamodb";
|
|
2
|
+
import type { Tenant } from "@webiny/api-core/types/tenancy.js";
|
|
3
|
+
export interface ITenantEntityAttributes extends IStandardEntityAttributes<Tenant> {
|
|
4
|
+
TYPE: string;
|
|
5
|
+
}
|
|
6
|
+
export type ITenantEntity = IEntity<ITenantEntityAttributes>;
|
|
File without changes
|