@hyperscale0/sdk 1.0.382 → 1.0.385

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/CHANGELOG.md CHANGED
@@ -4,6 +4,18 @@
4
4
 
5
5
  Newest first. A release that changed nothing the SDK sees has no entry.
6
6
 
7
+ ## Unreleased
8
+
9
+ ### Added
10
+
11
+ - `HyperscaleError.trace`, with `gate` and `remedy` lifted from it: the admission gate that refused, its law in one sentence, the facts it saw and the remedy, an operation with the fields to change or the person who must act. `RefusalTrace` types it.
12
+
13
+ - `client.call(name, input, { rehearse: true })` runs a mutation with no effect. The client sends `X-Hyperscale-Rehearsal: true`, and the call answers `OperationRehearsal`: the would-be `outcome`, `status`, `output` or `error`, receipt and ledger `postings`. A platform read refuses the option.
14
+
15
+ ### Changed
16
+
17
+ - `bank_statement` joined the `resourceKind` union: `activity.list` takes it as a filter and `activity.retrieve` can answer with it. An exhaustive switch over `resourceKind` needs the new case.
18
+
7
19
  ## 1.0.364
8
20
 
9
21
  ### Added
package/README.md CHANGED
@@ -93,7 +93,7 @@ With the type argument, a kind such as `"day-pass"` when the Product has `day_pa
93
93
 
94
94
  ## Errors and retries
95
95
 
96
- Every refusal is a `HyperscaleError` with the server's `message`, `code`, `status`, `details` and `requestId`, plus `nextStep` and `shortfall` when the server sends them. When no readable answer arrives (a timeout, a dropped connection, an HTML error page), the client throws `HyperscaleConnectionError`: the call may have run, so retry it with the same `idempotencyKey`.
96
+ Every refusal is a `HyperscaleError` with the server's `message`, `code`, `status`, `details` and `requestId`, plus `nextStep` and `shortfall` when the server sends them, and `trace` with `gate` and `remedy`: which admission gate refused, its law, the facts it saw and what would let the call pass ([errors](../../docs/public/api.md#errors)). When no readable answer arrives (a timeout, a dropped connection, an HTML error page), the client throws `HyperscaleConnectionError`: the call may have run, so retry it with the same `idempotencyKey`.
97
97
 
98
98
  The client makes an idempotency key for every write that needs one and keeps it across its own retries. Pass `{ idempotencyKey }` as the third argument to choose it. Reads retry on 408, 429 and 5xx, and writes retry only under a key. Set `timeout` (default 30000 ms) and `maxRetries` (default 2) in `createClient`.
99
99
 
package/client.d.ts CHANGED
@@ -1,13 +1,19 @@
1
1
  import type {
2
2
  ErrorCode,
3
+ ErrorResponse,
3
4
  ListOperations,
4
- Operations,
5
+ OperationRehearsal,
6
+ OperationsFor,
5
7
  product_objects_actionsOutput,
6
8
  product_objects_discoverOutput,
7
9
  product_objects_executeOutput,
10
+ RehearsableOperation,
8
11
  } from "./platform.js";
9
12
  export type * from "./platform.js";
10
13
 
14
+ /** The operations a Product key or a customer session may call. */
15
+ export type Operations = OperationsFor<"api_key" | "customer_session">;
16
+
11
17
  export interface ClientOptions {
12
18
  /** A Product key from `hyperscale key create`. */
13
19
  apiKey?: string;
@@ -31,6 +37,11 @@ export interface CallOptions {
31
37
  idempotencyKey?: string;
32
38
  turnstileToken?: string;
33
39
  headers?: Record<string, string>;
40
+ /**
41
+ * True runs a mutation with no effect: admission and execution run, nothing
42
+ * is kept, and the call answers OperationRehearsal in place of its output.
43
+ */
44
+ rehearse?: boolean;
34
45
  }
35
46
 
36
47
  /** One action of a generated Product type: subject fields and input. */
@@ -139,8 +150,17 @@ export declare class HyperscaleError extends Error {
139
150
  readonly nextStep?: string;
140
151
  /** Minor units missing from the paying account, when money ran short. */
141
152
  readonly shortfall?: string;
153
+ /** Which admission gate refused, the law it applied, the facts it saw and the remedy. */
154
+ readonly trace?: RefusalTrace;
155
+ /** The refusing gate, from `trace`. */
156
+ readonly gate?: RefusalTrace["gate"];
157
+ /** What would pass: an operation and the fields to change, or who must act. */
158
+ readonly remedy?: RefusalTrace["remedy"];
142
159
  }
143
160
 
161
+ /** The refusal trace every error body carries; see docs/design/refusals.md. */
162
+ export type RefusalTrace = NonNullable<ErrorResponse["error"]["trace"]>;
163
+
144
164
  /** No readable answer: the request may have run. Retry with the same key. */
145
165
  export declare class HyperscaleConnectionError extends HyperscaleError {
146
166
  readonly code: "connection_error";
@@ -155,10 +175,16 @@ export declare function isHyperscaleError(
155
175
  export interface Client<P extends ProductTypes = ProductTypes> {
156
176
  /** The Product's object kinds, their fields and their actions. */
157
177
  discover(): Promise<product_objects_discoverOutput>;
178
+ /** A rehearsed mutation: what it would do, with nothing kept. */
179
+ call<Name extends keyof Operations & RehearsableOperation>(
180
+ name: Name,
181
+ input: ProductCallInput<P, Name>,
182
+ options: CallOptions & { rehearse: true },
183
+ ): Promise<OperationRehearsal>;
158
184
  call<Name extends keyof Operations>(
159
185
  name: Name,
160
186
  input: ProductCallInput<P, Name>,
161
- options?: CallOptions,
187
+ options?: CallOptions & { rehearse?: false },
162
188
  ): Promise<Operations[Name]["output"]>;
163
189
  /** An operation of your own Product, by id or name from `key create`. */
164
190
  call<Name extends string>(
@@ -175,7 +201,7 @@ export interface Client<P extends ProductTypes = ProductTypes> {
175
201
  paginate<Name extends keyof ListOperations & keyof Operations>(
176
202
  name: Name,
177
203
  input: ProductCallInput<P, Name>,
178
- options?: CallOptions,
204
+ options?: Omit<CallOptions, "rehearse">,
179
205
  ): AsyncGenerator<ListItem<Name>, void, undefined>;
180
206
  objects: {
181
207
  /** Reads the action's current state, then runs it. */