@needle-tools/gltf-build-pipeline 3.0.0-alpha → 3.0.0-next.3fbb1fc
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/cli/index.js +49 -26
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -1190,7 +1190,7 @@ function registerExtensions(node) {
|
|
|
1190
1190
|
import { createTransform } from "@gltf-transform/functions";
|
|
1191
1191
|
|
|
1192
1192
|
// src/utils/version.gen.ts
|
|
1193
|
-
var version = "3.0.0-
|
|
1193
|
+
var version = "3.0.0-next.3fbb1fc";
|
|
1194
1194
|
|
|
1195
1195
|
// src/utils/version.ts
|
|
1196
1196
|
function getVersion(_marklocal = !0) {
|
|
@@ -3901,7 +3901,7 @@ function trackPipelineEnd(info) {
|
|
|
3901
3901
|
}
|
|
3902
3902
|
|
|
3903
3903
|
// src/auth/verify.ts
|
|
3904
|
-
import { jwtVerify, importJWK } from "jose";
|
|
3904
|
+
import { jwtVerify, importJWK, decodeProtectedHeader } from "jose";
|
|
3905
3905
|
|
|
3906
3906
|
// src/auth/keys.ts
|
|
3907
3907
|
var PROD_KEYS = [
|
|
@@ -3926,28 +3926,51 @@ var AuthError = class extends Error {
|
|
|
3926
3926
|
constructor(message) {
|
|
3927
3927
|
super(message), this.name = "AuthError";
|
|
3928
3928
|
}
|
|
3929
|
-
};
|
|
3929
|
+
}, LOCAL_LICENSE_URL = "http://localhost:8424/api/license", LOCAL_FETCH_TIMEOUT_MS = 2e3;
|
|
3930
|
+
async function tryFetchLocalToken(org) {
|
|
3931
|
+
try {
|
|
3932
|
+
let url = new URL(LOCAL_LICENSE_URL);
|
|
3933
|
+
org && url.searchParams.set("org", org);
|
|
3934
|
+
let res = await fetch(url, {
|
|
3935
|
+
signal: AbortSignal.timeout(LOCAL_FETCH_TIMEOUT_MS)
|
|
3936
|
+
});
|
|
3937
|
+
if (!res.ok) return null;
|
|
3938
|
+
let jwt = (await res.json()).needle_license_jwt;
|
|
3939
|
+
return typeof jwt == "string" && jwt.length > 0 ? jwt : null;
|
|
3940
|
+
} catch {
|
|
3941
|
+
return null;
|
|
3942
|
+
}
|
|
3943
|
+
}
|
|
3944
|
+
async function verifyWithKey(token, key, opts) {
|
|
3945
|
+
if (!key.alg) throw new AuthError(`trusted key '${key.kid ?? "?"}' is missing 'alg'`);
|
|
3946
|
+
let keyObj = await importJWK(key, key.alg);
|
|
3947
|
+
await jwtVerify(token, keyObj, opts?.requireExp ? { requiredClaims: ["exp"] } : void 0);
|
|
3948
|
+
}
|
|
3930
3949
|
async function verifyAuthToken(token) {
|
|
3931
3950
|
if (!token)
|
|
3932
3951
|
throw new AuthError("no token provided");
|
|
3933
3952
|
if (token.startsWith("nc_"))
|
|
3934
3953
|
throw new AuthError("NEEDLE_CLOUD_TOKEN is a needle-cloud access token (nc_*), not a JWT.");
|
|
3935
3954
|
try {
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
throw new AuthError("token header missing 'kid'");
|
|
3955
|
+
let header = decodeProtectedHeader(token);
|
|
3956
|
+
if (header.kid) {
|
|
3939
3957
|
let match = TRUSTED_KEYS.find((k) => k.kid === header.kid);
|
|
3940
3958
|
if (!match)
|
|
3941
3959
|
throw new AuthError(`token signed by unknown key '${header.kid}'`);
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3960
|
+
await verifyWithKey(token, match, { requireExp: !0 });
|
|
3961
|
+
} else {
|
|
3962
|
+
let lastError = null;
|
|
3963
|
+
for (let key of TRUSTED_KEYS)
|
|
3964
|
+
try {
|
|
3965
|
+
await verifyWithKey(token, key);
|
|
3966
|
+
return;
|
|
3967
|
+
} catch (err) {
|
|
3968
|
+
lastError = err;
|
|
3969
|
+
}
|
|
3970
|
+
if (lastError instanceof AuthError) throw lastError;
|
|
3971
|
+
let message = lastError instanceof Error ? lastError.message : String(lastError);
|
|
3972
|
+
throw new AuthError(message || "no trusted key could verify this token");
|
|
3973
|
+
}
|
|
3951
3974
|
} catch (err) {
|
|
3952
3975
|
if (err instanceof AuthError) throw err;
|
|
3953
3976
|
if (err && typeof err == "object" && "code" in err) {
|
|
@@ -3961,17 +3984,17 @@ async function verifyAuthToken(token) {
|
|
|
3961
3984
|
throw new AuthError(message);
|
|
3962
3985
|
}
|
|
3963
3986
|
}
|
|
3964
|
-
async function requireAuth(cliToken) {
|
|
3987
|
+
async function requireAuth(cliToken, org) {
|
|
3965
3988
|
let token = typeof cliToken == "string" && cliToken.length > 0 ? cliToken : process.env.NEEDLE_CLOUD_TOKEN;
|
|
3966
|
-
if (!token)
|
|
3967
|
-
throw new AuthError("pass --auth-token or set NEEDLE_CLOUD_TOKEN");
|
|
3989
|
+
if ((!token || typeof token == "string" && token.length === 0) && (token = await tryFetchLocalToken(org ?? process.env.NEEDLE_CLOUD_ORG)), !token)
|
|
3990
|
+
throw new AuthError("pass --auth-token or set NEEDLE_CLOUD_TOKEN (or log in to the needle-cloud CLI)");
|
|
3968
3991
|
await verifyAuthToken(token);
|
|
3969
3992
|
}
|
|
3970
3993
|
|
|
3971
3994
|
// src/cli/index.ts
|
|
3972
|
-
async function gateAuth(authToken, logger) {
|
|
3995
|
+
async function gateAuth(authToken, org, logger) {
|
|
3973
3996
|
try {
|
|
3974
|
-
await requireAuth(authToken);
|
|
3997
|
+
await requireAuth(authToken, typeof org == "string" ? org : void 0);
|
|
3975
3998
|
} catch (err) {
|
|
3976
3999
|
let message = err instanceof AuthError || err instanceof Error ? err.message : String(err);
|
|
3977
4000
|
logger.error(`[Needle Build Pipeline] Auth failed: ${message}`), process.exit(ERROR_CODES.AUTH_FAILED);
|
|
@@ -3985,8 +4008,8 @@ Caches are limited to ${cacheSizeLimit} MB disc space by default.
|
|
|
3985
4008
|
`).action(async ({ logger }) => {
|
|
3986
4009
|
logger.info("Clearing caches"), clearCache(logger);
|
|
3987
4010
|
}).command("stats", "Calculate glTF stats").help(`
|
|
3988
|
-
`).argument("<input>", "Path to a glTF, GLB or VRM file OR a directory").argument("<output>", "Output path for the stats", { default: null, validator: program.STRING }).option("--verbose", "Enable verbose output", { validator: program.BOOLEAN, default: !1 }).option("--auth-token <jwt>", "Required. A JWT minted by needle-cloud (alternatively set NEEDLE_CLOUD_TOKEN). Note: an `nc_*` needle-cloud access token is NOT a JWT and will be rejected.", { validator: program.STRING }).action(async ({ logger, args, options }) => {
|
|
3989
|
-
await gateAuth(options.authToken, logger), logger.level = options.verbose ? "debug" : "info", await ensureHashReady(), logger.info('Calculating stats for "' + args.input + '"');
|
|
4011
|
+
`).argument("<input>", "Path to a glTF, GLB or VRM file OR a directory").argument("<output>", "Output path for the stats", { default: null, validator: program.STRING }).option("--verbose", "Enable verbose output", { validator: program.BOOLEAN, default: !1 }).option("--auth-token <jwt>", "Required. A JWT minted by needle-cloud (alternatively set NEEDLE_CLOUD_TOKEN). Note: an `nc_*` needle-cloud access token is NOT a JWT and will be rejected.", { validator: program.STRING }).option("--org <org>", "Organization ID for local license-server fallback (or set NEEDLE_CLOUD_ORG).", { validator: program.STRING }).action(async ({ logger, args, options }) => {
|
|
4012
|
+
await gateAuth(options.authToken, options.org, logger), logger.level = options.verbose ? "debug" : "info", await ensureHashReady(), logger.info('Calculating stats for "' + args.input + '"');
|
|
3990
4013
|
let input = args.input.toString(), filestats = new Array();
|
|
3991
4014
|
await foreachGLTF(input, async (file) => {
|
|
3992
4015
|
let stats = await calculateStats(file, { verbose: !!options.verbose });
|
|
@@ -3998,8 +4021,8 @@ Caches are limited to ${cacheSizeLimit} MB disc space by default.
|
|
|
3998
4021
|
This will produce multiple versions of the input file, each with a different level of optimization.
|
|
3999
4022
|
Each version will be compressed and written to the output directory.
|
|
4000
4023
|
`).argument("<input>", "The input glTF, GLB or VRM file that should be compressed OR a directory that contains files to be compressed. Multiple files can be separated by commas.", { validator: program.STRING }).argument("<output>", "The output file or directory. It can be an absolute path or a relative path to the input file. If not provided, the input file will be overwritten.", { default: null, validator: program.STRING }).option("--compress", "When enabled files will be compressed", { validator: program.BOOLEAN, default: !0 }).option("--progressive", "When enabled files will processed to be progressively loaded", { validator: program.BOOLEAN, default: !0 }).option("--usecase <usecase>", `The usecase for the compression. This will set the compression settings. Possible options: [${UsecaseOptions.join(", ")}]`, { validator: program.STRING }).option("--config <config>", 'The path to a JSON file containing the compression settings. This can also be a needle.config.json file with a "compression" object or usecase string.', { validator: program.STRING }).option("--cache", `Use "--cache False" to disable caching.
|
|
4001
|
-
When caching is enabled then previously processed files will be detected and loaded from disc cache instead of being processed again if settings or the file contents have not changed.`, { validator: program.BOOLEAN, default: !0 }).option("--debug", 'Enable for more verbose outout with "--debug True"', { validator: program.BOOLEAN, default: !1 }).option("--verbose", 'Enable for more verbose outout with "--verbose True"', { validator: program.BOOLEAN, default: !1 }).option("--auth-token <jwt>", "Required. A JWT minted by needle-cloud (alternatively set NEEDLE_CLOUD_TOKEN). Note: an `nc_*` needle-cloud access token is NOT a JWT and will be rejected.", { validator: program.STRING }).action(async ({ logger, args, options }) => {
|
|
4002
|
-
if (await gateAuth(options.authToken, logger), logger.level = options.debug || options.verbose ? "debug" : "info", options.compress === !1 && options.progressive === !1) {
|
|
4024
|
+
When caching is enabled then previously processed files will be detected and loaded from disc cache instead of being processed again if settings or the file contents have not changed.`, { validator: program.BOOLEAN, default: !0 }).option("--debug", 'Enable for more verbose outout with "--debug True"', { validator: program.BOOLEAN, default: !1 }).option("--verbose", 'Enable for more verbose outout with "--verbose True"', { validator: program.BOOLEAN, default: !1 }).option("--auth-token <jwt>", "Required. A JWT minted by needle-cloud (alternatively set NEEDLE_CLOUD_TOKEN). Note: an `nc_*` needle-cloud access token is NOT a JWT and will be rejected.", { validator: program.STRING }).option("--org <org>", "Organization ID for local license-server fallback (or set NEEDLE_CLOUD_ORG).", { validator: program.STRING }).action(async ({ logger, args, options }) => {
|
|
4025
|
+
if (await gateAuth(options.authToken, options.org, logger), logger.level = options.debug || options.verbose ? "debug" : "info", options.compress === !1 && options.progressive === !1) {
|
|
4003
4026
|
logger.error(`[Needle Build Pipeline] v${getVersion()} You need to enable at least one of the options: --compress or --progressive`);
|
|
4004
4027
|
return;
|
|
4005
4028
|
}
|
|
@@ -4116,8 +4139,8 @@ When caching is enabled then previously processed files will be detected and loa
|
|
|
4116
4139
|
producing <name>.pmrem.ktx2. This is the same processing the Needle build pipeline
|
|
4117
4140
|
applies to EXR textures inside GLB/GLTF files, exposed as a standalone command for
|
|
4118
4141
|
raw .exr / .hdr inputs.
|
|
4119
|
-
`).argument("<input>", "Path to a .exr/.hdr file OR a directory containing .exr/.hdr files (recursive)", { validator: program.STRING }).argument("<output>", "Output file (when input is a single .exr/.hdr) or output directory. Defaults to writing next to the input file.", { default: null, validator: program.STRING }).option("--cache", 'Use "--cache False" to disable caching.', { validator: program.BOOLEAN, default: !0 }).option("--debug", 'Enable verbose output with "--debug True"', { validator: program.BOOLEAN, default: !1 }).option("--verbose", 'Enable verbose output with "--verbose True"', { validator: program.BOOLEAN, default: !1 }).option("--auth-token <jwt>", "Required. A JWT minted by needle-cloud (alternatively set NEEDLE_CLOUD_TOKEN). Note: an `nc_*` needle-cloud access token is NOT a JWT and will be rejected.", { validator: program.STRING }).hide().action(async ({ logger, args, options }) => {
|
|
4120
|
-
await gateAuth(options.authToken, logger), logger.level = options.debug || options.verbose ? "debug" : "info", await ensureHashReady();
|
|
4142
|
+
`).argument("<input>", "Path to a .exr/.hdr file OR a directory containing .exr/.hdr files (recursive)", { validator: program.STRING }).argument("<output>", "Output file (when input is a single .exr/.hdr) or output directory. Defaults to writing next to the input file.", { default: null, validator: program.STRING }).option("--cache", 'Use "--cache False" to disable caching.', { validator: program.BOOLEAN, default: !0 }).option("--debug", 'Enable verbose output with "--debug True"', { validator: program.BOOLEAN, default: !1 }).option("--verbose", 'Enable verbose output with "--verbose True"', { validator: program.BOOLEAN, default: !1 }).option("--auth-token <jwt>", "Required. A JWT minted by needle-cloud (alternatively set NEEDLE_CLOUD_TOKEN). Note: an `nc_*` needle-cloud access token is NOT a JWT and will be rejected.", { validator: program.STRING }).option("--org <org>", "Organization ID for local license-server fallback (or set NEEDLE_CLOUD_ORG).", { validator: program.STRING }).hide().action(async ({ logger, args, options }) => {
|
|
4143
|
+
await gateAuth(options.authToken, options.org, logger), logger.level = options.debug || options.verbose ? "debug" : "info", await ensureHashReady();
|
|
4121
4144
|
let input = args.input.toString();
|
|
4122
4145
|
existsSync13(input) || (logger.error(`Input does not exist: ${input}`), process.exit(ERROR_CODES.INVALID_ARGS));
|
|
4123
4146
|
let inputFiles = [], inputIsDirectory = isDirectory(input);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/gltf-build-pipeline",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-next.3fbb1fc",
|
|
4
4
|
"description": "Pipeline and tools for optimizing gltf files using gltf-transform and compression settings within glTF extensions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|