diff --git a/.changeset/afraid-wasps-punch.md b/.changeset/afraid-wasps-punch.md new file mode 100644 index 00000000000..f61c488c8e6 --- /dev/null +++ b/.changeset/afraid-wasps-punch.md @@ -0,0 +1,5 @@ +--- +'@atproto/api': patch +--- + +add checkSignupQueue method and expose refreshSession on agent diff --git a/lexicons/com/atproto/temp/checkSignupQueue.json b/lexicons/com/atproto/temp/checkSignupQueue.json new file mode 100644 index 00000000000..b7d9e65d7cf --- /dev/null +++ b/lexicons/com/atproto/temp/checkSignupQueue.json @@ -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" } + } + } + } + } + } +} diff --git a/packages/api/src/agent.ts b/packages/api/src/agent.ts index 54f599492b5..d46e2aa9e3c 100644 --- a/packages/api/src/agent.ts +++ b/packages/api/src/agent.ts @@ -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( @@ -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 } diff --git a/packages/api/src/client/index.ts b/packages/api/src/client/index.ts index c6463e93534..43a360f4db1 100644 --- a/packages/api/src/client/index.ts +++ b/packages/api/src/client/index.ts @@ -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' @@ -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' @@ -1207,6 +1209,17 @@ export class ComAtprotoTempNS { this._service = service } + checkSignupQueue( + params?: ComAtprotoTempCheckSignupQueue.QueryParams, + opts?: ComAtprotoTempCheckSignupQueue.CallOptions, + ): Promise { + 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, diff --git a/packages/api/src/client/lexicons.ts b/packages/api/src/client/lexicons.ts index 38d565f2571..8d7e4d6e658 100644 --- a/packages/api/src/client/lexicons.ts +++ b/packages/api/src/client/lexicons.ts @@ -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', @@ -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', diff --git a/packages/api/src/client/types/com/atproto/temp/checkSignupQueue.ts b/packages/api/src/client/types/com/atproto/temp/checkSignupQueue.ts new file mode 100644 index 00000000000..2f80322c82e --- /dev/null +++ b/packages/api/src/client/types/com/atproto/temp/checkSignupQueue.ts @@ -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 +} diff --git a/packages/bsky/src/lexicon/index.ts b/packages/bsky/src/lexicon/index.ts index 0e30f4d172c..bac09d83edb 100644 --- a/packages/bsky/src/lexicon/index.ts +++ b/packages/bsky/src/lexicon/index.ts @@ -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' @@ -1021,6 +1022,17 @@ export class ComAtprotoTempNS { this._server = server } + checkSignupQueue( + cfg: ConfigOf< + AV, + ComAtprotoTempCheckSignupQueue.Handler>, + ComAtprotoTempCheckSignupQueue.HandlerReqCtx> + >, + ) { + const nsid = 'com.atproto.temp.checkSignupQueue' // @ts-ignore + return this._server.xrpc.method(nsid, cfg) + } + fetchLabels( cfg: ConfigOf< AV, diff --git a/packages/bsky/src/lexicon/lexicons.ts b/packages/bsky/src/lexicon/lexicons.ts index 38d565f2571..8d7e4d6e658 100644 --- a/packages/bsky/src/lexicon/lexicons.ts +++ b/packages/bsky/src/lexicon/lexicons.ts @@ -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', @@ -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', diff --git a/packages/bsky/src/lexicon/types/com/atproto/temp/checkSignupQueue.ts b/packages/bsky/src/lexicon/types/com/atproto/temp/checkSignupQueue.ts new file mode 100644 index 00000000000..d2a431430a8 --- /dev/null +++ b/packages/bsky/src/lexicon/types/com/atproto/temp/checkSignupQueue.ts @@ -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 = { + auth: HA + params: QueryParams + input: HandlerInput + req: express.Request + res: express.Response +} +export type Handler = ( + ctx: HandlerReqCtx, +) => Promise | HandlerOutput diff --git a/packages/ozone/src/lexicon/index.ts b/packages/ozone/src/lexicon/index.ts index 0e30f4d172c..bac09d83edb 100644 --- a/packages/ozone/src/lexicon/index.ts +++ b/packages/ozone/src/lexicon/index.ts @@ -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' @@ -1021,6 +1022,17 @@ export class ComAtprotoTempNS { this._server = server } + checkSignupQueue( + cfg: ConfigOf< + AV, + ComAtprotoTempCheckSignupQueue.Handler>, + ComAtprotoTempCheckSignupQueue.HandlerReqCtx> + >, + ) { + const nsid = 'com.atproto.temp.checkSignupQueue' // @ts-ignore + return this._server.xrpc.method(nsid, cfg) + } + fetchLabels( cfg: ConfigOf< AV, diff --git a/packages/ozone/src/lexicon/lexicons.ts b/packages/ozone/src/lexicon/lexicons.ts index 38d565f2571..8d7e4d6e658 100644 --- a/packages/ozone/src/lexicon/lexicons.ts +++ b/packages/ozone/src/lexicon/lexicons.ts @@ -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', @@ -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', diff --git a/packages/ozone/src/lexicon/types/com/atproto/temp/checkSignupQueue.ts b/packages/ozone/src/lexicon/types/com/atproto/temp/checkSignupQueue.ts new file mode 100644 index 00000000000..d2a431430a8 --- /dev/null +++ b/packages/ozone/src/lexicon/types/com/atproto/temp/checkSignupQueue.ts @@ -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 = { + auth: HA + params: QueryParams + input: HandlerInput + req: express.Request + res: express.Response +} +export type Handler = ( + ctx: HandlerReqCtx, +) => Promise | HandlerOutput diff --git a/packages/pds/src/api/app/bsky/notification/registerPush.ts b/packages/pds/src/api/app/bsky/notification/registerPush.ts index e6a5bf1b14f..efe26ce9366 100644 --- a/packages/pds/src/api/app/bsky/notification/registerPush.ts +++ b/packages/pds/src/api/app/bsky/notification/registerPush.ts @@ -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 { diff --git a/packages/pds/src/api/com/atproto/server/getSession.ts b/packages/pds/src/api/com/atproto/server/getSession.ts index 8b81068a147..542677a2808 100644 --- a/packages/pds/src/api/com/atproto/server/getSession.ts +++ b/packages/pds/src/api/com/atproto/server/getSession.ts @@ -7,7 +7,7 @@ import { didDocForSession } from './util' export default function (server: Server, ctx: AppContext) { server.com.atproto.server.getSession({ - auth: ctx.authVerifier.access, + auth: ctx.authVerifier.accessDeactived, handler: async ({ auth, req }) => { if (ctx.entrywayAgent) { return resultPassthru( diff --git a/packages/pds/src/api/com/atproto/temp/checkSignupQueue.ts b/packages/pds/src/api/com/atproto/temp/checkSignupQueue.ts new file mode 100644 index 00000000000..2ca11d29bfa --- /dev/null +++ b/packages/pds/src/api/com/atproto/temp/checkSignupQueue.ts @@ -0,0 +1,26 @@ +import { Server } from '../../../../lexicon' +import AppContext from '../../../../context' +import { authPassthru, resultPassthru } from '../../../proxy' + +// THIS IS A TEMPORARY UNSPECCED ROUTE +export default function (server: Server, ctx: AppContext) { + server.com.atproto.temp.checkSignupQueue({ + auth: ctx.authVerifier.accessDeactived, + handler: async ({ req }) => { + if (!ctx.entrywayAgent) { + return { + encoding: 'application/json', + body: { + activated: true, + }, + } + } + return resultPassthru( + await ctx.entrywayAgent.com.atproto.temp.checkSignupQueue( + undefined, + authPassthru(req), + ), + ) + }, + }) +} diff --git a/packages/pds/src/auth-verifier.ts b/packages/pds/src/auth-verifier.ts index dc5f0bc29d5..b24f530ade3 100644 --- a/packages/pds/src/auth-verifier.ts +++ b/packages/pds/src/auth-verifier.ts @@ -22,6 +22,7 @@ export enum AuthScope { Access = 'com.atproto.access', Refresh = 'com.atproto.refresh', AppPass = 'com.atproto.appPass', + Deactivated = 'com.atproto.deactivated', } export enum RoleStatus { @@ -143,6 +144,14 @@ export class AuthVerifier { return this.validateAccessToken(ctx.req, [AuthScope.Access]) } + accessDeactived = (ctx: ReqCtx): Promise => { + return this.validateAccessToken(ctx.req, [ + AuthScope.Access, + AuthScope.AppPass, + AuthScope.Deactivated, + ]) + } + refresh = async (ctx: ReqCtx): Promise => { const { did, scope, token, audience, payload } = await this.validateBearerToken(ctx.req, [AuthScope.Refresh], { diff --git a/packages/pds/src/lexicon/index.ts b/packages/pds/src/lexicon/index.ts index 0e30f4d172c..bac09d83edb 100644 --- a/packages/pds/src/lexicon/index.ts +++ b/packages/pds/src/lexicon/index.ts @@ -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' @@ -1021,6 +1022,17 @@ export class ComAtprotoTempNS { this._server = server } + checkSignupQueue( + cfg: ConfigOf< + AV, + ComAtprotoTempCheckSignupQueue.Handler>, + ComAtprotoTempCheckSignupQueue.HandlerReqCtx> + >, + ) { + const nsid = 'com.atproto.temp.checkSignupQueue' // @ts-ignore + return this._server.xrpc.method(nsid, cfg) + } + fetchLabels( cfg: ConfigOf< AV, diff --git a/packages/pds/src/lexicon/lexicons.ts b/packages/pds/src/lexicon/lexicons.ts index 38d565f2571..8d7e4d6e658 100644 --- a/packages/pds/src/lexicon/lexicons.ts +++ b/packages/pds/src/lexicon/lexicons.ts @@ -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', @@ -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', diff --git a/packages/pds/src/lexicon/types/com/atproto/temp/checkSignupQueue.ts b/packages/pds/src/lexicon/types/com/atproto/temp/checkSignupQueue.ts new file mode 100644 index 00000000000..d2a431430a8 --- /dev/null +++ b/packages/pds/src/lexicon/types/com/atproto/temp/checkSignupQueue.ts @@ -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 = { + auth: HA + params: QueryParams + input: HandlerInput + req: express.Request + res: express.Response +} +export type Handler = ( + ctx: HandlerReqCtx, +) => Promise | HandlerOutput