@webiny/api-core-ddb 0.0.0-unstable.0156a4c312
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ApiCoreDdbFeature.d.ts +12 -0
- package/ApiCoreDdbFeature.js +16 -0
- package/ApiCoreDdbFeature.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/adminUsers/definitions/entities.d.ts +3 -0
- package/adminUsers/definitions/entities.js +9 -0
- package/adminUsers/definitions/entities.js.map +1 -0
- package/adminUsers/definitions/types.d.ts +5 -0
- package/adminUsers/definitions/types.js +0 -0
- package/adminUsers/index.d.ts +2 -0
- package/adminUsers/index.js +150 -0
- package/adminUsers/index.js.map +1 -0
- package/adminUsers/types.d.ts +22 -0
- package/adminUsers/types.js +8 -0
- package/adminUsers/types.js.map +1 -0
- package/createApiCoreDdb.d.ts +7 -0
- package/createApiCoreDdb.js +26 -0
- package/createApiCoreDdb.js.map +1 -0
- package/index.d.ts +4 -0
- package/index.js +3 -0
- package/keyValueStore/KeyValueStoreDynamoTable.d.ts +39 -0
- package/keyValueStore/KeyValueStoreDynamoTable.js +43 -0
- package/keyValueStore/KeyValueStoreDynamoTable.js.map +1 -0
- package/keyValueStore/KeyValueStoreStorageOperations.d.ts +28 -0
- package/keyValueStore/KeyValueStoreStorageOperations.js +234 -0
- package/keyValueStore/KeyValueStoreStorageOperations.js.map +1 -0
- package/keyValueStore/index.d.ts +8 -0
- package/keyValueStore/index.js +5 -0
- package/keyValueStore/index.js.map +1 -0
- package/package.json +45 -0
- package/security/definitions/entities.d.ts +5 -0
- package/security/definitions/entities.js +23 -0
- package/security/definitions/entities.js.map +1 -0
- package/security/definitions/types.d.ts +14 -0
- package/security/definitions/types.js +0 -0
- package/security/index.d.ts +3 -0
- package/security/index.js +401 -0
- package/security/index.js.map +1 -0
- package/security/types.d.ts +10 -0
- package/security/types.js +9 -0
- package/security/types.js.map +1 -0
- package/serviceDiscovery/DdbServiceManifestLoader.d.ts +7 -0
- package/serviceDiscovery/DdbServiceManifestLoader.js +27 -0
- package/serviceDiscovery/DdbServiceManifestLoader.js.map +1 -0
- package/serviceDiscovery/index.d.ts +1 -0
- package/serviceDiscovery/index.js +1 -0
- package/tenancy/definitions/tenantEntity.d.ts +8 -0
- package/tenancy/definitions/tenantEntity.js +8 -0
- package/tenancy/definitions/tenantEntity.js.map +1 -0
- package/tenancy/definitions/types.d.ts +6 -0
- package/tenancy/definitions/types.js +0 -0
- package/tenancy/index.d.ts +2 -0
- package/tenancy/index.js +115 -0
- package/tenancy/index.js.map +1 -0
- package/tenancy/types.d.ts +10 -0
- package/tenancy/types.js +7 -0
- package/tenancy/types.js.map +1 -0
|
@@ -0,0 +1,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,16 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { ApiCoreStorageOperationsFactory } from "@webiny/api-core";
|
|
3
|
+
import { createApiCoreDdb } from "./createApiCoreDdb.js";
|
|
4
|
+
const ApiCoreDdbFeature = createFeature({
|
|
5
|
+
name: "ApiCoreDdb",
|
|
6
|
+
register (container, { documentClient }) {
|
|
7
|
+
container.registerInstance(ApiCoreStorageOperationsFactory, {
|
|
8
|
+
create: ()=>createApiCoreDdb({
|
|
9
|
+
documentClient
|
|
10
|
+
})
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
export { ApiCoreDdbFeature };
|
|
15
|
+
|
|
16
|
+
//# 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 } from \"@webiny/api-core\";\nimport { createApiCoreDdb } from \"./createApiCoreDdb.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: () => createApiCoreDdb({ documentClient })\n });\n }\n});\n"],"names":["ApiCoreDdbFeature","createFeature","container","documentClient","ApiCoreStorageOperationsFactory","createApiCoreDdb"],"mappings":";;;AAaO,MAAMA,oBAAoBC,cAAgC;IAC7D,MAAM;IACN,UAASC,SAAS,EAAE,EAAEC,cAAc,EAAE;QAClCD,UAAU,gBAAgB,CAACE,iCAAiC;YACxD,QAAQ,IAAMC,iBAAiB;oBAAEF;gBAAe;QACpD;IACJ;AACJ"}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @webiny/api-core-ddb
|
|
2
|
+
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
6
|
+
|
|
7
|
+
📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createStandardEntity } from "@webiny/db-dynamodb";
|
|
2
|
+
import { ENTITIES } from "../types.js";
|
|
3
|
+
const createUserEntity = (table)=>createStandardEntity({
|
|
4
|
+
name: ENTITIES.USERS,
|
|
5
|
+
table
|
|
6
|
+
});
|
|
7
|
+
export { createUserEntity };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=entities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IEntity, IStandardEntityAttributes } from "@webiny/db-dynamodb";
|
|
2
|
+
import type { AdminUser } from "@webiny/api-core/types/users.js";
|
|
3
|
+
export interface IAdminUserEntityAttributes extends IStandardEntityAttributes<AdminUser> {
|
|
4
|
+
}
|
|
5
|
+
export type IAdminUserEntity = IEntity<IAdminUserEntityAttributes>;
|
|
File without changes
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
import { createTable, sortItems } from "@webiny/db-dynamodb";
|
|
3
|
+
import { createUserEntity } from "./definitions/entities.js";
|
|
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
|
+
users: createUserEntity(table.table)
|
|
12
|
+
};
|
|
13
|
+
const createUserKeys = (user)=>({
|
|
14
|
+
PK: `T#${user.tenant}#ADMIN_USER#${user.id}`,
|
|
15
|
+
SK: "A"
|
|
16
|
+
});
|
|
17
|
+
const createUserGSIKeys = (user)=>({
|
|
18
|
+
GSI1_PK: `T#${user.tenant}#ADMIN_USERS`,
|
|
19
|
+
GSI1_SK: user.email,
|
|
20
|
+
GSI_TENANT: user.tenant
|
|
21
|
+
});
|
|
22
|
+
const storageOperations = {
|
|
23
|
+
getTable () {
|
|
24
|
+
return table;
|
|
25
|
+
},
|
|
26
|
+
getEntities () {
|
|
27
|
+
return entities;
|
|
28
|
+
},
|
|
29
|
+
async createUser ({ user }) {
|
|
30
|
+
const keys = {
|
|
31
|
+
...createUserKeys(user),
|
|
32
|
+
...createUserGSIKeys(user)
|
|
33
|
+
};
|
|
34
|
+
try {
|
|
35
|
+
await entities.users.put({
|
|
36
|
+
...keys,
|
|
37
|
+
TYPE: "adminUsers.user",
|
|
38
|
+
data: user
|
|
39
|
+
});
|
|
40
|
+
return user;
|
|
41
|
+
} catch (err) {
|
|
42
|
+
throw error.from(err, {
|
|
43
|
+
message: "Could not create admin user.",
|
|
44
|
+
code: "CREATE_ADMIN_USER_ERROR",
|
|
45
|
+
data: {
|
|
46
|
+
keys
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
async deleteUser ({ user }) {
|
|
52
|
+
const keys = createUserKeys(user);
|
|
53
|
+
try {
|
|
54
|
+
await entities.users.delete(keys);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
throw error.from(err, {
|
|
57
|
+
message: "Could not delete group.",
|
|
58
|
+
code: "CREATE_DELETE_ERROR",
|
|
59
|
+
data: {
|
|
60
|
+
keys,
|
|
61
|
+
user
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
async getUser (params) {
|
|
67
|
+
const { where: { tenant, id, email } } = params;
|
|
68
|
+
try {
|
|
69
|
+
if (id) {
|
|
70
|
+
const response = await entities.users.get(createUserKeys({
|
|
71
|
+
tenant,
|
|
72
|
+
id
|
|
73
|
+
}));
|
|
74
|
+
return response?.data || null;
|
|
75
|
+
}
|
|
76
|
+
const response = await entities.users.queryOne({
|
|
77
|
+
partitionKey: `T#${tenant}#ADMIN_USERS`,
|
|
78
|
+
options: {
|
|
79
|
+
index: "GSI1",
|
|
80
|
+
eq: email
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return response?.data || null;
|
|
84
|
+
} catch (err) {
|
|
85
|
+
throw error.from(err, {
|
|
86
|
+
message: "Could not load user.",
|
|
87
|
+
code: "GET_ADMIN_USERS_ERROR",
|
|
88
|
+
data: {
|
|
89
|
+
id,
|
|
90
|
+
email
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
async listUsers ({ where, sort }) {
|
|
96
|
+
let items;
|
|
97
|
+
try {
|
|
98
|
+
const ddbItems = await entities.users.queryAll({
|
|
99
|
+
partitionKey: `T#${where.tenant}#ADMIN_USERS`,
|
|
100
|
+
options: {
|
|
101
|
+
index: "GSI1"
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
items = ddbItems.map((item)=>item.data);
|
|
105
|
+
} catch (err) {
|
|
106
|
+
throw error.from(err, {
|
|
107
|
+
message: "Could not list users.",
|
|
108
|
+
code: "LIST_ADMIN_USERS_ERROR"
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const { id_in, teams_in } = where;
|
|
112
|
+
const filtered = items.filter((item)=>{
|
|
113
|
+
if (Array.isArray(id_in) && !id_in.includes(item.id)) return false;
|
|
114
|
+
if (Array.isArray(teams_in)) return (item.teams || []).some((team)=>teams_in.includes(team));
|
|
115
|
+
return true;
|
|
116
|
+
});
|
|
117
|
+
return sortItems({
|
|
118
|
+
items: filtered,
|
|
119
|
+
sort
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
async updateUser ({ user }) {
|
|
123
|
+
const keys = {
|
|
124
|
+
...createUserKeys(user),
|
|
125
|
+
...createUserGSIKeys(user)
|
|
126
|
+
};
|
|
127
|
+
try {
|
|
128
|
+
await entities.users.put({
|
|
129
|
+
...keys,
|
|
130
|
+
TYPE: "adminUsers.user",
|
|
131
|
+
data: user
|
|
132
|
+
});
|
|
133
|
+
return user;
|
|
134
|
+
} catch (err) {
|
|
135
|
+
throw error.from(err, {
|
|
136
|
+
message: "Could not update user.",
|
|
137
|
+
code: "UPDATE_ADMIN_USER_ERROR",
|
|
138
|
+
data: {
|
|
139
|
+
keys,
|
|
140
|
+
user
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
return storageOperations;
|
|
147
|
+
};
|
|
148
|
+
export { createStorageOperations };
|
|
149
|
+
|
|
150
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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 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 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({ 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","table","createTable","process","entities","createUserEntity","createUserKeys","user","createUserGSIKeys","storageOperations","keys","err","WebinyError","tenant","id","email","response","where","sort","items","ddbItems","item","id_in","teams_in","filtered","Array","team","sortItems"],"mappings":"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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
+
import type { AdminUsersStorageOperations as BaseAdminUsersStorageOperations } from "@webiny/api-core/types/users.js";
|
|
3
|
+
import type { IAdminUserEntity } from "../adminUsers/definitions/types.js";
|
|
4
|
+
import { ITable } from "@webiny/db-dynamodb";
|
|
5
|
+
export declare enum ENTITIES {
|
|
6
|
+
SYSTEM = "AdminUsers.System",
|
|
7
|
+
USERS = "AdminUsers.User"
|
|
8
|
+
}
|
|
9
|
+
export interface ICreateAdminUsersStorageOperationsParams {
|
|
10
|
+
documentClient: DynamoDBDocument;
|
|
11
|
+
table?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface CreateAdminUsersStorageOperations {
|
|
14
|
+
(params: ICreateAdminUsersStorageOperationsParams): AdminUsersStorageOperations;
|
|
15
|
+
}
|
|
16
|
+
export interface IAdminUsersGetEntitiesResponse {
|
|
17
|
+
users: IAdminUserEntity;
|
|
18
|
+
}
|
|
19
|
+
export interface AdminUsersStorageOperations extends BaseAdminUsersStorageOperations {
|
|
20
|
+
getTable(): ITable;
|
|
21
|
+
getEntities(): IAdminUsersGetEntitiesResponse;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
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\";\n\nexport enum ENTITIES {\n SYSTEM = \"AdminUsers.System\",\n USERS = \"AdminUsers.User\"\n}\n\nexport interface ICreateAdminUsersStorageOperationsParams {\n documentClient: DynamoDBDocument;\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":"AAKO,IAAKA,iBAAQA,WAAAA,GAAAA,SAARA,QAAQ;;;WAARA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ApiCoreStorageOperations } from "@webiny/api-core/types/core.js";
|
|
2
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
3
|
+
interface CreateApiCoreDdbParams {
|
|
4
|
+
documentClient: DynamoDBDocument;
|
|
5
|
+
}
|
|
6
|
+
export declare const createApiCoreDdb: ({ documentClient }: CreateApiCoreDdbParams) => ApiCoreStorageOperations;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
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 })=>{
|
|
8
|
+
ServiceDiscovery.setLoader(new DdbServiceManifestLoader(documentClient));
|
|
9
|
+
return {
|
|
10
|
+
usersStorageOperations: createStorageOperations({
|
|
11
|
+
documentClient
|
|
12
|
+
}),
|
|
13
|
+
tenancyStorageOperations: index_js_createStorageOperations({
|
|
14
|
+
documentClient
|
|
15
|
+
}),
|
|
16
|
+
securityStorageOperations: external_security_index_js_createStorageOperations({
|
|
17
|
+
documentClient
|
|
18
|
+
}),
|
|
19
|
+
keyValueStorageOperations: external_keyValueStore_index_js_createStorageOperations({
|
|
20
|
+
documentClient
|
|
21
|
+
})
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export { createApiCoreDdb };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=createApiCoreDdb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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\";\n\ninterface CreateApiCoreDdbParams {\n documentClient: DynamoDBDocument;\n}\n\nexport const createApiCoreDdb = ({\n documentClient\n}: CreateApiCoreDdbParams): ApiCoreStorageOperations => {\n ServiceDiscovery.setLoader(new DdbServiceManifestLoader(documentClient));\n\n return {\n usersStorageOperations: createUsersStorageOperations({\n documentClient\n }),\n tenancyStorageOperations: createTenancyStorageOperations({\n documentClient\n }),\n securityStorageOperations: createSecurityStorageOperations({\n documentClient\n }),\n keyValueStorageOperations: createKeyValueStorageOperations({\n documentClient\n })\n };\n};\n"],"names":["createApiCoreDdb","documentClient","ServiceDiscovery","DdbServiceManifestLoader","createUsersStorageOperations","createTenancyStorageOperations","createSecurityStorageOperations","createKeyValueStorageOperations"],"mappings":";;;;;;AAaO,MAAMA,mBAAmB,CAAC,EAC7BC,cAAc,EACO;IACrBC,iBAAiB,SAAS,CAAC,IAAIC,yBAAyBF;IAExD,OAAO;QACH,wBAAwBG,wBAA6B;YACjDH;QACJ;QACA,0BAA0BI,iCAA+B;YACrDJ;QACJ;QACA,2BAA2BK,mDAAgC;YACvDL;QACJ;QACA,2BAA2BM,wDAAgC;YACvDN;QACJ;IACJ;AACJ"}
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
2
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
3
|
+
interface CreateKeysParams {
|
|
4
|
+
scopedKey: string;
|
|
5
|
+
}
|
|
6
|
+
interface CreateListKeysParams {
|
|
7
|
+
key: string;
|
|
8
|
+
scope: string;
|
|
9
|
+
collection: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class KeyValueStoreDynamoTable<T extends GenericRecord> {
|
|
12
|
+
private readonly entity;
|
|
13
|
+
constructor(documentClient: DynamoDBDocument);
|
|
14
|
+
createKeys({ scopedKey }: CreateKeysParams): {
|
|
15
|
+
PK: string;
|
|
16
|
+
SK: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* GSI1 keys for a member of a collection. Each collection is its own GSI1 partition, sorted by
|
|
20
|
+
* key, so `list` is one Query on it. A record outside every collection gets no GSI1 keys at all
|
|
21
|
+
* and costs the index nothing. The primary key gives each record its own partition, which a
|
|
22
|
+
* Query cannot list.
|
|
23
|
+
*/
|
|
24
|
+
createListKeys({ key, scope, collection }: CreateListKeysParams): {
|
|
25
|
+
GSI1_PK: string;
|
|
26
|
+
GSI1_SK: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The scope's length goes in front so the key reads back one way only: without it, scope `a#b`
|
|
30
|
+
* with collection `c` and scope `a` with collection `b#c` would share a partition, and a list
|
|
31
|
+
* in one scope would return another scope's records.
|
|
32
|
+
*/
|
|
33
|
+
createListPartitionKey(scope: string, collection: string): string;
|
|
34
|
+
/** Prefixed because DynamoDB rejects an empty string as an index key, and `""` is a valid key. */
|
|
35
|
+
createListSortKey(key: string): string;
|
|
36
|
+
parseListSortKey(sortKey: string): string;
|
|
37
|
+
getEntity(): import("@webiny/db-dynamodb").IEntity<import("@webiny/db-dynamodb").IGlobalEntityAttributes<T>>;
|
|
38
|
+
}
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createGlobalEntity, createTable, globalEntityAttributes } from "@webiny/db-dynamodb";
|
|
2
|
+
class KeyValueStoreDynamoTable {
|
|
3
|
+
constructor(documentClient){
|
|
4
|
+
const table = createTable({
|
|
5
|
+
name: process.env.DB_TABLE,
|
|
6
|
+
documentClient
|
|
7
|
+
});
|
|
8
|
+
this.entity = createGlobalEntity({
|
|
9
|
+
name: "KeyValueStore",
|
|
10
|
+
table: table.table,
|
|
11
|
+
attributes: {
|
|
12
|
+
...globalEntityAttributes
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
createKeys({ scopedKey }) {
|
|
17
|
+
return {
|
|
18
|
+
PK: `KV#${scopedKey}`,
|
|
19
|
+
SK: "A"
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
createListKeys({ key, scope, collection }) {
|
|
23
|
+
return {
|
|
24
|
+
GSI1_PK: this.createListPartitionKey(scope, collection),
|
|
25
|
+
GSI1_SK: this.createListSortKey(key)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
createListPartitionKey(scope, collection) {
|
|
29
|
+
return `KV#COL#${scope.length}#${scope}#${collection}`;
|
|
30
|
+
}
|
|
31
|
+
createListSortKey(key) {
|
|
32
|
+
return `K#${key}`;
|
|
33
|
+
}
|
|
34
|
+
parseListSortKey(sortKey) {
|
|
35
|
+
return sortKey.slice(2);
|
|
36
|
+
}
|
|
37
|
+
getEntity() {
|
|
38
|
+
return this.entity;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export { KeyValueStoreDynamoTable };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=KeyValueStoreDynamoTable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyValueStore/KeyValueStoreDynamoTable.js","sources":["../../src/keyValueStore/KeyValueStoreDynamoTable.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { createGlobalEntity, createTable, globalEntityAttributes } from \"@webiny/db-dynamodb\";\n\ninterface CreateKeysParams {\n scopedKey: string;\n}\n\ninterface CreateListKeysParams {\n key: string;\n scope: string;\n collection: string;\n}\n\nexport class KeyValueStoreDynamoTable<T extends GenericRecord> {\n private readonly entity;\n\n constructor(documentClient: DynamoDBDocument) {\n const table = createTable({\n name: process.env.DB_TABLE as string,\n documentClient\n });\n this.entity = createGlobalEntity<T>({\n name: \"KeyValueStore\",\n table: table.table,\n attributes: {\n ...globalEntityAttributes\n }\n });\n }\n\n createKeys({ scopedKey }: CreateKeysParams) {\n return {\n PK: `KV#${scopedKey}`,\n SK: `A`\n };\n }\n\n /**\n * GSI1 keys for a member of a collection. Each collection is its own GSI1 partition, sorted by\n * key, so `list` is one Query on it. A record outside every collection gets no GSI1 keys at all\n * and costs the index nothing. The primary key gives each record its own partition, which a\n * Query cannot list.\n */\n createListKeys({ key, scope, collection }: CreateListKeysParams) {\n return {\n GSI1_PK: this.createListPartitionKey(scope, collection),\n GSI1_SK: this.createListSortKey(key)\n };\n }\n\n /**\n * The scope's length goes in front so the key reads back one way only: without it, scope `a#b`\n * with collection `c` and scope `a` with collection `b#c` would share a partition, and a list\n * in one scope would return another scope's records.\n */\n createListPartitionKey(scope: string, collection: string) {\n return `KV#COL#${scope.length}#${scope}#${collection}`;\n }\n\n /** Prefixed because DynamoDB rejects an empty string as an index key, and `\"\"` is a valid key. */\n createListSortKey(key: string) {\n return `K#${key}`;\n }\n\n parseListSortKey(sortKey: string) {\n return sortKey.slice(\"K#\".length);\n }\n\n getEntity() {\n return this.entity;\n }\n}\n"],"names":["KeyValueStoreDynamoTable","documentClient","table","createTable","process","createGlobalEntity","globalEntityAttributes","scopedKey","key","scope","collection","sortKey"],"mappings":";AAcO,MAAMA;IAGT,YAAYC,cAAgC,CAAE;QAC1C,MAAMC,QAAQC,YAAY;YACtB,MAAMC,QAAQ,GAAG,CAAC,QAAQ;YAC1BH;QACJ;QACA,IAAI,CAAC,MAAM,GAAGI,mBAAsB;YAChC,MAAM;YACN,OAAOH,MAAM,KAAK;YAClB,YAAY;gBACR,GAAGI,sBAAsB;YAC7B;QACJ;IACJ;IAEA,WAAW,EAAEC,SAAS,EAAoB,EAAE;QACxC,OAAO;YACH,IAAI,CAAC,GAAG,EAAEA,WAAW;YACrB,IAAI;QACR;IACJ;IAQA,eAAe,EAAEC,GAAG,EAAEC,KAAK,EAAEC,UAAU,EAAwB,EAAE;QAC7D,OAAO;YACH,SAAS,IAAI,CAAC,sBAAsB,CAACD,OAAOC;YAC5C,SAAS,IAAI,CAAC,iBAAiB,CAACF;QACpC;IACJ;IAOA,uBAAuBC,KAAa,EAAEC,UAAkB,EAAE;QACtD,OAAO,CAAC,OAAO,EAAED,MAAM,MAAM,CAAC,CAAC,EAAEA,MAAM,CAAC,EAAEC,YAAY;IAC1D;IAGA,kBAAkBF,GAAW,EAAE;QAC3B,OAAO,CAAC,EAAE,EAAEA,KAAK;IACrB;IAEA,iBAAiBG,OAAe,EAAE;QAC9B,OAAOA,QAAQ,KAAK,CAAC;IACzB;IAEA,YAAY;QACR,OAAO,IAAI,CAAC,MAAM;IACtB;AACJ"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
+
import type { IKeyValueStorageListParams } from "@webiny/api-core/features/keyValueStore/abstractions.js";
|
|
3
|
+
import type { IKeyValueStorageListResult } from "@webiny/api-core/features/keyValueStore/abstractions.js";
|
|
4
|
+
import type { IKeyValueStoreSetOptions } from "@webiny/api-core/features/keyValueStore/abstractions.js";
|
|
5
|
+
import type { IKeyValueDeleteOptions } from "@webiny/api-core/features/keyValueStore/abstractions.js";
|
|
6
|
+
interface KeyValueRecord {
|
|
7
|
+
key: string;
|
|
8
|
+
value: any;
|
|
9
|
+
scope: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class KeyValueStoreStorageOperations {
|
|
12
|
+
private readonly table;
|
|
13
|
+
private readonly entity;
|
|
14
|
+
private readonly client;
|
|
15
|
+
constructor(dynamoDbClient: DynamoDBDocument);
|
|
16
|
+
private createScopedKey;
|
|
17
|
+
get(key: string, scope: string): Promise<KeyValueRecord | null>;
|
|
18
|
+
set(key: string, value: any, scope: string, options?: IKeyValueStoreSetOptions): Promise<boolean>;
|
|
19
|
+
delete(key: string, scope: string, options?: IKeyValueDeleteOptions): Promise<boolean>;
|
|
20
|
+
list(params: IKeyValueStorageListParams): Promise<IKeyValueStorageListResult>;
|
|
21
|
+
/**
|
|
22
|
+
* A GSI query resumes from the full key of an item: the table's own PK and SK as well as the
|
|
23
|
+
* index's. All four follow from the scope, collection and key, so the item does not have to
|
|
24
|
+
* exist any more.
|
|
25
|
+
*/
|
|
26
|
+
private createStartKey;
|
|
27
|
+
}
|
|
28
|
+
export {};
|