Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"CHANGELOG.md": true,
"package-lock.json": true,
"yarn.lock": true,
}
},
"typescript.tsdk": "node_modules/typescript/lib"
}
7,186 changes: 3,097 additions & 4,089 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"@semantic-release/npm": "^7.0.10",
"@types/dotenv": "^8.2.0",
"@types/jest": "^27.0.0",
"@types/node": "^18.15.5",
"@types/qs": "^6.9.1",
"@types/readable-stream": "^2.3.12",
"@types/serialize-error": "^4.0.1",
Expand Down Expand Up @@ -141,7 +142,7 @@
"tslint-config-prettier": "^1.18.0",
"tslint-config-standard": "^9.0.0",
"typedoc": "^0.20.13",
"typescript": "4.1.3",
"typescript": "^4.4.4",
"validate-commit-msg": "^2.14.0"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/cloud/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export class Cloud extends APICarrier {
this.setCachedMeData(response.data.data)

return response.data.data
} catch (err) {
} catch (err: any) {
if (err?.response?.status === 401) {
throw new CloudUnauthenticatedError(undefined, { error: err })
}
Expand Down
43 changes: 43 additions & 0 deletions src/entities/notification-campaign/notification-campaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export interface NotificationCampaignTestRawPayload {
communication_language?: string
}

export interface NotificationCampaignPublishOpts extends EntityFetchOptions {
date?: string
}

export type NotificationCampaignStatusType =
'draft' // user: campaign has been saved, but nothing else has been done with it. The campaign is not ready to be sent
| 'armed' // user: the campaign is ready to be sent, all recipient are primed and ready to be targetted
Expand Down Expand Up @@ -622,6 +626,37 @@ export class NotificationCampaign extends UniverseEntity<NotificationCampaignPay
throw this.handleError(new NotificationCampaignSyncAnalyticsRemoteError(err))
}
}

public async schedulePublish (options?: NotificationCampaignPublishOpts): Promise<NotificationCampaign | NotificationCampaignStaticEntryRawPayload > {
if (this.id === null || this.id === undefined) throw new TypeError('campaign schedule publish requires id to be set')

const body = {
date: options?.date
}

try {
const opts = {
method: 'POST',
url: `${this.universe.universeBase}/${this.endpoint}/${this.id}/schedule/publish${options?.query ? qs.stringify(options.query, { addQueryPrefix: true }) : ''}`,
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
responseType: 'json',
timeout: options?.timeout ?? 60000,
data: body
}
const res = await this.http.getClient()(opts)
const data = res.data.data[0] as NotificationCampaignRawPayload

if (options && options.raw === true) {
return data
}

return this.deserialize(data)
} catch (err) {
throw new NotificationCampaignSchedulePublishRemoteError(undefined, { error: err })
}
}
}

export interface NotificationCampaignsOptions {
Expand Down Expand Up @@ -782,3 +817,11 @@ export class NotificationCampaignSyncAnalyticsRemoteError extends BaseErrorV2 {
Object.setPrototypeOf(this, NotificationCampaignSyncAnalyticsRemoteError.prototype)
}
}
export class NotificationCampaignSchedulePublishRemoteError extends BaseErrorV2 {
public name = 'NotificationCampaignSchedulePublishRemoteError'
public message = 'Could not schedule campaign publish.'
constructor (err: Error | unknown, props? : BaseErrorV2Properties) {
super(err as Error, props)
Object.setPrototypeOf(this, NotificationCampaignSchedulePublishRemoteError.prototype)
}
}
2 changes: 1 addition & 1 deletion src/errors/base-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class BaseError extends Error {
Object.setPrototypeOf(this, BaseError.prototype)
}

static handleCommonProperties<T>(maybeError: T, additionalProperties?: { [key: string]: any }): { [key: string]: any } {
static handleCommonProperties<T extends {}>(maybeError: T, additionalProperties?: { [key: string]: any }): { [key: string]: any } {
const props = Object.assign(
{ error: maybeError },
additionalProperties ?? {},
Expand Down
4 changes: 2 additions & 2 deletions test/auth/logout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('Auth: logout', () => {

try {
await auth.logout()
} catch (err) {
} catch (err: any) {
expect(err.name).toBe('LogoutMissingToken')
}
})
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('Auth: logout', () => {
try {
await auth.authenticate()
await auth.logout()
} catch (err) {
} catch (err: any) {
expect(err.name).toBe('LogoutFailed')
}
})
Expand Down
2 changes: 1 addition & 1 deletion test/messages/get-all.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('v0: Messages: can get all messages', () => {
try {
const inst = await initInstance({ universe: UNIVERSE })
await inst.messages().getAll()
} catch (err) {
} catch (err: any) {
expect(err.name).toBe('MessagesFetchFailed')
}
})
Expand Down
2 changes: 1 addition & 1 deletion test/messages/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('v0: Messages: can alter a message', () => {

try {
await inst.messages().update(messageId, updateObject)
} catch (err) {
} catch (err: any) {
expect(err.name).toBe('MessageUpdateFailed')
}
})
Expand Down