mcp-scraper 0.90.6 → 0.90.7
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 -2
- package/README.md +1 -1
- package/dist/{analytics-repository-WNJESD4A.js → analytics-repository-FXS45ZTM.js} +1 -1
- 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/{chunk-MADTJXNI.js → chunk-5NQY2N7J.js} +105 -105
- package/dist/{chunk-COIA4RW4.js → chunk-74HHYSAZ.js} +1 -1
- package/dist/{chunk-BVSK6YHX.js → chunk-B2C7JU4O.js} +1 -1
- package/dist/{chunk-56UT5M5Y.js → chunk-BDLR4CCL.js} +3 -3
- package/dist/{chunk-5MMN27Q6.js → chunk-DSK6RKBS.js} +1 -1
- package/dist/{chunk-AAJG5OHF.js → chunk-I7IS7NTC.js} +1 -1
- package/dist/{chunk-Q5SUDDSQ.js → chunk-IGJKAECE.js} +1 -1
- package/dist/chunk-KDDU6BW3.js +48 -0
- package/dist/{chunk-NWRRVZKW.js → chunk-LPEIHMYH.js} +1 -1
- package/dist/{chunk-YDOBZMLS.js → chunk-OT2HUS2G.js} +1 -1
- package/dist/{chunk-AQSMJCTF.js → chunk-QUFR3KG2.js} +1 -1
- package/dist/{chunk-AQXYXVOP.js → chunk-R7LCD65B.js} +1 -1
- package/dist/{chunk-XXK5PLRB.js → chunk-TBTA7VVZ.js} +9 -8
- package/dist/{chunk-KKHTMYCD.js → chunk-TOJBPATJ.js} +1 -0
- package/dist/{chunk-4OTWTGKC.js → chunk-UKFNSXP3.js} +1 -1
- package/dist/chunk-WEPU72WA.js +1 -0
- package/dist/{chunk-D6BTAT5Y.js → chunk-YGBTTW5D.js} +1 -1
- package/dist/{chunk-WDB5CTRY.js → chunk-YTEAWZEN.js} +1 -1
- package/dist/{chunk-XARSC34L.js → chunk-ZKQRA6NQ.js} +5 -5
- package/dist/{db-XN7YPDGC.js → db-SVSD2AWJ.js} +1 -1
- package/dist/{extract-bundle-CP6WBOJI.js → extract-bundle-INT6JMJP.js} +1 -1
- package/dist/{gmail-service-5NH2GVQ5.js → gmail-service-YCPMGW3E.js} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{lead-list-enrichment-repository-AIMOP7YM.js → lead-list-enrichment-repository-B6Q4O4DG.js} +1 -1
- package/dist/{location-data-repository-25D3GHXE.js → location-data-repository-CBI5K7MR.js} +1 -1
- package/dist/{server-TQJ6Z3ZF.js → server-LYWW6XYE.js} +479 -454
- package/dist/{site-extract-repository-KG6FQU55.js → site-extract-repository-VPYOC3CP.js} +1 -1
- package/dist/{stripe-event-worker-ZNNQEVK4.js → stripe-event-worker-AQVRF24K.js} +1 -1
- package/dist/worker-U43KLOLN.js +1 -0
- package/package.json +1 -1
- package/dist/chunk-NOUHD54C.js +0 -48
- package/dist/chunk-UM4WSLKQ.js +0 -1
- package/dist/worker-4LFWAEX2.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as s,B as t,C as u,D as v,E as w,F as x,G as y,H as z,I as A,J as B,K as C,L as D,M as E,i as a,j as b,k as c,l as d,m as e,n as f,o as g,p as h,q as i,r as j,s as k,t as l,u as m,v as n,w as o,x as p,y as q,z as r}from"./chunk-
|
|
1
|
+
import{A as s,B as t,C as u,D as v,E as w,F as x,G as y,H as z,I as A,J as B,K as C,L as D,M as E,i as a,j as b,k as c,l as d,m as e,n as f,o as g,p as h,q as i,r as j,s as k,t as l,u as m,v as n,w as o,x as p,y as q,z as r}from"./chunk-LPEIHMYH.js";import"./chunk-TMB56NCA.js";import"./chunk-CTX3NMZQ.js";import"./chunk-TOJBPATJ.js";export{a as XRAY_ENTITLED_EXTRACT_BILLING_CLASS,q as abandonExtractSettlement,p as claimFailedExtractJobForRefinalize,z as completeExtractJob,w as countSuccessfulPages,d as createExtractJob,f as createOrGetExtractJob,b as extractJobLimitInfo,A as failExtractJob,o as failStaleRunningExtractJob,B as failUnfundedExtractJob,E as finalizeXRayEntitledExtractJobCharge,y as finishExtractJob,g as getExtractJob,e as getExtractJobByIdempotencyKey,v as getExtractedImageLinks,u as getExtractedPages,x as getExtractedUrls,h as listExtractJobs,t as listExtractPages,j as listFundedPendingExtractJobs,n as listStaleRunningExtractJobs,i as listUnsettledExtractJobs,k as markExtractJobDispatchAttempt,l as recordExtractJobDispatchFailure,m as recordExtractSettlementFailure,s as saveExtractPages,C as setExtractJobPublicError,r as setExtractJobTotal,D as settleExtractJob,c as terminalExtractJobStatus};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fb as S,hb as h}from"./chunk-
|
|
1
|
+
import{fb as S,hb as h}from"./chunk-5NQY2N7J.js";import"./chunk-YTEAWZEN.js";import"./chunk-UKFNSXP3.js";import"./chunk-IGJKAECE.js";import"./chunk-YGBTTW5D.js";import"./chunk-CTX3NMZQ.js";import"./chunk-BDLR4CCL.js";import{H as d,I as u,J as l,K as f,L as v}from"./chunk-TOJBPATJ.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{u as a,v as b,w as c}from"./chunk-KDDU6BW3.js";import"./chunk-XG6GCEUE.js";import"./chunk-R7LCD65B.js";import"./chunk-M5QHXNFZ.js";import"./chunk-I7IS7NTC.js";import"./chunk-CTX3NMZQ.js";import"./chunk-4FROKQJN.js";import"./chunk-BDLR4CCL.js";import"./chunk-2TZBO52D.js";import"./chunk-2PXP7TMY.js";import"./chunk-TOJBPATJ.js";export{b as drainQueue,c as startWorker,a as tickOnce};
|
package/package.json
CHANGED
package/dist/chunk-NOUHD54C.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import{a as C}from"./chunk-XG6GCEUE.js";import{d as k,g as T}from"./chunk-56UT5M5Y.js";import{b as y,g as p,h as R,ha as N,ia as x,j as I,ka as P,m as A,o as O,t as d}from"./chunk-KKHTMYCD.js";import{createHash as j,randomUUID as f}from"crypto";var w=class extends Error{constructor(){super("This idempotency key was already used with different normalized inputs."),this.name="OperationIdempotencyConflictError"}};function g(e){return j("sha256").update(e).digest("hex")}function S(e){return Array.isArray(e)?e.map(S):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).sort(([t],[n])=>t.localeCompare(n)).map(([t,n])=>[t,S(n)])):e}function L(e){return JSON.stringify(S(e??{}))}function l(e,t){let n=e.trim();if(!n)throw new Error(`${t} is required`);return n}function m(e,t=2e3){return e==null?null:e.slice(0,t)}async function U(e){let t=d(),n=l(e.tool,"tool"),s=l(e.ownerScope,"ownerScope"),i=e.idempotencyKey?.trim()||null,r=e.requestFingerprint?.trim()||null;if(i==null!=(r==null))throw new Error("idempotencyKey and requestFingerprint must be supplied together");let o=i?g(`${s}\0${n}\0${i}`):null,a=e.id??f(),c=[a,e.userId??null,g(s),n,o,r,e.jobId??null,e.requestId??null,e.deploymentCommit??null,L(e.normalizedFlags),e.startedAt??new Date().toISOString()];if(o){await t.execute({sql:`INSERT OR IGNORE INTO operation_runs
|
|
2
|
-
(id, user_id, owner_scope_hash, tool, idempotency_scope_hash, request_fingerprint,
|
|
3
|
-
job_id, request_id, deployment_commit, normalized_flags_json, started_at)
|
|
4
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,args:c});let b=(await t.execute({sql:"SELECT id, request_fingerprint FROM operation_runs WHERE idempotency_scope_hash = ?",args:[o]})).rows[0];if(!b)throw new Error("Operation run insert did not produce an idempotency receipt");if(String(b.request_fingerprint)!==r)throw new w;return{id:String(b.id),replayed:String(b.id)!==a}}return await t.execute({sql:`INSERT INTO operation_runs
|
|
5
|
-
(id, user_id, owner_scope_hash, tool, idempotency_scope_hash, request_fingerprint,
|
|
6
|
-
job_id, request_id, deployment_commit, normalized_flags_json, started_at)
|
|
7
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,args:c}),{id:a,replayed:!1}}async function M(e){let t=e.endedAt??new Date().toISOString();if((await d().execute({sql:`UPDATE operation_runs
|
|
8
|
-
SET status = ?, failure_class = ?, ended_at = ?, updated_at = ?
|
|
9
|
-
WHERE id = ? AND status = 'running'`,args:[e.status,m(e.failureClass,200),t,t,e.runId]})).rowsAffected===1)return;let s=m(e.failureClass,200),i=await d().execute({sql:"SELECT status, failure_class FROM operation_runs WHERE id = ?",args:[e.runId]});if(i.rows.length===0)throw new Error(`Unknown operation run: ${e.runId}`);let r=i.rows[0]?.failure_class==null?null:String(i.rows[0]?.failure_class);if(String(i.rows[0]?.status)!==e.status||r!==s)throw new Error(`Operation run ${e.runId} is already terminal as ${String(i.rows[0]?.status)}`)}async function q(e){if(!Number.isInteger(e.attemptNumber)||e.attemptNumber<1)throw new Error("attemptNumber must be a positive integer");if(e.attemptNumber===1&&(e.parentAttemptId||e.edgeKind||e.retryKind))throw new Error("The first attempt cannot have a parent or retry edge");if(e.attemptNumber>1&&(!e.parentAttemptId||!e.edgeKind))throw new Error("Every non-first attempt requires a parentAttemptId and edgeKind");if(e.retryKind&&!["same_method_retry","provider_fallback","durable_resume","reconciliation"].includes(e.edgeKind??""))throw new Error("retryKind requires a retry or reconciliation edgeKind");let t=e.id??f();return await d().execute({sql:`INSERT INTO operation_attempts
|
|
10
|
-
(id, run_id, parent_attempt_id, attempt_number, edge_kind, retry_kind, retry_reason, retry_owner,
|
|
11
|
-
method, provider, normalized_flags_json, started_at)
|
|
12
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,args:[t,e.runId,e.parentAttemptId??null,e.attemptNumber,e.edgeKind??null,e.retryKind??null,m(e.retryReason,500),m(e.retryOwner,100),l(e.method,"method"),e.provider??null,L(e.normalizedFlags),e.startedAt??new Date().toISOString()]}),t}async function D(e){if(!Number.isInteger(e.durationMs)||e.durationMs<0)throw new Error("durationMs must be a non-negative integer");let t=e.endedAt??new Date().toISOString();if((await d().execute({sql:`UPDATE operation_attempts SET
|
|
13
|
-
status = ?, error_code = ?, error_message = ?, ended_at = ?, duration_ms = ?, updated_at = ?
|
|
14
|
-
WHERE id = ? AND status = 'running'`,args:[e.status,m(e.errorCode,200),m(e.errorMessage),t,e.durationMs,t,e.attemptId]})).rowsAffected===1)return;let s=await d().execute({sql:"SELECT status, duration_ms FROM operation_attempts WHERE id = ?",args:[e.attemptId]});if(s.rows.length===0)throw new Error(`Unknown operation attempt: ${e.attemptId}`);if(String(s.rows[0]?.status)!==e.status||Number(s.rows[0]?.duration_ms)!==e.durationMs)throw new Error(`Operation attempt ${e.attemptId} is already terminal as ${String(s.rows[0]?.status)}`)}async function v(e){let t=l(e.provider,"provider"),n=l(e.method,"method"),s=g(l(e.accountScope,"accountScope")),i=e.providerSourceKey?.trim()||null,r=i?g(i):null,o=e.id??f(),a=await d().execute({sql:`INSERT OR IGNORE INTO provider_usage_receipts
|
|
15
|
-
(id, attempt_id, provider, account_scope_hash, method, provider_source_key,
|
|
16
|
-
provider_source_key_hash, provider_status)
|
|
17
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,args:[o,e.attemptId,t,s,n,i,r,e.providerStatus??null]});if(!r){if(a.rowsAffected===1)return{id:o,replayed:!1};let _=(await d().execute({sql:"SELECT attempt_id, provider, method FROM provider_usage_receipts WHERE id = ?",args:[o]})).rows[0];if(!_||String(_.attempt_id)!==e.attemptId||String(_.provider)!==t||String(_.method)!==n)throw new Error("Provider receipt ID is already used by a different receipt");return{id:o,replayed:!0}}let u=(await d().execute({sql:`SELECT id, attempt_id FROM provider_usage_receipts
|
|
18
|
-
WHERE provider = ? AND account_scope_hash = ? AND method = ? AND provider_source_key_hash = ?`,args:[t,s,n,r]})).rows[0];if(!u)throw new Error("Provider receipt insert did not produce a source receipt");if(String(u.attempt_id)!==e.attemptId)throw new Error("Provider source identity is already attached to a different attempt");return{id:String(u.id),replayed:String(u.id)!==o}}async function H(e,t){let n=l(t,"providerSourceKey"),s=g(n);if((await d().execute({sql:`UPDATE provider_usage_receipts
|
|
19
|
-
SET provider_source_key = ?, provider_source_key_hash = ?, updated_at = datetime('now')
|
|
20
|
-
WHERE id = ? AND provider_source_key IS NULL`,args:[n,s,e]})).rowsAffected===1)return;let r=await d().execute({sql:"SELECT provider_source_key_hash FROM provider_usage_receipts WHERE id = ?",args:[e]});if(!r.rows[0])throw new Error(`Unknown provider receipt: ${e}`);if(String(r.rows[0].provider_source_key_hash)!==s)throw new Error(`Provider receipt ${e} already has a different source identity`)}async function h(e){if(e.units!=null&&(!Number.isFinite(e.units)||e.units<0))throw new Error("units must be non-negative");if(e.amountUsdNanos!=null&&(!Number.isSafeInteger(e.amountUsdNanos)||e.amountUsdNanos<0))throw new Error("amountUsdNanos must be a non-negative safe integer");if(e.costState==="actual"&&e.amountUsdNanos==null)throw new Error("actual receipts require amountUsdNanos");if(e.costState==="actual"&&e.amountUsdNanos===0&&!e.zeroCostReason?.trim())throw new Error("actual zero-cost receipts require zeroCostReason");let t=e.checkedAt??new Date().toISOString(),n=e.finalizedAt??t;if((await d().execute({sql:`UPDATE provider_usage_receipts SET
|
|
21
|
-
cost_state = ?, units = ?, unit_type = ?, amount_usd_nanos = ?, rate_source = ?, zero_cost_reason = ?,
|
|
22
|
-
provider_status = ?, provider_duration_ms = ?, provider_captcha = ?, error_code = ?, error_message = ?,
|
|
23
|
-
checked_at = ?, finalized_at = ?, updated_at = ?
|
|
24
|
-
WHERE id = ? AND (cost_state = 'pending' OR (cost_state = 'estimated' AND ? = 'actual'))`,args:[e.costState,e.units??null,e.unitType??null,e.amountUsdNanos??null,e.rateSource??null,e.zeroCostReason??null,e.providerStatus??null,e.providerDurationMs??null,e.providerCaptcha==null?null:e.providerCaptcha?1:0,m(e.errorCode,200),m(e.errorMessage),t,n,n,e.receiptId,e.costState]})).rowsAffected===1)return;let i=await d().execute({sql:"SELECT cost_state, units, unit_type, amount_usd_nanos FROM provider_usage_receipts WHERE id = ?",args:[e.receiptId]});if(i.rows.length===0)throw new Error(`Unknown provider receipt: ${e.receiptId}`);let r=i.rows[0],o=r?.units==null&&e.units==null||Number(r?.units)===e.units,a=r?.amount_usd_nanos==null&&e.amountUsdNanos==null||Number(r?.amount_usd_nanos)===e.amountUsdNanos,c=r?.unit_type==null&&e.unitType==null||String(r?.unit_type)===e.unitType;if(String(r?.cost_state)!==e.costState||!o||!a||!c)throw new Error(`Provider receipt ${e.receiptId} is already finalized as ${String(i.rows[0]?.cost_state)}`)}async function se(e){let n=(await d().execute({sql:`SELECT id FROM provider_usage_receipts
|
|
25
|
-
WHERE provider = ? AND account_scope_hash = ? AND method = ? AND provider_source_key_hash = ?`,args:[l(e.provider,"provider"),g(l(e.accountScope,"accountScope")),l(e.method,"method"),g(l(e.providerSourceKey,"providerSourceKey"))]})).rows[0];if(!n)return!1;let{provider:s,accountScope:i,method:r,providerSourceKey:o,...a}=e;return await h({...a,receiptId:String(n.id)}),!0}async function ae(e=30){if(!Number.isInteger(e)||e<1||e>365)throw new Error("retentionDays must be an integer between 1 and 365");let t=`-${e} days`,n=d(),[s,i,r]=await Promise.all([n.execute({sql:`UPDATE operation_attempts
|
|
26
|
-
SET error_message = NULL, updated_at = datetime('now')
|
|
27
|
-
WHERE ended_at < datetime('now', ?) AND error_message IS NOT NULL`,args:[t]}),n.execute({sql:`UPDATE provider_usage_receipts
|
|
28
|
-
SET provider_source_key = NULL, error_message = NULL, updated_at = datetime('now')
|
|
29
|
-
WHERE finalized_at < datetime('now', ?)
|
|
30
|
-
AND (provider_source_key IS NOT NULL OR error_message IS NOT NULL)`,args:[t]}),n.execute({sql:`UPDATE harvest_attempts
|
|
31
|
-
SET provider_session_id = NULL, \u006b\u0065\u0072\u006e\u0065\u006c_session_id = NULL, error = NULL,
|
|
32
|
-
\u006b\u0065\u0072\u006e\u0065\u006c_delete_error = NULL, browser_close_error = NULL,
|
|
33
|
-
provider_error_message = NULL, provider_detail_json = NULL,
|
|
34
|
-
provider_disconnect_message = NULL, debug_json = NULL
|
|
35
|
-
WHERE completed_at < datetime('now', ?)
|
|
36
|
-
AND (provider_session_id IS NOT NULL OR \u006b\u0065\u0072\u006e\u0065\u006c_session_id IS NOT NULL OR error IS NOT NULL
|
|
37
|
-
OR \u006b\u0065\u0072\u006e\u0065\u006c_delete_error IS NOT NULL OR browser_close_error IS NOT NULL
|
|
38
|
-
OR provider_error_message IS NOT NULL OR provider_detail_json IS NOT NULL
|
|
39
|
-
OR provider_disconnect_message IS NOT NULL OR debug_json IS NOT NULL)`,args:[t]})]);return{operationAttempts:s.rowsAffected,providerReceipts:i.rowsAffected,legacyHarvestAttempts:r.rowsAffected}}async function F(e){let n={billing_authorizations:{column:"id"},billing_events:{column:"id"},billing_debits:{column:"idempotency_key"},billing_credits:{column:"idempotency_key"},ledger:{column:"id"}}[e.billingTable],s=l(e.billingKey,"billingKey"),i=await d().execute({sql:`SELECT b.user_id AS billing_user_id, r.user_id AS run_user_id
|
|
40
|
-
FROM operation_runs r
|
|
41
|
-
JOIN ${e.billingTable} b ON CAST(b.${n.column} AS TEXT) = ?
|
|
42
|
-
WHERE r.id = ?`,args:[s,e.runId]});if(!i.rows[0])throw new Error("Billing link target or operation run does not exist");let r=i.rows[0].billing_user_id,o=i.rows[0].run_user_id;if(o!=null&&r!=null&&String(o)!==String(r))throw new Error("Billing link owner does not match operation run owner");await d().execute({sql:`INSERT OR IGNORE INTO operation_billing_links
|
|
43
|
-
(run_id, billing_table, billing_key, relation, amount_mc) VALUES (?, ?, ?, ?, ?)`,args:[e.runId,e.billingTable,s,e.relation,e.amountMc??null]})}async function de(e,t=new Date().toISOString()){let n=f();return await d().execute({sql:"INSERT INTO provider_reconciliation_runs (id, provider, started_at) VALUES (?, ?, ?)",args:[n,l(e,"provider"),t]}),n}async function le(e){if([e.checkedCount,e.completedCount,e.pendingCount,e.unavailableCount,e.failedCount].some(i=>!Number.isInteger(i)||i<0))throw new Error("Reconciliation counts must be non-negative integers");if(e.completedCount+e.pendingCount+e.unavailableCount+e.failedCount>e.checkedCount)throw new Error("Reconciliation outcome counts cannot exceed checkedCount");let n=e.completedAt??new Date().toISOString();if((await d().execute({sql:`UPDATE provider_reconciliation_runs SET
|
|
44
|
-
status = ?, checked_count = ?, completed_count = ?, pending_count = ?, unavailable_count = ?,
|
|
45
|
-
failed_count = ?, error_code = ?, completed_at = ?
|
|
46
|
-
WHERE id = ? AND status = 'running'`,args:[e.status,e.checkedCount,e.completedCount,e.pendingCount,e.unavailableCount,e.failedCount,m(e.errorCode,200),n,e.id]})).rowsAffected!==1)throw new Error(`Unknown or terminal provider reconciliation run: ${e.id}`)}async function K(e){let t=d(),[n,s,i,r]=await Promise.all([t.execute({sql:"SELECT * FROM operation_runs WHERE id = ?",args:[e]}),t.execute({sql:"SELECT * FROM operation_attempts WHERE run_id = ? ORDER BY attempt_number",args:[e]}),t.execute({sql:`SELECT r.* FROM provider_usage_receipts r
|
|
47
|
-
JOIN operation_attempts a ON a.id = r.attempt_id
|
|
48
|
-
WHERE a.run_id = ? ORDER BY a.attempt_number, r.rowid`,args:[e]}),t.execute({sql:"SELECT * FROM operation_billing_links WHERE run_id = ? ORDER BY created_at, billing_table, billing_key",args:[e]})]);return n.rows[0]?{run:n.rows[0],attempts:[...s.rows],providerReceipts:[...i.rows],billingLinks:[...r.rows]}:null}function W(e){return e instanceof Error?e.message:String(e)}function B(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 V(e){return/captcha|recaptcha|unusual traffic|google\.com\/sorry|blocked/i.test(e)}function J(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 G(e){return/proxy unavailable|proxy_unavailable|connection_test_failed|did not return a proxy id|configured fallback/i.test(e)}function Q(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 Y(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 X(e){let t=W(e);return e instanceof A?{error_code:"request_aborted",error_type:"request_aborted",message:p("request_aborted"),retryable:!0,httpStatus:408,terminalStatus:"cancelled"}:e instanceof I||V(t)?{error_code:"captcha_exhausted",error_type:"captcha",message:p("captcha_exhausted"),retryable:!0,httpStatus:503,terminalStatus:"failed"}:C(e,t)?{error_code:"vendor_unavailable",error_type:"service_unavailable",message:p("vendor_unavailable"),retryable:!0,httpStatus:503,terminalStatus:"failed"}:e instanceof O?{error_code:"location_mismatch",error_type:"location_mismatch",message:p("location_mismatch"),retryable:!0,httpStatus:503,terminalStatus:"failed"}:J(t)?{error_code:"proxy_tunnel_failed",error_type:"connection",message:p("proxy_tunnel_failed"),retryable:!0,httpStatus:503,terminalStatus:"failed"}:G(t)?{error_code:"proxy_unavailable",error_type:"connection",message:p("proxy_unavailable"),retryable:!0,httpStatus:503,terminalStatus:"failed"}:Y(t)?{error_code:"browser_session_interrupted",error_type:"extraction",message:p("browser_session_interrupted"),retryable:!0,httpStatus:503,terminalStatus:"failed"}:B(e,t)?{error_code:"harvest_timeout",error_type:"timeout",message:p("harvest_timeout"),retryable:!0,httpStatus:504,terminalStatus:"failed"}:Q(t)?{error_code:"service_unavailable",error_type:"service_unavailable",message:y,retryable:!0,httpStatus:503,terminalStatus:"failed"}:{error_code:"extraction_failed",error_type:"extraction",message:y,retryable:!1,httpStatus:500,terminalStatus:"failed"}}function me(e){return JSON.stringify({error_code:e.error_code,error_type:e.error_type,message:e.message,retryable:e.retryable})}function z(e,t={}){let n=R({errorCode:e.error_code,errorType:e.error_type,retryable:e.retryable,retryAfterSeconds:t.retryAfterSeconds,chargeStatus:t.chargeStatus,details:t.details});return{error:n.message,...n}}function _e(e,t={}){let{error:n,...s}=z(e,t);return s}function ge(e,t={}){let n=X(e);return{body:z(n,t),status:n.httpStatus}}import{createHash as Z}from"crypto";var ee=1e9;function re(e){return Z("sha256").update(JSON.stringify(e)).digest("hex")}function te(e){return`harvest:${e}`}async function we(e){let t=te(e.jobId);try{return(await U({id:t,userId:e.userId,ownerScope:`user:${e.userId}`,tool:e.tool,normalizedFlags:e.normalizedFlags,idempotencyKey:`job:${e.jobId}`,requestFingerprint:re(e.normalizedFlags),jobId:e.jobId,requestId:e.requestId??null,deploymentCommit:process.env.VERCEL_GIT_COMMIT_SHA?.trim()||process.env.GIT_COMMIT_SHA?.trim()||null})).id}catch(n){return console.warn(JSON.stringify({event:"operation_run_start_failed",job_id:e.jobId,tool:e.tool,message:n instanceof Error?n.message:String(n)})),null}}async function Se(e,t,n){if(e)try{await M({runId:e,status:t,failureClass:n})}catch(s){console.warn(JSON.stringify({event:"operation_run_finish_failed",operation_run_id:e,message:s instanceof Error?s.message:String(s)}))}}async function ve(e,t,n,s){if(!(!e||!t))try{await F({runId:e,billingTable:"billing_debits",billingKey:t,relation:n,amountMc:s})}catch(i){console.warn(JSON.stringify({event:"operation_billing_link_failed",operation_run_id:e,relation:n,message:i instanceof Error?i.message:String(i)}))}}function E(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 oe(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 $(e,t,n=0){let s=new Map,i=null;return async r=>{if(e)try{if(r.type==="started"){let a=n+r.attemptNumber;if(a>1&&!i){let _=(await K(e))?.attempts.at(-1);i=_?.id==null?null:String(_.id)}let c=await q({runId:e,attemptNumber:a,method:r.method,provider:r.provider,parentAttemptId:a===1?null:i,edgeKind:a===1?null:n>0&&r.attemptNumber===1?"durable_resume":r.retryKind==="provider_fallback"?"provider_fallback":"same_method_retry",retryKind:a===1?null:n>0&&r.attemptNumber===1?"durable_resume":r.retryKind,retryReason:a===1?null:n>0&&r.attemptNumber===1?"durable_worker_resume":r.retryReason,retryOwner:a===1?null:n>0&&r.attemptNumber===1?"durable_reconciler":"harvest",normalizedFlags:{maxAttempts:r.maxAttempts,maxQuestions:r.maxQuestions,hasLocation:!!r.location,plannedProvider:r.provider,planReason:r.planReason??null,planTimeoutMs:r.planTimeoutMs??null},startedAt:r.startedAt}),u=await v({attemptId:c,provider:r.provider,accountScope:t,method:r.method,providerStatus:"started"});s.set(r.attemptNumber,{attemptId:c,receiptId:u.id,plannedProvider:r.provider,observedProvider:null,providerMismatch:!1,method:r.method,startedAtMs:Date.parse(r.startedAt)}),i=c;return}let o=s.get(r.attemptNumber);if(!o)throw new Error(`Missing operation attempt state for attempt ${r.attemptNumber}`);if(r.type==="provider_session_started"){let a=oe(r.provider);if(o.observedProvider=a,a!==o.plannedProvider){o.providerMismatch=!0,await h({receiptId:o.receiptId,costState:"unavailable",providerStatus:"provider_mismatch",errorCode:"provider_mismatch",errorMessage:`Planned ${o.plannedProvider}; observed ${a}`,finalizedAt:r.observedAt});let c=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 v({attemptId:o.attemptId,provider:a,accountScope:t,method:c,providerStatus:"observed_provider_mismatch"});o.receiptId=u.id,o.method=c}await H(o.receiptId,r.providerSessionId);return}if(await D({attemptId:o.attemptId,status:o.providerMismatch?"failed":E(r.outcome),errorCode:o.providerMismatch?"provider_mismatch":E(r.outcome)==="succeeded"?null:r.outcome,errorMessage:r.error,durationMs:r.durationMs,endedAt:r.completedAt}),(o.observedProvider??o.plannedProvider)==="\u006b\u0065\u0072\u006e\u0065\u006c"){let a=T(r.durationMs,!0);await h({receiptId:o.receiptId,costState:"estimated",units:r.durationMs/1e3,unitType:"browser_second",amountUsdNanos:Math.round(a*ee),rateSource:`\u006b\u0065\u0072\u006e\u0065\u006c_headful_usd_per_second:${k}`,providerStatus:o.providerMismatch?"provider_mismatch":r.outcome,providerDurationMs:r.durationMs,errorCode:o.providerMismatch?"provider_mismatch":E(r.outcome)==="succeeded"?null:r.outcome,errorMessage:r.error,finalizedAt:r.completedAt})}}catch(o){console.warn(JSON.stringify({event:"operation_attempt_telemetry_failed",operation_run_id:e,attempt_number:r.attemptNumber,message:o instanceof Error?o.message:String(o)}))}}}function Ae(e,t,n=null,s="production-default",i=0){let r=$(n,s,i);return async o=>{if(await r(o),o.type==="started"){await N({jobId:e,userId:t,attemptNumber:o.attemptNumber,maxAttempts:o.maxAttempts,query:o.query,location:o.location,maxQuestions:o.maxQuestions,startedAt:o.startedAt});return}if(o.type==="provider_session_started"){await x({jobId:e,attemptNumber:o.attemptNumber,browserProvider:o.provider,providerSessionId:o.providerSessionId,observedAt:o.observedAt});return}await P({jobId:e,attemptNumber:o.attemptNumber,outcome:o.outcome,\u006b\u0065\u0072\u006e\u0065\u006cSessionId:o.\u006b\u0065\u0072\u006e\u0065\u006cSessionId,questionCount:o.questionCount,durationMs:o.durationMs,error:o.error,willRetry:o.willRetry,\u006b\u0065\u0072\u006e\u0065\u006cDeleteStarted:o.cleanup.\u006b\u0065\u0072\u006e\u0065\u006cDeleteStarted,\u006b\u0065\u0072\u006e\u0065\u006cDeleteSucceeded:o.cleanup.\u006b\u0065\u0072\u006e\u0065\u006cDeleteSucceeded,\u006b\u0065\u0072\u006e\u0065\u006cDeleteError:o.cleanup.\u006b\u0065\u0072\u006e\u0065\u006cDeleteError,browserCloseSucceeded:o.cleanup.browserCloseSucceeded,browserCloseError:o.cleanup.browserCloseError,browserProvider:o.cleanup.provider??null,providerSessionId:o.cleanup.providerSessionId??null,providerLookupStatus:o.cleanup.providerSessionId?"pending":"not_applicable",providerErrorCode:o.cleanup.providerDisconnectObserved?"browser_session_interrupted":null,providerErrorMessage:o.cleanup.providerDisconnectMessage??null,providerReasonSource:o.cleanup.providerDisconnectObserved?"client_runtime":null,providerDisconnectObserved:o.cleanup.providerDisconnectObserved??!1,providerDisconnectMessage:o.cleanup.providerDisconnectMessage??null,debug:o.debug,completedAt:o.completedAt})}}async function Ne(e,t,n=3){for(let s=1;s<=n;s++){try{let i=await fetch(e,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t),signal:AbortSignal.timeout(1e4)});if(i.ok)return;console.warn(`[webhook] attempt ${s} \u2192 ${i.status} from ${e}`)}catch(i){console.warn(`[webhook] attempt ${s} failed:`,i instanceof Error?i.message:i)}s<n&&await new Promise(i=>setTimeout(i,1e3*s*2))}console.error(`[webhook] gave up after ${n} attempts for ${e}`)}export{q as a,D as b,v as c,H as d,h as e,se as f,ae as g,de as h,le as i,X as j,me as k,z as l,_e as m,ge as n,te as o,we as p,Se as q,ve as r,Ae as s,Ne as t};
|
package/dist/chunk-UM4WSLKQ.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var o="0.90.6";export{o as a};
|
package/dist/worker-4LFWAEX2.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as R,k as g,l as P,m as _,o as w,q as v,s as C,t as h}from"./chunk-NOUHD54C.js";import"./chunk-XG6GCEUE.js";import{w as A}from"./chunk-AQXYXVOP.js";import"./chunk-M5QHXNFZ.js";import{b as f,c as D}from"./chunk-AAJG5OHF.js";import{a as b,b as y}from"./chunk-CTX3NMZQ.js";import{a as O}from"./chunk-4FROKQJN.js";import{b as k}from"./chunk-56UT5M5Y.js";import"./chunk-2TZBO52D.js";import"./chunk-2PXP7TMY.js";import{Mb as o,Qb as d,Sb as m,Ua as c,gb as H,ib as p,na as u}from"./chunk-KKHTMYCD.js";var S=2,M=0;function N(e){if(!e||typeof e!="object")return 0;let t=e;return typeof t.totalQuestions=="number"?t.totalQuestions:Array.isArray(t.flat)?t.flat.length:0}function x(e){return b.paa_base+Math.max(1,e)*b.paa}async function K(e){M++;try{let t=typeof e.options=="string"?JSON.parse(e.options):e.options,r={value:null},i=w(e.id),n=await k({op:t.serpOnly?"serp":"paa",userId:Number(e.user_id),headlessSentOut:r,operationRunId:i,operationAccountScope:"production-default"},()=>A({...t,\u006b\u0065\u0072\u006e\u0065\u006cApiKey:O(),headless:!0,format:"json",outputDir:"/tmp/paa-output-api",onAttemptEvent:C(e.id,e.user_id,i)}));await H(e.id,n),await v(i,"succeeded");let l=await u(e.id,e.user_id);if(typeof t.billingHoldMc=="number"&&t.billingDebitKey){let s=t.serpOnly?y(r.value):x(N(n));await m(Number(e.user_id),t.billingDebitKey,s,t.serpOnly?"serp_refund":"paa_refund",t.serpOnly?"SERP search settlement":"PAA harvest settlement",t.serpOnly?"serp_search":"paa_harvest")}else if(!t.serpOnly&&typeof t.billingHoldMc=="number"){let s=x(N(n)),a=t.billingHoldMc-s;a>0?await o(e.user_id,a,"paa_refund","overestimate refund"):a<0&&await d(e.user_id,-a,"paa",t.query??e.query)}else if(t.serpOnly&&typeof t.billingHoldMc=="number"){let s=y(r.value),a=t.billingHoldMc-s;a>0?await o(e.user_id,a,"serp_refund","headless-mode pricing settle"):a<0&&await d(e.user_id,-a,"serp",t.query??e.query)}e.callback_url&&await h(e.callback_url,{job_id:e.id,status:"done",result:D(n),attempts:f(l)})}catch(t){console.error("[harvest/worker] failed",{jobId:e.id,error:t instanceof Error?t.message:String(t)});let r=R(t);await v(w(e.id),r.error_code==="harvest_timeout"?"timed_out":r.terminalStatus,r.error_code);let i=typeof e.options=="string"?JSON.parse(e.options):e.options,n=typeof i.billingHoldMc=="number"&&i.billingHoldMc>0;await p(e.id,g(r),_(r,{chargeStatus:n?"refund_pending":"not_charged"}));let l=await u(e.id,e.user_id);try{n&&(i.billingDebitKey?await m(Number(e.user_id),i.billingDebitKey,0,i.serpOnly?"serp_refund":"paa_refund","failed call",i.serpOnly?"serp_search":"paa_harvest"):await o(e.user_id,i.billingHoldMc,"refund","failed call"),await p(e.id,g(r),_(r,{chargeStatus:"refunded"})))}catch{}e.callback_url&&await h(e.callback_url,{job_id:e.id,status:"failed",...P(r),attempts:f(l)})}finally{M--}}async function J(){let e=await c();if(!e)return{claimed:!1};let t=Date.now();return await K(e),{claimed:!0,jobId:e.id,completed:!0,durationMs:Date.now()-t}}async function X(e){let t=[];for(let r=0;r<e.maxJobs&&!(Date.now()>=e.deadlineMs);r++){let i=await J();if(t.push(i),!i.claimed)break}return t}function $(){setInterval(async()=>{if(M>=S)return;let e=await c();e&&K(e)},2e3),console.log(`[worker] started \u2014 polling every 2s, max ${S} concurrent`)}export{X as drainQueue,$ as startWorker,J as tickOnce};
|