@skrybe/sdk 1.0.0

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 ADDED
@@ -0,0 +1,140 @@
1
+ # Skrybe TypeScript/JavaScript SDK
2
+
3
+ Official TypeScript/JavaScript SDK for the Skrybe API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @skrybe/sdk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Initialize the SDK
14
+
15
+ ```typescript
16
+ import { SkrybeSDK } from '@skrybe/sdk';
17
+
18
+ const skrybe = new SkrybeSDK({
19
+ apiKey: 'your-api-key'
20
+ });
21
+ ```
22
+
23
+ ### Send an Email
24
+
25
+ ```typescript
26
+ const response = await skrybe.sendEmail({
27
+ fromName: 'John Doe',
28
+ fromEmail: 'john@example.com',
29
+ replyTo: 'support@example.com',
30
+ subject: 'Welcome!',
31
+ htmlText: '<html><body>Hello [recipient.first]!</body></html>',
32
+ to: ['user@example.com'],
33
+ recipientVariables: {
34
+ 'user@example.com': {
35
+ first: 'John'
36
+ }
37
+ },
38
+ trackOpens: 1,
39
+ trackClicks: 1
40
+ });
41
+ ```
42
+
43
+ ### Create a Campaign
44
+
45
+ ```typescript
46
+ const response = await skrybe.createCampaign({
47
+ fromName: 'John Doe',
48
+ fromEmail: 'john@example.com',
49
+ replyTo: 'support@example.com',
50
+ title: 'Monthly Newsletter',
51
+ subject: 'Your Monthly Update',
52
+ htmlText: '<html><body>Newsletter content here</body></html>',
53
+ listIds: 'list-id-1,list-id-2',
54
+ trackOpens: 1,
55
+ trackClicks: 1,
56
+ sendCampaign: 1
57
+ });
58
+ ```
59
+
60
+ ### Get Lists
61
+
62
+ ```typescript
63
+ const lists = await skrybe.getLists();
64
+ // To include hidden lists
65
+ const allLists = await skrybe.getLists(true);
66
+ ```
67
+
68
+ ## API Reference
69
+
70
+ ### SkrybeSDK Configuration
71
+
72
+ ```typescript
73
+ interface SkrybeConfig {
74
+ apiKey: string;
75
+ baseURL?: string; // Defaults to https://dashboard.skry.be
76
+ }
77
+ ```
78
+
79
+ ### SendEmailOptions
80
+
81
+ ```typescript
82
+ interface SendEmailOptions {
83
+ fromName: string;
84
+ fromEmail: string;
85
+ replyTo: string;
86
+ subject: string;
87
+ htmlText: string;
88
+ plainText?: string;
89
+ to?: string[];
90
+ recipientVariables?: Record<string, Record<string, any>>;
91
+ listIds?: string[];
92
+ queryString?: string;
93
+ trackOpens?: 0 | 1 | 2;
94
+ trackClicks?: 0 | 1 | 2;
95
+ scheduleDateTime?: string;
96
+ scheduleTimezone?: string;
97
+ }
98
+ ```
99
+
100
+ ### CreateCampaignOptions
101
+
102
+ ```typescript
103
+ interface CreateCampaignOptions {
104
+ fromName: string;
105
+ fromEmail: string;
106
+ replyTo: string;
107
+ title: string;
108
+ subject: string;
109
+ htmlText: string;
110
+ plainText?: string;
111
+ listIds?: string;
112
+ segmentIds?: string;
113
+ excludeListIds?: string;
114
+ excludeSegmentIds?: string;
115
+ queryString?: string;
116
+ trackOpens?: 0 | 1 | 2;
117
+ trackClicks?: 0 | 1 | 2;
118
+ sendCampaign?: 0 | 1;
119
+ scheduleDateTime?: string;
120
+ scheduleTimezone?: string;
121
+ }
122
+ ```
123
+
124
+ ## Error Handling
125
+
126
+ The SDK throws errors for invalid API keys, missing required parameters, and other API errors. Make sure to wrap your API calls in try-catch blocks:
127
+
128
+ ```typescript
129
+ try {
130
+ const response = await skrybe.sendEmail({
131
+ // ... options
132
+ });
133
+ } catch (error) {
134
+ console.error('Error sending email:', error.message);
135
+ }
136
+ ```
137
+
138
+ ## License
139
+
140
+ MIT
@@ -0,0 +1,52 @@
1
+ export interface SkrybeConfig {
2
+ apiKey: string;
3
+ baseURL?: string;
4
+ }
5
+ export interface SendEmailOptions {
6
+ fromName: string;
7
+ fromEmail: string;
8
+ replyTo: string;
9
+ subject: string;
10
+ htmlText: string;
11
+ plainText?: string;
12
+ to?: string[];
13
+ recipientVariables?: Record<string, Record<string, any>>;
14
+ listIds?: string[];
15
+ queryString?: string;
16
+ trackOpens?: 0 | 1 | 2;
17
+ trackClicks?: 0 | 1 | 2;
18
+ scheduleDateTime?: string;
19
+ scheduleTimezone?: string;
20
+ }
21
+ export interface CreateCampaignOptions {
22
+ fromName: string;
23
+ fromEmail: string;
24
+ replyTo: string;
25
+ title: string;
26
+ subject: string;
27
+ htmlText: string;
28
+ plainText?: string;
29
+ listIds?: string;
30
+ segmentIds?: string;
31
+ excludeListIds?: string;
32
+ excludeSegmentIds?: string;
33
+ queryString?: string;
34
+ trackOpens?: 0 | 1 | 2;
35
+ trackClicks?: 0 | 1 | 2;
36
+ sendCampaign?: 0 | 1;
37
+ scheduleDateTime?: string;
38
+ scheduleTimezone?: string;
39
+ }
40
+ export interface List {
41
+ id: string;
42
+ name: string;
43
+ }
44
+ export declare class SkrybeSDK {
45
+ private client;
46
+ private apiKey;
47
+ constructor(config: SkrybeConfig);
48
+ private createFormData;
49
+ sendEmail(options: SendEmailOptions): Promise<string>;
50
+ createCampaign(options: CreateCampaignOptions): Promise<string>;
51
+ getLists(includeHidden?: boolean): Promise<List[]>;
52
+ }
package/dist/index.js ADDED
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SkrybeSDK = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ class SkrybeSDK {
9
+ constructor(config) {
10
+ this.apiKey = config.apiKey;
11
+ this.client = axios_1.default.create({
12
+ baseURL: config.baseURL || 'https://dashboard.skry.be',
13
+ headers: {
14
+ 'Content-Type': 'application/x-www-form-urlencoded'
15
+ }
16
+ });
17
+ }
18
+ createFormData(data) {
19
+ const formData = new URLSearchParams();
20
+ formData.append('api_key', this.apiKey);
21
+ Object.entries(data).forEach(([key, value]) => {
22
+ if (value !== undefined) {
23
+ if (Array.isArray(value)) {
24
+ formData.append(key, JSON.stringify(value));
25
+ }
26
+ else if (typeof value === 'object') {
27
+ formData.append(key, JSON.stringify(value));
28
+ }
29
+ else {
30
+ formData.append(key, String(value));
31
+ }
32
+ }
33
+ });
34
+ return formData;
35
+ }
36
+ async sendEmail(options) {
37
+ var _a;
38
+ const formData = this.createFormData({
39
+ from_name: options.fromName,
40
+ from_email: options.fromEmail,
41
+ reply_to: options.replyTo,
42
+ subject: options.subject,
43
+ html_text: options.htmlText,
44
+ plain_text: options.plainText,
45
+ to: options.to,
46
+ 'recipient-variables': options.recipientVariables,
47
+ list_ids: (_a = options.listIds) === null || _a === void 0 ? void 0 : _a.join(','),
48
+ query_string: options.queryString,
49
+ track_opens: options.trackOpens,
50
+ track_clicks: options.trackClicks,
51
+ schedule_date_time: options.scheduleDateTime,
52
+ schedule_timezone: options.scheduleTimezone
53
+ });
54
+ const response = await this.client.post('/api/emails/send.php', formData);
55
+ return response.data;
56
+ }
57
+ async createCampaign(options) {
58
+ const formData = this.createFormData({
59
+ from_name: options.fromName,
60
+ from_email: options.fromEmail,
61
+ reply_to: options.replyTo,
62
+ title: options.title,
63
+ subject: options.subject,
64
+ html_text: options.htmlText,
65
+ plain_text: options.plainText,
66
+ list_ids: options.listIds,
67
+ segment_ids: options.segmentIds,
68
+ exclude_list_ids: options.excludeListIds,
69
+ exclude_segments_ids: options.excludeSegmentIds,
70
+ query_string: options.queryString,
71
+ track_opens: options.trackOpens,
72
+ track_clicks: options.trackClicks,
73
+ send_campaign: options.sendCampaign,
74
+ schedule_date_time: options.scheduleDateTime,
75
+ schedule_timezone: options.scheduleTimezone
76
+ });
77
+ const response = await this.client.post('/api/campaigns/create.php', formData);
78
+ return response.data;
79
+ }
80
+ async getLists(includeHidden = false) {
81
+ const formData = this.createFormData({
82
+ include_hidden: includeHidden ? 'yes' : 'no'
83
+ });
84
+ const response = await this.client.post('/api/lists/get-lists.php', formData);
85
+ return response.data;
86
+ }
87
+ }
88
+ exports.SkrybeSDK = SkrybeSDK;
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@skrybe/sdk",
3
+ "version": "1.0.0",
4
+ "description": "Official TypeScript/JavaScript SDK for Skrybe API",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "prepare": "npm run build",
10
+ "test": "jest",
11
+ "prepublishOnly": "npm run build"
12
+ },
13
+ "keywords": [
14
+ "skrybe",
15
+ "email",
16
+ "marketing",
17
+ "api",
18
+ "sdk"
19
+ ],
20
+ "author": "Skrybe",
21
+ "license": "MIT",
22
+ "dependencies": {
23
+ "axios": "^1.6.7"
24
+ },
25
+ "devDependencies": {
26
+ "typescript": "^5.3.3",
27
+ "@types/node": "^20.11.16"
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "README.md"
32
+ ],
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/skrybe/sdk"
39
+ }
40
+ }