@marketing-sdk/customerio 0.1.1-experimental.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Cody
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,33 @@
1
+ import { CreateResponse, BaseProvider } from '@marketing-sdk/core';
2
+ import { CustomerIO } from './types';
3
+ export declare class CustomerIOClient extends BaseProvider {
4
+ private trackingApiUrl;
5
+ private appApiUrl;
6
+ private siteId;
7
+ private apiKey;
8
+ private appApiKey?;
9
+ constructor(siteId: string, apiKey: string, appApiKey?: string);
10
+ protected getDefaultHeaders(): Record<string, string>;
11
+ protected getAuthHeaders(): Record<string, string>;
12
+ private get trackingAuthHeaders();
13
+ private get appAuthHeaders();
14
+ identifyCustomer(customer: CustomerIO.CustomerPayload): Promise<CreateResponse>;
15
+ getCustomers(params?: {
16
+ start?: number;
17
+ limit?: number;
18
+ sort?: "id" | "created" | "updated";
19
+ filters?: Record<string, any>;
20
+ }): Promise<CreateResponse<CustomerIO.CustomersResponse>>;
21
+ getCustomer(customerId: string): Promise<CreateResponse<CustomerIO.CustomerResponse>>;
22
+ searchCustomers(searchParams: CustomerIO.CustomerSearchParams): Promise<CreateResponse<CustomerIO.CustomersResponse>>;
23
+ trackEvent(customerId: string, eventName: string, data?: Record<string, any>): Promise<CreateResponse>;
24
+ trackAnonymousEvent(eventName: string, data?: Record<string, any>): Promise<CreateResponse>;
25
+ deleteCustomer(customerId: string): Promise<CreateResponse>;
26
+ addDevice(customerId: string, device: CustomerIO.DevicePayload): Promise<CreateResponse>;
27
+ deleteDevice(customerId: string, deviceId: string): Promise<CreateResponse>;
28
+ /** @deprecated Use identifyCustomer instead */
29
+ createLead(lead: any): Promise<CreateResponse>;
30
+ /** @deprecated Use identifyCustomer instead */
31
+ createCustomer(customer: CustomerIO.CustomerPayload): Promise<CreateResponse>;
32
+ }
33
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAc,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC,qBAAa,gBAAiB,SAAQ,YAAY;IAChD,OAAO,CAAC,cAAc,CAAsC;IAC5D,OAAO,CAAC,SAAS,CAAgC;IACjD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAC,CAAS;gBAGzB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM;IAUpB,SAAS,CAAC,iBAAiB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAMrD,SAAS,C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MAAM,GACf,OAAO,CAAC,cAAc,CAAC;IAW1B,+CAA+C;IAClC,UAAU,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,cAAc,CAAC;IAc3D,+CAA+C;IAClC,cAAc,CACzB,QAAQ,EAAE,UAAU,CAAC,eAAe,GACnC,OAAO,CAAC,cAAc,CAAC;CAG3B"}
package/dist/client.js ADDED
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CustomerIOClient = void 0;
4
+ const core_1 = require("@marketing-sdk/core");
5
+ const validators_1 = require("./validators");
6
+ class CustomerIOClient extends core_1.BaseProvider {
7
+ constructor(siteId, apiKey, appApiKey) {
8
+ super({
9
+ timeout: 30000,
10
+ });
11
+ this.trackingApiUrl = "https://track.customer.io/api/v1";
12
+ this.appApiUrl = "https://api.customer.io/v1";
13
+ this.siteId = siteId;
14
+ this.apiKey = apiKey;
15
+ this.appApiKey = appApiKey;
16
+ }
17
+ getDefaultHeaders() {
18
+ return {
19
+ "Content-Type": "application/json",
20
+ };
21
+ }
22
+ getAuthHeaders() {
23
+ return {};
24
+ }
25
+ get trackingAuthHeaders() {
26
+ return {
27
+ "Content-Type": "application/json",
28
+ Authorization: `Basic ${Buffer.from(`${this.siteId}:${this.apiKey}`).toString("base64")}`,
29
+ };
30
+ }
31
+ get appAuthHeaders() {
32
+ if (!this.appApiKey) {
33
+ throw new Error("Customer.io App API key is required for this operation. Please set CUSTOMERIO_APP_API_KEY environment variable.");
34
+ }
35
+ return {
36
+ "Content-Type": "application/json",
37
+ Authorization: `Bearer ${this.appApiKey}`,
38
+ };
39
+ }
40
+ async identifyCustomer(customer) {
41
+ validators_1.CustomerIOValidators.validateCustomerPayload(customer);
42
+ const body = {
43
+ email: customer.email,
44
+ created_at: customer.created_at || Math.floor(Date.now() / 1000),
45
+ };
46
+ if (customer.firstName)
47
+ body.first_name = customer.firstName;
48
+ if (customer.lastName)
49
+ body.last_name = customer.lastName;
50
+ if (customer.attributes) {
51
+ Object.assign(body, customer.attributes);
52
+ }
53
+ return this.makeRequest({
54
+ url: `${this.trackingApiUrl}/customers/${customer.id}`,
55
+ method: "PUT",
56
+ body,
57
+ headers: this.trackingAuthHeaders,
58
+ }, "Identify Customer");
59
+ }
60
+ async getCustomers(params) {
61
+ if (!this.appApiKey) {
62
+ return {
63
+ data: null,
64
+ error: "App API key is required for this operation. Please set CUSTOMERIO_APP_API_KEY environment variable.",
65
+ };
66
+ }
67
+ if (params?.limit) {
68
+ core_1.Validators.validatePaginationParams({ limit: params.limit });
69
+ }
70
+ return this.makeRequest({
71
+ url: `${this.appApiUrl}/api/customers`,
72
+ method: "GET",
73
+ params,
74
+ headers: this.appAuthHeaders,
75
+ }, "Get Customers");
76
+ }
77
+ async getCustomer(customerId) {
78
+ if (!this.appApiKey) {
79
+ return {
80
+ data: null,
81
+ error: "App API key is required for this operation. Please set CUSTOMERIO_APP_API_KEY environment variable.",
82
+ };
83
+ }
84
+ core_1.Validators.validateId(customerId, "customerId");
85
+ return this.makeRequest({
86
+ url: `${this.appApiUrl}/api/customers/${customerId}`,
87
+ method: "GET",
88
+ headers: this.appAuthHeaders,
89
+ }, "Get Customer");
90
+ }
91
+ async searchCustomers(searchParams) {
92
+ if (!this.appApiKey) {
93
+ return {
94
+ data: null,
95
+ error: "App API key is required for this operation. Please set CUSTOMERIO_APP_API_KEY environment variable.",
96
+ };
97
+ }
98
+ if (searchParams.limit) {
99
+ core_1.Validators.validatePaginationParams({ limit: searchParams.limit });
100
+ }
101
+ return this.makeRequest({
102
+ url: `${this.appApiUrl}/api/customers/search`,
103
+ method: "POST",
104
+ body: searchParams,
105
+ headers: this.appAuthHeaders,
106
+ }, "Search Customers");
107
+ }
108
+ async trackEvent(customerId, eventName, data) {
109
+ core_1.Validators.validateId(customerId, "customerId");
110
+ return this.makeRequest({
111
+ url: `${this.trackingApiUrl}/customers/${customerId}/events`,
112
+ method: "POST",
113
+ body: {
114
+ name: eventName,
115
+ data: data || {},
116
+ },
117
+ headers: this.trackingAuthHeaders,
118
+ }, "Track Event");
119
+ }
120
+ async trackAnonymousEvent(eventName, data) {
121
+ return this.makeRequest({
122
+ url: `${this.trackingApiUrl}/events`,
123
+ method: "POST",
124
+ body: {
125
+ name: eventName,
126
+ data: data || {},
127
+ },
128
+ headers: this.trackingAuthHeaders,
129
+ }, "Track Anonymous Event");
130
+ }
131
+ async deleteCustomer(customerId) {
132
+ core_1.Validators.validateId(customerId, "customerId");
133
+ return this.makeRequest({
134
+ url: `${this.trackingApiUrl}/customers/${customerId}`,
135
+ method: "DELETE",
136
+ headers: this.trackingAuthHeaders,
137
+ }, "Delete Customer");
138
+ }
139
+ async addDevice(customerId, device) {
140
+ core_1.Validators.validateId(customerId, "customerId");
141
+ validators_1.CustomerIOValidators.validateDevicePayload(device);
142
+ return this.makeRequest({
143
+ url: `${this.trackingApiUrl}/customers/${customerId}/devices`,
144
+ method: "PUT",
145
+ body: device,
146
+ headers: this.trackingAuthHeaders,
147
+ }, "Add Device");
148
+ }
149
+ async deleteDevice(customerId, deviceId) {
150
+ core_1.Validators.validateId(customerId, "customerId");
151
+ core_1.Validators.validateId(deviceId, "deviceId");
152
+ return this.makeRequest({
153
+ url: `${this.trackingApiUrl}/customers/${customerId}/devices/${deviceId}`,
154
+ method: "DELETE",
155
+ headers: this.trackingAuthHeaders,
156
+ }, "Delete Device");
157
+ }
158
+ /** @deprecated Use identifyCustomer instead */
159
+ async createLead(lead) {
160
+ return this.identifyCustomer({
161
+ id: lead.email || `${lead.lastName.toLowerCase()}_${Date.now()}`,
162
+ email: lead.email,
163
+ firstName: lead.firstName,
164
+ lastName: lead.lastName,
165
+ attributes: {
166
+ company: lead.company,
167
+ phone: lead.phone,
168
+ source: lead.source,
169
+ },
170
+ });
171
+ }
172
+ /** @deprecated Use identifyCustomer instead */
173
+ async createCustomer(customer) {
174
+ return this.identifyCustomer(customer);
175
+ }
176
+ }
177
+ exports.CustomerIOClient = CustomerIOClient;
178
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AAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAE5C,OAAO,IAAI,CAAC,WAAW,CAAC;YACtB,GAAG,EAAE,GAAG,IAAI,CAAC,cAAc,cAAc,UAAU,YAAY,QAAQ,EAAE;YACzE,MAAM,EAAE,QAAQ;YAChB,OAAO,EAAE,IAAI,CAAC,mBAAmB;SAClC,EAAE,eAAe,CAAC,CAAC;IACtB,CAAC;IAED,+CAA+C;IACxC,KAAK,CAAC,UAAU,CAAC,IAAS;QAC/B,OAAO,IAAI,CAAC,gBAAgB,CAAC;YAC3B,EAAE,EAAE,IAAI,CAAC,KAAK,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE;YAChE,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,UAAU,EAAE;gBACV,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,MAAM,EAAE,IAAI,CAAC,MAAM;aACpB;SACF,CAAC,CAAC;IACL,CAAC;IAED,+CAA+C;IACxC,KAAK,CAAC,cAAc,CACzB,QAAoC;QAEpC,OAAO,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC;CACF;AA5OD,4CA4OC"}
@@ -0,0 +1,4 @@
1
+ export { CustomerIOClient } from './client';
2
+ export type { CustomerIO } from './types';
3
+ export { CustomerIOValidators, ValidationError } from './validators';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidationError = exports.CustomerIOValidators = exports.CustomerIOClient = void 0;
4
+ var client_1 = require("./client");
5
+ Object.defineProperty(exports, "CustomerIOClient", { enumerable: true, get: function () { return client_1.CustomerIOClient; } });
6
+ var validators_1 = require("./validators");
7
+ Object.defineProperty(exports, "CustomerIOValidators", { enumerable: true, get: function () { return validators_1.CustomerIOValidators; } });
8
+ Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return validators_1.ValidationError; } });
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAA4C;AAAnC,0GAAA,gBAAgB,OAAA;AAEzB,2CAAqE;AAA5D,kHAAA,oBAAoB,OAAA;AAAE,6GAAA,eAAe,OAAA"}
@@ -0,0 +1,77 @@
1
+ export declare namespace CustomerIO {
2
+ type CustomerPayload = {
3
+ id: string;
4
+ email: string;
5
+ firstName?: string;
6
+ lastName?: string;
7
+ created_at?: number;
8
+ attributes?: Record<string, any>;
9
+ };
10
+ type DevicePayload = {
11
+ device: {
12
+ id: string;
13
+ platform: string;
14
+ last_used?: number;
15
+ attributes?: Record<string, any>;
16
+ };
17
+ token: string;
18
+ };
19
+ type CustomerResponse = {
20
+ customer: {
21
+ id: string;
22
+ email: string;
23
+ attributes: {
24
+ created_at: number;
25
+ first_name?: string;
26
+ last_name?: string;
27
+ [key: string]: any;
28
+ };
29
+ timestamps: {
30
+ created: number;
31
+ last_updated: number;
32
+ };
33
+ };
34
+ };
35
+ type CustomersResponse = {
36
+ customers: Array<{
37
+ id: string;
38
+ email: string;
39
+ attributes: {
40
+ created_at: number;
41
+ first_name?: string;
42
+ last_name?: string;
43
+ [key: string]: any;
44
+ };
45
+ timestamps: {
46
+ created: number;
47
+ last_updated: number;
48
+ };
49
+ }>;
50
+ pagination: {
51
+ next: string | null;
52
+ start: number;
53
+ limit: number;
54
+ };
55
+ };
56
+ type CustomerSearchParams = {
57
+ filter?: {
58
+ segment?: {
59
+ id: string;
60
+ };
61
+ attribute?: {
62
+ field: string;
63
+ operator: string;
64
+ value: any;
65
+ }[];
66
+ and?: any[];
67
+ or?: any[];
68
+ };
69
+ sort?: {
70
+ field: string;
71
+ direction: "asc" | "desc";
72
+ }[];
73
+ limit?: number;
74
+ start?: number;
75
+ };
76
+ }
77
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,yBAAiB,UAAU,CAAC;IAC1B,KAAY,eAAe,GAAG;QAC5B,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAClC,CAAC;IAEF,KAAY,aAAa,GAAG;QAC1B,MAAM,EAAE;YACN,EAAE,EAAE,MAAM,CAAC;YACX,QAAQ,EAAE,MAAM,CAAC;YACjB,SAAS,CAAC,EAAE,MAAM,CAAC;YACnB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;SAClC,CAAC;QACF,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IAEF,KAAY,gBAAgB,GAAG;QAC7B,QAAQ,EAAE;YACR,EAAE,EAAE,MAAM,CAAC;YACX,KAAK,EAAE,MAAM,CAAC;YACd,UAAU,EAAE;gBACV,UAAU,EAAE,MAAM,CAAC;gBACnB,UAAU,CAAC,EAAE,MAAM,CAAC;gBACpB,SAAS,CAAC,EAAE,MAAM,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K,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;CACH"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import { ValidationError } from '@marketing-sdk/core';
2
+ import { CustomerIO } from './types';
3
+ export { ValidationError };
4
+ export declare class CustomerIOValidators {
5
+ static validateCustomerPayload(payload: CustomerIO.CustomerPayload): void;
6
+ static validateDevicePayload(payload: CustomerIO.DevicePayload): void;
7
+ }
8
+ //# sourceMappingURL=validators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B,qBAAa,oBAAoB;IAC/B,MAAM,CAAC,uBAAuB,CAAC,OAAO,EAAE,UAAU,CAAC,eAAe,GAAG,IAAI;IAkBzE,MAAM,CAAC,qBAAqB,CAAC,OAAO,EAAE,UAAU,CAAC,aAAa,GAAG,IAAI;CAkBtE"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CustomerIOValidators = exports.ValidationError = void 0;
4
+ const core_1 = require("@marketing-sdk/core");
5
+ Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return core_1.ValidationError; } });
6
+ class CustomerIOValidators {
7
+ static validateCustomerPayload(payload) {
8
+ if (!payload.id || payload.id.trim() === '') {
9
+ throw new core_1.ValidationError('id', 'Customer ID is required');
10
+ }
11
+ if (!payload.email || payload.email.trim() === '') {
12
+ throw new core_1.ValidationError('email', 'Email is required');
13
+ }
14
+ if (!core_1.Validators.validateEmail(payload.email)) {
15
+ throw new core_1.ValidationError('email', 'Invalid email format');
16
+ }
17
+ if (payload.created_at !== undefined && payload.created_at < 0) {
18
+ throw new core_1.ValidationError('created_at', 'Created timestamp cannot be negative');
19
+ }
20
+ }
21
+ static validateDevicePayload(payload) {
22
+ if (!payload.device?.id || payload.device.id.trim() === '') {
23
+ throw new core_1.ValidationError('device.id', 'Device ID is required');
24
+ }
25
+ if (!payload.device?.platform || payload.device.platform.trim() === '') {
26
+ throw new core_1.ValidationError('device.platform', 'Device platform is required');
27
+ }
28
+ if (!payload.token || payload.token.trim() === '') {
29
+ throw new core_1.ValidationError('token', 'Device token is required');
30
+ }
31
+ const validPlatforms = ['ios', 'android'];
32
+ if (!validPlatforms.includes(payload.device.platform.toLowerCase())) {
33
+ throw new core_1.ValidationError('device.platform', `Platform must be one of: ${validPlatforms.join(', ')}`);
34
+ }
35
+ }
36
+ }
37
+ exports.CustomerIOValidators = CustomerIOValidators;
38
+ //# sourceMappingURL=validators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.js","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":";;;AAAA,8CAAkE;AAGzD,gGAHY,sBAAe,OAGZ;AAExB,MAAa,oBAAoB;IAC/B,MAAM,CAAC,uBAAuB,CAAC,OAAmC;QAChE,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YAC5C,MAAM,IAAI,sBAAe,CAAC,IAAI,EAAE,yBAAyB,CAAC,CAAC;QAC7D,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YAClD,MAAM,IAAI,sBAAe,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;QAC1D,CAAC;QAED,IAAI,CAAC,iBAAU,CAAC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;CACF;AArCD,oDAqCC"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@marketing-sdk/customerio",
3
+ "version": "0.1.1-experimental.0",
4
+ "description": "Customer.io provider for marketing-sdk",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "dependencies": {
21
+ "@marketing-sdk/core": "0.1.1-experimental.0"
22
+ },
23
+ "peerDependencies": {
24
+ "@marketing-sdk/core": ">=0.1.0"
25
+ },
26
+ "devDependencies": {
27
+ "typescript": "^5.3.0",
28
+ "jest": "^29.7.0",
29
+ "ts-jest": "^29.1.0",
30
+ "@types/jest": "^29.5.0",
31
+ "@types/node": "^20.0.0"
32
+ },
33
+ "scripts": {
34
+ "build": "tsc",
35
+ "test": "jest",
36
+ "test:coverage": "jest --coverage",
37
+ "typecheck": "tsc --noEmit"
38
+ }
39
+ }