Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User invite codes #757

Merged
merged 15 commits into from
Apr 5, 2023
26 changes: 26 additions & 0 deletions lexicons/com/atproto/admin/disableInviteCodes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"lexicon": 1,
"id": "com.atproto.admin.disableInviteCodes",
"defs": {
"main": {
"type": "procedure",
"description": "Disable some set of codes and/or all codes associated with a set of users",
"input": {
"encoding": "application/json",
"schema": {
"type": "object",
"properties": {
"codes": {
"type": "array",
"items": {"type": "string"}
},
"accounts": {
"type": "array",
"items": {"type": "string"}
}
}
}
}
}
}
}
32 changes: 32 additions & 0 deletions lexicons/com/atproto/admin/getInviteCodeUsage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"lexicon": 1,
"id": "com.atproto.admin.getInviteCodeUsage",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be useful to add timespan parameters to this query, if that's not too difficult. Then in the dashboard we could give (last week, last month, all time) on these stats

"defs": {
"main": {
"type": "query",
"description": "High level stats about invite code usage",
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["total", "user", "admin"],
"properties": {
"total": { "type": "ref", "ref": "#codesDetail" },
"user": { "type": "ref", "ref": "#codesDetail" },
"admin": { "type": "ref", "ref": "#codesDetail" }
Copy link
Collaborator

@devinivy devinivy Apr 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's on the horizon to switch-up how admin auth works, and certain user accounts may be marked as admins. Just tossing that out there for a gut check that this API will still match-up with that nicely, given that there could be overlap between "user" and "admin".

I think it still could work— "user" would just have to be specifically for non-admin accounts. Or another way to think about it is whether the invite code is generated from createInviteCode versus getAccountInviteCodes.

}
}
}
},
"codesDetail": {
"type": "object",
"required": ["count", "available", "used", "disabled"],
"properties": {
"count": {"type": "integer"},
"available": {"type": "integer"},
"used": {"type": "integer"},
"disabled": {"type": "integer"}
}
}
}
}
63 changes: 63 additions & 0 deletions lexicons/com/atproto/admin/getInviteCodes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"lexicon": 1,
"id": "com.atproto.admin.getInviteCodes",
"defs": {
"main": {
"type": "query",
"description": "Admin view of invite codes",
"parameters": {
"type": "params",
"properties": {
"sort": {
"type": "string",
"knownValues": [
"recent",
"usage"
],
"default": "recent"
},
"limit": {"type": "integer", "minimum": 1, "maximum": 500, "default": 100},
"cursor": {"type": "string"}
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["codes"],
"properties": {
"cursor": {"type": "string"},
"codes": {
"type": "array",
"items": {"type": "ref", "ref": "#codeDetail"}
}
}
}
}
},
"codeDetail": {
"type": "object",
"required": ["code", "available", "disabled", "forAccount", "createdBy", "createdAt", "uses"],
"properties": {
"code": {"type": "string"},
"available": {"type": "integer"},
"disabled": {"type": "boolean"},
"forAccount": {"type": "string"},
"createdBy": {"type": "string", "format": "datetime"},
"createdAt": {"type": "string", "format": "datetime"},
"uses": {
"type": "array",
"items": {"type": "ref", "ref": "#codeUse"}
}
}
},
"codeUse": {
"type": "object",
"required": ["usedBy", "usedAt"],
"properties": {
"usedBy": {"type": "string", "format": "did"},
"usedAt": {"type": "string", "format": "datetime"}
}
}
}
}
3 changes: 2 additions & 1 deletion lexicons/com/atproto/server/createInviteCode.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"type": "object",
"required": ["useCount"],
"properties": {
"useCount": {"type": "integer"}
"useCount": {"type": "integer"},
"forAccount": {"type": "string", "format": "did"}
}
}
},
Expand Down
46 changes: 46 additions & 0 deletions lexicons/com/atproto/server/getAccountInviteCodes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"lexicon": 1,
"id": "com.atproto.server.getAccountInviteCodes",
"defs": {
"main": {
"type": "query",
"description": "Get all invite codes for a given account",
"parameters": {
"type": "params",
"properties": {
"includeUsed": { "type": "boolean", "default": true },
"createAvailable": { "type": "boolean", "default": true }
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["codes"],
"properties": {
"codes": {
"type": "array",
"items": {
"type": "ref",
"ref": "#invite"
}
}
}
}
},
"errors": [
{"name": "DuplicateCreate"}
]
},
"invite": {
"type": "object",
"required": ["code", "available", "uses", "disabled"],
"properties": {
"code": { "type": "string" },
"available": { "type": "integer" },
"uses": { "type": "integer" },
"disabled": { "type": "boolean" }
}
}
}
}
52 changes: 52 additions & 0 deletions packages/api/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {
import { schemas } from './lexicons'
import { CID } from 'multiformats/cid'
import * as ComAtprotoAdminDefs from './types/com/atproto/admin/defs'
import * as ComAtprotoAdminDisableInviteCodes from './types/com/atproto/admin/disableInviteCodes'
import * as ComAtprotoAdminGetInviteCodeUsage from './types/com/atproto/admin/getInviteCodeUsage'
import * as ComAtprotoAdminGetInviteCodes from './types/com/atproto/admin/getInviteCodes'
import * as ComAtprotoAdminGetModerationAction from './types/com/atproto/admin/getModerationAction'
import * as ComAtprotoAdminGetModerationActions from './types/com/atproto/admin/getModerationActions'
import * as ComAtprotoAdminGetModerationReport from './types/com/atproto/admin/getModerationReport'
Expand Down Expand Up @@ -37,6 +40,7 @@ import * as ComAtprotoServerCreateSession from './types/com/atproto/server/creat
import * as ComAtprotoServerDeleteAccount from './types/com/atproto/server/deleteAccount'
import * as ComAtprotoServerDeleteSession from './types/com/atproto/server/deleteSession'
import * as ComAtprotoServerDescribeServer from './types/com/atproto/server/describeServer'
import * as ComAtprotoServerGetAccountInviteCodes from './types/com/atproto/server/getAccountInviteCodes'
import * as ComAtprotoServerGetSession from './types/com/atproto/server/getSession'
import * as ComAtprotoServerRefreshSession from './types/com/atproto/server/refreshSession'
import * as ComAtprotoServerRequestAccountDelete from './types/com/atproto/server/requestAccountDelete'
Expand Down Expand Up @@ -86,6 +90,9 @@ import * as AppBskyRichtextFacet from './types/app/bsky/richtext/facet'
import * as AppBskyUnspeccedGetPopular from './types/app/bsky/unspecced/getPopular'

export * as ComAtprotoAdminDefs from './types/com/atproto/admin/defs'
export * as ComAtprotoAdminDisableInviteCodes from './types/com/atproto/admin/disableInviteCodes'
export * as ComAtprotoAdminGetInviteCodeUsage from './types/com/atproto/admin/getInviteCodeUsage'
export * as ComAtprotoAdminGetInviteCodes from './types/com/atproto/admin/getInviteCodes'
export * as ComAtprotoAdminGetModerationAction from './types/com/atproto/admin/getModerationAction'
export * as ComAtprotoAdminGetModerationActions from './types/com/atproto/admin/getModerationActions'
export * as ComAtprotoAdminGetModerationReport from './types/com/atproto/admin/getModerationReport'
Expand Down Expand Up @@ -115,6 +122,7 @@ export * as ComAtprotoServerCreateSession from './types/com/atproto/server/creat
export * as ComAtprotoServerDeleteAccount from './types/com/atproto/server/deleteAccount'
export * as ComAtprotoServerDeleteSession from './types/com/atproto/server/deleteSession'
export * as ComAtprotoServerDescribeServer from './types/com/atproto/server/describeServer'
export * as ComAtprotoServerGetAccountInviteCodes from './types/com/atproto/server/getAccountInviteCodes'
export * as ComAtprotoServerGetSession from './types/com/atproto/server/getSession'
export * as ComAtprotoServerRefreshSession from './types/com/atproto/server/refreshSession'
export * as ComAtprotoServerRequestAccountDelete from './types/com/atproto/server/requestAccountDelete'
Expand Down Expand Up @@ -240,6 +248,39 @@ export class AdminNS {
this._service = service
}

disableInviteCodes(
data?: ComAtprotoAdminDisableInviteCodes.InputSchema,
opts?: ComAtprotoAdminDisableInviteCodes.CallOptions,
): Promise<ComAtprotoAdminDisableInviteCodes.Response> {
return this._service.xrpc
.call('com.atproto.admin.disableInviteCodes', opts?.qp, data, opts)
.catch((e) => {
throw ComAtprotoAdminDisableInviteCodes.toKnownErr(e)
})
}

getInviteCodeUsage(
params?: ComAtprotoAdminGetInviteCodeUsage.QueryParams,
opts?: ComAtprotoAdminGetInviteCodeUsage.CallOptions,
): Promise<ComAtprotoAdminGetInviteCodeUsage.Response> {
return this._service.xrpc
.call('com.atproto.admin.getInviteCodeUsage', params, undefined, opts)
.catch((e) => {
throw ComAtprotoAdminGetInviteCodeUsage.toKnownErr(e)
})
}

getInviteCodes(
params?: ComAtprotoAdminGetInviteCodes.QueryParams,
opts?: ComAtprotoAdminGetInviteCodes.CallOptions,
): Promise<ComAtprotoAdminGetInviteCodes.Response> {
return this._service.xrpc
.call('com.atproto.admin.getInviteCodes', params, undefined, opts)
.catch((e) => {
throw ComAtprotoAdminGetInviteCodes.toKnownErr(e)
})
}

getModerationAction(
params?: ComAtprotoAdminGetModerationAction.QueryParams,
opts?: ComAtprotoAdminGetModerationAction.CallOptions,
Expand Down Expand Up @@ -569,6 +610,17 @@ export class ServerNS {
})
}

getAccountInviteCodes(
params?: ComAtprotoServerGetAccountInviteCodes.QueryParams,
opts?: ComAtprotoServerGetAccountInviteCodes.CallOptions,
): Promise<ComAtprotoServerGetAccountInviteCodes.Response> {
return this._service.xrpc
.call('com.atproto.server.getAccountInviteCodes', params, undefined, opts)
.catch((e) => {
throw ComAtprotoServerGetAccountInviteCodes.toKnownErr(e)
})
}

getSession(
params?: ComAtprotoServerGetSession.QueryParams,
opts?: ComAtprotoServerGetSession.CallOptions,
Expand Down
Loading