@blackcode_sa/metaestetics-api 1.14.71 → 1.14.73
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/index.d.mts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +60 -0
- package/dist/index.mjs +62 -1
- package/package.json +1 -1
- package/src/services/auth/auth.service.ts +79 -0
package/dist/index.d.mts
CHANGED
|
@@ -8615,6 +8615,22 @@ declare class AuthService extends BaseService {
|
|
|
8615
8615
|
* @returns The updated user profile.
|
|
8616
8616
|
*/
|
|
8617
8617
|
linkGoogleAccount(idToken: string): Promise<User>;
|
|
8618
|
+
/**
|
|
8619
|
+
* Sign in with Apple ID token (for existing users only).
|
|
8620
|
+
* Mirrors signInWithGoogleIdToken — verifies the user exists before allowing sign-in.
|
|
8621
|
+
*/
|
|
8622
|
+
signInWithAppleIdToken(idToken: string, rawNonce: string, appleUserInfo?: {
|
|
8623
|
+
fullName?: {
|
|
8624
|
+
givenName?: string;
|
|
8625
|
+
familyName?: string;
|
|
8626
|
+
};
|
|
8627
|
+
email?: string;
|
|
8628
|
+
}): Promise<User>;
|
|
8629
|
+
/**
|
|
8630
|
+
* Link an Apple account to the current user (anonymous → full account upgrade).
|
|
8631
|
+
* Mirrors linkGoogleAccount.
|
|
8632
|
+
*/
|
|
8633
|
+
linkAppleAccount(idToken: string, rawNonce: string): Promise<User>;
|
|
8618
8634
|
}
|
|
8619
8635
|
|
|
8620
8636
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -8615,6 +8615,22 @@ declare class AuthService extends BaseService {
|
|
|
8615
8615
|
* @returns The updated user profile.
|
|
8616
8616
|
*/
|
|
8617
8617
|
linkGoogleAccount(idToken: string): Promise<User>;
|
|
8618
|
+
/**
|
|
8619
|
+
* Sign in with Apple ID token (for existing users only).
|
|
8620
|
+
* Mirrors signInWithGoogleIdToken — verifies the user exists before allowing sign-in.
|
|
8621
|
+
*/
|
|
8622
|
+
signInWithAppleIdToken(idToken: string, rawNonce: string, appleUserInfo?: {
|
|
8623
|
+
fullName?: {
|
|
8624
|
+
givenName?: string;
|
|
8625
|
+
familyName?: string;
|
|
8626
|
+
};
|
|
8627
|
+
email?: string;
|
|
8628
|
+
}): Promise<User>;
|
|
8629
|
+
/**
|
|
8630
|
+
* Link an Apple account to the current user (anonymous → full account upgrade).
|
|
8631
|
+
* Mirrors linkGoogleAccount.
|
|
8632
|
+
*/
|
|
8633
|
+
linkAppleAccount(idToken: string, rawNonce: string): Promise<User>;
|
|
8618
8634
|
}
|
|
8619
8635
|
|
|
8620
8636
|
/**
|
package/dist/index.js
CHANGED
|
@@ -17040,6 +17040,66 @@ var AuthService = class extends BaseService {
|
|
|
17040
17040
|
throw handleFirebaseError(error);
|
|
17041
17041
|
}
|
|
17042
17042
|
}
|
|
17043
|
+
/**
|
|
17044
|
+
* Sign in with Apple ID token (for existing users only).
|
|
17045
|
+
* Mirrors signInWithGoogleIdToken — verifies the user exists before allowing sign-in.
|
|
17046
|
+
*/
|
|
17047
|
+
async signInWithAppleIdToken(idToken, rawNonce, appleUserInfo) {
|
|
17048
|
+
try {
|
|
17049
|
+
console.log("[AUTH] Signing in with Apple ID Token");
|
|
17050
|
+
const provider = new import_auth8.OAuthProvider("apple.com");
|
|
17051
|
+
const credential = provider.credential({ idToken, rawNonce });
|
|
17052
|
+
const { user: firebaseUser } = await (0, import_auth8.signInWithCredential)(this.auth, credential);
|
|
17053
|
+
console.log("[AUTH] Firebase user signed in via Apple:", firebaseUser.uid);
|
|
17054
|
+
const existingUser = await this.userService.getUserById(firebaseUser.uid);
|
|
17055
|
+
if (existingUser) {
|
|
17056
|
+
console.log("[AUTH] Existing user found, returning profile:", existingUser.uid);
|
|
17057
|
+
return existingUser;
|
|
17058
|
+
}
|
|
17059
|
+
console.log("[AUTH] No existing MetaEstetics user for Apple account \u2013 signing out.");
|
|
17060
|
+
await (0, import_auth8.signOut)(this.auth);
|
|
17061
|
+
throw new AuthError(
|
|
17062
|
+
'No account found. Please complete registration by starting with "Get Started".',
|
|
17063
|
+
"AUTH/USER_NOT_FOUND",
|
|
17064
|
+
404
|
|
17065
|
+
);
|
|
17066
|
+
} catch (error) {
|
|
17067
|
+
console.error("[AUTH] Error in signInWithAppleIdToken:", error);
|
|
17068
|
+
throw handleFirebaseError(error);
|
|
17069
|
+
}
|
|
17070
|
+
}
|
|
17071
|
+
/**
|
|
17072
|
+
* Link an Apple account to the current user (anonymous → full account upgrade).
|
|
17073
|
+
* Mirrors linkGoogleAccount.
|
|
17074
|
+
*/
|
|
17075
|
+
async linkAppleAccount(idToken, rawNonce) {
|
|
17076
|
+
try {
|
|
17077
|
+
console.log("[AUTH] Linking Apple account with ID Token");
|
|
17078
|
+
const currentUser = this.auth.currentUser;
|
|
17079
|
+
if (!currentUser) {
|
|
17080
|
+
throw AUTH_ERRORS.NOT_AUTHENTICATED;
|
|
17081
|
+
}
|
|
17082
|
+
const wasAnonymous = currentUser.isAnonymous;
|
|
17083
|
+
console.log(`[AUTH] Current user is ${wasAnonymous ? "anonymous" : "not anonymous"}`);
|
|
17084
|
+
const provider = new import_auth8.OAuthProvider("apple.com");
|
|
17085
|
+
const credential = provider.credential({ idToken, rawNonce });
|
|
17086
|
+
const userCredential = await (0, import_auth8.linkWithCredential)(currentUser, credential);
|
|
17087
|
+
const linkedFirebaseUser = userCredential.user;
|
|
17088
|
+
console.log("[AUTH] Apple account linked successfully to user:", linkedFirebaseUser.uid);
|
|
17089
|
+
if (wasAnonymous) {
|
|
17090
|
+
console.log("[AUTH] Upgrading anonymous user profile");
|
|
17091
|
+
const email = linkedFirebaseUser.email || "";
|
|
17092
|
+
return await this.userService.upgradeAnonymousUser(
|
|
17093
|
+
linkedFirebaseUser.uid,
|
|
17094
|
+
email
|
|
17095
|
+
);
|
|
17096
|
+
}
|
|
17097
|
+
return await this.userService.getUserById(linkedFirebaseUser.uid);
|
|
17098
|
+
} catch (error) {
|
|
17099
|
+
console.error("[AUTH] Error in linkAppleAccount:", error);
|
|
17100
|
+
throw handleFirebaseError(error);
|
|
17101
|
+
}
|
|
17102
|
+
}
|
|
17043
17103
|
};
|
|
17044
17104
|
|
|
17045
17105
|
// src/services/calendar/calendar.v2.service.ts
|
package/dist/index.mjs
CHANGED
|
@@ -7639,7 +7639,8 @@ import {
|
|
|
7639
7639
|
verifyPasswordResetCode,
|
|
7640
7640
|
confirmPasswordReset,
|
|
7641
7641
|
fetchSignInMethodsForEmail as fetchSignInMethodsForEmail2,
|
|
7642
|
-
signInWithCredential
|
|
7642
|
+
signInWithCredential,
|
|
7643
|
+
OAuthProvider
|
|
7643
7644
|
} from "firebase/auth";
|
|
7644
7645
|
import {
|
|
7645
7646
|
collection as collection21,
|
|
@@ -17128,6 +17129,66 @@ var AuthService = class extends BaseService {
|
|
|
17128
17129
|
throw handleFirebaseError(error);
|
|
17129
17130
|
}
|
|
17130
17131
|
}
|
|
17132
|
+
/**
|
|
17133
|
+
* Sign in with Apple ID token (for existing users only).
|
|
17134
|
+
* Mirrors signInWithGoogleIdToken — verifies the user exists before allowing sign-in.
|
|
17135
|
+
*/
|
|
17136
|
+
async signInWithAppleIdToken(idToken, rawNonce, appleUserInfo) {
|
|
17137
|
+
try {
|
|
17138
|
+
console.log("[AUTH] Signing in with Apple ID Token");
|
|
17139
|
+
const provider = new OAuthProvider("apple.com");
|
|
17140
|
+
const credential = provider.credential({ idToken, rawNonce });
|
|
17141
|
+
const { user: firebaseUser } = await signInWithCredential(this.auth, credential);
|
|
17142
|
+
console.log("[AUTH] Firebase user signed in via Apple:", firebaseUser.uid);
|
|
17143
|
+
const existingUser = await this.userService.getUserById(firebaseUser.uid);
|
|
17144
|
+
if (existingUser) {
|
|
17145
|
+
console.log("[AUTH] Existing user found, returning profile:", existingUser.uid);
|
|
17146
|
+
return existingUser;
|
|
17147
|
+
}
|
|
17148
|
+
console.log("[AUTH] No existing MetaEstetics user for Apple account \u2013 signing out.");
|
|
17149
|
+
await firebaseSignOut(this.auth);
|
|
17150
|
+
throw new AuthError(
|
|
17151
|
+
'No account found. Please complete registration by starting with "Get Started".',
|
|
17152
|
+
"AUTH/USER_NOT_FOUND",
|
|
17153
|
+
404
|
|
17154
|
+
);
|
|
17155
|
+
} catch (error) {
|
|
17156
|
+
console.error("[AUTH] Error in signInWithAppleIdToken:", error);
|
|
17157
|
+
throw handleFirebaseError(error);
|
|
17158
|
+
}
|
|
17159
|
+
}
|
|
17160
|
+
/**
|
|
17161
|
+
* Link an Apple account to the current user (anonymous → full account upgrade).
|
|
17162
|
+
* Mirrors linkGoogleAccount.
|
|
17163
|
+
*/
|
|
17164
|
+
async linkAppleAccount(idToken, rawNonce) {
|
|
17165
|
+
try {
|
|
17166
|
+
console.log("[AUTH] Linking Apple account with ID Token");
|
|
17167
|
+
const currentUser = this.auth.currentUser;
|
|
17168
|
+
if (!currentUser) {
|
|
17169
|
+
throw AUTH_ERRORS.NOT_AUTHENTICATED;
|
|
17170
|
+
}
|
|
17171
|
+
const wasAnonymous = currentUser.isAnonymous;
|
|
17172
|
+
console.log(`[AUTH] Current user is ${wasAnonymous ? "anonymous" : "not anonymous"}`);
|
|
17173
|
+
const provider = new OAuthProvider("apple.com");
|
|
17174
|
+
const credential = provider.credential({ idToken, rawNonce });
|
|
17175
|
+
const userCredential = await linkWithCredential(currentUser, credential);
|
|
17176
|
+
const linkedFirebaseUser = userCredential.user;
|
|
17177
|
+
console.log("[AUTH] Apple account linked successfully to user:", linkedFirebaseUser.uid);
|
|
17178
|
+
if (wasAnonymous) {
|
|
17179
|
+
console.log("[AUTH] Upgrading anonymous user profile");
|
|
17180
|
+
const email = linkedFirebaseUser.email || "";
|
|
17181
|
+
return await this.userService.upgradeAnonymousUser(
|
|
17182
|
+
linkedFirebaseUser.uid,
|
|
17183
|
+
email
|
|
17184
|
+
);
|
|
17185
|
+
}
|
|
17186
|
+
return await this.userService.getUserById(linkedFirebaseUser.uid);
|
|
17187
|
+
} catch (error) {
|
|
17188
|
+
console.error("[AUTH] Error in linkAppleAccount:", error);
|
|
17189
|
+
throw handleFirebaseError(error);
|
|
17190
|
+
}
|
|
17191
|
+
}
|
|
17131
17192
|
};
|
|
17132
17193
|
|
|
17133
17194
|
// src/services/calendar/calendar.v2.service.ts
|
package/package.json
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
confirmPasswordReset,
|
|
18
18
|
fetchSignInMethodsForEmail,
|
|
19
19
|
signInWithCredential,
|
|
20
|
+
OAuthProvider,
|
|
20
21
|
} from 'firebase/auth';
|
|
21
22
|
import {
|
|
22
23
|
getFirestore,
|
|
@@ -1411,4 +1412,82 @@ export class AuthService extends BaseService {
|
|
|
1411
1412
|
throw handleFirebaseError(error);
|
|
1412
1413
|
}
|
|
1413
1414
|
}
|
|
1415
|
+
|
|
1416
|
+
/**
|
|
1417
|
+
* Sign in with Apple ID token (for existing users only).
|
|
1418
|
+
* Mirrors signInWithGoogleIdToken — verifies the user exists before allowing sign-in.
|
|
1419
|
+
*/
|
|
1420
|
+
async signInWithAppleIdToken(
|
|
1421
|
+
idToken: string,
|
|
1422
|
+
rawNonce: string,
|
|
1423
|
+
appleUserInfo?: { fullName?: { givenName?: string; familyName?: string }; email?: string },
|
|
1424
|
+
): Promise<User> {
|
|
1425
|
+
try {
|
|
1426
|
+
console.log('[AUTH] Signing in with Apple ID Token');
|
|
1427
|
+
|
|
1428
|
+
// Build Apple OAuth credential
|
|
1429
|
+
const provider = new OAuthProvider('apple.com');
|
|
1430
|
+
const credential = provider.credential({ idToken, rawNonce });
|
|
1431
|
+
|
|
1432
|
+
// Sign in to Firebase
|
|
1433
|
+
const { user: firebaseUser } = await signInWithCredential(this.auth, credential);
|
|
1434
|
+
console.log('[AUTH] Firebase user signed in via Apple:', firebaseUser.uid);
|
|
1435
|
+
|
|
1436
|
+
// Load domain user document
|
|
1437
|
+
const existingUser = await this.userService.getUserById(firebaseUser.uid);
|
|
1438
|
+
if (existingUser) {
|
|
1439
|
+
console.log('[AUTH] Existing user found, returning profile:', existingUser.uid);
|
|
1440
|
+
return existingUser;
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
// No user document — sign out and error
|
|
1444
|
+
console.log('[AUTH] No existing MetaEstetics user for Apple account – signing out.');
|
|
1445
|
+
await firebaseSignOut(this.auth);
|
|
1446
|
+
throw new AuthError(
|
|
1447
|
+
'No account found. Please complete registration by starting with "Get Started".',
|
|
1448
|
+
'AUTH/USER_NOT_FOUND',
|
|
1449
|
+
404,
|
|
1450
|
+
);
|
|
1451
|
+
} catch (error) {
|
|
1452
|
+
console.error('[AUTH] Error in signInWithAppleIdToken:', error);
|
|
1453
|
+
throw handleFirebaseError(error);
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
/**
|
|
1458
|
+
* Link an Apple account to the current user (anonymous → full account upgrade).
|
|
1459
|
+
* Mirrors linkGoogleAccount.
|
|
1460
|
+
*/
|
|
1461
|
+
async linkAppleAccount(idToken: string, rawNonce: string): Promise<User> {
|
|
1462
|
+
try {
|
|
1463
|
+
console.log('[AUTH] Linking Apple account with ID Token');
|
|
1464
|
+
const currentUser = this.auth.currentUser;
|
|
1465
|
+
if (!currentUser) {
|
|
1466
|
+
throw AUTH_ERRORS.NOT_AUTHENTICATED;
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
const wasAnonymous = currentUser.isAnonymous;
|
|
1470
|
+
console.log(`[AUTH] Current user is ${wasAnonymous ? 'anonymous' : 'not anonymous'}`);
|
|
1471
|
+
|
|
1472
|
+
const provider = new OAuthProvider('apple.com');
|
|
1473
|
+
const credential = provider.credential({ idToken, rawNonce });
|
|
1474
|
+
const userCredential = await linkWithCredential(currentUser, credential);
|
|
1475
|
+
const linkedFirebaseUser = userCredential.user;
|
|
1476
|
+
console.log('[AUTH] Apple account linked successfully to user:', linkedFirebaseUser.uid);
|
|
1477
|
+
|
|
1478
|
+
if (wasAnonymous) {
|
|
1479
|
+
console.log('[AUTH] Upgrading anonymous user profile');
|
|
1480
|
+
const email = linkedFirebaseUser.email || '';
|
|
1481
|
+
return await this.userService.upgradeAnonymousUser(
|
|
1482
|
+
linkedFirebaseUser.uid,
|
|
1483
|
+
email,
|
|
1484
|
+
);
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
return (await this.userService.getUserById(linkedFirebaseUser.uid))!;
|
|
1488
|
+
} catch (error) {
|
|
1489
|
+
console.error('[AUTH] Error in linkAppleAccount:', error);
|
|
1490
|
+
throw handleFirebaseError(error);
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1414
1493
|
}
|