@codematic/opencdp 5.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +279 -0
- package/dist/cjs/client.d.ts +87 -0
- package/dist/cjs/client.js +890 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/types.d.ts +122 -0
- package/dist/cjs/types.js +40 -0
- package/dist/esm/client.d.ts +87 -0
- package/dist/esm/client.js +883 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/types.d.ts +122 -0
- package/dist/esm/types.js +36 -0
- package/package.json +40 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
export interface CDPConfig {
|
|
2
|
+
/**
|
|
3
|
+
* API key for the CDP.
|
|
4
|
+
* This is required for authentication.
|
|
5
|
+
*/
|
|
6
|
+
cdpApiKey: string;
|
|
7
|
+
/**
|
|
8
|
+
* Base URL for the OpenCDP API.
|
|
9
|
+
* If not provided, defaults to cdp server.
|
|
10
|
+
*/
|
|
11
|
+
cdpEndpoint?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Logger for OpenCDP operations.
|
|
14
|
+
* If not provided, defaults to console logging.
|
|
15
|
+
*/
|
|
16
|
+
cdpLogger?: Logger;
|
|
17
|
+
/**
|
|
18
|
+
* Maximum number of concurrent OpenCDP requests.
|
|
19
|
+
* Default: 10. Hard-capped internally at 30.
|
|
20
|
+
*/
|
|
21
|
+
maxConcurrentRequests?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Request timeout in milliseconds.
|
|
24
|
+
* Default: 10000 (10 seconds).
|
|
25
|
+
*/
|
|
26
|
+
timeout?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Customer.io config for dual-write
|
|
29
|
+
*/
|
|
30
|
+
customerIo?: {
|
|
31
|
+
siteId: string;
|
|
32
|
+
apiKey: string;
|
|
33
|
+
region?: 'us' | 'eu';
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Optional: If true, sends events to both OpenCDP and Customer.io.
|
|
37
|
+
* This is useful for dual-write scenarios.
|
|
38
|
+
*/
|
|
39
|
+
sendToCustomerIo?: boolean;
|
|
40
|
+
debug?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Optional: Opt-in to throwing errors from the SDK.
|
|
43
|
+
* Default: false. When false, the SDK logs errors and resolves without throwing.
|
|
44
|
+
* When true, validation and request failures will throw so callers can catch them.
|
|
45
|
+
*/
|
|
46
|
+
failOnException?: boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface Logger {
|
|
49
|
+
debug(message: string): void;
|
|
50
|
+
error(message: string, context?: Record<string, any>): void;
|
|
51
|
+
warn(message: string): void;
|
|
52
|
+
}
|
|
53
|
+
export type Identifiers = {
|
|
54
|
+
id: string | number;
|
|
55
|
+
} | {
|
|
56
|
+
email: string;
|
|
57
|
+
};
|
|
58
|
+
export type SendEmailRequestRequiredOptions = {
|
|
59
|
+
to: string;
|
|
60
|
+
identifiers: Identifiers;
|
|
61
|
+
};
|
|
62
|
+
export type SendEmailRequestOptionalOptions = Partial<{
|
|
63
|
+
message_data: Record<string, any>;
|
|
64
|
+
headers: Record<string, any>;
|
|
65
|
+
preheader: string;
|
|
66
|
+
reply_to: string;
|
|
67
|
+
bcc: string[];
|
|
68
|
+
cc: string[];
|
|
69
|
+
plaintext_body: string;
|
|
70
|
+
amp_body: string;
|
|
71
|
+
fake_bcc: boolean;
|
|
72
|
+
disable_message_retention: boolean;
|
|
73
|
+
send_to_unsubscribed: boolean;
|
|
74
|
+
tracked: boolean;
|
|
75
|
+
queue_draft: boolean;
|
|
76
|
+
send_at: number;
|
|
77
|
+
disable_css_preprocessing: boolean;
|
|
78
|
+
language: string;
|
|
79
|
+
attachments: Record<string, string>;
|
|
80
|
+
}>;
|
|
81
|
+
export type SendEmailRequestWithTemplate = SendEmailRequestRequiredOptions & SendEmailRequestOptionalOptions & {
|
|
82
|
+
transactional_message_id: string | number;
|
|
83
|
+
};
|
|
84
|
+
export type SendEmailRequestWithoutTemplate = SendEmailRequestRequiredOptions & SendEmailRequestOptionalOptions & {
|
|
85
|
+
body: string;
|
|
86
|
+
subject: string;
|
|
87
|
+
from: string;
|
|
88
|
+
};
|
|
89
|
+
export type SendEmailRequestOptions = SendEmailRequestWithTemplate | SendEmailRequestWithoutTemplate;
|
|
90
|
+
export type Message = Partial<SendEmailRequestWithTemplate & SendEmailRequestWithoutTemplate> & {
|
|
91
|
+
attachments?: Record<string, string>;
|
|
92
|
+
};
|
|
93
|
+
export declare class SendEmailRequest {
|
|
94
|
+
message: Message;
|
|
95
|
+
constructor(opts: SendEmailRequestOptions);
|
|
96
|
+
attach(name: string, data: any, options?: {
|
|
97
|
+
encode?: boolean | undefined;
|
|
98
|
+
}): void;
|
|
99
|
+
}
|
|
100
|
+
export interface SendPushRequest {
|
|
101
|
+
identifiers: {
|
|
102
|
+
id?: string;
|
|
103
|
+
email?: string;
|
|
104
|
+
cdp_id?: string;
|
|
105
|
+
};
|
|
106
|
+
transactional_message_id: string | number;
|
|
107
|
+
title?: string;
|
|
108
|
+
body?: string;
|
|
109
|
+
message_data?: Record<string, any>;
|
|
110
|
+
}
|
|
111
|
+
export interface SendSmsRequest {
|
|
112
|
+
identifiers: {
|
|
113
|
+
id?: string;
|
|
114
|
+
email?: string;
|
|
115
|
+
cdp_id?: string;
|
|
116
|
+
};
|
|
117
|
+
transactional_message_id?: string | number;
|
|
118
|
+
to?: string;
|
|
119
|
+
from?: string;
|
|
120
|
+
body?: string;
|
|
121
|
+
message_data?: Record<string, any>;
|
|
122
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export class SendEmailRequest {
|
|
2
|
+
constructor(opts) {
|
|
3
|
+
this.message = {
|
|
4
|
+
to: opts.to,
|
|
5
|
+
identifiers: opts.identifiers,
|
|
6
|
+
message_data: opts.message_data,
|
|
7
|
+
send_at: opts.send_at,
|
|
8
|
+
disable_message_retention: opts.disable_message_retention,
|
|
9
|
+
send_to_unsubscribed: opts.send_to_unsubscribed,
|
|
10
|
+
queue_draft: opts.queue_draft,
|
|
11
|
+
bcc: opts.bcc,
|
|
12
|
+
cc: opts.cc,
|
|
13
|
+
fake_bcc: opts.fake_bcc,
|
|
14
|
+
reply_to: opts.reply_to,
|
|
15
|
+
preheader: opts.preheader,
|
|
16
|
+
headers: opts.headers,
|
|
17
|
+
disable_css_preprocessing: opts.disable_css_preprocessing,
|
|
18
|
+
tracked: opts.tracked,
|
|
19
|
+
language: opts.language,
|
|
20
|
+
attachments: opts.attachments,
|
|
21
|
+
// Template-based fields
|
|
22
|
+
transactional_message_id: 'transactional_message_id' in opts ? opts.transactional_message_id : undefined,
|
|
23
|
+
body: 'body' in opts ? opts.body : undefined,
|
|
24
|
+
amp_body: opts.amp_body,
|
|
25
|
+
plaintext_body: opts.plaintext_body,
|
|
26
|
+
subject: 'subject' in opts ? opts.subject : undefined,
|
|
27
|
+
from: 'from' in opts ? opts.from : undefined
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
attach(name, data, options) {
|
|
31
|
+
if (!this.message.attachments) {
|
|
32
|
+
this.message.attachments = {};
|
|
33
|
+
}
|
|
34
|
+
this.message.attachments[name] = data;
|
|
35
|
+
}
|
|
36
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@codematic/opencdp",
|
|
3
|
+
"version": "5.0.13",
|
|
4
|
+
"description": "Codematic OpenCDP Node.js SDK",
|
|
5
|
+
"main": "./dist/cjs/index.js",
|
|
6
|
+
"module": "./dist/esm/index.js",
|
|
7
|
+
"types": "./dist/cjs/index.d.ts",
|
|
8
|
+
"homepage": "https://docs.opencdp.io/",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/esm/index.d.ts",
|
|
12
|
+
"import": "./dist/esm/index.js",
|
|
13
|
+
"require": "./dist/cjs/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"!dist/**/*.test.*"
|
|
19
|
+
],
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"axios": "^1.8.2",
|
|
25
|
+
"customerio-node": "^4.1.1",
|
|
26
|
+
"p-limit": "^3.1.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"jest": "^29.7.0",
|
|
30
|
+
"ts-jest": "^29.2.6",
|
|
31
|
+
"ts-node": "^10.9.2",
|
|
32
|
+
"typescript": "^5.8.2"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json",
|
|
36
|
+
"prepublishOnly": "npm run build && npm test",
|
|
37
|
+
"test": "jest"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|