@jsb188/graphql 1.0.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/cache/utils.ts ADDED
@@ -0,0 +1,56 @@
1
+ import type { ServerErrorObj } from '../types.d';
2
+
3
+ const TIME_TRACKER = new Map();
4
+
5
+ /**
6
+ * Check if data should be refetched based on time
7
+ */
8
+
9
+ export function checkIfNeedsRefetch(qryName: string, id: string, threshold: number = 3.6e+6): boolean {
10
+ const lastFetched = TIME_TRACKER.get(`${qryName}_${id}`);
11
+ if (!lastFetched) {
12
+ return true;
13
+ }
14
+
15
+ const now = Date.now();
16
+ const diff = now - lastFetched;
17
+
18
+ return diff > threshold;
19
+ }
20
+
21
+ /**
22
+ * Set fetched time
23
+ */
24
+
25
+ export function setFetchedTime(qryName: string, id: string, setOnlyIfUndefined: boolean = false) {
26
+ const key = `${qryName}_${id}`;
27
+ if (
28
+ !setOnlyIfUndefined ||
29
+ !TIME_TRACKER.get(key)
30
+ ) {
31
+ TIME_TRACKER.set(key, Date.now());
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Helper; check if normalized error is an error from the server (such as network error)
37
+ */
38
+
39
+ export function isServerError(error: ServerErrorObj): boolean {
40
+ return !!error && (
41
+ error.statusCode === 500 ||
42
+ error.errorCode === '30000' ||
43
+ error.errorCode === 'network_error'
44
+ );
45
+ }
46
+
47
+ /**
48
+ * Helper; check if error is network or developer error
49
+ */
50
+
51
+ export function isServerErrorGQL(apiResult: any): boolean {
52
+ return (
53
+ apiResult?.errors?.find((e: ServerErrorObj) => e.errorCode === '30000') ||
54
+ apiResult?.error?.errorCode === 'network_error'
55
+ );
56
+ }
@@ -0,0 +1,8 @@
1
+ export const authFragment = `fragment authFragment on Auth {
2
+ token
3
+ activated
4
+ hasPassword
5
+ stickySection
6
+ birthdate
7
+ version
8
+ }`;
@@ -0,0 +1,25 @@
1
+ export const platformProductFragment = `fragment platformProductFragment on PlatformProduct {
2
+ id
3
+ active
4
+ prices {
5
+ id
6
+ name
7
+ productName
8
+ productGroup
9
+ unitAmount
10
+ currency
11
+ recurringInterval
12
+ recurringIntervalCount
13
+ }
14
+ }`;
15
+
16
+ export const platformProductPurchaseResultFragment = `fragment platformProductPurchaseResultFragment on PlatformProductPurchaseResult {
17
+ id
18
+ userId
19
+ coins
20
+ productName
21
+ productGroup
22
+ paid
23
+ cancelled
24
+ expireAt
25
+ }`;
@@ -0,0 +1,15 @@
1
+ export const cardFragment = `fragment cardFragment on Card {
2
+ id
3
+ title
4
+ }`;
5
+
6
+ export const linkFragment = `fragment linkFragment on Link {
7
+ id
8
+ relatedId
9
+ text
10
+ url
11
+ type
12
+ photoUri
13
+ broken
14
+ order
15
+ }`;
@@ -0,0 +1,98 @@
1
+ // NOTE: Can't use "hasAccess" here; because live chats need participants[] data in back-end
2
+ // NOTE: "chatFragment" is used in lists, "chatPartial" is used in chat main
3
+ export const chatFragment = `fragment chatFragment on Chat {
4
+ id
5
+ ownerId
6
+ name
7
+ note
8
+ deleted
9
+ photoUri
10
+ unread
11
+ pinned
12
+
13
+ type
14
+ status
15
+ liveCategory
16
+
17
+ theme {
18
+ id
19
+ name
20
+ backgroundPhotoUri
21
+ }
22
+
23
+ lastMessage
24
+ lastMessageAt
25
+ lastMessageUserId
26
+ lastMessageDisplayName
27
+ lastMessagePhotoUri
28
+ lastMessageIsSelf
29
+ }`;
30
+
31
+ export const chatStickerFragment = `fragment chatStickerFragment on ChatSticker {
32
+ id
33
+ code
34
+ photoId
35
+ photoUri
36
+ }`;
37
+
38
+ // NOTE: "chatFragment" is used in lists, "chatPartial" is used in chat main
39
+ export const chatPartial = `fragment chatPartial on Chat {
40
+ id
41
+ ownerId
42
+ name
43
+ note
44
+ deleted
45
+ photoUri
46
+ unread
47
+ hasAccess
48
+
49
+ type
50
+ status
51
+ liveCategory
52
+
53
+ theme {
54
+ id
55
+ name
56
+ backgroundPhotoUri
57
+ }
58
+
59
+ stickers {
60
+ id
61
+ code
62
+ photoId
63
+ photoUri
64
+ }
65
+ }`;
66
+
67
+ export const chatStatusPartial = `fragment chatStatusPartial on Chat {
68
+ id
69
+ unread
70
+ pinned
71
+ status
72
+ }`;
73
+
74
+ export const chatMessageFragment = `fragment chatMessageFragment on ChatMessage {
75
+ id
76
+ userId
77
+ aiId
78
+
79
+ displayName
80
+ photoUri
81
+ plusStatus
82
+ badge
83
+ message
84
+ attachmentUri
85
+ interactionType
86
+
87
+ metaData {
88
+ stickers
89
+ }
90
+
91
+ createdAt
92
+ updatedAt
93
+ }`;
94
+
95
+ export const chatUserStatusFragment = `fragment chatUserStatusFragment on ChatUserStatus {
96
+ id
97
+ onlineStatus
98
+ }`;
@@ -0,0 +1,21 @@
1
+ export const emailFragment = `fragment emailFragment on Email {
2
+ id
3
+ address
4
+ verified
5
+ }`;
6
+
7
+ export const phoneFragment = `fragment phoneFragment on Phone {
8
+ id
9
+ number
10
+ verified
11
+ }`;
12
+
13
+ export const alertFragment = `fragment alertFragment on Alert {
14
+ id
15
+ relatedId
16
+ relatedUserId
17
+ type
18
+ value
19
+ createdAt
20
+ updatedAt
21
+ }`;
@@ -0,0 +1,69 @@
1
+ export const userFragment = `fragment userFragment on User {
2
+ id
3
+ username
4
+ displayName
5
+ moderator
6
+ deleted
7
+ plusStatus
8
+ onlineStatus
9
+ statusMessage
10
+
11
+ theme {
12
+ id
13
+ name
14
+ backgroundPhotoId
15
+ backgroundPhotoUri
16
+ }
17
+
18
+ profile {
19
+ id
20
+ description
21
+ pronouns
22
+ photoId
23
+ photoUri
24
+ backgroundPhotoId
25
+ backgroundPhotoUri
26
+ adult
27
+ }
28
+ }`;
29
+
30
+ export const userPartial = `fragment userPartial on User {
31
+ id
32
+ displayName
33
+ username
34
+ onlineStatus
35
+ plusStatus
36
+ statusMessage
37
+
38
+ profile {
39
+ id
40
+ photoId
41
+ photoUri
42
+ description
43
+ }
44
+ }`;
45
+
46
+ export const friendFragment = `fragment friendFragment on Friend {
47
+ id
48
+ chatId
49
+ myStatus
50
+ otherStatus
51
+ activityAt
52
+ }`;
53
+
54
+ export const plusFragment = `fragment plusFragment on UserPlus {
55
+ id
56
+ checkedAt
57
+ expireAt
58
+ cancelled
59
+ type
60
+ badge
61
+ }`;
62
+
63
+ export const userPersonaFragment = `fragment userPersonaFragment on UserPersona {
64
+ id
65
+ order
66
+ name
67
+ photoId
68
+ photoUri
69
+ }`;
@@ -0,0 +1,197 @@
1
+ import { gql } from 'graphql-tag';
2
+ import { emailFragment, phoneFragment } from '../fragments/otherFragments';
3
+ import { plusFragment, userFragment, userPersonaFragment } from '../fragments/userFragments';
4
+ import { authFragment } from '../fragments/authFragments';
5
+
6
+ const signInResultText = `...authFragment
7
+
8
+ user {
9
+ ...userFragment
10
+ lightMode
11
+
12
+ plus {
13
+ ...plusFragment
14
+ }
15
+
16
+ email {
17
+ ...emailFragment
18
+ }
19
+
20
+ phone {
21
+ ...phoneFragment
22
+ }
23
+
24
+ personas {
25
+ ...userPersonaFragment
26
+ }
27
+ }`;
28
+
29
+ const signInFragments = `
30
+ ${authFragment}
31
+ ${userFragment}
32
+ ${plusFragment}
33
+ ${emailFragment}
34
+ ${userPersonaFragment}
35
+ ${phoneFragment}
36
+ `;
37
+
38
+ export const signInWithTokenMtn = gql`
39
+ mutation signInWithToken (
40
+ $token: Token!
41
+ ) {
42
+ signInWithToken (
43
+ token: $token
44
+ ) {
45
+ ${signInResultText}
46
+ }
47
+ }
48
+ ${signInFragments}
49
+ `;
50
+
51
+ export const checkUsernameOrEmailMtn = gql`
52
+ mutation checkUsernameOrEmail (
53
+ $usernameOrEmail: String!
54
+ $authCheck: Boolean
55
+ ) {
56
+ checkUsernameOrEmail (
57
+ usernameOrEmail: $usernameOrEmail
58
+ authCheck: $authCheck
59
+ ) {
60
+ value
61
+ type
62
+ taken
63
+ }
64
+ }`;
65
+
66
+ export const emailVerificationStatusMtn = gql`
67
+ mutation emailVerificationStatus (
68
+ $token: Token!
69
+ ) {
70
+ emailVerificationStatus (
71
+ token: $token
72
+ )
73
+ }`;
74
+
75
+ export const sendEmailVerificationMtn = gql`
76
+ mutation sendEmailVerification (
77
+ $userId: UserID!
78
+ $email: String!
79
+ ) {
80
+ sendEmailVerification (
81
+ userId: $userId
82
+ email: $email
83
+ ) {
84
+ token
85
+ userId
86
+ username
87
+ emailAddress
88
+ }
89
+ }`;
90
+
91
+ export const signUpMtn = gql`
92
+ mutation signUp (
93
+ $email: String!
94
+ $displayName: String!
95
+ $username: String!
96
+ $password: String!
97
+ ) {
98
+ signUp (
99
+ email: $email
100
+ displayName: $displayName
101
+ username: $username
102
+ password: $password
103
+ ) {
104
+ token
105
+ userId
106
+ username
107
+ emailAddress
108
+ }
109
+ }
110
+ `;
111
+
112
+ export const signOutMtn = gql`
113
+ mutation signOut {
114
+ signOut
115
+ }
116
+ `;
117
+
118
+ export const updateAppSettingsMtn = gql`
119
+ mutation updateAppSettings (
120
+ $stickySection: StickySection
121
+ ) {
122
+ updateAppSettings (
123
+ stickySection: $stickySection
124
+ ) {
125
+ stickySection
126
+ }
127
+ }
128
+ `;
129
+
130
+ export const signInMtn = gql`
131
+ mutation signIn (
132
+ $usernameOrEmail: String!
133
+ $password: String!
134
+ ) {
135
+ signIn (
136
+ usernameOrEmail: $usernameOrEmail,
137
+ password: $password
138
+ ) {
139
+ ${signInResultText}
140
+ }
141
+ }
142
+ ${signInFragments}
143
+ `;
144
+
145
+ export const signInWithGoogleMtn = gql`
146
+ mutation signInWithGoogle (
147
+ $oauthToken: String!
148
+ ) {
149
+ signInWithGoogle (
150
+ oauthToken: $oauthToken
151
+ ) {
152
+ ${signInResultText}
153
+ }
154
+ }
155
+ ${signInFragments}
156
+ `;
157
+
158
+ export const signInWithDiscordMtn = gql`
159
+ mutation signInWithDiscord (
160
+ $oauthToken: String!
161
+ ) {
162
+ signInWithDiscord (
163
+ oauthToken: $oauthToken
164
+ ) {
165
+ ${signInResultText}
166
+ }
167
+ }
168
+ ${signInFragments}
169
+ `;
170
+
171
+ export const signInWithAppleMtn = gql`
172
+ mutation signInWithApple (
173
+ $code: String!
174
+ $idToken: String!
175
+ ) {
176
+ signInWithApple (
177
+ code: $code
178
+ idToken: $idToken
179
+ ) {
180
+ ${signInResultText}
181
+ }
182
+ }
183
+ ${signInFragments}
184
+ `;
185
+
186
+ export const changePasswordMtn = gql`
187
+ mutation changePassword (
188
+ $currentPassword: String!
189
+ $password: String!
190
+ $passwordRepeat: String!
191
+ ) {
192
+ changePassword (
193
+ currentPassword: $currentPassword
194
+ password: $password
195
+ passwordRepeat: $passwordRepeat
196
+ )
197
+ }`;
@@ -0,0 +1,34 @@
1
+ import { gql } from 'graphql-tag';
2
+ import { platformProductPurchaseResultFragment } from '../fragments/billingFragments';
3
+
4
+ export const purchasePlatformProductMtn = gql`
5
+ mutation purchasePlatformProduct (
6
+ $paymentId: String!
7
+ $paymentMethodId: String!
8
+ $productGroup: PlatformProductGroup!
9
+ $email: String!
10
+ $name: String
11
+ ) {
12
+ purchasePlatformProduct (
13
+ paymentId: $paymentId
14
+ paymentMethodId: $paymentMethodId
15
+ productGroup: $productGroup
16
+ email: $email
17
+ name: $name
18
+ ) {
19
+ ...platformProductPurchaseResultFragment
20
+ }
21
+ }
22
+
23
+ ${platformProductPurchaseResultFragment}
24
+ `;
25
+
26
+ export const cancelPlatformSubscriptionMtn = gql`
27
+ mutation cancelPlatformSubscription {
28
+ cancelPlatformSubscription {
29
+ ...platformProductPurchaseResultFragment
30
+ }
31
+ }
32
+
33
+ ${platformProductPurchaseResultFragment}
34
+ `;
@@ -0,0 +1,116 @@
1
+ import { gql } from 'graphql-tag';
2
+ import { chatPartial, chatStatusPartial, chatStickerFragment } from '../fragments/chatFragments';
3
+
4
+ export const editChatMtn = gql`
5
+ mutation editChat (
6
+ $chatId: GenericID!
7
+ $name: String
8
+ $note: String
9
+ $liveCategory: LiveCategory
10
+ $theme: ThemeInput
11
+ ) {
12
+ editChat (
13
+ chatId: $chatId
14
+ name: $name
15
+ note: $note
16
+ liveCategory: $liveCategory
17
+ theme: $theme
18
+ ) {
19
+ ...chatPartial
20
+ }
21
+ }
22
+
23
+ ${chatPartial}
24
+ `;
25
+
26
+ export const editChatStatusMtn = gql`
27
+ mutation editChatStatus (
28
+ $chatId: GenericID!
29
+ $unread: Boolean
30
+ $pinned: Boolean
31
+ $status: ChatStatus
32
+ ) {
33
+ editChatStatus (
34
+ chatId: $chatId
35
+ unread: $unread
36
+ pinned: $pinned
37
+ status: $status
38
+ ) {
39
+ ...chatStatusPartial
40
+ }
41
+ }
42
+
43
+ ${chatStatusPartial}
44
+ `;
45
+
46
+ export const createLiveChatMtn = gql`
47
+ mutation createLiveChat (
48
+ $name: String!
49
+ ) {
50
+ createLiveChat (
51
+ name: $name
52
+ )
53
+ }
54
+ `;
55
+
56
+ export const editCoOwnerMtn = gql`
57
+ mutation editCoOwner (
58
+ $chatId: GenericID!
59
+ $userId: UserID!
60
+ $remove: Boolean
61
+ ) {
62
+ editCoOwner (
63
+ chatId: $chatId
64
+ userId: $userId
65
+ remove: $remove
66
+ )
67
+ }
68
+ `;
69
+
70
+ export const editChatStickerMtn = gql`
71
+ mutation editChatSticker (
72
+ $stickerId: GenericID!
73
+ $photoId: GenericID
74
+ $code: String
75
+ ) {
76
+ editChatSticker (
77
+ stickerId: $stickerId
78
+ photoId: $photoId
79
+ code: $code
80
+ ) {
81
+ ...chatStickerFragment
82
+ }
83
+ }
84
+
85
+ ${chatStickerFragment}
86
+ `;
87
+
88
+ export const deleteChatStickerMtn = gql`
89
+ mutation deleteChatSticker (
90
+ $stickerId: GenericID!
91
+ ) {
92
+ deleteChatSticker (
93
+ stickerId: $stickerId
94
+ )
95
+ }
96
+ `;
97
+
98
+ export const createChatStickerMtn = gql`
99
+ mutation createChatSticker (
100
+ $chatId: GenericID!
101
+ $photoId: GenericID!
102
+ $code: String!
103
+ $coverPhoto: Boolean
104
+ ) {
105
+ createChatSticker (
106
+ chatId: $chatId
107
+ photoId: $photoId
108
+ code: $code
109
+ coverPhoto: $coverPhoto
110
+ ) {
111
+ ...chatStickerFragment
112
+ }
113
+ }
114
+
115
+ ${chatStickerFragment}
116
+ `;
@@ -0,0 +1,46 @@
1
+ import { gql } from 'graphql-tag';
2
+ import { alertFragment } from '../fragments/otherFragments';
3
+
4
+ export const prepareFileUploadMtn = gql`
5
+ mutation prepareFileUpload (
6
+ $files: [FilePrepareInput]!
7
+ ) {
8
+ prepareFileUpload (
9
+ files: $files
10
+ ) {
11
+ id
12
+ fileName
13
+ uri
14
+ token
15
+ }
16
+ }
17
+ `;
18
+
19
+ export const finishFileUploadMtn = gql`
20
+ mutation finishFileUpload (
21
+ $fileIds: [GenericID]!
22
+ ) {
23
+ finishFileUpload (
24
+ fileIds: $fileIds
25
+ ) {
26
+ id
27
+ uri
28
+ }
29
+ }
30
+ `;
31
+
32
+ export const alertCallToActionMtn = gql`
33
+ mutation alertCallToAction (
34
+ $alertId: GenericID!
35
+ $approve: Boolean!
36
+ ) {
37
+ alertCallToAction (
38
+ alertId: $alertId
39
+ approve: $approve
40
+ ) {
41
+ ...alertFragment
42
+ }
43
+ }
44
+
45
+ ${alertFragment}
46
+ `;