Skip to content

Commit

Permalink
Signup queueing - Client & PDS (#2090)
Browse files Browse the repository at this point in the history
* schema + codegen

* port session refresh

* pds updates

* typo

* changeset
  • Loading branch information
dholms authored Jan 25, 2024
1 parent 79ec5ad commit 8994d36
Show file tree
Hide file tree
Showing 19 changed files with 401 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-wasps-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@atproto/api': patch
---

add checkSignupQueue method and expose refreshSession on agent
22 changes: 22 additions & 0 deletions lexicons/com/atproto/temp/checkSignupQueue.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"lexicon": 1,
"id": "com.atproto.temp.checkSignupQueue",
"defs": {
"main": {
"type": "query",
"description": "Check accounts location in signup queue.",
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["activated"],
"properties": {
"activated": { "type": "boolean" },
"placeInQueue": { "type": "integer" },
"estimatedTimeMs": { "type": "integer" }
}
}
}
}
}
}
4 changes: 2 additions & 2 deletions packages/api/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export class AtpAgent {
// handle session-refreshes as needed
if (isErrorResponse(res, ['ExpiredToken']) && this.session?.refreshJwt) {
// attempt refresh
await this._refreshSession()
await this.refreshSession()

// resend the request with the new access token
res = await AtpAgent.fetch(
Expand All @@ -250,7 +250,7 @@ export class AtpAgent {
* - Wraps the actual implementation in a promise-guard to ensure only
* one refresh is attempted at a time.
*/
private async _refreshSession() {
async refreshSession() {
if (this._refreshSessionPromise) {
return this._refreshSessionPromise
}
Expand Down
13 changes: 13 additions & 0 deletions packages/api/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import * as ComAtprotoSyncListRepos from './types/com/atproto/sync/listRepos'
import * as ComAtprotoSyncNotifyOfUpdate from './types/com/atproto/sync/notifyOfUpdate'
import * as ComAtprotoSyncRequestCrawl from './types/com/atproto/sync/requestCrawl'
import * as ComAtprotoSyncSubscribeRepos from './types/com/atproto/sync/subscribeRepos'
import * as ComAtprotoTempCheckSignupQueue from './types/com/atproto/temp/checkSignupQueue'
import * as ComAtprotoTempFetchLabels from './types/com/atproto/temp/fetchLabels'
import * as ComAtprotoTempImportRepo from './types/com/atproto/temp/importRepo'
import * as ComAtprotoTempPushBlob from './types/com/atproto/temp/pushBlob'
Expand Down Expand Up @@ -227,6 +228,7 @@ export * as ComAtprotoSyncListRepos from './types/com/atproto/sync/listRepos'
export * as ComAtprotoSyncNotifyOfUpdate from './types/com/atproto/sync/notifyOfUpdate'
export * as ComAtprotoSyncRequestCrawl from './types/com/atproto/sync/requestCrawl'
export * as ComAtprotoSyncSubscribeRepos from './types/com/atproto/sync/subscribeRepos'
export * as ComAtprotoTempCheckSignupQueue from './types/com/atproto/temp/checkSignupQueue'
export * as ComAtprotoTempFetchLabels from './types/com/atproto/temp/fetchLabels'
export * as ComAtprotoTempImportRepo from './types/com/atproto/temp/importRepo'
export * as ComAtprotoTempPushBlob from './types/com/atproto/temp/pushBlob'
Expand Down Expand Up @@ -1207,6 +1209,17 @@ export class ComAtprotoTempNS {
this._service = service
}

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

fetchLabels(
params?: ComAtprotoTempFetchLabels.QueryParams,
opts?: ComAtprotoTempFetchLabels.CallOptions,
Expand Down
29 changes: 29 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4246,6 +4246,34 @@ export const schemaDict = {
},
},
},
ComAtprotoTempCheckSignupQueue: {
lexicon: 1,
id: 'com.atproto.temp.checkSignupQueue',
defs: {
main: {
type: 'query',
description: 'Check accounts location in signup queue.',
output: {
encoding: 'application/json',
schema: {
type: 'object',
required: ['activated'],
properties: {
activated: {
type: 'boolean',
},
placeInQueue: {
type: 'integer',
},
estimatedTimeMs: {
type: 'integer',
},
},
},
},
},
},
},
ComAtprotoTempFetchLabels: {
lexicon: 1,
id: 'com.atproto.temp.fetchLabels',
Expand Down Expand Up @@ -8336,6 +8364,7 @@ export const ids = {
ComAtprotoSyncNotifyOfUpdate: 'com.atproto.sync.notifyOfUpdate',
ComAtprotoSyncRequestCrawl: 'com.atproto.sync.requestCrawl',
ComAtprotoSyncSubscribeRepos: 'com.atproto.sync.subscribeRepos',
ComAtprotoTempCheckSignupQueue: 'com.atproto.temp.checkSignupQueue',
ComAtprotoTempFetchLabels: 'com.atproto.temp.fetchLabels',
ComAtprotoTempImportRepo: 'com.atproto.temp.importRepo',
ComAtprotoTempPushBlob: 'com.atproto.temp.pushBlob',
Expand Down
35 changes: 35 additions & 0 deletions packages/api/src/client/types/com/atproto/temp/checkSignupQueue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import { Headers, XRPCError } from '@atproto/xrpc'
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { isObj, hasProp } from '../../../../util'
import { lexicons } from '../../../../lexicons'
import { CID } from 'multiformats/cid'

export interface QueryParams {}

export type InputSchema = undefined

export interface OutputSchema {
activated: boolean
placeInQueue?: number
estimatedTimeMs?: number
[k: string]: unknown
}

export interface CallOptions {
headers?: Headers
}

export interface Response {
success: boolean
headers: Headers
data: OutputSchema
}

export function toKnownErr(e: any) {
if (e instanceof XRPCError) {
}
return e
}
12 changes: 12 additions & 0 deletions packages/bsky/src/lexicon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import * as ComAtprotoSyncListRepos from './types/com/atproto/sync/listRepos'
import * as ComAtprotoSyncNotifyOfUpdate from './types/com/atproto/sync/notifyOfUpdate'
import * as ComAtprotoSyncRequestCrawl from './types/com/atproto/sync/requestCrawl'
import * as ComAtprotoSyncSubscribeRepos from './types/com/atproto/sync/subscribeRepos'
import * as ComAtprotoTempCheckSignupQueue from './types/com/atproto/temp/checkSignupQueue'
import * as ComAtprotoTempFetchLabels from './types/com/atproto/temp/fetchLabels'
import * as ComAtprotoTempImportRepo from './types/com/atproto/temp/importRepo'
import * as ComAtprotoTempPushBlob from './types/com/atproto/temp/pushBlob'
Expand Down Expand Up @@ -1021,6 +1022,17 @@ export class ComAtprotoTempNS {
this._server = server
}

checkSignupQueue<AV extends AuthVerifier>(
cfg: ConfigOf<
AV,
ComAtprotoTempCheckSignupQueue.Handler<ExtractAuth<AV>>,
ComAtprotoTempCheckSignupQueue.HandlerReqCtx<ExtractAuth<AV>>
>,
) {
const nsid = 'com.atproto.temp.checkSignupQueue' // @ts-ignore
return this._server.xrpc.method(nsid, cfg)
}

fetchLabels<AV extends AuthVerifier>(
cfg: ConfigOf<
AV,
Expand Down
29 changes: 29 additions & 0 deletions packages/bsky/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4246,6 +4246,34 @@ export const schemaDict = {
},
},
},
ComAtprotoTempCheckSignupQueue: {
lexicon: 1,
id: 'com.atproto.temp.checkSignupQueue',
defs: {
main: {
type: 'query',
description: 'Check accounts location in signup queue.',
output: {
encoding: 'application/json',
schema: {
type: 'object',
required: ['activated'],
properties: {
activated: {
type: 'boolean',
},
placeInQueue: {
type: 'integer',
},
estimatedTimeMs: {
type: 'integer',
},
},
},
},
},
},
},
ComAtprotoTempFetchLabels: {
lexicon: 1,
id: 'com.atproto.temp.fetchLabels',
Expand Down Expand Up @@ -8336,6 +8364,7 @@ export const ids = {
ComAtprotoSyncNotifyOfUpdate: 'com.atproto.sync.notifyOfUpdate',
ComAtprotoSyncRequestCrawl: 'com.atproto.sync.requestCrawl',
ComAtprotoSyncSubscribeRepos: 'com.atproto.sync.subscribeRepos',
ComAtprotoTempCheckSignupQueue: 'com.atproto.temp.checkSignupQueue',
ComAtprotoTempFetchLabels: 'com.atproto.temp.fetchLabels',
ComAtprotoTempImportRepo: 'com.atproto.temp.importRepo',
ComAtprotoTempPushBlob: 'com.atproto.temp.pushBlob',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import express from 'express'
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { lexicons } from '../../../../lexicons'
import { isObj, hasProp } from '../../../../util'
import { CID } from 'multiformats/cid'
import { HandlerAuth } from '@atproto/xrpc-server'

export interface QueryParams {}

export type InputSchema = undefined

export interface OutputSchema {
activated: boolean
placeInQueue?: number
estimatedTimeMs?: number
[k: string]: unknown
}

export type HandlerInput = undefined

export interface HandlerSuccess {
encoding: 'application/json'
body: OutputSchema
headers?: { [key: string]: string }
}

export interface HandlerError {
status: number
message?: string
}

export type HandlerOutput = HandlerError | HandlerSuccess
export type HandlerReqCtx<HA extends HandlerAuth = never> = {
auth: HA
params: QueryParams
input: HandlerInput
req: express.Request
res: express.Response
}
export type Handler<HA extends HandlerAuth = never> = (
ctx: HandlerReqCtx<HA>,
) => Promise<HandlerOutput> | HandlerOutput
12 changes: 12 additions & 0 deletions packages/ozone/src/lexicon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import * as ComAtprotoSyncListRepos from './types/com/atproto/sync/listRepos'
import * as ComAtprotoSyncNotifyOfUpdate from './types/com/atproto/sync/notifyOfUpdate'
import * as ComAtprotoSyncRequestCrawl from './types/com/atproto/sync/requestCrawl'
import * as ComAtprotoSyncSubscribeRepos from './types/com/atproto/sync/subscribeRepos'
import * as ComAtprotoTempCheckSignupQueue from './types/com/atproto/temp/checkSignupQueue'
import * as ComAtprotoTempFetchLabels from './types/com/atproto/temp/fetchLabels'
import * as ComAtprotoTempImportRepo from './types/com/atproto/temp/importRepo'
import * as ComAtprotoTempPushBlob from './types/com/atproto/temp/pushBlob'
Expand Down Expand Up @@ -1021,6 +1022,17 @@ export class ComAtprotoTempNS {
this._server = server
}

checkSignupQueue<AV extends AuthVerifier>(
cfg: ConfigOf<
AV,
ComAtprotoTempCheckSignupQueue.Handler<ExtractAuth<AV>>,
ComAtprotoTempCheckSignupQueue.HandlerReqCtx<ExtractAuth<AV>>
>,
) {
const nsid = 'com.atproto.temp.checkSignupQueue' // @ts-ignore
return this._server.xrpc.method(nsid, cfg)
}

fetchLabels<AV extends AuthVerifier>(
cfg: ConfigOf<
AV,
Expand Down
29 changes: 29 additions & 0 deletions packages/ozone/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4246,6 +4246,34 @@ export const schemaDict = {
},
},
},
ComAtprotoTempCheckSignupQueue: {
lexicon: 1,
id: 'com.atproto.temp.checkSignupQueue',
defs: {
main: {
type: 'query',
description: 'Check accounts location in signup queue.',
output: {
encoding: 'application/json',
schema: {
type: 'object',
required: ['activated'],
properties: {
activated: {
type: 'boolean',
},
placeInQueue: {
type: 'integer',
},
estimatedTimeMs: {
type: 'integer',
},
},
},
},
},
},
},
ComAtprotoTempFetchLabels: {
lexicon: 1,
id: 'com.atproto.temp.fetchLabels',
Expand Down Expand Up @@ -8336,6 +8364,7 @@ export const ids = {
ComAtprotoSyncNotifyOfUpdate: 'com.atproto.sync.notifyOfUpdate',
ComAtprotoSyncRequestCrawl: 'com.atproto.sync.requestCrawl',
ComAtprotoSyncSubscribeRepos: 'com.atproto.sync.subscribeRepos',
ComAtprotoTempCheckSignupQueue: 'com.atproto.temp.checkSignupQueue',
ComAtprotoTempFetchLabels: 'com.atproto.temp.fetchLabels',
ComAtprotoTempImportRepo: 'com.atproto.temp.importRepo',
ComAtprotoTempPushBlob: 'com.atproto.temp.pushBlob',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import express from 'express'
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { lexicons } from '../../../../lexicons'
import { isObj, hasProp } from '../../../../util'
import { CID } from 'multiformats/cid'
import { HandlerAuth } from '@atproto/xrpc-server'

export interface QueryParams {}

export type InputSchema = undefined

export interface OutputSchema {
activated: boolean
placeInQueue?: number
estimatedTimeMs?: number
[k: string]: unknown
}

export type HandlerInput = undefined

export interface HandlerSuccess {
encoding: 'application/json'
body: OutputSchema
headers?: { [key: string]: string }
}

export interface HandlerError {
status: number
message?: string
}

export type HandlerOutput = HandlerError | HandlerSuccess
export type HandlerReqCtx<HA extends HandlerAuth = never> = {
auth: HA
params: QueryParams
input: HandlerInput
req: express.Request
res: express.Response
}
export type Handler<HA extends HandlerAuth = never> = (
ctx: HandlerReqCtx<HA>,
) => Promise<HandlerOutput> | HandlerOutput
2 changes: 1 addition & 1 deletion packages/pds/src/api/app/bsky/notification/registerPush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getDidDoc } from '../util/resolver'

export default function (server: Server, ctx: AppContext) {
server.app.bsky.notification.registerPush({
auth: ctx.authVerifier.access,
auth: ctx.authVerifier.accessDeactived,
handler: async ({ auth, input }) => {
const { serviceDid } = input.body
const {
Expand Down
Loading

0 comments on commit 8994d36

Please sign in to comment.