Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@trycourier/courier

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trycourier/courier - npm Package Compare versions

Comparing version 1.5.0 to 1.6.0

lib/lists/index.d.ts

31

CHANGELOG.md

@@ -6,6 +6,31 @@ # Change Log

## [Unreleased][unreleased]
## [v1.6.0] - 2020-09-22
### Added
- Support for `idempotencyKey` for `POST` methods by @aydrian & @rileylnapier
- Support for [Lists API](https://docs.courier.com/reference/lists-api) by @aydrian
- `POST /send/list` via `client.lists.send(params, config)`
- `GET /profiles/{recipient_id}/lists` via `client.lists.findByRecipientId(recipientId, params)`
- `GET /lists` via `client.lists.list(params)`
- `GET /lists/{list_id}` via `client.lists.get(listId)`
- `PUT /lists/{list_id}` via `client.lists.put(listId, {...})`
- `DELETE /lists/{list_id}` via `client.lists.delete(listId)`
- `PUT /lists/{list_id}/restore` via `client.lists.restore(listId)`
- `GET /lists/{list_id}/subscriptions` via `client.lists.getSubscriptions(listId)`
- `PUT /lists/{list_id}/subscriptions` via `client.lists.putSubscriptions(listId, [recipientId], config)`
- `PUT /lists/{list_id}/subscriptions/{recipient_id}` via `client.lists.subscribe(listId, recipientId)`
- `DELETE /lists/{list_id}/subscriptions/{recipient_id}` via `client.lists.unsubscribe(listId, recipientId)`
### Changed
- Default `base_url` is now `api.courier.com`
## [v1.5.0] - 2020-07-08
### Added
- Support for [Brands API](https://docs.trycourier.com/reference/brands-api) by @aydrian
- Support for [Brands API](https://docs.courier.com/reference/brands-api) by @aydrian
- `GET /brands` via `client.getBrands(params)`

@@ -16,3 +41,3 @@ - `GET /brands/:brand_id` via `client.getBrand(brandId)`

- `DELETE /brands/:brand_id` via `client.deleteBrand(brandId)`
- Support for specifying notification brand during [send](https://docs.trycourier.com/reference/send-api#sendmessage) by @aydrian
- Support for specifying notification brand during [send](https://docs.courier.com/reference/send-api#sendmessage) by @aydrian

@@ -72,2 +97,4 @@ ## [v1.4.0] - 2020-06-29

[unreleased]: https://github.com/trycourier/courier-python/compare/v1.6.0...HEAD
[v1.6.0]: https://github.com/trycourier/courier-python/compare/v1.5.0...v1.6.0
[v1.5.0]: https://github.com/trycourier/courier-python/compare/v1.4.0...v1.5.0

@@ -74,0 +101,0 @@ [v1.4.0]: https://github.com/trycourier/courier-python/compare/v1.3.0...v1.4.0

4

lib/brands.d.ts

@@ -1,2 +0,2 @@

import { ICourierBrand, ICourierBrandGetAllResponse, ICourierBrandParameters, ICourierBrandPutParameters, ICourierClientConfiguration } from "./types";
import { ICourierBrand, ICourierBrandGetAllResponse, ICourierBrandParameters, ICourierBrandPostConfig, ICourierBrandPutParameters, ICourierClientConfiguration } from "./types";
export declare const getBrands: (options: ICourierClientConfiguration) => (params?: {

@@ -6,4 +6,4 @@ cursor: string;

export declare const getBrand: (options: ICourierClientConfiguration) => (brandId: string) => Promise<ICourierBrand>;
export declare const createBrand: (options: ICourierClientConfiguration) => (params: ICourierBrandParameters) => Promise<ICourierBrand>;
export declare const createBrand: (options: ICourierClientConfiguration) => (params: ICourierBrandParameters, config?: ICourierBrandPostConfig | undefined) => Promise<ICourierBrand>;
export declare const replaceBrand: (options: ICourierClientConfiguration) => (params: ICourierBrandPutParameters) => Promise<ICourierBrand>;
export declare const deleteBrand: (options: ICourierClientConfiguration) => (brandId: string) => Promise<void>;

@@ -78,7 +78,14 @@ "use strict";

exports.createBrand = function (options) {
return function (params) { return __awaiter(void 0, void 0, void 0, function () {
var res;
return function (params, config) { return __awaiter(void 0, void 0, void 0, function () {
var axiosConfig, res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, options.httpClient.post("/brands", params)];
case 0:
axiosConfig = {
headers: {}
};
if (config && config.idempotencyKey) {
axiosConfig.headers["Idempotency-Key"] = config.idempotencyKey;
}
return [4 /*yield*/, options.httpClient.post("/brands", params, axiosConfig)];
case 1:

@@ -85,0 +92,0 @@ res = _a.sent();

@@ -41,16 +41,24 @@ "use strict";

var brands_1 = require("./brands");
var lists_1 = require("./lists");
var send = function (options) {
return function (params) { return __awaiter(void 0, void 0, void 0, function () {
var res;
return function (params, config) { return __awaiter(void 0, void 0, void 0, function () {
var axiosConfig, res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, options.httpClient.post("/send", {
brand: params.brand,
data: params.data,
event: params.eventId,
override: params.override,
preferences: params.preferences,
profile: params.profile,
recipient: params.recipientId
})];
case 0:
axiosConfig = {
headers: {}
};
if (config && config.idempotencyKey) {
axiosConfig.headers["Idempotency-Key"] = config.idempotencyKey;
}
return [4 /*yield*/, options.httpClient.post("/send", {
brand: params.brand,
data: params.data,
event: params.eventId,
override: params.override,
preferences: params.preferences,
profile: params.profile,
recipient: params.recipientId
}, axiosConfig)];
case 1:

@@ -92,9 +100,16 @@ res = _a.sent();

var mergeProfile = function (options) {
return function (params) { return __awaiter(void 0, void 0, void 0, function () {
var res;
return function (params, config) { return __awaiter(void 0, void 0, void 0, function () {
var axiosConfig, res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, options.httpClient.post("/profiles/" + params.recipientId, {
profile: params.profile
})];
case 0:
axiosConfig = {
headers: {}
};
if (config && config.idempotencyKey) {
axiosConfig.headers["Idempotency-Key"] = config.idempotencyKey;
}
return [4 /*yield*/, options.httpClient.post("/profiles/" + params.recipientId, {
profile: params.profile
}, axiosConfig)];
case 1:

@@ -128,2 +143,3 @@ res = _a.sent();

getProfile: getProfile(options),
lists: lists_1.lists(options),
mergeProfile: mergeProfile(options),

@@ -130,0 +146,0 @@ replaceBrand: brands_1.replaceBrand(options),

@@ -10,3 +10,3 @@ "use strict";

var DEFAULTS = {
BASE_URL: "https://api.trycourier.app"
BASE_URL: "https://api.courier.com"
};

@@ -13,0 +13,0 @@ exports.CourierClient = function (options) {

@@ -1,2 +0,4 @@

export declare type HttpMethodClient = <T>(url: string, body?: object) => Promise<{
import { AxiosRequestConfig } from "axios";
import { ICourierClientLists } from "./lists/types";
export declare type HttpMethodClient = <T>(url: string, body?: object, config?: AxiosRequestConfig) => Promise<{
data: T;

@@ -27,5 +29,20 @@ }>;

}
export interface ICourierSendConfig {
idempotencyKey?: string;
}
export interface ICourierSendResponse {
messageId: string;
}
export interface ICourierSendListOrPatternParams {
eventId: string;
data?: object;
brand?: string;
override?: object;
}
export interface ICourierSendListParams extends ICourierSendListOrPatternParams {
list: string;
}
export interface ICourierSendPatternParams extends ICourierSendListOrPatternParams {
pattern: string;
}
export interface ICourierProfilePutParameters {

@@ -42,2 +59,5 @@ recipientId: string;

}
export interface ICourierProfilePostConfig {
idempotencyKey?: string;
}
export interface ICourierProfilePostResponse {

@@ -111,2 +131,5 @@ status: "SUCCESS";

}
export interface ICourierBrandPostConfig {
idempotencyKey?: string;
}
export interface ICourierBrandPutParameters extends ICourierBrandParameters {

@@ -124,6 +147,6 @@ id: string;

export interface ICourierClient {
send: (params: ICourierSendParameters) => Promise<ICourierSendResponse>;
send: (params: ICourierSendParameters, config?: ICourierSendConfig) => Promise<ICourierSendResponse>;
getMessage: (messageId: string) => Promise<ICourierMessageGetResponse>;
replaceProfile: (params: ICourierProfilePutParameters) => Promise<ICourierProfilePutResponse>;
mergeProfile: (params: ICourierProfilePostParameters) => Promise<ICourierProfilePostResponse>;
mergeProfile: (params: ICourierProfilePostParameters, config?: ICourierProfilePostConfig) => Promise<ICourierProfilePostResponse>;
getProfile: (params: ICourierProfileGetParameters) => Promise<ICourierProfileGetResponse>;

@@ -134,6 +157,7 @@ getBrands: (params?: {

getBrand: (brandId: string) => Promise<ICourierBrand>;
createBrand: (params: ICourierBrandParameters) => Promise<ICourierBrand>;
createBrand: (params: ICourierBrandParameters, config?: ICourierBrandPostConfig) => Promise<ICourierBrand>;
replaceBrand: (params: ICourierBrandPutParameters) => Promise<ICourierBrand>;
deleteBrand: (brandId: string) => Promise<void>;
lists: ICourierClientLists;
}
export {};
{
"name": "@trycourier/courier",
"version": "1.5.0",
"version": "1.6.0",
"description": "A node.js module for communicating with the Courier REST API.",

@@ -36,2 +36,2 @@ "main": "lib/index.js",

}
}
}

@@ -30,2 +30,16 @@ # `@trycourier/courier`

});
// Example: send a message to a list
const { messageId } = await courier.lists.send({
eventId: "<EVENT_ID>", // get from the Courier UI
listId: "<LIST_ID>", // e.g. example.list.id
data: {} // optional variables for merging into templates
});
// Example: send a message to a pattern
const { messageId } = await courier.lists.send({
eventId: "<EVENT_ID>", // get from the Courier UI
pattern: "<PATTERN>", // e.g. example.list.*
data: {} // optional variables for merging into templates
});
```

@@ -37,3 +51,3 @@

If you need to use a base url other than the default https://api.trycourier.app, you can set it using the `COURIER_BASE_URL` env var.
If you need to use a base url other than the default https://api.courier.com, you can set it using the `COURIER_BASE_URL` env var.

@@ -90,3 +104,3 @@ ## Advanced Usage

// Example: get all brands
const {paging, results} = await courier.getBrands({
const { paging, results } = await courier.getBrands({
cursor: "<CURSOR>" // optional

@@ -104,3 +118,3 @@ });

settings: {
color: {
colors: {
primary: "#0000FF",

@@ -130,2 +144,47 @@ secondary: "#FF0000",

await courier.deleteBrand("<BRAND_ID>");
// Example: get all lists
const { paging, items } = await courier.lists.list({
cursor: "<CURSOR>" // optional
});
console.log(items);
// Example: get a specific list
const list = await courier.lists.get("<LIST_ID>");
console.log(list);
// Example: create or replace a list
const replacedList = await courier.lists.put("<LIST_ID>", {
name: "My New List"
});
console.log(replacedList);
// Example: delete a list
await courier.lists.delete("<LIST_ID>");
// Example: restore a list
await courier.lists.restore("<LIST_ID>");
// Example: get a list's subscriptions
const { paging, items } = await courier.lists.getSubscriptions("<LIST_ID>");
console.log(items);
// Example: replace many recipients to a new or existing list
await courier.lists.putSubscriptions("<LIST_ID>", [
"RECIPIENT_ID_1",
"RECIPIENT_ID_2"
]);
// Example: subscribe single recipient to a new or existing list
const { recipient } = courier.lists.subscribe("<LIST_ID>", "<RECIPIENT_ID>");
console.log(recipient);
// Example: unsubscribe recipient from list
await courier.lists.unsubscribe("<LIST_ID>", "<RECIPIENT_ID>");
// Example: get a recipient's subscribed lists
const { paging, items } = await courier.lists.findByRecipientId(
"<RECIPIENT_ID>"
);
console.log(items);
}

@@ -136,2 +195,36 @@

### Idempotency
For `POST` methods, you can supply an `idempotencyKey` in the config parameter to ensure the idempotency of the API Call. We recommend that you use a `V4 UUID` for the key. Keys are eligible to be removed from the system after they're at least 24 hours old, and a new request is generated if a key is reused after the original has been removed. For more info, see [Idempotent Requests](https://docs.courier.com/reference/idempotent-requests) in the Courier Documentation.
```javascript
import { CourierClient } from "@trycourier/courier";
import uuid4 from "uuid4";
const courier = CourierClient();
const idempotencyKey = uuid4();
async function run() {
const { messageId } = await courier.send(
{
eventId: "<EVENT_ID>",
recipientId: "<RECIPIENT_ID>",
profile: {
email: "example@example.com",
phone_number: "555-867-5309"
},
data: {
world: "JavaScript!"
}
},
{
idempotencyKey
}
);
console.log(messageId);
}
run();
```
## License

@@ -138,0 +231,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc