@shipstatic/ship 0.1.4 → 0.1.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/dist/browser.js +52 -0
- package/dist/browser.js.map +1 -0
- package/dist/cli.cjs +6 -4
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -24
- package/dist/index.d.ts +10 -24
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/browser-files-4HSSOKZU.js +0 -2
- package/dist/browser-files-4HSSOKZU.js.map +0 -1
- package/dist/browser-files-YFSJYLHP.browser.js +0 -2
- package/dist/browser-files-YFSJYLHP.browser.js.map +0 -1
- package/dist/chunk-4VJL7GMP.browser.js +0 -2
- package/dist/chunk-4VJL7GMP.browser.js.map +0 -1
- package/dist/chunk-GO2GMAFT.js +0 -2
- package/dist/chunk-GO2GMAFT.js.map +0 -1
- package/dist/chunk-KBFFWP3K.browser.js +0 -2
- package/dist/chunk-KBFFWP3K.browser.js.map +0 -1
- package/dist/chunk-OJ6FY5CZ.js +0 -2
- package/dist/chunk-OJ6FY5CZ.js.map +0 -1
- package/dist/chunk-Z566D7DF.browser.js +0 -2
- package/dist/chunk-Z566D7DF.browser.js.map +0 -1
- package/dist/index.browser.js +0 -20
- package/dist/index.browser.js.map +0 -1
- package/dist/lib-SI4AR47O.browser.js +0 -6
- package/dist/lib-SI4AR47O.browser.js.map +0 -1
- package/dist/path-3OU57R5J.browser.js +0 -2
- package/dist/path-3OU57R5J.browser.js.map +0 -1
- package/dist/path-6I7MXXVI.js +0 -2
- package/dist/path-6I7MXXVI.js.map +0 -1
- package/dist/spark-md5-DLLZAUJQ.browser.js +0 -2
- package/dist/spark-md5-DLLZAUJQ.browser.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -29,8 +29,8 @@ interface DeploymentOptions {
|
|
|
29
29
|
timeout?: number;
|
|
30
30
|
/** The API key to use for this specific deploy. Overrides client's default. */
|
|
31
31
|
apiKey?: string;
|
|
32
|
-
/** Whether to
|
|
33
|
-
|
|
32
|
+
/** Whether to preserve directory structure. By default, common parent directories are flattened. */
|
|
33
|
+
preserveDirs?: boolean;
|
|
34
34
|
/** Callback for overall deploy progress (0-100). */
|
|
35
35
|
onProgress?: (progress: number) => void;
|
|
36
36
|
/** Callback for detailed progress statistics. */
|
|
@@ -40,7 +40,7 @@ interface DeploymentOptions {
|
|
|
40
40
|
* Options for configuring an deploy operation via `apiClient.deployFiles`.
|
|
41
41
|
* Derived from DeploymentOptions but excludes client-side only options.
|
|
42
42
|
*/
|
|
43
|
-
type ApiDeployOptions = Omit<DeploymentOptions, '
|
|
43
|
+
type ApiDeployOptions = Omit<DeploymentOptions, 'preserveDirs'>;
|
|
44
44
|
/**
|
|
45
45
|
* Detailed statistics about the progress of an deploy operation.
|
|
46
46
|
*/
|
|
@@ -145,37 +145,22 @@ interface KeysResource {
|
|
|
145
145
|
* Now uses the simplified, declarative approach suggested in the feedback.
|
|
146
146
|
*
|
|
147
147
|
* @param paths - File or directory paths to scan and process.
|
|
148
|
-
* @param options - Processing options (basePath,
|
|
148
|
+
* @param options - Processing options (basePath, preserveDirs).
|
|
149
149
|
* @returns Promise resolving to an array of StaticFile objects.
|
|
150
150
|
* @throws {ShipClientError} If called outside Node.js or if fs/path modules fail.
|
|
151
151
|
*/
|
|
152
|
-
declare function processFilesForNode(paths: string[], options?:
|
|
153
|
-
basePath?: string;
|
|
154
|
-
stripCommonPrefix?: boolean;
|
|
155
|
-
}): Promise<StaticFile[]>;
|
|
152
|
+
declare function processFilesForNode(paths: string[], options?: DeploymentOptions): Promise<StaticFile[]>;
|
|
156
153
|
|
|
157
154
|
/**
|
|
158
155
|
* Processes browser files (FileList or File[]) into an array of StaticFile objects ready for deploy.
|
|
159
156
|
* Calculates MD5, filters junk files, and determines relative paths (stripping basePath if provided).
|
|
160
157
|
*
|
|
161
158
|
* @param browserFiles - FileList or File[] to process for deploy.
|
|
162
|
-
* @param options - Optional processing options (basePath for path stripping,
|
|
159
|
+
* @param options - Optional processing options (basePath for path stripping, preserveDirs).
|
|
163
160
|
* @returns Promise resolving to an array of StaticFile objects.
|
|
164
161
|
* @throws {ShipClientError} If called outside a browser or with invalid input.
|
|
165
162
|
*/
|
|
166
|
-
declare function processFilesForBrowser(browserFiles: FileList | File[], options?:
|
|
167
|
-
explicitBaseDirInput?: string;
|
|
168
|
-
stripCommonPrefix?: boolean;
|
|
169
|
-
}): Promise<StaticFile[]>;
|
|
170
|
-
/**
|
|
171
|
-
* Finds the common parent directory from a FileList or File[] using webkitRelativePath.
|
|
172
|
-
* Useful for stripping a common prefix if files are selected from a single folder.
|
|
173
|
-
*
|
|
174
|
-
* @param files - FileList or File[] to analyze.
|
|
175
|
-
* @returns Common parent directory string, or empty string if not consistent.
|
|
176
|
-
* @throws {ShipClientError} If called outside a browser.
|
|
177
|
-
*/
|
|
178
|
-
declare function findBrowserCommonParentDirectory(files: FileList | File[]): string;
|
|
163
|
+
declare function processFilesForBrowser(browserFiles: FileList | File[], options?: DeploymentOptions): Promise<StaticFile[]>;
|
|
179
164
|
|
|
180
165
|
/**
|
|
181
166
|
* @file Environment detection utilities for the Ship SDK.
|
|
@@ -221,6 +206,7 @@ declare class Ship {
|
|
|
221
206
|
private http;
|
|
222
207
|
private environment;
|
|
223
208
|
private configInitialized;
|
|
209
|
+
private configLoaded;
|
|
224
210
|
private readonly clientOptions;
|
|
225
211
|
private _deployments?;
|
|
226
212
|
private _aliases?;
|
|
@@ -228,7 +214,7 @@ declare class Ship {
|
|
|
228
214
|
private _keys?;
|
|
229
215
|
constructor(options?: ShipClientOptions);
|
|
230
216
|
/**
|
|
231
|
-
* Initialize platform config from API (called automatically on first use)
|
|
217
|
+
* Initialize config from file/env and platform config from API (called automatically on first use)
|
|
232
218
|
*/
|
|
233
219
|
private initializeConfig;
|
|
234
220
|
/**
|
|
@@ -257,4 +243,4 @@ declare class Ship {
|
|
|
257
243
|
deploy(input: DeployInput, options?: DeploymentOptions): Promise<Deployment>;
|
|
258
244
|
}
|
|
259
245
|
|
|
260
|
-
export { type AccountResource, type AliasResource, type ApiDeployOptions, type DeployInput, type DeploymentOptions, type DeploymentResource, type KeysResource, type ProgressStats, Ship, type ShipClientOptions, type StaticFile, __setTestEnvironment, Ship as default,
|
|
246
|
+
export { type AccountResource, type AliasResource, type ApiDeployOptions, type DeployInput, type DeploymentOptions, type DeploymentResource, type KeysResource, type ProgressStats, Ship, type ShipClientOptions, type StaticFile, __setTestEnvironment, Ship as default, processFilesForBrowser, processFilesForNode };
|
package/dist/index.d.ts
CHANGED
|
@@ -29,8 +29,8 @@ interface DeploymentOptions {
|
|
|
29
29
|
timeout?: number;
|
|
30
30
|
/** The API key to use for this specific deploy. Overrides client's default. */
|
|
31
31
|
apiKey?: string;
|
|
32
|
-
/** Whether to
|
|
33
|
-
|
|
32
|
+
/** Whether to preserve directory structure. By default, common parent directories are flattened. */
|
|
33
|
+
preserveDirs?: boolean;
|
|
34
34
|
/** Callback for overall deploy progress (0-100). */
|
|
35
35
|
onProgress?: (progress: number) => void;
|
|
36
36
|
/** Callback for detailed progress statistics. */
|
|
@@ -40,7 +40,7 @@ interface DeploymentOptions {
|
|
|
40
40
|
* Options for configuring an deploy operation via `apiClient.deployFiles`.
|
|
41
41
|
* Derived from DeploymentOptions but excludes client-side only options.
|
|
42
42
|
*/
|
|
43
|
-
type ApiDeployOptions = Omit<DeploymentOptions, '
|
|
43
|
+
type ApiDeployOptions = Omit<DeploymentOptions, 'preserveDirs'>;
|
|
44
44
|
/**
|
|
45
45
|
* Detailed statistics about the progress of an deploy operation.
|
|
46
46
|
*/
|
|
@@ -145,37 +145,22 @@ interface KeysResource {
|
|
|
145
145
|
* Now uses the simplified, declarative approach suggested in the feedback.
|
|
146
146
|
*
|
|
147
147
|
* @param paths - File or directory paths to scan and process.
|
|
148
|
-
* @param options - Processing options (basePath,
|
|
148
|
+
* @param options - Processing options (basePath, preserveDirs).
|
|
149
149
|
* @returns Promise resolving to an array of StaticFile objects.
|
|
150
150
|
* @throws {ShipClientError} If called outside Node.js or if fs/path modules fail.
|
|
151
151
|
*/
|
|
152
|
-
declare function processFilesForNode(paths: string[], options?:
|
|
153
|
-
basePath?: string;
|
|
154
|
-
stripCommonPrefix?: boolean;
|
|
155
|
-
}): Promise<StaticFile[]>;
|
|
152
|
+
declare function processFilesForNode(paths: string[], options?: DeploymentOptions): Promise<StaticFile[]>;
|
|
156
153
|
|
|
157
154
|
/**
|
|
158
155
|
* Processes browser files (FileList or File[]) into an array of StaticFile objects ready for deploy.
|
|
159
156
|
* Calculates MD5, filters junk files, and determines relative paths (stripping basePath if provided).
|
|
160
157
|
*
|
|
161
158
|
* @param browserFiles - FileList or File[] to process for deploy.
|
|
162
|
-
* @param options - Optional processing options (basePath for path stripping,
|
|
159
|
+
* @param options - Optional processing options (basePath for path stripping, preserveDirs).
|
|
163
160
|
* @returns Promise resolving to an array of StaticFile objects.
|
|
164
161
|
* @throws {ShipClientError} If called outside a browser or with invalid input.
|
|
165
162
|
*/
|
|
166
|
-
declare function processFilesForBrowser(browserFiles: FileList | File[], options?:
|
|
167
|
-
explicitBaseDirInput?: string;
|
|
168
|
-
stripCommonPrefix?: boolean;
|
|
169
|
-
}): Promise<StaticFile[]>;
|
|
170
|
-
/**
|
|
171
|
-
* Finds the common parent directory from a FileList or File[] using webkitRelativePath.
|
|
172
|
-
* Useful for stripping a common prefix if files are selected from a single folder.
|
|
173
|
-
*
|
|
174
|
-
* @param files - FileList or File[] to analyze.
|
|
175
|
-
* @returns Common parent directory string, or empty string if not consistent.
|
|
176
|
-
* @throws {ShipClientError} If called outside a browser.
|
|
177
|
-
*/
|
|
178
|
-
declare function findBrowserCommonParentDirectory(files: FileList | File[]): string;
|
|
163
|
+
declare function processFilesForBrowser(browserFiles: FileList | File[], options?: DeploymentOptions): Promise<StaticFile[]>;
|
|
179
164
|
|
|
180
165
|
/**
|
|
181
166
|
* @file Environment detection utilities for the Ship SDK.
|
|
@@ -221,6 +206,7 @@ declare class Ship {
|
|
|
221
206
|
private http;
|
|
222
207
|
private environment;
|
|
223
208
|
private configInitialized;
|
|
209
|
+
private configLoaded;
|
|
224
210
|
private readonly clientOptions;
|
|
225
211
|
private _deployments?;
|
|
226
212
|
private _aliases?;
|
|
@@ -228,7 +214,7 @@ declare class Ship {
|
|
|
228
214
|
private _keys?;
|
|
229
215
|
constructor(options?: ShipClientOptions);
|
|
230
216
|
/**
|
|
231
|
-
* Initialize platform config from API (called automatically on first use)
|
|
217
|
+
* Initialize config from file/env and platform config from API (called automatically on first use)
|
|
232
218
|
*/
|
|
233
219
|
private initializeConfig;
|
|
234
220
|
/**
|
|
@@ -257,4 +243,4 @@ declare class Ship {
|
|
|
257
243
|
deploy(input: DeployInput, options?: DeploymentOptions): Promise<Deployment>;
|
|
258
244
|
}
|
|
259
245
|
|
|
260
|
-
export { type AccountResource, type AliasResource, type ApiDeployOptions, type DeployInput, type DeploymentOptions, type DeploymentResource, type KeysResource, type ProgressStats, Ship, type ShipClientOptions, type StaticFile, __setTestEnvironment, Ship as default,
|
|
246
|
+
export { type AccountResource, type AliasResource, type ApiDeployOptions, type DeployInput, type DeploymentOptions, type DeploymentResource, type KeysResource, type ProgressStats, Ship, type ShipClientOptions, type StaticFile, __setTestEnvironment, Ship as default, processFilesForBrowser, processFilesForNode };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as fe,b as y,c as M,d as j,e as U,f as ue}from"./chunk-GO2GMAFT.js";import{a as me,b as B,c as k,d as p}from"./chunk-OJ6FY5CZ.js";import{z as v}from"zod";import{cosmiconfigSync as ye}from"cosmiconfig";var b={};B(b,Se);import*as Se from"@shipstatic/types";var S="https://api.shipstatic.com";var H="ship",he=v.object({apiUrl:v.string().url().optional(),apiKey:v.string().optional()}).strict();function q(i){try{return he.parse(i)}catch(e){if(e instanceof v.ZodError){let t=e.issues[0],o=t.path.length>0?` at ${t.path.join(".")}`:"";throw b.ShipError.config(`Configuration validation failed${o}: ${t.message}`)}throw b.ShipError.config("Configuration validation failed")}}function de(){try{let e=ye(H,{searchPlaces:[`.${H}rc`,"package.json"]}).search();if(e&&!e.isEmpty&&e.config)return q(e.config)}catch(i){if(i instanceof b.ShipError)throw i}return{}}function G(){if(y()!=="node")return{};let i={apiUrl:process.env.SHIP_API_URL,apiKey:process.env.SHIP_API_KEY},e=de(),t={apiUrl:i.apiUrl??e.apiUrl,apiKey:i.apiKey??e.apiKey};return q(t)}function V(i={},e={}){let t={apiUrl:i.apiUrl||e.apiUrl||S,apiKey:i.apiKey!==void 0?i.apiKey:e.apiKey};return t.apiKey!==void 0?{apiUrl:t.apiUrl,apiKey:t.apiKey}:{apiUrl:t.apiUrl}}function J(i={},e){let t={...i};return t.onProgress===void 0&&e.onProgress!==void 0&&(t.onProgress=e.onProgress),t.onProgressStats===void 0&&e.onProgressStats!==void 0&&(t.onProgressStats=e.onProgressStats),t.maxConcurrency===void 0&&e.maxConcurrentDeploys!==void 0&&(t.maxConcurrency=e.maxConcurrentDeploys),t.timeout===void 0&&e.timeout!==void 0&&(t.timeout=e.timeout),t.apiKey===void 0&&e.apiKey!==void 0&&(t.apiKey=e.apiKey),t.apiUrl===void 0&&e.apiUrl!==void 0&&(t.apiUrl=e.apiUrl),t}import*as T from"mime-types";import{ShipError as u}from"@shipstatic/types";var R="/deployments",ge="/ping",E="/aliases",Pe="/config",we="/account";function Fe(i){return typeof i=="string"?T.lookup(i)||"application/octet-stream":T.lookup(i.name)||i.type||"application/octet-stream"}async function be(i){let e=[];for await(let t of i)e.push(t);return e}var r,W,L,h,Y,X,Z,Q,N,I,O=class{constructor(e){k(this,r);this.apiUrl=e.apiUrl||S,this.apiKey=e.apiKey??""}async ping(){return(await p(this,r,h).call(this,`${this.apiUrl}${ge}`,{method:"GET"},"Ping"))?.success||!1}async getConfig(){return await p(this,r,h).call(this,`${this.apiUrl}${Pe}`,{method:"GET"},"Config")}async deploy(e,t={}){p(this,r,Y).call(this,e);let{apiUrl:o=this.apiUrl,signal:s}=t;try{let{requestBody:n,requestHeaders:a}=await p(this,r,X).call(this,e),g={method:"POST",body:n,headers:a,signal:s||null},m=await p(this,r,L).call(this,`${o}${R}`,g,"Deploy");return m.ok||await p(this,r,N).call(this,m,"Deploy"),await m.json()}catch(n){throw n instanceof u?n:(p(this,r,I).call(this,n,"Deploy"),u.business("An unexpected error occurred and was not handled."))}}async listDeployments(){return await p(this,r,h).call(this,`${this.apiUrl}${R}`,{method:"GET"},"List Deployments")}async getDeployment(e){return await p(this,r,h).call(this,`${this.apiUrl}${R}/${e}`,{method:"GET"},"Get Deployment")}async removeDeployment(e){await p(this,r,h).call(this,`${this.apiUrl}${R}/${e}`,{method:"DELETE"},"Remove Deployment")}async setAlias(e,t){return await p(this,r,h).call(this,`${this.apiUrl}${E}/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({deploymentId:t})},"Set Alias")}async getAlias(e){return await p(this,r,h).call(this,`${this.apiUrl}${E}/${encodeURIComponent(e)}`,{method:"GET"},"Get Alias")}async listAliases(){return await p(this,r,h).call(this,`${this.apiUrl}${E}`,{method:"GET"},"List Aliases")}async removeAlias(e){await p(this,r,h).call(this,`${this.apiUrl}${E}/${encodeURIComponent(e)}`,{method:"DELETE"},"Remove Alias")}async getAccount(){return await p(this,r,h).call(this,`${this.apiUrl}${we}`,{method:"GET"},"Get Account")}async createApiKey(){return await p(this,r,h).call(this,`${this.apiUrl}/key`,{method:"POST"},"Create API Key")}};r=new WeakSet,W=function(e={}){let t={...e};return this.apiKey&&(t.Authorization=`Bearer ${this.apiKey}`),t},L=async function(e,t={},o){let s=p(this,r,W).call(this,t.headers),n={...t,headers:s,credentials:y()==="browser"?"include":"same-origin"};try{return await fetch(e,n)}catch(a){throw p(this,r,I).call(this,a,o),a}},h=async function(e,t={},o){try{let s=await p(this,r,L).call(this,e,t,o);return s.ok||await p(this,r,N).call(this,s,o),s.headers.get("Content-Length")==="0"||s.status===204?void 0:await s.json()}catch(s){throw s instanceof u||p(this,r,I).call(this,s,o),s}},Y=function(e){if(!e.length)throw u.business("No files to deploy.");for(let t of e)if(!t.md5)throw u.file(`MD5 checksum missing for file: ${t.path}`,t.path)},X=async function(e){let t,o={};if(y()==="browser")t=p(this,r,Z).call(this,e);else if(y()==="node"){let{body:s,headers:n}=await p(this,r,Q).call(this,e);t=s,o=n}else throw u.business("Unknown or unsupported execution environment");return{requestBody:t,requestHeaders:o}},Z=function(e){let t=new FormData,o=[];for(let s=0;s<e.length;s++){let n=e[s],a;if(n.content instanceof File||n.content instanceof Blob)a=n.content;else throw u.file(`Unsupported file.content type for browser FormData: ${n.path}`,n.path);let g=Fe(a instanceof File?a:n.path),m=new File([a],n.path,{type:g});t.append("files[]",m),o.push(n.md5)}return t.append("checksums",JSON.stringify(o)),t},Q=async function(e){let{FormData:t,File:o}=await import("formdata-node"),{FormDataEncoder:s}=await import("form-data-encoder"),n=await import("path"),a=new t,g=[];for(let F=0;F<e.length;F++){let c=e[F],D=T.lookup(c.path)||"application/octet-stream",$;if(Buffer.isBuffer(c.content))$=new o([c.content],n.basename(c.path),{type:D});else if(typeof Blob<"u"&&c.content instanceof Blob)$=new o([c.content],n.basename(c.path),{type:D});else throw u.file(`Unsupported file.content type for Node.js FormData: ${c.path}`,c.path);let ce=c.path.startsWith("/")?c.path:"/"+c.path;a.append("files[]",$,ce),g.push(c.md5)}a.append("checksums",JSON.stringify(g));let m=new s(a),l=await be(m.encode()),f=Buffer.concat(l.map(F=>Buffer.from(F))),C={"Content-Type":m.contentType,"Content-Length":Buffer.byteLength(f).toString()};return{body:f,headers:C}},N=async function(e,t){let o={};try{let s=e.headers.get("content-type");s&&s.includes("application/json")?o=await e.json():o={message:await e.text()}}catch{o={message:"Failed to parse error response"}}if(o.error||o.code||o.message){let s=o.message||o.error||`${t} failed due to API error`;throw u.api(s,e.status,o.code,o)}throw u.api(`${t} failed due to API error`,e.status,void 0,o)},I=function(e,t){throw e.name==="AbortError"?u.cancelled(`${t} operation was cancelled.`):e instanceof TypeError&&e.message.includes("fetch")?u.network(`${t} failed due to network error: ${e.message}`,e):e instanceof u?e:u.business(`An unexpected error occurred during ${t}: ${e.message||"Unknown error"}`)};import{ShipError as De}from"@shipstatic/types";import{ShipError as Ce}from"@shipstatic/types";var K=null;function ee(i){K=i}function x(){if(K===null)throw Ce.config("Platform configuration not initialized. The SDK must fetch configuration from the API before performing operations.");return K}import{ShipError as d}from"@shipstatic/types";import{ShipError as A}from"@shipstatic/types";import*as w from"fs";import*as P from"path";function ie(i){let e=[];try{let t=w.readdirSync(i);for(let o of t){let s=P.join(i,o),n=w.statSync(s);if(n.isDirectory()){let a=ie(s);e.push(...a)}else n.isFile()&&e.push(s)}}catch(t){console.error(`Error reading directory ${i}:`,t)}return e}async function te(i,e={}){let t=P.resolve(i),s=(()=>{let l=w.statSync(t);return l.isFile()?[t]:l.isDirectory()?ie(t):[]})().filter(l=>{let f=P.basename(l);return j([f]).length>0}),n;e.basePath?n=e.basePath:e.stripCommonPrefix?w.statSync(t).isDirectory()?n=t:n=P.dirname(t):w.statSync(t).isDirectory()?n=t:n=P.dirname(t);let a=[],g=0;for(let l of s)try{let f=w.statSync(l);if(f.size===0){console.warn(`Skipping empty file: ${l}`);continue}let C=x();if(f.size>C.maxFileSize)throw A.business(`File ${l} is too large. Maximum allowed size is ${C.maxFileSize/(1024*1024)}MB.`);if(g+=f.size,g>C.maxTotalSize)throw A.business(`Total deploy size is too large. Maximum allowed is ${C.maxTotalSize/(1024*1024)}MB.`);let F=w.readFileSync(l),{md5:c}=await M(F),D=P.relative(n,l).replace(/\\/g,"/");a.push({path:D,content:F,size:F.length,md5:c})}catch(f){if(f instanceof A&&f.isClientError&&f.isClientError())throw f;console.error(`Could not process file ${l}:`,f)}let m=x();if(a.length>m.maxFilesCount)throw A.business(`Too many files to deploy. Maximum allowed is ${m.maxFilesCount} files.`);return a}async function z(i,e={}){if(y()!=="node")throw A.business("processFilesForNode can only be called in a Node.js environment.");if(i.length>1){let t=[];for(let o of i){let s=await te(o,e);t.push(...s)}return t}return await te(i[0],e)}function oe(i,e={}){let t=x();if(!e.skipEmptyCheck&&i.length===0)throw d.business("No files to deploy.");if(i.length>t.maxFilesCount)throw d.business(`Too many files to deploy. Maximum allowed is ${t.maxFilesCount}.`);let o=0;for(let s of i){if(s.size>t.maxFileSize)throw d.business(`File ${s.name} is too large. Maximum allowed size is ${t.maxFileSize/(1024*1024)}MB.`);o+=s.size}if(o>t.maxTotalSize)throw d.business(`Total deploy size is too large. Maximum allowed is ${t.maxTotalSize/(1024*1024)}MB.`)}function se(i){return oe(i,{skipEmptyCheck:!0}),i.forEach(e=>{e.path&&(e.path=e.path.replace(/\\/g,"/"))}),i}async function xe(i,e={}){if(!Array.isArray(i)||!i.every(s=>typeof s=="string"))throw d.business("Invalid input type for Node.js environment. Expected string[] file paths.");if(i.length===0)throw d.business("No files to deploy.");let t={};if(e.stripCommonPrefix!==void 0&&(t.stripCommonPrefix=e.stripCommonPrefix,e.stripCommonPrefix)){let s=me("path"),n=typeof process<"u"?process.cwd():"/",a=i.map(l=>s.resolve(n,l)),{findCommonParent:g}=await import("./path-6I7MXXVI.js"),m=g(a);m&&(t.basePath=m)}let o=await z(i,t);return se(o)}async function Ae(i,e={}){let t;if(i instanceof HTMLInputElement){if(!i.files)throw d.business("No files selected in HTMLInputElement");t=Array.from(i.files)}else if(typeof i=="object"&&i!==null&&typeof i.length=="number"&&typeof i.item=="function")t=Array.from(i);else if(Array.isArray(i)){if(i.length>0&&typeof i[0]=="string")throw d.business("Invalid input type for browser environment. Expected File[], FileList, or HTMLInputElement.");t=i}else throw d.business("Invalid input type for browser environment. Expected File[], FileList, or HTMLInputElement.");t=t.filter(n=>n.size===0?(console.warn(`Skipping empty file: ${n.name}`),!1):!0),oe(t);let o={};if(e.stripCommonPrefix!==void 0&&(o.stripCommonPrefix=e.stripCommonPrefix,e.stripCommonPrefix)){let{findBrowserCommonParentDirectory:n}=await import("./browser-files-4HSSOKZU.js"),a=n(i instanceof HTMLInputElement?i.files:i);a&&(o.basePath=a)}let s=await U(t,o);return se(s)}async function ne(i,e={}){let t=y();if(t==="node"){if(!Array.isArray(i)||!i.every(o=>typeof o=="string"))throw d.business("Invalid input type for Node.js environment. Expected string[] file paths.");return xe(i,e)}else if(t==="browser"){if(!(i instanceof HTMLInputElement||Array.isArray(i)||typeof FileList<"u"&&i instanceof FileList))throw d.business("In browser, input must be FileList, File[], or HTMLInputElement.");return Ae(i,e)}else throw d.business("Unsupported execution environment.")}function re(i,e,t){return{create:async(o,s={})=>{e&&await e();let n=t?J(s,t):s,a=await ne(o,n);return await i.deploy(a,n)},list:async()=>i.listDeployments(),remove:async o=>{await i.removeDeployment(o)},get:async o=>i.getDeployment(o)}}function ae(i){return{set:async(e,t)=>i.setAlias(e,t),get:async e=>i.getAlias(e),list:async()=>i.listAliases(),remove:async e=>{await i.removeAlias(e)}}}function pe(i){return{get:async()=>i.getAccount()}}function le(i){return{create:async()=>i.createApiKey()}}import{ShipError as ut,ShipErrorType as yt}from"@shipstatic/types";var _=class{constructor(e={}){this.configInitialized=!1;if(this.clientOptions=e,this.environment=y(),this.environment!=="node"&&this.environment!=="browser")throw De.business("Unsupported execution environment.");let t=G(),o=V(e,t);this.http=new O({...e,...o})}async initializeConfig(){if(this.configInitialized)return;let e=await this.http.getConfig();ee(e),this.configInitialized=!0}async ping(){return this.http.ping()}get deployments(){return this._deployments||(this._deployments=re(this.http,()=>this.initializeConfig(),this.clientOptions)),this._deployments}get aliases(){return this._aliases||(this._aliases=ae(this.http)),this._aliases}get account(){return this._account||(this._account=pe(this.http)),this._account}get keys(){return this._keys||(this._keys=le(this.http)),this._keys}async deploy(e,t){return this.deployments.create(e,t)}},ct=_;export{_ as Ship,ut as ShipError,yt as ShipErrorType,fe as __setTestEnvironment,ct as default,ue as findBrowserCommonParentDirectory,U as processFilesForBrowser,z as processFilesForNode};
|
|
1
|
+
var re=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var le=Object.prototype.hasOwnProperty;var _=(i,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ae(e))!le.call(i,n)&&n!==t&&re(i,n,{get:()=>e[n],enumerable:!(o=se(e,n))||o.enumerable});return i},K=(i,e,t)=>(_(i,e,"default"),t&&_(t,e,"default"));var U=null;function pe(i){U=i}function ce(){return typeof process<"u"&&process.versions&&process.versions.node?"node":typeof window<"u"||typeof self<"u"?"browser":"unknown"}function u(){return U||ce()}import{z as C}from"zod";var P={};K(P,Ee);import*as Ee from"@shipstatic/types";var A="https://api.shipstatic.com";var j="ship",me=C.object({apiUrl:C.string().url().optional(),apiKey:C.string().optional()}).strict();function H(i){try{return me.parse(i)}catch(e){if(e instanceof C.ZodError){let t=e.issues[0],o=t.path.length>0?` at ${t.path.join(".")}`:"";throw P.ShipError.config(`Configuration validation failed${o}: ${t.message}`)}throw P.ShipError.config("Configuration validation failed")}}async function fe(){try{if(u()!=="node")return{};let{cosmiconfigSync:i}=await import("cosmiconfig"),t=i(j,{searchPlaces:[`.${j}rc`,"package.json"]}).search();if(t&&!t.isEmpty&&t.config)return H(t.config)}catch(i){if(i instanceof P.ShipError)throw i}return{}}async function q(){if(u()!=="node")return{};let i={apiUrl:process.env.SHIP_API_URL,apiKey:process.env.SHIP_API_KEY},e=await fe(),t={apiUrl:i.apiUrl??e.apiUrl,apiKey:i.apiKey??e.apiKey};return H(t)}function L(i={},e={}){let t={apiUrl:i.apiUrl||e.apiUrl||A,apiKey:i.apiKey!==void 0?i.apiKey:e.apiKey};return t.apiKey!==void 0?{apiUrl:t.apiUrl,apiKey:t.apiKey}:{apiUrl:t.apiUrl}}function G(i={},e){let t={...i};return t.onProgress===void 0&&e.onProgress!==void 0&&(t.onProgress=e.onProgress),t.onProgressStats===void 0&&e.onProgressStats!==void 0&&(t.onProgressStats=e.onProgressStats),t.maxConcurrency===void 0&&e.maxConcurrentDeploys!==void 0&&(t.maxConcurrency=e.maxConcurrentDeploys),t.timeout===void 0&&e.timeout!==void 0&&(t.timeout=e.timeout),t.apiKey===void 0&&e.apiKey!==void 0&&(t.apiKey=e.apiKey),t.apiUrl===void 0&&e.apiUrl!==void 0&&(t.apiUrl=e.apiUrl),t}import*as I from"mime-types";import{ShipError as y}from"@shipstatic/types";var E="/deployments",ue="/ping",R="/aliases",ye="/config",he="/account";function de(i){return typeof i=="string"?I.lookup(i)||"application/octet-stream":I.lookup(i.name)||i.type||"application/octet-stream"}async function ge(i){let e=[];for await(let t of i)e.push(t);return e}var b=class{constructor(e){this.apiUrl=e.apiUrl||A,this.apiKey=e.apiKey??""}#n(e={}){let t={...e};return this.apiKey&&(t.Authorization=`Bearer ${this.apiKey}`),t}async#i(e,t={},o){let n=this.#n(t.headers),r={...t,headers:n,credentials:u()==="browser"?"include":"same-origin"};try{return await fetch(e,r)}catch(a){throw this.#t(a,o),a}}async#e(e,t={},o){try{let n=await this.#i(e,t,o);return n.ok||await this.#o(n,o),n.headers.get("Content-Length")==="0"||n.status===204?void 0:await n.json()}catch(n){throw n instanceof y||this.#t(n,o),n}}async ping(){return(await this.#e(`${this.apiUrl}${ue}`,{method:"GET"},"Ping"))?.success||!1}async getConfig(){return await this.#e(`${this.apiUrl}${ye}`,{method:"GET"},"Config")}async deploy(e,t={}){this.#r(e);let{apiUrl:o=this.apiUrl,signal:n}=t;try{let{requestBody:r,requestHeaders:a}=await this.#s(e),c={method:"POST",body:r,headers:a,signal:n||null},m=await this.#i(`${o}${E}`,c,"Deploy");return m.ok||await this.#o(m,"Deploy"),await m.json()}catch(r){throw r instanceof y?r:(this.#t(r,"Deploy"),y.business("An unexpected error occurred and was not handled."))}}#r(e){if(!e.length)throw y.business("No files to deploy.");for(let t of e)if(!t.md5)throw y.file(`MD5 checksum missing for file: ${t.path}`,t.path)}async#s(e){let t,o={};if(u()==="browser")t=this.#a(e);else if(u()==="node"){let{body:n,headers:r}=await this.#l(e);t=n,o=r}else throw y.business("Unknown or unsupported execution environment");return{requestBody:t,requestHeaders:o}}#a(e){let t=new FormData,o=[];for(let n=0;n<e.length;n++){let r=e[n],a;if(r.content instanceof File||r.content instanceof Blob)a=r.content;else throw y.file(`Unsupported file.content type for browser FormData: ${r.path}`,r.path);let c=de(a instanceof File?a:r.path),m=new File([a],r.path,{type:c});t.append("files[]",m),o.push(r.md5)}return t.append("checksums",JSON.stringify(o)),t}async#l(e){let{FormData:t,File:o}=await import("formdata-node"),{FormDataEncoder:n}=await import("form-data-encoder"),r=await import("path"),a=new t,c=[];for(let g=0;g<e.length;g++){let f=e[g],x=I.lookup(f.path)||"application/octet-stream",w;if(Buffer.isBuffer(f.content))w=new o([f.content],r.basename(f.path),{type:x});else if(typeof Blob<"u"&&f.content instanceof Blob)w=new o([f.content],r.basename(f.path),{type:x});else throw y.file(`Unsupported file.content type for Node.js FormData: ${f.path}`,f.path);let ne=f.path.startsWith("/")?f.path:"/"+f.path;a.append("files[]",w,ne),c.push(f.md5)}a.append("checksums",JSON.stringify(c));let m=new n(a),l=await ge(m.encode()),s=Buffer.concat(l.map(g=>Buffer.from(g))),p={"Content-Type":m.contentType,"Content-Length":Buffer.byteLength(s).toString()};return{body:s,headers:p}}async#o(e,t){let o={};try{let n=e.headers.get("content-type");n&&n.includes("application/json")?o=await e.json():o={message:await e.text()}}catch{o={message:"Failed to parse error response"}}if(o.error||o.code||o.message){let n=o.message||o.error||`${t} failed due to API error`;throw y.api(n,e.status,o.code,o)}throw y.api(`${t} failed due to API error`,e.status,void 0,o)}#t(e,t){throw e.name==="AbortError"?y.cancelled(`${t} operation was cancelled.`):e instanceof TypeError&&e.message.includes("fetch")?y.network(`${t} failed due to network error: ${e.message}`,e):e instanceof y?e:y.business(`An unexpected error occurred during ${t}: ${e.message||"Unknown error"}`)}async listDeployments(){return await this.#e(`${this.apiUrl}${E}`,{method:"GET"},"List Deployments")}async getDeployment(e){return await this.#e(`${this.apiUrl}${E}/${e}`,{method:"GET"},"Get Deployment")}async removeDeployment(e){await this.#e(`${this.apiUrl}${E}/${e}`,{method:"DELETE"},"Remove Deployment")}async setAlias(e,t){return await this.#e(`${this.apiUrl}${R}/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({deploymentId:t})},"Set Alias")}async getAlias(e){return await this.#e(`${this.apiUrl}${R}/${encodeURIComponent(e)}`,{method:"GET"},"Get Alias")}async listAliases(){return await this.#e(`${this.apiUrl}${R}`,{method:"GET"},"List Aliases")}async removeAlias(e){await this.#e(`${this.apiUrl}${R}/${encodeURIComponent(e)}`,{method:"DELETE"},"Remove Alias")}async getAccount(){return await this.#e(`${this.apiUrl}${he}`,{method:"GET"},"Get Account")}async createApiKey(){return await this.#e(`${this.apiUrl}/key`,{method:"POST"},"Create API Key")}};import{ShipError as xe}from"@shipstatic/types";import{ShipError as we}from"@shipstatic/types";var z=null;function J(i){z=i}function v(){if(z===null)throw we.config("Platform configuration not initialized. The SDK must fetch configuration from the API before performing operations.");return z}import{ShipError as d}from"@shipstatic/types";import{ShipError as D}from"@shipstatic/types";async function Fe(i){let e=(await import("spark-md5")).default;return new Promise((t,o)=>{let r=Math.ceil(i.size/2097152),a=0,c=new e.ArrayBuffer,m=new FileReader,l=()=>{let s=a*2097152,p=Math.min(s+2097152,i.size);m.readAsArrayBuffer(i.slice(s,p))};m.onload=s=>{let p=s.target?.result;if(!p){o(D.business("Failed to read file chunk"));return}c.append(p),a++,a<r?l():t({md5:c.end()})},m.onerror=()=>{o(D.business("Failed to calculate MD5: FileReader error"))},l()})}async function Pe(i){let e=await import("crypto");if(Buffer.isBuffer(i)){let o=e.createHash("md5");return o.update(i),{md5:o.digest("hex")}}let t=await import("fs");return new Promise((o,n)=>{let r=e.createHash("md5"),a=t.createReadStream(i);a.on("error",c=>n(D.business(`Failed to read file for MD5: ${c.message}`))),a.on("data",c=>r.update(c)),a.on("end",()=>o({md5:r.digest("hex")}))})}async function O(i){let e=u();if(e==="browser"){if(!(i instanceof Blob))throw D.business("Invalid input for browser MD5 calculation: Expected Blob or File.");return Fe(i)}if(e==="node"){if(!(Buffer.isBuffer(i)||typeof i=="string"))throw D.business("Invalid input for Node.js MD5 calculation: Expected Buffer or file path string.");return Pe(i)}throw D.business("Unknown or unsupported execution environment for MD5 calculation.")}import{isJunk as De}from"junk";var be=["__MACOSX",".Trashes",".fseventsd",".Spotlight-V100"];function T(i){return!i||i.length===0?[]:i.filter(e=>{if(!e)return!1;let t=e.replace(/\\/g,"/").split("/").filter(Boolean);if(t.length===0)return!0;let o=t[t.length-1];if(De(o))return!1;let n=t.slice(0,-1);for(let r of n)if(be.some(a=>r.toLowerCase()===a.toLowerCase()))return!1;return!0})}import{ShipError as S}from"@shipstatic/types";function $(i){if(!i||i.length===0)return"";let e=i.filter(r=>r&&typeof r=="string").map(r=>r.replace(/\\/g,"/"));if(e.length===0)return"";if(e.length===1)return e[0];let t=e.map(r=>r.split("/").filter(Boolean)),o=[],n=Math.min(...t.map(r=>r.length));for(let r=0;r<n;r++){let a=t[0][r];if(t.every(c=>c[r]===a))o.push(a);else break}return o.join("/")}function B(i){return i.replace(/\\/g,"/").replace(/^\/+/,"")}import*as F from"fs";import*as h from"path";function W(i){let e=[];try{let t=F.readdirSync(i);for(let o of t){let n=h.join(i,o),r=F.statSync(n);if(r.isDirectory()){let a=W(n);e.push(...a)}else r.isFile()&&e.push(n)}}catch(t){console.error(`Error reading directory ${i}:`,t)}return e}async function V(i,e={}){let t=h.resolve(i),n=(()=>{let s=F.statSync(t);return s.isFile()?[t]:s.isDirectory()?W(t):[]})().filter(s=>{let p=h.basename(s);return T([p]).length>0}),r=F.statSync(t),a;if(e.preserveDirs)a=r.isDirectory()?t:h.dirname(t);else{let s=n.map(p=>h.dirname(p));a=$(s)}let c=[],m=0;for(let s of n)try{let p=F.statSync(s);if(p.size===0){console.warn(`Skipping empty file: ${s}`);continue}let g=v();if(p.size>g.maxFileSize)throw S.business(`File ${s} is too large. Maximum allowed size is ${g.maxFileSize/(1024*1024)}MB.`);if(m+=p.size,m>g.maxTotalSize)throw S.business(`Total deploy size is too large. Maximum allowed is ${g.maxTotalSize/(1024*1024)}MB.`);let f=F.readFileSync(s),{md5:x}=await O(f),w=h.relative(a,s).replace(/\\/g,"/");(w.includes("..")||w.includes("\0"))&&(w=h.basename(s)),w||(w=h.basename(s)),c.push({path:w,content:f,size:f.length,md5:x})}catch(p){if(p instanceof S&&p.isClientError&&p.isClientError())throw p;console.error(`Could not process file ${s}:`,p)}let l=v();if(c.length>l.maxFilesCount)throw S.business(`Too many files to deploy. Maximum allowed is ${l.maxFilesCount} files.`);return c}async function k(i,e={}){if(u()!=="node")throw S.business("processFilesForNode can only be called in a Node.js environment.");if(i.length>1){let t=[];for(let o of i){let n=await V(o,e);t.push(...n)}return t}return await V(i[0],e)}import{ShipError as Y}from"@shipstatic/types";async function N(i,e={}){if(u()!=="browser")throw Y.business("processFilesForBrowser can only be called in a browser environment.");let t=Array.isArray(i)?i:Array.from(i),o="";if(!e.preserveDirs){let l=t.map(s=>s.webkitRelativePath||s.name).filter(s=>s).map(s=>s.includes("/")?s.substring(0,s.lastIndexOf("/")):"");o=$(l)}let n=[];for(let l of t){let s=l.webkitRelativePath||l.name;if(o&&!e.preserveDirs){s=B(s);let p=o.endsWith("/")?o:`${o}/`;s.startsWith(p)?s=s.substring(p.length):s===o&&(s="")}if(s=B(s),s.includes("..")||s.includes("\0"))throw Y.business(`Security error: Unsafe file path "${s}" for file: ${l.name}`);s||(s=l.name),n.push({file:l,relativePath:s})}let r=n.map(l=>l.relativePath),a=T(r),c=new Set(a),m=[];for(let l of n){if(!c.has(l.relativePath)||l.file.size===0)continue;let{md5:s}=await O(l.file);m.push({content:l.file,path:l.relativePath,size:l.file.size,md5:s})}return m}function X(i,e={}){let t=v();if(!e.skipEmptyCheck&&i.length===0)throw d.business("No files to deploy.");if(i.length>t.maxFilesCount)throw d.business(`Too many files to deploy. Maximum allowed is ${t.maxFilesCount}.`);let o=0;for(let n of i){if(n.size>t.maxFileSize)throw d.business(`File ${n.name} is too large. Maximum allowed size is ${t.maxFileSize/(1024*1024)}MB.`);o+=n.size}if(o>t.maxTotalSize)throw d.business(`Total deploy size is too large. Maximum allowed is ${t.maxTotalSize/(1024*1024)}MB.`)}function Z(i){return X(i,{skipEmptyCheck:!0}),i.forEach(e=>{e.path&&(e.path=e.path.replace(/\\/g,"/"))}),i}async function ve(i,e={}){if(!Array.isArray(i)||!i.every(o=>typeof o=="string"))throw d.business("Invalid input type for Node.js environment. Expected string[] file paths.");if(i.length===0)throw d.business("No files to deploy.");let t=await k(i,e);return Z(t)}async function Se(i,e={}){let t;if(i instanceof HTMLInputElement){if(!i.files)throw d.business("No files selected in HTMLInputElement");t=Array.from(i.files)}else if(typeof i=="object"&&i!==null&&typeof i.length=="number"&&typeof i.item=="function")t=Array.from(i);else if(Array.isArray(i)){if(i.length>0&&typeof i[0]=="string")throw d.business("Invalid input type for browser environment. Expected File[], FileList, or HTMLInputElement.");t=i}else throw d.business("Invalid input type for browser environment. Expected File[], FileList, or HTMLInputElement.");t=t.filter(n=>n.size===0?(console.warn(`Skipping empty file: ${n.name}`),!1):!0),X(t);let o=await N(t,e);return Z(o)}async function Q(i,e={}){let t=u();if(t==="node"){if(!Array.isArray(i)||!i.every(o=>typeof o=="string"))throw d.business("Invalid input type for Node.js environment. Expected string[] file paths.");return ve(i,e)}else if(t==="browser"){if(!(i instanceof HTMLInputElement||Array.isArray(i)||typeof FileList<"u"&&i instanceof FileList))throw d.business("In browser, input must be FileList, File[], or HTMLInputElement.");return Se(i,e)}else throw d.business("Unsupported execution environment.")}function ee(i,e,t){return{create:async(o,n={})=>{e&&await e();let r=t?G(n,t):n,a=await Q(o,r);return await i.deploy(a,r)},list:async()=>i.listDeployments(),remove:async o=>{await i.removeDeployment(o)},get:async o=>i.getDeployment(o)}}function te(i){return{set:async(e,t)=>i.setAlias(e,t),get:async e=>i.getAlias(e),list:async()=>i.listAliases(),remove:async e=>{await i.removeAlias(e)}}}function ie(i){return{get:async()=>i.getAccount()}}function oe(i){return{create:async()=>i.createApiKey()}}import{ShipError as At,ShipErrorType as Ct}from"@shipstatic/types";var M=class{constructor(e={}){this.configInitialized=!1;this.configLoaded=!1;if(this.clientOptions=e,this.environment=u(),this.environment!=="node"&&this.environment!=="browser")throw xe.business("Unsupported execution environment.");let t=L(e,{});this.http=new b({...e,...t})}async initializeConfig(){if(this.configInitialized)return;if(!this.configLoaded){let t=await q(),o=L(this.clientOptions,t);this.http=new b({...this.clientOptions,...o}),this.configLoaded=!0}let e=await this.http.getConfig();J(e),this.configInitialized=!0}async ping(){return await this.initializeConfig(),this.http.ping()}get deployments(){return this._deployments||(this._deployments=ee(this.http,()=>this.initializeConfig(),this.clientOptions)),this._deployments}get aliases(){return this._aliases||(this._aliases=te(this.http)),this._aliases}get account(){return this._account||(this._account=ie(this.http)),this._account}get keys(){return this._keys||(this._keys=oe(this.http)),this._keys}async deploy(e,t){return this.deployments.create(e,t)}},vt=M;export{M as Ship,At as ShipError,Ct as ShipErrorType,pe as __setTestEnvironment,vt as default,N as processFilesForBrowser,k as processFilesForNode};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|