@tinkerlandai/indiana-sdk 0.1.0 → 0.2.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/index.js CHANGED
@@ -1 +1 @@
1
- import{a as C,b as F,c as T,d as _,e as P}from"./chunk-Y7LNDG3O.js";import{a,b as h}from"./chunk-2HEB2TPD.js";import{Fh as s,Pa as O,Qa as S,Ra as N,lj as g,wj as v}from"./chunk-FMAMDKAV.js";function A(r){let{customerToken:d,...t}=r;return t}var D=r=>!(r instanceof a)||r.status===void 0||r.status>=500||[401,425].includes(r.status);function R(r){if(!/^gg_fr_[A-Za-z0-9_-]{43}$/.test(r.runToken))throw new a("INVALID_TOKEN","Run credential required");let d=h({...r,timeoutMs:r.timeoutMs??35e3});d.identify(r.runToken);let t,i=null,m=0,n=null,e=null,p=new Set;async function c(u,f){let I=m,l=v.parse(await d.request("funnels",g.parse(u)));if(I!==m)throw new a("IDENTITY_CHANGED","Run identity changed during the request");if(l.runToken&&l.runToken!==r.runToken)throw new a("INVALID_RESPONSE","Run credential changed");if(i&&(l.run.id!==i.id||l.run.source.type!==i.source.type||l.run.source.id!==i.source.id||l.run.source.versionId!==i.source.versionId||l.run.locale!==i.locale||!C(l.run.parameters,i.parameters)))throw new a("INVALID_RESPONSE","Run version changed");let E=f?.(l)??!1;if(!i||l.run.revision>=i.revision)i=l.run;else if(!E)return l;if(i)for(let q of p)try{q(structuredClone(i))}catch{}return l}async function y(){if(!n)throw new a("INVALID_REQUEST","No command is pending");let u=n,f=m,I={...n,...t?{customerToken:t}:{}};try{return await c(I,l=>f===m&&n===u&&l.run.pendingRequest?.requestId!==u.requestId?(n=null,!0):!1)}catch(l){throw f===m&&n===u&&!D(l)&&(n=null),l}}function w(u){let f=g.parse(u);if(f.operation==="start"||f.operation==="get")throw new a("INVALID_REQUEST","Mutation required");if(f.operation==="close"&&n?.operation!=="close"&&(n=null),n){if(JSON.stringify(A(n))!==JSON.stringify(A(f)))throw new a("COMMAND_PENDING","Retry the original command before sending another");if(e)return e}else n=f;let I=y();return e=I,I.then(()=>{e===I&&(e=null)},()=>{e===I&&(e=null)}),I}return{get view(){return i?structuredClone(i):null},get pendingCommand(){return n?structuredClone(A(n)):null},get webViewUrl(){return d.webViewUrl()},async get(u,f){return c({operation:"get",...u?{data:u}:{},...f?{purchase:f}:{},...t?{customerToken:t}:{}})},resume(u=i?.pendingRequest?.requestId){return u?n?.requestId===u?w(n):w({operation:"resume",requestId:u}):Promise.reject(new a("INVALID_REQUEST","No interrupted command is available"))},submit(u){return w(u)},retry(){return e||(n?w(n):Promise.reject(new a("INVALID_REQUEST","No command is pending")))},identify(u){if(!/^gg_ct_[A-Za-z0-9_-]{43}$/.test(u))throw new a("INVALID_TOKEN","Customer credential required");m++,t=u,d.identify(r.runToken)},subscribe(u){return p.add(u),()=>p.delete(u)},reset(){m++,t=void 0,i=null,n=null,e=null,d.reset(),p.clear()}}}function V(r){if(!/^gg_ct_[A-Za-z0-9_-]{32,128}$/.test(r.customerToken))throw new a("INVALID_TOKEN","A customer credential is required");if(!r.scope)throw new a("INVALID_REQUEST","An explicit App and environment scope is required");let d=P({...r,scope:r.scope,apiKey:r.customerToken});return{async start(t){let i=await d.start({...t,customerToken:r.customerToken}),m=R({...r,runToken:i.runToken});return m.identify(r.customerToken),{...i,controller:m}}}}function o(r){if(r!==null&&typeof r=="object"&&"customerId"in r)throw new a("INVALID_REQUEST","Customer requests use the verified session identity")}function H(r){let d=h(r),t=d.request,i=new Set,m=n=>{for(let e of i)try{e(n)}catch{}};return{async setupPayment(n){o(n);let e=s.setupPayment;return e.response.parse(await t(e.path,e.request.parse(n)))},async readPaymentSetup(n){o(n);let e=s.readPaymentSetup;return e.response.parse(await t(e.path,e.request.parse(n)))},async previewUpdate(n){o(n);let e=s.previewUpdate;return e.response.parse(await t(e.path,e.request.parse(n)))},async update(n){o(n);let e=s.update;return e.response.parse(await t(e.path,e.request.parse(n)))},async readSubscriptionUpdate(n){o(n);let e=s.readSubscriptionUpdate;return e.response.parse(await t(e.path,e.request.parse(n)))},async restoreNativePurchase(n){o(n);let e=s.restoreNativePurchase;return e.response.parse(await t(e.path,e.request.parse(n)))},async previewAttach(n){o(n);let e=s.previewAttach;return e.response.parse(await t(e.path,e.request.parse(n)))},async attach(n){o(n);let e=s.attach;return e.response.parse(await t(e.path,e.request.parse(n)))},async readSubscriptionOperation(n){o(n);let e=s.readSubscriptionOperation;return e.response.parse(await t(e.path,e.request.parse(n)))},async checkEntitlement(n){o(n);let e=s.checkEntitlement;return e.response.parse(await t(e.path,e.request.parse(n)))},async resolvePaywall(n){o(n);let e=s.resolvePaywall;return e.response.parse(await t(e.path,e.request.parse(n)))},async resolveOffering(n){o(n);let e=s.resolveOffering;return e.response.parse(await t(e.path,e.request.parse(n)))},async readHoldings(n={}){let e=s.readHoldings;return e.response.parse(await t(e.path,e.request.omit({customerId:!0}).parse(n)))},async readLedger(n){let e=s.readLedger;return e.response.parse(await t(e.path,e.request.parse({query:n})))},async readBillingInvoice(n){o(n);let e=s.readBillingInvoice;return e.response.parse(await t(e.path,e.request.parse(n)))},async readCreditStatement(n){o(n);let e=s.readCreditStatement;return e.response.parse(await t(e.path,e.request.parse(n)))},async quoteBalance(n){o(n);let e=s.quoteBalance;return e.response.parse(await t(e.path,e.request.parse({command:n})))},async readBillingControls(n={}){o(n);let e=s.readBillingControls;return e.response.parse(await t(e.path,e.request.parse(n)))},async prepareBillingAuthorization(n){o(n);let e=s.prepareBillingAuthorization;return e.response.parse(await t(e.path,e.request.parse(n)))},async confirmBillingAuthorization(n){o(n);let e=s.confirmBillingAuthorization;return e.response.parse(await t(e.path,e.request.parse(n)))},async setBillingCoupons(n){o(n);let e=s.setBillingCoupons,p=e.request.safeParse(n);if(!p.success)throw new a("INVALID_REQUEST","Invalid billing coupon list");let c=e.response.safeParse(await t(e.path,p.data));if(!c.success)throw new a("INVALID_RESPONSE","Invalid billing coupon receipt");return c.data},async revokeBillingAuthorization(n){o(n);let e=s.revokeBillingAuthorization;return e.response.parse(await t(e.path,e.request.parse(n)))},async listBillingInvoices(n={after:null,limit:25}){o(n);let e=s.listBillingInvoices;return e.response.parse(await t(e.path,e.request.parse(n)))},async confirmBillingAdjustment(n){o(n);let e=s.confirmBillingAdjustment;return e.response.parse(await t(e.path,e.request.parse(n)))},subscribeIdentity(n){return i.add(n),()=>{i.delete(n)}},identify(n){if(!/^gg_ct_[A-Za-z0-9_-]{43}$/.test(n))throw new a("INVALID_TOKEN","Browser SDK requires a customer session");d.identify(n),m(!0)},reset(){d.reset(),m(!1)},async redeemReward(n){o(n);let e=s.redeemReward,p=e.request.safeParse({...n,requestId:n.requestId??crypto.randomUUID()});if(!p.success)throw new a("INVALID_REQUEST","Invalid reward redemption");let c=e.response.safeParse(await t(e.path,p.data));if(!c.success)throw new a("INVALID_RESPONSE","Invalid reward receipt");return c.data.redemption},async claimRewardProduct(n){o(n);let e=s.claimRewardProduct,p=e.request.safeParse(n);if(!p.success)throw new a("INVALID_REQUEST","Invalid reward product claim");let c=e.response.safeParse(await t(e.path,p.data));if(!c.success)throw new a("INVALID_RESPONSE","Invalid reward product checkout");return c.data.checkout},async createReferralCode(n){o(n);let e=s.createReferralCode,p=e.request.safeParse({...n,requestId:n.requestId??crypto.randomUUID()});if(!p.success)throw new a("INVALID_REQUEST","Invalid referral program");let c=e.response.safeParse(await t(e.path,p.data));if(!c.success)throw new a("INVALID_RESPONSE","Invalid referral code");return c.data.referralCode},async redeemCoupon(n,e=crypto.randomUUID()){let p=s.redeemCoupon,c=p.request.safeParse({code:n,requestId:e});if(!c.success)throw new a("INVALID_REQUEST","Invalid coupon code");let y=p.response.safeParse(await t(p.path,c.data));if(!y.success)throw new a("INVALID_RESPONSE","Invalid Coupon receipt");let w=y.data;return{offer:w.offer,reason:w.reason}},async listOffers(){let n=s.listOffers.response.safeParse(await t("offers",{},"GET"));if(!n.success)throw new a("INVALID_RESPONSE","Invalid offers response");return n.data.offers}}}async function Z(...r){return(await import("./paywall-6HHA4OJV.js")).showPaywall(...r)}async function $(...r){return(await import("./funnel-runtime-host-QIYKF5KH.js")).showFunnelRun(...r)}export{a as IndianaError,T as createFeatureClient,V as createFunnelClient,R as createFunnelRunController,H as createIndiana,F as createPaywallSession,_ as evaluateFunnelNode,S as formatCouponDiscount,O as formatCouponMoney,N as formatCouponTerms,$ as showFunnelRun,Z as showPaywall};
1
+ import{b as C,c as F,d as T,e as _,f as P}from"./chunk-ULRVTA45.js";import{a,b as h}from"./chunk-EZFAY4ZL.js";import{Dj as v,Lh as s,Pa as O,Qa as S,Ra as N,sj as g}from"./chunk-YOH6DIUN.js";function A(r){let{customerToken:d,...n}=r;return n}var D=r=>!(r instanceof a)||r.status===void 0||r.status>=500||[401,425].includes(r.status);function R(r){if(!/^gg_fr_[A-Za-z0-9_-]{43}$/.test(r.runToken))throw new a("INVALID_TOKEN","Run credential required");let d=h({...r,timeoutMs:r.timeoutMs??35e3});d.identify(r.runToken);let n,i=null,m=0,t=null,e=null,p=new Set;async function c(u,f){let I=m,l=v.parse(await d.request("funnels",g.parse(u)));if(I!==m)throw new a("IDENTITY_CHANGED","Run identity changed during the request");if(l.runToken&&l.runToken!==r.runToken)throw new a("INVALID_RESPONSE","Run credential changed");if(i&&(l.run.id!==i.id||l.run.source.type!==i.source.type||l.run.source.id!==i.source.id||l.run.source.versionId!==i.source.versionId||l.run.locale!==i.locale||!C(l.run.parameters,i.parameters)))throw new a("INVALID_RESPONSE","Run version changed");let E=f?.(l)??!1;if(!i||l.run.revision>=i.revision)i=l.run;else if(!E)return l;if(i)for(let q of p)try{q(structuredClone(i))}catch{}return l}async function y(){if(!t)throw new a("INVALID_REQUEST","No command is pending");let u=t,f=m,I={...t,...n?{customerToken:n}:{}};try{return await c(I,l=>f===m&&t===u&&l.run.pendingRequest?.requestId!==u.requestId?(t=null,!0):!1)}catch(l){throw f===m&&t===u&&!D(l)&&(t=null),l}}function w(u){let f=g.parse(u);if(f.operation==="start"||f.operation==="get")throw new a("INVALID_REQUEST","Mutation required");if(f.operation==="close"&&t?.operation!=="close"&&(t=null),t){if(JSON.stringify(A(t))!==JSON.stringify(A(f)))throw new a("COMMAND_PENDING","Retry the original command before sending another");if(e)return e}else t=f;let I=y();return e=I,I.then(()=>{e===I&&(e=null)},()=>{e===I&&(e=null)}),I}return{get view(){return i?structuredClone(i):null},get pendingCommand(){return t?structuredClone(A(t)):null},get webViewUrl(){return d.webViewUrl()},async get(u,f){return c({operation:"get",...u?{data:u}:{},...f?{purchase:f}:{},...n?{customerToken:n}:{}})},resume(u=i?.pendingRequest?.requestId){return u?t?.requestId===u?w(t):w({operation:"resume",requestId:u}):Promise.reject(new a("INVALID_REQUEST","No interrupted command is available"))},submit(u){return w(u)},retry(){return e||(t?w(t):Promise.reject(new a("INVALID_REQUEST","No command is pending")))},identify(u){if(!/^gg_ct_[A-Za-z0-9_-]{43}$/.test(u))throw new a("INVALID_TOKEN","Customer credential required");m++,n=u,d.identify(r.runToken)},subscribe(u){return p.add(u),()=>p.delete(u)},reset(){m++,n=void 0,i=null,t=null,e=null,d.reset(),p.clear()}}}function V(r){if(!/^gg_ct_[A-Za-z0-9_-]{32,128}$/.test(r.customerToken))throw new a("INVALID_TOKEN","A customer credential is required");if(!r.scope)throw new a("INVALID_REQUEST","An explicit App and environment scope is required");let d=P({...r,scope:r.scope,apiKey:r.customerToken});return{async start(n){let i=await d.start(n),m=R({...r,runToken:i.runToken});return m.identify(r.customerToken),{...i,controller:m}}}}function o(r){if(r!==null&&typeof r=="object"&&"customerId"in r)throw new a("INVALID_REQUEST","Customer requests use the verified session identity")}function H(r){let d=h(r),n=d.request,i=new Set,m=t=>{for(let e of i)try{e(t)}catch{}};return{async setupPayment(t){o(t);let e=s.setupPayment;return e.response.parse(await n(e.path,e.request.parse(t)))},async readPaymentSetup(t){o(t);let e=s.readPaymentSetup;return e.response.parse(await n(e.path,e.request.parse(t)))},async previewUpdate(t){o(t);let e=s.previewUpdate;return e.response.parse(await n(e.path,e.request.parse(t)))},async update(t){o(t);let e=s.update;return e.response.parse(await n(e.path,e.request.parse(t)))},async readSubscriptionUpdate(t){o(t);let e=s.readSubscriptionUpdate;return e.response.parse(await n(e.path,e.request.parse(t)))},async restoreNativePurchase(t){o(t);let e=s.restoreNativePurchase;return e.response.parse(await n(e.path,e.request.parse(t)))},async previewAttach(t){o(t);let e=s.previewAttach;return e.response.parse(await n(e.path,e.request.parse(t)))},async attach(t){o(t);let e=s.attach;return e.response.parse(await n(e.path,e.request.parse(t)))},async readSubscriptionOperation(t){o(t);let e=s.readSubscriptionOperation;return e.response.parse(await n(e.path,e.request.parse(t)))},async checkEntitlement(t){o(t);let e=s.checkEntitlement;return e.response.parse(await n(e.path,e.request.parse(t)))},async resolvePaywall(t){o(t);let e=s.resolvePaywall;return e.response.parse(await n(e.path,e.request.parse(t)))},async resolveOffering(t){o(t);let e=s.resolveOffering;return e.response.parse(await n(e.path,e.request.parse(t)))},async readHoldings(t={}){let e=s.readHoldings;return e.response.parse(await n(e.path,e.request.omit({customerId:!0}).parse(t)))},async readLedger(t){let e=s.readLedger;return e.response.parse(await n(e.path,e.request.parse({query:t})))},async readBillingInvoice(t){o(t);let e=s.readBillingInvoice;return e.response.parse(await n(e.path,e.request.parse(t)))},async readCreditStatement(t){o(t);let e=s.readCreditStatement;return e.response.parse(await n(e.path,e.request.parse(t)))},async quoteBalance(t){o(t);let e=s.quoteBalance;return e.response.parse(await n(e.path,e.request.parse({command:t})))},async readBillingControls(t={}){o(t);let e=s.readBillingControls;return e.response.parse(await n(e.path,e.request.parse(t)))},async prepareBillingAuthorization(t){o(t);let e=s.prepareBillingAuthorization;return e.response.parse(await n(e.path,e.request.parse(t)))},async confirmBillingAuthorization(t){o(t);let e=s.confirmBillingAuthorization;return e.response.parse(await n(e.path,e.request.parse(t)))},async setBillingCoupons(t){o(t);let e=s.setBillingCoupons,p=e.request.safeParse(t);if(!p.success)throw new a("INVALID_REQUEST","Invalid billing coupon list");let c=e.response.safeParse(await n(e.path,p.data));if(!c.success)throw new a("INVALID_RESPONSE","Invalid billing coupon receipt");return c.data},async revokeBillingAuthorization(t){o(t);let e=s.revokeBillingAuthorization;return e.response.parse(await n(e.path,e.request.parse(t)))},async listBillingInvoices(t={after:null,limit:25}){o(t);let e=s.listBillingInvoices;return e.response.parse(await n(e.path,e.request.parse(t)))},async confirmBillingAdjustment(t){o(t);let e=s.confirmBillingAdjustment;return e.response.parse(await n(e.path,e.request.parse(t)))},subscribeIdentity(t){return i.add(t),()=>{i.delete(t)}},identify(t){if(!/^gg_ct_[A-Za-z0-9_-]{43}$/.test(t))throw new a("INVALID_TOKEN","Browser SDK requires a customer session");d.identify(t),m(!0)},reset(){d.reset(),m(!1)},async redeemReward(t){o(t);let e=s.redeemReward,p=e.request.safeParse({...t,requestId:t.requestId??crypto.randomUUID()});if(!p.success)throw new a("INVALID_REQUEST","Invalid reward redemption");let c=e.response.safeParse(await n(e.path,p.data));if(!c.success)throw new a("INVALID_RESPONSE","Invalid reward receipt");return c.data.redemption},async claimRewardProduct(t){o(t);let e=s.claimRewardProduct,p=e.request.safeParse(t);if(!p.success)throw new a("INVALID_REQUEST","Invalid reward product claim");let c=e.response.safeParse(await n(e.path,p.data));if(!c.success)throw new a("INVALID_RESPONSE","Invalid reward product checkout");return c.data.checkout},async createReferralCode(t){o(t);let e=s.createReferralCode,p=e.request.safeParse({...t,requestId:t.requestId??crypto.randomUUID()});if(!p.success)throw new a("INVALID_REQUEST","Invalid referral program");let c=e.response.safeParse(await n(e.path,p.data));if(!c.success)throw new a("INVALID_RESPONSE","Invalid referral code");return c.data.referralCode},async redeemCoupon(t,e=crypto.randomUUID()){let p=s.redeemCoupon,c=p.request.safeParse({code:t,requestId:e});if(!c.success)throw new a("INVALID_REQUEST","Invalid coupon code");let y=p.response.safeParse(await n(p.path,c.data));if(!y.success)throw new a("INVALID_RESPONSE","Invalid Coupon receipt");let w=y.data;return{offer:w.offer,reason:w.reason}},async listOffers(){let t=s.listOffers.response.safeParse(await n("offers",{},"GET"));if(!t.success)throw new a("INVALID_RESPONSE","Invalid offers response");return t.data.offers}}}async function Z(...r){return(await import("./paywall-HCADUT22.js")).showPaywall(...r)}async function $(...r){return(await import("./funnel-runtime-host-OJJSHKUD.js")).showFunnelRun(...r)}export{a as IndianaError,T as createFeatureClient,V as createFunnelClient,R as createFunnelRunController,H as createIndiana,F as createPaywallSession,_ as evaluateFunnelNode,S as formatCouponDiscount,O as formatCouponMoney,N as formatCouponTerms,$ as showFunnelRun,Z as showPaywall};