Update api client
This commit is contained in:
@ -1,15 +1,11 @@
|
||||
import axios from 'axios'
|
||||
import { getAuthToken } from './index'
|
||||
|
||||
export const addLabels = async (
|
||||
userId: string,
|
||||
apiEndpoint: string,
|
||||
jwtSecret: string,
|
||||
auth: string,
|
||||
pageId: string,
|
||||
labelIds: string[]
|
||||
) => {
|
||||
const auth = await getAuthToken(userId, jwtSecret)
|
||||
|
||||
const data = JSON.stringify({
|
||||
query: `mutation SetLabels($input: SetLabelsInput!) {
|
||||
setLabels(input: $input) {
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import axios from 'axios'
|
||||
import { getAuthToken } from './index'
|
||||
|
||||
interface NotificationData {
|
||||
body: string
|
||||
@ -10,15 +9,12 @@ interface NotificationData {
|
||||
}
|
||||
|
||||
export const sendNotification = async (
|
||||
userId: string,
|
||||
apiEndpoint: string,
|
||||
jwtSecret: string,
|
||||
auth: string,
|
||||
message: string,
|
||||
title?: string,
|
||||
image?: string
|
||||
) => {
|
||||
const auth = await getAuthToken(userId, jwtSecret)
|
||||
|
||||
const data: NotificationData = {
|
||||
body: message,
|
||||
title: title || message,
|
||||
|
||||
@ -1,30 +1,27 @@
|
||||
import { getAuthToken } from './index'
|
||||
import axios from 'axios'
|
||||
|
||||
export const archivePage = async (
|
||||
pageId: string,
|
||||
userId: string,
|
||||
apiEndpoint: string,
|
||||
jwtSecret: string
|
||||
auth: string
|
||||
) => {
|
||||
const auth = await getAuthToken(userId, jwtSecret)
|
||||
|
||||
const data = JSON.stringify({
|
||||
query: `mutation ArchivePage($input: ArchivePageInput!) {
|
||||
archivePage(input: $input) {
|
||||
... on ArchivePageSuccess {
|
||||
page {
|
||||
id
|
||||
}
|
||||
query: `mutation SetLinkArchived($input: ArchiveLinkInput!) {
|
||||
setLinkArchived(input: $input) {
|
||||
... on ArchiveLinkSuccess {
|
||||
linkId
|
||||
message
|
||||
}
|
||||
... on ArchivePageError {
|
||||
... on ArchiveLinkError {
|
||||
message
|
||||
errorCodes
|
||||
}
|
||||
}
|
||||
}`,
|
||||
variables: {
|
||||
input: {
|
||||
pageId,
|
||||
linkId: pageId,
|
||||
archived: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -43,28 +40,27 @@ export const archivePage = async (
|
||||
|
||||
export const markPageAsRead = async (
|
||||
pageId: string,
|
||||
userId: string,
|
||||
apiEndpoint: string,
|
||||
jwtSecret: string
|
||||
auth: string
|
||||
) => {
|
||||
const auth = await getAuthToken(userId, jwtSecret)
|
||||
|
||||
const data = JSON.stringify({
|
||||
query: `mutation MarkPageAsRead($input: MarkPageAsReadInput!) {
|
||||
markPageAsRead(input: $input) {
|
||||
... on MarkPageAsReadSuccess {
|
||||
page {
|
||||
query: `mutation SaveArticleReadingProgress($input: SaveArticleReadingProgressInput!) {
|
||||
saveArticleReadingProgress(input: $input) {
|
||||
... on SaveArticleReadingProgressSuccess {
|
||||
updatedArticle {
|
||||
id
|
||||
}
|
||||
}
|
||||
... on MarkPageAsReadError {
|
||||
... on SaveArticleReadingProgressError {
|
||||
errorCodes
|
||||
}
|
||||
}
|
||||
}`,
|
||||
variables: {
|
||||
input: {
|
||||
pageId,
|
||||
id: pageId,
|
||||
readingProgressPercent: 100,
|
||||
readingProgressAnchorIndex: 0,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
@ -133,6 +133,8 @@ export const triggerActions = async (
|
||||
continue
|
||||
}
|
||||
|
||||
const authToken = await getAuthToken(userId, jwtSecret)
|
||||
|
||||
for (const action of rule.actions) {
|
||||
switch (action.type) {
|
||||
case RuleActionType.AddLabel:
|
||||
@ -140,31 +142,25 @@ export const triggerActions = async (
|
||||
console.log('invalid data for add label action')
|
||||
continue
|
||||
}
|
||||
await addLabels(
|
||||
userId,
|
||||
apiEndpoint,
|
||||
jwtSecret,
|
||||
data.id,
|
||||
action.params
|
||||
)
|
||||
await addLabels(apiEndpoint, authToken, data.id, action.params)
|
||||
break
|
||||
case RuleActionType.Archive:
|
||||
if (!data.id) {
|
||||
console.log('invalid data for archive action')
|
||||
continue
|
||||
}
|
||||
await archivePage(userId, apiEndpoint, jwtSecret, data.id)
|
||||
await archivePage(apiEndpoint, authToken, data.id)
|
||||
break
|
||||
case RuleActionType.MarkAsRead:
|
||||
if (!data.id) {
|
||||
console.log('invalid data for mark as read action')
|
||||
continue
|
||||
}
|
||||
await markPageAsRead(userId, apiEndpoint, jwtSecret, data.id)
|
||||
await markPageAsRead(apiEndpoint, authToken, data.id)
|
||||
break
|
||||
case RuleActionType.SendNotification:
|
||||
for (const message of action.params) {
|
||||
await sendNotification(userId, apiEndpoint, jwtSecret, message)
|
||||
await sendNotification(apiEndpoint, authToken, message)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user