@needle-tools/gltf-build-pipeline 3.0.0-beta.1 → 3.0.0-beta.1.1b06064

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.
Files changed (2) hide show
  1. package/dist/cli/index.js +52 -28
  2. package/package.json +1 -1
package/dist/cli/index.js CHANGED
@@ -1194,7 +1194,7 @@ function registerExtensions(node) {
1194
1194
  import { createTransform } from "@gltf-transform/functions";
1195
1195
 
1196
1196
  // src/utils/version.gen.ts
1197
- var version = "3.0.0-beta.1";
1197
+ var version = "3.0.0-beta.1.1b06064";
1198
1198
 
1199
1199
  // src/utils/version.ts
1200
1200
  function getVersion(_marklocal = !0) {
@@ -3735,9 +3735,30 @@ async function calculateStats(inputfile, options) {
3735
3735
  return createNewFilestats(inputfile, document, json);
3736
3736
  }
3737
3737
 
3738
+ // src/utils/logfile.ts
3739
+ import { appendFileSync, existsSync as existsSync12, mkdirSync as mkdirSync8, renameSync, statSync as statSync6 } from "fs";
3740
+ import { join as join8 } from "path";
3741
+ import { homedir } from "os";
3742
+ var LOG_DIR = join8(homedir(), ".needle", "optimization-pipeline", "logs"), LOG_FILE = join8(LOG_DIR, "pipeline.log"), PREV_LOG_FILE = join8(LOG_DIR, "pipeline.prev.log"), MAX_LOG_BYTES = 1024 * 1024;
3743
+ function redactSecrets(message) {
3744
+ return message.replace(/([a-z][a-z0-9+.-]*:\/\/)[^/@\s]+@/gi, "$1").replace(/\b[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, "[REDACTED_JWT]").replace(/\bnc_[A-Za-z0-9_-]{6,}\b/g, "[REDACTED_TOKEN]");
3745
+ }
3746
+ function logToFile(message) {
3747
+ try {
3748
+ mkdirSync8(LOG_DIR, { recursive: !0 });
3749
+ try {
3750
+ existsSync12(LOG_FILE) && statSync6(LOG_FILE).size > MAX_LOG_BYTES && renameSync(LOG_FILE, PREV_LOG_FILE);
3751
+ } catch {
3752
+ }
3753
+ appendFileSync(LOG_FILE, `[${(/* @__PURE__ */ new Date()).toISOString()}] ${redactSecrets(message)}
3754
+ `);
3755
+ } catch {
3756
+ }
3757
+ }
3758
+
3738
3759
  // src/config/index.ts
3739
3760
  import { Logger as Logger3, Verbosity as Verbosity4 } from "@gltf-transform/core";
3740
- import { existsSync as existsSync12, readFileSync as readFileSync9, statSync as statSync6 } from "fs";
3761
+ import { existsSync as existsSync13, readFileSync as readFileSync9, statSync as statSync7 } from "fs";
3741
3762
  import path6, { dirname as dirname7, resolve as resolve2 } from "path";
3742
3763
  var UsecaseOptions = ["product", "world"], defaultConfig = {
3743
3764
  usecase: "default"
@@ -3752,9 +3773,9 @@ function createConfig(usecase) {
3752
3773
  function getConfig(configPath, fallbackSearchDirectory, opts) {
3753
3774
  let logger = opts?.logger;
3754
3775
  if (logger || (logger = new Logger3(Verbosity4.WARN)), configPath != null) {
3755
- if (configPath = resolve2(process.cwd(), configPath), !existsSync12(configPath))
3776
+ if (configPath = resolve2(process.cwd(), configPath), !existsSync13(configPath))
3756
3777
  throw new Error(`No config found at "${configPath}"`);
3757
- if (statSync6(configPath).isDirectory()) {
3778
+ if (statSync7(configPath).isDirectory()) {
3758
3779
  let res2 = searchConfig(configPath, logger);
3759
3780
  if (res2)
3760
3781
  return res2;
@@ -3775,9 +3796,9 @@ function getConfig(configPath, fallbackSearchDirectory, opts) {
3775
3796
  }
3776
3797
  var _cachedConfig;
3777
3798
  function searchConfig(directory, logger) {
3778
- for (statSync6(directory).isFile() && (directory = dirname7(directory)), directory = directory.replaceAll("\\", "/"); directory.length > 0; ) {
3799
+ for (statSync7(directory).isFile() && (directory = dirname7(directory)), directory = directory.replaceAll("\\", "/"); directory.length > 0; ) {
3779
3800
  let configPath = path6.join(directory, "needle.config.json");
3780
- if (existsSync12(configPath)) {
3801
+ if (existsSync13(configPath)) {
3781
3802
  let content = readFileSync9(configPath, "utf8"), config = resolveConfig(configPath, content, logger);
3782
3803
  if (config)
3783
3804
  return config;
@@ -3809,7 +3830,7 @@ function resolveConfig(filename, content, logger) {
3809
3830
  }
3810
3831
 
3811
3832
  // src/cli/index.ts
3812
- import { existsSync as existsSync14, readFileSync as readFileSync11, readdirSync as readdirSync3, statSync as statSync7, writeFileSync as writeFileSync7 } from "fs";
3833
+ import { existsSync as existsSync15, readFileSync as readFileSync11, readdirSync as readdirSync3, statSync as statSync8, writeFileSync as writeFileSync7 } from "fs";
3813
3834
  import path7, { basename as basename4, dirname as dirname8, resolve as resolve3 } from "path";
3814
3835
 
3815
3836
  // src/constants.ts
@@ -3926,9 +3947,9 @@ var PROD_KEYS = [
3926
3947
  var trusted = [...PROD_KEYS], TRUSTED_KEYS = trusted;
3927
3948
 
3928
3949
  // src/auth/verify.ts
3929
- import { readFileSync as readFileSync10, existsSync as existsSync13 } from "fs";
3930
- import { join as join8 } from "path";
3931
- import { homedir } from "os";
3950
+ import { readFileSync as readFileSync10, existsSync as existsSync14 } from "fs";
3951
+ import { join as join9 } from "path";
3952
+ import { homedir as homedir2 } from "os";
3932
3953
  var AuthError = class extends Error {
3933
3954
  constructor(message) {
3934
3955
  super(message), this.name = "AuthError";
@@ -3936,29 +3957,32 @@ var AuthError = class extends Error {
3936
3957
  }, LOCAL_FETCH_TIMEOUT_MS = 2e3;
3937
3958
  function getLocalServerToken() {
3938
3959
  try {
3939
- let file = join8(homedir(), ".needle", "local-server-token");
3940
- if (!existsSync13(file)) return null;
3960
+ let file = join9(homedir2(), ".needle", "local-server-token");
3961
+ if (!existsSync14(file)) return null;
3941
3962
  let data = JSON.parse(readFileSync10(file, "utf-8"));
3942
3963
  return typeof data.token == "string" ? data.token : null;
3943
- } catch {
3944
- return null;
3964
+ } catch (err) {
3965
+ return logToFile(`[auth] failed reading local-server-token (${err instanceof Error ? err.name : "unknown error"})`), null;
3945
3966
  }
3946
3967
  }
3947
3968
  async function tryFetchLocalToken(org) {
3969
+ let baseUrl = process.env.NEEDLE_LICENSE_SERVER_URL || "http://localhost:8424/api/license", safeServer = "local license server";
3948
3970
  try {
3949
- let baseUrl = process.env.NEEDLE_LICENSE_SERVER_URL || "http://localhost:8424/api/license", url = new URL(baseUrl);
3950
- org && url.searchParams.set("org", org);
3971
+ let url = new URL(baseUrl);
3972
+ org && url.searchParams.set("org", org), safeServer = `${url.origin}${url.pathname}`;
3951
3973
  let headers = {}, serverToken = getLocalServerToken();
3952
3974
  serverToken && (headers.Authorization = `Bearer ${serverToken}`);
3953
3975
  let res = await fetch(url, {
3954
3976
  signal: AbortSignal.timeout(LOCAL_FETCH_TIMEOUT_MS),
3955
3977
  headers
3956
3978
  });
3957
- if (!res.ok) return null;
3979
+ if (!res.ok)
3980
+ return logToFile(`[auth] license server (${safeServer}) returned HTTP ${res.status} ${res.statusText}${org ? ` \u2014 verify the --org value "${org}"` : ""}`), null;
3958
3981
  let jwt = (await res.json()).needle_license_jwt;
3959
- return typeof jwt == "string" && jwt.length > 0 ? jwt : null;
3960
- } catch {
3961
- return null;
3982
+ return typeof jwt == "string" && jwt.length > 0 ? jwt : (logToFile(`[auth] license server (${safeServer}) responded without a license token${org ? ` for org "${org}"` : ""}`), null);
3983
+ } catch (err) {
3984
+ let msg = err instanceof Error ? err.message : String(err);
3985
+ return logToFile(`[auth] could not reach license server (${safeServer})${org ? ` for org "${org}"` : ""}: ${msg}`), null;
3962
3986
  }
3963
3987
  }
3964
3988
  async function verifyWithKey(token, key) {
@@ -4023,7 +4047,7 @@ async function gateAuth(authToken, org, logger) {
4023
4047
  await requireAuth(authToken, typeof org == "string" ? org : void 0);
4024
4048
  } catch (err) {
4025
4049
  let message = err instanceof AuthError || err instanceof Error ? err.message : String(err);
4026
- logger.error(`[Needle Build Pipeline] Auth failed: ${message}`), process.exit(ERROR_CODES.AUTH_FAILED);
4050
+ logger.error(`[Needle Build Pipeline] v${getVersion()} Auth failed: ${message}`), logToFile(`[Needle Build Pipeline] v${getVersion()} Auth failed: ${message}`), process.exit(ERROR_CODES.AUTH_FAILED);
4027
4051
  }
4028
4052
  }
4029
4053
  program.cast(!1);
@@ -4077,7 +4101,7 @@ When caching is enabled then previously processed files will be detected and loa
4077
4101
  }
4078
4102
  let set = /* @__PURE__ */ new Set(), useCache = options.cache !== !1, debug = options.debug === !0, verbose = options.verbose === !0;
4079
4103
  await foreachGLTF(inputPaths, async (file) => {
4080
- if (existsSync14(file)) {
4104
+ if (existsSync15(file)) {
4081
4105
  if (file != input && options.progressive === !0 && isLOD(file)) {
4082
4106
  logger.debug(`\u2192 Ignore existing LOD file at ${file}`);
4083
4107
  return;
@@ -4093,12 +4117,12 @@ When caching is enabled then previously processed files will be detected and loa
4093
4117
  config
4094
4118
  }, file) : void 0;
4095
4119
  if (jobKey) {
4096
- let outputDir = output ? existsSync14(output) && isDirectory(output) ? output : dirname8(output) : dirname8(file), restored = tryRestoreJobResult(jobKey, outputDir, logger);
4120
+ let outputDir = output ? existsSync15(output) && isDirectory(output) ? output : dirname8(output) : dirname8(file), restored = tryRestoreJobResult(jobKey, outputDir, logger);
4097
4121
  if (restored) {
4098
- let inputFileSize = statSync7(file).size / 1024 / 1024;
4122
+ let inputFileSize = statSync8(file).size / 1024 / 1024;
4099
4123
  for (let f of restored)
4100
4124
  if (set.add(f), stats) {
4101
- let sizeInMB = statSync7(f).size / 1024 / 1024;
4125
+ let sizeInMB = statSync8(f).size / 1024 / 1024;
4102
4126
  stats.totalFilesProcessed++, stats.totalFileSizeInMB += sizeInMB, stats.totalFileSizeInMBBefore += inputFileSize;
4103
4127
  }
4104
4128
  logger.info(`\u2192 [CACHE] Restored ${restored.length} file(s) for job ${jobKey}`);
@@ -4169,7 +4193,7 @@ raw .exr / .hdr inputs.
4169
4193
  `).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: "", 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 }) => {
4170
4194
  warnUnknownOptions(options, logger), await gateAuth(options.authToken, options.org, logger), logger.level = options.debug || options.verbose ? "debug" : "info", await ensureHashReady();
4171
4195
  let input = args.input.toString();
4172
- existsSync14(input) || (logger.error(`Input does not exist: ${input}`), process.exit(ERROR_CODES.INVALID_ARGS));
4196
+ existsSync15(input) || (logger.error(`Input does not exist: ${input}`), process.exit(ERROR_CODES.INVALID_ARGS));
4173
4197
  let inputFiles = [], inputIsDirectory = isDirectory(input);
4174
4198
  if (inputIsDirectory ? collectPmremInputFiles(input, inputFiles) : isPmremInputFile(input) ? inputFiles.push(input) : (logger.error(`Input is not an .exr/.hdr file or directory: ${input}`), process.exit(ERROR_CODES.INVALID_ARGS)), inputFiles.length === 0) {
4175
4199
  logger.warn(`No .exr/.hdr files found in ${input}`);
@@ -4208,7 +4232,7 @@ function collectPmremInputFiles(dir, out) {
4208
4232
  for (let entry of readdirSync3(dir)) {
4209
4233
  if (entry === "node_modules" || entry.startsWith(".")) continue;
4210
4234
  let full = path7.join(dir, entry);
4211
- statSync7(full).isDirectory() ? collectPmremInputFiles(full, out) : isPmremInputFile(entry) && out.push(full);
4235
+ statSync8(full).isDirectory() ? collectPmremInputFiles(full, out) : isPmremInputFile(entry) && out.push(full);
4212
4236
  }
4213
4237
  }
4214
4238
  function resolvePmremOutputPath(srcPath, input, inputIsDirectory, outputArg) {
@@ -4219,7 +4243,7 @@ function resolvePmremOutputPath(srcPath, input, inputIsDirectory, outputArg) {
4219
4243
  let rel = path7.relative(input, srcPath), relDir = dirname8(rel), outDir = relDir === "." ? outputArg : path7.join(outputArg, relDir);
4220
4244
  return ensureIsDirectory(outDir), path7.join(outDir, outName);
4221
4245
  }
4222
- return existsSync14(outputArg) && isDirectory(outputArg) ? path7.join(outputArg, outName) : outputArg.toLowerCase().endsWith(".ktx2") ? (ensureIsDirectory(dirname8(outputArg)), outputArg) : (ensureIsDirectory(outputArg), path7.join(outputArg, outName));
4246
+ return existsSync15(outputArg) && isDirectory(outputArg) ? path7.join(outputArg, outName) : outputArg.toLowerCase().endsWith(".ktx2") ? (ensureIsDirectory(dirname8(outputArg)), outputArg) : (ensureIsDirectory(outputArg), path7.join(outputArg, outName));
4223
4247
  }
4224
4248
  program.run().catch((err) => {
4225
4249
  if (!(err.message.includes("Unknown command") && !err.message.includes("Did you mean")))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/gltf-build-pipeline",
3
- "version": "3.0.0-beta.1",
3
+ "version": "3.0.0-beta.1.1b06064",
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": {