@superartifacts/sdk 0.1.1 → 0.1.2

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
@@ -74,8 +74,8 @@ Per request: `{ idempotencyKey, timeout, signal, headers }`.
74
74
  ## Errors
75
75
 
76
76
  Every failure is a `SuperArtifactsError` with `status`, `code`, `message` and, when the API asked
77
- you to wait, `retryAfter` in seconds. Anything else the API said is in `details`. A missing key
78
- throws before any request, so that `AuthenticationError` has no `status` or `code`.
77
+ you to wait, `retryAfter` in seconds. Anything else the API said is in `details`. A client-side
78
+ failure has `status` 0 and its own `code`: a missing key is an `AuthenticationError` with `missing_api_key`.
79
79
 
80
80
  | Class | When |
81
81
  | --- | --- |
package/dist/index.cjs CHANGED
@@ -53,8 +53,8 @@ var SuperArtifactsError = class extends Error {
53
53
  constructor(status, code, message, retryAfter, details = {}, options) {
54
54
  super(message, options);
55
55
  this.name = new.target.name;
56
- if (status !== void 0) this.status = status;
57
- if (code !== void 0) this.code = code;
56
+ this.status = status;
57
+ this.code = code;
58
58
  if (retryAfter !== void 0) this.retryAfter = retryAfter;
59
59
  this.details = details;
60
60
  }
@@ -121,7 +121,7 @@ function errorFor(status, text, retryAfterHeader) {
121
121
  }
122
122
 
123
123
  // src/core.ts
124
- var VERSION = "0.1.1";
124
+ var VERSION = "0.1.2";
125
125
  var DEFAULT_BASE_URL = "https://superartifacts.app";
126
126
  var API_KEY_ENV = "SUPERARTIFACTS_API_KEY";
127
127
  var MAX_RETRY_AFTER_SECONDS = 60;
@@ -161,8 +161,8 @@ var Core = class {
161
161
  const apiKey = options.apiKey ?? globalThis.process?.env?.[API_KEY_ENV];
162
162
  if (!apiKey) {
163
163
  throw new AuthenticationError(
164
- void 0,
165
- void 0,
164
+ 0,
165
+ "missing_api_key",
166
166
  `No API key. Pass { apiKey } or set ${API_KEY_ENV}. Create one at https://superartifacts.app/settings/api-keys.`
167
167
  );
168
168
  }
@@ -237,8 +237,7 @@ var Core = class {
237
237
  const text = await response.text();
238
238
  if (response.ok) return parseAnswer(text, response.status);
239
239
  failure = errorFor(response.status, text, response.headers.get("retry-after"));
240
- const { status } = response;
241
- const { retryAfter } = failure;
240
+ const { status, retryAfter } = failure;
242
241
  if (status === 429 || retry && [502, 503, 504].includes(status)) {
243
242
  if (retryAfter !== void 0) delay = retryAfter * 1e3;
244
243
  retry = left && (retryAfter ?? 0) <= MAX_RETRY_AFTER_SECONDS;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- declare const VERSION = "0.1.1";
1
+ declare const VERSION = "0.1.2";
2
2
  interface ClientOptions {
3
3
  /** Defaults to the SUPERARTIFACTS_API_KEY environment variable. */
4
4
  apiKey?: string;
@@ -77,19 +77,16 @@ declare class Core {
77
77
  protected send(url: URL | string, init: RequestInit, repeatable: boolean, options?: RequestOptions): Promise<Record<string, unknown>>;
78
78
  }
79
79
 
80
- /**
81
- * Anything this SDK throws for a failed call. `status` is 0 when no answer arrived, and it
82
- * and `code` are absent when no request was made: an `AuthenticationError` for a missing key.
83
- */
80
+ /** Anything this SDK throws for a failed call. `status` is 0 when no answer arrived. */
84
81
  declare class SuperArtifactsError extends Error {
85
- readonly status?: number;
82
+ readonly status: number;
86
83
  /** Stable and machine-readable; `message` is for a person. */
87
- readonly code?: string;
84
+ readonly code: string;
88
85
  /** Seconds the API asked to wait. */
89
86
  readonly retryAfter?: number;
90
87
  /** Everything else the API said, e.g. `fix` or `approvalUrl`. */
91
88
  readonly details: Record<string, unknown>;
92
- constructor(status: number | undefined, code: string | undefined, message: string, retryAfter?: number, details?: Record<string, unknown>, options?: ErrorOptions);
89
+ constructor(status: number, code: string, message: string, retryAfter?: number, details?: Record<string, unknown>, options?: ErrorOptions);
93
90
  }
94
91
  declare class InvalidArgumentsError extends SuperArtifactsError {
95
92
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- declare const VERSION = "0.1.1";
1
+ declare const VERSION = "0.1.2";
2
2
  interface ClientOptions {
3
3
  /** Defaults to the SUPERARTIFACTS_API_KEY environment variable. */
4
4
  apiKey?: string;
@@ -77,19 +77,16 @@ declare class Core {
77
77
  protected send(url: URL | string, init: RequestInit, repeatable: boolean, options?: RequestOptions): Promise<Record<string, unknown>>;
78
78
  }
79
79
 
80
- /**
81
- * Anything this SDK throws for a failed call. `status` is 0 when no answer arrived, and it
82
- * and `code` are absent when no request was made: an `AuthenticationError` for a missing key.
83
- */
80
+ /** Anything this SDK throws for a failed call. `status` is 0 when no answer arrived. */
84
81
  declare class SuperArtifactsError extends Error {
85
- readonly status?: number;
82
+ readonly status: number;
86
83
  /** Stable and machine-readable; `message` is for a person. */
87
- readonly code?: string;
84
+ readonly code: string;
88
85
  /** Seconds the API asked to wait. */
89
86
  readonly retryAfter?: number;
90
87
  /** Everything else the API said, e.g. `fix` or `approvalUrl`. */
91
88
  readonly details: Record<string, unknown>;
92
- constructor(status: number | undefined, code: string | undefined, message: string, retryAfter?: number, details?: Record<string, unknown>, options?: ErrorOptions);
89
+ constructor(status: number, code: string, message: string, retryAfter?: number, details?: Record<string, unknown>, options?: ErrorOptions);
93
90
  }
94
91
  declare class InvalidArgumentsError extends SuperArtifactsError {
95
92
  }
package/dist/index.js CHANGED
@@ -10,8 +10,8 @@ var SuperArtifactsError = class extends Error {
10
10
  constructor(status, code, message, retryAfter, details = {}, options) {
11
11
  super(message, options);
12
12
  this.name = new.target.name;
13
- if (status !== void 0) this.status = status;
14
- if (code !== void 0) this.code = code;
13
+ this.status = status;
14
+ this.code = code;
15
15
  if (retryAfter !== void 0) this.retryAfter = retryAfter;
16
16
  this.details = details;
17
17
  }
@@ -78,7 +78,7 @@ function errorFor(status, text, retryAfterHeader) {
78
78
  }
79
79
 
80
80
  // src/core.ts
81
- var VERSION = "0.1.1";
81
+ var VERSION = "0.1.2";
82
82
  var DEFAULT_BASE_URL = "https://superartifacts.app";
83
83
  var API_KEY_ENV = "SUPERARTIFACTS_API_KEY";
84
84
  var MAX_RETRY_AFTER_SECONDS = 60;
@@ -118,8 +118,8 @@ var Core = class {
118
118
  const apiKey = options.apiKey ?? globalThis.process?.env?.[API_KEY_ENV];
119
119
  if (!apiKey) {
120
120
  throw new AuthenticationError(
121
- void 0,
122
- void 0,
121
+ 0,
122
+ "missing_api_key",
123
123
  `No API key. Pass { apiKey } or set ${API_KEY_ENV}. Create one at https://superartifacts.app/settings/api-keys.`
124
124
  );
125
125
  }
@@ -194,8 +194,7 @@ var Core = class {
194
194
  const text = await response.text();
195
195
  if (response.ok) return parseAnswer(text, response.status);
196
196
  failure = errorFor(response.status, text, response.headers.get("retry-after"));
197
- const { status } = response;
198
- const { retryAfter } = failure;
197
+ const { status, retryAfter } = failure;
199
198
  if (status === 429 || retry && [502, 503, 504].includes(status)) {
200
199
  if (retryAfter !== void 0) delay = retryAfter * 1e3;
201
200
  retry = left && (retryAfter ?? 0) <= MAX_RETRY_AFTER_SECONDS;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superartifacts/sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "The TypeScript SDK for the Super Artifacts REST API: publish artifacts, read their data, and manage projects, shares and templates from a server.",
5
5
  "license": "MIT",
6
6
  "type": "module",