@nosana/api 2.5.0 → 2.5.1

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.
@@ -10,7 +10,7 @@ function idempotencyInit({ idempotencyKey } = {}) {
10
10
  export function createNosanaJobsApi(client) {
11
11
  return {
12
12
  async get(address) {
13
- const { data, error } = await client.GET('/api/jobs/{address}', {
13
+ const { data, error, response } = await client.GET('/api/jobs/{address}', {
14
14
  params: {
15
15
  path: {
16
16
  address
@@ -18,22 +18,22 @@ export function createNosanaJobsApi(client) {
18
18
  }
19
19
  });
20
20
  if (error || !data) {
21
- throw errorFormatter('Failed to get job', error);
21
+ throw errorFormatter('Failed to get job', error, response);
22
22
  }
23
23
  return data;
24
24
  },
25
25
  async list(request, options) {
26
- const { data, error } = await client.POST('/api/jobs/list', {
26
+ const { data, error, response } = await client.POST('/api/jobs/list', {
27
27
  body: request,
28
28
  ...idempotencyInit(options),
29
29
  });
30
30
  if (error || !data) {
31
- throw errorFormatter('Failed to list job', error);
31
+ throw errorFormatter('Failed to list job', error, response);
32
32
  }
33
33
  return data;
34
34
  },
35
35
  async extend({ address, ...request }, options) {
36
- const { data, error } = await client.POST('/api/jobs/{address}/extend', {
36
+ const { data, error, response } = await client.POST('/api/jobs/{address}/extend', {
37
37
  params: {
38
38
  path: {
39
39
  address
@@ -43,12 +43,12 @@ export function createNosanaJobsApi(client) {
43
43
  ...idempotencyInit(options),
44
44
  });
45
45
  if (error || !data) {
46
- throw errorFormatter('Failed to extend job', error);
46
+ throw errorFormatter('Failed to extend job', error, response);
47
47
  }
48
48
  return data;
49
49
  },
50
50
  async stop(address, options) {
51
- const { data, error } = await client.POST('/api/jobs/{address}/stop', {
51
+ const { data, error, response } = await client.POST('/api/jobs/{address}/stop', {
52
52
  params: {
53
53
  path: {
54
54
  address
@@ -57,7 +57,7 @@ export function createNosanaJobsApi(client) {
57
57
  ...idempotencyInit(options),
58
58
  });
59
59
  if (error || !data) {
60
- throw errorFormatter('Failed to stop job', error);
60
+ throw errorFormatter('Failed to stop job', error, response);
61
61
  }
62
62
  return data;
63
63
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/routes/jobs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAgB/D,cAAc,YAAY,CAAC;AAE3B;;;GAGG;AACH,SAAS,eAAe,CAAC,EAAE,cAAc,KAA6B,EAAE;IACtE,OAAO,cAAc,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,iBAAiB,EAAE,cAAc,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAClF,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,MAAmB;IACrD,OAAO;QACL,KAAK,CAAC,GAAG,CAAC,OAAwC;YAChD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,qBAAqB,EAAE;gBAC9D,MAAM,EAAE;oBACN,IAAI,EAAE;wBACJ,OAAO;qBACR;iBACF;aACF,CAAC,CAAC;YAEH,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;gBACnB,MAAM,cAAc,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;YACnD,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,OAAgC,EAAE,OAAgC;YAC3E,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,gBAAgB,EAAE;gBAC1D,IAAI,EAAE,OAAO;gBACb,GAAG,eAAe,CAAC,OAAO,CAAC;aAC5B,CAAC,CAAC;YAEH,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;gBACnB,MAAM,cAAc,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;YACpD,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;QACD,KA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BACnB,MAAM,cAAc,CAAC,sBAAsB,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;YAChE,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,OAAgC,EAAE,OAAgC;YAC3E,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,0BAA0B,EAAE;gBAC9E,MAAM,EAAE;oBACN,IAAI,EAAE;wBACJ,OAAO;qBACR;iBACF;gBACD,GAAG,eAAe,CAAC,OAAO,CAAC;aAC5B,CAAC,CAAC;YAEH,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;gBACnB,MAAM,cAAc,CAAC,oBAAoB,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;YAC9D,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,6 +1,8 @@
1
1
  export interface ApiError extends Error {
2
2
  code?: string;
3
3
  statusCode?: number;
4
+ /** Raw `Retry-After` header value, when present (e.g. on a 409 IN_PROGRESS). */
5
+ retryAfter?: string;
4
6
  details?: unknown;
5
7
  }
6
8
  interface ErrorResponse {
@@ -9,6 +11,15 @@ interface ErrorResponse {
9
11
  code?: string;
10
12
  statusCode?: number;
11
13
  }
12
- export declare function errorFormatter(customMessage: string, errorObject?: ErrorResponse | unknown): ApiError;
14
+ /**
15
+ * Builds an {@link ApiError} from an openapi-fetch failure.
16
+ *
17
+ * The HTTP status and `Retry-After` are taken from `response` rather than the
18
+ * error body: the status is a property of the response, so reading it from
19
+ * `response.status` stays correct for error shapes that don't echo a status —
20
+ * proxy/gateway 5xx, framework default error pages, etc. A body `statusCode`,
21
+ * when present, still wins so existing payloads are unaffected.
22
+ */
23
+ export declare function errorFormatter(customMessage: string, errorObject?: ErrorResponse | unknown, response?: Response): ApiError;
13
24
  export {};
14
25
  //# sourceMappingURL=errorFormatter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errorFormatter.d.ts","sourceRoot":"","sources":["../../src/utils/errorFormatter.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAS,SAAQ,KAAK;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,aAAa;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,cAAc,CAC5B,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,aAAa,GAAG,OAAO,GACpC,QAAQ,CA2BV"}
1
+ {"version":3,"file":"errorFormatter.d.ts","sourceRoot":"","sources":["../../src/utils/errorFormatter.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAS,SAAQ,KAAK;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gFAAgF;IAChF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,aAAa;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,aAAa,GAAG,OAAO,EACrC,QAAQ,CAAC,EAAE,QAAQ,GAClB,QAAQ,CAsCV"}
@@ -1,14 +1,31 @@
1
- export function errorFormatter(customMessage, errorObject) {
1
+ /**
2
+ * Builds an {@link ApiError} from an openapi-fetch failure.
3
+ *
4
+ * The HTTP status and `Retry-After` are taken from `response` rather than the
5
+ * error body: the status is a property of the response, so reading it from
6
+ * `response.status` stays correct for error shapes that don't echo a status —
7
+ * proxy/gateway 5xx, framework default error pages, etc. A body `statusCode`,
8
+ * when present, still wins so existing payloads are unaffected.
9
+ */
10
+ export function errorFormatter(customMessage, errorObject, response) {
2
11
  const err = new Error();
12
+ // Response-derived metadata is independent of the error body.
13
+ const bodyStatus = typeof errorObject === 'object' && errorObject !== null
14
+ ? errorObject.statusCode
15
+ : undefined;
16
+ err.statusCode = bodyStatus ?? response?.status;
17
+ const retryAfter = response?.headers?.get('retry-after');
18
+ if (retryAfter) {
19
+ err.retryAfter = retryAfter;
20
+ }
3
21
  if (!errorObject) {
4
22
  err.message = customMessage;
5
23
  return err;
6
24
  }
7
25
  if (typeof errorObject === 'object' && errorObject !== null) {
8
- const { error, message, code, statusCode } = errorObject;
26
+ const { error, message, code } = errorObject;
9
27
  err.message = `${customMessage}: ${error || message || 'Unknown error'}`;
10
28
  err.code = code;
11
- err.statusCode = statusCode;
12
29
  err.details = errorObject;
13
30
  return err;
14
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"errorFormatter.js","sourceRoot":"","sources":["../../src/utils/errorFormatter.ts"],"names":[],"mappings":"AAaA,MAAM,UAAU,cAAc,CAC5B,aAAqB,EACrB,WAAqC;IAErC,MAAM,GAAG,GAAG,IAAI,KAAK,EAAc,CAAC;IAEpC,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,GAAG,CAAC,OAAO,GAAG,aAAa,CAAC;QAC5B,OAAO,GAAG,CAAC;IACb,CAAC;IAED,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,WAAW,KAAK,IAAI,EAAE,CAAC;QAC5D,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,WAA4B,CAAC;QAE1E,GAAG,CAAC,OAAO,GAAG,GAAG,aAAa,KAAK,KAAK,IAAI,OAAO,IAAI,eAAe,EA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QAC5D,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,WAA4B,CAAC;QAE9D,GAAG,CAAC,OAAO,GAAG,GAAG,aAAa,KAAK,KAAK,IAAI,OAAO,IAAI,eAAe,EAAE,CAAC;QACzE,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;QAChB,GAAG,CAAC,OAAO,GAAG,WAAW,CAAC;QAE1B,OAAO,GAAG,CAAC;IACb,CAAC;IAED,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;QACpC,GAAG,CAAC,OAAO,GAAG,GAAG,aAAa,KAAK,WAAW,EAAE,CAAC;QACjD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,GAAG,CAAC,OAAO,GAAG,aAAa,CAAC;IAC5B,GAAG,CAAC,OAAO,GAAG,WAAW,CAAC;IAC1B,OAAO,GAAG,CAAC;AACb,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nosana/api",
3
- "version": "2.5.0",
3
+ "version": "2.5.1",
4
4
  "description": "Nosana API module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -52,5 +52,5 @@
52
52
  "engines": {
53
53
  "node": ">=20.18.0"
54
54
  },
55
- "gitHead": "5b07b02e8e37562784ddb9302ecaba7921d992ef"
55
+ "gitHead": "e3d3b1b9c487b248f0c501a7455540ae01391cea"
56
56
  }