@dailyautomations/auth 1.0.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/client.d.ts +56 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +169 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +16 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +49 -0
- package/dist/errors.js.map +1 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +15 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useAuth.d.ts +22 -0
- package/dist/hooks/useAuth.d.ts.map +1 -0
- package/dist/hooks/useAuth.js +221 -0
- package/dist/hooks/useAuth.js.map +1 -0
- package/dist/hooks/useUser.d.ts +36 -0
- package/dist/hooks/useUser.d.ts.map +1 -0
- package/dist/hooks/useUser.js +40 -0
- package/dist/hooks/useUser.js.map +1 -0
- package/dist/identity.d.ts +42 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +179 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware.d.ts +49 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +116 -0
- package/dist/middleware.js.map +1 -0
- package/dist/provisioning.d.ts +41 -0
- package/dist/provisioning.d.ts.map +1 -0
- package/dist/provisioning.js +224 -0
- package/dist/provisioning.js.map +1 -0
- package/dist/react.d.ts +7 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +14 -0
- package/dist/react.js.map +1 -0
- package/dist/types.d.ts +99 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/workspace.d.ts +28 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +121 -0
- package/dist/workspace.js.map +1 -0
- package/package.json +75 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @daily/auth Client
|
|
3
|
+
* Standard authentication client for Daily applications
|
|
4
|
+
*/
|
|
5
|
+
import { type SupabaseClient, type User, type Session } from '@supabase/supabase-js';
|
|
6
|
+
import type { DailyAuthOptions, SignUpParams, SignInParams, OAuthParams, ResetPasswordParams, AuthResult, WorkspaceInfo } from './types.js';
|
|
7
|
+
export declare class DailyAuth {
|
|
8
|
+
private supabase;
|
|
9
|
+
private adminSupabase?;
|
|
10
|
+
private autoCreateWorkspace;
|
|
11
|
+
private workspace;
|
|
12
|
+
constructor(options: DailyAuthOptions);
|
|
13
|
+
/**
|
|
14
|
+
* Get the underlying Supabase client
|
|
15
|
+
*/
|
|
16
|
+
getClient(): SupabaseClient;
|
|
17
|
+
/**
|
|
18
|
+
* Sign up a new user
|
|
19
|
+
*/
|
|
20
|
+
signUp(params: SignUpParams): Promise<AuthResult>;
|
|
21
|
+
/**
|
|
22
|
+
* Sign in an existing user
|
|
23
|
+
*/
|
|
24
|
+
signIn(params: SignInParams): Promise<AuthResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Sign in with OAuth provider
|
|
27
|
+
*/
|
|
28
|
+
signInWithOAuth(params: OAuthParams): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Sign out the current user
|
|
31
|
+
*/
|
|
32
|
+
signOut(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Request password reset email
|
|
35
|
+
*/
|
|
36
|
+
resetPassword(params: ResetPasswordParams): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Get current session
|
|
39
|
+
*/
|
|
40
|
+
getSession(): Promise<Session | null>;
|
|
41
|
+
/**
|
|
42
|
+
* Get current user
|
|
43
|
+
*/
|
|
44
|
+
getUser(): Promise<User | null>;
|
|
45
|
+
/**
|
|
46
|
+
* Get user's workspaces
|
|
47
|
+
*/
|
|
48
|
+
getWorkspaces(userId: string): Promise<WorkspaceInfo[]>;
|
|
49
|
+
/**
|
|
50
|
+
* Listen to auth state changes
|
|
51
|
+
*/
|
|
52
|
+
onAuthStateChange(callback: (event: string, session: Session | null) => void): {
|
|
53
|
+
unsubscribe: () => void;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,IAAI,EACT,KAAK,OAAO,EACb,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,mBAAmB,EACnB,UAAU,EACV,aAAa,EACd,MAAM,YAAY,CAAC;AAKpB,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,aAAa,CAAC,CAAiB;IACvC,OAAO,CAAC,mBAAmB,CAAU;IACrC,OAAO,CAAC,SAAS,CAAmB;gBAExB,OAAO,EAAE,gBAAgB;IAmBrC;;OAEG;IACH,SAAS,IAAI,cAAc;IAI3B;;OAEG;IACG,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC;IA0CvD;;OAEG;IACG,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC;IAgCvD;;OAEG;IACG,eAAe,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAazD;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAO9B;;OAEG;IACG,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAY/D;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAK3C;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAKrC;;OAEG;IACG,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAI7D;;OAEG;IACH,iBAAiB,CACf,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,KAAK,IAAI,GACzD;QAAE,WAAW,EAAE,MAAM,IAAI,CAAA;KAAE;CAI/B"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @daily/auth Client
|
|
4
|
+
* Standard authentication client for Daily applications
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.DailyAuth = void 0;
|
|
8
|
+
const supabase_js_1 = require("@supabase/supabase-js");
|
|
9
|
+
const errors_js_1 = require("./errors.js");
|
|
10
|
+
const workspace_js_1 = require("./workspace.js");
|
|
11
|
+
class DailyAuth {
|
|
12
|
+
supabase;
|
|
13
|
+
adminSupabase;
|
|
14
|
+
autoCreateWorkspace;
|
|
15
|
+
workspace;
|
|
16
|
+
constructor(options) {
|
|
17
|
+
this.autoCreateWorkspace = options.autoCreateWorkspace ?? true;
|
|
18
|
+
// Client-side Supabase (uses anon key)
|
|
19
|
+
this.supabase = (0, supabase_js_1.createClient)(options.supabaseUrl, options.supabaseAnonKey);
|
|
20
|
+
// Server-side Supabase with service key
|
|
21
|
+
if (options.serviceKey) {
|
|
22
|
+
this.adminSupabase = (0, supabase_js_1.createClient)(options.supabaseUrl, options.serviceKey, {
|
|
23
|
+
auth: { autoRefreshToken: false, persistSession: false },
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
this.workspace = new workspace_js_1.WorkspaceService(this.adminSupabase || this.supabase, options.workspaceNameTemplate);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get the underlying Supabase client
|
|
30
|
+
*/
|
|
31
|
+
getClient() {
|
|
32
|
+
return this.supabase;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Sign up a new user
|
|
36
|
+
*/
|
|
37
|
+
async signUp(params) {
|
|
38
|
+
const { email, password, metadata, workspaceName } = params;
|
|
39
|
+
try {
|
|
40
|
+
const { data, error } = await this.supabase.auth.signUp({
|
|
41
|
+
email,
|
|
42
|
+
password,
|
|
43
|
+
options: { data: metadata },
|
|
44
|
+
});
|
|
45
|
+
if (error) {
|
|
46
|
+
throw errors_js_1.DailyAuthError.fromSupabaseError(error);
|
|
47
|
+
}
|
|
48
|
+
if (!data.user) {
|
|
49
|
+
throw new errors_js_1.DailyAuthError('UNKNOWN_ERROR', 'Signup succeeded but no user returned');
|
|
50
|
+
}
|
|
51
|
+
const result = {
|
|
52
|
+
user: data.user,
|
|
53
|
+
session: data.session,
|
|
54
|
+
isNewUser: true,
|
|
55
|
+
};
|
|
56
|
+
// Auto-create workspace for new user
|
|
57
|
+
if (this.autoCreateWorkspace && data.session) {
|
|
58
|
+
try {
|
|
59
|
+
const ws = await this.workspace.createForUser(data.user.id, email, workspaceName);
|
|
60
|
+
result.workspace = ws;
|
|
61
|
+
}
|
|
62
|
+
catch (wsError) {
|
|
63
|
+
console.error('Failed to create workspace:', wsError);
|
|
64
|
+
// Don't fail signup if workspace creation fails
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
if (err instanceof errors_js_1.DailyAuthError)
|
|
71
|
+
throw err;
|
|
72
|
+
throw errors_js_1.DailyAuthError.fromSupabaseError(err);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Sign in an existing user
|
|
77
|
+
*/
|
|
78
|
+
async signIn(params) {
|
|
79
|
+
const { email, password } = params;
|
|
80
|
+
try {
|
|
81
|
+
const { data, error } = await this.supabase.auth.signInWithPassword({
|
|
82
|
+
email,
|
|
83
|
+
password,
|
|
84
|
+
});
|
|
85
|
+
if (error) {
|
|
86
|
+
throw errors_js_1.DailyAuthError.fromSupabaseError(error);
|
|
87
|
+
}
|
|
88
|
+
if (!data.user || !data.session) {
|
|
89
|
+
throw new errors_js_1.DailyAuthError('INVALID_CREDENTIALS', 'Login failed');
|
|
90
|
+
}
|
|
91
|
+
// Get user's workspace
|
|
92
|
+
const workspaces = await this.workspace.getForUser(data.user.id);
|
|
93
|
+
return {
|
|
94
|
+
user: data.user,
|
|
95
|
+
session: data.session,
|
|
96
|
+
isNewUser: false,
|
|
97
|
+
workspace: workspaces[0], // Primary workspace
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
if (err instanceof errors_js_1.DailyAuthError)
|
|
102
|
+
throw err;
|
|
103
|
+
throw errors_js_1.DailyAuthError.fromSupabaseError(err);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Sign in with OAuth provider
|
|
108
|
+
*/
|
|
109
|
+
async signInWithOAuth(params) {
|
|
110
|
+
const { provider, redirectTo, scopes } = params;
|
|
111
|
+
const { error } = await this.supabase.auth.signInWithOAuth({
|
|
112
|
+
provider,
|
|
113
|
+
options: { redirectTo, scopes },
|
|
114
|
+
});
|
|
115
|
+
if (error) {
|
|
116
|
+
throw errors_js_1.DailyAuthError.fromSupabaseError(error);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Sign out the current user
|
|
121
|
+
*/
|
|
122
|
+
async signOut() {
|
|
123
|
+
const { error } = await this.supabase.auth.signOut();
|
|
124
|
+
if (error) {
|
|
125
|
+
throw errors_js_1.DailyAuthError.fromSupabaseError(error);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Request password reset email
|
|
130
|
+
*/
|
|
131
|
+
async resetPassword(params) {
|
|
132
|
+
const { email, redirectTo } = params;
|
|
133
|
+
const { error } = await this.supabase.auth.resetPasswordForEmail(email, {
|
|
134
|
+
redirectTo,
|
|
135
|
+
});
|
|
136
|
+
if (error) {
|
|
137
|
+
throw errors_js_1.DailyAuthError.fromSupabaseError(error);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Get current session
|
|
142
|
+
*/
|
|
143
|
+
async getSession() {
|
|
144
|
+
const { data } = await this.supabase.auth.getSession();
|
|
145
|
+
return data.session;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get current user
|
|
149
|
+
*/
|
|
150
|
+
async getUser() {
|
|
151
|
+
const { data } = await this.supabase.auth.getUser();
|
|
152
|
+
return data.user;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Get user's workspaces
|
|
156
|
+
*/
|
|
157
|
+
async getWorkspaces(userId) {
|
|
158
|
+
return this.workspace.getForUser(userId);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Listen to auth state changes
|
|
162
|
+
*/
|
|
163
|
+
onAuthStateChange(callback) {
|
|
164
|
+
const { data: { subscription } } = this.supabase.auth.onAuthStateChange(callback);
|
|
165
|
+
return { unsubscribe: () => subscription.unsubscribe() };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
exports.DailyAuth = DailyAuth;
|
|
169
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,uDAK+B;AAY/B,2CAA6C;AAC7C,iDAAkD;AAElD,MAAa,SAAS;IACZ,QAAQ,CAAiB;IACzB,aAAa,CAAkB;IAC/B,mBAAmB,CAAU;IAC7B,SAAS,CAAmB;IAEpC,YAAY,OAAyB;QACnC,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,IAAI,IAAI,CAAC;QAE/D,uCAAuC;QACv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E,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,qBAAqB,CAAC,KAAK,EAAE;YACtE,UAAU;SACX,CAAC,CAAC;QAEH,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,0BAAc,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU;QACd,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;QACvD,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO;QACX,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACpD,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,aAAa,CAAC,MAAc;QAChC,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,iBAAiB,CACf,QAA0D;QAE1D,MAAM,EAAE,IAAI,EAAE,EAAE,YAAY,EAAE,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAClF,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,EAAE,CAAC;IAC3D,CAAC;CACF;AAzLD,8BAyLC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @daily/auth Errors
|
|
3
|
+
* Custom error classes for authentication
|
|
4
|
+
*/
|
|
5
|
+
import type { AuthErrorCode, AuthErrorInfo } from './types.js';
|
|
6
|
+
export declare class DailyAuthError extends Error {
|
|
7
|
+
readonly code: AuthErrorCode;
|
|
8
|
+
readonly hint?: string;
|
|
9
|
+
constructor(code: AuthErrorCode, message: string, hint?: string);
|
|
10
|
+
toJSON(): AuthErrorInfo;
|
|
11
|
+
static fromSupabaseError(error: {
|
|
12
|
+
message: string;
|
|
13
|
+
status?: number;
|
|
14
|
+
}): DailyAuthError;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE/D,qBAAa,cAAe,SAAQ,KAAK;IACvC,SAAgB,IAAI,EAAE,aAAa,CAAC;IACpC,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;gBAElB,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;IAQ/D,MAAM,IAAI,aAAa;IAQvB,MAAM,CAAC,iBAAiB,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,cAAc;CAyDtF"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @daily/auth Errors
|
|
4
|
+
* Custom error classes for authentication
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.DailyAuthError = void 0;
|
|
8
|
+
class DailyAuthError extends Error {
|
|
9
|
+
code;
|
|
10
|
+
hint;
|
|
11
|
+
constructor(code, message, hint) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = 'DailyAuthError';
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.hint = hint;
|
|
16
|
+
Object.setPrototypeOf(this, DailyAuthError.prototype);
|
|
17
|
+
}
|
|
18
|
+
toJSON() {
|
|
19
|
+
return {
|
|
20
|
+
code: this.code,
|
|
21
|
+
message: this.message,
|
|
22
|
+
hint: this.hint,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
static fromSupabaseError(error) {
|
|
26
|
+
const message = error.message.toLowerCase();
|
|
27
|
+
if (message.includes('already registered') || message.includes('already exists')) {
|
|
28
|
+
return new DailyAuthError('EMAIL_ALREADY_EXISTS', 'An account with this email already exists', 'Try signing in instead, or reset your password');
|
|
29
|
+
}
|
|
30
|
+
if (message.includes('invalid login') || message.includes('invalid credentials')) {
|
|
31
|
+
return new DailyAuthError('INVALID_CREDENTIALS', 'Invalid email or password', 'Check your credentials and try again');
|
|
32
|
+
}
|
|
33
|
+
if (message.includes('email not confirmed')) {
|
|
34
|
+
return new DailyAuthError('EMAIL_NOT_CONFIRMED', 'Please confirm your email before signing in', 'Check your inbox for a confirmation link');
|
|
35
|
+
}
|
|
36
|
+
if (message.includes('password') && (message.includes('weak') || message.includes('short'))) {
|
|
37
|
+
return new DailyAuthError('WEAK_PASSWORD', 'Password is too weak', 'Use at least 8 characters with a mix of letters and numbers');
|
|
38
|
+
}
|
|
39
|
+
if (error.status === 429) {
|
|
40
|
+
return new DailyAuthError('RATE_LIMITED', 'Too many attempts. Please try again later', 'Wait a few minutes before trying again');
|
|
41
|
+
}
|
|
42
|
+
if (message.includes('network') || message.includes('fetch')) {
|
|
43
|
+
return new DailyAuthError('NETWORK_ERROR', 'Network error. Please check your connection', 'Ensure you have internet connectivity');
|
|
44
|
+
}
|
|
45
|
+
return new DailyAuthError('UNKNOWN_ERROR', error.message || 'An unexpected error occurred', 'Please try again or contact support');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.DailyAuthError = DailyAuthError;
|
|
49
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.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CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;YAC5F,OAAO,IAAI,cAAc,CACvB,eAAe,EACf,sBAAsB,EACtB,6DAA6D,CAC9D,CAAC;QACJ,CAAC;QAED,IAAI,KAAK,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YACzB,OAAO,IAAI,cAAc,CACvB,cAAc,EACd,2CAA2C,EAC3C,wCAAwC,CACzC,CAAC;QACJ,CAAC;QAED,IAAI,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7D,OAAO,IAAI,cAAc,CACvB,eAAe,EACf,6CAA6C,EAC7C,uCAAuC,CACxC,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,cAAc,CACvB,eAAe,EACf,KAAK,CAAC,OAAO,IAAI,8BAA8B,EAC/C,qCAAqC,CACtC,CAAC;IACJ,CAAC;CACF;AA7ED,wCA6EC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @daily/auth React Hooks
|
|
3
|
+
* Re-exports all hooks for convenient importing
|
|
4
|
+
*/
|
|
5
|
+
export { AuthProvider, useAuth, useAuthClient, type AuthProviderProps } from './useAuth.js';
|
|
6
|
+
export { useUser, useRequiredUser, type UseUserReturn } from './useUser.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC5F,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @daily/auth React Hooks
|
|
4
|
+
* Re-exports all hooks for convenient importing
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.useRequiredUser = exports.useUser = exports.useAuthClient = exports.useAuth = exports.AuthProvider = void 0;
|
|
8
|
+
var useAuth_js_1 = require("./useAuth.js");
|
|
9
|
+
Object.defineProperty(exports, "AuthProvider", { enumerable: true, get: function () { return useAuth_js_1.AuthProvider; } });
|
|
10
|
+
Object.defineProperty(exports, "useAuth", { enumerable: true, get: function () { return useAuth_js_1.useAuth; } });
|
|
11
|
+
Object.defineProperty(exports, "useAuthClient", { enumerable: true, get: function () { return useAuth_js_1.useAuthClient; } });
|
|
12
|
+
var useUser_js_1 = require("./useUser.js");
|
|
13
|
+
Object.defineProperty(exports, "useUser", { enumerable: true, get: function () { return useUser_js_1.useUser; } });
|
|
14
|
+
Object.defineProperty(exports, "useRequiredUser", { enumerable: true, get: function () { return useUser_js_1.useRequiredUser; } });
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2CAA4F;AAAnF,0GAAA,YAAY,OAAA;AAAE,qGAAA,OAAO,OAAA;AAAE,2GAAA,aAAa,OAAA;AAC7C,2CAA4E;AAAnE,qGAAA,OAAO,OAAA;AAAE,6GAAA,eAAe,OAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @daily/auth React Hooks
|
|
3
|
+
* useAuth hook for React applications
|
|
4
|
+
*/
|
|
5
|
+
import { type ReactNode } from 'react';
|
|
6
|
+
import { DailyAuth } from '../client.js';
|
|
7
|
+
import type { DailyAuthOptions, UseAuthReturn, AuthErrorInfo, AuthResult } from '../types.js';
|
|
8
|
+
export interface AuthProviderProps {
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
options: DailyAuthOptions;
|
|
11
|
+
onSignUp?: (result: AuthResult) => void;
|
|
12
|
+
onSignIn?: (result: AuthResult) => void;
|
|
13
|
+
onSignOut?: () => void;
|
|
14
|
+
onError?: (error: AuthErrorInfo) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare function AuthProvider({ children, options, onSignUp, onSignIn, onSignOut, onError, }: AuthProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export declare function useAuth(): UseAuthReturn;
|
|
18
|
+
/**
|
|
19
|
+
* Get the underlying DailyAuth client
|
|
20
|
+
*/
|
|
21
|
+
export declare function useAuthClient(): DailyAuth;
|
|
22
|
+
//# sourceMappingURL=useAuth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/hooks/useAuth.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAOL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EACV,gBAAgB,EAEhB,aAAa,EAMb,aAAa,EACb,UAAU,EACX,MAAM,aAAa,CAAC;AAgBrB,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IACxC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IACxC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;CAC1C;AAED,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,OAAO,GACR,EAAE,iBAAiB,2CAwNnB;AAMD,wBAAgB,OAAO,IAAI,aAAa,CASvC;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,SAAS,CAQzC"}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthProvider = AuthProvider;
|
|
4
|
+
exports.useAuth = useAuth;
|
|
5
|
+
exports.useAuthClient = useAuthClient;
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
/**
|
|
8
|
+
* @daily/auth React Hooks
|
|
9
|
+
* useAuth hook for React applications
|
|
10
|
+
*/
|
|
11
|
+
const react_1 = require("react");
|
|
12
|
+
const client_js_1 = require("../client.js");
|
|
13
|
+
const AuthContext = (0, react_1.createContext)(null);
|
|
14
|
+
function AuthProvider({ children, options, onSignUp, onSignIn, onSignOut, onError, }) {
|
|
15
|
+
const [user, setUser] = (0, react_1.useState)(null);
|
|
16
|
+
const [session, setSession] = (0, react_1.useState)(null);
|
|
17
|
+
const [workspace, setWorkspace] = (0, react_1.useState)(null);
|
|
18
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
19
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
20
|
+
const client = (0, react_1.useMemo)(() => new client_js_1.DailyAuth(options), [options.supabaseUrl, options.supabaseAnonKey]);
|
|
21
|
+
// Initialize auth state
|
|
22
|
+
(0, react_1.useEffect)(() => {
|
|
23
|
+
const initAuth = async () => {
|
|
24
|
+
try {
|
|
25
|
+
const currentSession = await client.getSession();
|
|
26
|
+
if (currentSession) {
|
|
27
|
+
setSession(currentSession);
|
|
28
|
+
const currentUser = await client.getUser();
|
|
29
|
+
setUser(currentUser);
|
|
30
|
+
if (currentUser) {
|
|
31
|
+
const workspaces = await client.getWorkspaces(currentUser.id);
|
|
32
|
+
setWorkspace(workspaces[0] || null);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
console.error('Auth init error:', err);
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
setIsLoading(false);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
initAuth();
|
|
44
|
+
const { unsubscribe } = client.onAuthStateChange(async (event, newSession) => {
|
|
45
|
+
setSession(newSession);
|
|
46
|
+
if (newSession?.user) {
|
|
47
|
+
setUser(newSession.user);
|
|
48
|
+
const workspaces = await client.getWorkspaces(newSession.user.id);
|
|
49
|
+
setWorkspace(workspaces[0] || null);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
setUser(null);
|
|
53
|
+
setWorkspace(null);
|
|
54
|
+
}
|
|
55
|
+
if (event === 'SIGNED_OUT') {
|
|
56
|
+
onSignOut?.();
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return unsubscribe;
|
|
60
|
+
}, [client]);
|
|
61
|
+
// ==========================================================================
|
|
62
|
+
// AUTH ACTIONS
|
|
63
|
+
// ==========================================================================
|
|
64
|
+
const signUp = (0, react_1.useCallback)(async (params) => {
|
|
65
|
+
setIsLoading(true);
|
|
66
|
+
setError(null);
|
|
67
|
+
try {
|
|
68
|
+
const result = await client.signUp(params);
|
|
69
|
+
setUser(result.user);
|
|
70
|
+
setSession(result.session);
|
|
71
|
+
setWorkspace(result.workspace || null);
|
|
72
|
+
onSignUp?.(result);
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
const authError = err.toJSON?.() || {
|
|
77
|
+
code: 'UNKNOWN_ERROR',
|
|
78
|
+
message: err.message,
|
|
79
|
+
};
|
|
80
|
+
setError(authError);
|
|
81
|
+
onError?.(authError);
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
setIsLoading(false);
|
|
86
|
+
}
|
|
87
|
+
}, [client, onSignUp, onError]);
|
|
88
|
+
const signIn = (0, react_1.useCallback)(async (params) => {
|
|
89
|
+
setIsLoading(true);
|
|
90
|
+
setError(null);
|
|
91
|
+
try {
|
|
92
|
+
const result = await client.signIn(params);
|
|
93
|
+
setUser(result.user);
|
|
94
|
+
setSession(result.session);
|
|
95
|
+
setWorkspace(result.workspace || null);
|
|
96
|
+
onSignIn?.(result);
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
const authError = err.toJSON?.() || {
|
|
101
|
+
code: 'UNKNOWN_ERROR',
|
|
102
|
+
message: err.message,
|
|
103
|
+
};
|
|
104
|
+
setError(authError);
|
|
105
|
+
onError?.(authError);
|
|
106
|
+
throw err;
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
setIsLoading(false);
|
|
110
|
+
}
|
|
111
|
+
}, [client, onSignIn, onError]);
|
|
112
|
+
const signInWithOAuth = (0, react_1.useCallback)(async (params) => {
|
|
113
|
+
setError(null);
|
|
114
|
+
try {
|
|
115
|
+
await client.signInWithOAuth(params);
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
const authError = err.toJSON?.() || {
|
|
119
|
+
code: 'UNKNOWN_ERROR',
|
|
120
|
+
message: err.message,
|
|
121
|
+
};
|
|
122
|
+
setError(authError);
|
|
123
|
+
onError?.(authError);
|
|
124
|
+
throw err;
|
|
125
|
+
}
|
|
126
|
+
}, [client, onError]);
|
|
127
|
+
const signOut = (0, react_1.useCallback)(async () => {
|
|
128
|
+
setIsLoading(true);
|
|
129
|
+
try {
|
|
130
|
+
await client.signOut();
|
|
131
|
+
setUser(null);
|
|
132
|
+
setSession(null);
|
|
133
|
+
setWorkspace(null);
|
|
134
|
+
setError(null);
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
console.error('Sign out error:', err);
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
setIsLoading(false);
|
|
141
|
+
}
|
|
142
|
+
}, [client]);
|
|
143
|
+
const resetPassword = (0, react_1.useCallback)(async (params) => {
|
|
144
|
+
setError(null);
|
|
145
|
+
try {
|
|
146
|
+
await client.resetPassword(params);
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
const authError = err.toJSON?.() || {
|
|
150
|
+
code: 'UNKNOWN_ERROR',
|
|
151
|
+
message: err.message,
|
|
152
|
+
};
|
|
153
|
+
setError(authError);
|
|
154
|
+
onError?.(authError);
|
|
155
|
+
throw err;
|
|
156
|
+
}
|
|
157
|
+
}, [client, onError]);
|
|
158
|
+
const switchWorkspace = (0, react_1.useCallback)(async (workspaceId) => {
|
|
159
|
+
if (!user)
|
|
160
|
+
return;
|
|
161
|
+
const workspaces = await client.getWorkspaces(user.id);
|
|
162
|
+
const newWorkspace = workspaces.find((w) => w.id === workspaceId);
|
|
163
|
+
if (newWorkspace) {
|
|
164
|
+
setWorkspace(newWorkspace);
|
|
165
|
+
}
|
|
166
|
+
}, [client, user]);
|
|
167
|
+
// ==========================================================================
|
|
168
|
+
// CONTEXT VALUE
|
|
169
|
+
// ==========================================================================
|
|
170
|
+
const value = (0, react_1.useMemo)(() => ({
|
|
171
|
+
user,
|
|
172
|
+
session,
|
|
173
|
+
workspace,
|
|
174
|
+
isLoading,
|
|
175
|
+
isAuthenticated: !!user && !!session,
|
|
176
|
+
error,
|
|
177
|
+
signUp,
|
|
178
|
+
signIn,
|
|
179
|
+
signInWithOAuth,
|
|
180
|
+
signOut,
|
|
181
|
+
resetPassword,
|
|
182
|
+
switchWorkspace,
|
|
183
|
+
client,
|
|
184
|
+
}), [
|
|
185
|
+
user,
|
|
186
|
+
session,
|
|
187
|
+
workspace,
|
|
188
|
+
isLoading,
|
|
189
|
+
error,
|
|
190
|
+
signUp,
|
|
191
|
+
signIn,
|
|
192
|
+
signInWithOAuth,
|
|
193
|
+
signOut,
|
|
194
|
+
resetPassword,
|
|
195
|
+
switchWorkspace,
|
|
196
|
+
client,
|
|
197
|
+
]);
|
|
198
|
+
return (0, jsx_runtime_1.jsx)(AuthContext.Provider, { value: value, children: children });
|
|
199
|
+
}
|
|
200
|
+
// =============================================================================
|
|
201
|
+
// useAuth HOOK
|
|
202
|
+
// =============================================================================
|
|
203
|
+
function useAuth() {
|
|
204
|
+
const context = (0, react_1.useContext)(AuthContext);
|
|
205
|
+
if (!context) {
|
|
206
|
+
throw new Error('useAuth must be used within an AuthProvider');
|
|
207
|
+
}
|
|
208
|
+
const { client: _, ...authReturn } = context;
|
|
209
|
+
return authReturn;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Get the underlying DailyAuth client
|
|
213
|
+
*/
|
|
214
|
+
function useAuthClient() {
|
|
215
|
+
const context = (0, react_1.useContext)(AuthContext);
|
|
216
|
+
if (!context) {
|
|
217
|
+
throw new Error('useAuthClient must be used within an AuthProvider');
|
|
218
|
+
}
|
|
219
|
+
return context.client;
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=useAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAuth.js","sourceRoot":"","sources":["../../src/hooks/useAuth.tsx"],"names":[],"mappings":";;AAoDA,oCA+NC;AAMD,0BASC;AAKD,sCAQC;;AA/SD;;;GAGG;AAEH,iCAQe;AAEf,4CAAyC;AAsBzC,MAAM,WAAW,GAAG,IAAA,qBAAa,EAA0B,IAAI,CAAC,CAAC;AAejE,SAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,OAAO,GACW;IAClB,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAA,gBAAQ,EAAc,IAAI,CAAC,CAAC;IACpD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,IAAA,gBAAQ,EAAiB,IAAI,CAAC,CAAC;IAC7D,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,IAAA,gBAAQ,E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,CAAC;IAEF,OAAO,uBAAC,WAAW,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAwB,CAAC;AAC/E,CAAC;AAED,gFAAgF;AAChF,eAAe;AACf,gFAAgF;AAEhF,SAAgB,OAAO;IACrB,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,WAAW,CAAC,CAAC;IAExC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,UAAU,EAAE,GAAG,OAAO,CAAC;IAC7C,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa;IAC3B,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,WAAW,CAAC,CAAC;IAExC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IAED,OAAO,OAAO,CAAC,MAAM,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @daily/auth useUser Hook
|
|
3
|
+
* Simplified user access hook
|
|
4
|
+
*/
|
|
5
|
+
import type { User } from '@supabase/supabase-js';
|
|
6
|
+
import type { WorkspaceInfo } from '../types.js';
|
|
7
|
+
export interface UseUserReturn {
|
|
8
|
+
/** Current authenticated user */
|
|
9
|
+
user: User | null;
|
|
10
|
+
/** User's current workspace */
|
|
11
|
+
workspace: WorkspaceInfo | null;
|
|
12
|
+
/** User's email */
|
|
13
|
+
email: string | null;
|
|
14
|
+
/** User's display name (from metadata) */
|
|
15
|
+
displayName: string | null;
|
|
16
|
+
/** User's avatar URL (from metadata) */
|
|
17
|
+
avatarUrl: string | null;
|
|
18
|
+
/** Whether user data is loading */
|
|
19
|
+
isLoading: boolean;
|
|
20
|
+
/** Whether user is authenticated */
|
|
21
|
+
isAuthenticated: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Simplified hook for accessing current user info
|
|
25
|
+
* Use this when you only need user data, not auth actions
|
|
26
|
+
*/
|
|
27
|
+
export declare function useUser(): UseUserReturn;
|
|
28
|
+
/**
|
|
29
|
+
* Hook that throws if user is not authenticated
|
|
30
|
+
* Use in components that require authentication
|
|
31
|
+
*/
|
|
32
|
+
export declare function useRequiredUser(): Omit<UseUserReturn, 'user' | 'workspace'> & {
|
|
33
|
+
user: User;
|
|
34
|
+
workspace: WorkspaceInfo;
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=useUser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUser.d.ts","sourceRoot":"","sources":["../../src/hooks/useUser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,WAAW,aAAa;IAC5B,iCAAiC;IACjC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,+BAA+B;IAC/B,SAAS,EAAE,aAAa,GAAG,IAAI,CAAC;IAChC,mBAAmB;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,0CAA0C;IAC1C,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,wCAAwC;IACxC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,mCAAmC;IACnC,SAAS,EAAE,OAAO,CAAC;IACnB,oCAAoC;IACpC,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAgB,OAAO,IAAI,aAAa,CAYvC;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,WAAW,CAAC,GAAG;IAC7E,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,aAAa,CAAC;CAC1B,CAeA"}
|