@webiny/api-core-ddb 0.0.0-unstable.61c048f412
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/LICENSE +21 -0
- package/README.md +11 -0
- package/adminUsers/definitions/entities.d.ts +3 -0
- package/adminUsers/definitions/entities.js +10 -0
- package/adminUsers/definitions/entities.js.map +1 -0
- package/adminUsers/definitions/types.d.ts +5 -0
- package/adminUsers/definitions/types.js +3 -0
- package/adminUsers/definitions/types.js.map +1 -0
- package/adminUsers/index.d.ts +2 -0
- package/adminUsers/index.js +165 -0
- package/adminUsers/index.js.map +1 -0
- package/adminUsers/types.d.ts +22 -0
- package/adminUsers/types.js +7 -0
- package/adminUsers/types.js.map +1 -0
- package/createApiCoreDdb.d.ts +7 -0
- package/createApiCoreDdb.js +24 -0
- package/createApiCoreDdb.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +3 -0
- package/index.js.map +1 -0
- package/keyValueStore/KeyValueStoreDynamoTable.d.ts +15 -0
- package/keyValueStore/KeyValueStoreDynamoTable.js +29 -0
- package/keyValueStore/KeyValueStoreDynamoTable.js.map +1 -0
- package/keyValueStore/KeyValueStoreStorageOperations.d.ts +16 -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 +6 -0
- package/keyValueStore/index.js.map +1 -0
- package/package.json +40 -0
- package/security/definitions/entities.d.ts +5 -0
- package/security/definitions/entities.js +28 -0
- package/security/definitions/entities.js.map +1 -0
- package/security/definitions/types.d.ts +14 -0
- package/security/definitions/types.js +3 -0
- package/security/definitions/types.js.map +1 -0
- package/security/index.d.ts +3 -0
- package/security/index.js +476 -0
- package/security/index.js.map +1 -0
- package/security/types.d.ts +10 -0
- package/security/types.js +8 -0
- package/security/types.js.map +1 -0
- package/tenancy/definitions/tenantEntity.d.ts +8 -0
- package/tenancy/definitions/tenantEntity.js +12 -0
- package/tenancy/definitions/tenantEntity.js.map +1 -0
- package/tenancy/definitions/types.d.ts +6 -0
- package/tenancy/definitions/types.js +3 -0
- package/tenancy/definitions/types.js.map +1 -0
- package/tenancy/index.d.ts +2 -0
- package/tenancy/index.js +135 -0
- package/tenancy/index.js.map +1 -0
- package/tenancy/types.d.ts +10 -0
- package/tenancy/types.js +6 -0
- package/tenancy/types.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { IEntity, IStandardEntityAttributes } from \"@webiny/db-dynamodb\";\nimport type { Role, StorageApiKey, Team } from \"@webiny/api-core/types/security.js\";\n\nexport interface IRoleEntityAttributes extends IStandardEntityAttributes<Role> {\n TYPE: string;\n}\nexport type IRoleEntity = IEntity<IRoleEntityAttributes>;\n\nexport interface ITeamEntityAttributes extends IStandardEntityAttributes<Team> {\n TYPE: string;\n}\nexport type ITeamEntity = IEntity<ITeamEntityAttributes>;\n\nexport interface IApiKeyEntityAttributes extends IStandardEntityAttributes<StorageApiKey> {\n TYPE: string;\n}\nexport type IApiKeyEntity = IEntity<IApiKeyEntityAttributes>;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
import { createApiKeyEntity, createRoleEntity, createTeamEntity } from "./definitions/entities.js";
|
|
3
|
+
import { createTable, sortItems } from "@webiny/db-dynamodb";
|
|
4
|
+
export const createStorageOperations = params => {
|
|
5
|
+
const {
|
|
6
|
+
table: tableName,
|
|
7
|
+
documentClient
|
|
8
|
+
} = params;
|
|
9
|
+
const table = createTable({
|
|
10
|
+
name: tableName || process.env.DB_TABLE,
|
|
11
|
+
documentClient
|
|
12
|
+
});
|
|
13
|
+
const entities = {
|
|
14
|
+
apiKeys: createApiKeyEntity(table.table),
|
|
15
|
+
roles: createRoleEntity(table.table),
|
|
16
|
+
teams: createTeamEntity(table.table)
|
|
17
|
+
};
|
|
18
|
+
const createApiKeyKeys = ({
|
|
19
|
+
id,
|
|
20
|
+
tenant
|
|
21
|
+
}) => ({
|
|
22
|
+
PK: `T#${tenant}#API_KEY#${id}`,
|
|
23
|
+
SK: `A`,
|
|
24
|
+
GSI_TENANT: tenant,
|
|
25
|
+
TYPE: "security.apiKey"
|
|
26
|
+
});
|
|
27
|
+
const createApiKeyGsiKeys = ({
|
|
28
|
+
slug,
|
|
29
|
+
token,
|
|
30
|
+
tenant
|
|
31
|
+
}) => ({
|
|
32
|
+
GSI1_PK: `T#${tenant}#API_KEYS`,
|
|
33
|
+
GSI1_SK: token,
|
|
34
|
+
GSI2_PK: `T#${tenant}#API_KEYS`,
|
|
35
|
+
GSI2_SK: slug
|
|
36
|
+
});
|
|
37
|
+
const createRoleKeys = role => ({
|
|
38
|
+
PK: `T#${role.tenant}#ROLE#${role.id}`,
|
|
39
|
+
SK: `A`
|
|
40
|
+
});
|
|
41
|
+
const createRoleGsiKeys = role => ({
|
|
42
|
+
GSI1_PK: `T#${role.tenant}#ROLES`,
|
|
43
|
+
GSI1_SK: role.slug,
|
|
44
|
+
GSI_TENANT: role.tenant,
|
|
45
|
+
TYPE: "security.role"
|
|
46
|
+
});
|
|
47
|
+
const createTeamKeys = team => ({
|
|
48
|
+
PK: `T#${team.tenant}#TEAM#${team.id}`,
|
|
49
|
+
SK: `A`
|
|
50
|
+
});
|
|
51
|
+
const createTeamGsiKeys = team => ({
|
|
52
|
+
GSI1_PK: `T#${team.tenant}#TEAMS`,
|
|
53
|
+
GSI1_SK: team.slug,
|
|
54
|
+
GSI_TENANT: team.tenant,
|
|
55
|
+
TYPE: "security.team"
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
async createApiKey({
|
|
59
|
+
apiKey
|
|
60
|
+
}) {
|
|
61
|
+
const keys = {
|
|
62
|
+
...createApiKeyKeys(apiKey),
|
|
63
|
+
...createApiKeyGsiKeys(apiKey)
|
|
64
|
+
};
|
|
65
|
+
try {
|
|
66
|
+
await entities.apiKeys.put({
|
|
67
|
+
data: apiKey,
|
|
68
|
+
...keys
|
|
69
|
+
});
|
|
70
|
+
} catch (err) {
|
|
71
|
+
throw WebinyError.from(err, {
|
|
72
|
+
message: "Could not create api key.",
|
|
73
|
+
code: "CREATE_API_KEY_ERROR",
|
|
74
|
+
data: {
|
|
75
|
+
keys
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
async createRole({
|
|
81
|
+
role
|
|
82
|
+
}) {
|
|
83
|
+
const keys = {
|
|
84
|
+
...createRoleKeys(role),
|
|
85
|
+
...createRoleGsiKeys(role)
|
|
86
|
+
};
|
|
87
|
+
try {
|
|
88
|
+
await entities.roles.put({
|
|
89
|
+
data: role,
|
|
90
|
+
...keys
|
|
91
|
+
});
|
|
92
|
+
} catch (err) {
|
|
93
|
+
throw WebinyError.from(err, {
|
|
94
|
+
message: "Could not create role.",
|
|
95
|
+
code: "CREATE_ROLE_ERROR",
|
|
96
|
+
data: {
|
|
97
|
+
keys
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
async createTeam({
|
|
103
|
+
team
|
|
104
|
+
}) {
|
|
105
|
+
const keys = {
|
|
106
|
+
...createTeamKeys(team),
|
|
107
|
+
...createTeamGsiKeys(team)
|
|
108
|
+
};
|
|
109
|
+
try {
|
|
110
|
+
await entities.teams.put({
|
|
111
|
+
data: team,
|
|
112
|
+
...keys
|
|
113
|
+
});
|
|
114
|
+
} catch (err) {
|
|
115
|
+
throw WebinyError.from(err, {
|
|
116
|
+
message: "Could not create team.",
|
|
117
|
+
code: "CREATE_TEAM_ERROR",
|
|
118
|
+
data: {
|
|
119
|
+
keys
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
async deleteApiKey({
|
|
125
|
+
apiKey
|
|
126
|
+
}) {
|
|
127
|
+
const keys = createApiKeyKeys(apiKey);
|
|
128
|
+
try {
|
|
129
|
+
await entities.apiKeys.delete(keys);
|
|
130
|
+
} catch (err) {
|
|
131
|
+
throw WebinyError.from(err, {
|
|
132
|
+
message: "Could not update api key.",
|
|
133
|
+
code: "UPDATE_API_KEY_ERROR",
|
|
134
|
+
data: {
|
|
135
|
+
keys
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
async deleteRole({
|
|
141
|
+
role
|
|
142
|
+
}) {
|
|
143
|
+
const keys = createRoleKeys(role);
|
|
144
|
+
try {
|
|
145
|
+
await entities.roles.delete(keys);
|
|
146
|
+
} catch (err) {
|
|
147
|
+
throw WebinyError.from(err, {
|
|
148
|
+
message: "Could not delete role.",
|
|
149
|
+
code: "CREATE_DELETE_ERROR",
|
|
150
|
+
data: {
|
|
151
|
+
keys,
|
|
152
|
+
role
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
async deleteTeam({
|
|
158
|
+
team
|
|
159
|
+
}) {
|
|
160
|
+
const keys = createTeamKeys(team);
|
|
161
|
+
try {
|
|
162
|
+
await entities.teams.delete(keys);
|
|
163
|
+
} catch (err) {
|
|
164
|
+
throw WebinyError.from(err, {
|
|
165
|
+
message: "Could not delete team.",
|
|
166
|
+
code: "CREATE_DELETE_ERROR",
|
|
167
|
+
data: {
|
|
168
|
+
keys,
|
|
169
|
+
team
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
async getApiKey({
|
|
175
|
+
id,
|
|
176
|
+
tenant
|
|
177
|
+
}) {
|
|
178
|
+
const keys = createApiKeyKeys({
|
|
179
|
+
id,
|
|
180
|
+
tenant
|
|
181
|
+
});
|
|
182
|
+
try {
|
|
183
|
+
const response = await entities.apiKeys.get(keys);
|
|
184
|
+
return response?.data || null;
|
|
185
|
+
} catch (err) {
|
|
186
|
+
throw WebinyError.from(err, {
|
|
187
|
+
message: "Could not load api key.",
|
|
188
|
+
code: "GET_API_KEY_ERROR",
|
|
189
|
+
data: {
|
|
190
|
+
id,
|
|
191
|
+
keys
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
async getApiKeyByToken({
|
|
197
|
+
tenant,
|
|
198
|
+
token
|
|
199
|
+
}) {
|
|
200
|
+
const queryParams = {
|
|
201
|
+
partitionKey: `T#${tenant}#API_KEYS`,
|
|
202
|
+
options: {
|
|
203
|
+
eq: token,
|
|
204
|
+
index: "GSI1"
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
try {
|
|
208
|
+
const result = await entities.apiKeys.queryOne(queryParams);
|
|
209
|
+
return result?.data || null;
|
|
210
|
+
} catch (err) {
|
|
211
|
+
throw WebinyError.from(err, {
|
|
212
|
+
message: "Could not load api key by token.",
|
|
213
|
+
code: "GET_BY_TOKEN_API_KEY_ERROR",
|
|
214
|
+
data: {
|
|
215
|
+
partitionKey: queryParams.partitionKey,
|
|
216
|
+
options: queryParams.options
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
async getApiKeyBySlug({
|
|
222
|
+
tenant,
|
|
223
|
+
slug
|
|
224
|
+
}) {
|
|
225
|
+
const queryParams = {
|
|
226
|
+
partitionKey: `T#${tenant}#API_KEYS`,
|
|
227
|
+
options: {
|
|
228
|
+
eq: slug,
|
|
229
|
+
index: "GSI2"
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
try {
|
|
233
|
+
const result = await entities.apiKeys.queryOne(queryParams);
|
|
234
|
+
return result?.data || null;
|
|
235
|
+
} catch (err) {
|
|
236
|
+
throw WebinyError.from(err, {
|
|
237
|
+
message: "Could not load api key by slug.",
|
|
238
|
+
code: "GET_BY_SLUG_API_KEY_ERROR",
|
|
239
|
+
data: {
|
|
240
|
+
partitionKey: queryParams.partitionKey,
|
|
241
|
+
options: queryParams.options
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
async getRole({
|
|
247
|
+
where: {
|
|
248
|
+
tenant,
|
|
249
|
+
id,
|
|
250
|
+
slug
|
|
251
|
+
}
|
|
252
|
+
}) {
|
|
253
|
+
try {
|
|
254
|
+
if (id) {
|
|
255
|
+
const result = await entities.roles.get(createRoleKeys({
|
|
256
|
+
tenant,
|
|
257
|
+
id
|
|
258
|
+
}));
|
|
259
|
+
return result?.data || null;
|
|
260
|
+
}
|
|
261
|
+
const result = await entities.roles.queryOne({
|
|
262
|
+
partitionKey: `T#${tenant}#ROLES`,
|
|
263
|
+
options: {
|
|
264
|
+
index: "GSI1",
|
|
265
|
+
eq: slug
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
return result?.data || null;
|
|
269
|
+
} catch (err) {
|
|
270
|
+
throw WebinyError.from(err, {
|
|
271
|
+
message: "Could not load role.",
|
|
272
|
+
code: "GET_ROLE_ERROR",
|
|
273
|
+
data: {
|
|
274
|
+
id,
|
|
275
|
+
slug
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
async getTeam({
|
|
281
|
+
where: {
|
|
282
|
+
tenant,
|
|
283
|
+
id,
|
|
284
|
+
slug
|
|
285
|
+
}
|
|
286
|
+
}) {
|
|
287
|
+
try {
|
|
288
|
+
if (id) {
|
|
289
|
+
const result = await entities.teams.get(createTeamKeys({
|
|
290
|
+
tenant,
|
|
291
|
+
id
|
|
292
|
+
}));
|
|
293
|
+
return result?.data || null;
|
|
294
|
+
}
|
|
295
|
+
const result = await entities.teams.queryOne({
|
|
296
|
+
partitionKey: `T#${tenant}#TEAMS`,
|
|
297
|
+
options: {
|
|
298
|
+
index: "GSI1",
|
|
299
|
+
eq: slug
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
return result?.data || null;
|
|
303
|
+
} catch (err) {
|
|
304
|
+
throw WebinyError.from(err, {
|
|
305
|
+
message: "Could not load team.",
|
|
306
|
+
code: "GET_TEAM_ERROR",
|
|
307
|
+
data: {
|
|
308
|
+
id,
|
|
309
|
+
slug
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
async listApiKeys({
|
|
315
|
+
where: {
|
|
316
|
+
tenant
|
|
317
|
+
},
|
|
318
|
+
sort
|
|
319
|
+
}) {
|
|
320
|
+
let items;
|
|
321
|
+
try {
|
|
322
|
+
items = await entities.apiKeys.queryAll({
|
|
323
|
+
partitionKey: `T#${tenant}#API_KEYS`,
|
|
324
|
+
options: {
|
|
325
|
+
index: "GSI1"
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
} catch (err) {
|
|
329
|
+
throw WebinyError.from(err, {
|
|
330
|
+
message: "Could not list api keys.",
|
|
331
|
+
code: "LIST_API_KEY_ERROR"
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
return sortItems({
|
|
335
|
+
items,
|
|
336
|
+
sort
|
|
337
|
+
}).map(item => item.data);
|
|
338
|
+
},
|
|
339
|
+
async listRoles({
|
|
340
|
+
where: {
|
|
341
|
+
tenant,
|
|
342
|
+
id_in,
|
|
343
|
+
slug_in
|
|
344
|
+
},
|
|
345
|
+
sort
|
|
346
|
+
}) {
|
|
347
|
+
let items;
|
|
348
|
+
try {
|
|
349
|
+
const ddbItems = await entities.roles.queryAll({
|
|
350
|
+
partitionKey: `T#${tenant}#ROLES`,
|
|
351
|
+
options: {
|
|
352
|
+
index: "GSI1"
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
items = ddbItems.map(item => item.data);
|
|
356
|
+
} catch (err) {
|
|
357
|
+
throw WebinyError.from(err, {
|
|
358
|
+
message: "Could not list roles.",
|
|
359
|
+
code: "LIST_ROLE_ERROR"
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
items = sortItems({
|
|
363
|
+
items,
|
|
364
|
+
sort
|
|
365
|
+
});
|
|
366
|
+
if (Array.isArray(id_in)) {
|
|
367
|
+
return items.filter(item => id_in.includes(item.id));
|
|
368
|
+
}
|
|
369
|
+
if (Array.isArray(slug_in)) {
|
|
370
|
+
return items.filter(item => slug_in.includes(item.slug));
|
|
371
|
+
}
|
|
372
|
+
return items;
|
|
373
|
+
},
|
|
374
|
+
async listTeams({
|
|
375
|
+
where: {
|
|
376
|
+
tenant,
|
|
377
|
+
id_in,
|
|
378
|
+
slug_in
|
|
379
|
+
},
|
|
380
|
+
sort
|
|
381
|
+
}) {
|
|
382
|
+
let items;
|
|
383
|
+
try {
|
|
384
|
+
const ddbRecords = await entities.teams.queryAll({
|
|
385
|
+
partitionKey: `T#${tenant}#TEAMS`,
|
|
386
|
+
options: {
|
|
387
|
+
index: "GSI1"
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
items = ddbRecords.map(item => item.data);
|
|
391
|
+
} catch (err) {
|
|
392
|
+
throw WebinyError.from(err, {
|
|
393
|
+
message: "Could not list teams.",
|
|
394
|
+
code: "LIST_TEAM_ERROR"
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
items = sortItems({
|
|
398
|
+
items,
|
|
399
|
+
sort
|
|
400
|
+
});
|
|
401
|
+
if (Array.isArray(id_in)) {
|
|
402
|
+
return items.filter(item => id_in.includes(item.id));
|
|
403
|
+
}
|
|
404
|
+
if (Array.isArray(slug_in)) {
|
|
405
|
+
return items.filter(item => slug_in.includes(item.slug));
|
|
406
|
+
}
|
|
407
|
+
return items;
|
|
408
|
+
},
|
|
409
|
+
async updateApiKey({
|
|
410
|
+
apiKey
|
|
411
|
+
}) {
|
|
412
|
+
const keys = {
|
|
413
|
+
...createApiKeyKeys(apiKey),
|
|
414
|
+
...createApiKeyGsiKeys(apiKey)
|
|
415
|
+
};
|
|
416
|
+
try {
|
|
417
|
+
await entities.apiKeys.put({
|
|
418
|
+
data: apiKey,
|
|
419
|
+
...keys
|
|
420
|
+
});
|
|
421
|
+
} catch (err) {
|
|
422
|
+
throw WebinyError.from(err, {
|
|
423
|
+
message: "Could not update api key.",
|
|
424
|
+
code: "UPDATE_API_KEY_ERROR",
|
|
425
|
+
data: {
|
|
426
|
+
keys
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
},
|
|
431
|
+
async updateRole({
|
|
432
|
+
role
|
|
433
|
+
}) {
|
|
434
|
+
const keys = createRoleKeys(role);
|
|
435
|
+
try {
|
|
436
|
+
await entities.roles.put({
|
|
437
|
+
data: role,
|
|
438
|
+
...keys,
|
|
439
|
+
...createRoleGsiKeys(role)
|
|
440
|
+
});
|
|
441
|
+
} catch (err) {
|
|
442
|
+
throw WebinyError.from(err, {
|
|
443
|
+
message: "Could not update role.",
|
|
444
|
+
code: "UPDATE_ROLE_ERROR",
|
|
445
|
+
data: {
|
|
446
|
+
keys,
|
|
447
|
+
role
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
},
|
|
452
|
+
async updateTeam({
|
|
453
|
+
team
|
|
454
|
+
}) {
|
|
455
|
+
const keys = createTeamKeys(team);
|
|
456
|
+
try {
|
|
457
|
+
await entities.teams.put({
|
|
458
|
+
data: team,
|
|
459
|
+
...keys,
|
|
460
|
+
...createTeamGsiKeys(team)
|
|
461
|
+
});
|
|
462
|
+
} catch (err) {
|
|
463
|
+
throw WebinyError.from(err, {
|
|
464
|
+
message: "Could not update team.",
|
|
465
|
+
code: "UPDATE_TEAM_ERROR",
|
|
466
|
+
data: {
|
|
467
|
+
keys,
|
|
468
|
+
team
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["WebinyError","createApiKeyEntity","createRoleEntity","createTeamEntity","createTable","sortItems","createStorageOperations","params","table","tableName","documentClient","name","process","env","DB_TABLE","entities","apiKeys","roles","teams","createApiKeyKeys","id","tenant","PK","SK","GSI_TENANT","TYPE","createApiKeyGsiKeys","slug","token","GSI1_PK","GSI1_SK","GSI2_PK","GSI2_SK","createRoleKeys","role","createRoleGsiKeys","createTeamKeys","team","createTeamGsiKeys","createApiKey","apiKey","keys","put","data","err","from","message","code","createRole","createTeam","deleteApiKey","delete","deleteRole","deleteTeam","getApiKey","response","get","getApiKeyByToken","queryParams","partitionKey","options","eq","index","result","queryOne","getApiKeyBySlug","getRole","where","getTeam","listApiKeys","sort","items","queryAll","map","item","listRoles","id_in","slug_in","ddbItems","Array","isArray","filter","includes","listTeams","ddbRecords","updateApiKey","updateRole","updateTeam"],"sources":["index.ts"],"sourcesContent":["import type { SecurityStorageParams } from \"./types.js\";\nimport type {\n StorageApiKey,\n Role,\n SecurityStorageOperations,\n Team\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<Role, \"tenant\" | \"id\">) => ({\n PK: `T#${role.tenant}#ROLE#${role.id}`,\n SK: `A`\n });\n\n const createRoleGsiKeys = (role: Pick<Role, \"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<Team, \"tenant\" | \"id\">) => ({\n PK: `T#${team.tenant}#TEAM#${team.id}`,\n SK: `A`\n });\n\n const createTeamGsiKeys = (team: Pick<Team, \"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<Role[]> {\n let items: Role[];\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<Team[]> {\n let items: Team[];\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"],"mappings":"AAOA,OAAOA,WAAW,MAAM,eAAe;AACvC,SAASC,kBAAkB,EAAEC,gBAAgB,EAAEC,gBAAgB;AAC/D,SAASC,WAAW,EAA8BC,SAAS,QAAQ,qBAAqB;AAExF,OAAO,MAAMC,uBAAuB,GAChCC,MAA6B,IACD;EAC5B,MAAM;IAAEC,KAAK,EAAEC,SAAS;IAAEC;EAAe,CAAC,GAAGH,MAAM;EAEnD,MAAMC,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AO,EAAE,wBAAwB;UACjCC,IAAI,EAAE,mBAAmB;UACzBJ,IAAI,EAAE;YAAEF,IAAI;YAAEP;UAAK;QACvB,CAAC,CAAC;MACN;IACJ,CAAC;IACD,MAAMqD,UAAUA,CAAC;MAAElD;IAAK,CAAC,EAAiB;MACtC,MAAMI,IAAI,GAAGL,cAAc,CAACC,IAAI,CAAC;MAEjC,IAAI;QACA,MAAMtB,QAAQ,CAACG,KAAK,CAACwB,GAAG,CAAC;UACrBC,IAAI,EAAEN,IAAI;UACV,GAAGI,IAAI;UACP,GAAGH,iBAAiB,CAACD,IAAI;QAC7B,CAAC,CAAC;MACN,CAAC,CAAC,OAAOO,GAAG,EAAE;QACV,MAAM5C,WAAW,CAAC6C,IAAI,CAACD,GAAG,EAAE;UACxBE,OAAO,EAAE,wBAAwB;UACjCC,IAAI,EAAE,mBAAmB;UACzBJ,IAAI,EAAE;YAAEF,IAAI;YAAEJ;UAAK;QACvB,CAAC,CAAC;MACN;IACJ;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"names":["ENTITIES"],"sources":["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"],"mappings":"AAEA,WAAYA,QAAQ,0BAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAAA,OAARA,QAAQ;AAAA","ignoreList":[]}
|
|
@@ -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,"names":["createStandardEntity","createTenantEntity","entityName","table","name"],"sources":["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"],"mappings":"AACA,SAASA,oBAAoB,QAAQ,qBAAqB;AAQ1D,OAAO,MAAMC,kBAAkB,GAAGA,CAAC;EAAEC,UAAU;EAAEC;AAAc,CAAC,KAAoB;EAChF,OAAOH,oBAAoB,CAAS;IAChCI,IAAI,EAAEF,UAAU;IAChBC;EACJ,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|
|
@@ -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>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { IEntity, IStandardEntityAttributes } from \"@webiny/db-dynamodb\";\nimport type { Tenant } from \"@webiny/api-core/types/tenancy.js\";\n\nexport interface ITenantEntityAttributes extends IStandardEntityAttributes<Tenant> {\n TYPE: string;\n}\n\nexport type ITenantEntity = IEntity<ITenantEntityAttributes>;\n"],"mappings":"","ignoreList":[]}
|