@conversokit/integrations 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.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 ConversoKit contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,22 @@
1
+ import type { EmailProvider, EmailSendOptions, EmailSendResult } from './email.js';
2
+ export interface CloudflareEmailProviderOptions {
3
+ accountId: string;
4
+ apiToken: string;
5
+ /** Override for testing. */
6
+ baseUrl?: string;
7
+ }
8
+ /**
9
+ * Cloudflare Email Service (currently in beta — requires Workers Paid plan
10
+ * and a domain onboarded via Cloudflare DNS).
11
+ *
12
+ * Docs: https://developers.cloudflare.com/email-service/get-started/send-emails/
13
+ */
14
+ export declare class CloudflareEmailProvider implements EmailProvider {
15
+ private options;
16
+ id: string;
17
+ private endpoint;
18
+ constructor(options: CloudflareEmailProviderOptions);
19
+ send(opts: EmailSendOptions): Promise<EmailSendResult>;
20
+ }
21
+ export declare function createCloudflareEmailProvider(env?: NodeJS.ProcessEnv): CloudflareEmailProvider | null;
22
+ //# sourceMappingURL=cloudflare.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../src/cloudflare.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEnF,MAAM,WAAW,8BAA8B;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,4BAA4B;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAaD;;;;;GAKG;AACH,qBAAa,uBAAwB,YAAW,aAAa;IAI/C,OAAO,CAAC,OAAO;IAH3B,EAAE,SAAgB;IAClB,OAAO,CAAC,QAAQ,CAAS;gBAEL,OAAO,EAAE,8BAA8B;IAKrD,IAAI,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;CAyC7D;AAED,wBAAgB,6BAA6B,CAC3C,GAAG,GAAE,MAAM,CAAC,UAAwB,kCAOrC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Cloudflare Email Service (currently in beta — requires Workers Paid plan
3
+ * and a domain onboarded via Cloudflare DNS).
4
+ *
5
+ * Docs: https://developers.cloudflare.com/email-service/get-started/send-emails/
6
+ */
7
+ export class CloudflareEmailProvider {
8
+ constructor(options) {
9
+ this.options = options;
10
+ this.id = 'cloudflare';
11
+ const base = options.baseUrl ?? 'https://api.cloudflare.com/client/v4';
12
+ this.endpoint = `${base}/accounts/${options.accountId}/email/sending/send`;
13
+ }
14
+ async send(opts) {
15
+ if (!opts.html && !opts.text) {
16
+ throw new Error('Cloudflare send requires either `html` or `text`.');
17
+ }
18
+ const body = {
19
+ to: opts.to,
20
+ from: opts.from,
21
+ subject: opts.subject
22
+ };
23
+ if (opts.html)
24
+ body.html = opts.html;
25
+ if (opts.text)
26
+ body.text = opts.text;
27
+ if (opts.replyTo)
28
+ body.reply_to = opts.replyTo;
29
+ const res = await fetch(this.endpoint, {
30
+ method: 'POST',
31
+ headers: {
32
+ Authorization: `Bearer ${this.options.apiToken}`,
33
+ 'Content-Type': 'application/json'
34
+ },
35
+ body: JSON.stringify(body)
36
+ });
37
+ let json = null;
38
+ try {
39
+ json = (await res.json());
40
+ }
41
+ catch {
42
+ // fall through to status-only error
43
+ }
44
+ if (!res.ok || !json?.success) {
45
+ const reason = json?.errors?.map((e) => `${e.code}: ${e.message}`).join('; ') ??
46
+ `HTTP ${res.status}`;
47
+ throw new Error(`Cloudflare send failed: ${reason}`);
48
+ }
49
+ const delivered = json.result?.delivered ?? [];
50
+ const queued = json.result?.queued ?? [];
51
+ const id = delivered[0] ?? queued[0] ?? '';
52
+ return { id, ok: true, provider: this.id };
53
+ }
54
+ }
55
+ export function createCloudflareEmailProvider(env = process.env) {
56
+ if (!env.CLOUDFLARE_ACCOUNT_ID || !env.CLOUDFLARE_EMAIL_API_TOKEN)
57
+ return null;
58
+ return new CloudflareEmailProvider({
59
+ accountId: env.CLOUDFLARE_ACCOUNT_ID,
60
+ apiToken: env.CLOUDFLARE_EMAIL_API_TOKEN
61
+ });
62
+ }
package/dist/crm.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ export interface CrmContact {
2
+ email?: string;
3
+ name?: string;
4
+ company?: string;
5
+ properties?: Record<string, string | number | boolean>;
6
+ }
7
+ export interface CrmUpsertResult {
8
+ id: string;
9
+ ok: boolean;
10
+ provider: string;
11
+ }
12
+ export interface CrmProvider {
13
+ id: string;
14
+ upsertContact(contact: CrmContact): Promise<CrmUpsertResult>;
15
+ }
16
+ export declare class MockCrmProvider implements CrmProvider {
17
+ id: string;
18
+ upsertContact(_contact: CrmContact): Promise<CrmUpsertResult>;
19
+ }
20
+ //# sourceMappingURL=crm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crm.d.ts","sourceRoot":"","sources":["../src/crm.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;CACxD;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,OAAO,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAC9D;AAED,qBAAa,eAAgB,YAAW,WAAW;IACjD,EAAE,SAAU;IACN,aAAa,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,eAAe,CAAC;CAOpE"}
package/dist/crm.js ADDED
@@ -0,0 +1,12 @@
1
+ export class MockCrmProvider {
2
+ constructor() {
3
+ this.id = 'mock';
4
+ }
5
+ async upsertContact(_contact) {
6
+ return {
7
+ id: `mock_${Math.random().toString(36).slice(2)}`,
8
+ ok: true,
9
+ provider: this.id
10
+ };
11
+ }
12
+ }
@@ -0,0 +1,19 @@
1
+ export interface EmailSendOptions {
2
+ to: string | string[];
3
+ from: string;
4
+ subject: string;
5
+ html?: string;
6
+ text?: string;
7
+ replyTo?: string;
8
+ tags?: Record<string, string>;
9
+ }
10
+ export interface EmailSendResult {
11
+ id: string;
12
+ ok: boolean;
13
+ provider: string;
14
+ }
15
+ export interface EmailProvider {
16
+ id: string;
17
+ send(options: EmailSendOptions): Promise<EmailSendResult>;
18
+ }
19
+ //# sourceMappingURL=email.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../src/email.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,OAAO,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAC3D"}
package/dist/email.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ import type { CrmContact, CrmProvider, CrmUpsertResult } from './crm.js';
2
+ export interface HubspotProviderOptions {
3
+ apiKey: string;
4
+ /** Override for tests / non-prod regions. */
5
+ baseUrl?: string;
6
+ }
7
+ export declare class HubspotProvider implements CrmProvider {
8
+ private options;
9
+ id: string;
10
+ private baseUrl;
11
+ constructor(options: HubspotProviderOptions);
12
+ private headers;
13
+ private toProperties;
14
+ upsertContact(contact: CrmContact): Promise<CrmUpsertResult>;
15
+ private findByEmail;
16
+ }
17
+ export declare function createHubspotProvider(env?: NodeJS.ProcessEnv): HubspotProvider | null;
18
+ //# sourceMappingURL=hubspot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hubspot.d.ts","sourceRoot":"","sources":["../src/hubspot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEzE,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAcD,qBAAa,eAAgB,YAAW,WAAW;IAIrC,OAAO,CAAC,OAAO;IAH3B,EAAE,SAAa;IACf,OAAO,CAAC,OAAO,CAAS;gBAEJ,OAAO,EAAE,sBAAsB;IAInD,OAAO,CAAC,OAAO;IAOf,OAAO,CAAC,YAAY;IAiBd,aAAa,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,eAAe,CAAC;YAyCpD,WAAW;CAsB1B;AAED,wBAAgB,qBAAqB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,0BAGzE"}
@@ -0,0 +1,87 @@
1
+ const DEFAULT_BASE_URL = 'https://api.hubapi.com';
2
+ export class HubspotProvider {
3
+ constructor(options) {
4
+ this.options = options;
5
+ this.id = 'hubspot';
6
+ this.baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
7
+ }
8
+ headers() {
9
+ return {
10
+ Authorization: `Bearer ${this.options.apiKey}`,
11
+ 'Content-Type': 'application/json'
12
+ };
13
+ }
14
+ toProperties(contact) {
15
+ const props = {};
16
+ if (contact.email)
17
+ props.email = contact.email;
18
+ if (contact.name) {
19
+ const [firstname, ...rest] = contact.name.split(' ');
20
+ props.firstname = firstname;
21
+ if (rest.length)
22
+ props.lastname = rest.join(' ');
23
+ }
24
+ if (contact.company)
25
+ props.company = contact.company;
26
+ if (contact.properties) {
27
+ for (const [k, v] of Object.entries(contact.properties)) {
28
+ props[k] = String(v);
29
+ }
30
+ }
31
+ return props;
32
+ }
33
+ async upsertContact(contact) {
34
+ const properties = this.toProperties(contact);
35
+ // Try create first.
36
+ const createRes = await fetch(`${this.baseUrl}/crm/v3/objects/contacts`, {
37
+ method: 'POST',
38
+ headers: this.headers(),
39
+ body: JSON.stringify({ properties })
40
+ });
41
+ if (createRes.ok) {
42
+ const json = (await createRes.json());
43
+ return { id: json.id, ok: true, provider: this.id };
44
+ }
45
+ // 409 = contact already exists. Look up by email and PATCH.
46
+ if (createRes.status === 409 && contact.email) {
47
+ const existingId = await this.findByEmail(contact.email);
48
+ if (existingId) {
49
+ const patchRes = await fetch(`${this.baseUrl}/crm/v3/objects/contacts/${existingId}`, {
50
+ method: 'PATCH',
51
+ headers: this.headers(),
52
+ body: JSON.stringify({ properties })
53
+ });
54
+ if (!patchRes.ok) {
55
+ throw new Error(`HubSpot contact patch failed: ${patchRes.status} ${await patchRes.text()}`);
56
+ }
57
+ return { id: existingId, ok: true, provider: this.id };
58
+ }
59
+ }
60
+ throw new Error(`HubSpot contact create failed: ${createRes.status} ${await createRes.text()}`);
61
+ }
62
+ async findByEmail(email) {
63
+ const res = await fetch(`${this.baseUrl}/crm/v3/objects/contacts/search`, {
64
+ method: 'POST',
65
+ headers: this.headers(),
66
+ body: JSON.stringify({
67
+ filterGroups: [
68
+ {
69
+ filters: [
70
+ { propertyName: 'email', operator: 'EQ', value: email }
71
+ ]
72
+ }
73
+ ],
74
+ limit: 1
75
+ })
76
+ });
77
+ if (!res.ok)
78
+ return null;
79
+ const json = (await res.json());
80
+ return json.results[0]?.id ?? null;
81
+ }
82
+ }
83
+ export function createHubspotProvider(env = process.env) {
84
+ if (!env.HUBSPOT_API_KEY)
85
+ return null;
86
+ return new HubspotProvider({ apiKey: env.HUBSPOT_API_KEY });
87
+ }
@@ -0,0 +1,11 @@
1
+ export * from './types.js';
2
+ export * from './stores.js';
3
+ export type { EmailProvider, EmailSendOptions, EmailSendResult } from './email.js';
4
+ export { MockPaymentProvider, MockEmailProvider } from './mock.js';
5
+ export { ResendEmailProvider, createResendProvider, type ResendEmailProviderOptions } from './resend.js';
6
+ export { CloudflareEmailProvider, createCloudflareEmailProvider, type CloudflareEmailProviderOptions } from './cloudflare.js';
7
+ export { StripeProvider, createStripeProvider, type StripeProviderOptions, type PriceLookup } from './stripe.js';
8
+ export { MockCrmProvider, type CrmProvider, type CrmContact, type CrmUpsertResult } from './crm.js';
9
+ export { HubspotProvider, createHubspotProvider, type HubspotProviderOptions } from './hubspot.js';
10
+ export { SupabaseCartStore, SupabaseOrderStore, SupabaseReservationStore, SupabaseLeadStore, SupabaseUserDataStore, createSupabaseStores, SUPABASE_SCHEMA_SQL, type SupabaseStoresOptions } from './supabase.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,YAAY,EACV,aAAa,EACb,gBAAgB,EAChB,eAAe,EAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,KAAK,0BAA0B,EAChC,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,uBAAuB,EACvB,6BAA6B,EAC7B,KAAK,8BAA8B,EACpC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,eAAe,EACf,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,eAAe,EACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,KAAK,sBAAsB,EAC5B,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,KAAK,qBAAqB,EAC3B,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export * from './types.js';
2
+ export * from './stores.js';
3
+ export { MockPaymentProvider, MockEmailProvider } from './mock.js';
4
+ export { ResendEmailProvider, createResendProvider } from './resend.js';
5
+ export { CloudflareEmailProvider, createCloudflareEmailProvider } from './cloudflare.js';
6
+ export { StripeProvider, createStripeProvider } from './stripe.js';
7
+ export { MockCrmProvider } from './crm.js';
8
+ export { HubspotProvider, createHubspotProvider } from './hubspot.js';
9
+ export { SupabaseCartStore, SupabaseOrderStore, SupabaseReservationStore, SupabaseLeadStore, SupabaseUserDataStore, createSupabaseStores, SUPABASE_SCHEMA_SQL } from './supabase.js';
package/dist/mock.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type { CheckoutSession, CreateCheckoutOptions, PaymentProvider } from './types.js';
2
+ import type { EmailProvider, EmailSendOptions, EmailSendResult } from './email.js';
3
+ export declare class MockPaymentProvider implements PaymentProvider {
4
+ id: string;
5
+ createCheckoutSession(options: CreateCheckoutOptions): Promise<CheckoutSession>;
6
+ }
7
+ export declare class MockEmailProvider implements EmailProvider {
8
+ id: string;
9
+ send(options: EmailSendOptions): Promise<EmailSendResult>;
10
+ }
11
+ //# sourceMappingURL=mock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,eAAe,EAChB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEnF,qBAAa,mBAAoB,YAAW,eAAe;IACzD,EAAE,SAAU;IACN,qBAAqB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC;CAQtF;AAED,qBAAa,iBAAkB,YAAW,aAAa;IACrD,EAAE,SAAU;IACN,IAAI,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;CAShE"}
package/dist/mock.js ADDED
@@ -0,0 +1,23 @@
1
+ export class MockPaymentProvider {
2
+ constructor() {
3
+ this.id = 'mock';
4
+ }
5
+ async createCheckoutSession(options) {
6
+ const sessionId = `sess_mock_${Math.random().toString(36).slice(2)}`;
7
+ const sep = options.successUrl.includes('?') ? '&' : '?';
8
+ return {
9
+ id: sessionId,
10
+ url: `${options.successUrl}${sep}session_id=${sessionId}`
11
+ };
12
+ }
13
+ }
14
+ export class MockEmailProvider {
15
+ constructor() {
16
+ this.id = 'mock';
17
+ }
18
+ async send(options) {
19
+ const id = `mail_mock_${Math.random().toString(36).slice(2)}`;
20
+ console.log(`[MockEmailProvider] ${options.from} → ${Array.isArray(options.to) ? options.to.join(', ') : options.to} · "${options.subject}"`);
21
+ return { id, ok: true, provider: this.id };
22
+ }
23
+ }
@@ -0,0 +1,12 @@
1
+ import type { EmailProvider, EmailSendOptions, EmailSendResult } from './email.js';
2
+ export interface ResendEmailProviderOptions {
3
+ apiKey: string;
4
+ }
5
+ export declare class ResendEmailProvider implements EmailProvider {
6
+ id: string;
7
+ private client;
8
+ constructor(options: ResendEmailProviderOptions);
9
+ send(options: EmailSendOptions): Promise<EmailSendResult>;
10
+ }
11
+ export declare function createResendProvider(env?: NodeJS.ProcessEnv): ResendEmailProvider | null;
12
+ //# sourceMappingURL=resend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resend.d.ts","sourceRoot":"","sources":["../src/resend.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEnF,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,mBAAoB,YAAW,aAAa;IACvD,EAAE,SAAY;IACd,OAAO,CAAC,MAAM,CAAS;gBAEX,OAAO,EAAE,0BAA0B;IAIzC,IAAI,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;CA6BhE;AAED,wBAAgB,oBAAoB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,8BAGxE"}
package/dist/resend.js ADDED
@@ -0,0 +1,41 @@
1
+ import { Resend } from 'resend';
2
+ export class ResendEmailProvider {
3
+ constructor(options) {
4
+ this.id = 'resend';
5
+ this.client = new Resend(options.apiKey);
6
+ }
7
+ async send(options) {
8
+ if (!options.html && !options.text) {
9
+ throw new Error('Resend send requires either `html` or `text`.');
10
+ }
11
+ const tags = options.tags
12
+ ? Object.entries(options.tags).map(([name, value]) => ({ name, value }))
13
+ : undefined;
14
+ // Build the payload incrementally so html/text optionality matches Resend's
15
+ // discriminated CreateEmailOptions union.
16
+ const base = {
17
+ from: options.from,
18
+ to: options.to,
19
+ subject: options.subject,
20
+ replyTo: options.replyTo,
21
+ tags
22
+ };
23
+ const payload = options.html
24
+ ? { ...base, html: options.html, text: options.text }
25
+ : { ...base, text: options.text };
26
+ const result = await this.client.emails.send(payload);
27
+ if (result.error) {
28
+ throw new Error(`Resend send failed: ${result.error.message}`);
29
+ }
30
+ return {
31
+ id: result.data?.id ?? '',
32
+ ok: true,
33
+ provider: this.id
34
+ };
35
+ }
36
+ }
37
+ export function createResendProvider(env = process.env) {
38
+ if (!env.RESEND_API_KEY)
39
+ return null;
40
+ return new ResendEmailProvider({ apiKey: env.RESEND_API_KEY });
41
+ }
@@ -0,0 +1,51 @@
1
+ import type { Cart, LeadSubmission, Reservation } from '@conversokit/shared';
2
+ export interface CartStore {
3
+ get(sessionId: string): Promise<Cart>;
4
+ set(sessionId: string, cart: Cart): Promise<void>;
5
+ clear(sessionId: string): Promise<void>;
6
+ }
7
+ export interface OrderRecord {
8
+ id: string;
9
+ sessionId: string;
10
+ amount: number;
11
+ currency: string;
12
+ status: 'pending' | 'paid' | 'failed';
13
+ rawEventType: string;
14
+ createdAt: string;
15
+ }
16
+ export interface OrderStore {
17
+ put(order: OrderRecord): Promise<void>;
18
+ list(): Promise<OrderRecord[]>;
19
+ }
20
+ export interface ReservationStore {
21
+ put(reservation: Reservation): Promise<void>;
22
+ get(id: string): Promise<Reservation | undefined>;
23
+ cancel(id: string): Promise<Reservation | undefined>;
24
+ list(): Promise<Reservation[]>;
25
+ }
26
+ export interface LeadStore {
27
+ put(lead: LeadSubmission & {
28
+ id: string;
29
+ }): Promise<void>;
30
+ list(): Promise<Array<LeadSubmission & {
31
+ id: string;
32
+ }>>;
33
+ }
34
+ export interface UserDataExport {
35
+ userId: string;
36
+ records: Record<string, unknown>;
37
+ exportedAt: string;
38
+ }
39
+ export interface UserDataStore {
40
+ put(userId: string, key: string, value: unknown): Promise<void>;
41
+ export(userId: string): Promise<UserDataExport>;
42
+ remove(userId: string): Promise<void>;
43
+ }
44
+ export interface ConversoKitStores {
45
+ cart: CartStore;
46
+ orders: OrderStore;
47
+ reservations: ReservationStore;
48
+ leads: LeadStore;
49
+ userData: UserDataStore;
50
+ }
51
+ //# sourceMappingURL=stores.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stores.d.ts","sourceRoot":"","sources":["../src/stores.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EACJ,cAAc,EACd,WAAW,EACZ,MAAM,qBAAqB,CAAC;AAE7B,MAAM,WAAW,SAAS;IACxB,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAC;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IAClD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IACrD,IAAI,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,SAAS;IACxB,GAAG,CAAC,IAAI,EAAE,cAAc,GAAG;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;CACzD;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAChD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,UAAU,CAAC;IACnB,YAAY,EAAE,gBAAgB,CAAC;IAC/B,KAAK,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,aAAa,CAAC;CACzB"}
package/dist/stores.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ import Stripe from 'stripe';
2
+ import type { CheckoutLineItem, CheckoutSession, CreateCheckoutOptions, WebhookCapablePaymentProvider, WebhookEvent } from './types.js';
3
+ export interface PriceLookup {
4
+ (item: CheckoutLineItem): Promise<{
5
+ priceId?: string;
6
+ amount?: number;
7
+ currency?: string;
8
+ productName?: string;
9
+ }>;
10
+ }
11
+ export interface StripeProviderOptions {
12
+ secretKey: string;
13
+ webhookSecret?: string;
14
+ /** Resolves CheckoutLineItem → Stripe price/amount. */
15
+ priceLookup?: PriceLookup;
16
+ apiVersion?: Stripe.LatestApiVersion;
17
+ }
18
+ export declare class StripeProvider implements WebhookCapablePaymentProvider {
19
+ id: string;
20
+ private client;
21
+ private webhookSecret?;
22
+ private priceLookup;
23
+ constructor(options: StripeProviderOptions);
24
+ createCheckoutSession(options: CreateCheckoutOptions): Promise<CheckoutSession>;
25
+ verifyWebhook(rawBody: string | Buffer, signature: string): WebhookEvent;
26
+ }
27
+ export declare function createStripeProvider(env?: NodeJS.ProcessEnv): StripeProvider | null;
28
+ //# sourceMappingURL=stripe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripe.d.ts","sourceRoot":"","sources":["../src/stripe.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,WAAW;IAC1B,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC;QAChC,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC,CAAC;CACJ;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,uDAAuD;IACvD,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC,gBAAgB,CAAC;CACtC;AAED,qBAAa,cAAe,YAAW,6BAA6B;IAClE,EAAE,SAAY;IACd,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,aAAa,CAAC,CAAS;IAC/B,OAAO,CAAC,WAAW,CAAc;gBAErB,OAAO,EAAE,qBAAqB;IAcpC,qBAAqB,CACzB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,CAAC;IA2C3B,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,YAAY;CAWzE;AAED,wBAAgB,oBAAoB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,yBAQxE"}
package/dist/stripe.js ADDED
@@ -0,0 +1,69 @@
1
+ import Stripe from 'stripe';
2
+ export class StripeProvider {
3
+ constructor(options) {
4
+ this.id = 'stripe';
5
+ this.client = new Stripe(options.secretKey, {
6
+ apiVersion: options.apiVersion
7
+ });
8
+ this.webhookSecret = options.webhookSecret;
9
+ this.priceLookup =
10
+ options.priceLookup ??
11
+ (async (item) => ({
12
+ amount: 1000,
13
+ currency: 'usd',
14
+ productName: `Item ${item.id}`
15
+ }));
16
+ }
17
+ async createCheckoutSession(options) {
18
+ const lineItems = [];
19
+ for (const item of options.items) {
20
+ const lookup = await this.priceLookup(item);
21
+ if (lookup.priceId) {
22
+ lineItems.push({ price: lookup.priceId, quantity: item.quantity });
23
+ }
24
+ else if (lookup.amount && lookup.currency) {
25
+ lineItems.push({
26
+ quantity: item.quantity,
27
+ price_data: {
28
+ currency: lookup.currency,
29
+ unit_amount: lookup.amount,
30
+ product_data: {
31
+ name: lookup.productName ?? item.id
32
+ }
33
+ }
34
+ });
35
+ }
36
+ else {
37
+ throw new Error(`priceLookup must return either priceId or amount+currency for item ${item.id}`);
38
+ }
39
+ }
40
+ const session = await this.client.checkout.sessions.create({
41
+ mode: 'payment',
42
+ line_items: lineItems,
43
+ success_url: options.successUrl,
44
+ cancel_url: options.cancelUrl,
45
+ customer_email: options.customerEmail,
46
+ metadata: options.metadata
47
+ }, options.idempotencyKey ? { idempotencyKey: options.idempotencyKey } : undefined);
48
+ if (!session.url) {
49
+ throw new Error('Stripe did not return a session URL');
50
+ }
51
+ return { id: session.id, url: session.url };
52
+ }
53
+ verifyWebhook(rawBody, signature) {
54
+ if (!this.webhookSecret) {
55
+ throw new Error('webhookSecret is required to verify webhooks');
56
+ }
57
+ const event = this.client.webhooks.constructEvent(rawBody, signature, this.webhookSecret);
58
+ return { id: event.id, type: event.type, data: event.data };
59
+ }
60
+ }
61
+ export function createStripeProvider(env = process.env) {
62
+ if (!env.STRIPE_SECRET_KEY) {
63
+ return null;
64
+ }
65
+ return new StripeProvider({
66
+ secretKey: env.STRIPE_SECRET_KEY,
67
+ webhookSecret: env.STRIPE_WEBHOOK_SECRET
68
+ });
69
+ }
@@ -0,0 +1,62 @@
1
+ import { type SupabaseClient } from '@supabase/supabase-js';
2
+ import type { Cart, LeadSubmission, Reservation } from '@conversokit/shared';
3
+ import type { CartStore, ConversoKitStores, LeadStore, OrderRecord, OrderStore, ReservationStore, UserDataExport, UserDataStore } from './stores.js';
4
+ export interface SupabaseStoresOptions {
5
+ client: SupabaseClient;
6
+ /** Schema name; default 'public'. */
7
+ schema?: string;
8
+ /** Table name overrides. Default: ck_carts, ck_orders, ck_reservations, ck_leads, ck_userdata. */
9
+ tables?: {
10
+ cart?: string;
11
+ orders?: string;
12
+ reservations?: string;
13
+ leads?: string;
14
+ userData?: string;
15
+ };
16
+ }
17
+ export declare class SupabaseCartStore implements CartStore {
18
+ private client;
19
+ private table;
20
+ constructor(client: SupabaseClient, table: string);
21
+ get(sessionId: string): Promise<Cart>;
22
+ set(sessionId: string, cart: Cart): Promise<void>;
23
+ clear(sessionId: string): Promise<void>;
24
+ }
25
+ export declare class SupabaseOrderStore implements OrderStore {
26
+ private client;
27
+ private table;
28
+ constructor(client: SupabaseClient, table: string);
29
+ put(order: OrderRecord): Promise<void>;
30
+ list(): Promise<OrderRecord[]>;
31
+ }
32
+ export declare class SupabaseReservationStore implements ReservationStore {
33
+ private client;
34
+ private table;
35
+ constructor(client: SupabaseClient, table: string);
36
+ put(reservation: Reservation): Promise<void>;
37
+ get(id: string): Promise<Reservation | undefined>;
38
+ cancel(id: string): Promise<Reservation | undefined>;
39
+ list(): Promise<Reservation[]>;
40
+ }
41
+ export declare class SupabaseLeadStore implements LeadStore {
42
+ private client;
43
+ private table;
44
+ constructor(client: SupabaseClient, table: string);
45
+ put(lead: LeadSubmission & {
46
+ id: string;
47
+ }): Promise<void>;
48
+ list(): Promise<Array<LeadSubmission & {
49
+ id: string;
50
+ }>>;
51
+ }
52
+ export declare class SupabaseUserDataStore implements UserDataStore {
53
+ private client;
54
+ private table;
55
+ constructor(client: SupabaseClient, table: string);
56
+ put(userId: string, key: string, value: unknown): Promise<void>;
57
+ export(userId: string): Promise<UserDataExport>;
58
+ remove(userId: string): Promise<void>;
59
+ }
60
+ export declare function createSupabaseStores(env?: NodeJS.ProcessEnv, overrides?: Partial<SupabaseStoresOptions>): ConversoKitStores | null;
61
+ export declare const SUPABASE_SCHEMA_SQL = "-- Run in Supabase SQL editor to create the ConversoKit tables.\ncreate table if not exists ck_carts (\n session_id text primary key,\n cart jsonb not null,\n updated_at timestamptz not null default now()\n);\n\ncreate table if not exists ck_orders (\n id text primary key,\n session_id text not null,\n amount integer not null default 0,\n currency text not null default 'usd',\n status text not null,\n raw_event_type text not null,\n created_at timestamptz not null default now()\n);\n\ncreate table if not exists ck_reservations (\n id text primary key,\n payload jsonb not null,\n created_at timestamptz not null default now()\n);\n\ncreate table if not exists ck_leads (\n id text primary key,\n payload jsonb not null,\n submitted_at timestamptz not null default now()\n);\n\ncreate table if not exists ck_userdata (\n user_id text not null,\n key text not null,\n value jsonb,\n updated_at timestamptz not null default now(),\n primary key (user_id, key)\n);\n";
62
+ //# sourceMappingURL=supabase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../src/supabase.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,226 @@
1
+ import { createClient } from '@supabase/supabase-js';
2
+ export class SupabaseCartStore {
3
+ constructor(client, table) {
4
+ this.client = client;
5
+ this.table = table;
6
+ }
7
+ async get(sessionId) {
8
+ const { data, error } = await this.client
9
+ .from(this.table)
10
+ .select('cart')
11
+ .eq('session_id', sessionId)
12
+ .maybeSingle();
13
+ if (error)
14
+ throw error;
15
+ return (data?.cart ?? { items: [], currency: 'USD' });
16
+ }
17
+ async set(sessionId, cart) {
18
+ const { error } = await this.client
19
+ .from(this.table)
20
+ .upsert({ session_id: sessionId, cart, updated_at: new Date().toISOString() });
21
+ if (error)
22
+ throw error;
23
+ }
24
+ async clear(sessionId) {
25
+ const { error } = await this.client
26
+ .from(this.table)
27
+ .delete()
28
+ .eq('session_id', sessionId);
29
+ if (error)
30
+ throw error;
31
+ }
32
+ }
33
+ export class SupabaseOrderStore {
34
+ constructor(client, table) {
35
+ this.client = client;
36
+ this.table = table;
37
+ }
38
+ async put(order) {
39
+ const { error } = await this.client.from(this.table).upsert({
40
+ id: order.id,
41
+ session_id: order.sessionId,
42
+ amount: order.amount,
43
+ currency: order.currency,
44
+ status: order.status,
45
+ raw_event_type: order.rawEventType,
46
+ created_at: order.createdAt
47
+ });
48
+ if (error)
49
+ throw error;
50
+ }
51
+ async list() {
52
+ const { data, error } = await this.client
53
+ .from(this.table)
54
+ .select('*')
55
+ .order('created_at', { ascending: false });
56
+ if (error)
57
+ throw error;
58
+ return (data ?? []).map((row) => ({
59
+ id: String(row.id),
60
+ sessionId: String(row.session_id),
61
+ amount: Number(row.amount),
62
+ currency: String(row.currency),
63
+ status: row.status,
64
+ rawEventType: String(row.raw_event_type),
65
+ createdAt: String(row.created_at)
66
+ }));
67
+ }
68
+ }
69
+ export class SupabaseReservationStore {
70
+ constructor(client, table) {
71
+ this.client = client;
72
+ this.table = table;
73
+ }
74
+ async put(reservation) {
75
+ const { error } = await this.client
76
+ .from(this.table)
77
+ .upsert({ id: reservation.id, payload: reservation });
78
+ if (error)
79
+ throw error;
80
+ }
81
+ async get(id) {
82
+ const { data, error } = await this.client
83
+ .from(this.table)
84
+ .select('payload')
85
+ .eq('id', id)
86
+ .maybeSingle();
87
+ if (error)
88
+ throw error;
89
+ return data?.payload ?? undefined;
90
+ }
91
+ async cancel(id) {
92
+ const existing = await this.get(id);
93
+ if (!existing)
94
+ return undefined;
95
+ const next = { ...existing, status: 'cancelled' };
96
+ await this.put(next);
97
+ return next;
98
+ }
99
+ async list() {
100
+ const { data, error } = await this.client.from(this.table).select('payload');
101
+ if (error)
102
+ throw error;
103
+ return (data ?? []).map((row) => row.payload);
104
+ }
105
+ }
106
+ export class SupabaseLeadStore {
107
+ constructor(client, table) {
108
+ this.client = client;
109
+ this.table = table;
110
+ }
111
+ async put(lead) {
112
+ const { error } = await this.client
113
+ .from(this.table)
114
+ .upsert({ id: lead.id, payload: lead, submitted_at: lead.submittedAt });
115
+ if (error)
116
+ throw error;
117
+ }
118
+ async list() {
119
+ const { data, error } = await this.client
120
+ .from(this.table)
121
+ .select('payload')
122
+ .order('submitted_at', { ascending: false });
123
+ if (error)
124
+ throw error;
125
+ return (data ?? []).map((row) => row.payload);
126
+ }
127
+ }
128
+ export class SupabaseUserDataStore {
129
+ constructor(client, table) {
130
+ this.client = client;
131
+ this.table = table;
132
+ }
133
+ async put(userId, key, value) {
134
+ const { error } = await this.client
135
+ .from(this.table)
136
+ .upsert({ user_id: userId, key, value, updated_at: new Date().toISOString() });
137
+ if (error)
138
+ throw error;
139
+ }
140
+ async export(userId) {
141
+ const { data, error } = await this.client
142
+ .from(this.table)
143
+ .select('key, value')
144
+ .eq('user_id', userId);
145
+ if (error)
146
+ throw error;
147
+ const records = {};
148
+ for (const row of data ?? []) {
149
+ records[String(row.key)] = row.value;
150
+ }
151
+ return {
152
+ userId,
153
+ records,
154
+ exportedAt: new Date().toISOString()
155
+ };
156
+ }
157
+ async remove(userId) {
158
+ const { error } = await this.client
159
+ .from(this.table)
160
+ .delete()
161
+ .eq('user_id', userId);
162
+ if (error)
163
+ throw error;
164
+ }
165
+ }
166
+ export function createSupabaseStores(env = process.env, overrides = {}) {
167
+ if (!env.SUPABASE_URL || !env.SUPABASE_SERVICE_ROLE_KEY) {
168
+ return null;
169
+ }
170
+ const client = overrides.client ??
171
+ createClient(env.SUPABASE_URL, env.SUPABASE_SERVICE_ROLE_KEY, {
172
+ auth: { persistSession: false }
173
+ });
174
+ const tables = {
175
+ cart: 'ck_carts',
176
+ orders: 'ck_orders',
177
+ reservations: 'ck_reservations',
178
+ leads: 'ck_leads',
179
+ userData: 'ck_userdata',
180
+ ...overrides.tables
181
+ };
182
+ return {
183
+ cart: new SupabaseCartStore(client, tables.cart),
184
+ orders: new SupabaseOrderStore(client, tables.orders),
185
+ reservations: new SupabaseReservationStore(client, tables.reservations),
186
+ leads: new SupabaseLeadStore(client, tables.leads),
187
+ userData: new SupabaseUserDataStore(client, tables.userData)
188
+ };
189
+ }
190
+ export const SUPABASE_SCHEMA_SQL = `-- Run in Supabase SQL editor to create the ConversoKit tables.
191
+ create table if not exists ck_carts (
192
+ session_id text primary key,
193
+ cart jsonb not null,
194
+ updated_at timestamptz not null default now()
195
+ );
196
+
197
+ create table if not exists ck_orders (
198
+ id text primary key,
199
+ session_id text not null,
200
+ amount integer not null default 0,
201
+ currency text not null default 'usd',
202
+ status text not null,
203
+ raw_event_type text not null,
204
+ created_at timestamptz not null default now()
205
+ );
206
+
207
+ create table if not exists ck_reservations (
208
+ id text primary key,
209
+ payload jsonb not null,
210
+ created_at timestamptz not null default now()
211
+ );
212
+
213
+ create table if not exists ck_leads (
214
+ id text primary key,
215
+ payload jsonb not null,
216
+ submitted_at timestamptz not null default now()
217
+ );
218
+
219
+ create table if not exists ck_userdata (
220
+ user_id text not null,
221
+ key text not null,
222
+ value jsonb,
223
+ updated_at timestamptz not null default now(),
224
+ primary key (user_id, key)
225
+ );
226
+ `;
@@ -0,0 +1,34 @@
1
+ export interface CheckoutLineItem {
2
+ id: string;
3
+ quantity: number;
4
+ /**
5
+ * Optional Stripe price ID. If absent, the provider's `priceLookup`
6
+ * callback resolves an id-to-price mapping.
7
+ */
8
+ priceId?: string;
9
+ }
10
+ export interface CheckoutSession {
11
+ id: string;
12
+ url: string;
13
+ }
14
+ export interface CreateCheckoutOptions {
15
+ items: CheckoutLineItem[];
16
+ successUrl: string;
17
+ cancelUrl: string;
18
+ customerEmail?: string;
19
+ metadata?: Record<string, string>;
20
+ idempotencyKey?: string;
21
+ }
22
+ export interface PaymentProvider {
23
+ id: string;
24
+ createCheckoutSession(options: CreateCheckoutOptions): Promise<CheckoutSession>;
25
+ }
26
+ export interface WebhookEvent {
27
+ id: string;
28
+ type: string;
29
+ data: unknown;
30
+ }
31
+ export interface WebhookCapablePaymentProvider extends PaymentProvider {
32
+ verifyWebhook(rawBody: string | Buffer, signature: string): WebhookEvent;
33
+ }
34
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,qBAAqB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CACjF;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,6BAA8B,SAAQ,eAAe;IACpE,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,YAAY,CAAC;CAC1E"}
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@conversokit/integrations",
3
+ "version": "0.1.0",
4
+ "description": "Real and mock integrations for ConversoKit: Stripe, HubSpot, Resend, Cloudflare Email, and Supabase persistent stores.",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/Xyborg/ConversoKit.git",
9
+ "directory": "packages/integrations"
10
+ },
11
+ "homepage": "https://github.com/Xyborg/ConversoKit#readme",
12
+ "bugs": "https://github.com/Xyborg/ConversoKit/issues",
13
+ "type": "module",
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "main": "dist/index.js",
18
+ "types": "dist/index.d.ts",
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "dependencies": {
23
+ "@supabase/supabase-js": "^2.43.0",
24
+ "resend": "^4.0.0",
25
+ "stripe": "^14.0.0",
26
+ "@conversokit/shared": "0.1.0"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^20.10.0",
30
+ "typescript": "^5.2.0"
31
+ },
32
+ "scripts": {
33
+ "build": "tsc --project tsconfig.json",
34
+ "dev": "tsc --project tsconfig.json --watch",
35
+ "typecheck": "tsc --noEmit",
36
+ "lint": "eslint src",
37
+ "test": "echo \"no tests yet\""
38
+ }
39
+ }