@tinkerlandai/indiana-sdk 0.9.2 → 0.10.1

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 (64) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +50 -5
  3. package/README.zh-CN.md +30 -5
  4. package/dist/{ai-usage-DMNKvCiq.d.ts → ai-usage-Cn7dhvFw.d.ts} +5 -5
  5. package/dist/{api--Zf0gxfj.d.ts → api-DC44FaTV.d.ts} +6346 -749
  6. package/dist/chunk-2Y4G5364.js +6 -0
  7. package/dist/chunk-6ZZUNGNE.js +1 -0
  8. package/dist/chunk-ABNSU3ZG.js +4 -0
  9. package/dist/chunk-ACF2FBUB.js +1 -0
  10. package/dist/{chunk-65TBYVCS.js → chunk-AHXYGGAA.js} +1 -1
  11. package/dist/chunk-BOCKPUCM.js +2 -0
  12. package/dist/chunk-CCPNMQHZ.js +1 -0
  13. package/dist/chunk-CLXORAOK.js +1 -0
  14. package/dist/chunk-EDQCH2QS.js +1 -0
  15. package/dist/chunk-IWWKVNEX.js +1 -0
  16. package/dist/chunk-QUWPPZHH.js +1 -0
  17. package/dist/chunk-SBPTOOYB.js +1 -0
  18. package/dist/chunk-WYZI3TNB.js +1 -0
  19. package/dist/chunk-X6BCUINI.js +173 -0
  20. package/dist/chunk-Y46ALAKP.js +1 -0
  21. package/dist/{configuration-sync-E98CqVwh.d.ts → configuration-sync-CXe9Zcng.d.ts} +74 -21
  22. package/dist/content-ZRWZ26PF.js +1 -0
  23. package/dist/coupon-fA1QujHt.d.ts +184 -0
  24. package/dist/{customer-page-9B97Qdt_.d.ts → customer-page-km5f1PJZ.d.ts} +86 -182
  25. package/dist/{funnel-local-client-BjPwXlQb.d.ts → funnel-local-client-BQsdOjQ7.d.ts} +19985 -2451
  26. package/dist/funnel-node-evaluation-P5B4fPfJ.d.ts +2054 -0
  27. package/dist/funnel-resource-client-Zof1WLgA.d.ts +14525 -0
  28. package/dist/funnel-runtime-host-N7TX3LWI.js +1 -0
  29. package/dist/index.d.ts +13905 -13996
  30. package/dist/index.js +1 -1
  31. package/dist/native-shell.js +1 -1
  32. package/dist/openrouter.d.ts +3 -3
  33. package/dist/openrouter.js +1 -1
  34. package/dist/page.d.ts +4 -4
  35. package/dist/page.js +1 -1
  36. package/dist/paywall-DR65VN2G.js +1 -0
  37. package/dist/popup.d.ts +7 -5
  38. package/dist/popup.js +1 -1
  39. package/dist/react-native.d.ts +36432 -174
  40. package/dist/react-native.js +1 -1
  41. package/dist/{screen-BITZ11jn.d.ts → screen-D81zCpfi.d.ts} +159 -6
  42. package/dist/{screen-renderer-A6VYE2QL.js → screen-renderer-ZSAR7LPS.js} +1 -1
  43. package/dist/server.d.ts +2924 -500
  44. package/dist/server.js +1 -1
  45. package/dist/visual-dom-OFB7BFFB.js +1 -0
  46. package/dist/visual.d.ts +2 -2
  47. package/dist/visual.js +1 -1
  48. package/package.json +1 -1
  49. package/dist/chunk-5O667MKA.js +0 -1
  50. package/dist/chunk-67A7I6MB.js +0 -1
  51. package/dist/chunk-CCQHYQ4P.js +0 -1
  52. package/dist/chunk-CPLLMISZ.js +0 -1
  53. package/dist/chunk-G23YNWWI.js +0 -1
  54. package/dist/chunk-L7LKE3MG.js +0 -173
  55. package/dist/chunk-NH2PTTNK.js +0 -2
  56. package/dist/chunk-PK5HYUHD.js +0 -1
  57. package/dist/chunk-SEW4YVR7.js +0 -1
  58. package/dist/chunk-UYSOTMY3.js +0 -1
  59. package/dist/chunk-WSVH6IQA.js +0 -1
  60. package/dist/chunk-YZSQDZXW.js +0 -4
  61. package/dist/content-3LOJVYQO.js +0 -1
  62. package/dist/errors-0TSUIbUi.d.ts +0 -115
  63. package/dist/funnel-runtime-host-NYHKQT6T.js +0 -1
  64. package/dist/paywall-ISCYOGPZ.js +0 -1
@@ -1,8 +1,8 @@
1
1
  import { OpenRouter } from '@openrouter/sdk';
2
2
  import { ChatUsage } from '@openrouter/sdk/models';
3
- import { F as FoundationApi } from './api--Zf0gxfj.js';
4
- import { c as createAiPricing, A as AiUsageContext, a as AiTokenUsage, b as AiTokenQuote } from './ai-usage-DMNKvCiq.js';
5
- import './screen-BITZ11jn.js';
3
+ import { F as FoundationApi } from './api-DC44FaTV.js';
4
+ import { c as createAiPricing, A as AiUsageContext, a as AiTokenUsage, b as AiTokenQuote } from './ai-usage-Cn7dhvFw.js';
5
+ import './screen-D81zCpfi.js';
6
6
  import 'zod';
7
7
  import 'zod/v4';
8
8
  import '@ai-sdk/provider';
@@ -1 +1 @@
1
- import"./chunk-67A7I6MB.js";import"./chunk-PK5HYUHD.js";import{fa as i}from"./chunk-G23YNWWI.js";import"./chunk-G56XGVMS.js";import"./chunk-WSVH6IQA.js";import"./chunk-7DXL3LHT.js";import"./chunk-3PZ4Y6UD.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 f(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 f({...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,f as trackOpenRouterUsage};
1
+ import"./chunk-CCPNMQHZ.js";import"./chunk-2Y4G5364.js";import{qa as i}from"./chunk-ACF2FBUB.js";import"./chunk-G56XGVMS.js";import"./chunk-IWWKVNEX.js";import"./chunk-7DXL3LHT.js";import"./chunk-3PZ4Y6UD.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 f(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 f({...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,f as trackOpenRouterUsage};
package/dist/page.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { C as ConfigurationSync } from './configuration-sync-E98CqVwh.js';
1
+ import { a as ConfigurationSync } from './configuration-sync-CXe9Zcng.js';
2
2
  import { J as JsonValue, R as Result } from './growth-rules-B4YYy64R.js';
3
3
  import { z } from 'zod';
4
- import './screen-BITZ11jn.js';
4
+ import './screen-D81zCpfi.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,13 +10,14 @@ 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
+ phase: z.ZodOptional<z.ZodString>;
14
+ key: z.ZodString;
13
15
  filters: z.ZodOptional<z.ZodArray<z.ZodObject<{
14
16
  attribute: z.ZodOptional<z.ZodString>;
15
17
  seed: z.ZodString;
16
18
  hashVersion: z.ZodLiteral<2>;
17
19
  ranges: z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
18
20
  }, z.core.$strict>>>;
19
- key: z.ZodString;
20
21
  condition: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
21
22
  force: z.ZodOptional<z.ZodNumber>;
22
23
  hashAttribute: z.ZodOptional<z.ZodString>;
@@ -48,7 +49,6 @@ declare const pageExperimentPayloadSchema: z.ZodObject<{
48
49
  name: z.ZodOptional<z.ZodString>;
49
50
  passthrough: z.ZodOptional<z.ZodBoolean>;
50
51
  }, z.core.$strict>>>;
51
- phase: z.ZodOptional<z.ZodString>;
52
52
  changeId: z.ZodString;
53
53
  variations: z.ZodArray<z.ZodObject<{
54
54
  urlRedirect: z.ZodString;
package/dist/page.js CHANGED
@@ -1 +1 @@
1
- import{d as o,e as r,f as e,g as f}from"./chunk-YZSQDZXW.js";import"./chunk-65TBYVCS.js";import"./chunk-DSPLGTQI.js";import"./chunk-WSVH6IQA.js";import"./chunk-3PZ4Y6UD.js";export{f as createPageExperiments,o as mergeQueryStrings,r as pageAttributes,e as readPayload};
1
+ import{d as o,e as r,f as e,g as f}from"./chunk-ABNSU3ZG.js";import"./chunk-AHXYGGAA.js";import"./chunk-DSPLGTQI.js";import"./chunk-IWWKVNEX.js";import"./chunk-3PZ4Y6UD.js";export{f as createPageExperiments,o as mergeQueryStrings,r as pageAttributes,e as readPayload};
@@ -0,0 +1 @@
1
+ import{b as Z}from"./chunk-SSLZKIIU.js";import{M as B}from"./chunk-2Y4G5364.js";import{L as V,i as G,ma as W,oa as X,qa as w}from"./chunk-ACF2FBUB.js";import{a as j}from"./chunk-DSPLGTQI.js";import"./chunk-G56XGVMS.js";import"./chunk-IWWKVNEX.js";import"./chunk-7DXL3LHT.js";import"./chunk-3PZ4Y6UD.js";async function ee(b,n,y){if(n.status!=="complete")throw new w("INVALID_RESPONSE","A verified completed purchase is required");if(await y.onComplete?.(n),!b||!y.check)return;let R=V.parse(await y.check());if(R.internal_feature_id!==b.internal_feature_id||R.quantity!==b.quantity)throw new w("INVALID_RESPONSE","The access requirement changed");R.allowed&&await y.onAccessGranted?.(R)}async function fe(b,n){let y=n.check?V.parse(await n.check()):null;if(y?.allowed)return await n.onAccessGranted?.(y),{check:y,host:null};let R=Z(b.ownerDocument),r=await n.start(),E=r.view??await r.refresh();if(!E)throw new w("INVALID_RESPONSE","Paywall presentation is missing");let{mountScreenPreview:te}=await import("./screen-renderer-ZSAR7LPS.js"),c=b.ownerDocument,_=new AbortController,C=c.createElement("section"),K=c.createElement("div"),D=c.createElement("div"),g=c.createElement("p"),u=c.createElement("button"),M=c.createElement("button"),d=c.createElement("dialog"),i=E.document.screen.strings.defaultLocale.startsWith("zh");C.dataset.indianaPaywall="",C.setAttribute("aria-label",E.document.name),C.style.cssText="width:100%;box-sizing:border-box;background:#fff;color:#172033;font:14px/1.5 system-ui,sans-serif",D.style.cssText="display:flex;gap:12px;padding:12px 20px;align-items:center;flex-wrap:wrap",g.setAttribute("role","status"),M.textContent=i?"\u5173\u95ED":"Close",u.textContent=i?"\u91CD\u8BD5":"Retry",u.hidden=!0,D.append(g,u,M),C.append(K,D);let L=E.document.presentation,O,p=!1,$=!1,f=null,Y=!1,m=()=>!Y&&n.canInteract?.()!==!1,q=!1,a=null,U=null,Q=new Map;async function H(e){if(!(!m()||!e.checkoutUrl||Q.get(e.operationId)===e.checkoutUrl)){Q.set(e.operationId,e.checkoutUrl);try{n.onCheckoutUrl?await n.onCheckoutUrl(e.checkoutUrl):c.defaultView?.location.assign(e.checkoutUrl)}catch(o){throw Q.delete(e.operationId),o}}}let N=e=>{g.textContent=e instanceof Error?e.message:i?"\u8BF7\u6C42\u5931\u8D25":"Request failed",j(n.onError,e),u.hidden=a===null};async function k(e){if(!($||p||!m())){$=!0,u.hidden=!0,g.textContent="";try{await e()}catch(o){p||N(o)}finally{$=!1}}}async function ne(e){await ee(y,e,n)}async function v(e){if(p)return;if(!m()){a=async()=>v(await r.read()),u.hidden=!1;return}if(g.textContent=e.status,e.problem){let t=e.problem;a=T,u.textContent=i?"\u68C0\u67E5\u5E76\u6062\u590D\u539F\u64CD\u4F5C":"Check and recover original purchase",N(new w(t.code,t.reason==="RESULT_UNKNOWN"?i?"\u4ED8\u6B3E\u7ED3\u679C\u5C1A\u672A\u786E\u5B9A\uFF0C\u8BF7\u6062\u590D\u539F\u64CD\u4F5C\uFF0C\u6682\u52FF\u91CD\u590D\u8D2D\u4E70\u3002":"The payment result is unknown. Recover the original purchase before buying again.":t.phase==="fulfillment"?i?"\u4ED8\u6B3E\u5DF2\u8BB0\u5F55\uFF0C\u5546\u6237\u6743\u76CA\u5904\u7406\u9700\u8981\u6838\u5BF9\u3002":"Payment was recorded. Access fulfillment needs attention.":t.code==="CAPABILITY_UNAVAILABLE"?i?"\u5546\u6237\u5C1A\u4E0D\u652F\u6301\u672C\u6B21\u8D2D\u4E70\u6240\u9700\u7684\u5B8C\u6574\u80FD\u529B\uFF0C\u8BF7\u5904\u7406\u540E\u6062\u590D\u539F\u64CD\u4F5C\u3002":"The merchant does not currently support all actions required by this purchase. Recover the original purchase after this is resolved.":t.code==="NOT_CONFIGURED"?i?"\u4ED8\u6B3E\u670D\u52A1\u8FDE\u63A5\u9700\u8981\u5904\u7406\uFF0C\u8BF7\u8054\u7CFB\u5546\u6237\u540E\u6062\u590D\u539F\u64CD\u4F5C\u3002":"The payment connection needs attention. Contact the merchant, then recover the original purchase.":i?"\u539F\u8D2D\u4E70\u64CD\u4F5C\u9700\u8981\u5904\u7406\uFF0C\u8BF7\u67E5\u8BE2\u6216\u6062\u590D\u6B64\u64CD\u4F5C\u3002":"The original purchase needs attention. Check or recover this operation.",void 0,void 0,t));return}if(e.merchantExecution?.type==="purchase"&&e.merchantExecution.paymentStatus==="succeeded"&&!["applied","not_applicable"].includes(e.merchantExecution.fulfillmentStatus)&&(g.textContent=i?"\u4ED8\u6B3E\u5DF2\u8BB0\u5F55\uFF0C\u6B63\u5728\u7B49\u5F85\u5546\u6237\u5B8C\u6210\u5904\u7406\u3002":"Payment was recorded. Waiting for merchant fulfillment."),e.status==="complete"){a=null,await ne(e);return}if(e.status!=="pending"){if(r.canReselect===!1){g.textContent=i?"\u6B63\u5728\u6838\u5BF9\u539F\u8D2D\u4E70\u7ED3\u679C":"Checking the original purchase result",u.textContent=i?"\u67E5\u8BE2\u7ED3\u679C":"Check result",a=async()=>v(await r.read()),u.hidden=!1;return}u.textContent=i?"\u91CD\u8BD5":"Retry",a=null,f=null;return}await H(e);let o=Date.now()+6e5,l=2e3;for(;!p&&Date.now()<o;){if(await new Promise(h=>{let P=()=>{clearTimeout(I),h()},I=setTimeout(()=>{_.signal.removeEventListener("abort",P),h()},l);_.signal.addEventListener("abort",P,{once:!0})}),p)return;if(!m()){a=async()=>v(await r.read()),u.hidden=!1;return}let t=await r.read();if(!t.problem&&t.status==="pending"&&await H(t),t.status!=="pending"||t.problem){await v(t);return}l=Math.min(l*1.5,3e4)}a=async()=>v(await r.read()),u.hidden=!1}async function T(){U?.remove(),U=null,a=T;let e=await r.confirm();if(!m()){a=T,u.hidden=!1;return}if(e.problem){await v(e);return}if(e.status==="pending"){if(e.checkoutUrl)await H(e);else if(e.execution&&e.execution.provider!=="merchant"||e.nativePurchase){if(!n.onPurchase)throw new w("PURCHASE_HANDLER_REQUIRED","Provide the merchant or native purchase handler");await n.onPurchase({operation:e,signal:_.signal})}}a=async()=>v(await r.read()),await v(e)}function re(e){U?.remove();let o=c.createElement("div"),l=c.createElement("button"),t=c.createElement("button"),h=c.createElement("p");h.textContent=e.lines.map(s=>s.productName).join(", ")+" \xB7 "+G(e.charge?.totalMinor??e.catalogAmountMinor-(e.discount?.amountMinor??0),e.currency),l.textContent=i?"\u786E\u8BA4\u8D2D\u4E70":"Confirm purchase",t.textContent=i?"\u53D6\u6D88":"Cancel",l.onclick=()=>{k(T)};let P=async()=>{let s=await r.cancel();p||(o.remove(),U=null,await v(s))};t.onclick=()=>{a=P,k(P)};let I=c.createElement("div");for(let s of e.lines){let J=c.createElement("p");J.textContent=`${s.productName} \xB7 ${G(s.catalogAmountMinor,e.currency)}${W(s.interval,i?"zh-CN":"en",s.intervalCount??1)}`,I.append(J);for(let x of s.prepaid??[]){let F=c.createElement("p"),A=r.view?.capabilities.plans[s.productVersionId]?.prepaid?.find(ae=>ae.internalFeatureId===x.internal_feature_id);F.textContent=`${A?.name??x.internal_feature_id} \xB7 ${x.quantity} ${i?"\u4EFD":"packs"} \xD7 ${x.terms.units}`,A&&(F.textContent+=W(A.reset==="week"||A.reset==="month"||A.reset==="year"?A.reset:"one_time",i?"zh-CN":"en",A.resetCount)),I.append(F)}if(s.trial){let x=c.createElement("p");x.textContent=i?`\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"}`,I.append(x)}}if(!e.charge){let s=c.createElement("p");s.textContent=i?"\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.",I.append(s)}o.append(h,I,l,t),D.prepend(o),U=o,a=null}async function z(){if(!f)return;if(a=z,!q){let o=r.view,l=o?.document.buttons[f.actionId],t=o&&l?.type==="checkout"?B(l.product,f.selection,o.capabilities):null;if(!t)throw new w("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area");let h=await n.resolveOfferId?.({actionId:f.actionId,productVersionId:t});if(p)return;h!==void 0&&(f.offerId=h),q=!0}if(!m()){u.hidden=!1;return}let e=await r.preview(f);p||re(e)}function S(e="destroy"){p||(p=!0,_.abort(),O?.destroy(),r.destroy(),d.open&&d.close(),d.remove(),C.remove(),R(),e==="dismiss"&&j(n.onDismiss))}M.onclick=()=>{m()&&S("dismiss")},d.addEventListener("cancel",e=>{e.preventDefault(),m()&&S("dismiss")}),u.onclick=()=>{a&&k(a)};try{if(L.type==="inline")b.append(C);else{let e={sm:420,md:640,lg:900};d.style.cssText=`padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto;width:${"size"in L?e[L.size]+"px":"100vw"}`,d.setAttribute("aria-label",E.document.name),d.append(C),b.append(d),m()&&d.showModal()}O=te(K,{mode:"live",rendererUrl:r.webViewUrl,title:E.document.name,onAction(e,o={}){if(!m())return;let l=r.view,t=l?.document.buttons[e];if(!t)return;if(t.type==="close"){k(async()=>{await n.onAction?.(e),S(n.onAction?"action":"dismiss")});return}if(t.type==="action"){a=async()=>{if(t.action.type==="event"){if(!n.onEvent)throw new w("EVENT_HANDLER_REQUIRED","Provide the event handler");await n.onEvent(t.action.event)}else n.onOpenUrl?await n.onOpenUrl(t.action.url):c.defaultView?.location.assign(t.action.url);await n.onAction?.(e),a=null},k(a);return}if((r.quote||f)&&r.canReselect===!1){a=r.quote?async()=>v(await r.read()):z,k(a);return}let h=l&&B(t.product,o,l.capabilities);if(!l||!h){N(new w("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));return}if(n.onPurchaseIntent){a=null,k(async()=>{let P={actionId:e,productVersionId:h,selection:structuredClone(o),featureQuantities:X(l.document.screen,h,o,l.capabilities)};await n.onPurchaseIntent(P)});return}if(f&&f.actionId!==e){N(new w("COMMAND_PENDING","Finish the current purchase"));return}f||(f={requestId:crypto.randomUUID(),actionId:e,selection:o},q=!1),k(z)},onEscape:()=>{m()&&S("dismiss")},onError:e=>N(new Error(e))}),O.update(E.document.screen,E.document.screen.strings.defaultLocale,{capabilities:E.capabilities,serverInput:{bindings:[],answers:{}}}),await O.ready}catch(e){throw S(),e}return{check:y,host:{setSuspended(e){Y=e,C.hidden=e,e&&d.open?d.close():!e&&!p&&L.type!=="inline"&&!d.open&&d.showModal()},destroy:S,refresh:async()=>{if(!m()){if(r.view)return r.view;throw new w("PRECONDITION_FAILED","Paywall presentation is suspended")}let e=await r.refresh();return p||O?.updateCapabilities(e.capabilities),e}}}}export{fe as showPaywall};
package/dist/popup.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { a as ScreenAction, b as ScreenNode, c as ScreenDocument } from './screen-BITZ11jn.js';
2
- import { O as Offer, c as OfferUnavailableReason, d as CustomerPageData, a as SurfaceData, e as ScreenParameters, f as ScreenRendererInput, S as ScreenAnswers, b as CustomerDataIntent } from './customer-page-9B97Qdt_.js';
1
+ import { b as ScreenAction, c as ScreenNode, d as ScreenDocument } from './screen-D81zCpfi.js';
2
+ import { O as Offer, a as OfferUnavailableReason } from './coupon-fA1QujHt.js';
3
+ import { b as CustomerPageData, a as SurfaceData, c as ScreenParameters, d as ScreenRendererInput, S as ScreenAnswers, C as CustomerDataIntent } from './customer-page-km5f1PJZ.js';
3
4
  import { WindowLike } from 'dompurify';
4
5
  import 'zod';
5
6
 
@@ -12,7 +13,7 @@ type PopupEvent = {
12
13
  name: string;
13
14
  properties: ScreenAction["properties"];
14
15
  /** Presentation-only choices; validate actual prices and entitlements on the server. */
15
- selection?: Record<string, string | boolean>;
16
+ selection?: Record<string, string | boolean | number>;
16
17
  } | {
17
18
  type: "closed";
18
19
  reason: "close_button" | "escape" | "action" | "destroy" | "timeout";
@@ -135,7 +136,7 @@ type ScreenPreviewHandle = {
135
136
  capabilities?: SurfaceData;
136
137
  customerData?: CustomerPageData;
137
138
  serverInput?: ScreenRendererInput;
138
- selection?: Record<string, string | boolean>;
139
+ selection?: Record<string, string | boolean | number>;
139
140
  /** Explicitly restart a live page even when its design and input are unchanged. */
140
141
  reset?: boolean;
141
142
  }): void;
@@ -163,7 +164,8 @@ declare function mountScreenPreview(container: HTMLElement, options?: {
163
164
  onHover?: (id: string | null) => void;
164
165
  onSelect?: (id: string | null) => void;
165
166
  onEdit?: (id: string) => void;
166
- onAction?: (actionId: string, selection?: Record<string, string | boolean>, answers?: ScreenAnswers) => void;
167
+ onAction?: (actionId: string, selection?: Record<string, string | boolean | number>, answers?: ScreenAnswers) => void;
168
+ onSelection?: (selection: Record<string, string | boolean | number>) => void;
167
169
  onAnswers?: (answers: ScreenAnswers) => void;
168
170
  onRendered?: () => void;
169
171
  /** Live previews report the page actually rendered, when the current screen is rendered. */
package/dist/popup.js CHANGED
@@ -1 +1 @@
1
- import{a as o,b as r,c as e,d as f,e as m,g as p,h as t,i as x,j as a}from"./chunk-L7LKE3MG.js";import"./chunk-SSLZKIIU.js";import"./chunk-G23YNWWI.js";import"./chunk-DSPLGTQI.js";import"./chunk-7DXL3LHT.js";import"./chunk-3PZ4Y6UD.js";export{p as formatCustomerDecimal,r as hostedRendererScript,o as hostedRendererShell,f as inspectCustomHtml,a as mountScreenPreview,x as preparePopup,m as prepareScreen,e as sanitizeCustomHtml,t as showPopup};
1
+ import{a as o,b as r,c as e,d as f,e as m,g as p,h as t,i as x,j as a}from"./chunk-X6BCUINI.js";import"./chunk-SSLZKIIU.js";import"./chunk-ACF2FBUB.js";import"./chunk-DSPLGTQI.js";import"./chunk-7DXL3LHT.js";import"./chunk-3PZ4Y6UD.js";export{p as formatCustomerDecimal,r as hostedRendererScript,o as hostedRendererShell,f as inspectCustomHtml,a as mountScreenPreview,x as preparePopup,m as prepareScreen,e as sanitizeCustomHtml,t as showPopup};