@statelyai/sdk 0.5.1 → 0.6.1

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.
@@ -0,0 +1,99 @@
1
+ //#region src/assetStorage.ts
2
+ function sanitizeFileName(name) {
3
+ return name.replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
4
+ }
5
+ function defaultObjectKey({ file, stateNodeId }) {
6
+ const fileName = sanitizeFileName(file.name) || "asset";
7
+ return `${stateNodeId}/${crypto.randomUUID()}-${fileName}`;
8
+ }
9
+ function createProjectObjectKey(projectVersionId) {
10
+ return ({ file }) => {
11
+ const fileName = sanitizeFileName(file.name) || "asset";
12
+ return `${projectVersionId}/${crypto.randomUUID()}-${fileName}`;
13
+ };
14
+ }
15
+ function joinUrl(baseUrl, key) {
16
+ return `${baseUrl.replace(/\/+$/, "")}/${key.split("/").map(encodeURIComponent).join("/")}`;
17
+ }
18
+ async function uploadToTarget(target, file) {
19
+ if (target.method === "POST" || target.fields) {
20
+ const formData = new FormData();
21
+ Object.entries(target.fields ?? {}).forEach(([name, value]) => {
22
+ formData.append(name, value);
23
+ });
24
+ formData.append("file", file);
25
+ const response = await fetch(target.uploadUrl, {
26
+ method: "POST",
27
+ body: formData
28
+ });
29
+ if (!response.ok) throw new Error(`Asset upload failed with ${response.status}`);
30
+ return;
31
+ }
32
+ const response = await fetch(target.uploadUrl, {
33
+ method: target.method ?? "PUT",
34
+ headers: {
35
+ "Content-Type": file.type || "application/octet-stream",
36
+ ...target.headers
37
+ },
38
+ body: file
39
+ });
40
+ if (!response.ok) throw new Error(`Asset upload failed with ${response.status}`);
41
+ }
42
+ function createS3AssetUploadAdapter(options) {
43
+ return {
44
+ accept: options.accept,
45
+ maxFileSize: options.maxFileSize,
46
+ async upload(request) {
47
+ const key = await (options.key ?? defaultObjectKey)(request);
48
+ const target = await options.getUploadTarget({
49
+ ...request,
50
+ key,
51
+ contentType: request.file.type || "application/octet-stream",
52
+ bucket: options.bucket
53
+ });
54
+ await uploadToTarget(target, request.file);
55
+ const url = target.publicUrl ?? (options.publicBaseUrl ? joinUrl(options.publicBaseUrl, key) : void 0);
56
+ if (!url) throw new Error("S3 asset upload adapter requires a publicUrl or publicBaseUrl");
57
+ return {
58
+ url,
59
+ name: request.file.name,
60
+ metadata: {
61
+ bucket: options.bucket,
62
+ key
63
+ }
64
+ };
65
+ }
66
+ };
67
+ }
68
+ function createSupabaseAssetUploadAdapter(options) {
69
+ const bucket = options.bucket ?? "assets";
70
+ return {
71
+ accept: options.accept,
72
+ maxFileSize: options.maxFileSize,
73
+ async upload(request) {
74
+ const storage = options.client.storage.from(bucket);
75
+ const key = await (options.key ?? (options.projectVersionId ? createProjectObjectKey(options.projectVersionId) : defaultObjectKey))(request);
76
+ const { data, error } = await storage.upload(key, request.file, {
77
+ cacheControl: options.cacheControl,
78
+ contentType: request.file.type || "application/octet-stream",
79
+ upsert: options.upsert
80
+ });
81
+ if (error) throw new Error(error.message);
82
+ if (!data?.path) throw new Error("Supabase asset upload did not return a path");
83
+ const publicUrl = storage.getPublicUrl?.(data.path)?.data.publicUrl ?? (options.publicBaseUrl ? joinUrl(options.publicBaseUrl, data.path) : void 0);
84
+ if (!publicUrl) throw new Error("Supabase asset upload adapter requires getPublicUrl or publicBaseUrl");
85
+ return {
86
+ url: publicUrl,
87
+ name: request.file.name,
88
+ metadata: {
89
+ bucket,
90
+ path: data.path,
91
+ key: data.path
92
+ }
93
+ };
94
+ }
95
+ };
96
+ }
97
+
98
+ //#endregion
99
+ export { createS3AssetUploadAdapter, createSupabaseAssetUploadAdapter };
package/dist/cli.d.mts CHANGED
@@ -1,9 +1,60 @@
1
- import "./graph-BfezxFKJ.mjs";
1
+ import { ConnectedRepo, CreateProjectInput, ProjectData, StudioClient } from "./studio.mjs";
2
+ import "./graph-DpBGHZwl.mjs";
2
3
  import { SyncPlan } from "./sync.mjs";
3
4
  import { Command } from "@oclif/core";
4
5
  import * as _oclif_core_interfaces0 from "@oclif/core/interfaces";
5
6
 
6
7
  //#region src/cli.d.ts
8
+ interface StatelySourceConfig {
9
+ include: string[];
10
+ exclude?: string[];
11
+ format: 'xstate' | 'redux' | 'zustand' | 'xgraph' | 'digraph' | 'mermaid' | 'scxml' | 'json' | 'asl-json' | 'asl-yaml' | 'auto';
12
+ xstateVersion?: number;
13
+ }
14
+ interface StatelyProjectConfig {
15
+ $schema: string;
16
+ version: string;
17
+ projectId: string;
18
+ studioUrl: string;
19
+ defaultXStateVersion: number;
20
+ sources: StatelySourceConfig[];
21
+ }
22
+ interface InitProjectOptions {
23
+ apiKey: string;
24
+ baseUrl?: string;
25
+ cwd?: string;
26
+ client?: StudioClient;
27
+ configPath?: string;
28
+ defaultXStateVersion?: number;
29
+ force?: boolean;
30
+ project?: Partial<CreateProjectInput>;
31
+ }
32
+ interface InitProjectResult {
33
+ config: StatelyProjectConfig;
34
+ configPath: string;
35
+ project: ProjectData;
36
+ }
37
+ declare function createStatelyProjectConfig(options: {
38
+ projectId: string;
39
+ studioUrl: string;
40
+ defaultXStateVersion?: number;
41
+ }): StatelyProjectConfig;
42
+ type ApiKeyResolution = {
43
+ apiKey: string;
44
+ detail: string;
45
+ source: 'env' | 'flag' | 'stored';
46
+ } | {
47
+ apiKey?: undefined;
48
+ detail?: undefined;
49
+ source: 'missing';
50
+ };
51
+ declare function getEnvApiKey(): {
52
+ apiKey: string;
53
+ variable: 'NEXT_PUBLIC_STATELY_API_KEY' | 'STATELY_API_KEY';
54
+ } | undefined;
55
+ declare function resolveApiKey(explicitApiKey?: string): Promise<ApiKeyResolution>;
56
+ declare function inferInitProjectName(cwd: string, repo?: ConnectedRepo): string;
57
+ declare function initProject(options: InitProjectOptions): Promise<InitProjectResult>;
7
58
  declare function formatPlanSummary(plan: SyncPlan): string;
8
59
  declare abstract class BaseSyncCommand extends Command {
9
60
  static enableJsonFlag: boolean;
@@ -71,12 +122,59 @@ declare class OpenCommand extends Command {
71
122
  };
72
123
  run(): Promise<void>;
73
124
  }
125
+ declare class InitCommand extends Command {
126
+ static enableJsonFlag: boolean;
127
+ static summary: string;
128
+ static description: string;
129
+ static flags: {
130
+ help: _oclif_core_interfaces0.BooleanFlag<void>;
131
+ 'api-key': _oclif_core_interfaces0.OptionFlag<string | undefined, _oclif_core_interfaces0.CustomOptions>;
132
+ 'base-url': _oclif_core_interfaces0.OptionFlag<string | undefined, _oclif_core_interfaces0.CustomOptions>;
133
+ name: _oclif_core_interfaces0.OptionFlag<string | undefined, _oclif_core_interfaces0.CustomOptions>;
134
+ visibility: _oclif_core_interfaces0.OptionFlag<string, _oclif_core_interfaces0.CustomOptions>;
135
+ force: _oclif_core_interfaces0.BooleanFlag<boolean>;
136
+ };
137
+ run(): Promise<void>;
138
+ }
139
+ declare class LoginCommand extends Command {
140
+ static enableJsonFlag: boolean;
141
+ static summary: string;
142
+ static description: string;
143
+ static flags: {
144
+ help: _oclif_core_interfaces0.BooleanFlag<void>;
145
+ 'api-key': _oclif_core_interfaces0.OptionFlag<string | undefined, _oclif_core_interfaces0.CustomOptions>;
146
+ stdin: _oclif_core_interfaces0.BooleanFlag<boolean>;
147
+ };
148
+ run(): Promise<void>;
149
+ }
150
+ declare class LogoutCommand extends Command {
151
+ static enableJsonFlag: boolean;
152
+ static summary: string;
153
+ static description: string;
154
+ static flags: {
155
+ help: _oclif_core_interfaces0.BooleanFlag<void>;
156
+ };
157
+ run(): Promise<void>;
158
+ }
159
+ declare class AuthStatusCommand extends Command {
160
+ static enableJsonFlag: boolean;
161
+ static summary: string;
162
+ static description: string;
163
+ static flags: {
164
+ help: _oclif_core_interfaces0.BooleanFlag<void>;
165
+ };
166
+ run(): Promise<void>;
167
+ }
74
168
  declare const COMMANDS: {
75
169
  plan: typeof PlanCommand;
76
170
  diff: typeof DiffCommand;
77
171
  pull: typeof PullCommand;
78
172
  open: typeof OpenCommand;
173
+ init: typeof InitCommand;
174
+ login: typeof LoginCommand;
175
+ logout: typeof LogoutCommand;
176
+ 'auth:status': typeof AuthStatusCommand;
79
177
  };
80
178
  declare function run(argv?: string[], entryUrl?: string): Promise<void>;
81
179
  //#endregion
82
- export { COMMANDS, formatPlanSummary, run };
180
+ export { ApiKeyResolution, COMMANDS, InitProjectOptions, InitProjectResult, StatelyProjectConfig, StatelySourceConfig, createStatelyProjectConfig, formatPlanSummary, getEnvApiKey, inferInitProjectName, initProject, resolveApiKey, run };