@contractspec/integration.providers-impls 1.53.0 → 1.55.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripe-payments.js","names":[],"sources":["../../src/impls/stripe-payments.ts"],"sourcesContent":["import Stripe from 'stripe';\n\nimport type {\n CapturePaymentInput,\n CreateCustomerInput,\n CreatePaymentIntentInput,\n ListInvoicesQuery,\n ListTransactionsQuery,\n Money,\n PaymentCustomer,\n PaymentIntent,\n PaymentInvoice,\n PaymentRefund,\n PaymentsProvider,\n PaymentTransaction,\n RefundPaymentInput,\n} from '../payments';\n\nexport interface StripePaymentsProviderOptions {\n apiKey: string;\n stripe?: Stripe;\n}\n\nconst API_VERSION: Stripe.LatestApiVersion = '2025-12-15.clover';\n\nexport class StripePaymentsProvider implements PaymentsProvider {\n private readonly stripe: Stripe;\n\n constructor(options: StripePaymentsProviderOptions) {\n this.stripe =\n options.stripe ??\n new Stripe(options.apiKey, {\n apiVersion: API_VERSION,\n });\n }\n\n async createCustomer(input: CreateCustomerInput): Promise<PaymentCustomer> {\n const customer = await this.stripe.customers.create({\n email: input.email,\n name: input.name,\n description: input.description,\n metadata: input.metadata,\n });\n return this.toCustomer(customer);\n }\n\n async getCustomer(customerId: string): Promise<PaymentCustomer | null> {\n const customer = await this.stripe.customers.retrieve(customerId);\n if (customer.deleted) return null;\n return this.toCustomer(customer);\n }\n\n async createPaymentIntent(\n input: CreatePaymentIntentInput\n ): Promise<PaymentIntent> {\n const intent = await this.stripe.paymentIntents.create({\n amount: input.amount.amount,\n currency: input.amount.currency,\n customer: input.customerId,\n description: input.description,\n capture_method: input.captureMethod ?? 'automatic',\n confirmation_method: input.confirmationMethod ?? 'automatic',\n automatic_payment_methods: { enabled: true },\n metadata: input.metadata,\n return_url: input.returnUrl,\n statement_descriptor: input.statementDescriptor,\n });\n return this.toPaymentIntent(intent);\n }\n\n async capturePayment(\n paymentIntentId: string,\n input?: CapturePaymentInput\n ): Promise<PaymentIntent> {\n const intent = await this.stripe.paymentIntents.capture(\n paymentIntentId,\n input?.amount ? { amount_to_capture: input.amount.amount } : undefined\n );\n return this.toPaymentIntent(intent);\n }\n\n async cancelPaymentIntent(paymentIntentId: string): Promise<PaymentIntent> {\n const intent = await this.stripe.paymentIntents.cancel(paymentIntentId);\n return this.toPaymentIntent(intent);\n }\n\n async refundPayment(input: RefundPaymentInput): Promise<PaymentRefund> {\n const refund = await this.stripe.refunds.create({\n payment_intent: input.paymentIntentId,\n amount: input.amount?.amount,\n reason: mapRefundReason(input.reason),\n metadata: input.metadata,\n });\n const paymentIntentId =\n typeof refund.payment_intent === 'string'\n ? refund.payment_intent\n : (refund.payment_intent?.id ?? '');\n return {\n id: refund.id,\n paymentIntentId,\n amount: {\n amount: refund.amount ?? 0,\n currency: refund.currency?.toUpperCase() ?? 'USD',\n },\n status: mapRefundStatus(refund.status),\n reason: refund.reason ?? undefined,\n metadata: this.toMetadata(refund.metadata),\n createdAt: refund.created ? new Date(refund.created * 1000) : undefined,\n };\n }\n\n async listInvoices(query?: ListInvoicesQuery): Promise<PaymentInvoice[]> {\n const requestedStatus = query?.status?.[0];\n const stripeStatus =\n requestedStatus && requestedStatus !== 'deleted'\n ? requestedStatus\n : undefined;\n const response = await this.stripe.invoices.list({\n customer: query?.customerId,\n status: stripeStatus,\n limit: query?.limit,\n starting_after: query?.startingAfter,\n });\n return response.data.map((invoice) => this.toInvoice(invoice));\n }\n\n async listTransactions(\n query?: ListTransactionsQuery\n ): Promise<PaymentTransaction[]> {\n const response = await this.stripe.charges.list({\n customer: query?.customerId,\n payment_intent: query?.paymentIntentId,\n limit: query?.limit,\n starting_after: query?.startingAfter,\n });\n return response.data.map((charge) => ({\n id: charge.id,\n paymentIntentId:\n typeof charge.payment_intent === 'string'\n ? charge.payment_intent\n : charge.payment_intent?.id,\n amount: {\n amount: charge.amount,\n currency: charge.currency?.toUpperCase() ?? 'USD',\n },\n type: 'capture',\n status: mapChargeStatus(charge.status),\n description: charge.description ?? undefined,\n createdAt: new Date(charge.created * 1000),\n metadata: this.mergeMetadata(this.toMetadata(charge.metadata), {\n balanceTransaction:\n typeof charge.balance_transaction === 'string'\n ? charge.balance_transaction\n : undefined,\n }),\n }));\n }\n\n private toCustomer(customer: Stripe.Customer): PaymentCustomer {\n const metadata = this.toMetadata(customer.metadata);\n const updatedAtValue = metadata?.updatedAt;\n return {\n id: customer.id,\n email: customer.email ?? undefined,\n name: customer.name ?? undefined,\n metadata,\n createdAt: customer.created\n ? new Date(customer.created * 1000)\n : undefined,\n updatedAt: updatedAtValue ? new Date(updatedAtValue) : undefined,\n };\n }\n\n private toPaymentIntent(intent: Stripe.PaymentIntent): PaymentIntent {\n const metadata = this.toMetadata(intent.metadata);\n return {\n id: intent.id,\n amount: this.toMoney(\n intent.amount_received ?? intent.amount ?? 0,\n intent.currency\n ),\n status: mapPaymentIntentStatus(intent.status),\n customerId:\n typeof intent.customer === 'string'\n ? intent.customer\n : intent.customer?.id,\n description: intent.description ?? undefined,\n clientSecret: intent.client_secret ?? undefined,\n metadata,\n createdAt: new Date(intent.created * 1000),\n updatedAt:\n intent.canceled_at != null\n ? new Date(intent.canceled_at * 1000)\n : new Date(intent.created * 1000),\n };\n }\n\n private toInvoice(invoice: Stripe.Invoice): PaymentInvoice {\n const metadata = this.toMetadata(invoice.metadata);\n return {\n id: invoice.id,\n number: invoice.number ?? undefined,\n status: (invoice.status as PaymentInvoice['status']) ?? 'draft',\n amountDue: this.toMoney(invoice.amount_due ?? 0, invoice.currency),\n amountPaid: this.toMoney(invoice.amount_paid ?? 0, invoice.currency),\n customerId:\n typeof invoice.customer === 'string'\n ? invoice.customer\n : invoice.customer?.id,\n dueDate: invoice.due_date ? new Date(invoice.due_date * 1000) : undefined,\n hostedInvoiceUrl: invoice.hosted_invoice_url ?? undefined,\n metadata,\n createdAt: invoice.created ? new Date(invoice.created * 1000) : undefined,\n updatedAt: invoice.status_transitions?.finalized_at\n ? new Date(invoice.status_transitions.finalized_at * 1000)\n : undefined,\n };\n }\n\n private toMoney(amount: number, currency?: string | null): Money {\n return {\n amount,\n currency: currency?.toUpperCase() ?? 'USD',\n };\n }\n\n private toMetadata(\n metadata: Stripe.Metadata | Stripe.Metadata | null | undefined\n ): Record<string, string> | undefined {\n if (!metadata) return undefined;\n const entries = Object.entries(metadata).filter(\n (entry): entry is [string, string] => typeof entry[1] === 'string'\n );\n if (entries.length === 0) return undefined;\n return Object.fromEntries(entries);\n }\n\n private mergeMetadata(\n base: Record<string, string> | undefined,\n extras: Record<string, string | undefined>\n ): Record<string, string> | undefined {\n const filteredExtras = Object.entries(extras).filter(\n (entry): entry is [string, string] => typeof entry[1] === 'string'\n );\n if (!base && filteredExtras.length === 0) {\n return undefined;\n }\n return {\n ...(base ?? {}),\n ...Object.fromEntries(filteredExtras),\n };\n }\n}\n\nfunction mapRefundReason(\n reason?: string\n): Stripe.RefundCreateParams.Reason | undefined {\n if (!reason) return undefined;\n const allowed: Stripe.RefundCreateParams.Reason[] = [\n 'duplicate',\n 'fraudulent',\n 'requested_by_customer',\n ];\n return allowed.includes(reason as Stripe.RefundCreateParams.Reason)\n ? (reason as Stripe.RefundCreateParams.Reason)\n : undefined;\n}\n\nfunction mapPaymentIntentStatus(\n status: string | null | undefined\n): PaymentIntent['status'] {\n switch (status) {\n case 'requires_payment_method':\n return 'requires_payment_method';\n case 'requires_confirmation':\n return 'requires_confirmation';\n case 'requires_action':\n case 'requires_capture':\n return 'requires_action';\n case 'processing':\n return 'processing';\n case 'succeeded':\n return 'succeeded';\n case 'canceled':\n return 'canceled';\n default:\n return 'requires_payment_method';\n }\n}\n\nfunction mapRefundStatus(\n status: string | null | undefined\n): PaymentRefund['status'] {\n switch (status) {\n case 'pending':\n case 'succeeded':\n case 'failed':\n case 'canceled':\n return status;\n default:\n return 'pending';\n }\n}\n\nfunction mapChargeStatus(\n status: string | null | undefined\n): PaymentTransaction['status'] {\n switch (status) {\n case 'pending':\n case 'processing':\n return 'pending';\n case 'succeeded':\n return 'succeeded';\n case 'failed':\n case 'canceled':\n return 'failed';\n default:\n return 'pending';\n }\n}\n"],"mappings":";;;AAuBA,MAAM,cAAuC;AAE7C,IAAa,yBAAb,MAAgE;CAC9D,AAAiB;CAEjB,YAAY,SAAwC;AAClD,OAAK,SACH,QAAQ,UACR,IAAI,OAAO,QAAQ,QAAQ,EACzB,YAAY,aACb,CAAC;;CAGN,MAAM,eAAe,OAAsD;EACzE,MAAM,WAAW,MAAM,KAAK,OAAO,UAAU,OAAO;GAClD,OAAO,MAAM;GACb,MAAM,MAAM;GACZ,aAAa,MAAM;GACnB,UAAU,MAAM;GACjB,CAAC;AACF,SAAO,KAAK,WAAW,SAAS;;CAGlC,MAAM,YAAY,YAAqD;EACrE,MAAM,WAAW,MAAM,KAAK,OAAO,UAAU,SAAS,WAAW;AACjE,MAAI,SAAS,QAAS,QAAO;AAC7B,SAAO,KAAK,WAAW,SAAS;;CAGlC,MAAM,oBACJ,OACwB;EACxB,MAAM,SAAS,MAAM,KAAK,OAAO,eAAe,OAAO;GACrD,QAAQ,MAAM,OAAO;GACrB,UAAU,MAAM,OAAO;GACvB,UAAU,MAAM;GAChB,aAAa,MAAM;GACnB,gBAAgB,MAAM,iBAAiB;GACvC,qBAAqB,MAAM,sBAAsB;GACjD,2BAA2B,EAAE,SAAS,MAAM;GAC5C,UAAU,MAAM;GAChB,YAAY,MAAM;GAClB,sBAAsB,MAAM;GAC7B,CAAC;AACF,SAAO,KAAK,gBAAgB,OAAO;;CAGrC,MAAM,eACJ,iBACA,OACwB;EACxB,MAAM,SAAS,MAAM,KAAK,OAAO,eAAe,QAC9C,iBACA,OAAO,SAAS,EAAE,mBAAmB,MAAM,OAAO,QAAQ,GAAG,OAC9D;AACD,SAAO,KAAK,gBAAgB,OAAO;;CAGrC,MAAM,oBAAoB,iBAAiD;EACzE,MAAM,SAAS,MAAM,KAAK,OAAO,eAAe,OAAO,gBAAgB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AK;EACL,KAAK,WACH,QAAO;EACT,QACE,QAAO;;;AAIb,SAAS,gBACP,QAC8B;AAC9B,SAAQ,QAAR;EACE,KAAK;EACL,KAAK,aACH,QAAO;EACT,KAAK,YACH,QAAO;EACT,KAAK;EACL,KAAK,WACH,QAAO;EACT,QACE,QAAO"}
|
|
1
|
+
{"version":3,"file":"stripe-payments.js","names":[],"sources":["../../src/impls/stripe-payments.ts"],"sourcesContent":["import Stripe from 'stripe';\n\nimport type {\n CapturePaymentInput,\n CreateCustomerInput,\n CreatePaymentIntentInput,\n ListInvoicesQuery,\n ListTransactionsQuery,\n Money,\n PaymentCustomer,\n PaymentIntent,\n PaymentInvoice,\n PaymentRefund,\n PaymentsProvider,\n PaymentTransaction,\n RefundPaymentInput,\n} from '../payments';\n\nexport interface StripePaymentsProviderOptions {\n apiKey: string;\n stripe?: Stripe;\n}\n\nconst API_VERSION: Stripe.LatestApiVersion = '2026-01-28.clover';\n\nexport class StripePaymentsProvider implements PaymentsProvider {\n private readonly stripe: Stripe;\n\n constructor(options: StripePaymentsProviderOptions) {\n this.stripe =\n options.stripe ??\n new Stripe(options.apiKey, {\n apiVersion: API_VERSION,\n });\n }\n\n async createCustomer(input: CreateCustomerInput): Promise<PaymentCustomer> {\n const customer = await this.stripe.customers.create({\n email: input.email,\n name: input.name,\n description: input.description,\n metadata: input.metadata,\n });\n return this.toCustomer(customer);\n }\n\n async getCustomer(customerId: string): Promise<PaymentCustomer | null> {\n const customer = await this.stripe.customers.retrieve(customerId);\n if (customer.deleted) return null;\n return this.toCustomer(customer);\n }\n\n async createPaymentIntent(\n input: CreatePaymentIntentInput\n ): Promise<PaymentIntent> {\n const intent = await this.stripe.paymentIntents.create({\n amount: input.amount.amount,\n currency: input.amount.currency,\n customer: input.customerId,\n description: input.description,\n capture_method: input.captureMethod ?? 'automatic',\n confirmation_method: input.confirmationMethod ?? 'automatic',\n automatic_payment_methods: { enabled: true },\n metadata: input.metadata,\n return_url: input.returnUrl,\n statement_descriptor: input.statementDescriptor,\n });\n return this.toPaymentIntent(intent);\n }\n\n async capturePayment(\n paymentIntentId: string,\n input?: CapturePaymentInput\n ): Promise<PaymentIntent> {\n const intent = await this.stripe.paymentIntents.capture(\n paymentIntentId,\n input?.amount ? { amount_to_capture: input.amount.amount } : undefined\n );\n return this.toPaymentIntent(intent);\n }\n\n async cancelPaymentIntent(paymentIntentId: string): Promise<PaymentIntent> {\n const intent = await this.stripe.paymentIntents.cancel(paymentIntentId);\n return this.toPaymentIntent(intent);\n }\n\n async refundPayment(input: RefundPaymentInput): Promise<PaymentRefund> {\n const refund = await this.stripe.refunds.create({\n payment_intent: input.paymentIntentId,\n amount: input.amount?.amount,\n reason: mapRefundReason(input.reason),\n metadata: input.metadata,\n });\n const paymentIntentId =\n typeof refund.payment_intent === 'string'\n ? refund.payment_intent\n : (refund.payment_intent?.id ?? '');\n return {\n id: refund.id,\n paymentIntentId,\n amount: {\n amount: refund.amount ?? 0,\n currency: refund.currency?.toUpperCase() ?? 'USD',\n },\n status: mapRefundStatus(refund.status),\n reason: refund.reason ?? undefined,\n metadata: this.toMetadata(refund.metadata),\n createdAt: refund.created ? new Date(refund.created * 1000) : undefined,\n };\n }\n\n async listInvoices(query?: ListInvoicesQuery): Promise<PaymentInvoice[]> {\n const requestedStatus = query?.status?.[0];\n const stripeStatus =\n requestedStatus && requestedStatus !== 'deleted'\n ? requestedStatus\n : undefined;\n const response = await this.stripe.invoices.list({\n customer: query?.customerId,\n status: stripeStatus,\n limit: query?.limit,\n starting_after: query?.startingAfter,\n });\n return response.data.map((invoice) => this.toInvoice(invoice));\n }\n\n async listTransactions(\n query?: ListTransactionsQuery\n ): Promise<PaymentTransaction[]> {\n const response = await this.stripe.charges.list({\n customer: query?.customerId,\n payment_intent: query?.paymentIntentId,\n limit: query?.limit,\n starting_after: query?.startingAfter,\n });\n return response.data.map((charge) => ({\n id: charge.id,\n paymentIntentId:\n typeof charge.payment_intent === 'string'\n ? charge.payment_intent\n : charge.payment_intent?.id,\n amount: {\n amount: charge.amount,\n currency: charge.currency?.toUpperCase() ?? 'USD',\n },\n type: 'capture',\n status: mapChargeStatus(charge.status),\n description: charge.description ?? undefined,\n createdAt: new Date(charge.created * 1000),\n metadata: this.mergeMetadata(this.toMetadata(charge.metadata), {\n balanceTransaction:\n typeof charge.balance_transaction === 'string'\n ? charge.balance_transaction\n : undefined,\n }),\n }));\n }\n\n private toCustomer(customer: Stripe.Customer): PaymentCustomer {\n const metadata = this.toMetadata(customer.metadata);\n const updatedAtValue = metadata?.updatedAt;\n return {\n id: customer.id,\n email: customer.email ?? undefined,\n name: customer.name ?? undefined,\n metadata,\n createdAt: customer.created\n ? new Date(customer.created * 1000)\n : undefined,\n updatedAt: updatedAtValue ? new Date(updatedAtValue) : undefined,\n };\n }\n\n private toPaymentIntent(intent: Stripe.PaymentIntent): PaymentIntent {\n const metadata = this.toMetadata(intent.metadata);\n return {\n id: intent.id,\n amount: this.toMoney(\n intent.amount_received ?? intent.amount ?? 0,\n intent.currency\n ),\n status: mapPaymentIntentStatus(intent.status),\n customerId:\n typeof intent.customer === 'string'\n ? intent.customer\n : intent.customer?.id,\n description: intent.description ?? undefined,\n clientSecret: intent.client_secret ?? undefined,\n metadata,\n createdAt: new Date(intent.created * 1000),\n updatedAt:\n intent.canceled_at != null\n ? new Date(intent.canceled_at * 1000)\n : new Date(intent.created * 1000),\n };\n }\n\n private toInvoice(invoice: Stripe.Invoice): PaymentInvoice {\n const metadata = this.toMetadata(invoice.metadata);\n return {\n id: invoice.id,\n number: invoice.number ?? undefined,\n status: (invoice.status as PaymentInvoice['status']) ?? 'draft',\n amountDue: this.toMoney(invoice.amount_due ?? 0, invoice.currency),\n amountPaid: this.toMoney(invoice.amount_paid ?? 0, invoice.currency),\n customerId:\n typeof invoice.customer === 'string'\n ? invoice.customer\n : invoice.customer?.id,\n dueDate: invoice.due_date ? new Date(invoice.due_date * 1000) : undefined,\n hostedInvoiceUrl: invoice.hosted_invoice_url ?? undefined,\n metadata,\n createdAt: invoice.created ? new Date(invoice.created * 1000) : undefined,\n updatedAt: invoice.status_transitions?.finalized_at\n ? new Date(invoice.status_transitions.finalized_at * 1000)\n : undefined,\n };\n }\n\n private toMoney(amount: number, currency?: string | null): Money {\n return {\n amount,\n currency: currency?.toUpperCase() ?? 'USD',\n };\n }\n\n private toMetadata(\n metadata: Stripe.Metadata | Stripe.Metadata | null | undefined\n ): Record<string, string> | undefined {\n if (!metadata) return undefined;\n const entries = Object.entries(metadata).filter(\n (entry): entry is [string, string] => typeof entry[1] === 'string'\n );\n if (entries.length === 0) return undefined;\n return Object.fromEntries(entries);\n }\n\n private mergeMetadata(\n base: Record<string, string> | undefined,\n extras: Record<string, string | undefined>\n ): Record<string, string> | undefined {\n const filteredExtras = Object.entries(extras).filter(\n (entry): entry is [string, string] => typeof entry[1] === 'string'\n );\n if (!base && filteredExtras.length === 0) {\n return undefined;\n }\n return {\n ...(base ?? {}),\n ...Object.fromEntries(filteredExtras),\n };\n }\n}\n\nfunction mapRefundReason(\n reason?: string\n): Stripe.RefundCreateParams.Reason | undefined {\n if (!reason) return undefined;\n const allowed: Stripe.RefundCreateParams.Reason[] = [\n 'duplicate',\n 'fraudulent',\n 'requested_by_customer',\n ];\n return allowed.includes(reason as Stripe.RefundCreateParams.Reason)\n ? (reason as Stripe.RefundCreateParams.Reason)\n : undefined;\n}\n\nfunction mapPaymentIntentStatus(\n status: string | null | undefined\n): PaymentIntent['status'] {\n switch (status) {\n case 'requires_payment_method':\n return 'requires_payment_method';\n case 'requires_confirmation':\n return 'requires_confirmation';\n case 'requires_action':\n case 'requires_capture':\n return 'requires_action';\n case 'processing':\n return 'processing';\n case 'succeeded':\n return 'succeeded';\n case 'canceled':\n return 'canceled';\n default:\n return 'requires_payment_method';\n }\n}\n\nfunction mapRefundStatus(\n status: string | null | undefined\n): PaymentRefund['status'] {\n switch (status) {\n case 'pending':\n case 'succeeded':\n case 'failed':\n case 'canceled':\n return status;\n default:\n return 'pending';\n }\n}\n\nfunction mapChargeStatus(\n status: string | null | undefined\n): PaymentTransaction['status'] {\n switch (status) {\n case 'pending':\n case 'processing':\n return 'pending';\n case 'succeeded':\n return 'succeeded';\n case 'failed':\n case 'canceled':\n return 'failed';\n default:\n return 'pending';\n }\n}\n"],"mappings":";;;AAuBA,MAAM,cAAuC;AAE7C,IAAa,yBAAb,MAAgE;CAC9D,AAAiB;CAEjB,YAAY,SAAwC;AAClD,OAAK,SACH,QAAQ,UACR,IAAI,OAAO,QAAQ,QAAQ,EACzB,YAAY,aACb,CAAC;;CAGN,MAAM,eAAe,OAAsD;EACzE,MAAM,WAAW,MAAM,KAAK,OAAO,UAAU,OAAO;GAClD,OAAO,MAAM;GACb,MAAM,MAAM;GACZ,aAAa,MAAM;GACnB,UAAU,MAAM;GACjB,CAAC;AACF,SAAO,KAAK,WAAW,SAAS;;CAGlC,MAAM,YAAY,YAAqD;EACrE,MAAM,WAAW,MAAM,KAAK,OAAO,UAAU,SAAS,WAAW;AACjE,MAAI,SAAS,QAAS,QAAO;AAC7B,SAAO,KAAK,WAAW,SAAS;;CAGlC,MAAM,oBACJ,OACwB;EACxB,MAAM,SAAS,MAAM,KAAK,OAAO,eAAe,OAAO;GACrD,QAAQ,MAAM,OAAO;GACrB,UAAU,MAAM,OAAO;GACvB,UAAU,MAAM;GAChB,aAAa,MAAM;GACnB,gBAAgB,MAAM,iBAAiB;GACvC,qBAAqB,MAAM,sBAAsB;GACjD,2BAA2B,EAAE,SAAS,MAAM;GAC5C,UAAU,MAAM;GAChB,YAAY,MAAM;GAClB,sBAAsB,MAAM;GAC7B,CAAC;AACF,SAAO,KAAK,gBAAgB,OAAO;;CAGrC,MAAM,eACJ,iBACA,OACwB;EACxB,MAAM,SAAS,MAAM,KAAK,OAAO,eAAe,QAC9C,iBACA,OAAO,SAAS,EAAE,mBAAmB,MAAM,OAAO,QAAQ,GAAG,OAC9D;AACD,SAAO,KAAK,gBAAgB,OAAO;;CAGrC,MAAM,oBAAoB,iBAAiD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P,QACyB;AACzB,SAAQ,QAAR;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,WACH,QAAO;EACT,QACE,QAAO;;;AAIb,SAAS,gBACP,QAC8B;AAC9B,SAAQ,QAAR;EACE,KAAK;EACL,KAAK,aACH,QAAO;EACT,KAAK,YACH,QAAO;EACT,KAAK;EACL,KAAK,WACH,QAAO;EACT,QACE,QAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contractspec/integration.providers-impls",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.55.0",
|
|
4
4
|
"description": "Integration provider implementations for email, payments, storage, and more",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contractspec",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"test": "bun test"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@contractspec/lib.contracts": "1.
|
|
34
|
-
"@contractspec/integration.runtime": "1.
|
|
33
|
+
"@contractspec/lib.contracts": "1.55.0",
|
|
34
|
+
"@contractspec/integration.runtime": "1.55.0",
|
|
35
35
|
"@elevenlabs/elevenlabs-js": "^2.30.0",
|
|
36
36
|
"@google-cloud/storage": "^7.18.0",
|
|
37
37
|
"@mistralai/mistralai": "^1.11.0",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/bun": "latest",
|
|
47
|
-
"@contractspec/tool.tsdown": "1.
|
|
48
|
-
"@contractspec/tool.typescript": "1.
|
|
47
|
+
"@contractspec/tool.tsdown": "1.55.0",
|
|
48
|
+
"@contractspec/tool.typescript": "1.55.0",
|
|
49
49
|
"tsdown": "^0.19.0",
|
|
50
50
|
"typescript": "^5.9.3"
|
|
51
51
|
},
|