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U,EAAQ,GAElB,MAAM,GAAM,EAAA,UAAA,WAkBZ,OAjBA,EAAI,IAAI,cAAe,CAErB,WACA,YACA,iBAEG,cAAc,KAEnB,EAAI,IAAI,SAAA,kBACR,EAAI,KAAI,EAAA,cAAA,YACR,EAAI,IAAI,WAAW,aAAa,IAChC,EAAI,KAAI,EAAA,OAAA,SAAK,CAAE,OAAQ,SAAA,IAAM,SAAA,UAC7B,EAAI,IAAI,YAAY,aAAa,IACjC,EAAI,IAAI,UAAU,aAAa,IAC/B,EAAI,IAAI,EAAO,KAAK,QACpB,EAAI,IAAI,MAAM,SAEP,IAAI,IAAI,CACb,MACA,OAEJ,CAEA,WAAM,SACE,KAAK,IAAI,UAAU,QACzB,MAAM,EAAS,KAAK,IAAI,OAAO,KAAK,IAAI,IAAI,QAAQ,MAKpD,OAJA,KAAK,OAAS,EACd,KAAK,OAAO,iBAAmB,IAC/B,KAAK,YAAa,EAAA,kBAAA,sBAAqB,CAAE,iBACnC,cAAA,QAAO,KAAK,EAAQ,aACnB,CACT,CAEA,aAAM,SACE,KAAK,IAAI,UAAU,gBACnB,KAAK,YAAY,mBACjB,KAAK,IAAI,gBAAgB,gBACzB,KAAK,IAAI,eAAe,cACxB,KAAK,IAAI,cAAc,cACvB,KAAK,IAAI,WAAW,UAC1B,cAAc,KAAK,iBACnB,cAAc,KAAK,uBACrB,EA1IF,QAAA,QA6IA,QAAA,QAAe,IAEf,MAAM,cAAiB,GAChB,EAAI,WAAW,QACb,EAAI,WAAW,WAAa,GADC","file":"/npm/@atproto/pds@0.4.212/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@atproto/pds@0.4.212/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","// catch errors that get thrown in async route handlers\n// this is a relatively non-invasive change to express\n// they get handled in the error.handler middleware\n// leave at top of file before importing Routes\nimport 'express-async-errors'\n\nimport events from 'node:events'\nimport http from 'node:http'\nimport { PlcClientError } from '@did-plc/lib'\nimport cors from 'cors'\nimport express from 'express'\nimport { HttpTerminator, createHttpTerminator } from 'http-terminator'\nimport { DAY, HOUR, MINUTE, SECOND } from '@atproto/common'\nimport {\n  MemoryRateLimiter,\n  MethodHandler,\n  RedisRateLimiter,\n  ResponseType,\n  XRPCError,\n} from '@atproto/xrpc-server'\nimport apiRoutes from './api'\nimport * as authRoutes from './auth-routes'\nimport * as basicRoutes from './basic-routes'\nimport { ServerConfig, ServerSecrets } from './config'\nimport { AppContext, AppContextOptions } from './context'\nimport * as error from './error'\nimport { createServer } from './lexicon'\nimport * as AppBskyFeedGetFeedSkeleton from './lexicon/types/app/bsky/feed/getFeedSkeleton'\nimport { loggerMiddleware } from './logger'\nimport { proxyHandler } from './pipethrough'\nimport compression from './util/compression'\nimport * as wellKnown from './well-known'\n\nexport { createSecretKeyObject } from './auth-verifier'\nexport * from './config'\nexport { AppContext } from './context'\nexport { Database } from './db'\nexport { DiskBlobStore } from './disk-blobstore'\nexport { createServer as createLexiconServer } from './lexicon'\nexport { httpLogger } from './logger'\nexport { type CommitDataWithOps, type PreparedWrite } from './repo'\nexport * as repoPrepare from './repo/prepare'\nexport { scripts } from './scripts'\nexport * as sequencer from './sequencer'\n\n// Legacy export for backwards compatibility\nexport type SkeletonHandler = MethodHandler<\n  void,\n  AppBskyFeedGetFeedSkeleton.QueryParams,\n  AppBskyFeedGetFeedSkeleton.HandlerInput,\n  AppBskyFeedGetFeedSkeleton.HandlerOutput\n>\n\nexport class PDS {\n  public ctx: AppContext\n  public app: express.Application\n  public server?: http.Server\n  private terminator?: HttpTerminator\n  private dbStatsInterval?: NodeJS.Timeout\n  private sequencerStatsInterval?: NodeJS.Timeout\n\n  constructor(opts: { ctx: AppContext; app: express.Application }) {\n    this.ctx = opts.ctx\n    this.app = opts.app\n  }\n\n  static async create(\n    cfg: ServerConfig,\n    secrets: ServerSecrets,\n    overrides?: Partial<AppContextOptions>,\n  ): Promise<PDS> {\n    const ctx = await AppContext.fromConfig(cfg, secrets, overrides)\n\n    const { rateLimits } = ctx.cfg\n\n    const server = createServer({\n      validateResponse: false,\n      payload: {\n        jsonLimit: 150 * 1024, // 150kb\n        textLimit: 100 * 1024, // 100kb\n        blobLimit: cfg.service.blobUploadLimit,\n      },\n      catchall: proxyHandler(ctx),\n      errorParser: (err) => {\n        if (err instanceof PlcClientError) {\n          const payloadMessage =\n            typeof err.data === 'object' &&\n            err.data != null &&\n            'message' in err.data &&\n            typeof err.data.message === 'string' &&\n            err.data.message\n\n          const type =\n            err.status >= 500\n              ? ResponseType.UpstreamFailure\n              : ResponseType.InvalidRequest\n\n          return new XRPCError(\n            type,\n            payloadMessage || 'Unable to perform PLC operation',\n          )\n        }\n\n        return XRPCError.fromError(err)\n      },\n      rateLimits: rateLimits.enabled\n        ? {\n            creator: ctx.redisScratch\n              ? (opts) => new RedisRateLimiter(ctx.redisScratch, opts)\n              : (opts) => new MemoryRateLimiter(opts),\n            bypass: ({ req }) => {\n              const { bypassKey, bypassIps } = rateLimits\n              if (\n                bypassKey &&\n                bypassKey === req.headers['x-ratelimit-bypass']\n              ) {\n                return true\n              }\n              if (bypassIps && bypassIps.includes(req.ip)) {\n                return true\n              }\n              return false\n            },\n            global: [\n              {\n                name: 'global-ip',\n                durationMs: 5 * MINUTE,\n                points: 3000,\n              },\n            ],\n            shared: [\n              {\n                name: 'repo-write-hour',\n                durationMs: HOUR,\n                points: 5000, // creates=3, puts=2, deletes=1\n              },\n              {\n                name: 'repo-write-day',\n                durationMs: DAY,\n                points: 35000, // creates=3, puts=2, deletes=1\n              },\n            ],\n          }\n        : undefined,\n    })\n\n    apiRoutes(server, ctx)\n\n    const app = express()\n    app.set('trust proxy', [\n      // e.g. load balancer\n      'loopback',\n      'linklocal',\n      'uniquelocal',\n      // e.g. trust x-forwarded-for via entryway ip\n      ...getTrustedIps(cfg),\n    ])\n    app.use(loggerMiddleware)\n    app.use(compression())\n    app.use(authRoutes.createRouter(ctx)) // Before CORS\n    app.use(cors({ maxAge: DAY / SECOND }))\n    app.use(basicRoutes.createRouter(ctx))\n    app.use(wellKnown.createRouter(ctx))\n    app.use(server.xrpc.router)\n    app.use(error.handler)\n\n    return new PDS({\n      ctx,\n      app,\n    })\n  }\n\n  async start(): Promise<http.Server> {\n    await this.ctx.sequencer.start()\n    const server = this.app.listen(this.ctx.cfg.service.port)\n    this.server = server\n    this.server.keepAliveTimeout = 90000\n    this.terminator = createHttpTerminator({ server })\n    await events.once(server, 'listening')\n    return server\n  }\n\n  async destroy(): Promise<void> {\n    await this.ctx.sequencer.destroy()\n    await this.terminator?.terminate()\n    await this.ctx.backgroundQueue.destroy()\n    await this.ctx.accountManager.close()\n    await this.ctx.redisScratch?.quit()\n    await this.ctx.proxyAgent.destroy()\n    clearInterval(this.dbStatsInterval)\n    clearInterval(this.sequencerStatsInterval)\n  }\n}\n\nexport default PDS\n\nconst getTrustedIps = (cfg: ServerConfig) => {\n  if (!cfg.rateLimits.enabled) return []\n  return cfg.rateLimits.bypassIps ?? []\n}\n"]}