@flopay/node 1.8.16 → 1.8.18
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/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var $=Object.create;var m=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var K=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var W=(r,e)=>{for(var t in e)m(r,t,{get:e[t],enumerable:!0})},v=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of H(e))!q.call(r,n)&&n!==t&&m(r,n,{get:()=>e[n],enumerable:!(i=z(e,n))||i.enumerable});return r};var Y=(r,e,t)=>(t=r!=null?$(K(r)):{},v(e||!r||!r.__esModule?m(t,"default",{value:r,enumerable:!0}):t,r)),G=r=>v(m({},"__esModule",{value:!0}),r);var Z={};W(Z,{FloPay:()=>l,STRIPE_API_VERSION:()=>
|
|
1
|
+
"use strict";var $=Object.create;var m=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var K=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var W=(r,e)=>{for(var t in e)m(r,t,{get:e[t],enumerable:!0})},v=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of H(e))!q.call(r,n)&&n!==t&&m(r,n,{get:()=>e[n],enumerable:!(i=z(e,n))||i.enumerable});return r};var Y=(r,e,t)=>(t=r!=null?$(K(r)):{},v(e||!r||!r.__esModule?m(t,"default",{value:r,enumerable:!0}):t,r)),G=r=>v(m({},"__esModule",{value:!0}),r);var Z={};W(Z,{FloPay:()=>l,STRIPE_API_VERSION:()=>C});module.exports=G(Z);var s=require("@flopay/shared"),_=Y(require("stripe"),1),C="2026-04-22.dahlia";function I(r){return typeof r=="string"&&r.trim()?r:void 0}function N(r){if(typeof r=="string")return r.trim()?r:void 0;if(!Array.isArray(r))return;let e=r.filter(t=>typeof t=="string"&&t.trim().length>0);return e.length>0?e.join("; "):void 0}function J(r,e){let t=e?.error,i=I(e?.code)??I(t?.code)??`http_${r}`,n=N(e?.message)??N(t?.message)??`Failed to create checkout session (HTTP ${r}).`;return new s.FloPayError(n,"api_error",{code:i,statusCode:r})}function X(r){for(let e of r){let t=e.charCodeAt(0);if(t<=8||t>=10&&t<=31||t===127)return!0}return!1}function Q(r){if(!r||r.trim()===""||r.length>s.MAX_IDEMPOTENCY_KEY_LENGTH||X(r))return!1;try{return new Headers({[s.IDEMPOTENCY_KEY_HEADER]:r}).get(s.IDEMPOTENCY_KEY_HEADER)===r}catch{return!1}}var l=class{constructor(e,t){if(!e)throw new s.FloPayError("A secret key is required to initialize the FloPay server SDK.","authentication_error");this.stripe=new _.default(t?.stripeSecretKey??e,{apiVersion:t?.apiVersion??C,appInfo:{name:"flopay-node",version:s.SDK_VERSION}}),this.checkout={sessions:{create:this.createSession.bind(this),retrieve:this.retrieveSession.bind(this),expire:this.expireSession.bind(this),listLineItems:this.listLineItems.bind(this)}},this.webhooks={constructEvent:this.constructWebhookEvent.bind(this)},this.customers={create:this.createCustomer.bind(this),retrieve:this.retrieveCustomer.bind(this),update:this.updateCustomer.bind(this)}}async createSession(e){let{billingApiUrl:t,checkoutBaseUrl:i,items:n=[],subscriptions:S=[],products:A,account:o,successUrl:M,cancelUrl:R,checkoutMode:T="confirm",captureMethod:p,couponCodes:U=[],checkoutMetadata:k,tagsData:P,redirectParams:x={},timeoutMs:O=12e3,clientId:V,currency:L,utmMetadata:h,idempotencyKey:b}=e,f=A??(0,s.foldIntoProducts)(n,S);(0,s.assertCaptureMethodEligible)({captureMethod:p,products:f});let y=(0,s.resolveSessionCurrency)(L,n,S,f);if(!y)throw new s.FloPayError("currency is required: pass `currency` on the session, or include a `currency` on the first item/subscription/product.","validation_error",{code:"CurrencyRequired",param:"currency"});let u={clientId:V,checkoutVersion:s.SDK_VERSION,successUrl:M,cancelUrl:R,currency:y,checkoutMode:T,products:f.map(a=>(0,s.buildProductPayload)(a,y)),accountData:{userId:o.userId,firstName:o.firstName??null,lastName:o.lastName??null,email:o.email,country:o.country??null,gender:o.gender??null,city:o.city??null,state:o.state??null,zip:o.zip??null},couponCodes:U};p==="manual"&&(u.captureMethod=p),k!==void 0&&(u.checkoutMetadata=k),P&&(u.tagsData=P),h&&h.length>0&&(u.utmMetadata=h);let D=`${t.replace(/\/+$/,"")}/v1/checkouts/sessions`,w=new AbortController,j=setTimeout(()=>w.abort(),O),c,d;try{let a=await fetch(D,{method:"POST",headers:{"Content-Type":"application/json",...Q(b)?{[s.IDEMPOTENCY_KEY_HEADER]:b}:{}},body:JSON.stringify(u),signal:w.signal});c=a.status;try{d=await a.json()}catch{}}finally{clearTimeout(j)}if(c>=400)throw J(c,d);if(c===201){let a=d?.data?.uuid,E=d?.data?.nonce;if(!a)throw new Error("Checkout session created but no UUID was returned by the billing API");if(!E)throw new s.FloPayError("Checkout session created but no `nonce` was returned by the billing API. Upgrade the billing service to TeamFloPay/backend#640 or later.","api_error",{code:"MissingCheckoutSessionToken"});let g=new URL(`${i.replace(/\/+$/,"")}/secure`);g.searchParams.set("id",a);for(let[F,B]of Object.entries(x))g.searchParams.set(F,B);return{status:201,redirectUrl:g.toString(),nonce:E}}return c===204?{status:204}:{status:c}}normalizeStripeSession(e){let t={open:"open",complete:"complete",expired:"expired"};return{id:e.id,clientSecret:e.client_secret??"",mode:e.mode,status:t[e.status??"open"]??"open",amount:e.amount_total??0,currency:e.currency??"usd",metadata:e.metadata??{}}}async retrieveSession(e){let t=await this.stripe.checkout.sessions.retrieve(e);return this.normalizeStripeSession(t)}async expireSession(e){let t=await this.stripe.checkout.sessions.expire(e);return this.normalizeStripeSession(t)}async listLineItems(e){return(await this.stripe.checkout.sessions.listLineItems(e)).data.map(i=>({price:i.price?.id,quantity:i.quantity??1}))}constructWebhookEvent(e,t,i){let n=this.stripe.webhooks.constructEvent(e,t,i);return{id:n.id,type:n.type,data:n.data,created:n.created}}async createCustomer(e){let t=await this.stripe.customers.create({email:e.email,name:e.name,metadata:e.metadata});return{id:t.id,email:t.email??e.email,firstName:e.name?.split(" ")[0],lastName:e.name?.split(" ").slice(1).join(" ")}}async retrieveCustomer(e){let t=await this.stripe.customers.retrieve(e);if(t.deleted)throw new s.FloPayError(`Customer ${e} has been deleted`,"api_error",{code:"resource_missing"});return{id:t.id,email:t.email??"",firstName:t.name?.split(" ")[0],lastName:t.name?.split(" ").slice(1).join(" ")}}async updateCustomer(e,t){let i=await this.stripe.customers.update(e,{email:t.email,name:t.name,metadata:t.metadata});return{id:i.id,email:i.email??"",firstName:i.name?.split(" ")[0],lastName:i.name?.split(" ").slice(1).join(" ")}}};0&&(module.exports={FloPay,STRIPE_API_VERSION});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{assertCaptureMethodEligible as B,buildProductPayload as $,FloPayError as u,foldIntoProducts as z,IDEMPOTENCY_KEY_HEADER as
|
|
1
|
+
import{assertCaptureMethodEligible as B,buildProductPayload as $,FloPayError as u,foldIntoProducts as z,IDEMPOTENCY_KEY_HEADER as y,MAX_IDEMPOTENCY_KEY_LENGTH as H,resolveSessionCurrency as K,SDK_VERSION as E}from"@flopay/shared";import q from"stripe";var N="2026-04-22.dahlia";function v(r){return typeof r=="string"&&r.trim()?r:void 0}function I(r){if(typeof r=="string")return r.trim()?r:void 0;if(!Array.isArray(r))return;let e=r.filter(t=>typeof t=="string"&&t.trim().length>0);return e.length>0?e.join("; "):void 0}function W(r,e){let t=e?.error,s=v(e?.code)??v(t?.code)??`http_${r}`,i=I(e?.message)??I(t?.message)??`Failed to create checkout session (HTTP ${r}).`;return new u(i,"api_error",{code:s,statusCode:r})}function Y(r){for(let e of r){let t=e.charCodeAt(0);if(t<=8||t>=10&&t<=31||t===127)return!0}return!1}function G(r){if(!r||r.trim()===""||r.length>H||Y(r))return!1;try{return new Headers({[y]:r}).get(y)===r}catch{return!1}}var g=class{constructor(e,t){if(!e)throw new u("A secret key is required to initialize the FloPay server SDK.","authentication_error");this.stripe=new q(t?.stripeSecretKey??e,{apiVersion:t?.apiVersion??N,appInfo:{name:"flopay-node",version:E}}),this.checkout={sessions:{create:this.createSession.bind(this),retrieve:this.retrieveSession.bind(this),expire:this.expireSession.bind(this),listLineItems:this.listLineItems.bind(this)}},this.webhooks={constructEvent:this.constructWebhookEvent.bind(this)},this.customers={create:this.createCustomer.bind(this),retrieve:this.retrieveCustomer.bind(this),update:this.updateCustomer.bind(this)}}async createSession(e){let{billingApiUrl:t,checkoutBaseUrl:s,items:i=[],subscriptions:C=[],products:_,account:n,successUrl:A,cancelUrl:M,checkoutMode:R="confirm",captureMethod:m,couponCodes:T=[],checkoutMetadata:S,tagsData:k,redirectParams:U={},timeoutMs:x=12e3,clientId:O,currency:V,utmMetadata:l,idempotencyKey:P}=e,p=_??z(i,C);B({captureMethod:m,products:p});let h=K(V,i,C,p);if(!h)throw new u("currency is required: pass `currency` on the session, or include a `currency` on the first item/subscription/product.","validation_error",{code:"CurrencyRequired",param:"currency"});let c={clientId:O,checkoutVersion:E,successUrl:A,cancelUrl:M,currency:h,checkoutMode:R,products:p.map(o=>$(o,h)),accountData:{userId:n.userId,firstName:n.firstName??null,lastName:n.lastName??null,email:n.email,country:n.country??null,gender:n.gender??null,city:n.city??null,state:n.state??null,zip:n.zip??null},couponCodes:T};m==="manual"&&(c.captureMethod=m),S!==void 0&&(c.checkoutMetadata=S),k&&(c.tagsData=k),l&&l.length>0&&(c.utmMetadata=l);let L=`${t.replace(/\/+$/,"")}/v1/checkouts/sessions`,b=new AbortController,D=setTimeout(()=>b.abort(),x),a,d;try{let o=await fetch(L,{method:"POST",headers:{"Content-Type":"application/json",...G(P)?{[y]:P}:{}},body:JSON.stringify(c),signal:b.signal});a=o.status;try{d=await o.json()}catch{}}finally{clearTimeout(D)}if(a>=400)throw W(a,d);if(a===201){let o=d?.data?.uuid,w=d?.data?.nonce;if(!o)throw new Error("Checkout session created but no UUID was returned by the billing API");if(!w)throw new u("Checkout session created but no `nonce` was returned by the billing API. Upgrade the billing service to TeamFloPay/backend#640 or later.","api_error",{code:"MissingCheckoutSessionToken"});let f=new URL(`${s.replace(/\/+$/,"")}/secure`);f.searchParams.set("id",o);for(let[j,F]of Object.entries(U))f.searchParams.set(j,F);return{status:201,redirectUrl:f.toString(),nonce:w}}return a===204?{status:204}:{status:a}}normalizeStripeSession(e){let t={open:"open",complete:"complete",expired:"expired"};return{id:e.id,clientSecret:e.client_secret??"",mode:e.mode,status:t[e.status??"open"]??"open",amount:e.amount_total??0,currency:e.currency??"usd",metadata:e.metadata??{}}}async retrieveSession(e){let t=await this.stripe.checkout.sessions.retrieve(e);return this.normalizeStripeSession(t)}async expireSession(e){let t=await this.stripe.checkout.sessions.expire(e);return this.normalizeStripeSession(t)}async listLineItems(e){return(await this.stripe.checkout.sessions.listLineItems(e)).data.map(s=>({price:s.price?.id,quantity:s.quantity??1}))}constructWebhookEvent(e,t,s){let i=this.stripe.webhooks.constructEvent(e,t,s);return{id:i.id,type:i.type,data:i.data,created:i.created}}async createCustomer(e){let t=await this.stripe.customers.create({email:e.email,name:e.name,metadata:e.metadata});return{id:t.id,email:t.email??e.email,firstName:e.name?.split(" ")[0],lastName:e.name?.split(" ").slice(1).join(" ")}}async retrieveCustomer(e){let t=await this.stripe.customers.retrieve(e);if(t.deleted)throw new u(`Customer ${e} has been deleted`,"api_error",{code:"resource_missing"});return{id:t.id,email:t.email??"",firstName:t.name?.split(" ")[0],lastName:t.name?.split(" ").slice(1).join(" ")}}async updateCustomer(e,t){let s=await this.stripe.customers.update(e,{email:t.email,name:t.name,metadata:t.metadata});return{id:s.id,email:s.email??"",firstName:s.name?.split(" ")[0],lastName:s.name?.split(" ").slice(1).join(" ")}}};export{g as FloPay,N as STRIPE_API_VERSION};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flopay/node",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.18",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"stripe": "^22.2.1",
|
|
30
|
-
"@flopay/shared": "1.8.
|
|
30
|
+
"@flopay/shared": "1.8.18"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"tsup": "^8.3.0",
|