@flipstream/sdk 0.13.0 → 0.15.0

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 (278) hide show
  1. package/CHANGELOG.md +120 -0
  2. package/README.md +143 -21
  3. package/dist/api/backend.d.ts +7 -0
  4. package/dist/api/backend.js +7 -0
  5. package/dist/api/backend.js.map +1 -1
  6. package/dist/api/credentials.js +4 -4
  7. package/dist/api/credentials.js.map +1 -1
  8. package/dist/api/datasets.js +30 -50
  9. package/dist/api/datasets.js.map +1 -1
  10. package/dist/api/handoff.d.ts +1 -1
  11. package/dist/api/handoff.js +7 -0
  12. package/dist/api/handoff.js.map +1 -1
  13. package/dist/api/log.d.ts +4 -4
  14. package/dist/api/log.js +23 -42
  15. package/dist/api/log.js.map +1 -1
  16. package/dist/api/me.d.ts +5 -3
  17. package/dist/api/me.js +3 -3
  18. package/dist/api/me.js.map +1 -1
  19. package/dist/api/members.d.ts +40 -17
  20. package/dist/api/members.js +66 -29
  21. package/dist/api/members.js.map +1 -1
  22. package/dist/api/ownRecord.d.ts +46 -0
  23. package/dist/api/ownRecord.js +57 -0
  24. package/dist/api/ownRecord.js.map +1 -0
  25. package/dist/api/refusal.d.ts +14 -0
  26. package/dist/api/refusal.js +23 -0
  27. package/dist/api/refusal.js.map +1 -0
  28. package/dist/api/wallet.d.ts +2 -1
  29. package/dist/api/wallet.js +18 -24
  30. package/dist/api/wallet.js.map +1 -1
  31. package/dist/api/workspaces.d.ts +7 -2
  32. package/dist/api/workspaces.js +14 -8
  33. package/dist/api/workspaces.js.map +1 -1
  34. package/dist/auth/discovery.js +4 -5
  35. package/dist/auth/discovery.js.map +1 -1
  36. package/dist/auth/transport.d.ts +6 -2
  37. package/dist/auth/transport.js +5 -3
  38. package/dist/auth/transport.js.map +1 -1
  39. package/dist/core/call.d.ts +9 -4
  40. package/dist/core/call.js +12 -8
  41. package/dist/core/call.js.map +1 -1
  42. package/dist/core/fetch.d.ts +20 -1
  43. package/dist/core/fetch.js +50 -3
  44. package/dist/core/fetch.js.map +1 -1
  45. package/dist/core/hosts.d.ts +11 -0
  46. package/dist/core/hosts.js +13 -0
  47. package/dist/core/hosts.js.map +1 -0
  48. package/dist/core/identify.d.ts +12 -2
  49. package/dist/core/identify.js +31 -19
  50. package/dist/core/identify.js.map +1 -1
  51. package/dist/core/inPlaceOf.d.ts +6 -0
  52. package/dist/core/inPlaceOf.js +17 -0
  53. package/dist/core/inPlaceOf.js.map +1 -0
  54. package/dist/core/invalid.d.ts +32 -9
  55. package/dist/core/invalid.js +36 -23
  56. package/dist/core/invalid.js.map +1 -1
  57. package/dist/core/notFound.d.ts +2 -2
  58. package/dist/core/notFound.js.map +1 -1
  59. package/dist/core/read.d.ts +4 -10
  60. package/dist/core/read.js +1 -11
  61. package/dist/core/read.js.map +1 -1
  62. package/dist/core/result.d.ts +14 -10
  63. package/dist/core/result.js +1 -0
  64. package/dist/core/result.js.map +1 -1
  65. package/dist/core/shared.d.ts +15 -9
  66. package/dist/core/shared.js +8 -6
  67. package/dist/core/shared.js.map +1 -1
  68. package/dist/core/signal.d.ts +7 -0
  69. package/dist/core/signal.js +9 -0
  70. package/dist/core/signal.js.map +1 -1
  71. package/dist/first-party/asPerson.d.ts +13 -0
  72. package/dist/first-party/asPerson.js +144 -0
  73. package/dist/first-party/asPerson.js.map +1 -0
  74. package/dist/first-party/attempts.d.ts +71 -0
  75. package/dist/first-party/attempts.js +132 -0
  76. package/dist/first-party/attempts.js.map +1 -0
  77. package/dist/first-party/authProxyMark.d.ts +7 -0
  78. package/dist/first-party/authProxyMark.js +8 -0
  79. package/dist/first-party/authProxyMark.js.map +1 -0
  80. package/dist/first-party/browser.d.ts +55 -0
  81. package/dist/first-party/browser.js +137 -0
  82. package/dist/first-party/browser.js.map +1 -0
  83. package/dist/first-party/browserSession.d.ts +95 -0
  84. package/dist/first-party/browserSession.js +242 -0
  85. package/dist/first-party/browserSession.js.map +1 -0
  86. package/dist/first-party/calls/consent.d.ts +77 -0
  87. package/dist/first-party/calls/consent.js +174 -0
  88. package/dist/first-party/calls/consent.js.map +1 -0
  89. package/dist/first-party/calls/device.d.ts +75 -0
  90. package/dist/first-party/calls/device.js +133 -0
  91. package/dist/first-party/calls/device.js.map +1 -0
  92. package/dist/first-party/calls/invitation.d.ts +198 -0
  93. package/dist/first-party/calls/invitation.js +240 -0
  94. package/dist/first-party/calls/invitation.js.map +1 -0
  95. package/dist/first-party/calls/logIn.d.ts +41 -0
  96. package/dist/first-party/calls/logIn.js +48 -0
  97. package/dist/first-party/calls/logIn.js.map +1 -0
  98. package/dist/first-party/calls/reset.d.ts +58 -0
  99. package/dist/first-party/calls/reset.js +163 -0
  100. package/dist/first-party/calls/reset.js.map +1 -0
  101. package/dist/first-party/calls/signUp.d.ts +21 -0
  102. package/dist/first-party/calls/signUp.js +72 -0
  103. package/dist/first-party/calls/signUp.js.map +1 -0
  104. package/dist/first-party/calls/twoStepSetup.d.ts +55 -0
  105. package/dist/first-party/calls/twoStepSetup.js +168 -0
  106. package/dist/first-party/calls/twoStepSetup.js.map +1 -0
  107. package/dist/first-party/claims.d.ts +88 -0
  108. package/dist/first-party/claims.js +181 -0
  109. package/dist/first-party/claims.js.map +1 -0
  110. package/dist/first-party/enrollment.d.ts +10 -0
  111. package/dist/first-party/enrollment.js +44 -0
  112. package/dist/first-party/enrollment.js.map +1 -0
  113. package/dist/first-party/entry.d.ts +549 -0
  114. package/dist/first-party/entry.js +580 -0
  115. package/dist/first-party/entry.js.map +1 -0
  116. package/dist/first-party/hooks.d.ts +66 -0
  117. package/dist/first-party/hooks.js +19 -0
  118. package/dist/first-party/hooks.js.map +1 -0
  119. package/dist/first-party/http.d.ts +191 -0
  120. package/dist/first-party/http.js +364 -0
  121. package/dist/first-party/http.js.map +1 -0
  122. package/dist/first-party/index.d.ts +14 -0
  123. package/dist/first-party/index.js +3 -0
  124. package/dist/first-party/index.js.map +1 -0
  125. package/dist/first-party/landed.d.ts +32 -0
  126. package/dist/first-party/landed.js +50 -0
  127. package/dist/first-party/landed.js.map +1 -0
  128. package/dist/first-party/landedProof.d.ts +12 -0
  129. package/dist/first-party/landedProof.js +20 -0
  130. package/dist/first-party/landedProof.js.map +1 -0
  131. package/dist/first-party/linkToken.d.ts +16 -0
  132. package/dist/first-party/linkToken.js +29 -0
  133. package/dist/first-party/linkToken.js.map +1 -0
  134. package/dist/first-party/links.d.ts +100 -0
  135. package/dist/first-party/links.js +84 -0
  136. package/dist/first-party/links.js.map +1 -0
  137. package/dist/first-party/locks.d.ts +36 -0
  138. package/dist/first-party/locks.js +64 -0
  139. package/dist/first-party/locks.js.map +1 -0
  140. package/dist/first-party/personTransport.d.ts +38 -0
  141. package/dist/first-party/personTransport.js +177 -0
  142. package/dist/first-party/personTransport.js.map +1 -0
  143. package/dist/first-party/proxy/app.d.ts +25 -0
  144. package/dist/first-party/proxy/app.js +94 -0
  145. package/dist/first-party/proxy/app.js.map +1 -0
  146. package/dist/first-party/proxy/bound.d.ts +5 -0
  147. package/dist/first-party/proxy/bound.js +13 -0
  148. package/dist/first-party/proxy/bound.js.map +1 -0
  149. package/dist/first-party/proxy/cases.d.ts +54 -0
  150. package/dist/first-party/proxy/cases.js +412 -0
  151. package/dist/first-party/proxy/cases.js.map +1 -0
  152. package/dist/first-party/proxy/decide.d.ts +29 -0
  153. package/dist/first-party/proxy/decide.js +140 -0
  154. package/dist/first-party/proxy/decide.js.map +1 -0
  155. package/dist/first-party/proxy/freeze.d.ts +2 -0
  156. package/dist/first-party/proxy/freeze.js +10 -0
  157. package/dist/first-party/proxy/freeze.js.map +1 -0
  158. package/dist/first-party/proxy/handler.d.ts +23 -0
  159. package/dist/first-party/proxy/handler.js +190 -0
  160. package/dist/first-party/proxy/handler.js.map +1 -0
  161. package/dist/first-party/proxy/headers.d.ts +8 -0
  162. package/dist/first-party/proxy/headers.js +20 -0
  163. package/dist/first-party/proxy/headers.js.map +1 -0
  164. package/dist/first-party/proxy/hop.d.ts +9 -0
  165. package/dist/first-party/proxy/hop.js +37 -0
  166. package/dist/first-party/proxy/hop.js.map +1 -0
  167. package/dist/first-party/proxy/host.d.ts +5 -0
  168. package/dist/first-party/proxy/host.js +11 -0
  169. package/dist/first-party/proxy/host.js.map +1 -0
  170. package/dist/first-party/proxy/index.d.ts +7 -0
  171. package/dist/first-party/proxy/index.js +6 -0
  172. package/dist/first-party/proxy/index.js.map +1 -0
  173. package/dist/first-party/proxy/pass-back.d.ts +21 -0
  174. package/dist/first-party/proxy/pass-back.js +51 -0
  175. package/dist/first-party/proxy/pass-back.js.map +1 -0
  176. package/dist/first-party/proxy/paths.d.ts +17 -0
  177. package/dist/first-party/proxy/paths.js +36 -0
  178. package/dist/first-party/proxy/paths.js.map +1 -0
  179. package/dist/first-party/proxy/shown.d.ts +5 -0
  180. package/dist/first-party/proxy/shown.js +16 -0
  181. package/dist/first-party/proxy/shown.js.map +1 -0
  182. package/dist/first-party/proxy/stand-in.d.ts +47 -0
  183. package/dist/first-party/proxy/stand-in.js +318 -0
  184. package/dist/first-party/proxy/stand-in.js.map +1 -0
  185. package/dist/first-party/report.d.ts +47 -0
  186. package/dist/first-party/report.js +38 -0
  187. package/dist/first-party/report.js.map +1 -0
  188. package/dist/first-party/result.d.ts +82 -0
  189. package/dist/first-party/result.js +40 -0
  190. package/dist/first-party/result.js.map +1 -0
  191. package/dist/first-party/session/cell.d.ts +177 -0
  192. package/dist/first-party/session/cell.js +89 -0
  193. package/dist/first-party/session/cell.js.map +1 -0
  194. package/dist/first-party/session/closed.d.ts +8 -0
  195. package/dist/first-party/session/closed.js +12 -0
  196. package/dist/first-party/session/closed.js.map +1 -0
  197. package/dist/first-party/session/index.d.ts +3 -0
  198. package/dist/first-party/session/index.js +3 -0
  199. package/dist/first-party/session/index.js.map +1 -0
  200. package/dist/first-party/session/logout.d.ts +82 -0
  201. package/dist/first-party/session/logout.js +328 -0
  202. package/dist/first-party/session/logout.js.map +1 -0
  203. package/dist/first-party/session/owed.d.ts +30 -0
  204. package/dist/first-party/session/owed.js +27 -0
  205. package/dist/first-party/session/owed.js.map +1 -0
  206. package/dist/first-party/session/refresh.d.ts +19 -0
  207. package/dist/first-party/session/refresh.js +229 -0
  208. package/dist/first-party/session/refresh.js.map +1 -0
  209. package/dist/first-party/session/results.d.ts +38 -0
  210. package/dist/first-party/session/results.js +74 -0
  211. package/dist/first-party/session/results.js.map +1 -0
  212. package/dist/first-party/session/session.d.ts +2 -0
  213. package/dist/first-party/session/session.js +379 -0
  214. package/dist/first-party/session/session.js.map +1 -0
  215. package/dist/first-party/session/shared.d.ts +34 -0
  216. package/dist/first-party/session/shared.js +104 -0
  217. package/dist/first-party/session/shared.js.map +1 -0
  218. package/dist/first-party/session/sharedSignal.d.ts +27 -0
  219. package/dist/first-party/session/sharedSignal.js +55 -0
  220. package/dist/first-party/session/sharedSignal.js.map +1 -0
  221. package/dist/first-party/session/signIn.d.ts +43 -0
  222. package/dist/first-party/session/signIn.js +294 -0
  223. package/dist/first-party/session/signIn.js.map +1 -0
  224. package/dist/first-party/session/signInThrough.d.ts +5 -0
  225. package/dist/first-party/session/signInThrough.js +95 -0
  226. package/dist/first-party/session/signInThrough.js.map +1 -0
  227. package/dist/first-party/session/sync.d.ts +17 -0
  228. package/dist/first-party/session/sync.js +143 -0
  229. package/dist/first-party/session/sync.js.map +1 -0
  230. package/dist/first-party/session/tokens.d.ts +18 -0
  231. package/dist/first-party/session/tokens.js +64 -0
  232. package/dist/first-party/session/tokens.js.map +1 -0
  233. package/dist/first-party/session/types.d.ts +270 -0
  234. package/dist/first-party/session/types.js +3 -0
  235. package/dist/first-party/session/types.js.map +1 -0
  236. package/dist/first-party/sessionWire.d.ts +31 -0
  237. package/dist/first-party/sessionWire.js +91 -0
  238. package/dist/first-party/sessionWire.js.map +1 -0
  239. package/dist/first-party/signInHooks.d.ts +57 -0
  240. package/dist/first-party/signInHooks.js +2 -0
  241. package/dist/first-party/signInHooks.js.map +1 -0
  242. package/dist/first-party/state.d.ts +51 -0
  243. package/dist/first-party/state.js +52 -0
  244. package/dist/first-party/state.js.map +1 -0
  245. package/dist/first-party/strip.d.ts +1 -0
  246. package/dist/first-party/strip.js +8 -0
  247. package/dist/first-party/strip.js.map +1 -0
  248. package/dist/first-party/twoStepLock.d.ts +26 -0
  249. package/dist/first-party/twoStepLock.js +58 -0
  250. package/dist/first-party/twoStepLock.js.map +1 -0
  251. package/dist/first-party/twoStepSession.d.ts +21 -0
  252. package/dist/first-party/twoStepSession.js +31 -0
  253. package/dist/first-party/twoStepSession.js.map +1 -0
  254. package/dist/first-party/wire.d.ts +63 -0
  255. package/dist/first-party/wire.js +5 -0
  256. package/dist/first-party/wire.js.map +1 -0
  257. package/dist/flipstream.d.ts +132 -36
  258. package/dist/flipstream.js +94 -47
  259. package/dist/flipstream.js.map +1 -1
  260. package/dist/index.d.ts +2 -2
  261. package/dist/index.js +3 -2
  262. package/dist/index.js.map +1 -1
  263. package/dist/node/keychainChild.js +60 -25
  264. package/dist/node/keychainChild.js.map +1 -1
  265. package/dist/node/keychainError.d.ts +4 -1
  266. package/dist/node/keychainError.js.map +1 -1
  267. package/dist/node/keychainStore.js +42 -8
  268. package/dist/node/keychainStore.js.map +1 -1
  269. package/dist/node/session.js +9 -8
  270. package/dist/node/session.js.map +1 -1
  271. package/dist/query/query.d.ts +52 -8
  272. package/dist/query/query.js +133 -19
  273. package/dist/query/query.js.map +1 -1
  274. package/dist/version.gen.js +1 -1
  275. package/docs/admin.md +53 -4
  276. package/docs/first-party.md +278 -0
  277. package/docs/node-sign-in.md +8 -4
  278. package/package.json +34 -5
@@ -0,0 +1,242 @@
1
+ import { wallClock } from '../core/deadline.js';
2
+ import { keepsNoStore } from '../core/fetch.js';
3
+ import { browserChannel, browserLocks, browserStorage, subscriberErrorReporter, } from './browser.js';
4
+ import { checkLanding } from './attempts.js';
5
+ import { checkCookieCalls, createAuthHttp } from './http.js';
6
+ import { checkLink, requestLink, } from './links.js';
7
+ import { createAuthSession, } from './session/index.js';
8
+ import { SessionClosedError } from './session/closed.js';
9
+ import { owedSlot } from './session/owed.js';
10
+ import { STATE_KEY } from './state.js';
11
+ /**
12
+ * Whether a link can land on the page's own origin: only an http or https origin (scheme, host
13
+ * and port, nothing more) can. Anything else (`'null'`, what an opaque origin reads as; `file://`;
14
+ * an extension's; a string that doesn't parse) is a session nobody can sign in to. Never a
15
+ * RangeError: the origin is the page's, not an option the developer gives (SDK-D1934).
16
+ */
17
+ export function linkCanLand(origin) {
18
+ let url;
19
+ try {
20
+ url = new URL(origin);
21
+ }
22
+ catch {
23
+ return false;
24
+ }
25
+ return (url.protocol === 'https:' || url.protocol === 'http:') && url.origin === origin;
26
+ }
27
+ /**
28
+ * The browser session and its whole session beside it, credentials included: for this module's
29
+ * browser events and the tests. os's createAuthInternals, without the console's own parts.
30
+ */
31
+ export function createFirstPartyInternals(deps) {
32
+ // A wrong address fails here, where the session is made, not on a person's first click, with
33
+ // an attempt left behind (#464's round 2, finding 4).
34
+ checkLanding(deps.landing);
35
+ const opaque = !linkCanLand(deps.origin);
36
+ // A page whose origin is opaque, or not http (a sandboxed frame, a file, an extension), has no
37
+ // address a link can land on: nobody can sign in there, as in a browser without locks or storage.
38
+ const storage = opaque ? null : deps.storage;
39
+ const locks = opaque ? null : deps.locks;
40
+ // An origin the page cannot land on is not given to the cookie client. createAuthHttp throws
41
+ // on one that does not parse, and this session is the inert one instead (SDK-D1934).
42
+ const http = createAuthHttp(deps.fetch, deps.now, deps.authPath, opaque ? undefined : deps.origin);
43
+ const session = createAuthSession({
44
+ http,
45
+ locks,
46
+ storage,
47
+ channel: deps.channel,
48
+ report: deps.report,
49
+ reportError: deps.reportError,
50
+ now: deps.now,
51
+ owed: opaque ? null : deps.owed,
52
+ });
53
+ const links = {
54
+ http,
55
+ // A browser without locks is unsupported: a link mailed from it could never be redeemed here,
56
+ // so no attempt is stored and nothing is asked (the Codex read of 254279c, 1).
57
+ storage: locks === null ? null : storage,
58
+ origin: deps.origin,
59
+ landing: deps.landing,
60
+ now: deps.now,
61
+ random: deps.random,
62
+ };
63
+ let sent = null;
64
+ // The page's calls that send follow the session's close(): a closed one sends nothing.
65
+ let closed = false;
66
+ const stillOpen = (call) => {
67
+ if (closed)
68
+ throw new SessionClosedError(call);
69
+ };
70
+ // Its own object, not the session narrowed by a type: what the page holds has no credential
71
+ // to reach, whatever it does with it.
72
+ const view = {
73
+ current: () => session.current(),
74
+ subscribe: (listener) => session.subscribe(listener),
75
+ ready: () => session.ready(),
76
+ start: () => {
77
+ session.start();
78
+ },
79
+ retry: () => {
80
+ session.retry();
81
+ },
82
+ twoStepPending: () => session.twoStepPending(),
83
+ twoStepEndedByTab: () => session.twoStepEndedByTab(),
84
+ verifyTwoStep: (code, signal, onSend) => session.verifyTwoStep(code, signal, onSend),
85
+ signOut: () => session.signOut(),
86
+ sync: () => session.sync(),
87
+ stateWritten: () => session.stateWritten(),
88
+ close: () => {
89
+ closed = true;
90
+ session.close();
91
+ },
92
+ };
93
+ const browser = {
94
+ session: view,
95
+ async requestLink(email, next, signal) {
96
+ stillOpen('requestLink()');
97
+ const result = await requestLink(links, email, next, signal);
98
+ if (result.kind === 'sent')
99
+ sent = { email: result.email, next, at: deps.now() };
100
+ return result;
101
+ },
102
+ lastSent: () => sent,
103
+ checkLink: (link) => {
104
+ const check = checkLink(storage, { ...link, token: deps.linkToken }, deps.now());
105
+ if (check.kind !== 'ready')
106
+ return check;
107
+ return {
108
+ kind: 'ready',
109
+ email: check.email,
110
+ attemptId: check.attemptId,
111
+ attempt: check.attempt,
112
+ };
113
+ },
114
+ redeem: (link, signal) => {
115
+ if (closed)
116
+ return Promise.reject(new SessionClosedError('redeem()'));
117
+ const check = checkLink(storage, { token: deps.linkToken, attempt: link.attemptId, email: link.email }, deps.now());
118
+ if (check.kind !== 'ready')
119
+ return Promise.resolve({ kind: 'dead-link' });
120
+ return session.redeem(check.token, check.attemptId, signal);
121
+ },
122
+ };
123
+ return { browser, session, linkDeps: links };
124
+ }
125
+ /**
126
+ * This page's slots for an owed logout, by origin and auth path (sdk#483): a module lives as long
127
+ * as its page, so a session made after another closed (a remount, a hot reload) finds what it left.
128
+ */
129
+ const pageSlots = new Map();
130
+ function pageSlot(key) {
131
+ const known = pageSlots.get(key);
132
+ if (known !== undefined)
133
+ return known;
134
+ const slot = owedSlot();
135
+ pageSlots.set(key, slot);
136
+ return slot;
137
+ }
138
+ /**
139
+ * The real browser's edges: localStorage, Web Locks and a BroadcastChannel (either of the first
140
+ * two missing makes the session `unsupported`), with the console's names, so its tabs and the
141
+ * console's take turns; this page's fetch, the wall clock and the browser's random bytes.
142
+ * An unsupported session opens no channel. Firefox throws from the constructor when storage
143
+ * is denied, and there is then nothing to close (SDK-D1940).
144
+ */
145
+ export function browserDeps(options) {
146
+ const locks = browserLocks();
147
+ const storage = browserStorage();
148
+ return {
149
+ ...options,
150
+ owed: pageSlot(`${options.origin}${options.authPath}`),
151
+ reportError: subscriberErrorReporter(globalThis),
152
+ // A wrapper, so the browser's own fetch is called with its own `this`.
153
+ fetch: (input, init) => fetch(input, init),
154
+ locks,
155
+ storage,
156
+ channel: locks === null || storage === null ? null : browserChannel('flipstream-auth'),
157
+ now: wallClock,
158
+ random: (bytes) => crypto.getRandomValues(bytes),
159
+ };
160
+ }
161
+ /**
162
+ * The browser session in a real browser (browserDeps), and the events that keep its tabs in
163
+ * step. `start()` is the caller's, after it has subscribed.
164
+ */
165
+ export function createBrowserSession(options) {
166
+ return createBrowserInternals(options).browser;
167
+ }
168
+ /**
169
+ * `createBrowserSession`, with its whole session beside it, for the entry's hooks (#465): what
170
+ * only the families read (the set-up challenge, the signed-in address), never the page.
171
+ * `browser.session.close()` also takes the browser's events off.
172
+ */
173
+ export function createBrowserInternals(options) {
174
+ // Before anything is opened: a wrong landing must not leave a channel
175
+ // behind (SDK-D1934). A cookie path that would leave the page is checked once the page can
176
+ // take a link, still before the channel, because that is the path which opens one.
177
+ checkLanding(options.landing);
178
+ // Outside a page (a server render, a prerender, a worker), or in a page whose origin can't take
179
+ // a link (a sandboxed frame or a data: page, whose origin is null; a file; an extension): an
180
+ // unsupported session, with no channel and no listener, so nothing holds the process and nothing
181
+ // needs closing. Its storage is never read: a sandboxed frame throws on localStorage.
182
+ // So is a page whose global Request doesn't keep `cache: 'no-store'` (one with no native fetch,
183
+ // where a polyfill such as whatwg-fetch fills it in): the person's bearer requests would go where
184
+ // its HTTP cache can answer them, and such a fetch can't keep `redirect: 'manual'` either
185
+ // (SDK-D2013, SDK-D1953). The check reads `Request`, not `fetch`; the person sender asks it again
186
+ // at each send.
187
+ if (typeof window === 'undefined' || typeof document === 'undefined' || !linkCanLand(options.origin) || !keepsNoStore()) {
188
+ return createFirstPartyInternals({
189
+ ...options,
190
+ reportError: subscriberErrorReporter(globalThis),
191
+ fetch: (input, init) => fetch(input, init),
192
+ locks: null,
193
+ storage: null,
194
+ channel: null,
195
+ now: wallClock,
196
+ random: (bytes) => crypto.getRandomValues(bytes),
197
+ owed: null,
198
+ });
199
+ }
200
+ // The cookie client throws when the path would leave this page. Prove that before the
201
+ // channel is opened, so the throw leaves nothing to close (SDK-D1934).
202
+ checkCookieCalls(options.authPath, options.origin);
203
+ const { browser, session, linkDeps } = createFirstPartyInternals(browserDeps(options));
204
+ // Another tab changed the shared state: catch up at once, even if its message never comes.
205
+ const stored = (event) => {
206
+ if (event.key === STATE_KEY || event.key === null)
207
+ void session.stateWritten();
208
+ };
209
+ // A laptop waking up can hold an expired token whose timer fired late, or have missed a
210
+ // sign-out in another tab: check on the way back.
211
+ const shown = () => {
212
+ if (document.visibilityState === 'visible')
213
+ void session.getAccessToken();
214
+ };
215
+ // Back online: don't wait out the backoff, and send a logout still owed.
216
+ const online = () => {
217
+ if (session.current().status === 'unavailable')
218
+ session.retry();
219
+ else
220
+ void session.sync();
221
+ };
222
+ window.addEventListener('storage', stored);
223
+ document.addEventListener('visibilitychange', shown);
224
+ window.addEventListener('online', online);
225
+ return {
226
+ session,
227
+ linkDeps,
228
+ browser: {
229
+ ...browser,
230
+ session: {
231
+ ...browser.session,
232
+ close: () => {
233
+ window.removeEventListener('storage', stored);
234
+ document.removeEventListener('visibilitychange', shown);
235
+ window.removeEventListener('online', online);
236
+ browser.session.close();
237
+ },
238
+ },
239
+ },
240
+ };
241
+ }
242
+ //# sourceMappingURL=browserSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browserSession.js","sourceRoot":"","sources":["../../src/first-party/browserSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EACL,cAAc,EACd,YAAY,EACZ,cAAc,EACd,uBAAuB,GAIxB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE5D,OAAO,EACL,SAAS,EACT,WAAW,GAIZ,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,iBAAiB,GAIlB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAE,QAAQ,EAAiB,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AA6DtC;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,IAAI,GAAQ,CAAA;IACZ,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAA;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,CAAA;AACzF,CAAC;AAED;;;GAGG;AACH,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,CAAA;oBAC5C,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;gBACzB,CAAC;aACF;SACF;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,77 @@
1
+ import { type AsPerson, type CallOptions, type Result } from '../result.js';
2
+ import { type Wire, type WireAnswer, type WireRequest } from '../wire.js';
3
+ /**
4
+ * Read from the page's own address, with nothing sent. To keep a request across a sign-in, pass
5
+ * the consent page's own path and query as `next` to `requestLink`: Confirm then lands back here
6
+ * and this reads the address again. There is no second mechanism.
7
+ */
8
+ export type ConsentRequest = {
9
+ readonly kind: 'asking';
10
+ readonly client_id: string;
11
+ /**
12
+ * The host of `redirect_uri`, worked out by the SDK: `URL.host`, so with its port when that
13
+ * isn't the scheme's own (`localhost:5173`). The approval verifies it (AFE-D31). The SDK also
14
+ * refuses an answer whose `redirect_to` doesn't have `redirect_uri`'s origin and path.
15
+ */
16
+ readonly redirect_host: string;
17
+ readonly scopes: readonly string[];
18
+ }
19
+ /** The address holds no authorize request, or one that can't be read. */
20
+ | {
21
+ readonly kind: 'invalid';
22
+ };
23
+ /** The request this session showed, which the page can pass back to approve or deny. */
24
+ export type AskingConsent = Extract<ConsentRequest, {
25
+ readonly kind: 'asking';
26
+ }>;
27
+ /** What can stop an approval or a denial. */
28
+ export type ConsentStop = AsPerson
29
+ /** pulse-auth cannot identify the app, resolve its metadata, or match its registered return address. */
30
+ | {
31
+ readonly kind: 'unknown_client';
32
+ }
33
+ /** A scope this app may not ask for. */
34
+ | {
35
+ readonly kind: 'invalid_scope';
36
+ }
37
+ /** A resource pulse-auth will not issue a token for. */
38
+ | {
39
+ readonly kind: 'invalid_target';
40
+ }
41
+ /**
42
+ * A press is pending or may already have answered this request. Once it settles, the page can try
43
+ * again if nothing was sent, or after a 429, which arrives as `unavailable`, or after
44
+ * `unknown_client`, `invalid_scope` or `invalid_target`.
45
+ * Approval renews once on `login_required`. If its retry never goes out or again gets `login_required`,
46
+ * the request is available again. If a sent press ends as `unavailable`, `signed_out` or `aborted`
47
+ * and may have acted, another press returns `answered`. Reload or sign in again to make a fresh press.
48
+ */
49
+ | {
50
+ readonly kind: 'answered';
51
+ };
52
+ interface ConsentCalls {
53
+ readonly consentRequest: () => ConsentRequest;
54
+ /** `redirect_to`: where the browser goes next, the app's own return address with its code. */
55
+ readonly approveConsent: (request: AskingConsent, options?: CallOptions) => Promise<Result<{
56
+ readonly redirect_to: string;
57
+ }, ConsentStop>>;
58
+ /** `redirect_to` carries the refusal back to the app. */
59
+ readonly denyConsent: (request: AskingConsent, options?: CallOptions) => Promise<Result<{
60
+ readonly redirect_to: string;
61
+ }, ConsentStop>>;
62
+ }
63
+ interface AuthorizeFields {
64
+ readonly client_id: string;
65
+ readonly redirect_uri: string;
66
+ readonly scope: string;
67
+ readonly state?: string;
68
+ readonly code_challenge?: string;
69
+ readonly code_challenge_method?: string;
70
+ readonly resource?: string;
71
+ }
72
+ type ConsentResult = Awaited<ReturnType<ConsentCalls['approveConsent']>>;
73
+ export declare function readConsentRequest(href: string): ConsentRequest;
74
+ export declare function consentPost(fields: AuthorizeFields, consent: boolean): WireRequest;
75
+ export declare function readConsentAnswer(answer: WireAnswer, fields: AuthorizeFields, consent: boolean): ConsentResult;
76
+ export declare function createConsentCalls(wire: Wire, href: () => string, shownRevision: () => number | 'signed_out' | undefined): ConsentCalls;
77
+ export {};
@@ -0,0 +1,174 @@
1
+ import { z } from 'zod';
2
+ import { checkSignal } from '../../core/signal.js';
3
+ import { emptyFields, ok, stopped } from '../result.js';
4
+ import { isUnavailable } from '../wire.js';
5
+ const PATH = '/oauth/authorize';
6
+ function absoluteUrl(value) {
7
+ try {
8
+ return new URL(value);
9
+ }
10
+ catch {
11
+ return null;
12
+ }
13
+ }
14
+ // oauth_internal/__init__.py:1931-1983. Only the callback itself identifies the host on screen.
15
+ function readAddress(href) {
16
+ const page = absoluteUrl(href);
17
+ if (page === null)
18
+ return null;
19
+ const query = page.searchParams;
20
+ const client_id = query.get('client_id') ?? '';
21
+ const redirect_uri = query.get('redirect_uri') ?? '';
22
+ const scope = query.get('scope') ?? '';
23
+ if (emptyFields({ client_id, redirect_uri, scope }, ['client_id', 'redirect_uri', 'scope']).length > 0)
24
+ return null;
25
+ // Check the raw authority before URL normalizes whitespace, slashes or empty userinfo.
26
+ const authority = /^https?:\/\/([^/?#]+)/i.exec(redirect_uri)?.[1];
27
+ if (!authority || authority.includes('@') || /[\\\s\p{Cc}]/u.test(redirect_uri))
28
+ return null;
29
+ const redirect = absoluteUrl(redirect_uri);
30
+ if (redirect === null || (redirect.protocol !== 'https:' && redirect.protocol !== 'http:') || redirect_uri.includes('#'))
31
+ return null;
32
+ const optional = {};
33
+ for (const key of ['state', 'code_challenge', 'code_challenge_method', 'resource']) {
34
+ const value = query.get(key);
35
+ if (value !== null)
36
+ optional[key] = value;
37
+ }
38
+ return {
39
+ request: Object.freeze({ kind: 'asking', client_id, redirect_host: redirect.host, scopes: Object.freeze(scope.split(' ').filter(Boolean)) }),
40
+ fields: { client_id, redirect_uri, scope, ...optional },
41
+ };
42
+ }
43
+ const invalidRequest = Object.freeze({ kind: 'invalid' });
44
+ export function readConsentRequest(href) {
45
+ return readAddress(href)?.request ?? invalidRequest;
46
+ }
47
+ // oauth/ingress/fastapi/__init__.py:315-331, 689-716. Both presses send consent explicitly.
48
+ export function consentPost(fields, consent) {
49
+ return { method: 'POST', path: PATH, body: { ...fields, consent } };
50
+ }
51
+ const Redirect = z.object({ redirect_url: z.string() });
52
+ const UnknownClient = z.object({ error: z.enum(['invalid_request', 'invalid_client']) });
53
+ export function readConsentAnswer(answer, fields, consent) {
54
+ // oauth_internal/__init__.py:587-596 checks the client and its registered callback.
55
+ if (answer.status === 400 && UnknownClient.safeParse(answer.body).success)
56
+ return stopped({ kind: 'unknown_client' });
57
+ if (isUnavailable(answer))
58
+ return stopped({ kind: 'unavailable' });
59
+ const invalid = stopped({ kind: 'invalid' });
60
+ if (answer.status !== 200)
61
+ return invalid;
62
+ const parsed = Redirect.safeParse(answer.body);
63
+ if (!parsed.success)
64
+ return invalid;
65
+ const url = absoluteUrl(parsed.data.redirect_url);
66
+ const target = absoluteUrl(fields.redirect_uri);
67
+ if (url === null || target === null || url.origin !== target.origin || url.pathname !== target.pathname)
68
+ return invalid;
69
+ // oauth_internal/__init__.py:602-681 appends '?' even to a callback with a query.
70
+ // Its last field then absorbs the response and a pre-existing code could look newly issued.
71
+ if (target.search !== '' && url.search.startsWith(target.search + '?'))
72
+ return invalid;
73
+ // oauth_internal/__init__.py:602,608,645,655,681 echoes state on every redirect.
74
+ const states = url.searchParams.getAll('state');
75
+ if (fields.state !== undefined && (states.length !== 1 || states[0] !== fields.state))
76
+ return invalid;
77
+ const codes = url.searchParams.getAll('code');
78
+ const errors = url.searchParams.getAll('error');
79
+ const redirect = { redirect_to: parsed.data.redirect_url };
80
+ if (errors.length === 0) {
81
+ // oauth_internal/__init__.py:657-681 issues exactly one code after approval.
82
+ return consent && codes.length === 1 && codes[0]?.trim() ? ok(redirect) : invalid;
83
+ }
84
+ if (codes.length !== 0 || errors.length !== 1)
85
+ return invalid;
86
+ switch (errors[0]) {
87
+ case 'access_denied': return consent ? invalid : ok(redirect); // oauth_internal/__init__.py:600-602
88
+ case 'login_required': return consent ? stopped({ kind: 'signed_out' }) : invalid; // oauth_internal/__init__.py:604-608
89
+ case 'invalid_scope': return stopped({ kind: 'invalid_scope' }); // oauth_internal/__init__.py:640-645
90
+ case 'invalid_target': return stopped({ kind: 'invalid_target' }); // oauth_internal/__init__.py:647-655
91
+ default: return invalid;
92
+ }
93
+ }
94
+ export function createConsentCalls(wire, href, shownRevision) {
95
+ // Bind each view to the exact parameters it showed, even across a later read of the address.
96
+ const shown = new WeakMap();
97
+ let owner;
98
+ let taken = new Set();
99
+ async function send(request, consent, options) {
100
+ const fields = shown.get(request);
101
+ const call = consent ? 'approveConsent' : 'denyConsent';
102
+ if (fields === undefined)
103
+ throw new TypeError(call + '() takes the request consentRequest() returned, as it is');
104
+ checkSignal(call, options);
105
+ if (options?.signal?.aborted)
106
+ return stopped({ kind: 'aborted' });
107
+ const revision = shownRevision();
108
+ if (revision === 'signed_out')
109
+ return stopped({ kind: 'signed_out' });
110
+ if (revision !== undefined && revision !== owner) {
111
+ taken = new Set();
112
+ owner = revision;
113
+ }
114
+ const key = JSON.stringify([fields.client_id, fields.redirect_uri, fields.state, fields.code_challenge,
115
+ fields.code_challenge_method, fields.resource, fields.scope]);
116
+ // A later sign-in has its own set, even if an earlier press is still settling.
117
+ const reservations = revision === undefined ? undefined : taken;
118
+ if (reservations?.has(key))
119
+ return stopped({ kind: 'answered' });
120
+ reservations?.add(key);
121
+ let keepReservation = false;
122
+ const onSend = () => { keepReservation = true; };
123
+ try {
124
+ const answer = await wire.asPerson(consentPost(fields, consent), options, consent ? {
125
+ onSend,
126
+ isUnauthorized(reply) {
127
+ const result = readConsentAnswer(reply, fields, true);
128
+ if (result.ok || result.error.kind !== 'signed_out')
129
+ return false;
130
+ // The anonymous request did nothing. Keep the reservation until the replay settles.
131
+ keepReservation = false;
132
+ return true;
133
+ },
134
+ } : { onSend });
135
+ if (answer.kind !== 'answer')
136
+ return stopped(answer);
137
+ const result = readConsentAnswer(answer, fields, consent);
138
+ if (!result.ok) {
139
+ switch (result.error.kind) {
140
+ case 'unknown_client':
141
+ case 'invalid_scope':
142
+ case 'invalid_target':
143
+ case 'signed_out': // A checked login_required on approve. Neither a code nor a denial was issued.
144
+ keepReservation = false;
145
+ break;
146
+ case 'unavailable':
147
+ if (answer.status === 429)
148
+ keepReservation = false;
149
+ break;
150
+ case 'invalid':
151
+ wire.report({ path: PATH, status: answer.status });
152
+ break;
153
+ }
154
+ }
155
+ return result;
156
+ }
157
+ finally {
158
+ if (!keepReservation)
159
+ reservations?.delete(key);
160
+ }
161
+ }
162
+ return {
163
+ consentRequest() {
164
+ const read = readAddress(href());
165
+ if (read === null)
166
+ return invalidRequest;
167
+ shown.set(read.request, read.fields);
168
+ return read.request;
169
+ },
170
+ approveConsent: (request, options) => send(request, true, options),
171
+ denyConsent: (request, options) => send(request, false, options),
172
+ };
173
+ }
174
+ //# sourceMappingURL=consent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consent.js","sourceRoot":"","sources":["../../../src/first-party/calls/consent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAgD,MAAM,cAAc,CAAA;AACrG,OAAO,EAAE,aAAa,EAAgD,MAAM,YAAY,CAAA;AA0DxF,MAAM,IAAI,GAAG,kBAAkB,CAAA;AAe/B,SAAS,WAAW,CAAC,KAAa;IAChC,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC;AAED,gGAAgG;AAChG,SAAS,WAAW,CAAC,IAAY;IAC/B,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAA;IAC9B,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAA;IAC/B,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,EAAE,CAAA;IAC9C,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,CAAA;IACpD,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAA;IACtC,IAAI,WAAW,CAAC,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,EAAE,CAAC,WAAW,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAA;IACnH,uFAAuF;IAC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L,cAAc;YACZ,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC,CAAA;YAChC,IAAI,IAAI,KAAK,IAAI;gBAAE,OAAO,cAAc,CAAA;YACxC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;YACpC,OAAO,IAAI,CAAC,OAAO,CAAA;QACrB,CAAC;QACD,cAAc,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC;QAClE,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC;KACjE,CAAA;AACH,CAAC"}
@@ -0,0 +1,75 @@
1
+ import { type AsPerson, type CallOptions, type Refused, type Result, type Sent } from '../result.js';
2
+ import { type Wire, type WireAnswer, type WireRequest } from '../wire.js';
3
+ /** The request a device made, as pulse-auth holds it: what the person is asked to approve. */
4
+ export interface DeviceRequest {
5
+ /** As pulse-auth formats it. */
6
+ readonly user_code: string;
7
+ /** The OAuth client the device signs in to. */
8
+ readonly client_id: string;
9
+ /**
10
+ * The name the client declares for itself: for a client registered by metadata document or
11
+ * dynamically, nobody has checked it, so show `client_id` beside it. Null when pulse-auth can't
12
+ * resolve the client.
13
+ */
14
+ readonly client_name: string | null;
15
+ /** What the device asks to be allowed, as pulse-auth names it. */
16
+ readonly scopes: readonly string[];
17
+ /** When the code runs out, epoch ms. */
18
+ readonly expires_at: number;
19
+ }
20
+ /** What stops a look-up. */
21
+ export type DeviceStop =
22
+ /** The code is unknown, expired or already used: pulse-auth says one thing for all three. */
23
+ {
24
+ readonly kind: 'unknown_code';
25
+ }
26
+ /** This request was already denied. Only a look-up says so. */
27
+ | {
28
+ readonly kind: 'already_denied';
29
+ };
30
+ /** What stops an approval or a denial. */
31
+ export type DeviceAnswerStop =
32
+ /**
33
+ * The code is unknown, expired or already used: pulse-auth says one thing for all three. A press
34
+ * on it would be sent again, but pulse-auth no longer holds the code: ask the device for a new one.
35
+ */
36
+ {
37
+ readonly kind: 'unknown_code';
38
+ }
39
+ /**
40
+ * A press from this page on this code (looked up again included) is still out, or may already
41
+ * have acted on it, for the person signed in now. Nothing was sent. Once the first settles, a
42
+ * press is sent again if nothing was sent, or after a 429, which arrives as `unavailable`. After
43
+ * a sent press ends as `signed_out`, `aborted`, `invalid` or any other `unavailable`, another
44
+ * press answers `answered`, and a fresh look-up doesn't change that: only signing in again lets
45
+ * a press be sent.
46
+ */
47
+ | {
48
+ readonly kind: 'answered';
49
+ };
50
+ export interface DeviceCalls {
51
+ readonly lookUpDevice: (request: {
52
+ readonly user_code: string;
53
+ }, options?: CallOptions) => Promise<Result<DeviceRequest, Sent | Refused | DeviceStop>>;
54
+ readonly approveDevice: (device: DeviceRequest, options?: CallOptions) => Promise<Result<{
55
+ readonly kind: 'approved';
56
+ }, AsPerson | DeviceAnswerStop>>;
57
+ readonly denyDevice: (device: DeviceRequest, options?: CallOptions) => Promise<Result<{
58
+ readonly kind: 'denied';
59
+ }, AsPerson | DeviceAnswerStop>>;
60
+ }
61
+ export declare function deviceLookupRequest(input: {
62
+ readonly user_code: string;
63
+ }): WireRequest | Refused;
64
+ export declare function deviceAnswerRequest(device: DeviceRequest, consent: boolean): WireRequest;
65
+ export declare function readDeviceLookup(answer: WireAnswer): Result<DeviceRequest, Sent | DeviceStop>;
66
+ type Decision = 'approved' | 'denied';
67
+ export declare function readDeviceAnswer<D extends Decision>(answer: WireAnswer, expected: D): Result<{
68
+ readonly kind: D;
69
+ }, Sent | DeviceAnswerStop>;
70
+ /**
71
+ * `signedIn` is the revision the page shows, or undefined when nobody is signed in: read at the
72
+ * press, as the wire pins the person there.
73
+ */
74
+ export declare function createDeviceCalls(wire: Pick<Wire, 'open' | 'asPerson' | 'report'>, signedIn: () => number | undefined): DeviceCalls;
75
+ export {};