Skip to content

Commit 782202f

Browse files
committed
feat: sync identities
1 parent 9ea0e34 commit 782202f

File tree

82 files changed

+1417
-472
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1417
-472
lines changed

api-schema.graphql

+18-2
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ input AdminUpdateNetworkInput {
158158

159159
input AdminUpdateNetworkTokenInput {
160160
name: String
161+
vault: String
161162
}
162163

163164
input AdminUpdateRuleInput {
@@ -305,6 +306,8 @@ type Identity {
305306
profile: JSON
306307
provider: IdentityProvider!
307308
providerId: String!
309+
syncEnded: DateTime
310+
syncStarted: DateTime
308311
updatedAt: DateTime
309312
url: String
310313
verified: Boolean
@@ -344,7 +347,7 @@ input LinkIdentityInput {
344347
type Log {
345348
bot: Bot
346349
botId: String
347-
communityId: String!
350+
communityId: String
348351
createdAt: DateTime
349352
data: JSON
350353
id: String!
@@ -353,6 +356,7 @@ type Log {
353356
identityProviderId: String
354357
level: LogLevel!
355358
message: String!
359+
networkAssetId: String
356360
relatedId: String
357361
relatedType: LogRelatedType
358362
rule: Rule
@@ -375,6 +379,7 @@ type LogPaging {
375379

376380
enum LogRelatedType {
377381
Bot
382+
BotMember
378383
Community
379384
Identity
380385
Rule
@@ -477,6 +482,7 @@ type NetworkAsset {
477482
name: String!
478483
owner: String!
479484
program: String
485+
resolver: NetworkResolver!
480486
symbol: String
481487
type: NetworkTokenType!
482488
updatedAt: DateTime
@@ -499,6 +505,12 @@ type NetworkPaging {
499505
meta: PagingMeta!
500506
}
501507

508+
enum NetworkResolver {
509+
Anybodies
510+
SolanaFungible
511+
SolanaNonFungible
512+
}
513+
502514
type NetworkToken {
503515
account: String!
504516
cluster: NetworkCluster!
@@ -513,6 +525,7 @@ type NetworkToken {
513525
symbol: String
514526
type: NetworkTokenType!
515527
updatedAt: DateTime
528+
vault: String
516529
}
517530

518531
type NetworkTokenPaging {
@@ -734,11 +747,12 @@ input UserFindManyIdentityInput {
734747

735748
input UserFindManyLogInput {
736749
botId: String
737-
communityId: String!
750+
communityId: String
738751
identityProvider: IdentityProvider
739752
identityProviderId: String
740753
level: LogLevel
741754
limit: Int = 10
755+
networkAssetId: String
742756
page: Int = 1
743757
relatedId: String
744758
relatedType: LogRelatedType
@@ -749,6 +763,7 @@ input UserFindManyLogInput {
749763

750764
input UserFindManyNetworkAssetInput {
751765
cluster: NetworkCluster!
766+
group: String
752767
limit: Int = 10
753768
page: Int = 1
754769
search: String
@@ -762,6 +777,7 @@ input UserFindManyNetworkTokenInput {
762777
page: Int = 1
763778
search: String
764779
type: NetworkTokenType
780+
username: String
765781
}
766782

767783
input UserFindManyRuleInput {

libs/api/bot/data-access/src/lib/api-bot-member.service.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ export class ApiBotMemberService {
6060
include: { bot: { select: { id: true, communityId: true } }, identity: { select: { ownerId: true } } },
6161
})
6262
.then(async (created) => {
63-
await this.core.logInfo(`Added ${userId} to ${serverId}`, {
64-
botId,
65-
communityId,
66-
identityProvider: IdentityProvider.Discord,
67-
identityProviderId: userId,
68-
})
6963
await this.core.data.communityMember.upsert({
7064
where: { communityId_userId: { communityId: created.bot.communityId, userId: created.identity.ownerId } },
7165
create: {
@@ -96,12 +90,6 @@ export class ApiBotMemberService {
9690
include: { bot: true, identity: { select: { ownerId: true } } },
9791
})
9892
.then(async (deleted) => {
99-
await this.core.logInfo(`Removed ${userId} from ${serverId}`, {
100-
botId,
101-
communityId,
102-
identityProvider: IdentityProvider.Discord,
103-
identityProviderId: userId,
104-
})
10593
const botMembers = await this.core.data.botMember.findMany({ where: { botId, userId } })
10694
if (!botMembers.length) {
10795
await this.core.data.communityMember
@@ -117,6 +105,8 @@ export class ApiBotMemberService {
117105
identityProvider: IdentityProvider.Discord,
118106
identityProviderId: userId,
119107
userId: res.userId,
108+
relatedId: res.id,
109+
relatedType: 'BotMember',
120110
})
121111
})
122112
}

libs/api/bot/data-access/src/lib/processors/api-bot-member-add-processor.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ export class ApiBotMemberAddProcessor extends WorkerHost {
2727
const added = await this.member.upsert(job.data)
2828
if (added) {
2929
await job.log(`Added ${job.data.userId} to ${job.data.serverId} by bot ${job.data.botId}`)
30-
await this.core.logInfo(`Added ${job.data.userId} to ${job.data.serverId} by bot ${job.data.botId}`, {
30+
await this.core.logInfo(`Added bot member`, {
3131
botId: job.data.botId,
3232
communityId: job.data.communityId,
3333
identityProvider: IdentityProvider.Discord,
3434
identityProviderId: job.data.userId,
35+
relatedId: added.id,
36+
relatedType: 'BotMember',
37+
data: { botId: job.data.botId, serverId: job.data.serverId, userId: job.data.userId },
3538
})
3639
return added
3740
} else {
@@ -41,6 +44,7 @@ export class ApiBotMemberAddProcessor extends WorkerHost {
4144
communityId: job.data.communityId,
4245
identityProvider: IdentityProvider.Discord,
4346
identityProviderId: job.data.userId,
47+
data: { botId: job.data.botId, serverId: job.data.serverId, userId: job.data.userId },
4448
})
4549
return undefined
4650
}

libs/api/core/data-access/src/lib/api-core-provision-data-networks.ts

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export const provisionNetworks: Prisma.NetworkCreateInput[] = [
9191
imageUrl: 'https://shdw-drive.genesysgo.net/GQfWBgNh4GUM1Y7nRrx8MFiMoxDLcNDCpsptXYxbozAE/collection.png',
9292
metadataUrl: 'https://shdw-drive.genesysgo.net/GQfWBgNh4GUM1Y7nRrx8MFiMoxDLcNDCpsptXYxbozAE/collection.json',
9393
name: 'Deanslist',
94+
vault: 'JiZUwqz0ETakNYOIulut:CjYTP9jJVmCqnmdPf8tyafTHxTQtAjsFckVGZWMwprca',
9495
program: TOKEN_PROGRAM_ID.toString(),
9596
symbol: 'DEAN',
9697
type: NetworkTokenType.NonFungible,

libs/api/core/data-access/src/lib/api-core-provision-data.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const provisionCommunities: Prisma.CommunityCreateInput[] = [
6666
{
6767
type: RuleConditionType.AnybodiesAsset,
6868
name: 'Deanslist NFT staked in Anybodies Vault',
69-
config: { vaultId: 'JiZUwqz0ETakNYOIulut' },
69+
config: { vault: 'JiZUwqz0ETakNYOIulut:CjYTP9jJVmCqnmdPf8tyafTHxTQtAjsFckVGZWMwprca' },
7070
amount: '1',
7171
},
7272
],
@@ -114,7 +114,7 @@ export const provisionCommunities: Prisma.CommunityCreateInput[] = [
114114
{
115115
type: RuleConditionType.AnybodiesAsset,
116116
name: 'Deanslist NFT staked in Anybodies Vault',
117-
config: { vaultId: 'JiZUwqz0ETakNYOIulut' },
117+
config: { vault: 'JiZUwqz0ETakNYOIulut:CjYTP9jJVmCqnmdPf8tyafTHxTQtAjsFckVGZWMwprca' },
118118
amount: '1',
119119
},
120120
],

libs/api/identity/data-access/src/lib/entity/identity.entity.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ export class Identity {
1212
createdAt?: Date
1313
@Field({ nullable: true })
1414
updatedAt?: Date
15-
15+
@Field({ nullable: true })
16+
syncStarted?: Date | null
17+
@Field({ nullable: true })
18+
syncEnded?: Date | null
1619
@Field(() => IdentityProvider)
1720
provider!: IdentityProvider
1821
@Field()

libs/api/log/data-access/src/lib/api-user-log.service.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ export class ApiUserLogService {
99
constructor(private readonly core: ApiCoreService) {}
1010

1111
async findManyLog(userId: string, input: UserFindManyLogInput): Promise<LogPaging> {
12-
await this.core.ensureCommunityAdmin({ communityId: input.communityId, userId })
12+
if (input.communityId) {
13+
await this.core.ensureCommunityAdmin({ communityId: input.communityId, userId })
14+
}
1315
return this.core.data.log
1416
.paginate({
1517
orderBy: { createdAt: 'desc' },
1618
where: getUserLogWhereInput(input),
19+
include: { bot: true, identity: true },
1720
})
1821
.withPages({ limit: input.limit, page: input.page })
1922
.then(([data, meta]) => ({ data, meta }))
@@ -27,7 +30,9 @@ export class ApiUserLogService {
2730
if (!found) {
2831
throw new Error('Log not found')
2932
}
30-
await this.core.ensureCommunityAdmin({ communityId: found.communityId, userId })
33+
if (found.communityId) {
34+
await this.core.ensureCommunityAdmin({ communityId: found.communityId, userId })
35+
}
3136
return found
3237
}
3338
}

libs/api/log/data-access/src/lib/dto/user-find-many-log.input.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import { LogRelatedType } from '../entity/log-related-type.enum'
55

66
@InputType()
77
export class UserFindManyLogInput extends PagingInput() {
8-
@Field()
9-
communityId!: string
8+
@Field({ nullable: true })
9+
communityId?: string
1010
@Field(() => LogLevel, { nullable: true })
1111
level?: LogLevel
1212
@Field({ nullable: true })
13+
botId?: string | null
14+
@Field({ nullable: true })
1315
relatedId?: string
1416
@Field(() => LogRelatedType, { nullable: true })
1517
relatedType?: LogRelatedType
@@ -18,7 +20,7 @@ export class UserFindManyLogInput extends PagingInput() {
1820
@Field({ nullable: true })
1921
identityProviderId?: string | null
2022
@Field({ nullable: true })
21-
botId?: string | null
23+
networkAssetId?: string
2224
@Field({ nullable: true })
2325
userId?: string | null
2426
@Field({ nullable: true })

libs/api/log/data-access/src/lib/entity/log.entity.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ export class Log {
2323
relatedId?: string | null
2424
@Field(() => LogRelatedType, { nullable: true })
2525
relatedType?: LogRelatedType | null
26-
@Field()
27-
communityId!: string
26+
@Field({ nullable: true })
27+
communityId?: string | null
2828
@Field(() => IdentityProvider, { nullable: true })
2929
identityProvider?: IdentityProvider | null
3030
@Field({ nullable: true })
3131
identityProviderId?: string | null
3232
@HideField()
3333
identity?: Identity | null
3434
@Field({ nullable: true })
35+
networkAssetId?: string | null
36+
@Field({ nullable: true })
3537
botId?: string | null
3638
@HideField()
3739
bot?: Bot | null

libs/api/log/data-access/src/lib/helpers/get-user-log-where.input.ts

+10-26
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,16 @@ import { UserFindManyLogInput } from '../dto/user-find-many-log.input'
33

44
export function getUserLogWhereInput(input: UserFindManyLogInput): Prisma.LogWhereInput {
55
const where: Prisma.LogWhereInput = {
6-
communityId: input.communityId,
7-
}
8-
9-
if (input.level) {
10-
where.level = input.level
11-
}
12-
if (input.relatedId) {
13-
where.relatedId = input.relatedId
14-
}
15-
if (input.relatedType) {
16-
where.relatedType = input.relatedType
17-
}
18-
if (input.identityProvider) {
19-
where.identityProvider = input.identityProvider
20-
}
21-
if (input.identityProviderId) {
22-
where.identityProviderId = input.identityProviderId
23-
}
24-
if (input.botId) {
25-
where.botId = input.botId
26-
}
27-
if (input.userId) {
28-
where.userId = input.userId
29-
}
30-
if (input.ruleId) {
31-
where.ruleId = input.ruleId
6+
communityId: input.communityId ?? undefined,
7+
networkAssetId: input.networkAssetId ?? undefined,
8+
level: input.level ?? undefined,
9+
relatedId: input.relatedId ?? undefined,
10+
relatedType: input.relatedType ?? undefined,
11+
identityProvider: input.identityProvider ?? undefined,
12+
identityProviderId: input.identityProviderId ?? undefined,
13+
botId: input.botId ?? undefined,
14+
userId: input.userId ?? undefined,
15+
ruleId: input.ruleId ?? undefined,
3216
}
3317

3418
if (input.search) {

libs/api/log/feature/src/lib/api-log.resolver.ts

+5
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ export class ApiLogResolver {
2828
user(@Parent() log: Log) {
2929
return log.user
3030
}
31+
32+
@ResolveField(() => String, { nullable: true })
33+
userId(@Parent() log: Log) {
34+
return log.userId ?? log.identity?.ownerId
35+
}
3136
}

0 commit comments

Comments
 (0)