@atproto/pds 0.4.40 → 0.4.42

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/account-manager/index.d.ts +3 -4
  3. package/dist/account-manager/index.d.ts.map +1 -1
  4. package/dist/account-manager/index.js +2 -3
  5. package/dist/account-manager/index.js.map +1 -1
  6. package/dist/auth-verifier.d.ts.map +1 -1
  7. package/dist/auth-verifier.js +11 -9
  8. package/dist/auth-verifier.js.map +1 -1
  9. package/dist/config/config.d.ts.map +1 -1
  10. package/dist/config/config.js +2 -1
  11. package/dist/config/config.js.map +1 -1
  12. package/dist/config/env.d.ts +2 -1
  13. package/dist/config/env.d.ts.map +1 -1
  14. package/dist/config/env.js +2 -1
  15. package/dist/config/env.js.map +1 -1
  16. package/dist/lexicon/index.d.ts +2 -0
  17. package/dist/lexicon/index.d.ts.map +1 -1
  18. package/dist/lexicon/index.js +4 -0
  19. package/dist/lexicon/index.js.map +1 -1
  20. package/dist/lexicon/lexicons.d.ts +32 -0
  21. package/dist/lexicon/lexicons.d.ts.map +1 -1
  22. package/dist/lexicon/lexicons.js +32 -0
  23. package/dist/lexicon/lexicons.js.map +1 -1
  24. package/dist/lexicon/types/app/bsky/notification/getUnreadCount.d.ts +1 -0
  25. package/dist/lexicon/types/app/bsky/notification/getUnreadCount.d.ts.map +1 -1
  26. package/dist/lexicon/types/app/bsky/notification/listNotifications.d.ts +2 -0
  27. package/dist/lexicon/types/app/bsky/notification/listNotifications.d.ts.map +1 -1
  28. package/dist/lexicon/types/app/bsky/notification/listNotifications.js.map +1 -1
  29. package/dist/lexicon/types/app/bsky/notification/putPreferences.d.ts +29 -0
  30. package/dist/lexicon/types/app/bsky/notification/putPreferences.d.ts.map +1 -0
  31. package/dist/lexicon/types/app/bsky/notification/putPreferences.js +3 -0
  32. package/dist/lexicon/types/app/bsky/notification/putPreferences.js.map +1 -0
  33. package/dist/logger.d.ts +3 -1
  34. package/dist/logger.d.ts.map +1 -1
  35. package/dist/logger.js +9 -76
  36. package/dist/logger.js.map +1 -1
  37. package/dist/oauth/detailed-account-store.d.ts +2 -2
  38. package/dist/oauth/detailed-account-store.d.ts.map +1 -1
  39. package/dist/oauth/detailed-account-store.js.map +1 -1
  40. package/package.json +9 -9
  41. package/src/account-manager/index.ts +4 -5
  42. package/src/auth-verifier.ts +18 -9
  43. package/src/config/config.ts +2 -1
  44. package/src/config/env.ts +4 -2
  45. package/src/lexicon/index.ts +12 -0
  46. package/src/lexicon/lexicons.ts +33 -0
  47. package/src/lexicon/types/app/bsky/notification/getUnreadCount.ts +1 -0
  48. package/src/lexicon/types/app/bsky/notification/listNotifications.ts +2 -0
  49. package/src/lexicon/types/app/bsky/notification/putPreferences.ts +38 -0
  50. package/src/logger.ts +11 -81
  51. package/src/oauth/detailed-account-store.ts +2 -2
package/src/logger.ts CHANGED
@@ -1,6 +1,7 @@
1
+ import { type IncomingMessage } from 'node:http'
1
2
  import { stdSerializers } from 'pino'
2
3
  import pinoHttp from 'pino-http'
3
- import { subsystemLogger } from '@atproto/common'
4
+ import { obfuscateHeaders, subsystemLogger } from '@atproto/common'
4
5
 
5
6
  export const dbLogger = subsystemLogger('pds:db')
6
7
  export const didCacheLogger = subsystemLogger('pds:did-cache')
@@ -17,85 +18,14 @@ export const oauthLogger = subsystemLogger('pds:oauth')
17
18
  export const loggerMiddleware = pinoHttp({
18
19
  logger: httpLogger,
19
20
  serializers: {
20
- err: errSerializer,
21
- req: reqSerializer,
21
+ err: (err: unknown) => ({
22
+ code: err?.['code'],
23
+ message: err?.['message'],
24
+ }),
25
+ req: (req: IncomingMessage) => {
26
+ const serialized = stdSerializers.req(req)
27
+ const headers = obfuscateHeaders(serialized.headers)
28
+ return { ...serialized, headers }
29
+ },
22
30
  },
23
31
  })
24
-
25
- function errSerializer(err: any) {
26
- return {
27
- code: err?.code,
28
- message: err?.message,
29
- }
30
- }
31
-
32
- function reqSerializer(req: any) {
33
- const serialized = stdSerializers.req(req)
34
- serialized.headers = obfuscateHeaders(serialized.headers)
35
- return serialized
36
- }
37
-
38
- function obfuscateHeaders(headers: Record<string, string>) {
39
- const obfuscatedHeaders: Record<string, string> = {}
40
- for (const key in headers) {
41
- if (key.toLowerCase() === 'authorization') {
42
- obfuscatedHeaders[key] = obfuscateAuthHeader(headers[key])
43
- } else if (key.toLowerCase() === 'dpop') {
44
- obfuscatedHeaders[key] = obfuscateJws(headers[key]) || 'Invalid'
45
- } else {
46
- obfuscatedHeaders[key] = headers[key]
47
- }
48
- }
49
- return obfuscatedHeaders
50
- }
51
-
52
- function obfuscateAuthHeader(authHeader: string): string {
53
- // This is a hot path (runs on every request). Avoid using split() or regex.
54
-
55
- const spaceIdx = authHeader.indexOf(' ')
56
- if (spaceIdx === -1) return 'Invalid'
57
-
58
- const type = authHeader.slice(0, spaceIdx)
59
- switch (type.toLowerCase()) {
60
- case 'bearer':
61
- return `${type} ${obfuscateBearer(authHeader.slice(spaceIdx + 1))}`
62
- case 'dpop':
63
- return `${type} ${obfuscateJws(authHeader.slice(spaceIdx + 1)) || 'Invalid'}`
64
- case 'basic':
65
- return `${type} ${obfuscateBasic(authHeader.slice(spaceIdx + 1)) || 'Invalid'}`
66
- default:
67
- return `Invalid`
68
- }
69
- }
70
-
71
- function obfuscateBasic(token: string): null | string {
72
- if (!token) return null
73
- const buffer = Buffer.from(token, 'base64')
74
- if (!buffer.length) return null // Buffer.from will silently ignore invalid base64 chars
75
- const authHeader = buffer.toString('utf8')
76
- const colIdx = authHeader.indexOf(':')
77
- if (colIdx === -1) return null
78
- const username = authHeader.slice(0, colIdx)
79
- return `${username}:***`
80
- }
81
-
82
- function obfuscateBearer(token: string): string {
83
- return obfuscateJws(token) || obfuscateToken(token)
84
- }
85
-
86
- function obfuscateToken(token: string): string {
87
- return token ? '***' : ''
88
- }
89
-
90
- function obfuscateJws(token: string): null | string {
91
- const firstDot = token.indexOf('.')
92
- if (firstDot === -1) return null
93
-
94
- const secondDot = token.indexOf('.', firstDot + 1)
95
- if (secondDot === -1) return null
96
-
97
- if (token.indexOf('.', secondDot + 1) !== -1) return null
98
-
99
- // Strip the signature
100
- return token.slice(0, secondDot) + '.obfuscated'
101
- }
@@ -2,7 +2,7 @@ import {
2
2
  AccountInfo,
3
3
  AccountStore,
4
4
  DeviceId,
5
- LoginCredentials,
5
+ SignInCredentials,
6
6
  } from '@atproto/oauth-provider'
7
7
 
8
8
  import { AccountManager } from '../account-manager/index'
@@ -50,7 +50,7 @@ export class DetailedAccountStore implements AccountStore {
50
50
  }
51
51
 
52
52
  async authenticateAccount(
53
- credentials: LoginCredentials,
53
+ credentials: SignInCredentials,
54
54
  deviceId: DeviceId,
55
55
  ): Promise<AccountInfo | null> {
56
56
  const accountInfo = await this.accountManager.authenticateAccount(