@benshi.ai/js-sdk
Version:
Benshi SDK
106 lines (97 loc) • 3.74 kB
text/typescript
import { NetworkProxy } from "../../../drivers/network/typings"
import { CTAType, INudgesRepository, Nudge } from "./typings"
export default class NudgesRepository implements INudgesRepository {
private apiURL
private networkDriver
public constructor(url: string, bsNetwork: NetworkProxy) {
this.apiURL = url
this.networkDriver = bsNetwork
}
public getNudges = async (userId: string): Promise<Nudge[]> => {
const now = new Date()
const expiryTime = new Date()
const seconds = now.getSeconds()
now.setSeconds(seconds + 5) // Date already takes into account changes in minutes ou hours
expiryTime.setSeconds(seconds + 15) // Date already takes into account changes in minutes ou hours
return [
{
id: 111,
"ref_type": "adp",
"ref_id": 233,
dispatched_at: now.toISOString(),
expire_at: expiryTime.toISOString(),
action: {
"id": 366,
"org_proj": "demo_sdkd",
"name": "-",
"description": "-",
"tags": [],
"type": "push_notification",
"target_cohort_ids": [],
call_to_action: {
type: CTAType.Redirect,
cta_resource: {
type: '',
id: '45'
}
},
definition: {
title: 'click to open itemId ---a',
body: '[111] Test Notification Demo Apps <ul><li>Risperdal Tablet222</li><li>Zolpidem Tablet</li></ul>'
},
"uses": 36,
"created_by": "",
"created_at": "2022-07-28T14:15:52.147502Z",
"resolve_detail": {
"ids": [
"6sJlS8aOLg904e4OUIdB",
"f5EUnyo33LyIMWHVDJev"
]
}
},
},
{
"id": 1776100,
"action": {
"id": 365,
"org_proj": "demo_sdkd",
"name": "-",
"description": "-",
"tags": [],
"type": "push_notification",
"target_cohort_ids": [],
"definition": {
"title": "item pair test",
"body": " Zolpidem Tablet Promethazine",
},
"uses": 36,
"created_by": "",
"created_at": "2022-07-28T14:15:52.147502Z",
"call_to_action": {
"type": CTAType.AddToCart,
"cta_resource": {
"type": "drug",
"id": "f5EUnyo33LyIMWHVDJev"
}
},
"resolve_detail": {
"ids": [
"6sJlS8aOLg904e4OUIdB",
"f5EUnyo33LyIMWHVDJev"
]
}
},
"ref_type": "adp",
"ref_id": 233,
dispatched_at: now.toISOString(),
expire_at: expiryTime.toISOString(),
}
]
}
public markNudgeAsShown = (nudgeId: string) => {
return
}
public haveBeenAlreadyShown = (nudgeId: string) => {
return false
}
}