@atproto/pds 0.4.22 → 0.4.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/actor-store/blob/reader.d.ts +4 -0
  3. package/dist/actor-store/blob/reader.d.ts.map +1 -1
  4. package/dist/actor-store/blob/reader.js +9 -3
  5. package/dist/actor-store/blob/reader.js.map +1 -1
  6. package/dist/api/chat/index.d.ts +4 -0
  7. package/dist/api/chat/index.d.ts.map +1 -0
  8. package/dist/api/chat/index.js +91 -0
  9. package/dist/api/chat/index.js.map +1 -0
  10. package/dist/api/com/atproto/repo/putRecord.d.ts.map +1 -1
  11. package/dist/api/com/atproto/repo/putRecord.js +19 -1
  12. package/dist/api/com/atproto/repo/putRecord.js.map +1 -1
  13. package/dist/api/index.d.ts.map +1 -1
  14. package/dist/api/index.js +2 -0
  15. package/dist/api/index.js.map +1 -1
  16. package/dist/index.js +1 -1
  17. package/dist/lexicon/lexicons.d.ts +9 -4
  18. package/dist/lexicon/lexicons.d.ts.map +1 -1
  19. package/dist/lexicon/lexicons.js +13 -7
  20. package/dist/lexicon/lexicons.js.map +1 -1
  21. package/dist/lexicon/types/chat/bsky/convo/defs.d.ts +4 -4
  22. package/dist/lexicon/types/chat/bsky/convo/defs.d.ts.map +1 -1
  23. package/dist/lexicon/types/chat/bsky/convo/defs.js +7 -7
  24. package/dist/lexicon/types/chat/bsky/convo/defs.js.map +1 -1
  25. package/dist/lexicon/types/chat/bsky/convo/sendMessage.d.ts +1 -1
  26. package/dist/lexicon/types/chat/bsky/convo/sendMessage.d.ts.map +1 -1
  27. package/dist/lexicon/types/chat/bsky/convo/sendMessageBatch.d.ts +1 -1
  28. package/dist/lexicon/types/chat/bsky/convo/sendMessageBatch.d.ts.map +1 -1
  29. package/dist/lexicon/types/chat/bsky/moderation/getMessageContext.d.ts +2 -0
  30. package/dist/lexicon/types/chat/bsky/moderation/getMessageContext.d.ts.map +1 -1
  31. package/dist/lexicon/types/tools/ozone/moderation/defs.d.ts +2 -1
  32. package/dist/lexicon/types/tools/ozone/moderation/defs.d.ts.map +1 -1
  33. package/dist/lexicon/types/tools/ozone/moderation/defs.js.map +1 -1
  34. package/dist/pipethrough.d.ts +2 -0
  35. package/dist/pipethrough.d.ts.map +1 -1
  36. package/dist/pipethrough.js +12 -1
  37. package/dist/pipethrough.js.map +1 -1
  38. package/package.json +4 -4
  39. package/src/actor-store/blob/reader.ts +13 -4
  40. package/src/api/chat/index.ts +90 -0
  41. package/src/api/com/atproto/repo/putRecord.ts +34 -1
  42. package/src/api/index.ts +2 -0
  43. package/src/index.ts +1 -1
  44. package/src/lexicon/lexicons.ts +14 -7
  45. package/src/lexicon/types/chat/bsky/convo/defs.ts +6 -6
  46. package/src/lexicon/types/chat/bsky/convo/sendMessage.ts +1 -1
  47. package/src/lexicon/types/chat/bsky/convo/sendMessageBatch.ts +1 -1
  48. package/src/lexicon/types/chat/bsky/moderation/getMessageContext.ts +2 -0
  49. package/src/lexicon/types/tools/ozone/moderation/defs.ts +2 -0
  50. package/src/pipethrough.ts +17 -1
  51. package/tests/crud.test.ts +30 -0
  52. package/tests/server.test.ts +1 -1
@@ -8306,24 +8306,24 @@ export const schemaDict = {
8306
8306
  defs: {
8307
8307
  messageRef: {
8308
8308
  type: 'object',
8309
- required: ['did', 'messageId'],
8309
+ required: ['did', 'messageId', 'convoId'],
8310
8310
  properties: {
8311
8311
  did: {
8312
8312
  type: 'string',
8313
8313
  format: 'did',
8314
8314
  },
8315
+ convoId: {
8316
+ type: 'string',
8317
+ },
8315
8318
  messageId: {
8316
8319
  type: 'string',
8317
8320
  },
8318
8321
  },
8319
8322
  },
8320
- message: {
8323
+ messageInput: {
8321
8324
  type: 'object',
8322
8325
  required: ['text'],
8323
8326
  properties: {
8324
- id: {
8325
- type: 'string',
8326
- },
8327
8327
  text: {
8328
8328
  type: 'string',
8329
8329
  maxLength: 10000,
@@ -8825,7 +8825,7 @@ export const schemaDict = {
8825
8825
  },
8826
8826
  message: {
8827
8827
  type: 'ref',
8828
- ref: 'lex:chat.bsky.convo.defs#message',
8828
+ ref: 'lex:chat.bsky.convo.defs#messageInput',
8829
8829
  },
8830
8830
  },
8831
8831
  },
@@ -8854,6 +8854,7 @@ export const schemaDict = {
8854
8854
  properties: {
8855
8855
  items: {
8856
8856
  type: 'array',
8857
+ maxLength: 100,
8857
8858
  items: {
8858
8859
  type: 'ref',
8859
8860
  ref: 'lex:chat.bsky.convo.sendMessageBatch#batchItem',
@@ -8888,7 +8889,7 @@ export const schemaDict = {
8888
8889
  },
8889
8890
  message: {
8890
8891
  type: 'ref',
8891
- ref: 'lex:chat.bsky.convo.defs#message',
8892
+ ref: 'lex:chat.bsky.convo.defs#messageInput',
8892
8893
  },
8893
8894
  },
8894
8895
  },
@@ -9038,6 +9039,11 @@ export const schemaDict = {
9038
9039
  type: 'params',
9039
9040
  required: ['messageId'],
9040
9041
  properties: {
9042
+ convoId: {
9043
+ type: 'string',
9044
+ description:
9045
+ 'Conversation that the message is from. NOTE: this field will eventually be required.',
9046
+ },
9041
9047
  messageId: {
9042
9048
  type: 'string',
9043
9049
  },
@@ -9340,6 +9346,7 @@ export const schemaDict = {
9340
9346
  refs: [
9341
9347
  'lex:com.atproto.admin.defs#repoRef',
9342
9348
  'lex:com.atproto.repo.strongRef',
9349
+ 'lex:chat.bsky.convo.defs#messageRef',
9343
9350
  ],
9344
9351
  },
9345
9352
  subjectBlobCids: {
@@ -11,6 +11,7 @@ import * as ChatBskyActorDefs from '../actor/defs'
11
11
 
12
12
  export interface MessageRef {
13
13
  did: string
14
+ convoId: string
14
15
  messageId: string
15
16
  [k: string]: unknown
16
17
  }
@@ -27,8 +28,7 @@ export function validateMessageRef(v: unknown): ValidationResult {
27
28
  return lexicons.validate('chat.bsky.convo.defs#messageRef', v)
28
29
  }
29
30
 
30
- export interface Message {
31
- id?: string
31
+ export interface MessageInput {
32
32
  text: string
33
33
  /** Annotations of text (mentions, URLs, hashtags, etc) */
34
34
  facets?: AppBskyRichtextFacet.Main[]
@@ -36,16 +36,16 @@ export interface Message {
36
36
  [k: string]: unknown
37
37
  }
38
38
 
39
- export function isMessage(v: unknown): v is Message {
39
+ export function isMessageInput(v: unknown): v is MessageInput {
40
40
  return (
41
41
  isObj(v) &&
42
42
  hasProp(v, '$type') &&
43
- v.$type === 'chat.bsky.convo.defs#message'
43
+ v.$type === 'chat.bsky.convo.defs#messageInput'
44
44
  )
45
45
  }
46
46
 
47
- export function validateMessage(v: unknown): ValidationResult {
48
- return lexicons.validate('chat.bsky.convo.defs#message', v)
47
+ export function validateMessageInput(v: unknown): ValidationResult {
48
+ return lexicons.validate('chat.bsky.convo.defs#messageInput', v)
49
49
  }
50
50
 
51
51
  export interface MessageView {
@@ -13,7 +13,7 @@ export interface QueryParams {}
13
13
 
14
14
  export interface InputSchema {
15
15
  convoId: string
16
- message: ChatBskyConvoDefs.Message
16
+ message: ChatBskyConvoDefs.MessageInput
17
17
  [k: string]: unknown
18
18
  }
19
19
 
@@ -51,7 +51,7 @@ export type Handler<HA extends HandlerAuth = never> = (
51
51
 
52
52
  export interface BatchItem {
53
53
  convoId: string
54
- message: ChatBskyConvoDefs.Message
54
+ message: ChatBskyConvoDefs.MessageInput
55
55
  [k: string]: unknown
56
56
  }
57
57
 
@@ -10,6 +10,8 @@ import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server'
10
10
  import * as ChatBskyConvoDefs from '../convo/defs'
11
11
 
12
12
  export interface QueryParams {
13
+ /** Conversation that the message is from. NOTE: this field will eventually be required. */
14
+ convoId?: string
13
15
  messageId: string
14
16
  before: number
15
17
  after: number
@@ -7,6 +7,7 @@ import { isObj, hasProp } from '../../../../util'
7
7
  import { CID } from 'multiformats/cid'
8
8
  import * as ComAtprotoAdminDefs from '../../../com/atproto/admin/defs'
9
9
  import * as ComAtprotoRepoStrongRef from '../../../com/atproto/repo/strongRef'
10
+ import * as ChatBskyConvoDefs from '../../../chat/bsky/convo/defs'
10
11
  import * as ComAtprotoModerationDefs from '../../../com/atproto/moderation/defs'
11
12
  import * as ComAtprotoServerDefs from '../../../com/atproto/server/defs'
12
13
  import * as ComAtprotoLabelDefs from '../../../com/atproto/label/defs'
@@ -32,6 +33,7 @@ export interface ModEventView {
32
33
  subject:
33
34
  | ComAtprotoAdminDefs.RepoRef
34
35
  | ComAtprotoRepoStrongRef.Main
36
+ | ChatBskyConvoDefs.MessageRef
35
37
  | { $type: string; [k: string]: unknown }
36
38
  subjectBlobCids: string[]
37
39
  createdBy: string
@@ -3,7 +3,7 @@ import * as ui8 from 'uint8arrays'
3
3
  import net from 'node:net'
4
4
  import stream from 'node:stream'
5
5
  import webStream from 'node:stream/web'
6
- import { jsonToLex } from '@atproto/lexicon'
6
+ import { LexValue, jsonToLex, stringifyLex } from '@atproto/lexicon'
7
7
  import {
8
8
  CatchallHandler,
9
9
  HandlerPipeThrough,
@@ -45,6 +45,22 @@ export const pipethrough = async (
45
45
  return parseProxyRes(res)
46
46
  }
47
47
 
48
+ export const pipethroughProcedure = async (
49
+ ctx: AppContext,
50
+ req: express.Request,
51
+ requester: string | null,
52
+ body?: LexValue,
53
+ ): Promise<HandlerPipeThrough> => {
54
+ const { url, aud } = await formatUrlAndAud(ctx, req)
55
+ const headers = await formatHeaders(ctx, req, aud, requester)
56
+ const encodedBody = body
57
+ ? new TextEncoder().encode(stringifyLex(body))
58
+ : undefined
59
+ const reqInit = formatReqInit(req, headers, encodedBody)
60
+ const res = await makeRequest(url, reqInit)
61
+ return parseProxyRes(res)
62
+ }
63
+
48
64
  // Request setup/formatting
49
65
  // -------------------
50
66
 
@@ -517,6 +517,36 @@ describe('crud operations', () => {
517
517
  description: 'Dog lover',
518
518
  })
519
519
  })
520
+
521
+ // @TODO remove after migrating legacy blobs
522
+ it('updates a legacy blob ref when updating profile', async () => {
523
+ const { repo } = bobAgent.api.com.atproto
524
+ const file = await fs.readFile(
525
+ '../dev-env/src/seed/img/key-portrait-small.jpg',
526
+ )
527
+ const uploadedRes = await repo.uploadBlob(file, {
528
+ encoding: 'image/jpeg',
529
+ })
530
+
531
+ await repo.putRecord({
532
+ ...profilePath,
533
+ repo: bob.did,
534
+ record: {
535
+ displayName: 'Robert',
536
+ avatar: BlobRef.fromJsonRef({
537
+ mimeType: uploadedRes.data.blob.mimeType,
538
+ cid: uploadedRes.data.blob.ref.toString(),
539
+ }),
540
+ },
541
+ })
542
+
543
+ const got = await repo.getRecord({
544
+ ...profilePath,
545
+ repo: bob.did,
546
+ })
547
+ const gotAvatar = got.data.value['avatar'] as BlobRef
548
+ expect(gotAvatar.original).toEqual(uploadedRes.data.blob.original)
549
+ })
520
550
  })
521
551
 
522
552
  // Validation
@@ -64,7 +64,7 @@ describe('server', () => {
64
64
  await axios.post(
65
65
  `${network.pds.url}/xrpc/com.atproto.repo.createRecord`,
66
66
  {
67
- data: 'x'.repeat(100 * 1024), // 100kb
67
+ data: 'x'.repeat(150 * 1024), // 150kb
68
68
  },
69
69
  { headers: sc.getHeaders(alice) },
70
70
  )