@tinkerlandai/indiana-sdk 0.6.1 → 0.6.2
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/CHANGELOG.md +6 -0
- package/README.md +13 -9
- package/README.zh-CN.md +19 -16
- package/dist/{ai-usage-C4Eg6sSr.d.ts → ai-usage-B4W5m4Ie.d.ts} +346 -346
- package/dist/{chunk-FRZNOXK6.js → chunk-ET4NANGB.js} +1 -1
- package/dist/{chunk-U3TULZCD.js → chunk-J7M7UH74.js} +1 -1
- package/dist/{chunk-GJGI34Q7.js → chunk-M3DG6ZCT.js} +1 -1
- package/dist/chunk-N6UIDDAX.js +4 -0
- package/dist/chunk-VMLGV5OS.js +11 -0
- package/dist/{configuration-sync-BWn1YZ78.d.ts → configuration-sync-Bnu8s4pc.d.ts} +41 -41
- package/dist/{funnel-runtime-host-YXWVCKAJ.js → funnel-runtime-host-3STQUS6F.js} +1 -1
- package/dist/{funnel-runtime-start-CKVuIOFs.d.ts → funnel-runtime-start-Zbd5ro5r.d.ts} +787 -787
- package/dist/index.d.ts +603 -603
- package/dist/index.js +1 -1
- package/dist/openrouter.d.ts +2 -2
- package/dist/openrouter.js +1 -1
- package/dist/page.d.ts +19 -18
- package/dist/page.js +1 -1
- package/dist/{paywall-GRSGZLVG.js → paywall-LBDMGVWZ.js} +1 -1
- package/dist/popup.d.ts +16 -12
- package/dist/popup.js +176 -6
- package/dist/server.d.ts +4 -4
- package/dist/server.js +1 -1
- package/dist/src-X6KT6WIH.js +1 -0
- package/dist/visual.js +1 -1
- package/package.json +10 -9
- package/dist/chunk-46S4DTCD.js +0 -11
- package/dist/chunk-4JBIKJMU.js +0 -4
- package/dist/src-UWBQFGYH.js +0 -1
- package/dist/{customer-page-OBB82t8_.d.ts → customer-page-B4FGCVpt.d.ts} +4 -4
- package/dist/{screen-BbLE1OMn.d.ts → screen-16d-xADb.d.ts} +160 -160
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as _,e as W,h as X,i as V,j as ee,k as te,l as j,m as re}from"./chunk-U3TULZCD.js";import{a as B}from"./chunk-FRZNOXK6.js";import{a as s}from"./chunk-5TEZEOHX.js";import"./chunk-S5TVMQRC.js";import{Vf as n,W as Y,X as Z,Y as $,wf as U}from"./chunk-46S4DTCD.js";import"./chunk-RMJJOSVZ.js";import"./chunk-OHDY27EI.js";import"./chunk-S2MSIA57.js";var z=o=>new TextEncoder().encode(JSON.stringify(o)).length;function Q(o,f,r,i){if(i&&r&&(i.scope.projectId!==r.projectId||i.scope.environment!==r.environment))throw new s("SCOPE_MISMATCH","Configuration belongs to another App/environment");let p=0,I,c=m=>{I={config:structuredClone(m),until:Date.now()+3e4}},t=[],e=null,a,l=new Set;function A(){if(!f())throw new s("NOT_IDENTIFIED","Call identify before using Features or events")}function R(){a||!t.length||(a=setTimeout(()=>{a=void 0,N().catch(()=>{}).finally(R)},5e3),typeof a=="object"&&"unref"in a&&a.unref())}function x(m,v={}){if(A(),I&&Date.now()<I.until&&!U(I.config,m))return;k();let h=n.trackEvents.request.parse({events:[{eventUuid:crypto.randomUUID(),timestamp:new Date().toISOString(),name:m,properties:v}]}).events[0];if(z({events:[h]})>6e4)throw new s("INVALID_REQUEST","Event exceeds the delivery size limit");if(t.length>=500)throw new s("EVENT_QUEUE_FULL","Flush pending events before tracking more");t.push(structuredClone(h)),R()}async function N(m=!1){if(A(),e)return e;let v=p,h=(async()=>{let O={inserted:0,duplicates:0,rejected:0,skipped:0},C=t.length;for(;C&&v===p;){let E=[];for(let F of t.slice(0,Math.min(C,100))){if(E.length&&z({events:[...E,F]})>6e4)break;E.push(F)}let g=n.trackEvents,w=g.response.parse(await o(g.path,g.request.parse({events:E}),g.method,{keepalive:m}));if(v!==p)throw new s("IDENTITY_CHANGED","Event identity changed during delivery");if(w.inserted+w.duplicates+w.rejected+w.skipped!==E.length)throw new s("INVALID_RESPONSE","Incomplete event acknowledgement");c(w.analyticsConfig),t.splice(0,E.length),C-=E.length,O.inserted+=w.inserted,O.duplicates+=w.duplicates,O.rejected+=w.rejected,O.skipped+=w.skipped}return O})();e=h;try{return await h}finally{e===h&&(e=null)}}async function G(m={}){i||A();let v=p,h=!1,O=async()=>{if(h||v!==p)throw new s("IDENTITY_CHANGED","Feature identity changed");let y=n.getFeatures,d=i?{scope:{projectId:i.scope.projectId,environment:i.scope.environment},payload:await i.features()}:y.response.parse(await o(y.path,y.request.parse({}),y.method));if(v!==p)throw new s("IDENTITY_CHANGED","Feature identity changed");if(r&&(d.scope.projectId!==r.projectId||d.scope.environment!==r.environment))throw new s("INVALID_RESPONSE","Feature response scope changed");return c(d.payload.analyticsConfig),d},C=await O(),E=!0,g,w=y=>{try{m.onError?.(y)}catch{}},F=(y,d)=>{try{x(y,d)}catch(S){w(S)}},P=_({assertUsable:i?.assertFeatures,scope:C.scope,attributes:m.attributes,onError:m.onError,load:async()=>E?(E=!1,C.payload):(await O()).payload,evaluateRemote:async y=>{if(v!==p)throw new s("IDENTITY_CHANGED","Feature identity changed");let d=n.evaluateFeatures,S=d.response.parse(await o(d.path,d.request.parse(y),d.method));if(S.scope.projectId!==C.scope.projectId||S.scope.environment!==C.scope.environment)throw new s("INVALID_RESPONSE","Remote Feature response scope changed");return{generation:S.generation,evaluatedAt:S.evaluatedAt,expiresAt:S.expiresAt,features:S.features}},onExperimentViewed:(y,d)=>F("Experiment Viewed",{experimentId:y.key,variationId:d.key}),onFeatureUsage:(y,d)=>F("Feature Evaluated",{feature:y,value:d.value,source:d.source,ruleId:d.ruleId,...d.experimentResult?{variationId:d.experimentResult.key}:{}})}),J=P.refresh;function D(){clearTimeout(g),!i&&(h||v!==p||!P.expiresAt||(g=setTimeout(()=>{q().catch(w)},Math.min(2147483647,Math.max(1e3,Date.parse(P.expiresAt)-Date.now()))),typeof g=="object"&&"unref"in g&&g.unref()))}async function q(){try{return await J()}finally{D()}}let L=()=>{h||q().catch(w)},M=P.subscribe(D),K=i?.subscribe(()=>{!h&&i.fresh&&q().catch(w)});function T(){h||(h=!0,clearTimeout(g),typeof window<"u"&&window.removeEventListener("focus",L),M(),K?.(),P.reset(),l.delete(T))}l.add(T);try{await P.init()}catch(y){throw T(),y}return D(),!i&&typeof window<"u"&&window.addEventListener("focus",L),Object.assign(P,{refresh:q,destroy:T})}let b;function k(){if(b||typeof document>"u")return;let m=()=>{document.visibilityState==="hidden"&&f()&&t.length&&N(!0).catch(()=>{})};document.addEventListener("visibilitychange",m),b=()=>document.removeEventListener("visibilitychange",m)}return{features:G,track(m,v){return k(),x(m,v)},flush:N,reset(){p++,I=void 0,clearTimeout(a),a=void 0,t=[],e=null;for(let m of l)m();b?.(),b=void 0}}}function H(o,f){let r="source"in f?{funnelId:f.source.id,funnelVersionId:f.source.versionId}:"versionId"in f?{funnelId:f.funnelId,funnelVersionId:f.versionId}:f,i=n.grantOffer.request.pick({funnelId:!0,funnelVersionId:!0}).required({funnelId:!0}).safeParse(r);if(!i.success)throw new s("INVALID_REQUEST","A valid Funnel source is required");let p=Object.freeze(i.data);function I(c){if("customerId"in c)throw new s("INVALID_REQUEST","Customer identity cannot be overridden");if("funnelId"in c&&c.funnelId!==void 0&&c.funnelId!==p.funnelId||"funnelVersionId"in c&&c.funnelVersionId!==void 0&&c.funnelVersionId!==p.funnelVersionId)throw new s("SCOPE_MISMATCH","The original Funnel source cannot change");return{...c,...p}}return{async claimCoupon(c,t=crypto.randomUUID()){let e=n.grantOffer,a=e.response.parse(await o(e.path,e.request.parse(I({couponId:c,requestId:t}))));return{offer:a.offer,reason:a.reason}},async resolveOffering(c){let t=n.resolveOffering;return t.response.parse(await o(t.path,t.request.parse(I(c))))},async resolvePaywall(c){let t=n.resolvePaywall;return t.response.parse(await o(t.path,t.request.parse(I(c))))},async previewAttach(c){let t=n.previewAttach;return t.response.parse(await o(t.path,t.request.parse(I(c))))}}}function ne(o){if(!/^gg_ct_[A-Za-z0-9_-]{32,128}$/.test(o.customerToken))throw new s("INVALID_TOKEN","A customer credential is required");if(!o.scope)throw new s("INVALID_REQUEST","An explicit App and environment scope is required");let f=j({...o,scope:o.scope,apiKey:o.customerToken});return{async start(r){let i=await f.start(r),p=V({...o,runToken:i.runToken});p.identify(o.customerToken);let I=i.run.instruction?.type==="evaluate"?await p.get():i;return{...i,...I,controller:p}}}}function u(o){if(o!==null&&typeof o=="object"&&"customerId"in o)throw new s("INVALID_REQUEST","Customer requests use the verified session identity")}function ve(o){let f=B(o),r=f.request,i=!1,p=Q(r,()=>i,o.scope,o.configuration),I=new Set,c=t=>{for(let e of I)try{e(t)}catch{}};return{forFunnel(t){return H(r,t)},async features(t={}){return p.features(t)},track(t,e){return p.track(t,e)},flush(){return p.flush()},async setupPayment(t){u(t);let e=n.setupPayment;return e.response.parse(await r(e.path,e.request.parse(t)))},async readPaymentSetup(t){u(t);let e=n.readPaymentSetup;return e.response.parse(await r(e.path,e.request.parse(t)))},async previewUpdate(t){u(t);let e=n.previewUpdate;return e.response.parse(await r(e.path,e.request.parse(t)))},async update(t){u(t);let e=n.update;return e.response.parse(await r(e.path,e.request.parse(t)))},async readSubscriptionUpdate(t){u(t);let e=n.readSubscriptionUpdate;return e.response.parse(await r(e.path,e.request.parse(t)))},async restoreNativePurchase(t){u(t);let e=n.restoreNativePurchase;return e.response.parse(await r(e.path,e.request.parse(t)))},async previewAttach(t){u(t);let e=n.previewAttach;return e.response.parse(await r(e.path,e.request.parse(t)))},async attach(t){u(t);let e=n.attach;return e.response.parse(await r(e.path,e.request.parse(t)))},async readSubscriptionOperation(t){u(t);let e=n.readSubscriptionOperation;return e.response.parse(await r(e.path,e.request.parse(t)))},async checkEntitlement(t){u(t);let e=n.checkEntitlement;return e.response.parse(await r(e.path,e.request.parse(t)))},async resolvePaywall(t){u(t);let e=n.resolvePaywall;return e.response.parse(await r(e.path,e.request.parse(t)))},async resolveOffering(t){u(t);let e=n.resolveOffering;return e.response.parse(await r(e.path,e.request.parse(t)))},async readHoldings(t={}){let e=n.readHoldings;return e.response.parse(await r(e.path,e.request.omit({customerId:!0}).parse(t)))},async readLedger(t){let e=n.readLedger;return e.response.parse(await r(e.path,e.request.parse({query:t})))},async readBillingInvoice(t){u(t);let e=n.readBillingInvoice;return e.response.parse(await r(e.path,e.request.parse(t)))},async readCreditStatement(t){u(t);let e=n.readCreditStatement;return e.response.parse(await r(e.path,e.request.parse(t)))},async quoteBalance(t){u(t);let e=n.quoteBalance;return e.response.parse(await r(e.path,e.request.parse({command:t})))},async readBillingControls(t={}){u(t);let e=n.readBillingControls;return e.response.parse(await r(e.path,e.request.parse(t)))},async prepareBillingAuthorization(t){u(t);let e=n.prepareBillingAuthorization;return e.response.parse(await r(e.path,e.request.parse(t)))},async confirmBillingAuthorization(t){u(t);let e=n.confirmBillingAuthorization;return e.response.parse(await r(e.path,e.request.parse(t)))},async setBillingCoupons(t){u(t);let e=n.setBillingCoupons,a=e.request.safeParse(t);if(!a.success)throw new s("INVALID_REQUEST","Invalid billing coupon list");let l=e.response.safeParse(await r(e.path,a.data));if(!l.success)throw new s("INVALID_RESPONSE","Invalid billing coupon receipt");return l.data},async revokeBillingAuthorization(t){u(t);let e=n.revokeBillingAuthorization;return e.response.parse(await r(e.path,e.request.parse(t)))},async listBillingInvoices(t={after:null,limit:25}){u(t);let e=n.listBillingInvoices;return e.response.parse(await r(e.path,e.request.parse(t)))},async confirmBillingAdjustment(t){u(t);let e=n.confirmBillingAdjustment;return e.response.parse(await r(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 s("INVALID_TOKEN","Browser SDK requires a customer session");p.reset(),f.identify(t),i=!0,c(!0)},reset(){i=!1,p.reset(),f.reset(),c(!1)},async redeemReward(t){u(t);let e=n.redeemReward,a=e.request.safeParse({...t,requestId:t.requestId??crypto.randomUUID()});if(!a.success)throw new s("INVALID_REQUEST","Invalid reward redemption");let l=e.response.safeParse(await r(e.path,a.data));if(!l.success)throw new s("INVALID_RESPONSE","Invalid reward receipt");return l.data.redemption},async claimRewardProduct(t){u(t);let e=n.claimRewardProduct,a=e.request.safeParse(t);if(!a.success)throw new s("INVALID_REQUEST","Invalid reward product claim");let l=e.response.safeParse(await r(e.path,a.data));if(!l.success)throw new s("INVALID_RESPONSE","Invalid reward product checkout");return l.data.checkout},async createReferralCode(t){u(t);let e=n.createReferralCode,a=e.request.safeParse({...t,requestId:t.requestId??crypto.randomUUID()});if(!a.success)throw new s("INVALID_REQUEST","Invalid referral program");let l=e.response.safeParse(await r(e.path,a.data));if(!l.success)throw new s("INVALID_RESPONSE","Invalid referral code");return l.data.referralCode},async redeemCoupon(t,e=crypto.randomUUID()){let a=n.redeemCoupon,l=a.request.safeParse({code:t,requestId:e});if(!l.success)throw new s("INVALID_REQUEST","Invalid coupon code");let A=a.response.safeParse(await r(a.path,l.data));if(!A.success)throw new s("INVALID_RESPONSE","Invalid Coupon receipt");let R=A.data;return{offer:R.offer,reason:R.reason}},async claimCoupon(t,e=crypto.randomUUID()){let a=n.grantOffer,l=a.request.safeParse({couponId:t,requestId:e});if(!l.success)throw new s("INVALID_REQUEST","Invalid Coupon claim");let A=a.response.safeParse(await r(a.path,l.data));if(!A.success)throw new s("INVALID_RESPONSE","Invalid Coupon receipt");return{offer:A.data.offer,reason:A.data.reason}},async listOffers(){let t=n.listOffers.response.safeParse(await r("offers",{},"GET"));if(!t.success)throw new s("INVALID_RESPONSE","Invalid offers response");return t.data.offers}}}async function ge(...o){return(await import("./paywall-GRSGZLVG.js")).showPaywall(...o)}async function Ae(...o){return(await import("./funnel-runtime-host-YXWVCKAJ.js")).showFunnelRun(...o)}export{s as IndianaError,X as createBrowserFunnelCommandStorage,te as createConfigurationSync,_ as createFeatureClient,ne as createFunnelClient,V as createFunnelRunController,ve as createIndiana,re as createLocalFunnelClient,ee as createPaywallSession,W as evaluateFunnelNode,Z as formatCouponDiscount,Y as formatCouponMoney,$ as formatCouponTerms,Ae as showFunnelRun,ge as showPaywall};
|
|
1
|
+
import{a as _,e as X,h as ee,i as V,j as te,k as re,l as j,m as ne}from"./chunk-J7M7UH74.js";import{a as B}from"./chunk-ET4NANGB.js";import{a as s}from"./chunk-5TEZEOHX.js";import"./chunk-S5TVMQRC.js";import{Vf as n,W as Z,X as $,Y as W,wf as L}from"./chunk-VMLGV5OS.js";import"./chunk-RMJJOSVZ.js";import"./chunk-OHDY27EI.js";import"./chunk-S2MSIA57.js";var z=o=>new TextEncoder().encode(JSON.stringify(o)).length,Q=16384;function H(o,f,r,i){if(i&&r&&(i.scope.projectId!==r.projectId||i.scope.environment!==r.environment))throw new s("SCOPE_MISMATCH","Configuration belongs to another App/environment");let p=0,I,c=m=>{I={config:structuredClone(m),until:Date.now()+3e4}},t=[],e=null,a,l=new Set;function E(){if(!f())throw new s("NOT_IDENTIFIED","Call identify before using Features or events")}function P(){a||!t.length||(a=setTimeout(()=>{a=void 0,N().catch(()=>{}).finally(P)},5e3),typeof a=="object"&&"unref"in a&&a.unref())}function x(m,v={}){if(E(),I&&Date.now()<I.until&&!L(I.config,m))return;k();let h=n.trackEvents.request.parse({events:[{eventUuid:crypto.randomUUID(),timestamp:new Date().toISOString(),name:m,properties:v}]}).events[0];if(z({events:[h]})>Q)throw new s("INVALID_REQUEST","Event exceeds the delivery size limit");if(t.length>=500)throw new s("EVENT_QUEUE_FULL","Flush pending events before tracking more");t.push(structuredClone(h)),P()}async function N(m=!1){if(E(),e)return e;let v=p,h=(async()=>{let O={inserted:0,duplicates:0,rejected:0,skipped:0},C=t.length;for(;C&&v===p;){let A=[];for(let F of t.slice(0,Math.min(C,100))){if(A.length&&z({events:[...A,F]})>Q)break;A.push(F)}let g=n.trackEvents,w=g.response.parse(await o(g.path,g.request.parse({events:A}),g.method,{keepalive:m}));if(v!==p)throw new s("IDENTITY_CHANGED","Event identity changed during delivery");if(w.inserted+w.duplicates+w.rejected+w.skipped!==A.length)throw new s("INVALID_RESPONSE","Incomplete event acknowledgement");c(w.analyticsConfig),t.splice(0,A.length),C-=A.length,O.inserted+=w.inserted,O.duplicates+=w.duplicates,O.rejected+=w.rejected,O.skipped+=w.skipped}return O})();e=h;try{return await h}finally{e===h&&(e=null)}}async function J(m={}){i||E();let v=p,h=!1,O=async()=>{if(h||v!==p)throw new s("IDENTITY_CHANGED","Feature identity changed");let y=n.getFeatures,d=i?{scope:{projectId:i.scope.projectId,environment:i.scope.environment},payload:await i.features()}:y.response.parse(await o(y.path,y.request.parse({}),y.method));if(v!==p)throw new s("IDENTITY_CHANGED","Feature identity changed");if(r&&(d.scope.projectId!==r.projectId||d.scope.environment!==r.environment))throw new s("INVALID_RESPONSE","Feature response scope changed");return c(d.payload.analyticsConfig),d},C=await O(),A=!0,g,w=y=>{try{m.onError?.(y)}catch{}},F=(y,d)=>{try{x(y,d)}catch(S){w(S)}},R=_({assertUsable:i?.assertFeatures,scope:C.scope,attributes:m.attributes,onError:m.onError,load:async()=>A?(A=!1,C.payload):(await O()).payload,evaluateRemote:async y=>{if(v!==p)throw new s("IDENTITY_CHANGED","Feature identity changed");let d=n.evaluateFeatures,S=d.response.parse(await o(d.path,d.request.parse(y),d.method));if(S.scope.projectId!==C.scope.projectId||S.scope.environment!==C.scope.environment)throw new s("INVALID_RESPONSE","Remote Feature response scope changed");return{generation:S.generation,evaluatedAt:S.evaluatedAt,expiresAt:S.expiresAt,features:S.features}},onExperimentViewed:(y,d)=>F("Experiment Viewed",{experimentId:y.key,variationId:d.key}),onFeatureUsage:(y,d)=>F("Feature Evaluated",{feature:y,value:d.value,source:d.source,ruleId:d.ruleId,...d.experimentResult?{variationId:d.experimentResult.key}:{}})}),M=R.refresh;function D(){clearTimeout(g),!i&&(h||v!==p||!R.expiresAt||(g=setTimeout(()=>{b().catch(w)},Math.min(2147483647,Math.max(1e3,Date.parse(R.expiresAt)-Date.now()))),typeof g=="object"&&"unref"in g&&g.unref()))}async function b(){try{return await M()}finally{D()}}let U=()=>{h||b().catch(w)},Y=R.subscribe(D),K=i?.subscribe(()=>{!h&&i.fresh&&b().catch(w)});function q(){h||(h=!0,clearTimeout(g),typeof window<"u"&&window.removeEventListener("focus",U),Y(),K?.(),R.reset(),l.delete(q))}l.add(q);try{await R.init()}catch(y){throw q(),y}return D(),!i&&typeof window<"u"&&window.addEventListener("focus",U),Object.assign(R,{refresh:b,destroy:q})}let T;function k(){if(T||typeof document>"u")return;let m=()=>{document.visibilityState==="hidden"&&f()&&t.length&&N(!0).catch(()=>{})};document.addEventListener("visibilitychange",m),T=()=>document.removeEventListener("visibilitychange",m)}return{features:J,track(m,v){return k(),x(m,v)},flush:N,reset(){p++,I=void 0,clearTimeout(a),a=void 0,t=[],e=null;for(let m of l)m();T?.(),T=void 0}}}function G(o,f){let r="source"in f?{funnelId:f.source.id,funnelVersionId:f.source.versionId}:"versionId"in f?{funnelId:f.funnelId,funnelVersionId:f.versionId}:f,i=n.grantOffer.request.pick({funnelId:!0,funnelVersionId:!0}).required({funnelId:!0}).safeParse(r);if(!i.success)throw new s("INVALID_REQUEST","A valid Funnel source is required");let p=Object.freeze(i.data);function I(c){if("customerId"in c)throw new s("INVALID_REQUEST","Customer identity cannot be overridden");if("funnelId"in c&&c.funnelId!==void 0&&c.funnelId!==p.funnelId||"funnelVersionId"in c&&c.funnelVersionId!==void 0&&c.funnelVersionId!==p.funnelVersionId)throw new s("SCOPE_MISMATCH","The original Funnel source cannot change");return{...c,...p}}return{async claimCoupon(c,t=crypto.randomUUID()){let e=n.grantOffer,a=e.response.parse(await o(e.path,e.request.parse(I({couponId:c,requestId:t}))));return{offer:a.offer,reason:a.reason}},async resolveOffering(c){let t=n.resolveOffering;return t.response.parse(await o(t.path,t.request.parse(I(c))))},async resolvePaywall(c){let t=n.resolvePaywall;return t.response.parse(await o(t.path,t.request.parse(I(c))))},async previewAttach(c){let t=n.previewAttach;return t.response.parse(await o(t.path,t.request.parse(I(c))))}}}function se(o){if(!/^gg_ct_[A-Za-z0-9_-]{32,128}$/.test(o.customerToken))throw new s("INVALID_TOKEN","A customer credential is required");if(!o.scope)throw new s("INVALID_REQUEST","An explicit App and environment scope is required");let f=j({...o,scope:o.scope,apiKey:o.customerToken});return{async start(r){let i=await f.start(r),p=V({...o,runToken:i.runToken});p.identify(o.customerToken);let I=i.run.instruction?.type==="evaluate"?await p.get():i;return{...i,...I,controller:p}}}}function u(o){if(o!==null&&typeof o=="object"&&"customerId"in o)throw new s("INVALID_REQUEST","Customer requests use the verified session identity")}function ge(o){let f=B(o),r=f.request,i=!1,p=H(r,()=>i,o.scope,o.configuration),I=new Set,c=t=>{for(let e of I)try{e(t)}catch{}};return{forFunnel(t){return G(r,t)},async features(t={}){return p.features(t)},track(t,e){return p.track(t,e)},flush(){return p.flush()},async setupPayment(t){u(t);let e=n.setupPayment;return e.response.parse(await r(e.path,e.request.parse(t)))},async readPaymentSetup(t){u(t);let e=n.readPaymentSetup;return e.response.parse(await r(e.path,e.request.parse(t)))},async previewUpdate(t){u(t);let e=n.previewUpdate;return e.response.parse(await r(e.path,e.request.parse(t)))},async update(t){u(t);let e=n.update;return e.response.parse(await r(e.path,e.request.parse(t)))},async readSubscriptionUpdate(t){u(t);let e=n.readSubscriptionUpdate;return e.response.parse(await r(e.path,e.request.parse(t)))},async restoreNativePurchase(t){u(t);let e=n.restoreNativePurchase;return e.response.parse(await r(e.path,e.request.parse(t)))},async previewAttach(t){u(t);let e=n.previewAttach;return e.response.parse(await r(e.path,e.request.parse(t)))},async attach(t){u(t);let e=n.attach;return e.response.parse(await r(e.path,e.request.parse(t)))},async readSubscriptionOperation(t){u(t);let e=n.readSubscriptionOperation;return e.response.parse(await r(e.path,e.request.parse(t)))},async checkEntitlement(t){u(t);let e=n.checkEntitlement;return e.response.parse(await r(e.path,e.request.parse(t)))},async resolvePaywall(t){u(t);let e=n.resolvePaywall;return e.response.parse(await r(e.path,e.request.parse(t)))},async resolveOffering(t){u(t);let e=n.resolveOffering;return e.response.parse(await r(e.path,e.request.parse(t)))},async readHoldings(t={}){let e=n.readHoldings;return e.response.parse(await r(e.path,e.request.omit({customerId:!0}).parse(t)))},async readLedger(t){let e=n.readLedger;return e.response.parse(await r(e.path,e.request.parse({query:t})))},async readBillingInvoice(t){u(t);let e=n.readBillingInvoice;return e.response.parse(await r(e.path,e.request.parse(t)))},async readCreditStatement(t){u(t);let e=n.readCreditStatement;return e.response.parse(await r(e.path,e.request.parse(t)))},async quoteBalance(t){u(t);let e=n.quoteBalance;return e.response.parse(await r(e.path,e.request.parse({command:t})))},async readBillingControls(t={}){u(t);let e=n.readBillingControls;return e.response.parse(await r(e.path,e.request.parse(t)))},async prepareBillingAuthorization(t){u(t);let e=n.prepareBillingAuthorization;return e.response.parse(await r(e.path,e.request.parse(t)))},async confirmBillingAuthorization(t){u(t);let e=n.confirmBillingAuthorization;return e.response.parse(await r(e.path,e.request.parse(t)))},async setBillingCoupons(t){u(t);let e=n.setBillingCoupons,a=e.request.safeParse(t);if(!a.success)throw new s("INVALID_REQUEST","Invalid billing coupon list");let l=e.response.safeParse(await r(e.path,a.data));if(!l.success)throw new s("INVALID_RESPONSE","Invalid billing coupon receipt");return l.data},async revokeBillingAuthorization(t){u(t);let e=n.revokeBillingAuthorization;return e.response.parse(await r(e.path,e.request.parse(t)))},async listBillingInvoices(t={after:null,limit:25}){u(t);let e=n.listBillingInvoices;return e.response.parse(await r(e.path,e.request.parse(t)))},async confirmBillingAdjustment(t){u(t);let e=n.confirmBillingAdjustment;return e.response.parse(await r(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 s("INVALID_TOKEN","Browser SDK requires a customer session");p.reset(),f.identify(t),i=!0,c(!0)},reset(){i=!1,p.reset(),f.reset(),c(!1)},async redeemReward(t){u(t);let e=n.redeemReward,a=e.request.safeParse({...t,requestId:t.requestId??crypto.randomUUID()});if(!a.success)throw new s("INVALID_REQUEST","Invalid reward redemption");let l=e.response.safeParse(await r(e.path,a.data));if(!l.success)throw new s("INVALID_RESPONSE","Invalid reward receipt");return l.data.redemption},async claimRewardProduct(t){u(t);let e=n.claimRewardProduct,a=e.request.safeParse(t);if(!a.success)throw new s("INVALID_REQUEST","Invalid reward product claim");let l=e.response.safeParse(await r(e.path,a.data));if(!l.success)throw new s("INVALID_RESPONSE","Invalid reward product checkout");return l.data.checkout},async createReferralCode(t){u(t);let e=n.createReferralCode,a=e.request.safeParse({...t,requestId:t.requestId??crypto.randomUUID()});if(!a.success)throw new s("INVALID_REQUEST","Invalid referral program");let l=e.response.safeParse(await r(e.path,a.data));if(!l.success)throw new s("INVALID_RESPONSE","Invalid referral code");return l.data.referralCode},async redeemCoupon(t,e=crypto.randomUUID()){let a=n.redeemCoupon,l=a.request.safeParse({code:t,requestId:e});if(!l.success)throw new s("INVALID_REQUEST","Invalid coupon code");let E=a.response.safeParse(await r(a.path,l.data));if(!E.success)throw new s("INVALID_RESPONSE","Invalid Coupon receipt");let P=E.data;return{offer:P.offer,reason:P.reason}},async claimCoupon(t,e=crypto.randomUUID()){let a=n.grantOffer,l=a.request.safeParse({couponId:t,requestId:e});if(!l.success)throw new s("INVALID_REQUEST","Invalid Coupon claim");let E=a.response.safeParse(await r(a.path,l.data));if(!E.success)throw new s("INVALID_RESPONSE","Invalid Coupon receipt");return{offer:E.data.offer,reason:E.data.reason}},async listOffers(){let t=n.listOffers.response.safeParse(await r("offers",{},"GET"));if(!t.success)throw new s("INVALID_RESPONSE","Invalid offers response");return t.data.offers}}}async function Ee(...o){return(await import("./paywall-LBDMGVWZ.js")).showPaywall(...o)}async function Ae(...o){return(await import("./funnel-runtime-host-3STQUS6F.js")).showFunnelRun(...o)}export{s as IndianaError,ee as createBrowserFunnelCommandStorage,re as createConfigurationSync,_ as createFeatureClient,se as createFunnelClient,V as createFunnelRunController,ge as createIndiana,ne as createLocalFunnelClient,te as createPaywallSession,X as evaluateFunnelNode,$ as formatCouponDiscount,Z as formatCouponMoney,W as formatCouponTerms,Ae as showFunnelRun,Ee as showPaywall};
|
package/dist/openrouter.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { OpenRouter } from '@openrouter/sdk';
|
|
2
2
|
import { ChatUsage } from '@openrouter/sdk/models';
|
|
3
|
-
import { c as createAiPricing, F as FoundationApi, a as AiUsageContext, b as AiTokenUsage, d as AiTokenQuote } from './ai-usage-
|
|
3
|
+
import { c as createAiPricing, F as FoundationApi, a as AiUsageContext, b as AiTokenUsage, d as AiTokenQuote } from './ai-usage-B4W5m4Ie.js';
|
|
4
4
|
import '@ai-sdk/provider';
|
|
5
|
-
import './screen-
|
|
5
|
+
import './screen-16d-xADb.js';
|
|
6
6
|
import 'zod';
|
|
7
7
|
import 'zod/v4';
|
|
8
8
|
|
package/dist/openrouter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./chunk-
|
|
1
|
+
import"./chunk-M3DG6ZCT.js";import"./chunk-ET4NANGB.js";import{a as i}from"./chunk-5TEZEOHX.js";import"./chunk-S5TVMQRC.js";import"./chunk-VMLGV5OS.js";import"./chunk-RMJJOSVZ.js";import"./chunk-OHDY27EI.js";import"./chunk-S2MSIA57.js";import{z as k}from"zod";var c=k.number().int().min(0).max(1e9);function R(e,o){let a=c.parse(e.promptTokens),p=c.parse(e.completionTokens),s=c.parse(e.promptTokensDetails?.cachedTokens??0),t=c.parse(e.promptTokensDetails?.cacheWriteTokens??0),r=c.parse(e.promptTokensDetails?.audioTokens??0),l=c.parse(e.completionTokensDetails?.audioTokens??0),n=c.parse(e.completionTokensDetails?.reasoningTokens??0);if(c.parse(e.totalTokens)!==a+p||s+t+r>a||n+l>p||(e.promptTokensDetails?.videoTokens??0)>0)throw new i("AI_USAGE_UNAVAILABLE","Token pools must conserve usage; video needs an explicit token mapper");return{input:a-s-t-r,output:p-l-(o==="separate"?n:0),cache_read:s,cache_write:t,input_audio:r,output_audio:l,reasoning:o==="separate"?n:0}}function I(e){if(!Number.isFinite(e)||e<0)throw new i("AI_USAGE_UNAVAILABLE","Provider cost must be a nonnegative USD amount");let o=String(e),a=o.includes("e")?e.toFixed(18).replace(/0+$/,"").replace(/\.$/,""):o;if(!/^(0|[1-9]\d{0,11})(\.\d{1,18})?$/.test(a)||Number(a)!==e)throw new i("AI_USAGE_UNAVAILABLE","Provider cost exceeds the supported precision");return a}async function h(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning)||!e.modelId||!e.generationId)throw new i("INVALID_REQUEST","Actual model, generation ID and reasoning pricing are required");let o={context:e.context,generationId:e.generationId,modelId:`openrouter/${e.modelId}`,usage:e.usage,tokens:null,quote:null,receipt:null,phase:"captured"};await e.persist(o);let a=e.mapTokens?e.mapTokens(e.usage):R(e.usage,e.reasoning),p=e.usage.cost==null?void 0:I(e.usage.cost),s=e.quote??await e.pricing.quoteTokens({modelId:o.modelId,tokens:a});if(s.pricing.modelId!==o.modelId||Object.keys(a).some(l=>a[l]!==s.tokens[l]))throw new i("INVALID_REQUEST","Saved quote must match the provider model and token pools");await e.persist({...o,tokens:a,quote:s,phase:"quoted"});let t=await e.pricing.trackTokens(e.client,{...e.context,quote:s,providerCostUsd:p,generationId:e.generationId});if(!t.receipt.accepted)throw new i("AI_BALANCE_REJECTED","OpenRouter usage was saved but the balance request was rejected");let r={...o,tokens:a,quote:s,receipt:t,phase:"settled"};return await e.persist(r),r}function T(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning))throw new i("INVALID_REQUEST","Reasoning pricing is required");let o=e.openRouter.chat;async function a(t){if(!t.usage||!t.modelId||!t.generationId)throw new i("AI_USAGE_UNAVAILABLE","OpenRouter did not return final usage and the actual model");await h({...e,context:t.context,generationId:t.generationId,modelId:t.modelId.slice(11),usage:t.usage})}let p=async(t,r)=>{let n={context:await e.context(),generationId:null,modelId:null,usage:null,tokens:null,quote:null,receipt:null,phase:"incomplete"},d;try{d=await o.send(t,r)}catch(g){throw await e.persist(n),g}if(!(d instanceof ReadableStream)){if(n={...n,generationId:d.id,modelId:d.model?`openrouter/${d.model}`:null,usage:d.usage??null},!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter omitted final accounting");return await a(n),d}let w=d.getReader(),m=!1;return new ReadableStream({async pull(g){try{let{value:u,done:A}=await w.read();if(A){if(m=!0,!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter stream ended without final accounting");await a(n),g.close();return}if(u.error)throw new i("AI_PROVIDER_ERROR",u.error.message);u.usage&&(n={...n,generationId:u.id,modelId:u.model?`openrouter/${u.model}`:null,usage:u.usage}),g.enqueue(u)}catch(u){m||(m=!0,await e.persist(n)),await w.cancel(u),g.error(u)}},async cancel(g){m||(m=!0,await e.persist(n)),await w.cancel(g)}})},s=new Proxy(o,{get(t,r){return r==="send"?p:Reflect.get(t,r,t)}});return new Proxy(e.openRouter,{get(t,r){return r==="chat"?s:Reflect.get(t,r,t)}})}export{T as createOpenRouterUsageClient,h as trackOpenRouterUsage};
|
package/dist/page.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { C as ConfigurationSync } from './configuration-sync-
|
|
1
|
+
import { C as ConfigurationSync } from './configuration-sync-Bnu8s4pc.js';
|
|
2
2
|
import { J as JsonValue, R as Result } from './growth-rules-B4YYy64R.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import './screen-
|
|
4
|
+
import './screen-16d-xADb.js';
|
|
5
5
|
|
|
6
6
|
/** GET /api/v1/page-experiments/{environmentId}: page experiments and the saved groups they reference only. */
|
|
7
7
|
declare const pageExperimentPayloadSchema: z.ZodObject<{
|
|
@@ -10,22 +10,13 @@ declare const pageExperimentPayloadSchema: z.ZodObject<{
|
|
|
10
10
|
generation: z.ZodString;
|
|
11
11
|
experiments: z.ZodArray<z.ZodObject<{
|
|
12
12
|
name: z.ZodOptional<z.ZodString>;
|
|
13
|
-
|
|
14
|
-
key: z.ZodOptional<z.ZodString>;
|
|
15
|
-
name: z.ZodOptional<z.ZodString>;
|
|
16
|
-
passthrough: z.ZodOptional<z.ZodBoolean>;
|
|
17
|
-
}, z.core.$strict>>>;
|
|
13
|
+
coverage: z.ZodOptional<z.ZodNumber>;
|
|
18
14
|
key: z.ZodString;
|
|
19
|
-
|
|
20
|
-
attribute: z.ZodOptional<z.ZodString>;
|
|
21
|
-
seed: z.ZodString;
|
|
22
|
-
hashVersion: z.ZodLiteral<2>;
|
|
23
|
-
ranges: z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
|
|
24
|
-
}, z.core.$strict>>>;
|
|
15
|
+
condition: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
|
|
25
16
|
seed: z.ZodOptional<z.ZodString>;
|
|
26
17
|
hashVersion: z.ZodOptional<z.ZodLiteral<2>>;
|
|
27
18
|
ranges: z.ZodOptional<z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>>;
|
|
28
|
-
|
|
19
|
+
force: z.ZodOptional<z.ZodNumber>;
|
|
29
20
|
urlPatterns: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
30
21
|
include: z.ZodBoolean;
|
|
31
22
|
type: z.ZodEnum<{
|
|
@@ -34,21 +25,30 @@ declare const pageExperimentPayloadSchema: z.ZodObject<{
|
|
|
34
25
|
}>;
|
|
35
26
|
pattern: z.ZodString;
|
|
36
27
|
}, z.core.$strict>>>;
|
|
37
|
-
force: z.ZodOptional<z.ZodNumber>;
|
|
38
28
|
persistQueryString: z.ZodOptional<z.ZodBoolean>;
|
|
39
29
|
hashAttribute: z.ZodOptional<z.ZodString>;
|
|
30
|
+
phase: z.ZodOptional<z.ZodString>;
|
|
31
|
+
filters: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
32
|
+
attribute: z.ZodOptional<z.ZodString>;
|
|
33
|
+
seed: z.ZodString;
|
|
34
|
+
hashVersion: z.ZodLiteral<2>;
|
|
35
|
+
ranges: z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
|
|
36
|
+
}, z.core.$strict>>>;
|
|
40
37
|
parentConditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
41
38
|
id: z.ZodString;
|
|
42
39
|
condition: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
43
40
|
gate: z.ZodOptional<z.ZodBoolean>;
|
|
44
41
|
}, z.core.$strict>>>;
|
|
45
42
|
weights: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
46
|
-
coverage: z.ZodOptional<z.ZodNumber>;
|
|
47
43
|
fallbackAttribute: z.ZodOptional<z.ZodString>;
|
|
48
44
|
disableStickyBucketing: z.ZodOptional<z.ZodBoolean>;
|
|
49
45
|
bucketVersion: z.ZodOptional<z.ZodNumber>;
|
|
50
46
|
minBucketVersion: z.ZodOptional<z.ZodNumber>;
|
|
51
|
-
|
|
47
|
+
meta: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
48
|
+
key: z.ZodOptional<z.ZodString>;
|
|
49
|
+
name: z.ZodOptional<z.ZodString>;
|
|
50
|
+
passthrough: z.ZodOptional<z.ZodBoolean>;
|
|
51
|
+
}, z.core.$strict>>>;
|
|
52
52
|
changeId: z.ZodString;
|
|
53
53
|
variations: z.ZodArray<z.ZodObject<{
|
|
54
54
|
urlRedirect: z.ZodString;
|
|
@@ -72,7 +72,8 @@ type PageExperimentPayload = z.infer<typeof pageExperimentPayloadSchema>;
|
|
|
72
72
|
/**
|
|
73
73
|
* Page experiments for anonymous merchant pages (docs/growthbook-sdk-delivery.md): URL redirect experiments delivered
|
|
74
74
|
* by a public App environment ID. Assignment, URL targeting and query-string overrides use the vendored GrowthBook
|
|
75
|
-
* engine; the exposure is sent before navigating. The environment ID is public and never
|
|
75
|
+
* engine; the exposure is sent before navigating and kept until acknowledged. The environment ID is public and never
|
|
76
|
+
* authenticates anything.
|
|
76
77
|
*/
|
|
77
78
|
type PageExperimentsOptions = {
|
|
78
79
|
configuration?: ConfigurationSync;
|
package/dist/page.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{h as a,i as b,j as c,k as d}from"./chunk-N6UIDDAX.js";import"./chunk-S5TVMQRC.js";import"./chunk-OHDY27EI.js";import"./chunk-S2MSIA57.js";export{d as createPageExperiments,a as mergeQueryStrings,b as pageAttributes,c as readPayload};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as z}from"./chunk-6X42DWOM.js";import"./chunk-
|
|
1
|
+
import{a as z}from"./chunk-6X42DWOM.js";import"./chunk-ET4NANGB.js";import{a as w}from"./chunk-5TEZEOHX.js";import"./chunk-S5TVMQRC.js";import{Gd as q,_j as j}from"./chunk-VMLGV5OS.js";import{f as $,ja as N}from"./chunk-RMJJOSVZ.js";import"./chunk-OHDY27EI.js";import"./chunk-S2MSIA57.js";async function W(b,n,h){if(n.status!=="complete")throw new w("INVALID_RESPONSE","A verified completed purchase is required");if(await h.onComplete?.(n),!b||!h.check)return;let t=N.parse(await h.check());if(t.internal_feature_id!==b.internal_feature_id||t.quantity!==b.quantity)throw new w("INVALID_RESPONSE","The access requirement changed");t.allowed&&await h.onAccessGranted?.(t)}async function ie(b,n){let h=n.check?N.parse(await n.check()):null;if(h?.allowed)return await n.onAccessGranted?.(h),{check:h,host:null};let t=await n.start(),y=t.view;if(!y)throw new w("INVALID_RESPONSE","Paywall presentation is missing");let{mountScreenPreview:J}=await import("./popup.js"),a=b.ownerDocument,S=new AbortController,v=a.createElement("section"),Q=a.createElement("div"),O=a.createElement("div"),P=a.createElement("p"),c=a.createElement("button"),L=a.createElement("button"),u=a.createElement("dialog"),_=a.activeElement,p=y.document.screen.strings.defaultLocale.startsWith("zh");v.dataset.indianaPaywall="",v.setAttribute("aria-label",y.document.name),v.style.cssText="width:100%;box-sizing:border-box;background:#fff;color:#172033;font:14px/1.5 system-ui,sans-serif",O.style.cssText="display:flex;gap:12px;padding:12px 20px;align-items:center;flex-wrap:wrap",P.setAttribute("role","status"),L.textContent=p?"\u5173\u95ED":"Close",c.textContent=p?"\u91CD\u8BD5":"Retry",c.hidden=!0,O.append(P,c,L),v.append(Q,O);let D=y.document.presentation,A,d=!1,T=!1,f=null,G=!1,m=()=>!G&&n.canInteract?.()!==!1,M=!1,r=null,I=null,U=e=>{P.textContent=e instanceof Error?e.message:p?"\u8BF7\u6C42\u5931\u8D25":"Request failed",z(n.onError,e),c.hidden=r===null};async function k(e){if(!(T||d||!m())){T=!0,c.hidden=!0,P.textContent="";try{await e()}catch(s){d||U(s)}finally{T=!1}}}async function K(e){await W(h,e,n)}async function E(e){if(d)return;if(!m()){r=async()=>E(await t.read()),c.hidden=!1;return}if(P.textContent=e.status,e.status==="complete"){r=null,await K(e);return}if(e.status!=="pending"){if(t.canReselect===!1){P.textContent=p?"\u6B63\u5728\u6838\u5BF9\u539F\u8D2D\u4E70\u7ED3\u679C":"Checking the original purchase result",c.textContent=p?"\u67E5\u8BE2\u7ED3\u679C":"Check result",r=async()=>E(await t.read()),c.hidden=!1;return}c.textContent=p?"\u91CD\u8BD5":"Retry",r=null,f=null;return}let s=Date.now()+6e5,l=2e3;for(;!d&&Date.now()<s;){if(await new Promise(C=>{let R=()=>{clearTimeout(x),C()},x=setTimeout(()=>{S.signal.removeEventListener("abort",R),C()},l);S.signal.addEventListener("abort",R,{once:!0})}),d)return;if(!m()){r=async()=>E(await t.read()),c.hidden=!1;return}let i=await t.read();if(i.status!=="pending"){await E(i);return}l=Math.min(l*1.5,3e4)}r=async()=>E(await t.read()),c.hidden=!1}async function V(){I?.remove(),I=null,r=V;let e=await t.confirm();if(!m()){r=V,c.hidden=!1;return}if(e.status==="pending"){if(e.checkoutUrl)n.onCheckoutUrl?await n.onCheckoutUrl(e.checkoutUrl):a.defaultView?.location.assign(e.checkoutUrl);else if(e.execution||e.nativePurchase){if(!n.onPurchase)throw new w("PURCHASE_HANDLER_REQUIRED","Provide the merchant or native purchase handler");await n.onPurchase({operation:e,signal:S.signal})}}r=async()=>E(await t.read()),await E(e)}function X(e){I?.remove();let s=a.createElement("div"),l=a.createElement("button"),i=a.createElement("button"),C=a.createElement("p");C.textContent=e.lines.map(o=>o.productName).join(", ")+" \xB7 "+$(e.charge?.totalMinor??e.catalogAmountMinor-(e.discount?.amountMinor??0),e.currency),l.textContent=p?"\u786E\u8BA4\u8D2D\u4E70":"Confirm purchase",i.textContent=p?"\u53D6\u6D88":"Cancel",l.onclick=()=>{k(V)};let R=async()=>{let o=await t.cancel();d||(s.remove(),I=null,await E(o))};i.onclick=()=>{r=R,k(R)};let x=a.createElement("div");for(let o of e.lines){let B=a.createElement("p");if(B.textContent=`${o.productName} \xB7 ${$(o.catalogAmountMinor,e.currency)}${j(o.interval,p?"zh-CN":"en",o.intervalCount??1)}`,x.append(B),o.trial){let F=a.createElement("p");F.textContent=p?`\u8BD5\u7528 ${o.trial.days} \u5929\uFF1B${o.trial.cardRequired?"\u9700\u8981\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F":"\u65E0\u9700\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F"}`:`Trial days: ${o.trial.days}; ${o.trial.cardRequired?"a payment method is required":"no payment method is required"}`,x.append(F)}}if(!e.charge){let o=a.createElement("p");o.textContent=p?"\u76EE\u5F55\u4EF7\u683C\uFF1B\u6700\u7EC8\u91D1\u989D\u4EE5\u7ED3\u8D26\u65F6\u7A0E\u8D39\u548C\u8BD5\u7528\u89C4\u5219\u4E3A\u51C6\u3002":"Catalog price; the final charge depends on checkout taxes and trial terms.",x.append(o)}s.append(C,x,l,i),O.prepend(s),I=s,r=null}async function H(){if(!f)return;if(r=H,!M){let s=t.view,l=s?.document.buttons[f.actionId],i=s&&l?.type==="checkout"?q(l.product,f.selection,s.capabilities):null;if(!i)throw new w("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area");let C=await n.resolveOfferId?.({actionId:f.actionId,productVersionId:i});if(d)return;C!==void 0&&(f.offerId=C),M=!0}if(!m()){c.hidden=!1;return}let e=await t.preview(f);d||X(e)}function g(e="destroy"){d||(d=!0,S.abort(),A?.destroy(),t.destroy(),u.open&&u.close(),u.remove(),v.remove(),_ instanceof HTMLElement&&_.isConnected&&_.focus(),e==="dismiss"&&z(n.onDismiss))}L.onclick=()=>{m()&&g("dismiss")},u.addEventListener("cancel",e=>{e.preventDefault(),m()&&g("dismiss")}),c.onclick=()=>{r&&k(r)};try{if(D.type==="inline")b.append(v);else{let e={sm:420,md:640,lg:900};u.style.cssText=`padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto;width:${"size"in D?e[D.size]+"px":"100vw"}`,u.setAttribute("aria-label",y.document.name),u.append(v),b.append(u),m()&&u.showModal()}A=J(Q,{mode:"live",rendererUrl:t.webViewUrl,title:y.document.name,onAction(e,s={}){if(!m())return;let l=t.view,i=l?.document.buttons[e];if(i){if(i.type==="close"){k(async()=>{await n.onAction?.(e),g(n.onAction?"action":"dismiss")});return}if(i.type==="action"){r=async()=>{if(i.action.type==="event"){if(!n.onEvent)throw new w("EVENT_HANDLER_REQUIRED","Provide the event handler");await n.onEvent(i.action.event)}else n.onOpenUrl?await n.onOpenUrl(i.action.url):a.defaultView?.location.assign(i.action.url);await n.onAction?.(e),r=null},k(r);return}if((t.quote||f)&&t.canReselect===!1){r=t.quote?async()=>E(await t.read()):H,k(r);return}if(!l||!q(i.product,s,l.capabilities)){U(new w("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));return}if(f&&f.actionId!==e){U(new w("COMMAND_PENDING","Finish the current purchase"));return}f||(f={requestId:crypto.randomUUID(),actionId:e,selection:s},M=!1),k(H)}},onEscape:()=>{m()&&g("dismiss")},onError:e=>U(new Error(e))}),A.update(y.document.screen,y.document.screen.strings.defaultLocale,{capabilities:y.capabilities,serverInput:{bindings:[],answers:{}}}),await A.ready}catch(e){throw g(),e}return{check:h,host:{setSuspended(e){G=e,v.hidden=e,e&&u.open?u.close():!e&&!d&&D.type!=="inline"&&!u.open&&u.showModal()},destroy:g,refresh:async()=>{if(!m()){if(t.view)return t.view;throw new w("PRECONDITION_FAILED","Paywall presentation is suspended")}let e=await t.refresh();return d||A?.updateCapabilities(e.capabilities),e}}}}export{ie as showPaywall};
|
package/dist/popup.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as ScreenAction, b as ScreenNode, c as ScreenDocument } from './screen-
|
|
2
|
-
import { O as Offer, b as OfferUnavailableReason, c as CustomerPageData, a as CustomerDataIntent } from './customer-page-
|
|
1
|
+
import { a as ScreenAction, b as ScreenNode, c as ScreenDocument } from './screen-16d-xADb.js';
|
|
2
|
+
import { O as Offer, b as OfferUnavailableReason, c as CustomerPageData, a as CustomerDataIntent } from './customer-page-B4FGCVpt.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { WindowLike } from 'dompurify';
|
|
5
5
|
|
|
@@ -15,15 +15,15 @@ declare const surfaceDataSchema: z.ZodObject<{
|
|
|
15
15
|
quantity: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
16
16
|
allowed: z.ZodBoolean;
|
|
17
17
|
reason: z.ZodNullable<z.ZodEnum<{
|
|
18
|
-
|
|
18
|
+
unavailable: "unavailable";
|
|
19
19
|
insufficient_balance: "insufficient_balance";
|
|
20
|
-
capacity_exceeded: "capacity_exceeded";
|
|
21
20
|
limit_exceeded: "limit_exceeded";
|
|
22
21
|
awaiting_topup: "awaiting_topup";
|
|
23
22
|
authorization_required: "authorization_required";
|
|
24
23
|
payment_blocked: "payment_blocked";
|
|
25
24
|
cash_budget_exceeded: "cash_budget_exceeded";
|
|
26
|
-
|
|
25
|
+
not_entitled: "not_entitled";
|
|
26
|
+
capacity_exceeded: "capacity_exceeded";
|
|
27
27
|
authentication_required: "authentication_required";
|
|
28
28
|
}>>;
|
|
29
29
|
preview: z.ZodNullable<z.ZodObject<{
|
|
@@ -79,10 +79,10 @@ declare const surfaceDataSchema: z.ZodObject<{
|
|
|
79
79
|
}>;
|
|
80
80
|
amountMinor: z.ZodString;
|
|
81
81
|
interval: z.ZodEnum<{
|
|
82
|
-
free: "free";
|
|
83
82
|
week: "week";
|
|
84
83
|
month: "month";
|
|
85
84
|
year: "year";
|
|
85
|
+
free: "free";
|
|
86
86
|
one_time: "one_time";
|
|
87
87
|
}>;
|
|
88
88
|
intervalCount: z.ZodNumber;
|
|
@@ -329,11 +329,6 @@ type RendererEditorKey = {
|
|
|
329
329
|
* Only per-mount routing lives in the URL fragment; per-visitor data arrives through the host bridge.
|
|
330
330
|
*/
|
|
331
331
|
declare function hostedScreenScript(): string;
|
|
332
|
-
/** Public, deterministic shell. Only per-mount routing lives in the URL fragment;
|
|
333
|
-
* customer credentials, designs and business data arrive through the host bridge.
|
|
334
|
-
* Keep this bootstrap self-contained, like the renderer and Funnel runtime.
|
|
335
|
-
*/
|
|
336
|
-
declare function hostedRendererScript(): string;
|
|
337
332
|
|
|
338
333
|
/** Preserve authoritative decimal strings and localize their digits without rounding through Number. */
|
|
339
334
|
declare function formatCustomerDecimal(value: string, locale: string): string;
|
|
@@ -365,6 +360,15 @@ declare function inspectCustomHtml(html: string, css: string, actionIds: readonl
|
|
|
365
360
|
/** Strict validation always runs; repeated pure design can reuse HTML/CSS preparation. */
|
|
366
361
|
declare function prepareScreen(input: unknown, window: WindowLike): ScreenDocument;
|
|
367
362
|
|
|
363
|
+
declare const hostedRendererShell: {
|
|
364
|
+
readonly tag: string;
|
|
365
|
+
readonly csp: string;
|
|
366
|
+
readonly html: string;
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
/** The bootstrap the shell's CSP hash authorizes. */
|
|
370
|
+
declare function hostedRendererScript(): string;
|
|
371
|
+
|
|
368
372
|
type PopupHandle = {
|
|
369
373
|
destroy: () => void;
|
|
370
374
|
updateCapabilities: (data: SurfaceData) => void;
|
|
@@ -450,4 +454,4 @@ type CustomerPageHandle = {
|
|
|
450
454
|
destroy(): void;
|
|
451
455
|
};
|
|
452
456
|
|
|
453
|
-
export { type CustomerPageHandle, type HtmlCodeDiagnostic, type PopupEvent, type PopupHandle, type RendererEditorKey, type RendererEditorMessages, ScreenDocument, type ScreenNodeRect, type ScreenPreviewHandle, formatCustomerDecimal, hostedRendererScript, hostedScreenScript, inspectCustomHtml, mountScreenPreview, prepareScreen, sanitizeCustomHtml, showPopup };
|
|
457
|
+
export { type CustomerPageHandle, type HtmlCodeDiagnostic, type PopupEvent, type PopupHandle, type RendererEditorKey, type RendererEditorMessages, ScreenDocument, type ScreenNodeRect, type ScreenPreviewHandle, formatCustomerDecimal, hostedRendererScript, hostedRendererShell, hostedScreenScript, inspectCustomHtml, mountScreenPreview, prepareScreen, sanitizeCustomHtml, showPopup };
|