@webiny/api-core-ddb 0.0.0-unstable.3c5210ad37 → 0.0.0-unstable.48a4e5b6c1
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
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
+
export interface ApiCoreDdbConfig {
|
|
3
|
+
documentClient: DynamoDBDocument;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Registers the DynamoDB implementation of ApiCoreStorageOperationsFactory. ApiCoreFeature.register
|
|
7
|
+
* resolves + builds it. Mirrors HeadlessCmsDdbFeature.
|
|
8
|
+
*/
|
|
9
|
+
export declare const ApiCoreDdbFeature: {
|
|
10
|
+
name: string;
|
|
11
|
+
register(container: import("@webiny/di").Container, context: ApiCoreDdbConfig): void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { ApiCoreStorageOperationsFactory, TenancyStorageOperationsFactory } from "@webiny/api-core";
|
|
3
|
+
import { createApiCoreDdb } from "./createApiCoreDdb.js";
|
|
4
|
+
import { createStorageOperations } from "./tenancy/index.js";
|
|
5
|
+
const ApiCoreDdbFeature = createFeature({
|
|
6
|
+
name: "ApiCoreDdb",
|
|
7
|
+
register (container, { documentClient }) {
|
|
8
|
+
container.registerInstance(ApiCoreStorageOperationsFactory, {
|
|
9
|
+
create: ({ scopeTenant })=>createApiCoreDdb({
|
|
10
|
+
documentClient,
|
|
11
|
+
scopeTenant
|
|
12
|
+
})
|
|
13
|
+
});
|
|
14
|
+
container.registerInstance(TenancyStorageOperationsFactory, {
|
|
15
|
+
create: ()=>createStorageOperations({
|
|
16
|
+
documentClient
|
|
17
|
+
})
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
export { ApiCoreDdbFeature };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=ApiCoreDdbFeature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiCoreDdbFeature.js","sources":["../src/ApiCoreDdbFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { ApiCoreStorageOperationsFactory, TenancyStorageOperationsFactory } from \"@webiny/api-core\";\nimport { createApiCoreDdb } from \"./createApiCoreDdb.js\";\nimport { createStorageOperations as createTenancyStorageOperations } from \"./tenancy/index.js\";\n\nexport interface ApiCoreDdbConfig {\n documentClient: DynamoDBDocument;\n}\n\n/**\n * Registers the DynamoDB implementation of ApiCoreStorageOperationsFactory. ApiCoreFeature.register\n * resolves + builds it. Mirrors HeadlessCmsDdbFeature.\n */\nexport const ApiCoreDdbFeature = createFeature<ApiCoreDdbConfig>({\n name: \"ApiCoreDdb\",\n register(container, { documentClient }) {\n container.registerInstance(ApiCoreStorageOperationsFactory, {\n create: ({ scopeTenant }) => createApiCoreDdb({ documentClient, scopeTenant })\n });\n // The tenant registry on its own: the request container reads the request's tenant from it.\n container.registerInstance(TenancyStorageOperationsFactory, {\n create: () => createTenancyStorageOperations({ documentClient })\n });\n }\n});\n"],"names":["ApiCoreDdbFeature","createFeature","container","documentClient","ApiCoreStorageOperationsFactory","scopeTenant","createApiCoreDdb","TenancyStorageOperationsFactory","createTenancyStorageOperations"],"mappings":";;;;AAcO,MAAMA,oBAAoBC,cAAgC;IAC7D,MAAM;IACN,UAASC,SAAS,EAAE,EAAEC,cAAc,EAAE;QAClCD,UAAU,gBAAgB,CAACE,iCAAiC;YACxD,QAAQ,CAAC,EAAEC,WAAW,EAAE,GAAKC,iBAAiB;oBAAEH;oBAAgBE;gBAAY;QAChF;QAEAH,UAAU,gBAAgB,CAACK,iCAAiC;YACxD,QAAQ,IAAMC,wBAA+B;oBAAEL;gBAAe;QAClE;IACJ;AACJ"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { createStandardEntity } from "@webiny/db-dynamodb";
|
|
2
2
|
import { ENTITIES } from "../types.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
3
|
+
const createUserEntity = (table)=>createStandardEntity({
|
|
4
|
+
name: ENTITIES.USERS,
|
|
5
|
+
table
|
|
6
|
+
});
|
|
7
|
+
export { createUserEntity };
|
|
9
8
|
|
|
10
9
|
//# sourceMappingURL=entities.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"adminUsers/definitions/entities.js","sources":["../../../src/adminUsers/definitions/entities.ts"],"sourcesContent":["import { createStandardEntity } from \"@webiny/db-dynamodb\";\nimport type { Table } from \"@webiny/db-dynamodb/toolbox.js\";\nimport { ENTITIES } from \"../types.js\";\nimport type { IAdminUserEntity } from \"~/adminUsers/definitions/types.js\";\nimport type { AdminUser } from \"@webiny/api-core/types/users.js\";\n\nexport const createUserEntity = (table: Table<string, string, string>): IAdminUserEntity => {\n return createStandardEntity<AdminUser>({\n name: ENTITIES.USERS,\n table\n });\n};\n"],"names":["createUserEntity","table","createStandardEntity","ENTITIES"],"mappings":";;AAMO,MAAMA,mBAAmB,CAACC,QACtBC,qBAAgC;QACnC,MAAMC,SAAS,KAAK;QACpBF;IACJ"}
|
package/adminUsers/index.js
CHANGED
|
@@ -1,165 +1,205 @@
|
|
|
1
|
-
import
|
|
1
|
+
import error from "@webiny/error";
|
|
2
2
|
import { createTable, sortItems } from "@webiny/db-dynamodb";
|
|
3
3
|
import { createUserEntity } from "./definitions/entities.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const table = createTable({
|
|
10
|
-
name: tableName || process.env.DB_TABLE,
|
|
11
|
-
documentClient
|
|
12
|
-
});
|
|
13
|
-
const entities = {
|
|
14
|
-
users: createUserEntity(table.table)
|
|
15
|
-
};
|
|
16
|
-
const createUserKeys = user => ({
|
|
17
|
-
PK: `T#${user.tenant}#ADMIN_USER#${user.id}`,
|
|
18
|
-
SK: `A`
|
|
19
|
-
});
|
|
20
|
-
const createUserGSIKeys = user => {
|
|
21
|
-
return {
|
|
22
|
-
GSI1_PK: `T#${user.tenant}#ADMIN_USERS`,
|
|
23
|
-
GSI1_SK: user.email,
|
|
24
|
-
GSI_TENANT: user.tenant
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
const storageOperations = {
|
|
28
|
-
getTable() {
|
|
29
|
-
return table;
|
|
30
|
-
},
|
|
31
|
-
getEntities() {
|
|
32
|
-
return entities;
|
|
33
|
-
},
|
|
34
|
-
async createUser({
|
|
35
|
-
user
|
|
36
|
-
}) {
|
|
37
|
-
const keys = {
|
|
38
|
-
...createUserKeys(user),
|
|
39
|
-
...createUserGSIKeys(user)
|
|
40
|
-
};
|
|
41
|
-
try {
|
|
42
|
-
await entities.users.put({
|
|
43
|
-
...keys,
|
|
44
|
-
TYPE: "adminUsers.user",
|
|
45
|
-
data: user
|
|
4
|
+
const createStorageOperations = (params)=>{
|
|
5
|
+
const { table: tableName, documentClient, scopeTenant } = params;
|
|
6
|
+
const inScope = (user)=>({
|
|
7
|
+
...user,
|
|
8
|
+
tenant: scopeTenant.getId()
|
|
46
9
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
10
|
+
const table = createTable({
|
|
11
|
+
name: tableName || process.env.DB_TABLE,
|
|
12
|
+
documentClient
|
|
13
|
+
});
|
|
14
|
+
const entities = {
|
|
15
|
+
users: createUserEntity(table.table)
|
|
16
|
+
};
|
|
17
|
+
const createUserKeys = (user)=>({
|
|
18
|
+
PK: `T#${user.tenant}#ADMIN_USER#${user.id}`,
|
|
19
|
+
SK: "A"
|
|
55
20
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
await entities.users.delete(keys);
|
|
64
|
-
} catch (err) {
|
|
65
|
-
throw WebinyError.from(err, {
|
|
66
|
-
message: "Could not delete group.",
|
|
67
|
-
code: "CREATE_DELETE_ERROR",
|
|
68
|
-
data: {
|
|
69
|
-
keys,
|
|
70
|
-
user
|
|
71
|
-
}
|
|
21
|
+
const createUserIndexPartitionKey = (id)=>`ADMIN_USER#${id}`;
|
|
22
|
+
const createUserGSIKeys = (user)=>({
|
|
23
|
+
GSI1_PK: `T#${user.tenant}#ADMIN_USERS`,
|
|
24
|
+
GSI1_SK: user.email,
|
|
25
|
+
GSI2_PK: createUserIndexPartitionKey(user.id),
|
|
26
|
+
GSI2_SK: `T#${user.tenant}`,
|
|
27
|
+
GSI_TENANT: user.tenant
|
|
72
28
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
29
|
+
const storageOperations = {
|
|
30
|
+
getTable () {
|
|
31
|
+
return table;
|
|
32
|
+
},
|
|
33
|
+
getEntities () {
|
|
34
|
+
return entities;
|
|
35
|
+
},
|
|
36
|
+
async createUser (params) {
|
|
37
|
+
const user = inScope(params.user);
|
|
38
|
+
const keys = {
|
|
39
|
+
...createUserKeys(user),
|
|
40
|
+
...createUserGSIKeys(user)
|
|
41
|
+
};
|
|
42
|
+
try {
|
|
43
|
+
await entities.users.put({
|
|
44
|
+
...keys,
|
|
45
|
+
TYPE: "adminUsers.user",
|
|
46
|
+
data: user
|
|
47
|
+
});
|
|
48
|
+
return user;
|
|
49
|
+
} catch (err) {
|
|
50
|
+
throw error.from(err, {
|
|
51
|
+
message: "Could not create admin user.",
|
|
52
|
+
code: "CREATE_ADMIN_USER_ERROR",
|
|
53
|
+
data: {
|
|
54
|
+
keys
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
async deleteUser (params) {
|
|
60
|
+
const user = inScope(params.user);
|
|
61
|
+
const keys = createUserKeys(user);
|
|
62
|
+
try {
|
|
63
|
+
await entities.users.delete(keys);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
throw error.from(err, {
|
|
66
|
+
message: "Could not delete group.",
|
|
67
|
+
code: "CREATE_DELETE_ERROR",
|
|
68
|
+
data: {
|
|
69
|
+
keys,
|
|
70
|
+
user
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
async getUser (params) {
|
|
76
|
+
const { where: { id, email } } = params;
|
|
77
|
+
const tenant = scopeTenant.getId();
|
|
78
|
+
try {
|
|
79
|
+
if (id) {
|
|
80
|
+
const response = await entities.users.get(createUserKeys({
|
|
81
|
+
tenant,
|
|
82
|
+
id
|
|
83
|
+
}));
|
|
84
|
+
return response?.data || null;
|
|
85
|
+
}
|
|
86
|
+
const response = await entities.users.queryOne({
|
|
87
|
+
partitionKey: `T#${tenant}#ADMIN_USERS`,
|
|
88
|
+
options: {
|
|
89
|
+
index: "GSI1",
|
|
90
|
+
eq: email
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return response?.data || null;
|
|
94
|
+
} catch (err) {
|
|
95
|
+
throw error.from(err, {
|
|
96
|
+
message: "Could not load user.",
|
|
97
|
+
code: "GET_ADMIN_USERS_ERROR",
|
|
98
|
+
data: {
|
|
99
|
+
id,
|
|
100
|
+
email
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
async getUserAcrossTenants (params) {
|
|
106
|
+
const { id, tenants } = params;
|
|
107
|
+
if (0 === tenants.length) return [];
|
|
108
|
+
try {
|
|
109
|
+
const reader = entities.users.createEntityReader({
|
|
110
|
+
read: tenants.map((tenant)=>createUserKeys({
|
|
111
|
+
tenant,
|
|
112
|
+
id
|
|
113
|
+
}))
|
|
114
|
+
});
|
|
115
|
+
const items = await reader.execute();
|
|
116
|
+
return items.filter((item)=>!!item?.data).map((item)=>item.data);
|
|
117
|
+
} catch (err) {
|
|
118
|
+
throw error.from(err, {
|
|
119
|
+
message: "Could not load user across tenants.",
|
|
120
|
+
code: "GET_ADMIN_USER_ACROSS_TENANTS_ERROR",
|
|
121
|
+
data: {
|
|
122
|
+
id,
|
|
123
|
+
tenants
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
async listUserRecords (params) {
|
|
129
|
+
const { id } = params;
|
|
130
|
+
try {
|
|
131
|
+
const items = await entities.users.queryAll({
|
|
132
|
+
partitionKey: createUserIndexPartitionKey(id),
|
|
133
|
+
options: {
|
|
134
|
+
index: "GSI2"
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
return items.map((item)=>item.data);
|
|
138
|
+
} catch (err) {
|
|
139
|
+
throw error.from(err, {
|
|
140
|
+
message: "Could not list user records.",
|
|
141
|
+
code: "LIST_ADMIN_USER_RECORDS_ERROR",
|
|
142
|
+
data: {
|
|
143
|
+
id
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
async listUsers ({ where, sort }) {
|
|
149
|
+
const tenant = scopeTenant.getId();
|
|
150
|
+
let items;
|
|
151
|
+
try {
|
|
152
|
+
const ddbItems = await entities.users.queryAll({
|
|
153
|
+
partitionKey: `T#${tenant}#ADMIN_USERS`,
|
|
154
|
+
options: {
|
|
155
|
+
index: "GSI1"
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
items = ddbItems.map((item)=>item.data);
|
|
159
|
+
} catch (err) {
|
|
160
|
+
throw error.from(err, {
|
|
161
|
+
message: "Could not list users.",
|
|
162
|
+
code: "LIST_ADMIN_USERS_ERROR"
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
const { id_in, teams_in } = where;
|
|
166
|
+
const filtered = items.filter((item)=>{
|
|
167
|
+
if (Array.isArray(id_in) && !id_in.includes(item.id)) return false;
|
|
168
|
+
if (Array.isArray(teams_in)) return (item.teams || []).some((team)=>teams_in.includes(team));
|
|
169
|
+
return true;
|
|
170
|
+
});
|
|
171
|
+
return sortItems({
|
|
172
|
+
items: filtered,
|
|
173
|
+
sort
|
|
174
|
+
});
|
|
175
|
+
},
|
|
176
|
+
async updateUser (params) {
|
|
177
|
+
const user = inScope(params.user);
|
|
178
|
+
const keys = {
|
|
179
|
+
...createUserKeys(user),
|
|
180
|
+
...createUserGSIKeys(user)
|
|
181
|
+
};
|
|
182
|
+
try {
|
|
183
|
+
await entities.users.put({
|
|
184
|
+
...keys,
|
|
185
|
+
TYPE: "adminUsers.user",
|
|
186
|
+
data: user
|
|
187
|
+
});
|
|
188
|
+
return user;
|
|
189
|
+
} catch (err) {
|
|
190
|
+
throw error.from(err, {
|
|
191
|
+
message: "Could not update user.",
|
|
192
|
+
code: "UPDATE_ADMIN_USER_ERROR",
|
|
193
|
+
data: {
|
|
194
|
+
keys,
|
|
195
|
+
user
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
90
199
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
options: {
|
|
94
|
-
index: "GSI1",
|
|
95
|
-
eq: email
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
return response?.data || null;
|
|
99
|
-
} catch (err) {
|
|
100
|
-
throw WebinyError.from(err, {
|
|
101
|
-
message: "Could not load user.",
|
|
102
|
-
code: "GET_ADMIN_USERS_ERROR",
|
|
103
|
-
data: {
|
|
104
|
-
id,
|
|
105
|
-
email
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
async listUsers({
|
|
111
|
-
where,
|
|
112
|
-
sort
|
|
113
|
-
}) {
|
|
114
|
-
let items;
|
|
115
|
-
try {
|
|
116
|
-
const ddbItems = await entities.users.queryAll({
|
|
117
|
-
partitionKey: `T#${where.tenant}#ADMIN_USERS`,
|
|
118
|
-
options: {
|
|
119
|
-
index: "GSI1"
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
items = ddbItems.map(item => {
|
|
123
|
-
return item.data;
|
|
124
|
-
});
|
|
125
|
-
} catch (err) {
|
|
126
|
-
throw WebinyError.from(err, {
|
|
127
|
-
message: "Could not list users.",
|
|
128
|
-
code: "LIST_ADMIN_USERS_ERROR"
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
return sortItems({
|
|
132
|
-
items,
|
|
133
|
-
sort
|
|
134
|
-
});
|
|
135
|
-
},
|
|
136
|
-
async updateUser({
|
|
137
|
-
user
|
|
138
|
-
}) {
|
|
139
|
-
const keys = {
|
|
140
|
-
...createUserKeys(user),
|
|
141
|
-
...createUserGSIKeys(user)
|
|
142
|
-
};
|
|
143
|
-
try {
|
|
144
|
-
await entities.users.put({
|
|
145
|
-
...keys,
|
|
146
|
-
TYPE: "adminUsers.user",
|
|
147
|
-
data: user
|
|
148
|
-
});
|
|
149
|
-
return user;
|
|
150
|
-
} catch (err) {
|
|
151
|
-
throw WebinyError.from(err, {
|
|
152
|
-
message: "Could not update user.",
|
|
153
|
-
code: "UPDATE_ADMIN_USER_ERROR",
|
|
154
|
-
data: {
|
|
155
|
-
keys,
|
|
156
|
-
user
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
return storageOperations;
|
|
200
|
+
};
|
|
201
|
+
return storageOperations;
|
|
163
202
|
};
|
|
203
|
+
export { createStorageOperations };
|
|
164
204
|
|
|
165
205
|
//# sourceMappingURL=index.js.map
|
package/adminUsers/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["WebinyError","createTable","sortItems","createUserEntity","createStorageOperations","params","table","tableName","documentClient","name","process","env","DB_TABLE","entities","users","createUserKeys","user","PK","tenant","id","SK","createUserGSIKeys","GSI1_PK","GSI1_SK","email","GSI_TENANT","storageOperations","getTable","getEntities","createUser","keys","put","TYPE","data","err","from","message","code","deleteUser","delete","getUser","where","response","get","queryOne","partitionKey","options","index","eq","listUsers","sort","items","ddbItems","queryAll","map","item","updateUser"],"sources":["index.ts"],"sourcesContent":["import type { AdminUsersStorageOperations, CreateAdminUsersStorageOperations } from \"./types.js\";\nimport WebinyError from \"@webiny/error\";\nimport { createTable, type IStandardEntityAttributes, sortItems } from \"@webiny/db-dynamodb\";\nimport { createUserEntity } from \"./definitions/entities.js\";\nimport type {\n AdminUser,\n StorageOperationsGetUserParams,\n StorageOperationsListUsersParams\n} from \"@webiny/api-core/types/users.js\";\n\nexport const createStorageOperations: CreateAdminUsersStorageOperations = params => {\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 users: createUserEntity(table.table)\n };\n\n const createUserKeys = (user: Pick<AdminUser, \"tenant\" | \"id\">) => ({\n PK: `T#${user.tenant}#ADMIN_USER#${user.id}`,\n SK: `A`\n });\n\n const createUserGSIKeys = (user: AdminUser) => {\n return {\n GSI1_PK: `T#${user.tenant}#ADMIN_USERS`,\n GSI1_SK: user.email,\n GSI_TENANT: user.tenant\n };\n };\n\n const storageOperations: AdminUsersStorageOperations = {\n getTable() {\n return table;\n },\n getEntities() {\n return entities;\n },\n async createUser({ user }) {\n const keys = {\n ...createUserKeys(user),\n ...createUserGSIKeys(user)\n };\n\n try {\n await entities.users.put({\n ...keys,\n TYPE: \"adminUsers.user\",\n data: user\n });\n\n return user;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create admin user.\",\n code: \"CREATE_ADMIN_USER_ERROR\",\n data: { keys }\n });\n }\n },\n async deleteUser({ user }) {\n const keys = createUserKeys(user);\n\n try {\n await entities.users.delete(keys);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not delete group.\",\n code: \"CREATE_DELETE_ERROR\",\n data: { keys, user }\n });\n }\n },\n async getUser<TUser extends AdminUser = AdminUser>(\n params: StorageOperationsGetUserParams\n ): Promise<TUser | null> {\n const {\n where: { tenant, id, email }\n } = params;\n try {\n if (id) {\n const response = await entities.users.get<IStandardEntityAttributes<TUser>>(\n createUserKeys({ tenant, id })\n );\n return (response?.data as TUser) || null;\n }\n\n const response = await entities.users.queryOne<IStandardEntityAttributes<TUser>>({\n partitionKey: `T#${tenant}#ADMIN_USERS`,\n options: {\n index: \"GSI1\",\n eq: email\n }\n });\n\n return (response?.data as TUser) || null;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load user.\",\n code: \"GET_ADMIN_USERS_ERROR\",\n data: { id, email }\n });\n }\n },\n async listUsers<TUser extends AdminUser = AdminUser>({\n where,\n sort\n }: StorageOperationsListUsersParams) {\n let items: TUser[];\n try {\n const ddbItems = await entities.users.queryAll<IStandardEntityAttributes<TUser>>({\n partitionKey: `T#${where.tenant}#ADMIN_USERS`,\n options: {\n index: \"GSI1\"\n }\n });\n items = ddbItems.map(item => {\n return item.data as TUser;\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list users.\",\n code: \"LIST_ADMIN_USERS_ERROR\"\n });\n }\n\n return sortItems({ items, sort });\n },\n async updateUser({ user }) {\n const keys = {\n ...createUserKeys(user),\n ...createUserGSIKeys(user)\n };\n\n try {\n await entities.users.put({\n ...keys,\n TYPE: \"adminUsers.user\",\n data: user\n });\n return user;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update user.\",\n code: \"UPDATE_ADMIN_USER_ERROR\",\n data: { keys, user }\n });\n }\n }\n };\n\n return storageOperations;\n};\n"],"mappings":"AACA,OAAOA,WAAW,M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C,WAAW,CAACmC,IAAI,CAACD,GAAG,EAAE;UACxBE,OAAO,EAAE,wBAAwB;UACjCC,IAAI,EAAE,yBAAyB;UAC/BJ,IAAI,EAAE;YAAEH,IAAI;YAAEd;UAAK;QACvB,CAAC,CAAC;MACN;IACJ;EACJ,CAAC;EAED,OAAOU,iBAAiB;AAC5B,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"adminUsers/index.js","sources":["../../src/adminUsers/index.ts"],"sourcesContent":["import type { AdminUsersStorageOperations, CreateAdminUsersStorageOperations } from \"./types.js\";\nimport WebinyError from \"@webiny/error\";\nimport { createTable, type IStandardEntityAttributes, sortItems } from \"@webiny/db-dynamodb\";\nimport { createUserEntity } from \"./definitions/entities.js\";\nimport type {\n AdminUser,\n StorageOperationsGetUserAcrossTenantsParams,\n StorageOperationsGetUserParams,\n StorageOperationsListUserRecordsParams,\n StorageOperationsListUsersParams\n} from \"@webiny/api-core/types/users.js\";\n\nexport const createStorageOperations: CreateAdminUsersStorageOperations = params => {\n const { table: tableName, documentClient, scopeTenant } = params;\n\n /** The user with its scope's tenant, whatever tenant it carries. */\n const inScope = <T extends AdminUser>(user: T): T => {\n return { ...user, tenant: scopeTenant.getId() };\n };\n\n const table = createTable({\n name: tableName || (process.env.DB_TABLE as string),\n documentClient\n });\n\n const entities = {\n users: createUserEntity(table.table)\n };\n\n const createUserKeys = (user: Pick<AdminUser, \"tenant\" | \"id\">) => ({\n PK: `T#${user.tenant}#ADMIN_USER#${user.id}`,\n SK: `A`\n });\n\n const createUserIndexPartitionKey = (id: string) => `ADMIN_USER#${id}`;\n\n const createUserGSIKeys = (user: AdminUser) => {\n return {\n GSI1_PK: `T#${user.tenant}#ADMIN_USERS`,\n GSI1_SK: user.email,\n // The user→tenant index: every tenant's record of one user, in one partition.\n GSI2_PK: createUserIndexPartitionKey(user.id),\n GSI2_SK: `T#${user.tenant}`,\n GSI_TENANT: user.tenant\n };\n };\n\n const storageOperations: AdminUsersStorageOperations = {\n getTable() {\n return table;\n },\n getEntities() {\n return entities;\n },\n async createUser(params) {\n const user = inScope(params.user);\n const keys = {\n ...createUserKeys(user),\n ...createUserGSIKeys(user)\n };\n\n try {\n await entities.users.put({\n ...keys,\n TYPE: \"adminUsers.user\",\n data: user\n });\n\n return user;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create admin user.\",\n code: \"CREATE_ADMIN_USER_ERROR\",\n data: { keys }\n });\n }\n },\n async deleteUser(params) {\n const user = inScope(params.user);\n const keys = createUserKeys(user);\n\n try {\n await entities.users.delete(keys);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not delete group.\",\n code: \"CREATE_DELETE_ERROR\",\n data: { keys, user }\n });\n }\n },\n async getUser<TUser extends AdminUser = AdminUser>(\n params: StorageOperationsGetUserParams\n ): Promise<TUser | null> {\n const {\n where: { id, email }\n } = params;\n const tenant = scopeTenant.getId();\n try {\n if (id) {\n const response = await entities.users.get<IStandardEntityAttributes<TUser>>(\n createUserKeys({ tenant, id })\n );\n return (response?.data as TUser) || null;\n }\n\n const response = await entities.users.queryOne<IStandardEntityAttributes<TUser>>({\n partitionKey: `T#${tenant}#ADMIN_USERS`,\n options: {\n index: \"GSI1\",\n eq: email\n }\n });\n\n return (response?.data as TUser) || null;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load user.\",\n code: \"GET_ADMIN_USERS_ERROR\",\n data: { id, email }\n });\n }\n },\n // Cross-tenant by design: one user's records in the given tenants, not the scope's tenant.\n async getUserAcrossTenants<TUser extends AdminUser = AdminUser>(\n params: StorageOperationsGetUserAcrossTenantsParams\n ): Promise<TUser[]> {\n const { id, tenants } = params;\n if (tenants.length === 0) {\n return [];\n }\n\n try {\n // The batch reader splits the keys into chunks of 100 (the BatchGetItem limit).\n const reader = entities.users.createEntityReader({\n read: tenants.map(tenant => createUserKeys({ tenant, id }))\n });\n const items = await reader.execute();\n\n return items\n .filter(item => !!item?.data)\n .map(item => {\n return item.data as unknown as TUser;\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load user across tenants.\",\n code: \"GET_ADMIN_USER_ACROSS_TENANTS_ERROR\",\n data: { id, tenants }\n });\n }\n },\n // Cross-tenant by design: every tenant's record of one user.\n async listUserRecords<TUser extends AdminUser = AdminUser>(\n params: StorageOperationsListUserRecordsParams\n ): Promise<TUser[]> {\n const { id } = params;\n\n try {\n const items = await entities.users.queryAll<IStandardEntityAttributes<TUser>>({\n partitionKey: createUserIndexPartitionKey(id),\n options: {\n index: \"GSI2\"\n }\n });\n\n return items.map(item => item.data as TUser);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list user records.\",\n code: \"LIST_ADMIN_USER_RECORDS_ERROR\",\n data: { id }\n });\n }\n },\n async listUsers<TUser extends AdminUser = AdminUser>({\n where,\n sort\n }: StorageOperationsListUsersParams) {\n const tenant = scopeTenant.getId();\n let items: TUser[];\n try {\n const ddbItems = await entities.users.queryAll<IStandardEntityAttributes<TUser>>({\n partitionKey: `T#${tenant}#ADMIN_USERS`,\n options: {\n index: \"GSI1\"\n }\n });\n items = ddbItems.map(item => {\n return item.data as TUser;\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list users.\",\n code: \"LIST_ADMIN_USERS_ERROR\"\n });\n }\n\n const { id_in, teams_in } = where;\n\n const filtered = items.filter(item => {\n if (Array.isArray(id_in) && !id_in.includes(item.id)) {\n return false;\n }\n if (Array.isArray(teams_in)) {\n return (item.teams || []).some(team => teams_in.includes(team));\n }\n return true;\n });\n\n return sortItems({ items: filtered, sort });\n },\n async updateUser(params) {\n const user = inScope(params.user);\n const keys = {\n ...createUserKeys(user),\n ...createUserGSIKeys(user)\n };\n\n try {\n await entities.users.put({\n ...keys,\n TYPE: \"adminUsers.user\",\n data: user\n });\n return user;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update user.\",\n code: \"UPDATE_ADMIN_USER_ERROR\",\n data: { keys, user }\n });\n }\n }\n };\n\n return storageOperations;\n};\n"],"names":["createStorageOperations","params","tableName","documentClient","scopeTenant","inScope","user","table","createTable","process","entities","createUserEntity","createUserKeys","createUserIndexPartitionKey","id","createUserGSIKeys","storageOperations","keys","err","WebinyError","email","tenant","response","tenants","reader","items","item","where","sort","ddbItems","id_in","teams_in","filtered","Array","team","sortItems"],"mappings":";;;AAYO,MAAMA,0BAA6DC,CAAAA;IACtE,MAAM,EAAE,OAAOC,SAAS,EAAEC,cAAc,EAAEC,WAAW,EAAE,GAAGH;IAG1D,MAAMI,UAAU,CAAsBC,OAC3B;YAAE,GAAGA,IAAI;YAAE,QAAQF,YAAY,KAAK;QAAG;IAGlD,MAAMG,QAAQC,YAAY;QACtB,MAAMN,aAAcO,QAAQ,GAAG,CAAC,QAAQ;QACxCN;IACJ;IAEA,MAAMO,WAAW;QACb,OAAOC,iBAAiBJ,MAAM,KAAK;IACvC;IAEA,MAAMK,iBAAiB,CAACN,OAA4C;YAChE,IAAI,CAAC,EAAE,EAAEA,KAAK,MAAM,CAAC,YAAY,EAAEA,KAAK,EAAE,EAAE;YAC5C,IAAI;QACR;IAEA,MAAMO,8BAA8B,CAACC,KAAe,CAAC,WAAW,EAAEA,IAAI;IAEtE,MAAMC,oBAAoB,CAACT,OAChB;YACH,SAAS,CAAC,EAAE,EAAEA,KAAK,MAAM,CAAC,YAAY,CAAC;YACvC,SAASA,KAAK,KAAK;YAEnB,SAASO,4BAA4BP,KAAK,EAAE;YAC5C,SAAS,CAAC,EAAE,EAAEA,KAAK,MAAM,EAAE;YAC3B,YAAYA,KAAK,MAAM;QAC3B;IAGJ,MAAMU,oBAAiD;QACnD;YACI,OAAOT;QACX;QACA;YACI,OAAOG;QACX;QACA,MAAM,YAAWT,MAAM;YACnB,MAAMK,OAAOD,QAAQJ,OAAO,IAAI;YAChC,MAAMgB,OAAO;gBACT,GAAGL,eAAeN,KAAK;gBACvB,GAAGS,kBAAkBT,KAAK;YAC9B;YAEA,IAAI;gBACA,MAAMI,SAAS,KAAK,CAAC,GAA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K;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;gBACV;YACJ;YAEA,MAAM,EAAEY,KAAK,EAAEC,QAAQ,EAAE,GAAGJ;YAE5B,MAAMK,WAAWP,MAAM,MAAM,CAACC,CAAAA;gBAC1B,IAAIO,MAAM,OAAO,CAACH,UAAU,CAACA,MAAM,QAAQ,CAACJ,KAAK,EAAE,GAC/C,OAAO;gBAEX,IAAIO,MAAM,OAAO,CAACF,WACd,OAAQL,AAAAA,CAAAA,KAAK,KAAK,IAAI,EAAC,EAAG,IAAI,CAACQ,CAAAA,OAAQH,SAAS,QAAQ,CAACG;gBAE7D,OAAO;YACX;YAEA,OAAOC,UAAU;gBAAE,OAAOH;gBAAUJ;YAAK;QAC7C;QACA,MAAM,YAAW3B,MAAM;YACnB,MAAMK,OAAOD,QAAQJ,OAAO,IAAI;YAChC,MAAMgB,OAAO;gBACT,GAAGL,eAAeN,KAAK;gBACvB,GAAGS,kBAAkBT,KAAK;YAC9B;YAEA,IAAI;gBACA,MAAMI,SAAS,KAAK,CAAC,GAAG,CAAC;oBACrB,GAAGO,IAAI;oBACP,MAAM;oBACN,MAAMX;gBACV;gBACA,OAAOA;YACX,EAAE,OAAOY,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAED;wBAAMX;oBAAK;gBACvB;YACJ;QACJ;IACJ;IAEA,OAAOU;AACX"}
|
package/adminUsers/types.d.ts
CHANGED
|
@@ -2,12 +2,15 @@ import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js"
|
|
|
2
2
|
import type { AdminUsersStorageOperations as BaseAdminUsersStorageOperations } from "@webiny/api-core/types/users.js";
|
|
3
3
|
import type { IAdminUserEntity } from "../adminUsers/definitions/types.js";
|
|
4
4
|
import { ITable } from "@webiny/db-dynamodb";
|
|
5
|
+
import type { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
5
6
|
export declare enum ENTITIES {
|
|
6
7
|
SYSTEM = "AdminUsers.System",
|
|
7
8
|
USERS = "AdminUsers.User"
|
|
8
9
|
}
|
|
9
10
|
export interface ICreateAdminUsersStorageOperationsParams {
|
|
10
11
|
documentClient: DynamoDBDocument;
|
|
12
|
+
/** The tenant the storage acts on: its scope's. Reading one user across tenants doesn't use it. */
|
|
13
|
+
scopeTenant: ScopeTenant.Interface;
|
|
11
14
|
table?: string;
|
|
12
15
|
}
|
|
13
16
|
export interface CreateAdminUsersStorageOperations {
|
package/adminUsers/types.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var types_ENTITIES = /*#__PURE__*/ function(ENTITIES) {
|
|
2
|
+
ENTITIES["SYSTEM"] = "AdminUsers.System";
|
|
3
|
+
ENTITIES["USERS"] = "AdminUsers.User";
|
|
4
|
+
return ENTITIES;
|
|
5
5
|
}({});
|
|
6
|
+
export { types_ENTITIES as ENTITIES };
|
|
6
7
|
|
|
7
8
|
//# sourceMappingURL=types.js.map
|
package/adminUsers/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"adminUsers/types.js","sources":["../../src/adminUsers/types.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { AdminUsersStorageOperations as BaseAdminUsersStorageOperations } from \"@webiny/api-core/types/users.js\";\nimport type { IAdminUserEntity } from \"~/adminUsers/definitions/types.js\";\nimport { ITable } from \"@webiny/db-dynamodb\";\nimport type { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\n\nexport enum ENTITIES {\n SYSTEM = \"AdminUsers.System\",\n USERS = \"AdminUsers.User\"\n}\n\nexport interface ICreateAdminUsersStorageOperationsParams {\n documentClient: DynamoDBDocument;\n /** The tenant the storage acts on: its scope's. Reading one user across tenants doesn't use it. */\n scopeTenant: ScopeTenant.Interface;\n table?: string;\n}\n\nexport interface CreateAdminUsersStorageOperations {\n (params: ICreateAdminUsersStorageOperationsParams): AdminUsersStorageOperations;\n}\n\nexport interface IAdminUsersGetEntitiesResponse {\n users: IAdminUserEntity;\n}\n\nexport interface AdminUsersStorageOperations extends BaseAdminUsersStorageOperations {\n getTable(): ITable;\n getEntities(): IAdminUsersGetEntitiesResponse;\n}\n"],"names":["ENTITIES"],"mappings":"AAMO,IAAKA,iBAAQA,WAAAA,GAAAA,SAAAA,QAAAA"}
|
package/createApiCoreDdb.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { ApiCoreStorageOperations } from "@webiny/api-core/types/core.js";
|
|
2
2
|
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
3
|
+
import type { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
3
4
|
interface CreateApiCoreDdbParams {
|
|
4
5
|
documentClient: DynamoDBDocument;
|
|
6
|
+
/**
|
|
7
|
+
* The tenant the storage acts on: its tenant scope's. The tenant records and the key-value store
|
|
8
|
+
* don't use it (the tenant registry is tenant-neutral, and the store is keyed by its own scope).
|
|
9
|
+
*/
|
|
10
|
+
scopeTenant: ScopeTenant.Interface;
|
|
5
11
|
}
|
|
6
|
-
export declare const createApiCoreDdb: ({ documentClient }: CreateApiCoreDdbParams) => ApiCoreStorageOperations;
|
|
12
|
+
export declare const createApiCoreDdb: ({ documentClient, scopeTenant }: CreateApiCoreDdbParams) => ApiCoreStorageOperations;
|
|
7
13
|
export {};
|
package/createApiCoreDdb.js
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createStorageOperations
|
|
3
|
-
import { createStorageOperations as
|
|
4
|
-
import { createStorageOperations as
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import { ServiceDiscovery } from "@webiny/api-core/features/serviceDiscovery/index.js";
|
|
2
|
+
import { createStorageOperations } from "./adminUsers/index.js";
|
|
3
|
+
import { createStorageOperations as index_js_createStorageOperations } from "./tenancy/index.js";
|
|
4
|
+
import { createStorageOperations as external_security_index_js_createStorageOperations } from "./security/index.js";
|
|
5
|
+
import { createStorageOperations as external_keyValueStore_index_js_createStorageOperations } from "./keyValueStore/index.js";
|
|
6
|
+
import { DdbServiceManifestLoader } from "./serviceDiscovery/index.js";
|
|
7
|
+
const createApiCoreDdb = ({ documentClient, scopeTenant })=>{
|
|
8
|
+
ServiceDiscovery.setLoader(new DdbServiceManifestLoader(documentClient));
|
|
9
|
+
return {
|
|
10
|
+
usersStorageOperations: createStorageOperations({
|
|
11
|
+
documentClient,
|
|
12
|
+
scopeTenant
|
|
13
|
+
}),
|
|
14
|
+
tenancyStorageOperations: index_js_createStorageOperations({
|
|
15
|
+
documentClient
|
|
16
|
+
}),
|
|
17
|
+
securityStorageOperations: external_security_index_js_createStorageOperations({
|
|
18
|
+
documentClient,
|
|
19
|
+
scopeTenant
|
|
20
|
+
}),
|
|
21
|
+
keyValueStorageOperations: external_keyValueStore_index_js_createStorageOperations({
|
|
22
|
+
documentClient
|
|
23
|
+
})
|
|
24
|
+
};
|
|
22
25
|
};
|
|
26
|
+
export { createApiCoreDdb };
|
|
23
27
|
|
|
24
28
|
//# sourceMappingURL=createApiCoreDdb.js.map
|
package/createApiCoreDdb.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"createApiCoreDdb.js","sources":["../src/createApiCoreDdb.ts"],"sourcesContent":["import type { ApiCoreStorageOperations } from \"@webiny/api-core/types/core.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { ServiceDiscovery } from \"@webiny/api-core/features/serviceDiscovery/index.js\";\nimport { createStorageOperations as createUsersStorageOperations } from \"./adminUsers/index.js\";\nimport { createStorageOperations as createTenancyStorageOperations } from \"./tenancy/index.js\";\nimport { createStorageOperations as createSecurityStorageOperations } from \"./security/index.js\";\nimport { createStorageOperations as createKeyValueStorageOperations } from \"./keyValueStore/index.js\";\nimport { DdbServiceManifestLoader } from \"./serviceDiscovery/index.js\";\nimport type { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\n\ninterface CreateApiCoreDdbParams {\n documentClient: DynamoDBDocument;\n /**\n * The tenant the storage acts on: its tenant scope's. The tenant records and the key-value store\n * don't use it (the tenant registry is tenant-neutral, and the store is keyed by its own scope).\n */\n scopeTenant: ScopeTenant.Interface;\n}\n\nexport const createApiCoreDdb = ({\n documentClient,\n scopeTenant\n}: CreateApiCoreDdbParams): ApiCoreStorageOperations => {\n ServiceDiscovery.setLoader(new DdbServiceManifestLoader(documentClient));\n\n return {\n usersStorageOperations: createUsersStorageOperations({\n documentClient,\n scopeTenant\n }),\n tenancyStorageOperations: createTenancyStorageOperations({\n documentClient\n }),\n securityStorageOperations: createSecurityStorageOperations({\n documentClient,\n scopeTenant\n }),\n keyValueStorageOperations: createKeyValueStorageOperations({\n documentClient\n })\n };\n};\n"],"names":["createApiCoreDdb","documentClient","scopeTenant","ServiceDiscovery","DdbServiceManifestLoader","createUsersStorageOperations","createTenancyStorageOperations","createSecurityStorageOperations","createKeyValueStorageOperations"],"mappings":";;;;;;AAmBO,MAAMA,mBAAmB,CAAC,EAC7BC,cAAc,EACdC,WAAW,EACU;IACrBC,iBAAiB,SAAS,CAAC,IAAIC,yBAAyBH;IAExD,OAAO;QACH,wBAAwBI,wBAA6B;YACjDJ;YACAC;QACJ;QACA,0BAA0BI,iCAA+B;YACrDL;QACJ;QACA,2BAA2BM,mDAAgC;YACvDN;YACAC;QACJ;QACA,2BAA2BM,wDAAgC;YACvDP;QACJ;IACJ;AACJ"}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * from "./createApiCoreDdb.js";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
export { ApiCoreDdbFeature } from "./ApiCoreDdbFeature.js";
|
|
3
|
+
export { DdbServiceManifestLoader } from "./serviceDiscovery/index.js";
|