@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/CHANGELOG.md +7 -0
- package/README.md +10 -6
- package/dist/{ai-usage-DX99gvfl.d.ts → ai-usage-CO0lDavO.d.ts} +210 -62
- package/dist/{chunk-2HEB2TPD.js → chunk-EZFAY4ZL.js} +1 -1
- package/dist/chunk-ULRVTA45.js +1 -0
- package/dist/chunk-YOH6DIUN.js +27 -0
- package/dist/funnel-runtime-host-OJJSHKUD.js +1 -0
- package/dist/{funnel-runtime-start-CcuXliU_.d.ts → funnel-runtime-start-DvrWekm0.d.ts} +1631 -135
- package/dist/index.d.ts +624 -40
- package/dist/index.js +1 -1
- package/dist/native-shell.js +1 -1
- package/dist/openrouter.d.ts +1 -1
- package/dist/openrouter.js +1 -1
- package/dist/paywall-HCADUT22.js +1 -0
- package/dist/popup.js +3 -3
- package/dist/server.d.ts +2 -2
- package/dist/server.js +1 -1
- package/dist/src-3GT6E6XD.js +1 -0
- package/package.json +1 -1
- package/dist/chunk-FMAMDKAV.js +0 -27
- package/dist/chunk-Y7LNDG3O.js +0 -1
- package/dist/funnel-runtime-host-QIYKF5KH.js +0 -1
- package/dist/paywall-6HHA4OJV.js +0 -1
- package/dist/src-G7U7DUQR.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as $}from"./chunk-6X42DWOM.js";import{a as s}from"./chunk-EZFAY4ZL.js";import{Oe as Z,fg as K}from"./chunk-YOH6DIUN.js";function ee(I){let n=I.view;if(!n?.paywall)throw new s("INVALID_REQUEST","The current node is not a Paywall");let x=n.paywall.receiptId,Q=n.nodeId,f=n.visit,v=n.paywall.resolution,r=n.paywall.quote,c=n.paywall.operation,T=!1,R=n.paywall.purchaseRequestId,h=null,D=new Map,S=new Map;function E(t){let a=t.run.paywall;if(a?.receiptId===x){if(a.resolution.id!==v.id||a.resolution.offering.id!==v.offering.id)throw new s("INVALID_RESPONSE","The pinned Paywall binding changed");v=a.resolution}if(t.purchase&&t.purchase.receiptId!==x)throw new s("INVALID_RESPONSE","Purchase receipt changed");let l=t.purchase??(a?.receiptId===x?a:null),i=l?.quote??r,u=l?.operation??(i?.operationId===r?.operationId?c:null);if(i&&u&&i.operationId!==u.operationId)throw new s("INVALID_RESPONSE","Purchase operation changed");r=i,(c?.operationId!==u?.operationId||c?.status==="pending"||u?.status==="complete")&&(c=u)}async function m(t,a){if(T)throw new s("IDENTITY_CHANGED","Paywall presentation has closed");let l=D.get(t);if(l){if(JSON.stringify(l.input)!==JSON.stringify(a))throw new s("CONFLICT","A purchase request cannot change its input")}else{let P=I.view;if(!P||P.nodeId!==Q||P.visit!==f||P.paywall?.receiptId!==x)throw new s("PRECONDITION_FAILED","The Paywall visit has changed");l={operation:"submit",requestId:t,nodeId:Q,visit:f,revision:P.revision,input:a},D.set(t,l)}let i=await I.submit(l),u=Date.now()+3e4;for(;i.run.pendingRequest?.requestId===t&&Date.now()<u&&!T;)await new Promise(P=>setTimeout(P,1e3)),i=await I.resume(t);if(i.run.pendingRequest?.requestId===t)throw new s("COMMAND_PENDING","The purchase command is still pending; retry the original request",202);E(i)}async function C(t){if(!r)throw new s("INVALID_REQUEST","A quoted purchase is required");let a=`${t}:${r.operationId}`,l=S.get(a);if(l||(l=crypto.randomUUID(),S.set(a,l)),await m(l,{type:t==="confirm"?"paywall_confirm":"paywall_cancel",operationId:r.operationId}),!c)throw new s("INVALID_RESPONSE","The accepted purchase result is missing");return structuredClone(c)}return{get view(){return structuredClone(v)},get quote(){return r?structuredClone(r):null},get operation(){return c?structuredClone(c):null},get webViewUrl(){return I.webViewUrl},async refresh(){return E(await I.get()),structuredClone(v)},preview(t){if(R&&R!==t.requestId&&(!c||c.status==="pending"))return Promise.reject(new s("COMMAND_PENDING","Retry the original purchase before starting another"));if(R===t.requestId&&h)return h;let a=v.document.buttons[t.actionId],l=a?.type==="checkout"?Z(a.product,t.selection,v.capabilities):null;if(!l)return Promise.reject(new s("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));R=t.requestId;let i=(async()=>{if(await m(t.requestId,{type:"paywall_quote",actionId:t.actionId,productVersionId:l,...t.offerId?{offerId:t.offerId}:{},...t.nativeOffer?{nativeOffer:t.nativeOffer}:{}}),!r)throw new s("INVALID_RESPONSE","The accepted quote is missing");return structuredClone(r)})();return h=i,i.then(()=>{h===i&&(h=null)},u=>{h===i&&(h=null),u instanceof s&&u.status!==void 0&&u.status<500&&![401,425].includes(u.status)&&(R=null)}),i},confirm:()=>C("confirm"),cancel:()=>C("cancel"),async read(){if(!r)throw new s("INVALID_REQUEST","A quoted purchase is required");if(E(await I.get(void 0,{receiptId:x,operationId:r.operationId})),!c)throw new s("INVALID_RESPONSE","The current purchase result is missing");return structuredClone(c)},destroy(){T=!0,D.clear(),S.clear()}}}async function fe(I,n){let{mountScreenPreview:x}=await import("./popup.js"),{showPaywall:Q}=await import("./paywall-HCADUT22.js"),f=I.ownerDocument,v=f.activeElement,r=f.createElement("section"),c=f.createElement("div"),T=f.createElement("div"),R=f.createElement("p"),h=f.createElement("p"),D=f.createElement("button"),S=f.createElement("button"),E=f.createElement("button"),m=f.createElement("dialog");r.dataset.indianaFunnel="",r.setAttribute("aria-busy","false"),r.style.cssText="box-sizing:border-box;width:100%;min-width:0;font:14px/1.5 system-ui,sans-serif;color:#172033;background:#fff",T.style.cssText="display:flex;gap:12px;align-items:center;flex-wrap:wrap;padding:12px 20px",R.setAttribute("role","status"),h.setAttribute("role","alert"),h.hidden=!0,D.type=S.type=E.type="button",T.append(D,R,h,E,S),r.append(c,T),I.append(r);let C=null,t=null,a=null,l="",i=!1,u=0,P="",F=null,G=Promise.resolve(),q=null,V={},j=new Map,J=new Set,H=new Set,M=new Set,A={},k=e=>{i||(h.textContent=e instanceof Error?e.message:"Request failed",h.hidden=!1,E.hidden=n.client.pendingCommand===null,$(n.onError,e))};function U(){let e=n.client.view;if(!e)throw new s("INVALID_REQUEST","No current Run is available");return{requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:e.revision}}async function N(e,o=!1){if(!(u&&!o||i)){u++,r.setAttribute("aria-busy","true"),h.hidden=!0;try{let d=await e();i||await z(n.client.view??d.run)}catch(d){k(d)}finally{u=Math.max(0,u-1),r.setAttribute("aria-busy",String(u>0)),i||(E.hidden=n.client.pendingCommand===null)}}}function Y(e){if(J.has(e)||H.has(e)||i)return;H.add(e);let o=async()=>{if(i||l!==e){H.delete(e);return}if(u||n.client.pendingCommand){setTimeout(()=>{o()},250);return}try{await n.client.submit({operation:"shown",...U()}),J.add(e)}catch(d){k(d)}finally{H.delete(e)}};o()}function X(){F&&clearTimeout(F),!(i||!a||!["running","waiting"].includes(a.status))&&(F=setTimeout(()=>{F=null,N(()=>n.client.get()).finally(X)},a.pendingRequest?1500:5e3))}async function ne(e){let o=n.client.view,d=o?.screen,y=d?.customerData.nodes[e.nodeId];if(!o||!d||!y)return;if(!["refresh","next","previous","filter","sources_next","sources_previous"].includes(e.action)){let g=K(d.document,e.nodeId),_=g?.type==="customer_data"?g.data.outputs?.[e.action]:void 0;_&&d.outputs.includes(_)?await N(()=>n.client.submit({operation:"submit",...U(),input:{type:"screen",output:_,answers:A,selection:e.value?{[e.nodeId]:e.value}:{}}})):await n.onCustomerDataIntent?.(e,o);return}let p=e.action.startsWith("sources_")?y.resources.find(g=>g.key===e.value):null;if(e.action.startsWith("sources_")&&!p)throw new s("INVALID_REQUEST","Choose a current resource");let O=`${o.visit}:${e.nodeId}:${p?.key??""}`,L=j.get(O)??[null],b=V[e.nodeId]??{page:1,after:null,filter:"all",...p?{resourceKey:p.key}:{}};if(e.action==="filter"){let g=e.value;if(!g||!["all","purchase","refund","source","usage","debt","settlement"].includes(g))throw new s("INVALID_REQUEST","Unknown data filter");b={page:1,after:null,filter:g},L.splice(0,L.length,null)}else if(e.action==="next"||e.action==="sources_next"){let g=p?.sources.at(-1),_=p?g?{kind:"ledger",cursor:{at:g.detail[0],id:g.id,type:"source"}}:null:d.dataCursors[e.nodeId];if(!_||!p&&!y.hasNext)return;L[b.page]=_,b={...b,page:b.page+1,after:_}}else if(e.action==="previous"||e.action==="sources_previous"){if(b.page<=1)return;b={...b,page:b.page-1,after:L[b.page-2]??null}}j.set(O,L),V={...V,[e.nodeId]:b},await N(()=>n.client.get({nodeId:o.nodeId,visit:o.visit,revision:o.revision,components:V}))}function te(e){let o=e.screen?.presentation;if(!o||o.type==="inline"){m.open&&m.close(),r.parentElement!==I&&I.append(r);return}r.parentElement!==m&&(m.append(r),I.append(m));let d={sm:420,md:640,lg:900};m.style.cssText=`padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto;width:${"size"in o?d[o.size]+"px":"100vw"}`,m.setAttribute("aria-label",e.screen?.document.name??"Funnel"),m.open||m.showModal()}async function ie(e){if(i)return;a=e;let o=e.locale.startsWith("zh");D.textContent=o?"\u8FD4\u56DE":"Back",S.textContent=o?"\u5173\u95ED":"Close",E.textContent=o?"\u91CD\u8BD5":"Retry",D.disabled=u>0||!!n.client.pendingCommand||!e.canBack,E.hidden=n.client.pendingCommand===null,R.textContent=e.pendingRequest?o?"\u6B63\u5728\u5904\u7406":"Processing":e.instruction?.type==="wait"?o?"\u7B49\u5F85\u4E2D":"Waiting":"",P!==`${e.revision}:${e.visit}:${e.status}`&&(P=`${e.revision}:${e.visit}:${e.status}`,$(n.onState,structuredClone(e)));let d=e.screen||e.paywall?`${e.id}:${e.nodeId}:${e.visit}`:"";if(d!==l&&(C?.destroy(),C=null,t?.destroy(),t=null,c.replaceChildren(),l=d,A={...e.answers},V={},j.clear()),te(e),e.screen)C||(C=x(c,{mode:"live",rendererUrl:n.client.webViewUrl,title:e.screen.document.name,onAction(w,p={},O={}){A={...A,...O},N(()=>n.client.submit({operation:"submit",...U(),input:{type:"screen",output:w,answers:A,selection:p}}))},onAnswers:w=>{A={...A,...w}},onCustomerDataIntent:w=>{ne(w).catch(k)},onEscape:()=>{W()},onError:w=>k(new Error(w)),onRendered:()=>Y(d)})),C.update(e.screen.document,e.locale,{capabilities:e.screen.capabilities,customerData:e.screen.customerData,parameters:e.parameters,serverInput:{bindings:e.screen.inputs,answers:A}}),await C.ready;else if(e.paywall&&!t){let w=await Q(c,{start:async()=>ee(n.client),onPurchase:n.onPurchase,onCheckoutUrl:n.onCheckoutUrl,resolveOfferId:n.resolveOfferId,onEvent:n.onEvent,onOpenUrl:p=>n.onOpenUrl?n.onOpenUrl({receiptId:e.paywall.receiptId,url:p}):f.defaultView?.location.assign(p),onAction:async p=>{let O=await n.client.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:e.revision,input:{type:"screen",output:p,answers:{}}});await z(n.client.view??O.run)},onError:k,onDismiss:()=>{!i&&n.client.view?.visit===e.visit&&W()}});i?w.host?.destroy():t=w.host,Y(d)}let y=e.instruction;if(y&&["open_url","event"].includes(y.type)&&!M.has(y.receiptId)){let w=f.createElement("button");w.type="button",w.textContent=o?"\u7EE7\u7EED":"Continue",w.onclick=()=>{let p=U();N(async()=>{if(y.type==="open_url"&&(n.onOpenUrl?await n.onOpenUrl({receiptId:y.receiptId,url:y.url}):f.defaultView?.location.assign(y.url)),y.type==="event"){if(!n.onEvent)throw new s("EVENT_HANDLER_REQUIRED","Provide the event handler");await n.onEvent(y.event)}if(i||n.client.view?.nodeId!==p.nodeId||n.client.view.visit!==p.visit)throw new s("PRECONDITION_FAILED","The client action visit changed");let O=await n.client.submit({operation:"submit",...p,input:{type:"client_action",receiptId:y.receiptId,outcome:"success"}});return M.add(y.receiptId),O})},c.replaceChildren(w)}!e.pendingRequest&&e.status==="completed"&&!M.has(`complete:${e.id}`)&&(M.add(`complete:${e.id}`),$(n.onComplete,structuredClone(e))),X()}function z(e){return G=G.catch(()=>{}).then(()=>ie(e)),G}let re=n.client.subscribe(e=>{z(e).catch(k)});function W(){return q||(i?Promise.resolve():n.client.view&&!["running","waiting"].includes(n.client.view.status)?(B(),Promise.resolve()):(q=N(()=>n.client.submit({operation:"close",...U()}),!0).then(()=>{n.client.view?.status==="closed"&&B()}).finally(()=>{q=null}),q))}function B(){i||(i=!0,F&&clearTimeout(F),re(),C?.destroy(),t?.destroy(),m.close(),m.remove(),r.remove(),v instanceof HTMLElement&&v.isConnected&&v.focus(),$(n.onDismiss,a?structuredClone(a):null))}D.onclick=()=>{N(()=>n.client.submit({operation:"back",...U()}))},S.onclick=()=>{W()},E.onclick=()=>{N(()=>n.client.retry())},m.addEventListener("cancel",e=>{e.preventDefault(),W()});try{let e=await n.client.get();await z(n.client.view??e.run)}catch(e){throw B(),e}return{destroy:B,refresh:()=>N(()=>n.client.get())}}export{fe as showFunnelRun};
|