@shipstatic/ship 2.2.0-beta.4 → 2.2.0-beta.6

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/README.md CHANGED
@@ -230,6 +230,25 @@ const ship = new Ship({ session: true });
230
230
  ship.setToken('ship-...');
231
231
  ```
232
232
 
233
+ ### Retries
234
+
235
+ Failed requests are retried automatically: transport failures (including a
236
+ timeout) and 500/502/503/504, twice by default, with full-jitter exponential
237
+ backoff. `maxRetries` is the knob; `0` disables it.
238
+
239
+ ```javascript
240
+ const ship = new Ship({ token: 'ship-...', maxRetries: 5 });
241
+ ```
242
+
243
+ Deliberately never retried: a maintenance 503 (its message says when to come
244
+ back), 429 (the rate limiter has answered), `PUT`/`DELETE` (a repeat can
245
+ misreport a lost success as a failure), anything stopped by a `signal` you
246
+ supplied, and any other non-`GET` without an `Idempotency-Key` — with the key,
247
+ a deploy replays its stored result instead of creating a second one.
248
+
249
+ `timeout` is the ceiling on one ATTEMPT. For a hard overall deadline pass your
250
+ own `signal` (`AbortSignal.timeout(ms)`), which is never retried past.
251
+
233
252
  ### Deploy Options
234
253
 
235
254
  ```typescript
package/dist/browser.d.ts CHANGED
@@ -1883,8 +1883,31 @@ interface ShipClientOptions {
1883
1883
  /**
1884
1884
  * Timeout in milliseconds for every API request made by this client
1885
1885
  * instance. Defaults to 30 seconds.
1886
+ *
1887
+ * With retries, this is the ceiling on an ATTEMPT rather than on the wall
1888
+ * clock — each attempt is an honest request and deserves the ceiling you
1889
+ * named, and {@link ShipClientOptions.maxRetries} is the lever on the total.
1890
+ * For a hard overall deadline, pass your own `signal`
1891
+ * (`AbortSignal.timeout(ms)`): the client never retries past a signal you
1892
+ * supplied.
1886
1893
  */
1887
1894
  timeout?: number | undefined;
1895
+ /**
1896
+ * How many times to retry a failed request. Defaults to 2 (three attempts);
1897
+ * `0` disables retrying entirely.
1898
+ *
1899
+ * Retried: transport failures (including a timeout — nothing was exchanged
1900
+ * either way) and 500/502/503/504, with full-jitter exponential backoff.
1901
+ *
1902
+ * NOT retried, each deliberately: a maintenance 503 (a state, not a fault —
1903
+ * its message says when to come back), 429 (the rate limiter has just
1904
+ * answered), anything stopped by a `signal` you supplied, and any request
1905
+ * that cannot be safely repeated — `PUT`/`DELETE` are excluded outright, and
1906
+ * other non-`GET` methods retry only when they carry an `Idempotency-Key`,
1907
+ * which is what lets a deploy replay its stored result instead of creating a
1908
+ * second one.
1909
+ */
1910
+ maxRetries?: number | undefined;
1888
1911
  /**
1889
1912
  * When true, the client authenticates with the first-party cookie session
1890
1913
  * (`AuthMethod.SESSION`) — requests are sent with `credentials: 'include'`
@@ -2009,6 +2032,7 @@ declare class ApiHttp extends SimpleEvents {
2009
2032
  private readonly session;
2010
2033
  private readonly caller;
2011
2034
  private readonly timeout;
2035
+ private readonly maxRetries;
2012
2036
  private readonly deployTimeout;
2013
2037
  private readonly deployBuildTimeout;
2014
2038
  private readonly fetch;
@@ -2022,9 +2046,36 @@ declare class ApiHttp extends SimpleEvents {
2022
2046
  */
2023
2047
  setGlobalHeaders(headers: Record<string, string>): void;
2024
2048
  /**
2025
- * Execute HTTP request with timeout, events, and error handling
2049
+ * Execute an HTTP request, retrying the failures that are worth retrying.
2050
+ *
2051
+ * The loop lives here because `attemptOnce` is already the single wrap point
2052
+ * for headers, the timeout signal, the events and error normalization — so
2053
+ * an attempt is a whole request and nothing has to be undone between two.
2054
+ *
2055
+ * **Events stay honest across attempts**: `request` and `error` fire per
2056
+ * attempt, so a consumer counting requests sees what actually went out;
2057
+ * `response` fires once, on the one that worked.
2058
+ *
2059
+ * **The caller's `timeout` governs an ATTEMPT, not the wall clock.** Each
2060
+ * attempt is an honest request and deserves the ceiling the caller named;
2061
+ * `maxRetries` is the lever on the total. A caller who wants a hard overall
2062
+ * deadline passes their own `signal` — see `isRetryable` for why that ends
2063
+ * the loop even when it is a timeout.
2026
2064
  */
2027
2065
  private executeRequest;
2066
+ /**
2067
+ * Is this failure worth another attempt?
2068
+ *
2069
+ * Two axes, and both must say yes: what went wrong, and whether the request
2070
+ * is one that may be sent twice.
2071
+ */
2072
+ private isRetryable;
2073
+ /** Did this request carry the header that makes a repeat safe? */
2074
+ private hasIdempotencyKey;
2075
+ /**
2076
+ * One attempt: headers, timeout signal, events, and error normalization.
2077
+ */
2078
+ private attemptOnce;
2028
2079
  /**
2029
2080
  * Simple request - returns data only
2030
2081
  */
@@ -2385,6 +2436,56 @@ interface MD5Result {
2385
2436
  }
2386
2437
  declare function calculateMD5(input: Blob | Buffer | string): Promise<MD5Result>;
2387
2438
 
2439
+ /**
2440
+ * @file One ordered table of deploy-file rules, and the single evaluation two
2441
+ * renderers share.
2442
+ *
2443
+ * **The defect this closes:** one rule was rendering as three sentences. A
2444
+ * file over the size cap said `File x is too large. Maximum allowed size is
2445
+ * 20MB.` from the deploy pipelines, `File size (21 MB) exceeds limit of 20 MB`
2446
+ * from `validateFiles`, and `File too large. Maximum 20971520 bytes allowed`
2447
+ * from the API — against the dual-validation doctrine that an error reads the
2448
+ * same wherever it was caught (root `CLAUDE.md`). Both pipelines also restated
2449
+ * the whole ordered check, so node/browser parity was a comment.
2450
+ *
2451
+ * **A rule states a predicate and a sentence; a renderer chooses only how to
2452
+ * DELIVER it.** That is the `SHAPES`-table move (`cli/formatters.ts`) applied
2453
+ * to validation: the throwing renderer raises the first broken rule, the
2454
+ * collecting renderer records it, and neither authors prose. Adding a rule is
2455
+ * a row, and both surfaces get it in the same position by construction.
2456
+ *
2457
+ * **Wording follows the API where a choice existed**, so the deferred Phase B
2458
+ * — promoting this table to `@shipstatic/types` with the API consuming it —
2459
+ * has less to move. Two deliberate deviations, recorded rather than silent:
2460
+ *
2461
+ * - **Sizes are formatted, not raw bytes.** The API says `20971520 bytes`;
2462
+ * a browser upload UI showing that is worse for the person reading it, and
2463
+ * the unit is the smaller half of the sentence to reconcile later.
2464
+ * - **The path is named.** The API has no path to name; the throwing renderer
2465
+ * has nothing BUT the message, so dropping it would leave a CLI user asking
2466
+ * which file.
2467
+ *
2468
+ * Out of scope, and left where they are: `validateDeployPath` (a rule about
2469
+ * the deploy PATH rather than the file, and pipelines-only), and
2470
+ * `validateFiles`' UI-tier pre-checks — empty, negative, count, unbuilt
2471
+ * marker, processing error — which have one holder each and no drift.
2472
+ */
2473
+
2474
+ /** What a rule is asked about: one file, and the deploy so far. */
2475
+ interface FileRuleInput {
2476
+ /** The path this file will be served at. */
2477
+ readonly path: string;
2478
+ /** This file's size in bytes. */
2479
+ readonly size: number;
2480
+ /** Bytes accumulated INCLUDING this file — the total rule's subject. */
2481
+ readonly totalSize: number;
2482
+ }
2483
+
2484
+ /**
2485
+ * @file Shared security validation for the deploy pipeline.
2486
+ * Used by both Node.js and browser file processing pipelines.
2487
+ */
2488
+
2388
2489
  /**
2389
2490
  * Validate a deploy path for security concerns.
2390
2491
  * Rejects paths containing path traversal patterns or null bytes.
@@ -2403,24 +2504,22 @@ declare function calculateMD5(input: Blob | Buffer | string): Promise<MD5Result>
2403
2504
  */
2404
2505
  declare function validateDeployPath(deployPath: string, sourceIdentifier: string): void;
2405
2506
  /**
2406
- * Validate a deploy file's name and extension.
2407
- * Rejects unsafe filenames (shell/URL-dangerous chars, reserved names)
2408
- * and file extensions the platform refuses to host.
2507
+ * The THROWING renderer of `FILE_RULES` — the deploy pipelines' shape.
2409
2508
  *
2410
- * **The blocklist is the platform's, delivered not this package's.** It
2411
- * arrives as `PlatformLimits.blockedExtensions` from `GET /limits`, which the
2412
- * client has already fetched by the time any file is processed. That is what
2413
- * keeps a pinned CLI from enforcing a policy the platform has moved on from,
2414
- * in either direction. Callers pass `[]` when the API sent no list (one that
2415
- * predates the field): the check then does nothing and the API refuses the
2416
- * file at the boundary, which is the correct place for it to be refused.
2509
+ * It raises the first rule the file breaks and nothing else: the rules, their
2510
+ * order and their sentences all live in `file-rules.ts`, so this function
2511
+ * cannot re-order, skip or reword one. That is what makes node/browser parity
2512
+ * structural both pipelines call this, and this calls the one table.
2417
2513
  *
2418
- * @param deployPath - The deployment path to validate
2419
- * @param sourceIdentifier - Human-readable identifier for error messages
2420
- * @param blockedExtensions - The platform's blocklist, from `/limits`
2421
- * @throws {ShipError} If the filename is unsafe or the extension is blocked
2514
+ * Its counterpart is the collecting renderer in `file-validation.ts`
2515
+ * (`validateFiles`), which reaches the same verdict and reports it as a list
2516
+ * instead of a throw.
2517
+ *
2518
+ * @param input - The file and the deploy so far (`totalSize` INCLUDES it)
2519
+ * @param limits - The platform's limits, from `/limits`
2520
+ * @throws {ShipError} The first broken rule's sentence
2422
2521
  */
2423
- declare function validateDeployFile(deployPath: string, sourceIdentifier: string, blockedExtensions: readonly string[]): void;
2522
+ declare function validateDeployFile(input: FileRuleInput, limits: PlatformLimits): void;
2424
2523
 
2425
2524
  /**
2426
2525
  * Utility functions for string manipulation.
package/dist/browser.js CHANGED
@@ -1,2 +1,2 @@
1
- var Je=Object.create;var B=Object.defineProperty;var Qe=Object.getOwnPropertyDescriptor;var Ze=Object.getOwnPropertyNames;var et=Object.getPrototypeOf,tt=Object.prototype.hasOwnProperty;var nt=(t,n,e)=>n in t?B(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e;var L=(t,n)=>()=>(t&&(n=t(t=0)),n);var ye=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),rt=(t,n)=>{for(var e in n)B(t,e,{get:n[e],enumerable:!0})},it=(t,n,e,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let p of Ze(n))!tt.call(t,p)&&p!==e&&B(t,p,{get:()=>n[p],enumerable:!(a=Qe(n,p))||a.enumerable});return t};var H=(t,n,e)=>(e=t!=null?Je(et(t)):{},it(n||!t||!t.__esModule?B(e,"default",{value:t,enumerable:!0}):e,t));var G=(t,n,e)=>nt(t,typeof n!="symbol"?n+"":n,e);function Ft(t){if(!t||typeof t!="string")return;let n=t.trim().toLowerCase();return Object.values(st).includes(n)?n:void 0}function Ee(t){if(t==null)return;if(typeof t!="string")throw f.validation("Idempotency key must be a string.");let n=t.trim();if(!n)throw f.validation("Idempotency key must not be empty.");if(n.length>z.MAX_LENGTH)throw f.validation(`Idempotency key must be at most ${z.MAX_LENGTH} characters.`);return n}function pt(t){let n=t.code;return n==="ERR_INVALID_URL"?!1:typeof n=="string"?!0:t instanceof TypeError?!/\burl\b/i.test(t.message):!1}function Ae(t){return t!==null&&typeof t=="object"&&"name"in t&&t.name==="ShipError"&&"status"in t}function ut(t){let n=t.replace(/\\/g,"/").split("/").pop()??"",e=n.lastIndexOf(".");return e<=0||e===n.length-1?null:n.slice(e+1).toLowerCase()}function V(t,n){let e=ut(t);return e===null?!1:Array.isArray(n)?n.includes(e):n.has(e)}function De(t){return dt.test(t)}function K(t){return t.replace(/\\/g,"/").split("/").filter(Boolean).some(e=>ft.has(e))}function mt(t){return t.startsWith(Te.PREFIX)?C.API_KEY:t.startsWith(Se.PREFIX)?C.DEPLOY_TOKEN:C.OPAQUE}function Ie(t){let n=t.charCodeAt(0)===65279?t.slice(1):t,e;try{e=JSON.parse(n)}catch(a){throw f.config(`invalid JSON format in config: ${a.message}`,{filePath:N})}if(e===null||typeof e!="object"||Array.isArray(e))throw f.config(`${N} must contain a JSON object`,{filePath:N})}function be(t,n,e){if(!t.startsWith(n.PREFIX))throw f.validation(`${e} must start with "${n.PREFIX}"`);if(t.length!==n.TOTAL_LENGTH)throw f.validation(`${e} must be ${n.TOTAL_LENGTH} characters total (${n.PREFIX} + ${n.HEX_LENGTH} hex chars)`);let a=t.slice(n.PREFIX.length);if(!new RegExp(`^[a-f0-9]{${n.HEX_LENGTH}}$`,"i").test(a))throw f.validation(`${e} must contain ${n.HEX_LENGTH} hexadecimal characters after "${n.PREFIX}" prefix`)}function ht(t){be(t,Te,"API key")}function yt(t){be(t,Se,"Deploy token")}function ee(t){switch(mt(t)){case C.API_KEY:ht(t);return;case C.DEPLOY_TOKEN:yt(t);return;case C.OPAQUE:if(!t)throw f.validation("Token must be a non-empty string")}}function we(t){if(!t||t.length>$.MAX_LENGTH||!$.PATTERN.test(t))throw f.validation(`Caller must be 1-${$.MAX_LENGTH} characters: letters, digits, dots, underscores, or hyphens`)}function Bt(t){try{let n=new URL(t);if(!["http:","https:"].includes(n.protocol))throw f.validation("API URL must use http:// or https:// protocol");if(n.pathname!=="/"&&n.pathname!=="")throw f.validation("API URL must not contain a path");if(n.search||n.hash)throw f.validation("API URL must not contain query parameters or fragments")}catch(n){throw Ae(n)?n:f.validation("API URL must be a valid URL")}}function Ht(t){return/^[a-z]+-[a-z]+-[a-z0-9]{7}(\.[a-z0-9.-]+)?$/i.test(t)}function Pe(t,n){return t.endsWith(`.${n}`)}function Vt(t,n){return!Pe(t,n)}function Kt(t,n){return Pe(t,n)?t.slice(0,-(n.length+1)):null}function jt(t){return`https://${t}`}function Yt(t){return`https://${t}`}function qt(t){return!t||t.length===0?null:JSON.stringify(t)}function Xt(t){if(!t)return[];try{let n=JSON.parse(t);return Array.isArray(n)?n:[]}catch{return[]}}function ne(t){if(t==null)return;if(typeof t!="string")throw f.validation("Password must be a string");let n=t.trim();if(n.length<k.MIN_LENGTH||n.length>k.MAX_LENGTH)throw f.validation(`Password must be between ${k.MIN_LENGTH} and ${k.MAX_LENGTH} characters`);return n}var vt,st,Ot,z,Ct,D,x,E,ot,Z,at,lt,f,ct,$t,dt,ft,Ut,ge,Te,Se,$,C,Mt,N,Re,j,te,Gt,kt,zt,R,F,Le,k,I=L(()=>{"use strict";vt={PENDING:"pending",SUCCESS:"success",FAILED:"failed",DELETING:"deleting"},st={WEB:"web",SDK:"sdk",CLI:"cli",MCP:"mcp",GIT:"git",N8N:"n8n",GPT:"gpt",VSC:"vsc"},Ot={PENDING:"pending",PARTIAL:"partial",SUCCESS:"success",PAUSED:"paused"},z={HEADER:"Idempotency-Key",MAX_LENGTH:256,WINDOW_SECONDS:1440*60};Ct={FREE:"free",STANDARD:"standard",SPONSORED:"sponsored",ENTERPRISE:"enterprise",SUSPENDED:"suspended",TERMINATING:"terminating",TERMINATED:"terminated"},D={DEPLOYMENTS:"/deployments",DEPLOYMENT:t=>`/deployments/${t}`,DEPLOYMENT_CONFIG:t=>`/deployments/${t}/config`,DOMAINS:"/domains",DOMAIN:t=>`/domains/${t}`,DOMAIN_VERIFY:t=>`/domains/${t}/verify`,DOMAIN_DNS:t=>`/domains/${t}/dns`,DOMAIN_RECORDS:t=>`/domains/${t}/records`,DOMAIN_SHARE:t=>`/domains/${t}/share`,DOMAIN_PROPAGATION:t=>`/domains/${t}/propagation`,DOMAINS_VALIDATE:"/domains/validate",TOKENS:"/tokens",TOKEN:t=>`/tokens/${t}`,ACCOUNT:"/account",ACCOUNT_KEY:"/account/key",ACCOUNT_CLAIM:"/account/claim",ACTIVITIES:"/activities",LABELS:"/labels",LIMITS:"/limits",PING:"/ping",SETUP:"/setup",SPA_CHECK:"/spa-check",UPLOAD:"/upload"},x={FILES:"files[]",CHECKSUMS:"checksums",LABELS:"labels",VIA:"via",PASSWORD:"password",BUILD:"build",PRERENDER:"prerender",SPA:"spa",CAPTCHA:"captcha"},E={Validation:"validation_failed",NotFound:"not_found",Forbidden:"forbidden",RateLimit:"rate_limit_exceeded",Authentication:"authentication_failed",Business:"business_logic_error",Api:"internal_server_error",Maintenance:"maintenance",Network:"network_error",Cancelled:"operation_cancelled",File:"file_error",Config:"config_error"},ot=new Set([E.Network,E.Cancelled,E.File,E.Config]),Z={client:new Set([E.Business,E.Cancelled,E.Config,E.File,E.Forbidden,E.NotFound,E.RateLimit,E.Validation]),network:new Set([E.Network]),auth:new Set([E.Authentication])},at=new Set(Object.values(E).filter(t=>!ot.has(t))),lt=200;f=class t extends Error{constructor(e,a,p,c){super(a);G(this,"type");G(this,"status");G(this,"details");this.type=e,this.status=p,this.details=c,this.name="ShipError"}toResponse(){let e=this.details,a=this.type===E.Authentication&&e?.internal?void 0:this.details;return{error:this.type,message:this.message,status:this.status,details:a}}static async fromHttpResponse(e,a){let p,c,h;try{if(e.headers.get("content-type")?.includes("application/json")){let m=await e.json();if(m&&typeof m=="object"){let T=m;typeof T.message=="string"?p=T.message:typeof T.error=="string"&&(p=T.error),c=T.details,typeof T.error=="string"&&at.has(T.error)&&(h=T.error)}}else{let m=(await e.text()).trim();m&&!m.startsWith("<")&&m.length<=lt&&(p=m)}}catch{}let y=e.headers.get("retry-after");if(y!==null){let g=y.trim(),m=/^\d+$/.test(g)?Number(g):Math.ceil((Date.parse(g)-Date.now())/1e3);if(Number.isFinite(m)&&m>=0){let T=c&&typeof c=="object"?c:{};T.retryAfter===void 0&&(c={...T,retryAfter:m})}}p=p||`${a||"Request"} failed with status ${e.status}`;let d=h??(e.status===401?E.Authentication:e.status===403?E.Forbidden:e.status===429?E.RateLimit:E.Api);return new t(d,p,e.status,c)}static fromFetchError(e,a){if(Ae(e))return e;let p=a||"Request",c=e?.name;return c==="AbortError"?t.cancelled(`${p} was cancelled`):c==="TimeoutError"?t.network(`${p} timed out`,{cause:e}):e instanceof Error?pt(e)?t.network(`${p} failed: ${e.message}`,{cause:e}):new t(E.Api,`${p} failed: ${e.message}`):new t(E.Api,`${p} failed: Unknown error`)}static validation(e,a){return new t(E.Validation,e,400,a)}static notFound(e,a){let p=a?`${e} ${a} not found`:`${e} not found`;return new t(E.NotFound,p,404)}static forbidden(e,a){return new t(E.Forbidden,e,403,a)}static rateLimit(e="Too many requests",a){return new t(E.RateLimit,e,429,a)}static authentication(e="Authentication required",a){return new t(E.Authentication,e,401,a)}static business(e,a=400,p){return new t(E.Business,e,a,p)}static network(e,a){return new t(E.Network,e,void 0,a)}static cancelled(e,a){return new t(E.Cancelled,e,void 0,a)}static file(e,a){return new t(E.File,e,void 0,a)}static config(e,a){return new t(E.Config,e,void 0,a)}static api(e,a=500,p){return new t(E.Api,e,a,p)}static maintenance(e,a){return new t(E.Maintenance,e,503,a)}isClientError(){return Z.client.has(this.type)?!0:this.status!==void 0&&this.status>=400&&this.status<500}isNetworkError(){return Z.network.has(this.type)}isAuthError(){return Z.auth.has(this.type)}isType(e){return this.type===e}};ct=["html","htm","xhtml","xml","txt","md","markdown","pdf","csv","json","jsonc","webmanifest","map","toml","yaml","yml","rss","atom","css","scss","sass","less","js","mjs","cjs","jsx","ts","tsx","wasm","vue","svelte","png","jpg","jpeg","gif","webp","avif","svg","ico","bmp","tif","tiff","heic","heif","woff","woff2","ttf","otf","eot","mp3","wav","ogg","oga","opus","m4a","aac","flac","weba","mp4","webm","ogv","mov","m4v","avi","glb","gltf","usdz","vtt","srt","zip"],$t=ct.map(t=>`.${t}`).join(","),dt=/[\x00-\x1f\x7f#?%\\<>"]/;ft=new Set(["node_modules","package.json"]);Ut="/auth",ge={SESSION:"session",API_KEY:"apiKey",TOKEN:"token",AGENT:"agent",OAUTH:"oauth",WEBHOOK:"webhook",SYSTEM:"system"},Te={PREFIX:"ship-",HEX_LENGTH:32,TOTAL_LENGTH:37,HINT_LENGTH:4},Se={PREFIX:"deploy-",HEX_LENGTH:32,TOTAL_LENGTH:39},$={HEADER:"X-Caller",MAX_LENGTH:128,PATTERN:/^[a-zA-Z0-9._-]+$/},C={API_KEY:ge.API_KEY,DEPLOY_TOKEN:ge.TOKEN,OPAQUE:"opaque"};Mt={ACCOUNT_READ:"account:read",DEPLOYMENTS_READ:"deployments:read",DEPLOYMENTS_WRITE:"deployments:write",DOMAINS_READ:"domains:read",DOMAINS_WRITE:"domains:write"},N="ship.json",Re={rewrites:[{source:"/(.*)",destination:"/index.html"}]},j={INDEX_FILE:"index.html",MAX_INDEX_BYTES:100*1024};te="https://api.shipstatic.com",Gt={TOKEN:"SHIP_TOKEN",API_URL:"SHIP_API_URL"},kt="https://my.shipstatic.com/api-key",zt=4320*60,R={PENDING:"pending",PROCESSING_ERROR:"processing_error",EXCLUDED:"excluded",VALIDATION_FAILED:"validation_failed",READY:"ready"};F={MIN_LENGTH:3,MAX_LENGTH:25,MAX_COUNT:10,SEPARATORS:"._-"},Le=/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/;k={MIN_LENGTH:6,MAX_LENGTH:128}});var Oe=ye((Ne,ve)=>{"use strict";(function(t){if(typeof Ne=="object")ve.exports=t();else if(typeof define=="function"&&define.amd)define(t);else{var n;try{n=window}catch{n=self}n.SparkMD5=t()}})(function(t){"use strict";var n=function(u,l){return u+l&4294967295},e=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function a(u,l,i,r,o,s){return l=n(n(l,u),n(r,s)),n(l<<o|l>>>32-o,i)}function p(u,l){var i=u[0],r=u[1],o=u[2],s=u[3];i+=(r&o|~r&s)+l[0]-680876936|0,i=(i<<7|i>>>25)+r|0,s+=(i&r|~i&o)+l[1]-389564586|0,s=(s<<12|s>>>20)+i|0,o+=(s&i|~s&r)+l[2]+606105819|0,o=(o<<17|o>>>15)+s|0,r+=(o&s|~o&i)+l[3]-1044525330|0,r=(r<<22|r>>>10)+o|0,i+=(r&o|~r&s)+l[4]-176418897|0,i=(i<<7|i>>>25)+r|0,s+=(i&r|~i&o)+l[5]+1200080426|0,s=(s<<12|s>>>20)+i|0,o+=(s&i|~s&r)+l[6]-1473231341|0,o=(o<<17|o>>>15)+s|0,r+=(o&s|~o&i)+l[7]-45705983|0,r=(r<<22|r>>>10)+o|0,i+=(r&o|~r&s)+l[8]+1770035416|0,i=(i<<7|i>>>25)+r|0,s+=(i&r|~i&o)+l[9]-1958414417|0,s=(s<<12|s>>>20)+i|0,o+=(s&i|~s&r)+l[10]-42063|0,o=(o<<17|o>>>15)+s|0,r+=(o&s|~o&i)+l[11]-1990404162|0,r=(r<<22|r>>>10)+o|0,i+=(r&o|~r&s)+l[12]+1804603682|0,i=(i<<7|i>>>25)+r|0,s+=(i&r|~i&o)+l[13]-40341101|0,s=(s<<12|s>>>20)+i|0,o+=(s&i|~s&r)+l[14]-1502002290|0,o=(o<<17|o>>>15)+s|0,r+=(o&s|~o&i)+l[15]+1236535329|0,r=(r<<22|r>>>10)+o|0,i+=(r&s|o&~s)+l[1]-165796510|0,i=(i<<5|i>>>27)+r|0,s+=(i&o|r&~o)+l[6]-1069501632|0,s=(s<<9|s>>>23)+i|0,o+=(s&r|i&~r)+l[11]+643717713|0,o=(o<<14|o>>>18)+s|0,r+=(o&i|s&~i)+l[0]-373897302|0,r=(r<<20|r>>>12)+o|0,i+=(r&s|o&~s)+l[5]-701558691|0,i=(i<<5|i>>>27)+r|0,s+=(i&o|r&~o)+l[10]+38016083|0,s=(s<<9|s>>>23)+i|0,o+=(s&r|i&~r)+l[15]-660478335|0,o=(o<<14|o>>>18)+s|0,r+=(o&i|s&~i)+l[4]-405537848|0,r=(r<<20|r>>>12)+o|0,i+=(r&s|o&~s)+l[9]+568446438|0,i=(i<<5|i>>>27)+r|0,s+=(i&o|r&~o)+l[14]-1019803690|0,s=(s<<9|s>>>23)+i|0,o+=(s&r|i&~r)+l[3]-187363961|0,o=(o<<14|o>>>18)+s|0,r+=(o&i|s&~i)+l[8]+1163531501|0,r=(r<<20|r>>>12)+o|0,i+=(r&s|o&~s)+l[13]-1444681467|0,i=(i<<5|i>>>27)+r|0,s+=(i&o|r&~o)+l[2]-51403784|0,s=(s<<9|s>>>23)+i|0,o+=(s&r|i&~r)+l[7]+1735328473|0,o=(o<<14|o>>>18)+s|0,r+=(o&i|s&~i)+l[12]-1926607734|0,r=(r<<20|r>>>12)+o|0,i+=(r^o^s)+l[5]-378558|0,i=(i<<4|i>>>28)+r|0,s+=(i^r^o)+l[8]-2022574463|0,s=(s<<11|s>>>21)+i|0,o+=(s^i^r)+l[11]+1839030562|0,o=(o<<16|o>>>16)+s|0,r+=(o^s^i)+l[14]-35309556|0,r=(r<<23|r>>>9)+o|0,i+=(r^o^s)+l[1]-1530992060|0,i=(i<<4|i>>>28)+r|0,s+=(i^r^o)+l[4]+1272893353|0,s=(s<<11|s>>>21)+i|0,o+=(s^i^r)+l[7]-155497632|0,o=(o<<16|o>>>16)+s|0,r+=(o^s^i)+l[10]-1094730640|0,r=(r<<23|r>>>9)+o|0,i+=(r^o^s)+l[13]+681279174|0,i=(i<<4|i>>>28)+r|0,s+=(i^r^o)+l[0]-358537222|0,s=(s<<11|s>>>21)+i|0,o+=(s^i^r)+l[3]-722521979|0,o=(o<<16|o>>>16)+s|0,r+=(o^s^i)+l[6]+76029189|0,r=(r<<23|r>>>9)+o|0,i+=(r^o^s)+l[9]-640364487|0,i=(i<<4|i>>>28)+r|0,s+=(i^r^o)+l[12]-421815835|0,s=(s<<11|s>>>21)+i|0,o+=(s^i^r)+l[15]+530742520|0,o=(o<<16|o>>>16)+s|0,r+=(o^s^i)+l[2]-995338651|0,r=(r<<23|r>>>9)+o|0,i+=(o^(r|~s))+l[0]-198630844|0,i=(i<<6|i>>>26)+r|0,s+=(r^(i|~o))+l[7]+1126891415|0,s=(s<<10|s>>>22)+i|0,o+=(i^(s|~r))+l[14]-1416354905|0,o=(o<<15|o>>>17)+s|0,r+=(s^(o|~i))+l[5]-57434055|0,r=(r<<21|r>>>11)+o|0,i+=(o^(r|~s))+l[12]+1700485571|0,i=(i<<6|i>>>26)+r|0,s+=(r^(i|~o))+l[3]-1894986606|0,s=(s<<10|s>>>22)+i|0,o+=(i^(s|~r))+l[10]-1051523|0,o=(o<<15|o>>>17)+s|0,r+=(s^(o|~i))+l[1]-2054922799|0,r=(r<<21|r>>>11)+o|0,i+=(o^(r|~s))+l[8]+1873313359|0,i=(i<<6|i>>>26)+r|0,s+=(r^(i|~o))+l[15]-30611744|0,s=(s<<10|s>>>22)+i|0,o+=(i^(s|~r))+l[6]-1560198380|0,o=(o<<15|o>>>17)+s|0,r+=(s^(o|~i))+l[13]+1309151649|0,r=(r<<21|r>>>11)+o|0,i+=(o^(r|~s))+l[4]-145523070|0,i=(i<<6|i>>>26)+r|0,s+=(r^(i|~o))+l[11]-1120210379|0,s=(s<<10|s>>>22)+i|0,o+=(i^(s|~r))+l[2]+718787259|0,o=(o<<15|o>>>17)+s|0,r+=(s^(o|~i))+l[9]-343485551|0,r=(r<<21|r>>>11)+o|0,u[0]=i+u[0]|0,u[1]=r+u[1]|0,u[2]=o+u[2]|0,u[3]=s+u[3]|0}function c(u){var l=[],i;for(i=0;i<64;i+=4)l[i>>2]=u.charCodeAt(i)+(u.charCodeAt(i+1)<<8)+(u.charCodeAt(i+2)<<16)+(u.charCodeAt(i+3)<<24);return l}function h(u){var l=[],i;for(i=0;i<64;i+=4)l[i>>2]=u[i]+(u[i+1]<<8)+(u[i+2]<<16)+(u[i+3]<<24);return l}function y(u){var l=u.length,i=[1732584193,-271733879,-1732584194,271733878],r,o,s,w,_,O;for(r=64;r<=l;r+=64)p(i,c(u.substring(r-64,r)));for(u=u.substring(r-64),o=u.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],r=0;r<o;r+=1)s[r>>2]|=u.charCodeAt(r)<<(r%4<<3);if(s[r>>2]|=128<<(r%4<<3),r>55)for(p(i,s),r=0;r<16;r+=1)s[r]=0;return w=l*8,w=w.toString(16).match(/(.*?)(.{0,8})$/),_=parseInt(w[2],16),O=parseInt(w[1],16)||0,s[14]=_,s[15]=O,p(i,s),i}function d(u){var l=u.length,i=[1732584193,-271733879,-1732584194,271733878],r,o,s,w,_,O;for(r=64;r<=l;r+=64)p(i,h(u.subarray(r-64,r)));for(u=r-64<l?u.subarray(r-64):new Uint8Array(0),o=u.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],r=0;r<o;r+=1)s[r>>2]|=u[r]<<(r%4<<3);if(s[r>>2]|=128<<(r%4<<3),r>55)for(p(i,s),r=0;r<16;r+=1)s[r]=0;return w=l*8,w=w.toString(16).match(/(.*?)(.{0,8})$/),_=parseInt(w[2],16),O=parseInt(w[1],16)||0,s[14]=_,s[15]=O,p(i,s),i}function g(u){var l="",i;for(i=0;i<4;i+=1)l+=e[u>>i*8+4&15]+e[u>>i*8&15];return l}function m(u){var l;for(l=0;l<u.length;l+=1)u[l]=g(u[l]);return u.join("")}m(y("hello"))!=="5d41402abc4b2a76b9719d911017c592"&&(n=function(u,l){var i=(u&65535)+(l&65535),r=(u>>16)+(l>>16)+(i>>16);return r<<16|i&65535}),typeof ArrayBuffer<"u"&&!ArrayBuffer.prototype.slice&&(function(){function u(l,i){return l=l|0||0,l<0?Math.max(l+i,0):Math.min(l,i)}ArrayBuffer.prototype.slice=function(l,i){var r=this.byteLength,o=u(l,r),s=r,w,_,O,he;return i!==t&&(s=u(i,r)),o>s?new ArrayBuffer(0):(w=s-o,_=new ArrayBuffer(w),O=new Uint8Array(_),he=new Uint8Array(this,o,w),O.set(he),_)}})();function T(u){return/[\u0080-\uFFFF]/.test(u)&&(u=unescape(encodeURIComponent(u))),u}function S(u,l){var i=u.length,r=new ArrayBuffer(i),o=new Uint8Array(r),s;for(s=0;s<i;s+=1)o[s]=u.charCodeAt(s);return l?o:r}function b(u){return String.fromCharCode.apply(null,new Uint8Array(u))}function P(u,l,i){var r=new Uint8Array(u.byteLength+l.byteLength);return r.set(new Uint8Array(u)),r.set(new Uint8Array(l),u.byteLength),i?r:r.buffer}function v(u){var l=[],i=u.length,r;for(r=0;r<i-1;r+=2)l.push(parseInt(u.substr(r,2),16));return String.fromCharCode.apply(String,l)}function A(){this.reset()}return A.prototype.append=function(u){return this.appendBinary(T(u)),this},A.prototype.appendBinary=function(u){this._buff+=u,this._length+=u.length;var l=this._buff.length,i;for(i=64;i<=l;i+=64)p(this._hash,c(this._buff.substring(i-64,i)));return this._buff=this._buff.substring(i-64),this},A.prototype.end=function(u){var l=this._buff,i=l.length,r,o=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],s;for(r=0;r<i;r+=1)o[r>>2]|=l.charCodeAt(r)<<(r%4<<3);return this._finish(o,i),s=m(this._hash),u&&(s=v(s)),this.reset(),s},A.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},A.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},A.prototype.setState=function(u){return this._buff=u.buff,this._length=u.length,this._hash=u.hash,this},A.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},A.prototype._finish=function(u,l){var i=l,r,o,s;if(u[i>>2]|=128<<(i%4<<3),i>55)for(p(this._hash,u),i=0;i<16;i+=1)u[i]=0;r=this._length*8,r=r.toString(16).match(/(.*?)(.{0,8})$/),o=parseInt(r[2],16),s=parseInt(r[1],16)||0,u[14]=o,u[15]=s,p(this._hash,u)},A.hash=function(u,l){return A.hashBinary(T(u),l)},A.hashBinary=function(u,l){var i=y(u),r=m(i);return l?v(r):r},A.ArrayBuffer=function(){this.reset()},A.ArrayBuffer.prototype.append=function(u){var l=P(this._buff.buffer,u,!0),i=l.length,r;for(this._length+=u.byteLength,r=64;r<=i;r+=64)p(this._hash,h(l.subarray(r-64,r)));return this._buff=r-64<i?new Uint8Array(l.buffer.slice(r-64)):new Uint8Array(0),this},A.ArrayBuffer.prototype.end=function(u){var l=this._buff,i=l.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],o,s;for(o=0;o<i;o+=1)r[o>>2]|=l[o]<<(o%4<<3);return this._finish(r,i),s=m(this._hash),u&&(s=v(s)),this.reset(),s},A.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},A.ArrayBuffer.prototype.getState=function(){var u=A.prototype.getState.call(this);return u.buff=b(u.buff),u},A.ArrayBuffer.prototype.setState=function(u){return u.buff=S(u.buff,!0),A.prototype.setState.call(this,u)},A.ArrayBuffer.prototype.destroy=A.prototype.destroy,A.ArrayBuffer.prototype._finish=A.prototype._finish,A.ArrayBuffer.hash=function(u,l){var i=d(new Uint8Array(u)),r=m(i);return l?v(r):r},A})});var X=ye((an,Fe)=>{"use strict";Fe.exports={}});async function Tt(t){let n=(await Promise.resolve().then(()=>H(Oe(),1))).default,e=new n.ArrayBuffer,a=2097152;for(let p=0;p<t.size;p+=a){let c=Math.min(p+a,t.size);e.append(await t.slice(p,c).arrayBuffer())}return{md5:e.end()}}async function St(t){let{createHash:n}=await Promise.resolve().then(()=>H(X(),1)),e=n("md5");return e.update(t),{md5:e.digest("hex")}}async function Rt(t){let{createHash:n}=await Promise.resolve().then(()=>H(X(),1)),{createReadStream:e}=await Promise.resolve().then(()=>H(X(),1));return new Promise((a,p)=>{let c=n("md5"),h=e(t);h.on("error",y=>p(f.file(`Failed to read file for MD5: ${y.message}`,{filePath:t}))),h.on("data",y=>c.update(y)),h.on("end",()=>a({md5:c.digest("hex")}))})}async function M(t){if(t instanceof Blob)return Tt(t);if(typeof Buffer<"u"&&Buffer.isBuffer(t))return St(t);if(typeof t=="string")return Rt(t);throw f.business("Invalid input for MD5 calculation")}var W=L(()=>{"use strict";I()});function Q(t){return t.replace(/\\/g,"/").replace(/\/+/g,"/").replace(/^\/+/,"")}var Ge=L(()=>{"use strict"});function ke(t,n={}){if(n.flatten===!1)return t.map(a=>({path:Q(a),name:ie(a)}));let e=bt(t);return t.map(a=>{let p=Q(a);if(e){let c=e.endsWith("/")?e:`${e}/`;p.startsWith(c)&&(p=p.substring(c.length))}return p||(p=ie(a)),{path:p,name:ie(a)}})}function bt(t){if(!t.length)return"";let e=t.map(c=>Q(c)).map(c=>c.split("/")),a=[],p=Math.min(...e.map(c=>c.length));for(let c=0;c<p-1;c++){let h=e[0][c];if(e.every(y=>y[c]===h))a.push(h);else break}return a.join("/")}function ie(t){return t.split(/[/\\]/).pop()||t}var se=L(()=>{"use strict";Ge()});function Pn(t){oe=t}function wt(){return typeof process<"u"&&process.versions&&process.versions.node?"node":typeof window<"u"||typeof self<"u"?"browser":"unknown"}function ze(){return oe||wt()}var oe,ae=L(()=>{"use strict";oe=null});function le(t,n=1){if(t===0)return"0 Bytes";let e=1024,a=["Bytes","KB","MB","GB"],p=Math.floor(Math.log(t)/Math.log(e));return`${parseFloat((t/e**p).toFixed(n))} ${a[p]}`}function pe(t){if(De(t))return{valid:!1,reason:"File name contains unsafe characters"};if(t.startsWith(" ")||t.endsWith(" "))return{valid:!1,reason:"File name cannot start/end with spaces"};if(t.endsWith("."))return{valid:!1,reason:"File name cannot end with dots"};let n=/^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\.|$)/i,e=t.split("/").pop()||t;return n.test(e)?{valid:!1,reason:"File name uses a reserved system name"}:t.includes("..")?{valid:!1,reason:"File name contains path traversal pattern"}:{valid:!0}}function _n(t,n){let e=[],a=[],p=[];if(t.length===0){let d={file:"(no files)",message:"At least one file must be provided"};return e.push(d),{files:[],validFiles:[],errors:e,warnings:[],canDeploy:!1}}for(let d of t)if(K(d.name))return e.push({file:d.name,message:"Unbuilt project detected \u2014 deploy your build output (dist/, build/, out/), not the project folder"}),{files:t.map(g=>({...g,status:R.VALIDATION_FAILED,statusMessage:"Unbuilt project detected"})),validFiles:[],errors:e,warnings:[],canDeploy:!1};if(t.length>n.maxFilesCount){let d={file:`(${t.length} files)`,message:`File count (${t.length}) exceeds limit of ${n.maxFilesCount}`};return e.push(d),{files:t.map(g=>({...g,status:R.VALIDATION_FAILED,statusMessage:d.message})),validFiles:[],errors:e,warnings:[],canDeploy:!1}}let c=0;for(let d of t){let g=R.READY,m="Ready for upload",T=d.name?pe(d.name):{valid:!1,reason:"File name cannot be empty"};if(d.status===R.PROCESSING_ERROR)g=R.VALIDATION_FAILED,m=d.statusMessage||"File failed during processing",e.push({file:d.name,message:m});else if(d.size===0){g=R.EXCLUDED,m="File is empty (0 bytes) and cannot be deployed due to storage limitations",a.push({file:d.name,message:m}),p.push({...d,status:g,statusMessage:m});continue}else d.size<0?(g=R.VALIDATION_FAILED,m="File size must be positive",e.push({file:d.name,message:m})):!d.name||d.name.trim().length===0?(g=R.VALIDATION_FAILED,m="File name cannot be empty",e.push({file:d.name||"(empty)",message:m})):d.name.includes("\0")?(g=R.VALIDATION_FAILED,m="File name contains invalid characters (null byte)",e.push({file:d.name,message:m})):T.valid?V(d.name,n.blockedExtensions??[])?(g=R.VALIDATION_FAILED,m=`File extension not allowed: "${d.name}"`,e.push({file:d.name,message:m})):d.size>n.maxFileSize?(g=R.VALIDATION_FAILED,m=`File size (${le(d.size)}) exceeds limit of ${le(n.maxFileSize)}`,e.push({file:d.name,message:m})):(c+=d.size,c>n.maxTotalSize&&(g=R.VALIDATION_FAILED,m=`Total size would exceed limit of ${le(n.maxTotalSize)}`,e.push({file:d.name,message:m}))):(g=R.VALIDATION_FAILED,m=T.reason||"Invalid file name",e.push({file:d.name,message:m}));p.push({...d,status:g,statusMessage:m})}e.length>0&&(p=p.map(d=>d.status===R.EXCLUDED?d:{...d,status:R.VALIDATION_FAILED,statusMessage:d.status===R.VALIDATION_FAILED?d.statusMessage:"Deployment failed due to validation errors in bundle"}));let h=e.length===0?p.filter(d=>d.status===R.READY):[],y=e.length===0;return{files:p,validFiles:h,errors:e,warnings:a,canDeploy:y}}function Pt(t){return t.filter(n=>n.status===R.READY)}function Nn(t){return Pt(t).length>0}var ue=L(()=>{"use strict";I()});function Ve(t){return xt.test(t)}var Lt,xt,Ke=L(()=>{"use strict";Lt=["^npm-debug\\.log$","^\\..*\\.swp$","^\\.DS_Store$","^\\.AppleDouble$","^\\.LSOverride$","^Icon\\r$","^\\._.*","^\\.Spotlight-V100(?:$|\\/)","\\.Trashes","^__MACOSX$","~$","^Thumbs\\.db$","^ehthumbs\\.db$","^[Dd]esktop\\.ini$","@eaDir$"],xt=new RegExp(Lt.join("|"))});function je(t,n){if(!t||t.length===0)return[];if(!n?.allowUnbuilt&&t.find(a=>a&&K(a)))throw f.business("Unbuilt project detected \u2014 deploy your build output (dist/, build/, out/), not the project folder");return t.filter(e=>{if(!e)return!1;let a=e.replace(/\\/g,"/").split("/").filter(Boolean);if(a.length===0)return!0;let p=a[a.length-1];if(Ve(p))return!1;for(let h of a)if(h!==".well-known"&&(h.startsWith(".")||h.length>255))return!1;let c=a.slice(0,-1);for(let h of c)if(_t.some(y=>h.toLowerCase()===y.toLowerCase()))return!1;return!0})}var _t,ce=L(()=>{"use strict";I();Ke();_t=["__MACOSX",".Trashes",".fseventsd",".Spotlight-V100"]});function Ye(t,n){if(t.includes("\0")||t.includes("/../")||t.startsWith("../")||t.endsWith("/.."))throw f.business(`Security error: Unsafe file path "${t}" for file: ${n}`)}function qe(t,n,e){let a=pe(t);if(!a.valid)throw f.business(a.reason||"Invalid file name");if(V(t,e))throw f.business(`File extension not allowed: "${n}"`)}var de=L(()=>{"use strict";I();ue()});var We={};rt(We,{processFilesForBrowser:()=>Xe});async function Xe(t,n={},e){if(ze()!=="browser")throw f.business("processFilesForBrowser can only be called in a browser environment.");let a=t.map(S=>S.webkitRelativePath||S.name),p=n.build||n.prerender,c=ke(a,{flatten:n.pathDetect!==!1}),h=c.map(S=>S.path),y=new Set(je(h,{allowUnbuilt:p})),d=[];for(let S=0;S<t.length;S++)y.has(h[S])&&d.push({file:t[S],deployPath:c[S].path});if(d.length===0)return[];if(p){let S=[];for(let b=0;b<d.length;b++){let{file:P,deployPath:v}=d[b];if(P.size===0)continue;let{md5:A}=await M(P);S.push({path:v,content:P,size:P.size,md5:A})}return S}if(!e)throw f.config("Platform limits not provided. processFilesForBrowser requires the limits argument for deploy-mode validation \u2014 pass `ship.getLimits()` result.");let g=[],m=0,T=e.blockedExtensions??[];for(let S=0;S<d.length;S++){let{file:b,deployPath:P}=d[S];if(Ye(P,b.name),b.size===0)continue;if(qe(P,b.name,T),b.size>e.maxFileSize)throw f.business(`File ${b.name} is too large. Maximum allowed size is ${e.maxFileSize/(1024*1024)}MB.`);if(m+=b.size,m>e.maxTotalSize)throw f.business(`Total deploy size is too large. Maximum allowed is ${e.maxTotalSize/(1024*1024)}MB.`);let{md5:v}=await M(b);g.push({path:P,content:b,size:b.size,md5:v})}if(g.length>e.maxFilesCount)throw f.business(`Too many files to deploy. Maximum allowed is ${e.maxFilesCount} files.`);return g}var fe=L(()=>{"use strict";I();se();ae();ce();W();de()});I();I();I();var Y=class{constructor(){this.handlers=new Map}on(n,e){this.handlers.has(n)||this.handlers.set(n,new Set),this.handlers.get(n)?.add(e)}off(n,e){let a=this.handlers.get(n);a&&(a.delete(e),a.size===0&&this.handlers.delete(n))}emit(n,...e){let a=this.handlers.get(n);if(!a)return;let p=Array.from(a);for(let c of p)try{c(...e)}catch(h){a.delete(c),n!=="error"&&setTimeout(()=>{let y=h instanceof Error?h:new Error(String(h));this.emit("error",y,String(n))},0)}}};I();I();function U(t){if(t==null)return;if(t.length===0)return t;if(t.length>F.MAX_COUNT)throw f.validation(`Maximum ${F.MAX_COUNT} labels allowed`);let n=t.map((a,p)=>{if(typeof a!="string")throw f.validation(`Label at index ${p} must be a string`);let c=a.trim().toLowerCase();if(c.length<F.MIN_LENGTH)throw f.validation(`Labels must be at least ${F.MIN_LENGTH} characters long`);if(c.length>F.MAX_LENGTH)throw f.validation(`Labels must be no more than ${F.MAX_LENGTH} characters long`);if(!Le.test(c))throw f.validation(`Labels must start and end with alphanumeric characters, with optional separators (${F.SEPARATORS}) between segments`);return c}),e=[...new Set(n)];if(e.length!==n.length)throw f.validation("Duplicate labels are not allowed");return e}async function xe(t){let n=t.find(p=>p.path===N||p.path===`/${N}`);if(!n)return;let e=n.content,a=typeof e.text=="function"?await e.text():n.content.toString("utf8");Ie(a)}var gt=3e4,_e=3e5,Et=3e5,At=_e+Et,Dt="sdk";function re(t){let n=new URLSearchParams;t?.limit!==void 0&&n.set("limit",String(t.limit)),t?.cursor!==void 0&&n.set("cursor",t.cursor);let e=n.toString();return e?`?${e}`:""}var q=class extends Y{constructor(e){super();this.globalHeaders={};this.apiUrl=e.apiUrl||te,this.getAuthHeadersCallback=e.getAuthHeaders,this.session=e.session??!1,this.caller=e.caller,this.timeout=e.timeout??gt,this.deployTimeout=e.timeout??_e,this.deployBuildTimeout=e.timeout??At,this.fetch=e.fetch??globalThis.fetch.bind(globalThis),this.createDeployBody=e.createDeployBody,this.deployEndpoint=e.deployEndpoint||D.DEPLOYMENTS}setGlobalHeaders(e){this.globalHeaders=e}async executeRequest(e,a,p,c=this.timeout){let h=()=>{};try{let y=await this.mergeHeaders(a.headers),d=this.createTimeoutSignal(a.signal,c);h=d.cleanup;let g={...a,headers:y,credentials:this.session&&!y.Authorization?"include":void 0,signal:d.signal};this.emit("request",e,g);let m=await this.fetch(e,g);if(h(),!m.ok)throw await f.fromHttpResponse(m,p);return this.emit("response",this.safeClone(m),e),{data:await this.parseResponse(this.safeClone(m)),status:m.status}}catch(y){h();let d=f.fromFetchError(y,p);throw this.emit("error",d,e),d}}async request(e,a,p,c){let{data:h}=await this.executeRequest(e,a,p,c);return h}async requestWithStatus(e,a,p){return this.executeRequest(e,a,p)}async mergeHeaders(e={}){return{...this.globalHeaders,...this.caller?{[$.HEADER]:this.caller}:{},...await this.getAuthHeadersCallback(),...e}}createTimeoutSignal(e,a=this.timeout){let p=new AbortController,c=setTimeout(()=>p.abort(),a);if(e){let h=()=>p.abort();e.addEventListener("abort",h),e.aborted&&p.abort()}return{signal:p.signal,cleanup:()=>clearTimeout(c)}}safeClone(e){try{return e.clone()}catch{return e}}async parseResponse(e){if(!(e.headers.get("Content-Length")==="0"||e.status===204))return e.json()}async deploy(e,a={}){if(!e.length)throw f.business("No files to deploy");for(let g of e)if(!g.md5)throw f.file(`MD5 checksum missing for file: ${g.path}`,{filePath:g.path});ne(a.password);let p=Ee(a.idempotencyKey),c=U(a.labels);await xe(e);let h=a.build||a.prerender||a.spa?{build:a.build,prerender:a.prerender,spa:a.spa}:void 0,{body:y,headers:d}=await this.createDeployBody(e,{labels:c,via:a.via??Dt,password:a.password,flags:h,captcha:a.captcha});return this.request(`${this.apiUrl}${this.deployEndpoint}`,{method:"POST",body:y,headers:p?{...d,[z.HEADER]:p}:d,signal:a.signal||null},"Deploy",a.build||a.prerender?this.deployBuildTimeout:this.deployTimeout)}async listDeployments(e){return this.request(`${this.apiUrl}${D.DEPLOYMENTS}${re(e)}`,{method:"GET"},"List deployments")}async getDeployment(e){return this.request(`${this.apiUrl}${D.DEPLOYMENT(encodeURIComponent(e))}`,{method:"GET"},"Get deployment")}async updateDeploymentLabels(e,a){let p=U(a);return this.request(`${this.apiUrl}${D.DEPLOYMENT(encodeURIComponent(e))}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({labels:p})},"Update deployment labels")}async deleteDeployment(e){return this.request(`${this.apiUrl}${D.DEPLOYMENT(encodeURIComponent(e))}`,{method:"DELETE"},"Delete deployment")}async setDomain(e,a,p){let c=U(p),h={};a&&(h.deployment=a),c!==void 0&&(h.labels=c);let{data:y,status:d}=await this.requestWithStatus(`${this.apiUrl}${D.DOMAIN(encodeURIComponent(e))}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(h)},"Set domain");return{...y,isCreate:d===201}}async listDomains(e){return this.request(`${this.apiUrl}${D.DOMAINS}${re(e)}`,{method:"GET"},"List domains")}async getDomain(e){return this.request(`${this.apiUrl}${D.DOMAIN(encodeURIComponent(e))}`,{method:"GET"},"Get domain")}async deleteDomain(e){return this.request(`${this.apiUrl}${D.DOMAIN(encodeURIComponent(e))}`,{method:"DELETE"},"Delete domain")}async verifyDomain(e){return this.request(`${this.apiUrl}${D.DOMAIN_VERIFY(encodeURIComponent(e))}`,{method:"POST"},"Verify domain")}async getDomainDns(e){return this.request(`${this.apiUrl}${D.DOMAIN_DNS(encodeURIComponent(e))}`,{method:"GET"},"Get domain DNS")}async getDomainRecords(e){return this.request(`${this.apiUrl}${D.DOMAIN_RECORDS(encodeURIComponent(e))}`,{method:"GET"},"Get domain records")}async getDomainShare(e){return this.request(`${this.apiUrl}${D.DOMAIN_SHARE(encodeURIComponent(e))}`,{method:"GET"},"Get domain share")}async validateDomain(e){return this.request(`${this.apiUrl}${D.DOMAINS_VALIDATE}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({domain:e})},"Validate domain")}async createToken(e,a){let p=U(a),c={};return e!==void 0&&(c.ttl=e),p!==void 0&&(c.labels=p),this.request(`${this.apiUrl}${D.TOKENS}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)},"Create token")}async listTokens(e){return this.request(`${this.apiUrl}${D.TOKENS}${re(e)}`,{method:"GET"},"List tokens")}async deleteToken(e){return this.request(`${this.apiUrl}${D.TOKEN(encodeURIComponent(e))}`,{method:"DELETE"},"Delete token")}async getToken(e){return this.request(`${this.apiUrl}${D.TOKEN(encodeURIComponent(e))}`,{method:"GET"},"Get token")}async getAccount(){return this.request(`${this.apiUrl}${D.ACCOUNT}`,{method:"GET"},"Get account")}async getLimits(){return this.request(`${this.apiUrl}${D.LIMITS}`,{method:"GET"},"Get limits")}async ping(){return this.request(`${this.apiUrl}${D.PING}`,{method:"GET"},"Ping")}async checkSPA(e,a={}){let p=e.find(d=>d.path===j.INDEX_FILE||d.path===`/${j.INDEX_FILE}`);if(!p||p.size>j.MAX_INDEX_BYTES)return!1;let c;if(typeof Buffer<"u"&&Buffer.isBuffer(p.content))c=p.content.toString("utf-8");else if(typeof Blob<"u"&&p.content instanceof Blob)c=await p.content.text();else if(typeof File<"u"&&p.content instanceof File)c=await p.content.text();else return!1;let h={files:e.map(d=>d.path),index:c};return(await this.request(`${this.apiUrl}${D.SPA_CHECK}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(h)},"SPA check")).isSPA}};I();I();W();async function It(){let t=JSON.stringify(Re,null,2),n;typeof Buffer<"u"?n=Buffer.from(t,"utf-8"):n=new Blob([t],{type:"application/json"});let{md5:e}=await M(n);return{path:N,content:n,size:t.length,md5:e}}async function Ce(t,n,e){if(e.spaDetect===!1||e.spa||e.build||e.prerender||t.some(a=>a.path===N))return t;try{if(await n.checkSPA(t,e)){let p=await It();return[...t,p]}}catch{}return t}function $e(t){let{getApi:n,ensureInit:e,processInput:a}=t;return{upload:async(p,c={})=>{if(await e(),!a)throw f.config("processInput function is not provided.");let h=n(),y=await a(p,c);return y=await Ce(y,h,c),h.deploy(y,c)},list:async p=>(await e(),n().listDeployments(p)),get:async p=>(await e(),n().getDeployment(p)),set:async(p,c)=>(await e(),n().updateDeploymentLabels(p,c.labels)),delete:async p=>(await e(),n().deleteDeployment(p))}}function Ue(t){let{getApi:n,ensureInit:e}=t;return{set:async(a,p={})=>(await e(),n().setDomain(a,p.deployment,p.labels)),list:async a=>(await e(),n().listDomains(a)),get:async a=>(await e(),n().getDomain(a)),delete:async a=>(await e(),n().deleteDomain(a)),verify:async a=>(await e(),n().verifyDomain(a)),validate:async a=>(await e(),n().validateDomain(a)),dns:async a=>(await e(),n().getDomainDns(a)),records:async a=>(await e(),n().getDomainRecords(a)),share:async a=>(await e(),n().getDomainShare(a))}}function Me(t){let{getApi:n,ensureInit:e}=t;return{get:async()=>(await e(),n().getAccount())}}function Be(t){let{getApi:n,ensureInit:e}=t;return{create:async(a={})=>(await e(),n().createToken(a.ttl,a.labels)),list:async a=>(await e(),n().listTokens(a)),get:async a=>(await e(),n().getToken(a)),delete:async a=>(await e(),n().deleteToken(a))}}var J=class{constructor(n={}){this.initPromise=null;this.platformLimits=null;this.credential=null;if(n={...n,apiUrl:n.apiUrl||void 0,token:n.token||void 0,caller:n.caller||void 0},this.clientOptions=n,n.caller!==void 0&&we(n.caller),n.token&&n.session)throw f.config("Provide either `token` or `session`, not both.");typeof n.token=="string"?(ee(n.token),this.credential=n.token):n.token&&(this.credential=n.token),this.http=new q({...n,getAuthHeaders:()=>this.getAuthHeaders(),createDeployBody:this.getDeployBodyCreator()});let e={getApi:()=>this.http,ensureInit:()=>this.ensureInitialized()};this.deployments=$e({...e,processInput:(a,p)=>this.processInput(a,p)}),this.domains=Ue(e),this.account=Me(e),this.tokens=Be(e)}async ensureInitialized(){return this.initPromise||(this.initPromise=this.fetchPlatformLimits()),this.initPromise}async fetchPlatformLimits(){try{this.platformLimits=await this.http.getLimits()}catch(n){throw this.initPromise=null,n}}async ping(){return await this.ensureInitialized(),this.http.ping()}async deploy(n,e){return this.deployments.upload(n,e)}async whoami(){return this.account.get()}async getLimits(){return this.platformLimits?this.platformLimits:(await this.ensureInitialized(),this.platformLimits)}on(n,e){this.http.on(n,e)}off(n,e){this.http.off(n,e)}setHeaders(n){this.http.setGlobalHeaders(n)}clearHeaders(){this.http.setGlobalHeaders({})}setToken(n){if(this.clientOptions.session)throw f.config("Provide either `token` or `session`, not both.");if(typeof n=="string"){if(!n)throw f.business("Invalid token provided. Token must be a non-empty string.");ee(n),this.credential=n;return}if(typeof n!="function")throw f.business("Invalid token provided. Token must be a non-empty string or a provider function.");this.credential=n}async getAuthHeaders(){if(this.credential===null)return{};let n=typeof this.credential=="function"?await this.credential():this.credential;if(!n)throw f.authentication("Token provider returned no token.");if(typeof n!="string")throw f.authentication("Token provider returned a non-string value.");return{Authorization:`Bearer ${n}`}}};I();async function He(t,n={}){let{labels:e,via:a,password:p,flags:c,captcha:h}=n,y=new FormData,d=[];for(let g of t){if(!(g.content instanceof File||g.content instanceof Blob))throw f.file(`Unsupported file.content type for browser: ${g.path}`,{filePath:g.path});if(!g.md5)throw f.file(`File missing md5 checksum: ${g.path}`,{filePath:g.path});let m=new File([g.content],g.path,{type:"application/octet-stream"});y.append(x.FILES,m),d.push(g.md5)}return y.append(x.CHECKSUMS,JSON.stringify(d)),e&&e.length>0&&y.append(x.LABELS,JSON.stringify(e)),a&&y.append(x.VIA,a),p&&y.append(x.PASSWORD,p),c?.build&&y.append(x.BUILD,"true"),c?.prerender&&y.append(x.PRERENDER,"true"),c?.spa&&y.append(x.SPA,"true"),h&&y.append(x.CAPTCHA,h),{body:y,headers:{}}}I();I();se();ae();ue();ce();W();de();function Hn(t,n,e,a=!0){let p=t===1?n:e;return a?`${t} ${p}`:p}fe();var me=class extends J{async deploy(n,e){return super.deploy(n,e)}async processInput(n,e){if(!Array.isArray(n)||!n.every(p=>p instanceof File))throw f.business("Invalid input type for browser environment. Expected File[].");if(n.length===0)throw f.business("No files to deploy.");let{processFilesForBrowser:a}=await Promise.resolve().then(()=>(fe(),We));return a(n,e,this.platformLimits??void 0)}getDeployBodyCreator(){return He}},ur=me;export{Te as API_KEY,D as API_PATHS,Ut as AUTH_BASE_PATH,Ct as AccountPlan,q as ApiHttp,ge as AuthMethod,$ as CALLER,te as DEFAULT_API,N as DEPLOYMENT_CONFIG_FILENAME,x as DEPLOY_FIELDS,Se as DEPLOY_TOKEN,vt as DeploymentStatus,st as DeploymentVia,Ot as DomainStatus,E as ErrorType,R as FILE_VALIDATION_STATUS,R as FileValidationStatus,z as IDEMPOTENCY_KEY_CONSTRAINTS,_t as JUNK_DIRECTORIES,F as LABEL_CONSTRAINTS,Le as LABEL_PATTERN,kt as MY_API_KEY_URL,Mt as OAuthScope,k as PASSWORD_CONSTRAINTS,zt as PUBLIC_DEPLOYMENT_TTL_SECONDS,Gt as SHIP_ENV,j as SPA_CHECK_CONSTRAINTS,Re as SPA_DEFAULT_CONFIG,me as Ship,f as ShipError,C as TokenKind,ft as UNBUILT_PROJECT_MARKERS,dt as UNSAFE_FILENAME_CHARS,$t as WEB_FILE_ACCEPT,Pn as __setTestEnvironment,Nn as allValidFilesReady,Ie as assertShipJsonSyntax,M as calculateMD5,mt as classifyToken,Me as createAccountResource,$e as createDeploymentResource,Ue as createDomainResource,Be as createTokenResource,ur as default,Xt as deserializeLabels,Kt as extractSubdomain,je as filterJunk,le as formatFileSize,jt as generateDeploymentUrl,Yt as generateDomainUrl,ze as getENV,Pt as getValidFiles,K as hasUnbuiltMarker,De as hasUnsafeChars,V as isBlockedExtension,Vt as isCustomDomain,Ht as isDeployment,Pe as isPlatformDomain,Ae as isShipError,Ft as normalizeVia,ke as optimizeDeployPaths,Hn as pluralize,Xe as processFilesForBrowser,qt as serializeLabels,ht as validateApiKey,Bt as validateApiUrl,we as validateCaller,qe as validateDeployFile,Ye as validateDeployPath,yt as validateDeployToken,pe as validateFileName,_n as validateFiles,Ee as validateIdempotencyKey,ne as validatePassword,ee as validateToken};
1
+ var Ze=Object.create;var H=Object.defineProperty;var et=Object.getOwnPropertyDescriptor;var tt=Object.getOwnPropertyNames;var nt=Object.getPrototypeOf,rt=Object.prototype.hasOwnProperty;var it=(t,n,e)=>n in t?H(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e;var w=(t,n)=>()=>(t&&(n=t(t=0)),n);var ge=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),st=(t,n)=>{for(var e in n)H(t,e,{get:n[e],enumerable:!0})},ot=(t,n,e,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let l of tt(n))!rt.call(t,l)&&l!==e&&H(t,l,{get:()=>n[l],enumerable:!(o=et(n,l))||o.enumerable});return t};var k=(t,n,e)=>(e=t!=null?Ze(nt(t)):{},ot(n||!t||!t.__esModule?H(e,"default",{value:t,enumerable:!0}):e,t));var G=(t,n,e)=>it(t,typeof n!="symbol"?n+"":n,e);function Gt(t){if(!t||typeof t!="string")return;let n=t.trim().toLowerCase();return Object.values(at).includes(n)?n:void 0}function Ae(t){if(t==null)return;if(typeof t!="string")throw m.validation("Idempotency key must be a string.");let n=t.trim();if(!n)throw m.validation("Idempotency key must not be empty.");if(n.length>U.MAX_LENGTH)throw m.validation(`Idempotency key must be at most ${U.MAX_LENGTH} characters.`);return n}function ct(t){let n=t.code;return n==="ERR_INVALID_URL"?!1:typeof n=="string"?!0:t instanceof TypeError?!/\burl\b/i.test(t.message):!1}function De(t){return t!==null&&typeof t=="object"&&"name"in t&&t.name==="ShipError"&&"status"in t}function ft(t){let n=t.replace(/\\/g,"/").split("/").pop()??"",e=n.lastIndexOf(".");return e<=0||e===n.length-1?null:n.slice(e+1).toLowerCase()}function Te(t,n){let e=ft(t);return e===null?!1:Array.isArray(n)?n.includes(e):n.has(e)}function Se(t){return mt.test(t)}function K(t){return t.replace(/\\/g,"/").split("/").filter(Boolean).some(e=>ht.has(e))}function yt(t){return t.startsWith(Re.PREFIX)?O.API_KEY:t.startsWith(be.PREFIX)?O.DEPLOY_TOKEN:O.OPAQUE}function we(t){let n=t.charCodeAt(0)===65279?t.slice(1):t,e;try{e=JSON.parse(n)}catch(o){throw m.config(`invalid JSON format in config: ${o.message}`,{filePath:v})}if(e===null||typeof e!="object"||Array.isArray(e))throw m.config(`${v} must contain a JSON object`,{filePath:v})}function Le(t,n,e){if(!t.startsWith(n.PREFIX))throw m.validation(`${e} must start with "${n.PREFIX}"`);if(t.length!==n.TOTAL_LENGTH)throw m.validation(`${e} must be ${n.TOTAL_LENGTH} characters total (${n.PREFIX} + ${n.HEX_LENGTH} hex chars)`);let o=t.slice(n.PREFIX.length);if(!new RegExp(`^[a-f0-9]{${n.HEX_LENGTH}}$`,"i").test(o))throw m.validation(`${e} must contain ${n.HEX_LENGTH} hexadecimal characters after "${n.PREFIX}" prefix`)}function gt(t){Le(t,Re,"API key")}function Et(t){Le(t,be,"Deploy token")}function te(t){switch(yt(t)){case O.API_KEY:gt(t);return;case O.DEPLOY_TOKEN:Et(t);return;case O.OPAQUE:if(!t)throw m.validation("Token must be a non-empty string")}}function Pe(t){if(!t||t.length>$.MAX_LENGTH||!$.PATTERN.test(t))throw m.validation(`Caller must be 1-${$.MAX_LENGTH} characters: letters, digits, dots, underscores, or hyphens`)}function jt(t){try{let n=new URL(t);if(!["http:","https:"].includes(n.protocol))throw m.validation("API URL must use http:// or https:// protocol");if(n.pathname!=="/"&&n.pathname!=="")throw m.validation("API URL must not contain a path");if(n.search||n.hash)throw m.validation("API URL must not contain query parameters or fragments")}catch(n){throw De(n)?n:m.validation("API URL must be a valid URL")}}function qt(t){return/^[a-z]+-[a-z]+-[a-z0-9]{7}(\.[a-z0-9.-]+)?$/i.test(t)}function _e(t,n){return t.endsWith(`.${n}`)}function Qt(t,n){return!_e(t,n)}function Zt(t,n){return _e(t,n)?t.slice(0,-(n.length+1)):null}function en(t){return`https://${t}`}function tn(t){return`https://${t}`}function nn(t){return!t||t.length===0?null:JSON.stringify(t)}function rn(t){if(!t)return[];try{let n=JSON.parse(t);return Array.isArray(n)?n:[]}catch{return[]}}function re(t){if(t==null)return;if(typeof t!="string")throw m.validation("Password must be a string");let n=t.trim();if(n.length<z.MIN_LENGTH||n.length>z.MAX_LENGTH)throw m.validation(`Password must be between ${z.MIN_LENGTH} and ${z.MAX_LENGTH} characters`);return n}var Ht,at,kt,U,zt,T,P,A,lt,ee,pt,ut,m,dt,Kt,mt,ht,Vt,Ee,Re,be,$,O,Yt,v,Ie,V,ne,Xt,Wt,Jt,b,N,ve,z,R=w(()=>{"use strict";Ht={PENDING:"pending",SUCCESS:"success",FAILED:"failed",DELETING:"deleting"},at={WEB:"web",SDK:"sdk",CLI:"cli",MCP:"mcp",GIT:"git",N8N:"n8n",GPT:"gpt",VSC:"vsc"},kt={PENDING:"pending",PARTIAL:"partial",SUCCESS:"success",PAUSED:"paused"},U={HEADER:"Idempotency-Key",MAX_LENGTH:256,WINDOW_SECONDS:1440*60};zt={FREE:"free",STANDARD:"standard",SPONSORED:"sponsored",ENTERPRISE:"enterprise",SUSPENDED:"suspended",TERMINATING:"terminating",TERMINATED:"terminated"},T={DEPLOYMENTS:"/deployments",DEPLOYMENT:t=>`/deployments/${t}`,DEPLOYMENT_CONFIG:t=>`/deployments/${t}/config`,DOMAINS:"/domains",DOMAIN:t=>`/domains/${t}`,DOMAIN_VERIFY:t=>`/domains/${t}/verify`,DOMAIN_DNS:t=>`/domains/${t}/dns`,DOMAIN_RECORDS:t=>`/domains/${t}/records`,DOMAIN_SHARE:t=>`/domains/${t}/share`,DOMAIN_PROPAGATION:t=>`/domains/${t}/propagation`,DOMAINS_VALIDATE:"/domains/validate",TOKENS:"/tokens",TOKEN:t=>`/tokens/${t}`,ACCOUNT:"/account",ACCOUNT_KEY:"/account/key",ACCOUNT_CLAIM:"/account/claim",ACTIVITIES:"/activities",LABELS:"/labels",LIMITS:"/limits",PING:"/ping",SETUP:"/setup",SPA_CHECK:"/spa-check",UPLOAD:"/upload"},P={FILES:"files[]",CHECKSUMS:"checksums",LABELS:"labels",VIA:"via",PASSWORD:"password",BUILD:"build",PRERENDER:"prerender",SPA:"spa",CAPTCHA:"captcha"},A={Validation:"validation_failed",NotFound:"not_found",Forbidden:"forbidden",RateLimit:"rate_limit_exceeded",Authentication:"authentication_failed",Business:"business_logic_error",Api:"internal_server_error",Maintenance:"maintenance",Network:"network_error",Cancelled:"operation_cancelled",File:"file_error",Config:"config_error"},lt=new Set([A.Network,A.Cancelled,A.File,A.Config]),ee={client:new Set([A.Business,A.Cancelled,A.Config,A.File,A.Forbidden,A.NotFound,A.RateLimit,A.Validation]),network:new Set([A.Network]),auth:new Set([A.Authentication])},pt=new Set(Object.values(A).filter(t=>!lt.has(t))),ut=200;m=class t extends Error{constructor(e,o,l,c){super(o);G(this,"type");G(this,"status");G(this,"details");this.type=e,this.status=l,this.details=c,this.name="ShipError"}toResponse(){let e=this.details,o=this.type===A.Authentication&&e?.internal?void 0:this.details;return{error:this.type,message:this.message,status:this.status,details:o}}static async fromHttpResponse(e,o){let l,c,d;try{if(e.headers.get("content-type")?.includes("application/json")){let y=await e.json();if(y&&typeof y=="object"){let E=y;typeof E.message=="string"?l=E.message:typeof E.error=="string"&&(l=E.error),c=E.details,typeof E.error=="string"&&pt.has(E.error)&&(d=E.error)}}else{let y=(await e.text()).trim();y&&!y.startsWith("<")&&y.length<=ut&&(l=y)}}catch{}let h=e.headers.get("retry-after");if(h!==null){let g=h.trim(),y=/^\d+$/.test(g)?Number(g):Math.ceil((Date.parse(g)-Date.now())/1e3);if(Number.isFinite(y)&&y>=0){let E=c&&typeof c=="object"?c:{};E.retryAfter===void 0&&(c={...E,retryAfter:y})}}l=l||`${o||"Request"} failed with status ${e.status}`;let f=d??(e.status===401?A.Authentication:e.status===403?A.Forbidden:e.status===429?A.RateLimit:A.Api);return new t(f,l,e.status,c)}static fromFetchError(e,o){if(De(e))return e;let l=o||"Request",c=e?.name;return c==="AbortError"?t.cancelled(`${l} was cancelled`):c==="TimeoutError"?t.network(`${l} timed out`,{cause:e}):e instanceof Error?ct(e)?t.network(`${l} failed: ${e.message}`,{cause:e}):new t(A.Api,`${l} failed: ${e.message}`):new t(A.Api,`${l} failed: Unknown error`)}static validation(e,o){return new t(A.Validation,e,400,o)}static notFound(e,o){let l=o?`${e} ${o} not found`:`${e} not found`;return new t(A.NotFound,l,404)}static forbidden(e,o){return new t(A.Forbidden,e,403,o)}static rateLimit(e="Too many requests",o){return new t(A.RateLimit,e,429,o)}static authentication(e="Authentication required",o){return new t(A.Authentication,e,401,o)}static business(e,o=400,l){return new t(A.Business,e,o,l)}static network(e,o){return new t(A.Network,e,void 0,o)}static cancelled(e,o){return new t(A.Cancelled,e,void 0,o)}static file(e,o){return new t(A.File,e,void 0,o)}static config(e,o){return new t(A.Config,e,void 0,o)}static api(e,o=500,l){return new t(A.Api,e,o,l)}static maintenance(e,o){return new t(A.Maintenance,e,503,o)}isClientError(){return ee.client.has(this.type)?!0:this.status!==void 0&&this.status>=400&&this.status<500}isNetworkError(){return ee.network.has(this.type)}isAuthError(){return ee.auth.has(this.type)}isType(e){return this.type===e}};dt=["html","htm","xhtml","xml","txt","md","markdown","pdf","csv","json","jsonc","webmanifest","map","toml","yaml","yml","rss","atom","css","scss","sass","less","js","mjs","cjs","jsx","ts","tsx","wasm","vue","svelte","png","jpg","jpeg","gif","webp","avif","svg","ico","bmp","tif","tiff","heic","heif","woff","woff2","ttf","otf","eot","mp3","wav","ogg","oga","opus","m4a","aac","flac","weba","mp4","webm","ogv","mov","m4v","avi","glb","gltf","usdz","vtt","srt","zip"],Kt=dt.map(t=>`.${t}`).join(","),mt=/[\x00-\x1f\x7f#?%\\<>"]/;ht=new Set(["node_modules","package.json"]);Vt="/auth",Ee={SESSION:"session",API_KEY:"apiKey",TOKEN:"token",AGENT:"agent",OAUTH:"oauth",WEBHOOK:"webhook",SYSTEM:"system"},Re={PREFIX:"ship-",HEX_LENGTH:32,TOTAL_LENGTH:37,HINT_LENGTH:4},be={PREFIX:"deploy-",HEX_LENGTH:32,TOTAL_LENGTH:39},$={HEADER:"X-Caller",MAX_LENGTH:128,PATTERN:/^[a-zA-Z0-9._-]+$/},O={API_KEY:Ee.API_KEY,DEPLOY_TOKEN:Ee.TOKEN,OPAQUE:"opaque"};Yt={ACCOUNT_READ:"account:read",DEPLOYMENTS_READ:"deployments:read",DEPLOYMENTS_WRITE:"deployments:write",DOMAINS_READ:"domains:read",DOMAINS_WRITE:"domains:write"},v="ship.json",Ie={rewrites:[{source:"/(.*)",destination:"/index.html"}]},V={INDEX_FILE:"index.html",MAX_INDEX_BYTES:100*1024};ne="https://api.shipstatic.com",Xt={TOKEN:"SHIP_TOKEN",API_URL:"SHIP_API_URL"},Wt="https://my.shipstatic.com/api-key",Jt=4320*60,b={PENDING:"pending",PROCESSING_ERROR:"processing_error",EXCLUDED:"excluded",VALIDATION_FAILED:"validation_failed",READY:"ready"};N={MIN_LENGTH:3,MAX_LENGTH:25,MAX_COUNT:10,SEPARATORS:"._-"},ve=/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/;z={MIN_LENGTH:6,MAX_LENGTH:128}});var Ce=ge((Fe,Oe)=>{"use strict";(function(t){if(typeof Fe=="object")Oe.exports=t();else if(typeof define=="function"&&define.amd)define(t);else{var n;try{n=window}catch{n=self}n.SparkMD5=t()}})(function(t){"use strict";var n=function(u,p){return u+p&4294967295},e=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function o(u,p,i,r,a,s){return p=n(n(p,u),n(r,s)),n(p<<a|p>>>32-a,i)}function l(u,p){var i=u[0],r=u[1],a=u[2],s=u[3];i+=(r&a|~r&s)+p[0]-680876936|0,i=(i<<7|i>>>25)+r|0,s+=(i&r|~i&a)+p[1]-389564586|0,s=(s<<12|s>>>20)+i|0,a+=(s&i|~s&r)+p[2]+606105819|0,a=(a<<17|a>>>15)+s|0,r+=(a&s|~a&i)+p[3]-1044525330|0,r=(r<<22|r>>>10)+a|0,i+=(r&a|~r&s)+p[4]-176418897|0,i=(i<<7|i>>>25)+r|0,s+=(i&r|~i&a)+p[5]+1200080426|0,s=(s<<12|s>>>20)+i|0,a+=(s&i|~s&r)+p[6]-1473231341|0,a=(a<<17|a>>>15)+s|0,r+=(a&s|~a&i)+p[7]-45705983|0,r=(r<<22|r>>>10)+a|0,i+=(r&a|~r&s)+p[8]+1770035416|0,i=(i<<7|i>>>25)+r|0,s+=(i&r|~i&a)+p[9]-1958414417|0,s=(s<<12|s>>>20)+i|0,a+=(s&i|~s&r)+p[10]-42063|0,a=(a<<17|a>>>15)+s|0,r+=(a&s|~a&i)+p[11]-1990404162|0,r=(r<<22|r>>>10)+a|0,i+=(r&a|~r&s)+p[12]+1804603682|0,i=(i<<7|i>>>25)+r|0,s+=(i&r|~i&a)+p[13]-40341101|0,s=(s<<12|s>>>20)+i|0,a+=(s&i|~s&r)+p[14]-1502002290|0,a=(a<<17|a>>>15)+s|0,r+=(a&s|~a&i)+p[15]+1236535329|0,r=(r<<22|r>>>10)+a|0,i+=(r&s|a&~s)+p[1]-165796510|0,i=(i<<5|i>>>27)+r|0,s+=(i&a|r&~a)+p[6]-1069501632|0,s=(s<<9|s>>>23)+i|0,a+=(s&r|i&~r)+p[11]+643717713|0,a=(a<<14|a>>>18)+s|0,r+=(a&i|s&~i)+p[0]-373897302|0,r=(r<<20|r>>>12)+a|0,i+=(r&s|a&~s)+p[5]-701558691|0,i=(i<<5|i>>>27)+r|0,s+=(i&a|r&~a)+p[10]+38016083|0,s=(s<<9|s>>>23)+i|0,a+=(s&r|i&~r)+p[15]-660478335|0,a=(a<<14|a>>>18)+s|0,r+=(a&i|s&~i)+p[4]-405537848|0,r=(r<<20|r>>>12)+a|0,i+=(r&s|a&~s)+p[9]+568446438|0,i=(i<<5|i>>>27)+r|0,s+=(i&a|r&~a)+p[14]-1019803690|0,s=(s<<9|s>>>23)+i|0,a+=(s&r|i&~r)+p[3]-187363961|0,a=(a<<14|a>>>18)+s|0,r+=(a&i|s&~i)+p[8]+1163531501|0,r=(r<<20|r>>>12)+a|0,i+=(r&s|a&~s)+p[13]-1444681467|0,i=(i<<5|i>>>27)+r|0,s+=(i&a|r&~a)+p[2]-51403784|0,s=(s<<9|s>>>23)+i|0,a+=(s&r|i&~r)+p[7]+1735328473|0,a=(a<<14|a>>>18)+s|0,r+=(a&i|s&~i)+p[12]-1926607734|0,r=(r<<20|r>>>12)+a|0,i+=(r^a^s)+p[5]-378558|0,i=(i<<4|i>>>28)+r|0,s+=(i^r^a)+p[8]-2022574463|0,s=(s<<11|s>>>21)+i|0,a+=(s^i^r)+p[11]+1839030562|0,a=(a<<16|a>>>16)+s|0,r+=(a^s^i)+p[14]-35309556|0,r=(r<<23|r>>>9)+a|0,i+=(r^a^s)+p[1]-1530992060|0,i=(i<<4|i>>>28)+r|0,s+=(i^r^a)+p[4]+1272893353|0,s=(s<<11|s>>>21)+i|0,a+=(s^i^r)+p[7]-155497632|0,a=(a<<16|a>>>16)+s|0,r+=(a^s^i)+p[10]-1094730640|0,r=(r<<23|r>>>9)+a|0,i+=(r^a^s)+p[13]+681279174|0,i=(i<<4|i>>>28)+r|0,s+=(i^r^a)+p[0]-358537222|0,s=(s<<11|s>>>21)+i|0,a+=(s^i^r)+p[3]-722521979|0,a=(a<<16|a>>>16)+s|0,r+=(a^s^i)+p[6]+76029189|0,r=(r<<23|r>>>9)+a|0,i+=(r^a^s)+p[9]-640364487|0,i=(i<<4|i>>>28)+r|0,s+=(i^r^a)+p[12]-421815835|0,s=(s<<11|s>>>21)+i|0,a+=(s^i^r)+p[15]+530742520|0,a=(a<<16|a>>>16)+s|0,r+=(a^s^i)+p[2]-995338651|0,r=(r<<23|r>>>9)+a|0,i+=(a^(r|~s))+p[0]-198630844|0,i=(i<<6|i>>>26)+r|0,s+=(r^(i|~a))+p[7]+1126891415|0,s=(s<<10|s>>>22)+i|0,a+=(i^(s|~r))+p[14]-1416354905|0,a=(a<<15|a>>>17)+s|0,r+=(s^(a|~i))+p[5]-57434055|0,r=(r<<21|r>>>11)+a|0,i+=(a^(r|~s))+p[12]+1700485571|0,i=(i<<6|i>>>26)+r|0,s+=(r^(i|~a))+p[3]-1894986606|0,s=(s<<10|s>>>22)+i|0,a+=(i^(s|~r))+p[10]-1051523|0,a=(a<<15|a>>>17)+s|0,r+=(s^(a|~i))+p[1]-2054922799|0,r=(r<<21|r>>>11)+a|0,i+=(a^(r|~s))+p[8]+1873313359|0,i=(i<<6|i>>>26)+r|0,s+=(r^(i|~a))+p[15]-30611744|0,s=(s<<10|s>>>22)+i|0,a+=(i^(s|~r))+p[6]-1560198380|0,a=(a<<15|a>>>17)+s|0,r+=(s^(a|~i))+p[13]+1309151649|0,r=(r<<21|r>>>11)+a|0,i+=(a^(r|~s))+p[4]-145523070|0,i=(i<<6|i>>>26)+r|0,s+=(r^(i|~a))+p[11]-1120210379|0,s=(s<<10|s>>>22)+i|0,a+=(i^(s|~r))+p[2]+718787259|0,a=(a<<15|a>>>17)+s|0,r+=(s^(a|~i))+p[9]-343485551|0,r=(r<<21|r>>>11)+a|0,u[0]=i+u[0]|0,u[1]=r+u[1]|0,u[2]=a+u[2]|0,u[3]=s+u[3]|0}function c(u){var p=[],i;for(i=0;i<64;i+=4)p[i>>2]=u.charCodeAt(i)+(u.charCodeAt(i+1)<<8)+(u.charCodeAt(i+2)<<16)+(u.charCodeAt(i+3)<<24);return p}function d(u){var p=[],i;for(i=0;i<64;i+=4)p[i>>2]=u[i]+(u[i+1]<<8)+(u[i+2]<<16)+(u[i+3]<<24);return p}function h(u){var p=u.length,i=[1732584193,-271733879,-1732584194,271733878],r,a,s,I,_,x;for(r=64;r<=p;r+=64)l(i,c(u.substring(r-64,r)));for(u=u.substring(r-64),a=u.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],r=0;r<a;r+=1)s[r>>2]|=u.charCodeAt(r)<<(r%4<<3);if(s[r>>2]|=128<<(r%4<<3),r>55)for(l(i,s),r=0;r<16;r+=1)s[r]=0;return I=p*8,I=I.toString(16).match(/(.*?)(.{0,8})$/),_=parseInt(I[2],16),x=parseInt(I[1],16)||0,s[14]=_,s[15]=x,l(i,s),i}function f(u){var p=u.length,i=[1732584193,-271733879,-1732584194,271733878],r,a,s,I,_,x;for(r=64;r<=p;r+=64)l(i,d(u.subarray(r-64,r)));for(u=r-64<p?u.subarray(r-64):new Uint8Array(0),a=u.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],r=0;r<a;r+=1)s[r>>2]|=u[r]<<(r%4<<3);if(s[r>>2]|=128<<(r%4<<3),r>55)for(l(i,s),r=0;r<16;r+=1)s[r]=0;return I=p*8,I=I.toString(16).match(/(.*?)(.{0,8})$/),_=parseInt(I[2],16),x=parseInt(I[1],16)||0,s[14]=_,s[15]=x,l(i,s),i}function g(u){var p="",i;for(i=0;i<4;i+=1)p+=e[u>>i*8+4&15]+e[u>>i*8&15];return p}function y(u){var p;for(p=0;p<u.length;p+=1)u[p]=g(u[p]);return u.join("")}y(h("hello"))!=="5d41402abc4b2a76b9719d911017c592"&&(n=function(u,p){var i=(u&65535)+(p&65535),r=(u>>16)+(p>>16)+(i>>16);return r<<16|i&65535}),typeof ArrayBuffer<"u"&&!ArrayBuffer.prototype.slice&&(function(){function u(p,i){return p=p|0||0,p<0?Math.max(p+i,0):Math.min(p,i)}ArrayBuffer.prototype.slice=function(p,i){var r=this.byteLength,a=u(p,r),s=r,I,_,x,ye;return i!==t&&(s=u(i,r)),a>s?new ArrayBuffer(0):(I=s-a,_=new ArrayBuffer(I),x=new Uint8Array(_),ye=new Uint8Array(this,a,I),x.set(ye),_)}})();function E(u){return/[\u0080-\uFFFF]/.test(u)&&(u=unescape(encodeURIComponent(u))),u}function S(u,p){var i=u.length,r=new ArrayBuffer(i),a=new Uint8Array(r),s;for(s=0;s<i;s+=1)a[s]=u.charCodeAt(s);return p?a:r}function L(u){return String.fromCharCode.apply(null,new Uint8Array(u))}function C(u,p,i){var r=new Uint8Array(u.byteLength+p.byteLength);return r.set(new Uint8Array(u)),r.set(new Uint8Array(p),u.byteLength),i?r:r.buffer}function F(u){var p=[],i=u.length,r;for(r=0;r<i-1;r+=2)p.push(parseInt(u.substr(r,2),16));return String.fromCharCode.apply(String,p)}function D(){this.reset()}return D.prototype.append=function(u){return this.appendBinary(E(u)),this},D.prototype.appendBinary=function(u){this._buff+=u,this._length+=u.length;var p=this._buff.length,i;for(i=64;i<=p;i+=64)l(this._hash,c(this._buff.substring(i-64,i)));return this._buff=this._buff.substring(i-64),this},D.prototype.end=function(u){var p=this._buff,i=p.length,r,a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],s;for(r=0;r<i;r+=1)a[r>>2]|=p.charCodeAt(r)<<(r%4<<3);return this._finish(a,i),s=y(this._hash),u&&(s=F(s)),this.reset(),s},D.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},D.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},D.prototype.setState=function(u){return this._buff=u.buff,this._length=u.length,this._hash=u.hash,this},D.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},D.prototype._finish=function(u,p){var i=p,r,a,s;if(u[i>>2]|=128<<(i%4<<3),i>55)for(l(this._hash,u),i=0;i<16;i+=1)u[i]=0;r=this._length*8,r=r.toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(r[2],16),s=parseInt(r[1],16)||0,u[14]=a,u[15]=s,l(this._hash,u)},D.hash=function(u,p){return D.hashBinary(E(u),p)},D.hashBinary=function(u,p){var i=h(u),r=y(i);return p?F(r):r},D.ArrayBuffer=function(){this.reset()},D.ArrayBuffer.prototype.append=function(u){var p=C(this._buff.buffer,u,!0),i=p.length,r;for(this._length+=u.byteLength,r=64;r<=i;r+=64)l(this._hash,d(p.subarray(r-64,r)));return this._buff=r-64<i?new Uint8Array(p.buffer.slice(r-64)):new Uint8Array(0),this},D.ArrayBuffer.prototype.end=function(u){var p=this._buff,i=p.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],a,s;for(a=0;a<i;a+=1)r[a>>2]|=p[a]<<(a%4<<3);return this._finish(r,i),s=y(this._hash),u&&(s=F(s)),this.reset(),s},D.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},D.ArrayBuffer.prototype.getState=function(){var u=D.prototype.getState.call(this);return u.buff=L(u.buff),u},D.ArrayBuffer.prototype.setState=function(u){return u.buff=S(u.buff,!0),D.prototype.setState.call(this,u)},D.ArrayBuffer.prototype.destroy=D.prototype.destroy,D.ArrayBuffer.prototype._finish=D.prototype._finish,D.ArrayBuffer.hash=function(u,p){var i=f(new Uint8Array(u)),r=y(i);return p?F(r):r},D})});var q=ge((hn,$e)=>{"use strict";$e.exports={}});async function Pt(t){let n=(await Promise.resolve().then(()=>k(Ce(),1))).default,e=new n.ArrayBuffer,o=2097152;for(let l=0;l<t.size;l+=o){let c=Math.min(l+o,t.size);e.append(await t.slice(l,c).arrayBuffer())}return{md5:e.end()}}async function _t(t){let{createHash:n}=await Promise.resolve().then(()=>k(q(),1)),e=n("md5");return e.update(t),{md5:e.digest("hex")}}async function vt(t){let{createHash:n}=await Promise.resolve().then(()=>k(q(),1)),{createReadStream:e}=await Promise.resolve().then(()=>k(q(),1));return new Promise((o,l)=>{let c=n("md5"),d=e(t);d.on("error",h=>l(m.file(`Failed to read file for MD5: ${h.message}`,{filePath:t}))),d.on("data",h=>c.update(h)),d.on("end",()=>o({md5:c.digest("hex")}))})}async function B(t){if(t instanceof Blob)return Pt(t);if(typeof Buffer<"u"&&Buffer.isBuffer(t))return _t(t);if(typeof t=="string")return vt(t);throw m.business("Invalid input for MD5 calculation")}var X=w(()=>{"use strict";R()});function J(t){return t.replace(/\\/g,"/").replace(/\/+/g,"/").replace(/^\/+/,"")}var ze=w(()=>{"use strict"});function Ke(t,n={}){if(n.flatten===!1)return t.map(o=>({path:J(o),name:se(o)}));let e=Nt(t);return t.map(o=>{let l=J(o);if(e){let c=e.endsWith("/")?e:`${e}/`;l.startsWith(c)&&(l=l.substring(c.length))}return l||(l=se(o)),{path:l,name:se(o)}})}function Nt(t){if(!t.length)return"";let e=t.map(c=>J(c)).map(c=>c.split("/")),o=[],l=Math.min(...e.map(c=>c.length));for(let c=0;c<l-1;c++){let d=e[0][c];if(e.every(h=>h[c]===d))o.push(d);else break}return o.join("/")}function se(t){return t.split(/[/\\]/).pop()||t}var oe=w(()=>{"use strict";ze()});function Cn(t){ae=t}function Ft(){return typeof process<"u"&&process.versions&&process.versions.node?"node":typeof window<"u"||typeof self<"u"?"browser":"unknown"}function Ve(){return ae||Ft()}var ae,le=w(()=>{"use strict";ae=null});function Z(t,n){return Ot.find(e=>e.broken(t,n))}var Ot,ue=w(()=>{"use strict";R();ce();Ot=[{name:"name",broken:({path:t})=>!pe(t).valid,sentence:({path:t})=>pe(t).reason??"Invalid file name"},{name:"extension",broken:({path:t},n)=>Te(t,n.blockedExtensions??[]),sentence:({path:t})=>`File extension not allowed: "${t}"`},{name:"fileSize",broken:({size:t},n)=>t>n.maxFileSize,sentence:({path:t},n)=>`File "${t}" too large. Maximum ${Q(n.maxFileSize)} allowed`},{name:"totalSize",broken:({totalSize:t},n)=>t>n.maxTotalSize,sentence:({totalSize:t},n)=>`Total upload size too large. ${Q(t)} exceeds maximum of ${Q(n.maxTotalSize)}`}]});function Q(t,n=1){if(t===0)return"0 Bytes";let e=1024,o=["Bytes","KB","MB","GB"],l=Math.floor(Math.log(t)/Math.log(e));return`${parseFloat((t/e**l).toFixed(n))} ${o[l]}`}function pe(t){if(Se(t))return{valid:!1,reason:"File name contains unsafe characters"};if(t.startsWith(" ")||t.endsWith(" "))return{valid:!1,reason:"File name cannot start/end with spaces"};if(t.endsWith("."))return{valid:!1,reason:"File name cannot end with dots"};let n=/^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\.|$)/i,e=t.split("/").pop()||t;return n.test(e)?{valid:!1,reason:"File name uses a reserved system name"}:t.includes("..")?{valid:!1,reason:"File name contains path traversal pattern"}:{valid:!0}}function Gn(t,n){let e=[],o=[],l=[];if(t.length===0){let f={file:"(no files)",message:"At least one file must be provided"};return e.push(f),{files:[],validFiles:[],errors:e,warnings:[],canDeploy:!1}}for(let f of t)if(K(f.name))return e.push({file:f.name,message:"Unbuilt project detected \u2014 deploy your build output (dist/, build/, out/), not the project folder"}),{files:t.map(g=>({...g,status:b.VALIDATION_FAILED,statusMessage:"Unbuilt project detected"})),validFiles:[],errors:e,warnings:[],canDeploy:!1};if(t.length>n.maxFilesCount){let f={file:`(${t.length} files)`,message:`File count (${t.length}) exceeds limit of ${n.maxFilesCount}`};return e.push(f),{files:t.map(g=>({...g,status:b.VALIDATION_FAILED,statusMessage:f.message})),validFiles:[],errors:e,warnings:[],canDeploy:!1}}let c=0;for(let f of t){let g=b.READY,y="Ready for upload";if(f.status===b.PROCESSING_ERROR)g=b.VALIDATION_FAILED,y=f.statusMessage||"File failed during processing",e.push({file:f.name,message:y});else if(f.size===0){g=b.EXCLUDED,y="File is empty (0 bytes) and cannot be deployed due to storage limitations",o.push({file:f.name,message:y}),l.push({...f,status:g,statusMessage:y});continue}else if(f.size<0)g=b.VALIDATION_FAILED,y="File size must be positive",e.push({file:f.name,message:y});else if(!f.name||f.name.trim().length===0)g=b.VALIDATION_FAILED,y="File name cannot be empty",e.push({file:f.name||"(empty)",message:y});else if(f.name.includes("\0"))g=b.VALIDATION_FAILED,y="File name contains invalid characters (null byte)",e.push({file:f.name,message:y});else{let E={path:f.name,size:f.size,totalSize:c+f.size},S=Z(E,n);S?(g=b.VALIDATION_FAILED,y=S.sentence(E,n),e.push({file:S.name==="totalSize"?`(${t.length} files)`:f.name,message:y})):c=E.totalSize}l.push({...f,status:g,statusMessage:y})}e.length>0&&(l=l.map(f=>f.status===b.EXCLUDED?f:{...f,status:b.VALIDATION_FAILED,statusMessage:f.status===b.VALIDATION_FAILED?f.statusMessage:"Deployment failed due to validation errors in bundle"}));let d=e.length===0?l.filter(f=>f.status===b.READY):[],h=e.length===0;return{files:l,validFiles:d,errors:e,warnings:o,canDeploy:h}}function Ct(t){return t.filter(n=>n.status===b.READY)}function zn(t){return Ct(t).length>0}var ce=w(()=>{"use strict";R();ue()});function Ye(t){return Ut.test(t)}var $t,Ut,je=w(()=>{"use strict";$t=["^npm-debug\\.log$","^\\..*\\.swp$","^\\.DS_Store$","^\\.AppleDouble$","^\\.LSOverride$","^Icon\\r$","^\\._.*","^\\.Spotlight-V100(?:$|\\/)","\\.Trashes","^__MACOSX$","~$","^Thumbs\\.db$","^ehthumbs\\.db$","^[Dd]esktop\\.ini$","@eaDir$"],Ut=new RegExp($t.join("|"))});function qe(t,n){if(!t||t.length===0)return[];if(!n?.allowUnbuilt&&t.find(o=>o&&K(o)))throw m.business("Unbuilt project detected \u2014 deploy your build output (dist/, build/, out/), not the project folder");return t.filter(e=>{if(!e)return!1;let o=e.replace(/\\/g,"/").split("/").filter(Boolean);if(o.length===0)return!0;let l=o[o.length-1];if(Ye(l))return!1;for(let d of o)if(d!==".well-known"&&(d.startsWith(".")||d.length>255))return!1;let c=o.slice(0,-1);for(let d of c)if(Mt.some(h=>d.toLowerCase()===h.toLowerCase()))return!1;return!0})}var Mt,fe=w(()=>{"use strict";R();je();Mt=["__MACOSX",".Trashes",".fseventsd",".Spotlight-V100"]});function Xe(t,n){if(t.includes("\0")||t.includes("/../")||t.startsWith("../")||t.endsWith("/.."))throw m.business(`Security error: Unsafe file path "${t}" for file: ${n}`)}function We(t,n){let e=Z(t,n);if(e)throw m.business(e.sentence(t,n))}var de=w(()=>{"use strict";R();ue()});var Qe={};st(Qe,{processFilesForBrowser:()=>Je});async function Je(t,n={},e){if(Ve()!=="browser")throw m.business("processFilesForBrowser can only be called in a browser environment.");let o=t.map(E=>E.webkitRelativePath||E.name),l=n.build||n.prerender,c=Ke(o,{flatten:n.pathDetect!==!1}),d=c.map(E=>E.path),h=new Set(qe(d,{allowUnbuilt:l})),f=[];for(let E=0;E<t.length;E++)h.has(d[E])&&f.push({file:t[E],deployPath:c[E].path});if(f.length===0)return[];if(l){let E=[];for(let S=0;S<f.length;S++){let{file:L,deployPath:C}=f[S];if(L.size===0)continue;let{md5:F}=await B(L);E.push({path:C,content:L,size:L.size,md5:F})}return E}if(!e)throw m.config("Platform limits not provided. processFilesForBrowser requires the limits argument for deploy-mode validation \u2014 pass `ship.getLimits()` result.");let g=[],y=0;for(let E=0;E<f.length;E++){let{file:S,deployPath:L}=f[E];if(Xe(L,S.name),S.size===0)continue;y+=S.size,We({path:L,size:S.size,totalSize:y},e);let{md5:C}=await B(S);g.push({path:L,content:S,size:S.size,md5:C})}if(g.length>e.maxFilesCount)throw m.business(`Too many files to deploy. Maximum allowed is ${e.maxFilesCount} files.`);return g}var me=w(()=>{"use strict";R();oe();le();fe();X();de()});R();R();R();var Y=class{constructor(){this.handlers=new Map}on(n,e){this.handlers.has(n)||this.handlers.set(n,new Set),this.handlers.get(n)?.add(e)}off(n,e){let o=this.handlers.get(n);o&&(o.delete(e),o.size===0&&this.handlers.delete(n))}emit(n,...e){let o=this.handlers.get(n);if(!o)return;let l=Array.from(o);for(let c of l)try{c(...e)}catch(d){o.delete(c),n!=="error"&&setTimeout(()=>{let h=d instanceof Error?d:new Error(String(d));this.emit("error",h,String(n))},0)}}};R();R();function M(t){if(t==null)return;if(t.length===0)return t;if(t.length>N.MAX_COUNT)throw m.validation(`Maximum ${N.MAX_COUNT} labels allowed`);let n=t.map((o,l)=>{if(typeof o!="string")throw m.validation(`Label at index ${l} must be a string`);let c=o.trim().toLowerCase();if(c.length<N.MIN_LENGTH)throw m.validation(`Labels must be at least ${N.MIN_LENGTH} characters long`);if(c.length>N.MAX_LENGTH)throw m.validation(`Labels must be no more than ${N.MAX_LENGTH} characters long`);if(!ve.test(c))throw m.validation(`Labels must start and end with alphanumeric characters, with optional separators (${N.SEPARATORS}) between segments`);return c}),e=[...new Set(n)];if(e.length!==n.length)throw m.validation("Duplicate labels are not allowed");return e}async function xe(t){let n=t.find(l=>l.path===v||l.path===`/${v}`);if(!n)return;let e=n.content,o=typeof e.text=="function"?await e.text():n.content.toString("utf8");we(o)}var At=3e4,Dt=2,Tt=300,St=2e3,Rt=new Set([500,502,503,504]);function bt(t,n){return new Promise((e,o)=>{if(n?.aborted){o(n.reason);return}let l=()=>{clearTimeout(d),n?.removeEventListener("abort",c)},c=()=>{l(),o(n?.reason)},d=setTimeout(()=>{l(),e()},t);n?.addEventListener("abort",c)})}var Ne=3e5,It=3e5,wt=Ne+It,Lt="sdk";function ie(t){let n=new URLSearchParams;t?.limit!==void 0&&n.set("limit",String(t.limit)),t?.cursor!==void 0&&n.set("cursor",t.cursor);let e=n.toString();return e?`?${e}`:""}var j=class extends Y{constructor(e){super();this.globalHeaders={};this.apiUrl=e.apiUrl||ne,this.getAuthHeadersCallback=e.getAuthHeaders,this.session=e.session??!1,this.caller=e.caller,this.timeout=e.timeout??At,this.maxRetries=Math.max(0,e.maxRetries??Dt),this.deployTimeout=e.timeout??Ne,this.deployBuildTimeout=e.timeout??wt,this.fetch=e.fetch??globalThis.fetch.bind(globalThis),this.createDeployBody=e.createDeployBody,this.deployEndpoint=e.deployEndpoint||T.DEPLOYMENTS}setGlobalHeaders(e){this.globalHeaders=e}async executeRequest(e,o,l,c=this.timeout){for(let d=0;;d++)try{return await this.attemptOnce(e,o,l,c)}catch(h){let f=m.fromFetchError(h,l);if(d>=this.maxRetries||!this.isRetryable(f,o))throw f;let g=Math.min(St,Tt*2**d);try{await bt(Math.random()*g,o.signal)}catch(y){let E=m.fromFetchError(y,l);throw this.emit("error",E,e),E}}}isRetryable(e,o){if(o.signal?.aborted||e.isType(A.Maintenance)||e.isType(A.Cancelled)||!(e.isNetworkError()||e.status!==void 0&&Rt.has(e.status)))return!1;let c=(o.method??"GET").toUpperCase();return c==="GET"||c==="HEAD"?!0:c==="PUT"||c==="DELETE"?!1:this.hasIdempotencyKey(o.headers)}hasIdempotencyKey(e){if(!e)return!1;let o=U.HEADER.toLowerCase(),l=!1,c=d=>{d.toLowerCase()===o&&(l=!0)};if(e instanceof Headers)e.forEach((d,h)=>{c(h)});else if(Array.isArray(e))for(let[d]of e)c(d);else for(let d of Object.keys(e))c(d);return l}async attemptOnce(e,o,l,c=this.timeout){let d=()=>{};try{let h=await this.mergeHeaders(o.headers),f=this.createTimeoutSignal(o.signal,c);d=f.cleanup;let g={...o,headers:h,credentials:this.session&&!h.Authorization?"include":void 0,signal:f.signal};this.emit("request",e,g);let y=await this.fetch(e,g);if(d(),!y.ok)throw await m.fromHttpResponse(y,l);return this.emit("response",this.safeClone(y),e),{data:await this.parseResponse(this.safeClone(y)),status:y.status}}catch(h){d();let f=m.fromFetchError(h,l);throw this.emit("error",f,e),f}}async request(e,o,l,c){let{data:d}=await this.executeRequest(e,o,l,c);return d}async requestWithStatus(e,o,l){return this.executeRequest(e,o,l)}async mergeHeaders(e={}){return{...this.globalHeaders,...this.caller?{[$.HEADER]:this.caller}:{},...await this.getAuthHeadersCallback(),...e}}createTimeoutSignal(e,o=this.timeout){let l=new AbortController,c=setTimeout(()=>l.abort(new DOMException(`Timed out after ${o}ms`,"TimeoutError")),o),d=e?()=>l.abort(e.reason):void 0;return e&&d&&(e.addEventListener("abort",d),e.aborted&&l.abort(e.reason)),{signal:l.signal,cleanup:()=>{clearTimeout(c),e&&d&&e.removeEventListener("abort",d)}}}safeClone(e){try{return e.clone()}catch{return e}}async parseResponse(e){if(!(e.headers.get("Content-Length")==="0"||e.status===204))return e.json()}async deploy(e,o={}){if(!e.length)throw m.business("No files to deploy");for(let g of e)if(!g.md5)throw m.file(`MD5 checksum missing for file: ${g.path}`,{filePath:g.path});re(o.password);let l=Ae(o.idempotencyKey),c=M(o.labels);await xe(e);let d=o.build||o.prerender||o.spa?{build:o.build,prerender:o.prerender,spa:o.spa}:void 0,{body:h,headers:f}=await this.createDeployBody(e,{labels:c,via:o.via??Lt,password:o.password,flags:d,captcha:o.captcha});return this.request(`${this.apiUrl}${this.deployEndpoint}`,{method:"POST",body:h,headers:l?{...f,[U.HEADER]:l}:f,signal:o.signal||null},"Deploy",o.build||o.prerender?this.deployBuildTimeout:this.deployTimeout)}async listDeployments(e){return this.request(`${this.apiUrl}${T.DEPLOYMENTS}${ie(e)}`,{method:"GET"},"List deployments")}async getDeployment(e){return this.request(`${this.apiUrl}${T.DEPLOYMENT(encodeURIComponent(e))}`,{method:"GET"},"Get deployment")}async updateDeploymentLabels(e,o){let l=M(o);return this.request(`${this.apiUrl}${T.DEPLOYMENT(encodeURIComponent(e))}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({labels:l})},"Update deployment labels")}async deleteDeployment(e){return this.request(`${this.apiUrl}${T.DEPLOYMENT(encodeURIComponent(e))}`,{method:"DELETE"},"Delete deployment")}async setDomain(e,o,l){let c=M(l),d={};o&&(d.deployment=o),c!==void 0&&(d.labels=c);let{data:h,status:f}=await this.requestWithStatus(`${this.apiUrl}${T.DOMAIN(encodeURIComponent(e))}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(d)},"Set domain");return{...h,isCreate:f===201}}async listDomains(e){return this.request(`${this.apiUrl}${T.DOMAINS}${ie(e)}`,{method:"GET"},"List domains")}async getDomain(e){return this.request(`${this.apiUrl}${T.DOMAIN(encodeURIComponent(e))}`,{method:"GET"},"Get domain")}async deleteDomain(e){return this.request(`${this.apiUrl}${T.DOMAIN(encodeURIComponent(e))}`,{method:"DELETE"},"Delete domain")}async verifyDomain(e){return this.request(`${this.apiUrl}${T.DOMAIN_VERIFY(encodeURIComponent(e))}`,{method:"POST"},"Verify domain")}async getDomainDns(e){return this.request(`${this.apiUrl}${T.DOMAIN_DNS(encodeURIComponent(e))}`,{method:"GET"},"Get domain DNS")}async getDomainRecords(e){return this.request(`${this.apiUrl}${T.DOMAIN_RECORDS(encodeURIComponent(e))}`,{method:"GET"},"Get domain records")}async getDomainShare(e){return this.request(`${this.apiUrl}${T.DOMAIN_SHARE(encodeURIComponent(e))}`,{method:"GET"},"Get domain share")}async validateDomain(e){return this.request(`${this.apiUrl}${T.DOMAINS_VALIDATE}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({domain:e})},"Validate domain")}async createToken(e,o){let l=M(o),c={};return e!==void 0&&(c.ttl=e),l!==void 0&&(c.labels=l),this.request(`${this.apiUrl}${T.TOKENS}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)},"Create token")}async listTokens(e){return this.request(`${this.apiUrl}${T.TOKENS}${ie(e)}`,{method:"GET"},"List tokens")}async deleteToken(e){return this.request(`${this.apiUrl}${T.TOKEN(encodeURIComponent(e))}`,{method:"DELETE"},"Delete token")}async getToken(e){return this.request(`${this.apiUrl}${T.TOKEN(encodeURIComponent(e))}`,{method:"GET"},"Get token")}async getAccount(){return this.request(`${this.apiUrl}${T.ACCOUNT}`,{method:"GET"},"Get account")}async getLimits(){return this.request(`${this.apiUrl}${T.LIMITS}`,{method:"GET"},"Get limits")}async ping(){return this.request(`${this.apiUrl}${T.PING}`,{method:"GET"},"Ping")}async checkSPA(e,o={}){let l=e.find(f=>f.path===V.INDEX_FILE||f.path===`/${V.INDEX_FILE}`);if(!l||l.size>V.MAX_INDEX_BYTES)return!1;let c;if(typeof Buffer<"u"&&Buffer.isBuffer(l.content))c=l.content.toString("utf-8");else if(typeof Blob<"u"&&l.content instanceof Blob)c=await l.content.text();else if(typeof File<"u"&&l.content instanceof File)c=await l.content.text();else return!1;let d={files:e.map(f=>f.path),index:c};return(await this.request(`${this.apiUrl}${T.SPA_CHECK}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(d)},"SPA check")).isSPA}};R();R();X();async function xt(){let t=JSON.stringify(Ie,null,2),n;typeof Buffer<"u"?n=Buffer.from(t,"utf-8"):n=new Blob([t],{type:"application/json"});let{md5:e}=await B(n);return{path:v,content:n,size:t.length,md5:e}}async function Ue(t,n,e){if(e.spaDetect===!1||e.spa||e.build||e.prerender||t.some(o=>o.path===v))return t;try{if(await n.checkSPA(t,e)){let l=await xt();return[...t,l]}}catch{}return t}function Me(t){let{getApi:n,ensureInit:e,processInput:o}=t;return{upload:async(l,c={})=>{if(await e(),!o)throw m.config("processInput function is not provided.");let d=n(),h=await o(l,c);return h=await Ue(h,d,c),d.deploy(h,c)},list:async l=>(await e(),n().listDeployments(l)),get:async l=>(await e(),n().getDeployment(l)),set:async(l,c)=>(await e(),n().updateDeploymentLabels(l,c.labels)),delete:async l=>(await e(),n().deleteDeployment(l))}}function Be(t){let{getApi:n,ensureInit:e}=t;return{set:async(o,l={})=>(await e(),n().setDomain(o,l.deployment,l.labels)),list:async o=>(await e(),n().listDomains(o)),get:async o=>(await e(),n().getDomain(o)),delete:async o=>(await e(),n().deleteDomain(o)),verify:async o=>(await e(),n().verifyDomain(o)),validate:async o=>(await e(),n().validateDomain(o)),dns:async o=>(await e(),n().getDomainDns(o)),records:async o=>(await e(),n().getDomainRecords(o)),share:async o=>(await e(),n().getDomainShare(o))}}function He(t){let{getApi:n,ensureInit:e}=t;return{get:async()=>(await e(),n().getAccount())}}function ke(t){let{getApi:n,ensureInit:e}=t;return{create:async(o={})=>(await e(),n().createToken(o.ttl,o.labels)),list:async o=>(await e(),n().listTokens(o)),get:async o=>(await e(),n().getToken(o)),delete:async o=>(await e(),n().deleteToken(o))}}var W=class{constructor(n={}){this.initPromise=null;this.platformLimits=null;this.credential=null;if(n={...n,apiUrl:n.apiUrl||void 0,token:n.token||void 0,caller:n.caller||void 0},this.clientOptions=n,n.caller!==void 0&&Pe(n.caller),n.token&&n.session)throw m.config("Provide either `token` or `session`, not both.");typeof n.token=="string"?(te(n.token),this.credential=n.token):n.token&&(this.credential=n.token),this.http=new j({...n,getAuthHeaders:()=>this.getAuthHeaders(),createDeployBody:this.getDeployBodyCreator()});let e={getApi:()=>this.http,ensureInit:()=>this.ensureInitialized()};this.deployments=Me({...e,processInput:(o,l)=>this.processInput(o,l)}),this.domains=Be(e),this.account=He(e),this.tokens=ke(e)}async ensureInitialized(){return this.initPromise||(this.initPromise=this.fetchPlatformLimits()),this.initPromise}async fetchPlatformLimits(){try{this.platformLimits=await this.http.getLimits()}catch(n){throw this.initPromise=null,n}}async ping(){return await this.ensureInitialized(),this.http.ping()}async deploy(n,e){return this.deployments.upload(n,e)}async whoami(){return this.account.get()}async getLimits(){return this.platformLimits?this.platformLimits:(await this.ensureInitialized(),this.platformLimits)}on(n,e){this.http.on(n,e)}off(n,e){this.http.off(n,e)}setHeaders(n){this.http.setGlobalHeaders(n)}clearHeaders(){this.http.setGlobalHeaders({})}setToken(n){if(this.clientOptions.session)throw m.config("Provide either `token` or `session`, not both.");if(typeof n=="string"){if(!n)throw m.business("Invalid token provided. Token must be a non-empty string.");te(n),this.credential=n;return}if(typeof n!="function")throw m.business("Invalid token provided. Token must be a non-empty string or a provider function.");this.credential=n}async getAuthHeaders(){if(this.credential===null)return{};let n=typeof this.credential=="function"?await this.credential():this.credential;if(!n)throw m.authentication("Token provider returned no token.");if(typeof n!="string")throw m.authentication("Token provider returned a non-string value.");return{Authorization:`Bearer ${n}`}}};R();async function Ge(t,n={}){let{labels:e,via:o,password:l,flags:c,captcha:d}=n,h=new FormData,f=[];for(let g of t){if(!(g.content instanceof File||g.content instanceof Blob))throw m.file(`Unsupported file.content type for browser: ${g.path}`,{filePath:g.path});if(!g.md5)throw m.file(`File missing md5 checksum: ${g.path}`,{filePath:g.path});let y=new File([g.content],g.path,{type:"application/octet-stream"});h.append(P.FILES,y),f.push(g.md5)}return h.append(P.CHECKSUMS,JSON.stringify(f)),e&&e.length>0&&h.append(P.LABELS,JSON.stringify(e)),o&&h.append(P.VIA,o),l&&h.append(P.PASSWORD,l),c?.build&&h.append(P.BUILD,"true"),c?.prerender&&h.append(P.PRERENDER,"true"),c?.spa&&h.append(P.SPA,"true"),d&&h.append(P.CAPTCHA,d),{body:h,headers:{}}}R();R();oe();le();ce();fe();X();de();function Qn(t,n,e,o=!0){let l=t===1?n:e;return o?`${t} ${l}`:l}me();var he=class extends W{async deploy(n,e){return super.deploy(n,e)}async processInput(n,e){if(!Array.isArray(n)||!n.every(l=>l instanceof File))throw m.business("Invalid input type for browser environment. Expected File[].");if(n.length===0)throw m.business("No files to deploy.");let{processFilesForBrowser:o}=await Promise.resolve().then(()=>(me(),Qe));return o(n,e,this.platformLimits??void 0)}getDeployBodyCreator(){return Ge}},Sr=he;export{Re as API_KEY,T as API_PATHS,Vt as AUTH_BASE_PATH,zt as AccountPlan,j as ApiHttp,Ee as AuthMethod,$ as CALLER,ne as DEFAULT_API,v as DEPLOYMENT_CONFIG_FILENAME,P as DEPLOY_FIELDS,be as DEPLOY_TOKEN,Ht as DeploymentStatus,at as DeploymentVia,kt as DomainStatus,A as ErrorType,b as FILE_VALIDATION_STATUS,b as FileValidationStatus,U as IDEMPOTENCY_KEY_CONSTRAINTS,Mt as JUNK_DIRECTORIES,N as LABEL_CONSTRAINTS,ve as LABEL_PATTERN,Wt as MY_API_KEY_URL,Yt as OAuthScope,z as PASSWORD_CONSTRAINTS,Jt as PUBLIC_DEPLOYMENT_TTL_SECONDS,Xt as SHIP_ENV,V as SPA_CHECK_CONSTRAINTS,Ie as SPA_DEFAULT_CONFIG,he as Ship,m as ShipError,O as TokenKind,ht as UNBUILT_PROJECT_MARKERS,mt as UNSAFE_FILENAME_CHARS,Kt as WEB_FILE_ACCEPT,Cn as __setTestEnvironment,zn as allValidFilesReady,we as assertShipJsonSyntax,B as calculateMD5,yt as classifyToken,He as createAccountResource,Me as createDeploymentResource,Be as createDomainResource,ke as createTokenResource,Sr as default,rn as deserializeLabels,Zt as extractSubdomain,qe as filterJunk,Q as formatFileSize,en as generateDeploymentUrl,tn as generateDomainUrl,Ve as getENV,Ct as getValidFiles,K as hasUnbuiltMarker,Se as hasUnsafeChars,Te as isBlockedExtension,Qt as isCustomDomain,qt as isDeployment,_e as isPlatformDomain,De as isShipError,Gt as normalizeVia,Ke as optimizeDeployPaths,Qn as pluralize,Je as processFilesForBrowser,nn as serializeLabels,gt as validateApiKey,jt as validateApiUrl,Pe as validateCaller,We as validateDeployFile,Xe as validateDeployPath,Et as validateDeployToken,pe as validateFileName,Gn as validateFiles,Ae as validateIdempotencyKey,re as validatePassword,te as validateToken};
2
2
  //# sourceMappingURL=browser.js.map