@trendify/cli 0.1.9 → 0.1.10
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/shared/config/env.config.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/dist/app.d.ts +0 -14
- package/dist/app.d.ts.map +0 -1
- package/dist/app.js +0 -448
- package/dist/cli-update-service.d.ts +0 -29
- package/dist/cli-update-service.d.ts.map +0 -1
- package/dist/cli-update-service.js +0 -206
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -51
- package/dist/config/app-paths.d.ts +0 -4
- package/dist/config/app-paths.d.ts.map +0 -1
- package/dist/config/app-paths.js +0 -5
- package/dist/config/env.d.ts +0 -14
- package/dist/config/env.d.ts.map +0 -1
- package/dist/config/env.js +0 -58
- package/dist/modules/auth/auth-service.d.ts +0 -60
- package/dist/modules/auth/auth-service.d.ts.map +0 -1
- package/dist/modules/auth/auth-service.js +0 -494
- package/dist/modules/auth/auth-storage.d.ts +0 -11
- package/dist/modules/auth/auth-storage.d.ts.map +0 -1
- package/dist/modules/auth/auth-storage.js +0 -65
- package/dist/modules/auth/auth-user.d.ts +0 -3
- package/dist/modules/auth/auth-user.d.ts.map +0 -1
- package/dist/modules/auth/auth-user.js +0 -10
- package/dist/modules/auth/page/login-page.d.ts +0 -12
- package/dist/modules/auth/page/login-page.d.ts.map +0 -1
- package/dist/modules/auth/page/login-page.js +0 -22
- package/dist/modules/discovery/components/discovery-step-header.d.ts +0 -7
- package/dist/modules/discovery/components/discovery-step-header.d.ts.map +0 -1
- package/dist/modules/discovery/components/discovery-step-header.js +0 -5
- package/dist/modules/discovery/page/discovery-page.d.ts +0 -11
- package/dist/modules/discovery/page/discovery-page.d.ts.map +0 -1
- package/dist/modules/discovery/page/discovery-page.js +0 -58
- package/dist/modules/profile/page/profile-page.d.ts +0 -12
- package/dist/modules/profile/page/profile-page.d.ts.map +0 -1
- package/dist/modules/profile/page/profile-page.js +0 -180
- package/dist/modules/profile/pages/profile.page.d.ts +0 -12
- package/dist/modules/profile/pages/profile.page.d.ts.map +0 -1
- package/dist/modules/profile/pages/profile.page.js +0 -180
- package/dist/shared/components/action-menu-page.d.ts +0 -13
- package/dist/shared/components/action-menu-page.d.ts.map +0 -1
- package/dist/shared/components/action-menu-page.js +0 -7
- package/dist/shared/components/radio-select.d.ts +0 -12
- package/dist/shared/components/radio-select.d.ts.map +0 -1
- package/dist/shared/components/radio-select.js +0 -16
- package/dist/shared/components/step-header.d.ts +0 -7
- package/dist/shared/components/step-header.d.ts.map +0 -1
- package/dist/shared/components/step-header.js +0 -5
- package/dist/shared/components/text-field.d.ts +0 -12
- package/dist/shared/components/text-field.d.ts.map +0 -1
- package/dist/shared/components/text-field.js +0 -6
- package/dist/shared/template/app-logo.d.ts +0 -2
- package/dist/shared/template/app-logo.d.ts.map +0 -1
- package/dist/shared/template/app-logo.js +0 -13
- package/dist/shared/template/app-menu.d.ts +0 -17
- package/dist/shared/template/app-menu.d.ts.map +0 -1
- package/dist/shared/template/app-menu.js +0 -85
- package/dist/shared/template/app-shell.d.ts +0 -12
- package/dist/shared/template/app-shell.d.ts.map +0 -1
- package/dist/shared/template/app-shell.js +0 -15
|
@@ -1,494 +0,0 @@
|
|
|
1
|
-
import { createClient, } from '@supabase/supabase-js';
|
|
2
|
-
import { TRENDIFY_AUTH_STORAGE_FILE } from '../../config/app-paths.js';
|
|
3
|
-
import { getCliEnvValidationResult } from '../../config/env.js';
|
|
4
|
-
import { FileStorage } from './auth-storage.js';
|
|
5
|
-
const AUTH_STORAGE_KEY = 'trendify.auth.token';
|
|
6
|
-
const ACTIVE_WORKSPACE_STORAGE_KEY = 'trendify.auth.active-workspace-id';
|
|
7
|
-
function toAuthErrorMessage(error, fallbackMessage) {
|
|
8
|
-
if (error && typeof error === 'object' && 'message' in error && typeof error.message === 'string') {
|
|
9
|
-
return error.message;
|
|
10
|
-
}
|
|
11
|
-
return fallbackMessage;
|
|
12
|
-
}
|
|
13
|
-
function isWorkspaceRole(value) {
|
|
14
|
-
return value === 'owner' || value === 'admin' || value === 'member';
|
|
15
|
-
}
|
|
16
|
-
function normalizeWorkspaceMembership(value) {
|
|
17
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
const candidate = value;
|
|
21
|
-
const id = typeof candidate.workspace_id === 'string' ? candidate.workspace_id.trim() : '';
|
|
22
|
-
const name = typeof candidate.workspace_name === 'string' ? candidate.workspace_name.trim() : '';
|
|
23
|
-
const slug = typeof candidate.workspace_slug === 'string' ? candidate.workspace_slug.trim() : '';
|
|
24
|
-
const role = candidate.role;
|
|
25
|
-
if (!id || !name || !slug || !isWorkspaceRole(role)) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
return {
|
|
29
|
-
id,
|
|
30
|
-
name,
|
|
31
|
-
role,
|
|
32
|
-
slug,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
export class AuthService {
|
|
36
|
-
client;
|
|
37
|
-
storage;
|
|
38
|
-
env;
|
|
39
|
-
storageFilePath;
|
|
40
|
-
static create(env) {
|
|
41
|
-
const storage = new FileStorage(TRENDIFY_AUTH_STORAGE_FILE);
|
|
42
|
-
const client = createClient(env.supabaseUrl, env.supabasePublishableDefaultKey, {
|
|
43
|
-
auth: {
|
|
44
|
-
autoRefreshToken: true,
|
|
45
|
-
detectSessionInUrl: false,
|
|
46
|
-
persistSession: true,
|
|
47
|
-
storage,
|
|
48
|
-
storageKey: AUTH_STORAGE_KEY,
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
return new AuthService(client, storage, env, TRENDIFY_AUTH_STORAGE_FILE);
|
|
52
|
-
}
|
|
53
|
-
constructor(client, storage, env, storageFilePath) {
|
|
54
|
-
this.client = client;
|
|
55
|
-
this.storage = storage;
|
|
56
|
-
this.env = env;
|
|
57
|
-
this.storageFilePath = storageFilePath;
|
|
58
|
-
this.activeWorkspaceId = null;
|
|
59
|
-
}
|
|
60
|
-
activeWorkspaceId;
|
|
61
|
-
getSessionStorageFilePath() {
|
|
62
|
-
return this.storageFilePath;
|
|
63
|
-
}
|
|
64
|
-
onAuthStateChange(listener) {
|
|
65
|
-
return this.client.auth.onAuthStateChange((_event, session) => {
|
|
66
|
-
listener({
|
|
67
|
-
activeWorkspace: null,
|
|
68
|
-
requiresWorkspaceSelection: false,
|
|
69
|
-
session,
|
|
70
|
-
user: session?.user ?? null,
|
|
71
|
-
workspaces: [],
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
getActiveWorkspaceId() {
|
|
76
|
-
return this.activeWorkspaceId;
|
|
77
|
-
}
|
|
78
|
-
async getWorkspaceScopedClient() {
|
|
79
|
-
try {
|
|
80
|
-
const { data: { session }, error, } = await this.client.auth.getSession();
|
|
81
|
-
if (error) {
|
|
82
|
-
return {
|
|
83
|
-
data: null,
|
|
84
|
-
error: error.message,
|
|
85
|
-
errorCode: error.code ?? null,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
if (!session?.access_token) {
|
|
89
|
-
return {
|
|
90
|
-
data: null,
|
|
91
|
-
error: 'Nao existe uma sessao ativa para criar um cliente com espaco de trabalho.',
|
|
92
|
-
errorCode: null,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
const activeWorkspaceId = this.activeWorkspaceId ?? (await this.readStoredActiveWorkspaceId());
|
|
96
|
-
if (!activeWorkspaceId) {
|
|
97
|
-
return {
|
|
98
|
-
data: null,
|
|
99
|
-
error: 'Selecione um espaco de trabalho antes de consultar dados protegidos.',
|
|
100
|
-
errorCode: null,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
const workspaceClient = createClient(this.env.supabaseUrl, this.env.supabasePublishableDefaultKey, {
|
|
104
|
-
auth: {
|
|
105
|
-
autoRefreshToken: false,
|
|
106
|
-
detectSessionInUrl: false,
|
|
107
|
-
persistSession: false,
|
|
108
|
-
},
|
|
109
|
-
global: {
|
|
110
|
-
headers: {
|
|
111
|
-
Authorization: `Bearer ${session.access_token}`,
|
|
112
|
-
'x-tenant-id': activeWorkspaceId,
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
return {
|
|
117
|
-
data: workspaceClient,
|
|
118
|
-
error: null,
|
|
119
|
-
errorCode: null,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
catch (error) {
|
|
123
|
-
return {
|
|
124
|
-
data: null,
|
|
125
|
-
error: toAuthErrorMessage(error, 'Nao foi possivel preparar o cliente do espaco de trabalho atual.'),
|
|
126
|
-
errorCode: null,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
async restoreSession() {
|
|
131
|
-
try {
|
|
132
|
-
const { data: { session }, error: sessionError, } = await this.client.auth.getSession();
|
|
133
|
-
if (sessionError) {
|
|
134
|
-
return {
|
|
135
|
-
data: null,
|
|
136
|
-
error: sessionError.message,
|
|
137
|
-
errorCode: sessionError.code ?? null,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
if (!session) {
|
|
141
|
-
return {
|
|
142
|
-
data: {
|
|
143
|
-
activeWorkspace: null,
|
|
144
|
-
requiresWorkspaceSelection: false,
|
|
145
|
-
session: null,
|
|
146
|
-
user: null,
|
|
147
|
-
workspaces: [],
|
|
148
|
-
},
|
|
149
|
-
error: null,
|
|
150
|
-
errorCode: null,
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
const { data: { user }, error: userError, } = await this.client.auth.getUser();
|
|
154
|
-
if (userError || !user) {
|
|
155
|
-
await this.client.auth.signOut({ scope: 'local' });
|
|
156
|
-
await this.clearStoredActiveWorkspaceId();
|
|
157
|
-
return {
|
|
158
|
-
data: {
|
|
159
|
-
activeWorkspace: null,
|
|
160
|
-
requiresWorkspaceSelection: false,
|
|
161
|
-
session: null,
|
|
162
|
-
user: null,
|
|
163
|
-
workspaces: [],
|
|
164
|
-
},
|
|
165
|
-
error: userError?.message ?? 'Sua sessao expirou. Faca login novamente.',
|
|
166
|
-
errorCode: userError?.code ?? null,
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
return await this.buildAuthenticatedSnapshot(session, user);
|
|
170
|
-
}
|
|
171
|
-
catch (error) {
|
|
172
|
-
return {
|
|
173
|
-
data: null,
|
|
174
|
-
error: toAuthErrorMessage(error, 'Nao foi possivel restaurar a sessao atual.'),
|
|
175
|
-
errorCode: null,
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
async signInWithPassword(email, password) {
|
|
180
|
-
try {
|
|
181
|
-
const { data, error } = await this.client.auth.signInWithPassword({
|
|
182
|
-
email,
|
|
183
|
-
password,
|
|
184
|
-
});
|
|
185
|
-
if (error) {
|
|
186
|
-
return {
|
|
187
|
-
data: null,
|
|
188
|
-
error: error.message,
|
|
189
|
-
errorCode: error.code ?? null,
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
if (!data.session || !data.user) {
|
|
193
|
-
return {
|
|
194
|
-
data: null,
|
|
195
|
-
error: 'O Supabase nao retornou uma sessao valida para este usuario.',
|
|
196
|
-
errorCode: null,
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
return await this.buildAuthenticatedSnapshot(data.session, data.user);
|
|
200
|
-
}
|
|
201
|
-
catch (error) {
|
|
202
|
-
return {
|
|
203
|
-
data: null,
|
|
204
|
-
error: toAuthErrorMessage(error, 'Nao foi possivel concluir o login agora.'),
|
|
205
|
-
errorCode: null,
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
async signOut() {
|
|
210
|
-
try {
|
|
211
|
-
const { error } = await this.client.auth.signOut({ scope: 'local' });
|
|
212
|
-
if (error) {
|
|
213
|
-
return {
|
|
214
|
-
data: null,
|
|
215
|
-
error: error.message,
|
|
216
|
-
errorCode: error.code ?? null,
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
await this.clearStoredActiveWorkspaceId();
|
|
220
|
-
return {
|
|
221
|
-
data: null,
|
|
222
|
-
error: null,
|
|
223
|
-
errorCode: null,
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
catch (error) {
|
|
227
|
-
return {
|
|
228
|
-
data: null,
|
|
229
|
-
error: toAuthErrorMessage(error, 'Nao foi possivel encerrar a sessao atual.'),
|
|
230
|
-
errorCode: null,
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
async selectWorkspace(workspaceId) {
|
|
235
|
-
const trimmedWorkspaceId = workspaceId.trim();
|
|
236
|
-
if (!trimmedWorkspaceId) {
|
|
237
|
-
return {
|
|
238
|
-
data: null,
|
|
239
|
-
error: 'Informe um espaco de trabalho valido para continuar.',
|
|
240
|
-
errorCode: null,
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
try {
|
|
244
|
-
const workspaceResult = await this.listMyWorkspaces();
|
|
245
|
-
if (workspaceResult.error || !workspaceResult.data) {
|
|
246
|
-
return {
|
|
247
|
-
data: null,
|
|
248
|
-
error: workspaceResult.error ?? 'Nao foi possivel carregar os espacos de trabalho disponiveis.',
|
|
249
|
-
errorCode: workspaceResult.errorCode,
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
const selectedWorkspace = workspaceResult.data.find((workspace) => workspace.id === trimmedWorkspaceId);
|
|
253
|
-
if (!selectedWorkspace) {
|
|
254
|
-
return {
|
|
255
|
-
data: null,
|
|
256
|
-
error: 'Esse espaco de trabalho nao esta disponivel para a sua conta.',
|
|
257
|
-
errorCode: null,
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
await this.storeActiveWorkspaceId(selectedWorkspace.id);
|
|
261
|
-
return {
|
|
262
|
-
data: selectedWorkspace,
|
|
263
|
-
error: null,
|
|
264
|
-
errorCode: null,
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
catch (error) {
|
|
268
|
-
return {
|
|
269
|
-
data: null,
|
|
270
|
-
error: toAuthErrorMessage(error, 'Nao foi possivel selecionar o espaco de trabalho agora.'),
|
|
271
|
-
errorCode: null,
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
async updateDisplayName(displayName) {
|
|
276
|
-
try {
|
|
277
|
-
const { data: { user: currentUser }, error: currentUserError, } = await this.client.auth.getUser();
|
|
278
|
-
if (currentUserError) {
|
|
279
|
-
return {
|
|
280
|
-
data: null,
|
|
281
|
-
error: currentUserError.message,
|
|
282
|
-
errorCode: currentUserError.code ?? null,
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
if (!currentUser) {
|
|
286
|
-
return {
|
|
287
|
-
data: null,
|
|
288
|
-
error: 'Nao existe um usuario autenticado para atualizar o profile.',
|
|
289
|
-
errorCode: null,
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
const currentMetadata = currentUser.user_metadata &&
|
|
293
|
-
typeof currentUser.user_metadata === 'object' &&
|
|
294
|
-
!Array.isArray(currentUser.user_metadata)
|
|
295
|
-
? currentUser.user_metadata
|
|
296
|
-
: {};
|
|
297
|
-
const { data, error } = await this.client.auth.updateUser({
|
|
298
|
-
data: {
|
|
299
|
-
...currentMetadata,
|
|
300
|
-
display_name: displayName,
|
|
301
|
-
},
|
|
302
|
-
});
|
|
303
|
-
if (error) {
|
|
304
|
-
return {
|
|
305
|
-
data: null,
|
|
306
|
-
error: error.message,
|
|
307
|
-
errorCode: error.code ?? null,
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
if (!data.user) {
|
|
311
|
-
return {
|
|
312
|
-
data: null,
|
|
313
|
-
error: 'O Supabase nao retornou o usuario atualizado.',
|
|
314
|
-
errorCode: null,
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
return {
|
|
318
|
-
data: data.user,
|
|
319
|
-
error: null,
|
|
320
|
-
errorCode: null,
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
catch (error) {
|
|
324
|
-
return {
|
|
325
|
-
data: null,
|
|
326
|
-
error: toAuthErrorMessage(error, 'Nao foi possivel atualizar o display name agora.'),
|
|
327
|
-
errorCode: null,
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
async sendPasswordReauthenticationCode() {
|
|
332
|
-
try {
|
|
333
|
-
const { error } = await this.client.auth.reauthenticate();
|
|
334
|
-
if (error) {
|
|
335
|
-
return {
|
|
336
|
-
data: null,
|
|
337
|
-
error: error.message,
|
|
338
|
-
errorCode: error.code ?? null,
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
return {
|
|
342
|
-
data: null,
|
|
343
|
-
error: null,
|
|
344
|
-
errorCode: null,
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
catch (error) {
|
|
348
|
-
return {
|
|
349
|
-
data: null,
|
|
350
|
-
error: toAuthErrorMessage(error, 'Nao foi possivel solicitar o codigo de verificacao.'),
|
|
351
|
-
errorCode: null,
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
async updatePassword(password, nonce) {
|
|
356
|
-
try {
|
|
357
|
-
const { data, error } = await this.client.auth.updateUser(nonce
|
|
358
|
-
? {
|
|
359
|
-
nonce,
|
|
360
|
-
password,
|
|
361
|
-
}
|
|
362
|
-
: {
|
|
363
|
-
password,
|
|
364
|
-
});
|
|
365
|
-
if (error) {
|
|
366
|
-
return {
|
|
367
|
-
data: null,
|
|
368
|
-
error: error.message,
|
|
369
|
-
errorCode: error.code ?? null,
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
if (!data.user) {
|
|
373
|
-
return {
|
|
374
|
-
data: null,
|
|
375
|
-
error: 'O Supabase nao retornou o usuario atualizado apos trocar a senha.',
|
|
376
|
-
errorCode: null,
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
return {
|
|
380
|
-
data: data.user,
|
|
381
|
-
error: null,
|
|
382
|
-
errorCode: null,
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
catch (error) {
|
|
386
|
-
return {
|
|
387
|
-
data: null,
|
|
388
|
-
error: toAuthErrorMessage(error, 'Nao foi possivel atualizar a senha agora.'),
|
|
389
|
-
errorCode: null,
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
async buildAuthenticatedSnapshot(session, user) {
|
|
394
|
-
const workspaceResult = await this.listMyWorkspaces();
|
|
395
|
-
if (workspaceResult.error || !workspaceResult.data) {
|
|
396
|
-
return {
|
|
397
|
-
data: null,
|
|
398
|
-
error: workspaceResult.error ?? 'Nao foi possivel carregar os espacos de trabalho desta conta.',
|
|
399
|
-
errorCode: workspaceResult.errorCode,
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
if (workspaceResult.data.length === 0) {
|
|
403
|
-
await this.clearStoredActiveWorkspaceId();
|
|
404
|
-
return {
|
|
405
|
-
data: null,
|
|
406
|
-
error: 'Sua conta nao esta vinculada a nenhum espaco de trabalho. Fale com um administrador.',
|
|
407
|
-
errorCode: 'workspace_membership_missing',
|
|
408
|
-
};
|
|
409
|
-
}
|
|
410
|
-
const storedActiveWorkspaceId = await this.readStoredActiveWorkspaceId();
|
|
411
|
-
const storedWorkspace = storedActiveWorkspaceId
|
|
412
|
-
? workspaceResult.data.find((workspace) => workspace.id === storedActiveWorkspaceId)
|
|
413
|
-
: null;
|
|
414
|
-
const singleWorkspace = workspaceResult.data.length === 1 ? workspaceResult.data[0] ?? null : null;
|
|
415
|
-
const activeWorkspace = storedWorkspace ?? singleWorkspace;
|
|
416
|
-
const requiresWorkspaceSelection = activeWorkspace === null;
|
|
417
|
-
if (activeWorkspace) {
|
|
418
|
-
await this.storeActiveWorkspaceId(activeWorkspace.id);
|
|
419
|
-
}
|
|
420
|
-
else {
|
|
421
|
-
await this.clearStoredActiveWorkspaceId();
|
|
422
|
-
}
|
|
423
|
-
return {
|
|
424
|
-
data: {
|
|
425
|
-
activeWorkspace,
|
|
426
|
-
requiresWorkspaceSelection,
|
|
427
|
-
session,
|
|
428
|
-
user,
|
|
429
|
-
workspaces: workspaceResult.data,
|
|
430
|
-
},
|
|
431
|
-
error: null,
|
|
432
|
-
errorCode: null,
|
|
433
|
-
};
|
|
434
|
-
}
|
|
435
|
-
async listMyWorkspaces() {
|
|
436
|
-
try {
|
|
437
|
-
const { data, error } = await this.client.rpc('list_my_workspaces');
|
|
438
|
-
if (error) {
|
|
439
|
-
return {
|
|
440
|
-
data: null,
|
|
441
|
-
error: error.message,
|
|
442
|
-
errorCode: error.code ?? null,
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
const workspaces = Array.isArray(data)
|
|
446
|
-
? data
|
|
447
|
-
.map(normalizeWorkspaceMembership)
|
|
448
|
-
.filter((workspace) => workspace !== null)
|
|
449
|
-
: [];
|
|
450
|
-
return {
|
|
451
|
-
data: workspaces,
|
|
452
|
-
error: null,
|
|
453
|
-
errorCode: null,
|
|
454
|
-
};
|
|
455
|
-
}
|
|
456
|
-
catch (error) {
|
|
457
|
-
return {
|
|
458
|
-
data: null,
|
|
459
|
-
error: toAuthErrorMessage(error, 'Nao foi possivel consultar os espacos de trabalho desta conta.'),
|
|
460
|
-
errorCode: null,
|
|
461
|
-
};
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
async readStoredActiveWorkspaceId() {
|
|
465
|
-
const storedValue = await this.storage.getItem(ACTIVE_WORKSPACE_STORAGE_KEY);
|
|
466
|
-
const trimmedValue = storedValue?.trim() ?? '';
|
|
467
|
-
return trimmedValue ? trimmedValue : null;
|
|
468
|
-
}
|
|
469
|
-
async storeActiveWorkspaceId(workspaceId) {
|
|
470
|
-
this.activeWorkspaceId = workspaceId;
|
|
471
|
-
await this.storage.setItem(ACTIVE_WORKSPACE_STORAGE_KEY, workspaceId);
|
|
472
|
-
}
|
|
473
|
-
async clearStoredActiveWorkspaceId() {
|
|
474
|
-
this.activeWorkspaceId = null;
|
|
475
|
-
await this.storage.removeItem(ACTIVE_WORKSPACE_STORAGE_KEY);
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
let cachedAuthBootstrap = null;
|
|
479
|
-
export function getAuthBootstrapResult() {
|
|
480
|
-
if (cachedAuthBootstrap) {
|
|
481
|
-
return cachedAuthBootstrap;
|
|
482
|
-
}
|
|
483
|
-
const envValidation = getCliEnvValidationResult();
|
|
484
|
-
if (!envValidation.ok) {
|
|
485
|
-
cachedAuthBootstrap = envValidation;
|
|
486
|
-
return cachedAuthBootstrap;
|
|
487
|
-
}
|
|
488
|
-
cachedAuthBootstrap = {
|
|
489
|
-
ok: true,
|
|
490
|
-
env: envValidation.env,
|
|
491
|
-
authService: AuthService.create(envValidation.env),
|
|
492
|
-
};
|
|
493
|
-
return cachedAuthBootstrap;
|
|
494
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type SupportedStorage } from '@supabase/supabase-js';
|
|
2
|
-
export declare class FileStorage implements SupportedStorage {
|
|
3
|
-
private readonly filePath;
|
|
4
|
-
private queue;
|
|
5
|
-
constructor(filePath: string);
|
|
6
|
-
getItem(key: string): Promise<string | null>;
|
|
7
|
-
removeItem(key: string): Promise<void>;
|
|
8
|
-
setItem(key: string, value: string): Promise<void>;
|
|
9
|
-
private runExclusive;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=auth-storage.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-storage.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth-storage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AA0C9D,qBAAa,WAAY,YAAW,gBAAgB;IAG/B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAF5C,OAAO,CAAC,KAAK,CAAuC;gBAEhB,QAAQ,EAAE,MAAM;IAEvC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAQ5C,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAatC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS/D,OAAO,CAAC,YAAY;CAUrB"}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { chmod, mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { dirname } from 'node:path';
|
|
3
|
-
async function ensureParentDirectory(filePath) {
|
|
4
|
-
await mkdir(dirname(filePath), { recursive: true });
|
|
5
|
-
}
|
|
6
|
-
async function readStorageMap(filePath) {
|
|
7
|
-
try {
|
|
8
|
-
const fileContents = await readFile(filePath, 'utf8');
|
|
9
|
-
const parsedContents = JSON.parse(fileContents);
|
|
10
|
-
if (!parsedContents || typeof parsedContents !== 'object' || Array.isArray(parsedContents)) {
|
|
11
|
-
return {};
|
|
12
|
-
}
|
|
13
|
-
return Object.fromEntries(Object.entries(parsedContents).filter((entry) => typeof entry[1] === 'string'));
|
|
14
|
-
}
|
|
15
|
-
catch (error) {
|
|
16
|
-
if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
|
|
17
|
-
return {};
|
|
18
|
-
}
|
|
19
|
-
return {};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
async function writeStorageMap(filePath, data) {
|
|
23
|
-
await ensureParentDirectory(filePath);
|
|
24
|
-
const tempFilePath = `${filePath}.tmp`;
|
|
25
|
-
await writeFile(tempFilePath, JSON.stringify(data, null, 2), 'utf8');
|
|
26
|
-
await rename(tempFilePath, filePath);
|
|
27
|
-
if (process.platform !== 'win32') {
|
|
28
|
-
await chmod(filePath, 0o600).catch(() => undefined);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export class FileStorage {
|
|
32
|
-
filePath;
|
|
33
|
-
queue = Promise.resolve();
|
|
34
|
-
constructor(filePath) {
|
|
35
|
-
this.filePath = filePath;
|
|
36
|
-
}
|
|
37
|
-
async getItem(key) {
|
|
38
|
-
return this.runExclusive(async () => {
|
|
39
|
-
const data = await readStorageMap(this.filePath);
|
|
40
|
-
return data[key] ?? null;
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
async removeItem(key) {
|
|
44
|
-
await this.runExclusive(async () => {
|
|
45
|
-
const data = await readStorageMap(this.filePath);
|
|
46
|
-
if (!(key in data)) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
delete data[key];
|
|
50
|
-
await writeStorageMap(this.filePath, data);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
async setItem(key, value) {
|
|
54
|
-
await this.runExclusive(async () => {
|
|
55
|
-
const data = await readStorageMap(this.filePath);
|
|
56
|
-
data[key] = value;
|
|
57
|
-
await writeStorageMap(this.filePath, data);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
runExclusive(operation) {
|
|
61
|
-
const nextOperation = this.queue.then(operation, operation);
|
|
62
|
-
this.queue = nextOperation.then(() => undefined, () => undefined);
|
|
63
|
-
return nextOperation;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-user.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth-user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,eAAe,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAa1G"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export function getUserDisplayName(user) {
|
|
2
|
-
const value = user && user.user_metadata && typeof user.user_metadata === 'object' && !Array.isArray(user.user_metadata)
|
|
3
|
-
? user.user_metadata.display_name
|
|
4
|
-
: null;
|
|
5
|
-
if (typeof value !== 'string') {
|
|
6
|
-
return null;
|
|
7
|
-
}
|
|
8
|
-
const trimmedValue = value.trim();
|
|
9
|
-
return trimmedValue ? trimmedValue : null;
|
|
10
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
type LoginPageProps = {
|
|
2
|
-
readonly busy: boolean;
|
|
3
|
-
readonly email: string;
|
|
4
|
-
readonly onEmailChange: (value: string) => void;
|
|
5
|
-
readonly onPasswordChange: (value: string) => void;
|
|
6
|
-
readonly onSubmit: () => void;
|
|
7
|
-
readonly password: string;
|
|
8
|
-
readonly sessionStorageFilePath: string;
|
|
9
|
-
};
|
|
10
|
-
export declare function LoginPage({ busy, email, onEmailChange, onPasswordChange, onSubmit, password, sessionStorageFilePath, }: LoginPageProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
-
export {};
|
|
12
|
-
//# sourceMappingURL=login-page.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"login-page.d.ts","sourceRoot":"","sources":["../../../../src/modules/auth/page/login-page.tsx"],"names":[],"mappings":"AAIA,KAAK,cAAc,GAAG;IACpB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,QAAQ,CAAC,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,QAAQ,CAAC,QAAQ,EAAE,MAAM,IAAI,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,sBAAsB,EAAE,MAAM,CAAC;CACzC,CAAC;AAIF,wBAAgB,SAAS,CAAC,EACxB,IAAI,EACJ,KAAK,EACL,aAAa,EACb,gBAAgB,EAChB,QAAQ,EACR,QAAQ,EACR,sBAAsB,GACvB,EAAE,cAAc,2CAsDhB"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Box, Text, useInput } from 'ink';
|
|
3
|
-
import { useState } from 'react';
|
|
4
|
-
import { TextField } from '../../../shared/components/text-field.js';
|
|
5
|
-
export function LoginPage({ busy, email, onEmailChange, onPasswordChange, onSubmit, password, sessionStorageFilePath, }) {
|
|
6
|
-
const [focusField, setFocusField] = useState('email');
|
|
7
|
-
useInput((_input, key) => {
|
|
8
|
-
if (busy) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
if (key.tab || key.downArrow || key.upArrow) {
|
|
12
|
-
setFocusField((current) => (current === 'email' ? 'password' : 'email'));
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: "Entre com um usuario ja cadastrado no Supabase para liberar os comandos internos." }), _jsx(Text, { dimColor: true, children: "Apos o login, a CLI tambem valida o espaco de trabalho vinculado a sua conta." }), _jsx(Text, { dimColor: true, children: "Cadastro nao esta habilitado nesta CLI." }), _jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { color: focusField === 'email' ? 'greenBright' : 'white', children: "Email" }), _jsx(TextField, { focus: focusField === 'email', placeholder: "voce@empresa.com", value: email, onChange: onEmailChange, onSubmit: (value) => {
|
|
16
|
-
if (value.trim()) {
|
|
17
|
-
setFocusField('password');
|
|
18
|
-
}
|
|
19
|
-
} })] }), _jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { color: focusField === 'password' ? 'greenBright' : 'white', children: "Senha" }), _jsx(TextField, { focus: focusField === 'password', mask: "*", placeholder: "Sua senha", value: password, onChange: onPasswordChange, onSubmit: () => {
|
|
20
|
-
onSubmit();
|
|
21
|
-
} })] }), _jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { dimColor: true, children: "Enter faz login. Tab ou setas alternam o campo ativo." }), _jsxs(Text, { dimColor: true, children: ["Sessao persistida localmente em: ", sessionStorageFilePath] })] })] }));
|
|
22
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
type DiscoveryStepHeaderProps = {
|
|
2
|
-
readonly subtitle: string;
|
|
3
|
-
readonly title: string;
|
|
4
|
-
};
|
|
5
|
-
export declare function DiscoveryStepHeader({ subtitle, title }: DiscoveryStepHeaderProps): import("react/jsx-runtime").JSX.Element;
|
|
6
|
-
export {};
|
|
7
|
-
//# sourceMappingURL=discovery-step-header.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"discovery-step-header.d.ts","sourceRoot":"","sources":["../../../../src/modules/discovery/components/discovery-step-header.tsx"],"names":[],"mappings":"AAEA,KAAK,wBAAwB,GAAG;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,wBAAwB,2CAOhF"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Box, Text } from 'ink';
|
|
3
|
-
export function DiscoveryStepHeader({ subtitle, title }) {
|
|
4
|
-
return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { color: "yellow", children: title }), _jsx(Text, { dimColor: true, children: subtitle })] }));
|
|
5
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
type DiscoveryScope = 'amplo' | 'restrito';
|
|
2
|
-
type DiscoveryPageProps = {
|
|
3
|
-
readonly onCancel: () => void;
|
|
4
|
-
readonly onComplete: (result: {
|
|
5
|
-
scope: DiscoveryScope;
|
|
6
|
-
theme: string;
|
|
7
|
-
}) => void;
|
|
8
|
-
};
|
|
9
|
-
export declare function DiscoveryPage({ onCancel, onComplete }: DiscoveryPageProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
-
export {};
|
|
11
|
-
//# sourceMappingURL=discovery-page.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"discovery-page.d.ts","sourceRoot":"","sources":["../../../../src/modules/discovery/page/discovery-page.tsx"],"names":[],"mappings":"AAOA,KAAK,cAAc,GAAG,OAAO,GAAG,UAAU,CAAC;AAE3C,KAAK,kBAAkB,GAAG;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,IAAI,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,cAAc,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CACjF,CAAC;AAeF,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,kBAAkB,2CAsEzE"}
|