@messenger-box/platform-client 10.0.3-alpha.17 → 10.0.3-alpha.171

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 (128) hide show
  1. package/lib/graphql/fragments/post-message.gql +36 -0
  2. package/lib/graphql/id-generation.js.map +1 -1
  3. package/lib/graphql/index.js.map +1 -1
  4. package/lib/graphql/mutations/channel-mutation.gql +5 -0
  5. package/lib/graphql/mutations/messages-mutation.gql +3 -0
  6. package/lib/graphql/policies/channel-policies.d.ts.map +1 -1
  7. package/lib/graphql/policies/channel-policies.js +150 -2
  8. package/lib/graphql/policies/channel-policies.js.map +1 -1
  9. package/lib/graphql/policies/messages-policies.d.ts.map +1 -1
  10. package/lib/graphql/policies/messages-policies.js +229 -37
  11. package/lib/graphql/policies/messages-policies.js.map +1 -1
  12. package/lib/graphql/policies/post-thread-policies.d.ts.map +1 -1
  13. package/lib/graphql/policies/post-thread-policies.js +136 -31
  14. package/lib/graphql/policies/post-thread-policies.js.map +1 -1
  15. package/lib/graphql/policies/posts-policies.js.map +1 -1
  16. package/lib/graphql/policies/teams-policies.d.ts.map +1 -1
  17. package/lib/graphql/policies/teams-policies.js +13 -1
  18. package/lib/graphql/policies/teams-policies.js.map +1 -1
  19. package/lib/graphql/policies/user-account-policies.js.map +1 -1
  20. package/lib/graphql/policies/user-policies.js.map +1 -1
  21. package/lib/graphql/queries/channels-by-user.gql +26 -0
  22. package/lib/graphql/queries/messages.gql +2 -2
  23. package/lib/graphql/queries/organization-query.gql +70 -35
  24. package/lib/graphql/queries/post-thread-message.gql +4 -0
  25. package/lib/graphql/queries/teams-query.gql +29 -29
  26. package/lib/graphql/queries/user-account.gql +1 -1
  27. package/lib/graphql/queries/users.gql +1 -1
  28. package/lib/graphql/schema/index.js.map +1 -1
  29. package/lib/graphql/subscription/fileUpdated.gql +11 -0
  30. package/lib/hooks/use-base-file-upload.hook.d.ts.map +1 -1
  31. package/lib/hooks/use-upload-file.hook.d.ts +1 -1
  32. package/lib/hooks/use-upload-file.hook.d.ts.map +1 -1
  33. package/lib/hooks/use-upload-file.hook.js +1 -1
  34. package/lib/hooks/use-upload-file.hook.js.map +1 -1
  35. package/lib/hooks/use-upload-file.hook.native.d.ts +1 -1
  36. package/lib/hooks/use-upload-file.hook.native.d.ts.map +1 -1
  37. package/lib/hooks/use-upload-file.hook.native.js +1 -1
  38. package/lib/hooks/use-upload-file.hook.native.js.map +1 -1
  39. package/lib/hooks/use-upload-files.hook.d.ts +1 -1
  40. package/lib/hooks/use-upload-files.hook.d.ts.map +1 -1
  41. package/lib/hooks/use-upload-files.hook.js +1 -1
  42. package/lib/hooks/use-upload-files.hook.js.map +1 -1
  43. package/lib/hooks/use-upload-files.hook.native.d.ts +1 -1
  44. package/lib/hooks/use-upload-files.hook.native.d.ts.map +1 -1
  45. package/lib/hooks/use-upload-files.hook.native.js +1 -1
  46. package/lib/hooks/use-upload-files.hook.native.js.map +1 -1
  47. package/lib/utils/index.d.ts.map +1 -1
  48. package/lib/utils/index.js.map +1 -1
  49. package/package.json +4 -4
  50. package/CHANGELOG.md +0 -141
  51. package/jest.config.js +0 -25
  52. package/rollup.config.mjs +0 -36
  53. package/src/graphql/fragments/configuration.gql +0 -12
  54. package/src/graphql/fragments/extended-user-account.gql +0 -10
  55. package/src/graphql/fragments/file-info.gql +0 -12
  56. package/src/graphql/fragments/messenger-user.gql +0 -15
  57. package/src/graphql/fragments/minimal-user.gql +0 -9
  58. package/src/graphql/fragments/post-message.gql +0 -116
  59. package/src/graphql/fragments/post-thread-message.gql +0 -77
  60. package/src/graphql/fragments/user.gql +0 -11
  61. package/src/graphql/id-generation.ts +0 -8
  62. package/src/graphql/index.ts +0 -24
  63. package/src/graphql/mutations/channel-mutation.gql +0 -72
  64. package/src/graphql/mutations/expo-notification-token.gql +0 -13
  65. package/src/graphql/mutations/message-threads-mutation.gql +0 -44
  66. package/src/graphql/mutations/messages-mutation.gql +0 -110
  67. package/src/graphql/mutations/messages-mutation.gql.bk +0 -66
  68. package/src/graphql/mutations/organization-mutation.gql.bk +0 -14
  69. package/src/graphql/mutations/teams-mutation.gql.bk +0 -8
  70. package/src/graphql/policies/channel-policies.ts +0 -7
  71. package/src/graphql/policies/index.ts +0 -7
  72. package/src/graphql/policies/messages-policies.ts +0 -109
  73. package/src/graphql/policies/post-thread-policies.ts +0 -59
  74. package/src/graphql/policies/posts-policies.ts +0 -110
  75. package/src/graphql/policies/teams-policies.ts +0 -7
  76. package/src/graphql/policies/user-account-policies.ts +0 -15
  77. package/src/graphql/policies/user-policies.ts +0 -32
  78. package/src/graphql/queries/channel.gql +0 -57
  79. package/src/graphql/queries/channels-by-user.gql +0 -60
  80. package/src/graphql/queries/check-for-new-messages.gql +0 -5
  81. package/src/graphql/queries/file-url.gql +0 -5
  82. package/src/graphql/queries/get-device-token.gql +0 -8
  83. package/src/graphql/queries/messages.gql +0 -28
  84. package/src/graphql/queries/organization-query.gql +0 -90
  85. package/src/graphql/queries/post-message.gql +0 -8
  86. package/src/graphql/queries/post-thread-message.gql +0 -20
  87. package/src/graphql/queries/support-service-channels.gql +0 -18
  88. package/src/graphql/queries/teams-query.gql +0 -32
  89. package/src/graphql/queries/user-account.gql +0 -5
  90. package/src/graphql/queries/users.gql +0 -48
  91. package/src/graphql/schema/index.ts +0 -6
  92. package/src/graphql/schema/messages.graphql +0 -5
  93. package/src/graphql/schema/post.graphql +0 -44
  94. package/src/graphql/schema/services.graphql +0 -6
  95. package/src/graphql/schema/user-account.graphql +0 -3
  96. package/src/graphql/subscription/chat-message-added.gql +0 -6
  97. package/src/graphql/subscription/public-post-added.gql +0 -5
  98. package/src/graphql/subscription/thread-chat-message-added.gql +0 -5
  99. package/src/graphql/subscription/thread-created-updated.gql +0 -12
  100. package/src/hooks/index.ts +0 -4
  101. package/src/hooks/use-base-file-upload.hook.ts +0 -148
  102. package/src/hooks/use-upload-file.hook.native.ts +0 -22
  103. package/src/hooks/use-upload-file.hook.ts +0 -22
  104. package/src/hooks/use-upload-files.hook.native.ts +0 -22
  105. package/src/hooks/use-upload-files.hook.ts +0 -22
  106. package/src/index.ts +0 -3
  107. package/src/inversify-containers/index.ts +0 -1
  108. package/src/inversify-containers/module.ts +0 -4
  109. package/src/packages/constants/constants.ts +0 -1831
  110. package/src/packages/types/channels.ts +0 -194
  111. package/src/packages/types/emojis.ts +0 -41
  112. package/src/packages/types/files.ts +0 -43
  113. package/src/packages/types/posts.ts +0 -155
  114. package/src/packages/types/reactions.ts +0 -8
  115. package/src/packages/types/teams.ts +0 -109
  116. package/src/packages/types/utilities.ts +0 -30
  117. package/src/services/index.ts +0 -0
  118. package/src/tests/mutation/__snapshots__/set-device-token.test.ts.snap +0 -18
  119. package/src/tests/mutation/set-device-token.test.ts +0 -85
  120. package/src/utils/constants.tsx +0 -1120
  121. package/src/utils/i18n.tsx +0 -15
  122. package/src/utils/index.ts +0 -34
  123. package/src/utils/post_list.ts +0 -54
  124. package/src/utils/post_utils.ts +0 -33
  125. package/src/utils/user_agent.tsx +0 -153
  126. package/src/utils/utils.tsx +0 -54
  127. package/tsconfig.json +0 -14
  128. package/webpack.config.js +0 -58
@@ -1,60 +0,0 @@
1
- query GetChannelsByUser($role: String, $criteria: AnyObject, $limit: Int, $skip: Int, $sort: Sort) {
2
- channelsByUser(role: $role, criteria: $criteria, limit: $limit, skip: $skip, sort: $sort) {
3
- id
4
- title
5
- description
6
- type
7
- displayName
8
- members {
9
- id
10
- user {
11
- ...MessengerUser
12
- }
13
- }
14
- creator {
15
- ...MessengerUser
16
- }
17
- createdAt
18
- updatedAt
19
- }
20
- }
21
-
22
-
23
-
24
- query GetChannelsByUserWithServiceChannels($role: String, $criteria: AnyObject, $supportServiceCriteria: AnyObject, $limit: Int, $skip: Int, $sort: Sort,$supportServices:Boolean = true) {
25
- supportServiceChannels(role: $role, criteria: $supportServiceCriteria, limit: $limit, skip: $skip, sort: $sort) @include(if: $supportServices) {
26
- id
27
- title
28
- description
29
- type
30
- displayName
31
- members {
32
- id
33
- user {
34
- ...MessengerUser
35
- }
36
- }
37
- creator {
38
- ...MessengerUser
39
- }
40
- }
41
- channelsByUser(role: $role, criteria: $criteria, limit: $limit, skip: $skip, sort: $sort) {
42
- id
43
- title
44
- description
45
- type
46
- displayName
47
- members {
48
- id
49
- user {
50
- ...MessengerUser
51
- }
52
- }
53
- creator {
54
- ...MessengerUser
55
- }
56
- createdAt
57
- updatedAt
58
- }
59
- }
60
-
@@ -1,5 +0,0 @@
1
- query CheckForNewMessages($channelId: ID,$parentId: String) {
2
- messages(channelId: $channelId,parentId:$parentId, limit: 0){
3
- totalCount
4
- }
5
- }
@@ -1,5 +0,0 @@
1
- query FileUrl($id: ID!){
2
- fileInfo(id: $id) {
3
- url
4
- }
5
- }
@@ -1,8 +0,0 @@
1
- query GetDeviceToken {
2
- getDeviceToken {
3
- tokens {
4
- token
5
- type
6
- }
7
- }
8
- }
@@ -1,28 +0,0 @@
1
- query Messages($channelId: ID,$parentId: String, $limit: Int! = 10, $skip: Int! = 0, $sort: Sort) {
2
- messages(channelId: $channelId,parentId:$parentId, limit: $limit, skip: $skip, sort: $sort) @connection(key: "messages", filter: ["channelId","skip"]){
3
- messagesRefId @client
4
- data{
5
- ...Post
6
- }
7
- totalCount
8
- }
9
- }
10
-
11
- query PostThreadMessages($channelId: ID,$parentId: String, $limit: Int! = 10, $skip: Int! = 0, $sort: Sort) {
12
- messages(channelId: $channelId,parentId:$parentId, limit: $limit, skip: $skip, sort: $sort) @connection(key: "threadposts", filter: ["channelId","parentId",,"skip"]) {
13
- threadmessagesRefId @client
14
- data{
15
- ...Post
16
- }
17
- totalCount
18
- }
19
- }
20
-
21
- query PublicMessages($channelId: ID!) {
22
- publicMessages(channelId: $channelId) {
23
- totalCount
24
- data {
25
- ...Post
26
- }
27
- }
28
- }
@@ -1,90 +0,0 @@
1
- query GetOrganizationDetail($where: OrgDetailWhere!) {
2
- getOrganizationDetail(where: $where) {
3
- createdAt
4
- description
5
- id
6
- invitations {
7
- active
8
- acceptedAt
9
- createdAt
10
- email
11
- fullName
12
- id
13
- invitedBy
14
- teamId
15
- updatedAt
16
- tokenExpiration
17
- role
18
- inviteCount
19
- }
20
- name
21
- orgMembers {
22
- crossCheckEmail
23
- inactive
24
- orgName
25
- user {
26
- email
27
- alias
28
- emailVerified
29
- id
30
- username
31
- }
32
- roles
33
- userId
34
- }
35
- orgUserCount
36
- periodStart
37
- periodStop
38
- picture
39
- status
40
- title
41
- updatedAt
42
- }
43
- }
44
-
45
-
46
-
47
-
48
- query GetOrganizationMembersWithChannels($orgName: String,$role: String, $channelCriteria: AnyObject,$offset: Int, $limit: Int, $sort: Sort) {
49
- getOrganizationMembers(offset: $offset, limit: $limit, orgName: $orgName) {
50
- totalCount
51
- data {
52
- userId
53
- roles
54
- user {
55
- id
56
- givenName
57
- familyName
58
- picture
59
- username
60
- email
61
- alias
62
- }
63
- teamNames
64
- }
65
- }
66
- channelsByUser(role: $role, criteria: $channelCriteria, limit: $limit, skip: $offset, sort: $sort) {
67
- id
68
- title
69
- description
70
- orgName
71
- type
72
- displayName
73
- members {
74
- id
75
- user {
76
- ...MessengerUser
77
- }
78
- }
79
- creator {
80
- ...MessengerUser
81
- }
82
- createdAt
83
- updatedAt
84
- }
85
- }
86
-
87
- query GetOrganizationSharableLink($teamId: String) {
88
- getOrganizationSharableLink(teamId: $teamId)
89
- }
90
-
@@ -1,8 +0,0 @@
1
- query GetMessages($channelId: ID,$parentId: String, $limit: Int! = 30, $skip: Int! = 0) {
2
- messages(channelId: $channelId,parentId:$parentId, limit: $limit, skip: $skip) {
3
- totalCount
4
- data {
5
- ...Post
6
- }
7
- }
8
- }
@@ -1,20 +0,0 @@
1
- query ThreadMessages($channelId: ID, $postParentId: ID,$selectedFields: String, $role: String, $participantsIds: [String], $limit: Int, $skip: Int,$isServiceThreads: Boolean,$repliesLimit2: Int, $repliesSkip2: Int) {
2
- threadMessages(channelId: $channelId, postParentId: $postParentId, selectedFields: $selectedFields, role: $role,participantsIds:$participantsIds, limit: $limit, skip: $skip,isServiceThreads: $isServiceThreads) {
3
- totalCount
4
- data {
5
- ...PostThreadWithoutReplies
6
- replies(limit: $repliesLimit2, skip: $repliesSkip2) {
7
- ...PostWithoutReplies
8
- }
9
- }
10
- }
11
- }
12
-
13
- query GetPostThread($postThreadId: ID, $channelId: ID, $postParentId: ID, $role: String, $participantsIds: [String], $selectedFields: String, $limit: Int, $skip: Int, $sort: Sort ,$isServiceThreads: Boolean) {
14
- getPostThread(postThreadId: $postThreadId, channelId: $channelId, postParentId: $postParentId, role: $role, participantsIds: $participantsIds, selectedFields: $selectedFields,isServiceThreads: $isServiceThreads) {
15
- ...PostThreadWithoutReplies
16
- replies(limit: $limit, skip: $skip, sort: $sort) {
17
- ...PostWithoutReplies
18
- }
19
- }
20
- }
@@ -1,18 +0,0 @@
1
- query SupportServiceChannels($role: String, $criteria: AnyObject, $limit: Int, $skip: Int, $sort: Sort) {
2
- supportServiceChannels(role: $role, criteria: $criteria, limit: $limit, skip: $skip, sort: $sort) {
3
- id
4
- title
5
- description
6
- type
7
- displayName
8
- members {
9
- id
10
- user {
11
- ...MessengerUser
12
- }
13
- }
14
- creator {
15
- ...MessengerUser
16
- }
17
- }
18
- }
@@ -1,32 +0,0 @@
1
-
2
-
3
- query GetOrganizationTeam($orgName: String!, $teamName: String!) {
4
- getTeam(orgName: $orgName, teamName: $teamName) {
5
- title
6
- orgName
7
- name
8
- id
9
- createdAt
10
- updatedAt
11
- _id
12
- teamMembers:members {
13
- id
14
- name
15
- email
16
- username
17
- userId
18
- status
19
- role
20
- }
21
- members {
22
- id
23
- name
24
- email
25
- username
26
- userId
27
- status
28
- role
29
- }
30
- }
31
- }
32
-
@@ -1,5 +0,0 @@
1
- query UserAccount($userId:String!){
2
- getUserAccount(userId:$userId ){
3
- ...MessengerUser
4
- }
5
- }
@@ -1,48 +0,0 @@
1
- query GetAllUsers {
2
- getUsers {
3
- ...MinimalUser
4
- }
5
- }
6
-
7
- query GetUserById($userId: String!) {
8
- getUserAccount(userId: $userId) {
9
- ...MinimalUser
10
- }
11
- }
12
-
13
- query UsersToChat($auth0Id: String!) {
14
- usersToChat(auth0Id: $auth0Id) {
15
- ...MinimalUser
16
- }
17
- }
18
-
19
- query CurrentUser($auth0Id: String!) {
20
- currentUser(auth0Id: $auth0Id) {
21
- ...MinimalUser
22
- }
23
- }
24
-
25
-
26
-
27
- # query GetOrganizationMembers($offset: Int, $limit: Int, $orgName: String) {
28
- # getOrganizationMembers(offset: $offset, limit: $limit, orgName: $orgName) {
29
- # totalCount
30
- # data {
31
- # _id
32
- # userId
33
- # name
34
- # email
35
- # role
36
- # user {
37
- # id
38
- # givenName
39
- # familyName
40
- # picture
41
- # username
42
- # email
43
- # alias
44
- # }
45
- # teamNames
46
- # }
47
- # }
48
- # }
@@ -1,6 +0,0 @@
1
- import postSchema from './post.graphql';
2
- import userAccountSchema from './user-account.graphql'
3
- import messagesSchema from './messages.graphql'
4
-
5
- const schema = [postSchema,userAccountSchema,messagesSchema];
6
- export { schema };
@@ -1,5 +0,0 @@
1
- extend type Messages {
2
- id: String
3
- messagesRefId:String
4
- threadmessagesRefId:String
5
- }
@@ -1,44 +0,0 @@
1
-
2
-
3
- extend type Post {
4
- isPinned: Boolean @client
5
- disableGroupHighlight: Boolean @client
6
- fromBot: Boolean @client
7
-
8
- """ Set to center the post """
9
- center: Boolean @client
10
-
11
- """ Set to render post compactly """
12
- compactDisplay: Boolean @client
13
-
14
- """ Set to render a preview of the parent post above this reply """
15
- isFirstReply: Boolean @client
16
-
17
- """ Set to highlight the background of the post """
18
- shouldHighlight: Boolean @client
19
-
20
- """ Set to render this post as if it was attached to the previous post """
21
- consecutivePostByUser: Boolean @client
22
-
23
- """ Set if the previous post is a comment """
24
- previousPostIsComment: Boolean @client
25
-
26
- togglePostMenu: Boolean @client
27
-
28
- """ Set to render this comment as a mention """
29
- isCommentMention: Boolean @client
30
-
31
- """ If the post has replies """
32
- hasReplies: Boolean @client
33
-
34
- """ To check if the current post is last in the list """
35
- isLastPost: Boolean @client
36
-
37
- """ Whether or not the channel that contains this post is archived """
38
- channelArchived: Boolean @client
39
-
40
- """ Set to mark the post as flagged """
41
- isFlagged: Boolean @client
42
-
43
- isCollapsedThreadsEnabled: Boolean @client
44
- }
@@ -1,6 +0,0 @@
1
- extend enum ClientCacheTypeNames {
2
- Post
3
- Channel
4
- ChannelMember
5
- UserAccount
6
- }
@@ -1,3 +0,0 @@
1
- extend type UserAccount {
2
- fullName: String
3
- }
@@ -1,6 +0,0 @@
1
-
2
- subscription onChatMessageAdded ($channelId: String, $directTo: String) {
3
- chatMessageAdded (channelId: $channelId, directTo: $directTo) {
4
- ...Post
5
- }
6
- }
@@ -1,5 +0,0 @@
1
- subscription onPublicPostAdded ($channelId: String!) {
2
- publicPostAdded(channelId: $channelId) {
3
- ...Post
4
- }
5
- }
@@ -1,5 +0,0 @@
1
- subscription onThreadChatMessageAdded($channelId: String, $postParentId: String) {
2
- threadChatMessageAdded(channelId: $channelId, postParentId: $postParentId) {
3
- ...Post
4
- }
5
- }
@@ -1,12 +0,0 @@
1
- subscription onThreadCreatedUpdated($channelId: String, $postParentId: String) {
2
- threadCreatedUpdated(channelId: $channelId, postParentId: $postParentId) {
3
- isCreated
4
- isUpdated
5
- lastMessage {
6
- ...PostWithoutReplies
7
- }
8
- data {
9
- ...PostThread
10
- }
11
- }
12
- }
@@ -1,4 +0,0 @@
1
- export { useUploadFile } from './use-upload-file.hook';
2
- export { useUploadFiles } from './use-upload-files.hook';
3
- export { useUploadFile as useUploadFileNative } from './use-upload-file.hook.native';
4
- export { useUploadFiles as useUploadFilesNative } from './use-upload-files.hook.native';
@@ -1,148 +0,0 @@
1
- import { ApolloError } from '@apollo/client';
2
- import { ImageInfo } from 'expo-image-picker';
3
- import { useCallback } from 'react';
4
- import { ApolloClient, NetworkStatus } from '@apollo/client/core';
5
- import { BaseMutationOptions } from '@apollo/client/react/types/types';
6
- import { IFileInfo, IUploadedFileInput } from 'common';
7
-
8
- export interface IStartUploadResponse<T = IFileInfo> {
9
- data?: Omit<T, 'createdAt' | 'updatedAt'>;
10
- urls?: string[];
11
- error: ApolloError;
12
- }
13
-
14
- export interface CustomBlob extends Blob {
15
- name: string;
16
- width: number;
17
- height: number;
18
- }
19
-
20
- export interface IStartUploadOptions<C, S> {
21
- file: ImageInfo | ImageInfo[];
22
- createUploadLink?: {
23
- variables: C;
24
- } & BaseMutationOptions<any, C>;
25
- saveUploadedFile?: {
26
- variables: S;
27
- } & BaseMutationOptions<any, S>;
28
- }
29
-
30
- export interface IUseUploadFileResponse<C, S> {
31
- startUpload: <T = IFileInfo>(options: IStartUploadOptions<C, S>) => Promise<IStartUploadResponse<T>>;
32
- loading: boolean;
33
- error: ApolloError;
34
- networkStatus: NetworkStatus;
35
- client: ApolloClient<any>;
36
- called: boolean;
37
- }
38
-
39
- export interface IUseUploadFileOptions<C, S> {
40
- createUploadLink: {
41
- name: string;
42
- mutation: any;
43
- processVariables: (file: CustomBlob | CustomBlob[], variables?: C) => Record<string, unknown>;
44
- };
45
- saveUploadedFile: {
46
- name: string;
47
- mutation: any;
48
- processVariables: (file: IUploadedFileInput | IUploadedFileInput[], variables?: S) => Record<string, unknown>;
49
- };
50
- }
51
-
52
- export const useBaseUploadFile = <C, S>(options: IUseUploadFileOptions<C, S>): IUseUploadFileResponse<C, S> => {
53
- const { createUploadLink: createLink, saveUploadedFile } = options;
54
- const [createUploadLink, { loading: linkLoading, error: linkError }] = createLink.mutation();
55
- const [attachFile, { loading: fileStoring, error: fileSaveError, ...rest }] = saveUploadedFile.mutation();
56
-
57
- const startUpload = useCallback(async (options: IStartUploadOptions<C, S>): Promise<IStartUploadResponse> => {
58
- try {
59
- const {
60
- file,
61
- createUploadLink: createUploadLinkOptions,
62
- saveUploadedFile: saveUploadedFileOptions,
63
- } = options;
64
-
65
- const blobs = await Promise.all(
66
- (Array.isArray(file) ? file : [file]).map(async ({ uri }) => {
67
- const res = await fetch(uri);
68
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
- const blob: any = await res.blob();
70
- // eslint-disable-next-line no-underscore-dangle
71
- const { name, size, type: mimeType, width, height } = blob._data;
72
- blob.name = name;
73
- blob.width = width;
74
- blob.height = height;
75
- blob.mimeType = mimeType;
76
- blob.mimeType = size;
77
- return blob;
78
- }),
79
- );
80
- const { variables: createUploadLinkVariables, ...restCreateUploadLinkOptions } =
81
- createUploadLinkOptions || {};
82
- const { data: link, errors: linkErrors } = await createUploadLink({
83
- variables: createLink.processVariables(
84
- Array.isArray(file) ? blobs : blobs[0],
85
- createUploadLinkVariables,
86
- ),
87
- ...restCreateUploadLinkOptions,
88
- });
89
- if (linkErrors) {
90
- return { error: linkErrors[0] };
91
- }
92
- const uploadLinks: string[] = Array.isArray(link[createLink.name])
93
- ? link[createLink.name]
94
- : [link[createLink.name]];
95
- const urls = await Promise.all(
96
- uploadLinks.map(async (link, index) => {
97
- const response = await fetch(link, {
98
- method: 'PUT',
99
- body: blobs[index],
100
- });
101
- if (response.status !== 200) {
102
- return undefined;
103
- }
104
- return link;
105
- }),
106
- );
107
- const filesInfo: IUploadedFileInput[] = await Promise.all(
108
- blobs.map(async (i, index) => {
109
- // eslint-disable-next-line no-underscore-dangle
110
- const { name, size, type: mimeType, width, height } = (i as any)._data;
111
- const url = urls[index];
112
- return {
113
- name,
114
- size,
115
- mimeType,
116
- url,
117
- width,
118
- height,
119
- };
120
- }),
121
- );
122
- const { variables: saveUploadedFileVariables, ...restSaveUploadedFileOptions } =
123
- saveUploadedFileOptions || {};
124
- const { data: attachedFile, errors: attachFileErrors } = await attachFile({
125
- variables: saveUploadedFile.processVariables(
126
- Array.isArray(file) ? filesInfo : filesInfo[0],
127
- saveUploadedFileVariables,
128
- ),
129
- ...restSaveUploadedFileOptions,
130
- });
131
-
132
- return {
133
- data: attachedFile[saveUploadedFile.name],
134
- urls,
135
- error: attachFileErrors ? attachFileErrors[0] : null,
136
- };
137
- } catch (e) {
138
- console.error(e);
139
- }
140
- }, []);
141
-
142
- return {
143
- startUpload,
144
- loading: linkLoading || fileStoring,
145
- error: linkError || fileSaveError,
146
- ...rest,
147
- };
148
- };
@@ -1,22 +0,0 @@
1
- import { useUploadFile as useBaseUploadFile } from '@container-stack/file-info-client/lib/hooks/use-file-upload.native.js';
2
- import { useAttachUploadedFileToMessageMutation, useCreateMessageFileUploadLinkMutation } from 'common/graphql';
3
-
4
- export const useUploadFile = (): ReturnType<typeof useBaseUploadFile> =>
5
- useBaseUploadFile({
6
- createUploadLink: {
7
- name: 'createMessageFileUploadLink',
8
- mutation: useCreateMessageFileUploadLinkMutation,
9
- processVariables: (file, variables) => ({
10
- filename: Array.isArray(file) ? file[0]?.name : file.name,
11
- ...(typeof variables === 'object' ? variables : {}),
12
- }),
13
- },
14
- saveUploadedFile: {
15
- name: 'attachUploadedFileToMessage',
16
- mutation: useAttachUploadedFileToMessageMutation,
17
- processVariables: (file, variables) => ({
18
- file,
19
- ...(typeof variables === 'object' ? variables : {}),
20
- }),
21
- },
22
- });
@@ -1,22 +0,0 @@
1
- import { useUploadFile as useBaseUploadFile } from '@container-stack/file-info-client/lib/hooks/use-upload-file.js';
2
- import { useAttachUploadedFileToMessageMutation, useCreateMessageFileUploadLinkMutation } from 'common/graphql';
3
-
4
- export const useUploadFile = (): ReturnType<typeof useBaseUploadFile> =>
5
- useBaseUploadFile({
6
- createUploadLink: {
7
- name: 'createMessageFileUploadLink',
8
- mutation: useCreateMessageFileUploadLinkMutation,
9
- processVariables: (file, variables) => ({
10
- filename: Array.isArray(file) ? file[0]?.name : file.name,
11
- ...(typeof variables === 'object' ? variables : {}),
12
- }),
13
- },
14
- saveUploadedFile: {
15
- name: 'attachUploadedFileToMessage',
16
- mutation: useAttachUploadedFileToMessageMutation,
17
- processVariables: (file, variables) => ({
18
- file,
19
- ...(typeof variables === 'object' ? variables : {}),
20
- }),
21
- },
22
- });
@@ -1,22 +0,0 @@
1
- import { useUploadFile } from '@container-stack/file-info-client/lib/hooks/use-file-upload.native.js';
2
- import { useAttachUploadedFilesToMessageMutation, useCreateMessageFilesUploadLinkMutation } from 'common/graphql';
3
-
4
- export const useUploadFiles = (): ReturnType<typeof useUploadFile> =>
5
- useUploadFile({
6
- createUploadLink: {
7
- name: 'createMessageFilesUploadLink',
8
- mutation: useCreateMessageFilesUploadLinkMutation,
9
- processVariables: (files, variables) => ({
10
- filenames: Array.isArray(files) ? files.map((file) => file.name) : [files.name],
11
- ...(typeof variables === 'object' ? variables : {}),
12
- }),
13
- },
14
- saveUploadedFile: {
15
- name: 'attachUploadedFilesToMessage',
16
- mutation: useAttachUploadedFilesToMessageMutation,
17
- processVariables: (files, variables) => ({
18
- files,
19
- ...(typeof variables === 'object' ? variables : {}),
20
- }),
21
- },
22
- });