wirl 0.1.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.
@@ -0,0 +1,73 @@
1
+ interface WirlOptions {
2
+ apiKey: string;
3
+ baseUrl?: string;
4
+ }
5
+ interface TrackParams {
6
+ email: string;
7
+ event: string;
8
+ properties?: Record<string, unknown>;
9
+ }
10
+ interface IdentifyParams {
11
+ email: string;
12
+ properties: Record<string, unknown>;
13
+ }
14
+ interface TriggerParams {
15
+ email: string;
16
+ sequence: string;
17
+ }
18
+ interface ExitParams {
19
+ email: string;
20
+ sequence: string;
21
+ }
22
+ interface TrackResponse {
23
+ success: boolean;
24
+ contact_id: string;
25
+ event_id: string;
26
+ }
27
+ interface IdentifyResponse {
28
+ success: boolean;
29
+ contact_id: string;
30
+ created: boolean;
31
+ }
32
+ interface TriggerResponse {
33
+ success: boolean;
34
+ enrolled: boolean;
35
+ }
36
+ interface ExitResponse {
37
+ success: boolean;
38
+ exited: boolean;
39
+ }
40
+ interface WirlError {
41
+ error: string;
42
+ details?: unknown;
43
+ }
44
+ declare class WirlAPIError extends Error {
45
+ readonly statusCode: number;
46
+ readonly details?: unknown;
47
+ constructor(message: string, statusCode: number, details?: unknown);
48
+ }
49
+ declare class Wirl {
50
+ private readonly apiKey;
51
+ private readonly baseUrl;
52
+ constructor(options: WirlOptions);
53
+ private request;
54
+ /**
55
+ * Track an event for a contact.
56
+ * Creates the contact if they don't exist.
57
+ */
58
+ track(params: TrackParams): Promise<TrackResponse>;
59
+ /**
60
+ * Create or update a contact with properties.
61
+ */
62
+ identify(params: IdentifyParams): Promise<IdentifyResponse>;
63
+ /**
64
+ * Manually enroll a contact in a sequence.
65
+ */
66
+ trigger(params: TriggerParams): Promise<TriggerResponse>;
67
+ /**
68
+ * Remove a contact from an active sequence.
69
+ */
70
+ exit(params: ExitParams): Promise<ExitResponse>;
71
+ }
72
+
73
+ export { type ExitParams, type ExitResponse, type IdentifyParams, type IdentifyResponse, type TrackParams, type TrackResponse, type TriggerParams, type TriggerResponse, Wirl, WirlAPIError, type WirlError, type WirlOptions, Wirl as default };
@@ -0,0 +1,73 @@
1
+ interface WirlOptions {
2
+ apiKey: string;
3
+ baseUrl?: string;
4
+ }
5
+ interface TrackParams {
6
+ email: string;
7
+ event: string;
8
+ properties?: Record<string, unknown>;
9
+ }
10
+ interface IdentifyParams {
11
+ email: string;
12
+ properties: Record<string, unknown>;
13
+ }
14
+ interface TriggerParams {
15
+ email: string;
16
+ sequence: string;
17
+ }
18
+ interface ExitParams {
19
+ email: string;
20
+ sequence: string;
21
+ }
22
+ interface TrackResponse {
23
+ success: boolean;
24
+ contact_id: string;
25
+ event_id: string;
26
+ }
27
+ interface IdentifyResponse {
28
+ success: boolean;
29
+ contact_id: string;
30
+ created: boolean;
31
+ }
32
+ interface TriggerResponse {
33
+ success: boolean;
34
+ enrolled: boolean;
35
+ }
36
+ interface ExitResponse {
37
+ success: boolean;
38
+ exited: boolean;
39
+ }
40
+ interface WirlError {
41
+ error: string;
42
+ details?: unknown;
43
+ }
44
+ declare class WirlAPIError extends Error {
45
+ readonly statusCode: number;
46
+ readonly details?: unknown;
47
+ constructor(message: string, statusCode: number, details?: unknown);
48
+ }
49
+ declare class Wirl {
50
+ private readonly apiKey;
51
+ private readonly baseUrl;
52
+ constructor(options: WirlOptions);
53
+ private request;
54
+ /**
55
+ * Track an event for a contact.
56
+ * Creates the contact if they don't exist.
57
+ */
58
+ track(params: TrackParams): Promise<TrackResponse>;
59
+ /**
60
+ * Create or update a contact with properties.
61
+ */
62
+ identify(params: IdentifyParams): Promise<IdentifyResponse>;
63
+ /**
64
+ * Manually enroll a contact in a sequence.
65
+ */
66
+ trigger(params: TriggerParams): Promise<TriggerResponse>;
67
+ /**
68
+ * Remove a contact from an active sequence.
69
+ */
70
+ exit(params: ExitParams): Promise<ExitResponse>;
71
+ }
72
+
73
+ export { type ExitParams, type ExitResponse, type IdentifyParams, type IdentifyResponse, type TrackParams, type TrackResponse, type TriggerParams, type TriggerResponse, Wirl, WirlAPIError, type WirlError, type WirlOptions, Wirl as default };
package/dist/index.js ADDED
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Wirl: () => Wirl,
24
+ WirlAPIError: () => WirlAPIError,
25
+ default: () => index_default
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+ var WirlAPIError = class extends Error {
29
+ constructor(message, statusCode, details) {
30
+ super(message);
31
+ this.name = "WirlAPIError";
32
+ this.statusCode = statusCode;
33
+ this.details = details;
34
+ }
35
+ };
36
+ var Wirl = class {
37
+ constructor(options) {
38
+ if (!options.apiKey) {
39
+ throw new Error("API key is required");
40
+ }
41
+ this.apiKey = options.apiKey;
42
+ this.baseUrl = options.baseUrl?.replace(/\/$/, "") ?? "https://api.wirl.dev";
43
+ }
44
+ async request(method, path, body) {
45
+ const url = `${this.baseUrl}/api/v1${path}`;
46
+ const response = await fetch(url, {
47
+ method,
48
+ headers: {
49
+ "Authorization": `Bearer ${this.apiKey}`,
50
+ "Content-Type": "application/json"
51
+ },
52
+ body: body ? JSON.stringify(body) : void 0
53
+ });
54
+ const data = await response.json();
55
+ if (!response.ok) {
56
+ throw new WirlAPIError(
57
+ data.error ?? "Request failed",
58
+ response.status,
59
+ data.details
60
+ );
61
+ }
62
+ return data;
63
+ }
64
+ /**
65
+ * Track an event for a contact.
66
+ * Creates the contact if they don't exist.
67
+ */
68
+ async track(params) {
69
+ return this.request("POST", "/events", {
70
+ email: params.email,
71
+ event: params.event,
72
+ properties: params.properties
73
+ });
74
+ }
75
+ /**
76
+ * Create or update a contact with properties.
77
+ */
78
+ async identify(params) {
79
+ return this.request("POST", "/contacts", {
80
+ email: params.email,
81
+ properties: params.properties
82
+ });
83
+ }
84
+ /**
85
+ * Manually enroll a contact in a sequence.
86
+ */
87
+ async trigger(params) {
88
+ return this.request("PUT", "/sequences", {
89
+ email: params.email,
90
+ sequence: params.sequence
91
+ });
92
+ }
93
+ /**
94
+ * Remove a contact from an active sequence.
95
+ */
96
+ async exit(params) {
97
+ return this.request("DELETE", "/sequences", {
98
+ email: params.email,
99
+ sequence: params.sequence
100
+ });
101
+ }
102
+ };
103
+ var index_default = Wirl;
104
+ // Annotate the CommonJS export names for ESM import in node:
105
+ 0 && (module.exports = {
106
+ Wirl,
107
+ WirlAPIError
108
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,82 @@
1
+ // src/index.ts
2
+ var WirlAPIError = class extends Error {
3
+ constructor(message, statusCode, details) {
4
+ super(message);
5
+ this.name = "WirlAPIError";
6
+ this.statusCode = statusCode;
7
+ this.details = details;
8
+ }
9
+ };
10
+ var Wirl = class {
11
+ constructor(options) {
12
+ if (!options.apiKey) {
13
+ throw new Error("API key is required");
14
+ }
15
+ this.apiKey = options.apiKey;
16
+ this.baseUrl = options.baseUrl?.replace(/\/$/, "") ?? "https://api.wirl.dev";
17
+ }
18
+ async request(method, path, body) {
19
+ const url = `${this.baseUrl}/api/v1${path}`;
20
+ const response = await fetch(url, {
21
+ method,
22
+ headers: {
23
+ "Authorization": `Bearer ${this.apiKey}`,
24
+ "Content-Type": "application/json"
25
+ },
26
+ body: body ? JSON.stringify(body) : void 0
27
+ });
28
+ const data = await response.json();
29
+ if (!response.ok) {
30
+ throw new WirlAPIError(
31
+ data.error ?? "Request failed",
32
+ response.status,
33
+ data.details
34
+ );
35
+ }
36
+ return data;
37
+ }
38
+ /**
39
+ * Track an event for a contact.
40
+ * Creates the contact if they don't exist.
41
+ */
42
+ async track(params) {
43
+ return this.request("POST", "/events", {
44
+ email: params.email,
45
+ event: params.event,
46
+ properties: params.properties
47
+ });
48
+ }
49
+ /**
50
+ * Create or update a contact with properties.
51
+ */
52
+ async identify(params) {
53
+ return this.request("POST", "/contacts", {
54
+ email: params.email,
55
+ properties: params.properties
56
+ });
57
+ }
58
+ /**
59
+ * Manually enroll a contact in a sequence.
60
+ */
61
+ async trigger(params) {
62
+ return this.request("PUT", "/sequences", {
63
+ email: params.email,
64
+ sequence: params.sequence
65
+ });
66
+ }
67
+ /**
68
+ * Remove a contact from an active sequence.
69
+ */
70
+ async exit(params) {
71
+ return this.request("DELETE", "/sequences", {
72
+ email: params.email,
73
+ sequence: params.sequence
74
+ });
75
+ }
76
+ };
77
+ var index_default = Wirl;
78
+ export {
79
+ Wirl,
80
+ WirlAPIError,
81
+ index_default as default
82
+ };
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "wirl",
3
+ "version": "0.1.0",
4
+ "description": "Wirl SDK for email sequence automation",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsup src/index.ts --format cjs,esm --dts",
20
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
21
+ "lint": "eslint src",
22
+ "prepublishOnly": "npm run build"
23
+ },
24
+ "keywords": [
25
+ "email",
26
+ "automation",
27
+ "sequences",
28
+ "marketing",
29
+ "wirl"
30
+ ],
31
+ "author": "",
32
+ "license": "MIT",
33
+ "devDependencies": {
34
+ "@types/node": "^20.0.0",
35
+ "tsup": "^8.0.0",
36
+ "typescript": "^5.0.0"
37
+ },
38
+ "engines": {
39
+ "node": ">=18.0.0"
40
+ }
41
+ }