@atproto/ozone 0.0.14 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @atproto/ozone
2
2
 
3
+ ## 0.0.15
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`6ec885992`](https://github.com/bluesky-social/atproto/commit/6ec8859929a16f9725319cc398b716acf913b01f), [`6ec885992`](https://github.com/bluesky-social/atproto/commit/6ec8859929a16f9725319cc398b716acf913b01f), [`6ec885992`](https://github.com/bluesky-social/atproto/commit/6ec8859929a16f9725319cc398b716acf913b01f)]:
8
+ - @atproto/api@0.10.4
9
+
3
10
  ## 0.0.14
4
11
 
5
12
  ### Patch Changes
@@ -5,6 +5,7 @@ export type OzoneConfig = {
5
5
  db: DatabaseConfig;
6
6
  appview: AppviewConfig;
7
7
  pds: PdsConfig | null;
8
+ cdn: CdnConfig;
8
9
  identity: IdentityConfig;
9
10
  };
10
11
  export type ServiceConfig = {
@@ -31,3 +32,6 @@ export type PdsConfig = {
31
32
  export type IdentityConfig = {
32
33
  plcUrl: string;
33
34
  };
35
+ export type CdnConfig = {
36
+ paths?: string[];
37
+ };
@@ -15,6 +15,7 @@ export type OzoneEnvironment = {
15
15
  dbPoolMaxUses?: number;
16
16
  dbPoolIdleTimeoutMs?: number;
17
17
  didPlcUrl?: string;
18
+ cdnPaths?: string[];
18
19
  adminPassword?: string;
19
20
  moderatorPassword?: string;
20
21
  triagePassword?: string;
package/dist/context.d.ts CHANGED
@@ -10,6 +10,7 @@ import { ModerationServiceCreator } from './mod-service';
10
10
  import { BackgroundQueue } from './background';
11
11
  import Sequencer from './sequencer/sequencer';
12
12
  import { CommunicationTemplateServiceCreator } from './communication-service/template';
13
+ import { ImageInvalidator } from './image-invalidator';
13
14
  export type AppContextOptions = {
14
15
  db: Database;
15
16
  cfg: OzoneConfig;
@@ -19,6 +20,7 @@ export type AppContextOptions = {
19
20
  pdsAgent: AtpAgent | undefined;
20
21
  signingKey: Keypair;
21
22
  idResolver: IdResolver;
23
+ imgInvalidator?: ImageInvalidator;
22
24
  backgroundQueue: BackgroundQueue;
23
25
  sequencer: Sequencer;
24
26
  };
@@ -0,0 +1,3 @@
1
+ export interface ImageInvalidator {
2
+ invalidate(subject: string, paths: string[]): Promise<void>;
3
+ }
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ import http from 'http';
6
6
  import { OzoneConfig, OzoneSecrets } from './config';
7
7
  import AppContext, { AppContextOptions } from './context';
8
8
  export * from './config';
9
+ export { type ImageInvalidator } from './image-invalidator';
9
10
  export { Database } from './db';
10
11
  export { OzoneDaemon, EventPusher, EventReverser } from './daemon';
11
12
  export { AppContext } from './context';
package/dist/index.js CHANGED
@@ -95204,6 +95204,12 @@ var envStr = (name2) => {
95204
95204
  return void 0;
95205
95205
  return str;
95206
95206
  };
95207
+ var envList = (name2) => {
95208
+ const str = process.env[name2];
95209
+ if (str === void 0 || str.length === 0)
95210
+ return [];
95211
+ return str.split(",");
95212
+ };
95207
95213
 
95208
95214
  // ../../node_modules/.pnpm/cborg@1.10.2/node_modules/cborg/esm/lib/is.js
95209
95215
  var typeofs = [
@@ -133064,17 +133070,19 @@ var LabelChannel = "label_channel";
133064
133070
 
133065
133071
  // src/mod-service/index.ts
133066
133072
  var ModerationService = class {
133067
- constructor(db, backgroundQueue, eventPusher, appviewAgent, appviewAuth, serverDid) {
133073
+ constructor(db, backgroundQueue, eventPusher, appviewAgent, appviewAuth, serverDid, imgInvalidator, cdnPaths) {
133068
133074
  this.db = db;
133069
133075
  this.backgroundQueue = backgroundQueue;
133070
133076
  this.eventPusher = eventPusher;
133071
133077
  this.appviewAgent = appviewAgent;
133072
133078
  this.appviewAuth = appviewAuth;
133073
133079
  this.serverDid = serverDid;
133080
+ this.imgInvalidator = imgInvalidator;
133081
+ this.cdnPaths = cdnPaths;
133074
133082
  this.views = new ModerationViews(this.db, this.appviewAgent, this.appviewAuth);
133075
133083
  }
133076
- static creator(backgroundQueue, eventPusher, appviewAgent, appviewAuth, serverDid) {
133077
- return (db) => new ModerationService(db, backgroundQueue, eventPusher, appviewAgent, appviewAuth, serverDid);
133084
+ static creator(backgroundQueue, eventPusher, appviewAgent, appviewAuth, serverDid, imgInvalidator, cdnPaths) {
133085
+ return (db) => new ModerationService(db, backgroundQueue, eventPusher, appviewAgent, appviewAuth, serverDid, imgInvalidator, cdnPaths);
133078
133086
  }
133079
133087
  async getEvent(id) {
133080
133088
  return await this.db.db.selectFrom("moderation_event").selectAll().where("id", "=", id).executeTakeFirst();
@@ -133371,10 +133379,16 @@ var ModerationService = class {
133371
133379
  confirmedAt: null,
133372
133380
  attempts: 0,
133373
133381
  lastAttempted: null
133374
- })).returning("id").execute();
133382
+ })).returning(["id", "subjectDid", "subjectBlobCid", "eventType"]).execute();
133375
133383
  this.db.onCommit(() => {
133376
133384
  this.backgroundQueue.add(async () => {
133377
- await Promise.all(blobEvts.map((evt) => this.eventPusher.attemptBlobEvent(evt.id)));
133385
+ await Promise.allSettled(blobEvts.map((evt) => this.eventPusher.attemptBlobEvent(evt.id).catch((err) => httpLogger.error({ err, ...evt }, "failed to push blob event"))));
133386
+ if (this.imgInvalidator) {
133387
+ await Promise.allSettled((subject.blobCids ?? []).map((cid2) => {
133388
+ const paths = (this.cdnPaths ?? []).map((path) => path.replace("%s", subject.did).replace("%s", cid2));
133389
+ return this.imgInvalidator?.invalidate(cid2, paths).catch((err) => httpLogger.error({ err, paths, cid: cid2 }, "failed to invalidate blob on cdn"));
133390
+ }));
133391
+ }
133378
133392
  });
133379
133393
  });
133380
133394
  }
@@ -134194,7 +134208,7 @@ var AppContext = class {
134194
134208
  appview: cfg.appview,
134195
134209
  pds: cfg.pds ?? void 0
134196
134210
  });
134197
- const modService = ModerationService.creator(backgroundQueue, eventPusher, appviewAgent, appviewAuth, cfg.service.did);
134211
+ const modService = ModerationService.creator(backgroundQueue, eventPusher, appviewAgent, appviewAuth, cfg.service.did, overrides?.imgInvalidator, cfg.cdn.paths);
134198
134212
  const communicationTemplateService = CommunicationTemplateService.creator();
134199
134213
  const idResolver = new IdResolver({
134200
134214
  plcUrl: cfg.identity.plcUrl
@@ -134323,6 +134337,9 @@ var envToCfg = (env) => {
134323
134337
  url: env.pdsUrl,
134324
134338
  did: env.pdsDid
134325
134339
  };
134340
+ const cdnCfg = {
134341
+ paths: env.cdnPaths
134342
+ };
134326
134343
  (0, import_node_assert.default)(env.didPlcUrl);
134327
134344
  const identityCfg = {
134328
134345
  plcUrl: env.didPlcUrl
@@ -134332,6 +134349,7 @@ var envToCfg = (env) => {
134332
134349
  db: dbCfg,
134333
134350
  appview: appviewCfg,
134334
134351
  pds: pdsCfg,
134352
+ cdn: cdnCfg,
134335
134353
  identity: identityCfg
134336
134354
  };
134337
134355
  };
@@ -134354,6 +134372,7 @@ var readEnv = () => {
134354
134372
  dbPoolMaxUses: envInt("OZONE_DB_POOL_MAX_USES"),
134355
134373
  dbPoolIdleTimeoutMs: envInt("OZONE_DB_POOL_IDLE_TIMEOUT_MS"),
134356
134374
  didPlcUrl: envStr("OZONE_DID_PLC_URL"),
134375
+ cdnPaths: envList("OZONE_CDN_PATHS"),
134357
134376
  adminPassword: envStr("OZONE_ADMIN_PASSWORD"),
134358
134377
  moderatorPassword: envStr("OZONE_MODERATOR_PASSWORD"),
134359
134378
  triagePassword: envStr("OZONE_TRIAGE_PASSWORD"),