@webiny/api-core-ddb 6.3.0-beta.4 → 6.4.0-beta.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/adminUsers/definitions/entities.js +5 -6
- package/adminUsers/definitions/entities.js.map +1 -1
- package/adminUsers/definitions/types.js +0 -3
- package/adminUsers/index.js +135 -156
- package/adminUsers/index.js.map +1 -1
- package/adminUsers/types.js +5 -4
- package/adminUsers/types.js.map +1 -1
- package/createApiCoreDdb.js +19 -22
- package/createApiCoreDdb.js.map +1 -1
- package/index.js +0 -2
- package/keyValueStore/KeyValueStoreDynamoTable.js +24 -25
- package/keyValueStore/KeyValueStoreDynamoTable.js.map +1 -1
- package/keyValueStore/KeyValueStoreStorageOperations.d.ts +2 -1
- package/keyValueStore/KeyValueStoreStorageOperations.js +72 -72
- package/keyValueStore/KeyValueStoreStorageOperations.js.map +1 -1
- package/keyValueStore/index.js +2 -3
- package/keyValueStore/index.js.map +1 -1
- package/package.json +9 -9
- package/security/definitions/entities.js +19 -24
- package/security/definitions/entities.js.map +1 -1
- package/security/definitions/types.js +0 -3
- package/security/index.js +389 -464
- package/security/index.js.map +1 -1
- package/security/types.js +6 -5
- package/security/types.js.map +1 -1
- package/tenancy/definitions/tenantEntity.js +5 -9
- package/tenancy/definitions/tenantEntity.js.map +1 -1
- package/tenancy/definitions/types.js +0 -3
- package/tenancy/index.js +107 -127
- package/tenancy/index.js.map +1 -1
- package/tenancy/types.js +4 -3
- package/tenancy/types.js.map +1 -1
- package/adminUsers/definitions/types.js.map +0 -1
- package/index.js.map +0 -1
- package/security/definitions/types.js.map +0 -1
- package/tenancy/definitions/types.js.map +0 -1
package/security/index.js
CHANGED
|
@@ -1,476 +1,401 @@
|
|
|
1
|
-
import
|
|
1
|
+
import error from "@webiny/error";
|
|
2
2
|
import { createApiKeyEntity, createRoleEntity, createTeamEntity } from "./definitions/entities.js";
|
|
3
3
|
import { createTable, sortItems } from "@webiny/db-dynamodb";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
table
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
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"
|
|
69
20
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
keys
|
|
76
|
-
}
|
|
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
|
|
77
26
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
|
27
|
+
const createRoleKeys = (role)=>({
|
|
28
|
+
PK: `T#${role.tenant}#ROLE#${role.id}`,
|
|
29
|
+
SK: "A"
|
|
91
30
|
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
keys
|
|
98
|
-
}
|
|
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"
|
|
99
36
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
|
37
|
+
const createTeamKeys = (team)=>({
|
|
38
|
+
PK: `T#${team.tenant}#TEAM#${team.id}`,
|
|
39
|
+
SK: "A"
|
|
113
40
|
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
keys
|
|
120
|
-
}
|
|
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"
|
|
121
46
|
});
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
+
}
|
|
205
396
|
}
|
|
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
|
-
};
|
|
397
|
+
};
|
|
474
398
|
};
|
|
399
|
+
export { createStorageOperations };
|
|
475
400
|
|
|
476
401
|
//# sourceMappingURL=index.js.map
|