@synergenius/flow-weaver 0.26.7 → 0.27.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.
- package/README.md +193 -9
- package/dist/cli/commands/account.d.ts +4 -0
- package/dist/cli/commands/account.js +50 -0
- package/dist/cli/commands/ai-credentials.d.ts +12 -0
- package/dist/cli/commands/ai-credentials.js +95 -0
- package/dist/cli/commands/apikey.d.ts +4 -0
- package/dist/cli/commands/apikey.js +64 -0
- package/dist/cli/commands/auth.d.ts +1 -0
- package/dist/cli/commands/auth.js +15 -15
- package/dist/cli/commands/deploy.js +14 -37
- package/dist/cli/commands/org.d.ts +8 -0
- package/dist/cli/commands/org.js +136 -0
- package/dist/cli/config/platform-client.d.ts +87 -0
- package/dist/cli/config/platform-client.js +127 -1
- package/dist/cli/flow-weaver.mjs +7447 -14908
- package/dist/cli/index.js +111 -0
- package/dist/cli/utils/cli-helpers.d.ts +44 -0
- package/dist/cli/utils/cli-helpers.js +99 -0
- package/dist/generated-version.d.ts +1 -1
- package/dist/generated-version.js +1 -1
- package/package.json +8 -6
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { requireLogin, isUuid, fmt, exitWithError } from '../utils/cli-helpers.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve an org identifier (UUID, slug, name, or prefix) to an org ID.
|
|
4
|
+
* Exact slug/name matches take priority over prefix matches.
|
|
5
|
+
*/
|
|
6
|
+
async function resolveOrgId(client, identifier) {
|
|
7
|
+
if (isUuid(identifier))
|
|
8
|
+
return identifier;
|
|
9
|
+
const orgs = await client.listOrgs();
|
|
10
|
+
// Exact match first (slug or name)
|
|
11
|
+
const exact = orgs.find((o) => o.slug === identifier || o.name === identifier);
|
|
12
|
+
if (exact)
|
|
13
|
+
return exact.id;
|
|
14
|
+
// Prefix match as fallback
|
|
15
|
+
const prefixMatches = orgs.filter((o) => o.slug.startsWith(identifier) || o.id.startsWith(identifier));
|
|
16
|
+
if (prefixMatches.length === 0) {
|
|
17
|
+
throw new Error(`No organization matching "${identifier}". Run: fw org list`);
|
|
18
|
+
}
|
|
19
|
+
if (prefixMatches.length > 1) {
|
|
20
|
+
throw new Error(`Ambiguous: "${identifier}" matches ${prefixMatches.length} organizations. Use the full slug or ID.`);
|
|
21
|
+
}
|
|
22
|
+
return prefixMatches[0].id;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Resolve a user identifier (email, email prefix, or UUID) to a userId within an org.
|
|
26
|
+
* Exact email matches take priority over prefix matches.
|
|
27
|
+
*/
|
|
28
|
+
async function resolveUserId(client, orgId, identifier, orgLabel) {
|
|
29
|
+
if (isUuid(identifier))
|
|
30
|
+
return identifier;
|
|
31
|
+
const org = await client.getOrg(orgId);
|
|
32
|
+
// Exact match first
|
|
33
|
+
const exact = org.members.find((m) => m.email === identifier);
|
|
34
|
+
if (exact)
|
|
35
|
+
return exact.userId;
|
|
36
|
+
// Prefix match as fallback
|
|
37
|
+
const prefixMatches = org.members.filter((m) => m.email.startsWith(identifier) || m.userId.startsWith(identifier));
|
|
38
|
+
if (prefixMatches.length === 0) {
|
|
39
|
+
throw new Error(`No member matching "${identifier}" in this organization. Run: fw org members ${orgLabel ?? orgId}`);
|
|
40
|
+
}
|
|
41
|
+
if (prefixMatches.length > 1) {
|
|
42
|
+
throw new Error(`Ambiguous: "${identifier}" matches ${prefixMatches.length} members. Use the full email or ID.`);
|
|
43
|
+
}
|
|
44
|
+
return prefixMatches[0].userId;
|
|
45
|
+
}
|
|
46
|
+
export async function orgListCommand() {
|
|
47
|
+
const { client } = requireLogin();
|
|
48
|
+
try {
|
|
49
|
+
const orgs = await client.listOrgs();
|
|
50
|
+
console.log('');
|
|
51
|
+
if (orgs.length === 0) {
|
|
52
|
+
console.log(' No organizations. Create one with: fw org create <name>');
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
console.log(` ${orgs.length} organization${orgs.length === 1 ? '' : 's'}:`);
|
|
56
|
+
console.log('');
|
|
57
|
+
for (const org of orgs) {
|
|
58
|
+
const roleColor = org.role === 'owner' ? '\x1b[33m' : '\x1b[2m';
|
|
59
|
+
console.log(` ${fmt.bold(org.name)} ${fmt.dim(org.slug)} ${roleColor}${org.role}\x1b[0m`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
console.log('');
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
exitWithError(err, 'Failed to list organizations');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export async function orgCreateCommand(name) {
|
|
69
|
+
const { client } = requireLogin();
|
|
70
|
+
try {
|
|
71
|
+
const org = await client.createOrg(name);
|
|
72
|
+
console.log('');
|
|
73
|
+
console.log(fmt.ok('Organization created'));
|
|
74
|
+
console.log('');
|
|
75
|
+
console.log(` Name: ${org.name}`);
|
|
76
|
+
console.log(` Slug: ${org.slug}`);
|
|
77
|
+
console.log(` ID: ${fmt.dim(org.id)}`);
|
|
78
|
+
console.log('');
|
|
79
|
+
console.log(` Invite members: fw org invite ${org.slug} <email>`);
|
|
80
|
+
console.log('');
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
exitWithError(err, 'Failed to create organization');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export async function orgMembersCommand(identifier) {
|
|
87
|
+
const { client } = requireLogin();
|
|
88
|
+
try {
|
|
89
|
+
const orgId = await resolveOrgId(client, identifier);
|
|
90
|
+
const org = await client.getOrg(orgId);
|
|
91
|
+
console.log('');
|
|
92
|
+
console.log(` ${fmt.bold(org.name)}`);
|
|
93
|
+
console.log('');
|
|
94
|
+
if (org.members.length === 0) {
|
|
95
|
+
console.log(' No members.');
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
for (const m of org.members) {
|
|
99
|
+
const roleColor = m.role === 'owner' ? '\x1b[33m' : '\x1b[2m';
|
|
100
|
+
console.log(` ${m.email.padEnd(30)} ${m.name.padEnd(20)} ${roleColor}${m.role}\x1b[0m`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
console.log('');
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
exitWithError(err, 'Failed to get organization');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export async function orgInviteCommand(identifier, email, options) {
|
|
110
|
+
const { client } = requireLogin();
|
|
111
|
+
const role = options.role ?? 'editor';
|
|
112
|
+
try {
|
|
113
|
+
if (!['editor', 'viewer'].includes(role)) {
|
|
114
|
+
throw new Error(`Invalid role "${role}". Use: editor, viewer`);
|
|
115
|
+
}
|
|
116
|
+
const orgId = await resolveOrgId(client, identifier);
|
|
117
|
+
await client.inviteOrgMember(orgId, email, role);
|
|
118
|
+
console.log(fmt.ok(`Invited ${email} as ${role}`));
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
exitWithError(err, 'Failed to invite member');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export async function orgRemoveCommand(identifier, userIdentifier) {
|
|
125
|
+
const { client } = requireLogin();
|
|
126
|
+
try {
|
|
127
|
+
const orgId = await resolveOrgId(client, identifier);
|
|
128
|
+
const userId = await resolveUserId(client, orgId, userIdentifier, identifier);
|
|
129
|
+
await client.removeOrgMember(orgId, userId);
|
|
130
|
+
console.log(fmt.ok('Member removed'));
|
|
131
|
+
}
|
|
132
|
+
catch (err) {
|
|
133
|
+
exitWithError(err, 'Failed to remove member');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=org.js.map
|
|
@@ -30,6 +30,93 @@ export declare class PlatformClient {
|
|
|
30
30
|
plan: string;
|
|
31
31
|
}>;
|
|
32
32
|
streamChat(message: string, conversationId?: string): AsyncGenerator<Record<string, unknown>>;
|
|
33
|
+
createApiKey(name: string): Promise<{
|
|
34
|
+
id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
keyPrefix: string;
|
|
37
|
+
key: string;
|
|
38
|
+
createdAt: string;
|
|
39
|
+
}>;
|
|
40
|
+
listApiKeys(): Promise<Array<{
|
|
41
|
+
id: string;
|
|
42
|
+
name: string;
|
|
43
|
+
keyPrefix: string;
|
|
44
|
+
createdAt: string;
|
|
45
|
+
}>>;
|
|
46
|
+
revokeApiKey(id: string): Promise<void>;
|
|
47
|
+
createAiCredential(opts: {
|
|
48
|
+
provider: string;
|
|
49
|
+
label: string;
|
|
50
|
+
apiKey: string;
|
|
51
|
+
baseUrl?: string;
|
|
52
|
+
defaultModel?: string;
|
|
53
|
+
isDefault?: boolean;
|
|
54
|
+
}): Promise<{
|
|
55
|
+
id: string;
|
|
56
|
+
provider: string;
|
|
57
|
+
label: string;
|
|
58
|
+
createdAt: string;
|
|
59
|
+
}>;
|
|
60
|
+
listAiCredentials(): Promise<Array<{
|
|
61
|
+
id: string;
|
|
62
|
+
provider: string;
|
|
63
|
+
label: string;
|
|
64
|
+
defaultModel?: string;
|
|
65
|
+
isDefault: boolean;
|
|
66
|
+
createdAt: string;
|
|
67
|
+
}>>;
|
|
68
|
+
revokeAiCredential(id: string): Promise<void>;
|
|
69
|
+
testAiCredential(id: string): Promise<{
|
|
70
|
+
success: boolean;
|
|
71
|
+
message?: string;
|
|
72
|
+
}>;
|
|
73
|
+
getDetailedUsage(): Promise<{
|
|
74
|
+
plan: string;
|
|
75
|
+
usage: {
|
|
76
|
+
workflows: {
|
|
77
|
+
used: number;
|
|
78
|
+
limit: number;
|
|
79
|
+
};
|
|
80
|
+
deployments: {
|
|
81
|
+
used: number;
|
|
82
|
+
limit: number;
|
|
83
|
+
};
|
|
84
|
+
executions: {
|
|
85
|
+
used: number;
|
|
86
|
+
limit: number;
|
|
87
|
+
period: string;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
limits: {
|
|
91
|
+
timeoutMs: number;
|
|
92
|
+
};
|
|
93
|
+
}>;
|
|
94
|
+
listOrgs(): Promise<Array<{
|
|
95
|
+
id: string;
|
|
96
|
+
name: string;
|
|
97
|
+
slug: string;
|
|
98
|
+
role: string;
|
|
99
|
+
createdAt: string;
|
|
100
|
+
}>>;
|
|
101
|
+
createOrg(name: string): Promise<{
|
|
102
|
+
id: string;
|
|
103
|
+
name: string;
|
|
104
|
+
slug: string;
|
|
105
|
+
}>;
|
|
106
|
+
getOrg(orgId: string): Promise<{
|
|
107
|
+
id: string;
|
|
108
|
+
name: string;
|
|
109
|
+
slug: string;
|
|
110
|
+
members: Array<{
|
|
111
|
+
userId: string;
|
|
112
|
+
name: string;
|
|
113
|
+
email: string;
|
|
114
|
+
role: string;
|
|
115
|
+
joinedAt: string;
|
|
116
|
+
}>;
|
|
117
|
+
}>;
|
|
118
|
+
inviteOrgMember(orgId: string, email: string, role?: string): Promise<void>;
|
|
119
|
+
removeOrgMember(orgId: string, userId: string): Promise<void>;
|
|
33
120
|
validate(): Promise<boolean>;
|
|
34
121
|
}
|
|
35
122
|
export declare function createPlatformClient(creds: StoredCredentials): PlatformClient;
|
|
@@ -8,12 +8,15 @@ export class PlatformClient {
|
|
|
8
8
|
async fetch(path, opts = {}) {
|
|
9
9
|
const isApiKey = this.token.startsWith('fw_');
|
|
10
10
|
const headers = {
|
|
11
|
-
'Content-Type': 'application/json',
|
|
12
11
|
...(isApiKey
|
|
13
12
|
? { 'X-API-Key': this.token }
|
|
14
13
|
: { Authorization: `Bearer ${this.token}` }),
|
|
15
14
|
...(opts.headers ?? {}),
|
|
16
15
|
};
|
|
16
|
+
// Only set Content-Type for requests with a body (Fastify rejects empty body with application/json)
|
|
17
|
+
if (opts.body) {
|
|
18
|
+
headers['Content-Type'] = 'application/json';
|
|
19
|
+
}
|
|
17
20
|
return fetch(`${this.baseUrl}${path}`, { ...opts, headers });
|
|
18
21
|
}
|
|
19
22
|
// Auth
|
|
@@ -105,6 +108,129 @@ export class PlatformClient {
|
|
|
105
108
|
}
|
|
106
109
|
}
|
|
107
110
|
}
|
|
111
|
+
// API Keys
|
|
112
|
+
async createApiKey(name) {
|
|
113
|
+
const resp = await this.fetch('/api-keys', {
|
|
114
|
+
method: 'POST',
|
|
115
|
+
body: JSON.stringify({ name }),
|
|
116
|
+
});
|
|
117
|
+
if (!resp.ok) {
|
|
118
|
+
const err = await resp.json().catch(() => ({ error: resp.statusText }));
|
|
119
|
+
throw new Error(err.error ?? `Failed to create API key: ${resp.status}`);
|
|
120
|
+
}
|
|
121
|
+
const data = await resp.json();
|
|
122
|
+
return data.apiKey;
|
|
123
|
+
}
|
|
124
|
+
async listApiKeys() {
|
|
125
|
+
const resp = await this.fetch('/api-keys');
|
|
126
|
+
if (!resp.ok) {
|
|
127
|
+
throw new Error(`Failed to list API keys: ${resp.status}`);
|
|
128
|
+
}
|
|
129
|
+
const data = await resp.json().catch(() => ({ apiKeys: [] }));
|
|
130
|
+
return data.apiKeys ?? [];
|
|
131
|
+
}
|
|
132
|
+
async revokeApiKey(id) {
|
|
133
|
+
const resp = await this.fetch(`/api-keys/${id}`, { method: 'DELETE' });
|
|
134
|
+
if (resp.status === 404) {
|
|
135
|
+
throw new Error('API key not found or already revoked');
|
|
136
|
+
}
|
|
137
|
+
if (!resp.ok) {
|
|
138
|
+
throw new Error(`Failed to revoke API key: ${resp.status}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// AI Credentials
|
|
142
|
+
async createAiCredential(opts) {
|
|
143
|
+
const resp = await this.fetch('/ai-credentials', {
|
|
144
|
+
method: 'POST',
|
|
145
|
+
body: JSON.stringify(opts),
|
|
146
|
+
});
|
|
147
|
+
if (!resp.ok) {
|
|
148
|
+
const err = await resp.json().catch(() => ({ error: resp.statusText }));
|
|
149
|
+
throw new Error(err.error ?? `Failed to add credential: ${resp.status}`);
|
|
150
|
+
}
|
|
151
|
+
const data = await resp.json();
|
|
152
|
+
return data.credential;
|
|
153
|
+
}
|
|
154
|
+
async listAiCredentials() {
|
|
155
|
+
const resp = await this.fetch('/ai-credentials');
|
|
156
|
+
if (!resp.ok)
|
|
157
|
+
throw new Error(`Failed to list credentials: ${resp.status}`);
|
|
158
|
+
const data = await resp.json().catch(() => ({ credentials: [] }));
|
|
159
|
+
return data.credentials ?? [];
|
|
160
|
+
}
|
|
161
|
+
async revokeAiCredential(id) {
|
|
162
|
+
const resp = await this.fetch(`/ai-credentials/${id}`, { method: 'DELETE' });
|
|
163
|
+
if (resp.status === 404)
|
|
164
|
+
throw new Error('Credential not found');
|
|
165
|
+
if (!resp.ok)
|
|
166
|
+
throw new Error(`Failed to revoke credential: ${resp.status}`);
|
|
167
|
+
}
|
|
168
|
+
async testAiCredential(id) {
|
|
169
|
+
const resp = await this.fetch(`/ai-credentials/${id}/test`, { method: 'POST' });
|
|
170
|
+
if (!resp.ok) {
|
|
171
|
+
const err = await resp.json().catch(() => ({ error: resp.statusText }));
|
|
172
|
+
throw new Error(err.error ?? `Test failed: ${resp.status}`);
|
|
173
|
+
}
|
|
174
|
+
return await resp.json().catch(() => ({ success: true }));
|
|
175
|
+
}
|
|
176
|
+
// Billing / Usage
|
|
177
|
+
async getDetailedUsage() {
|
|
178
|
+
const resp = await this.fetch('/billing/usage');
|
|
179
|
+
if (!resp.ok)
|
|
180
|
+
throw new Error(`Failed to fetch usage: ${resp.status}`);
|
|
181
|
+
const data = await resp.json().catch(() => null);
|
|
182
|
+
if (!data?.usage)
|
|
183
|
+
throw new Error('Invalid usage response');
|
|
184
|
+
return data;
|
|
185
|
+
}
|
|
186
|
+
// Organizations
|
|
187
|
+
async listOrgs() {
|
|
188
|
+
const resp = await this.fetch('/organizations');
|
|
189
|
+
if (!resp.ok)
|
|
190
|
+
throw new Error(`Failed to list organizations: ${resp.status}`);
|
|
191
|
+
const data = await resp.json().catch(() => []);
|
|
192
|
+
return Array.isArray(data) ? data : [];
|
|
193
|
+
}
|
|
194
|
+
async createOrg(name) {
|
|
195
|
+
const resp = await this.fetch('/organizations', {
|
|
196
|
+
method: 'POST',
|
|
197
|
+
body: JSON.stringify({ name }),
|
|
198
|
+
});
|
|
199
|
+
if (!resp.ok) {
|
|
200
|
+
const err = await resp.json().catch(() => ({ error: resp.statusText }));
|
|
201
|
+
throw new Error(err.error ?? `Failed to create organization: ${resp.status}`);
|
|
202
|
+
}
|
|
203
|
+
const data = await resp.json().catch(() => null);
|
|
204
|
+
if (!data)
|
|
205
|
+
throw new Error('Invalid organization response');
|
|
206
|
+
return data;
|
|
207
|
+
}
|
|
208
|
+
async getOrg(orgId) {
|
|
209
|
+
const resp = await this.fetch(`/organizations/${orgId}`);
|
|
210
|
+
if (!resp.ok)
|
|
211
|
+
throw new Error(`Failed to get organization: ${resp.status}`);
|
|
212
|
+
const data = await resp.json().catch(() => null);
|
|
213
|
+
if (!data)
|
|
214
|
+
throw new Error('Invalid organization response');
|
|
215
|
+
return data;
|
|
216
|
+
}
|
|
217
|
+
async inviteOrgMember(orgId, email, role = 'editor') {
|
|
218
|
+
const resp = await this.fetch(`/organizations/${orgId}/members`, {
|
|
219
|
+
method: 'POST',
|
|
220
|
+
body: JSON.stringify({ email, role }),
|
|
221
|
+
});
|
|
222
|
+
if (!resp.ok) {
|
|
223
|
+
const err = await resp.json().catch(() => ({ error: resp.statusText }));
|
|
224
|
+
throw new Error(err.error ?? `Failed to invite member: ${resp.status}`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async removeOrgMember(orgId, userId) {
|
|
228
|
+
const resp = await this.fetch(`/organizations/${orgId}/members/${userId}`, { method: 'DELETE' });
|
|
229
|
+
if (!resp.ok) {
|
|
230
|
+
const err = await resp.json().catch(() => ({ error: resp.statusText }));
|
|
231
|
+
throw new Error(err.error ?? `Failed to remove member: ${resp.status}`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
108
234
|
// Validate connection
|
|
109
235
|
async validate() {
|
|
110
236
|
try {
|