@byte_fluffy/nexra-sdk 0.1.0-alpha.29 → 0.1.0-alpha.30

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 CHANGED
@@ -37,6 +37,65 @@ available from `@byte_fluffy/nexra-sdk/media`.
37
37
  The default API base URL is `https://api.nexra-ai.com/v1`. When overriding
38
38
  `baseUrl`, include the `/v1` API prefix.
39
39
 
40
+ ## Error contract migration
41
+
42
+ `0.1.0-alpha.30` introduces the flat public error response and matching SDK
43
+ types and exception getters. Existing HTTP envelopes and historical Task
44
+ objects remain supported as described below.
45
+
46
+ New Nexra responses keep one platform request context at the root:
47
+ `nexraRequestId` and `nexraHttpStatus`. Platform classification is
48
+ `nexraError: { code, message, param? }`. Provider context uses the independent
49
+ root fields `upstreamHttpStatus`, `upstreamRequestId` and `upstreamError`.
50
+ Successful Task receipts and results can carry the platform context without
51
+ an error. New Task results do not duplicate the old `requestId` or `error`
52
+ wrapper. The SDK's exported `Task` and `TaskPage` types describe these public
53
+ results, not the server's internal Task read model.
54
+
55
+ `NexraApiError.status` remains the actual fetch response status. Its read-only
56
+ `code` getter and inherited `message` expose the server's platform classification;
57
+ `nexraError` retains that classification object. Both exception types expose
58
+ `nexraHttpStatus`, `nexraRequestId`, `upstreamHttpStatus`, `upstreamRequestId` and
59
+ `upstreamError`. `NexraTaskError` derives these fields and `taskId` from its
60
+ retained `task`, and has no fetch `status`.
61
+
62
+ Platform HTTP status and request ID describe the same originating request.
63
+ A failed Task can retain its original creation HTTP 202 while a later GET
64
+ returns HTTP 200; its provider might separately return HTTP 400. Missing origin
65
+ evidence is omitted, not inferred from Task failure or a later query. The
66
+ SDK preserves server messages and unknown code strings without localizing or
67
+ reclassifying them. Set `Accept-Language: zh-CN` or `en` through existing client
68
+ `headers` when needed.
69
+
70
+ The SDK accepts old HTTP envelopes and Task error fields internally. Deprecated
71
+ `requestId` and `details` exception getters return `nexraRequestId` and the
72
+ parameter context, without adding serialized aliases. Use `nexraError.param`
73
+ for new parameter handling. Public retry/category hints are removed; the SDK
74
+ no longer exposes `NexraApiError.retryable`.
75
+
76
+ `upstreamError` contains captured provider error content. When an older captured
77
+ body has its own `error` member, input normalization selects that member once;
78
+ otherwise it retains the complete captured error body. An already canonical
79
+ `upstreamError` is not unwrapped again. Provider fields named `requestId`,
80
+ `httpStatus`, `retryable` or `category` remain unchanged. Diagnostic flags such
81
+ as `upstreamRedacted`, `upstreamTruncated`, `upstreamUnavailableReason`,
82
+ `upstreamFormat` and `upstreamEvent` remain available when supplied by the server.
83
+ This diagnostic projection does not rewrite original Native HTTP responses or
84
+ Task outputs.
85
+
86
+ Against older servers, `tasks.get`, `list`, `watch`, `wait` and
87
+ `NexraTaskError.task` retain original Task/Event objects and their historical
88
+ fields. Only exception getters adapt the input shape; the SDK does not clean
89
+ returned objects or manufacture context for old successful responses.
90
+
91
+ HTTP retry behavior is unchanged: eligible HTTP 503 requests make at most three
92
+ attempts by default, and `maxRetries: 0` makes one attempt. Retry decisions use
93
+ the actual fetch status rather than platform or provider payload metadata.
94
+ Retried Task creation keeps the same idempotency key and payload; failed Tasks
95
+ throw `NexraTaskError` without submitting another generation.
96
+ `NexraWaitTimeoutError` remains a local wait timeout with the original `taskId`
97
+ and does not mean generation failed.
98
+
40
99
  ## Model display names
41
100
 
42
101
  `getModelSpec`, `listModelSpecs`, `nexra.models.search`, `nexra.models.get`, and
@@ -1,4 +1,4 @@
1
- import { J as JsonObject } from './json-Drjj1OKl.js';
1
+ import { a as JsonObject } from './json-Cz0MkWQn.js';
2
2
 
3
3
  declare const MEDIA_KINDS: readonly ["image", "video", "audio", "document", "archive", "other"];
4
4
  type MediaKind = (typeof MEDIA_KINDS)[number];
@@ -58,4 +58,4 @@ interface AssetCertificationWaitOptions {
58
58
  signal?: AbortSignal;
59
59
  }
60
60
 
61
- export { type AssetReference as A, MEDIA_KINDS as M, type AssetImportRequest as a, type AssetInput as b, type AssetUploadOptions as c, type MediaAsset as d, type MediaAssetStatus as e, type MediaKind as f, type AssetCertificationRequest as g, type AssetCertification as h, type AssetCertificationWaitOptions as i };
61
+ export { type AssetImportRequest as A, MEDIA_KINDS as M, type AssetInput as a, type AssetReference as b, type AssetUploadOptions as c, type MediaAsset as d, type MediaAssetStatus as e, type MediaKind as f, type AssetCertificationRequest as g, type AssetCertification as h, type AssetCertificationWaitOptions as i };
package/dist/catalog.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { J as JsonObject } from './json-Drjj1OKl.js';
2
- import { H as HttpTransport, N as NexraCatalogChangeParams, a as NexraCatalogChangePage, b as NexraCatalogModelState, c as NexraSalePriceList, C as CreateNexraQuoteRequest, d as NexraQuote, e as CreateNexraDisplayQuoteBatchRequest, f as NexraDisplayQuoteBatch, g as NexraCatalogRevision, h as NexraModelSpec, i as NexraModelEndpointSpec, j as NexraModelSpecFilter } from './media-geometry-nJ7I7ohO.js';
3
- export { M as MediaGeometryField, k as MediaGeometryProjection, l as NexraBillingCurrency, m as NexraCatalogModelIdentity, n as NexraModelOperation, o as NexraSalePrice, p as NexraSettlement, U as UnifiedMediaGeometry, q as applyMediaGeometry, r as decodeMediaGeometry, s as encodeMediaGeometry, t as projectMediaGeometry } from './media-geometry-nJ7I7ohO.js';
1
+ import { a as JsonObject } from './json-Cz0MkWQn.js';
2
+ import { H as HttpTransport, A as NexraCatalogChangeParams, B as NexraCatalogChangePage, D as NexraCatalogModelState, u as NexraSalePriceList, d as CreateNexraQuoteRequest, s as NexraQuote, C as CreateNexraDisplayQuoteBatchRequest, n as NexraDisplayQuoteBatch, m as NexraCatalogRevision, q as NexraModelSpec, E as NexraModelEndpointSpec, r as NexraModelSpecFilter } from './media-geometry-DAVFGry1.js';
3
+ export { e as MediaGeometryField, f as MediaGeometryProjection, l as NexraBillingCurrency, G as NexraCatalogModelIdentity, p as NexraModelOperation, t as NexraSalePrice, v as NexraSettlement, U as UnifiedMediaGeometry, w as applyMediaGeometry, x as decodeMediaGeometry, y as encodeMediaGeometry, z as projectMediaGeometry } from './media-geometry-DAVFGry1.js';
4
4
 
5
5
  declare function formatModelDisplayName(displayName: string): string;
6
6
 
package/dist/catalog.js CHANGED
@@ -9,8 +9,8 @@ import {
9
9
  listModelSpecs,
10
10
  projectMediaGeometry,
11
11
  resolveNexraLanguageReasoning
12
- } from "./chunk-ESV6ODRA.js";
13
- import "./chunk-IEBCNRT4.js";
12
+ } from "./chunk-3CF6PDT3.js";
13
+ import "./chunk-DKQZWIQ7.js";
14
14
  export {
15
15
  CatalogClient,
16
16
  applyMediaGeometry,
@@ -1,6 +1,8 @@
1
1
  import {
2
+ normalizePublicErrorInput,
3
+ pickPublicErrorFields,
2
4
  sortRatioDisplayOrder
3
- } from "./chunk-IEBCNRT4.js";
5
+ } from "./chunk-DKQZWIQ7.js";
4
6
 
5
7
  // src/catalog/generated/audio.generated.json
6
8
  var audio_generated_default = [
@@ -50341,27 +50343,98 @@ function applyNoWatermark(inputSchema, input) {
50341
50343
  // src/errors.ts
50342
50344
  var NexraApiError = class extends Error {
50343
50345
  status;
50344
- code;
50345
- requestId;
50346
- retryable;
50347
- details;
50346
+ nexraError;
50347
+ nexraRequestId;
50348
+ nexraHttpStatus;
50349
+ upstreamHttpStatus;
50350
+ upstreamRequestId;
50351
+ upstreamError;
50352
+ upstreamRedacted;
50353
+ upstreamTruncated;
50354
+ upstreamUnavailableReason;
50355
+ upstreamFormat;
50356
+ upstreamEvent;
50348
50357
  constructor(message, options) {
50349
- super(message);
50358
+ const classification = options.nexraError ?? { code: options.code ?? "api_error", message };
50359
+ const { nexraError, ...metadata } = pickPublicErrorFields({ ...options, nexraError: classification });
50360
+ super(nexraError?.message ?? message);
50350
50361
  this.name = "NexraApiError";
50351
50362
  this.status = options.status;
50352
- this.code = options.code ?? "api_error";
50353
- this.requestId = options.requestId;
50354
- this.retryable = options.retryable ?? false;
50355
- this.details = options.details;
50363
+ this.nexraError = nexraError ?? classification;
50364
+ Object.assign(this, metadata);
50365
+ }
50366
+ get code() {
50367
+ return this.nexraError.code;
50368
+ }
50369
+ /** @deprecated Use nexraRequestId. */
50370
+ get requestId() {
50371
+ return this.nexraRequestId;
50372
+ }
50373
+ /** @deprecated Use nexraError.param. */
50374
+ get details() {
50375
+ return this.nexraError.param ? { param: this.nexraError.param } : void 0;
50356
50376
  }
50357
50377
  };
50358
50378
  var NexraTaskError = class extends Error {
50359
50379
  task;
50360
50380
  constructor(task) {
50361
- super(task.error?.message ?? `Task ${task.id} ended with status ${task.status}`);
50381
+ const fields = pickPublicErrorFields(task);
50382
+ const legacyMessage = Object.hasOwn(task, "nexraError") ? void 0 : task.error?.message;
50383
+ super(fields.nexraError?.message ?? legacyMessage ?? `Task ${task.id} ended with status ${task.status}`);
50362
50384
  this.name = "NexraTaskError";
50363
50385
  this.task = task;
50364
50386
  }
50387
+ get nexraError() {
50388
+ return this.publicFields.nexraError;
50389
+ }
50390
+ get code() {
50391
+ return this.nexraError?.code;
50392
+ }
50393
+ /** @deprecated Use nexraError.param. */
50394
+ get details() {
50395
+ const param = this.nexraError?.param;
50396
+ return param ? { param } : void 0;
50397
+ }
50398
+ /** @deprecated Use nexraRequestId. */
50399
+ get requestId() {
50400
+ return this.nexraRequestId;
50401
+ }
50402
+ get nexraRequestId() {
50403
+ return this.publicFields.nexraRequestId;
50404
+ }
50405
+ get nexraHttpStatus() {
50406
+ return this.publicFields.nexraHttpStatus;
50407
+ }
50408
+ get upstreamHttpStatus() {
50409
+ return this.publicFields.upstreamHttpStatus;
50410
+ }
50411
+ get upstreamRequestId() {
50412
+ return this.publicFields.upstreamRequestId;
50413
+ }
50414
+ get upstreamError() {
50415
+ return this.publicFields.upstreamError;
50416
+ }
50417
+ get upstreamRedacted() {
50418
+ return this.publicFields.upstreamRedacted;
50419
+ }
50420
+ get upstreamTruncated() {
50421
+ return this.publicFields.upstreamTruncated;
50422
+ }
50423
+ get upstreamUnavailableReason() {
50424
+ return this.publicFields.upstreamUnavailableReason;
50425
+ }
50426
+ get upstreamFormat() {
50427
+ return this.publicFields.upstreamFormat;
50428
+ }
50429
+ get upstreamEvent() {
50430
+ return this.publicFields.upstreamEvent;
50431
+ }
50432
+ get publicFields() {
50433
+ return pickPublicErrorFields(this.task);
50434
+ }
50435
+ get taskId() {
50436
+ return this.task.id;
50437
+ }
50365
50438
  };
50366
50439
  var NexraWaitTimeoutError = class extends Error {
50367
50440
  taskId;
@@ -50375,7 +50448,7 @@ var NexraWaitTimeoutError = class extends Error {
50375
50448
  };
50376
50449
 
50377
50450
  // src/generated/version.generated.ts
50378
- var SDK_VERSION = "0.1.0-alpha.29";
50451
+ var SDK_VERSION = "0.1.0-alpha.30";
50379
50452
 
50380
50453
  // src/transport.ts
50381
50454
  var DEFAULT_BASE_URL = "https://api.nexra-ai.com/v1";
@@ -50475,13 +50548,18 @@ async function createApiError(response) {
50475
50548
  payload = await response.clone().json();
50476
50549
  } catch {
50477
50550
  }
50478
- const error = payload?.error;
50479
- return new NexraApiError(error?.message ?? `Nexra API returned HTTP ${response.status}`, {
50551
+ const requestId = response.headers.get("x-request-id") ?? void 0;
50552
+ const normalized = normalizePublicErrorInput(payload, { nexraRequestId: requestId, nexraHttpStatus: response.status });
50553
+ const owner = payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
50554
+ const candidate = Object.hasOwn(owner, "nexraError") ? owner.nexraError : owner.error ?? owner;
50555
+ const error = candidate && typeof candidate === "object" && !Array.isArray(candidate) ? candidate : {};
50556
+ const message = normalized?.nexraError.message ?? (typeof error.message === "string" ? error.message : `Nexra API returned HTTP ${response.status}`);
50557
+ return new NexraApiError(message, {
50558
+ ...normalized,
50480
50559
  status: response.status,
50481
- code: error?.code,
50482
- requestId: error?.requestId ?? response.headers.get("x-request-id") ?? void 0,
50483
- retryable: error?.retryable ?? shouldRetryStatus(response.status),
50484
- details: error?.details
50560
+ code: normalized?.nexraError.code ?? (typeof error.code === "string" ? error.code : void 0),
50561
+ nexraRequestId: normalized?.nexraRequestId ?? requestId,
50562
+ nexraHttpStatus: normalized ? normalized.nexraHttpStatus : requestId ? response.status : void 0
50485
50563
  });
50486
50564
  }
50487
50565
  function isSafeMethod(method) {