@atproto/ozone 0.2.21 → 0.2.22
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 +16 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +2 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/report/closeReports.d.ts +4 -0
- package/dist/api/report/closeReports.d.ts.map +1 -0
- package/dist/api/report/closeReports.js +46 -0
- package/dist/api/report/closeReports.js.map +1 -0
- package/dist/api/report/createActivity.d.ts.map +1 -1
- package/dist/api/report/createActivity.js +5 -1
- package/dist/api/report/createActivity.js.map +1 -1
- package/dist/config/config.d.ts +1 -0
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +1 -0
- package/dist/config/config.js.map +1 -1
- package/dist/config/env.d.ts +1 -0
- package/dist/config/env.d.ts.map +1 -1
- package/dist/config/env.js +1 -0
- package/dist/config/env.js.map +1 -1
- package/dist/daemon/context.d.ts.map +1 -1
- package/dist/daemon/context.js +1 -1
- package/dist/daemon/context.js.map +1 -1
- package/dist/daemon/materialized-view-refresher.d.ts +1 -1
- package/dist/daemon/materialized-view-refresher.d.ts.map +1 -1
- package/dist/daemon/materialized-view-refresher.js +35 -21
- package/dist/daemon/materialized-view-refresher.js.map +1 -1
- package/dist/daemon/stats-computer.d.ts +1 -1
- package/dist/daemon/stats-computer.d.ts.map +1 -1
- package/dist/daemon/stats-computer.js +3 -4
- package/dist/daemon/stats-computer.js.map +1 -1
- package/dist/db/index.d.ts +2 -0
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +4 -0
- package/dist/db/index.js.map +1 -1
- package/dist/db/migrations/20260720T000000000Z-add-convo-subjects-to-stats-views.d.ts +4 -0
- package/dist/db/migrations/20260720T000000000Z-add-convo-subjects-to-stats-views.d.ts.map +1 -0
- package/dist/db/migrations/20260720T000000000Z-add-convo-subjects-to-stats-views.js +257 -0
- package/dist/db/migrations/20260720T000000000Z-add-convo-subjects-to-stats-views.js.map +1 -0
- package/dist/db/migrations/index.d.ts +1 -0
- package/dist/db/migrations/index.d.ts.map +1 -1
- package/dist/db/migrations/index.js +1 -0
- package/dist/db/migrations/index.js.map +1 -1
- package/dist/db/schema/record_events_stats.d.ts +1 -1
- package/dist/db/schema/record_events_stats.d.ts.map +1 -1
- package/dist/db/schema/record_events_stats.js.map +1 -1
- package/dist/lexicon/index.d.ts +2 -0
- package/dist/lexicon/index.d.ts.map +1 -1
- package/dist/lexicon/index.js +5 -0
- package/dist/lexicon/index.js.map +1 -1
- package/dist/lexicon/lexicons.d.ts +154 -6
- package/dist/lexicon/lexicons.d.ts.map +1 -1
- package/dist/lexicon/lexicons.js +84 -3
- package/dist/lexicon/lexicons.js.map +1 -1
- package/dist/lexicon/types/app/bsky/video/defs.d.ts +2 -0
- package/dist/lexicon/types/app/bsky/video/defs.d.ts.map +1 -1
- package/dist/lexicon/types/app/bsky/video/defs.js.map +1 -1
- package/dist/lexicon/types/com/atproto/server/describeServer.d.ts +2 -0
- package/dist/lexicon/types/com/atproto/server/describeServer.d.ts.map +1 -1
- package/dist/lexicon/types/com/atproto/server/describeServer.js.map +1 -1
- package/dist/lexicon/types/tools/ozone/report/closeReports.d.ts +34 -0
- package/dist/lexicon/types/tools/ozone/report/closeReports.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/closeReports.js +10 -0
- package/dist/lexicon/types/tools/ozone/report/closeReports.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/createActivity.d.ts +4 -2
- package/dist/lexicon/types/tools/ozone/report/createActivity.d.ts.map +1 -1
- package/dist/lexicon/types/tools/ozone/report/createActivity.js.map +1 -1
- package/dist/mod-service/report.d.ts +21 -0
- package/dist/mod-service/report.d.ts.map +1 -1
- package/dist/mod-service/report.js +87 -4
- package/dist/mod-service/report.js.map +1 -1
- package/dist/report/activity.d.ts +4 -1
- package/dist/report/activity.d.ts.map +1 -1
- package/dist/report/activity.js +14 -5
- package/dist/report/activity.js.map +1 -1
- package/dist/report/handle-report-update.js +1 -1
- package/dist/report/handle-report-update.js.map +1 -1
- package/package.json +9 -9
|
@@ -34,7 +34,7 @@ export const VALID_TRANSITIONS = {
|
|
|
34
34
|
open: ['closed', 'escalated', 'queued', 'assigned'],
|
|
35
35
|
closed: ['open'],
|
|
36
36
|
escalated: ['open', 'closed'],
|
|
37
|
-
queued: ['assigned', 'open'],
|
|
37
|
+
queued: ['assigned', 'open', 'closed'],
|
|
38
38
|
assigned: ['open', 'closed', 'escalated', 'queued'],
|
|
39
39
|
};
|
|
40
40
|
/** Activity types that map to a specific target status */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle-report-update.js","sourceRoot":"","sources":["../../src/report/handle-report-update.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,8EAA8E;AAC9E,wEAAwE;AACxE,8EAA8E;AAE9E,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,YACS,aAAqB,EACrB,YAAoB;QAE3B,KAAK,CAAC,yBAAyB,YAAY,UAAU,CAAC,CAAA;6BAH/C,aAAa;4BACb,YAAY;QAGnB,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAA;IACpC,CAAC;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/C,YACS,UAAkB,EAClB,QAAgB;QAEvB,KAAK,CAAC,kCAAkC,UAAU,SAAS,QAAQ,GAAG,CAAC,CAAA;0BAHhE,UAAU;wBACV,QAAQ;QAGf,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAA;IACtC,CAAC;CACF;AAED,8EAA8E;AAC9E,uBAAuB;AACvB,8EAA8E;AAE9E,yEAAyE;AACzE,MAAM,CAAC,MAAM,iBAAiB,GAA6B;IACzD,IAAI,EAAE,CAAC,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,CAAC;IACnD,MAAM,EAAE,CAAC,MAAM,CAAC;IAChB,SAAS,EAAE,CAAC,MAAM,EA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AAC,aAAqB;IAC9C,+CAA+C;IAC/C,IAAI,aAAa,KAAK,MAAM,EAAE,CAAC;QAC7B,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAA;IAC7C,CAAC;IAED,OAAO;QACL,UAAU,EAAE,QAAQ;QACpB,QAAQ,EAAE,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE;KAC3E,CAAA;AACH,CAAC;AAED,8EAA8E;AAC9E,oBAAoB;AACpB,8EAA8E;AAE9E,SAAS,kBAAkB,CAAC,UAAkB,EAAE,QAAgB;IAC9D,IAAI,UAAU,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,IAAI,oBAAoB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IACtD,CAAC;IACD,MAAM,OAAO,GAAG,iBAAiB,CAAC,UAAU,CAAC,IAAI,EAAE,CAAA;IACnD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,sBAAsB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IACxD,CAAC;AACH,CAAC","sourcesContent":["/**\n * Pure, synchronous state-transition logic for reports.\n *\n * Every code path that changes a report's status or creates a report activity\n * should call `handleReportUpdate` to determine the next status and the\n * activity record to insert. This keeps the state machine in one place and\n * decouples it from DB operations so it works for both single-row transactions\n * and bulk updates.\n */\n\n// ---------------------------------------------------------------------------\n// Error types — callers decide how to surface these (throw, skip, etc.)\n// ---------------------------------------------------------------------------\n\nexport class AlreadyInTargetState extends Error {\n constructor(\n public currentStatus: string,\n public targetStatus: string,\n ) {\n super(`Report is already in '${targetStatus}' status`)\n this.name = 'AlreadyInTargetState'\n }\n}\n\nexport class InvalidStateTransition extends Error {\n constructor(\n public fromStatus: string,\n public toStatus: string,\n ) {\n super(`Cannot transition report from '${fromStatus}' to '${toStatus}'`)\n this.name = 'InvalidStateTransition'\n }\n}\n\n// ---------------------------------------------------------------------------\n// State machine tables\n// ---------------------------------------------------------------------------\n\n/** Valid state transitions: key = fromState, value = allowed toStates */\nexport const VALID_TRANSITIONS: Record<string, string[]> = {\n open: ['closed', 'escalated', 'queued', 'assigned'],\n closed: ['open'],\n escalated: ['open', 'closed'],\n queued: ['assigned', 'open'],\n assigned: ['open', 'closed', 'escalated', 'queued'],\n}\n\n/** Activity types that map to a specific target status */\nconst ACTIVITY_TO_STATE: Record<string, string> = {\n queueActivity: 'queued',\n assignmentActivity: 'assigned',\n escalationActivity: 'escalated',\n closeActivity: 'closed',\n reopenActivity: 'open',\n}\n\n/** Activity types that are only valid from specific source states */\nconst ACTIVITY_VALID_FROM_STATES: Record<string, string[]> = {\n reopenActivity: ['closed'],\n}\n\n/** Moderation event types → target status (+ activity type) */\nconst EVENT_TYPE_MAP: Record<string, { status: string; activityType: string }> =\n {\n 'tools.ozone.moderation.defs#modEventAcknowledge': {\n status: 'closed',\n activityType: 'closeActivity',\n },\n 'tools.ozone.moderation.defs#modEventTakedown': {\n status: 'closed',\n activityType: 'closeActivity',\n },\n 'tools.ozone.moderation.defs#modEventLabel': {\n status: 'closed',\n activityType: 'closeActivity',\n },\n 'tools.ozone.moderation.defs#modEventComment': {\n status: 'closed',\n activityType: 'closeActivity',\n },\n 'tools.ozone.moderation.defs#modEventEscalate': {\n status: 'escalated',\n activityType: 'escalationActivity',\n },\n }\n\n// ---------------------------------------------------------------------------\n// Action types — the three ways a report's status can change\n// ---------------------------------------------------------------------------\n\nexport type ReportUpdateAction =\n | { type: 'activity'; activityType: string }\n | { type: 'event'; eventType: string }\n | { type: 'queue' }\n\n// ---------------------------------------------------------------------------\n// Result type\n// ---------------------------------------------------------------------------\n\nexport type ActivityRecord = {\n activityType: string\n previousStatus: string\n}\n\nexport type ReportUpdateResult = {\n nextStatus: string | null\n activity: ActivityRecord | null\n}\n\n// ---------------------------------------------------------------------------\n// Core function\n// ---------------------------------------------------------------------------\n\n/**\n * Determines the next status and activity record for a report update.\n *\n * @throws AlreadyInTargetState if the report is already in the target status\n * @throws InvalidStateTransition if the transition is not allowed\n * @returns nextStatus (null = no change) and activity (null = nothing to record)\n */\nexport function handleReportUpdate(\n currentStatus: string,\n action: ReportUpdateAction,\n): ReportUpdateResult {\n switch (action.type) {\n case 'activity':\n return handleActivityAction(currentStatus, action.activityType)\n case 'event':\n return handleEventAction(currentStatus, action.eventType)\n case 'queue':\n return handleQueueAction(currentStatus)\n }\n}\n\n// ---------------------------------------------------------------------------\n// Action handlers\n// ---------------------------------------------------------------------------\n\nfunction handleActivityAction(\n currentStatus: string,\n activityType: string,\n): ReportUpdateResult {\n const toState = ACTIVITY_TO_STATE[activityType] ?? null\n\n // Note-type activities — no state change, but still produce an activity record\n if (toState === null) {\n return { nextStatus: null, activity: null }\n }\n\n // Check activity-specific source-state constraints\n const validFromStates = ACTIVITY_VALID_FROM_STATES[activityType]\n if (validFromStates && !validFromStates.includes(currentStatus)) {\n throw new InvalidStateTransition(currentStatus, toState)\n }\n\n validateTransition(currentStatus, toState)\n\n return {\n nextStatus: toState,\n activity: { activityType, previousStatus: currentStatus },\n }\n}\n\nfunction handleEventAction(\n currentStatus: string,\n eventType: string,\n): ReportUpdateResult {\n const mapping = EVENT_TYPE_MAP[eventType]\n if (!mapping) {\n // Event type doesn't affect report status\n return { nextStatus: null, activity: null }\n }\n\n validateTransition(currentStatus, mapping.status)\n\n return {\n nextStatus: mapping.status,\n activity: {\n activityType: mapping.activityType,\n previousStatus: currentStatus,\n },\n }\n}\n\nfunction handleQueueAction(currentStatus: string): ReportUpdateResult {\n // Queue routing only transitions open → queued\n if (currentStatus !== 'open') {\n return { nextStatus: null, activity: null }\n }\n\n return {\n nextStatus: 'queued',\n activity: { activityType: 'queueActivity', previousStatus: currentStatus },\n }\n}\n\n// ---------------------------------------------------------------------------\n// Shared validation\n// ---------------------------------------------------------------------------\n\nfunction validateTransition(fromStatus: string, toStatus: string): void {\n if (fromStatus === toStatus) {\n throw new AlreadyInTargetState(fromStatus, toStatus)\n }\n const allowed = VALID_TRANSITIONS[fromStatus] ?? []\n if (!allowed.includes(toStatus)) {\n throw new InvalidStateTransition(fromStatus, toStatus)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"handle-report-update.js","sourceRoot":"","sources":["../../src/report/handle-report-update.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,8EAA8E;AAC9E,wEAAwE;AACxE,8EAA8E;AAE9E,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,YACS,aAAqB,EACrB,YAAoB;QAE3B,KAAK,CAAC,yBAAyB,YAAY,UAAU,CAAC,CAAA;6BAH/C,aAAa;4BACb,YAAY;QAGnB,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAA;IACpC,CAAC;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/C,YACS,UAAkB,EAClB,QAAgB;QAEvB,KAAK,CAAC,kCAAkC,UAAU,SAAS,QAAQ,GAAG,CAAC,CAAA;0BAHhE,UAAU;wBACV,QAAQ;QAGf,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAA;IACtC,CAAC;CACF;AAED,8EAA8E;AAC9E,uBAAuB;AACvB,8EAA8E;AAE9E,yEAAyE;AACzE,MAAM,CAAC,MAAM,iBAAiB,GAA6B;IACzD,IAAI,EAAE,CAAC,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,CAAC;IACnD,MAAM,EAAE,CAAC,MAAM,CAAC;IAChB,SAAS,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC7B,MAAM,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC;IACtC,QAAQ,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,CAAC;CACpD,CAAA;AAED,0DAA0D;AAC1D,MAAM,iBAAiB,GAA2B;IAChD,aAAa,EAAE,QAAQ;IACvB,kBAAkB,EAAE,UAAU;IAC9B,kBAAkB,EAAE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C3E,CAAA;AACH,CAAC;AAED,8EAA8E;AAC9E,oBAAoB;AACpB,8EAA8E;AAE9E,SAAS,kBAAkB,CAAC,UAAkB,EAAE,QAAgB;IAC9D,IAAI,UAAU,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,IAAI,oBAAoB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IACtD,CAAC;IACD,MAAM,OAAO,GAAG,iBAAiB,CAAC,UAAU,CAAC,IAAI,EAAE,CAAA;IACnD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,sBAAsB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IACxD,CAAC;AACH,CAAC","sourcesContent":["/**\n * Pure, synchronous state-transition logic for reports.\n *\n * Every code path that changes a report's status or creates a report activity\n * should call `handleReportUpdate` to determine the next status and the\n * activity record to insert. This keeps the state machine in one place and\n * decouples it from DB operations so it works for both single-row transactions\n * and bulk updates.\n */\n\n// ---------------------------------------------------------------------------\n// Error types — callers decide how to surface these (throw, skip, etc.)\n// ---------------------------------------------------------------------------\n\nexport class AlreadyInTargetState extends Error {\n constructor(\n public currentStatus: string,\n public targetStatus: string,\n ) {\n super(`Report is already in '${targetStatus}' status`)\n this.name = 'AlreadyInTargetState'\n }\n}\n\nexport class InvalidStateTransition extends Error {\n constructor(\n public fromStatus: string,\n public toStatus: string,\n ) {\n super(`Cannot transition report from '${fromStatus}' to '${toStatus}'`)\n this.name = 'InvalidStateTransition'\n }\n}\n\n// ---------------------------------------------------------------------------\n// State machine tables\n// ---------------------------------------------------------------------------\n\n/** Valid state transitions: key = fromState, value = allowed toStates */\nexport const VALID_TRANSITIONS: Record<string, string[]> = {\n open: ['closed', 'escalated', 'queued', 'assigned'],\n closed: ['open'],\n escalated: ['open', 'closed'],\n queued: ['assigned', 'open', 'closed'],\n assigned: ['open', 'closed', 'escalated', 'queued'],\n}\n\n/** Activity types that map to a specific target status */\nconst ACTIVITY_TO_STATE: Record<string, string> = {\n queueActivity: 'queued',\n assignmentActivity: 'assigned',\n escalationActivity: 'escalated',\n closeActivity: 'closed',\n reopenActivity: 'open',\n}\n\n/** Activity types that are only valid from specific source states */\nconst ACTIVITY_VALID_FROM_STATES: Record<string, string[]> = {\n reopenActivity: ['closed'],\n}\n\n/** Moderation event types → target status (+ activity type) */\nconst EVENT_TYPE_MAP: Record<string, { status: string; activityType: string }> =\n {\n 'tools.ozone.moderation.defs#modEventAcknowledge': {\n status: 'closed',\n activityType: 'closeActivity',\n },\n 'tools.ozone.moderation.defs#modEventTakedown': {\n status: 'closed',\n activityType: 'closeActivity',\n },\n 'tools.ozone.moderation.defs#modEventLabel': {\n status: 'closed',\n activityType: 'closeActivity',\n },\n 'tools.ozone.moderation.defs#modEventComment': {\n status: 'closed',\n activityType: 'closeActivity',\n },\n 'tools.ozone.moderation.defs#modEventEscalate': {\n status: 'escalated',\n activityType: 'escalationActivity',\n },\n }\n\n// ---------------------------------------------------------------------------\n// Action types — the three ways a report's status can change\n// ---------------------------------------------------------------------------\n\nexport type ReportUpdateAction =\n | { type: 'activity'; activityType: string }\n | { type: 'event'; eventType: string }\n | { type: 'queue' }\n\n// ---------------------------------------------------------------------------\n// Result type\n// ---------------------------------------------------------------------------\n\nexport type ActivityRecord = {\n activityType: string\n previousStatus: string\n}\n\nexport type ReportUpdateResult = {\n nextStatus: string | null\n activity: ActivityRecord | null\n}\n\n// ---------------------------------------------------------------------------\n// Core function\n// ---------------------------------------------------------------------------\n\n/**\n * Determines the next status and activity record for a report update.\n *\n * @throws AlreadyInTargetState if the report is already in the target status\n * @throws InvalidStateTransition if the transition is not allowed\n * @returns nextStatus (null = no change) and activity (null = nothing to record)\n */\nexport function handleReportUpdate(\n currentStatus: string,\n action: ReportUpdateAction,\n): ReportUpdateResult {\n switch (action.type) {\n case 'activity':\n return handleActivityAction(currentStatus, action.activityType)\n case 'event':\n return handleEventAction(currentStatus, action.eventType)\n case 'queue':\n return handleQueueAction(currentStatus)\n }\n}\n\n// ---------------------------------------------------------------------------\n// Action handlers\n// ---------------------------------------------------------------------------\n\nfunction handleActivityAction(\n currentStatus: string,\n activityType: string,\n): ReportUpdateResult {\n const toState = ACTIVITY_TO_STATE[activityType] ?? null\n\n // Note-type activities — no state change, but still produce an activity record\n if (toState === null) {\n return { nextStatus: null, activity: null }\n }\n\n // Check activity-specific source-state constraints\n const validFromStates = ACTIVITY_VALID_FROM_STATES[activityType]\n if (validFromStates && !validFromStates.includes(currentStatus)) {\n throw new InvalidStateTransition(currentStatus, toState)\n }\n\n validateTransition(currentStatus, toState)\n\n return {\n nextStatus: toState,\n activity: { activityType, previousStatus: currentStatus },\n }\n}\n\nfunction handleEventAction(\n currentStatus: string,\n eventType: string,\n): ReportUpdateResult {\n const mapping = EVENT_TYPE_MAP[eventType]\n if (!mapping) {\n // Event type doesn't affect report status\n return { nextStatus: null, activity: null }\n }\n\n validateTransition(currentStatus, mapping.status)\n\n return {\n nextStatus: mapping.status,\n activity: {\n activityType: mapping.activityType,\n previousStatus: currentStatus,\n },\n }\n}\n\nfunction handleQueueAction(currentStatus: string): ReportUpdateResult {\n // Queue routing only transitions open → queued\n if (currentStatus !== 'open') {\n return { nextStatus: null, activity: null }\n }\n\n return {\n nextStatus: 'queued',\n activity: { activityType: 'queueActivity', previousStatus: currentStatus },\n }\n}\n\n// ---------------------------------------------------------------------------\n// Shared validation\n// ---------------------------------------------------------------------------\n\nfunction validateTransition(fromStatus: string, toStatus: string): void {\n if (fromStatus === toStatus) {\n throw new AlreadyInTargetState(fromStatus, toStatus)\n }\n const allowed = VALID_TRANSITIONS[fromStatus] ?? []\n if (!allowed.includes(toStatus)) {\n throw new InvalidStateTransition(fromStatus, toStatus)\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/ozone",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.22",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Backend service for moderating the Bluesky network.",
|
|
6
6
|
"keywords": [
|
|
@@ -45,15 +45,15 @@
|
|
|
45
45
|
"uint8arrays": "^5.0.0",
|
|
46
46
|
"undici": "^8.5.0",
|
|
47
47
|
"ws": "^8.12.0",
|
|
48
|
-
"@atproto/api": "^0.20.
|
|
49
|
-
"@atproto/
|
|
48
|
+
"@atproto/api": "^0.20.35",
|
|
49
|
+
"@atproto/identity": "^0.5.6",
|
|
50
50
|
"@atproto/crypto": "^0.5.4",
|
|
51
|
-
"@atproto/lexicon": "^0.7.
|
|
51
|
+
"@atproto/lexicon": "^0.7.8",
|
|
52
52
|
"@atproto/syntax": "^0.7.2",
|
|
53
|
-
"@atproto/identity": "^0.5.6",
|
|
54
53
|
"@atproto/ws-client": "^0.1.7",
|
|
55
|
-
"@atproto/xrpc": "^0.8.
|
|
56
|
-
"@atproto/xrpc-server": "^0.11.
|
|
54
|
+
"@atproto/xrpc": "^0.8.7",
|
|
55
|
+
"@atproto/xrpc-server": "^0.11.12",
|
|
56
|
+
"@atproto/common": "^0.7.2"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@did-plc/server": "^0.0.1",
|
|
@@ -65,8 +65,8 @@
|
|
|
65
65
|
"@types/qs": "^6.9.7",
|
|
66
66
|
"@types/ws": "^8.18.1",
|
|
67
67
|
"jest": "^30.0.0",
|
|
68
|
-
"@atproto/lex-cli": "^0.10.
|
|
69
|
-
"@atproto/pds": "^0.5.
|
|
68
|
+
"@atproto/lex-cli": "^0.10.7",
|
|
69
|
+
"@atproto/pds": "^0.5.22"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"codegen:lex": "lex gen-server --yes ./src/lexicon ../../lexicons/com/atproto/*/* ../../lexicons/app/bsky/*/* ../../lexicons/chat/bsky/*/* ../../lexicons/tools/ozone/*/*",
|