customerio-node
Advanced tools
Comparing version 3.4.1 to 3.5.0
export * from './lib/track'; | ||
export * from './lib/api'; | ||
export * from './lib/regions'; | ||
export { IdentifierType } from './lib/types'; | ||
export { CustomerIORequestError } from './lib/utils'; |
@@ -17,7 +17,9 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CustomerIORequestError = void 0; | ||
exports.CustomerIORequestError = exports.IdentifierType = void 0; | ||
__exportStar(require("./lib/track"), exports); | ||
__exportStar(require("./lib/api"), exports); | ||
__exportStar(require("./lib/regions"), exports); | ||
var types_1 = require("./lib/types"); | ||
Object.defineProperty(exports, "IdentifierType", { enumerable: true, get: function () { return types_1.IdentifierType; } }); | ||
var utils_1 = require("./lib/utils"); | ||
Object.defineProperty(exports, "CustomerIORequestError", { enumerable: true, get: function () { return utils_1.CustomerIORequestError; } }); |
@@ -6,8 +6,8 @@ /// <reference types="node" /> | ||
import { SendEmailRequest } from './api/requests'; | ||
import { Filter } from './types'; | ||
type APIDefaults = RequestOptions & { | ||
import { Filter, IdentifierType } from './types'; | ||
declare type APIDefaults = RequestOptions & { | ||
region: Region; | ||
url?: string; | ||
}; | ||
type Recipients = Record<string, unknown>; | ||
declare type Recipients = Record<string, unknown>; | ||
export declare enum DeliveryExportMetric { | ||
@@ -28,3 +28,3 @@ Created = "created", | ||
} | ||
export type DeliveryExportRequestOptions = { | ||
export declare type DeliveryExportRequestOptions = { | ||
start?: number; | ||
@@ -50,3 +50,4 @@ end?: number; | ||
createDeliveriesExport(newsletterId: number, options?: DeliveryExportRequestOptions): Promise<Record<string, any>>; | ||
getAttributes(id: string | number, idType?: IdentifierType): Promise<Record<string, any>>; | ||
} | ||
export { SendEmailRequest } from './api/requests'; |
@@ -11,2 +11,3 @@ "use strict"; | ||
const utils_1 = require("./utils"); | ||
const types_1 = require("./types"); | ||
var DeliveryExportMetric; | ||
@@ -105,2 +106,11 @@ (function (DeliveryExportMetric) { | ||
} | ||
getAttributes(id, idType = types_1.IdentifierType.Id) { | ||
if ((0, utils_1.isEmpty)(id)) { | ||
throw new utils_1.MissingParamError('customerId'); | ||
} | ||
if (!(0, utils_1.isIdentifierType)(idType)) { | ||
throw new Error('idType must be one of "id", "cio_id", or "email"'); | ||
} | ||
return this.request.get(`${this.apiRoot}/customers/${id}/attributes?id_type=${idType}`); | ||
} | ||
} | ||
@@ -107,0 +117,0 @@ exports.APIClient = APIClient; |
@@ -1,2 +0,2 @@ | ||
export type Identifiers = { | ||
export declare type Identifiers = { | ||
id: string | number; | ||
@@ -6,7 +6,7 @@ } | { | ||
}; | ||
export type SendEmailRequestRequiredOptions = { | ||
export declare type SendEmailRequestRequiredOptions = { | ||
to: string; | ||
identifiers: Identifiers; | ||
}; | ||
export type SendEmailRequestOptionalOptions = Partial<{ | ||
export declare type SendEmailRequestOptionalOptions = Partial<{ | ||
message_data: Record<string, any>; | ||
@@ -28,6 +28,6 @@ headers: Record<string, any>; | ||
}>; | ||
export type SendEmailRequestWithTemplate = SendEmailRequestRequiredOptions & SendEmailRequestOptionalOptions & { | ||
export declare type SendEmailRequestWithTemplate = SendEmailRequestRequiredOptions & SendEmailRequestOptionalOptions & { | ||
transactional_message_id: string | number; | ||
}; | ||
export type SendEmailRequestWithoutTemplate = SendEmailRequestRequiredOptions & SendEmailRequestOptionalOptions & { | ||
export declare type SendEmailRequestWithoutTemplate = SendEmailRequestRequiredOptions & SendEmailRequestOptionalOptions & { | ||
body: string; | ||
@@ -37,4 +37,4 @@ subject: string; | ||
}; | ||
export type SendEmailRequestOptions = SendEmailRequestWithTemplate | SendEmailRequestWithoutTemplate; | ||
export type Message = Partial<SendEmailRequestWithTemplate & SendEmailRequestWithoutTemplate> & { | ||
export declare type SendEmailRequestOptions = SendEmailRequestWithTemplate | SendEmailRequestWithoutTemplate; | ||
export declare type Message = Partial<SendEmailRequestWithTemplate & SendEmailRequestWithoutTemplate> & { | ||
attachments: Record<string, string>; | ||
@@ -41,0 +41,0 @@ }; |
/// <reference types="node" /> | ||
import type { RequestOptions } from 'https'; | ||
export type BasicAuth = { | ||
export declare type BasicAuth = { | ||
apikey: string; | ||
siteid: string; | ||
}; | ||
export type BearerAuth = string; | ||
export type RequestAuth = BasicAuth | BearerAuth; | ||
export type RequestData = Record<string, any> | undefined; | ||
export type RequestHandlerOptions = { | ||
export declare type BearerAuth = string; | ||
export declare type RequestAuth = BasicAuth | BearerAuth; | ||
export declare type RequestData = Record<string, any> | undefined; | ||
export declare type RequestHandlerOptions = { | ||
method: RequestOptions['method']; | ||
@@ -12,0 +12,0 @@ uri: string; |
@@ -40,3 +40,3 @@ "use strict"; | ||
hostname: url.hostname, | ||
path: url.pathname, | ||
path: `${url.pathname}${url.search}`, | ||
}); | ||
@@ -43,0 +43,0 @@ let req = (0, https_1.request)(options, (res) => { |
@@ -6,3 +6,3 @@ /// <reference types="node" /> | ||
import { IdentifierType } from './types'; | ||
type TrackDefaults = RequestOptions & { | ||
declare type TrackDefaults = RequestOptions & { | ||
region: Region; | ||
@@ -9,0 +9,0 @@ url?: string; |
@@ -121,2 +121,5 @@ "use strict"; | ||
} | ||
if (!(0, utils_1.isIdentifierType)(primaryIdType) || !(0, utils_1.isIdentifierType)(secondaryIdType)) { | ||
throw new Error('primaryIdType and secondaryIdType must be one of "id", "cio_id", or "email"'); | ||
} | ||
return this.request.post(`${this.trackRoot}/merge_customers`, { | ||
@@ -123,0 +126,0 @@ primary: { |
@@ -10,6 +10,6 @@ export declare enum IdentifierType { | ||
} | ||
export type SegmentFilter = { | ||
export declare type SegmentFilter = { | ||
id: number; | ||
}; | ||
export type AttributeFilter = { | ||
export declare type AttributeFilter = { | ||
field: string; | ||
@@ -19,13 +19,13 @@ operator: FilterOperator; | ||
}; | ||
export type NotFilter = { | ||
export declare type NotFilter = { | ||
segment?: SegmentFilter; | ||
attribute?: AttributeFilter; | ||
}; | ||
export type FilterObject = SegmentFilter | AttributeFilter | NotFilter; | ||
export type AndFilter = { | ||
export declare type FilterObject = SegmentFilter | AttributeFilter | NotFilter; | ||
export declare type AndFilter = { | ||
and: FilterObject[]; | ||
}; | ||
export type OrFilter = { | ||
export declare type OrFilter = { | ||
or: FilterObject[]; | ||
}; | ||
export type Filter = AndFilter | OrFilter; | ||
export declare type Filter = AndFilter | OrFilter; |
@@ -5,2 +5,3 @@ /// <reference types="node" /> | ||
export declare const cleanEmail: (email: string) => string; | ||
export declare const isIdentifierType: (value: unknown) => boolean; | ||
export declare class CustomerIORequestError extends Error { | ||
@@ -7,0 +8,0 @@ statusCode: number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MissingParamError = exports.CustomerIORequestError = exports.cleanEmail = exports.isEmpty = void 0; | ||
exports.MissingParamError = exports.CustomerIORequestError = exports.isIdentifierType = exports.cleanEmail = exports.isEmpty = void 0; | ||
const types_1 = require("../lib/types"); | ||
const isEmpty = (value) => { | ||
@@ -12,3 +13,14 @@ return value === null || value === undefined || (typeof value === 'string' && value.trim() === ''); | ||
exports.cleanEmail = cleanEmail; | ||
const isIdentifierType = (value) => { | ||
return Object.values(types_1.IdentifierType).includes(value); | ||
}; | ||
exports.isIdentifierType = isIdentifierType; | ||
class CustomerIORequestError extends Error { | ||
constructor(json, statusCode, response, body) { | ||
super(CustomerIORequestError.composeMessage(json)); | ||
this.name = 'CustomerIORequestError'; | ||
this.statusCode = statusCode; | ||
this.response = response; | ||
this.body = body; | ||
} | ||
static composeMessage(json) { | ||
@@ -28,9 +40,2 @@ if (!json) { | ||
} | ||
constructor(json, statusCode, response, body) { | ||
super(CustomerIORequestError.composeMessage(json)); | ||
this.name = 'CustomerIORequestError'; | ||
this.statusCode = statusCode; | ||
this.response = response; | ||
this.body = body; | ||
} | ||
} | ||
@@ -37,0 +42,0 @@ exports.CustomerIORequestError = CustomerIORequestError; |
@@ -1,1 +0,1 @@ | ||
export declare const version = "3.4.1"; | ||
export declare const version = "3.5.0"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = void 0; | ||
exports.version = '3.4.1'; | ||
exports.version = '3.5.0'; |
export * from './lib/track'; | ||
export * from './lib/api'; | ||
export * from './lib/regions'; | ||
export { IdentifierType } from './lib/types'; | ||
export { CustomerIORequestError } from './lib/utils'; |
@@ -5,4 +5,4 @@ import type { RequestOptions } from 'https'; | ||
import { SendEmailRequest } from './api/requests'; | ||
import { cleanEmail, isEmpty, MissingParamError } from './utils'; | ||
import { Filter } from './types'; | ||
import { cleanEmail, isEmpty, isIdentifierType, MissingParamError } from './utils'; | ||
import { Filter, IdentifierType } from './types'; | ||
@@ -142,4 +142,16 @@ type APIDefaults = RequestOptions & { region: Region; url?: string }; | ||
} | ||
getAttributes(id: string | number, idType: IdentifierType = IdentifierType.Id) { | ||
if (isEmpty(id)) { | ||
throw new MissingParamError('customerId'); | ||
} | ||
if (!isIdentifierType(idType)) { | ||
throw new Error('idType must be one of "id", "cio_id", or "email"'); | ||
} | ||
return this.request.get(`${this.apiRoot}/customers/${id}/attributes?id_type=${idType}`); | ||
} | ||
} | ||
export { SendEmailRequest } from './api/requests'; |
@@ -76,3 +76,3 @@ import { request } from 'https'; | ||
hostname: url.hostname, | ||
path: url.pathname, | ||
path: `${url.pathname}${url.search}`, | ||
}); | ||
@@ -79,0 +79,0 @@ let req = request(options, (res) => { |
import type { RequestOptions } from 'https'; | ||
import Request, { BasicAuth, RequestData, PushRequestData } from './request'; | ||
import { Region, RegionUS } from './regions'; | ||
import { isEmpty, MissingParamError } from './utils'; | ||
import { isEmpty, isIdentifierType, MissingParamError } from './utils'; | ||
import { IdentifierType } from './types'; | ||
@@ -159,2 +159,6 @@ | ||
if (!isIdentifierType(primaryIdType) || !isIdentifierType(secondaryIdType)) { | ||
throw new Error('primaryIdType and secondaryIdType must be one of "id", "cio_id", or "email"'); | ||
} | ||
return this.request.post(`${this.trackRoot}/merge_customers`, { | ||
@@ -161,0 +165,0 @@ primary: { |
import { IncomingMessage } from 'http'; | ||
import { IdentifierType } from '../lib/types'; | ||
@@ -11,2 +12,6 @@ export const isEmpty = (value: unknown) => { | ||
export const isIdentifierType = (value: unknown) => { | ||
return Object.values(IdentifierType).includes(value as IdentifierType); | ||
}; | ||
export class CustomerIORequestError extends Error { | ||
@@ -13,0 +18,0 @@ statusCode: number; |
@@ -1,1 +0,1 @@ | ||
export const version = '3.4.1'; | ||
export const version = '3.5.0'; |
{ | ||
"name": "customerio-node", | ||
"description": "A node client for the Customer.io event API. http://customer.io", | ||
"version": "3.4.1", | ||
"version": "3.5.0", | ||
"author": "Customer.io (https://customer.io)", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -376,2 +376,25 @@ <p align="center"> | ||
### api.getAttributes(id, id_type) | ||
Returns a list of attributes for a customer profile. | ||
```javascript | ||
api.getAttributes("1", "id"); | ||
``` | ||
OR | ||
```javascript | ||
const { IdentifierType } = require("customerio-node"); | ||
api.getAttributes("1", IdentifierType.ID); | ||
``` | ||
[You can learn more about the available recipient fields here](https://customer.io/docs/api/#operation/getPersonAttributes). | ||
#### Options | ||
- **id**: Customer identifier, String or number (required) | ||
- **id_type**: One of the ID types - "id" / "email" / "cio_id" (default is "id") | ||
### api.listExports() | ||
@@ -378,0 +401,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
65497
1262
489