@webiny/api-core-ddb 0.0.0-unstable.7c2def32a7 → 0.0.0-unstable.9609e4e0c9

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.
@@ -108,8 +108,14 @@ const createStorageOperations = (params)=>{
108
108
  code: "LIST_ADMIN_USERS_ERROR"
109
109
  });
110
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
+ });
111
117
  return sortItems({
112
- items,
118
+ items: filtered,
113
119
  sort
114
120
  });
115
121
  },
@@ -1 +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 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,GAAG,CAAC;oBACrB,GAAGM,IAAI;oBACP,MAAM;oBACN,MAAMH;gBACV;gBAEA,OAAOA;YACX,EAAE,OAAOI,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAED;oBAAK;gBACjB;YACJ;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,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
+ {"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":";;;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,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E,cAAc,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,MAAM,EAAEW,KAAK,EAAEC,QAAQ,EAAE,GAAGN;YAE5B,MAAMO,WAAWL,MAAM,MAAM,CAACE,CAAAA;gBAC1B,IAAII,MAAM,OAAO,CAACH,UAAU,CAACA,MAAM,QAAQ,CAACD,KAAK,EAAE,GAC/C,OAAO;gBAEX,IAAII,MAAM,OAAO,CAACF,WACd,OAAQF,AAAAA,CAAAA,KAAK,KAAK,IAAI,EAAC,EAAG,IAAI,CAACK,CAAAA,OAAQH,SAAS,QAAQ,CAACG;gBAE7D,OAAO;YACX;YAEA,OAAOC,UAAU;gBAAE,OAAOH;gBAAUN;YAAK;QAC7C;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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-core-ddb",
3
- "version": "0.0.0-unstable.7c2def32a7",
3
+ "version": "0.0.0-unstable.9609e4e0c9",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -21,20 +21,20 @@
21
21
  "author": "Webiny Ltd.",
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@webiny/api": "0.0.0-unstable.7c2def32a7",
25
- "@webiny/api-core": "0.0.0-unstable.7c2def32a7",
26
- "@webiny/aws-sdk": "0.0.0-unstable.7c2def32a7",
27
- "@webiny/db-dynamodb": "0.0.0-unstable.7c2def32a7",
28
- "@webiny/error": "0.0.0-unstable.7c2def32a7",
29
- "@webiny/feature": "0.0.0-unstable.7c2def32a7"
24
+ "@webiny/api": "0.0.0-unstable.9609e4e0c9",
25
+ "@webiny/api-core": "0.0.0-unstable.9609e4e0c9",
26
+ "@webiny/aws-sdk": "0.0.0-unstable.9609e4e0c9",
27
+ "@webiny/db-dynamodb": "0.0.0-unstable.9609e4e0c9",
28
+ "@webiny/error": "0.0.0-unstable.9609e4e0c9",
29
+ "@webiny/feature": "0.0.0-unstable.9609e4e0c9"
30
30
  },
31
31
  "devDependencies": {
32
- "@webiny/api": "0.0.0-unstable.7c2def32a7",
33
- "@webiny/build-tools": "0.0.0-unstable.7c2def32a7",
32
+ "@webiny/api": "0.0.0-unstable.9609e4e0c9",
33
+ "@webiny/build-tools": "0.0.0-unstable.9609e4e0c9",
34
34
  "jest-dynalite": "3.6.1",
35
35
  "rimraf": "6.1.3",
36
36
  "typescript": "7.0.2",
37
- "vitest": "4.1.11"
37
+ "vitest": "5.0.5"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public"