@webiny/api-core-ddb 6.5.4-beta.1 → 6.5.4
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/adminUsers/index.js.map +1 -1
- package/package.json +9 -9
- package/security/index.js.map +1 -1
- package/tenancy/index.js.map +1 -1
package/adminUsers/index.js.map
CHANGED
|
@@ -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 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 } = 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 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({ 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 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 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 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","createUserIndexPartitionKey","id","createUserGSIKeys","storageOperations","keys","err","WebinyError","tenant","email","response","tenants","reader","items","item","where","sort","ddbItems","sortItems"],"mappings":";;;AAYO,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,M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AAK,CAAC,QAAQ,CAAmC;oBAC1E,cAAcI,4BAA4BC;oBAC1C,SAAS;wBACL,OAAO;oBACX;gBACJ;gBAEA,OAAOW,MAAM,GAAG,CAACC,CAAAA,OAAQA,KAAK,IAAI;YACtC,EAAE,OAAOR,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAEJ;oBAAG;gBACf;YACJ;QACJ;QACA,MAAM,WAA+C,EACjDa,KAAK,EACLC,IAAI,EAC2B;YAC/B,IAAIH;YACJ,IAAI;gBACA,MAAMI,WAAW,MAAMpB,SAAS,KAAK,CAAC,QAAQ,CAAmC;oBAC7E,cAAc,CAAC,EAAE,EAAEkB,MAAM,MAAM,CAAC,YAAY,CAAC;oBAC7C,SAAS;wBACL,OAAO;oBACX;gBACJ;gBACAF,QAAQI,SAAS,GAAG,CAACH,CAAAA,OACVA,KAAK,IAAI;YAExB,EAAE,OAAOR,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;gBACV;YACJ;YAEA,OAAOY,UAAU;gBAAEL;gBAAOG;YAAK;QACnC;QACA,MAAM,YAAW,EAAEhB,IAAI,EAAE;YACrB,MAAMK,OAAO;gBACT,GAAGN,eAAeC,KAAK;gBACvB,GAAGG,kBAAkBH,KAAK;YAC9B;YAEA,IAAI;gBACA,MAAMH,SAAS,KAAK,CAAC,GAAG,CAAC;oBACrB,GAAGQ,IAAI;oBACP,MAAM;oBACN,MAAML;gBACV;gBACA,OAAOA;YACX,EAAE,OAAOM,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAED;wBAAML;oBAAK;gBACvB;YACJ;QACJ;IACJ;IAEA,OAAOI;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 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 } = 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 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({ 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 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 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 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","createUserIndexPartitionKey","id","createUserGSIKeys","storageOperations","keys","err","WebinyError","tenant","email","response","tenants","reader","items","item","where","sort","ddbItems","sortItems"],"mappings":";;;AAYO,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,CAAC;IAED,MAAMC,8BAA8B,CAACC,KAAe,CAAC,WAAW,EAAEA,IAAI;IAEtE,MAAMC,oBAAoB,CAACH,OAChB;YACH,SAAS,CAAC,EAAE,EAAEA,KAAK,MAAM,CAAC,YAAY,CAAC;YACvC,SAASA,KAAK,KAAK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,IAAI,EAC2B;YAC/B,IAAIH;YACJ,IAAI;gBACA,MAAMI,WAAW,MAAMpB,SAAS,KAAK,CAAC,QAAQ,CAAmC;oBAC7E,cAAc,CAAC,EAAE,EAAEkB,MAAM,MAAM,CAAC,YAAY,CAAC;oBAC7C,SAAS;wBACL,OAAO;oBACX;gBACJ;gBACAF,QAAQI,SAAS,GAAG,CAACH,CAAAA,OACVA,KAAK,IAAI;YAExB,EAAE,OAAOR,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;gBACV;YACJ;YAEA,OAAOY,UAAU;gBAAEL;gBAAOG;YAAK;QACnC;QACA,MAAM,YAAW,EAAEhB,IAAI,EAAE;YACrB,MAAMK,OAAO;gBACT,GAAGN,eAAeC,KAAK;gBACvB,GAAGG,kBAAkBH,KAAK;YAC9B;YAEA,IAAI;gBACA,MAAMH,SAAS,KAAK,CAAC,GAAG,CAAC;oBACrB,GAAGQ,IAAI;oBACP,MAAM;oBACN,MAAML;gBACV;gBACA,OAAOA;YACX,EAAE,OAAOM,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAED;wBAAML;oBAAK;gBACvB;YACJ;QACJ;IACJ;IAEA,OAAOI;AACX"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-core-ddb",
|
|
3
|
-
"version": "6.5.4
|
|
3
|
+
"version": "6.5.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -21,16 +21,16 @@
|
|
|
21
21
|
"author": "Webiny Ltd.",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@webiny/api": "6.5.4
|
|
25
|
-
"@webiny/api-core": "6.5.4
|
|
26
|
-
"@webiny/aws-sdk": "6.5.4
|
|
27
|
-
"@webiny/db-dynamodb": "6.5.4
|
|
28
|
-
"@webiny/error": "6.5.4
|
|
24
|
+
"@webiny/api": "6.5.4",
|
|
25
|
+
"@webiny/api-core": "6.5.4",
|
|
26
|
+
"@webiny/aws-sdk": "6.5.4",
|
|
27
|
+
"@webiny/db-dynamodb": "6.5.4",
|
|
28
|
+
"@webiny/error": "6.5.4"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@webiny/api": "6.5.4
|
|
32
|
-
"@webiny/build-tools": "6.5.4
|
|
33
|
-
"@webiny/project-utils": "6.5.4
|
|
31
|
+
"@webiny/api": "6.5.4",
|
|
32
|
+
"@webiny/build-tools": "6.5.4",
|
|
33
|
+
"@webiny/project-utils": "6.5.4",
|
|
34
34
|
"jest-dynalite": "3.6.1",
|
|
35
35
|
"rimraf": "6.1.4",
|
|
36
36
|
"typescript": "7.0.2"
|
package/security/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"security/index.js","sources":["../../src/security/index.ts"],"sourcesContent":["import type { SecurityStorageParams } from \"./types.js\";\nimport type {\n StorageApiKey,\n StorageRole,\n SecurityStorageOperations,\n StorageTeam\n} from \"@webiny/api-core/types/security.js\";\nimport WebinyError from \"@webiny/error\";\nimport { createApiKeyEntity, createRoleEntity, createTeamEntity } from \"./definitions/entities.js\";\nimport { createTable, type IEntityQueryOneParams, sortItems } from \"@webiny/db-dynamodb\";\n\nexport const createStorageOperations = (\n params: SecurityStorageParams\n): SecurityStorageOperations => {\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 apiKeys: createApiKeyEntity(table.table),\n roles: createRoleEntity(table.table),\n teams: createTeamEntity(table.table)\n };\n\n const createApiKeyKeys = ({ id, tenant }: Pick<StorageApiKey, \"id\" | \"tenant\">) => ({\n PK: `T#${tenant}#API_KEY#${id}`,\n SK: `A`,\n GSI_TENANT: tenant,\n TYPE: \"security.apiKey\"\n });\n\n const createApiKeyGsiKeys = ({\n slug,\n token,\n tenant\n }: Pick<StorageApiKey, \"slug\" | \"tenant\" | \"token\">) => ({\n GSI1_PK: `T#${tenant}#API_KEYS`,\n GSI1_SK: token,\n GSI2_PK: `T#${tenant}#API_KEYS`,\n GSI2_SK: slug\n });\n\n const createRoleKeys = (role: Pick<StorageRole, \"tenant\" | \"id\">) => ({\n PK: `T#${role.tenant}#ROLE#${role.id}`,\n SK: `A`\n });\n\n const createRoleGsiKeys = (role: Pick<StorageRole, \"tenant\" | \"slug\">) => ({\n GSI1_PK: `T#${role.tenant}#ROLES`,\n GSI1_SK: role.slug,\n GSI_TENANT: role.tenant as string,\n TYPE: \"security.role\"\n });\n\n const createTeamKeys = (team: Pick<StorageTeam, \"tenant\" | \"id\">) => ({\n PK: `T#${team.tenant}#TEAM#${team.id}`,\n SK: `A`\n });\n\n const createTeamGsiKeys = (team: Pick<StorageTeam, \"tenant\" | \"slug\">) => ({\n GSI1_PK: `T#${team.tenant}#TEAMS`,\n GSI1_SK: team.slug,\n GSI_TENANT: team.tenant as string,\n TYPE: \"security.team\"\n });\n\n return {\n async createApiKey({ apiKey }): Promise<void> {\n const keys = {\n ...createApiKeyKeys(apiKey),\n ...createApiKeyGsiKeys(apiKey)\n };\n\n try {\n await entities.apiKeys.put({\n data: apiKey,\n ...keys\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create api key.\",\n code: \"CREATE_API_KEY_ERROR\",\n data: { keys }\n });\n }\n },\n async createRole({ role }): Promise<void> {\n const keys = {\n ...createRoleKeys(role),\n ...createRoleGsiKeys(role)\n };\n\n try {\n await entities.roles.put({\n data: role,\n ...keys\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create role.\",\n code: \"CREATE_ROLE_ERROR\",\n data: { keys }\n });\n }\n },\n async createTeam({ team }): Promise<void> {\n const keys = {\n ...createTeamKeys(team),\n ...createTeamGsiKeys(team)\n };\n\n try {\n await entities.teams.put({\n data: team,\n ...keys\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create team.\",\n code: \"CREATE_TEAM_ERROR\",\n data: { keys }\n });\n }\n },\n async deleteApiKey({ apiKey }) {\n const keys = createApiKeyKeys(apiKey);\n\n try {\n await entities.apiKeys.delete(keys);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update api key.\",\n code: \"UPDATE_API_KEY_ERROR\",\n data: { keys }\n });\n }\n },\n async deleteRole({ role }) {\n const keys = createRoleKeys(role);\n\n try {\n await entities.roles.delete(keys);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not delete role.\",\n code: \"CREATE_DELETE_ERROR\",\n data: { keys, role }\n });\n }\n },\n async deleteTeam({ team }) {\n const keys = createTeamKeys(team);\n\n try {\n await entities.teams.delete(keys);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not delete team.\",\n code: \"CREATE_DELETE_ERROR\",\n data: { keys, team }\n });\n }\n },\n async getApiKey({ id, tenant }) {\n const keys = createApiKeyKeys({ id, tenant });\n\n try {\n const response = await entities.apiKeys.get(keys);\n\n return response?.data || null;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load api key.\",\n code: \"GET_API_KEY_ERROR\",\n data: { id, keys }\n });\n }\n },\n async getApiKeyByToken({ tenant, token }) {\n const queryParams: IEntityQueryOneParams = {\n partitionKey: `T#${tenant}#API_KEYS`,\n options: {\n eq: token,\n index: \"GSI1\"\n }\n };\n\n try {\n const result = await entities.apiKeys.queryOne(queryParams);\n return result?.data || null;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load api key by token.\",\n code: \"GET_BY_TOKEN_API_KEY_ERROR\",\n data: { partitionKey: queryParams.partitionKey, options: queryParams.options }\n });\n }\n },\n async getApiKeyBySlug({ tenant, slug }) {\n const queryParams: IEntityQueryOneParams = {\n partitionKey: `T#${tenant}#API_KEYS`,\n options: {\n eq: slug,\n index: \"GSI2\"\n }\n };\n\n try {\n const result = await entities.apiKeys.queryOne(queryParams);\n return result?.data || null;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load api key by slug.\",\n code: \"GET_BY_SLUG_API_KEY_ERROR\",\n data: { partitionKey: queryParams.partitionKey, options: queryParams.options }\n });\n }\n },\n async getRole({ where: { tenant, id, slug } }) {\n try {\n if (id) {\n const result = await entities.roles.get(createRoleKeys({ tenant, id }));\n return result?.data || null;\n }\n const result = await entities.roles.queryOne({\n partitionKey: `T#${tenant}#ROLES`,\n options: {\n index: \"GSI1\",\n eq: slug\n }\n });\n\n return result?.data || null;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load role.\",\n code: \"GET_ROLE_ERROR\",\n data: { id, slug }\n });\n }\n },\n async getTeam({ where: { tenant, id, slug } }) {\n try {\n if (id) {\n const result = await entities.teams.get(createTeamKeys({ tenant, id }));\n\n return result?.data || null;\n }\n\n const result = await entities.teams.queryOne({\n partitionKey: `T#${tenant}#TEAMS`,\n options: {\n index: \"GSI1\",\n eq: slug\n }\n });\n\n return result?.data || null;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load team.\",\n code: \"GET_TEAM_ERROR\",\n data: { id, slug }\n });\n }\n },\n async listApiKeys({ where: { tenant }, sort }): Promise<StorageApiKey[]> {\n let items;\n try {\n items = await entities.apiKeys.queryAll({\n partitionKey: `T#${tenant}#API_KEYS`,\n options: {\n index: \"GSI1\"\n }\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list api keys.\",\n code: \"LIST_API_KEY_ERROR\"\n });\n }\n\n return sortItems({ items, sort }).map(item => item.data);\n },\n async listRoles({ where: { tenant, id_in, slug_in }, sort }): Promise<StorageRole[]> {\n let items: StorageRole[];\n try {\n const ddbItems = await entities.roles.queryAll({\n partitionKey: `T#${tenant}#ROLES`,\n options: {\n index: \"GSI1\"\n }\n });\n items = ddbItems.map(item => item.data);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list roles.\",\n code: \"LIST_ROLE_ERROR\"\n });\n }\n\n items = sortItems({ items, sort });\n\n if (Array.isArray(id_in)) {\n return items.filter(item => id_in.includes(item.id));\n }\n\n if (Array.isArray(slug_in)) {\n return items.filter(item => slug_in.includes(item.slug));\n }\n\n return items;\n },\n async listTeams({ where: { tenant, id_in, slug_in }, sort }): Promise<StorageTeam[]> {\n let items: StorageTeam[];\n try {\n const ddbRecords = await entities.teams.queryAll({\n partitionKey: `T#${tenant}#TEAMS`,\n options: {\n index: \"GSI1\"\n }\n });\n\n items = ddbRecords.map(item => item.data);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list teams.\",\n code: \"LIST_TEAM_ERROR\"\n });\n }\n\n items = sortItems({ items, sort });\n\n if (Array.isArray(id_in)) {\n return items.filter(item => id_in.includes(item.id));\n }\n\n if (Array.isArray(slug_in)) {\n return items.filter(item => slug_in.includes(item.slug));\n }\n return items;\n },\n async updateApiKey({ apiKey }): Promise<void> {\n const keys = {\n ...createApiKeyKeys(apiKey),\n ...createApiKeyGsiKeys(apiKey)\n };\n\n try {\n await entities.apiKeys.put({\n data: apiKey,\n ...keys\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update api key.\",\n code: \"UPDATE_API_KEY_ERROR\",\n data: { keys }\n });\n }\n },\n async updateRole({ role }): Promise<void> {\n const keys = createRoleKeys(role);\n\n try {\n await entities.roles.put({\n data: role,\n ...keys,\n ...createRoleGsiKeys(role)\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update role.\",\n code: \"UPDATE_ROLE_ERROR\",\n data: { keys, role }\n });\n }\n },\n async updateTeam({ team }): Promise<void> {\n const keys = createTeamKeys(team);\n\n try {\n await entities.teams.put({\n data: team,\n ...keys,\n ...createTeamGsiKeys(team)\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update team.\",\n code: \"UPDATE_TEAM_ERROR\",\n data: { keys, team }\n });\n }\n }\n };\n};\n"],"names":["createStorageOperations","params","tableName","documentClient","table","createTable","process","entities","createApiKeyEntity","createRoleEntity","createTeamEntity","createApiKeyKeys","id","tenant","createApiKeyGsiKeys","slug","token","createRoleKeys","role","createRoleGsiKeys","createTeamKeys","team","createTeamGsiKeys","apiKey","keys","err","WebinyError","response","queryParams","result","sort","items","sortItems","item","id_in","slug_in","ddbItems","Array","ddbRecords"],"mappings":";;;AAWO,MAAMA,0BAA0B,CACnCC;IAEA,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,SAASC,mBAAmBJ,MAAM,KAAK;QACvC,OAAOK,iBAAiBL,MAAM,KAAK;QACnC,OAAOM,iBAAiBN,MAAM,KAAK;IACvC;IAEA,MAAMO,mBAAmB,CAAC,EAAEC,EAAE,EAAEC,MAAM,EAAwC,GAAM;YAChF,IAAI,CAAC,EAAE,EAAEA,OAAO,SAAS,EAAED,IAAI;YAC/B,IAAI;YACJ,YAAYC;YACZ,MAAM;QACV;IAEA,MAAMC,sBAAsB,CAAC,EACzBC,IAAI,EACJC,KAAK,EACLH,MAAM,EACyC,GAAM;YACrD,SAAS,CAAC,EAAE,EAAEA,OAAO,SAAS,CAAC;YAC/B,SAASG;YACT,SAAS,CAAC,EAAE,EAAEH,OAAO,SAAS,CAAC;YAC/B,SAASE;QACb;IAEA,MAAME,iBAAiB,CAACC,OAA8C;YAClE,IAAI,CAAC,EAAE,EAAEA,KAAK,MAAM,CAAC,MAAM,EAAEA,KAAK,EAAE,EAAE;YACtC,IAAI;QACR;IAEA,MAAMC,oBAAoB,CAACD,OAAgD;YACvE,SAAS,CAAC,EAAE,EAAEA,KAAK,MAAM,CAAC,MAAM,CAAC;YACjC,SAASA,KAAK,IAAI;YAClB,YAAYA,KAAK,MAAM;YACvB,MAAM;QACV;IAEA,MAAME,iBAAiB,CAACC,OAA8C;YAClE,IAAI,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AMH;oBAAK;gBACvB;YACJ;QACJ;IACJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"security/index.js","sources":["../../src/security/index.ts"],"sourcesContent":["import type { SecurityStorageParams } from \"./types.js\";\nimport type {\n StorageApiKey,\n StorageRole,\n SecurityStorageOperations,\n StorageTeam\n} from \"@webiny/api-core/types/security.js\";\nimport WebinyError from \"@webiny/error\";\nimport { createApiKeyEntity, createRoleEntity, createTeamEntity } from \"./definitions/entities.js\";\nimport { createTable, type IEntityQueryOneParams, sortItems } from \"@webiny/db-dynamodb\";\n\nexport const createStorageOperations = (\n params: SecurityStorageParams\n): SecurityStorageOperations => {\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 apiKeys: createApiKeyEntity(table.table),\n roles: createRoleEntity(table.table),\n teams: createTeamEntity(table.table)\n };\n\n const createApiKeyKeys = ({ id, tenant }: Pick<StorageApiKey, \"id\" | \"tenant\">) => ({\n PK: `T#${tenant}#API_KEY#${id}`,\n SK: `A`,\n GSI_TENANT: tenant,\n TYPE: \"security.apiKey\"\n });\n\n const createApiKeyGsiKeys = ({\n slug,\n token,\n tenant\n }: Pick<StorageApiKey, \"slug\" | \"tenant\" | \"token\">) => ({\n GSI1_PK: `T#${tenant}#API_KEYS`,\n GSI1_SK: token,\n GSI2_PK: `T#${tenant}#API_KEYS`,\n GSI2_SK: slug\n });\n\n const createRoleKeys = (role: Pick<StorageRole, \"tenant\" | \"id\">) => ({\n PK: `T#${role.tenant}#ROLE#${role.id}`,\n SK: `A`\n });\n\n const createRoleGsiKeys = (role: Pick<StorageRole, \"tenant\" | \"slug\">) => ({\n GSI1_PK: `T#${role.tenant}#ROLES`,\n GSI1_SK: role.slug,\n GSI_TENANT: role.tenant as string,\n TYPE: \"security.role\"\n });\n\n const createTeamKeys = (team: Pick<StorageTeam, \"tenant\" | \"id\">) => ({\n PK: `T#${team.tenant}#TEAM#${team.id}`,\n SK: `A`\n });\n\n const createTeamGsiKeys = (team: Pick<StorageTeam, \"tenant\" | \"slug\">) => ({\n GSI1_PK: `T#${team.tenant}#TEAMS`,\n GSI1_SK: team.slug,\n GSI_TENANT: team.tenant as string,\n TYPE: \"security.team\"\n });\n\n return {\n async createApiKey({ apiKey }): Promise<void> {\n const keys = {\n ...createApiKeyKeys(apiKey),\n ...createApiKeyGsiKeys(apiKey)\n };\n\n try {\n await entities.apiKeys.put({\n data: apiKey,\n ...keys\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create api key.\",\n code: \"CREATE_API_KEY_ERROR\",\n data: { keys }\n });\n }\n },\n async createRole({ role }): Promise<void> {\n const keys = {\n ...createRoleKeys(role),\n ...createRoleGsiKeys(role)\n };\n\n try {\n await entities.roles.put({\n data: role,\n ...keys\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create role.\",\n code: \"CREATE_ROLE_ERROR\",\n data: { keys }\n });\n }\n },\n async createTeam({ team }): Promise<void> {\n const keys = {\n ...createTeamKeys(team),\n ...createTeamGsiKeys(team)\n };\n\n try {\n await entities.teams.put({\n data: team,\n ...keys\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create team.\",\n code: \"CREATE_TEAM_ERROR\",\n data: { keys }\n });\n }\n },\n async deleteApiKey({ apiKey }) {\n const keys = createApiKeyKeys(apiKey);\n\n try {\n await entities.apiKeys.delete(keys);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update api key.\",\n code: \"UPDATE_API_KEY_ERROR\",\n data: { keys }\n });\n }\n },\n async deleteRole({ role }) {\n const keys = createRoleKeys(role);\n\n try {\n await entities.roles.delete(keys);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not delete role.\",\n code: \"CREATE_DELETE_ERROR\",\n data: { keys, role }\n });\n }\n },\n async deleteTeam({ team }) {\n const keys = createTeamKeys(team);\n\n try {\n await entities.teams.delete(keys);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not delete team.\",\n code: \"CREATE_DELETE_ERROR\",\n data: { keys, team }\n });\n }\n },\n async getApiKey({ id, tenant }) {\n const keys = createApiKeyKeys({ id, tenant });\n\n try {\n const response = await entities.apiKeys.get(keys);\n\n return response?.data || null;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load api key.\",\n code: \"GET_API_KEY_ERROR\",\n data: { id, keys }\n });\n }\n },\n async getApiKeyByToken({ tenant, token }) {\n const queryParams: IEntityQueryOneParams = {\n partitionKey: `T#${tenant}#API_KEYS`,\n options: {\n eq: token,\n index: \"GSI1\"\n }\n };\n\n try {\n const result = await entities.apiKeys.queryOne(queryParams);\n return result?.data || null;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load api key by token.\",\n code: \"GET_BY_TOKEN_API_KEY_ERROR\",\n data: { partitionKey: queryParams.partitionKey, options: queryParams.options }\n });\n }\n },\n async getApiKeyBySlug({ tenant, slug }) {\n const queryParams: IEntityQueryOneParams = {\n partitionKey: `T#${tenant}#API_KEYS`,\n options: {\n eq: slug,\n index: \"GSI2\"\n }\n };\n\n try {\n const result = await entities.apiKeys.queryOne(queryParams);\n return result?.data || null;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load api key by slug.\",\n code: \"GET_BY_SLUG_API_KEY_ERROR\",\n data: { partitionKey: queryParams.partitionKey, options: queryParams.options }\n });\n }\n },\n async getRole({ where: { tenant, id, slug } }) {\n try {\n if (id) {\n const result = await entities.roles.get(createRoleKeys({ tenant, id }));\n return result?.data || null;\n }\n const result = await entities.roles.queryOne({\n partitionKey: `T#${tenant}#ROLES`,\n options: {\n index: \"GSI1\",\n eq: slug\n }\n });\n\n return result?.data || null;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load role.\",\n code: \"GET_ROLE_ERROR\",\n data: { id, slug }\n });\n }\n },\n async getTeam({ where: { tenant, id, slug } }) {\n try {\n if (id) {\n const result = await entities.teams.get(createTeamKeys({ tenant, id }));\n\n return result?.data || null;\n }\n\n const result = await entities.teams.queryOne({\n partitionKey: `T#${tenant}#TEAMS`,\n options: {\n index: \"GSI1\",\n eq: slug\n }\n });\n\n return result?.data || null;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load team.\",\n code: \"GET_TEAM_ERROR\",\n data: { id, slug }\n });\n }\n },\n async listApiKeys({ where: { tenant }, sort }): Promise<StorageApiKey[]> {\n let items;\n try {\n items = await entities.apiKeys.queryAll({\n partitionKey: `T#${tenant}#API_KEYS`,\n options: {\n index: \"GSI1\"\n }\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list api keys.\",\n code: \"LIST_API_KEY_ERROR\"\n });\n }\n\n return sortItems({ items, sort }).map(item => item.data);\n },\n async listRoles({ where: { tenant, id_in, slug_in }, sort }): Promise<StorageRole[]> {\n let items: StorageRole[];\n try {\n const ddbItems = await entities.roles.queryAll({\n partitionKey: `T#${tenant}#ROLES`,\n options: {\n index: \"GSI1\"\n }\n });\n items = ddbItems.map(item => item.data);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list roles.\",\n code: \"LIST_ROLE_ERROR\"\n });\n }\n\n items = sortItems({ items, sort });\n\n if (Array.isArray(id_in)) {\n return items.filter(item => id_in.includes(item.id));\n }\n\n if (Array.isArray(slug_in)) {\n return items.filter(item => slug_in.includes(item.slug));\n }\n\n return items;\n },\n async listTeams({ where: { tenant, id_in, slug_in }, sort }): Promise<StorageTeam[]> {\n let items: StorageTeam[];\n try {\n const ddbRecords = await entities.teams.queryAll({\n partitionKey: `T#${tenant}#TEAMS`,\n options: {\n index: \"GSI1\"\n }\n });\n\n items = ddbRecords.map(item => item.data);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list teams.\",\n code: \"LIST_TEAM_ERROR\"\n });\n }\n\n items = sortItems({ items, sort });\n\n if (Array.isArray(id_in)) {\n return items.filter(item => id_in.includes(item.id));\n }\n\n if (Array.isArray(slug_in)) {\n return items.filter(item => slug_in.includes(item.slug));\n }\n return items;\n },\n async updateApiKey({ apiKey }): Promise<void> {\n const keys = {\n ...createApiKeyKeys(apiKey),\n ...createApiKeyGsiKeys(apiKey)\n };\n\n try {\n await entities.apiKeys.put({\n data: apiKey,\n ...keys\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update api key.\",\n code: \"UPDATE_API_KEY_ERROR\",\n data: { keys }\n });\n }\n },\n async updateRole({ role }): Promise<void> {\n const keys = createRoleKeys(role);\n\n try {\n await entities.roles.put({\n data: role,\n ...keys,\n ...createRoleGsiKeys(role)\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update role.\",\n code: \"UPDATE_ROLE_ERROR\",\n data: { keys, role }\n });\n }\n },\n async updateTeam({ team }): Promise<void> {\n const keys = createTeamKeys(team);\n\n try {\n await entities.teams.put({\n data: team,\n ...keys,\n ...createTeamGsiKeys(team)\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update team.\",\n code: \"UPDATE_TEAM_ERROR\",\n data: { keys, team }\n });\n }\n }\n };\n};\n"],"names":["createStorageOperations","params","tableName","documentClient","table","createTable","process","entities","createApiKeyEntity","createRoleEntity","createTeamEntity","createApiKeyKeys","id","tenant","createApiKeyGsiKeys","slug","token","createRoleKeys","role","createRoleGsiKeys","createTeamKeys","team","createTeamGsiKeys","apiKey","keys","err","WebinyError","response","queryParams","result","sort","items","sortItems","item","id_in","slug_in","ddbItems","Array","ddbRecords"],"mappings":";;;AAWO,MAAMA,0BAA0B,CACnCC;IAEA,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,SAASC,mBAAmBJ,MAAM,KAAK;QACvC,OAAOK,iBAAiBL,MAAM,KAAK;QACnC,OAAOM,iBAAiBN,MAAM,KAAK;IACvC;IAEA,MAAMO,mBAAmB,CAAC,EA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ACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAED;oBAAK;gBACjB;YACJ;QACJ;QACA,MAAM,YAAW,EAAEN,IAAI,EAAE;YACrB,MAAMM,OAAOP,eAAeC;YAE5B,IAAI;gBACA,MAAMX,SAAS,KAAK,CAAC,GAAG,CAAC;oBACrB,MAAMW;oBACN,GAAGM,IAAI;oBACP,GAAGL,kBAAkBD,KAAK;gBAC9B;YACJ,EAAE,OAAOO,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAED;wBAAMN;oBAAK;gBACvB;YACJ;QACJ;QACA,MAAM,YAAW,EAAEG,IAAI,EAAE;YACrB,MAAMG,OAAOJ,eAAeC;YAE5B,IAAI;gBACA,MAAMd,SAAS,KAAK,CAAC,GAAG,CAAC;oBACrB,MAAMc;oBACN,GAAGG,IAAI;oBACP,GAAGF,kBAAkBD,KAAK;gBAC9B;YACJ,EAAE,OAAOI,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAED;wBAAMH;oBAAK;gBACvB;YACJ;QACJ;IACJ;AACJ"}
|
package/tenancy/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tenancy/index.js","sources":["../../src/tenancy/index.ts"],"sourcesContent":["import { createTable, type IEntityQueryAllParams } from \"@webiny/db-dynamodb\";\nimport WebinyError from \"@webiny/error\";\nimport { createTenantEntity } from \"./definitions/tenantEntity.js\";\nimport type { CreateTenancyStorageOperations } from \"./types.js\";\nimport { ENTITIES } from \"./types.js\";\nimport type { ListTenantsParams, Tenant } from \"@webiny/api-core/types/tenancy.js\";\n\nconst setTenantDefaults = (item: Tenant) => {\n if (!item.tags) {\n item.tags = [];\n }\n\n if (!item.description) {\n item.description = \"\";\n }\n\n return item;\n};\n\nexport const createStorageOperations: CreateTenancyStorageOperations = params => {\n const { documentClient } = params;\n\n const tableInstance = createTable({\n name: (process.env.DB_TABLE_TENANCY || process.env.DB_TABLE) as string,\n documentClient\n });\n\n const entities = {\n tenants: createTenantEntity({\n entityName: ENTITIES.TENANT,\n table: tableInstance.table\n })\n };\n\n return {\n getTable() {\n return tableInstance;\n },\n getEntities() {\n return entities;\n },\n\n async getTenantsByIds(ids: string[]): Promise<Tenant[]> {\n const batchReader = entities.tenants.createEntityReader({\n read: ids.map(id => {\n return {\n PK: `T#${id}`,\n SK: \"A\"\n };\n })\n });\n const tenants = await batchReader.execute();\n\n return tenants\n .map(item => {\n return item.data;\n })\n .map(item => {\n return setTenantDefaults(item);\n });\n },\n\n async listTenants(params: ListTenantsParams = {}): Promise<Tenant[]> {\n const { parent } = params;\n\n const options: IEntityQueryAllParams[\"options\"] = {\n index: \"GSI1\"\n };\n\n if (parent) {\n options.beginsWith = `T#${parent}#`;\n } else {\n options.gt = \" \";\n }\n\n const tenants = await entities.tenants.queryAll({\n partitionKey: `TENANTS`,\n options\n });\n\n return tenants\n .map(item => {\n return item.data;\n })\n .map(item => {\n return setTenantDefaults(item);\n });\n },\n\n async createTenant(data: Tenant): Promise<Tenant> {\n const keys = {\n PK: `T#${data.id}`,\n SK: \"A\",\n GSI1_PK: \"TENANTS\",\n GSI1_SK: `T#${data.parent}#${data.createdOn}`,\n GSI_TENANT: data.id\n };\n\n try {\n await entities.tenants.put({\n TYPE: \"tenancy.tenant\",\n ...keys,\n data\n });\n\n return data;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create tenant record.\",\n code: \"CREATE_TENANT_ERROR\",\n data: {\n keys,\n data\n }\n });\n }\n },\n\n async updateTenant(data: Tenant): Promise<Tenant> {\n const tenantPK = `T#${data.id}`;\n\n const keys = {\n PK: tenantPK,\n SK: \"A\",\n GSI1_PK: \"TENANTS\",\n GSI1_SK: `T#${data.parent}#${data.createdOn}`,\n GSI_TENANT: data.id,\n TYPE: \"tenancy.tenant\"\n };\n\n try {\n await entities.tenants.put({\n ...keys,\n data\n });\n return data;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update tenant record.\",\n code: \"CREATE_TENANT_ERROR\",\n data: { keys, data }\n });\n }\n },\n\n async deleteTenant(id: string): Promise<void> {\n await entities.tenants.delete({\n PK: `T#${id}`,\n SK: \"A\"\n });\n }\n };\n};\n"],"names":["setTenantDefaults","item","createStorageOperations","params","documentClient","tableInstance","createTable","process","entities","createTenantEntity","ENTITIES","ids","batchReader","id","tenants","parent","options","data","keys","err","WebinyError","tenantPK"],"mappings":";;;;AAOA,MAAMA,oBAAoB,CAACC;IACvB,IAAI,CAACA,KAAK,IAAI,EACVA,KAAK,IAAI,GAAG,EAAE;IAGlB,IAAI,CAACA,KAAK,WAAW,EACjBA,KAAK,WAAW,GAAG;IAGvB,OAAOA;AACX;AAEO,MAAMC,0BAA0DC,CAAAA;IACnE,MAAM,EAAEC,cAAc,EAAE,GAAGD;IAE3B,MAAME,gBAAgBC,YAAY;QAC9B,MAAOC,QAAQ,GAAG,CAAC,gBAAgB,IAAIA,QAAQ,GAAG,CAAC,QAAQ;QAC3DH;IACJ;IAEA,MAAMI,WAAW;QACb,SAASC,mBAAmB;YACxB,YAAYC,SAAS,MAAM;YAC3B,OAAOL,cAAc,KAAK;QAC9B;IACJ;IAEA,OAAO;QACH;YACI,OAAOA;QACX;QACA;YACI,OAAOG;QACX;QAEA,MAAM,iBAAgBG,GAAa;YAC/B,MAAMC,cAAcJ,SAAS,OAAO,CAAC,kBAAkB,CAAC;gBACpD,MAAMG,IAAI,GAAG,CAACE,CAAAA,KACH;wBACH,IAAI,CAAC,EAAE,EAAEA,IAAI;wBACb,IAAI;oBACR;
|
|
1
|
+
{"version":3,"file":"tenancy/index.js","sources":["../../src/tenancy/index.ts"],"sourcesContent":["import { createTable, type IEntityQueryAllParams } from \"@webiny/db-dynamodb\";\nimport WebinyError from \"@webiny/error\";\nimport { createTenantEntity } from \"./definitions/tenantEntity.js\";\nimport type { CreateTenancyStorageOperations } from \"./types.js\";\nimport { ENTITIES } from \"./types.js\";\nimport type { ListTenantsParams, Tenant } from \"@webiny/api-core/types/tenancy.js\";\n\nconst setTenantDefaults = (item: Tenant) => {\n if (!item.tags) {\n item.tags = [];\n }\n\n if (!item.description) {\n item.description = \"\";\n }\n\n return item;\n};\n\nexport const createStorageOperations: CreateTenancyStorageOperations = params => {\n const { documentClient } = params;\n\n const tableInstance = createTable({\n name: (process.env.DB_TABLE_TENANCY || process.env.DB_TABLE) as string,\n documentClient\n });\n\n const entities = {\n tenants: createTenantEntity({\n entityName: ENTITIES.TENANT,\n table: tableInstance.table\n })\n };\n\n return {\n getTable() {\n return tableInstance;\n },\n getEntities() {\n return entities;\n },\n\n async getTenantsByIds(ids: string[]): Promise<Tenant[]> {\n const batchReader = entities.tenants.createEntityReader({\n read: ids.map(id => {\n return {\n PK: `T#${id}`,\n SK: \"A\"\n };\n })\n });\n const tenants = await batchReader.execute();\n\n return tenants\n .map(item => {\n return item.data;\n })\n .map(item => {\n return setTenantDefaults(item);\n });\n },\n\n async listTenants(params: ListTenantsParams = {}): Promise<Tenant[]> {\n const { parent } = params;\n\n const options: IEntityQueryAllParams[\"options\"] = {\n index: \"GSI1\"\n };\n\n if (parent) {\n options.beginsWith = `T#${parent}#`;\n } else {\n options.gt = \" \";\n }\n\n const tenants = await entities.tenants.queryAll({\n partitionKey: `TENANTS`,\n options\n });\n\n return tenants\n .map(item => {\n return item.data;\n })\n .map(item => {\n return setTenantDefaults(item);\n });\n },\n\n async createTenant(data: Tenant): Promise<Tenant> {\n const keys = {\n PK: `T#${data.id}`,\n SK: \"A\",\n GSI1_PK: \"TENANTS\",\n GSI1_SK: `T#${data.parent}#${data.createdOn}`,\n GSI_TENANT: data.id\n };\n\n try {\n await entities.tenants.put({\n TYPE: \"tenancy.tenant\",\n ...keys,\n data\n });\n\n return data;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create tenant record.\",\n code: \"CREATE_TENANT_ERROR\",\n data: {\n keys,\n data\n }\n });\n }\n },\n\n async updateTenant(data: Tenant): Promise<Tenant> {\n const tenantPK = `T#${data.id}`;\n\n const keys = {\n PK: tenantPK,\n SK: \"A\",\n GSI1_PK: \"TENANTS\",\n GSI1_SK: `T#${data.parent}#${data.createdOn}`,\n GSI_TENANT: data.id,\n TYPE: \"tenancy.tenant\"\n };\n\n try {\n await entities.tenants.put({\n ...keys,\n data\n });\n return data;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update tenant record.\",\n code: \"CREATE_TENANT_ERROR\",\n data: { keys, data }\n });\n }\n },\n\n async deleteTenant(id: string): Promise<void> {\n await entities.tenants.delete({\n PK: `T#${id}`,\n SK: \"A\"\n });\n }\n };\n};\n"],"names":["setTenantDefaults","item","createStorageOperations","params","documentClient","tableInstance","createTable","process","entities","createTenantEntity","ENTITIES","ids","batchReader","id","tenants","parent","options","data","keys","err","WebinyError","tenantPK"],"mappings":";;;;AAOA,MAAMA,oBAAoB,CAACC;IACvB,IAAI,CAACA,KAAK,IAAI,EACVA,KAAK,IAAI,GAAG,EAAE;IAGlB,IAAI,CAACA,KAAK,WAAW,EACjBA,KAAK,WAAW,GAAG;IAGvB,OAAOA;AACX;AAEO,MAAMC,0BAA0DC,CAAAA;IACnE,MAAM,EAAEC,cAAc,EAAE,GAAGD;IAE3B,MAAME,gBAAgBC,YAAY;QAC9B,MAAOC,QAAQ,GAAG,CAAC,gBAAgB,IAAIA,QAAQ,GAAG,CAAC,QAAQ;QAC3DH;IACJ;IAEA,MAAMI,WAAW;QACb,SAASC,mBAAmB;YACxB,YAAYC,SAAS,MAAM;YAC3B,OAAOL,cAAc,KAAK;QAC9B;IACJ;IAEA,OAAO;QACH;YACI,OAAOA;QACX;QACA;YACI,OAAOG;QACX;QAEA,MAAM,iBAAgBG,GAAa;YAC/B,MAAMC,cAAcJ,SAAS,OAAO,CAAC,kBAAkB,CAAC;gBACpD,MAAMG,IAAI,GAAG,CAACE,CAAAA,KACH;wBACH,IAAI,CAAC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