@atproto/ozone 0.1.126 → 0.1.128

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.
Files changed (157) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/api/index.d.ts.map +1 -1
  3. package/dist/api/index.js +10 -0
  4. package/dist/api/index.js.map +1 -1
  5. package/dist/api/moderation/emitEvent.d.ts.map +1 -1
  6. package/dist/api/moderation/emitEvent.js +2 -0
  7. package/dist/api/moderation/emitEvent.js.map +1 -1
  8. package/dist/api/moderation/queryEvents.d.ts.map +1 -1
  9. package/dist/api/moderation/queryEvents.js +2 -1
  10. package/dist/api/moderation/queryEvents.js.map +1 -1
  11. package/dist/api/report/createReport.d.ts.map +1 -1
  12. package/dist/api/report/createReport.js +2 -1
  13. package/dist/api/report/createReport.js.map +1 -1
  14. package/dist/api/safelink/addRule.d.ts +4 -0
  15. package/dist/api/safelink/addRule.d.ts.map +1 -0
  16. package/dist/api/safelink/addRule.js +37 -0
  17. package/dist/api/safelink/addRule.js.map +1 -0
  18. package/dist/api/safelink/queryEvents.d.ts +4 -0
  19. package/dist/api/safelink/queryEvents.d.ts.map +1 -0
  20. package/dist/api/safelink/queryEvents.js +29 -0
  21. package/dist/api/safelink/queryEvents.js.map +1 -0
  22. package/dist/api/safelink/queryRules.d.ts +4 -0
  23. package/dist/api/safelink/queryRules.d.ts.map +1 -0
  24. package/dist/api/safelink/queryRules.js +43 -0
  25. package/dist/api/safelink/queryRules.js.map +1 -0
  26. package/dist/api/safelink/removeRule.d.ts +4 -0
  27. package/dist/api/safelink/removeRule.d.ts.map +1 -0
  28. package/dist/api/safelink/removeRule.js +35 -0
  29. package/dist/api/safelink/removeRule.js.map +1 -0
  30. package/dist/api/safelink/updateRule.d.ts +4 -0
  31. package/dist/api/safelink/updateRule.d.ts.map +1 -0
  32. package/dist/api/safelink/updateRule.js +37 -0
  33. package/dist/api/safelink/updateRule.js.map +1 -0
  34. package/dist/api/util.d.ts +8 -0
  35. package/dist/api/util.d.ts.map +1 -1
  36. package/dist/api/util.js +33 -1
  37. package/dist/api/util.js.map +1 -1
  38. package/dist/context.d.ts +3 -0
  39. package/dist/context.d.ts.map +1 -1
  40. package/dist/context.js +12 -6
  41. package/dist/context.js.map +1 -1
  42. package/dist/db/migrations/20250609T110704000Z-safelink.d.ts +4 -0
  43. package/dist/db/migrations/20250609T110704000Z-safelink.d.ts.map +1 -0
  44. package/dist/db/migrations/20250609T110704000Z-safelink.js +51 -0
  45. package/dist/db/migrations/20250609T110704000Z-safelink.js.map +1 -0
  46. package/dist/db/migrations/20250618T180246000Z-add-mod-tool-to-moderation-event.d.ts +4 -0
  47. package/dist/db/migrations/20250618T180246000Z-add-mod-tool-to-moderation-event.d.ts.map +1 -0
  48. package/dist/db/migrations/20250618T180246000Z-add-mod-tool-to-moderation-event.js +20 -0
  49. package/dist/db/migrations/20250618T180246000Z-add-mod-tool-to-moderation-event.js.map +1 -0
  50. package/dist/db/migrations/index.d.ts +2 -0
  51. package/dist/db/migrations/index.d.ts.map +1 -1
  52. package/dist/db/migrations/index.js +3 -1
  53. package/dist/db/migrations/index.js.map +1 -1
  54. package/dist/db/schema/index.d.ts +2 -1
  55. package/dist/db/schema/index.d.ts.map +1 -1
  56. package/dist/db/schema/moderation_event.d.ts +6 -0
  57. package/dist/db/schema/moderation_event.d.ts.map +1 -1
  58. package/dist/db/schema/safelink.d.ts +31 -0
  59. package/dist/db/schema/safelink.d.ts.map +1 -0
  60. package/dist/db/schema/safelink.js +6 -0
  61. package/dist/db/schema/safelink.js.map +1 -0
  62. package/dist/lexicon/index.d.ts +15 -0
  63. package/dist/lexicon/index.d.ts.map +1 -1
  64. package/dist/lexicon/index.js +40 -1
  65. package/dist/lexicon/index.js.map +1 -1
  66. package/dist/lexicon/lexicons.d.ts +3427 -2489
  67. package/dist/lexicon/lexicons.d.ts.map +1 -1
  68. package/dist/lexicon/lexicons.js +499 -0
  69. package/dist/lexicon/lexicons.js.map +1 -1
  70. package/dist/lexicon/types/com/atproto/moderation/createReport.d.ts +14 -0
  71. package/dist/lexicon/types/com/atproto/moderation/createReport.d.ts.map +1 -1
  72. package/dist/lexicon/types/com/atproto/moderation/createReport.js +9 -0
  73. package/dist/lexicon/types/com/atproto/moderation/createReport.js.map +1 -1
  74. package/dist/lexicon/types/tools/ozone/moderation/defs.d.ts +14 -0
  75. package/dist/lexicon/types/tools/ozone/moderation/defs.d.ts.map +1 -1
  76. package/dist/lexicon/types/tools/ozone/moderation/defs.js +9 -0
  77. package/dist/lexicon/types/tools/ozone/moderation/defs.js.map +1 -1
  78. package/dist/lexicon/types/tools/ozone/moderation/emitEvent.d.ts +1 -0
  79. package/dist/lexicon/types/tools/ozone/moderation/emitEvent.d.ts.map +1 -1
  80. package/dist/lexicon/types/tools/ozone/moderation/queryEvents.d.ts +2 -0
  81. package/dist/lexicon/types/tools/ozone/moderation/queryEvents.d.ts.map +1 -1
  82. package/dist/lexicon/types/tools/ozone/safelink/addRule.d.ts +47 -0
  83. package/dist/lexicon/types/tools/ozone/safelink/addRule.d.ts.map +1 -0
  84. package/dist/lexicon/types/tools/ozone/safelink/addRule.js +7 -0
  85. package/dist/lexicon/types/tools/ozone/safelink/addRule.js.map +1 -0
  86. package/dist/lexicon/types/tools/ozone/safelink/defs.d.ts +47 -0
  87. package/dist/lexicon/types/tools/ozone/safelink/defs.d.ts.map +1 -0
  88. package/dist/lexicon/types/tools/ozone/safelink/defs.js +25 -0
  89. package/dist/lexicon/types/tools/ozone/safelink/defs.js.map +1 -0
  90. package/dist/lexicon/types/tools/ozone/safelink/queryEvents.d.ts +51 -0
  91. package/dist/lexicon/types/tools/ozone/safelink/queryEvents.d.ts.map +1 -0
  92. package/dist/lexicon/types/tools/ozone/safelink/queryEvents.js +7 -0
  93. package/dist/lexicon/types/tools/ozone/safelink/queryEvents.js.map +1 -0
  94. package/dist/lexicon/types/tools/ozone/safelink/queryRules.d.ts +57 -0
  95. package/dist/lexicon/types/tools/ozone/safelink/queryRules.d.ts.map +1 -0
  96. package/dist/lexicon/types/tools/ozone/safelink/queryRules.js +7 -0
  97. package/dist/lexicon/types/tools/ozone/safelink/queryRules.js.map +1 -0
  98. package/dist/lexicon/types/tools/ozone/safelink/removeRule.d.ts +45 -0
  99. package/dist/lexicon/types/tools/ozone/safelink/removeRule.d.ts.map +1 -0
  100. package/dist/lexicon/types/tools/ozone/safelink/removeRule.js +7 -0
  101. package/dist/lexicon/types/tools/ozone/safelink/removeRule.js.map +1 -0
  102. package/dist/lexicon/types/tools/ozone/safelink/updateRule.d.ts +47 -0
  103. package/dist/lexicon/types/tools/ozone/safelink/updateRule.d.ts.map +1 -0
  104. package/dist/lexicon/types/tools/ozone/safelink/updateRule.js +7 -0
  105. package/dist/lexicon/types/tools/ozone/safelink/updateRule.js.map +1 -0
  106. package/dist/mod-service/index.d.ts +13 -1
  107. package/dist/mod-service/index.d.ts.map +1 -1
  108. package/dist/mod-service/index.js +10 -3
  109. package/dist/mod-service/index.js.map +1 -1
  110. package/dist/mod-service/status.d.ts +6 -0
  111. package/dist/mod-service/status.d.ts.map +1 -1
  112. package/dist/mod-service/views.d.ts.map +1 -1
  113. package/dist/mod-service/views.js +6 -0
  114. package/dist/mod-service/views.js.map +1 -1
  115. package/dist/safelink/service.d.ts +69 -0
  116. package/dist/safelink/service.d.ts.map +1 -0
  117. package/dist/safelink/service.js +179 -0
  118. package/dist/safelink/service.js.map +1 -0
  119. package/package.json +5 -5
  120. package/src/api/index.ts +10 -0
  121. package/src/api/moderation/emitEvent.ts +2 -0
  122. package/src/api/moderation/queryEvents.ts +2 -0
  123. package/src/api/report/createReport.ts +2 -1
  124. package/src/api/safelink/addRule.ts +48 -0
  125. package/src/api/safelink/queryEvents.ts +32 -0
  126. package/src/api/safelink/queryRules.ts +58 -0
  127. package/src/api/safelink/removeRule.ts +42 -0
  128. package/src/api/safelink/updateRule.ts +48 -0
  129. package/src/api/util.ts +38 -0
  130. package/src/context.ts +11 -0
  131. package/src/db/migrations/20250609T110704000Z-safelink.ts +53 -0
  132. package/src/db/migrations/20250618T180246000Z-add-mod-tool-to-moderation-event.ts +18 -0
  133. package/src/db/migrations/index.ts +2 -0
  134. package/src/db/schema/index.ts +3 -1
  135. package/src/db/schema/moderation_event.ts +1 -0
  136. package/src/db/schema/safelink.ts +39 -0
  137. package/src/lexicon/index.ts +70 -0
  138. package/src/lexicon/lexicons.ts +509 -0
  139. package/src/lexicon/types/com/atproto/moderation/createReport.ts +20 -0
  140. package/src/lexicon/types/tools/ozone/moderation/defs.ts +21 -0
  141. package/src/lexicon/types/tools/ozone/moderation/emitEvent.ts +1 -0
  142. package/src/lexicon/types/tools/ozone/moderation/queryEvents.ts +2 -0
  143. package/src/lexicon/types/tools/ozone/safelink/addRule.ts +64 -0
  144. package/src/lexicon/types/tools/ozone/safelink/defs.ts +76 -0
  145. package/src/lexicon/types/tools/ozone/safelink/queryEvents.ts +68 -0
  146. package/src/lexicon/types/tools/ozone/safelink/queryRules.ts +74 -0
  147. package/src/lexicon/types/tools/ozone/safelink/removeRule.ts +62 -0
  148. package/src/lexicon/types/tools/ozone/safelink/updateRule.ts +64 -0
  149. package/src/mod-service/index.ts +17 -2
  150. package/src/mod-service/views.ts +6 -0
  151. package/src/safelink/service.ts +304 -0
  152. package/tests/__snapshots__/safelink.test.ts.snap +179 -0
  153. package/tests/communication-templates.test.ts +7 -7
  154. package/tests/mod-tool.test.ts +128 -0
  155. package/tests/safelink.test.ts +534 -0
  156. package/tsconfig.build.tsbuildinfo +1 -1
  157. package/tsconfig.tests.tsbuildinfo +1 -1
@@ -0,0 +1,64 @@
1
+ /**
2
+ * GENERATED CODE - DO NOT MODIFY
3
+ */
4
+ import express from 'express'
5
+ import { type ValidationResult, BlobRef } from '@atproto/lexicon'
6
+ import { CID } from 'multiformats/cid'
7
+ import { validate as _validate } from '../../../../lexicons'
8
+ import {
9
+ type $Typed,
10
+ is$typed as _is$typed,
11
+ type OmitKey,
12
+ } from '../../../../util'
13
+ import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server'
14
+ import type * as ToolsOzoneSafelinkDefs from './defs.js'
15
+
16
+ const is$typed = _is$typed,
17
+ validate = _validate
18
+ const id = 'tools.ozone.safelink.addRule'
19
+
20
+ export interface QueryParams {}
21
+
22
+ export interface InputSchema {
23
+ /** The URL or domain to apply the rule to */
24
+ url: string
25
+ pattern: ToolsOzoneSafelinkDefs.PatternType
26
+ action: ToolsOzoneSafelinkDefs.ActionType
27
+ reason: ToolsOzoneSafelinkDefs.ReasonType
28
+ /** Optional comment about the decision */
29
+ comment?: string
30
+ /** Author DID. Only respected when using admin auth */
31
+ createdBy?: string
32
+ }
33
+
34
+ export type OutputSchema = ToolsOzoneSafelinkDefs.Event
35
+
36
+ export interface HandlerInput {
37
+ encoding: 'application/json'
38
+ body: InputSchema
39
+ }
40
+
41
+ export interface HandlerSuccess {
42
+ encoding: 'application/json'
43
+ body: OutputSchema
44
+ headers?: { [key: string]: string }
45
+ }
46
+
47
+ export interface HandlerError {
48
+ status: number
49
+ message?: string
50
+ error?: 'InvalidUrl' | 'RuleAlreadyExists'
51
+ }
52
+
53
+ export type HandlerOutput = HandlerError | HandlerSuccess | HandlerPipeThrough
54
+ export type HandlerReqCtx<HA extends HandlerAuth = never> = {
55
+ auth: HA
56
+ params: QueryParams
57
+ input: HandlerInput
58
+ req: express.Request
59
+ res: express.Response
60
+ resetRouteRateLimits: () => Promise<void>
61
+ }
62
+ export type Handler<HA extends HandlerAuth = never> = (
63
+ ctx: HandlerReqCtx<HA>,
64
+ ) => Promise<HandlerOutput> | HandlerOutput
@@ -0,0 +1,76 @@
1
+ /**
2
+ * GENERATED CODE - DO NOT MODIFY
3
+ */
4
+ import { type ValidationResult, BlobRef } from '@atproto/lexicon'
5
+ import { CID } from 'multiformats/cid'
6
+ import { validate as _validate } from '../../../../lexicons'
7
+ import {
8
+ type $Typed,
9
+ is$typed as _is$typed,
10
+ type OmitKey,
11
+ } from '../../../../util'
12
+
13
+ const is$typed = _is$typed,
14
+ validate = _validate
15
+ const id = 'tools.ozone.safelink.defs'
16
+
17
+ /** An event for URL safety decisions */
18
+ export interface Event {
19
+ $type?: 'tools.ozone.safelink.defs#event'
20
+ /** Auto-incrementing row ID */
21
+ id: number
22
+ eventType: EventType
23
+ /** The URL that this rule applies to */
24
+ url: string
25
+ pattern: PatternType
26
+ action: ActionType
27
+ reason: ReasonType
28
+ /** DID of the user who created this rule */
29
+ createdBy: string
30
+ createdAt: string
31
+ /** Optional comment about the decision */
32
+ comment?: string
33
+ }
34
+
35
+ const hashEvent = 'event'
36
+
37
+ export function isEvent<V>(v: V) {
38
+ return is$typed(v, id, hashEvent)
39
+ }
40
+
41
+ export function validateEvent<V>(v: V) {
42
+ return validate<Event & V>(v, id, hashEvent)
43
+ }
44
+
45
+ export type EventType = 'addRule' | 'updateRule' | 'removeRule' | (string & {})
46
+ export type PatternType = 'domain' | 'url' | (string & {})
47
+ export type ActionType = 'block' | 'warn' | 'whitelist' | (string & {})
48
+ export type ReasonType = 'csam' | 'spam' | 'phishing' | 'none' | (string & {})
49
+
50
+ /** Input for creating a URL safety rule */
51
+ export interface UrlRule {
52
+ $type?: 'tools.ozone.safelink.defs#urlRule'
53
+ /** The URL or domain to apply the rule to */
54
+ url: string
55
+ pattern: PatternType
56
+ action: ActionType
57
+ reason: ReasonType
58
+ /** Optional comment about the decision */
59
+ comment?: string
60
+ /** DID of the user added the rule. */
61
+ createdBy: string
62
+ /** Timestamp when the rule was created */
63
+ createdAt: string
64
+ /** Timestamp when the rule was last updated */
65
+ updatedAt: string
66
+ }
67
+
68
+ const hashUrlRule = 'urlRule'
69
+
70
+ export function isUrlRule<V>(v: V) {
71
+ return is$typed(v, id, hashUrlRule)
72
+ }
73
+
74
+ export function validateUrlRule<V>(v: V) {
75
+ return validate<UrlRule & V>(v, id, hashUrlRule)
76
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * GENERATED CODE - DO NOT MODIFY
3
+ */
4
+ import express from 'express'
5
+ import { type ValidationResult, BlobRef } from '@atproto/lexicon'
6
+ import { CID } from 'multiformats/cid'
7
+ import { validate as _validate } from '../../../../lexicons'
8
+ import {
9
+ type $Typed,
10
+ is$typed as _is$typed,
11
+ type OmitKey,
12
+ } from '../../../../util'
13
+ import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server'
14
+ import type * as ToolsOzoneSafelinkDefs from './defs.js'
15
+
16
+ const is$typed = _is$typed,
17
+ validate = _validate
18
+ const id = 'tools.ozone.safelink.queryEvents'
19
+
20
+ export interface QueryParams {}
21
+
22
+ export interface InputSchema {
23
+ /** Cursor for pagination */
24
+ cursor?: string
25
+ /** Maximum number of results to return */
26
+ limit: number
27
+ /** Filter by specific URLs or domains */
28
+ urls?: string[]
29
+ /** Filter by pattern type */
30
+ patternType?: string
31
+ /** Sort direction */
32
+ sortDirection: 'asc' | 'desc' | (string & {})
33
+ }
34
+
35
+ export interface OutputSchema {
36
+ /** Next cursor for pagination. Only present if there are more results. */
37
+ cursor?: string
38
+ events: ToolsOzoneSafelinkDefs.Event[]
39
+ }
40
+
41
+ export interface HandlerInput {
42
+ encoding: 'application/json'
43
+ body: InputSchema
44
+ }
45
+
46
+ export interface HandlerSuccess {
47
+ encoding: 'application/json'
48
+ body: OutputSchema
49
+ headers?: { [key: string]: string }
50
+ }
51
+
52
+ export interface HandlerError {
53
+ status: number
54
+ message?: string
55
+ }
56
+
57
+ export type HandlerOutput = HandlerError | HandlerSuccess | HandlerPipeThrough
58
+ export type HandlerReqCtx<HA extends HandlerAuth = never> = {
59
+ auth: HA
60
+ params: QueryParams
61
+ input: HandlerInput
62
+ req: express.Request
63
+ res: express.Response
64
+ resetRouteRateLimits: () => Promise<void>
65
+ }
66
+ export type Handler<HA extends HandlerAuth = never> = (
67
+ ctx: HandlerReqCtx<HA>,
68
+ ) => Promise<HandlerOutput> | HandlerOutput
@@ -0,0 +1,74 @@
1
+ /**
2
+ * GENERATED CODE - DO NOT MODIFY
3
+ */
4
+ import express from 'express'
5
+ import { type ValidationResult, BlobRef } from '@atproto/lexicon'
6
+ import { CID } from 'multiformats/cid'
7
+ import { validate as _validate } from '../../../../lexicons'
8
+ import {
9
+ type $Typed,
10
+ is$typed as _is$typed,
11
+ type OmitKey,
12
+ } from '../../../../util'
13
+ import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server'
14
+ import type * as ToolsOzoneSafelinkDefs from './defs.js'
15
+
16
+ const is$typed = _is$typed,
17
+ validate = _validate
18
+ const id = 'tools.ozone.safelink.queryRules'
19
+
20
+ export interface QueryParams {}
21
+
22
+ export interface InputSchema {
23
+ /** Cursor for pagination */
24
+ cursor?: string
25
+ /** Maximum number of results to return */
26
+ limit: number
27
+ /** Filter by specific URLs or domains */
28
+ urls?: string[]
29
+ /** Filter by pattern type */
30
+ patternType?: string
31
+ /** Filter by action types */
32
+ actions?: string[]
33
+ /** Filter by reason type */
34
+ reason?: string
35
+ /** Filter by rule creator */
36
+ createdBy?: string
37
+ /** Sort direction */
38
+ sortDirection: 'asc' | 'desc' | (string & {})
39
+ }
40
+
41
+ export interface OutputSchema {
42
+ /** Next cursor for pagination. Only present if there are more results. */
43
+ cursor?: string
44
+ rules: ToolsOzoneSafelinkDefs.UrlRule[]
45
+ }
46
+
47
+ export interface HandlerInput {
48
+ encoding: 'application/json'
49
+ body: InputSchema
50
+ }
51
+
52
+ export interface HandlerSuccess {
53
+ encoding: 'application/json'
54
+ body: OutputSchema
55
+ headers?: { [key: string]: string }
56
+ }
57
+
58
+ export interface HandlerError {
59
+ status: number
60
+ message?: string
61
+ }
62
+
63
+ export type HandlerOutput = HandlerError | HandlerSuccess | HandlerPipeThrough
64
+ export type HandlerReqCtx<HA extends HandlerAuth = never> = {
65
+ auth: HA
66
+ params: QueryParams
67
+ input: HandlerInput
68
+ req: express.Request
69
+ res: express.Response
70
+ resetRouteRateLimits: () => Promise<void>
71
+ }
72
+ export type Handler<HA extends HandlerAuth = never> = (
73
+ ctx: HandlerReqCtx<HA>,
74
+ ) => Promise<HandlerOutput> | HandlerOutput
@@ -0,0 +1,62 @@
1
+ /**
2
+ * GENERATED CODE - DO NOT MODIFY
3
+ */
4
+ import express from 'express'
5
+ import { type ValidationResult, BlobRef } from '@atproto/lexicon'
6
+ import { CID } from 'multiformats/cid'
7
+ import { validate as _validate } from '../../../../lexicons'
8
+ import {
9
+ type $Typed,
10
+ is$typed as _is$typed,
11
+ type OmitKey,
12
+ } from '../../../../util'
13
+ import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server'
14
+ import type * as ToolsOzoneSafelinkDefs from './defs.js'
15
+
16
+ const is$typed = _is$typed,
17
+ validate = _validate
18
+ const id = 'tools.ozone.safelink.removeRule'
19
+
20
+ export interface QueryParams {}
21
+
22
+ export interface InputSchema {
23
+ /** The URL or domain to remove the rule for */
24
+ url: string
25
+ pattern: ToolsOzoneSafelinkDefs.PatternType
26
+ /** Optional comment about why the rule is being removed */
27
+ comment?: string
28
+ /** Optional DID of the user. Only respected when using admin auth. */
29
+ createdBy?: string
30
+ }
31
+
32
+ export type OutputSchema = ToolsOzoneSafelinkDefs.Event
33
+
34
+ export interface HandlerInput {
35
+ encoding: 'application/json'
36
+ body: InputSchema
37
+ }
38
+
39
+ export interface HandlerSuccess {
40
+ encoding: 'application/json'
41
+ body: OutputSchema
42
+ headers?: { [key: string]: string }
43
+ }
44
+
45
+ export interface HandlerError {
46
+ status: number
47
+ message?: string
48
+ error?: 'RuleNotFound'
49
+ }
50
+
51
+ export type HandlerOutput = HandlerError | HandlerSuccess | HandlerPipeThrough
52
+ export type HandlerReqCtx<HA extends HandlerAuth = never> = {
53
+ auth: HA
54
+ params: QueryParams
55
+ input: HandlerInput
56
+ req: express.Request
57
+ res: express.Response
58
+ resetRouteRateLimits: () => Promise<void>
59
+ }
60
+ export type Handler<HA extends HandlerAuth = never> = (
61
+ ctx: HandlerReqCtx<HA>,
62
+ ) => Promise<HandlerOutput> | HandlerOutput
@@ -0,0 +1,64 @@
1
+ /**
2
+ * GENERATED CODE - DO NOT MODIFY
3
+ */
4
+ import express from 'express'
5
+ import { type ValidationResult, BlobRef } from '@atproto/lexicon'
6
+ import { CID } from 'multiformats/cid'
7
+ import { validate as _validate } from '../../../../lexicons'
8
+ import {
9
+ type $Typed,
10
+ is$typed as _is$typed,
11
+ type OmitKey,
12
+ } from '../../../../util'
13
+ import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server'
14
+ import type * as ToolsOzoneSafelinkDefs from './defs.js'
15
+
16
+ const is$typed = _is$typed,
17
+ validate = _validate
18
+ const id = 'tools.ozone.safelink.updateRule'
19
+
20
+ export interface QueryParams {}
21
+
22
+ export interface InputSchema {
23
+ /** The URL or domain to update the rule for */
24
+ url: string
25
+ pattern: ToolsOzoneSafelinkDefs.PatternType
26
+ action: ToolsOzoneSafelinkDefs.ActionType
27
+ reason: ToolsOzoneSafelinkDefs.ReasonType
28
+ /** Optional comment about the update */
29
+ comment?: string
30
+ /** Optional DID to credit as the creator. Only respected for admin_token authentication. */
31
+ createdBy?: string
32
+ }
33
+
34
+ export type OutputSchema = ToolsOzoneSafelinkDefs.Event
35
+
36
+ export interface HandlerInput {
37
+ encoding: 'application/json'
38
+ body: InputSchema
39
+ }
40
+
41
+ export interface HandlerSuccess {
42
+ encoding: 'application/json'
43
+ body: OutputSchema
44
+ headers?: { [key: string]: string }
45
+ }
46
+
47
+ export interface HandlerError {
48
+ status: number
49
+ message?: string
50
+ error?: 'RuleNotFound'
51
+ }
52
+
53
+ export type HandlerOutput = HandlerError | HandlerSuccess | HandlerPipeThrough
54
+ export type HandlerReqCtx<HA extends HandlerAuth = never> = {
55
+ auth: HA
56
+ params: QueryParams
57
+ input: HandlerInput
58
+ req: express.Request
59
+ res: express.Response
60
+ resetRouteRateLimits: () => Promise<void>
61
+ }
62
+ export type Handler<HA extends HandlerAuth = never> = (
63
+ ctx: HandlerReqCtx<HA>,
64
+ ) => Promise<HandlerOutput> | HandlerOutput
@@ -1,6 +1,6 @@
1
1
  import { Insertable, RawBuilder, sql } from 'kysely'
2
2
  import { CID } from 'multiformats/cid'
3
- import { AtpAgent } from '@atproto/api'
3
+ import { AtpAgent, ToolsOzoneModerationDefs } from '@atproto/api'
4
4
  import { addHoursToDate, chunkArray } from '@atproto/common'
5
5
  import { Keypair } from '@atproto/crypto'
6
6
  import { IdResolver } from '@atproto/identity'
@@ -167,6 +167,7 @@ export class ModerationService {
167
167
  collections: string[]
168
168
  subjectType?: string
169
169
  policies?: string[]
170
+ modTool?: string[]
170
171
  }): Promise<{ cursor?: string; events: ModerationEventRow[] }> {
171
172
  const {
172
173
  subject,
@@ -188,6 +189,7 @@ export class ModerationService {
188
189
  collections,
189
190
  subjectType,
190
191
  policies,
192
+ modTool,
191
193
  } = opts
192
194
  const { ref } = this.db.db.dynamic
193
195
  let builder = this.db.db.selectFrom('moderation_event').selectAll()
@@ -288,6 +290,11 @@ export class ModerationService {
288
290
  return qb
289
291
  })
290
292
  }
293
+ if (modTool?.length) {
294
+ builder = builder
295
+ .where('modTool', 'is not', null)
296
+ .where(sql`("modTool" ->> 'name')`, 'in', modTool)
297
+ }
291
298
 
292
299
  const keyset = new TimeIdKeyset(
293
300
  ref(`moderation_event.createdAt`),
@@ -397,12 +404,13 @@ export class ModerationService {
397
404
  subject: ModSubject
398
405
  createdBy: string
399
406
  createdAt?: Date
407
+ modTool?: ToolsOzoneModerationDefs.ModTool
400
408
  }): Promise<{
401
409
  event: ModerationEventRow
402
410
  subjectStatus: ModerationSubjectStatusRow | null
403
411
  }> {
404
412
  this.db.assertTransaction()
405
- const { event, subject, createdBy, createdAt = new Date() } = info
413
+ const { event, subject, createdBy, createdAt = new Date(), modTool } = info
406
414
 
407
415
  const createLabelVals =
408
416
  isModEventLabel(event) && event.createLabelVals.length > 0
@@ -508,6 +516,7 @@ export class ModerationService {
508
516
  subjectCid: subjectInfo.subjectCid,
509
517
  subjectBlobCids: jsonb(subjectInfo.subjectBlobCids),
510
518
  subjectMessageId: subjectInfo.subjectMessageId,
519
+ modTool: modTool ? jsonb(modTool) : null,
511
520
  })
512
521
  .returningAll()
513
522
  .executeTakeFirstOrThrow()
@@ -802,6 +811,10 @@ export class ModerationService {
802
811
  subject: ModSubject
803
812
  reportedBy: string
804
813
  createdAt?: Date
814
+ modTool?: {
815
+ name: string
816
+ meta?: { [_ in string]: unknown }
817
+ }
805
818
  }): Promise<{
806
819
  event: ModerationEventRow
807
820
  subjectStatus: ModerationSubjectStatusRow | null
@@ -812,6 +825,7 @@ export class ModerationService {
812
825
  reportedBy,
813
826
  createdAt = new Date(),
814
827
  subject,
828
+ modTool,
815
829
  } = info
816
830
 
817
831
  const result = await this.logEvent({
@@ -823,6 +837,7 @@ export class ModerationService {
823
837
  createdBy: reportedBy,
824
838
  subject,
825
839
  createdAt,
840
+ modTool,
826
841
  })
827
842
 
828
843
  return result
@@ -141,6 +141,12 @@ export class ModerationViews {
141
141
  createdAt: row.createdAt,
142
142
  subjectHandle: row.subjectHandle ?? undefined,
143
143
  creatorHandle: row.creatorHandle ?? undefined,
144
+ modTool: row.modTool
145
+ ? {
146
+ name: row.modTool.name,
147
+ meta: row.modTool.meta,
148
+ }
149
+ : undefined,
144
150
  }
145
151
 
146
152
  const { event } = eventView