wirecopy 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Wirecopy contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # Wirecopy CLI
2
+
3
+ Publish files and working web artifacts from terminals, coding agents and CI.
4
+
5
+ ```bash
6
+ npx wirecopy site ./dist
7
+ npx wirecopy publish ./report.pdf
8
+ ```
9
+
10
+ Install the `wirecopy` command globally when you use it regularly:
11
+
12
+ ```bash
13
+ npm install --global wirecopy
14
+ wirecopy configure
15
+ wirecopy site ./dist
16
+ ```
17
+
18
+ Create a revocable device token on the Devices page at
19
+ <https://wirecopy.app/device_tokens>. `wirecopy configure` prompts for it
20
+ without echoing the token or placing it in shell history. The token is stored
21
+ in a user-only configuration file. For CI, provide `WIRECOPY_TOKEN` through
22
+ the environment instead:
23
+
24
+ ```bash
25
+ WIRECOPY_TOKEN='wc_live_...' wirecopy site ./dist --json
26
+ ```
27
+
28
+ `WIRECOPY_SERVER` overrides the default `https://wirecopy.app` API host.
29
+ `WIRECOPY_EXPIRES_IN` sets the default retention in seconds.
30
+
31
+ ## Commands
32
+
33
+ ```text
34
+ wirecopy configure [--token wc_live_...] [--server URL] [--expires seconds]
35
+ wirecopy logout
36
+ wirecopy publish <path> [more paths] [--expires seconds] [--format raw|markdown|html|json]
37
+ wirecopy site <index.html|site.zip|folder> [--storage managed|byos] [--expires seconds] [--json]
38
+ wirecopy links [--json]
39
+ wirecopy links revoke <id>
40
+ ```
41
+
42
+ File bytes upload directly to the object-storage grant returned by Wirecopy.
43
+ Site folders are packaged locally as deterministic, uncompressed ZIP archives
44
+ before publication.
45
+
46
+ Human-readable progress goes to stderr. Links and JSON results go to stdout so
47
+ the commands compose safely with scripts.
48
+
49
+ ## Development
50
+
51
+ ```bash
52
+ npm install
53
+ npm test
54
+ npm pack
55
+ ```
56
+
57
+ Requires Node.js 20.11 or newer.
package/dist/api.d.ts ADDED
@@ -0,0 +1,60 @@
1
+ import type { PreparedInput } from "./input.js";
2
+ export interface UploadGrant {
3
+ url: string;
4
+ method: string;
5
+ headers: Record<string, string>;
6
+ }
7
+ export interface UploadIntent {
8
+ id: string;
9
+ state: string;
10
+ filename: string;
11
+ content_type: string;
12
+ byte_size: number;
13
+ expires_at: string;
14
+ error?: {
15
+ code: string;
16
+ message?: string;
17
+ } | null;
18
+ link?: {
19
+ url: string;
20
+ expires_at: string;
21
+ } | null;
22
+ upload?: UploadGrant | null;
23
+ }
24
+ export interface ManagedLink {
25
+ id: number;
26
+ url: string;
27
+ filename: string;
28
+ byte_size: number;
29
+ content_type: string;
30
+ access_count: number;
31
+ last_accessed_at: string | null;
32
+ expires_at: string;
33
+ revoked_at: string | null;
34
+ created_at: string;
35
+ }
36
+ export interface PublishedSite {
37
+ id: number;
38
+ state: string;
39
+ name: string;
40
+ url: string;
41
+ storage: "managed" | "byos";
42
+ byte_size: number;
43
+ file_count: number;
44
+ expires_at: string;
45
+ }
46
+ export declare class WirecopyApi {
47
+ private readonly server;
48
+ private readonly token;
49
+ constructor(server: string, token: string);
50
+ createIntent(input: PreparedInput, expiresIn: number): Promise<UploadIntent>;
51
+ upload(input: PreparedInput, grant: UploadGrant): Promise<void>;
52
+ completeIntent(id: string): Promise<UploadIntent>;
53
+ intent(id: string): Promise<UploadIntent>;
54
+ links(): Promise<ManagedLink[]>;
55
+ revokeLink(id: number): Promise<void>;
56
+ publishSite(input: PreparedInput, expiresIn: number, storage?: "managed" | "byos"): Promise<PublishedSite>;
57
+ private request;
58
+ }
59
+ export declare function waitForAvailable(api: WirecopyApi, initial: UploadIntent): Promise<UploadIntent>;
60
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAA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CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAMD,qBAAa,WAAW;IAEpB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,KAAK;gBADL,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM;IAG1B,YAAY,CAAC,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAe5E,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAuB/D,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAOjD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAIzC,KAAK,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAK/B,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrC,WAAW,CACf,KAAK,EAAE,aAAa,EACpB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,SAAS,GAAG,MAAM,GAC3B,OAAO,CAAC,aAAa,CAAC;YAsCX,OAAO;CAoCtB;AAED,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,YAAY,CAAC,CAqBvB"}
package/dist/api.js ADDED
@@ -0,0 +1,184 @@
1
+ import { createReadStream } from "node:fs";
2
+ import { appendFile, mkdtemp, open, rm, stat } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { basename, join } from "node:path";
5
+ import { Readable } from "node:stream";
6
+ import { isLoopback } from "./config.js";
7
+ import { ApiError } from "./errors.js";
8
+ export class WirecopyApi {
9
+ server;
10
+ token;
11
+ constructor(server, token) {
12
+ this.server = server;
13
+ this.token = token;
14
+ }
15
+ async createIntent(input, expiresIn) {
16
+ return this.request("/api/v1/upload_intents", {
17
+ method: "POST",
18
+ body: JSON.stringify({
19
+ upload: {
20
+ mode: "file",
21
+ filename: input.filename,
22
+ content_type: input.contentType,
23
+ byte_size: input.byteSize,
24
+ expires_in: expiresIn,
25
+ },
26
+ }),
27
+ });
28
+ }
29
+ async upload(input, grant) {
30
+ validateUploadGrant(grant);
31
+ const response = await networkRequest(grant.url, {
32
+ method: grant.method,
33
+ headers: grant.headers,
34
+ body: Readable.toWeb(createReadStream(input.path)),
35
+ duplex: "half",
36
+ redirect: "error",
37
+ signal: AbortSignal.timeout(10 * 60 * 1000),
38
+ }, "Object storage upload failed.");
39
+ if (!response.ok) {
40
+ throw new ApiError("upload_rejected", `Object storage rejected the upload (HTTP ${response.status}).`, response.status);
41
+ }
42
+ }
43
+ async completeIntent(id) {
44
+ return this.request(`/api/v1/upload_intents/${encodeURIComponent(id)}/complete`, {
45
+ method: "POST",
46
+ body: "{}",
47
+ });
48
+ }
49
+ async intent(id) {
50
+ return this.request(`/api/v1/upload_intents/${encodeURIComponent(id)}`);
51
+ }
52
+ async links() {
53
+ const response = await this.request("/api/v1/links");
54
+ return response.links;
55
+ }
56
+ async revokeLink(id) {
57
+ await this.request(`/api/v1/links/${id}`, { method: "DELETE" });
58
+ }
59
+ async publishSite(input, expiresIn, storage) {
60
+ const boundary = `wirecopy-${crypto.randomUUID()}`;
61
+ const temporaryDirectory = await mkdtemp(join(tmpdir(), "wirecopy-request-"));
62
+ const bodyPath = join(temporaryDirectory, "multipart");
63
+ try {
64
+ await appendFile(bodyPath, part(boundary, "site[mode]", "site"));
65
+ await appendFile(bodyPath, part(boundary, "site[expires_in]", String(expiresIn)));
66
+ if (storage) {
67
+ await appendFile(bodyPath, part(boundary, "site[storage]", storage));
68
+ }
69
+ await appendFile(bodyPath, `--${boundary}\r\nContent-Disposition: form-data; name="site[archive]"; filename="${escapeFilename(input.filename)}"\r\nContent-Type: ${input.contentType}\r\n\r\n`);
70
+ const output = await open(bodyPath, "a");
71
+ try {
72
+ for await (const chunk of createReadStream(input.path)) {
73
+ await output.write(chunk);
74
+ }
75
+ }
76
+ finally {
77
+ await output.close();
78
+ }
79
+ await appendFile(bodyPath, `\r\n--${boundary}--\r\n`);
80
+ const size = (await stat(bodyPath)).size;
81
+ return await this.request("/api/v1/sites", {
82
+ method: "POST",
83
+ headers: {
84
+ "Content-Type": `multipart/form-data; boundary=${boundary}`,
85
+ "Content-Length": String(size),
86
+ },
87
+ body: Readable.toWeb(createReadStream(bodyPath)),
88
+ duplex: "half",
89
+ });
90
+ }
91
+ finally {
92
+ await rm(temporaryDirectory, { recursive: true, force: true });
93
+ }
94
+ }
95
+ async request(path, init = {}) {
96
+ const headers = new Headers(init.headers);
97
+ headers.set("Accept", "application/json");
98
+ headers.set("Authorization", `Bearer ${this.token}`);
99
+ if (typeof init.body === "string" && !headers.has("Content-Type")) {
100
+ headers.set("Content-Type", "application/json");
101
+ }
102
+ const response = await networkRequest(new URL(path, this.server), {
103
+ ...init,
104
+ headers,
105
+ redirect: "error",
106
+ signal: init.signal ?? AbortSignal.timeout(path === "/api/v1/sites" ? 10 * 60 * 1000 : 30_000),
107
+ }, "Could not reach the Wirecopy service.");
108
+ if (response.status === 204) {
109
+ return undefined;
110
+ }
111
+ const body = await response.text();
112
+ if (!response.ok) {
113
+ const detail = parseError(body);
114
+ throw new ApiError(detail.code ?? `http_${response.status}`, detail.message ?? `Wirecopy request failed (HTTP ${response.status}).`, response.status);
115
+ }
116
+ try {
117
+ return JSON.parse(body);
118
+ }
119
+ catch {
120
+ throw new ApiError("invalid_response", "The Wirecopy service returned an invalid response.");
121
+ }
122
+ }
123
+ }
124
+ export async function waitForAvailable(api, initial) {
125
+ let intent = initial;
126
+ if (intent.state === "quarantined") {
127
+ for (let attempt = 0; attempt < 30; attempt += 1) {
128
+ await new Promise((resolve) => setTimeout(resolve, 500 + attempt * 50));
129
+ intent = await api.intent(intent.id);
130
+ if (["available", "rejected"].includes(intent.state)) {
131
+ break;
132
+ }
133
+ }
134
+ }
135
+ if (intent.state !== "available" || !intent.link) {
136
+ if (intent.error) {
137
+ throw new ApiError(intent.error.code, intent.error.message ?? intent.error.code);
138
+ }
139
+ throw new ApiError("scan_timeout", "The safety check is taking longer than expected. The file remains quarantined.");
140
+ }
141
+ return intent;
142
+ }
143
+ function part(boundary, name, value) {
144
+ return `--${boundary}\r\nContent-Disposition: form-data; name="${name}"\r\n\r\n${value}\r\n`;
145
+ }
146
+ function escapeFilename(value) {
147
+ return basename(value).replaceAll('"', "_").replaceAll("\r", "_").replaceAll("\n", "_");
148
+ }
149
+ function parseError(body) {
150
+ try {
151
+ const parsed = JSON.parse(body);
152
+ return parsed.error ?? {};
153
+ }
154
+ catch {
155
+ return {};
156
+ }
157
+ }
158
+ function validateUploadGrant(grant) {
159
+ if (grant.method.toUpperCase() !== "PUT") {
160
+ throw new ApiError("invalid_upload_grant", "The Wirecopy service returned an unsupported upload method.");
161
+ }
162
+ let url;
163
+ try {
164
+ url = new URL(grant.url);
165
+ }
166
+ catch {
167
+ throw new ApiError("invalid_upload_grant", "The Wirecopy service returned an invalid upload URL.");
168
+ }
169
+ if (url.protocol !== "https:" && !(url.protocol === "http:" && isLoopback(url.hostname))) {
170
+ throw new ApiError("invalid_upload_grant", "Wirecopy refused an insecure object-storage upload URL.");
171
+ }
172
+ }
173
+ async function networkRequest(input, init, failureMessage) {
174
+ try {
175
+ return await fetch(input, init);
176
+ }
177
+ catch (error) {
178
+ const reason = error instanceof Error && error.name === "TimeoutError"
179
+ ? " The request timed out."
180
+ : "";
181
+ throw new ApiError("network_error", `${failureMessage}${reason}`);
182
+ }
183
+ }
184
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,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AAI,CAAC,CAAC,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;QACzF,MAAM,IAAI,QAAQ,CAChB,sBAAsB,EACtB,yDAAyD,CAC1D,CAAC;IACJ,CAAC;AACH,CAAC;AAED,KAAK,UAAU,cAAc,CAC3B,KAAmB,EACnB,IAAiB,EACjB,cAAsB;IAEtB,IAAI,CAAC;QACH,OAAO,MAAM,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc;YACpE,CAAC,CAAC,yBAAyB;YAC3B,CAAC,CAAC,EAAE,CAAC;QACP,MAAM,IAAI,QAAQ,CAAC,eAAe,EAAE,GAAG,cAAc,GAAG,MAAM,EAAE,CAAC,CAAC;IACpE,CAAC;AACH,CAAC"}
@@ -0,0 +1,23 @@
1
+ export interface WirecopyConfig {
2
+ server: string;
3
+ token: string;
4
+ expiresIn: number;
5
+ }
6
+ interface StoredConfig {
7
+ server?: string;
8
+ token?: string;
9
+ expiresIn?: number;
10
+ }
11
+ export declare function configPath(environment?: NodeJS.ProcessEnv): string;
12
+ export declare function readStoredConfig(path?: string): Promise<StoredConfig>;
13
+ export declare function loadConfig(environment?: NodeJS.ProcessEnv): Promise<WirecopyConfig>;
14
+ export declare function saveConfig(input: {
15
+ token: string;
16
+ server?: string;
17
+ expiresIn?: number;
18
+ }): Promise<string>;
19
+ export declare function clearConfig(): Promise<void>;
20
+ export declare function parsePositiveInteger(value: string | number, label: string): number;
21
+ export declare function isLoopback(hostname: string): boolean;
22
+ export {};
23
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,YAAY;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAKD,wBAAgB,UAAU,CAAC,WAAW,oBAAc,GAAG,MAAM,CAW5D;AAED,wBAAsB,gBAAgB,CAAC,IAAI,SAAe,GAAG,OAAO,CAAC,YAAY,CAAC,CASjF;AAED,wBAAsB,UAAU,CAAC,WAAW,oBAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAiBnF;AAED,wBAAsB,UAAU,CAAC,KAAK,EAAE;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,OAAO,CAAC,MAAM,CAAC,CAgBlB;AAED,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAEjD;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAMlF;AA0BD,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAMpD"}
package/dist/config.js ADDED
@@ -0,0 +1,95 @@
1
+ import { chmod, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
2
+ import { homedir } from "node:os";
3
+ import { dirname, join } from "node:path";
4
+ import { isIP } from "node:net";
5
+ import { ConfigurationError } from "./errors.js";
6
+ const DEFAULT_SERVER = "https://wirecopy.app";
7
+ const DEFAULT_EXPIRES_IN = 86_400;
8
+ export function configPath(environment = process.env) {
9
+ if (environment.WIRECOPY_CONFIG_FILE) {
10
+ return environment.WIRECOPY_CONFIG_FILE;
11
+ }
12
+ if (environment.WIRECOPY_CONFIG_DIR) {
13
+ return join(environment.WIRECOPY_CONFIG_DIR, "config.json");
14
+ }
15
+ if (process.platform === "win32" && environment.APPDATA) {
16
+ return join(environment.APPDATA, "Wirecopy", "config.json");
17
+ }
18
+ return join(environment.XDG_CONFIG_HOME ?? join(homedir(), ".config"), "wirecopy", "config.json");
19
+ }
20
+ export async function readStoredConfig(path = configPath()) {
21
+ try {
22
+ return JSON.parse(await readFile(path, "utf8"));
23
+ }
24
+ catch (error) {
25
+ if (error.code === "ENOENT") {
26
+ return {};
27
+ }
28
+ throw new ConfigurationError(`Could not read Wirecopy configuration at ${path}.`);
29
+ }
30
+ }
31
+ export async function loadConfig(environment = process.env) {
32
+ const stored = await readStoredConfig(configPath(environment));
33
+ const server = environment.WIRECOPY_SERVER ?? stored.server ?? DEFAULT_SERVER;
34
+ const token = environment.WIRECOPY_TOKEN ?? stored.token;
35
+ const expiresIn = parsePositiveInteger(environment.WIRECOPY_EXPIRES_IN ?? stored.expiresIn ?? DEFAULT_EXPIRES_IN, "WIRECOPY_EXPIRES_IN");
36
+ if (!token) {
37
+ throw new ConfigurationError("No device token configured. Run 'wirecopy configure --token wc_live_…' or set WIRECOPY_TOKEN.");
38
+ }
39
+ validateServer(server);
40
+ return { server, token, expiresIn };
41
+ }
42
+ export async function saveConfig(input) {
43
+ const path = configPath();
44
+ const existing = await readStoredConfig(path);
45
+ const config = {
46
+ server: input.server ?? existing.server ?? DEFAULT_SERVER,
47
+ token: input.token,
48
+ expiresIn: input.expiresIn ?? existing.expiresIn ?? DEFAULT_EXPIRES_IN,
49
+ };
50
+ validateServer(config.server);
51
+ await mkdir(dirname(path), { recursive: true, mode: 0o700 });
52
+ const temporaryPath = `${path}.${process.pid}.tmp`;
53
+ await writeFile(temporaryPath, `${JSON.stringify(config, null, 2)}\n`, { mode: 0o600 });
54
+ await chmod(temporaryPath, 0o600);
55
+ await rename(temporaryPath, path);
56
+ return path;
57
+ }
58
+ export async function clearConfig() {
59
+ await rm(configPath(), { force: true });
60
+ }
61
+ export function parsePositiveInteger(value, label) {
62
+ const parsed = typeof value === "number" ? value : Number(value);
63
+ if (!Number.isSafeInteger(parsed) || parsed <= 0) {
64
+ throw new ConfigurationError(`${label} must be a positive integer.`);
65
+ }
66
+ return parsed;
67
+ }
68
+ function validateServer(value) {
69
+ try {
70
+ const url = new URL(value);
71
+ if (!["http:", "https:"].includes(url.protocol)) {
72
+ throw new Error();
73
+ }
74
+ if (url.username || url.password) {
75
+ throw new Error();
76
+ }
77
+ if (url.protocol === "http:" && !isLoopback(url.hostname)) {
78
+ throw new ConfigurationError("Wirecopy refuses to send a device token over plaintext HTTP. Use HTTPS or a loopback development server.");
79
+ }
80
+ }
81
+ catch {
82
+ if (value.startsWith("http://")) {
83
+ throw new ConfigurationError("Wirecopy refuses to send a device token over plaintext HTTP. Use HTTPS or a loopback development server.");
84
+ }
85
+ throw new ConfigurationError(`Invalid Wirecopy server URL: ${value}`);
86
+ }
87
+ }
88
+ export function isLoopback(hostname) {
89
+ const normalized = hostname.replace(/^\[|\]$/g, "").toLowerCase();
90
+ if (normalized === "localhost" || normalized === "::1") {
91
+ return true;
92
+ }
93
+ return isIP(normalized) === 4 && normalized.startsWith("127.");
94
+ }
95
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAcjD,MAAM,cAAc,GAAG,sBAAsB,CAAC;AAC9C,MAAM,kBAAkB,GAAG,MAAM,CAA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