|
1 | 1 | import { createHash } from 'node:crypto' |
2 | | -import { isRecordLike } from '@sim/utils/object' |
| 2 | +import { isRecordLike, toRecord } from '@sim/utils/object' |
3 | 3 | import type { OAuth2Tokens } from 'better-auth/oauth2' |
4 | 4 | import type { GenericOAuthConfig } from 'better-auth/plugins' |
5 | 5 | import { OAuth2Client, type TokenPayload } from 'google-auth-library' |
@@ -830,7 +830,7 @@ const USER_INFO_MANAGED_OAUTH_CONNECTORS = new Map<string, () => ManagedOAuthCon |
830 | 830 | }, |
831 | 831 | parse: (profile) => { |
832 | 832 | const account = asProfileRecord(profile, 'Dropbox') |
833 | | - const name = isRecordLike(account.name) ? account.name : {} |
| 833 | + const name = toRecord(account.name) |
834 | 834 | return withOptionalIdentityFields( |
835 | 835 | { |
836 | 836 | providerSubjectId: requireIdentityField(account.account_id, 'Dropbox account id'), |
@@ -889,15 +889,15 @@ const USER_INFO_MANAGED_OAUTH_CONNECTORS = new Map<string, () => ManagedOAuthCon |
889 | 889 | * `bot.owner.user`. A workspace-owned internal integration reports |
890 | 890 | * `{ type: 'workspace' }` and identifies nobody, which cannot be bound to an invitation. |
891 | 891 | */ |
892 | | - const bot = isRecordLike(self.bot) ? self.bot : {} |
893 | | - const owner = isRecordLike(bot.owner) ? bot.owner : {} |
| 892 | + const bot = toRecord(self.bot) |
| 893 | + const owner = toRecord(bot.owner) |
894 | 894 | if (owner.type !== 'user') { |
895 | 895 | throw new Error( |
896 | 896 | 'Notion returned a workspace-owned integration, which identifies no person to bind this invitation to' |
897 | 897 | ) |
898 | 898 | } |
899 | 899 | const user = asProfileRecord(owner.user, 'Notion') |
900 | | - const person = isRecordLike(user.person) ? user.person : {} |
| 900 | + const person = toRecord(user.person) |
901 | 901 | return withOptionalIdentityFields( |
902 | 902 | { |
903 | 903 | providerSubjectId: requireIdentityField(user.id, 'Notion user id'), |
@@ -1004,7 +1004,7 @@ const USER_INFO_MANAGED_OAUTH_CONNECTORS = new Map<string, () => ManagedOAuthCon |
1004 | 1004 | scopes: { |
1005 | 1005 | from: 'profile', |
1006 | 1006 | read: (profile) => { |
1007 | | - const metadata = isRecordLike(profile) ? profile : {} |
| 1007 | + const metadata = toRecord(profile) |
1008 | 1008 | if (Array.isArray(metadata.scopes)) { |
1009 | 1009 | return metadata.scopes.filter((scope): scope is string => typeof scope === 'string') |
1010 | 1010 | } |
@@ -1135,7 +1135,7 @@ const USER_INFO_MANAGED_OAUTH_CONNECTORS = new Map<string, () => ManagedOAuthCon |
1135 | 1135 | parse: (profile) => { |
1136 | 1136 | const envelope = asProfileRecord(profile, 'Asana') |
1137 | 1137 | const user = asProfileRecord(envelope.data, 'Asana') |
1138 | | - const photo = isRecordLike(user.photo) ? user.photo : {} |
| 1138 | + const photo = toRecord(user.photo) |
1139 | 1139 | return withOptionalIdentityFields( |
1140 | 1140 | { |
1141 | 1141 | providerSubjectId: requireIdentityField(user.gid, 'Asana user id'), |
|
0 commit comments