@superartifacts/sdk 0.1.0 → 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
@@ -1,7 +1,10 @@
1
1
  # @superartifacts/sdk
2
2
 
3
3
  The TypeScript SDK for the [Super Artifacts](https://superartifacts.app) REST API. No runtime
4
- dependencies. Node 20.3+, Bun, Deno and Cloudflare Workers.
4
+ dependencies.
5
+
6
+ Node 20.3+. It uses only the standard `fetch`, so other runtimes that provide it may work; only
7
+ Node is tested.
5
8
 
6
9
  ```bash
7
10
  npm install @superartifacts/sdk
@@ -9,6 +12,8 @@ npm install @superartifacts/sdk
9
12
 
10
13
  **Server-side only.** The API refuses any request carrying an `Origin` header, which means every
11
14
  browser, and a key on a page is a leaked key. The client throws if you construct it in a browser.
15
+ `dangerouslyAllowBrowser: true` turns that check off for use behind your own proxy, and ships the
16
+ key to every visitor.
12
17
 
13
18
  ## Quickstart
14
19
 
@@ -43,9 +48,12 @@ Every method takes one object holding the operation's path, query and body field
43
48
  optional second argument for this request alone:
44
49
 
45
50
  ```ts
46
- await sa.artifacts.update({ artifact: 'hello', visibility: 'private' }, { timeout: 10_000 })
51
+ await sa.artifacts.update({ artifact: 'hello', visibility: 'private' }, { timeout: 30_000 })
47
52
  ```
48
53
 
54
+ Responses are untyped JSON until the API describes them: every result is an open object, so
55
+ destructure and index it without a cast.
56
+
49
57
  Resources: `account`, `artifacts`, `live`, `uploads`, `data`, `schema`, `entries`, `secrets`,
50
58
  `templates`, `projects`, `shares`, `comments`, `mentions`, `signatures`.
51
59
 
@@ -66,12 +74,13 @@ Per request: `{ idempotencyKey, timeout, signal, headers }`.
66
74
  ## Errors
67
75
 
68
76
  Every failure is a `SuperArtifactsError` with `status`, `code`, `message` and, when the API asked
69
- you to wait, `retryAfter` in seconds. Anything else the API said is in `details`.
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`.
70
79
 
71
80
  | Class | When |
72
81
  | --- | --- |
73
82
  | `InvalidArgumentsError` | 400 |
74
- | `AuthenticationError` | 401 |
83
+ | `AuthenticationError` | 401, or no key to send |
75
84
  | `PlanLimitError` | 402 |
76
85
  | `PermissionError` | 403 `forbidden` |
77
86
  | `ScopeRequiredError` | 403 `scope_required`: a read key called a write |
package/dist/index.cjs CHANGED
@@ -121,7 +121,7 @@ function errorFor(status, text, retryAfterHeader) {
121
121
  }
122
122
 
123
123
  // src/core.ts
124
- var VERSION = "0.1.0";
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;
@@ -160,8 +160,10 @@ var Core = class {
160
160
  }
161
161
  const apiKey = options.apiKey ?? globalThis.process?.env?.[API_KEY_ENV];
162
162
  if (!apiKey) {
163
- throw new Error(
164
- `No API key. Set ${API_KEY_ENV} or pass { apiKey }. Create one at https://superartifacts.app/settings/api-keys`
163
+ throw new AuthenticationError(
164
+ 0,
165
+ "missing_api_key",
166
+ `No API key. Pass { apiKey } or set ${API_KEY_ENV}. Create one at https://superartifacts.app/settings/api-keys.`
165
167
  );
166
168
  }
167
169
  this.#apiKey = apiKey;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- declare const VERSION = "0.1.0";
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;
@@ -45,6 +45,13 @@ type Query<Op> = Op extends {
45
45
  } ? [NonNullable<Q>] extends [never] ? object : NonNullable<Q> : object;
46
46
  /** Path, query and body fields of an operation, in one object. */
47
47
  type Params<Op> = Path<Op> & Query<Op> & Body<Op>;
48
+ type JsonObject = {
49
+ [key: string]: any;
50
+ };
51
+ /** R's named properties, without the index signature an open object carries. */
52
+ type Declared<R> = keyof {
53
+ [K in keyof R as string extends K ? never : K]: unknown;
54
+ };
48
55
  type Result<Op> = Op extends {
49
56
  responses: {
50
57
  200: {
@@ -53,7 +60,7 @@ type Result<Op> = Op extends {
53
60
  };
54
61
  };
55
62
  };
56
- } ? R : unknown;
63
+ } ? [Declared<R>] extends [never] ? JsonObject : R : unknown;
57
64
  declare class Core {
58
65
  #private;
59
66
  constructor(options?: ClientOptions);
@@ -2349,7 +2356,7 @@ declare class Resources extends Core {
2349
2356
  readonly signatures: SignaturesResource;
2350
2357
  }
2351
2358
 
2352
- type Row = Record<string, unknown>;
2359
+ type Row = JsonObject;
2353
2360
  declare class Data extends DataResource {
2354
2361
  /** Every row `listArtifactRows` matches, page by page. */
2355
2362
  iterArtifactRows(params: Params<operations['listArtifactRows']>, options?: RequestOptions): AsyncGenerator<Row>;
@@ -2386,4 +2393,4 @@ declare class SuperArtifacts extends Resources {
2386
2393
  }
2387
2394
 
2388
2395
  export { AuthenticationError, ConflictError, ConnectionError, InternalError, InvalidArgumentsError, NotFoundError, OPERATIONS, PayloadTooLargeError, PermissionError, PlanLimitError, RateLimitError, ScopeRequiredError, SuperArtifacts, SuperArtifactsError, TimeoutError, VERSION, SuperArtifacts as default, errorFor };
2389
- export type { ClientOptions, FileToUpload, Operation, Params, RequestOptions, Result, components, operations };
2396
+ export type { ClientOptions, FileToUpload, JsonObject, Operation, Params, RequestOptions, Result, components, operations };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- declare const VERSION = "0.1.0";
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;
@@ -45,6 +45,13 @@ type Query<Op> = Op extends {
45
45
  } ? [NonNullable<Q>] extends [never] ? object : NonNullable<Q> : object;
46
46
  /** Path, query and body fields of an operation, in one object. */
47
47
  type Params<Op> = Path<Op> & Query<Op> & Body<Op>;
48
+ type JsonObject = {
49
+ [key: string]: any;
50
+ };
51
+ /** R's named properties, without the index signature an open object carries. */
52
+ type Declared<R> = keyof {
53
+ [K in keyof R as string extends K ? never : K]: unknown;
54
+ };
48
55
  type Result<Op> = Op extends {
49
56
  responses: {
50
57
  200: {
@@ -53,7 +60,7 @@ type Result<Op> = Op extends {
53
60
  };
54
61
  };
55
62
  };
56
- } ? R : unknown;
63
+ } ? [Declared<R>] extends [never] ? JsonObject : R : unknown;
57
64
  declare class Core {
58
65
  #private;
59
66
  constructor(options?: ClientOptions);
@@ -2349,7 +2356,7 @@ declare class Resources extends Core {
2349
2356
  readonly signatures: SignaturesResource;
2350
2357
  }
2351
2358
 
2352
- type Row = Record<string, unknown>;
2359
+ type Row = JsonObject;
2353
2360
  declare class Data extends DataResource {
2354
2361
  /** Every row `listArtifactRows` matches, page by page. */
2355
2362
  iterArtifactRows(params: Params<operations['listArtifactRows']>, options?: RequestOptions): AsyncGenerator<Row>;
@@ -2386,4 +2393,4 @@ declare class SuperArtifacts extends Resources {
2386
2393
  }
2387
2394
 
2388
2395
  export { AuthenticationError, ConflictError, ConnectionError, InternalError, InvalidArgumentsError, NotFoundError, OPERATIONS, PayloadTooLargeError, PermissionError, PlanLimitError, RateLimitError, ScopeRequiredError, SuperArtifacts, SuperArtifactsError, TimeoutError, VERSION, SuperArtifacts as default, errorFor };
2389
- export type { ClientOptions, FileToUpload, Operation, Params, RequestOptions, Result, components, operations };
2396
+ export type { ClientOptions, FileToUpload, JsonObject, Operation, Params, RequestOptions, Result, components, operations };
package/dist/index.js CHANGED
@@ -78,7 +78,7 @@ function errorFor(status, text, retryAfterHeader) {
78
78
  }
79
79
 
80
80
  // src/core.ts
81
- var VERSION = "0.1.0";
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;
@@ -117,8 +117,10 @@ var Core = class {
117
117
  }
118
118
  const apiKey = options.apiKey ?? globalThis.process?.env?.[API_KEY_ENV];
119
119
  if (!apiKey) {
120
- throw new Error(
121
- `No API key. Set ${API_KEY_ENV} or pass { apiKey }. Create one at https://superartifacts.app/settings/api-keys`
120
+ throw new AuthenticationError(
121
+ 0,
122
+ "missing_api_key",
123
+ `No API key. Pass { apiKey } or set ${API_KEY_ENV}. Create one at https://superartifacts.app/settings/api-keys.`
122
124
  );
123
125
  }
124
126
  this.#apiKey = apiKey;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superartifacts/sdk",
3
- "version": "0.1.0",
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",