@bkazemi/verily 0.7.0 → 0.8.1

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 (48) hide show
  1. package/README.md +183 -94
  2. package/dist/browser/mark.d.ts +2 -6
  3. package/dist/browser/mark.js +6 -12
  4. package/dist/browser/provider-mark.d.ts +3 -3
  5. package/dist/browser/provider-mark.js +15 -90
  6. package/dist/instance/auth.d.ts +14 -0
  7. package/dist/instance/auth.js +80 -0
  8. package/dist/instance/bin.d.ts +2 -0
  9. package/dist/instance/bin.js +36 -0
  10. package/dist/instance/cloudflare.d.ts +57 -0
  11. package/dist/instance/cloudflare.js +71 -0
  12. package/dist/instance/env.d.ts +51 -0
  13. package/dist/instance/env.js +84 -0
  14. package/dist/instance/index.d.ts +136 -0
  15. package/dist/instance/index.js +777 -0
  16. package/dist/instance/init.d.ts +6 -0
  17. package/dist/instance/init.js +28 -0
  18. package/dist/instance/limits.d.ts +30 -0
  19. package/dist/instance/limits.js +45 -0
  20. package/dist/instance/node.d.ts +13 -0
  21. package/dist/instance/node.js +43 -0
  22. package/dist/instance/page.d.ts +18 -0
  23. package/dist/instance/page.js +30 -0
  24. package/dist/instance/postgres.d.ts +19 -0
  25. package/dist/instance/postgres.js +83 -0
  26. package/dist/instance/routes.d.ts +7 -0
  27. package/dist/instance/routes.js +22 -0
  28. package/dist/instance/serve.d.ts +31 -0
  29. package/dist/instance/serve.js +49 -0
  30. package/dist/instance/sites.d.ts +169 -0
  31. package/dist/instance/sites.js +413 -0
  32. package/dist/instance/starter.d.ts +6 -0
  33. package/dist/instance/starter.js +99 -0
  34. package/dist/instance/store.d.ts +20 -0
  35. package/dist/instance/store.js +11 -0
  36. package/dist/instance/undici.d.ts +8 -0
  37. package/dist/instance/undici.js +9 -0
  38. package/dist/marks.d.ts +44 -0
  39. package/dist/marks.js +98 -0
  40. package/dist/server/index.js +46 -67
  41. package/dist/server/render.d.ts +49 -0
  42. package/dist/server/render.js +104 -0
  43. package/dist/server/style.d.ts +1 -1
  44. package/dist/server/style.js +145 -1
  45. package/dist/verily.js +96 -104
  46. package/dist/version.d.ts +1 -1
  47. package/dist/version.js +1 -1
  48. package/package.json +30 -2
@@ -0,0 +1,136 @@
1
+ import { type LocalAccount, type Provider } from '../core/index.js';
2
+ import { type Store } from './store.js';
3
+ import { type Site } from './sites.js';
4
+ export { fromEnv, type InstanceEnv } from './env.js';
5
+ export { registry, type Site } from './sites.js';
6
+ export { recordStorage, type KeyValue, type Store } from './store.js';
7
+ export interface InstanceOptions {
8
+ /** Everything the instance keeps: the records, and its own sessions, handoffs and counts. */
9
+ store: Store;
10
+ /** The origin the instance is served from. HTTPS, with no trailing slash. */
11
+ origin: string;
12
+ /** The owner's own site. A registered site's subjects carry their site's name instead. */
13
+ siteName: string;
14
+ /** What the owner links here: one of their accounts, a page, or the site. */
15
+ owner: Omit<LocalAccount, 'id' | 'siteName'> & {
16
+ profileUrl: string;
17
+ };
18
+ /** The secret the owner signs in with. */
19
+ ownerKey: string;
20
+ reportUrl: string;
21
+ /** The methods offered. A registered site may narrow these for its own holders. */
22
+ providers: Provider[];
23
+ /** The sites that send their users here instead of hosting Verily, as `registry()` reads them. */
24
+ sites?: Map<string, Site>;
25
+ /**
26
+ * The key public records are signed by, armored. Left out, a key is made on first use and
27
+ * kept in the store. `false` turns signing off.
28
+ */
29
+ signingKey?: string | false;
30
+ /** How many codes may be mailed in a day, where the mail allowance is not the default. */
31
+ mailPerDay?: number;
32
+ /** How often each published proof is re-read. Six hours by default. */
33
+ recheckMs?: number;
34
+ /** How many proofs one `upkeep()` re-reads per provider. 10 by default. */
35
+ recheckBudget?: number;
36
+ }
37
+ /**
38
+ * The checks that need nothing stored: the origin, the method, and a bound on the body.
39
+ * Gives back the response to send, or the request with its body read. `handle` runs this
40
+ * itself. A host that passes requests on to another process can run it first, so that
41
+ * process is not woken for a request this turns away.
42
+ */
43
+ export declare function admit(request: Request, origin: string): Promise<Request | Response>;
44
+ /** A multi-site Verily server: a request handler, and the upkeep its host runs on a timer. */
45
+ export type Instance = ReturnType<typeof createInstance>;
46
+ export declare function createInstance(options: InstanceOptions): Server;
47
+ declare class Server {
48
+ private readonly options;
49
+ private readonly app;
50
+ private readonly store;
51
+ private readonly origin;
52
+ private readonly auth;
53
+ private readonly sites;
54
+ private readonly local;
55
+ constructor(options: InstanceOptions);
56
+ /** The library's service, for a host that needs more than requests and upkeep. */
57
+ get service(): import("../server/service.js").VerilyService;
58
+ /**
59
+ * What a host runs on a timer, about hourly: drops what has expired, and re-reads the
60
+ * published proofs that are due. The default of 10 per provider each hour stays inside
61
+ * the rate limit a provider gives an unauthenticated caller.
62
+ */
63
+ upkeep(): Promise<void>;
64
+ /**
65
+ * Answers one request. `address` is the client's address as the host knows it, which
66
+ * rate limits count by. The instance reads no forwarding header itself, since which one
67
+ * can be trusted depends on what the host sits behind.
68
+ */
69
+ handle(request: Request, address?: string | null): Promise<Response>;
70
+ private route;
71
+ /**
72
+ * One request from the connect dialog on a site's own page. The page holds the session
73
+ * and the flow's binding and sends them as headers, because this instance's cookies are
74
+ * another site's on that page and a browser may not send them. Here they are put where
75
+ * the library looks for them, and a binding the library sets comes back as a header. The
76
+ * session works only from its own site's origin, and only for the dialog's requests.
77
+ */
78
+ private dialog;
79
+ /**
80
+ * Gives the sign-in window the binding of a flow a site's dialog started, as the cookie
81
+ * the provider's callback checks. `origin` is where the page that sent the binding is,
82
+ * as the window's own script saw it. It must be the site the flow's subject belongs to.
83
+ */
84
+ private enter;
85
+ /** The site a subject belongs to, by its id's prefix. The owner's id has none. */
86
+ private siteOf;
87
+ /**
88
+ * A site's backend reading its own subjects' connections, unlisted ones included, which
89
+ * nobody else can read. This is what lets a site show a link to its own users without the
90
+ * link being public. A refused request counts against the caller's address, and a good
91
+ * one against the site's own allowance, apart from the one its holders' handoffs share.
92
+ */
93
+ private read;
94
+ /** This installation's own signing key, made the first time a record is signed. */
95
+ private signingKey;
96
+ private site;
97
+ /**
98
+ * Counts a request that creates state: every POST, and the GETs that start a handoff, a
99
+ * session or a flow. A signed-in holder has a bucket of their own and anyone else is
100
+ * counted by address, so one visitor cannot lock everyone else out. A site's requests
101
+ * also share a ceiling, so one site cannot starve another.
102
+ */
103
+ private allowed;
104
+ /**
105
+ * Removes a link from a site session and reports it back to the site. There is no flow to
106
+ * hold the result, so the session holds it, and success is reported only once the
107
+ * revocation has committed: pending first, then revoked, then complete. A retry resumes
108
+ * wherever the last attempt stopped, and one already complete reads what it stored.
109
+ */
110
+ private disconnect;
111
+ /**
112
+ * Lists an account another way, or retires it, from a site session, and reports it back
113
+ * to the site as a disconnect is reported: pending on the session first, then changed,
114
+ * then complete. Asking again for what already holds changes nothing, so a retry is safe.
115
+ */
116
+ private mark;
117
+ /**
118
+ * The settings page for whoever is signed in: the owner, or a holder a site sent here.
119
+ * The owner's page carries the embed for their own site; a site's holder has the site to
120
+ * show their badge, and removes a link through a route that tells the site so.
121
+ */
122
+ private settings;
123
+ /**
124
+ * Every record the instance holds, for its operator: each site's subjects, public and
125
+ * unlisted alike, with what each is linked to and how it stands. Read-only. A public
126
+ * record links to its evidence; an unlisted one has no page that is the operator's to open.
127
+ */
128
+ private records;
129
+ /**
130
+ * Asks before an account is retired or a connection is removed, since neither can be
131
+ * undone. The page's one button posts to the route that does it.
132
+ */
133
+ private confirm;
134
+ /** One connection: the account's card, its state, and what can be done with it. */
135
+ private connection;
136
+ }