@webiny/api-core-ddb 6.3.0 → 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.
- package/adminUsers/definitions/entities.js +5 -6
- package/adminUsers/definitions/entities.js.map +1 -1
- package/adminUsers/definitions/types.js +0 -3
- package/adminUsers/index.js +135 -156
- package/adminUsers/index.js.map +1 -1
- package/adminUsers/types.js +5 -4
- package/adminUsers/types.js.map +1 -1
- package/createApiCoreDdb.js +19 -22
- package/createApiCoreDdb.js.map +1 -1
- package/index.js +0 -2
- package/keyValueStore/KeyValueStoreDynamoTable.js +24 -25
- package/keyValueStore/KeyValueStoreDynamoTable.js.map +1 -1
- package/keyValueStore/KeyValueStoreStorageOperations.d.ts +2 -1
- package/keyValueStore/KeyValueStoreStorageOperations.js +72 -72
- package/keyValueStore/KeyValueStoreStorageOperations.js.map +1 -1
- package/keyValueStore/index.js +2 -3
- package/keyValueStore/index.js.map +1 -1
- package/package.json +9 -9
- package/security/definitions/entities.js +19 -24
- package/security/definitions/entities.js.map +1 -1
- package/security/definitions/types.js +0 -3
- package/security/index.js +389 -464
- package/security/index.js.map +1 -1
- package/security/types.js +6 -5
- package/security/types.js.map +1 -1
- package/tenancy/definitions/tenantEntity.js +5 -9
- package/tenancy/definitions/tenantEntity.js.map +1 -1
- package/tenancy/definitions/types.js +0 -3
- package/tenancy/index.js +107 -127
- package/tenancy/index.js.map +1 -1
- package/tenancy/types.js +4 -3
- package/tenancy/types.js.map +1 -1
- package/adminUsers/definitions/types.js.map +0 -1
- package/index.js.map +0 -1
- package/security/definitions/types.js.map +0 -1
- package/tenancy/definitions/types.js.map +0 -1
package/security/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["WebinyError","createApiKeyEntity","createRoleEntity","createTeamEntity","createTable","sortItems","createStorageOperations","params","table","tableName","documentClient","name","process","env","DB_TABLE","entities","apiKeys","roles","teams","createApiKeyKeys","id","tenant","PK","SK","GSI_TENANT","TYPE","createApiKeyGsiKeys","slug","token","GSI1_PK","GSI1_SK","GSI2_PK","GSI2_SK","createRoleKeys","role","createRoleGsiKeys","createTeamKeys","team","createTeamGsiKeys","createApiKey","apiKey","keys","put","data","err","from","message","code","createRole","createTeam","deleteApiKey","delete","deleteRole","deleteTeam","getApiKey","response","get","getApiKeyByToken","queryParams","partitionKey","options","eq","index","result","queryOne","getApiKeyBySlug","getRole","where","getTeam","listApiKeys","sort","items","queryAll","map","item","listRoles","id_in","slug_in","ddbItems","Array","isArray","filter","includes","listTeams","ddbRecords","updateApiKey","updateRole","updateTeam"],"sources":["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"],"mappings":"AAOA,OAAOA,WAAW,MAAM,eAAe;AACvC,SAASC,kBAAkB,EAAEC,gBAAgB,EAAEC,gBAAgB;AAC/D,SAASC,WAAW,EAA8BC,SAAS,QAAQ,qBAAqB;AAExF,OAAO,MAAMC,uBAAuB,GAChCC,MAA6B,IACD;EAC5B,MAAM;IAAEC,KAAK,EAAEC,SAAS;IAAEC;EAAe,CAAC,GAAGH,MAAM;EAEnD,MAAMC,KA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AAE,wBAAwB;UACjCC,IAAI,EAAE,mBAAmB;UACzBJ,IAAI,EAAE;YAAEF,IAAI;YAAEP;UAAK;QACvB,CAAC,CAAC;MACN;IACJ,CAAC;IACD,MAAMqD,UAAUA,CAAC;MAAElD;IAAK,CAAC,EAAiB;MACtC,MAAMI,IAAI,GAAGL,cAAc,CAACC,IAAI,CAAC;MAEjC,IAAI;QACA,MAAMtB,QAAQ,CAACG,KAAK,CAACwB,GAAG,CAAC;UACrBC,IAAI,EAAEN,IAAI;UACV,GAAGI,IAAI;UACP,GAAGH,iBAAiB,CAACD,IAAI;QAC7B,CAAC,CAAC;MACN,CAAC,CAAC,OAAOO,GAAG,EAAE;QACV,MAAM5C,WAAW,CAAC6C,IAAI,CAACD,GAAG,EAAE;UACxBE,OAAO,EAAE,wBAAwB;UACjCC,IAAI,EAAE,mBAAmB;UACzBJ,IAAI,EAAE;YAAEF,IAAI;YAAEJ;UAAK;QACvB,CAAC,CAAC;MACN;IACJ;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
|
|
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;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ACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAED;wBAAMH;oBAAK;gBACvB;YACJ;QACJ;IACJ;AACJ"}
|
package/security/types.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var types_ENTITIES = /*#__PURE__*/ function(ENTITIES) {
|
|
2
|
+
ENTITIES["API_KEY"] = "SecurityApiKey";
|
|
3
|
+
ENTITIES["ROLE"] = "SecurityRole";
|
|
4
|
+
ENTITIES["TEAM"] = "SecurityTeam";
|
|
5
|
+
return ENTITIES;
|
|
6
6
|
}({});
|
|
7
|
+
export { types_ENTITIES as ENTITIES };
|
|
7
8
|
|
|
8
9
|
//# sourceMappingURL=types.js.map
|
package/security/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"security/types.js","sources":["../../src/security/types.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\n\nexport enum ENTITIES {\n API_KEY = \"SecurityApiKey\",\n ROLE = \"SecurityRole\",\n TEAM = \"SecurityTeam\"\n}\n\nexport interface SecurityStorageParams {\n documentClient: DynamoDBDocument;\n table?: string;\n}\n"],"names":["ENTITIES"],"mappings":"AAEO,IAAKA,iBAAQA,WAAAA,GAAAA,SAARA,QAAQ;;;;WAARA"}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { createStandardEntity } from "@webiny/db-dynamodb";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
})
|
|
6
|
-
|
|
7
|
-
name: entityName,
|
|
8
|
-
table
|
|
9
|
-
});
|
|
10
|
-
};
|
|
2
|
+
const createTenantEntity = ({ entityName, table })=>createStandardEntity({
|
|
3
|
+
name: entityName,
|
|
4
|
+
table
|
|
5
|
+
});
|
|
6
|
+
export { createTenantEntity };
|
|
11
7
|
|
|
12
8
|
//# sourceMappingURL=tenantEntity.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"tenancy/definitions/tenantEntity.js","sources":["../../../src/tenancy/definitions/tenantEntity.ts"],"sourcesContent":["import type { Table } from \"@webiny/db-dynamodb/toolbox.js\";\nimport { createStandardEntity } from \"@webiny/db-dynamodb\";\nimport type { ITenantEntity } from \"~/tenancy/definitions/types.js\";\nimport type { Tenant } from \"@webiny/api-core/types/tenancy.js\";\n\ninterface Params {\n entityName: string;\n table: Table<string, string, string>;\n}\nexport const createTenantEntity = ({ entityName, table }: Params): ITenantEntity => {\n return createStandardEntity<Tenant>({\n name: entityName,\n table\n });\n};\n"],"names":["createTenantEntity","entityName","table","createStandardEntity"],"mappings":";AASO,MAAMA,qBAAqB,CAAC,EAAEC,UAAU,EAAEC,KAAK,EAAU,GACrDC,qBAA6B;QAChC,MAAMF;QACNC;IACJ"}
|
package/tenancy/index.js
CHANGED
|
@@ -1,135 +1,115 @@
|
|
|
1
1
|
import { createTable } from "@webiny/db-dynamodb";
|
|
2
|
-
import
|
|
2
|
+
import error from "@webiny/error";
|
|
3
3
|
import { createTenantEntity } from "./definitions/tenantEntity.js";
|
|
4
4
|
import { ENTITIES } from "./types.js";
|
|
5
|
-
const setTenantDefaults = item
|
|
6
|
-
|
|
7
|
-
item.
|
|
8
|
-
|
|
9
|
-
if (!item.description) {
|
|
10
|
-
item.description = "";
|
|
11
|
-
}
|
|
12
|
-
return item;
|
|
5
|
+
const setTenantDefaults = (item)=>{
|
|
6
|
+
if (!item.tags) item.tags = [];
|
|
7
|
+
if (!item.description) item.description = "";
|
|
8
|
+
return item;
|
|
13
9
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
entityName: ENTITIES.TENANT,
|
|
25
|
-
table: tableInstance.table
|
|
26
|
-
})
|
|
27
|
-
};
|
|
28
|
-
return {
|
|
29
|
-
getTable() {
|
|
30
|
-
return tableInstance;
|
|
31
|
-
},
|
|
32
|
-
getEntities() {
|
|
33
|
-
return entities;
|
|
34
|
-
},
|
|
35
|
-
async getTenantsByIds(ids) {
|
|
36
|
-
const batchReader = entities.tenants.createEntityReader({
|
|
37
|
-
read: ids.map(id => {
|
|
38
|
-
return {
|
|
39
|
-
PK: `T#${id}`,
|
|
40
|
-
SK: "A"
|
|
41
|
-
};
|
|
10
|
+
const createStorageOperations = (params)=>{
|
|
11
|
+
const { documentClient } = params;
|
|
12
|
+
const tableInstance = createTable({
|
|
13
|
+
name: process.env.DB_TABLE_TENANCY || process.env.DB_TABLE,
|
|
14
|
+
documentClient
|
|
15
|
+
});
|
|
16
|
+
const entities = {
|
|
17
|
+
tenants: createTenantEntity({
|
|
18
|
+
entityName: ENTITIES.TENANT,
|
|
19
|
+
table: tableInstance.table
|
|
42
20
|
})
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
getTable () {
|
|
24
|
+
return tableInstance;
|
|
25
|
+
},
|
|
26
|
+
getEntities () {
|
|
27
|
+
return entities;
|
|
28
|
+
},
|
|
29
|
+
async getTenantsByIds (ids) {
|
|
30
|
+
const batchReader = entities.tenants.createEntityReader({
|
|
31
|
+
read: ids.map((id)=>({
|
|
32
|
+
PK: `T#${id}`,
|
|
33
|
+
SK: "A"
|
|
34
|
+
}))
|
|
35
|
+
});
|
|
36
|
+
const tenants = await batchReader.execute();
|
|
37
|
+
return tenants.map((item)=>item.data).map((item)=>setTenantDefaults(item));
|
|
38
|
+
},
|
|
39
|
+
async listTenants (params = {}) {
|
|
40
|
+
const { parent } = params;
|
|
41
|
+
const options = {
|
|
42
|
+
index: "GSI1"
|
|
43
|
+
};
|
|
44
|
+
if (parent) options.beginsWith = `T#${parent}#`;
|
|
45
|
+
else options.gt = " ";
|
|
46
|
+
const tenants = await entities.tenants.queryAll({
|
|
47
|
+
partitionKey: "TENANTS",
|
|
48
|
+
options
|
|
49
|
+
});
|
|
50
|
+
return tenants.map((item)=>item.data).map((item)=>setTenantDefaults(item));
|
|
51
|
+
},
|
|
52
|
+
async createTenant (data) {
|
|
53
|
+
const keys = {
|
|
54
|
+
PK: `T#${data.id}`,
|
|
55
|
+
SK: "A",
|
|
56
|
+
GSI1_PK: "TENANTS",
|
|
57
|
+
GSI1_SK: `T#${data.parent}#${data.createdOn}`,
|
|
58
|
+
GSI_TENANT: data.id
|
|
59
|
+
};
|
|
60
|
+
try {
|
|
61
|
+
await entities.tenants.put({
|
|
62
|
+
TYPE: "tenancy.tenant",
|
|
63
|
+
...keys,
|
|
64
|
+
data
|
|
65
|
+
});
|
|
66
|
+
return data;
|
|
67
|
+
} catch (err) {
|
|
68
|
+
throw error.from(err, {
|
|
69
|
+
message: "Could not create tenant record.",
|
|
70
|
+
code: "CREATE_TENANT_ERROR",
|
|
71
|
+
data: {
|
|
72
|
+
keys,
|
|
73
|
+
data
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
async updateTenant (data) {
|
|
79
|
+
const tenantPK = `T#${data.id}`;
|
|
80
|
+
const keys = {
|
|
81
|
+
PK: tenantPK,
|
|
82
|
+
SK: "A",
|
|
83
|
+
GSI1_PK: "TENANTS",
|
|
84
|
+
GSI1_SK: `T#${data.parent}#${data.createdOn}`,
|
|
85
|
+
GSI_TENANT: data.id,
|
|
86
|
+
TYPE: "tenancy.tenant"
|
|
87
|
+
};
|
|
88
|
+
try {
|
|
89
|
+
await entities.tenants.put({
|
|
90
|
+
...keys,
|
|
91
|
+
data
|
|
92
|
+
});
|
|
93
|
+
return data;
|
|
94
|
+
} catch (err) {
|
|
95
|
+
throw error.from(err, {
|
|
96
|
+
message: "Could not update tenant record.",
|
|
97
|
+
code: "CREATE_TENANT_ERROR",
|
|
98
|
+
data: {
|
|
99
|
+
keys,
|
|
100
|
+
data
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
async deleteTenant (id) {
|
|
106
|
+
await entities.tenants.delete({
|
|
107
|
+
PK: `T#${id}`,
|
|
108
|
+
SK: "A"
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
};
|
|
133
112
|
};
|
|
113
|
+
export { createStorageOperations };
|
|
134
114
|
|
|
135
115
|
//# sourceMappingURL=index.js.map
|
package/tenancy/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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,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AAMT,SAAS,OAAO,CAAC,GAAG,CAAC;oBACvB,MAAM;oBACN,GAAGU,IAAI;oBACPD;gBACJ;gBAEA,OAAOA;YACX,EAAE,OAAOE,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBACFD;wBACAD;oBACJ;gBACJ;YACJ;QACJ;QAEA,MAAM,cAAaA,IAAY;YAC3B,MAAMI,WAAW,CAAC,EAAE,EAAEJ,KAAK,EAAE,EAAE;YAE/B,MAAMC,OAAO;gBACT,IAAIG;gBACJ,IAAI;gBACJ,SAAS;gBACT,SAAS,CAAC,EAAE,EAAEJ,KAAK,MAAM,CAAC,CAAC,EAAEA,KAAK,SAAS,EAAE;gBAC7C,YAAYA,KAAK,EAAE;gBACnB,MAAM;YACV;YAEA,IAAI;gBACA,MAAMT,SAAS,OAAO,CAAC,GAAG,CAAC;oBACvB,GAAGU,IAAI;oBACPD;gBACJ;gBACA,OAAOA;YACX,EAAE,OAAOE,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAED;wBAAMD;oBAAK;gBACvB;YACJ;QACJ;QAEA,MAAM,cAAaJ,EAAU;YACzB,MAAML,SAAS,OAAO,CAAC,MAAM,CAAC;gBAC1B,IAAI,CAAC,EAAE,EAAEK,IAAI;gBACb,IAAI;YACR;QACJ;IACJ;AACJ"}
|
package/tenancy/types.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
var types_ENTITIES = /*#__PURE__*/ function(ENTITIES) {
|
|
2
|
+
ENTITIES["TENANT"] = "TenancyTenant";
|
|
3
|
+
return ENTITIES;
|
|
4
4
|
}({});
|
|
5
|
+
export { types_ENTITIES as ENTITIES };
|
|
5
6
|
|
|
6
7
|
//# sourceMappingURL=types.js.map
|
package/tenancy/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"tenancy/types.js","sources":["../../src/tenancy/types.ts"],"sourcesContent":["import type { TenancyStorageOperations } from \"@webiny/api-core/types/tenancy.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\n\nexport enum ENTITIES {\n TENANT = \"TenancyTenant\"\n}\n\nexport interface CreateTenancyStorageOperations {\n (params: { documentClient: DynamoDBDocument }): TenancyStorageOperations;\n}\n"],"names":["ENTITIES"],"mappings":"AAGO,IAAKA,iBAAQA,WAAAA,GAAAA,SAARA,QAAQ;;WAARA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { IEntity, IStandardEntityAttributes } from \"@webiny/db-dynamodb\";\nimport type { AdminUser } from \"@webiny/api-core/types/users.js\";\n\nexport interface IAdminUserEntityAttributes extends IStandardEntityAttributes<AdminUser> {}\n\nexport type IAdminUserEntity = IEntity<IAdminUserEntityAttributes>;\n"],"mappings":"","ignoreList":[]}
|
package/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./createApiCoreDdb.js\";\n"],"mappings":"AAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { IEntity, IStandardEntityAttributes } from \"@webiny/db-dynamodb\";\nimport type { StorageApiKey, StorageRole, StorageTeam } from \"@webiny/api-core/types/security.js\";\n\nexport interface IRoleEntityAttributes extends IStandardEntityAttributes<StorageRole> {\n TYPE: string;\n}\nexport type IRoleEntity = IEntity<IRoleEntityAttributes>;\n\nexport interface ITeamEntityAttributes extends IStandardEntityAttributes<StorageTeam> {\n TYPE: string;\n}\nexport type ITeamEntity = IEntity<ITeamEntityAttributes>;\n\nexport interface IApiKeyEntityAttributes extends IStandardEntityAttributes<StorageApiKey> {\n TYPE: string;\n}\nexport type IApiKeyEntity = IEntity<IApiKeyEntityAttributes>;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { IEntity, IStandardEntityAttributes } from \"@webiny/db-dynamodb\";\nimport type { Tenant } from \"@webiny/api-core/types/tenancy.js\";\n\nexport interface ITenantEntityAttributes extends IStandardEntityAttributes<Tenant> {\n TYPE: string;\n}\n\nexport type ITenantEntity = IEntity<ITenantEntityAttributes>;\n"],"mappings":"","ignoreList":[]}
|