@atproto/api 0.18.8 → 0.18.9

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 (31) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/atp-agent.d.ts +8 -2
  3. package/dist/atp-agent.d.ts.map +1 -1
  4. package/dist/atp-agent.js +115 -80
  5. package/dist/atp-agent.js.map +1 -1
  6. package/dist/client/index.d.ts.map +1 -1
  7. package/dist/client/index.js +6 -1
  8. package/dist/client/index.js.map +1 -1
  9. package/dist/client/lexicons.d.ts +44 -8
  10. package/dist/client/lexicons.d.ts.map +1 -1
  11. package/dist/client/lexicons.js +27 -4
  12. package/dist/client/lexicons.js.map +1 -1
  13. package/dist/client/types/com/atproto/server/deleteSession.d.ts +7 -1
  14. package/dist/client/types/com/atproto/server/deleteSession.d.ts.map +1 -1
  15. package/dist/client/types/com/atproto/server/deleteSession.js +23 -0
  16. package/dist/client/types/com/atproto/server/deleteSession.js.map +1 -1
  17. package/dist/client/types/com/atproto/server/getSession.d.ts +3 -3
  18. package/dist/client/types/com/atproto/server/getSession.d.ts.map +1 -1
  19. package/dist/client/types/com/atproto/server/getSession.js.map +1 -1
  20. package/dist/client/types/com/atproto/server/refreshSession.d.ts +9 -0
  21. package/dist/client/types/com/atproto/server/refreshSession.d.ts.map +1 -1
  22. package/dist/client/types/com/atproto/server/refreshSession.js +17 -1
  23. package/dist/client/types/com/atproto/server/refreshSession.js.map +1 -1
  24. package/package.json +2 -2
  25. package/src/atp-agent.ts +147 -99
  26. package/src/client/index.ts +5 -6
  27. package/src/client/lexicons.ts +28 -4
  28. package/src/client/types/com/atproto/server/deleteSession.ts +17 -0
  29. package/src/client/types/com/atproto/server/getSession.ts +1 -1
  30. package/src/client/types/com/atproto/server/refreshSession.ts +17 -0
  31. package/tests/dispatcher.test.ts +13 -10
@@ -24,6 +24,9 @@ export interface OutputSchema {
24
24
  handle: string
25
25
  did: string
26
26
  didDoc?: { [_ in string]: unknown }
27
+ email?: string
28
+ emailConfirmed?: boolean
29
+ emailAuthFactor?: boolean
27
30
  active?: boolean
28
31
  /** Hosting status of the account. If not specified, then assume 'active'. */
29
32
  status?: 'takendown' | 'suspended' | 'deactivated' | (string & {})
@@ -47,9 +50,23 @@ export class AccountTakedownError extends XRPCError {
47
50
  }
48
51
  }
49
52
 
53
+ export class InvalidTokenError extends XRPCError {
54
+ constructor(src: XRPCError) {
55
+ super(src.status, src.error, src.message, src.headers, { cause: src })
56
+ }
57
+ }
58
+
59
+ export class ExpiredTokenError extends XRPCError {
60
+ constructor(src: XRPCError) {
61
+ super(src.status, src.error, src.message, src.headers, { cause: src })
62
+ }
63
+ }
64
+
50
65
  export function toKnownErr(e: any) {
51
66
  if (e instanceof XRPCError) {
52
67
  if (e.error === 'AccountTakedown') return new AccountTakedownError(e)
68
+ if (e.error === 'InvalidToken') return new InvalidTokenError(e)
69
+ if (e.error === 'ExpiredToken') return new ExpiredTokenError(e)
53
70
  }
54
71
 
55
72
  return e
@@ -355,12 +355,13 @@ describe('AtpAgent', () => {
355
355
  expect(typeof sessions[1]).toEqual('undefined')
356
356
  })
357
357
 
358
- it('does not modify or persist the session on a failed refresh', async () => {
359
- const events: string[] = []
360
- const sessions: (AtpSessionData | undefined)[] = []
361
- const persistSession = (evt: AtpSessionEvent, sess?: AtpSessionData) => {
362
- events.push(evt)
363
- sessions.push(sess)
358
+ it('does not modify the session on a failed refresh', async () => {
359
+ const events: { event: string; session: AtpSessionData | undefined }[] = []
360
+ const persistSession = (
361
+ event: AtpSessionEvent,
362
+ session?: AtpSessionData,
363
+ ) => {
364
+ events.push({ event, session: session && { ...session } })
364
365
  }
365
366
 
366
367
  const agent = new AtpAgent({ service: network.pds.url, persistSession })
@@ -407,10 +408,12 @@ describe('AtpAgent', () => {
407
408
  // still has session because it wasn't invalidated
408
409
  expect(agent.hasSession).toEqual(true)
409
410
 
410
- expect(events.length).toEqual(1)
411
- expect(events[0]).toEqual('create')
412
- expect(sessions.length).toEqual(1)
413
- expect(sessions[0]?.accessJwt).toEqual(origAccessJwt)
411
+ expect(events.length).toEqual(2)
412
+
413
+ expect(events[0].event).toEqual('create')
414
+ expect(events[0].session?.accessJwt).toEqual(origAccessJwt)
415
+ expect(events[1].event).toEqual('network-error')
416
+ expect(events[1].session?.accessJwt).toEqual(origAccessJwt)
414
417
  })
415
418
 
416
419
  describe('createAccount', () => {