@tinkerlandai/indiana-sdk 0.4.0 → 0.5.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +6 -6
  3. package/README.zh-CN.md +4 -4
  4. package/THIRD_PARTY_NOTICES.md +0 -1
  5. package/dist/ai-usage-BzydP8eN.d.ts +11085 -0
  6. package/dist/chunk-3OSMEG44.js +17 -0
  7. package/dist/chunk-GA6X57BO.js +1 -0
  8. package/dist/chunk-GTBD4BJ4.js +11 -0
  9. package/dist/{chunk-2UFPTDCV.js → chunk-QUW4UOKZ.js} +1 -1
  10. package/dist/chunk-RMFH5TWV.js +1 -0
  11. package/dist/chunk-YNUVRZRQ.js +1 -0
  12. package/dist/funnel-runtime-host-RZRB2CY6.js +1 -0
  13. package/dist/{funnel-runtime-start-B93fV5gJ.d.ts → funnel-runtime-start-JHA9ES24.d.ts} +63 -29
  14. package/dist/index.d.ts +108 -53
  15. package/dist/index.js +1 -1
  16. package/dist/native-shell.js +1 -1
  17. package/dist/openrouter.d.ts +3 -2
  18. package/dist/openrouter.js +1 -1
  19. package/dist/page.d.ts +12 -12
  20. package/dist/page.js +1 -1
  21. package/dist/{paywall-M5CIDUIT.js → paywall-MYBEOVTQ.js} +1 -1
  22. package/dist/popup.d.ts +254 -1
  23. package/dist/popup.js +6 -6
  24. package/dist/{screen-Keau_Qa2.d.ts → screen-16d-xADb.d.ts} +354 -463
  25. package/dist/server.d.ts +4 -3
  26. package/dist/server.js +1 -1
  27. package/dist/src-E2GXK6WA.js +1 -0
  28. package/dist/visual-editor-agent-FDCV3BXP.js +1 -0
  29. package/dist/visual.js +1 -1
  30. package/package.json +3 -2
  31. package/dist/ai-usage-D9xVKhvu.d.ts +0 -9953
  32. package/dist/chunk-LFNFVYC2.js +0 -1
  33. package/dist/chunk-PVJKOUNE.js +0 -11
  34. package/dist/chunk-TZ6REIUE.js +0 -17
  35. package/dist/chunk-VTSEZ4GI.js +0 -1
  36. package/dist/funnel-runtime-host-4PQY2MFC.js +0 -1
  37. package/dist/src-XEDJAKEB.js +0 -1
  38. package/dist/visual-editor-agent-PYMKMPY3.js +0 -1
@@ -1,9 +1,10 @@
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-D9xVKhvu.js';
3
+ import { c as createAiPricing, F as FoundationApi, a as AiUsageContext, b as AiTokenUsage, d as AiTokenQuote } from './ai-usage-BzydP8eN.js';
4
4
  import '@ai-sdk/provider';
5
- import './screen-Keau_Qa2.js';
5
+ import './screen-16d-xADb.js';
6
6
  import 'zod';
7
+ import 'zod/v4';
7
8
 
8
9
  type OpenRouterUsageRecord = {
9
10
  context: AiUsageContext;
@@ -1 +1 @@
1
- import{a as i}from"./chunk-LFNFVYC2.js";import"./chunk-PVJKOUNE.js";import"./chunk-TZ6REIUE.js";import{z as R}from"zod";var c=R.number().int().min(0).max(1e9);function k(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):k(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};
1
+ import"./chunk-RMFH5TWV.js";import{a as i}from"./chunk-YNUVRZRQ.js";import"./chunk-GTBD4BJ4.js";import"./chunk-3OSMEG44.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
@@ -7,12 +7,13 @@ declare const pageExperimentPayloadSchema: z.ZodObject<{
7
7
  trackExposures: z.ZodBoolean;
8
8
  generation: z.ZodString;
9
9
  experiments: z.ZodArray<z.ZodObject<{
10
+ name: z.ZodOptional<z.ZodString>;
11
+ coverage: z.ZodOptional<z.ZodNumber>;
12
+ key: z.ZodString;
10
13
  condition: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
11
14
  seed: z.ZodOptional<z.ZodString>;
12
15
  hashVersion: z.ZodOptional<z.ZodLiteral<2>>;
13
16
  ranges: z.ZodOptional<z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>>;
14
- key: z.ZodString;
15
- name: z.ZodOptional<z.ZodString>;
16
17
  force: z.ZodOptional<z.ZodNumber>;
17
18
  urlPatterns: z.ZodOptional<z.ZodArray<z.ZodObject<{
18
19
  include: z.ZodBoolean;
@@ -31,22 +32,21 @@ declare const pageExperimentPayloadSchema: z.ZodObject<{
31
32
  hashVersion: z.ZodLiteral<2>;
32
33
  ranges: z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
33
34
  }, z.core.$strict>>>;
34
- coverage: z.ZodOptional<z.ZodNumber>;
35
- meta: z.ZodOptional<z.ZodArray<z.ZodObject<{
36
- key: z.ZodOptional<z.ZodString>;
37
- name: z.ZodOptional<z.ZodString>;
38
- passthrough: z.ZodOptional<z.ZodBoolean>;
39
- }, z.core.$strict>>>;
40
- fallbackAttribute: z.ZodOptional<z.ZodString>;
41
- disableStickyBucketing: z.ZodOptional<z.ZodBoolean>;
42
- bucketVersion: z.ZodOptional<z.ZodNumber>;
43
- minBucketVersion: z.ZodOptional<z.ZodNumber>;
44
35
  parentConditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
45
36
  id: z.ZodString;
46
37
  condition: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
47
38
  gate: z.ZodOptional<z.ZodBoolean>;
48
39
  }, z.core.$strict>>>;
49
40
  weights: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
41
+ fallbackAttribute: z.ZodOptional<z.ZodString>;
42
+ disableStickyBucketing: z.ZodOptional<z.ZodBoolean>;
43
+ bucketVersion: z.ZodOptional<z.ZodNumber>;
44
+ minBucketVersion: z.ZodOptional<z.ZodNumber>;
45
+ meta: z.ZodOptional<z.ZodArray<z.ZodObject<{
46
+ key: z.ZodOptional<z.ZodString>;
47
+ name: z.ZodOptional<z.ZodString>;
48
+ passthrough: z.ZodOptional<z.ZodBoolean>;
49
+ }, z.core.$strict>>>;
50
50
  changeId: z.ZodString;
51
51
  variations: z.ZodArray<z.ZodObject<{
52
52
  urlRedirect: z.ZodString;
package/dist/page.js CHANGED
@@ -1 +1 @@
1
- import{g as a,h as b,i as c,j as d}from"./chunk-2UFPTDCV.js";import"./chunk-TZ6REIUE.js";export{d as createPageExperiments,a as mergeQueryStrings,b as pageAttributes,c as readPayload};
1
+ import{g as a,h as b,i as c,j as d}from"./chunk-QUW4UOKZ.js";import"./chunk-3OSMEG44.js";export{d as createPageExperiments,a as mergeQueryStrings,b as pageAttributes,c as readPayload};
@@ -1 +1 @@
1
- import{a as H}from"./chunk-6X42DWOM.js";import{a as m}from"./chunk-LFNFVYC2.js";import{$l as B,Ie as U,hf as V,y as M}from"./chunk-PVJKOUNE.js";import"./chunk-TZ6REIUE.js";async function F(y,t,d){if(t.status!=="complete")throw new m("INVALID_RESPONSE","A verified completed purchase is required");if(await d.onComplete?.(t),!y||!d.check)return;let i=U.parse(await d.check());if(i.internal_feature_id!==y.internal_feature_id||i.quantity!==y.quantity)throw new m("INVALID_RESPONSE","The access requirement changed");i.allowed&&await d.onAccessGranted?.(i)}async function re(y,t){let d=t.check?U.parse(await t.check()):null;if(d?.allowed)return await t.onAccessGranted?.(d),{check:d,host:null};let i=await t.start(),p=i.view;if(!p)throw new m("INVALID_RESPONSE","Paywall presentation is missing");let{mountScreenPreview:j}=await import("./popup.js"),n=y.ownerDocument,R=new AbortController,v=n.createElement("section"),$=n.createElement("div"),I=n.createElement("div"),P=n.createElement("p"),E=n.createElement("button"),D=n.createElement("button"),f=n.createElement("dialog"),L=n.activeElement,w=p.document.screen.strings.defaultLocale.startsWith("zh");v.dataset.indianaPaywall="",v.setAttribute("aria-label",p.document.name),v.style.cssText="width:100%;box-sizing:border-box;background:#fff;color:#172033;font:14px/1.5 system-ui,sans-serif",I.style.cssText="display:flex;gap:12px;padding:12px 20px;align-items:center;flex-wrap:wrap",P.setAttribute("role","status"),D.textContent=w?"\u5173\u95ED":"Close",E.textContent=w?"\u91CD\u8BD5":"Retry",E.hidden=!0,I.append(P,E,D),v.append($,I);let N=p.document.presentation,g,u=!1,_=!1,l=null,T=!1,a=null,x=null,S=e=>{P.textContent=e instanceof Error?e.message:w?"\u8BF7\u6C42\u5931\u8D25":"Request failed",H(t.onError,e),E.hidden=a===null};async function b(e){if(!(_||u)){_=!0,E.hidden=!0,P.textContent="";try{await e()}catch(o){u||S(o)}finally{_=!1}}}async function W(e){await F(d,e,t)}async function O(e){if(u)return;if(P.textContent=e.status,e.status==="complete"){a=null,await W(e);return}if(e.status!=="pending"){a=null,l=null;return}let o=Date.now()+6e5,c=2e3;for(;!u&&Date.now()<o;){if(await new Promise(h=>{let A=()=>{clearTimeout(C),h()},C=setTimeout(()=>{R.signal.removeEventListener("abort",A),h()},c);R.signal.addEventListener("abort",A,{once:!0})}),u)return;let r=await i.read();if(r.status!=="pending"){await O(r);return}c=Math.min(c*1.5,3e4)}a=async()=>O(await i.read()),E.hidden=!1}async function z(){x?.remove(),x=null,a=z;let e=await i.confirm();if(e.status==="pending"){if(e.checkoutUrl)t.onCheckoutUrl?await t.onCheckoutUrl(e.checkoutUrl):n.defaultView?.location.assign(e.checkoutUrl);else if(e.execution||e.nativePurchase){if(!t.onPurchase)throw new m("PURCHASE_HANDLER_REQUIRED","Provide the merchant or native purchase handler");await t.onPurchase({operation:e,signal:R.signal})}}a=async()=>O(await i.read()),await O(e)}function J(e){x?.remove();let o=n.createElement("div"),c=n.createElement("button"),r=n.createElement("button"),h=n.createElement("p");h.textContent=e.lines.map(s=>s.productName).join(", ")+" \xB7 "+M(e.charge?.totalMinor??e.catalogAmountMinor-(e.discount?.amountMinor??0),e.currency),c.textContent=w?"\u786E\u8BA4\u8D2D\u4E70":"Confirm purchase",r.textContent=w?"\u53D6\u6D88":"Cancel",c.onclick=()=>{b(z)};let A=async()=>{await i.cancel(),!u&&(l=null,a=null,o.remove(),x=null)};r.onclick=()=>{a=A,b(A)};let C=n.createElement("div");for(let s of e.lines){let q=n.createElement("p");if(q.textContent=`${s.productName} \xB7 ${M(s.catalogAmountMinor,e.currency)}${B(s.interval,w?"zh-CN":"en",s.intervalCount??1)}`,C.append(q),s.trial){let G=n.createElement("p");G.textContent=w?`\u8BD5\u7528 ${s.trial.days} \u5929\uFF1B${s.trial.cardRequired?"\u9700\u8981\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F":"\u65E0\u9700\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F"}`:`Trial days: ${s.trial.days}; ${s.trial.cardRequired?"a payment method is required":"no payment method is required"}`,C.append(G)}}if(!e.charge){let s=n.createElement("p");s.textContent=w?"\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.",C.append(s)}o.append(h,C,c,r),I.prepend(o),x=o,a=null}async function Q(){if(!l)return;if(a=Q,!T){let o=i.view,c=o?.document.buttons[l.actionId],r=o&&c?.type==="checkout"?V(c.product,l.selection,o.capabilities):null;if(!r)throw new m("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area");let h=await t.resolveOfferId?.({actionId:l.actionId,productVersionId:r});if(u)return;h!==void 0&&(l.offerId=h),T=!0}let e=await i.preview(l);u||J(e)}function k(e="destroy"){u||(u=!0,R.abort(),g?.destroy(),i.destroy(),f.open&&f.close(),f.remove(),v.remove(),L instanceof HTMLElement&&L.isConnected&&L.focus(),e==="dismiss"&&H(t.onDismiss))}D.onclick=()=>k("dismiss"),f.addEventListener("cancel",e=>{e.preventDefault(),k("dismiss")}),E.onclick=()=>{a&&b(a)};try{if(N.type==="inline")y.append(v);else{let e={sm:420,md:640,lg:900};f.style.cssText=`padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto;width:${"size"in N?e[N.size]+"px":"100vw"}`,f.setAttribute("aria-label",p.document.name),f.append(v),y.append(f),f.showModal()}g=j($,{mode:"live",rendererUrl:i.webViewUrl,title:p.document.name,onAction(e,o={}){let c=i.view,r=c?.document.buttons[e];if(r){if(r.type==="close"){b(async()=>{await t.onAction?.(e),k(t.onAction?"action":"dismiss")});return}if(r.type==="action"){a=async()=>{if(r.action.type==="event"){if(!t.onEvent)throw new m("EVENT_HANDLER_REQUIRED","Provide the event handler");await t.onEvent(r.action.event)}else t.onOpenUrl?await t.onOpenUrl(r.action.url):n.defaultView?.location.assign(r.action.url);await t.onAction?.(e),a=null},b(a);return}if(!c||!V(r.product,o,c.capabilities)){S(new m("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));return}if(l&&l.actionId!==e){S(new m("COMMAND_PENDING","Finish the current purchase"));return}l||(l={requestId:crypto.randomUUID(),actionId:e,selection:o},T=!1),b(Q)}},onEscape:()=>k("dismiss"),onError:e=>S(new Error(e))}),g.update(p.document.screen,p.document.screen.strings.defaultLocale,{capabilities:p.capabilities,serverInput:{bindings:[],answers:{}}}),await g.ready}catch(e){throw k(),e}return{check:d,host:{destroy:k,refresh:async()=>{let e=await i.refresh();return u||g?.updateCapabilities(e.capabilities),e}}}}export{re as showPaywall};
1
+ import{a as H}from"./chunk-6X42DWOM.js";import{a as m}from"./chunk-YNUVRZRQ.js";import{Te as V,gm as B,se as U,y as M}from"./chunk-GTBD4BJ4.js";import"./chunk-3OSMEG44.js";async function F(y,t,d){if(t.status!=="complete")throw new m("INVALID_RESPONSE","A verified completed purchase is required");if(await d.onComplete?.(t),!y||!d.check)return;let i=U.parse(await d.check());if(i.internal_feature_id!==y.internal_feature_id||i.quantity!==y.quantity)throw new m("INVALID_RESPONSE","The access requirement changed");i.allowed&&await d.onAccessGranted?.(i)}async function re(y,t){let d=t.check?U.parse(await t.check()):null;if(d?.allowed)return await t.onAccessGranted?.(d),{check:d,host:null};let i=await t.start(),p=i.view;if(!p)throw new m("INVALID_RESPONSE","Paywall presentation is missing");let{mountScreenPreview:j}=await import("./popup.js"),n=y.ownerDocument,R=new AbortController,v=n.createElement("section"),$=n.createElement("div"),I=n.createElement("div"),P=n.createElement("p"),E=n.createElement("button"),D=n.createElement("button"),f=n.createElement("dialog"),L=n.activeElement,w=p.document.screen.strings.defaultLocale.startsWith("zh");v.dataset.indianaPaywall="",v.setAttribute("aria-label",p.document.name),v.style.cssText="width:100%;box-sizing:border-box;background:#fff;color:#172033;font:14px/1.5 system-ui,sans-serif",I.style.cssText="display:flex;gap:12px;padding:12px 20px;align-items:center;flex-wrap:wrap",P.setAttribute("role","status"),D.textContent=w?"\u5173\u95ED":"Close",E.textContent=w?"\u91CD\u8BD5":"Retry",E.hidden=!0,I.append(P,E,D),v.append($,I);let N=p.document.presentation,g,u=!1,_=!1,l=null,T=!1,a=null,x=null,S=e=>{P.textContent=e instanceof Error?e.message:w?"\u8BF7\u6C42\u5931\u8D25":"Request failed",H(t.onError,e),E.hidden=a===null};async function b(e){if(!(_||u)){_=!0,E.hidden=!0,P.textContent="";try{await e()}catch(o){u||S(o)}finally{_=!1}}}async function W(e){await F(d,e,t)}async function O(e){if(u)return;if(P.textContent=e.status,e.status==="complete"){a=null,await W(e);return}if(e.status!=="pending"){a=null,l=null;return}let o=Date.now()+6e5,c=2e3;for(;!u&&Date.now()<o;){if(await new Promise(h=>{let A=()=>{clearTimeout(C),h()},C=setTimeout(()=>{R.signal.removeEventListener("abort",A),h()},c);R.signal.addEventListener("abort",A,{once:!0})}),u)return;let r=await i.read();if(r.status!=="pending"){await O(r);return}c=Math.min(c*1.5,3e4)}a=async()=>O(await i.read()),E.hidden=!1}async function z(){x?.remove(),x=null,a=z;let e=await i.confirm();if(e.status==="pending"){if(e.checkoutUrl)t.onCheckoutUrl?await t.onCheckoutUrl(e.checkoutUrl):n.defaultView?.location.assign(e.checkoutUrl);else if(e.execution||e.nativePurchase){if(!t.onPurchase)throw new m("PURCHASE_HANDLER_REQUIRED","Provide the merchant or native purchase handler");await t.onPurchase({operation:e,signal:R.signal})}}a=async()=>O(await i.read()),await O(e)}function J(e){x?.remove();let o=n.createElement("div"),c=n.createElement("button"),r=n.createElement("button"),h=n.createElement("p");h.textContent=e.lines.map(s=>s.productName).join(", ")+" \xB7 "+M(e.charge?.totalMinor??e.catalogAmountMinor-(e.discount?.amountMinor??0),e.currency),c.textContent=w?"\u786E\u8BA4\u8D2D\u4E70":"Confirm purchase",r.textContent=w?"\u53D6\u6D88":"Cancel",c.onclick=()=>{b(z)};let A=async()=>{await i.cancel(),!u&&(l=null,a=null,o.remove(),x=null)};r.onclick=()=>{a=A,b(A)};let C=n.createElement("div");for(let s of e.lines){let q=n.createElement("p");if(q.textContent=`${s.productName} \xB7 ${M(s.catalogAmountMinor,e.currency)}${B(s.interval,w?"zh-CN":"en",s.intervalCount??1)}`,C.append(q),s.trial){let G=n.createElement("p");G.textContent=w?`\u8BD5\u7528 ${s.trial.days} \u5929\uFF1B${s.trial.cardRequired?"\u9700\u8981\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F":"\u65E0\u9700\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F"}`:`Trial days: ${s.trial.days}; ${s.trial.cardRequired?"a payment method is required":"no payment method is required"}`,C.append(G)}}if(!e.charge){let s=n.createElement("p");s.textContent=w?"\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.",C.append(s)}o.append(h,C,c,r),I.prepend(o),x=o,a=null}async function Q(){if(!l)return;if(a=Q,!T){let o=i.view,c=o?.document.buttons[l.actionId],r=o&&c?.type==="checkout"?V(c.product,l.selection,o.capabilities):null;if(!r)throw new m("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area");let h=await t.resolveOfferId?.({actionId:l.actionId,productVersionId:r});if(u)return;h!==void 0&&(l.offerId=h),T=!0}let e=await i.preview(l);u||J(e)}function k(e="destroy"){u||(u=!0,R.abort(),g?.destroy(),i.destroy(),f.open&&f.close(),f.remove(),v.remove(),L instanceof HTMLElement&&L.isConnected&&L.focus(),e==="dismiss"&&H(t.onDismiss))}D.onclick=()=>k("dismiss"),f.addEventListener("cancel",e=>{e.preventDefault(),k("dismiss")}),E.onclick=()=>{a&&b(a)};try{if(N.type==="inline")y.append(v);else{let e={sm:420,md:640,lg:900};f.style.cssText=`padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto;width:${"size"in N?e[N.size]+"px":"100vw"}`,f.setAttribute("aria-label",p.document.name),f.append(v),y.append(f),f.showModal()}g=j($,{mode:"live",rendererUrl:i.webViewUrl,title:p.document.name,onAction(e,o={}){let c=i.view,r=c?.document.buttons[e];if(r){if(r.type==="close"){b(async()=>{await t.onAction?.(e),k(t.onAction?"action":"dismiss")});return}if(r.type==="action"){a=async()=>{if(r.action.type==="event"){if(!t.onEvent)throw new m("EVENT_HANDLER_REQUIRED","Provide the event handler");await t.onEvent(r.action.event)}else t.onOpenUrl?await t.onOpenUrl(r.action.url):n.defaultView?.location.assign(r.action.url);await t.onAction?.(e),a=null},b(a);return}if(!c||!V(r.product,o,c.capabilities)){S(new m("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));return}if(l&&l.actionId!==e){S(new m("COMMAND_PENDING","Finish the current purchase"));return}l||(l={requestId:crypto.randomUUID(),actionId:e,selection:o},T=!1),b(Q)}},onEscape:()=>k("dismiss"),onError:e=>S(new Error(e))}),g.update(p.document.screen,p.document.screen.strings.defaultLocale,{capabilities:p.capabilities,serverInput:{bindings:[],answers:{}}}),await g.ready}catch(e){throw k(),e}return{check:d,host:{destroy:k,refresh:async()=>{let e=await i.refresh();return u||g?.updateCapabilities(e.capabilities),e}}}}export{re as showPaywall};
package/dist/popup.d.ts CHANGED
@@ -1,8 +1,261 @@
1
- import { a as ScreenAction, b as ScreenNode, c as ScreenDocument, d as SurfaceData } from './screen-Keau_Qa2.js';
1
+ import { a as ScreenAction, b as ScreenNode, c as ScreenDocument } from './screen-16d-xADb.js';
2
2
  import { O as Offer, b as OfferUnavailableReason, c as CustomerPageData, a as CustomerDataIntent } from './customer-page-aZb5Twue.js';
3
3
  import { z } from 'zod';
4
4
  import { WindowLike } from 'dompurify';
5
5
 
6
+ declare const surfaceDataSchema: z.ZodObject<{
7
+ paywall: z.ZodOptional<z.ZodObject<{
8
+ internal_feature_id: z.ZodString;
9
+ name: z.ZodString;
10
+ kind: z.ZodEnum<{
11
+ access: "access";
12
+ metered: "metered";
13
+ credit: "credit";
14
+ }>;
15
+ quantity: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
16
+ allowed: z.ZodBoolean;
17
+ reason: z.ZodNullable<z.ZodEnum<{
18
+ unavailable: "unavailable";
19
+ insufficient_balance: "insufficient_balance";
20
+ limit_exceeded: "limit_exceeded";
21
+ awaiting_topup: "awaiting_topup";
22
+ authorization_required: "authorization_required";
23
+ payment_blocked: "payment_blocked";
24
+ cash_budget_exceeded: "cash_budget_exceeded";
25
+ not_entitled: "not_entitled";
26
+ capacity_exceeded: "capacity_exceeded";
27
+ authentication_required: "authentication_required";
28
+ }>>;
29
+ preview: z.ZodNullable<z.ZodObject<{
30
+ scenario: z.ZodEnum<{
31
+ feature_flag: "feature_flag";
32
+ usage_limit: "usage_limit";
33
+ }>;
34
+ candidates: z.ZodArray<z.ZodObject<{
35
+ productId: z.ZodString;
36
+ productVersionId: z.ZodString;
37
+ name: z.ZodString;
38
+ action: z.ZodEnum<{
39
+ purchase: "purchase";
40
+ upgrade: "upgrade";
41
+ addon: "addon";
42
+ topup: "topup";
43
+ }>;
44
+ membershipId: z.ZodNullable<z.ZodString>;
45
+ currency: z.ZodEnum<{
46
+ USD: "USD";
47
+ EUR: "EUR";
48
+ CNY: "CNY";
49
+ GBP: "GBP";
50
+ JPY: "JPY";
51
+ CAD: "CAD";
52
+ AUD: "AUD";
53
+ NZD: "NZD";
54
+ CHF: "CHF";
55
+ HKD: "HKD";
56
+ SGD: "SGD";
57
+ KRW: "KRW";
58
+ INR: "INR";
59
+ BRL: "BRL";
60
+ MXN: "MXN";
61
+ TWD: "TWD";
62
+ THB: "THB";
63
+ IDR: "IDR";
64
+ MYR: "MYR";
65
+ PHP: "PHP";
66
+ VND: "VND";
67
+ ZAR: "ZAR";
68
+ AED: "AED";
69
+ SAR: "SAR";
70
+ SEK: "SEK";
71
+ NOK: "NOK";
72
+ DKK: "DKK";
73
+ PLN: "PLN";
74
+ CZK: "CZK";
75
+ HUF: "HUF";
76
+ ILS: "ILS";
77
+ TRY: "TRY";
78
+ RON: "RON";
79
+ }>;
80
+ amountMinor: z.ZodString;
81
+ interval: z.ZodEnum<{
82
+ week: "week";
83
+ month: "month";
84
+ year: "year";
85
+ free: "free";
86
+ one_time: "one_time";
87
+ }>;
88
+ intervalCount: z.ZodNumber;
89
+ }, z.core.$strict>>;
90
+ }, z.core.$strict>>;
91
+ }, z.core.$strict>>;
92
+ nodes: z.ZodRecord<z.ZodString, z.ZodObject<{
93
+ base: z.ZodObject<{
94
+ text: z.ZodOptional<z.ZodString>;
95
+ label: z.ZodOptional<z.ZodString>;
96
+ alt: z.ZodOptional<z.ZodString>;
97
+ html: z.ZodOptional<z.ZodString>;
98
+ price: z.ZodOptional<z.ZodObject<{
99
+ current: z.ZodString;
100
+ original: z.ZodNullable<z.ZodString>;
101
+ period: z.ZodString;
102
+ }, z.core.$strip>>;
103
+ code: z.ZodOptional<z.ZodString>;
104
+ countdownAt: z.ZodOptional<z.ZodISODateTime>;
105
+ planId: z.ZodOptional<z.ZodString>;
106
+ planVersionId: z.ZodOptional<z.ZodString>;
107
+ currency: z.ZodOptional<z.ZodEnum<{
108
+ USD: "USD";
109
+ EUR: "EUR";
110
+ CNY: "CNY";
111
+ GBP: "GBP";
112
+ JPY: "JPY";
113
+ CAD: "CAD";
114
+ AUD: "AUD";
115
+ NZD: "NZD";
116
+ CHF: "CHF";
117
+ HKD: "HKD";
118
+ SGD: "SGD";
119
+ KRW: "KRW";
120
+ INR: "INR";
121
+ BRL: "BRL";
122
+ MXN: "MXN";
123
+ TWD: "TWD";
124
+ THB: "THB";
125
+ IDR: "IDR";
126
+ MYR: "MYR";
127
+ PHP: "PHP";
128
+ VND: "VND";
129
+ ZAR: "ZAR";
130
+ AED: "AED";
131
+ SAR: "SAR";
132
+ SEK: "SEK";
133
+ NOK: "NOK";
134
+ DKK: "DKK";
135
+ PLN: "PLN";
136
+ CZK: "CZK";
137
+ HUF: "HUF";
138
+ ILS: "ILS";
139
+ TRY: "TRY";
140
+ RON: "RON";
141
+ }>>;
142
+ couponId: z.ZodOptional<z.ZodUUID>;
143
+ offerId: z.ZodOptional<z.ZodUUID>;
144
+ unavailable: z.ZodOptional<z.ZodBoolean>;
145
+ unavailableReason: z.ZodOptional<z.ZodString>;
146
+ missing: z.ZodOptional<z.ZodArray<z.ZodString>>;
147
+ }, z.core.$strict>;
148
+ picker: z.ZodOptional<z.ZodString>;
149
+ byPlan: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
150
+ text: z.ZodOptional<z.ZodString>;
151
+ label: z.ZodOptional<z.ZodString>;
152
+ alt: z.ZodOptional<z.ZodString>;
153
+ html: z.ZodOptional<z.ZodString>;
154
+ price: z.ZodOptional<z.ZodObject<{
155
+ current: z.ZodString;
156
+ original: z.ZodNullable<z.ZodString>;
157
+ period: z.ZodString;
158
+ }, z.core.$strip>>;
159
+ code: z.ZodOptional<z.ZodString>;
160
+ countdownAt: z.ZodOptional<z.ZodISODateTime>;
161
+ planId: z.ZodOptional<z.ZodString>;
162
+ planVersionId: z.ZodOptional<z.ZodString>;
163
+ currency: z.ZodOptional<z.ZodEnum<{
164
+ USD: "USD";
165
+ EUR: "EUR";
166
+ CNY: "CNY";
167
+ GBP: "GBP";
168
+ JPY: "JPY";
169
+ CAD: "CAD";
170
+ AUD: "AUD";
171
+ NZD: "NZD";
172
+ CHF: "CHF";
173
+ HKD: "HKD";
174
+ SGD: "SGD";
175
+ KRW: "KRW";
176
+ INR: "INR";
177
+ BRL: "BRL";
178
+ MXN: "MXN";
179
+ TWD: "TWD";
180
+ THB: "THB";
181
+ IDR: "IDR";
182
+ MYR: "MYR";
183
+ PHP: "PHP";
184
+ VND: "VND";
185
+ ZAR: "ZAR";
186
+ AED: "AED";
187
+ SAR: "SAR";
188
+ SEK: "SEK";
189
+ NOK: "NOK";
190
+ DKK: "DKK";
191
+ PLN: "PLN";
192
+ CZK: "CZK";
193
+ HUF: "HUF";
194
+ ILS: "ILS";
195
+ TRY: "TRY";
196
+ RON: "RON";
197
+ }>>;
198
+ couponId: z.ZodOptional<z.ZodUUID>;
199
+ offerId: z.ZodOptional<z.ZodUUID>;
200
+ unavailable: z.ZodOptional<z.ZodBoolean>;
201
+ unavailableReason: z.ZodOptional<z.ZodString>;
202
+ missing: z.ZodOptional<z.ZodArray<z.ZodString>>;
203
+ }, z.core.$strict>>>;
204
+ }, z.core.$strict>>;
205
+ plans: z.ZodRecord<z.ZodString, z.ZodObject<{
206
+ id: z.ZodString;
207
+ versionId: z.ZodString;
208
+ available: z.ZodBoolean;
209
+ name: z.ZodString;
210
+ price: z.ZodString;
211
+ period: z.ZodString;
212
+ currency: z.ZodOptional<z.ZodEnum<{
213
+ USD: "USD";
214
+ EUR: "EUR";
215
+ CNY: "CNY";
216
+ GBP: "GBP";
217
+ JPY: "JPY";
218
+ CAD: "CAD";
219
+ AUD: "AUD";
220
+ NZD: "NZD";
221
+ CHF: "CHF";
222
+ HKD: "HKD";
223
+ SGD: "SGD";
224
+ KRW: "KRW";
225
+ INR: "INR";
226
+ BRL: "BRL";
227
+ MXN: "MXN";
228
+ TWD: "TWD";
229
+ THB: "THB";
230
+ IDR: "IDR";
231
+ MYR: "MYR";
232
+ PHP: "PHP";
233
+ VND: "VND";
234
+ ZAR: "ZAR";
235
+ AED: "AED";
236
+ SAR: "SAR";
237
+ SEK: "SEK";
238
+ NOK: "NOK";
239
+ DKK: "DKK";
240
+ PLN: "PLN";
241
+ CZK: "CZK";
242
+ HUF: "HUF";
243
+ ILS: "ILS";
244
+ TRY: "TRY";
245
+ RON: "RON";
246
+ }>>;
247
+ }, z.core.$strict>>;
248
+ pickers: z.ZodRecord<z.ZodString, z.ZodObject<{
249
+ options: z.ZodArray<z.ZodString>;
250
+ selected: z.ZodNullable<z.ZodString>;
251
+ }, z.core.$strict>>;
252
+ diagnostics: z.ZodArray<z.ZodObject<{
253
+ nodeId: z.ZodString;
254
+ message: z.ZodString;
255
+ }, z.core.$strict>>;
256
+ }, z.core.$strict>;
257
+ type SurfaceData = z.infer<typeof surfaceDataSchema>;
258
+
6
259
  type PopupEvent = {
7
260
  type: "shown";
8
261
  } | {