add state to the integration handler request payload
This commit is contained in:
@ -6,13 +6,14 @@ import * as jwt from 'jsonwebtoken'
|
||||
import { DateTime } from 'luxon'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { getIntegrationClient, updateIntegration } from './integrations'
|
||||
import { State } from './integrations/integration'
|
||||
import { search } from './item'
|
||||
|
||||
interface IntegrationRequest {
|
||||
integrationId: string
|
||||
syncAt: number // unix timestamp in milliseconds
|
||||
integrationName: string
|
||||
includeArchived?: boolean
|
||||
state?: State
|
||||
}
|
||||
|
||||
interface Claims {
|
||||
@ -230,7 +231,7 @@ export const importer = Sentry.GCPFunction.wrapHttpFunction(
|
||||
token: claims.token,
|
||||
since,
|
||||
offset,
|
||||
includeArchived: req.body.includeArchived,
|
||||
state: req.body.state,
|
||||
})
|
||||
syncedAt = retrieved.since || Date.now()
|
||||
retrievedData = retrieved.data
|
||||
|
||||
@ -1,5 +1,12 @@
|
||||
import { Item } from '../item'
|
||||
|
||||
export enum State {
|
||||
ARCHIVED = 'ARCHIVED',
|
||||
UNREAD = 'UNREAD',
|
||||
UNARCHIVED = 'UNARCHIVED',
|
||||
ALL = 'ALL',
|
||||
}
|
||||
|
||||
export interface RetrievedData {
|
||||
url: string
|
||||
labels?: string[]
|
||||
@ -16,7 +23,7 @@ export interface RetrieveRequest {
|
||||
since?: number // unix timestamp in milliseconds
|
||||
count?: number
|
||||
offset?: number
|
||||
includeArchived?: boolean
|
||||
state?: State
|
||||
}
|
||||
|
||||
export abstract class IntegrationClient {
|
||||
|
||||
@ -3,6 +3,7 @@ import {
|
||||
IntegrationClient,
|
||||
RetrievedResult,
|
||||
RetrieveRequest,
|
||||
State,
|
||||
} from './integration'
|
||||
|
||||
interface PocketResponse {
|
||||
@ -60,7 +61,8 @@ export class PocketClient extends IntegrationClient {
|
||||
accessToken: string,
|
||||
since: number, // unix timestamp in seconds
|
||||
count = 100,
|
||||
offset = 0
|
||||
offset = 0,
|
||||
state = 'all'
|
||||
): Promise<PocketResponse | null> => {
|
||||
const url = `${this.apiUrl}/get`
|
||||
try {
|
||||
@ -69,7 +71,7 @@ export class PocketClient extends IntegrationClient {
|
||||
{
|
||||
consumer_key: process.env.POCKET_CONSUMER_KEY,
|
||||
access_token: accessToken,
|
||||
state: 'all',
|
||||
state,
|
||||
detailType: 'complete',
|
||||
since,
|
||||
sort: 'oldest',
|
||||
@ -95,13 +97,25 @@ export class PocketClient extends IntegrationClient {
|
||||
since = 0,
|
||||
count = 100,
|
||||
offset = 0,
|
||||
includeArchived = false,
|
||||
state = State.UNARCHIVED,
|
||||
}: RetrieveRequest): Promise<RetrievedResult> => {
|
||||
let pocketItemState = 'all'
|
||||
|
||||
switch (state) {
|
||||
case State.ARCHIVED:
|
||||
pocketItemState = 'archive'
|
||||
break
|
||||
case State.UNREAD:
|
||||
pocketItemState = 'unread'
|
||||
break
|
||||
}
|
||||
|
||||
const pocketData = await this.retrievePocketData(
|
||||
token,
|
||||
since / 1000,
|
||||
count,
|
||||
offset
|
||||
offset,
|
||||
pocketItemState
|
||||
)
|
||||
if (!pocketData) {
|
||||
throw new Error('Error retrieving pocket data')
|
||||
@ -125,7 +139,8 @@ export class PocketClient extends IntegrationClient {
|
||||
if (item.state === 'DELETED') {
|
||||
return false
|
||||
}
|
||||
return includeArchived || item.state !== 'ARCHIVED'
|
||||
|
||||
return state !== State.UNARCHIVED || item.state !== 'ARCHIVED'
|
||||
})
|
||||
|
||||
if (pocketData.error) {
|
||||
|
||||
Reference in New Issue
Block a user