@contractspec/integration.providers-impls 1.57.0 → 1.58.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/dist/analytics.d.ts +1 -8
- package/dist/analytics.d.ts.map +1 -1
- package/dist/analytics.js +3 -3
- package/dist/calendar.d.ts +1 -8
- package/dist/calendar.d.ts.map +1 -1
- package/dist/calendar.js +3 -3
- package/dist/database.d.ts +1 -8
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +3 -3
- package/dist/email.d.ts +1 -8
- package/dist/email.d.ts.map +1 -1
- package/dist/email.js +3 -3
- package/dist/embedding.d.ts +1 -8
- package/dist/embedding.d.ts.map +1 -1
- package/dist/embedding.js +3 -3
- package/dist/impls/elevenlabs-voice.d.ts +14 -18
- package/dist/impls/elevenlabs-voice.d.ts.map +1 -1
- package/dist/impls/elevenlabs-voice.js +98 -88
- package/dist/impls/fal-voice.d.ts +22 -26
- package/dist/impls/fal-voice.d.ts.map +1 -1
- package/dist/impls/fal-voice.js +103 -78
- package/dist/impls/fathom-meeting-recorder.d.ts +35 -39
- package/dist/impls/fathom-meeting-recorder.d.ts.map +1 -1
- package/dist/impls/fathom-meeting-recorder.js +285 -142
- package/dist/impls/fathom-meeting-recorder.mapper.d.ts +4 -8
- package/dist/impls/fathom-meeting-recorder.mapper.d.ts.map +1 -1
- package/dist/impls/fathom-meeting-recorder.mapper.js +102 -38
- package/dist/impls/fathom-meeting-recorder.types.d.ts +16 -20
- package/dist/impls/fathom-meeting-recorder.types.d.ts.map +1 -1
- package/dist/impls/fathom-meeting-recorder.types.js +1 -0
- package/dist/impls/fathom-meeting-recorder.utils.d.ts +10 -14
- package/dist/impls/fathom-meeting-recorder.utils.d.ts.map +1 -1
- package/dist/impls/fathom-meeting-recorder.utils.js +58 -41
- package/dist/impls/fathom-meeting-recorder.webhooks.d.ts +3 -7
- package/dist/impls/fathom-meeting-recorder.webhooks.d.ts.map +1 -1
- package/dist/impls/fathom-meeting-recorder.webhooks.js +25 -20
- package/dist/impls/fireflies-meeting-recorder.d.ts +21 -25
- package/dist/impls/fireflies-meeting-recorder.d.ts.map +1 -1
- package/dist/impls/fireflies-meeting-recorder.js +272 -149
- package/dist/impls/fireflies-meeting-recorder.queries.d.ts +3 -6
- package/dist/impls/fireflies-meeting-recorder.queries.d.ts.map +1 -1
- package/dist/impls/fireflies-meeting-recorder.queries.js +10 -8
- package/dist/impls/fireflies-meeting-recorder.types.d.ts +26 -29
- package/dist/impls/fireflies-meeting-recorder.types.d.ts.map +1 -1
- package/dist/impls/fireflies-meeting-recorder.types.js +1 -0
- package/dist/impls/fireflies-meeting-recorder.utils.d.ts +4 -7
- package/dist/impls/fireflies-meeting-recorder.utils.d.ts.map +1 -1
- package/dist/impls/fireflies-meeting-recorder.utils.js +34 -27
- package/dist/impls/gcs-storage.d.ts +18 -22
- package/dist/impls/gcs-storage.d.ts.map +1 -1
- package/dist/impls/gcs-storage.js +92 -84
- package/dist/impls/gmail-inbound.d.ts +20 -24
- package/dist/impls/gmail-inbound.d.ts.map +1 -1
- package/dist/impls/gmail-inbound.js +212 -185
- package/dist/impls/gmail-outbound.d.ts +12 -16
- package/dist/impls/gmail-outbound.d.ts.map +1 -1
- package/dist/impls/gmail-outbound.js +126 -92
- package/dist/impls/google-calendar.d.ts +17 -21
- package/dist/impls/google-calendar.d.ts.map +1 -1
- package/dist/impls/google-calendar.js +182 -145
- package/dist/impls/gradium-voice.d.ts +20 -22
- package/dist/impls/gradium-voice.d.ts.map +1 -1
- package/dist/impls/gradium-voice.js +85 -74
- package/dist/impls/granola-meeting-recorder.d.ts +31 -24
- package/dist/impls/granola-meeting-recorder.d.ts.map +1 -1
- package/dist/impls/granola-meeting-recorder.js +511 -143
- package/dist/impls/granola-meeting-recorder.mcp.d.ts +25 -0
- package/dist/impls/granola-meeting-recorder.mcp.d.ts.map +1 -0
- package/dist/impls/granola-meeting-recorder.mcp.js +279 -0
- package/dist/impls/granola-meeting-recorder.types.d.ts +60 -49
- package/dist/impls/granola-meeting-recorder.types.d.ts.map +1 -1
- package/dist/impls/granola-meeting-recorder.types.js +1 -0
- package/dist/impls/index.d.ts +28 -28
- package/dist/impls/index.d.ts.map +1 -0
- package/dist/impls/index.js +4659 -29
- package/dist/impls/jira.d.ts +18 -22
- package/dist/impls/jira.d.ts.map +1 -1
- package/dist/impls/jira.js +112 -101
- package/dist/impls/linear.d.ts +17 -21
- package/dist/impls/linear.d.ts.map +1 -1
- package/dist/impls/linear.js +78 -69
- package/dist/impls/mistral-embedding.d.ts +17 -21
- package/dist/impls/mistral-embedding.d.ts.map +1 -1
- package/dist/impls/mistral-embedding.js +41 -39
- package/dist/impls/mistral-llm.d.ts +25 -29
- package/dist/impls/mistral-llm.d.ts.map +1 -1
- package/dist/impls/mistral-llm.js +266 -244
- package/dist/impls/notion.d.ts +20 -24
- package/dist/impls/notion.d.ts.map +1 -1
- package/dist/impls/notion.js +145 -110
- package/dist/impls/posthog-reader.d.ts +18 -22
- package/dist/impls/posthog-reader.d.ts.map +1 -1
- package/dist/impls/posthog-reader.js +148 -129
- package/dist/impls/posthog-utils.d.ts +4 -7
- package/dist/impls/posthog-utils.d.ts.map +1 -1
- package/dist/impls/posthog-utils.js +31 -22
- package/dist/impls/posthog.d.ts +33 -37
- package/dist/impls/posthog.d.ts.map +1 -1
- package/dist/impls/posthog.js +320 -119
- package/dist/impls/postmark-email.d.ts +13 -17
- package/dist/impls/postmark-email.d.ts.map +1 -1
- package/dist/impls/postmark-email.js +55 -50
- package/dist/impls/powens-client.d.ts +111 -114
- package/dist/impls/powens-client.d.ts.map +1 -1
- package/dist/impls/powens-client.js +194 -170
- package/dist/impls/powens-openbanking.d.ts +22 -26
- package/dist/impls/powens-openbanking.d.ts.map +1 -1
- package/dist/impls/powens-openbanking.js +425 -217
- package/dist/impls/provider-factory.d.ts +29 -33
- package/dist/impls/provider-factory.d.ts.map +1 -1
- package/dist/impls/provider-factory.js +4072 -275
- package/dist/impls/qdrant-vector.d.ts +18 -22
- package/dist/impls/qdrant-vector.d.ts.map +1 -1
- package/dist/impls/qdrant-vector.js +76 -69
- package/dist/impls/stripe-payments.d.ts +22 -26
- package/dist/impls/stripe-payments.d.ts.map +1 -1
- package/dist/impls/stripe-payments.js +219 -193
- package/dist/impls/supabase-psql.d.ts +21 -25
- package/dist/impls/supabase-psql.d.ts.map +1 -1
- package/dist/impls/supabase-psql.js +138 -98
- package/dist/impls/supabase-vector.d.ts +29 -33
- package/dist/impls/supabase-vector.d.ts.map +1 -1
- package/dist/impls/supabase-vector.js +278 -103
- package/dist/impls/tldv-meeting-recorder.d.ts +18 -22
- package/dist/impls/tldv-meeting-recorder.d.ts.map +1 -1
- package/dist/impls/tldv-meeting-recorder.js +142 -127
- package/dist/impls/twilio-sms.d.ts +14 -17
- package/dist/impls/twilio-sms.d.ts.map +1 -1
- package/dist/impls/twilio-sms.js +62 -55
- package/dist/index.d.ts +15 -64
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4700 -107
- package/dist/llm.d.ts +1 -8
- package/dist/llm.d.ts.map +1 -1
- package/dist/llm.js +3 -3
- package/dist/meeting-recorder.d.ts +1 -8
- package/dist/meeting-recorder.d.ts.map +1 -1
- package/dist/meeting-recorder.js +3 -3
- package/dist/node/analytics.js +2 -0
- package/dist/node/calendar.js +2 -0
- package/dist/node/database.js +2 -0
- package/dist/node/email.js +2 -0
- package/dist/node/embedding.js +2 -0
- package/dist/node/impls/elevenlabs-voice.js +102 -0
- package/dist/node/impls/fal-voice.js +112 -0
- package/dist/node/impls/fathom-meeting-recorder.js +287 -0
- package/dist/node/impls/fathom-meeting-recorder.mapper.js +105 -0
- package/dist/node/impls/fathom-meeting-recorder.types.js +0 -0
- package/dist/node/impls/fathom-meeting-recorder.utils.js +72 -0
- package/dist/node/impls/fathom-meeting-recorder.webhooks.js +29 -0
- package/dist/node/impls/fireflies-meeting-recorder.js +274 -0
- package/dist/node/impls/fireflies-meeting-recorder.queries.js +85 -0
- package/dist/node/impls/fireflies-meeting-recorder.types.js +0 -0
- package/dist/node/impls/fireflies-meeting-recorder.utils.js +42 -0
- package/dist/node/impls/gcs-storage.js +97 -0
- package/dist/node/impls/gmail-inbound.js +227 -0
- package/dist/node/impls/gmail-outbound.js +139 -0
- package/dist/node/impls/google-calendar.js +191 -0
- package/dist/node/impls/gradium-voice.js +90 -0
- package/dist/node/impls/granola-meeting-recorder.js +512 -0
- package/dist/node/impls/granola-meeting-recorder.mcp.js +278 -0
- package/dist/node/impls/granola-meeting-recorder.types.js +0 -0
- package/dist/node/impls/index.js +4658 -0
- package/dist/node/impls/jira.js +124 -0
- package/dist/node/impls/linear.js +83 -0
- package/dist/node/impls/mistral-embedding.js +43 -0
- package/dist/node/impls/mistral-llm.js +269 -0
- package/dist/node/impls/notion.js +160 -0
- package/dist/node/impls/posthog-reader.js +159 -0
- package/dist/node/impls/posthog-utils.js +38 -0
- package/dist/node/impls/posthog.js +322 -0
- package/dist/node/impls/postmark-email.js +60 -0
- package/dist/node/impls/powens-client.js +195 -0
- package/dist/node/impls/powens-openbanking.js +426 -0
- package/dist/node/impls/provider-factory.js +4080 -0
- package/dist/node/impls/qdrant-vector.js +78 -0
- package/dist/node/impls/stripe-payments.js +228 -0
- package/dist/node/impls/supabase-psql.js +150 -0
- package/dist/node/impls/supabase-vector.js +323 -0
- package/dist/node/impls/tldv-meeting-recorder.js +145 -0
- package/dist/node/impls/twilio-sms.js +65 -0
- package/dist/node/index.js +4699 -0
- package/dist/node/llm.js +2 -0
- package/dist/node/meeting-recorder.js +2 -0
- package/dist/node/openbanking.js +2 -0
- package/dist/node/payments.js +2 -0
- package/dist/node/project-management.js +2 -0
- package/dist/node/runtime.js +0 -0
- package/dist/node/secrets/provider.js +11 -0
- package/dist/node/sms.js +2 -0
- package/dist/node/storage.js +2 -0
- package/dist/node/vector-store.js +2 -0
- package/dist/node/voice.js +2 -0
- package/dist/openbanking.d.ts +1 -8
- package/dist/openbanking.d.ts.map +1 -1
- package/dist/openbanking.js +3 -3
- package/dist/payments.d.ts +1 -8
- package/dist/payments.d.ts.map +1 -1
- package/dist/payments.js +3 -3
- package/dist/project-management.d.ts +1 -8
- package/dist/project-management.d.ts.map +1 -1
- package/dist/project-management.js +3 -3
- package/dist/runtime.d.ts +2 -2
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/secrets/provider.d.ts +3 -2
- package/dist/secrets/provider.d.ts.map +1 -0
- package/dist/secrets/provider.js +12 -3
- package/dist/sms.d.ts +1 -8
- package/dist/sms.d.ts.map +1 -1
- package/dist/sms.js +3 -3
- package/dist/storage.d.ts +1 -8
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +3 -3
- package/dist/vector-store.d.ts +1 -8
- package/dist/vector-store.d.ts.map +1 -1
- package/dist/vector-store.js +3 -3
- package/dist/voice.d.ts +1 -8
- package/dist/voice.d.ts.map +1 -1
- package/dist/voice.js +3 -3
- package/package.json +405 -114
- package/dist/_virtual/_rolldown/runtime.js +0 -36
- package/dist/impls/elevenlabs-voice.js.map +0 -1
- package/dist/impls/fal-voice.js.map +0 -1
- package/dist/impls/fathom-meeting-recorder.js.map +0 -1
- package/dist/impls/fathom-meeting-recorder.mapper.js.map +0 -1
- package/dist/impls/fathom-meeting-recorder.utils.js.map +0 -1
- package/dist/impls/fathom-meeting-recorder.webhooks.js.map +0 -1
- package/dist/impls/fireflies-meeting-recorder.js.map +0 -1
- package/dist/impls/fireflies-meeting-recorder.queries.js.map +0 -1
- package/dist/impls/fireflies-meeting-recorder.utils.js.map +0 -1
- package/dist/impls/gcs-storage.js.map +0 -1
- package/dist/impls/gmail-inbound.js.map +0 -1
- package/dist/impls/gmail-outbound.js.map +0 -1
- package/dist/impls/google-calendar.js.map +0 -1
- package/dist/impls/gradium-voice.js.map +0 -1
- package/dist/impls/granola-meeting-recorder.js.map +0 -1
- package/dist/impls/jira.js.map +0 -1
- package/dist/impls/linear.js.map +0 -1
- package/dist/impls/mistral-embedding.js.map +0 -1
- package/dist/impls/mistral-llm.js.map +0 -1
- package/dist/impls/notion.js.map +0 -1
- package/dist/impls/posthog-reader.js.map +0 -1
- package/dist/impls/posthog-utils.js.map +0 -1
- package/dist/impls/posthog.js.map +0 -1
- package/dist/impls/postmark-email.js.map +0 -1
- package/dist/impls/powens-client.js.map +0 -1
- package/dist/impls/powens-openbanking.js.map +0 -1
- package/dist/impls/provider-factory.js.map +0 -1
- package/dist/impls/qdrant-vector.js.map +0 -1
- package/dist/impls/stripe-payments.js.map +0 -1
- package/dist/impls/supabase-psql.js.map +0 -1
- package/dist/impls/supabase-vector.js.map +0 -1
- package/dist/impls/tldv-meeting-recorder.js.map +0 -1
- package/dist/impls/twilio-sms.js.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// src/impls/qdrant-vector.ts
|
|
2
|
+
import { QdrantClient } from "@qdrant/js-client-rest";
|
|
3
|
+
|
|
4
|
+
class QdrantVectorProvider {
|
|
5
|
+
client;
|
|
6
|
+
createCollectionIfMissing;
|
|
7
|
+
distance;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.client = options.client ?? new QdrantClient({
|
|
10
|
+
url: options.url,
|
|
11
|
+
apiKey: options.apiKey,
|
|
12
|
+
...options.clientParams
|
|
13
|
+
});
|
|
14
|
+
this.createCollectionIfMissing = options.createCollectionIfMissing ?? true;
|
|
15
|
+
this.distance = options.distance ?? "Cosine";
|
|
16
|
+
}
|
|
17
|
+
async upsert(request) {
|
|
18
|
+
if (request.documents.length === 0)
|
|
19
|
+
return;
|
|
20
|
+
const firstDocument = request.documents[0];
|
|
21
|
+
if (!firstDocument)
|
|
22
|
+
return;
|
|
23
|
+
const vectorSize = firstDocument.vector.length;
|
|
24
|
+
if (this.createCollectionIfMissing) {
|
|
25
|
+
await this.ensureCollection(request.collection, vectorSize);
|
|
26
|
+
}
|
|
27
|
+
const points = request.documents.map((document) => ({
|
|
28
|
+
id: document.id,
|
|
29
|
+
vector: document.vector,
|
|
30
|
+
payload: {
|
|
31
|
+
...document.payload,
|
|
32
|
+
...document.namespace ? { namespace: document.namespace } : {},
|
|
33
|
+
...document.expiresAt ? { expiresAt: document.expiresAt.toISOString() } : {}
|
|
34
|
+
}
|
|
35
|
+
}));
|
|
36
|
+
await this.client.upsert(request.collection, {
|
|
37
|
+
wait: true,
|
|
38
|
+
points
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async search(query) {
|
|
42
|
+
const results = await this.client.search(query.collection, {
|
|
43
|
+
vector: query.vector,
|
|
44
|
+
limit: query.topK,
|
|
45
|
+
filter: query.filter,
|
|
46
|
+
score_threshold: query.scoreThreshold,
|
|
47
|
+
with_payload: true,
|
|
48
|
+
with_vector: false
|
|
49
|
+
});
|
|
50
|
+
return results.map((item) => ({
|
|
51
|
+
id: String(item.id),
|
|
52
|
+
score: item.score,
|
|
53
|
+
payload: item.payload ?? undefined,
|
|
54
|
+
namespace: typeof item.payload === "object" && item.payload !== null ? item.payload.namespace : undefined
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
async delete(request) {
|
|
58
|
+
await this.client.delete(request.collection, {
|
|
59
|
+
wait: true,
|
|
60
|
+
points: request.ids
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async ensureCollection(collectionName, vectorSize) {
|
|
64
|
+
try {
|
|
65
|
+
await this.client.getCollection(collectionName);
|
|
66
|
+
} catch (_error) {
|
|
67
|
+
await this.client.createCollection(collectionName, {
|
|
68
|
+
vectors: {
|
|
69
|
+
size: vectorSize,
|
|
70
|
+
distance: this.distance
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
QdrantVectorProvider
|
|
78
|
+
};
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// src/impls/stripe-payments.ts
|
|
2
|
+
import Stripe from "stripe";
|
|
3
|
+
var API_VERSION = "2026-01-28.clover";
|
|
4
|
+
|
|
5
|
+
class StripePaymentsProvider {
|
|
6
|
+
stripe;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.stripe = options.stripe ?? new Stripe(options.apiKey, {
|
|
9
|
+
apiVersion: API_VERSION
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
async createCustomer(input) {
|
|
13
|
+
const customer = await this.stripe.customers.create({
|
|
14
|
+
email: input.email,
|
|
15
|
+
name: input.name,
|
|
16
|
+
description: input.description,
|
|
17
|
+
metadata: input.metadata
|
|
18
|
+
});
|
|
19
|
+
return this.toCustomer(customer);
|
|
20
|
+
}
|
|
21
|
+
async getCustomer(customerId) {
|
|
22
|
+
const customer = await this.stripe.customers.retrieve(customerId);
|
|
23
|
+
if (customer.deleted)
|
|
24
|
+
return null;
|
|
25
|
+
return this.toCustomer(customer);
|
|
26
|
+
}
|
|
27
|
+
async createPaymentIntent(input) {
|
|
28
|
+
const intent = await this.stripe.paymentIntents.create({
|
|
29
|
+
amount: input.amount.amount,
|
|
30
|
+
currency: input.amount.currency,
|
|
31
|
+
customer: input.customerId,
|
|
32
|
+
description: input.description,
|
|
33
|
+
capture_method: input.captureMethod ?? "automatic",
|
|
34
|
+
confirmation_method: input.confirmationMethod ?? "automatic",
|
|
35
|
+
automatic_payment_methods: { enabled: true },
|
|
36
|
+
metadata: input.metadata,
|
|
37
|
+
return_url: input.returnUrl,
|
|
38
|
+
statement_descriptor: input.statementDescriptor
|
|
39
|
+
});
|
|
40
|
+
return this.toPaymentIntent(intent);
|
|
41
|
+
}
|
|
42
|
+
async capturePayment(paymentIntentId, input) {
|
|
43
|
+
const intent = await this.stripe.paymentIntents.capture(paymentIntentId, input?.amount ? { amount_to_capture: input.amount.amount } : undefined);
|
|
44
|
+
return this.toPaymentIntent(intent);
|
|
45
|
+
}
|
|
46
|
+
async cancelPaymentIntent(paymentIntentId) {
|
|
47
|
+
const intent = await this.stripe.paymentIntents.cancel(paymentIntentId);
|
|
48
|
+
return this.toPaymentIntent(intent);
|
|
49
|
+
}
|
|
50
|
+
async refundPayment(input) {
|
|
51
|
+
const refund = await this.stripe.refunds.create({
|
|
52
|
+
payment_intent: input.paymentIntentId,
|
|
53
|
+
amount: input.amount?.amount,
|
|
54
|
+
reason: mapRefundReason(input.reason),
|
|
55
|
+
metadata: input.metadata
|
|
56
|
+
});
|
|
57
|
+
const paymentIntentId = typeof refund.payment_intent === "string" ? refund.payment_intent : refund.payment_intent?.id ?? "";
|
|
58
|
+
return {
|
|
59
|
+
id: refund.id,
|
|
60
|
+
paymentIntentId,
|
|
61
|
+
amount: {
|
|
62
|
+
amount: refund.amount ?? 0,
|
|
63
|
+
currency: refund.currency?.toUpperCase() ?? "USD"
|
|
64
|
+
},
|
|
65
|
+
status: mapRefundStatus(refund.status),
|
|
66
|
+
reason: refund.reason ?? undefined,
|
|
67
|
+
metadata: this.toMetadata(refund.metadata),
|
|
68
|
+
createdAt: refund.created ? new Date(refund.created * 1000) : undefined
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
async listInvoices(query) {
|
|
72
|
+
const requestedStatus = query?.status?.[0];
|
|
73
|
+
const stripeStatus = requestedStatus && requestedStatus !== "deleted" ? requestedStatus : undefined;
|
|
74
|
+
const response = await this.stripe.invoices.list({
|
|
75
|
+
customer: query?.customerId,
|
|
76
|
+
status: stripeStatus,
|
|
77
|
+
limit: query?.limit,
|
|
78
|
+
starting_after: query?.startingAfter
|
|
79
|
+
});
|
|
80
|
+
return response.data.map((invoice) => this.toInvoice(invoice));
|
|
81
|
+
}
|
|
82
|
+
async listTransactions(query) {
|
|
83
|
+
const response = await this.stripe.charges.list({
|
|
84
|
+
customer: query?.customerId,
|
|
85
|
+
payment_intent: query?.paymentIntentId,
|
|
86
|
+
limit: query?.limit,
|
|
87
|
+
starting_after: query?.startingAfter
|
|
88
|
+
});
|
|
89
|
+
return response.data.map((charge) => ({
|
|
90
|
+
id: charge.id,
|
|
91
|
+
paymentIntentId: typeof charge.payment_intent === "string" ? charge.payment_intent : charge.payment_intent?.id,
|
|
92
|
+
amount: {
|
|
93
|
+
amount: charge.amount,
|
|
94
|
+
currency: charge.currency?.toUpperCase() ?? "USD"
|
|
95
|
+
},
|
|
96
|
+
type: "capture",
|
|
97
|
+
status: mapChargeStatus(charge.status),
|
|
98
|
+
description: charge.description ?? undefined,
|
|
99
|
+
createdAt: new Date(charge.created * 1000),
|
|
100
|
+
metadata: this.mergeMetadata(this.toMetadata(charge.metadata), {
|
|
101
|
+
balanceTransaction: typeof charge.balance_transaction === "string" ? charge.balance_transaction : undefined
|
|
102
|
+
})
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
toCustomer(customer) {
|
|
106
|
+
const metadata = this.toMetadata(customer.metadata);
|
|
107
|
+
const updatedAtValue = metadata?.updatedAt;
|
|
108
|
+
return {
|
|
109
|
+
id: customer.id,
|
|
110
|
+
email: customer.email ?? undefined,
|
|
111
|
+
name: customer.name ?? undefined,
|
|
112
|
+
metadata,
|
|
113
|
+
createdAt: customer.created ? new Date(customer.created * 1000) : undefined,
|
|
114
|
+
updatedAt: updatedAtValue ? new Date(updatedAtValue) : undefined
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
toPaymentIntent(intent) {
|
|
118
|
+
const metadata = this.toMetadata(intent.metadata);
|
|
119
|
+
return {
|
|
120
|
+
id: intent.id,
|
|
121
|
+
amount: this.toMoney(intent.amount_received ?? intent.amount ?? 0, intent.currency),
|
|
122
|
+
status: mapPaymentIntentStatus(intent.status),
|
|
123
|
+
customerId: typeof intent.customer === "string" ? intent.customer : intent.customer?.id,
|
|
124
|
+
description: intent.description ?? undefined,
|
|
125
|
+
clientSecret: intent.client_secret ?? undefined,
|
|
126
|
+
metadata,
|
|
127
|
+
createdAt: new Date(intent.created * 1000),
|
|
128
|
+
updatedAt: intent.canceled_at != null ? new Date(intent.canceled_at * 1000) : new Date(intent.created * 1000)
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
toInvoice(invoice) {
|
|
132
|
+
const metadata = this.toMetadata(invoice.metadata);
|
|
133
|
+
return {
|
|
134
|
+
id: invoice.id,
|
|
135
|
+
number: invoice.number ?? undefined,
|
|
136
|
+
status: invoice.status ?? "draft",
|
|
137
|
+
amountDue: this.toMoney(invoice.amount_due ?? 0, invoice.currency),
|
|
138
|
+
amountPaid: this.toMoney(invoice.amount_paid ?? 0, invoice.currency),
|
|
139
|
+
customerId: typeof invoice.customer === "string" ? invoice.customer : invoice.customer?.id,
|
|
140
|
+
dueDate: invoice.due_date ? new Date(invoice.due_date * 1000) : undefined,
|
|
141
|
+
hostedInvoiceUrl: invoice.hosted_invoice_url ?? undefined,
|
|
142
|
+
metadata,
|
|
143
|
+
createdAt: invoice.created ? new Date(invoice.created * 1000) : undefined,
|
|
144
|
+
updatedAt: invoice.status_transitions?.finalized_at ? new Date(invoice.status_transitions.finalized_at * 1000) : undefined
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
toMoney(amount, currency) {
|
|
148
|
+
return {
|
|
149
|
+
amount,
|
|
150
|
+
currency: currency?.toUpperCase() ?? "USD"
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
toMetadata(metadata) {
|
|
154
|
+
if (!metadata)
|
|
155
|
+
return;
|
|
156
|
+
const entries = Object.entries(metadata).filter((entry) => typeof entry[1] === "string");
|
|
157
|
+
if (entries.length === 0)
|
|
158
|
+
return;
|
|
159
|
+
return Object.fromEntries(entries);
|
|
160
|
+
}
|
|
161
|
+
mergeMetadata(base, extras) {
|
|
162
|
+
const filteredExtras = Object.entries(extras).filter((entry) => typeof entry[1] === "string");
|
|
163
|
+
if (!base && filteredExtras.length === 0) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
...base ?? {},
|
|
168
|
+
...Object.fromEntries(filteredExtras)
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function mapRefundReason(reason) {
|
|
173
|
+
if (!reason)
|
|
174
|
+
return;
|
|
175
|
+
const allowed = [
|
|
176
|
+
"duplicate",
|
|
177
|
+
"fraudulent",
|
|
178
|
+
"requested_by_customer"
|
|
179
|
+
];
|
|
180
|
+
return allowed.includes(reason) ? reason : undefined;
|
|
181
|
+
}
|
|
182
|
+
function mapPaymentIntentStatus(status) {
|
|
183
|
+
switch (status) {
|
|
184
|
+
case "requires_payment_method":
|
|
185
|
+
return "requires_payment_method";
|
|
186
|
+
case "requires_confirmation":
|
|
187
|
+
return "requires_confirmation";
|
|
188
|
+
case "requires_action":
|
|
189
|
+
case "requires_capture":
|
|
190
|
+
return "requires_action";
|
|
191
|
+
case "processing":
|
|
192
|
+
return "processing";
|
|
193
|
+
case "succeeded":
|
|
194
|
+
return "succeeded";
|
|
195
|
+
case "canceled":
|
|
196
|
+
return "canceled";
|
|
197
|
+
default:
|
|
198
|
+
return "requires_payment_method";
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function mapRefundStatus(status) {
|
|
202
|
+
switch (status) {
|
|
203
|
+
case "pending":
|
|
204
|
+
case "succeeded":
|
|
205
|
+
case "failed":
|
|
206
|
+
case "canceled":
|
|
207
|
+
return status;
|
|
208
|
+
default:
|
|
209
|
+
return "pending";
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function mapChargeStatus(status) {
|
|
213
|
+
switch (status) {
|
|
214
|
+
case "pending":
|
|
215
|
+
case "processing":
|
|
216
|
+
return "pending";
|
|
217
|
+
case "succeeded":
|
|
218
|
+
return "succeeded";
|
|
219
|
+
case "failed":
|
|
220
|
+
case "canceled":
|
|
221
|
+
return "failed";
|
|
222
|
+
default:
|
|
223
|
+
return "pending";
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
export {
|
|
227
|
+
StripePaymentsProvider
|
|
228
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// src/impls/supabase-psql.ts
|
|
2
|
+
import { Buffer } from "node:buffer";
|
|
3
|
+
import { sql as drizzleSql } from "drizzle-orm";
|
|
4
|
+
import { drizzle } from "drizzle-orm/postgres-js";
|
|
5
|
+
import postgres from "postgres";
|
|
6
|
+
|
|
7
|
+
class SupabasePostgresProvider {
|
|
8
|
+
client;
|
|
9
|
+
db;
|
|
10
|
+
ownsClient;
|
|
11
|
+
createDrizzle;
|
|
12
|
+
constructor(options = {}) {
|
|
13
|
+
this.createDrizzle = options.createDrizzle ?? ((client) => drizzle(client));
|
|
14
|
+
if (options.db) {
|
|
15
|
+
if (!options.client) {
|
|
16
|
+
throw new Error("SupabasePostgresProvider requires a postgres client when db is provided.");
|
|
17
|
+
}
|
|
18
|
+
this.client = options.client;
|
|
19
|
+
this.db = options.db;
|
|
20
|
+
this.ownsClient = false;
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (options.client) {
|
|
24
|
+
this.client = options.client;
|
|
25
|
+
this.ownsClient = false;
|
|
26
|
+
} else {
|
|
27
|
+
if (!options.connectionString) {
|
|
28
|
+
throw new Error("SupabasePostgresProvider requires either a connectionString or a client.");
|
|
29
|
+
}
|
|
30
|
+
this.client = postgres(options.connectionString, {
|
|
31
|
+
max: options.maxConnections,
|
|
32
|
+
prepare: false,
|
|
33
|
+
ssl: resolveSslMode(options.sslMode)
|
|
34
|
+
});
|
|
35
|
+
this.ownsClient = true;
|
|
36
|
+
}
|
|
37
|
+
this.db = this.createDrizzle(this.client);
|
|
38
|
+
}
|
|
39
|
+
async query(statement, params = []) {
|
|
40
|
+
const query = buildParameterizedSql(statement, params);
|
|
41
|
+
const result = await this.db.execute(query);
|
|
42
|
+
const rows = asRows(result);
|
|
43
|
+
return {
|
|
44
|
+
rows,
|
|
45
|
+
rowCount: rows.length
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async execute(statement, params = []) {
|
|
49
|
+
const query = buildParameterizedSql(statement, params);
|
|
50
|
+
await this.db.execute(query);
|
|
51
|
+
}
|
|
52
|
+
async transaction(run) {
|
|
53
|
+
const transactionResult = this.client.begin(async (transactionClient) => {
|
|
54
|
+
const transactionalProvider = new SupabasePostgresProvider({
|
|
55
|
+
client: transactionClient,
|
|
56
|
+
db: this.createDrizzle(transactionClient),
|
|
57
|
+
createDrizzle: this.createDrizzle
|
|
58
|
+
});
|
|
59
|
+
return run(transactionalProvider);
|
|
60
|
+
});
|
|
61
|
+
return transactionResult;
|
|
62
|
+
}
|
|
63
|
+
async close() {
|
|
64
|
+
if (this.ownsClient) {
|
|
65
|
+
await this.client.end({ timeout: 5 });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function buildParameterizedSql(statement, params) {
|
|
70
|
+
const segments = [];
|
|
71
|
+
const pattern = /\$(\d+)/g;
|
|
72
|
+
let cursor = 0;
|
|
73
|
+
for (const match of statement.matchAll(pattern)) {
|
|
74
|
+
const token = match[0];
|
|
75
|
+
const indexPart = match[1];
|
|
76
|
+
const start = match.index;
|
|
77
|
+
if (indexPart == null || start == null)
|
|
78
|
+
continue;
|
|
79
|
+
const parameterIndex = Number(indexPart) - 1;
|
|
80
|
+
if (!Number.isInteger(parameterIndex) || parameterIndex < 0 || parameterIndex >= params.length) {
|
|
81
|
+
throw new Error(`SQL placeholder ${token} is out of bounds for ${params.length} parameter(s).`);
|
|
82
|
+
}
|
|
83
|
+
const staticSegment = statement.slice(cursor, start);
|
|
84
|
+
if (staticSegment.length > 0) {
|
|
85
|
+
segments.push(drizzleSql.raw(staticSegment));
|
|
86
|
+
}
|
|
87
|
+
const parameterValue = params[parameterIndex];
|
|
88
|
+
if (parameterValue === undefined) {
|
|
89
|
+
throw new Error(`SQL placeholder ${token} is missing a parameter value.`);
|
|
90
|
+
}
|
|
91
|
+
const normalizedValue = normalizeParam(parameterValue);
|
|
92
|
+
segments.push(drizzleSql`${normalizedValue}`);
|
|
93
|
+
cursor = start + token.length;
|
|
94
|
+
}
|
|
95
|
+
const tailSegment = statement.slice(cursor);
|
|
96
|
+
if (tailSegment.length > 0) {
|
|
97
|
+
segments.push(drizzleSql.raw(tailSegment));
|
|
98
|
+
}
|
|
99
|
+
if (segments.length === 0) {
|
|
100
|
+
return drizzleSql.raw("");
|
|
101
|
+
}
|
|
102
|
+
return drizzleSql.join(segments);
|
|
103
|
+
}
|
|
104
|
+
function normalizeParam(value) {
|
|
105
|
+
if (typeof value === "bigint") {
|
|
106
|
+
return value.toString();
|
|
107
|
+
}
|
|
108
|
+
if (value instanceof Uint8Array) {
|
|
109
|
+
return Buffer.from(value);
|
|
110
|
+
}
|
|
111
|
+
if (isPlainObject(value)) {
|
|
112
|
+
return JSON.stringify(value);
|
|
113
|
+
}
|
|
114
|
+
return value;
|
|
115
|
+
}
|
|
116
|
+
function asRows(result) {
|
|
117
|
+
if (!Array.isArray(result)) {
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
function isPlainObject(value) {
|
|
123
|
+
if (value == null || typeof value !== "object") {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
if (Array.isArray(value)) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
if (value instanceof Date) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
if (value instanceof Uint8Array) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
function resolveSslMode(mode) {
|
|
138
|
+
switch (mode) {
|
|
139
|
+
case "allow":
|
|
140
|
+
return false;
|
|
141
|
+
case "prefer":
|
|
142
|
+
return "prefer";
|
|
143
|
+
case "require":
|
|
144
|
+
default:
|
|
145
|
+
return "require";
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
export {
|
|
149
|
+
SupabasePostgresProvider
|
|
150
|
+
};
|