@hyperscale0/sdk 3.0.0 → 3.1.0

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/client.d.ts CHANGED
@@ -5,8 +5,15 @@ import type {
5
5
  } from "./platform.js";
6
6
  export type * from "./platform.js";
7
7
 
8
+ import type {
9
+ sandbox_rehearsal_createOutput,
10
+ payment_reminder_delivery_retrieveOutput,
11
+ } from "../../generated/sdk/tenant_portal.ts";
12
+
8
13
  export interface ClientOptions {
9
- apiKey: string;
14
+ apiKey?: string;
15
+ sessionToken?: string;
16
+ staffTenantId?: string;
10
17
  productId: string;
11
18
  baseUrl?: string;
12
19
  environment?: "sandbox" | "live";
@@ -18,6 +25,13 @@ export interface ActionInput {
18
25
  input?: Record<string, unknown>;
19
26
  }
20
27
  export interface Client {
28
+ rehearse(
29
+ name: string,
30
+ options: { idempotencyKey: string },
31
+ ): Promise<sandbox_rehearsal_createOutput>;
32
+ reminderDelivery(
33
+ operationId: string,
34
+ ): Promise<payment_reminder_delivery_retrieveOutput>;
21
35
  discover(): Promise<{
22
36
  instruments: product_instruments_listOutput;
23
37
  actions: product_actions_listOutput;
package/client.js CHANGED
@@ -1,11 +1,20 @@
1
1
  export function createClient({
2
2
  apiKey,
3
+ sessionToken,
4
+ staffTenantId,
3
5
  productId,
4
6
  baseUrl = "https://hyperscale0.ai",
5
7
  environment = "sandbox",
6
8
  }) {
7
- if (!apiKey || !productId)
8
- throw new Error("apiKey and productId are required");
9
+ if (
10
+ !apiKey === !sessionToken ||
11
+ !productId ||
12
+ (staffTenantId && !sessionToken)
13
+ )
14
+ throw new Error(
15
+ "Choose one API key or session token and a Product; staff requires a session",
16
+ );
17
+ const credential = sessionToken ?? apiKey;
9
18
  const origin = new URL(baseUrl);
10
19
  if (
11
20
  origin.origin !== baseUrl ||
@@ -22,7 +31,7 @@ export function createClient({
22
31
  const response = await fetch(new URL(path, origin), {
23
32
  method: input === undefined ? "GET" : "POST",
24
33
  headers: {
25
- authorization: `Bearer ${apiKey}`,
34
+ authorization: `Bearer ${credential}`,
26
35
  "x-hyperscale-environment": environment,
27
36
  ...(input === undefined ? {} : { "content-type": "application/json" }),
28
37
  ...(idempotencyKey ? { "idempotency-key": idempotencyKey } : {}),
@@ -38,13 +47,34 @@ export function createClient({
38
47
  );
39
48
  error.status = response.status;
40
49
  error.code = result?.error?.code;
50
+ error.details = result?.error?.details;
41
51
  error.requestId = response.headers.get("x-request-id");
42
52
  throw error;
43
53
  }
44
54
  return result;
45
55
  }
46
56
  const productPath = `/v1/products/${encodeURIComponent(productId)}`;
57
+ const actionPath = staffTenantId
58
+ ? `/v1/admin/tenants/${encodeURIComponent(staffTenantId)}/products/${encodeURIComponent(productId)}/operations`
59
+ : sessionToken
60
+ ? `${productPath}/operations`
61
+ : "/v1/operations";
47
62
  return {
63
+ rehearse: (name, { idempotencyKey } = {}) => {
64
+ if (!sessionToken || staffTenantId || !idempotencyKey)
65
+ throw new Error(
66
+ "rehearse requires a tenant session and idempotency key",
67
+ );
68
+ return request(
69
+ "/v1/sandbox/rehearsals",
70
+ { productId, name },
71
+ idempotencyKey,
72
+ );
73
+ },
74
+ reminderDelivery: (operationId) =>
75
+ request(
76
+ `${productPath}/payment-reminders/${encodeURIComponent(operationId)}`,
77
+ ),
48
78
  discover: async () => {
49
79
  const [instruments, actions] = await Promise.all([
50
80
  request(`${productPath}/instruments`),
@@ -71,7 +101,7 @@ export function createClient({
71
101
  if (!idempotencyKey)
72
102
  throw new Error("act requires an idempotencyKey for safe retries");
73
103
  return request(
74
- `/v1/operations/${encodeURIComponent(name)}`,
104
+ `${actionPath}/${encodeURIComponent(name)}`,
75
105
  input,
76
106
  idempotencyKey,
77
107
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperscale0/sdk",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "license": "LicenseRef-Hyperscale-Proprietary",
@@ -22,5 +22,5 @@
22
22
  "publishConfig": {
23
23
  "access": "public"
24
24
  },
25
- "gitHead": "ceeb9999f9724709720171ecbd457ac180941901"
25
+ "gitHead": "1ffed3f20362cb9e934d527f1df3e9d35585347c"
26
26
  }