@webiny/api-core-ddb 6.3.0-beta.4 → 6.4.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/adminUsers/definitions/entities.js +5 -6
  2. package/adminUsers/definitions/entities.js.map +1 -1
  3. package/adminUsers/definitions/types.js +0 -3
  4. package/adminUsers/index.js +135 -156
  5. package/adminUsers/index.js.map +1 -1
  6. package/adminUsers/types.js +5 -4
  7. package/adminUsers/types.js.map +1 -1
  8. package/createApiCoreDdb.js +19 -22
  9. package/createApiCoreDdb.js.map +1 -1
  10. package/index.js +0 -2
  11. package/keyValueStore/KeyValueStoreDynamoTable.js +24 -25
  12. package/keyValueStore/KeyValueStoreDynamoTable.js.map +1 -1
  13. package/keyValueStore/KeyValueStoreStorageOperations.d.ts +2 -1
  14. package/keyValueStore/KeyValueStoreStorageOperations.js +72 -72
  15. package/keyValueStore/KeyValueStoreStorageOperations.js.map +1 -1
  16. package/keyValueStore/index.js +2 -3
  17. package/keyValueStore/index.js.map +1 -1
  18. package/package.json +9 -9
  19. package/security/definitions/entities.js +19 -24
  20. package/security/definitions/entities.js.map +1 -1
  21. package/security/definitions/types.js +0 -3
  22. package/security/index.js +389 -464
  23. package/security/index.js.map +1 -1
  24. package/security/types.js +6 -5
  25. package/security/types.js.map +1 -1
  26. package/tenancy/definitions/tenantEntity.js +5 -9
  27. package/tenancy/definitions/tenantEntity.js.map +1 -1
  28. package/tenancy/definitions/types.js +0 -3
  29. package/tenancy/index.js +107 -127
  30. package/tenancy/index.js.map +1 -1
  31. package/tenancy/types.js +4 -3
  32. package/tenancy/types.js.map +1 -1
  33. package/adminUsers/definitions/types.js.map +0 -1
  34. package/index.js.map +0 -1
  35. package/security/definitions/types.js.map +0 -1
  36. package/tenancy/definitions/types.js.map +0 -1
@@ -1,10 +1,9 @@
1
1
  import { createStandardEntity } from "@webiny/db-dynamodb";
2
2
  import { ENTITIES } from "../types.js";
3
- export const createUserEntity = table => {
4
- return createStandardEntity({
5
- name: ENTITIES.USERS,
6
- table
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,"names":["createStandardEntity","ENTITIES","createUserEntity","table","name","USERS"],"sources":["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"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,qBAAqB;AAE1D,SAASC,QAAQ;AAIjB,OAAO,MAAMC,gBAAgB,GAAIC,KAAoC,IAAuB;EACxF,OAAOH,oBAAoB,CAAY;IACnCI,IAAI,EAAEH,QAAQ,CAACI,KAAK;IACpBF;EACJ,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
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"}
@@ -1,3 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=types.js.map
@@ -1,165 +1,144 @@
1
- import WebinyError from "@webiny/error";
1
+ import error from "@webiny/error";
2
2
  import { createTable, sortItems } from "@webiny/db-dynamodb";
3
3
  import { createUserEntity } from "./definitions/entities.js";
4
- export const createStorageOperations = params => {
5
- const {
6
- table: tableName,
7
- documentClient
8
- } = params;
9
- const table = createTable({
10
- name: tableName || process.env.DB_TABLE,
11
- documentClient
12
- });
13
- const entities = {
14
- 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
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)
25
12
  };
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
13
+ const createUserKeys = (user)=>({
14
+ PK: `T#${user.tenant}#ADMIN_USER#${user.id}`,
15
+ SK: "A"
46
16
  });
47
- return user;
48
- } catch (err) {
49
- throw WebinyError.from(err, {
50
- message: "Could not create admin user.",
51
- code: "CREATE_ADMIN_USER_ERROR",
52
- data: {
53
- keys
54
- }
17
+ const createUserGSIKeys = (user)=>({
18
+ GSI1_PK: `T#${user.tenant}#ADMIN_USERS`,
19
+ GSI1_SK: user.email,
20
+ GSI_TENANT: user.tenant
55
21
  });
56
- }
57
- },
58
- async deleteUser({
59
- user
60
- }) {
61
- const keys = createUserKeys(user);
62
- try {
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
- }
72
- });
73
- }
74
- },
75
- async getUser(params) {
76
- const {
77
- where: {
78
- tenant,
79
- id,
80
- email
81
- }
82
- } = params;
83
- try {
84
- if (id) {
85
- const response = await entities.users.get(createUserKeys({
86
- tenant,
87
- id
88
- }));
89
- return response?.data || null;
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
+ return sortItems({
112
+ items,
113
+ sort
114
+ });
115
+ },
116
+ async updateUser ({ user }) {
117
+ const keys = {
118
+ ...createUserKeys(user),
119
+ ...createUserGSIKeys(user)
120
+ };
121
+ try {
122
+ await entities.users.put({
123
+ ...keys,
124
+ TYPE: "adminUsers.user",
125
+ data: user
126
+ });
127
+ return user;
128
+ } catch (err) {
129
+ throw error.from(err, {
130
+ message: "Could not update user.",
131
+ code: "UPDATE_ADMIN_USER_ERROR",
132
+ data: {
133
+ keys,
134
+ user
135
+ }
136
+ });
137
+ }
90
138
  }
91
- const response = await entities.users.queryOne({
92
- partitionKey: `T#${tenant}#ADMIN_USERS`,
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;
139
+ };
140
+ return storageOperations;
163
141
  };
142
+ export { createStorageOperations };
164
143
 
165
144
  //# sourceMappingURL=index.js.map
@@ -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,MAAM,eAAe;AACvC,SAASC,WAAW,EAAkCC,SAAS,QAAQ,qBAAqB;AAC5F,SAASC,gBAAgB;AAOzB,OAAO,MAAMC,uBAA0D,GAAGC,MAAM,IAAI;EAChF,MAAM;IAAEC,KAAK,EAAEC,SAAS;IAAEC;EAAe,CAAC,GAAGH,MAAM;EAEnD,MAAMC,KAAK,GAAGL,WAAW,CAAC;IACtBQ,IAAI,EAAEF,SAAS,IAAKG,OAAO,CAACC,GAAG,CAACC,QAAmB;IACnDJ;EACJ,CAAC,CAAC;EAEF,MAAMK,QAAQ,GAAG;IACbC,KAAK,EAAEX,gBAAgB,CAACG,KAAK,CAACA,KAAK;EACvC,CAAC;EAED,MAAMS,cAAc,GAAIC,IAAsC,KAAM;IAChEC,EAAE,EAAE,KAAKD,IAAI,CAACE,MAAM,eAAeF,IAAI,CAACG,EAAE,EAAE;IAC5CC,EAAE,EAAE;EACR,CAAC,CAAC;EAEF,MAAMC,iBAAiB,GAAIL,IAAe,IAAK;IAC3C,OAAO;MACHM,OAAO,EAAE,KAAKN,IAAI,CAACE,MAAM,cAAc;MACvCK,OAAO,EAAEP,IAAI,CAACQ,KAAK;MACnBC,UAAU,EAAET,IAAI,CAACE;IACrB,CAAC;EACL,CAAC;EAED,MAAMQ,iB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EA,OAAOnC,SAAS,CAAC;QAAEiD,KAAK;QAAED;MAAK,CAAC,CAAC;IACrC,CAAC;IACD,MAAMM,UAAUA,CAAC;MAAExC;IAAK,CAAC,EAAE;MACvB,MAAMc,IAAI,GAAG;QACT,GAAGf,cAAc,CAACC,IAAI,CAAC;QACvB,GAAGK,iBAAiB,CAACL,IAAI;MAC7B,CAAC;MAED,IAAI;QACA,MAAMH,QAAQ,CAACC,KAAK,CAACiB,GAAG,CAAC;UACrB,GAAGD,IAAI;UACPE,IAAI,EAAE,iBAAiB;UACvBC,IAAI,EAAEjB;QACV,CAAC,CAAC;QACF,OAAOA,IAAI;MACf,CAAC,CAAC,OAAOkB,GAAG,EAAE;QACV,MAAMlC,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 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"],"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","sortItems"],"mappings":";;;AAUO,MAAMA,0BAA6DC,CAAAA;IACtE,MAAM,EAAE,OAAOC,SAAS,EAAEC,cAAc,EAAE,GAAGF;IAE7C,MAAMG,QAAQC,YAAY;QACtB,MAAMH,aAAcI,QAAQ,GAAG,CAAC,QAAQ;QACxCH;IACJ;IAEA,MAAMI,WAAW;QACb,OAAOC,iBAAiBJ,MAAM,KAAK;IACvC;IAEA,MAAMK,iBAAiB,CAACC,OAA4C;YAChE,IAAI,CAAC,EAAE,EAAEA,KAAK,MAAM,CAAC,YAAY,EAAEA,KAAK,EAAE,EAAE;YAC5C,IAAI;QACR;IAEA,MAAMC,oBAAoB,CAACD,OAChB;YACH,SAAS,CAAC,EAAE,EAAEA,KAAK,MAAM,CAAC,YAAY,CAAC;YACvC,SAASA,KAAK,KAAK;YACnB,YAAYA,KAAK,MAAM;QAC3B;IAGJ,MAAME,oBAAiD;QACnD;YACI,OAAOR;QACX;QACA;YACI,OAAOG;QACX;QACA,MAAM,YAAW,EAAEG,IAAI,EAAE;YACrB,MAAMG,OAAO;gBACT,GAAGJ,eAAeC,KAAK;gBACvB,GAAGC,kBAAkBD,KAAK;YAC9B;YAEA,IAAI;gBACA,MAAMH,SAAS,KAAK,CAAC,G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,CAAC,EAAE,EAAEa,MAAM,MAAM,CAAC,YAAY,CAAC;oBAC7C,SAAS;wBACL,OAAO;oBACX;gBACJ;gBACAE,QAAQC,SAAS,GAAG,CAACC,CAAAA,OACVA,KAAK,IAAI;YAExB,EAAE,OAAOV,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;gBACV;YACJ;YAEA,OAAOW,UAAU;gBAAEH;gBAAOD;YAAK;QACnC;QACA,MAAM,YAAW,EAAEX,IAAI,EAAE;YACrB,MAAMG,OAAO;gBACT,GAAGJ,eAAeC,KAAK;gBACvB,GAAGC,kBAAkBD,KAAK;YAC9B;YAEA,IAAI;gBACA,MAAMH,SAAS,KAAK,CAAC,GAAG,CAAC;oBACrB,GAAGM,IAAI;oBACP,MAAM;oBACN,MAAMH;gBACV;gBACA,OAAOA;YACX,EAAE,OAAOI,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAED;wBAAMH;oBAAK;gBACvB;YACJ;QACJ;IACJ;IAEA,OAAOE;AACX"}
@@ -1,7 +1,8 @@
1
- export let ENTITIES = /*#__PURE__*/function (ENTITIES) {
2
- ENTITIES["SYSTEM"] = "AdminUsers.System";
3
- ENTITIES["USERS"] = "AdminUsers.User";
4
- return ENTITIES;
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
@@ -1 +1 @@
1
- {"version":3,"names":["ENTITIES"],"sources":["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"],"mappings":"AAKA,WAAYA,QAAQ,0BAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAAA,OAARA,QAAQ;AAAA","ignoreList":[]}
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"}
@@ -1,24 +1,21 @@
1
- import { createStorageOperations as createUsersStorageOperations } from "./adminUsers/index.js";
2
- import { createStorageOperations as createTenancyStorageOperations } from "./tenancy/index.js";
3
- import { createStorageOperations as createSecurityStorageOperations } from "./security/index.js";
4
- import { createStorageOperations as createKeyValueStorageOperations } from "./keyValueStore/index.js";
5
- export const createApiCoreDdb = ({
6
- documentClient
7
- }) => {
8
- return {
9
- usersStorageOperations: createUsersStorageOperations({
10
- documentClient
11
- }),
12
- tenancyStorageOperations: createTenancyStorageOperations({
13
- documentClient
14
- }),
15
- securityStorageOperations: createSecurityStorageOperations({
16
- documentClient
17
- }),
18
- keyValueStorageOperations: createKeyValueStorageOperations({
19
- documentClient
20
- })
21
- };
22
- };
1
+ import { createStorageOperations } from "./adminUsers/index.js";
2
+ import { createStorageOperations as index_js_createStorageOperations } from "./tenancy/index.js";
3
+ import { createStorageOperations as external_security_index_js_createStorageOperations } from "./security/index.js";
4
+ import { createStorageOperations as external_keyValueStore_index_js_createStorageOperations } from "./keyValueStore/index.js";
5
+ const createApiCoreDdb = ({ documentClient })=>({
6
+ usersStorageOperations: createStorageOperations({
7
+ documentClient
8
+ }),
9
+ tenancyStorageOperations: index_js_createStorageOperations({
10
+ documentClient
11
+ }),
12
+ securityStorageOperations: external_security_index_js_createStorageOperations({
13
+ documentClient
14
+ }),
15
+ keyValueStorageOperations: external_keyValueStore_index_js_createStorageOperations({
16
+ documentClient
17
+ })
18
+ });
19
+ export { createApiCoreDdb };
23
20
 
24
21
  //# sourceMappingURL=createApiCoreDdb.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createStorageOperations","createUsersStorageOperations","createTenancyStorageOperations","createSecurityStorageOperations","createKeyValueStorageOperations","createApiCoreDdb","documentClient","usersStorageOperations","tenancyStorageOperations","securityStorageOperations","keyValueStorageOperations"],"sources":["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 { 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\";\n\ninterface CreateApiCoreDdbParams {\n documentClient: DynamoDBDocument;\n}\n\nexport const createApiCoreDdb = ({\n documentClient\n}: CreateApiCoreDdbParams): ApiCoreStorageOperations => {\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"],"mappings":"AAEA,SAASA,uBAAuB,IAAIC,4BAA4B;AAChE,SAASD,uBAAuB,IAAIE,8BAA8B;AAClE,SAASF,uBAAuB,IAAIG,+BAA+B;AACnE,SAASH,uBAAuB,IAAII,+BAA+B;AAMnE,OAAO,MAAMC,gBAAgB,GAAGA,CAAC;EAC7BC;AACoB,CAAC,KAA+B;EACpD,OAAO;IACHC,sBAAsB,EAAEN,4BAA4B,CAAC;MACjDK;IACJ,CAAC,CAAC;IACFE,wBAAwB,EAAEN,8BAA8B,CAAC;MACrDI;IACJ,CAAC,CAAC;IACFG,yBAAyB,EAAEN,+BAA+B,CAAC;MACvDG;IACJ,CAAC,CAAC;IACFI,yBAAyB,EAAEN,+BAA+B,CAAC;MACvDE;IACJ,CAAC;EACL,CAAC;AACL,CAAC","ignoreList":[]}
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 { 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\";\n\ninterface CreateApiCoreDdbParams {\n documentClient: DynamoDBDocument;\n}\n\nexport const createApiCoreDdb = ({\n documentClient\n}: CreateApiCoreDdbParams): ApiCoreStorageOperations => {\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","createUsersStorageOperations","createTenancyStorageOperations","createSecurityStorageOperations","createKeyValueStorageOperations"],"mappings":";;;;AAWO,MAAMA,mBAAmB,CAAC,EAC7BC,cAAc,EACO,GACd;QACH,wBAAwBC,wBAA6B;YACjDD;QACJ;QACA,0BAA0BE,iCAA+B;YACrDF;QACJ;QACA,2BAA2BG,mDAAgC;YACvDH;QACJ;QACA,2BAA2BI,wDAAgC;YACvDJ;QACJ;IACJ"}
package/index.js CHANGED
@@ -1,3 +1 @@
1
1
  export * from "./createApiCoreDdb.js";
2
-
3
- //# sourceMappingURL=index.js.map
@@ -1,29 +1,28 @@
1
1
  import { createGlobalEntity, createTable, globalEntityAttributes } from "@webiny/db-dynamodb";
2
- export 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({
17
- scopedKey
18
- }) {
19
- return {
20
- PK: `KV#${scopedKey}`,
21
- SK: `A`
22
- };
23
- }
24
- getEntity() {
25
- return this.entity;
26
- }
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
+ getEntity() {
23
+ return this.entity;
24
+ }
27
25
  }
26
+ export { KeyValueStoreDynamoTable };
28
27
 
29
28
  //# sourceMappingURL=KeyValueStoreDynamoTable.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createGlobalEntity","createTable","globalEntityAttributes","KeyValueStoreDynamoTable","constructor","documentClient","table","name","process","env","DB_TABLE","entity","attributes","createKeys","scopedKey","PK","SK","getEntity"],"sources":["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\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 getEntity() {\n return this.entity;\n }\n}\n"],"mappings":"AAEA,SAASA,kBAAkB,EAAEC,WAAW,EAAEC,sBAAsB,QAAQ,qBAAqB;AAM7F,OAAO,MAAMC,wBAAwB,CAA0B;EAG3DC,WAAWA,CAACC,cAAgC,EAAE;IAC1C,MAAMC,KAAK,GAAGL,WAAW,CAAC;MACtBM,IAAI,EAAEC,OAAO,CAACC,GAAG,CAACC,QAAkB;MACpCL;IACJ,CAAC,CAAC;IACF,IAAI,CAACM,MAAM,GAAGX,kBAAkB,CAAI;MAChCO,IAAI,EAAE,eAAe;MACrBD,KAAK,EAAEA,KAAK,CAACA,KAAK;MAClBM,UAAU,EAAE;QACR,GAAGV;MACP;IACJ,CAAC,CAAC;EACN;EAEAW,UAAUA,CAAC;IAAEC;EAA4B,CAAC,EAAE;IACxC,OAAO;MACHC,EAAE,EAAE,MAAMD,SAAS,EAAE;MACrBE,EAAE,EAAE;IACR,CAAC;EACL;EAEAC,SAASA,CAAA,EAAG;IACR,OAAO,IAAI,CAACN,MAAM;EACtB;AACJ","ignoreList":[]}
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\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 getEntity() {\n return this.entity;\n }\n}\n"],"names":["KeyValueStoreDynamoTable","documentClient","table","createTable","process","createGlobalEntity","globalEntityAttributes","scopedKey"],"mappings":";AAQO,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;IAEA,YAAY;QACR,OAAO,IAAI,CAAC,MAAM;IACtB;AACJ"}
@@ -1,4 +1,5 @@
1
1
  import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
2
+ import type { IKeyValueStoreSetOptions } from "@webiny/api-core/features/keyValueStore/abstractions.js";
2
3
  interface KeyValueRecord {
3
4
  key: string;
4
5
  value: any;
@@ -10,7 +11,7 @@ export declare class KeyValueStoreStorageOperations {
10
11
  constructor(dynamoDbClient: DynamoDBDocument);
11
12
  private createScopedKey;
12
13
  get(key: string, scope: string): Promise<KeyValueRecord | null>;
13
- set(key: string, value: any, scope: string): Promise<void>;
14
+ set(key: string, value: any, scope: string, options?: IKeyValueStoreSetOptions): Promise<void>;
14
15
  delete(key: string, scope: string): Promise<void>;
15
16
  }
16
17
  export {};