mcp-scraper 0.97.0 → 0.97.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.
- package/CHANGELOG.md +18 -1
- package/README.md +1 -1
- package/dist/actions-5X5CQAKO.js +1 -0
- package/dist/bin/api-server.js +1 -1
- package/dist/bin/mcp-scraper-cli.js +1 -1
- package/dist/bin/mcp-scraper-core.js +1 -1
- package/dist/bin/mcp-scraper-install.js +1 -1
- package/dist/bin/mcp-stdio-server.js +1 -1
- package/dist/bin/paa-harvest.js +1 -1
- package/dist/bundle-GS657HXG.js +1 -0
- package/dist/chunk-2L7CHN5N.js +4 -0
- package/dist/{chunk-4P3LZNVA.js → chunk-4AEW53RU.js} +145 -145
- package/dist/{chunk-U3NV72AL.js → chunk-4YZ74SJ6.js} +1 -8
- package/dist/{chunk-AMYPXA2F.js → chunk-5RQWFYXY.js} +74 -74
- package/dist/{chunk-PD7BI7TR.js → chunk-5TQINRZN.js} +1 -1
- package/dist/{chunk-Z4EHBBL4.js → chunk-5UQAL7HV.js} +1 -1
- package/dist/{chunk-GLCR4KJI.js → chunk-6D25Q5BR.js} +20 -14
- package/dist/chunk-C3JWX6KM.js +10 -0
- package/dist/{chunk-NULRGHJ4.js → chunk-F3M7INSN.js} +7 -7
- package/dist/chunk-FLAWC5PF.js +5 -0
- package/dist/{chunk-PQRT4T2G.js → chunk-FM7BX2LU.js} +1 -1
- package/dist/chunk-IPQOBOFY.js +1 -0
- package/dist/chunk-J7XDXIB6.js +163 -0
- package/dist/chunk-JHDD6R3O.js +8 -0
- package/dist/chunk-KBZY2OGP.js +11 -0
- package/dist/{chunk-JNPM3U3L.js → chunk-NQFTETVC.js} +1 -1
- package/dist/{chunk-A4UASMEQ.js → chunk-P6CDR3RM.js} +1 -1
- package/dist/chunk-QCBCOEH5.js +1 -0
- package/dist/chunk-SJNSTO3C.js +42 -0
- package/dist/{chunk-MVMWPKRC.js → chunk-TZYITYL4.js} +1 -1
- package/dist/{chunk-YJPFEL2E.js → chunk-UUJYICAJ.js} +1 -1
- package/dist/{chunk-OSKCHEVM.js → chunk-XNTAHMPA.js} +1 -1
- package/dist/{chunk-ND4WIBXT.js → chunk-ZDECILF6.js} +1 -1
- package/dist/{chunk-OOB3RKWD.js → chunk-ZNPGM3XE.js} +1 -1
- package/dist/compatibility-UPPKZ4KY.js +1 -0
- package/dist/direct-completion-ZVPPEBDU.js +1 -0
- package/dist/dispatch-GRMMPKQD.js +1 -0
- package/dist/index.cjs +34 -34
- package/dist/index.js +1 -1
- package/dist/jobs-NRZHGQ7I.js +1 -0
- package/dist/queue-2VKW7SGH.js +1 -0
- package/dist/reconciliation-QC6SILLR.js +1 -0
- package/dist/{report-artifact-offload-6OOY2PTM.js → report-artifact-offload-PQNFDNPL.js} +1 -1
- package/dist/{server-6HUBN3OR.js → server-EYMJROPX.js} +530 -533
- package/dist/settlement-47EUTSGX.js +1 -0
- package/dist/vendor-errors-647LSH6H.js +1 -0
- package/dist/worker-AWJF7UYR.js +1 -0
- package/package.json +1 -1
- package/dist/actions-NCZNPYEY.js +0 -1
- package/dist/bundle-XR6XKYJM.js +0 -1
- package/dist/chunk-63VWBMYR.js +0 -3
- package/dist/chunk-6FAMBNHY.js +0 -1
- package/dist/chunk-M5QHXNFZ.js +0 -10
- package/dist/chunk-U4WIJZCX.js +0 -1
- package/dist/chunk-WHVK6FUB.js +0 -11
- package/dist/chunk-XYUJTIPE.js +0 -203
- package/dist/dispatch-ILBBKOSW.js +0 -1
- package/dist/queue-VOGXQDPR.js +0 -1
- package/dist/reconciliation-OXBG7JA2.js +0 -1
- package/dist/settlement-3PS32LQO.js +0 -1
- package/dist/worker-NXRU3TT3.js +0 -1
package/dist/chunk-XYUJTIPE.js
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import{e as pt,f as lr,g as ur,h as dr,i as cr}from"./chunk-OSKCHEVM.js";import{a as br}from"./chunk-U4WIJZCX.js";import{K as Fe,d as Ft,e as oe,f as K,g as Ut,l as Xt,m as Yt,t as er}from"./chunk-GLCR4KJI.js";import{b as nr,c as sr,e as mt,g as gt,m as ue,n as _t,o as de,p as ce,q as ze}from"./chunk-WHVK6FUB.js";import{a as le,b as Ie,c as S,e as hr}from"./chunk-63VWBMYR.js";import{c as ir,d as ar,e as pr,f as mr,g as gr,j as _r}from"./chunk-U3NV72AL.js";import{b as ie,d as ae,e as X,f as Y,g as yr,j as Q,p as We}from"./chunk-7SR7MEU5.js";import{d as Ue,e as $e,f as Je,g as Se,i as ne,l as Ae,n as se,p as Ge,s as Be,t as T}from"./chunk-ANQ4JJVI.js";import{b as $t,c as Jt,d as Gt}from"./chunk-B4ZKPLSP.js";import{a as tr,b as rr,c as or}from"./chunk-VVSHZV5S.js";import{b as ct,d as Bt,e as Wt,g as U,h as B,j as zt,m as Vt,o as Kt}from"./chunk-C7MGJUTU.js";import{b as Qt,c as Zt}from"./chunk-4ZVO6GX4.js";import{a as m}from"./chunk-WNUXMPVX.js";import{b as fr}from"./chunk-B3JRL45T.js";import{c as O,d as h,f as we}from"./chunk-HNNYXMSI.js";import{randomUUID as Ho}from"crypto";async function qn(e,t,r){let o=Ho();return await m().execute({sql:"INSERT INTO jobs (id, user_id, query, options, status, started_at) VALUES (?, ?, ?, ?, 'running', datetime('now'))",args:[o,e,t,JSON.stringify(r)]}),o}async function Mn(e,t,r,o){let n=await m().execute({sql:`INSERT INTO jobs (id, user_id, query, options, status, started_at)
|
|
2
|
-
VALUES (?, ?, ?, ?, 'running', datetime('now'))
|
|
3
|
-
ON CONFLICT(id) DO NOTHING`,args:[e,t,r,JSON.stringify(o)]}),i=await S(e,t);if(!i)throw new Error(`getOrCreateRunningJob: row missing immediately after insert/lookup for ${e}`);return{job:i,created:n.rowsAffected===1}}async function Ln(e,t,r){await m().execute({sql:`UPDATE jobs
|
|
4
|
-
SET status = 'running', started_at = COALESCE(started_at, datetime('now')),
|
|
5
|
-
options = CASE WHEN ? = 'runtime' THEN json_set(options, '$.executionOwner', 'runtime') ELSE options END
|
|
6
|
-
WHERE id = ?
|
|
7
|
-
AND (status = 'pending' OR (
|
|
8
|
-
status = 'running' AND ? = 'runtime'
|
|
9
|
-
AND json_extract(options, '$.executionOwner') = 'inngest'
|
|
10
|
-
AND EXISTS (SELECT 1 FROM operation_executions e JOIN operation_runs r ON r.id = e.run_id
|
|
11
|
-
WHERE e.run_id = 'extract-url-execution:' || jobs.id AND r.user_id = jobs.user_id
|
|
12
|
-
AND r.status = 'running' AND e.phase = 'claimed'
|
|
13
|
-
AND e.expires_at_ms <= CAST(strftime('%s', 'now') AS INTEGER) * 1000)
|
|
14
|
-
))
|
|
15
|
-
AND (json_extract(options, '$.executionOwner') = ?
|
|
16
|
-
OR (? = 'runtime' AND json_extract(options, '$.executionOwner') = 'inngest'))
|
|
17
|
-
AND json_extract(options, '$.jobKind') = ?`,args:[t,e,t,t,t,r]});let o=await S(e);if(!(!o||o.options.executionOwner!==t||o.options.jobKind!==r))return o}async function Hn(e=25){let t=Math.max(1,Math.min(100,Math.floor(e)));return(await m().execute({sql:`SELECT * FROM jobs
|
|
18
|
-
WHERE status IN ('pending', 'running')
|
|
19
|
-
AND json_extract(options, '$.executionOwner') IN ('runtime', 'inngest')
|
|
20
|
-
AND json_extract(options, '$.jobKind') = 'extract_url'
|
|
21
|
-
AND json_extract(options, '$.billingDebitKey') IS NOT NULL
|
|
22
|
-
AND EXISTS (SELECT 1 FROM billing_debits d
|
|
23
|
-
WHERE d.idempotency_key = json_extract(jobs.options, '$.billingDebitKey')
|
|
24
|
-
AND d.user_id = jobs.user_id AND d.status = 'applied'
|
|
25
|
-
AND d.operation = ? AND d.amount_mc = ?)
|
|
26
|
-
AND (
|
|
27
|
-
NOT EXISTS (SELECT 1 FROM operation_executions e
|
|
28
|
-
WHERE e.run_id = 'extract-url-execution:' || jobs.id)
|
|
29
|
-
AND (status = 'pending' OR json_extract(options, '$.executionOwner') = 'runtime')
|
|
30
|
-
OR EXISTS (SELECT 1 FROM operation_executions e JOIN operation_runs r ON r.id = e.run_id
|
|
31
|
-
WHERE e.run_id = 'extract-url-execution:' || jobs.id AND r.user_id = jobs.user_id
|
|
32
|
-
AND r.status = 'running' AND e.phase = 'claimed'
|
|
33
|
-
AND e.expires_at_ms <= CAST(strftime('%s', 'now') AS INTEGER) * 1000)
|
|
34
|
-
)
|
|
35
|
-
AND created_at <= datetime('now', '-30 seconds')
|
|
36
|
-
AND (status = 'pending' OR datetime(COALESCE(started_at, created_at)) <= datetime('now', '-30 seconds'))
|
|
37
|
-
AND datetime(COALESCE(json_extract(options, '$.extractUrlLastDispatchAt'), '1970-01-01')) <= datetime('now', '-30 seconds')
|
|
38
|
-
ORDER BY created_at
|
|
39
|
-
LIMIT ?`,args:[mr.EXTRACT_URL,pr.page_scrape,t]})).rows.map(o=>Ie(le(o)))}async function Fn(e,t){return(await m().execute({sql:`UPDATE jobs
|
|
40
|
-
SET options = json_set(options,
|
|
41
|
-
'$.extractUrlDispatchAttempts', COALESCE(json_extract(options, '$.extractUrlDispatchAttempts'), 0) + 1,
|
|
42
|
-
'$.extractUrlLastDispatchAt', ?,
|
|
43
|
-
'$.extractUrlLastDispatchError', ?)
|
|
44
|
-
WHERE id = ? AND (status = 'pending' OR (status = 'running' AND (
|
|
45
|
-
json_extract(options, '$.executionOwner') = 'runtime'
|
|
46
|
-
OR EXISTS (SELECT 1 FROM operation_executions e JOIN operation_runs r ON r.id = e.run_id
|
|
47
|
-
WHERE e.run_id = 'extract-url-execution:' || jobs.id AND r.user_id = jobs.user_id
|
|
48
|
-
AND r.status = 'running' AND e.phase = 'claimed'
|
|
49
|
-
AND e.expires_at_ms <= CAST(strftime('%s', 'now') AS INTEGER) * 1000)
|
|
50
|
-
)))
|
|
51
|
-
AND json_extract(options, '$.executionOwner') IN ('runtime', 'inngest')
|
|
52
|
-
AND json_extract(options, '$.jobKind') = 'extract_url'`,args:[new Date().toISOString(),t??null,e]})).rowsAffected===1}async function Un(e){return(await m().execute({sql:"SELECT * FROM jobs WHERE user_id = ? ORDER BY created_at DESC LIMIT 50",args:[e]})).rows.map(r=>Ie(le(r)))}async function vr(){let e=m(),t=await e.execute(`
|
|
53
|
-
SELECT * FROM jobs
|
|
54
|
-
WHERE status = 'pending'
|
|
55
|
-
AND COALESCE(json_extract(options, '$.executionOwner'), 'cron') NOT IN ('direct', 'runtime', 'inngest')
|
|
56
|
-
AND json_extract(options,'$.queueExecutionProtocol') IS NOT 0
|
|
57
|
-
ORDER BY created_at
|
|
58
|
-
LIMIT 1
|
|
59
|
-
`),r=t.rows[0]?le(t.rows[0]):void 0;return r?(await e.execute({sql:"UPDATE jobs SET status = 'running', started_at = datetime('now') WHERE id = ? AND status = 'pending'",args:[r.id]})).rowsAffected===0?void 0:{...r,status:"running"}:void 0}async function $n(e,t){await m().execute({sql:`UPDATE jobs SET status = 'done', result = ?, error = NULL, public_error_json = NULL, completed_at = datetime('now') WHERE id = ? AND ${gt}`,args:[JSON.stringify(t),e]})}async function Jn(e,t,r){await m().execute({sql:`UPDATE jobs SET status = 'failed', error = ?, public_error_json = ?, completed_at = datetime('now') WHERE id = ? AND ${gt}`,args:[t,Bt(r),e]})}async function zn(e=25){let t=Math.max(1,Math.min(100,Math.floor(e)));return(await m().execute({sql:`SELECT * FROM jobs
|
|
60
|
-
WHERE status IN ('done', 'failed', 'cancelled')
|
|
61
|
-
AND json_extract(options, '$.executionOwner') IN ('direct', 'inngest')
|
|
62
|
-
AND json_extract(options, '$.billingDebitKey') IS NOT NULL
|
|
63
|
-
AND CAST(json_extract(options, '$.billingHoldMc') AS INTEGER) > 0
|
|
64
|
-
AND json_extract(options, '$.billingSettledAt') IS NULL
|
|
65
|
-
ORDER BY completed_at DESC
|
|
66
|
-
LIMIT ?`,args:[t]})).rows.map(o=>Ie(le(o)))}async function Er(e,t=25,r="1"){if(!/^[a-z_]+$/.test(e)||!r.trim()||r.length>8192)throw Error("Invalid intent selection");return(await m().execute({sql:`SELECT r.id,r.user_id,r.job_id FROM operation_runs r
|
|
67
|
-
JOIN operation_executions e ON e.run_id=r.id
|
|
68
|
-
WHERE r.tool=? AND r.status='running' AND e.phase='claimed'
|
|
69
|
-
AND e.expires_at_ms <= CAST(strftime('%s','now') AS INTEGER)*1000
|
|
70
|
-
AND json_extract(r.normalized_flags_json,'$._storeGateRequired') IS 1 AND (${r})
|
|
71
|
-
ORDER BY r.started_at LIMIT ?`,args:[e,Math.max(1,Math.min(100,Math.floor(t)))]})).rows.map(n=>({runId:String(n.id),userId:Number(n.user_id),jobId:String(n.job_id)}))}import{request as Go}from"https";import{HttpsProxyAgent as Bo}from"https-proxy-agent";var Ve={source:"https://\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061.com/users/zone/premium_domains",retrievedAt:"2026-09-23T20:14:30.483Z",includedStatuses:["premium","remove_candidate"],domains:["advanceautoparts.com","affitto.it","agoda.cn","albertsons.com","allpeople.com","autozone.com","bestbuy.com","bestwestern.com","billiger.de","bottlerover.com","carousell.com","carousell.com.hk","carousell.com.my","carousell.ph","carousell.sg","carsales.com.au","cdiscount.com","chewy.com","costco.com","cvs.com","despegar.com.mx","dickssportinggoods.com","dynos.es","emaxme.com","familytreenow.com","feuvert.fr","flooranddecor.com","foodlion.com","footlocker.co.uk","footlocker.com","giantfoodstores.com","gopuff.com","gplay.bg","hermes.com","hyatt.com","idealo.de","immobilienscout24.de","ingatlan.com","instacart.com","intersport.fr","joann.com","kroger.com","lazada.co.id","lazada.co.th","lazada.com.my","lazada.com.ph","lazada.sg","lazada.vn","lowes.ca","lowes.com","mcmaster.com","mediamarkt.de","mediamarkt.es","medline.com","mscdirect.com","napaonline.com","nofrills.ca","peoplefinders.com","platt.com","publicdatausa.com","realcanadiansuperstore.ca","realestate.com.au","restaurantguru.com","searchpeoplefree.com","shopee.cl","shopee.co.id","shopee.co.th","shopee.com.br","shopee.com.co","shopee.com.mx","shopee.com.my","shopee.ph","shopee.sg","shopee.tw","shopee.vn","similarweb.com","skyscanner.co.kr","skyscanner.net","stopandshop.com","target.com","temu.com","ticketmaster.com","totalwine.com","tractorsupply.com","walmart.com.mx","wayfair.com","weismarkets.com","wizzair.com","worten.pt"]};var Yn=Ve.source,Qn=Ve.retrievedAt,Uo=new Set(Ve.domains);function Re(e){let t=new URL(e).hostname.toLowerCase().replace(/\.$/,"");for(let r of Uo)if(t===r||t.endsWith(`.${r}`))return"premium";return"standard"}function Ne(e){for(let t of["providerProduct","billingTier","billableEvent","unitType","source","policyVersion","effectiveAt"])if(!e[t]?.trim())throw new Error(`Provider rate ${t} is required`);if(!Number.isSafeInteger(e.numeratorUsdNanos)||e.numeratorUsdNanos<0)throw new Error("Provider rate numerator must be a non-negative safe integer");if(!Number.isSafeInteger(e.denominatorUnits)||e.denominatorUnits<1)throw new Error("Provider rate denominator must be a positive safe integer");if(Number.isNaN(Date.parse(e.effectiveAt)))throw new Error("Provider rate effectiveAt must be a date");return e}function Ke(e,t){if(Ne(e),!Number.isSafeInteger(t)||t<0)throw new Error("Billable units must be a non-negative safe integer");let r=BigInt(e.numeratorUsdNanos)*BigInt(t),o=BigInt(e.denominatorUnits),n=(r*2n+o)/(o*2n);if(n>BigInt(Number.MAX_SAFE_INTEGER))throw new Error("Provider amount exceeds safe integer range");return Number(n)}function $o(){return Ne({providerProduct:"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061_serp_api",billingTier:"payg",billableEvent:"successful_delivery",unitType:"request",numeratorUsdNanos:15e8,denominatorUnits:1e3,source:"owner_confirmed_2026-09-24;docs/decisions/2026-08-11-preserve-questions-only-paa-while-evaluating-serp-api.md",policyVersion:"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061-serp-payg-2026-09-24",effectiveAt:"2026-08-11T00:00:00Z"})}function wr(e=process.env){let t=e.\u0042\u0052\u0049\u0047\u0048\u0054\u0044\u0041\u0054\u0041_SERP_CONTRACT_USD_PER_1000?.trim(),r=e.\u0042\u0052\u0049\u0047\u0048\u0054\u0044\u0041\u0054\u0041_SERP_RATE_SOURCE?.trim(),o=e.\u0042\u0052\u0049\u0047\u0048\u0054\u0044\u0041\u0054\u0041_SERP_RATE_POLICY_VERSION?.trim(),n=e.\u0042\u0052\u0049\u0047\u0048\u0054\u0044\u0041\u0054\u0041_SERP_RATE_EFFECTIVE_AT?.trim();if(!t&&!r&&!o&&!n)return $o();if(!t||!r||!o||!n)throw new Error("\u0042\u0072\u0069\u0067\u0068\u0074 \u0044\u0061\u0074\u0061 SERP contract rate requires amount, source, policy version, and effective date");let i=Number(t);if(!Number.isFinite(i)||i<0)throw new Error("Invalid \u0042\u0072\u0069\u0067\u0068\u0074 \u0044\u0061\u0074\u0061 SERP contract amount");return Ne({providerProduct:"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061_serp_api",billingTier:"payg",billableEvent:"successful_delivery",unitType:"request",numeratorUsdNanos:Math.round(i*1e9),denominatorUnits:1e3,source:r,policyVersion:o,effectiveAt:n})}function Jo(e){return Ne({providerProduct:"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061_browser_api",billingTier:e,billableEvent:"transferred_byte",unitType:"byte",numeratorUsdNanos:8e9,denominatorUnits:1e9,source:"owner_confirmed_2026-10-12",policyVersion:"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061-browser-account-2026-10-12",effectiveAt:"2026-10-12T00:00:00Z"})}function ts(e){return Jo(Re(e))}function Sr(){return Ne({providerProduct:"apify_google_serp_scraperlink",billingTier:"store_pay_per_event",billableEvent:"serp_page",unitType:"page",numeratorUsdNanos:5e8,denominatorUnits:1e3,source:"https://apify.com/scraperlink/google-search-results-serp-scraper",policyVersion:"scraperlink-listing-2026-09-24",effectiveAt:"2026-09-24T00:00:00Z"})}var Wo="https://api.\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061.com/request",zo=8e3,Vo="brd.superproxy.io",Ko="44445",Xo=10*1024*1024;async function Yo(e,t){let r=new URL(`http://${t.host}:${t.port}`);r.username=t.username,r.password=t.password;let o=new Bo(r);try{return await new Promise((n,i)=>{let s=Go(e,{agent:o,headers:{"x-unblock-data-format":"parsed"},rejectUnauthorized:!1,signal:t.signal},a=>{let l=[],u=0;a.on("data",d=>{let c=Buffer.isBuffer(d)?d:Buffer.from(d);if(u+=c.length,u>Xo){s.destroy(new Error("\u0042\u0072\u0069\u0067\u0068\u0074 \u0044\u0061\u0074\u0061 SERP response exceeded the maximum size"));return}l.push(c)}),a.on("end",()=>n({ok:(a.statusCode??500)>=200&&(a.statusCode??500)<300,status:a.statusCode??500,rawText:Buffer.concat(l).toString("utf8"),providerRequestId:typeof a.headers["x-response-id"]=="string"?a.headers["x-response-id"]:typeof a.headers["x-request-id"]=="string"?a.headers["x-request-id"]:null}))});s.on("error",()=>i(new Error("\u0042\u0072\u0069\u0067\u0068\u0074 \u0044\u0061\u0074\u0061 native SERP request failed"))),s.end()})}finally{o.destroy()}}function Cr(e){let t=e.\u0042\u0052\u0049\u0047\u0048\u0054\u0044\u0041\u0054\u0041_SERP_PROXY_USERNAME?.trim(),r=e.\u0042\u0052\u0049\u0047\u0048\u0054\u0044\u0041\u0054\u0041_SERP_PROXY_PASSWORD?.trim();if(t||r){if(!t||!r)throw new Error("\u0042\u0072\u0069\u0067\u0068\u0074 \u0044\u0061\u0074\u0061 SERP requires both \u0042\u0052\u0049\u0047\u0048\u0054\u0044\u0041\u0054\u0041_SERP_PROXY_USERNAME and \u0042\u0052\u0049\u0047\u0048\u0054\u0044\u0041\u0054\u0041_SERP_PROXY_PASSWORD");if(/[\u0000-\u001f\u007f]/.test(t+r))throw new Error("\u0042\u0072\u0069\u0067\u0068\u0074 \u0044\u0061\u0074\u0061 SERP native credentials contain invalid control characters");return{method:"native",username:t,password:r}}let o=e.\u0042\u0052\u0049\u0047\u0048\u0054\u0044\u0041\u0054\u0041_SERP_API_KEY?.trim(),n=e.\u0042\u0052\u0049\u0047\u0048\u0054\u0044\u0041\u0054\u0041_SERP_ZONE?.trim();if(!o||!n)throw new Error("\u0042\u0072\u0069\u0067\u0068\u0074 \u0044\u0061\u0074\u0061 SERP requires \u0042\u0052\u0049\u0047\u0048\u0054\u0044\u0041\u0054\u0041_SERP_API_KEY and \u0042\u0052\u0049\u0047\u0048\u0054\u0044\u0041\u0054\u0041_SERP_ZONE, or complete native SERP proxy credentials; \u0042\u0052\u0049\u0047\u0048\u0054\u0044\u0041\u0054\u0041_API_KEY is not used for SERP");if(/\s|[\u0000-\u001f\u007f]/.test(o)||!/^[a-zA-Z0-9_-]+$/.test(n))throw new Error("\u0042\u0072\u0069\u0067\u0068\u0074 \u0044\u0061\u0074\u0061 SERP API key or zone has an invalid format");return{method:"rest",apiKey:o,zone:n}}function Ze(e=process.env){try{return Cr(e),!0}catch{return!1}}function _(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)?e:null}function q(e){return Array.isArray(e)?e:[]}function Z(e){return typeof e=="string"&&e.trim()?e.trim():null}function N(e){return typeof e=="number"&&Number.isFinite(e)?e:typeof e=="string"&&e.trim()&&Number.isFinite(Number(e))?Number(e):null}function y(e,t){for(let r of t){let o=Z(e[r]);if(o)return o}return null}function me(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return""}}function jr(e){return{rawUrl:e,resolvedUrl:e,linkType:"plain",resolutionStatus:"not_needed"}}function Qo(e){let t=e;if(typeof t=="string")try{t=JSON.parse(t)}catch{throw new Error("\u0042\u0072\u0069\u0067\u0068\u0074 \u0044\u0061\u0074\u0061 SERP API returned invalid JSON")}let r=_(t);if(!r)throw new Error("\u0042\u0072\u0069\u0067\u0068\u0074 \u0044\u0061\u0074\u0061 SERP API returned an invalid payload");if(typeof r.body=="string")try{let n=JSON.parse(r.body);if(_(n))return _(n)}catch{}let o=_(r.body);return o?_(o.result)??_(o.data)??o:_(r.result)??_(r.data)??r}function ge(e,t){for(let o of t){let n=q(e[o]);if(n.length)return n}let r=_(e.results);if(r)for(let o of t){let n=q(r[o]);if(n.length)return n}return[]}function pe(e,t){let r=[e,_(e.results)].filter(o=>!!o);for(let o of r)for(let n of t)if(Object.prototype.hasOwnProperty.call(o,n))return{observed:!0,rawShapeValid:Array.isArray(o[n]),rawCount:q(o[n]).length};return{observed:!1,rawShapeValid:!1,rawCount:0}}function ft(e,t){let r=[e,_(e.results)].filter(o=>!!o);for(let o of r)for(let n of t){if(!Object.prototype.hasOwnProperty.call(o,n))continue;let i=_(o[n]);return{observed:!0,rawShapeValid:i!==null,rawCount:i&&Object.keys(i).length>0?1:0}}return{observed:!1,rawShapeValid:!1,rawCount:0}}function Ar(e){return ge(e,["organic","organic_results","organicResults"]).flatMap((t,r)=>{let o=_(t);if(!o)return[];let n=y(o,["link","url","href"]),i=y(o,["title","name"]);if(!n||!i)return[];let s=_(o.rating)??_(o.inline_rating);return[{position:Math.max(1,Math.trunc(N(o.global_rank)??N(o.rank)??N(o.position)??r+1)),title:i,url:n,...jr(n),domain:me(n),cite:y(o,["display_link","displayLink","cite"]),snippet:y(o,["description","snippet","text"]),isRedditStyle:me(n)==="reddit.com",inlineRating:s?{value:String(s.value??s.rating??""),count:String(s.count??s.reviews??"")}:null}]}).sort((t,r)=>t.position-r.position)}function Ir(e){return ge(e,["snack_pack","local","local_results","local_pack","localPack"]).flatMap((t,r)=>{let o=_(t);if(!o)return[];let n=y(o,["title","name"]);if(!n)return[];let i=q(o.extensions??o.metadata).map(Z).filter(s=>!!s);return[{position:Math.max(1,Math.trunc(N(o.global_rank)??N(o.rank)??N(o.position)??r+1)),name:n,cid:y(o,["cid"]),rating:y(o,["rating"])??(N(o.rating)!=null?String(N(o.rating)):null),reviewCount:y(o,["reviews_cnt","reviews","review_count","reviewCount"])??(N(o.reviews_cnt)!=null?String(N(o.reviews_cnt)):N(o.reviews)!=null?String(N(o.reviews)):null),metadata:i,websiteUrl:y(o,["website","website_url","link"]),directionsUrl:y(o,["directions","directions_url"])}]})}function qr(e){let t=_(e);return q(t?.citations??t?.sources??t?.references).flatMap(r=>{let o=_(r);if(!o)return[];let n=y(o,["link","url","href"]);return n?[{text:y(o,["title","text","name"])??me(n),href:n,...jr(n)}]:[]})}function Qe(e,t=0){if(t>4)return[];if(Array.isArray(e))return e.flatMap(i=>Qe(i,t+1));let r=_(e);if(!r)return[];let o=y(r,["snippet","text","answer"]),n=Qe(r.texts??r.list??r.items,t+1);return[...o?[o]:[],...n]}function Rr(e,t){if(!t)return{detected:!1,text:null,citations:[]};let r=_(e.ai_overview)??_(e.aiOverview)??_(e.overview);if(!r)return{detected:!1,text:null,citations:[]};let o=y(r,["text","answer","description"])??(Qe(r.texts).join(`
|
|
72
|
-
|
|
73
|
-
`).slice(0,5e4)||null),n=qr(r);return{detected:!!(o||n.length),text:o,citations:n}}function Nr(e,t){if(!t)return{detected:!1,text:null,citations:[]};let r=_(e.ai_mode)??_(e.aiMode);if(!r)return{detected:!1,text:null,citations:[]};let o=y(r,["text","answer","description"])??(Qe(r.texts).join(`
|
|
74
|
-
|
|
75
|
-
`).slice(0,5e4)||null),n=qr(r);return{detected:!!(o||n.length),text:o,citations:n}}function xr(e,t){return t?[...ge(e,["videos","video_results"]),...ge(e,["short_videos","shorts"])].flatMap(r=>{let o=_(r);if(!o)return[];let n=y(o,["link","url"]),i=y(o,["title","name"]);return!n||!i?[]:[{type:"video",title:i,channel:y(o,["channel","source"])??"",platform:me(n),duration:y(o,["duration"])??"",url:n}]}):[]}function Dr(e,t){if(!t)return[];let r=_(e.forums);return[...ge(e,["discussions","forums","forum_results"]),...q(r?.items)].flatMap(o=>{let n=_(o);if(!n)return[];let i=y(n,["link","url"]),s=y(n,["title","name"]);return!i||!s?[]:[{title:s,source:y(n,["source"])??me(i),url:i}]})}function kr(e,t){return t?ge(e,["what_people_are_saying","whatPeopleSaying"]).flatMap(r=>{let o=_(r);if(!o)return[];let n=y(o,["link","url"]),i=y(o,["title","name"]);if(!n||!i)return[];let s=y(o,["platform","source"])??me(n),a=s.toLowerCase();return[{type:a.includes("reddit")?"reddit":a.includes("facebook")?"facebook":a.includes("instagram")?"instagram":a.includes("tiktok")?"tiktok":a.includes("youtube")?"youtube":a.includes("news")?"news":"unknown",title:i,url:n,source:s,platform:s,popularComment:y(o,["comment","popular_comment"]),engagement:y(o,["engagement"])??"",date:y(o,["date"])??"",duration:y(o,["duration"]),authorNote:y(o,["author_note"])}]}):[]}var Zo={featuredSnippets:["featured_snippets","featured_snippet","featuredSnippet"],knowledgePanel:["knowledge","knowledge_graph","knowledgeGraph"],topStories:["top_stories","topStories"],news:["news","news_results"],images:["images","image_results"],shopping:["shopping","shopping_results"],relatedSearches:["related","related_searches","relatedSearches"],recipes:["recipes","recipe_results"],jobs:["jobs","job_results"],topAds:["top_ads"],bottomAds:["bottom_ads"],topProducts:["top_pla"],bottomProducts:["bottom_pla"],jackpotProducts:["jackpot_pla"],shortVideos:["short_videos","shorts"],localMap:["snack_pack_map"],flights:["flights"],hotels:["hotels_selection"],popularProducts:["popular_products"],weather:["weather"],currencyExchange:["currency_exchange"],latestPosts:["latest_posts"],perspectives:["perspectives"],navigation:["navigation"],chips:["chips"],spelling:["spelling"]};function Xe(e,t){for(let r of[e,_(e.results)])if(r){for(let o of t)if(Object.prototype.hasOwnProperty.call(r,o))return{observed:!0,value:r[o]}}return{observed:!1,value:null}}function Ye(e,t,r){return e?t==null||Array.isArray(t)&&t.length===0?"observed_absent":Array.isArray(t)?r>0?"observed_present":"incomplete":_(t)?r>0?"observed_present":Object.keys(_(t)).length===0?"observed_absent":"incomplete":"incomplete":"unknown"}function en(e){let t=y(e,["answer","snippet","text"]);return t||q(e.answers).flatMap((o,n)=>{let i=_(o),s=_(i?.value),a=i?.type==="answer"?Z(s?.text):null;return a?[{prose:a,rank:N(i?.rank)??n+1,index:n}]:[]}).sort((o,n)=>o.rank-n.rank||o.index-n.index).map(o=>o.prose).join(`
|
|
76
|
-
|
|
77
|
-
`)||null}function tn(e,t){let r={},o=[["localPack",["snack_pack","local","local_results","local_pack","localPack"],t.localPack],["forums",["discussions","forums","forum_results"],t.forums],["videos",["videos","video_results","short_videos","shorts"],t.videos],["aiOverview",["ai_overview","aiOverview","overview"],t.aiOverview],["whatPeopleSaying",["what_people_are_saying","whatPeopleSaying"],t.whatPeopleSaying],["entityIds",["knowledge","knowledge_graph","knowledgeGraph"],t.entityIds]];for(let[l,u,d]of o){let c=Xe(e,u);r[l]=Ye(c.observed,c.value,d)}let n=Xe(e,["ai_mode","aiMode"]);r.aiMode=Ye(n.observed,n.value,t.aiMode);let i=Xe(e,["people_also_ask","peopleAlsoAsk","related_questions","paa"]),s=q(i.value).slice(0,30).flatMap(l=>{let u=_(l);if(!u)return[];let d=y(u,["question","title"]);if(!d)return[];let c=Z(u.question)?Z(u.title)?.slice(0,1e3):null,p=Z(u.answer_source)?.slice(0,1e3),b=y(u,["answer_display_link","display_link"])?.slice(0,2e3);return[{question:d.slice(0,1e3),answer:en(u)?.slice(0,1e4)??null,url:y(u,["answer_link","link","url"])??null,...c?{sourceTitle:c}:{},...p?{sourceName:p}:{},...b?{displayLink:b}:{}}]});r.paaPreview=Ye(i.observed,i.value,s.length);let a=[];for(let[l,u]of Object.entries(Zo)){let d=Xe(e,u);if(!d.observed)continue;let c=_(d.value),b=(Array.isArray(d.value)?d.value:c&&(Array.isArray(c.items)||Array.isArray(c.posts))?[...q(c.items),...q(c.posts)]:[d.value]).slice(0,20).flatMap(f=>{let E=_(f);if(!E)return[];let x=y(E,["title","name","heading"]),H=y(E,["link","url","website"]),J=y(E,["description","snippet","text","summary","story"]);return!x&&!H&&!J?[]:[{title:x?.slice(0,1e3)??null,url:H,description:J?.slice(0,1e4)??null,position:N(E.global_rank)??N(E.rank)??N(E.position)??null}]});r[l]=Ye(d.observed,d.value,b.length);let v=Object.fromEntries(Object.entries(c??{}).slice(0,30).flatMap(([f,E])=>/^[a-zA-Z0-9_]{1,80}$/.test(f)&&(E===null||["string","number","boolean"].includes(typeof E))?[[f,typeof E=="string"?E.slice(0,2e3):E]]:[]));a.push({name:l,attributes:v,items:b})}return{status:r,paaPreview:s,additional:a}}function Pr(e,t){let r=new Set,o=new Set(t.map(s=>s.cid).filter(s=>!!s)),n=new Set,i=(s,a=0)=>{if(a>6||s==null)return;if(Array.isArray(s)){for(let u of s)i(u,a+1);return}let l=_(s);if(l)for(let[u,d]of Object.entries(l)){let c=u.toLowerCase().replace(/[^a-z]/g,""),p=Z(d);p&&(c==="kgid"||c==="kgmid"||c==="mid")?r.add(p):p&&c==="cid"?o.add(p):p&&c==="gcid"?n.add(p):typeof d=="object"&&i(d,a+1)}};return i(e),{entities:[],kgIds:[...r],cids:[...o],gcids:[...n]}}function Or(e,t){let r=e instanceof Error?e.message:String(e);return t.aborted||/timeout|timed out/i.test(r)?"timeout":/captcha|recaptcha|unusual traffic|google\.com\/sorry|blocked/i.test(r)?"captcha":/invalid (?:json|payload)/i.test(r)?"invalid_payload":"provider_error"}function Tr(e){return e==="invalid_payload"?"invalid_payload":e==="captcha"?"serp_readiness":e==="timeout"||e==="provider_error"?"provider_transport":"pagination"}async function yt(e,t=process.env,r=fetch,o=Yo,n){if(e.pages!==1)throw new Error("\u0042\u0072\u0069\u0067\u0068\u0074 \u0044\u0061\u0074\u0061 SERP supports one page only; use Apify for two pages");let i=Cr(t),s=i.method==="native",a=Date.now(),l=Zt(),u=null,d=e.location?Yt(e.location):null;if(e.location&&!d?.canonical)throw new ue("query_integrity","location_unresolved",`SERP location could not be resolved without changing the query (candidates: ${d?.ambiguousCandidates??0})`);let c=d?.canonical?Xt(d.canonical):null,p=AbortSignal.timeout(e.includeAllSerpFeatures?33e3:zo),b=e.signal?AbortSignal.any([e.signal,p]):p,v=1,f=[],E=[],x=0,H=async g=>{let P=Date.now(),R=s?"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061_serp_native_proxy":"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061_serp_rest",C=null,G=null,be=!1,he=!1,re=null,ve=null;if(l?.operationRunId&&(g===1||u))try{C=await ie({runId:l.operationRunId,attemptNumber:n?n.attemptNumber+g-1:g,method:R,provider:"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061",...g===2?{parentAttemptId:u,edgeKind:"next_phase"}:n?{parentAttemptId:n.parentAttemptId,edgeKind:"provider_fallback",retryKind:"provider_fallback"}:{},normalizedFlags:{page:g,device:e.device,hasLocation:!!e.location}}),g===1&&(u=C),G=(await X({attemptId:C,provider:"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061",providerProduct:"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061_serp_api",accountScope:l.operationAccountScope??"production-default",method:R,providerStatus:"started"})).id}catch(A){throw console.warn(JSON.stringify({event:"direct_serp_telemetry_start_failed",page:g,message:A instanceof Error?A.message:String(A)})),A}let D=new URLSearchParams({q:e.query,gl:e.gl,hl:e.hl,pws:"0",num:"10",...g===2?{start:"10"}:{}}),He=$t(e.recency);He&&D.set("tbs",He),e.device==="mobile"&&D.set("brd_mobile","1"),e.includeAiOverview&&D.set("brd_ai_overview","2"),c&&D.set("uule",c),s&&D.set("brd_json","1"),x+=1;let F;try{if(i.method==="native"){let k=t.\u0042\u0052\u0049\u0047\u0048\u0054\u0044\u0041\u0054\u0041_SERP_PROXY_HOST?.trim()||Vo,Ee=t.\u0042\u0052\u0049\u0047\u0048\u0054\u0044\u0041\u0054\u0041_SERP_PROXY_PORT?.trim()||Ko;F=await o(`https://www.google.com/search?${D}`,{username:i.username,password:i.password,host:k,port:Ee,signal:b})}else{let k=await r(Wo,{method:"POST",headers:{Authorization:`Bearer ${i.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({zone:i.zone,url:`https://www.google.com/search?${D}`,format:"json",data_format:"parsed"}),signal:b});F={ok:k.ok,status:k.status,rawText:await k.text(),providerRequestId:k.headers.get("x-response-id")??k.headers.get("x-request-id")}}if(ve=`http_${F.status}`,G&&F.providerRequestId&&await Y(G,F.providerRequestId),!F.ok)throw new Error(`\u0042\u0072\u0069\u0067\u0068\u0074 \u0044\u0061\u0074\u0061 SERP API failed with HTTP ${F.status}`);be=!0;let A;try{A=Qo(JSON.parse(F.rawText))}catch(k){let Ee=k instanceof Error&&k.message!=="Unexpected end of JSON input"?k.message:"\u0042\u0072\u0069\u0067\u0068\u0074 \u0044\u0061\u0074\u0061 SERP API returned invalid JSON";throw new ue("invalid_payload","invalid_provider_payload",Ee)}let w=Ar(A);return f.push({page:g,attempted:!0,captured:w.length>0,resultCount:w.length,requestOffset:g===2?10:0,providerRequestIdObserved:!!F.providerRequestId,...w.length===0?{failureCode:"empty_page"}:{}}),he=!0,A}catch(A){re=A;let w=Or(A,b);if(f.some(Ee=>Ee.page===g)||f.push({page:g,attempted:!0,captured:!1,resultCount:0,requestOffset:g===2?10:0,providerRequestIdObserved:!1,failureCode:w}),g===2)throw A;let k=A instanceof ue?A.stage:Tr(w);throw A instanceof ue?A:new ue(k,w,A instanceof Error?A.message:String(A))}finally{let A=null;if(G&&be)try{let w=wr(t);await Q({receiptId:G,costState:"measured",units:1,unitType:"request",amountUsdNanos:Ke(w,1),rateSource:w.source,providerProduct:w.providerProduct,billingTier:w.billingTier,billableEvent:w.billableEvent,measurementSource:"provider_http_delivery",rateNumerator:w.numeratorUsdNanos,rateDenominator:w.denominatorUnits,ratePolicyVersion:w.policyVersion,rateEffectiveAt:w.effectiveAt,providerStatus:ve??"delivered",providerDurationMs:Date.now()-P})}catch(w){console.warn(JSON.stringify({event:"direct_serp_receipt_finalize_failed",page:g,message:w instanceof Error?w.message:String(w)})),A=w}if(C&&await ae({attemptId:C,status:he?"succeeded":b.aborted?"timed_out":"failed",errorCode:re?Or(re,b):null,durationMs:Date.now()-P}).catch(w=>console.warn(JSON.stringify({event:"direct_serp_attempt_finish_failed",page:g,message:w instanceof Error?w.message:String(w)}))),A)throw A}};try{E.push({page:1,payload:await H(1)})}catch(g){throw g}let J=null;if(v===2)try{E.push({page:2,payload:await H(2)})}catch(g){J=g}let at=Date.now()-a,Ce=Date.now(),I=E[0].payload,je=E.flatMap(({page:g,payload:P})=>Ar(P).map(R=>({...R,position:g===2&&R.position<=10?R.position+10:R.position,sourcePage:g}))).filter((g,P,R)=>R.findIndex(C=>_t(C.url)===_t(g.url))===P),qe=e.includeLocalPack||e.includeAllSerpFeatures,V=qe?Ir(I):[],ye=pe(I,["snack_pack","local","local_results","local_pack","localPack"]),To=ce({requested:qe,moduleObserved:ye.observed,rawCount:ye.rawCount,mappedCount:V.length,rawShapeValid:ye.rawShapeValid}),Dt=e.includeAiOverview||e.includeAllSerpFeatures,kt=Rr(I,Dt),Pt=e.includeForums||e.includeAllSerpFeatures,Ot=Dr(I,Pt),Tt=e.includeVideos||e.includeAllSerpFeatures,Ct=xr(I,Tt),jt=e.includeWhatPeopleSaying||e.includeAllSerpFeatures,qt=kr(I,jt),lt=_(I.forums),ut=lt&&Array.isArray(lt.items)?{observed:!0,rawCount:lt.items.length,rawShapeValid:!0}:pe(I,["discussions","forums","forum_results"]),dt=pe(I,["videos","video_results","short_videos","shorts"]),Mt={localPack:To,forums:ce({requested:Pt,moduleObserved:ut.observed,rawCount:ut.rawCount,mappedCount:Ot.length,rawShapeValid:ut.rawShapeValid}),videos:ce({requested:Tt,moduleObserved:dt.observed,rawCount:dt.rawCount,mappedCount:Ct.length,rawShapeValid:dt.rawShapeValid}),aiOverview:ce({requested:Dt,moduleObserved:ft(I,["ai_overview","aiOverview","overview"]).observed,rawCount:ft(I,["ai_overview","aiOverview","overview"]).rawCount,mappedCount:kt.detected?1:0,rawShapeValid:ft(I,["ai_overview","aiOverview","overview"]).rawShapeValid}),whatPeopleSaying:ce({requested:jt,moduleObserved:pe(I,["what_people_are_saying","whatPeopleSaying"]).observed,rawCount:pe(I,["what_people_are_saying","whatPeopleSaying"]).rawCount,mappedCount:qt.length,rawShapeValid:pe(I,["what_people_are_saying","whatPeopleSaying"]).rawShapeValid})},Co=de(1,f),jo=f.find(g=>g.page===1)?.resultCount??0,Me=f.find(g=>g.page===2)?.resultCount??0,qo=ze({query:e.query,finalQuery:e.query,canonicalLocation:d?.canonical??null,locationResolutionSource:d?.source??"not_requested",locationAmbiguousCandidates:d?.ambiguousCandidates??0,uule:c,outboundProviderMethod:s?"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061_serp_native_proxy":"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061_serp_rest"}),Le=J?Tr(f.find(g=>g.page===2)?.failureCode??"provider_error"):Object.values(Mt).some(g=>g==="incomplete"||g==="unknown")?"optional_feature_parsing":null,Mo={pagination:{...Co,providerRequestCount:x},features:Mt,queryIntegrity:qo,failureStage:Le},Lt=e.includeAllSerpFeatures?(()=>{let g=E.map(({page:P,payload:R})=>{let C=Ir(R),G=Dr(R,!0),be=xr(R,!0),he=kr(R,!0),re=Rr(R,!0),ve=Nr(R,!0),D=Pr(R,C),He=tn(R,{localPack:C.length,forums:G.length,videos:be.length,aiOverview:re.detected?1:0,aiMode:ve.detected?1:0,whatPeopleSaying:he.length,entityIds:D.entities.length+D.kgIds.length+D.cids.length+D.gcids.length});return{page:P,...He,localPack:C,forums:G,videos:be,whatPeopleSaying:he,aiOverview:re,aiMode:ve,entityIds:D}});return{status:g[0].status,paaPreview:g.flatMap(P=>P.paaPreview),additional:g.flatMap(P=>P.additional),pages:g}})():void 0,Lo=new Date().toISOString(),Ht=Date.now()-a;return{seed:e.query,location:e.location??null,extractedAt:Lo,diagnostics:{phaseTimings:{providerConnectMs:at,serpParseMs:Date.now()-Ce,totalServerMs:Ht},pagination:{requestedPages:v,capturedPages:v===2&&Me>0?2:1,page2Status:v===2?Me>0?"captured":"failed":"not_requested",page1OrganicCount:jo,page2OrganicCount:Me,...v===2&&Me===0?{failureCode:f.find(g=>g.page===2)?.failureCode==="captcha"?"captcha":f.find(g=>g.page===2)?.failureCode==="timeout"?"timeout":"empty_page"}:{}},completionStatus:"serp_only",problem:null,resultQuality:Le?"partial":"complete",degradedResult:!!Le,degradationReasons:[],retryRecommended:!!Le,serpCompleteness:Mo},totalQuestions:0,surface:"web",aiOverview:kt,aiMode:Nr(I,e.includeAllSerpFeatures),...Lt?{fullSerpFeatures:Lt}:{},whatPeopleSaying:qt,tree:[],flat:[],videos:Ct,forums:Ot,organicResults:je,localPack:V,entityIds:Pr(I,V),stats:{seed:e.query,totalQuestions:0,maxDepthReached:0,durationMs:Ht,errorCount:0}}}var rn="scraperlink~google-search-results-serp-scraper",xe="https://api.apify.com/v2";var M=class extends Error{constructor(r,o=null,n=!1,i=null){super(r);this.runId=o;this.retrySafe=n;this.terminalStatus=i;this.name="ApifyGoogleRunError"}runId;retrySafe;terminalStatus};function De(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function ke(e){return typeof e=="string"&&e.trim()?e.trim():null}function on(e){try{return["http:","https:"].includes(new URL(e).protocol)}catch{return!1}}function nn(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{throw new Error("Apify searchResults is not valid JSON")}}function Mr(e,t){if(!Array.isArray(e)||e.length===0)throw new Error("Apify dataset contains no search results");let r=[];for(let[i,s]of e.entries()){let a=De(s);if(!a)throw new Error("Apify dataset contains an invalid row");let l=nn(a.searchResults??a),u=De(l),d=Array.isArray(l)?l:Array.isArray(u?.results)?u.results:Array.isArray(u?.organicResults)?u.organicResults:Array.isArray(u?.organic)?u.organic:u&&(u.position!==void 0||u.title!==void 0)?[u]:null;if(!d)throw new Error("Apify dataset search result shape is unsupported");let c=Number(a.page_number??u?.page_number??i+1);if(!Number.isInteger(c)||c<1||c>t)throw new Error("Apify dataset has an unexpected page number");r.push(...d.map(p=>({row:p,page:c})))}let o=r.map(({row:i,page:s},a)=>{let l=De(i),u=l?.position,d=ke(l?.title),c=ke(l?.url??l?.link);if(!l||!d||!c||!on(c)||u!==void 0&&(!Number.isInteger(u)||u<1))throw new Error(`Apify search result ${a+1} is missing a valid position, URL, or title`);let p=ke(l.description??l.snippet),b=typeof u=="number"?u:a%10+1;return{position:s>1&&b<=10?b+(s-1)*10:b,url:c,title:d,description:p}});if(o.length>t*10)throw new Error("Apify returned more results than requested");let n={page1:o.filter(i=>i.position<=10).length,page2:o.filter(i=>i.position>10).length};if(n.page1===0)throw new Error("Apify did not return the first result page");return{results:o,pageResultCounts:n}}async function et(e,t,r,o){let n=await r(e,{headers:{Authorization:`Bearer ${t}`},signal:o});if(!n.ok)throw new Error(`Apify API returned HTTP ${n.status}`);return n.json()}function bt(e){let t=De(De(e)?.data),r=ke(t?.id),o=ke(t?.status);if(!r||!o)throw new Error("Apify returned an invalid run receipt");return{id:r,status:o}}async function sn(e,t=fetch){let r=performance.now(),o=AbortSignal.timeout(9e4),n=e.signal?AbortSignal.any([e.signal,o]):o,i=e.runId,s=!1,a=null;try{if(!/^[A-Za-z0-9]+$/.test(i))throw new Error("Invalid Apify run ID");let l=bt(await et(`${xe}/actor-runs/${i}?waitForFinish=30`,e.token,t,n));for(;["READY","RUNNING","TIMING-OUT","ABORTING"].includes(l.status);)l=bt(await et(`${xe}/actor-runs/${i}?waitForFinish=30`,e.token,t,n));if(s=!0,a=l.status,l.status!=="SUCCEEDED")throw new Error(`Apify run ended with status ${l.status}`);let u=e.pages??1,d=await et(`${xe}/actor-runs/${i}/dataset/items?format=json`,e.token,t,n);return{query:e.query,...Mr(d,u),requestedPages:u,runId:i,elapsedMs:Math.round(performance.now()-r)}}catch(l){throw new M(l instanceof Error?l.message:String(l),i,s,a)}}async function Lr(e,t,r=fetch){let o=performance.now(),n=e.query.trim(),i=e.pages??1;if(!n||n.includes(`
|
|
78
|
-
`))throw new Error("Apify search requires one nonempty query");if(i!==1&&i!==2)throw new Error("Apify search supports one or two pages");let s=t.token.trim();if(!s)throw new Error("Apify API token is required");let a=t.maxChargeUsd??.01;if(!Number.isFinite(a)||a<=0)throw new Error("Invalid Apify charge cap");let l=AbortSignal.timeout(9e4),u=e.signal?AbortSignal.any([e.signal,l]):l,d=`${xe}/actors/${rn}/runs?maxTotalChargeUsd=${a}&restartOnError=false&waitForFinish=30`,c=null,p=!1,b=null;try{let v=await r(d,{method:"POST",headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json"},body:JSON.stringify({keyword:n,limit:i===2?"20":"10",page:1,proxy_location:"us",include_merged:!1}),signal:u});if(!v.ok)throw new Error(`Apify run start returned HTTP ${v.status}`);let f=bt(await v.json());if(c=f.id,p=!["READY","RUNNING","TIMING-OUT","ABORTING"].includes(f.status),p&&(b=f.status),f.status!=="SUCCEEDED"&&f.status!=="READY"&&f.status!=="RUNNING")throw new Error(`Apify run ended with status ${f.status}`);if(f.status==="SUCCEEDED"){let x=await et(`${xe}/actor-runs/${c}/dataset/items?format=json`,s,r,u);return{query:n,...Mr(x,i),requestedPages:i,runId:c,elapsedMs:Math.round(performance.now()-o)}}return{...await sn({runId:c,query:n,token:s,pages:i,signal:u},r),elapsedMs:Math.round(performance.now()-o)}}catch(v){throw v instanceof M?v:new M(v instanceof Error?v.message:String(v),c,p,b)}}var Hr="apify_google_serp",Fr="apify",an="apify_google_serp_scraperlink";async function Ur(e,t,r,o){let n=Sr();await Q({receiptId:e,costState:"estimated",units:t,unitType:n.unitType,amountUsdNanos:Ke(n,t),rateSource:n.source,providerProduct:n.providerProduct,billingTier:n.billingTier,billableEvent:n.billableEvent,measurementSource:"actor_run_succeeded",rateNumerator:n.numeratorUsdNanos,rateDenominator:n.denominatorUnits,ratePolicyVersion:n.policyVersion,rateEffectiveAt:n.effectiveAt,providerStatus:o,providerDurationMs:r})}async function $r(e){let t=performance.now(),r=await ie({runId:e.operationRunId,attemptNumber:e.attemptNumber,method:Hr,provider:Fr,parentAttemptId:e.parentAttemptId,edgeKind:e.edgeKind,retryKind:e.retryKind,normalizedFlags:{page:1,pages:e.options.pages??1,proxyLocation:"us"}}),o=await X({attemptId:r,provider:Fr,providerProduct:an,billingTier:"store_pay_per_event",accountScope:e.accountScope,method:Hr,providerStatus:"before_actor_start"}),n=null,i=null;try{return n=await Lr(e.options,{token:e.token},e.fetchImpl),await Y(o.id,n.runId),await Ur(o.id,n.requestedPages,n.elapsedMs,"succeeded_estimated"),{...n,attemptId:r}}catch(s){throw i=s,n?Object.assign(new M("Apify cost tracking failed after run completion",n.runId),{attemptId:r}):(s instanceof M&&s.runId&&(await Y(o.id,s.runId),s.terminalStatus==="SUCCEEDED"?await Ur(o.id,e.options.pages??1,Math.round(performance.now()-t),"succeeded_dataset_unavailable"):await yr({receiptId:o.id,units:e.options.pages??1,unitType:"page",providerStatus:"run_outcome_or_cost_pending"})),Object.assign(s instanceof Error?s:new Error(String(s)),{attemptId:r}))}finally{await ae({attemptId:r,status:i?e.options.signal?.aborted?"timed_out":"failed":"succeeded",errorCode:i?"apify_search_failed":null,durationMs:Math.round(performance.now()-t)})}}function Jr(e,t=e.requestedPages){let r=e.results.map(s=>{let a=new URL(s.url).hostname.replace(/^www\./,"");return{position:s.position,title:s.title,url:s.url,rawUrl:s.url,resolvedUrl:s.url,linkType:"plain",resolutionStatus:"not_needed",domain:a,cite:null,snippet:s.description,isRedditStyle:a==="reddit.com",inlineRating:null}}),o=t===2&&e.pageResultCounts.page2>0?2:1,n=t===2&&o===1,i=de(t,[{page:1,attempted:!0,captured:!0,resultCount:e.pageResultCounts.page1,requestOffset:0,providerRequestIdObserved:!0},...t===2?[{page:2,attempted:!0,captured:!n,resultCount:e.pageResultCounts.page2,requestOffset:10,providerRequestIdObserved:!0,...n?{failureCode:"empty_page"}:{}}]:[]]);return{seed:e.query,location:null,extractedAt:new Date().toISOString(),diagnostics:{phaseTimings:{providerConnectMs:e.elapsedMs,totalServerMs:e.elapsedMs},pagination:{requestedPages:t,capturedPages:o,page2Status:t===2?n?"failed":"captured":"not_requested",page1OrganicCount:e.pageResultCounts.page1,page2OrganicCount:e.pageResultCounts.page2},completionStatus:"serp_only",problem:null,resultQuality:n?"partial":"complete",degradedResult:n,degradationReasons:n?["page_two_missing"]:[],retryRecommended:!1,serpCompleteness:{pagination:i,features:{localPack:"not_requested",forums:"not_requested",videos:"not_requested",aiOverview:"not_requested",whatPeopleSaying:"not_requested"},queryIntegrity:ze({query:e.query,finalQuery:e.query,locationResolutionSource:"not_requested",outboundProviderMethod:"default_search"}),failureStage:null}},totalQuestions:0,surface:"web",aiOverview:{detected:!1,text:null,citations:[],shareUrl:null},aiMode:{detected:!1,text:null,citations:[]},whatPeopleSaying:[],tree:[],flat:[],videos:[],forums:[],organicResults:r,localPack:[],entityIds:{entities:[],kgIds:[],cids:[],gcids:[]},stats:{seed:e.query,totalQuestions:0,maxDepthReached:0,durationMs:e.elapsedMs,errorCount:0}}}var ln=12e3;async function Br(e){let t=await We(e.runId);if(!t||String(t.run.id)!==e.runId||Number(t.run.user_id)!==e.userId||t.run.tool!=="search_serp"||t.run.job_id!==e.jobId||t.attempts.length===0||!t.attempts.every(o=>o.run_id===e.runId&&o.provider==="\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061"&&["\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061_serp_native_proxy","\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061_serp_rest"].includes(String(o.method))&&["failed","timed_out","cancelled"].includes(String(o.status))&&typeof o.ended_at=="string"&&Number.isFinite(Date.parse(o.ended_at))&&o.duration_ms!=null&&Number.isSafeInteger(Number(o.duration_ms))&&Number(o.duration_ms)>=0))return null;let r=t.attempts[t.attempts.length-1].status;return r==="cancelled"?{errorCode:"request_aborted",httpStatus:408,terminalStatus:"cancelled"}:r==="timed_out"?{errorCode:"harvest_timeout",httpStatus:504,terminalStatus:"failed"}:{errorCode:"service_unavailable",httpStatus:503,terminalStatus:"failed"}}function Wr(e){return e.recency?er():e.mode==="full"&&e.pages===1?Ze():!!e.token||Ze()}async function ht(e){if(e.signal.throwIfAborted(),e.recency)return un(e);if(e.mode==="full")return dn(e);if(!e.token)return Gr(e);let t=performance.now(),r;for(let o=1;o<=2;o++){let n=AbortSignal.any([e.signal,AbortSignal.timeout(ln)]),i=e.pages;try{let s=await $r({options:{query:e.query,pages:i,signal:n},token:e.token,operationRunId:e.operationRunId,accountScope:e.accountScope,attemptNumber:o,...r?{parentAttemptId:r,edgeKind:"same_method_retry",retryKind:"same_method"}:{}});console.info(JSON.stringify({event:"serp_provider_succeeded",provider:"apify",operationRunId:e.operationRunId,attemptNumber:o,durationMs:s.elapsedMs,resultCount:s.results.length,requestedPages:e.pages,providerRequestedPages:s.requestedPages,deliveredPages:s.pageResultCounts.page2>0?2:1,runId:s.runId}));let a=Jr(s,e.pages);return a.stats.durationMs=Math.round(performance.now()-t),a.diagnostics.phaseTimings&&(a.diagnostics.phaseTimings.totalServerMs=a.stats.durationMs),{result:a,mode:"light",deliveryProvider:"apify",deliveredPages:s.pageResultCounts.page2>0?2:1}}catch(s){r=s&&typeof s=="object"&&"attemptId"in s?String(s.attemptId):void 0;let a=s instanceof M?s:null;if(console.warn(JSON.stringify({event:"serp_provider_failed",provider:"apify",operationRunId:e.operationRunId,attemptNumber:o,runId:a?.runId??null,requestedPages:e.pages,attemptPages:i,retrySafe:a?.retrySafe===!0,error:s instanceof Error?s.message:String(s)})),e.signal.aborted||!r||a?.retrySafe!==!0)throw s}}return Gr(e,r)}async function Gr(e,t){if(e.signal.throwIfAborted(),!Ze())throw new Error("\u0042\u0072\u0069\u0067\u0068\u0074 \u0044\u0061\u0074\u0061 SERP API fallback is not configured; set \u0042\u0052\u0049\u0047\u0048\u0054\u0044\u0041\u0054\u0041_SERP_API_KEY and \u0042\u0052\u0049\u0047\u0048\u0054\u0044\u0041\u0054\u0041_SERP_ZONE, or the SERP proxy username and password");let r=performance.now(),o={query:e.query,gl:"us",hl:"en",device:"desktop",pages:1,includeAllSerpFeatures:!1,includeLocalPack:!1,includeForums:!1,includeVideos:!1,includeAiOverview:!1,includeWhatPeopleSaying:!1,signal:e.signal};console.info(JSON.stringify({event:"serp_provider_fallback",provider:"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061",operationRunId:e.operationRunId,attemptNumber:3,requestedPages:e.pages,providerRequestedPages:1}));try{let n=await yt(o,process.env,fetch,void 0,t?{attemptNumber:3,parentAttemptId:t}:void 0);if(n.organicResults.length===0)throw new Error("Search returned no organic results");if(e.pages===2){n.diagnostics.pagination={requestedPages:2,capturedPages:1,page2Status:"unavailable",page1OrganicCount:n.organicResults.length,page2OrganicCount:0},n.diagnostics.resultQuality="partial",n.diagnostics.degradedResult=!0,n.diagnostics.degradationReasons=[...new Set([...n.diagnostics.degradationReasons??[],"page_two_missing"])],n.diagnostics.retryRecommended=!1;let i=n.diagnostics;i.serpCompleteness&&(i.serpCompleteness.pagination=de(2,i.serpCompleteness.pagination.evidence.filter(s=>s.page===1)),i.serpCompleteness.failureStage="pagination")}return n.stats.durationMs=Math.round(performance.now()-r),n.diagnostics.phaseTimings&&(n.diagnostics.phaseTimings.totalServerMs=n.stats.durationMs),console.info(JSON.stringify({event:"serp_provider_succeeded",provider:"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061",operationRunId:e.operationRunId,attemptNumber:3,durationMs:n.stats.durationMs,resultCount:n.organicResults.length,requestedPages:e.pages,providerRequestedPages:1,deliveredPages:1,resultQuality:n.diagnostics.resultQuality})),{result:n,mode:"light",deliveryProvider:"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061",deliveredPages:1}}catch(n){throw console.warn(JSON.stringify({event:"serp_provider_failed",provider:"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061",operationRunId:e.operationRunId,attemptNumber:3,error:n instanceof Error?n.message:String(n)})),n}}async function un(e){let t=await Fe({...e.physicalFactory?{physicalExecution:await e.physicalFactory()}:{},query:e.query,gl:"us",hl:"en",device:"desktop",pages:e.pages,recency:e.recency,serpOnly:!0,forceManagedSerp:!0,maxAttempts:2,proxyMode:"none",maxQuestions:1,depth:1,headless:!0,format:"json",outputDir:"/tmp/paa-output-api",softDeadlineMs:Date.now()+23e4,signal:e.signal,onAttemptEvent:e.onAttemptEvent});if(t.organicResults.length===0)throw new Error("Search returned no organic results");let r=t.diagnostics.pagination?.capturedPages===2?2:1;if(e.pages===2&&r===1&&(t.diagnostics.resultQuality="partial",t.diagnostics.degradedResult=!0,t.diagnostics.degradationReasons=["page_two_missing"],t.diagnostics.retryRecommended=!0),e.mode==="full"){let o=Object.fromEntries(["localPack","forums","videos","aiOverview","aiMode","whatPeopleSaying","entityIds","paaPreview","topStories"].map(n=>[n,"unsupported"]));t.fullSerpFeatures={status:o,paaPreview:[],additional:[],pages:[]}}return{result:t,mode:e.mode==="full"?"full":"light",deliveryProvider:"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061",deliveredPages:r}}async function dn(e){if(e.pages===2){let t=await ht({...e,mode:"light",pages:2}),r=Object.fromEntries(["localPack","forums","videos","aiOverview","aiMode","whatPeopleSaying","entityIds","paaPreview","topStories"].map(n=>[n,"unsupported"]));t.result.fullSerpFeatures={status:r,paaPreview:[],additional:[],pages:[]};let o=t.result.diagnostics;return o.serpCompleteness&&(o.serpCompleteness.features={localPack:"unsupported",forums:"unsupported",videos:"unsupported",aiOverview:"unsupported",whatPeopleSaying:"unsupported"}),{...t,mode:"full"}}return cn({...e,mode:"full"})}async function cn(e){let t=performance.now(),r=e.mode==="full",o={query:e.query,gl:"us",hl:"en",device:"desktop",pages:1,...e.recency?{recency:e.recency}:{},includeAllSerpFeatures:r,includeLocalPack:r,includeForums:r,includeVideos:r,includeAiOverview:r,includeWhatPeopleSaying:r,signal:e.signal},n=await yt(o);if(n.organicResults.length===0)throw new Error("Search returned no organic results");return n.stats.durationMs=Math.round(performance.now()-t),n.diagnostics.phaseTimings&&(n.diagnostics.phaseTimings.totalServerMs=n.stats.durationMs),{result:n,mode:r?"full":"light",deliveryProvider:"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061",deliveredPages:n.diagnostics.pagination?.capturedPages===2?2:1}}import{randomUUID as ao}from"crypto";var zr="2026-10-10-operation-final-settlements.1";async function Vr(e){let t=async()=>{let[r,o,n]=await Promise.all([e.execute("SELECT sql FROM sqlite_master WHERE name='operation_final_settlements'"),e.execute("PRAGMA index_info(operation_final_settlement_key)"),e.execute({sql:"SELECT 1 FROM schema_migrations WHERE version=?",args:[zr]})]),i=String(r.rows[0]?.sql??"").replace(/\s+/g," ");return n.rows.length===1&&o.rows.map(s=>s.name).join(",")==="debit_key"&&i.includes("run_id TEXT NOT NULL REFERENCES operation_runs(id)")&&i.includes("user_id INTEGER NOT NULL CHECK (user_id > 0)")&&i.includes("final_amount_mc INTEGER NOT NULL CHECK (final_amount_mc >= 0)")&&i.includes("receipt_json TEXT NOT NULL CHECK (json_valid(receipt_json))")};if(!await t()){try{await e.batch([`CREATE TABLE IF NOT EXISTS operation_final_settlements (
|
|
79
|
-
id TEXT NOT NULL PRIMARY KEY,
|
|
80
|
-
run_id TEXT NOT NULL REFERENCES operation_runs(id),
|
|
81
|
-
user_id INTEGER NOT NULL CHECK (user_id > 0),
|
|
82
|
-
debit_key TEXT NOT NULL REFERENCES operation_debit_plans(debit_key),
|
|
83
|
-
final_amount_mc INTEGER NOT NULL CHECK (final_amount_mc >= 0),
|
|
84
|
-
refund_operation TEXT NOT NULL,source_surface TEXT NOT NULL,
|
|
85
|
-
receipt_json TEXT NOT NULL CHECK (json_valid(receipt_json)),
|
|
86
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
87
|
-
)`,"CREATE UNIQUE INDEX IF NOT EXISTS operation_final_settlement_key ON operation_final_settlements(debit_key)",{sql:"INSERT OR IGNORE INTO schema_migrations(version) VALUES (?)",args:[zr]}],"write")}catch(r){if(!await t().catch(()=>!1))throw r}if(!await t())throw Error("Final settlement schema is incomplete")}}var pn="(CAST(strftime('%s','now') AS INTEGER)*1000)";async function Kr(e){let{claim:t,gate:r}=e;if(we({userId:t.userId,tool:r.tool,jobId:r.jobId},r),!Number.isSafeInteger(e.amountMc)||e.amountMc<0||!e.key||!e.refundOperation||!e.sourceSurface)throw Error("Invalid final settlement input");let o=h({key:e.key,amountMc:e.amountMc,refundOperation:e.refundOperation,sourceSurface:e.sourceSurface,material:e.material});if(Buffer.byteLength(o)>16*1024*1024)throw Error("Final settlement material exceeds budget");let n=m();await Vr(n),await K({userId:t.userId,runId:t.runId});let i=Ut(t.userId,r.jobId),s="settlement:"+O(`${t.runId}\0${e.key}`),a=`EXISTS(SELECT 1 FROM operation_runs r JOIN operation_executions x ON x.run_id=r.id
|
|
88
|
-
WHERE r.id=? AND r.user_id=? AND r.tool=? AND r.job_id=? AND r.status=? AND x.claim_token=? AND x.phase=? AND x.expires_at_ms>${pn}) AND (${r.sql}) AND (${i.sql})`,l=[t.runId,t.userId,r.tool,r.jobId,e.recovery?"unknown":"running",t.token,e.recovery?"unknown":"effects_started",...r.args,...i.args];try{await n.execute({sql:`INSERT OR IGNORE INTO operation_final_settlements(id,run_id,user_id,debit_key,final_amount_mc,refund_operation,source_surface,receipt_json)
|
|
89
|
-
SELECT ?,?,?,?,?,?,?,? WHERE (${a}) AND EXISTS(SELECT 1 FROM operation_debit_plans p JOIN billing_debits d ON d.idempotency_key=p.debit_key
|
|
90
|
-
WHERE p.run_id=? AND p.debit_key=? AND p.refund_operation=? AND p.source_surface=? AND d.user_id=? AND d.status='applied' AND ?>=0 AND ?<=p.amount_mc)`,args:[s,t.runId,t.userId,e.key,e.amountMc,e.refundOperation,e.sourceSurface,o,...l,t.runId,e.key,e.refundOperation,e.sourceSurface,t.userId,e.amountMc,e.amountMc]})}catch{}let u=(await n.execute({sql:`SELECT s.* FROM operation_final_settlements s WHERE s.id=? AND s.run_id=? AND s.user_id=? AND (${a})`,args:[s,t.runId,t.userId,...l]})).rows[0];if(!u||u.receipt_json!==o)throw Error("final_settlement_plan_unknown_or_conflicting");return{...t,mode:e.recovery?"compensate":"execute",settlementPlanId:s}}function tt(e){return{...e,sql:`EXISTS(SELECT 1 FROM operation_final_settlements s JOIN billing_events b ON b.user_id=s.user_id
|
|
91
|
-
WHERE s.run_id=? AND s.user_id=? AND s.debit_key=? AND b.billing_class='wallet_hold_settlement' AND b.status='settled'
|
|
92
|
-
AND b.source_surface=s.source_surface AND b.amount_mc=s.final_amount_mc AND json_extract(b.metadata,'$.debitIdempotencyKey')=s.debit_key
|
|
93
|
-
AND json_extract(b.metadata,'$.refundOperation')=s.refund_operation)`,args:[e.runId,e.userId,e.key]}}var Xr="2026-10-10-outbound-delivery.1";async function rt(e){let t=async()=>{let r=(await e.execute("SELECT sql FROM sqlite_master WHERE name='outbound_deliveries'")).rows[0],o=(await e.execute({sql:"SELECT 1 FROM schema_migrations WHERE version=?",args:[Xr]})).rows,n=String(r?.sql??"").replace(/\s+/g," "),i=(await e.execute("PRAGMA index_info(outbound_delivery_job)")).rows.map(s=>s.name).join(",");return o.length===1&&i==="job_id,user_id"&&n.includes("request_json TEXT NOT NULL CHECK (json_valid(request_json))")&&n.includes("expires_at_ms INTEGER NOT NULL")&&n.includes("'accepted','unknown','expired','unavailable'")};if(!await t()){try{await e.batch([`CREATE TABLE IF NOT EXISTS outbound_deliveries (
|
|
94
|
-
id TEXT NOT NULL PRIMARY KEY,user_id INTEGER NOT NULL CHECK (user_id > 0),job_id TEXT NOT NULL,
|
|
95
|
-
parent_run_id TEXT NOT NULL REFERENCES operation_runs(id),request_json TEXT NOT NULL CHECK (json_valid(request_json)),
|
|
96
|
-
state TEXT NOT NULL CHECK (state IN ('requested','frozen','sending','accepted','unknown','expired','unavailable')),
|
|
97
|
-
expires_at_ms INTEGER NOT NULL,payload_json TEXT CHECK (payload_json IS NULL OR json_valid(payload_json)),payload_sha256 TEXT,
|
|
98
|
-
send_nonce TEXT,send_token TEXT,http_status INTEGER,receipt_json TEXT CHECK (receipt_json IS NULL OR json_valid(receipt_json)),
|
|
99
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now')),updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
100
|
-
)`,"CREATE UNIQUE INDEX IF NOT EXISTS outbound_delivery_job ON outbound_deliveries(job_id,user_id)",{sql:"INSERT OR IGNORE INTO schema_migrations(version) VALUES (?)",args:[Xr]}],"write")}catch(r){if(!await t().catch(()=>!1))throw r}if(!await t())throw Error("Delivery schema is incomplete")}}var ee=class extends Error{};var _e="(CAST(strftime('%s','now') AS INTEGER)*1000)",Pe=e=>`delivery:${e}`,te=e=>h(e);async function j(e,t){let r=m();await rt(r);let o=(await r.execute({sql:`SELECT *,${_e} AS now_ms FROM outbound_deliveries WHERE id=? AND user_id=?`,args:[e,t]})).rows[0];if(!o)return null;let n=JSON.parse(String(o.request_json));if(n.id!==e||n.userId!==t||n.jobId!==o.job_id||n.parentRunId!==o.parent_run_id)throw Error("Delivery request conflicts");return{...n,state:String(o.state),expiresAtMs:Number(o.expires_at_ms),nowMs:Number(o.now_ms),payloadJson:o.payload_json==null?null:String(o.payload_json),payloadSha256:o.payload_sha256==null?null:String(o.payload_sha256),sendNonce:o.send_nonce==null?null:String(o.send_nonce),sendToken:o.send_token==null?null:String(o.send_token),httpStatus:o.http_status==null?null:Number(o.http_status),receiptJson:o.receipt_json==null?null:String(o.receipt_json)}}async function Yr(e,t,r){if(we({userId:e.userId,tool:r.tool,jobId:e.jobId},r),!e.id||!e.url||!["paa-direct","paa-queue"].includes(e.profile)||!Number.isSafeInteger(e.userId)||e.userId<=0||t.runId!==e.parentRunId||t.userId!==e.userId||!/^[a-f0-9]{64}$/.test(e.fingerprint))throw Error("Invalid delivery request");let o=m();await rt(o);let n;try{await o.execute({sql:`INSERT OR IGNORE INTO outbound_deliveries(id,user_id,job_id,parent_run_id,request_json,state,expires_at_ms)
|
|
101
|
-
SELECT ?,?,?,?,?,'requested',${_e}+? WHERE (${r.sql}) AND EXISTS(SELECT 1 FROM operation_runs r JOIN operation_executions x ON x.run_id=r.id
|
|
102
|
-
WHERE r.id=? AND r.user_id=? AND r.tool=? AND r.job_id=? AND r.status='running' AND x.phase='claimed' AND x.claim_token=? AND x.expires_at_ms>${_e})`,args:[e.id,e.userId,e.jobId,e.parentRunId,te(e),864e5,...r.args,t.runId,t.userId,r.tool,r.jobId,t.token]})}catch(s){n=s}let i=await j(e.id,e.userId);if(!i||te($(i))!==te(e))throw n??Error("Delivery request receipt is unavailable or conflicting");return i}function $(e){return{id:e.id,userId:e.userId,jobId:e.jobId,parentRunId:e.parentRunId,url:e.url,profile:e.profile,fingerprint:e.fingerprint}}async function Qr(e,t,r){let o;try{o=h(t)}catch{throw new ee("Delivery payload cannot be serialized")}let n=O(o);if(Buffer.byteLength(o)>16777216)throw new ee("Delivery payload exceeds budget");we({userId:e.userId,tool:r.tool,jobId:e.jobId},r);let i;try{await m().execute({sql:`UPDATE outbound_deliveries SET state='frozen',payload_json=?,payload_sha256=?,updated_at=datetime('now') WHERE id=? AND user_id=? AND request_json=? AND state='requested' AND expires_at_ms>${_e} AND (${r.sql})`,args:[o,n,e.id,e.userId,te($(e)),...r.args]})}catch(a){i=a}let s=await j(e.id,e.userId);if(!s||s.payloadJson!==o||s.payloadSha256!==n)throw i??Error("Delivery payload receipt is unavailable or conflicting");return s}function Oe(e,t,r,o){return{userId:e.userId,tool:"paa_callback",jobId:e.jobId,sql:`(${t.sql}) AND EXISTS(SELECT 1 FROM outbound_deliveries d WHERE d.id=? AND d.user_id=? AND d.request_json=? AND d.state=? AND d.payload_json=? AND d.payload_sha256=? ${r==="accepted"?"":`AND d.expires_at_ms>${_e}`} ${o?"AND d.send_nonce=?":""})`,args:[...t.args,e.id,e.userId,te($(e)),r,e.payloadJson,e.payloadSha256,...o?[o]:[]]}}async function Zr(e,t,r,o){let n=Oe(e,o,"frozen"),i=se(t,{tool:n.tool,jobId:e.jobId}),s;try{await m().execute({sql:`UPDATE outbound_deliveries SET state='sending',send_nonce=?,send_token=?,updated_at=datetime('now') WHERE id=? AND user_id=? AND state='frozen' AND (${n.sql}) AND (${i.sql})`,args:[r,t.token,e.id,e.userId,...n.args,...i.args]})}catch(l){s=l}let a=await j(e.id,e.userId);if(!a||a.state!=="sending"||a.sendNonce!==r||a.sendToken!==t.token||a.payloadSha256!==e.payloadSha256)throw s??Error("Delivery send permission is unavailable");return a}async function eo(e,t,r){let o=Oe(e,r,"sending",e.sendNonce),n=se(t,{tool:o.tool,jobId:e.jobId});return(await m().execute({sql:`SELECT 1 WHERE (${o.sql}) AND (${n.sql})`,args:[...o.args,...n.args]})).rows.length===1}async function to(e,t){if(!e.sendNonce||!e.sendToken||!e.payloadSha256||t<200||t>=300)throw Error("Invalid endpoint acceptance");let r=h({deliveryId:e.id,idempotencyKey:e.id,payloadSha256:e.payloadSha256,httpStatus:t}),o=m(),n;try{await o.execute({sql:`UPDATE outbound_deliveries SET state='accepted',http_status=?,receipt_json=?,updated_at=datetime('now') WHERE id=? AND user_id=? AND state IN ('sending','unknown') AND send_nonce=? AND send_token=? AND payload_sha256=? AND request_json=?
|
|
103
|
-
AND EXISTS(SELECT 1 FROM operation_runs WHERE id=? AND user_id=? AND tool='paa_callback' AND job_id=?)`,args:[t,r,e.id,e.userId,e.sendNonce,e.sendToken,e.payloadSha256,te($(e)),Pe(e.id),e.userId,e.jobId]})}catch(s){n=s}let i=await j(e.id,e.userId);if(!i||i.state!=="accepted"||i.receiptJson!==r)throw n??Error("Endpoint acceptance receipt is unavailable");return i}async function vt(e){await m().execute({sql:"UPDATE outbound_deliveries SET state='unknown',updated_at=datetime('now') WHERE id=? AND user_id=? AND request_json=? AND state='frozen' AND send_nonce IS NULL AND EXISTS(SELECT 1 FROM operation_executions x JOIN operation_runs o ON o.id=x.run_id WHERE o.id=? AND o.user_id=? AND o.tool='paa_callback' AND o.job_id=? AND x.phase IN ('effects_started','unknown'))",args:[e.id,e.userId,te($(e)),Pe(e.id),e.userId,e.jobId]})}async function ro(e){await m().execute({sql:"UPDATE outbound_deliveries SET state='unknown',updated_at=datetime('now') WHERE id=? AND user_id=? AND state='sending' AND send_nonce=?",args:[e.id,e.userId,e.sendNonce]})}async function ot(e,t,r){await m().execute({sql:`UPDATE outbound_deliveries SET state=?,updated_at=datetime('now') WHERE id=? AND user_id=? AND state IN ('requested','frozen') AND send_nonce IS NULL ${t==="expired"?`AND expires_at_ms<=${_e}`:""} ${r?`AND (${r.sql})`:""}`,args:[t,e.id,e.userId,...r?r.args:[]]})}async function L(e){let t=e.state==="sending"?"unknown":e.state;return await m().execute({sql:"UPDATE jobs SET options=json_set(options,'$.callbackDeliveryState',?,'$.callbackDeliveryId',?,'$.callbackDeliveryExpiresAtMs',?) WHERE id=? AND user_id=? AND callback_url=? AND json_extract(options,'$.callbackDeliveryProtocol')=1",args:[t,e.id,e.expiresAtMs,e.jobId,e.userId,e.url]}).catch(()=>{}),{state:t,deliveryId:e.id,expiresAtMs:e.expiresAtMs,...e.httpStatus?{httpStatus:e.httpStatus}:{}}}async function oo(e=25){let t=m();return await rt(t),(await t.execute({sql:"SELECT d.id,d.user_id,d.job_id FROM outbound_deliveries d JOIN jobs j ON j.id=d.job_id AND j.user_id=d.user_id WHERE (d.state IN ('requested','frozen') OR (d.state='accepted' AND EXISTS(SELECT 1 FROM operation_executions x WHERE x.run_id='delivery:'||d.id AND x.phase<>'published'))) AND j.status IN ('done','failed','cancelled') AND json_extract(j.options,'$.executionState')='finalized' ORDER BY d.created_at LIMIT ?",args:[Math.max(1,Math.min(100,Math.floor(e)))]})).rows.map(r=>({id:String(r.id),userId:Number(r.user_id),jobId:String(r.job_id)}))}function Et(e){if(!e.callback_url||e.options.callbackDeliveryProtocol!==1)return null;let t=e.options.executionProtocol===1&&e.options.directCompletionProtocol===1&&e.options.executionOwner==="direct",r=e.options.queueExecutionProtocol===1&&e.options.executionOwner==="cron";if(!t&&!r)throw Error("Callback parent profile is unavailable");return{id:`paa-callback:${e.id}`,userId:e.user_id,jobId:e.id,parentRunId:t?`paa-execution:${e.id}`:`harvest:${e.id}`,url:e.callback_url,profile:t?"paa-direct":"paa-queue",fingerprint:String(e.options.requestFingerprint)}}async function no(e,t,r){let o=Et(e);o&&await Yr(o,t,{...r,sql:`(${r.sql}) AND EXISTS(SELECT 1 FROM jobs WHERE id=? AND user_id=? AND callback_url=? AND json_extract(options,'$.callbackDeliveryProtocol')=1 AND json_extract(options,'$.requestFingerprint')=?)`,args:[...r.args,e.id,e.user_id,e.callback_url,o.fingerprint]})}function so(e,t){let r=Et(e);return r?{...t,sql:`(${t.sql}) AND EXISTS(SELECT 1 FROM outbound_deliveries WHERE id=? AND user_id=? AND request_json=? AND state='requested')`,args:[...t.args,r.id,r.userId,h(r)]}:t}async function io(e,t){let r=await S(e,t);if(!r?.callback_url)return{kind:"none"};let o=Et(r);if(!o)return{kind:"unavailable"};let n=await j(o.id,r.user_id);if(!n||h($(n))!==h(o))return{kind:"unavailable"};if(!["done","failed","cancelled"].includes(r.status)||r.options.executionState!=="finalized"||r.options.holdState!=="settled"||!r.options.syncCapturedAt)return{kind:"pending",record:n};let i=await T(o.parentRunId,r.user_id,o.profile==="paa-direct"?"harvest_paa":"search_serp",r.id);if(!i||i.phase!=="published")return{kind:"pending",record:n};let s=o.profile==="paa-direct"?i.flags:i.flags.intent;if(!s||s.callbackUrl!==o.url||s.requestFingerprint!==o.fingerprint||s.userId!==r.user_id||s.jobId!==r.id||r.query!==s.options?.query||h(Object.fromEntries(Object.keys(s.options).map(p=>[p,r.options[p]])))!==h(s.options)||s.hold?.userId!==r.user_id||s.hold.key!==r.options.billingDebitKey||s.hold.amountMc!==r.options.billingHoldMc||r.status!==r.options.syncTerminalStatus||r.options.syncFinalAmountMc!==r.options.billingFinalAmountMc)return{kind:"unavailable"};if(r.options.syncRequiresPhysicalReceipt===1&&(await oe(o.parentRunId,r.user_id)).length===0)return{kind:"pending",record:n};if(await K({runId:o.parentRunId,userId:r.user_id}))return{kind:"pending",record:n};let a=O(h({result:r.result,error:r.publicError,httpStatus:r.options.syncHttpStatus,requiresPhysical:r.options.syncRequiresPhysicalReceipt})),l={jobId:r.id,requestFingerprint:s.requestFingerprint,captureSha256:a,status:r.status},u=h({...l,amountMc:Number(r.options.syncFinalAmountMc),physicalOutcome:"terminated"}),d=tt({userId:r.user_id,jobId:r.id,tool:o.profile==="paa-direct"?"harvest_paa":"search_serp",runId:o.parentRunId,key:s.hold.key}),c={...d,sql:`(${d.sql}) AND EXISTS(SELECT 1 FROM jobs j JOIN operation_runs r ON r.job_id=j.id AND r.user_id=j.user_id JOIN operation_executions x ON x.run_id=r.id JOIN operation_final_settlements s ON s.run_id=r.id AND s.user_id=r.user_id
|
|
104
|
-
WHERE j.id=? AND j.user_id=? AND r.id=? AND x.phase='published' AND r.status=x.result_status AND x.result_json=? AND j.status=?
|
|
105
|
-
AND j.callback_url=? AND json_extract(j.options,'$.requestFingerprint')=? AND r.request_fingerprint=? AND j.query=json_extract(r.normalized_flags_json,?)
|
|
106
|
-
AND NOT EXISTS(SELECT 1 FROM json_each(r.normalized_flags_json,?) v WHERE NOT EXISTS(SELECT 1 FROM json_each(j.options) actual WHERE actual.key=v.key AND actual.type=v.type AND actual.value IS v.value))
|
|
107
|
-
AND json_extract(j.options,'$.callbackDeliveryProtocol')=1 AND json_extract(j.options,'$.executionState')='finalized' AND json_extract(j.options,'$.holdState')='settled'
|
|
108
|
-
AND json_extract(j.options,'$.syncFinalAmountMc')=? AND json_extract(j.options,'$.billingFinalAmountMc')=? AND json_extract(j.options,'$.syncTerminalStatus')=? AND json(j.result) IS json(?) AND j.public_error_json IS ?
|
|
109
|
-
AND s.debit_key=? AND s.final_amount_mc=? AND json_extract(s.receipt_json,'$.material.captureSha256')=?)`,args:[...d.args,r.id,r.user_id,o.parentRunId,u,r.status,o.url,o.fingerprint,i.fingerprint,o.profile==="paa-direct"?"$.options.query":"$.intent.options.query",o.profile==="paa-direct"?"$.options":"$.intent.options",Number(r.options.syncFinalAmountMc),Number(r.options.syncFinalAmountMc),r.status,r.result==null?null:h(r.result),r.publicError==null?null:JSON.stringify(r.publicError),s.hold.key,Number(r.options.syncFinalAmountMc),a]};return{kind:"ready",job:r,record:n,domain:c}}var z=e=>`harvest:${e}`,lo=e=>e.profile==="direct"?"executionProtocol":e.profile==="queue"?"queueExecutionProtocol":"syncExecutionProtocol";function fe(e,t="'running'"){let r=h(e.options),o=Object.keys(JSON.parse(r)).sort();if(o.some(n=>!/^[a-zA-Z][a-zA-Z0-9]*$/.test(n)))throw Error("Invalid synchronous option key");return{userId:e.userId,tool:e.tool,jobId:e.jobId,sql:`EXISTS(SELECT 1 FROM jobs j WHERE j.id=? AND j.user_id=? AND j.status IN (${t}) AND json_extract(j.options,'$.${lo(e)}')=1 AND j.query=? AND j.callback_url IS ? ${e.profile==="direct"?"AND json_extract(j.options,'$.executionOwner')='direct' AND json_extract(j.options,'$.directCompletionProtocol')=1 AND json_extract(j.options,'$.paaLeaseToken')=? AND json_extract(j.options,'$.executionRunId')=?":e.profile==="queue"?"AND json_extract(j.options,'$.executionOwner')='cron'":""} AND json_extract(j.options,'$.requestFingerprint')=? AND json_extract(j.options,'$.billingHoldMc')=? ${o.map(()=>"AND json_extract(j.options,?) IS json_extract(?,?)").join(" ")})`,args:[e.jobId,e.userId,String(e.options.query),e.callbackUrl??null,...e.profile==="direct"?[e.recordToken,`paa-execution:${e.jobId}`]:[],e.requestFingerprint,e.hold.amountMc,...o.flatMap(n=>[`$.${n}`,r,`$.${n}`])]}}function wt(e){let t=JSON.parse(h(e));if(!t.jobId||!Number.isSafeInteger(t.userId)||t.userId<=0||!["harvest_paa","search_serp"].includes(t.tool)||!Number.isSafeInteger(t.deadlineAt)||!Number.isSafeInteger(t.hold.amountMc)||t.hold.amountMc<=0||t.hold.userId!==t.userId||t.hold.key!==(t.profile==="queue"?`serp-search:${t.jobId}:hold`:`harvest-sync:${t.jobId}:charge`)||!/^[a-f0-9]{64}$/.test(t.requestFingerprint)||!t.refundOperation||!t.sourceSurface)throw Error("Invalid synchronous funded intent");if(t.profile==="queue"&&(t.tool!=="search_serp"||t.options.serpOnly!==!0||t.deadlineAt!==0||!Number.isSafeInteger(t.budgetMs)||t.budgetMs<1e3||t.budgetMs>36e5||t.hold.operation!=="serp"||t.refundOperation!=="serp_refund"||t.sourceSurface!=="serp_search"||t.hold.description!==`SERP search: ${t.options.query}`.slice(0,500)))throw Error("Invalid queued compatibility intent");return t}async function uo(e){let t=await T(z(e.id),e.user_id,e.options.serpOnly===!0?"search_serp":"harvest_paa",e.id);if(!t||t.flags.syncExecutionProtocol!==1||!t.flags.intent)return null;let r=wt(t.flags.intent);if((r.profile==="queue"?e.options.queueExecutionProtocol:e.options.syncExecutionProtocol)!==1||r.jobId!==e.id||r.userId!==e.user_id||t.fingerprint!==r.requestFingerprint)throw Error("Synchronous intent receipt conflicts");return r}async function W(e,t="held"){let r=e.options.serpOnly===!0?2:mt;return{status:503,headers:{"Retry-After":String(r)},body:{job_id:e.id,status:"running",saved_status:e.status,...B({errorCode:"response_lost",retryable:!0,chargeStatus:t==="held"?"refund_pending":void 0,details:{retry_guidance:`Wait at least ${r} seconds before retrying this exact request with the same idempotencyKey or reading the returned job. Saved content and settlement resume without another acquisition.`}}),executionState:"unknown",hold_state:t,status_tool:e.options.queueExecutionProtocol===1?"harvest_paa_status":e.options.serpOnly===!0?"search_serp":"harvest_paa_status",...e.result?{result:e.result}:{}}}}async function _n(e,t){await m().execute({sql:`UPDATE jobs SET options=json_set(options,'$.executionState','unknown','$.holdState',CASE WHEN json_extract(options,'$.billingSettledAt') IS NOT NULL THEN 'settled' ELSE 'held' END) WHERE id=? AND user_id=? AND json_extract(options,'$.${lo(e)}')=1 AND EXISTS(SELECT 1 FROM operation_executions x WHERE x.run_id=? AND x.claim_token=?)`,args:[e.jobId,e.userId,t.runId,t.token]})}async function nt(e,t,r,o,n,i=null,s=200,a=!0){if(!Number.isSafeInteger(o)||o<0||o>e.hold.amountMc)throw Error("Invalid captured synchronous charge");let l=r==null?null:h(r),u=i==null?null:JSON.stringify(i),d=fe(e),c;try{await m().execute({sql:`UPDATE jobs SET result=?,public_error_json=?,options=json_set(options,'$.syncCapturedAt',datetime('now'),'$.syncFinalAmountMc',?,'$.syncTerminalStatus',?,'$.syncHttpStatus',?,'$.syncRequiresPhysicalReceipt',?)
|
|
110
|
-
WHERE id=? AND user_id=? AND json_extract(options,'$.syncCapturedAt') IS NULL AND (${d.sql})
|
|
111
|
-
AND EXISTS(SELECT 1 FROM operation_runs r JOIN operation_executions x ON x.run_id=r.id WHERE r.id=? AND r.user_id=? AND x.claim_token=? AND x.phase IN ('effects_started','unknown') AND r.status IN ('running','unknown'))`,args:[l,u,o,n,s,a?1:0,e.jobId,e.userId,...d.args,t.runId,t.userId,t.token]})}catch(b){c=b}let p=await S(e.jobId,e.userId);if(!p?.options.syncCapturedAt||h({result:p.result})!==h({result:r==null?null:JSON.parse(l)})||p.options.syncFinalAmountMc!==o||p.options.syncTerminalStatus!==n||h({error:p.publicError})!==h({error:Wt(i)})||p.options.syncHttpStatus!==s||p.options.syncRequiresPhysicalReceipt!==(a?1:0))throw c??Error("synchronous_capture_receipt_unknown_or_conflicting");return p}async function it(e,t){return{status:t?200:Number(e.options.syncHttpStatus??200),body:{job_id:e.id,status:e.status,...e.result?{result:e.result}:{},...e.publicError?{...e.publicError,error:e.publicError.message,...e.options.holdState==="settled"&&e.options.billingFinalAmountMc===0?{charge_status:"refunded"}:{}}:{},...t?{replayed:!0}:{}}}}async function co(e,t){if(e.profile!==void 0||e.tool!=="search_serp"||e.options.serpOnly!==!0||e.options.mode!=="full"||e.options.pages!==1||e.options.recency||e.options.serpIdentity||t.runId!==z(e.jobId)||t.userId!==e.userId||await K({userId:t.userId,runId:t.runId})||(await oe(t.runId,t.userId)).length!==0)return null;let r=await Br({runId:t.runId,userId:t.userId,jobId:e.jobId});return r?{publicError:B({errorCode:r.errorCode,retryable:r.terminalStatus!=="cancelled"}),httpStatus:r.httpStatus,terminalStatus:r.terminalStatus}:null}async function st(e,t,r,o=!1){let n=await S(e.jobId,e.userId);if(!n?.options.syncCapturedAt)throw Error("Synchronous capture is not known");if(n.options.syncRequiresPhysicalReceipt===1&&(await oe(t.runId,t.userId)).length===0)throw Error("synchronous_physical_receipt_missing");if(await K({userId:e.userId,runId:t.runId}))throw Error("synchronous_physical_outcome_unknown");let i=Number(n.options.syncFinalAmountMc),s=String(n.options.syncTerminalStatus);if(!["done","failed","cancelled"].includes(s))throw Error("Invalid synchronous terminal receipt");let a={jobId:n.id,requestFingerprint:e.requestFingerprint,captureSha256:O(h({result:n.result,error:n.publicError,httpStatus:n.options.syncHttpStatus,requiresPhysical:n.options.syncRequiresPhysicalReceipt})),status:s},l=fe(e,"'running','done','failed','cancelled'"),u={...l,sql:`(${l.sql}) AND EXISTS(SELECT 1 FROM jobs WHERE id=? AND user_id=? AND json_extract(options,'$.syncCapturedAt') IS NOT NULL AND json_extract(options,'$.syncFinalAmountMc')=? AND json_extract(options,'$.syncTerminalStatus')=? AND json(result) IS json(?) AND public_error_json IS ? AND json_extract(options,'$.syncHttpStatus')=? AND json_extract(options,'$.syncRequiresPhysicalReceipt')=?)`,args:[...l.args,n.id,n.user_id,i,s,n.result==null?null:h(n.result),n.publicError==null?null:JSON.stringify(n.publicError),Number(n.options.syncHttpStatus),Number(n.options.syncRequiresPhysicalReceipt)]},d=await Kr({claim:t,recovery:r,gate:u,key:e.hold.key,amountMc:i,refundOperation:e.refundOperation,sourceSurface:e.sourceSurface,material:a});if((await cr(e.userId,e.hold.key,e.sourceSurface)??await ur(e.userId,e.hold.key,i,e.refundOperation,"Synchronous harvest settlement",e.sourceSurface,d)).final_amount_mc!==i)throw Error("Synchronous settlement receipt conflicts");let p=tt({userId:n.user_id,tool:e.tool,jobId:n.id,runId:t.runId,key:e.hold.key}),b=se(t,{tool:e.tool,jobId:n.id,recovery:r}),v;try{await m().execute({sql:`UPDATE jobs SET status=?,completed_at=COALESCE(completed_at,datetime('now')),options=json_set(options,'$.executionState','finalized','$.holdState','settled','$.physicalOutcome','terminated','$.billingSettledAt',COALESCE(json_extract(options,'$.billingSettledAt'),datetime('now')),'$.billingFinalAmountMc',?${e.profile==="direct"?",'$.billedMc',?":""}) WHERE id=? AND user_id=? AND (${u.sql}) AND (${b.sql}) AND (${p.sql})`,args:[s,i,...e.profile==="direct"?[i]:[],n.id,n.user_id,...u.args,...b.args,...p.args]})}catch(H){v=H}let f=await S(n.id,n.user_id);if(!f||f.status!==s||f.options.billingFinalAmountMc!==i||f.options.holdState!=="settled"||h({result:f.result})!==h({result:n.result}))throw v??Error("synchronous_publication_receipt_unknown");let E={status:r?"unknown":s==="done"?"succeeded":s,json:h({...a,amountMc:i,physicalOutcome:"terminated"})};if(!(r?await Je(t,E,p):await $e(t,E)))throw Error("Synchronous execution receipt publication unknown");return it(f,o)}async function St(e){if(e.options.syncExecutionProtocol!==1&&e.options.queueExecutionProtocol!==1)return null;let t=await uo(e);if(!t)return e.options.queueExecutionProtocol===1||await Ge(z(e.id),e.user_id)?W(e,"unconfirmed"):null;let r=await T(z(e.id),e.user_id,t.tool,e.id);if(r?.phase==="published"&&e.options.holdState==="settled")return it(e,!0);if(r?.phase==="claimed"&&r.expiresAtMs<=r.nowMs&&e.status==="running"&&!e.options.syncCapturedAt)return null;if(r?.phase==="claimed"||r?.phase==="effects_started"&&r.expiresAtMs>r.nowMs)return{status:409,headers:{"Retry-After":String(t.tool==="harvest_paa"?mt:2)},body:{job_id:e.id,error:"This request is already running under the supplied Idempotency-Key.",errorCode:"idempotency_in_progress",retryable:!0,...e.result?{result:e.result}:{}}};let o=await Ue(z(e.id),e.user_id);if(!o)return W(e);try{if(!e.options.syncCapturedAt){let n=await co(t,o);n&&await nt(t,o,null,0,n.terminalStatus,n.publicError,n.httpStatus,!1)}return await st(t,o,!0,!0)}catch{return W(await S(e.id,e.user_id)??e,e.options.holdState==="settled"?"settled":"held")}}async function po(e,t,r=!0){let o=await pt(t.userId,t.hold.key);if(!o||o.status!=="applied"){if(!r)throw Error("Original applied hold is unavailable");let n=await lr(t.userId,t.hold.amountMc,t.hold.operation,t.hold.description,t.hold.key);if(!n.ok)return{status:402,body:{job_id:t.jobId,error:"Insufficient balance",error_code:"insufficient_balance",balance_mc:n.balance_mc,required_mc:t.hold.amountMc}}}return await dr(e,{hold:t.hold,label:t.profile==="queue"?"original-queue-hold":"original-sync-hold",refundOperation:t.refundOperation,sourceSurface:t.sourceSurface,tool:t.tool,jobId:t.jobId}),null}async function mo(e,t,r){let o=wt(e),n,i=!1,s=!1,a=!1,l=await S(o.jobId,o.userId);try{let u=await uo(l);if(u){if(u.requestFingerprint!==o.requestFingerprint)throw Error("Synchronous request conflicts");o=u}else if(o.profile==="queue"||await Ge(z(o.jobId),o.userId)||(await pt(o.userId,o.hold.key))?.status==="applied")return W(l,"unconfirmed");if(o.profile!=="queue"&&Date.now()>=o.deadlineAt)return W(l,"unconfirmed");let d=await Ae({id:z(o.jobId),userId:o.userId,ownerScope:`user:${o.userId}`,tool:o.tool,jobId:o.jobId,idempotencyKey:`job:${o.jobId}`,requestFingerprint:o.requestFingerprint,normalizedFlags:{syncExecutionProtocol:1,intent:o}},ao(),Math.min(36e5,Math.max(1e3,(o.profile==="queue"?o.budgetMs:o.deadlineAt-Date.now())+3e4)),fe(o));if(d.kind!=="claimed")return W(l,"unconfirmed");n=d.claim;let c=await po(n,o);if(c)return c;let p=fe(o),b=ir(o.hold),v=await S(o.jobId,o.userId),f=so(v,{...p,sql:`(${p.sql}) AND (${b.sql})`,args:[...p.args,...b.args]});if(!await Be(n,f))throw Error("Synchronous effect start unknown");if(i=!0,o.profile==="queue"){let Ce=se(n,{tool:o.tool,jobId:o.jobId}),I=fe(o),je;try{await m().execute({sql:`UPDATE jobs SET options=json_set(options,'$.compatDeadlineAt',CAST(strftime('%s','now') AS INTEGER)*1000+?) WHERE id=? AND user_id=? AND json_extract(options,'$.compatDeadlineAt') IS NULL AND (${I.sql}) AND (${Ce.sql})`,args:[o.budgetMs,o.jobId,o.userId,...I.args,...Ce.args]})}catch(ye){je=ye}let qe=await S(o.jobId,o.userId),V=Number(qe?.options.compatDeadlineAt);if(!Number.isSafeInteger(V)||V<=Date.now())throw je??Error("Queued deadline unavailable or expired");o={...o,deadlineAt:V}}let E=0,x=n,H={claim:n,deadlineAt:o.deadlineAt,physicalFactory:async()=>Ft({claim:x,gate:f,deadlineAt:o.deadlineAt,scope:`sync-browser-${++E}`,profile:"customer-funded"})},J=await t(H);a=!0,await nt(o,n,J.result,J.amountMc,"done",null,200,o.options.serpOnly!==!0||E>0);let at=await st(o,n,!1);return s=!0,at}catch(u){if(n&&i){if(!(await S(o.jobId,o.userId))?.options.syncCapturedAt&&!a){let c=await oe(n.runId,n.userId).catch(()=>[]);if(c.length>0&&c.every(p=>p.state==="terminated"||p.state==="not_started")){let p=r(u);try{await nt(o,n,null,0,p.terminalStatus==="cancelled"?"cancelled":"failed",p.publicError,p.httpStatus);let b=await st(o,n,!1);return s=!0,b}catch{}}if(c.length===0){let p=await co(o,n).catch(()=>null);if(p)try{await nt(o,n,null,0,p.terminalStatus,p.publicError,p.httpStatus,!1);let b=await st(o,n,!1);return s=!0,b}catch{}}}await ne(n).catch(()=>{}),await _n(o,n).catch(()=>{})}return W(await S(o.jobId,o.userId)??l)}finally{n&&!i&&await Se(n).catch(()=>{}),n&&i&&!s&&await ne(n).catch(()=>{})}}async function At(e,t=!0){let r=wt(e);if(r.profile!=="queue")throw Error("Queue profile required");let o=!1,n=z(r.jobId),i=await S(r.jobId,r.userId),s=async()=>({kind:"unknown",reply:i?await W(i):{status:503,body:{job_id:r.jobId,status:"pending",executionState:"unknown",hold_state:o?"held":"unconfirmed",status_tool:"harvest_paa_status",...B({errorCode:"response_lost",retryable:!0})}}});if(i&&i.options.queueExecutionProtocol!==1)return s();let a=await T(n,r.userId,r.tool,r.jobId);if(a){if(a.flags.syncExecutionProtocol!==1||h({intent:a.flags.intent})!==h({intent:r}))return s();if(["effects_started","unknown","published"].includes(a.phase)){if(!i)return s();let d=await St(i);if(d&&d.status!==200)return{kind:"unknown",reply:d};let c=await S(r.jobId,r.userId);return c?{kind:"ready",job:c,replayed:!0}:s()}}else if(i||await Ge(n,r.userId))return s();let l={userId:r.userId,tool:r.tool,jobId:r.jobId,sql:"EXISTS(SELECT 1 FROM users WHERE id=? AND active=1)",args:[r.userId]},u;try{let d=await Ae({id:n,userId:r.userId,ownerScope:`user:${r.userId}`,tool:r.tool,jobId:r.jobId,idempotencyKey:`job:${r.jobId}`,requestFingerprint:r.requestFingerprint,normalizedFlags:{syncExecutionProtocol:1,intent:r}},ao(),45e3,l);if(d.kind!=="claimed")return s();u=d.claim;let c=await po(u,r,t);if(c)return{kind:"unfunded",reply:c};if(o=!0,!i&&(await hr(r.jobId,r.userId,String(r.options.query),{...r.options,executionOwner:"cron",queueExecutionProtocol:1,...r.callbackUrl?{callbackDeliveryProtocol:1}:{},billingHoldMc:r.hold.amountMc,billingDebitKey:r.hold.key,requestFingerprint:r.requestFingerprint},r.callbackUrl??void 0)).kind==="unknown")return s();let p=fe(r,"'pending','running','done','failed','cancelled'"),b=(await m().execute({sql:`SELECT 1 WHERE (${p.sql})`,args:p.args})).rows.length>0,v=await S(r.jobId,r.userId);return b&&v&&await no(v,u,p),b&&v?{kind:"ready",job:v,replayed:!!(i||a)}:s()}catch{return s()}finally{u&&await Se(u).catch(()=>{})}}function go(e){let t=JSON.parse(h(e.options)),r=t.serpOnly===!0&&!t.serpIdentity;return{profile:"queue",jobId:e.jobId,userId:e.userId,tool:"search_serp",requestFingerprint:e.requestFingerprint,options:t,callbackUrl:e.callbackUrl??null,deadlineAt:0,budgetMs:Jt(Number(t.maxQuestions??30),!0,t.mode,t.pages,!!t.recency,r).serverMs,hold:{userId:e.userId,key:`serp-search:${e.jobId}:hold`,amountMc:e.amountMc,operation:"serp",description:`SERP search: ${t.query}`.slice(0,500)},refundOperation:"serp_refund",sourceSurface:"serp_search"}}var wi=e=>At(go(e));async function fn(e,t){let r;try{r=await T(`harvest:${t}`,e,"search_serp",t)}catch{return{kind:"unknown",reply:{status:503,body:{job_id:t,status:"pending",executionState:"unknown",hold_state:"unconfirmed",status_tool:"harvest_paa_status",...B({errorCode:"response_lost",retryable:!0})}}}}return r?.flags.syncExecutionProtocol!==1||r.flags.intent?.profile!=="queue"?null:At(r.flags.intent,!1)}async function _o(){for(let t of await Er("search_serp",1,`json_extract(r.normalized_flags_json,'$.intent.profile')='queue' AND (EXISTS(SELECT 1 FROM (SELECT r.user_id AS user_id,json_extract(r.normalized_flags_json,'$.intent') AS normalized_flags_json) saved WHERE ${ar("saved.user_id","json_extract(saved.normalized_flags_json,'$.hold.key')")}))`))await S(t.jobId,t.userId)||await fn(t.userId,t.jobId);let e=(await m().execute(`SELECT j.id,j.user_id FROM jobs j JOIN operation_runs r ON r.id='harvest:'||j.id AND r.user_id=j.user_id JOIN operation_executions x ON x.run_id=r.id
|
|
112
|
-
WHERE json_extract(j.options,'$.queueExecutionProtocol')=1 AND x.phase IN ('effects_started','unknown') AND x.expires_at_ms<=CAST(strftime('%s','now') AS INTEGER)*1000
|
|
113
|
-
ORDER BY j.created_at LIMIT 1`)).rows[0];return e?S(String(e.id),Number(e.user_id)):void 0}async function fo(e,t){if(e.options.queueExecutionProtocol!==1)return await m().execute({sql:"UPDATE jobs SET options=json_set(options,'$.queueExecutionProtocol',0,'$.executionState','unknown','$.holdState','unconfirmed') WHERE id=? AND user_id=? AND json_extract(options,'$.queueExecutionProtocol') IS NULL",args:[e.id,e.user_id]}),{completed:!1,replayed:!1,reply:null};let r=await St(e);if(r)return{completed:(await S(e.id,e.user_id))?.options.executionState==="finalized"&&r.status===200,replayed:!0,reply:r};let o=e.options,n=Object.fromEntries(Object.entries(o).filter(([l])=>!["executionOwner","queueExecutionProtocol","billingHoldMc","billingDebitKey","requestFingerprint","compatDeadlineAt","executionState","holdState"].includes(l))),i=go({jobId:e.id,userId:e.user_id,options:n,requestFingerprint:String(o.requestFingerprint),amountMc:Number(o.billingHoldMc),callbackUrl:e.callback_url}),s=await mo(i,async l=>{let u={value:null},d=o.serpOnly===!0&&!o.serpIdentity,c=`harvest:${e.id}`,p=null,b=AbortSignal.timeout(Math.max(0,l.deadlineAt-Date.now()));if(d&&!Wr({pages:o.pages===2?2:1,recency:o.recency==="week"||o.recency==="month"?o.recency:void 0,mode:o.mode,token:t.apifyToken}))throw Error("Search providers are not configured");let v=await t.withCostContext({op:"serp",userId:e.user_id,headlessSentOut:u,operationRunId:c,operationAccountScope:"production-default"},async()=>d?ht({query:String(o.query??e.query),pages:o.pages===2?2:1,mode:o.mode,recency:o.recency==="week"||o.recency==="month"?o.recency:void 0,token:t.apifyToken,operationRunId:c,accountScope:"production-default",signal:b,onAttemptEvent:t.onAttemptEvent,physicalFactory:l.physicalFactory}).then(x=>(p=x,x.result)):Fe({...o,physicalExecution:await l.physicalFactory(),\u006b\u0065\u0072\u006e\u0065\u006cApiKey:t.\u006b\u0065\u0072\u006e\u0065\u006cApiKey,headless:!0,format:"json",outputDir:"/tmp/paa-output-api",signal:b,onAttemptEvent:t.onAttemptEvent}));if(d&&!p)throw Error("Search provider billing receipt is missing");let f=p,E=d?_r(f.deliveredPages,f.deliveryProvider):gr(u.value);return{result:v,amountMc:Math.min(Number(o.billingHoldMc),E)}},t.classifyFailure);return{completed:(await S(e.id,e.user_id))?.options.executionState==="finalized"&&!!(s.body.status&&["done","failed","cancelled"].includes(String(s.body.status))),replayed:!1,reply:s}}import{randomUUID as yn}from"crypto";function Te(e){return e==null?null:Number(e)===1}function yo(e){if(e==null)return null;try{return JSON.parse(String(e))}catch{return null}}function bo(e){return{id:String(e.id),job_id:String(e.job_id),user_id:Number(e.user_id),attempt_number:Number(e.attempt_number),max_attempts:Number(e.max_attempts),query:String(e.query),location:e.location!=null?String(e.location):null,max_questions:Number(e.max_questions),status:String(e.status),outcome:e.outcome!=null?String(e.outcome):null,\u006b\u0065\u0072\u006e\u0065\u006c_session_id:e.\u006b\u0065\u0072\u006e\u0065\u006c_session_id!=null?String(e.\u006b\u0065\u0072\u006e\u0065\u006c_session_id):null,question_count:e.question_count!=null?Number(e.question_count):null,duration_ms:e.duration_ms!=null?Number(e.duration_ms):null,error:e.error!=null?String(e.error):null,will_retry:Te(e.will_retry),\u006b\u0065\u0072\u006e\u0065\u006c_delete_started:Number(e.\u006b\u0065\u0072\u006e\u0065\u006c_delete_started??0)===1,\u006b\u0065\u0072\u006e\u0065\u006c_delete_succeeded:Te(e.\u006b\u0065\u0072\u006e\u0065\u006c_delete_succeeded),\u006b\u0065\u0072\u006e\u0065\u006c_delete_error:e.\u006b\u0065\u0072\u006e\u0065\u006c_delete_error!=null?String(e.\u006b\u0065\u0072\u006e\u0065\u006c_delete_error):null,browser_close_succeeded:Te(e.browser_close_succeeded),browser_close_error:e.browser_close_error!=null?String(e.browser_close_error):null,browser_provider:e.browser_provider!=null?String(e.browser_provider):null,provider_session_id:e.provider_session_id!=null?String(e.provider_session_id):null,provider_session_observed_at:e.provider_session_observed_at!=null?String(e.provider_session_observed_at):null,provider_lookup_status:e.provider_lookup_status!=null?String(e.provider_lookup_status):null,provider_status:e.provider_status!=null?String(e.provider_status):null,provider_error_code:e.provider_error_code!=null?String(e.provider_error_code):null,provider_error_message:e.provider_error_message!=null?String(e.provider_error_message):null,provider_reason_source:e.provider_reason_source!=null?String(e.provider_reason_source):null,provider_duration_ms:e.provider_duration_ms!=null?Number(e.provider_duration_ms):null,provider_bandwidth_bytes:e.provider_bandwidth_bytes!=null?Number(e.provider_bandwidth_bytes):null,provider_captcha:Te(e.provider_captcha),provider_checked_at:e.provider_checked_at!=null?String(e.provider_checked_at):null,provider_detail:yo(e.provider_detail_json),provider_disconnect_observed:Te(e.provider_disconnect_observed),provider_disconnect_message:e.provider_disconnect_message!=null?String(e.provider_disconnect_message):null,debug:yo(e.debug_json),created_at:String(e.created_at),completed_at:e.completed_at!=null?String(e.completed_at):null}}async function ho(e){await m().execute({sql:`
|
|
114
|
-
INSERT INTO harvest_attempts (
|
|
115
|
-
id, job_id, user_id, attempt_number, max_attempts, query, location, max_questions, status, created_at
|
|
116
|
-
)
|
|
117
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'running', ?)
|
|
118
|
-
ON CONFLICT(job_id, attempt_number) DO NOTHING
|
|
119
|
-
`,args:[yn(),e.jobId,e.userId,e.attemptNumber,e.maxAttempts,e.query,e.location,e.maxQuestions,e.startedAt]})}async function vo(e){return(await m().execute({sql:`
|
|
120
|
-
UPDATE harvest_attempts SET
|
|
121
|
-
browser_provider = ?,
|
|
122
|
-
provider_session_id = ?,
|
|
123
|
-
provider_session_observed_at = COALESCE(provider_session_observed_at, ?),
|
|
124
|
-
provider_lookup_status = CASE
|
|
125
|
-
WHEN provider_lookup_status = 'complete' THEN provider_lookup_status
|
|
126
|
-
ELSE 'pending'
|
|
127
|
-
END
|
|
128
|
-
WHERE job_id = ? AND attempt_number = ? AND status = 'running'
|
|
129
|
-
`,args:[e.browserProvider,e.providerSessionId,e.observedAt,e.jobId,e.attemptNumber]})).rowsAffected===1}async function Eo(e){await m().execute({sql:`
|
|
130
|
-
UPDATE harvest_attempts SET
|
|
131
|
-
status = 'finished',
|
|
132
|
-
outcome = ?,
|
|
133
|
-
\u006b\u0065\u0072\u006e\u0065\u006c_session_id = ?,
|
|
134
|
-
question_count = ?,
|
|
135
|
-
duration_ms = ?,
|
|
136
|
-
error = ?,
|
|
137
|
-
will_retry = ?,
|
|
138
|
-
\u006b\u0065\u0072\u006e\u0065\u006c_delete_started = ?,
|
|
139
|
-
\u006b\u0065\u0072\u006e\u0065\u006c_delete_succeeded = ?,
|
|
140
|
-
\u006b\u0065\u0072\u006e\u0065\u006c_delete_error = ?,
|
|
141
|
-
browser_close_succeeded = ?,
|
|
142
|
-
browser_close_error = ?,
|
|
143
|
-
browser_provider = COALESCE(browser_provider, ?),
|
|
144
|
-
provider_session_id = COALESCE(provider_session_id, ?),
|
|
145
|
-
provider_lookup_status = CASE
|
|
146
|
-
WHEN provider_lookup_status = 'complete' THEN provider_lookup_status
|
|
147
|
-
ELSE COALESCE(?, provider_lookup_status)
|
|
148
|
-
END,
|
|
149
|
-
provider_status = COALESCE(provider_status, ?),
|
|
150
|
-
provider_error_code = CASE
|
|
151
|
-
WHEN provider_reason_source = 'provider_session_api' THEN provider_error_code
|
|
152
|
-
ELSE COALESCE(?, provider_error_code)
|
|
153
|
-
END,
|
|
154
|
-
provider_error_message = CASE
|
|
155
|
-
WHEN provider_reason_source = 'provider_session_api' THEN provider_error_message
|
|
156
|
-
ELSE COALESCE(?, provider_error_message)
|
|
157
|
-
END,
|
|
158
|
-
provider_reason_source = CASE
|
|
159
|
-
WHEN provider_reason_source = 'provider_session_api' THEN provider_reason_source
|
|
160
|
-
ELSE COALESCE(?, provider_reason_source)
|
|
161
|
-
END,
|
|
162
|
-
provider_duration_ms = COALESCE(provider_duration_ms, ?),
|
|
163
|
-
provider_bandwidth_bytes = COALESCE(provider_bandwidth_bytes, ?),
|
|
164
|
-
provider_captcha = COALESCE(provider_captcha, ?),
|
|
165
|
-
provider_checked_at = COALESCE(provider_checked_at, ?),
|
|
166
|
-
provider_detail_json = COALESCE(provider_detail_json, ?),
|
|
167
|
-
provider_disconnect_observed = COALESCE(provider_disconnect_observed, ?),
|
|
168
|
-
provider_disconnect_message = COALESCE(provider_disconnect_message, ?),
|
|
169
|
-
debug_json = ?,
|
|
170
|
-
completed_at = ?
|
|
171
|
-
WHERE job_id = ? AND attempt_number = ?
|
|
172
|
-
`,args:[e.outcome,e.\u006b\u0065\u0072\u006e\u0065\u006cSessionId,e.questionCount,e.durationMs,e.error,e.willRetry?1:0,e.\u006b\u0065\u0072\u006e\u0065\u006cDeleteStarted?1:0,e.\u006b\u0065\u0072\u006e\u0065\u006cDeleteSucceeded==null?null:e.\u006b\u0065\u0072\u006e\u0065\u006cDeleteSucceeded?1:0,e.\u006b\u0065\u0072\u006e\u0065\u006cDeleteError,e.browserCloseSucceeded==null?null:e.browserCloseSucceeded?1:0,e.browserCloseError,e.browserProvider??null,e.providerSessionId??null,e.providerLookupStatus??null,e.providerStatus??null,e.providerErrorCode??null,e.providerErrorMessage??null,e.providerReasonSource??null,e.providerDurationMs??null,e.providerBandwidthBytes??null,e.providerCaptcha==null?null:e.providerCaptcha?1:0,e.providerCheckedAt??null,e.providerDetail==null?null:wo(e.providerDetail),e.providerDisconnectObserved==null?null:e.providerDisconnectObserved?1:0,e.providerDisconnectMessage??null,e.debug==null?null:JSON.stringify(e.debug),e.completedAt,e.jobId,e.attemptNumber]})}function wo(e,t=4096){let r=JSON.stringify(e);return r.length<=t?r:JSON.stringify({truncated:!0})}async function Ri(e){return(await m().execute({sql:`
|
|
173
|
-
UPDATE harvest_attempts SET
|
|
174
|
-
provider_lookup_status = ?,
|
|
175
|
-
provider_status = ?,
|
|
176
|
-
provider_error_code = ?,
|
|
177
|
-
provider_error_message = ?,
|
|
178
|
-
provider_reason_source = ?,
|
|
179
|
-
provider_duration_ms = ?,
|
|
180
|
-
provider_bandwidth_bytes = ?,
|
|
181
|
-
provider_captcha = ?,
|
|
182
|
-
provider_checked_at = ?,
|
|
183
|
-
provider_detail_json = ?
|
|
184
|
-
WHERE id = ?
|
|
185
|
-
AND job_id = ?
|
|
186
|
-
AND user_id = ?
|
|
187
|
-
AND browser_provider = '\u0062\u0072\u0069\u0067\u0068\u0074_\u0064\u0061\u0074\u0061_browser_api'
|
|
188
|
-
AND provider_session_id = ?
|
|
189
|
-
AND COALESCE(provider_lookup_status, '') <> 'complete'
|
|
190
|
-
`,args:[e.lookupStatus,e.providerStatus??null,e.errorCode??null,e.errorMessage??null,e.reasonSource??null,e.durationMs??null,e.bandwidthBytes??null,e.captcha==null?null:e.captcha?1:0,e.checkedAt,e.detail==null?null:wo(e.detail),e.attemptId,e.jobId,e.userId,e.providerSessionId]})).rowsAffected===1}async function Ni(e=25){let t=Math.max(1,Math.min(100,Math.trunc(e)));return(await m().execute({sql:`
|
|
191
|
-
SELECT * FROM harvest_attempts
|
|
192
|
-
WHERE browser_provider = '\u0062\u0072\u0069\u0067\u0068\u0074_\u0064\u0061\u0074\u0061_browser_api'
|
|
193
|
-
AND provider_session_id IS NOT NULL
|
|
194
|
-
AND provider_lookup_status IN ('pending', 'temporary_error')
|
|
195
|
-
ORDER BY COALESCE(provider_checked_at, created_at) ASC
|
|
196
|
-
LIMIT ?
|
|
197
|
-
`,args:[t]})).rows.map(o=>bo(o))}async function So(e,t){return(t==null?await m().execute({sql:"SELECT * FROM harvest_attempts WHERE job_id = ? ORDER BY attempt_number ASC",args:[e]}):await m().execute({sql:`
|
|
198
|
-
SELECT ha.*
|
|
199
|
-
FROM harvest_attempts ha
|
|
200
|
-
INNER JOIN jobs j ON j.id = ha.job_id
|
|
201
|
-
WHERE ha.job_id = ? AND j.user_id = ?
|
|
202
|
-
ORDER BY ha.attempt_number ASC
|
|
203
|
-
`,args:[e,t]})).rows.map(o=>bo(o))}import{createHash as Ti}from"crypto";var bn=1e9;function It(e){return e==="timeout"?"timed_out":e==="request_aborted"?"cancelled":e==="browser_session_interrupted"?"interrupted":e==="captcha"||e==="proxy_tunnel_failed"||e==="proxy_unavailable"||e==="location_mismatch"||e==="error"?"failed":"succeeded"}function hn(e){return e==="\u0062\u0072\u0069\u0067\u0068\u0074_\u0064\u0061\u0074\u0061_browser_api"?"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061":"\u006b\u0065\u0072\u006e\u0065\u006c"}function Ao(e,t,r=0){let o=new Map,n=null;return async i=>{if(e)try{if(i.type==="started"){let a=r+i.attemptNumber;if(a>1&&!n){let c=(await We(e))?.attempts.at(-1);n=c?.id==null?null:String(c.id)}let l=await ie({runId:e,attemptNumber:a,method:i.method,provider:i.provider,parentAttemptId:a===1?null:n,edgeKind:a===1?null:r>0&&i.attemptNumber===1?"durable_resume":i.retryKind==="provider_fallback"?"provider_fallback":"same_method_retry",retryKind:a===1?null:r>0&&i.attemptNumber===1?"durable_resume":i.retryKind,retryReason:a===1?null:r>0&&i.attemptNumber===1?"durable_worker_resume":i.retryReason,retryOwner:a===1?null:r>0&&i.attemptNumber===1?"durable_reconciler":"harvest",normalizedFlags:{maxAttempts:i.maxAttempts,maxQuestions:i.maxQuestions,hasLocation:!!i.location,plannedProvider:i.provider,planReason:i.planReason??null,planTimeoutMs:i.planTimeoutMs??null},startedAt:i.startedAt}),u=await X({attemptId:l,provider:i.provider,providerProduct:i.provider==="\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061"?"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061_browser_api":"\u006b\u0065\u0072\u006e\u0065\u006c_browser",billingTier:i.provider==="\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061"?Re("https://www.google.com/search"):null,accountScope:t,method:i.method,providerStatus:"started"});o.set(i.attemptNumber,{attemptId:l,receiptId:u.id,plannedProvider:i.provider,observedProvider:null,providerMismatch:!1,method:i.method,startedAtMs:Date.parse(i.startedAt),billingMode:null}),n=l;return}let s=o.get(i.attemptNumber);if(!s)throw new Error(`Missing operation attempt state for attempt ${i.attemptNumber}`);if(i.type==="provider_session_started"){let a=hn(i.provider);if(s.observedProvider=a,s.billingMode=i.billingMode??null,a!==s.plannedProvider){s.providerMismatch=!0,await Q({receiptId:s.receiptId,costState:"unavailable",providerStatus:"provider_mismatch",errorCode:"provider_mismatch",errorMessage:`Planned ${s.plannedProvider}; observed ${a}`,finalizedAt:i.observedAt});let l=a==="\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061"?"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061_browser":"\u006b\u0065\u0072\u006e\u0065\u006c_browser",u=await X({attemptId:s.attemptId,provider:a,providerProduct:a==="\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061"?"\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061_browser_api":"\u006b\u0065\u0072\u006e\u0065\u006c_browser",billingTier:a==="\u0062\u0072\u0069\u0067\u0068\u0074\u0064\u0061\u0074\u0061"?Re("https://www.google.com/search"):null,accountScope:t,method:l,providerStatus:"observed_provider_mismatch"});s.receiptId=u.id,s.method=l}await Y(s.receiptId,i.providerSessionId);return}if(await ae({attemptId:s.attemptId,status:s.providerMismatch?"failed":It(i.outcome),errorCode:s.providerMismatch?"provider_mismatch":It(i.outcome)==="succeeded"?null:i.outcome,errorMessage:i.error,durationMs:i.durationMs,endedAt:i.completedAt}),(s.observedProvider??s.plannedProvider)==="\u006b\u0065\u0072\u006e\u0065\u006c"){let a=s.billingMode==="headful",l=s.billingMode==="headless"||s.billingMode==="headful"?or(i.durationMs,a):null;await Q({receiptId:s.receiptId,costState:"estimated",units:i.durationMs/1e3,unitType:"wall_open_second",amountUsdNanos:l==null?null:Math.round(l*bn),providerProduct:"\u006b\u0065\u0072\u006e\u0065\u006c_browser",billingTier:s.billingMode,billableEvent:"provider_active_gb_second",measurementSource:"wall_open_time_proxy",rateSource:l!=null?`${rr};\u006b\u0065\u0072\u006e\u0065\u006c_usd_per_second:${tr}`:null,providerStatus:s.providerMismatch?"provider_mismatch":i.outcome,providerDurationMs:i.durationMs,errorCode:s.providerMismatch?"provider_mismatch":It(i.outcome)==="succeeded"?null:i.outcome,errorMessage:i.error,finalizedAt:i.completedAt})}}catch(s){console.warn(JSON.stringify({event:"operation_attempt_telemetry_failed",operation_run_id:e,attempt_number:i.attemptNumber,message:s instanceof Error?s.message:String(s)}))}}}function Io(e,t,r=null,o="production-default",n=0){let i=Ao(r,o,n);return async s=>{if(await i(s),s.type==="started"){await ho({jobId:e,userId:t,attemptNumber:s.attemptNumber,maxAttempts:s.maxAttempts,query:s.query,location:s.location,maxQuestions:s.maxQuestions,startedAt:s.startedAt});return}if(s.type==="provider_session_started"){await vo({jobId:e,attemptNumber:s.attemptNumber,browserProvider:s.provider,providerSessionId:s.providerSessionId,observedAt:s.observedAt});return}await Eo({jobId:e,attemptNumber:s.attemptNumber,outcome:s.outcome,\u006b\u0065\u0072\u006e\u0065\u006cSessionId:s.\u006b\u0065\u0072\u006e\u0065\u006cSessionId,questionCount:s.questionCount,durationMs:s.durationMs,error:s.error,willRetry:s.willRetry,\u006b\u0065\u0072\u006e\u0065\u006cDeleteStarted:s.cleanup.\u006b\u0065\u0072\u006e\u0065\u006cDeleteStarted,\u006b\u0065\u0072\u006e\u0065\u006cDeleteSucceeded:s.cleanup.\u006b\u0065\u0072\u006e\u0065\u006cDeleteSucceeded,\u006b\u0065\u0072\u006e\u0065\u006cDeleteError:s.cleanup.\u006b\u0065\u0072\u006e\u0065\u006cDeleteError,browserCloseSucceeded:s.cleanup.browserCloseSucceeded,browserCloseError:s.cleanup.browserCloseError,browserProvider:s.cleanup.provider??null,providerSessionId:s.cleanup.providerSessionId??null,providerLookupStatus:s.cleanup.providerSessionId?"pending":"not_applicable",providerErrorCode:s.cleanup.providerDisconnectObserved?"browser_session_interrupted":null,providerErrorMessage:s.cleanup.providerDisconnectMessage??null,providerReasonSource:s.cleanup.providerDisconnectObserved?"client_runtime":null,providerDisconnectObserved:s.cleanup.providerDisconnectObserved??!1,providerDisconnectMessage:s.cleanup.providerDisconnectMessage??null,debug:s.debug,completedAt:s.completedAt})}}function vn(e){return e instanceof Error?e.message:String(e)}function En(e,t){return e instanceof DOMException&&(e.name==="TimeoutError"||e.name==="AbortError")?!0:/timeout|timed out|Timeout \d+ms exceeded|deadline/i.test(t)}function wn(e){return/captcha|recaptcha|unusual traffic|google\.com\/sorry|blocked/i.test(e)}function Sn(e){return/ERR_TUNNEL_CONNECTION_FAILED|ERR_PROXY_CONNECTION_FAILED|ERR_SOCKS_CONNECTION_FAILED|tunnel connection failed|proxy connection failed|transport error: proxy/i.test(e)}function An(e){return/proxy unavailable|proxy_unavailable|connection_test_failed|did not return a proxy id|configured fallback/i.test(e)}function In(e){return/(?:spending|billing|organization|account).{0,80}(?:cap|limit|blocked|disabled)|(?:quota|capacity).{0,40}(?:reached|exceeded)|https?:\/\/\S*dashboard/i.test(e)}function Rn(e){return/browser (?:has been )?closed|context (?:has been )?closed|target page, context or browser has been closed|session closed|page has been closed/i.test(e)}function Rt(e){let t=vn(e);return e instanceof Vt?{error_code:"request_aborted",error_type:"request_aborted",message:U("request_aborted"),retryable:!0,httpStatus:408,terminalStatus:"cancelled"}:e instanceof zt||wn(t)?{error_code:"captcha_exhausted",error_type:"captcha",message:U("captcha_exhausted"),retryable:!0,httpStatus:503,terminalStatus:"failed"}:br(e,t)?{error_code:"vendor_unavailable",error_type:"service_unavailable",message:U("vendor_unavailable"),retryable:!0,httpStatus:503,terminalStatus:"failed"}:e instanceof Kt?{error_code:"location_mismatch",error_type:"location_mismatch",message:U("location_mismatch"),retryable:!0,httpStatus:503,terminalStatus:"failed"}:Sn(t)?{error_code:"proxy_tunnel_failed",error_type:"connection",message:U("proxy_tunnel_failed"),retryable:!0,httpStatus:503,terminalStatus:"failed"}:An(t)?{error_code:"proxy_unavailable",error_type:"connection",message:U("proxy_unavailable"),retryable:!0,httpStatus:503,terminalStatus:"failed"}:Rn(t)?{error_code:"browser_session_interrupted",error_type:"extraction",message:U("browser_session_interrupted"),retryable:!0,httpStatus:503,terminalStatus:"failed"}:En(e,t)?{error_code:"harvest_timeout",error_type:"timeout",message:U("harvest_timeout"),retryable:!0,httpStatus:504,terminalStatus:"failed"}:In(t)?{error_code:"service_unavailable",error_type:"service_unavailable",message:ct,retryable:!0,httpStatus:503,terminalStatus:"failed"}:{error_code:"extraction_failed",error_type:"extraction",message:ct,retryable:!1,httpStatus:500,terminalStatus:"failed"}}function Ji(e){return JSON.stringify({error_code:e.error_code,error_type:e.error_type,message:e.message,retryable:e.retryable})}function Ro(e,t={}){let r=B({errorCode:e.error_code,errorType:e.error_type,retryable:e.retryable,retryAfterSeconds:t.retryAfterSeconds,chargeStatus:t.chargeStatus,details:t.details});return{error:r.message,...r}}function No(e,t={}){let{error:r,...o}=Ro(e,t);return o}function Gi(e,t={}){let r=Rt(e);return{body:Ro(r,t),status:r.httpStatus}}import{randomUUID as xo}from"crypto";var Nn=3e4;async function Do(e,t,r){if(!e.receiptJson)return;let o=Pe(e.id);if((await T(o,e.userId,"paa_callback",e.jobId))?.phase==="published")return;if(r){if(await $e(r,{status:"succeeded",json:e.receiptJson}))return;await ne(r)}let i=await Ue(o,e.userId);i&&await Je(i,{status:"unknown",json:e.receiptJson},Oe(e,t,"accepted"))}function xn(e){return!!(e.payloadJson&&e.payloadSha256===O(e.payloadJson)&&e.sendNonce&&e.sendToken&&e.httpStatus&&e.httpStatus>=200&&e.httpStatus<300&&e.receiptJson===h({deliveryId:e.id,idempotencyKey:e.id,payloadSha256:e.payloadSha256,httpStatus:e.httpStatus}))}async function ko(e){let t=e.record,r,o=!1;try{if(t=await j(t.id,t.userId)??t,t.state==="accepted")return xn(t)?(await Do(t,e.domain).catch(()=>{}),L(t)):{state:"unavailable",deliveryId:t.id};if(["sending","unknown","expired","unavailable"].includes(t.state))return L(t);if(t.expiresAtMs<=t.nowMs)return await ot(t,"expired"),L(await j(t.id,t.userId));if(t.payloadJson||(t=await Qr(t,await e.compose(),e.domain)),!t.payloadJson||t.payloadSha256!==O(t.payloadJson))throw Error("Delivery payload conflicts");let n=Oe(t,e.domain,"frozen"),i=Pe(t.id),s={version:1,purpose:"outbound-callback",request:$(t),payloadSha256:t.payloadSha256},a=await Ae({id:i,userId:t.userId,ownerScope:`user:${t.userId}`,tool:"paa_callback",jobId:t.jobId,idempotencyKey:t.id,requestFingerprint:O(h(s)),normalizedFlags:s},xo(),Nn,n);if(a.kind!=="claimed"){let u=await T(i,t.userId,"paa_callback",t.jobId);if(u&&["effects_started","unknown","published"].includes(u.phase)){await vt(t),u.phase==="published"&&await ot(t,"unavailable",n);let d=await j(t.id,t.userId);return d?L(d):{state:"unknown",deliveryId:t.id}}return{state:"pending",deliveryId:t.id,expiresAtMs:t.expiresAtMs}}if(r=a.claim,!await e.validate(t.url))return L(t);if(!await Be(r,n))throw Error("Delivery effects start is unconfirmed");if(o=!0,t=await Zr(t,r,xo(),e.domain),!await eo(t,r,e.domain))throw Error("Delivery authority was lost before send");let l=await fetch(t.url,{method:"POST",headers:{"content-type":"application/json","idempotency-key":t.id},body:t.payloadJson,redirect:"error",signal:AbortSignal.timeout(1e4)});if(!l.ok||l.status<200||l.status>=300)throw Error("Recipient acceptance is unconfirmed");return t=await to(t,l.status),await Do(t,e.domain,r).catch(()=>{}),L(t)}catch(n){if(n instanceof ee&&await ot(t,"unavailable",e.domain).catch(()=>{}),r){let s=await T(r.runId,r.userId,"paa_callback",t.jobId).catch(()=>null);(o||s?.phase==="effects_started"||s?.phase==="unknown")&&await ne(r).catch(()=>{})}t.sendNonce?await ro(t).catch(()=>{}):await vt(t).catch(()=>{});let i=await j(t.id,t.userId).catch(()=>null);return i?L(i):{state:"unknown",deliveryId:t.id}}finally{r&&!o&&await Se(r).catch(()=>{})}}async function Nt(e,t){let r=await io(e,t);return r.kind==="none"?{state:"none"}:r.kind==="unavailable"?{state:"unavailable"}:r.kind==="pending"?(await L(r.record),{state:"pending",deliveryId:r.record.id,expiresAtMs:r.record.expiresAtMs}):ko({record:r.record,domain:r.domain,validate:async o=>{let n=await fr(o,{field:"callback_url",requireHttps:!0});return!n.error&&n.parsed?.href===o&&!n.parsed.username&&!n.parsed.password},compose:async()=>{let o=(await it(r.job,!1)).body;return{...o,...o.result?{result:sr(o.result)}:{},...r.record.profile==="paa-queue"?{attempts:nr(await So(r.job.id,r.job.user_id))}:{}}}})}async function sa(e=25){let t=0,r=0,o=await oo(e);for(let n of o)try{(await Nt(n.jobId,n.userId)).state==="accepted"?t++:r++}catch{r++}return{checked:o.length,accepted:t,pending:r}}var Po=2,xt=0;async function Oo(){let e=await _o(),t=e?void 0:await vr(),r=e??(t?await S(t.id,Number(t.user_id)):void 0);if(!r)return{claimed:!1};let o=Date.now();xt++;try{let n=await fo(r,{\u006b\u0065\u0072\u006e\u0065\u006cApiKey:Gt(),apifyToken:process.env.APIFY_API_TOKEN?.trim(),onAttemptEvent:Io(r.id,r.user_id,`harvest:${r.id}`),withCostContext:Qt,classifyFailure:i=>{let s=Rt(i);return{publicError:No(s),httpStatus:s.httpStatus,terminalStatus:s.terminalStatus}}});return n.completed&&r.callback_url&&await Nt(r.id,r.user_id).catch(()=>{}),{claimed:!0,jobId:r.id,completed:n.completed,durationMs:Date.now()-o}}finally{xt--}}async function _a(e){let t=[];for(let r=0;r<e.maxJobs&&!(Date.now()>=e.deadlineMs);r++){let o=await Oo();if(t.push(o),!o.claimed)break}return t}function fa(){setInterval(async()=>{xt>=Po||Oo()},2e3),console.log(`[worker] started \u2014 polling every 2s, max ${Po} concurrent`)}export{qn as a,Mn as b,Ln as c,Hn as d,Fn as e,Un as f,$n as g,Jn as h,Kr as i,tt as j,Re as k,Ke as l,Jo as m,ts as n,Ri as o,Ni as p,So as q,Rt as r,Ji as s,No as t,Gi as u,no as v,so as w,Wr as x,ht as y,W as z,_n as A,nt as B,it as C,st as D,St as E,mo as F,Nt as G,sa as H,zn as I,Er as J,wi as K,fn as L,Io as M,Oo as N,_a as O,fa as P};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{f as a,g as b}from"./chunk-YJPFEL2E.js";import"./chunk-JNPM3U3L.js";import"./chunk-KXJCGV3H.js";import"./chunk-ANQ4JJVI.js";import"./chunk-SEZETSB3.js";import"./chunk-SDQW7IJN.js";import"./chunk-C7MGJUTU.js";import"./chunk-PKQHHCO4.js";import"./chunk-4ZVO6GX4.js";import"./chunk-WNUXMPVX.js";import"./chunk-OILOHQNL.js";import"./chunk-HNNYXMSI.js";export{a as dispatchSiteExtractJob,b as redispatchFundedSiteExtractJobs};
|
package/dist/queue-VOGXQDPR.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as d,u,v as l,w as f,wb as S,x as v,yb as h}from"./chunk-AMYPXA2F.js";import"./chunk-PQRT4T2G.js";import"./chunk-NNOX3FYG.js";import"./chunk-NALXKTUU.js";import"./chunk-OSKCHEVM.js";import"./chunk-B5Y26E3A.js";import"./chunk-U3NV72AL.js";import"./chunk-VVSHZV5S.js";import"./chunk-4ZVO6GX4.js";import"./chunk-WNUXMPVX.js";import"./chunk-EYGA6LOU.js";var g=12;function b(e){return e&&typeof e=="object"&&"code"in e&&typeof e.code=="string"?e.code:e instanceof Error?e.name:"unknown_error"}function k(e){return Math.min(21600,30*2**Math.max(0,e-1))}async function x(e={}){let w=e.stripeClient??S,E=Math.max(1,Math.min(100,e.limit??100)),r=500,i=0,s=0,c=0,m=0;for(;i<r;){let a=await d(Math.min(E,r-i),e.leaseSeconds??300);if(a.length===0)break;i+=a.length;for(let t of a)try{let n=await w.events.retrieve(t.eventId);await h(n),await u(t.eventId,t.token)&&(s+=1)}catch(n){let p=n instanceof Error?n.message:String(n),o=b(n);t.attemptCount>=g||o==="resource_missing"?await f(t.eventId,t.token,p,o)&&(m+=1):await l(t.eventId,t.token,p,o,k(t.attemptCount))&&(c+=1)}}return{claimed:i,processed:s,retried:c,deadLettered:m,capped:i>=r,health:await v()}}export{x as drainStripeEventQueue};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as b,k as c}from"./chunk-A4UASMEQ.js";import{g as a}from"./chunk-YJPFEL2E.js";import"./chunk-PD7BI7TR.js";import"./chunk-OSKCHEVM.js";import"./chunk-NULRGHJ4.js";import"./chunk-U4WIJZCX.js";import"./chunk-JNPM3U3L.js";import"./chunk-KXJCGV3H.js";import"./chunk-JMZIDHYQ.js";import"./chunk-M5QHXNFZ.js";import"./chunk-QER2ELZP.js";import"./chunk-U3NV72AL.js";import"./chunk-CNSVZTTT.js";import"./chunk-K3VDGJNK.js";import"./chunk-7SR7MEU5.js";import"./chunk-ANQ4JJVI.js";import"./chunk-SEZETSB3.js";import"./chunk-SDQW7IJN.js";import"./chunk-C7MGJUTU.js";import"./chunk-PKQHHCO4.js";import"./chunk-4ZVO6GX4.js";import"./chunk-WNUXMPVX.js";import"./chunk-EYGA6LOU.js";import"./chunk-OLYPLX5C.js";import"./chunk-B3JRL45T.js";import"./chunk-OILOHQNL.js";import"./chunk-HNNYXMSI.js";export{c as reconcileSiteExtractSettlements,a as redispatchFundedSiteExtractJobs,b as refinalizeExtractJob};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as a,c as b}from"./chunk-PD7BI7TR.js";import"./chunk-OSKCHEVM.js";import"./chunk-JNPM3U3L.js";import"./chunk-KXJCGV3H.js";import"./chunk-U3NV72AL.js";import"./chunk-ANQ4JJVI.js";import"./chunk-SEZETSB3.js";import"./chunk-SDQW7IJN.js";import"./chunk-C7MGJUTU.js";import"./chunk-PKQHHCO4.js";import"./chunk-4ZVO6GX4.js";import"./chunk-WNUXMPVX.js";import"./chunk-EYGA6LOU.js";import"./chunk-OILOHQNL.js";import"./chunk-HNNYXMSI.js";export{a as settleExtractJobCharge,b as settleTerminalExtractJob};
|
package/dist/worker-NXRU3TT3.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{N as a,O as b,P as c}from"./chunk-XYUJTIPE.js";import"./chunk-OSKCHEVM.js";import"./chunk-U4WIJZCX.js";import"./chunk-GLCR4KJI.js";import"./chunk-M5QHXNFZ.js";import"./chunk-WHVK6FUB.js";import"./chunk-63VWBMYR.js";import"./chunk-U3NV72AL.js";import"./chunk-7SR7MEU5.js";import"./chunk-ANQ4JJVI.js";import"./chunk-B4ZKPLSP.js";import"./chunk-VVSHZV5S.js";import"./chunk-C7MGJUTU.js";import"./chunk-PKQHHCO4.js";import"./chunk-4ZVO6GX4.js";import"./chunk-WNUXMPVX.js";import"./chunk-EYGA6LOU.js";import"./chunk-6N5EC7ZO.js";import"./chunk-B3JRL45T.js";import"./chunk-HNNYXMSI.js";export{b as drainQueue,c as startWorker,a as tickOnce};
|