@dropthis/cli 0.1.5
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 +171 -0
- package/dist/cli.cjs +1489 -0
- package/dist/cli.cjs.map +1 -0
- package/node_modules/@dropthis/node/README.md +90 -0
- package/node_modules/@dropthis/node/dist/index.cjs +1010 -0
- package/node_modules/@dropthis/node/dist/index.cjs.map +1 -0
- package/node_modules/@dropthis/node/dist/index.d.cts +408 -0
- package/node_modules/@dropthis/node/dist/index.d.ts +408 -0
- package/node_modules/@dropthis/node/dist/index.mjs +969 -0
- package/node_modules/@dropthis/node/dist/index.mjs.map +1 -0
- package/node_modules/@dropthis/node/package.json +55 -0
- package/node_modules/@nodelib/fs.scandir/LICENSE +21 -0
- package/node_modules/@nodelib/fs.scandir/README.md +171 -0
- package/node_modules/@nodelib/fs.scandir/out/adapters/fs.d.ts +20 -0
- package/node_modules/@nodelib/fs.scandir/out/adapters/fs.js +19 -0
- package/node_modules/@nodelib/fs.scandir/out/constants.d.ts +4 -0
- package/node_modules/@nodelib/fs.scandir/out/constants.js +17 -0
- package/node_modules/@nodelib/fs.scandir/out/index.d.ts +12 -0
- package/node_modules/@nodelib/fs.scandir/out/index.js +26 -0
- package/node_modules/@nodelib/fs.scandir/out/providers/async.d.ts +7 -0
- package/node_modules/@nodelib/fs.scandir/out/providers/async.js +104 -0
- package/node_modules/@nodelib/fs.scandir/out/providers/common.d.ts +1 -0
- package/node_modules/@nodelib/fs.scandir/out/providers/common.js +13 -0
- package/node_modules/@nodelib/fs.scandir/out/providers/sync.d.ts +5 -0
- package/node_modules/@nodelib/fs.scandir/out/providers/sync.js +54 -0
- package/node_modules/@nodelib/fs.scandir/out/settings.d.ts +20 -0
- package/node_modules/@nodelib/fs.scandir/out/settings.js +24 -0
- package/node_modules/@nodelib/fs.scandir/out/types/index.d.ts +20 -0
- package/node_modules/@nodelib/fs.scandir/out/types/index.js +2 -0
- package/node_modules/@nodelib/fs.scandir/out/utils/fs.d.ts +2 -0
- package/node_modules/@nodelib/fs.scandir/out/utils/fs.js +19 -0
- package/node_modules/@nodelib/fs.scandir/out/utils/index.d.ts +2 -0
- package/node_modules/@nodelib/fs.scandir/out/utils/index.js +5 -0
- package/node_modules/@nodelib/fs.scandir/package.json +44 -0
- package/node_modules/@nodelib/fs.stat/LICENSE +21 -0
- package/node_modules/@nodelib/fs.stat/README.md +126 -0
- package/node_modules/@nodelib/fs.stat/out/adapters/fs.d.ts +13 -0
- package/node_modules/@nodelib/fs.stat/out/adapters/fs.js +17 -0
- package/node_modules/@nodelib/fs.stat/out/index.d.ts +12 -0
- package/node_modules/@nodelib/fs.stat/out/index.js +26 -0
- package/node_modules/@nodelib/fs.stat/out/providers/async.d.ts +4 -0
- package/node_modules/@nodelib/fs.stat/out/providers/async.js +36 -0
- package/node_modules/@nodelib/fs.stat/out/providers/sync.d.ts +3 -0
- package/node_modules/@nodelib/fs.stat/out/providers/sync.js +23 -0
- package/node_modules/@nodelib/fs.stat/out/settings.d.ts +16 -0
- package/node_modules/@nodelib/fs.stat/out/settings.js +16 -0
- package/node_modules/@nodelib/fs.stat/out/types/index.d.ts +4 -0
- package/node_modules/@nodelib/fs.stat/out/types/index.js +2 -0
- package/node_modules/@nodelib/fs.stat/package.json +37 -0
- package/node_modules/@nodelib/fs.walk/LICENSE +21 -0
- package/node_modules/@nodelib/fs.walk/README.md +215 -0
- package/node_modules/@nodelib/fs.walk/out/index.d.ts +14 -0
- package/node_modules/@nodelib/fs.walk/out/index.js +34 -0
- package/node_modules/@nodelib/fs.walk/out/providers/async.d.ts +12 -0
- package/node_modules/@nodelib/fs.walk/out/providers/async.js +30 -0
- package/node_modules/@nodelib/fs.walk/out/providers/index.d.ts +4 -0
- package/node_modules/@nodelib/fs.walk/out/providers/index.js +9 -0
- package/node_modules/@nodelib/fs.walk/out/providers/stream.d.ts +12 -0
- package/node_modules/@nodelib/fs.walk/out/providers/stream.js +34 -0
- package/node_modules/@nodelib/fs.walk/out/providers/sync.d.ts +10 -0
- package/node_modules/@nodelib/fs.walk/out/providers/sync.js +14 -0
- package/node_modules/@nodelib/fs.walk/out/readers/async.d.ts +30 -0
- package/node_modules/@nodelib/fs.walk/out/readers/async.js +97 -0
- package/node_modules/@nodelib/fs.walk/out/readers/common.d.ts +7 -0
- package/node_modules/@nodelib/fs.walk/out/readers/common.js +31 -0
- package/node_modules/@nodelib/fs.walk/out/readers/reader.d.ts +6 -0
- package/node_modules/@nodelib/fs.walk/out/readers/reader.js +11 -0
- package/node_modules/@nodelib/fs.walk/out/readers/sync.d.ts +15 -0
- package/node_modules/@nodelib/fs.walk/out/readers/sync.js +59 -0
- package/node_modules/@nodelib/fs.walk/out/settings.d.ts +30 -0
- package/node_modules/@nodelib/fs.walk/out/settings.js +26 -0
- package/node_modules/@nodelib/fs.walk/out/types/index.d.ts +8 -0
- package/node_modules/@nodelib/fs.walk/out/types/index.js +2 -0
- package/node_modules/@nodelib/fs.walk/package.json +44 -0
- package/node_modules/braces/LICENSE +21 -0
- package/node_modules/braces/README.md +586 -0
- package/node_modules/braces/index.js +170 -0
- package/node_modules/braces/lib/compile.js +60 -0
- package/node_modules/braces/lib/constants.js +57 -0
- package/node_modules/braces/lib/expand.js +113 -0
- package/node_modules/braces/lib/parse.js +331 -0
- package/node_modules/braces/lib/stringify.js +32 -0
- package/node_modules/braces/lib/utils.js +122 -0
- package/node_modules/braces/package.json +77 -0
- package/node_modules/fast-glob/LICENSE +21 -0
- package/node_modules/fast-glob/README.md +830 -0
- package/node_modules/fast-glob/out/index.d.ts +40 -0
- package/node_modules/fast-glob/out/index.js +102 -0
- package/node_modules/fast-glob/out/managers/tasks.d.ts +22 -0
- package/node_modules/fast-glob/out/managers/tasks.js +110 -0
- package/node_modules/fast-glob/out/providers/async.d.ts +9 -0
- package/node_modules/fast-glob/out/providers/async.js +23 -0
- package/node_modules/fast-glob/out/providers/filters/deep.d.ts +16 -0
- package/node_modules/fast-glob/out/providers/filters/deep.js +62 -0
- package/node_modules/fast-glob/out/providers/filters/entry.d.ts +17 -0
- package/node_modules/fast-glob/out/providers/filters/entry.js +85 -0
- package/node_modules/fast-glob/out/providers/filters/error.d.ts +8 -0
- package/node_modules/fast-glob/out/providers/filters/error.js +15 -0
- package/node_modules/fast-glob/out/providers/matchers/matcher.d.ts +33 -0
- package/node_modules/fast-glob/out/providers/matchers/matcher.js +45 -0
- package/node_modules/fast-glob/out/providers/matchers/partial.d.ts +4 -0
- package/node_modules/fast-glob/out/providers/matchers/partial.js +38 -0
- package/node_modules/fast-glob/out/providers/provider.d.ts +19 -0
- package/node_modules/fast-glob/out/providers/provider.js +48 -0
- package/node_modules/fast-glob/out/providers/stream.d.ts +11 -0
- package/node_modules/fast-glob/out/providers/stream.js +31 -0
- package/node_modules/fast-glob/out/providers/sync.d.ts +9 -0
- package/node_modules/fast-glob/out/providers/sync.js +23 -0
- package/node_modules/fast-glob/out/providers/transformers/entry.d.ts +8 -0
- package/node_modules/fast-glob/out/providers/transformers/entry.js +26 -0
- package/node_modules/fast-glob/out/readers/async.d.ts +10 -0
- package/node_modules/fast-glob/out/readers/async.js +35 -0
- package/node_modules/fast-glob/out/readers/reader.d.ts +15 -0
- package/node_modules/fast-glob/out/readers/reader.js +33 -0
- package/node_modules/fast-glob/out/readers/stream.d.ts +14 -0
- package/node_modules/fast-glob/out/readers/stream.js +55 -0
- package/node_modules/fast-glob/out/readers/sync.d.ts +12 -0
- package/node_modules/fast-glob/out/readers/sync.js +43 -0
- package/node_modules/fast-glob/out/settings.d.ts +164 -0
- package/node_modules/fast-glob/out/settings.js +59 -0
- package/node_modules/fast-glob/out/types/index.d.ts +31 -0
- package/node_modules/fast-glob/out/types/index.js +2 -0
- package/node_modules/fast-glob/out/utils/array.d.ts +2 -0
- package/node_modules/fast-glob/out/utils/array.js +22 -0
- package/node_modules/fast-glob/out/utils/errno.d.ts +2 -0
- package/node_modules/fast-glob/out/utils/errno.js +7 -0
- package/node_modules/fast-glob/out/utils/fs.d.ts +4 -0
- package/node_modules/fast-glob/out/utils/fs.js +19 -0
- package/node_modules/fast-glob/out/utils/index.d.ts +8 -0
- package/node_modules/fast-glob/out/utils/index.js +17 -0
- package/node_modules/fast-glob/out/utils/path.d.ts +13 -0
- package/node_modules/fast-glob/out/utils/path.js +68 -0
- package/node_modules/fast-glob/out/utils/pattern.d.ts +49 -0
- package/node_modules/fast-glob/out/utils/pattern.js +206 -0
- package/node_modules/fast-glob/out/utils/stream.d.ts +4 -0
- package/node_modules/fast-glob/out/utils/stream.js +17 -0
- package/node_modules/fast-glob/out/utils/string.d.ts +2 -0
- package/node_modules/fast-glob/out/utils/string.js +11 -0
- package/node_modules/fast-glob/package.json +81 -0
- package/node_modules/fastq/LICENSE +13 -0
- package/node_modules/fastq/README.md +310 -0
- package/node_modules/fastq/SECURITY.md +15 -0
- package/node_modules/fastq/bench.js +66 -0
- package/node_modules/fastq/eslint.config.js +11 -0
- package/node_modules/fastq/example.js +14 -0
- package/node_modules/fastq/example.mjs +9 -0
- package/node_modules/fastq/index.d.ts +59 -0
- package/node_modules/fastq/package.json +49 -0
- package/node_modules/fastq/queue.js +346 -0
- package/node_modules/fastq/test/example.ts +83 -0
- package/node_modules/fastq/test/promise.js +325 -0
- package/node_modules/fastq/test/test.js +733 -0
- package/node_modules/fastq/test/tsconfig.json +11 -0
- package/node_modules/fill-range/LICENSE +21 -0
- package/node_modules/fill-range/README.md +237 -0
- package/node_modules/fill-range/index.js +248 -0
- package/node_modules/fill-range/package.json +74 -0
- package/node_modules/glob-parent/LICENSE +15 -0
- package/node_modules/glob-parent/README.md +137 -0
- package/node_modules/glob-parent/index.js +42 -0
- package/node_modules/glob-parent/package.json +48 -0
- package/node_modules/ignore/LICENSE-MIT +21 -0
- package/node_modules/ignore/README.md +452 -0
- package/node_modules/ignore/index.d.ts +81 -0
- package/node_modules/ignore/index.js +784 -0
- package/node_modules/ignore/legacy.js +681 -0
- package/node_modules/ignore/package.json +87 -0
- package/node_modules/is-extglob/LICENSE +21 -0
- package/node_modules/is-extglob/README.md +107 -0
- package/node_modules/is-extglob/index.js +20 -0
- package/node_modules/is-extglob/package.json +69 -0
- package/node_modules/is-glob/LICENSE +21 -0
- package/node_modules/is-glob/README.md +206 -0
- package/node_modules/is-glob/index.js +150 -0
- package/node_modules/is-glob/package.json +81 -0
- package/node_modules/is-number/LICENSE +21 -0
- package/node_modules/is-number/README.md +187 -0
- package/node_modules/is-number/index.js +18 -0
- package/node_modules/is-number/package.json +82 -0
- package/node_modules/merge2/LICENSE +21 -0
- package/node_modules/merge2/README.md +144 -0
- package/node_modules/merge2/index.js +144 -0
- package/node_modules/merge2/package.json +43 -0
- package/node_modules/micromatch/LICENSE +21 -0
- package/node_modules/micromatch/README.md +1024 -0
- package/node_modules/micromatch/index.js +474 -0
- package/node_modules/micromatch/package.json +119 -0
- package/node_modules/mime-db/HISTORY.md +541 -0
- package/node_modules/mime-db/LICENSE +23 -0
- package/node_modules/mime-db/README.md +109 -0
- package/node_modules/mime-db/db.json +9342 -0
- package/node_modules/mime-db/index.js +12 -0
- package/node_modules/mime-db/package.json +56 -0
- package/node_modules/mime-types/HISTORY.md +421 -0
- package/node_modules/mime-types/LICENSE +23 -0
- package/node_modules/mime-types/README.md +126 -0
- package/node_modules/mime-types/index.js +211 -0
- package/node_modules/mime-types/mimeScore.js +52 -0
- package/node_modules/mime-types/package.json +45 -0
- package/node_modules/picomatch/LICENSE +21 -0
- package/node_modules/picomatch/README.md +716 -0
- package/node_modules/picomatch/index.js +3 -0
- package/node_modules/picomatch/lib/constants.js +184 -0
- package/node_modules/picomatch/lib/parse.js +1392 -0
- package/node_modules/picomatch/lib/picomatch.js +342 -0
- package/node_modules/picomatch/lib/scan.js +391 -0
- package/node_modules/picomatch/lib/utils.js +64 -0
- package/node_modules/picomatch/package.json +81 -0
- package/node_modules/queue-microtask/LICENSE +20 -0
- package/node_modules/queue-microtask/README.md +90 -0
- package/node_modules/queue-microtask/index.d.ts +2 -0
- package/node_modules/queue-microtask/index.js +9 -0
- package/node_modules/queue-microtask/package.json +55 -0
- package/node_modules/reusify/.github/dependabot.yml +7 -0
- package/node_modules/reusify/.github/workflows/ci.yml +96 -0
- package/node_modules/reusify/LICENSE +22 -0
- package/node_modules/reusify/README.md +139 -0
- package/node_modules/reusify/SECURITY.md +15 -0
- package/node_modules/reusify/benchmarks/createNoCodeFunction.js +30 -0
- package/node_modules/reusify/benchmarks/fib.js +13 -0
- package/node_modules/reusify/benchmarks/reuseNoCodeFunction.js +38 -0
- package/node_modules/reusify/eslint.config.js +14 -0
- package/node_modules/reusify/package.json +50 -0
- package/node_modules/reusify/reusify.d.ts +14 -0
- package/node_modules/reusify/reusify.js +33 -0
- package/node_modules/reusify/test.js +66 -0
- package/node_modules/reusify/tsconfig.json +11 -0
- package/node_modules/run-parallel/LICENSE +20 -0
- package/node_modules/run-parallel/README.md +85 -0
- package/node_modules/run-parallel/index.js +51 -0
- package/node_modules/run-parallel/package.json +58 -0
- package/node_modules/to-regex-range/LICENSE +21 -0
- package/node_modules/to-regex-range/README.md +305 -0
- package/node_modules/to-regex-range/index.js +288 -0
- package/node_modules/to-regex-range/package.json +88 -0
- package/package.json +53 -0
|
@@ -0,0 +1,1010 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
DeploymentsResource: () => DeploymentsResource,
|
|
34
|
+
Dropthis: () => Dropthis,
|
|
35
|
+
UploadsResource: () => UploadsResource,
|
|
36
|
+
createErrorResult: () => createErrorResult,
|
|
37
|
+
redactSecrets: () => redactSecrets
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(index_exports);
|
|
40
|
+
|
|
41
|
+
// src/publish/prepare.ts
|
|
42
|
+
var import_promises2 = require("fs/promises");
|
|
43
|
+
var import_node_path2 = require("path");
|
|
44
|
+
|
|
45
|
+
// src/case.ts
|
|
46
|
+
function toCamelKey(key) {
|
|
47
|
+
return key.replace(/_([a-z])/g, (_, char) => char.toUpperCase());
|
|
48
|
+
}
|
|
49
|
+
function toSnakeKey(key) {
|
|
50
|
+
return key.replace(/[A-Z]/g, (char) => `_${char.toLowerCase()}`);
|
|
51
|
+
}
|
|
52
|
+
function toCamelCase(value) {
|
|
53
|
+
if (Array.isArray(value)) return value.map(toCamelCase);
|
|
54
|
+
if (value && typeof value === "object") {
|
|
55
|
+
return Object.fromEntries(
|
|
56
|
+
Object.entries(value).map(([key, item]) => [
|
|
57
|
+
toCamelKey(key),
|
|
58
|
+
toCamelCase(item)
|
|
59
|
+
])
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
function toSnakeCase(value) {
|
|
65
|
+
if (Array.isArray(value)) return value.map(toSnakeCase);
|
|
66
|
+
if (value && typeof value === "object") {
|
|
67
|
+
return Object.fromEntries(
|
|
68
|
+
Object.entries(value).filter(([, item]) => item !== void 0).map(([key, item]) => [toSnakeKey(key), toSnakeCase(item)])
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/publish/checksum.ts
|
|
75
|
+
var import_node_crypto = require("crypto");
|
|
76
|
+
var import_node_fs = require("fs");
|
|
77
|
+
function sha256Bytes(bytes) {
|
|
78
|
+
return (0, import_node_crypto.createHash)("sha256").update(bytes).digest("hex");
|
|
79
|
+
}
|
|
80
|
+
async function sha256File(path) {
|
|
81
|
+
const hash = (0, import_node_crypto.createHash)("sha256");
|
|
82
|
+
for await (const chunk of (0, import_node_fs.createReadStream)(path)) {
|
|
83
|
+
hash.update(chunk);
|
|
84
|
+
}
|
|
85
|
+
return hash.digest("hex");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// src/publish/detect.ts
|
|
89
|
+
function isHttpUrl(value) {
|
|
90
|
+
try {
|
|
91
|
+
const url = new URL(value);
|
|
92
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
93
|
+
} catch {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function looksLikeHtml(value) {
|
|
98
|
+
const trimmed = value.trimStart().toLowerCase();
|
|
99
|
+
return trimmed.startsWith("<!doctype html") || trimmed.startsWith("<html") || /^<[a-z][a-z0-9:-]*(\s|>)/.test(trimmed);
|
|
100
|
+
}
|
|
101
|
+
function detectStringInput(value) {
|
|
102
|
+
if (isHttpUrl(value)) return { mode: "sourceUrl" };
|
|
103
|
+
return {
|
|
104
|
+
mode: "content",
|
|
105
|
+
contentType: looksLikeHtml(value) ? "text/html" : "text/plain; charset=utf-8"
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function detectBytesContentType(bytes) {
|
|
109
|
+
const text = Buffer.from(bytes).toString("utf8");
|
|
110
|
+
if (text.includes("\uFFFD")) return "application/octet-stream";
|
|
111
|
+
return looksLikeHtml(text) ? "text/html" : "text/plain; charset=utf-8";
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/publish/files.ts
|
|
115
|
+
var import_promises = require("fs/promises");
|
|
116
|
+
var import_node_path = require("path");
|
|
117
|
+
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
118
|
+
var import_ignore = __toESM(require("ignore"), 1);
|
|
119
|
+
var import_mime_types = require("mime-types");
|
|
120
|
+
var DEFAULT_IGNORES = [
|
|
121
|
+
".git",
|
|
122
|
+
".git/**",
|
|
123
|
+
"node_modules",
|
|
124
|
+
"node_modules/**",
|
|
125
|
+
".DS_Store",
|
|
126
|
+
".env",
|
|
127
|
+
".env.*",
|
|
128
|
+
".cache",
|
|
129
|
+
".cache/**",
|
|
130
|
+
".tmp",
|
|
131
|
+
".tmp/**",
|
|
132
|
+
"dist/.cache",
|
|
133
|
+
"dist/.cache/**"
|
|
134
|
+
];
|
|
135
|
+
async function collectPublishFiles(inputPath, options = {}) {
|
|
136
|
+
const inputStat = await (0, import_promises.stat)(inputPath);
|
|
137
|
+
if (inputStat.isFile()) {
|
|
138
|
+
return [
|
|
139
|
+
{
|
|
140
|
+
absolutePath: inputPath,
|
|
141
|
+
path: (0, import_node_path.basename)(inputPath),
|
|
142
|
+
contentType: await detectPathContentType(inputPath),
|
|
143
|
+
sizeBytes: inputStat.size
|
|
144
|
+
}
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
if (!inputStat.isDirectory()) {
|
|
148
|
+
throw new Error(`Input is not a file or directory: ${inputPath}`);
|
|
149
|
+
}
|
|
150
|
+
const matcher = (0, import_ignore.default)().add([
|
|
151
|
+
...options.ignoreDefaults === false ? [] : DEFAULT_IGNORES,
|
|
152
|
+
...options.ignore ?? []
|
|
153
|
+
]);
|
|
154
|
+
const entries = await (0, import_fast_glob.default)("**/*", {
|
|
155
|
+
cwd: inputPath,
|
|
156
|
+
onlyFiles: true,
|
|
157
|
+
followSymbolicLinks: false,
|
|
158
|
+
dot: true,
|
|
159
|
+
unique: true
|
|
160
|
+
});
|
|
161
|
+
const paths = entries.map((entry) => entry.split(import_node_path.sep).join("/")).filter((entry) => !matcher.ignores(entry)).sort((a, b) => a.localeCompare(b));
|
|
162
|
+
return Promise.all(
|
|
163
|
+
paths.map(async (path) => {
|
|
164
|
+
const absolutePath = `${inputPath}/${path}`;
|
|
165
|
+
const fileStat = await (0, import_promises.stat)(absolutePath);
|
|
166
|
+
return {
|
|
167
|
+
absolutePath,
|
|
168
|
+
path,
|
|
169
|
+
contentType: await detectPathContentType(absolutePath),
|
|
170
|
+
sizeBytes: fileStat.size
|
|
171
|
+
};
|
|
172
|
+
})
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
async function detectPathContentType(path) {
|
|
176
|
+
const detected = (0, import_mime_types.lookup)(path);
|
|
177
|
+
if (detected) return detected;
|
|
178
|
+
return detectBytesContentType(await (0, import_promises.readFile)(path));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// src/publish/prepare.ts
|
|
182
|
+
var SINGLE_PUT_CHECKSUM_THRESHOLD_BYTES = 10 * 1024 * 1024;
|
|
183
|
+
async function preparePublishRequest(input, options = {}) {
|
|
184
|
+
if (input instanceof URL) {
|
|
185
|
+
throw new Error(
|
|
186
|
+
"URL inputs are not supported. Fetch the content first, then pass it as a string or file."
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
if (typeof input === "string") {
|
|
190
|
+
const local = await localKind(input);
|
|
191
|
+
if (local === "file") {
|
|
192
|
+
return fileStaged(input, options);
|
|
193
|
+
}
|
|
194
|
+
if (local === "directory") {
|
|
195
|
+
return folderStaged(input, options);
|
|
196
|
+
}
|
|
197
|
+
const detection = detectStringInput(input);
|
|
198
|
+
if (detection.mode === "sourceUrl")
|
|
199
|
+
throw new Error(
|
|
200
|
+
"URL inputs are not supported. Fetch the content first, then pass it as a string or file."
|
|
201
|
+
);
|
|
202
|
+
return stringContent(input, options, detection.contentType);
|
|
203
|
+
}
|
|
204
|
+
if (input instanceof Uint8Array || Buffer.isBuffer(input)) {
|
|
205
|
+
return bytesStaged(input, options);
|
|
206
|
+
}
|
|
207
|
+
return explicitInput(input, options);
|
|
208
|
+
}
|
|
209
|
+
async function stringContent(content, options, detectedContentType) {
|
|
210
|
+
const contentType = options.contentType ?? detectedContentType;
|
|
211
|
+
return bytesStaged(Buffer.from(content), {
|
|
212
|
+
...options,
|
|
213
|
+
path: options.path ?? entryForContentType(contentType),
|
|
214
|
+
contentType
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
function entryForContentType(contentType) {
|
|
218
|
+
const normalized = contentType.toLowerCase().split(";", 1)[0]?.trim() ?? "";
|
|
219
|
+
if (normalized === "text/html" || normalized === "application/xhtml+xml")
|
|
220
|
+
return "index.html";
|
|
221
|
+
if (normalized === "application/json") return "index.json";
|
|
222
|
+
if (normalized === "text/css") return "index.css";
|
|
223
|
+
if (normalized === "text/javascript" || normalized === "application/javascript")
|
|
224
|
+
return "index.js";
|
|
225
|
+
if (normalized.startsWith("text/")) return "index.txt";
|
|
226
|
+
return "index";
|
|
227
|
+
}
|
|
228
|
+
async function localKind(input) {
|
|
229
|
+
try {
|
|
230
|
+
const info = await (0, import_promises2.stat)(input);
|
|
231
|
+
if (info.isFile()) return "file";
|
|
232
|
+
if (info.isDirectory()) return "directory";
|
|
233
|
+
return "none";
|
|
234
|
+
} catch {
|
|
235
|
+
return "none";
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
async function fileStaged(path, options) {
|
|
239
|
+
const fileStat = await (0, import_promises2.stat)(path);
|
|
240
|
+
const manifestPath = options.path ?? (0, import_node_path2.basename)(path);
|
|
241
|
+
return stagedRequest(
|
|
242
|
+
[
|
|
243
|
+
{
|
|
244
|
+
path: manifestPath,
|
|
245
|
+
contentType: options.contentType ?? await detectPathContentType(path),
|
|
246
|
+
sizeBytes: fileStat.size,
|
|
247
|
+
source: { kind: "path", path }
|
|
248
|
+
}
|
|
249
|
+
],
|
|
250
|
+
{ ...options, entry: options.entry ?? manifestPath }
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
async function folderStaged(path, options) {
|
|
254
|
+
const files = (await collectPublishFiles(path, options)).map((file) => ({
|
|
255
|
+
path: file.path,
|
|
256
|
+
contentType: file.contentType,
|
|
257
|
+
sizeBytes: file.sizeBytes,
|
|
258
|
+
source: { kind: "path", path: file.absolutePath }
|
|
259
|
+
}));
|
|
260
|
+
return stagedRequest(files, options);
|
|
261
|
+
}
|
|
262
|
+
async function bytesStaged(bytes, options) {
|
|
263
|
+
return stagedRequest(
|
|
264
|
+
[
|
|
265
|
+
{
|
|
266
|
+
path: options.path ?? "index",
|
|
267
|
+
contentType: options.contentType ?? detectBytesContentType(bytes),
|
|
268
|
+
sizeBytes: bytes.byteLength,
|
|
269
|
+
source: { kind: "bytes", bytes }
|
|
270
|
+
}
|
|
271
|
+
],
|
|
272
|
+
options
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
async function stagedRequest(files, options) {
|
|
276
|
+
const preparedFiles = await Promise.all(
|
|
277
|
+
files.map(async (file) => {
|
|
278
|
+
if (file.sizeBytes <= SINGLE_PUT_CHECKSUM_THRESHOLD_BYTES) return file;
|
|
279
|
+
const checksumSha256 = file.source.kind === "bytes" ? sha256Bytes(file.source.bytes) : await sha256File(file.source.path);
|
|
280
|
+
return { ...file, checksumSha256 };
|
|
281
|
+
})
|
|
282
|
+
);
|
|
283
|
+
const manifestFiles = preparedFiles.map((file) => ({
|
|
284
|
+
path: file.path,
|
|
285
|
+
contentType: file.contentType,
|
|
286
|
+
sizeBytes: file.sizeBytes,
|
|
287
|
+
...file.checksumSha256 ? { checksumSha256: file.checksumSha256 } : {}
|
|
288
|
+
}));
|
|
289
|
+
const prepared = {
|
|
290
|
+
kind: "staged",
|
|
291
|
+
manifest: {
|
|
292
|
+
schemaVersion: 1,
|
|
293
|
+
files: manifestFiles,
|
|
294
|
+
...options.entry ? { entry: options.entry } : {}
|
|
295
|
+
},
|
|
296
|
+
files: preparedFiles,
|
|
297
|
+
options: optionsBody(options)
|
|
298
|
+
};
|
|
299
|
+
if (options.metadata) prepared.metadata = options.metadata;
|
|
300
|
+
return prepared;
|
|
301
|
+
}
|
|
302
|
+
async function explicitInput(input, options) {
|
|
303
|
+
if ("content" in input)
|
|
304
|
+
return stringContent(
|
|
305
|
+
input.content,
|
|
306
|
+
{ ...options, ...input },
|
|
307
|
+
input.contentType ?? options.contentType ?? "text/html"
|
|
308
|
+
);
|
|
309
|
+
if ("sourceUrl" in input)
|
|
310
|
+
throw new Error(
|
|
311
|
+
"sourceUrl inputs are not supported. Fetch the content first, then pass it as a string or file."
|
|
312
|
+
);
|
|
313
|
+
if ("sourceUrls" in input)
|
|
314
|
+
throw new Error(
|
|
315
|
+
"sourceUrls inputs are not supported. Fetch the content first, then pass it as a string or file."
|
|
316
|
+
);
|
|
317
|
+
return stagedRequest(
|
|
318
|
+
input.files.map((file) => {
|
|
319
|
+
const bytes = explicitFileBytes(file);
|
|
320
|
+
return {
|
|
321
|
+
path: file.path,
|
|
322
|
+
contentType: file.contentType,
|
|
323
|
+
sizeBytes: bytes.byteLength,
|
|
324
|
+
source: { kind: "bytes", bytes }
|
|
325
|
+
};
|
|
326
|
+
}),
|
|
327
|
+
{ ...options, ...input }
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
function explicitFileBytes(file) {
|
|
331
|
+
if (file.content !== void 0) return Buffer.from(file.content);
|
|
332
|
+
if (file.contentBase64 !== void 0)
|
|
333
|
+
return Buffer.from(file.contentBase64, "base64");
|
|
334
|
+
if (file.bytes !== void 0) return file.bytes;
|
|
335
|
+
throw new TypeError(`Explicit file ${file.path} is missing content bytes`);
|
|
336
|
+
}
|
|
337
|
+
function optionsBody(options) {
|
|
338
|
+
return toSnakeCase({
|
|
339
|
+
title: options.title,
|
|
340
|
+
visibility: options.visibility,
|
|
341
|
+
password: options.password,
|
|
342
|
+
noindex: options.noindex,
|
|
343
|
+
expiresAt: options.expiresAt instanceof Date ? options.expiresAt.toISOString() : options.expiresAt
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// src/publish/upload.ts
|
|
348
|
+
var import_node_crypto2 = require("crypto");
|
|
349
|
+
var import_promises3 = require("fs/promises");
|
|
350
|
+
|
|
351
|
+
// src/errors.ts
|
|
352
|
+
var API_KEY_RE = /sk_[A-Za-z0-9_-]+/g;
|
|
353
|
+
function redactSecrets(message) {
|
|
354
|
+
return message.replace(API_KEY_RE, "sk_[redacted]");
|
|
355
|
+
}
|
|
356
|
+
function createErrorResult(code, message, statusCode, extra = {}) {
|
|
357
|
+
return {
|
|
358
|
+
data: null,
|
|
359
|
+
error: {
|
|
360
|
+
code,
|
|
361
|
+
message: redactSecrets(message),
|
|
362
|
+
statusCode,
|
|
363
|
+
...extra.type ? { type: extra.type } : {},
|
|
364
|
+
...extra.detail !== void 0 ? { detail: extra.detail } : {},
|
|
365
|
+
...extra.param !== void 0 ? { param: extra.param } : {},
|
|
366
|
+
...extra.currentRevision !== void 0 ? { currentRevision: extra.currentRevision } : {},
|
|
367
|
+
...extra.requestId !== void 0 ? { requestId: extra.requestId } : {}
|
|
368
|
+
},
|
|
369
|
+
headers: extra.headers ?? {}
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// src/publish/upload.ts
|
|
374
|
+
var MAX_PART_TARGETS_PER_REQUEST = 100;
|
|
375
|
+
async function publishStaged(transport, prepared, finalPath, options = {}) {
|
|
376
|
+
const baseKey = options.idempotencyKey ?? `sdk-${(0, import_node_crypto2.randomUUID)()}`;
|
|
377
|
+
const createResult = await transport.request(
|
|
378
|
+
"POST",
|
|
379
|
+
"/uploads",
|
|
380
|
+
{
|
|
381
|
+
body: toSnakeCase(prepared.manifest),
|
|
382
|
+
idempotencyKey: `${baseKey}:create-upload`
|
|
383
|
+
}
|
|
384
|
+
);
|
|
385
|
+
if (createResult.error) return errorResult(createResult);
|
|
386
|
+
const completedFiles = {};
|
|
387
|
+
for (const file of prepared.files) {
|
|
388
|
+
const target = createResult.data.files.find(
|
|
389
|
+
(candidate) => candidate.path === file.path
|
|
390
|
+
);
|
|
391
|
+
if (!target) {
|
|
392
|
+
return createErrorResult(
|
|
393
|
+
"upload_target_missing",
|
|
394
|
+
`Upload target missing for ${file.path}`,
|
|
395
|
+
null
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
if (target.upload.strategy === "multipart") {
|
|
399
|
+
const partsResult = await uploadMultipartFile(
|
|
400
|
+
transport,
|
|
401
|
+
createResult.data.uploadId,
|
|
402
|
+
target.fileId,
|
|
403
|
+
file,
|
|
404
|
+
target.upload.partSize
|
|
405
|
+
);
|
|
406
|
+
if (partsResult.error) return errorResult(partsResult);
|
|
407
|
+
completedFiles[target.fileId] = { parts: partsResult.data };
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
const bytes = await fileBytes(file);
|
|
411
|
+
const uploadResult = await transport.putSignedUrl(
|
|
412
|
+
target.upload.url,
|
|
413
|
+
bytes,
|
|
414
|
+
target.upload.headers
|
|
415
|
+
);
|
|
416
|
+
if (uploadResult.error) return errorResult(uploadResult);
|
|
417
|
+
}
|
|
418
|
+
const completeResult = await transport.request(
|
|
419
|
+
"POST",
|
|
420
|
+
`/uploads/${encodeURIComponent(createResult.data.uploadId)}/complete`,
|
|
421
|
+
{
|
|
422
|
+
body: toSnakeCase({ files: completedFiles }),
|
|
423
|
+
idempotencyKey: `${baseKey}:complete-upload`
|
|
424
|
+
}
|
|
425
|
+
);
|
|
426
|
+
if (completeResult.error) return errorResult(completeResult);
|
|
427
|
+
const finalOptions = {
|
|
428
|
+
body: {
|
|
429
|
+
upload_id: createResult.data.uploadId,
|
|
430
|
+
options: prepared.options,
|
|
431
|
+
...prepared.metadata ? { metadata: prepared.metadata } : {}
|
|
432
|
+
},
|
|
433
|
+
idempotencyKey: `${baseKey}:publish`
|
|
434
|
+
};
|
|
435
|
+
if (options.ifRevision !== void 0)
|
|
436
|
+
finalOptions.ifRevision = options.ifRevision;
|
|
437
|
+
return transport.request("POST", finalPath, finalOptions);
|
|
438
|
+
}
|
|
439
|
+
async function uploadMultipartFile(transport, uploadId, fileId, file, partSize) {
|
|
440
|
+
if (!partSize || partSize < 1) {
|
|
441
|
+
return createErrorResult(
|
|
442
|
+
"invalid_upload_target",
|
|
443
|
+
"Multipart upload target did not include a valid part size.",
|
|
444
|
+
null
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
const bytes = await fileBytes(file);
|
|
448
|
+
const partNumbers = Array.from(
|
|
449
|
+
{ length: Math.ceil(bytes.byteLength / partSize) },
|
|
450
|
+
(_, index) => index + 1
|
|
451
|
+
);
|
|
452
|
+
const parts = [];
|
|
453
|
+
for (let startIndex = 0; startIndex < partNumbers.length; startIndex += MAX_PART_TARGETS_PER_REQUEST) {
|
|
454
|
+
const partNumberBatch = partNumbers.slice(
|
|
455
|
+
startIndex,
|
|
456
|
+
startIndex + MAX_PART_TARGETS_PER_REQUEST
|
|
457
|
+
);
|
|
458
|
+
const targetsResult = await transport.request(
|
|
459
|
+
"POST",
|
|
460
|
+
`/uploads/${encodeURIComponent(uploadId)}/parts`,
|
|
461
|
+
{ body: toSnakeCase({ fileId, partNumbers: partNumberBatch }) }
|
|
462
|
+
);
|
|
463
|
+
if (targetsResult.error) return errorResult(targetsResult);
|
|
464
|
+
for (const target of targetsResult.data.parts) {
|
|
465
|
+
const start = (target.partNumber - 1) * partSize;
|
|
466
|
+
const end = Math.min(start + partSize, bytes.byteLength);
|
|
467
|
+
const uploadResult = await transport.putSignedUrl(
|
|
468
|
+
target.url,
|
|
469
|
+
bytes.slice(start, end),
|
|
470
|
+
target.headers
|
|
471
|
+
);
|
|
472
|
+
if (uploadResult.error) return errorResult(uploadResult);
|
|
473
|
+
if (!uploadResult.data.etag) {
|
|
474
|
+
return createErrorResult(
|
|
475
|
+
"missing_upload_etag",
|
|
476
|
+
"Signed upload response did not include an ETag.",
|
|
477
|
+
null
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
parts.push({
|
|
481
|
+
partNumber: target.partNumber,
|
|
482
|
+
etag: uploadResult.data.etag
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return { data: parts, error: null, headers: {} };
|
|
487
|
+
}
|
|
488
|
+
async function fileBytes(file) {
|
|
489
|
+
if (file.source.kind === "bytes") return file.source.bytes;
|
|
490
|
+
return (0, import_promises3.readFile)(file.source.path);
|
|
491
|
+
}
|
|
492
|
+
function errorResult(result) {
|
|
493
|
+
if (!result.error) throw new Error("Expected an error result");
|
|
494
|
+
return { data: null, error: result.error, headers: result.headers };
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// src/resources/account.ts
|
|
498
|
+
var AccountResource = class {
|
|
499
|
+
constructor(transport) {
|
|
500
|
+
this.transport = transport;
|
|
501
|
+
}
|
|
502
|
+
transport;
|
|
503
|
+
get() {
|
|
504
|
+
return this.transport.request("GET", "/account");
|
|
505
|
+
}
|
|
506
|
+
update(input) {
|
|
507
|
+
return this.transport.request("PATCH", "/account", {
|
|
508
|
+
body: toSnakeCase(input)
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
delete() {
|
|
512
|
+
return this.transport.request("DELETE", "/account");
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
// src/resources/api-keys.ts
|
|
517
|
+
var ApiKeysResource = class {
|
|
518
|
+
constructor(transport) {
|
|
519
|
+
this.transport = transport;
|
|
520
|
+
}
|
|
521
|
+
transport;
|
|
522
|
+
list() {
|
|
523
|
+
return this.transport.request("GET", "/api-keys");
|
|
524
|
+
}
|
|
525
|
+
create(input) {
|
|
526
|
+
return this.transport.request("POST", "/api-keys", { body: input });
|
|
527
|
+
}
|
|
528
|
+
delete(keyId) {
|
|
529
|
+
return this.transport.request(
|
|
530
|
+
"DELETE",
|
|
531
|
+
`/api-keys/${encodeURIComponent(keyId)}`
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
// src/resources/auth.ts
|
|
537
|
+
var AuthResource = class {
|
|
538
|
+
constructor(transport) {
|
|
539
|
+
this.transport = transport;
|
|
540
|
+
}
|
|
541
|
+
transport;
|
|
542
|
+
requestEmailOtp(input) {
|
|
543
|
+
return this.transport.request("POST", "/auth/email/otp", {
|
|
544
|
+
body: input,
|
|
545
|
+
authenticated: false
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
verifyEmailOtp(input) {
|
|
549
|
+
return this.transport.request("POST", "/auth/email/verify", {
|
|
550
|
+
body: input,
|
|
551
|
+
authenticated: false
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
logout() {
|
|
555
|
+
return this.transport.request("DELETE", "/auth/session");
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
// src/resources/deployments.ts
|
|
560
|
+
var DeploymentsResource = class {
|
|
561
|
+
constructor(transport) {
|
|
562
|
+
this.transport = transport;
|
|
563
|
+
}
|
|
564
|
+
transport;
|
|
565
|
+
create(dropId, body, options = {}) {
|
|
566
|
+
const requestOptions = {
|
|
567
|
+
body: toSnakeCase(body)
|
|
568
|
+
};
|
|
569
|
+
if (options.idempotencyKey)
|
|
570
|
+
requestOptions.idempotencyKey = options.idempotencyKey;
|
|
571
|
+
if (options.ifRevision !== void 0)
|
|
572
|
+
requestOptions.ifRevision = options.ifRevision;
|
|
573
|
+
return this.transport.request(
|
|
574
|
+
"POST",
|
|
575
|
+
`/drops/${encodeURIComponent(dropId)}/deployments`,
|
|
576
|
+
requestOptions
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
createRaw(dropId, body, options = {}) {
|
|
580
|
+
const requestOptions = { body };
|
|
581
|
+
if (options.idempotencyKey)
|
|
582
|
+
requestOptions.idempotencyKey = options.idempotencyKey;
|
|
583
|
+
if (options.ifRevision !== void 0)
|
|
584
|
+
requestOptions.ifRevision = options.ifRevision;
|
|
585
|
+
return this.transport.request(
|
|
586
|
+
"POST",
|
|
587
|
+
`/drops/${encodeURIComponent(dropId)}/deployments`,
|
|
588
|
+
requestOptions
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
list(dropId, params = {}) {
|
|
592
|
+
return this.transport.request(
|
|
593
|
+
"GET",
|
|
594
|
+
`/drops/${encodeURIComponent(dropId)}/deployments`,
|
|
595
|
+
{
|
|
596
|
+
params: toSnakeCase(params)
|
|
597
|
+
}
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
get(dropId, deploymentId) {
|
|
601
|
+
return this.transport.request(
|
|
602
|
+
"GET",
|
|
603
|
+
`/drops/${encodeURIComponent(dropId)}/deployments/${encodeURIComponent(deploymentId)}`
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
// src/types.ts
|
|
609
|
+
var CursorPage = class {
|
|
610
|
+
object = "list";
|
|
611
|
+
data;
|
|
612
|
+
hasMore;
|
|
613
|
+
nextCursor;
|
|
614
|
+
fetchNextPage;
|
|
615
|
+
constructor(input) {
|
|
616
|
+
this.data = input.data;
|
|
617
|
+
this.hasMore = input.hasMore;
|
|
618
|
+
this.nextCursor = input.nextCursor;
|
|
619
|
+
this.fetchNextPage = input.fetchNextPage;
|
|
620
|
+
}
|
|
621
|
+
async autoPagingToArray(options = {}) {
|
|
622
|
+
const items = [];
|
|
623
|
+
for await (const item of this) {
|
|
624
|
+
items.push(item);
|
|
625
|
+
if (options.limit !== void 0 && items.length >= options.limit) break;
|
|
626
|
+
}
|
|
627
|
+
return items;
|
|
628
|
+
}
|
|
629
|
+
async *[Symbol.asyncIterator]() {
|
|
630
|
+
for (const item of this.data) yield item;
|
|
631
|
+
let current = this;
|
|
632
|
+
while (current.hasMore && current.fetchNextPage) {
|
|
633
|
+
const next = await current.fetchNextPage();
|
|
634
|
+
if (next.error) break;
|
|
635
|
+
current = next.data;
|
|
636
|
+
for (const item of current.data) yield item;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
// src/resources/drops.ts
|
|
642
|
+
var DropsResource = class {
|
|
643
|
+
constructor(transport) {
|
|
644
|
+
this.transport = transport;
|
|
645
|
+
}
|
|
646
|
+
transport;
|
|
647
|
+
create(body, options = {}) {
|
|
648
|
+
const requestOptions = {
|
|
649
|
+
body: toSnakeCase(body)
|
|
650
|
+
};
|
|
651
|
+
if (options.idempotencyKey)
|
|
652
|
+
requestOptions.idempotencyKey = options.idempotencyKey;
|
|
653
|
+
return this.transport.request("POST", "/drops", requestOptions);
|
|
654
|
+
}
|
|
655
|
+
createRaw(body, options = {}) {
|
|
656
|
+
const requestOptions = { body };
|
|
657
|
+
if (options.idempotencyKey)
|
|
658
|
+
requestOptions.idempotencyKey = options.idempotencyKey;
|
|
659
|
+
return this.transport.request("POST", "/drops", requestOptions);
|
|
660
|
+
}
|
|
661
|
+
async list(params = {}) {
|
|
662
|
+
const result = await this.transport.request("GET", "/drops", {
|
|
663
|
+
params: toSnakeCase(params)
|
|
664
|
+
});
|
|
665
|
+
if (result.error) return result;
|
|
666
|
+
const page = new CursorPage({
|
|
667
|
+
data: result.data.drops,
|
|
668
|
+
nextCursor: result.data.nextCursor,
|
|
669
|
+
hasMore: result.data.nextCursor !== null,
|
|
670
|
+
fetchNextPage: result.data.nextCursor ? () => this.list({ ...params, cursor: result.data.nextCursor }) : void 0
|
|
671
|
+
});
|
|
672
|
+
return { data: page, error: null, headers: result.headers };
|
|
673
|
+
}
|
|
674
|
+
get(dropId) {
|
|
675
|
+
return this.transport.request(
|
|
676
|
+
"GET",
|
|
677
|
+
`/drops/${encodeURIComponent(dropId)}`
|
|
678
|
+
);
|
|
679
|
+
}
|
|
680
|
+
update(dropId, body, options = {}) {
|
|
681
|
+
const bodyRecord = body;
|
|
682
|
+
if (hasContent(bodyRecord)) {
|
|
683
|
+
throw new TypeError(
|
|
684
|
+
"drops.update() only patches drop options; use deployments.create() or update() for content"
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
const requestOptions = {
|
|
688
|
+
body: updateBody(body)
|
|
689
|
+
};
|
|
690
|
+
const bodyOptions = body;
|
|
691
|
+
const idempotencyKey = options.idempotencyKey ?? bodyOptions.idempotencyKey;
|
|
692
|
+
const ifRevision = options.ifRevision ?? bodyOptions.ifRevision;
|
|
693
|
+
if (idempotencyKey) requestOptions.idempotencyKey = idempotencyKey;
|
|
694
|
+
if (ifRevision !== void 0) requestOptions.ifRevision = ifRevision;
|
|
695
|
+
return this.transport.request(
|
|
696
|
+
"PATCH",
|
|
697
|
+
`/drops/${encodeURIComponent(dropId)}`,
|
|
698
|
+
requestOptions
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
delete(dropId) {
|
|
702
|
+
return this.transport.request(
|
|
703
|
+
"DELETE",
|
|
704
|
+
`/drops/${encodeURIComponent(dropId)}`
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
function updateBody(body) {
|
|
709
|
+
const {
|
|
710
|
+
metadata,
|
|
711
|
+
idempotencyKey: _idempotencyKey,
|
|
712
|
+
ifRevision: _ifRevision,
|
|
713
|
+
ignore: _ignore,
|
|
714
|
+
ignoreDefaults: _ignoreDefaults,
|
|
715
|
+
contentType: _contentType,
|
|
716
|
+
path: _path,
|
|
717
|
+
entry: _entry,
|
|
718
|
+
...dropOptions
|
|
719
|
+
} = body;
|
|
720
|
+
return toSnakeCase({ options: dropOptions, metadata });
|
|
721
|
+
}
|
|
722
|
+
function hasContent(body) {
|
|
723
|
+
return ["content", "contentType", "content_type", "entry", "files"].some(
|
|
724
|
+
(field) => body[field] !== void 0
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
// src/resources/uploads.ts
|
|
729
|
+
var UploadsResource = class {
|
|
730
|
+
constructor(transport) {
|
|
731
|
+
this.transport = transport;
|
|
732
|
+
}
|
|
733
|
+
transport;
|
|
734
|
+
create(body, options = {}) {
|
|
735
|
+
const requestOptions = {
|
|
736
|
+
body: toSnakeCase(body)
|
|
737
|
+
};
|
|
738
|
+
if (options.idempotencyKey)
|
|
739
|
+
requestOptions.idempotencyKey = options.idempotencyKey;
|
|
740
|
+
return this.transport.request("POST", "/uploads", requestOptions);
|
|
741
|
+
}
|
|
742
|
+
get(uploadId) {
|
|
743
|
+
return this.transport.request(
|
|
744
|
+
"GET",
|
|
745
|
+
`/uploads/${encodeURIComponent(uploadId)}`
|
|
746
|
+
);
|
|
747
|
+
}
|
|
748
|
+
createPartTargets(uploadId, body) {
|
|
749
|
+
return this.transport.request(
|
|
750
|
+
"POST",
|
|
751
|
+
`/uploads/${encodeURIComponent(uploadId)}/parts`,
|
|
752
|
+
{ body: toSnakeCase(body) }
|
|
753
|
+
);
|
|
754
|
+
}
|
|
755
|
+
complete(uploadId, body, options = {}) {
|
|
756
|
+
const requestOptions = {
|
|
757
|
+
body: toSnakeCase(body)
|
|
758
|
+
};
|
|
759
|
+
if (options.idempotencyKey)
|
|
760
|
+
requestOptions.idempotencyKey = options.idempotencyKey;
|
|
761
|
+
return this.transport.request(
|
|
762
|
+
"POST",
|
|
763
|
+
`/uploads/${encodeURIComponent(uploadId)}/complete`,
|
|
764
|
+
requestOptions
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
cancel(uploadId) {
|
|
768
|
+
return this.transport.request(
|
|
769
|
+
"DELETE",
|
|
770
|
+
`/uploads/${encodeURIComponent(uploadId)}`
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
|
|
775
|
+
// src/transport.ts
|
|
776
|
+
var DEFAULT_BASE_URL = "https://api.dropthis.app";
|
|
777
|
+
var SDK_VERSION = "0.1.0";
|
|
778
|
+
var Transport = class {
|
|
779
|
+
apiKey;
|
|
780
|
+
baseUrl;
|
|
781
|
+
timeoutMs;
|
|
782
|
+
fetchImpl;
|
|
783
|
+
constructor(options = {}) {
|
|
784
|
+
const resolved = typeof options === "string" ? { apiKey: options } : options;
|
|
785
|
+
this.apiKey = resolved.apiKey ?? process.env.DROPTHIS_API_KEY;
|
|
786
|
+
this.baseUrl = (resolved.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
787
|
+
this.timeoutMs = resolved.timeoutMs ?? 3e4;
|
|
788
|
+
this.fetchImpl = resolved.fetch ?? globalThis.fetch;
|
|
789
|
+
}
|
|
790
|
+
multipart(method, path, form, options = {}) {
|
|
791
|
+
return this.request(method, path, { ...options, body: form });
|
|
792
|
+
}
|
|
793
|
+
async putSignedUrl(url, body, headers) {
|
|
794
|
+
const controller = new AbortController();
|
|
795
|
+
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
796
|
+
try {
|
|
797
|
+
const request = {
|
|
798
|
+
method: "PUT",
|
|
799
|
+
headers,
|
|
800
|
+
body,
|
|
801
|
+
signal: controller.signal
|
|
802
|
+
};
|
|
803
|
+
if (body instanceof ReadableStream) request.duplex = "half";
|
|
804
|
+
const response = await this.fetchImpl(url, request);
|
|
805
|
+
const responseHeaders = headersToObject(response.headers);
|
|
806
|
+
if (!response.ok) {
|
|
807
|
+
const text = await response.text();
|
|
808
|
+
return createErrorResult(
|
|
809
|
+
`signed_upload_${response.status}`,
|
|
810
|
+
text || response.statusText,
|
|
811
|
+
response.status,
|
|
812
|
+
{ headers: responseHeaders }
|
|
813
|
+
);
|
|
814
|
+
}
|
|
815
|
+
return {
|
|
816
|
+
data: {
|
|
817
|
+
etag: response.headers.get("ETag") ?? responseHeaders.etag ?? null
|
|
818
|
+
},
|
|
819
|
+
error: null,
|
|
820
|
+
headers: responseHeaders
|
|
821
|
+
};
|
|
822
|
+
} catch (error) {
|
|
823
|
+
const message = error instanceof Error && error.name === "AbortError" ? "Request timed out" : error instanceof Error ? error.message : "Network error";
|
|
824
|
+
return createErrorResult(
|
|
825
|
+
error instanceof Error && error.name === "AbortError" ? "timeout" : "network_error",
|
|
826
|
+
message,
|
|
827
|
+
null
|
|
828
|
+
);
|
|
829
|
+
} finally {
|
|
830
|
+
clearTimeout(timeout);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
async request(method, path, options = {}) {
|
|
834
|
+
const authenticated = options.authenticated ?? true;
|
|
835
|
+
if (authenticated && !this.apiKey) {
|
|
836
|
+
return createErrorResult(
|
|
837
|
+
"missing_api_key",
|
|
838
|
+
"No API key provided. Pass apiKey or set DROPTHIS_API_KEY.",
|
|
839
|
+
null
|
|
840
|
+
);
|
|
841
|
+
}
|
|
842
|
+
const headers = {
|
|
843
|
+
"user-agent": `dropthis-node/${SDK_VERSION}`
|
|
844
|
+
};
|
|
845
|
+
if (authenticated && this.apiKey)
|
|
846
|
+
headers.authorization = `Bearer ${this.apiKey}`;
|
|
847
|
+
if (options.idempotencyKey)
|
|
848
|
+
headers["idempotency-key"] = options.idempotencyKey;
|
|
849
|
+
if (options.ifRevision !== void 0)
|
|
850
|
+
headers["If-Revision"] = String(options.ifRevision);
|
|
851
|
+
if (options.body !== void 0 && !(options.body instanceof FormData))
|
|
852
|
+
headers["content-type"] = "application/json";
|
|
853
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
854
|
+
for (const [key, value] of Object.entries(options.params ?? {})) {
|
|
855
|
+
if (value !== void 0 && value !== null)
|
|
856
|
+
url.searchParams.set(key, String(value));
|
|
857
|
+
}
|
|
858
|
+
const controller = new AbortController();
|
|
859
|
+
const timeout = setTimeout(
|
|
860
|
+
() => controller.abort(),
|
|
861
|
+
options.timeoutMs ?? this.timeoutMs
|
|
862
|
+
);
|
|
863
|
+
try {
|
|
864
|
+
const request = {
|
|
865
|
+
method,
|
|
866
|
+
headers,
|
|
867
|
+
signal: controller.signal
|
|
868
|
+
};
|
|
869
|
+
if (options.body instanceof FormData) {
|
|
870
|
+
request.body = options.body;
|
|
871
|
+
} else if (options.body !== void 0) {
|
|
872
|
+
request.body = JSON.stringify(options.body);
|
|
873
|
+
}
|
|
874
|
+
const response = await this.fetchImpl(url.toString(), request);
|
|
875
|
+
const responseHeaders = headersToObject(response.headers);
|
|
876
|
+
const text = await response.text();
|
|
877
|
+
const parsed = parseJson(text);
|
|
878
|
+
if (!response.ok) {
|
|
879
|
+
const body = parsed && typeof parsed === "object" ? parsed : {};
|
|
880
|
+
const message = stringValue(body.detail) ?? stringValue(body.error) ?? stringValue(body.message) ?? response.statusText;
|
|
881
|
+
const code = stringValue(body.code) ?? stringValue(body.error_code) ?? `http_${response.status}`;
|
|
882
|
+
const currentRevision = numberValue(body.current_revision);
|
|
883
|
+
return createErrorResult(code, message, response.status, {
|
|
884
|
+
detail: body,
|
|
885
|
+
param: stringValue(body.param),
|
|
886
|
+
...currentRevision !== void 0 ? { currentRevision } : {},
|
|
887
|
+
requestId: responseHeaders["x-request-id"] ?? null,
|
|
888
|
+
headers: responseHeaders
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
return {
|
|
892
|
+
data: toCamelCase(parsed),
|
|
893
|
+
error: null,
|
|
894
|
+
headers: responseHeaders
|
|
895
|
+
};
|
|
896
|
+
} catch (error) {
|
|
897
|
+
const message = error instanceof Error && error.name === "AbortError" ? "Request timed out" : error instanceof Error ? error.message : "Network error";
|
|
898
|
+
return createErrorResult(
|
|
899
|
+
error instanceof Error && error.name === "AbortError" ? "timeout" : "network_error",
|
|
900
|
+
message,
|
|
901
|
+
null
|
|
902
|
+
);
|
|
903
|
+
} finally {
|
|
904
|
+
clearTimeout(timeout);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
};
|
|
908
|
+
function headersToObject(headers) {
|
|
909
|
+
const result = {};
|
|
910
|
+
headers.forEach((value, key) => {
|
|
911
|
+
result[key.toLowerCase()] = value;
|
|
912
|
+
});
|
|
913
|
+
return result;
|
|
914
|
+
}
|
|
915
|
+
function parseJson(text) {
|
|
916
|
+
if (!text) return null;
|
|
917
|
+
try {
|
|
918
|
+
return JSON.parse(text);
|
|
919
|
+
} catch {
|
|
920
|
+
return text;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
function stringValue(value) {
|
|
924
|
+
return typeof value === "string" ? value : null;
|
|
925
|
+
}
|
|
926
|
+
function numberValue(value) {
|
|
927
|
+
return typeof value === "number" ? value : void 0;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
// src/dropthis.ts
|
|
931
|
+
var Dropthis = class {
|
|
932
|
+
transport;
|
|
933
|
+
authResource;
|
|
934
|
+
apiKeysResource;
|
|
935
|
+
accountResource;
|
|
936
|
+
dropsResource;
|
|
937
|
+
deploymentsResource;
|
|
938
|
+
uploadsResource;
|
|
939
|
+
constructor(options = {}) {
|
|
940
|
+
this.transport = new Transport(options);
|
|
941
|
+
}
|
|
942
|
+
get auth() {
|
|
943
|
+
if (!this.authResource)
|
|
944
|
+
this.authResource = new AuthResource(this.transport);
|
|
945
|
+
return this.authResource;
|
|
946
|
+
}
|
|
947
|
+
get apiKeys() {
|
|
948
|
+
if (!this.apiKeysResource)
|
|
949
|
+
this.apiKeysResource = new ApiKeysResource(this.transport);
|
|
950
|
+
return this.apiKeysResource;
|
|
951
|
+
}
|
|
952
|
+
get account() {
|
|
953
|
+
if (!this.accountResource)
|
|
954
|
+
this.accountResource = new AccountResource(this.transport);
|
|
955
|
+
return this.accountResource;
|
|
956
|
+
}
|
|
957
|
+
get drops() {
|
|
958
|
+
if (!this.dropsResource)
|
|
959
|
+
this.dropsResource = new DropsResource(this.transport);
|
|
960
|
+
return this.dropsResource;
|
|
961
|
+
}
|
|
962
|
+
get deployments() {
|
|
963
|
+
if (!this.deploymentsResource)
|
|
964
|
+
this.deploymentsResource = new DeploymentsResource(this.transport);
|
|
965
|
+
return this.deploymentsResource;
|
|
966
|
+
}
|
|
967
|
+
get uploads() {
|
|
968
|
+
if (!this.uploadsResource)
|
|
969
|
+
this.uploadsResource = new UploadsResource(this.transport);
|
|
970
|
+
return this.uploadsResource;
|
|
971
|
+
}
|
|
972
|
+
async prepare(input, options = {}) {
|
|
973
|
+
return preparePublishRequest(input, options);
|
|
974
|
+
}
|
|
975
|
+
async publish(input, options = {}) {
|
|
976
|
+
const prepared = await preparePublishRequest(input, options);
|
|
977
|
+
return publishStaged(this.transport, prepared, "/drops", options);
|
|
978
|
+
}
|
|
979
|
+
async update(dropId, inputOrOptions = {}, options = {}) {
|
|
980
|
+
if (looksLikeOptionsOnly(inputOrOptions)) {
|
|
981
|
+
return this.drops.update(dropId, inputOrOptions, options);
|
|
982
|
+
}
|
|
983
|
+
const prepared = await preparePublishRequest(
|
|
984
|
+
inputOrOptions,
|
|
985
|
+
options
|
|
986
|
+
);
|
|
987
|
+
const path = `/drops/${encodeURIComponent(dropId)}/deployments`;
|
|
988
|
+
return publishStaged(this.transport, prepared, path, options);
|
|
989
|
+
}
|
|
990
|
+
request(method, path, options = {}) {
|
|
991
|
+
return this.transport.request(method, path, options);
|
|
992
|
+
}
|
|
993
|
+
requestSignedUpload(url, bytes, headers) {
|
|
994
|
+
return this.transport.putSignedUrl(url, bytes, headers);
|
|
995
|
+
}
|
|
996
|
+
};
|
|
997
|
+
function looksLikeOptionsOnly(input) {
|
|
998
|
+
if (input instanceof Uint8Array) return false;
|
|
999
|
+
if (typeof input !== "object" || input === null) return false;
|
|
1000
|
+
return !("content" in input || "files" in input);
|
|
1001
|
+
}
|
|
1002
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1003
|
+
0 && (module.exports = {
|
|
1004
|
+
DeploymentsResource,
|
|
1005
|
+
Dropthis,
|
|
1006
|
+
UploadsResource,
|
|
1007
|
+
createErrorResult,
|
|
1008
|
+
redactSecrets
|
|
1009
|
+
});
|
|
1010
|
+
//# sourceMappingURL=index.cjs.map
|