@tinkerlandai/indiana-sdk 0.1.0 → 0.3.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 +20 -0
- package/README.md +63 -7
- package/THIRD_PARTY_NOTICES.md +27 -0
- package/dist/{ai-usage-DX99gvfl.d.ts → ai-usage-D_mBF5Gp.d.ts} +539 -80
- package/dist/chunk-D37O6FAW.js +11 -0
- package/dist/chunk-MJG7X7LM.js +17 -0
- package/dist/chunk-PTWRGCVW.js +1 -0
- package/dist/chunk-X5UXOLOU.js +1 -0
- package/dist/funnel-runtime-host-OVCJIQRT.js +1 -0
- package/dist/{funnel-runtime-start-CcuXliU_.d.ts → funnel-runtime-start-CQhy2kx1.d.ts} +2742 -1416
- package/dist/growth-rules-D64pEvg9.d.ts +166 -0
- package/dist/index.d.ts +3041 -2268
- package/dist/index.js +1 -1
- package/dist/native-shell.js +1 -1
- package/dist/openrouter.d.ts +2 -2
- package/dist/openrouter.js +1 -1
- package/dist/page.d.ts +134 -0
- package/dist/page.js +4 -0
- package/dist/paywall-4JTI7QAB.js +1 -0
- package/dist/popup.d.ts +31 -4
- package/dist/popup.js +15 -4
- package/dist/server.d.ts +4 -3
- package/dist/server.js +1 -1
- package/dist/src-RZJKF6LQ.js +1 -0
- package/package.json +5 -1
- package/dist/chunk-2HEB2TPD.js +0 -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
- package/dist/{screen-DfuSw6Tz.d.ts → screen-Keau_Qa2.d.ts} +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function j(e){let t=2166136261,n=e.length;for(let r=0;r<n;r++)t^=e.charCodeAt(r),t+=(t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24);return t>>>0}function T(e,t,n){return n===2?j(j(e+t)+"")%1e4/1e4:null}function re(e){return e<=0?[]:new Array(e).fill(1/e)}function C(e,t){return e>=t[0]&&e<t[1]}function G(e,t){for(let n=0;n<t.length;n++)if(C(e,t[n]))return n;return-1}function P(e,t,n){t=t===void 0?1:t,t<0?t=0:t>1&&(t=1);let r=re(e);n=n||r,n.length!==e&&(n=r);let o=n.reduce((a,u)=>u+a,0);(o<.99||o>1.01)&&(n=r);let i=0,s=t;return n.map(a=>{let u=i;return i+=a,[u,u+s*a]})}function K(e,t,n){if(!t)return null;let r=t.split("?")[1];if(!r)return null;let o=r.replace(/#.*/,"").split("&").map(i=>i.split("=",2)).filter(([i])=>i===e).map(([,i])=>parseInt(i));return o.length>0&&o[0]>=0&&o[0]<n?o[0]:null}function M(e){try{return e()}catch{return!1}}function B(e){return typeof e=="string"?e:JSON.stringify(e)}function g(e){typeof e=="number"&&(e=e+""),(!e||typeof e!="string")&&(e="0");let t=e.replace(/(^v|\+.*$)/g,"").split(/[-.]/);return t.length===3&&t.push("~"),t.map(n=>n.match(/^[0-9]+$/)?n.padStart(5," "):n).join("-")}function oe(e){try{let t=e.replace(/([^\\])\//g,"$1\\/");return new RegExp(t)}catch{return}}function I(e,t){if(!t.length)return!1;let n=!1,r=!1;for(let o=0;o<t.length;o++){let i=Ue(e,t[o].type,t[o].pattern);if(t[o].include===!1){if(i)return!1}else n=!0,i&&(r=!0)}return r||!n}function Oe(e,t,n){try{let r=t.replace(/[*.+?^${}()|[\]\\]/g,"\\$&").replace(/_____/g,".*");return n&&(r="\\/?"+r.replace(/(^\/|\/$)/g,"")+"\\/?"),new RegExp("^"+r+"$","i").test(e)}catch{return!1}}function Le(e,t){try{let n=new URL(t.replace(/^([^:/?]*)\./i,"https://$1.").replace(/\*/g,"_____"),"https://_____"),r=[[e.host,n.host,!1],[e.pathname,n.pathname,!0]];return n.hash&&r.push([e.hash,n.hash,!1]),n.searchParams.forEach((o,i)=>{r.push([e.searchParams.get(i)||"",o,!1])}),!r.some(o=>!Oe(o[0],o[1],o[2]))}catch{return!1}}function Ue(e,t,n){try{let r=new URL(e,"https://_");if(t==="regex"){let o=oe(n);return o?o.test(r.href)||o.test(r.href.substring(r.origin.length)):!1}else if(t==="simple")return Le(r,n);return!1}catch{return!1}}function N(e){for(let n of["namespace","status","url","groups"])if(Object.hasOwn(e,n))throw new TypeError(`Retired experiment field: ${n}`);let t=e;if(t.hashVersion!==void 0&&t.hashVersion!==2)throw new TypeError("Only hash version 2 is supported");if(t.filters?.some(n=>n.hashVersion!==2))throw new TypeError("Only hash version 2 is supported")}function F(e){for(let t of Object.values(e)){if(Array.isArray(t))throw new TypeError("Saved groups require typed list or condition entries");if(t&&Object.hasOwn(t,"useEmptyListGroup"))throw new TypeError("Retired saved group field: useEmptyListGroup")}}function se(e){for(let t of["overrides","groups"])if(Object.hasOwn(e,t))throw new TypeError(`Retired evaluation context field: ${t}`);F(e.savedGroups??{})}var _e=e=>e/2**32|0,De=e=>e>>>0;function ie(e,t,n,r){let o=_e(n),i=De(n);e.setUint32(t,r?i:o,r),e.setUint32(t+4,r?o:i,r)}function ae(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}var q=e=>e?`"${e}" `:"";function je(e,t=""){if(typeof e!="number")throw new TypeError(q(t)+"expected number, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(q(t)+"expected integer >= 0, got "+e);return e}function $(e,t,n=""){if(ae(e)&&(t===void 0||e.length===t))return e;t!==void 0&&je(t,"length");let r=ae(e),o=t!==void 0?` of length ${t}`:"",i=r?`length=${e.length}`:`type=${typeof e}`,s=q(n)+"expected Uint8Array"+o+", got "+i;throw r?new RangeError(s):new TypeError(s)}var Ge=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof e)},ue=(e,t)=>{Ge(e,t);let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)throw new TypeError(`"${t}" expected plain object`);if(Object.hasOwn(e,"__proto__"))throw new TypeError(`"${t}.__proto__" is not allowed`)};function W(e,t=!0){if(e.destroyed)throw new Error("hash was destroyed");if(t&&e.finished)throw new Error("digest() was already called")}function ce(e,t){$(e,void 0,"output");let n=t.outputLen;if(!(e.length>=n))throw new RangeError('"output" expected length >= '+n)}function J(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function H(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function x(e,t){return e<<32-t|e>>>t}var Pe=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Ke=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function fe(e){if($(e),Pe)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=Ke[e[n]];return t}function Me(e,t,n="opts"){return ue(e,"defaults"),t!==void 0&&ue(t,n),Object.assign(Object.create(null),e,t)}function le(e,t={}){if(typeof e!="function")throw new TypeError('"hashCons" expected function, got type='+typeof e);t=Me({},t,"info");let n=(o,i)=>e(i).update(o).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.canXOF=r.canXOF,n.create=o=>e(o),Object.assign(n,t),Object.freeze(n)}var de=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function he(e,t,n){return e&t^~e&n}function be(e,t,n){return e&t^e&n^t&n}var O=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,n,r,o){this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=o,this.buffer=new Uint8Array(t),this.view=H(this.buffer)}update(t){W(this),$(t);let{view:n,buffer:r,blockLen:o}=this,i=t.length,s=!1;for(let a=0;a<i;){let u=Math.min(o-this.pos,i-a);if(u===o){let f=H(t);for(;o<=i-a;a+=o)this.process(f,a);s=!0;continue}r.set(a===0&&u===i?t:t.subarray(a,a+u),this.pos),this.pos+=u,a+=u,this.pos===o&&(this.process(n,0),this.pos=0,s=!0)}return this.length+=t.length,s&&this.roundClean(),this}digestInto(t){W(this),ce(t,this),this.finished=!0;let{buffer:n,view:r,blockLen:o,isLE:i}=this,{pos:s}=this;n[s++]=128,n.fill(0,s),this.padOffset>o-s&&(this.process(r,0),n.fill(0)),ie(r,o-8,this.length*8,i),this.process(r,0),this.roundClean();let a=t===n?r:H(t),u=this.outputLen,f=u/4,l=this.get();if(u%4||f>l.length)throw new Error("invalid outputLen");for(let c=0;c<f;c++)a.setUint32(4*c,l[c],i)}digest(){let{buffer:t,outputLen:n}=this;this.digestInto(t);let r=t.slice(0,n);return this.destroy(),r}_cloneIntoMeta(t){let{buffer:n,length:r,finished:o,destroyed:i,pos:s}=this;return t.destroyed=i,t.finished=o,t.length=r,t.pos=s,s&&t.buffer.set(n),t}clone(){return this._cloneInto()}},ge=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Ie=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),m=new Uint32Array(64),Q=class extends O{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(t,n){super(64,t,8,!1),this.A=n[0]|0,this.B=n[1]|0,this.C=n[2]|0,this.D=n[3]|0,this.E=n[4]|0,this.F=n[5]|0,this.G=n[6]|0,this.H=n[7]|0}get(){let{A:t,B:n,C:r,D:o,E:i,F:s,G:a,H:u}=this;return[t,n,r,o,i,s,a,u]}set(t,n,r,o,i,s,a,u){this.A=t|0,this.B=n|0,this.C=r|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=u|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,n){for(let c=0;c<16;c++,n+=4)m[c]=t.getUint32(n,!1);for(let c=16;c<64;c++){let p=m[c-15],y=m[c-2],A=x(p,7)^x(p,18)^p>>>3,b=x(y,17)^x(y,19)^y>>>10;m[c]=b+m[c-7]+A+m[c-16]|0}let{A:r,B:o,C:i,D:s,E:a,F:u,G:f,H:l}=this;for(let c=0;c<64;c++){let p=x(a,6)^x(a,11)^x(a,25),y=l+p+he(a,u,f)+Ie[c]+m[c]|0,b=(x(r,2)^x(r,13)^x(r,22))+be(r,o,i)|0;l=f,f=u,u=a,a=s+y|0,s=i,i=o,o=r,r=y+b|0}r=r+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,u=u+this.F|0,f=f+this.G|0,l=l+this.H|0,this.set(r,o,i,s,a,u,f,l)}roundClean(){J(m)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),J(this.buffer)}},X=class extends Q{constructor(){super(32,ge)}};var pe=le(()=>new X,de(1));var xe=new Map,z=32,ye=new WeakMap,ke=new WeakMap;function Ne(e){return fe(pe(new TextEncoder().encode(String(e))))}var U=e=>Array.isArray(e)?e.map(U):typeof e=="string"||typeof e=="number"?Ne(e):null,L=e=>typeof e=="string"?e.toLowerCase():e;function Ee(e){let t=ye.get(e);return t||(t=new Set(e),ye.set(e,t)),t}function qe(e){let t=ke.get(e);return t||(t=new Set(e.map(L)),ke.set(e,t)),t}function We(e){F(e);for(let t of Object.values(e)){let n=t?.type==="list"||t?.type==="hashed"?t.values:null;n&&n.length>=z&&Ee(n)}return e}function k(e,t,n,r){n=n||{},r||F(n),r=r||new Set;for(let[o,i]of Object.entries(t))switch(o){case"$or":if(!Ae(e,i,n,r))return!1;break;case"$nor":if(Ae(e,i,n,r))return!1;break;case"$and":if(!Ye(e,i,n,r))return!1;break;case"$not":if(k(e,i,n,r))return!1;break;case"$savedGroup":if(!Je(e,i,n,r))return!1;break;default:if(!V(i,ve(e,o),n,!1,r))return!1}return!0}function Je(e,t,n,r){if(!t||typeof t!="object"||Array.isArray(t))return!1;let{id:o,attributeKey:i}=t;if(typeof o!="string"||r.has(o)||i!==void 0&&typeof i!="string")return!1;let s=n[o];if(!s||Array.isArray(s)||typeof s!="object")return!1;let a=new Set(r).add(o);if(s.type==="list"||s.type==="hashed"){let u=i??s.attributeKey;if(typeof u!="string"||!Array.isArray(s.values))return!1;let f=ve(e,u);return E(s.type==="hashed"?U(f):f,s.values)}return s.type==="condition"?!s.condition||typeof s.condition!="object"?!1:k(e,s.condition,n,a):!1}function ve(e,t){let n=t.split("."),r=e;for(let o=0;o<n.length;o++)if(r&&typeof r=="object"&&n[o]in r)r=r[n[o]];else return null;return r}function me(e,t=!1){let n=`${e}${t?"/i":""}`,r=xe.get(n);return r||(r=new RegExp(e.replace(/([^\\])\//g,"$1\\/"),t?"i":void 0),xe.set(n,r)),r}function V(e,t,n,r=!1,o=new Set){if(typeof e=="string")return r?String(t).toLowerCase()===e.toLowerCase():t+""===e;if(typeof e=="number")return t*1===e;if(typeof e=="boolean")return t!==null&&!!t===e;if(e===null)return t===null;if(Array.isArray(e)||!Be(e))return JSON.stringify(t)===JSON.stringify(e);let i=e;for(let s in i)if(!ze(s,t,i[s],n,o))return!1;return!0}function Be(e){let t=Object.keys(e);return t.length>0&&t.filter(n=>n[0]==="$").length===t.length}function Qe(e){if(e===null)return"null";if(Array.isArray(e))return"array";let t=typeof e;return["string","number","boolean","object","undefined"].includes(t)?t:"unknown"}function Xe(e,t,n,r){if(!Array.isArray(e))return!1;let o=Be(t)?i=>V(t,i,n,!1,r):i=>k(i,t,n,r);for(let i=0;i<e.length;i++)if((e[i]??null)!==null&&o(e[i]))return!0;return!1}function E(e,t,n=!1){if(n){let o;if(t.length>=z){let i=qe(t);o=s=>{let a=L(s);return!(typeof a=="number"&&Number.isNaN(a))&&i.has(a)}}else o=i=>t.some(s=>L(i)===L(s));return Array.isArray(e)?e.some(i=>o(i)):o(e)}let r=t.length>=z?(o=>i=>o.has(i))(Ee(t)):o=>t.includes(o);return Array.isArray(e)?e.some(o=>r(o)):r(e)}function we(e){return e===void 0?[]:e&&typeof e=="object"&&(e.type==="list"||e.type==="hashed")&&Array.isArray(e.values)?e.values:null}function Se(e,t,n,r=!1,o=new Set){if(!Array.isArray(e))return!1;for(let i=0;i<t.length;i++){let s=!1;for(let a=0;a<e.length;a++)if(V(t[i],e[a],n,r,o)){s=!0;break}if(!s)return!1}return!0}function ze(e,t,n,r,o=new Set){let i=t,s=n;switch(e){case"$veq":return g(t)===g(n);case"$vne":return g(t)!==g(n);case"$vgt":return g(t)>g(n);case"$vgte":return g(t)>=g(n);case"$vlt":return g(t)<g(n);case"$vlte":return g(t)<=g(n);case"$eq":return t===n;case"$ne":return t!==n;case"$lt":return i<s;case"$lte":return i<=s;case"$gt":return i>s;case"$gte":return i>=s;case"$exists":return n?t!=null:t==null;case"$in":return Array.isArray(n)?E(t,n):!1;case"$ini":return Array.isArray(n)?E(t,n,!0):!1;case"$inGroup":{let a=r[n],u=we(a);return u===null?!1:E(a?.type==="hashed"?U(t):t,u)}case"$notInGroup":{let a=r[n],u=we(a);return u===null?!1:!E(a?.type==="hashed"?U(t):t,u)}case"$nin":return Array.isArray(n)?!E(t,n):!1;case"$nini":return Array.isArray(n)?!E(t,n,!0):!1;case"$not":return!V(n,t,r,!1,o);case"$size":return Array.isArray(t)?V(n,t.length,r,!1,o):!1;case"$elemMatch":return Xe(t,n,r,o);case"$all":return Array.isArray(n)?Se(t,n,r,!1,o):!1;case"$alli":return Array.isArray(n)?Se(t,n,r,!0,o):!1;case"$regex":try{return me(n).test(t)}catch{return!1}case"$regexi":try{return me(n,!0).test(t)}catch{return!1}case"$type":return Qe(t)===n;default:return!1}}function Ae(e,t,n,r){if(!t.length)return!0;for(let o=0;o<t.length;o++)if(k(e,t[o],n,r))return!0;return!1}function Ye(e,t,n,r){for(let o=0;o<t.length;o++)if(!k(e,t[o],n,r))return!1;return!0}function Y(e){return se(e),{context:e,stack:{evaluatedFeatures:new Set}}}function Z(e){return{...e.attributes,...e.attributeOverrides}}function w(e,t,n){let r=t||"id",o="",i=Z(e);return i[r]&&(o=i[r]),!o&&n&&(i[n]&&(o=i[n]),o&&(r=n)),{hashAttribute:r,hashValue:o}}function d(e,t,n){e.context.log?.(t,n)}function _(e,t){return t=t||0,`${e}__${t}`}function ee(e,t){return`${e}||${t}`}function Ze(e,t,n){let r=e.stickyBucketAssignmentDocs;if(!r)return{};let{hashAttribute:o,hashValue:i}=w(e,t),s=ee(o,B(i)),{hashAttribute:a,hashValue:u}=w(e,n),f=u?ee(a,B(u)):null,l={};return f&&r[f]&&Object.assign(l,r[f].assignments||{}),r[s]&&Object.assign(l,r[s].assignments||{}),l}function Re({context:e,expKey:t,expBucketVersion:n,expHashAttribute:r,expFallbackAttribute:o,expMinBucketVersion:i,expMeta:s}){n=n||0,i=i||0,r=r||"id",s=s||[];let a=_(t,n),u=Ze(e,r,o);if(i>0)for(let c=0;c<i;c++){let p=_(t,c);if(u[p]!==void 0)return{variation:-1,versionIsBlocked:!0}}let f=u[a];if(f===void 0)return{variation:-1};let l=s.findIndex(c=>c.key===f);return l<0?{variation:-1}:{variation:l}}function Te(e,t,n,r){let o=ee(t,n),i=e.stickyBucketAssignmentDocs,s=i&&i[o]?i[o].assignments||{}:{},a={...s,...r},u=JSON.stringify(s)!==JSON.stringify(a);return{key:o,doc:{attributeName:t,attributeValue:n,assignments:a},changed:u}}function et(e,t){let n=Y(t),r=Ve(e,null,n);return t.onExperimentEval?.(e,r),r}function tt(e,t){return ne(e,Y(t))}function nt(e){return e.forcedVariations||{}}function Ce(e,t,n){let{context:r}=e;if(r.trackedExperiments){let o=He(t,n);if(r.trackedExperiments.has(o))return;r.trackedExperiments.add(o)}te(()=>r.onExperimentViewed?.(t,n))}function rt(e,t,n){let{context:r}=e;if(r.trackedFeatureUsage){let o=JSON.stringify(n.value);if(r.trackedFeatureUsage[t]===o)return;r.trackedFeatureUsage[t]=o}te(()=>r.onFeatureUsage?.(t,n))}function te(e){try{let t=e();t&&typeof t.catch=="function"&&t.catch(()=>{})}catch{}}function ne(e,t){let{context:n}=t;if(t.stack.evaluatedFeatures.has(e))return d(t,`evalFeature: circular dependency detected: ${t.stack.id} -> ${e}`,{from:t.stack.id,to:e}),S(t,e,null,"cyclicPrerequisite");t.stack.evaluatedFeatures.add(e),t.stack.id=e;let r=n.features?.[e];for(let i of r?.rules??[])N(i);let o=n.forcedFeatureValues;if(o&&o.has(e))return d(t,"Global override",{id:e,value:o.get(e)}),S(t,e,o.get(e),"override");if(!r)return d(t,"Unknown feature",{id:e}),S(t,e,null,"unknownFeature");if(r.rules){let i=new Set(t.stack.evaluatedFeatures);e:for(let s of r.rules){if(s.parentConditions)for(let f of s.parentConditions){t.stack.evaluatedFeatures=new Set(i);let l=ne(f.id,t);if(l.source==="cyclicPrerequisite")return S(t,e,null,"cyclicPrerequisite");let c={value:l.value};if(!k(c,f.condition||{},n.savedGroups||{})){if(f.gate)return d(t,"Feature blocked by prerequisite",{id:e,rule:s}),S(t,e,null,"prerequisite");d(t,"Skip rule because prerequisite evaluation fails",{id:e,rule:s});continue e}}if(s.filters&&$e(s.filters,t)){d(t,"Skip rule because of filters",{id:e,rule:s});continue}if("force"in s){if(s.condition&&!Fe(s.condition,t)){d(t,"Skip rule because of condition ff",{id:e,rule:s});continue}if(!ot(t,s.seed||e,s.hashAttribute,n.saveStickyBucketAssignmentDoc&&!s.disableStickyBucketing?s.fallbackAttribute:void 0,s.range,s.coverage,s.hashVersion)){d(t,"Skip rule because user not included in rollout",{id:e,rule:s});continue}return d(t,"Force value from rule",{id:e,rule:s}),s.tracks&&s.tracks.forEach(f=>{Ce(t,f.experiment,f.result)}),S(t,e,s.force,"force",s.id)}if(!s.variations){d(t,"Skip invalid rule",{id:e,rule:s});continue}let a={variations:s.variations,key:s.key||e};"coverage"in s&&(a.coverage=s.coverage),s.weights&&(a.weights=s.weights),s.hashAttribute&&(a.hashAttribute=s.hashAttribute),s.fallbackAttribute&&(a.fallbackAttribute=s.fallbackAttribute),s.disableStickyBucketing&&(a.disableStickyBucketing=s.disableStickyBucketing),s.bucketVersion!==void 0&&(a.bucketVersion=s.bucketVersion),s.minBucketVersion!==void 0&&(a.minBucketVersion=s.minBucketVersion),s.meta&&(a.meta=s.meta),s.ranges&&(a.ranges=s.ranges),s.name&&(a.name=s.name),s.phase&&(a.phase=s.phase),s.seed&&(a.seed=s.seed),s.hashVersion&&(a.hashVersion=s.hashVersion),s.filters&&(a.filters=s.filters),s.condition&&(a.condition=s.condition);let u=Ve(a,e,t);if(n.onExperimentEval?.(a,u),u.inExperiment&&!u.passthrough)return S(t,e,u.value,"experiment",s.id,a,u)}}return d(t,"Use default value",{id:e,value:r.defaultValue}),S(t,e,r.defaultValue===void 0?null:r.defaultValue,"defaultValue")}function Ve(e,t,n){let{context:r}=n;N(e);let o=e.key,i=e.variations.length;if(i<2)return d(n,"Invalid experiment",{id:o}),h(n,e,-1,!1,t);if(r.enabled===!1)return d(n,"Context disabled",{id:o}),h(n,e,-1,!1,t);if(e.urlPatterns&&!I(r.url||"",e.urlPatterns))return d(n,"Skip because of url targeting",{id:o}),h(n,e,-1,!1,t);let s=K(o,r.url||"",i);if(s!==null)return d(n,"Force via querystring",{id:o,variation:s}),h(n,e,s,!1,t);let a=nt(r);if(o in a){let b=a[o];return d(n,"Force via dev tools",{id:o,variation:b}),h(n,e,b,!1,t)}if(e.active===!1)return d(n,"Skip because inactive",{id:o}),h(n,e,-1,!1,t);let{hashAttribute:u,hashValue:f}=w(r,e.hashAttribute,r.saveStickyBucketAssignmentDoc&&!e.disableStickyBucketing?e.fallbackAttribute:void 0);if(!f)return d(n,"Skip because missing hashAttribute",{id:o}),h(n,e,-1,!1,t);let l=-1,c=!1,p=!1;if(r.saveStickyBucketAssignmentDoc&&!e.disableStickyBucketing){let{variation:b,versionIsBlocked:v}=Re({context:r,expKey:e.key,expBucketVersion:e.bucketVersion,expHashAttribute:e.hashAttribute,expFallbackAttribute:e.fallbackAttribute,expMinBucketVersion:e.minBucketVersion,expMeta:e.meta});c=b>=0,l=b,p=!!v}if(!c){if(e.filters&&$e(e.filters,n))return d(n,"Skip because of filters",{id:o}),h(n,e,-1,!1,t);if(e.include&&!M(e.include))return d(n,"Skip because of include function",{id:o}),h(n,e,-1,!1,t);if(e.condition&&!Fe(e.condition,n))return d(n,"Skip because of condition exp",{id:o}),h(n,e,-1,!1,t);if(e.parentConditions){let b=new Set(n.stack.evaluatedFeatures);for(let v of e.parentConditions){n.stack.evaluatedFeatures=new Set(b);let R=ne(v.id,n);if(R.source==="cyclicPrerequisite")return h(n,e,-1,!1,t);let D={value:R.value};if(!k(D,v.condition||{},r.savedGroups||{}))return d(n,"Skip because prerequisite evaluation fails",{id:o}),h(n,e,-1,!1,t)}}}let y=T(e.seed||o,f,e.hashVersion??2);if(y===null)return d(n,"Skip because of invalid hash version",{id:o}),h(n,e,-1,!1,t);if(!c){let b=e.ranges||P(i,e.coverage===void 0?1:e.coverage,e.weights);l=G(y,b)}if(p)return d(n,"Skip because sticky bucket version is blocked",{id:o}),h(n,e,-1,!1,t,void 0,!0);if(l<0)return d(n,"Skip because of coverage",{id:o}),h(n,e,-1,!1,t);if("force"in e)return d(n,"Force variation",{id:o,variation:e.force}),h(n,e,e.force===void 0?-1:e.force,!1,t);if(r.qaMode)return d(n,"Skip because QA mode",{id:o}),h(n,e,-1,!1,t);let A=h(n,e,l,!0,t,y,c);if(r.saveStickyBucketAssignmentDoc&&!e.disableStickyBucketing){let{changed:b,key:v,doc:R}=Te(r,u,B(f),{[_(e.key,e.bucketVersion)]:A.key});if(b){r.stickyBucketAssignmentDocs=r.stickyBucketAssignmentDocs||{},r.stickyBucketAssignmentDocs[v]=R;let D=r.saveStickyBucketAssignmentDoc;te(()=>D(R))}}return Ce(n,e,A),d(n,"In experiment",{id:o,variation:A.variationId}),A}function S(e,t,n,r,o,i,s){let a={value:n,on:!!n,off:!n,source:r,ruleId:o||""};return i&&(a.experiment=i),s&&(a.experimentResult=s),r!=="override"&&rt(e,t,a),a}function Fe(e,t){return k(Z(t.context),e,t.context.savedGroups||{})}function $e(e,t){return e.some(n=>{let{hashValue:r}=w(t.context,n.attribute);if(!r)return!0;let o=T(n.seed,r,n.hashVersion||2);return o===null?!0:!n.ranges.some(i=>C(o,i))})}function ot(e,t,n,r,o,i,s){if(!o&&i===void 0)return!0;if(!o&&i===0)return!1;let{hashValue:a}=w(e.context,n,r);if(!a)return!1;let u=T(t,a,s??2);return u===null?!1:o?C(u,o):i!==void 0?u<=i:!0}function h(e,t,n,r,o,i,s){let a=!0;(n<0||n>=t.variations.length)&&(n=0,a=!1);let{hashAttribute:u,hashValue:f}=w(e.context,t.hashAttribute,e.context.saveStickyBucketAssignmentDoc&&!t.disableStickyBucketing?t.fallbackAttribute:void 0),l=t.meta?t.meta[n]:{},c={key:l.key||""+n,featureId:o,inExperiment:a,hashUsed:r,variationId:n,value:t.variations[n],hashAttribute:u,hashValue:f,stickyBucketUsed:!!s};return l.name&&(c.name=l.name),i!==void 0&&(c.bucket=i),l.passthrough&&(c.passthrough=l.passthrough),c}function He(e,t){return t.hashAttribute+t.hashValue+e.key+t.variationId}/*!
|
|
2
|
+
Copyright (c) 2025 GrowthBook, Inc.
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
5
|
+
furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all
|
|
8
|
+
copies or substantial portions of the Software.
|
|
9
|
+
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
11
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
12
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
13
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
14
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
15
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
16
|
+
SOFTWARE.
|
|
17
|
+
*/export{K as a,B as b,I as c,We as d,k as e,et as f,tt as g};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as c,b as C}from"./chunk-X5UXOLOU.js";import{Fk as L,ci as N,di as _,gi as q,hf as V,ma as R,ok as U,qi as A,zk as T}from"./chunk-D37O6FAW.js";import{d as b,e as D,f as k,g as x}from"./chunk-MJG7X7LM.js";function j(a){let e=null,i=null,l=0,r=0,s=new Set,n=null,u=null,y=new Set,g=()=>{for(let t of y)try{t()}catch{}},o={attributes:R.parse(a.attributes??{}),onFeatureUsage:a.onFeatureUsage?(t,f)=>{s.has(t)||a.onFeatureUsage(t,structuredClone(f))}:void 0,onExperimentViewed:a.onExperimentViewed?(t,f)=>a.onExperimentViewed(structuredClone(t),structuredClone(f)):void 0,stickyBucketAssignmentDocs:structuredClone(a.stickyBucketAssignmentDocs),saveStickyBucketAssignmentDoc:a.saveStickyBucketAssignmentDoc?t=>a.saveStickyBucketAssignmentDoc(structuredClone(t)):void 0,trackedFeatureUsage:{},trackedExperiments:new Set},w=()=>({value:null,source:"unknownFeature",on:!1,off:!0,ruleId:""});function d(t,f=new Set){return s.has(t)?!n||!n.features[t]||["unknownFeature","cyclicPrerequisite"].includes(n.features[t].source):f.has(t)?!1:(f.add(t),(e?.features[t]?.rules??[]).some(p=>[...p.parentConditions??[],...(p.tracks??[]).flatMap(h=>h.experiment.parentConditions??[])].some(h=>d(h.id,f))))}let m=t=>{if(!e)throw new Error("Initialize the Feature client before evaluation");if(e.expiresAt&&Date.parse(e.expiresAt)<=Date.now())throw new Error("Feature configuration expired; refresh before evaluation");return n?.expiresAt&&Date.parse(n.expiresAt)<=Date.now()&&(n=null,o.features=e.features),s.has(t)?!n||n.expiresAt&&Date.parse(n.expiresAt)<=Date.now()?w():structuredClone(n.features[t]??w()):d(t)?w():structuredClone(x(t,o))};async function v(){if(!e||!s.size)return;if(!a.evaluateRemote)throw new Error("Remote Feature evaluation requires a server loader");let t=r;if(u?.revision===t)return u.loading;let f=l,p=e,h=[...s],I=(async()=>{let E=q.parse(await a.evaluateRemote({attributes:structuredClone(o.attributes),features:h}));if(!(f!==l||t!==r||p!==e)){if(E.generation!==p.generation)throw new Error("Feature configuration changed; refresh before evaluation");if(h.some(S=>!Object.hasOwn(E.features,S))||Object.keys(E.features).some(S=>!s.has(S)))throw new Error("Invalid remote Feature results");n=structuredClone(E),o.features={...p.features,...Object.fromEntries(Object.entries(n.features).map(([S,B])=>[S,{defaultValue:B.value}]))},g()}})();u={revision:t,loading:I};try{await I}finally{u?.loading===I&&(u=null)}}function P(){v().catch(t=>{try{a.onError?.(t)}catch{}})}async function F(){if(i)return i;let t=l,f=(async()=>{let p=await a.load(),h="remoteFeatures"in p?_.parse(p):null,I=h??N.parse(p);if(I.scope.projectId!==a.scope.projectId||I.scope.environment!==a.scope.environment)throw new Error("Feature payload scope changed");if(t!==l)throw new Error("Feature client was reset");let E=new Set(h?.remoteFeatures??[]);if([...E].some(S=>Object.hasOwn(I.features,S)))throw new Error("Remote Feature definitions must not be delivered locally");return e=structuredClone(I),s=E,n=null,u=null,r++,o.features=e.features,o.savedGroups=b(e.savedGroups),o.trackedFeatureUsage={},g(),P(),structuredClone(e)})();i=f;try{return await f}finally{i===f&&(i=null)}}return{init:F,refresh:F,refreshRemote:v,get generation(){return e?.generation??null},get expiresAt(){return e?.expiresAt??null},subscribe(t){return y.add(t),()=>{y.delete(t)}},setAttributes(t){o.attributes=R.parse(t),r++,n=null,u=null,o.features=e?.features??{},o.trackedFeatureUsage={},g(),P()},evalFeature:m,isOn(t){return m(t).on},isOff(t){return m(t).off},getFeatureValue(t,f){let p=m(t).value;return structuredClone(p===null?f:p)},reset(){l++,r++,i=null,u=null,e=null,n=null,s.clear(),o.features={},o.savedGroups={},o.stickyBucketAssignmentDocs={},o.attributes={},o.trackedFeatureUsage={},o.trackedExperiments?.clear(),g()}}}async function M(a,e){if(!/^gg_ct_[A-Za-z0-9_-]{43}$/.test(e.customerToken))throw new c("INVALID_TOKEN","A verified Customer credential is required");let i=C(a);i.identify(e.customerToken);let l=A.resolvePaywall.request.parse({selector:{type:"paywall",paywallId:e.paywallId},commerce:e.commerce,locale:e.locale,...e.requirement?{requirement:e.requirement}:{}}),r=null,s=null,n=null,u=null,y=null;async function g(){let d=A.resolvePaywall,m=d.response.parse(await i.request(d.path,d.request.parse({...l,selector:r?{type:"version",versionId:r.id}:l.selector})));if(m.paywall.paywallId!==e.paywallId)throw new c("INVALID_RESPONSE","The requested Paywall changed");if(r&&(m.paywall.id!==r.id||m.paywall.paywallId!==r.paywallId||m.paywall.offering.id!==r.offering.id))throw new c("INVALID_RESPONSE","The pinned Paywall or Offering Version changed");return r=m.paywall,structuredClone(r)}async function o(d){if(!s)throw new c("INVALID_REQUEST","A quoted purchase is required");let m=d==="read"?A.readSubscriptionOperation:A.attach,v=m.response.parse(await i.request(m.path,m.request.parse({operationId:s.operationId,...d==="read"?{}:{intent:d}})));if(v.operation.operationId!==s.operationId||v.operation.currency!==l.commerce.currency)throw new c("INVALID_RESPONSE","The purchase operation changed");return n?.status==="complete"&&v.operation.status!=="complete"||n&&n.status!=="pending"&&v.operation.status==="pending"||(n=v.operation),structuredClone(n)}let w={get view(){return r?structuredClone(r):null},get quote(){return s?structuredClone(s):null},get operation(){return n?structuredClone(n):null},get webViewUrl(){return i.webViewUrl()},refresh:g,async preview(d){if(!r)throw new c("INVALID_REQUEST","Load the Paywall first");let m=r.document.buttons[d.actionId];if(m?.type!=="checkout")throw new c("INVALID_REQUEST","Choose an authored purchase action");let v=V(m.product,d.selection,r.capabilities);if(!v)throw new c("PRODUCT_UNAVAILABLE","Choose an available Product");let P=A.previewAttach.request.parse({requestId:d.requestId,plans:[{productVersionId:v}],provider:l.commerce.provider,currency:l.commerce.currency,...d.offerId?{offerId:d.offerId}:{},...d.nativeOffer?{nativeOffer:d.nativeOffer}:{}}),F=JSON.stringify(P);if(u&&u!==F&&(!n||n.status==="pending"))throw new c("COMMAND_PENDING","Finish or cancel the original purchase before changing it");if(u===F){if(y)return y;if(s)return structuredClone(s)}u=F;let t=(async()=>{let f=A.previewAttach,p=f.response.parse(await i.request(f.path,P));if(p.quote.currency!==l.commerce.currency||p.quote.provider!==l.commerce.provider||p.quote.lines.length!==1||p.quote.lines[0].productVersionId!==v)throw new c("INVALID_RESPONSE","The purchase quote changed its selected Product or presentment");return s=p.quote,n=null,structuredClone(s)})();y=t;try{return await t}finally{y===t&&(y=null)}},confirm:()=>o("confirm"),cancel:()=>o("cancel"),read:()=>o("read"),destroy(){i.reset(),r=null,s=null,n=null,u=null}};return await g(),w}function X(a,e,i){let l=L.parse(a);if(l.evaluationMode!=="local")throw new c("EVALUATION_MODE","Remote nodes are evaluated by Grow");if(l.expiresAt&&Date.parse(l.expiresAt)<=Date.now())throw new c("CONFIGURATION_EXPIRED","Refresh local rules at the scheduled transition");let r=l.topology.nodes.find(o=>o.id===e);if(!r)throw new c("NOT_FOUND","Funnel node is unavailable");let s=R.parse(i.attributes??{}),n={attributes:s,saveStickyBucketAssignmentDoc:i.saveStickyBucketAssignmentDoc?o=>i.saveStickyBucketAssignmentDoc(structuredClone(o)):void 0,onFeatureUsage:i.onFeatureUsage?(o,w)=>i.onFeatureUsage(o,structuredClone(w)):void 0,onExperimentViewed:i.onExperimentViewed?(o,w)=>i.onExperimentViewed(structuredClone(o),structuredClone(w)):void 0,features:structuredClone(l.growth.features),savedGroups:b(l.growth.savedGroups),stickyBucketAssignmentDocs:structuredClone(i.stickyBucketAssignmentDocs)},u,y;if(r.type==="condition"){let o=l.conditions[r.id];if(!o)throw new c("INVALID_RESPONSE","Local condition rules are unavailable");u=o.find(w=>D(s,w.condition,n.savedGroups))?.port??"default"}else if(r.type==="feature"){if(!r.resources.featureKey)throw new c("INVALID_RESPONSE","Feature reference is unavailable");y=x(r.resources.featureKey,n).value,u="next"}else if(r.type==="split"){let o=r.resources.experimentId,w=o?l.growth.experiments[o]:null;if(!w||!o)throw new c("INVALID_RESPONSE","Experiment reference is unavailable");let d=k(w,n);y=d.value,u=d.inExperiment&&!d.passthrough&&typeof d.value=="string"?d.value:"notParticipating"}else throw new c("SERVER_REQUIRED","This node is driven by the authoritative Funnel runtime");let g=r.outputs[u];if(!g)throw new c("INVALID_RESPONSE","Evaluated node exit is unavailable");return{nodeId:e,port:u,target:g,...y===void 0?{}:{value:y}}}function H(a,e){return e.type==="id"?a.customerId===e.value:a.externalUserId===e.value}function O(a,e){if(a===e)return!0;if(Array.isArray(a)||Array.isArray(e))return Array.isArray(a)&&Array.isArray(e)&&a.length===e.length&&a.every((r,s)=>O(r,e[s]));if(!a||!e||typeof a!="object"||typeof e!="object")return!1;let i=Object.entries(a),l=Object.entries(e);return i.length===l.length&&i.every(([r,s])=>Object.hasOwn(e,r)&&O(s,Reflect.get(e,r)))}function ne(a){let e=/^gg_ct_[A-Za-z0-9_-]{32,128}$/.test(a.apiKey);if(typeof window<"u"&&!e)throw new c("SERVER_ONLY","Funnel starts are issued by your backend");if(!e&&!/^gg_sk_[A-Za-z0-9_-]{32,128}$/.test(a.apiKey))throw new c("INVALID_TOKEN","A customer credential or server API key is required");let i=C({...a,timeoutMs:a.timeoutMs??35e3});return i.identify(a.apiKey),{async start(l){let r=U.safeParse({...l,operation:"start"});if(!r.success||r.data.operation!=="start"||(e?r.data.customer!==void 0:r.data.customer===void 0))throw new c("INVALID_REQUEST","Invalid current Funnel start");let s=r.data,n=T.safeParse(await i.request("funnels",s));if(!n.success||!n.data.runToken)throw new c("INVALID_RESPONSE","Funnel start credentials are missing");let u=n.data;if(u.run.source.id!==s.funnelId||u.run.locale!==(s.locale??"en")||!O(u.run.parameters,s.parameters??{})||(s.customer?!u.customerId||s.customer.type==="id"&&u.customerId!==s.customer.value:u.customerId!==void 0))throw new c("INVALID_RESPONSE","Funnel start contract changed");return{...u,runToken:u.runToken}}}}export{j as a,H as b,O as c,M as d,X as e,ne as f};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Y as S,_b as C,gc as k,jc as L,mc as T,nc as v,oc as j,rc as R,ui as V}from"./chunk-D37O6FAW.js";var U={name:"@tinkerlandai/indiana-sdk",version:"0.3.0",description:"Framework-independent Indiana SDK for customer identity, entitlements, credits, offers and growth surfaces.",license:"UNLICENSED",repository:{type:"git",url:"git+https://github.com/tinkerlandai/Indiana.git",directory:"packages/sdk"},engines:{node:">=22"},publishConfig:{access:"public",tag:"beta"},type:"module",sideEffects:!1,files:["dist","README.md","CHANGELOG.md","THIRD_PARTY_NOTICES.md"],exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js"},"./popup":{types:"./dist/popup.d.ts",import:"./dist/popup.js"},"./server":{types:"./dist/server.d.ts",import:"./dist/server.js"},"./openrouter":{types:"./dist/openrouter.d.ts",import:"./dist/openrouter.js"},"./native-shell":{types:"./dist/native-shell.d.ts",import:"./dist/native-shell.js"},"./page":{types:"./dist/page.d.ts",import:"./dist/page.js"}},scripts:{build:"tsup",prepack:"pnpm run build",typecheck:"tsc --noEmit"},dependencies:{"@ai-sdk/provider":"4.0.26","@types/json-schema":"7.0.15","css-tree":"^3.2.1",dompurify:"^3.4.15",zod:"4.6.5"},devDependencies:{"@indiana/contracts":"workspace:*","@openrouter/sdk":"^1.4.25","@types/css-tree":"^3.2.0",ai:"7.0.136",tsup:"^8.5.1",typescript:"^5.9.3"},peerDependencies:{"@openrouter/sdk":"^1.4.25"},peerDependenciesMeta:{"@openrouter/sdk":{optional:!0}}};var e=class extends Error{constructor(f,d,n,N,i){super(d);this.code=f;this.status=n;this.requestId=N;this.name="IndianaError",this.reason=i?.reason;let c=T(f,n??0,{...i,retryAfter:i?.retryAfterSeconds===void 0?void 0:String(i.retryAfterSeconds)});this.retryable=c.retryable,this.recovery=c.recovery,this.retryAfterSeconds=c.retryAfterSeconds}code;status;requestId;retryable;recovery;retryAfterSeconds;reason},$=Symbol("IndianaNoContent");function J(l,A){let f=l.webView??"hosted";if(!["hosted","embedded"].includes(f))throw new e("INVALID_REQUEST","Invalid Web View mode");let d=l.scope?S.parse(l.scope):void 0,n=new URL(l.baseUrl);if(n.username||n.password||n.search||n.hash)throw new e("INVALID_URL","baseUrl must not contain credentials, query, or fragment");if(n.protocol!=="https:"&&!(n.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(n.hostname)))throw new e("INVALID_URL","Use HTTPS, or HTTP on localhost during development");let N=l.fetch??globalThis.fetch.bind(globalThis),i=l.timeoutMs??1e4;if(!Number.isFinite(i)||i<=0||i>12e4)throw new e("INVALID_TIMEOUT","timeoutMs must be between 1 and 120000");let c=null,b,u=0,p=null,h=new Set;function O(){u+=1,c=null,p=null;for(let s of h)s.abort();h.clear()}async function M(s,q={},D="POST",H={}){if(!c)throw new e("NOT_IDENTIFIED","Call identify with a server-issued customer token first");let g=u,o=new AbortController;h.add(o);let y=()=>g!==u?new e("IDENTITY_CHANGED","Customer identity changed while the request was in flight"):new e("TIMEOUT","Indiana request timed out"),I,x=new Promise((r,a)=>{I=()=>a(y()),o.signal.addEventListener("abort",I,{once:!0})}),K=setTimeout(()=>o.abort(),i),G=async()=>{let r=await N(`${n.href.replace(/\/$/,"")}/api/v1/${s}`,{method:D,headers:{"Content-Type":"application/json",Authorization:`Bearer ${c}`,[v]:R.current,[j]:U.version,...d?{"X-Indiana-Project":d.projectId,"X-Indiana-Environment":d.environment}:{}},body:D==="POST"?JSON.stringify(q):void 0,signal:o.signal,credentials:"omit",cache:"no-store",redirect:"error",...H.keepalive?{keepalive:!0}:{}});if(o.signal.aborted)throw y();let a;try{a=r.status===204?$:await r.json()}catch{throw o.signal.aborted?y():new e(r.ok?"INVALID_RESPONSE":"HTTP_ERROR","The gateway returned an unreadable response",r.status,r.headers.get("X-Request-Id")??void 0)}if(o.signal.aborted)throw y();if(g!==u)throw new e("IDENTITY_CHANGED","Customer identity changed while the request was in flight");if(!r.ok){let t=L.safeParse(a),m=t.success&&(!C.safeParse(t.data.error.code).success||k(t.data.error.code,r.status)),_=m?t.data.error.code:"HTTP_ERROR",P=T(_,r.status,{retryAfter:r.headers.get("Retry-After"),recovery:m?t.data.error.recovery:void 0,reason:m?t.data.error.reason:void 0});throw new e(_,m?t.data.error.message:"Indiana request failed",r.status,r.headers.get("X-Request-Id")??(t.success?t.data.requestId:void 0),{...P,...t.success&&t.data.error.retryable===!1?{retryable:!1}:{},...P.retryAfterSeconds===void 0&&t.success&&t.data.error.retryAfterSeconds!==void 0?{retryAfterSeconds:t.data.error.retryAfterSeconds}:{}})}if(r.headers.get(v)!==R.current)throw new e("PROTOCOL_MISMATCH","Response protocol does not match this SDK");if(d&&a&&typeof a=="object"&&"scope"in a){let t=S.safeParse(a.scope);if(!t.success||t.data.projectId!==d.projectId||t.data.environment!==d.environment)throw new e("SCOPE_MISMATCH","Response scope does not match this SDK instance")}let E=r.headers.get("X-Indiana-Web-View");if(E){if(!/^\/web-view\/renderer\/[a-f0-9]{64}$/.test(E))throw new e("INVALID_RESPONSE","Invalid Web View renderer metadata");b=E}let w=r.headers.get("X-Indiana-Telemetry-Subject");if(w){if(!/^[a-f0-9]{64}$/.test(w))throw new e("INVALID_RESPONSE","Invalid telemetry identity");p!==w&&(p=w,A?.(p))}return a};try{return await Promise.race([G(),x])}catch(r){throw g!==u?new e("IDENTITY_CHANGED","Customer identity changed while the request was in flight"):r instanceof e?r:new e(o.signal.aborted?"TIMEOUT":"NETWORK_ERROR",o.signal.aborted?"Indiana request timed out":"Unable to read the Indiana response")}finally{clearTimeout(K),o.signal.removeEventListener("abort",I),h.delete(o)}}return{subjectKey:()=>p,screenUrl(s){if(!V.safeParse(s).success)throw new e("INVALID_RESPONSE","Invalid published screen render address");return new URL(s,n).href},webViewUrl(){if(f!=="embedded"){if(!b)throw new e("INVALID_RESPONSE","The gateway did not provide a hosted Web View renderer");return new URL(b,n).href}},identify(s){if(!s.trim()||/\s/.test(s)||s.length>4096)throw new e("INVALID_TOKEN","A nonempty server-issued token is required");O(),c=s},reset:O,request:M}}export{e as a,J as b};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as V}from"./chunk-6X42DWOM.js";import{a}from"./chunk-X5UXOLOU.js";import{Ag as oe,hf as re}from"./chunk-D37O6FAW.js";import"./chunk-MJG7X7LM.js";function se(b){let n=b.view;if(!n?.paywall)throw new a("INVALID_REQUEST","The current node is not a Paywall");let A=n.paywall.receiptId,M=n.nodeId,f=n.visit,P=n.paywall.resolution,o=n.paywall.quote,p=n.paywall.operation,U=!1,O=n.paywall.purchaseRequestId,I=null,D=new Map,S=new Map;function R(t){let l=t.run.paywall;if(l?.receiptId===A){if(l.resolution.id!==P.id||l.resolution.offering.id!==P.offering.id)throw new a("INVALID_RESPONSE","The pinned Paywall binding changed");P=l.resolution}if(t.purchase&&t.purchase.receiptId!==A)throw new a("INVALID_RESPONSE","Purchase receipt changed");let u=t.purchase??(l?.receiptId===A?l:null),d=u?.quote??o,r=u?.operation??(d?.operationId===o?.operationId?p:null);if(d&&r&&d.operationId!==r.operationId)throw new a("INVALID_RESPONSE","Purchase operation changed");o=d,(p?.operationId!==r?.operationId||p?.status==="pending"||r?.status==="complete")&&(p=r)}async function m(t,l){if(U)throw new a("IDENTITY_CHANGED","Paywall presentation has closed");let u=D.get(t);if(u){if(JSON.stringify(u.input)!==JSON.stringify(l))throw new a("CONFLICT","A purchase request cannot change its input")}else{let y=b.view;if(!y||y.nodeId!==M||y.visit!==f||y.paywall?.receiptId!==A)throw new a("PRECONDITION_FAILED","The Paywall visit has changed");u={operation:"submit",requestId:t,nodeId:M,visit:f,revision:y.revision,input:l},D.set(t,u)}let d=await b.submit(u),r=Date.now()+3e4;for(;d.run.pendingRequest?.requestId===t&&Date.now()<r&&!U;)await new Promise(y=>setTimeout(y,1e3)),d=await b.resume(t);if(d.run.pendingRequest?.requestId===t)throw new a("COMMAND_PENDING","The purchase command is still pending; retry the original request",202);R(d)}async function E(t){if(!o)throw new a("INVALID_REQUEST","A quoted purchase is required");let l=`${t}:${o.operationId}`,u=S.get(l);if(u||(u=crypto.randomUUID(),S.set(l,u)),await m(u,{type:t==="confirm"?"paywall_confirm":"paywall_cancel",operationId:o.operationId}),!p)throw new a("INVALID_RESPONSE","The accepted purchase result is missing");return structuredClone(p)}return{get view(){return structuredClone(P)},get quote(){return o?structuredClone(o):null},get operation(){return p?structuredClone(p):null},get webViewUrl(){return b.webViewUrl},async refresh(){return R(await b.get()),structuredClone(P)},preview(t){if(O&&O!==t.requestId&&(!p||p.status==="pending"))return Promise.reject(new a("COMMAND_PENDING","Retry the original purchase before starting another"));if(O===t.requestId&&I)return I;let l=P.document.buttons[t.actionId],u=l?.type==="checkout"?re(l.product,t.selection,P.capabilities):null;if(!u)return Promise.reject(new a("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));O=t.requestId;let d=(async()=>{if(await m(t.requestId,{type:"paywall_quote",actionId:t.actionId,productVersionId:u,...t.offerId?{offerId:t.offerId}:{},...t.nativeOffer?{nativeOffer:t.nativeOffer}:{}}),!o)throw new a("INVALID_RESPONSE","The accepted quote is missing");return structuredClone(o)})();return I=d,d.then(()=>{I===d&&(I=null)},r=>{I===d&&(I=null),r instanceof a&&r.status!==void 0&&r.status<500&&![401,425].includes(r.status)&&(O=null)}),d},confirm:()=>E("confirm"),cancel:()=>E("cancel"),async read(){if(!o)throw new a("INVALID_REQUEST","A quoted purchase is required");if(R(await b.get(void 0,{receiptId:A,operationId:o.operationId})),!p)throw new a("INVALID_RESPONSE","The current purchase result is missing");return structuredClone(p)},destroy(){U=!0,D.clear(),S.clear()}}}async function ve(b,n){let{mountScreenPreview:A}=await import("./popup.js"),{showPaywall:M}=await import("./paywall-4JTI7QAB.js"),f=b.ownerDocument,P=f.activeElement,o=f.createElement("section"),p=f.createElement("div"),U=f.createElement("div"),O=f.createElement("p"),I=f.createElement("p"),D=f.createElement("button"),S=f.createElement("button"),R=f.createElement("button"),m=f.createElement("dialog");o.dataset.indianaFunnel="",o.setAttribute("aria-busy","false"),o.style.cssText="box-sizing:border-box;width:100%;min-width:0;font:14px/1.5 system-ui,sans-serif;color:#172033;background:#fff",U.style.cssText="display:flex;gap:12px;align-items:center;flex-wrap:wrap;padding:12px 20px",O.setAttribute("role","status"),I.setAttribute("role","alert"),I.hidden=!0,D.type=S.type=R.type="button",U.append(D,O,I,R,S),o.append(p,U),b.append(o);let E=null,t=null,l=null,u="",d="",r=!1,y=0,j=!1,ee="",k=null,Y=Promise.resolve(),L=null,$=null,Q={},X=new Map,ne=new Set,z=new Set,W=new Set,_={},x=(e,i=null)=>{r||($=i,I.textContent=e instanceof Error?e.message:"Request failed",I.hidden=!1,R.hidden=n.client.pendingCommand===null,V(n.onError,e))};function T(){let e=n.client.view;if(!e)throw new a("INVALID_REQUEST","No current Run is available");return{requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:e.revision}}async function F(e,i=!1){if(!(y&&!i||r)){y++,o.setAttribute("aria-busy","true"),I.hidden=!0,$=null;try{let h=await e();r||await H(n.client.view??h.run)}catch(h){x(h,n.client.pendingCommand?.requestId??null)}finally{y=Math.max(0,y-1),o.setAttribute("aria-busy",String(y>0)),r||(R.hidden=n.client.pendingCommand===null,D.disabled=y>0||!!n.client.pendingCommand||!n.client.view?.canBack)}}}function te(e){if(ne.has(e)||z.has(e)||r)return;z.add(e);let i=async()=>{if(r||u!==e){z.delete(e);return}if(y||n.client.pendingCommand){setTimeout(()=>{i()},250);return}try{await n.client.submit({operation:"shown",...T()}),ne.add(e)}catch(h){x(h)}finally{z.delete(e)}};i()}function Z(){k&&clearTimeout(k),!(r||!l||!["running","waiting"].includes(l.status))&&(k=setTimeout(()=>{k=null,ie().finally(Z)},l.pendingRequest?1500:5e3))}async function ie(){if(!(r||j||y)){j=!0;try{let e=await n.client.get();r||await H(n.client.view??e.run)}catch(e){x(e)}finally{j=!1}}}async function ae(e){let i=n.client.view,h=i?.screen,s=h?.customerData.nodes[e.nodeId];if(!i||!h||!s)return;if(!["refresh","next","previous","filter","sources_next","sources_previous"].includes(e.action)){let C=E?.document,q=C?oe(C,e.nodeId):null,K=q?.type==="customer_data"?q.data.outputs?.[e.action]:void 0;K&&h.outputs.includes(K)?await F(()=>n.client.submit({operation:"submit",...T(),input:{type:"screen",output:K,answers:_,selection:e.value?{[e.nodeId]:e.value}:{}}})):await n.onCustomerDataIntent?.(e,i);return}let c=e.action.startsWith("sources_")?s.resources.find(C=>C.key===e.value):null;if(e.action.startsWith("sources_")&&!c)throw new a("INVALID_REQUEST","Choose a current resource");let N=`${i.visit}:${e.nodeId}:${c?.key??""}`,w=X.get(N)??[null],v=Q[e.nodeId]??{page:1,after:null,filter:"all",...c?{resourceKey:c.key}:{}};if(e.action==="filter"){let C=e.value;if(!C||!["all","purchase","refund","source","usage","debt","settlement"].includes(C))throw new a("INVALID_REQUEST","Unknown data filter");v={page:1,after:null,filter:C},w.splice(0,w.length,null)}else if(e.action==="next"||e.action==="sources_next"){let C=c?.sources.at(-1),q=c?C?{kind:"ledger",cursor:{at:C.detail[0],id:C.id,type:"source"}}:null:h.dataCursors[e.nodeId];if(!q||!c&&!s.hasNext)return;w[v.page]=q,v={...v,page:v.page+1,after:q}}else if(e.action==="previous"||e.action==="sources_previous"){if(v.page<=1)return;v={...v,page:v.page-1,after:w[v.page-2]??null}}X.set(N,w),Q={...Q,[e.nodeId]:v},await F(()=>n.client.get({nodeId:i.nodeId,visit:i.visit,revision:i.revision,components:Q}))}function le(e){let i=e.screen?.presentation;if(!i||i.type==="inline"){m.open&&m.close(),o.parentElement!==b&&b.append(o);return}o.parentElement!==m&&(m.append(o),b.append(m));let h={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 i?h[i.size]+"px":"100vw"}`,m.setAttribute("aria-label",E?.document?.name??(e.screen?.content.type==="document"?e.screen.content.document.name:"Funnel")),m.open||m.showModal()}async function ue(e){if(r)return;l=e,$&&n.client.pendingCommand?.requestId!==$&&(I.hidden=!0,$=null);let i=e.locale.startsWith("zh");if(D.textContent=i?"\u8FD4\u56DE":"Back",S.textContent=i?"\u5173\u95ED":"Close",R.textContent=i?"\u91CD\u8BD5":"Retry",D.disabled=y>0||!!n.client.pendingCommand||!e.canBack,R.hidden=n.client.pendingCommand===null,O.textContent=e.pendingRequest?i?"\u6B63\u5728\u5904\u7406":"Processing":e.instruction?.type==="wait"?i?"\u7B49\u5F85\u4E2D":"Waiting":"",ee!==`${e.revision}:${e.visit}:${e.status}:${e.stopped}`&&(ee=`${e.revision}:${e.visit}:${e.status}:${e.stopped}`,V(n.onState,structuredClone(e))),e.stopped){E?.destroy(),E=null,t?.destroy(),t=null,p.replaceChildren(),u="",d="",m.open&&m.close(),o.hidden=!0,Z();return}o.hidden=!1;let h=e.screen||e.paywall?`${e.id}:${e.nodeId}:${e.visit}`:"";if(h!==u&&(E?.destroy(),E=null,t?.destroy(),t=null,p.replaceChildren(),u=h,d="",_={...e.answers},Q={},X.clear()),le(e),e.screen){let g=e.screen.content;E||(E=A(p,{mode:"live",...g.type==="render"?{screenUrl:de(g.url)}:{rendererUrl:n.client.webViewUrl,title:g.document.name},onAction(w,J={},v={}){_={..._,...v},F(()=>n.client.submit({operation:"submit",...T(),input:{type:"screen",output:w,answers:_,selection:J}}))},onAnswers:w=>{_={..._,...w}},onCustomerDataIntent:w=>{ae(w).catch(x)},onEscape:()=>{B()},onError:w=>x(new Error(w)),onRendered:()=>te(h)}));let c={capabilities:e.screen.capabilities,customerData:e.screen.customerData,parameters:e.parameters,serverInput:{bindings:e.screen.inputs,answers:_}},N=JSON.stringify([g,e.locale,c.capabilities,c.customerData,c.parameters,e.screen.inputs]);N!==d&&(E.update(g.type==="document"?g.document:null,e.locale,c),d=N),await E.ready}else if(e.paywall&&!t){let g=await M(p,{start:async()=>se(n.client),onPurchase:n.onPurchase,onCheckoutUrl:n.onCheckoutUrl,resolveOfferId:n.resolveOfferId,onEvent:n.onEvent,onOpenUrl:c=>n.onOpenUrl?n.onOpenUrl({receiptId:e.paywall.receiptId,url:c,openIn:"same_window"}):f.defaultView?.location.assign(c),onAction:async c=>{let N=await n.client.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:e.revision,input:{type:"screen",output:c,answers:{}}});await H(n.client.view??N.run)},onError:x,onDismiss:()=>{!r&&n.client.view?.visit===e.visit&&B()}});r?g.host?.destroy():t=g.host,te(h)}let s=e.instruction;if(s&&["open_url","event"].includes(s.type)&&!W.has(s.receiptId)){let g=f.createElement("button");g.type="button",g.textContent=s.type==="open_url"?`${i?"\u524D\u5F80":"Continue to"} ${new URL(s.url).host}`:i?"\u7EE7\u7EED":"Continue",g.onclick=()=>{let c=T(),N=s.type==="open_url"&&!n.onOpenUrl&&s.openIn==="new_window"?ce(s.url):null;F(async()=>{let w="success";if(s.type==="open_url")if(n.onOpenUrl)try{w=await n.onOpenUrl({receiptId:s.receiptId,url:s.url,openIn:s.openIn})===!1?"failed":"opened"}catch(v){V(n.onError,v),w="failed"}else w=s.openIn==="new_window"&&!N?"failed":"opened";if(s.type==="event"){if(!n.onEvent)throw new a("EVENT_HANDLER_REQUIRED","Provide the event handler");await n.onEvent(s.event)}if(r||n.client.view?.nodeId!==c.nodeId||n.client.view.visit!==c.visit)throw new a("PRECONDITION_FAILED","The client action visit changed");let J=await n.client.submit({operation:"submit",...c,input:{type:"client_action",receiptId:s.receiptId,outcome:w}});return W.add(s.receiptId),s.type==="open_url"&&!n.onOpenUrl&&s.openIn==="same_window"&&f.defaultView?.location.assign(s.url),J})},p.replaceChildren(g)}!e.pendingRequest&&e.status==="completed"&&!W.has(`complete:${e.id}`)&&(W.add(`complete:${e.id}`),V(n.onComplete,structuredClone(e))),Z()}function ce(e){let i=f.defaultView?.open(e,"_blank")??null;return i&&(i.opener=null),i}function de(e){return n.client.screenUrl?n.client.screenUrl(e):new URL(e,f.defaultView?.location.href).href}function H(e){return Y=Y.catch(()=>{}).then(()=>ue(e)),Y}let pe=n.client.subscribe(e=>{H(e).catch(x)});function B(){return L||(r?Promise.resolve():n.client.view&&!["running","waiting"].includes(n.client.view.status)?(G(),Promise.resolve()):(L=F(()=>n.client.submit({operation:"close",...T()}),!0).then(()=>{n.client.view?.status==="closed"&&G()}).finally(()=>{L=null}),L))}function G(){r||(r=!0,k&&clearTimeout(k),pe(),E?.destroy(),t?.destroy(),m.close(),m.remove(),o.remove(),P instanceof HTMLElement&&P.isConnected&&P.focus(),V(n.onDismiss,l?structuredClone(l):null))}D.onclick=()=>{F(()=>n.client.submit({operation:"back",...T()}))},S.onclick=()=>{B()},R.onclick=()=>{F(()=>n.client.retry())},m.addEventListener("cancel",e=>{e.preventDefault(),B()});try{let e=await n.client.get();await H(n.client.view??e.run)}catch(e){throw G(),e}return{destroy:G,refresh:ie}}export{ve as showFunnelRun};
|