customerio-node
Advanced tools
Comparing version 4.0.0 to 4.1.0
@@ -5,3 +5,3 @@ /// <reference types="node" /> | ||
import { Region } from './regions'; | ||
import { SendEmailRequest } from './api/requests'; | ||
import { SendEmailRequest, SendPushRequest } from './api/requests'; | ||
import { Filter, IdentifierType } from './types'; | ||
@@ -42,2 +42,3 @@ type APIDefaults = RequestOptions & { | ||
sendEmail(req: SendEmailRequest): Promise<Record<string, any>>; | ||
sendPush(req: SendPushRequest): Promise<Record<string, any>>; | ||
getCustomersByEmail(email: string): Promise<Record<string, any>>; | ||
@@ -52,2 +53,2 @@ triggerBroadcast(id: string | number, data: RequestData, recipients: Recipients): Promise<Record<string, any>>; | ||
} | ||
export { SendEmailRequest } from './api/requests'; | ||
export { SendEmailRequest, SendPushRequest } from './api/requests'; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SendEmailRequest = exports.APIClient = exports.DeliveryExportMetric = void 0; | ||
exports.SendPushRequest = exports.SendEmailRequest = exports.APIClient = exports.DeliveryExportMetric = void 0; | ||
const request_1 = __importDefault(require("./request")); | ||
@@ -59,2 +59,8 @@ const regions_1 = require("./regions"); | ||
} | ||
sendPush(req) { | ||
if (!(req instanceof requests_1.SendPushRequest)) { | ||
throw new Error('"request" must be an instance of SendPushRequest'); | ||
} | ||
return this.request.post(`${this.apiRoot}/send/push`, req.message); | ||
} | ||
getCustomersByEmail(email) { | ||
@@ -120,1 +126,2 @@ if (typeof email !== 'string' || (0, utils_1.isEmpty)(email)) { | ||
Object.defineProperty(exports, "SendEmailRequest", { enumerable: true, get: function () { return requests_2.SendEmailRequest; } }); | ||
Object.defineProperty(exports, "SendPushRequest", { enumerable: true, get: function () { return requests_2.SendPushRequest; } }); |
@@ -36,7 +36,7 @@ export type Identifiers = { | ||
export type SendEmailRequestOptions = SendEmailRequestWithTemplate | SendEmailRequestWithoutTemplate; | ||
export type Message = Partial<SendEmailRequestWithTemplate & SendEmailRequestWithoutTemplate> & { | ||
export type EmailMessage = Partial<SendEmailRequestWithTemplate & SendEmailRequestWithoutTemplate> & { | ||
attachments: Record<string, string>; | ||
}; | ||
export declare class SendEmailRequest { | ||
message: Message; | ||
message: EmailMessage; | ||
constructor(opts: SendEmailRequestOptions); | ||
@@ -47,1 +47,36 @@ attach(name: string, data: any, { encode }?: { | ||
} | ||
export type SendPushCustomPayload = { | ||
ios: Record<string, any>; | ||
android: Record<string, any>; | ||
}; | ||
export type SendPushRequestRequiredOptions = { | ||
identifiers: Identifiers; | ||
transactional_message_id: string | number; | ||
}; | ||
export type SendPushRequestOptionalOptions = Partial<{ | ||
to: string; | ||
title: string; | ||
message: string; | ||
disable_message_retention: boolean; | ||
send_to_unsubscribed: boolean; | ||
queue_draft: boolean; | ||
message_data: Record<string, any>; | ||
send_at: number; | ||
language: string; | ||
image_url: string; | ||
link: string; | ||
sound: string; | ||
custom_data: Record<string, string>; | ||
device: Record<string, any>; | ||
custom_device: Record<string, any>; | ||
}>; | ||
export type SendPushRequestWithoutCustomPayload = SendPushRequestRequiredOptions & SendPushRequestOptionalOptions & {}; | ||
export type SendPushRequestWithCustomPayload = SendPushRequestRequiredOptions & SendPushRequestOptionalOptions & { | ||
custom_payload: SendPushCustomPayload; | ||
}; | ||
export type SendPushRequestOptions = SendPushRequestWithoutCustomPayload | SendPushRequestWithCustomPayload; | ||
export type PushMessage = Partial<Omit<SendPushRequestWithoutCustomPayload, 'device'> & Omit<SendPushRequestWithCustomPayload, 'device'>>; | ||
export declare class SendPushRequest { | ||
message: PushMessage; | ||
constructor(opts: SendPushRequestOptions); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SendEmailRequest = void 0; | ||
exports.SendPushRequest = exports.SendEmailRequest = void 0; | ||
class SendEmailRequest { | ||
@@ -54,1 +54,27 @@ constructor(opts) { | ||
exports.SendEmailRequest = SendEmailRequest; | ||
class SendPushRequest { | ||
constructor(opts) { | ||
this.message = { | ||
identifiers: opts.identifiers, | ||
to: opts.to, | ||
transactional_message_id: opts.transactional_message_id, | ||
title: opts.title, | ||
message: opts.message, | ||
disable_message_retention: opts.disable_message_retention, | ||
send_to_unsubscribed: opts.send_to_unsubscribed, | ||
queue_draft: opts.queue_draft, | ||
message_data: opts.message_data, | ||
send_at: opts.send_at, | ||
language: opts.language, | ||
image_url: opts.image_url, | ||
link: opts.link, | ||
sound: opts.sound, | ||
custom_data: opts.custom_data, | ||
custom_device: opts.device, | ||
}; | ||
if ('custom_payload' in opts) { | ||
this.message.custom_payload = opts.custom_payload; | ||
} | ||
} | ||
} | ||
exports.SendPushRequest = SendPushRequest; |
@@ -1,1 +0,1 @@ | ||
export declare const version = "4.0.0"; | ||
export declare const version = "4.1.0"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = void 0; | ||
exports.version = '4.0.0'; | ||
exports.version = '4.1.0'; |
import type { RequestOptions } from 'https'; | ||
import Request, { BearerAuth, RequestData } from './request'; | ||
import { Region, RegionUS } from './regions'; | ||
import { SendEmailRequest } from './api/requests'; | ||
import { SendEmailRequest, SendPushRequest } from './api/requests'; | ||
import { cleanEmail, isEmpty, isIdentifierType, MissingParamError } from './utils'; | ||
@@ -80,2 +80,10 @@ import { Filter, IdentifierType } from './types'; | ||
sendPush(req: SendPushRequest) { | ||
if (!(req instanceof SendPushRequest)) { | ||
throw new Error('"request" must be an instance of SendPushRequest'); | ||
} | ||
return this.request.post(`${this.apiRoot}/send/push`, req.message); | ||
} | ||
getCustomersByEmail(email: string) { | ||
@@ -156,2 +164,2 @@ if (typeof email !== 'string' || isEmpty(email)) { | ||
export { SendEmailRequest } from './api/requests'; | ||
export { SendEmailRequest, SendPushRequest } from './api/requests'; |
@@ -40,7 +40,8 @@ export type Identifiers = { id: string | number } | { email: string }; | ||
export type Message = Partial<SendEmailRequestWithTemplate & SendEmailRequestWithoutTemplate> & { | ||
export type EmailMessage = Partial<SendEmailRequestWithTemplate & SendEmailRequestWithoutTemplate> & { | ||
attachments: Record<string, string>; | ||
}; | ||
export class SendEmailRequest { | ||
message: Message; | ||
message: EmailMessage; | ||
@@ -100,1 +101,71 @@ constructor(opts: SendEmailRequestOptions) { | ||
} | ||
export type SendPushCustomPayload = { | ||
ios: Record<string, any>; | ||
android: Record<string, any>; | ||
}; | ||
export type SendPushRequestRequiredOptions = { | ||
identifiers: Identifiers; | ||
transactional_message_id: string | number; | ||
}; | ||
export type SendPushRequestOptionalOptions = Partial<{ | ||
to: string; | ||
title: string; | ||
message: string; | ||
disable_message_retention: boolean; | ||
send_to_unsubscribed: boolean; | ||
queue_draft: boolean; | ||
message_data: Record<string, any>; | ||
send_at: number; | ||
language: string; | ||
image_url: string; | ||
link: string; | ||
sound: string; | ||
custom_data: Record<string, string>; | ||
device: Record<string, any>; | ||
custom_device: Record<string, any>; | ||
}>; | ||
export type SendPushRequestWithoutCustomPayload = SendPushRequestRequiredOptions & SendPushRequestOptionalOptions & {}; | ||
export type SendPushRequestWithCustomPayload = SendPushRequestRequiredOptions & | ||
SendPushRequestOptionalOptions & { | ||
custom_payload: SendPushCustomPayload; | ||
}; | ||
export type SendPushRequestOptions = SendPushRequestWithoutCustomPayload | SendPushRequestWithCustomPayload; | ||
export type PushMessage = Partial< | ||
Omit<SendPushRequestWithoutCustomPayload, 'device'> & Omit<SendPushRequestWithCustomPayload, 'device'> | ||
>; | ||
export class SendPushRequest { | ||
message: PushMessage; | ||
constructor(opts: SendPushRequestOptions) { | ||
this.message = { | ||
identifiers: opts.identifiers, | ||
to: opts.to, | ||
transactional_message_id: opts.transactional_message_id, | ||
title: opts.title, | ||
message: opts.message, | ||
disable_message_retention: opts.disable_message_retention, | ||
send_to_unsubscribed: opts.send_to_unsubscribed, | ||
queue_draft: opts.queue_draft, | ||
message_data: opts.message_data, | ||
send_at: opts.send_at, | ||
language: opts.language, | ||
image_url: opts.image_url, | ||
link: opts.link, | ||
sound: opts.sound, | ||
custom_data: opts.custom_data, | ||
custom_device: opts.device, | ||
}; | ||
if ('custom_payload' in opts) { | ||
this.message.custom_payload = opts.custom_payload; | ||
} | ||
} | ||
} |
@@ -1,1 +0,1 @@ | ||
export const version = '4.0.0'; | ||
export const version = '4.1.0'; |
{ | ||
"name": "customerio-node", | ||
"description": "A node client for the Customer.io event API. http://customer.io", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"author": "Customer.io (https://customer.io)", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -298,4 +298,6 @@ <p align="center"> | ||
To use the Customer.io [Transactional API](https://customer.io/docs/transactional-api), import our API client and initialize it with an [app key](https://customer.io/docs/managing-credentials#app-api-keys). | ||
To use the Customer.io [Transactional API](https://customer.io/docs/transactional-api), import our API client and initialize it with an [app key](https://customer.io/docs/managing-credentials#app-api-keys) and create a request object of your message type. | ||
Create a new `SendEmailRequest` object containing: | ||
@@ -341,2 +343,36 @@ | ||
#### Push | ||
Create a new `SendPushRequest` object containing: | ||
- `transactional_message_id`: the ID or trigger name of the transactional message you want to send. | ||
- an `identifiers` object containing the `id` or `email` of your recipient. If the profile does not exist, Customer.io will create it. | ||
Use `sendPush` referencing your request to send a transactional message. [Learn more about transactional messages and `sendPushRequest` properties](https://customer.io/docs/transactional-api). | ||
```javascript | ||
const { APIClient, SendPushRequest, RegionUS, RegionEU } = require("customerio-node"); | ||
const api = new APIClient("app-key", { region: RegionUS }); | ||
const request = new SendPushRequest({ | ||
transactional_message_id: "3", | ||
message_data: { | ||
name: "Person", | ||
items: { | ||
name: "shoes", | ||
price: "59.99", | ||
}, | ||
products: [], | ||
}, | ||
identifiers: { | ||
id: "2", | ||
}, | ||
}); | ||
api | ||
.sendPush(request) | ||
.then((res) => console.log(res)) | ||
.catch((err) => console.log(err.statusCode, err.message)); | ||
``` | ||
### api.triggerBroadcast(campaign_id, data, recipients) | ||
@@ -343,0 +379,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72426
1412
525