@qrvey/assets-sharing 0.3.4-dev.2092 → 0.3.4-dev.2153

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/dist/cjs/common/common.type.js +3 -0
  2. package/dist/cjs/common/common.type.js.map +1 -0
  3. package/dist/cjs/common/constants.js +56 -0
  4. package/dist/cjs/common/constants.js.map +1 -0
  5. package/dist/cjs/common/persistence/base.js +15 -0
  6. package/dist/cjs/common/persistence/base.js.map +1 -0
  7. package/dist/cjs/common/persistence/poolClient.js +11 -0
  8. package/dist/cjs/common/persistence/poolClient.js.map +1 -0
  9. package/dist/cjs/common/util.js +12 -0
  10. package/dist/cjs/common/util.js.map +1 -0
  11. package/dist/cjs/context.js +22 -0
  12. package/dist/cjs/context.js.map +1 -0
  13. package/dist/cjs/index.js +43 -0
  14. package/dist/cjs/index.js.map +1 -0
  15. package/dist/cjs/quser/entities/types/user.type.js +3 -0
  16. package/dist/cjs/quser/entities/types/user.type.js.map +1 -0
  17. package/dist/cjs/quser/entities/user.js +25 -0
  18. package/dist/cjs/quser/entities/user.js.map +1 -0
  19. package/dist/cjs/quser/implementations/group.model.js +19 -0
  20. package/dist/cjs/quser/implementations/group.model.js.map +1 -0
  21. package/dist/cjs/quser/implementations/group.repository.js +19 -0
  22. package/dist/cjs/quser/implementations/group.repository.js.map +1 -0
  23. package/dist/cjs/quser/implementations/user.model.js +24 -0
  24. package/dist/cjs/quser/implementations/user.model.js.map +1 -0
  25. package/dist/cjs/quser/implementations/user.repository.js +29 -0
  26. package/dist/cjs/quser/implementations/user.repository.js.map +1 -0
  27. package/dist/cjs/quser/interfaces/rolesRepository.interface.js +3 -0
  28. package/dist/cjs/quser/interfaces/rolesRepository.interface.js.map +1 -0
  29. package/dist/cjs/quser/interfaces/userRepository.interface.js +3 -0
  30. package/dist/cjs/quser/interfaces/userRepository.interface.js.map +1 -0
  31. package/dist/cjs/quser/services/fromTokenToUser.js +52 -0
  32. package/dist/cjs/quser/services/fromTokenToUser.js.map +1 -0
  33. package/dist/cjs/quser/services/hasAdminRole.js +48 -0
  34. package/dist/cjs/quser/services/hasAdminRole.js.map +1 -0
  35. package/{src/sharing/entities/details.ts → dist/cjs/sharing/entities/details.js} +29 -65
  36. package/dist/cjs/sharing/entities/details.js.map +1 -0
  37. package/{src/sharing/entities/sharing.ts → dist/cjs/sharing/entities/sharing.js} +16 -37
  38. package/dist/cjs/sharing/entities/sharing.js.map +1 -0
  39. package/dist/cjs/sharing/entities/types/details.type.js +3 -0
  40. package/dist/cjs/sharing/entities/types/details.type.js.map +1 -0
  41. package/dist/cjs/sharing/entities/types/orgTreeResult.js +3 -0
  42. package/dist/cjs/sharing/entities/types/orgTreeResult.js.map +1 -0
  43. package/dist/cjs/sharing/entities/types/organization.type.js +3 -0
  44. package/dist/cjs/sharing/entities/types/organization.type.js.map +1 -0
  45. package/dist/cjs/sharing/entities/types/sharing.type.js +3 -0
  46. package/dist/cjs/sharing/entities/types/sharing.type.js.map +1 -0
  47. package/dist/cjs/sharing/implementations/admin.repository.js +47 -0
  48. package/dist/cjs/sharing/implementations/admin.repository.js.map +1 -0
  49. package/dist/cjs/sharing/implementations/details.model.js +93 -0
  50. package/dist/cjs/sharing/implementations/details.model.js.map +1 -0
  51. package/dist/cjs/sharing/implementations/details.repository.js +114 -0
  52. package/dist/cjs/sharing/implementations/details.repository.js.map +1 -0
  53. package/dist/cjs/sharing/implementations/dm.model.js +22 -0
  54. package/dist/cjs/sharing/implementations/dm.model.js.map +1 -0
  55. package/dist/cjs/sharing/implementations/dm.repository.js +20 -0
  56. package/dist/cjs/sharing/implementations/dm.repository.js.map +1 -0
  57. package/dist/cjs/sharing/implementations/dx.model.js +30 -0
  58. package/dist/cjs/sharing/implementations/dx.model.js.map +1 -0
  59. package/dist/cjs/sharing/implementations/dx.repository.js +21 -0
  60. package/dist/cjs/sharing/implementations/dx.repository.js.map +1 -0
  61. package/dist/cjs/sharing/implementations/organization.model.js +31 -0
  62. package/dist/cjs/sharing/implementations/organization.model.js.map +1 -0
  63. package/dist/cjs/sharing/implementations/organization.repository.js +66 -0
  64. package/dist/cjs/sharing/implementations/organization.repository.js.map +1 -0
  65. package/dist/cjs/sharing/implementations/sharing.model.js +33 -0
  66. package/dist/cjs/sharing/implementations/sharing.model.js.map +1 -0
  67. package/dist/cjs/sharing/implementations/sharing.repository.js +31 -0
  68. package/dist/cjs/sharing/implementations/sharing.repository.js.map +1 -0
  69. package/dist/cjs/sharing/interfaces/adminRepository.interface.js +3 -0
  70. package/dist/cjs/sharing/interfaces/adminRepository.interface.js.map +1 -0
  71. package/dist/cjs/sharing/interfaces/dashboardRepository.interface.js +3 -0
  72. package/dist/cjs/sharing/interfaces/dashboardRepository.interface.js.map +1 -0
  73. package/dist/cjs/sharing/interfaces/detailsRepository.interface.js +3 -0
  74. package/dist/cjs/sharing/interfaces/detailsRepository.interface.js.map +1 -0
  75. package/dist/cjs/sharing/interfaces/downloadManagerRepository.interface.js +3 -0
  76. package/dist/cjs/sharing/interfaces/downloadManagerRepository.interface.js.map +1 -0
  77. package/dist/cjs/sharing/interfaces/organizationRepository.interface.js +3 -0
  78. package/dist/cjs/sharing/interfaces/organizationRepository.interface.js.map +1 -0
  79. package/dist/cjs/sharing/interfaces/sharingRepository.interface.js +3 -0
  80. package/dist/cjs/sharing/interfaces/sharingRepository.interface.js.map +1 -0
  81. package/dist/cjs/sharing/services/checkAppPermissions.js +45 -0
  82. package/dist/cjs/sharing/services/checkAppPermissions.js.map +1 -0
  83. package/dist/cjs/sharing/services/checkOrgPermissions.js +32 -0
  84. package/dist/cjs/sharing/services/checkOrgPermissions.js.map +1 -0
  85. package/dist/cjs/sharing/services/checkUserAccessLevel.js +58 -0
  86. package/dist/cjs/sharing/services/checkUserAccessLevel.js.map +1 -0
  87. package/dist/cjs/sharing/services/delete.js +32 -0
  88. package/dist/cjs/sharing/services/delete.js.map +1 -0
  89. package/dist/cjs/sharing/services/getOrgTree.js +26 -0
  90. package/dist/cjs/sharing/services/getOrgTree.js.map +1 -0
  91. package/dist/cjs/sharing/services/list.js +44 -0
  92. package/dist/cjs/sharing/services/list.js.map +1 -0
  93. package/dist/cjs/sharing/services/upsert.js +135 -0
  94. package/dist/cjs/sharing/services/upsert.js.map +1 -0
  95. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
  96. package/dist/esm/index.mjs +1198 -0
  97. package/dist/esm/index.mjs.map +1 -0
  98. package/dist/types/index.d.ts +167 -0
  99. package/package.json +7 -2
  100. package/.eslintrc +0 -88
  101. package/__test__/hasAdminRole.test.ts +0 -299
  102. package/jest.config.ts +0 -15
  103. package/src/common/common.type.ts +0 -33
  104. package/src/common/constants.ts +0 -64
  105. package/src/common/persistence/base.ts +0 -13
  106. package/src/common/persistence/poolClient.ts +0 -7
  107. package/src/common/util.ts +0 -8
  108. package/src/context.ts +0 -47
  109. package/src/index.ts +0 -48
  110. package/src/quser/entities/types/user.type.ts +0 -14
  111. package/src/quser/entities/user.ts +0 -31
  112. package/src/quser/implementations/group.model.ts +0 -18
  113. package/src/quser/implementations/group.repository.ts +0 -20
  114. package/src/quser/implementations/user.model.ts +0 -23
  115. package/src/quser/implementations/user.repository.ts +0 -35
  116. package/src/quser/interfaces/rolesRepository.interface.ts +0 -3
  117. package/src/quser/interfaces/userRepository.interface.ts +0 -10
  118. package/src/quser/services/fromTokenToUser.ts +0 -49
  119. package/src/quser/services/hasAdminRole.ts +0 -52
  120. package/src/sharing/entities/types/details.type.ts +0 -58
  121. package/src/sharing/entities/types/organization.type.ts +0 -10
  122. package/src/sharing/entities/types/sharing.type.ts +0 -24
  123. package/src/sharing/implementations/admin.repository.ts +0 -66
  124. package/src/sharing/implementations/details.model.ts +0 -93
  125. package/src/sharing/implementations/details.repository.ts +0 -154
  126. package/src/sharing/implementations/dm.model.ts +0 -21
  127. package/src/sharing/implementations/dm.repository.ts +0 -23
  128. package/src/sharing/implementations/dx.model.ts +0 -30
  129. package/src/sharing/implementations/dx.repository.ts +0 -22
  130. package/src/sharing/implementations/organization.model.ts +0 -32
  131. package/src/sharing/implementations/organization.repository.ts +0 -21
  132. package/src/sharing/implementations/sharing.model.ts +0 -33
  133. package/src/sharing/implementations/sharing.repository.ts +0 -36
  134. package/src/sharing/interfaces/adminRepository.interface.ts +0 -13
  135. package/src/sharing/interfaces/dashboardRepository.interface.ts +0 -3
  136. package/src/sharing/interfaces/detailsRepository.interface.ts +0 -60
  137. package/src/sharing/interfaces/downloadManagerRepository.interface.ts +0 -3
  138. package/src/sharing/interfaces/organizationRepository.interface.ts +0 -5
  139. package/src/sharing/interfaces/sharingRepository.interface.ts +0 -32
  140. package/src/sharing/services/checkAppPermissions.ts +0 -47
  141. package/src/sharing/services/checkOrgPermissions.ts +0 -29
  142. package/src/sharing/services/checkUserAccessLevel.ts +0 -63
  143. package/src/sharing/services/delete.ts +0 -24
  144. package/src/sharing/services/list.ts +0 -53
  145. package/src/sharing/services/upsert.ts +0 -197
  146. package/tsconfig.cjs.json +0 -7
  147. package/tsconfig.json +0 -27
  148. package/tsup.config.cjs.ts +0 -19
  149. package/tsup.config.esm.ts +0 -12
  150. package/tsup.config.types.ts +0 -9
@@ -1,33 +0,0 @@
1
- import { CrudSchema } from '@qrvey/data-persistence';
2
-
3
- import { DATABASE_INFO } from '../../common/constants';
4
-
5
- export class SharingModel extends CrudSchema {
6
- static table = {
7
- name: `${DATABASE_INFO.SERVER_PREFIX}_sharing`,
8
- alias: `${DATABASE_INFO.TABLE_PREFIX}_sharing`,
9
- };
10
-
11
- static columns = {
12
- asset_id: { type: 'string', primary: true },
13
- asset_type: { type: 'string' },
14
- created_at: { type: 'date' },
15
- updated_at: { type: 'date' },
16
- deleted_at: { type: 'date' },
17
- qvAttributes: { type: 'object' },
18
- };
19
-
20
- static indexes = {
21
- sharingAssetIdAssetType: {
22
- name: 'sharing_asset_id_asset_type_index',
23
- columns: ['asset_id', 'asset_type'],
24
- },
25
- sharingAssetType: {
26
- name: 'sharing_asset_type_index',
27
- columns: ['asset_type'],
28
- },
29
- };
30
-
31
- static schema = DATABASE_INFO.DATA_PERSISTENCE_SCHEMA;
32
- static usePool = true;
33
- }
@@ -1,36 +0,0 @@
1
- import { SharingModel } from './sharing.model';
2
- import { BaseRepository } from '../../common/persistence/base';
3
- import { SharingTable } from '../entities/types/sharing.type';
4
- import { SharingRepositoryInterface } from '../interfaces/sharingRepository.interface';
5
-
6
- export class SharingRepository
7
- extends BaseRepository
8
- implements SharingRepositoryInterface
9
- {
10
- constructor() {
11
- super(SharingModel);
12
- }
13
-
14
- async getOne(assetId: string): Promise<SharingTable | null> {
15
- const params = {
16
- filters: [this.filter('asset_id', assetId)],
17
- };
18
- const response = await super.findItem(params);
19
- return response as SharingTable;
20
- }
21
-
22
- async create(sharing: SharingTable): Promise<SharingTable> {
23
- const response = (await super.create(sharing)) as SharingTable;
24
- return response;
25
- }
26
-
27
- async patch(assetId: string, sharing: SharingTable): Promise<boolean> {
28
- await super.update([this.filter('asset_id', assetId)], sharing);
29
- return true;
30
- }
31
-
32
- async delete(assetId: string): Promise<boolean> {
33
- await super.remove([this.filter('asset_id', assetId)]);
34
- return true;
35
- }
36
- }
@@ -1,13 +0,0 @@
1
- import { AppOwner } from '../../common/constants';
2
-
3
- export interface AdminRepositoryInterface {
4
- getApplicationInfo(params: { appId: string; userId: string }): Promise<{
5
- status: number;
6
- data: AppOwner;
7
- }>;
8
-
9
- getPlatformConfiguration(): Promise<{
10
- status: number;
11
- legacyMode: boolean;
12
- }>;
13
- }
@@ -1,3 +0,0 @@
1
- export interface DashboardRepositoryInterface {
2
- get(identifier: string): Promise<{ dashboardId: string } | null>;
3
- }
@@ -1,60 +0,0 @@
1
- import {
2
- ListInput,
3
- ListOutput,
4
- ParamsFromTokenToUser,
5
- } from '../../common/common.type';
6
- import { SharingDetailsTable } from '../entities/types/details.type';
7
-
8
- export interface SharingDetailsRepositoryInterface {
9
- /**
10
- * Retrieves a single sharing detail by its ID.
11
- * @param sharingDetailId - The ID of the sharing detail to retrieve.
12
- * @returns A promise that resolves to the sharing detail or null if not found.
13
- */
14
- getOne(sharingDetailId: string): Promise<SharingDetailsTable | null>;
15
-
16
- /**
17
- * Retrieves a single sharing detail by its asset ID and the user it is shared with.
18
- * @param assetId - The ID of the asset.
19
- * @param sharedWith - The user with whom the asset is shared.
20
- * @returns A promise that resolves to the sharing detail or null if not found.
21
- */
22
- getBySharedWith(
23
- assetId: string,
24
- sharedWith: string,
25
- ): Promise<SharingDetailsTable | null>;
26
-
27
- /**
28
- * Retrieves a list of sharing details based on the provided options.
29
- * @param options - An object containing the asset ID to filter the sharing details.
30
- * @returns A promise that resolves to an array of sharing details.
31
- */
32
- getList(
33
- options: ListInput<{ assetId: string; user?: ParamsFromTokenToUser }>,
34
- ): Promise<ListOutput<SharingDetailsTable>>;
35
-
36
- /**
37
- * Creates a new sharing detail in the repository.
38
- * @param details - The sharing detail to create.
39
- * @returns A promise that resolves to the created sharing detail.
40
- */
41
- create(details: SharingDetailsTable): Promise<SharingDetailsTable>;
42
-
43
- /**
44
- * Updates an existing sharing detail in the repository.
45
- * @param sharingDetailId - The ID of the sharing detail to update.
46
- * @param details - The updated sharing detail.
47
- * @returns A promise that resolves to a boolean indicating success or failure.
48
- */
49
- patch(
50
- sharingDetailId: string,
51
- details: SharingDetailsTable,
52
- ): Promise<boolean>;
53
-
54
- /**
55
- * Deletes a sharing detail from the repository.
56
- * @param sharingDetailId - The ID of the sharing detail to delete.
57
- * @returns A promise that resolves to a boolean indicating success or failure.
58
- */
59
- delete(sharingDetailId: string): Promise<boolean>;
60
- }
@@ -1,3 +0,0 @@
1
- export interface DownloadManagerRepositoryInterface {
2
- get(identifier: string): Promise<{ downloadManagerId: string } | null>;
3
- }
@@ -1,5 +0,0 @@
1
- import { OrganizationType } from '../entities/types/organization.type';
2
-
3
- export interface OrganizationRepositoryInterface {
4
- getOne(orgId: string): Promise<OrganizationType | null>;
5
- }
@@ -1,32 +0,0 @@
1
- import { SharingTable } from '../entities/types/sharing.type';
2
-
3
- export interface SharingRepositoryInterface {
4
- /**
5
- * Retrieves a sharing record by its asset ID.
6
- * @param assetId - The ID of the asset to retrieve.
7
- * @returns A promise that resolves to the sharing record or null if not found.
8
- */
9
- getOne(assetId: string): Promise<SharingTable | null>;
10
-
11
- /**
12
- * Creates a new sharing record.
13
- * @param sharing - The sharing record to create.
14
- * @returns A promise that resolves to the created sharing record.
15
- */
16
- create(sharing: SharingTable): Promise<SharingTable>;
17
-
18
- /**
19
- * Updates a sharing record by its ID.
20
- * @param assetId - The ID of the sharing record to update.
21
- * @param sharing - The updated sharing record.
22
- * @returns A promise that resolves to a boolean indicating whether the update was successful.
23
- */
24
- patch(assetId: string, sharing: SharingTable): Promise<boolean>;
25
-
26
- /**
27
- * Deletes a sharing record by its ID.
28
- * @param assetId - The ID of the sharing record to delete.
29
- * @returns A promise that resolves to a boolean indicating whether the deletion was successful.
30
- */
31
- delete(assetId: string): Promise<boolean>;
32
- }
@@ -1,47 +0,0 @@
1
- import { inject, injectable } from 'tsyringe';
2
-
3
- import {
4
- AppPermissionResponse,
5
- AppSharingStatus,
6
- } from '../../common/constants';
7
- import { AdminRepositoryInterface } from '../interfaces/adminRepository.interface';
8
-
9
- @injectable()
10
- export default class CheckAppPermissions {
11
- constructor(
12
- @inject('AdminRepository')
13
- private readonly adminRepository: AdminRepositoryInterface,
14
- ) {}
15
-
16
- //TODO Need Test
17
- async execute({
18
- appId,
19
- userId,
20
- }: {
21
- appId: string;
22
- userId: string;
23
- }): Promise<AppPermissionResponse> {
24
- // If no user is available, block access by default
25
- if (!userId) return { privacy: AppSharingStatus.PRIVATE };
26
-
27
- // Fetch application status and global platform configuration in parallel
28
- const appInfo = await this.adminRepository.getApplicationInfo({
29
- appId,
30
- userId,
31
- });
32
- const platform = await this.adminRepository.getPlatformConfiguration();
33
-
34
- // Check if the application is shared with the current user
35
- if (appInfo.status !== 200)
36
- return { privacy: AppSharingStatus.PRIVATE };
37
-
38
- // According to QRV-297, the LegacyMode ON will have public access, in future implementation, other options will be added.
39
- const hasPublicAccess = platform?.legacyMode;
40
-
41
- const privacy = hasPublicAccess
42
- ? AppSharingStatus.PUBLIC
43
- : AppSharingStatus.PRIVATE;
44
-
45
- return { privacy };
46
- }
47
- }
@@ -1,29 +0,0 @@
1
- import { inject, injectable } from 'tsyringe';
2
-
3
- import {
4
- AppPermissionResponse,
5
- AppSharingStatus,
6
- } from '../../common/constants';
7
- import { OrganizationRepositoryInterface } from '../interfaces/organizationRepository.interface';
8
-
9
- @injectable()
10
- export default class CheckOrgPermissions {
11
- constructor(
12
- @inject('OrganizationRepository')
13
- private readonly organizationRepository: OrganizationRepositoryInterface,
14
- ) {}
15
-
16
- //TODO Need Tes
17
- async execute({
18
- orgId,
19
- }: {
20
- orgId: string;
21
- }): Promise<AppPermissionResponse> {
22
- const hasPublicAccess = await this.organizationRepository.getOne(orgId);
23
- const privacy = hasPublicAccess?.effective_content_privacy
24
- ? AppSharingStatus.PRIVATE
25
- : AppSharingStatus.PUBLIC;
26
-
27
- return { privacy };
28
- }
29
- }
@@ -1,63 +0,0 @@
1
- import { inject, injectable } from 'tsyringe';
2
-
3
- import { ACCESS_LEVEL, SHARE_TYPE } from '../../common/constants';
4
- import { fromTokenToUser } from '../../index';
5
- import { SharingDetail } from '../entities/details';
6
- import { SharingDetailsRepositoryInterface } from '../interfaces/detailsRepository.interface';
7
-
8
- @injectable()
9
- export class CheckUserAccessLevel {
10
- constructor(
11
- @inject('SharingDetailsRepository')
12
- private readonly detailsRepository: SharingDetailsRepositoryInterface,
13
- ) {}
14
-
15
- public async execute({
16
- userId,
17
- assetId,
18
- clientId,
19
- loginType,
20
- roles,
21
- orgId,
22
- }: {
23
- assetId: string;
24
- userId: string;
25
- clientId?: string;
26
- loginType?: string;
27
- roles?: string[];
28
- orgId?: string;
29
- }): Promise<{ level: ACCESS_LEVEL; levelAsText: string }> {
30
- const user = await fromTokenToUser({
31
- body: { userId, clientId, roles, orgId, loginType },
32
- });
33
- const details = await this.detailsRepository.getList({
34
- data: { assetId, user },
35
- sorting: [{ column: 'access_level', direction: 'DESC' }],
36
- });
37
- if (details.items.length === 0)
38
- return { level: ACCESS_LEVEL.NONE, levelAsText: 'NONE' };
39
-
40
- const priority = {
41
- [SHARE_TYPE.USER]: 3,
42
- [SHARE_TYPE.ROLE]: 2,
43
- [SHARE_TYPE.ORGANIZATION]: 1,
44
- };
45
- const priorityDetail = details.items.reduce((best, current) => {
46
- const bestPriority = priority[best.shared_type as SHARE_TYPE];
47
- const currentPriority = priority[current.shared_type as SHARE_TYPE];
48
- const isBetter =
49
- currentPriority > bestPriority ||
50
- (currentPriority === bestPriority &&
51
- current.access_level > best.access_level);
52
-
53
- if (isBetter) return current;
54
- return best;
55
- });
56
-
57
- const currentDetail = SharingDetail.parse(priorityDetail);
58
- return {
59
- level: currentDetail.getAccessLevel,
60
- levelAsText: currentDetail.getAccessLevelAsText,
61
- };
62
- }
63
- }
@@ -1,24 +0,0 @@
1
- import { inject, injectable } from 'tsyringe';
2
-
3
- import { SharingRepositoryInterface } from '../interfaces/sharingRepository.interface';
4
-
5
- export interface Delete {
6
- assetId: string;
7
- }
8
-
9
- @injectable()
10
- export class DeleteSharing {
11
- constructor(
12
- @inject('SharingRepository')
13
- private readonly sharingRepository: SharingRepositoryInterface,
14
- ) {}
15
-
16
- public async execute({ body }: { body: Delete }): Promise<boolean | null> {
17
- const { assetId } = body;
18
- const sharing = await this.sharingRepository.getOne(assetId);
19
-
20
- if (!sharing) return null;
21
- const detailSharing = await this.sharingRepository.delete(assetId);
22
- return detailSharing;
23
- }
24
- }
@@ -1,53 +0,0 @@
1
- import { inject, injectable } from 'tsyringe';
2
-
3
- import { Sorting } from '../../common/common.type';
4
- import { SharingDetail } from '../entities/details';
5
- import {
6
- GetSharingList,
7
- ListSharingDetails,
8
- SharingDetailsTable,
9
- } from '../entities/types/details.type';
10
- import { SharingDetailsRepositoryInterface } from '../interfaces/detailsRepository.interface';
11
- import { SharingRepositoryInterface } from '../interfaces/sharingRepository.interface';
12
-
13
- @injectable()
14
- export class ListSharing {
15
- constructor(
16
- @inject('SharingRepository')
17
- private readonly sharingRepository: SharingRepositoryInterface,
18
- @inject('SharingDetailsRepository')
19
- private readonly detailsRepository: SharingDetailsRepositoryInterface,
20
- ) {}
21
-
22
- public async execute({
23
- body,
24
- }: {
25
- body: GetSharingList;
26
- }): Promise<ListSharingDetails | null> {
27
- const {
28
- data: { assetId },
29
- pagination,
30
- } = body;
31
- const sharing = await this.sharingRepository.getOne(assetId);
32
-
33
- if (!sharing) return null;
34
-
35
- const sorting: Array<Sorting> =
36
- body.sorting && body.sorting?.length > 0
37
- ? body.sorting
38
- : [{ column: 'created_at', direction: 'ASC' }];
39
-
40
- const detailSharing = await this.detailsRepository.getList({
41
- data: { assetId },
42
- pagination,
43
- sorting,
44
- });
45
- const items = detailSharing.items.map((item) =>
46
- SharingDetail.parse(item as SharingDetailsTable).toJSON(),
47
- );
48
- return {
49
- ...detailSharing,
50
- items,
51
- };
52
- }
53
- }
@@ -1,197 +0,0 @@
1
- import { inject, injectable } from 'tsyringe';
2
-
3
- import {
4
- ACCESS_LEVEL,
5
- ASSET_TYPE,
6
- ORGANIZATION_QRVEY,
7
- SHARED_ORIGIN,
8
- SHARE_TYPE,
9
- } from '../../common/constants';
10
- import { RoleRepositoryInterface } from '../../quser/interfaces/rolesRepository.interface';
11
- import { UserRepositoryInterface } from '../../quser/interfaces/userRepository.interface';
12
- import { SharingDetail } from '../entities/details';
13
- import { Sharing } from '../entities/sharing';
14
- import { ResponseSharingDetails } from '../entities/types/details.type';
15
- import { DashboardRepositoryInterface } from '../interfaces/dashboardRepository.interface';
16
- import { SharingDetailsRepositoryInterface } from '../interfaces/detailsRepository.interface';
17
- import { DownloadManagerRepositoryInterface } from '../interfaces/downloadManagerRepository.interface';
18
- import { SharingRepositoryInterface } from '../interfaces/sharingRepository.interface';
19
-
20
- interface SharingWith {
21
- sharedId?: string;
22
- sharedWith: string;
23
- sharedOrigin: SHARED_ORIGIN;
24
- accessLevel: ACCESS_LEVEL;
25
- orgId?: string;
26
- sharedEmail?: string;
27
- sharedType: SHARE_TYPE;
28
- }
29
-
30
- export interface UpsertInterface {
31
- assetId: string;
32
- assetType: ASSET_TYPE;
33
- add?: Array<SharingWith>;
34
- remove?: Array<{
35
- sharedId: string;
36
- }>;
37
- }
38
-
39
- @injectable()
40
- export class UpsertSharing {
41
- constructor(
42
- @inject('SharingRepository')
43
- private readonly sharingRepository: SharingRepositoryInterface,
44
- @inject('SharingDetailsRepository')
45
- private readonly detailsRepository: SharingDetailsRepositoryInterface,
46
- @inject('dxRepository')
47
- private readonly dxRepository: DashboardRepositoryInterface,
48
- @inject('dmRepository')
49
- private readonly dmRepository: DownloadManagerRepositoryInterface,
50
- @inject('UserRepository')
51
- private readonly userRepository: UserRepositoryInterface,
52
- @inject('RoleRepository')
53
- private readonly roleRepository: RoleRepositoryInterface,
54
- ) {}
55
-
56
- public async execute({
57
- body,
58
- }: {
59
- body: UpsertInterface;
60
- }): Promise<ResponseSharingDetails[]> {
61
- const assetId = body.assetId;
62
-
63
- const isValidAsset = await this.validateIfAssetExists(
64
- assetId,
65
- body.assetType,
66
- );
67
- if (!isValidAsset)
68
- throw new Error(`Asset with ID ${assetId} not found`);
69
-
70
- const sharing = await this.sharingRepository.getOne(assetId);
71
- let currentSharing: Sharing;
72
- if (sharing) {
73
- currentSharing = Sharing.parse(sharing);
74
- } else {
75
- const createSharing = {
76
- assetId,
77
- assetType: body.assetType,
78
- };
79
- currentSharing = Sharing.create(createSharing);
80
- await this.sharingRepository.create(currentSharing.toTable());
81
- }
82
-
83
- let updatedList: SharingDetail[] = [];
84
- if (body.add) updatedList = await this.addDetails(assetId, body.add);
85
- if (body.remove) await this.removeDetails(body.remove);
86
-
87
- currentSharing.update();
88
- await this.sharingRepository.patch(
89
- currentSharing.getAssetId,
90
- currentSharing.toTable(),
91
- );
92
- return updatedList.map((detail) => detail.toJSON());
93
- }
94
-
95
- private async validateIfAssetExists(
96
- assetId: string,
97
- assetType: ASSET_TYPE,
98
- ): Promise<boolean> {
99
- switch (assetType) {
100
- case ASSET_TYPE.DX: {
101
- const result = await this.dxRepository.get(assetId);
102
- if (result) return true;
103
- return false;
104
- }
105
- case ASSET_TYPE.DM: {
106
- return true;
107
- }
108
-
109
- default:
110
- return false;
111
- }
112
- }
113
-
114
- private async addDetails(
115
- assetId: string,
116
- list: Required<UpsertInterface>['add'],
117
- ): Promise<SharingDetail[]> {
118
- const sharingList: SharingDetail[] = [];
119
- for (const detail of list) {
120
- const currentDetail = await this.addSpecificDetail(assetId, detail);
121
- if (currentDetail) sharingList.push(currentDetail);
122
- }
123
- return sharingList;
124
- }
125
-
126
- private async addSpecificDetail(
127
- assetId: string,
128
- detail: SharingWith,
129
- ): Promise<SharingDetail | null> {
130
- let currentDetail: SharingDetail;
131
- const isValid = await this.validateIfSharedWithExist(detail);
132
- if (!isValid) return null;
133
-
134
- let sharingDetail = await this.detailsRepository.getBySharedWith(
135
- assetId,
136
- detail.sharedWith,
137
- );
138
- if (!sharingDetail && detail.sharedId) {
139
- sharingDetail = await this.detailsRepository.getOne(
140
- detail.sharedId,
141
- );
142
- }
143
-
144
- if (sharingDetail) {
145
- currentDetail = SharingDetail.parse(sharingDetail);
146
- currentDetail.update(detail);
147
- await this.detailsRepository.patch(
148
- currentDetail.getSharingDetailsId,
149
- currentDetail.toTable(),
150
- );
151
- } else {
152
- const createDetails = {
153
- assetId: assetId,
154
- orgId: detail.orgId ?? ORGANIZATION_QRVEY, //TODO If shareOrigin is INTERNAL then `ORGANIZATION_QRVEY` else fail
155
- ...detail,
156
- };
157
- currentDetail = SharingDetail.create(createDetails);
158
- await this.detailsRepository.create(currentDetail.toTable());
159
- }
160
- return currentDetail;
161
- }
162
-
163
- private async validateIfSharedWithExist(
164
- detail: SharingWith,
165
- ): Promise<boolean> {
166
- if (
167
- detail.sharedOrigin === SHARED_ORIGIN.EXTERNAL ||
168
- detail.sharedOrigin === SHARED_ORIGIN.UNKNOWN
169
- )
170
- return true;
171
-
172
- const isQrveyOrg =
173
- detail.sharedType === SHARE_TYPE.ORGANIZATION &&
174
- detail.sharedWith === ORGANIZATION_QRVEY;
175
- if (isQrveyOrg) return true; // NOTE: If more Internal Organization arrive, need to change this validation
176
-
177
- if (detail.sharedType === SHARE_TYPE.USER) {
178
- const user = await this.userRepository.getOne(detail.sharedWith);
179
- if (user) return true;
180
- }
181
-
182
- if (detail.sharedType === SHARE_TYPE.ROLE) {
183
- const role = await this.roleRepository.getOne(detail.sharedWith);
184
- if (role) return true;
185
- }
186
-
187
- return false;
188
- }
189
-
190
- private async removeDetails(
191
- list: Required<UpsertInterface>['remove'],
192
- ): Promise<void> {
193
- for (const detail of list) {
194
- await this.detailsRepository.delete(detail.sharedId);
195
- }
196
- }
197
- }
package/tsconfig.cjs.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./dist/cjs",
5
- "module": "commonjs"
6
- }
7
- }
package/tsconfig.json DELETED
@@ -1,27 +0,0 @@
1
- {
2
- "extends": "tsconfig/tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./dist",
5
- "experimentalDecorators": true
6
- },
7
- "references": [
8
- {
9
- "path": "../id-generator"
10
- },
11
- {
12
- "path": "../data-persistence"
13
- }
14
- ],
15
- "include": [
16
- "src/index.ts"
17
- ],
18
- "exclude": [
19
- "dist",
20
- "build",
21
- "node_modules",
22
- "coverage",
23
- "**/*.test.ts",
24
- "**/*.test.d.ts",
25
- "**/*.spec.ts"
26
- ]
27
- }
@@ -1,19 +0,0 @@
1
- import { defineConfig } from 'tsup';
2
-
3
- export default defineConfig({
4
- entryPoints: ['./src/index.ts'],
5
- bundle: true,
6
- minify: false,
7
- format: ['cjs'],
8
- treeshake: true,
9
- sourcemap: true,
10
- outDir: 'dist/cjs',
11
- references: [
12
- {
13
- path: "../id-generator"
14
- },
15
- {
16
- path: "../data-persistence"
17
- }
18
- ],
19
- });
@@ -1,12 +0,0 @@
1
- import { defineConfig } from 'tsup';
2
-
3
- export default defineConfig({
4
- entryPoints: ['./src/index.ts'],
5
- bundle: true,
6
- minify: false,
7
- format: ['esm'],
8
- treeshake: true,
9
- sourcemap: true,
10
- dts: false,
11
- outDir: 'dist/esm',
12
- });