@webiny/api-core-ddb 0.0.0-unstable.61c048f412 → 0.0.0-unstable.676006d08e
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 +23 -0
- package/ApiCoreDdbFeature.js.map +1 -0
- 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 +196 -156
- package/adminUsers/index.js.map +1 -1
- package/adminUsers/types.d.ts +3 -0
- package/adminUsers/types.js +5 -4
- package/adminUsers/types.js.map +1 -1
- package/createApiCoreDdb.d.ts +7 -1
- package/createApiCoreDdb.js +25 -21
- package/createApiCoreDdb.js.map +1 -1
- package/index.d.ts +3 -0
- package/index.js +2 -2
- package/keyValueStore/KeyValueStoreDynamoTable.d.ts +24 -0
- package/keyValueStore/KeyValueStoreDynamoTable.js +39 -25
- package/keyValueStore/KeyValueStoreDynamoTable.js.map +1 -1
- package/keyValueStore/KeyValueStoreStorageOperations.d.ts +14 -2
- package/keyValueStore/KeyValueStoreStorageOperations.js +222 -71
- package/keyValueStore/KeyValueStoreStorageOperations.js.map +1 -1
- package/keyValueStore/index.js +2 -3
- package/keyValueStore/index.js.map +1 -1
- package/package.json +20 -15
- package/security/definitions/entities.js +19 -24
- package/security/definitions/entities.js.map +1 -1
- package/security/definitions/types.d.ts +3 -3
- package/security/definitions/types.js +0 -3
- package/security/index.js +415 -463
- package/security/index.js.map +1 -1
- package/security/types.d.ts +3 -0
- package/security/types.js +6 -5
- package/security/types.js.map +1 -1
- 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.js +5 -9
- package/tenancy/definitions/tenantEntity.js.map +1 -1
- package/tenancy/definitions/types.js +0 -3
- package/tenancy/index.js +138 -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,428 @@
|
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
4
|
+
const createStorageOperations = (params)=>{
|
|
5
|
+
const { table: tableName, documentClient, scopeTenant } = params;
|
|
6
|
+
const inScope = (record)=>({
|
|
7
|
+
...record,
|
|
8
|
+
tenant: scopeTenant.getId()
|
|
69
9
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
10
|
+
const table = createTable({
|
|
11
|
+
name: tableName || process.env.DB_TABLE,
|
|
12
|
+
documentClient
|
|
13
|
+
});
|
|
14
|
+
const entities = {
|
|
15
|
+
apiKeys: createApiKeyEntity(table.table),
|
|
16
|
+
roles: createRoleEntity(table.table),
|
|
17
|
+
teams: createTeamEntity(table.table)
|
|
18
|
+
};
|
|
19
|
+
const createApiKeyKeys = ({ id, tenant })=>({
|
|
20
|
+
PK: `T#${tenant}#API_KEY#${id}`,
|
|
21
|
+
SK: "A",
|
|
22
|
+
GSI_TENANT: tenant,
|
|
23
|
+
TYPE: "security.apiKey"
|
|
77
24
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const keys = {
|
|
84
|
-
...createRoleKeys(role),
|
|
85
|
-
...createRoleGsiKeys(role)
|
|
86
|
-
};
|
|
87
|
-
try {
|
|
88
|
-
await entities.roles.put({
|
|
89
|
-
data: role,
|
|
90
|
-
...keys
|
|
25
|
+
const createApiKeyGsiKeys = ({ slug, token, tenant })=>({
|
|
26
|
+
GSI1_PK: `T#${tenant}#API_KEYS`,
|
|
27
|
+
GSI1_SK: token,
|
|
28
|
+
GSI2_PK: `T#${tenant}#API_KEYS`,
|
|
29
|
+
GSI2_SK: slug
|
|
91
30
|
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
code: "CREATE_ROLE_ERROR",
|
|
96
|
-
data: {
|
|
97
|
-
keys
|
|
98
|
-
}
|
|
31
|
+
const createRoleKeys = (role)=>({
|
|
32
|
+
PK: `T#${role.tenant}#ROLE#${role.id}`,
|
|
33
|
+
SK: "A"
|
|
99
34
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const keys = {
|
|
106
|
-
...createTeamKeys(team),
|
|
107
|
-
...createTeamGsiKeys(team)
|
|
108
|
-
};
|
|
109
|
-
try {
|
|
110
|
-
await entities.teams.put({
|
|
111
|
-
data: team,
|
|
112
|
-
...keys
|
|
35
|
+
const createRoleGsiKeys = (role)=>({
|
|
36
|
+
GSI1_PK: `T#${role.tenant}#ROLES`,
|
|
37
|
+
GSI1_SK: role.slug,
|
|
38
|
+
GSI_TENANT: role.tenant,
|
|
39
|
+
TYPE: "security.role"
|
|
113
40
|
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
code: "CREATE_TEAM_ERROR",
|
|
118
|
-
data: {
|
|
119
|
-
keys
|
|
120
|
-
}
|
|
41
|
+
const createTeamKeys = (team)=>({
|
|
42
|
+
PK: `T#${team.tenant}#TEAM#${team.id}`,
|
|
43
|
+
SK: "A"
|
|
121
44
|
});
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
}
|
|
45
|
+
const createTeamGsiKeys = (team)=>({
|
|
46
|
+
GSI1_PK: `T#${team.tenant}#TEAMS`,
|
|
47
|
+
GSI1_SK: team.slug,
|
|
48
|
+
GSI_TENANT: team.tenant,
|
|
49
|
+
TYPE: "security.team"
|
|
137
50
|
});
|
|
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
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
51
|
+
return {
|
|
52
|
+
async createApiKey (params) {
|
|
53
|
+
const apiKey = inScope(params.apiKey);
|
|
54
|
+
const keys = {
|
|
55
|
+
...createApiKeyKeys(apiKey),
|
|
56
|
+
...createApiKeyGsiKeys(apiKey)
|
|
57
|
+
};
|
|
58
|
+
try {
|
|
59
|
+
await entities.apiKeys.put({
|
|
60
|
+
data: apiKey,
|
|
61
|
+
...keys
|
|
62
|
+
});
|
|
63
|
+
} catch (err) {
|
|
64
|
+
throw error.from(err, {
|
|
65
|
+
message: "Could not create api key.",
|
|
66
|
+
code: "CREATE_API_KEY_ERROR",
|
|
67
|
+
data: {
|
|
68
|
+
keys
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
async createRole (params) {
|
|
74
|
+
const role = inScope(params.role);
|
|
75
|
+
const keys = {
|
|
76
|
+
...createRoleKeys(role),
|
|
77
|
+
...createRoleGsiKeys(role)
|
|
78
|
+
};
|
|
79
|
+
try {
|
|
80
|
+
await entities.roles.put({
|
|
81
|
+
data: role,
|
|
82
|
+
...keys
|
|
83
|
+
});
|
|
84
|
+
} catch (err) {
|
|
85
|
+
throw error.from(err, {
|
|
86
|
+
message: "Could not create role.",
|
|
87
|
+
code: "CREATE_ROLE_ERROR",
|
|
88
|
+
data: {
|
|
89
|
+
keys
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
async createTeam (params) {
|
|
95
|
+
const team = inScope(params.team);
|
|
96
|
+
const keys = {
|
|
97
|
+
...createTeamKeys(team),
|
|
98
|
+
...createTeamGsiKeys(team)
|
|
99
|
+
};
|
|
100
|
+
try {
|
|
101
|
+
await entities.teams.put({
|
|
102
|
+
data: team,
|
|
103
|
+
...keys
|
|
104
|
+
});
|
|
105
|
+
} catch (err) {
|
|
106
|
+
throw error.from(err, {
|
|
107
|
+
message: "Could not create team.",
|
|
108
|
+
code: "CREATE_TEAM_ERROR",
|
|
109
|
+
data: {
|
|
110
|
+
keys
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
async deleteApiKey (params) {
|
|
116
|
+
const keys = createApiKeyKeys(inScope(params.apiKey));
|
|
117
|
+
try {
|
|
118
|
+
await entities.apiKeys.delete(keys);
|
|
119
|
+
} catch (err) {
|
|
120
|
+
throw error.from(err, {
|
|
121
|
+
message: "Could not update api key.",
|
|
122
|
+
code: "UPDATE_API_KEY_ERROR",
|
|
123
|
+
data: {
|
|
124
|
+
keys
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
async deleteRole (params) {
|
|
130
|
+
const role = inScope(params.role);
|
|
131
|
+
const keys = createRoleKeys(role);
|
|
132
|
+
try {
|
|
133
|
+
await entities.roles.delete(keys);
|
|
134
|
+
} catch (err) {
|
|
135
|
+
throw error.from(err, {
|
|
136
|
+
message: "Could not delete role.",
|
|
137
|
+
code: "CREATE_DELETE_ERROR",
|
|
138
|
+
data: {
|
|
139
|
+
keys,
|
|
140
|
+
role
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
async deleteTeam (params) {
|
|
146
|
+
const team = inScope(params.team);
|
|
147
|
+
const keys = createTeamKeys(team);
|
|
148
|
+
try {
|
|
149
|
+
await entities.teams.delete(keys);
|
|
150
|
+
} catch (err) {
|
|
151
|
+
throw error.from(err, {
|
|
152
|
+
message: "Could not delete team.",
|
|
153
|
+
code: "CREATE_DELETE_ERROR",
|
|
154
|
+
data: {
|
|
155
|
+
keys,
|
|
156
|
+
team
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
async getApiKey (params) {
|
|
162
|
+
const { id } = params;
|
|
163
|
+
const tenant = scopeTenant.getId();
|
|
164
|
+
const keys = createApiKeyKeys({
|
|
165
|
+
id,
|
|
166
|
+
tenant
|
|
167
|
+
});
|
|
168
|
+
try {
|
|
169
|
+
const response = await entities.apiKeys.get(keys);
|
|
170
|
+
return response?.data || null;
|
|
171
|
+
} catch (err) {
|
|
172
|
+
throw error.from(err, {
|
|
173
|
+
message: "Could not load api key.",
|
|
174
|
+
code: "GET_API_KEY_ERROR",
|
|
175
|
+
data: {
|
|
176
|
+
id,
|
|
177
|
+
keys
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
async getApiKeyByToken (params) {
|
|
183
|
+
const { token } = params;
|
|
184
|
+
const tenant = scopeTenant.getId();
|
|
185
|
+
const queryParams = {
|
|
186
|
+
partitionKey: `T#${tenant}#API_KEYS`,
|
|
187
|
+
options: {
|
|
188
|
+
eq: token,
|
|
189
|
+
index: "GSI1"
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
try {
|
|
193
|
+
const result = await entities.apiKeys.queryOne(queryParams);
|
|
194
|
+
return result?.data || null;
|
|
195
|
+
} catch (err) {
|
|
196
|
+
throw error.from(err, {
|
|
197
|
+
message: "Could not load api key by token.",
|
|
198
|
+
code: "GET_BY_TOKEN_API_KEY_ERROR",
|
|
199
|
+
data: {
|
|
200
|
+
partitionKey: queryParams.partitionKey,
|
|
201
|
+
options: queryParams.options
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
async getApiKeyBySlug (params) {
|
|
207
|
+
const { slug } = params;
|
|
208
|
+
const tenant = scopeTenant.getId();
|
|
209
|
+
const queryParams = {
|
|
210
|
+
partitionKey: `T#${tenant}#API_KEYS`,
|
|
211
|
+
options: {
|
|
212
|
+
eq: slug,
|
|
213
|
+
index: "GSI2"
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
try {
|
|
217
|
+
const result = await entities.apiKeys.queryOne(queryParams);
|
|
218
|
+
return result?.data || null;
|
|
219
|
+
} catch (err) {
|
|
220
|
+
throw error.from(err, {
|
|
221
|
+
message: "Could not load api key by slug.",
|
|
222
|
+
code: "GET_BY_SLUG_API_KEY_ERROR",
|
|
223
|
+
data: {
|
|
224
|
+
partitionKey: queryParams.partitionKey,
|
|
225
|
+
options: queryParams.options
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
async getRole ({ where }) {
|
|
231
|
+
const { id, slug } = where;
|
|
232
|
+
const tenant = scopeTenant.getId();
|
|
233
|
+
try {
|
|
234
|
+
if (id) {
|
|
235
|
+
const result = await entities.roles.get(createRoleKeys({
|
|
236
|
+
tenant,
|
|
237
|
+
id
|
|
238
|
+
}));
|
|
239
|
+
return result?.data || null;
|
|
240
|
+
}
|
|
241
|
+
const result = await entities.roles.queryOne({
|
|
242
|
+
partitionKey: `T#${tenant}#ROLES`,
|
|
243
|
+
options: {
|
|
244
|
+
index: "GSI1",
|
|
245
|
+
eq: slug
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
return result?.data || null;
|
|
249
|
+
} catch (err) {
|
|
250
|
+
throw error.from(err, {
|
|
251
|
+
message: "Could not load role.",
|
|
252
|
+
code: "GET_ROLE_ERROR",
|
|
253
|
+
data: {
|
|
254
|
+
id,
|
|
255
|
+
slug
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
async getTeam ({ where }) {
|
|
261
|
+
const { id, slug } = where;
|
|
262
|
+
const tenant = scopeTenant.getId();
|
|
263
|
+
try {
|
|
264
|
+
if (id) {
|
|
265
|
+
const result = await entities.teams.get(createTeamKeys({
|
|
266
|
+
tenant,
|
|
267
|
+
id
|
|
268
|
+
}));
|
|
269
|
+
return result?.data || null;
|
|
270
|
+
}
|
|
271
|
+
const result = await entities.teams.queryOne({
|
|
272
|
+
partitionKey: `T#${tenant}#TEAMS`,
|
|
273
|
+
options: {
|
|
274
|
+
index: "GSI1",
|
|
275
|
+
eq: slug
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
return result?.data || null;
|
|
279
|
+
} catch (err) {
|
|
280
|
+
throw error.from(err, {
|
|
281
|
+
message: "Could not load team.",
|
|
282
|
+
code: "GET_TEAM_ERROR",
|
|
283
|
+
data: {
|
|
284
|
+
id,
|
|
285
|
+
slug
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
async listApiKeys ({ sort }) {
|
|
291
|
+
const tenant = scopeTenant.getId();
|
|
292
|
+
let items;
|
|
293
|
+
try {
|
|
294
|
+
items = await entities.apiKeys.queryAll({
|
|
295
|
+
partitionKey: `T#${tenant}#API_KEYS`,
|
|
296
|
+
options: {
|
|
297
|
+
index: "GSI1"
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
} catch (err) {
|
|
301
|
+
throw error.from(err, {
|
|
302
|
+
message: "Could not list api keys.",
|
|
303
|
+
code: "LIST_API_KEY_ERROR"
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
return sortItems({
|
|
307
|
+
items,
|
|
308
|
+
sort
|
|
309
|
+
}).map((item)=>item.data);
|
|
310
|
+
},
|
|
311
|
+
async listRoles ({ where, sort }) {
|
|
312
|
+
const { id_in, slug_in } = where;
|
|
313
|
+
const tenant = scopeTenant.getId();
|
|
314
|
+
let items;
|
|
315
|
+
try {
|
|
316
|
+
const ddbItems = await entities.roles.queryAll({
|
|
317
|
+
partitionKey: `T#${tenant}#ROLES`,
|
|
318
|
+
options: {
|
|
319
|
+
index: "GSI1"
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
items = ddbItems.map((item)=>item.data);
|
|
323
|
+
} catch (err) {
|
|
324
|
+
throw error.from(err, {
|
|
325
|
+
message: "Could not list roles.",
|
|
326
|
+
code: "LIST_ROLE_ERROR"
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
items = sortItems({
|
|
330
|
+
items,
|
|
331
|
+
sort
|
|
332
|
+
});
|
|
333
|
+
if (Array.isArray(id_in)) return items.filter((item)=>id_in.includes(item.id));
|
|
334
|
+
if (Array.isArray(slug_in)) return items.filter((item)=>slug_in.includes(item.slug));
|
|
335
|
+
return items;
|
|
336
|
+
},
|
|
337
|
+
async listTeams ({ where, sort }) {
|
|
338
|
+
const { id_in, slug_in } = where;
|
|
339
|
+
const tenant = scopeTenant.getId();
|
|
340
|
+
let items;
|
|
341
|
+
try {
|
|
342
|
+
const ddbRecords = await entities.teams.queryAll({
|
|
343
|
+
partitionKey: `T#${tenant}#TEAMS`,
|
|
344
|
+
options: {
|
|
345
|
+
index: "GSI1"
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
items = ddbRecords.map((item)=>item.data);
|
|
349
|
+
} catch (err) {
|
|
350
|
+
throw error.from(err, {
|
|
351
|
+
message: "Could not list teams.",
|
|
352
|
+
code: "LIST_TEAM_ERROR"
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
items = sortItems({
|
|
356
|
+
items,
|
|
357
|
+
sort
|
|
358
|
+
});
|
|
359
|
+
if (Array.isArray(id_in)) return items.filter((item)=>id_in.includes(item.id));
|
|
360
|
+
if (Array.isArray(slug_in)) return items.filter((item)=>slug_in.includes(item.slug));
|
|
361
|
+
return items;
|
|
362
|
+
},
|
|
363
|
+
async updateApiKey (params) {
|
|
364
|
+
const apiKey = inScope(params.apiKey);
|
|
365
|
+
const keys = {
|
|
366
|
+
...createApiKeyKeys(apiKey),
|
|
367
|
+
...createApiKeyGsiKeys(apiKey)
|
|
368
|
+
};
|
|
369
|
+
try {
|
|
370
|
+
await entities.apiKeys.put({
|
|
371
|
+
data: apiKey,
|
|
372
|
+
...keys
|
|
373
|
+
});
|
|
374
|
+
} catch (err) {
|
|
375
|
+
throw error.from(err, {
|
|
376
|
+
message: "Could not update api key.",
|
|
377
|
+
code: "UPDATE_API_KEY_ERROR",
|
|
378
|
+
data: {
|
|
379
|
+
keys
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
async updateRole (params) {
|
|
385
|
+
const role = inScope(params.role);
|
|
386
|
+
const keys = createRoleKeys(role);
|
|
387
|
+
try {
|
|
388
|
+
await entities.roles.put({
|
|
389
|
+
data: role,
|
|
390
|
+
...keys,
|
|
391
|
+
...createRoleGsiKeys(role)
|
|
392
|
+
});
|
|
393
|
+
} catch (err) {
|
|
394
|
+
throw error.from(err, {
|
|
395
|
+
message: "Could not update role.",
|
|
396
|
+
code: "UPDATE_ROLE_ERROR",
|
|
397
|
+
data: {
|
|
398
|
+
keys,
|
|
399
|
+
role
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
},
|
|
404
|
+
async updateTeam (params) {
|
|
405
|
+
const team = inScope(params.team);
|
|
406
|
+
const keys = createTeamKeys(team);
|
|
407
|
+
try {
|
|
408
|
+
await entities.teams.put({
|
|
409
|
+
data: team,
|
|
410
|
+
...keys,
|
|
411
|
+
...createTeamGsiKeys(team)
|
|
412
|
+
});
|
|
413
|
+
} catch (err) {
|
|
414
|
+
throw error.from(err, {
|
|
415
|
+
message: "Could not update team.",
|
|
416
|
+
code: "UPDATE_TEAM_ERROR",
|
|
417
|
+
data: {
|
|
418
|
+
keys,
|
|
419
|
+
team
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
}
|
|
294
423
|
}
|
|
295
|
-
|
|
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
|
-
};
|
|
424
|
+
};
|
|
474
425
|
};
|
|
426
|
+
export { createStorageOperations };
|
|
475
427
|
|
|
476
428
|
//# sourceMappingURL=index.js.map
|