@statelyai/sdk 0.11.0 → 0.12.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/dist/studio.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import { createAuthorizationHeader, getCredentialToken } from "./auth.mjs";
2
+
1
3
  //#region src/studio.ts
2
4
  var StudioApiError = class extends Error {
3
5
  status;
@@ -79,10 +81,19 @@ function connectedReposMatch(left, right) {
79
81
  function createStatelyClient(options = {}) {
80
82
  const baseUrl = options.baseUrl ?? "https://stately.ai";
81
83
  const fetchImpl = getFetch(options.fetch);
82
- async function request(path, init = {}, apiKeyOverride) {
84
+ const defaultCredential = options.credential ?? (options.apiKey ? {
85
+ type: "api_key",
86
+ token: options.apiKey
87
+ } : void 0);
88
+ const defaultAuthMode = options.authMode ?? "auto";
89
+ async function request(path, init = {}, credentialOverride, authModeOverride) {
83
90
  const headers = new Headers(init.headers);
84
- const apiKey = apiKeyOverride ?? options.apiKey;
85
- if (apiKey) headers.set("Authorization", `Bearer ${apiKey}`);
91
+ const authMode = authModeOverride ?? defaultAuthMode;
92
+ const credential = credentialOverride ?? defaultCredential;
93
+ if (authMode !== "none") {
94
+ if (!getCredentialToken(credential) || !credential) throw new StudioApiError("No Stately credential configured. Pass createStatelyClient({ credential }) or set authMode: \"none\" for no-auth self-hosted deployments.", 401);
95
+ headers.set("Authorization", createAuthorizationHeader(credential));
96
+ }
86
97
  const response = await fetchImpl(joinApiUrl(baseUrl, path), {
87
98
  ...init,
88
99
  headers
@@ -92,8 +103,8 @@ function createStatelyClient(options = {}) {
92
103
  return unwrapResponseData(data);
93
104
  }
94
105
  return {
95
- auth: { verify(apiKey) {
96
- return request("/verify", { method: "GET" }, apiKey);
106
+ auth: { verify(credential) {
107
+ return request("/verify", { method: "GET" }, credential);
97
108
  } },
98
109
  projects: {
99
110
  list() {
@@ -143,12 +154,15 @@ function createStatelyClient(options = {}) {
143
154
  }
144
155
  },
145
156
  code: { extractMachines(code, extractOptions = {}) {
146
- const apiKey = extractOptions.apiKey ?? options.apiKey ?? "anonymous";
157
+ const credential = extractOptions.credential ?? (extractOptions.apiKey ? {
158
+ type: "api_key",
159
+ token: extractOptions.apiKey
160
+ } : void 0);
147
161
  return request("/code", {
148
162
  method: "POST",
149
163
  headers: { "Content-Type": "application/json" },
150
164
  body: JSON.stringify({ code })
151
- }, apiKey);
165
+ }, credential, extractOptions.authMode);
152
166
  } }
153
167
  };
154
168
  }
package/dist/sync.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { b as DigraphConfig, i as StatelyGraph } from "./graph-GeuH-mFK.mjs";
1
+ import { b as DigraphConfig, i as StatelyGraph } from "./graph-CszT5J6W.mjs";
2
2
  import { CreateProjectInput, ProjectData, StudioClient, StudioMachineRecord, XStateVersion } from "./studio.mjs";
3
3
  import { GraphDiff } from "@statelyai/graph";
4
4