@metacensus/api 0.2.0 → 0.3.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.
- package/README.md +102 -66
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/public.d.ts +1 -1
- package/dist/public.d.ts.map +1 -1
- package/dist/public.js +2 -2
- package/dist/public.js.map +1 -1
- package/dist/src/client.d.ts +49 -37
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +138 -79
- package/dist/src/client.js.map +1 -1
- package/dist/src/metacensus/v1/auth.d.ts +2 -2
- package/dist/src/metacensus/v1/auth.d.ts.map +1 -1
- package/dist/src/metacensus/v1/common.d.ts +34 -3
- package/dist/src/metacensus/v1/common.d.ts.map +1 -1
- package/dist/src/metacensus/v1/prop.d.ts +26 -16
- package/dist/src/metacensus/v1/prop.d.ts.map +1 -1
- package/dist/src/metacensus/v1/prop.js +18 -18
- package/dist/src/metacensus/v1/prop.js.map +1 -1
- package/dist/src/metacensus/v1/topic.d.ts +11 -6
- package/dist/src/metacensus/v1/topic.d.ts.map +1 -1
- package/dist/src/metacensus/v1/user.d.ts +9 -4
- package/dist/src/metacensus/v1/user.d.ts.map +1 -1
- package/dist/src/route-manifest.js +7 -7
- package/dist/src/route-manifest.js.map +1 -1
- package/dist/src/signing.d.ts.map +1 -1
- package/dist/src/signing.js +7 -12
- package/dist/src/signing.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -4,61 +4,120 @@ TypeScript interfaces for the MetaCensus API contract — every request and
|
|
|
4
4
|
response under `/metacensus/api/v1` and `/metacensus/public`, generated from the
|
|
5
5
|
`.proto` sources that also generate the Go side.
|
|
6
6
|
|
|
7
|
-
What ships is the generated interfaces, the route manifest, `protobufPackage`,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
what says so, and what fails the build. The signing module is inside that
|
|
11
|
-
guard rather than an exception to it.
|
|
7
|
+
What ships is the generated interfaces, the route manifest, `protobufPackage`, a
|
|
8
|
+
batteries-included client per surface, and the signing chain. How dependencies
|
|
9
|
+
are weighed is in the repository's AGENTS.md, under "Dependencies".
|
|
12
10
|
|
|
13
11
|
```bash
|
|
14
12
|
npm install @metacensus/api
|
|
15
13
|
```
|
|
16
14
|
|
|
17
15
|
```ts
|
|
18
|
-
import
|
|
19
|
-
import { routes, Client, ApiError, type Transport } from "@metacensus/api";
|
|
16
|
+
import { Client, ApiError, type Signer } from "@metacensus/api";
|
|
20
17
|
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
const client = new Client({ baseUrl: "https://api.example.com", signer });
|
|
19
|
+
await client.login({ email, password }); // token stored internally
|
|
20
|
+
const topic = await client.getTopic({ topicId }); // TopicRecord: { id, recorded, name, description }
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`Client` is batteries-included: it owns its `fetch`, holds the session token
|
|
24
|
+
across `login`/`logout`, and signs writes with the `signer` you inject. It is the
|
|
25
|
+
client to reach for. Construct it with:
|
|
26
|
+
|
|
27
|
+
- `baseUrl` — the origin; the client adds `/metacensus/api/v1` and the route.
|
|
28
|
+
- `fetch?` — a `fetch` to use instead of the global, for tests or instrumentation
|
|
29
|
+
(wrap the global to add retries, a 401 policy, or logging).
|
|
30
|
+
- `signer?` — signs writes; see "Writes", below. Omit it for a read-only client.
|
|
31
|
+
- `token?` — an initial bearer token, to resume a session without logging in.
|
|
32
|
+
|
|
33
|
+
A non-2xx response throws `ApiError` (`method`, `url`, `status`, and the raw
|
|
34
|
+
`body` — parse it defensively, since a 404 or 405 comes from the router, not a
|
|
35
|
+
handler). Every scalar is required, which is what makes Go's `EmitDefaultValues`
|
|
36
|
+
and these types describe the same document: `client.createTopic({ content: { name } })`
|
|
37
|
+
does not type-check, `{ content: { name, description: "" } }` does.
|
|
38
|
+
|
|
39
|
+
## Reads: flat record or signed envelope
|
|
40
|
+
|
|
41
|
+
A read returns the **flat record** — the domain object with the server's `id`
|
|
42
|
+
and `recorded` folded in, and the `{content, userSignature}` envelope gone:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
const topic = await client.getTopic({ topicId }); // { id, recorded, name, description }
|
|
46
|
+
topic.name; // not topic.content.name
|
|
27
47
|
```
|
|
28
48
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
49
|
+
The envelope isn't uniform, so the record isn't either:
|
|
50
|
+
|
|
51
|
+
| Response shape | `getX` / `listX` returns |
|
|
52
|
+
| --- | --- |
|
|
53
|
+
| id-bearing envelope (topic, prop, user) | `TopicRecord` — `{ id, recorded, ...content }` — / `TopicRecord[]` |
|
|
54
|
+
| a vote — envelope with **no `id`** | `VoteRecord` (no `id`) / `VoteRecord[]` |
|
|
55
|
+
| a member — already flat | `Member`, unchanged / `Member[]` |
|
|
56
|
+
|
|
57
|
+
When you need the signature itself — verifying authorship, comparing `recorded`
|
|
58
|
+
against the signer's `signingTime`, or re-hashing the document — each
|
|
59
|
+
signed-envelope read has a **`getXSigned`** twin that returns the raw envelope:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
const signed = await client.getTopicSigned({ topicId }); // TopicSigned: { id, recorded, content, userSignature }
|
|
63
|
+
await verify(pub, signed.content, signed.userSignature);
|
|
64
|
+
```
|
|
33
65
|
|
|
34
|
-
|
|
35
|
-
retries. The client calls no `fetch`, keeps no cache, and throws `ApiError` for
|
|
36
|
-
any non-2xx the transport did not handle itself. `ApiError.body` is raw text —
|
|
37
|
-
a 404 or 405 comes from the server's router rather than a handler, so parse it
|
|
38
|
-
defensively rather than assuming JSON.
|
|
66
|
+
`getXSigned` exists only where there's a signature to see; `Member` has none.
|
|
39
67
|
|
|
40
|
-
|
|
41
|
-
request message and is made before the client is called; see "Signing", below.
|
|
68
|
+
## Writes and the signer
|
|
42
69
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
70
|
+
A write takes **flat content** — never the envelope — and the `signer` assembles
|
|
71
|
+
the rest. The signer is set once on the constructor, because the key it signs
|
|
72
|
+
with is identical for a session:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { SPEC, sign, keyId } from "@metacensus/api/signing";
|
|
76
|
+
|
|
77
|
+
const signer: Signer = async (content, contentType) => {
|
|
78
|
+
const s = {
|
|
79
|
+
signerId,
|
|
80
|
+
keyId: await keyId(publicKey),
|
|
81
|
+
alg: "Es384",
|
|
82
|
+
publicKey: "",
|
|
83
|
+
signingTime: new Date().toISOString(),
|
|
84
|
+
spec: SPEC,
|
|
85
|
+
contentType, // the client names it — you don't
|
|
86
|
+
value: "",
|
|
87
|
+
};
|
|
88
|
+
s.value = await sign(privateKey, content, s);
|
|
89
|
+
return s;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const client = new Client({ baseUrl, signer });
|
|
93
|
+
const created = await client.createTopic({ content: { name: "A review", description: "" } });
|
|
94
|
+
// TopicRecord, flattened like a read
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The client supplies `content` and the exact `contentType` (the one thing
|
|
98
|
+
`sign`/`verify` leave to the caller, and the easiest to get wrong); your closure
|
|
99
|
+
holds the key and does the crypto — the key never enters the client. A write on
|
|
100
|
+
a client built without a signer throws.
|
|
101
|
+
|
|
102
|
+
## Auth and the session token
|
|
103
|
+
|
|
104
|
+
`login` and `signUp` store the returned token; the client adds
|
|
105
|
+
`Authorization: Bearer <token>` to every later request, and `logout` clears it.
|
|
106
|
+
`signUp` signs its `User` content through the same signer (that signature enrols
|
|
107
|
+
the key — inline `publicKey`, empty `signerId`; keep the password out of
|
|
108
|
+
`content`, since content is what gets stored). `token` (a getter) exposes the
|
|
109
|
+
current token, to persist and later restore a session via the `token` option.
|
|
47
110
|
|
|
48
111
|
## The public surface
|
|
49
112
|
|
|
50
113
|
The public, unauthenticated surface is an entry point of its own in the same
|
|
51
|
-
package, with a client to match:
|
|
114
|
+
package, with a client to match — no signer, no token:
|
|
52
115
|
|
|
53
116
|
```ts
|
|
54
117
|
import type { PartnerSubmission } from "@metacensus/api/public";
|
|
55
|
-
import {
|
|
56
|
-
PartnerSubmission_Interest,
|
|
57
|
-
PublicClient,
|
|
58
|
-
publicPrefix,
|
|
59
|
-
} from "@metacensus/api/public";
|
|
118
|
+
import { PartnerSubmission_Interest, PublicClient } from "@metacensus/api/public";
|
|
60
119
|
|
|
61
|
-
const pub = new PublicClient(
|
|
120
|
+
const pub = new PublicClient({ baseUrl });
|
|
62
121
|
await pub.submitPartnerInterest({ name, email, interests, message, website: "" });
|
|
63
122
|
```
|
|
64
123
|
|
|
@@ -66,8 +125,6 @@ One package because the SPA calls both surfaces from one build; an entry point
|
|
|
66
125
|
per surface because a consumer of only the public surface should not acquire the
|
|
67
126
|
authenticated types. `@metacensus/api/signing` is a third, splitting by concern
|
|
68
127
|
rather than by surface — nothing on the public surface is ever signed.
|
|
69
|
-
`PublicClient` sends no credentials of its own; pass it a separate transport
|
|
70
|
-
from the one you pass `Client`.
|
|
71
128
|
|
|
72
129
|
`ApiError` is the same class from either entry point, so `instanceof ApiError`
|
|
73
130
|
holds for a failure from either surface. Importing it twice is harmless.
|
|
@@ -91,41 +148,20 @@ the enum's comment for why.
|
|
|
91
148
|
Every write on the authenticated surface carries a `content` message and a
|
|
92
149
|
`userSignature` over it. A session token says who is connected; the signature
|
|
93
150
|
says who authored the record, and the API server does not check it — it is
|
|
94
|
-
verified by the persistence layer, behind the edge.
|
|
151
|
+
verified by the persistence layer, behind the edge. `@metacensus/api/signing` is
|
|
152
|
+
what your `Signer` uses to make one:
|
|
95
153
|
|
|
96
154
|
```ts
|
|
97
|
-
import { SPEC, sign, keyId, generateKeyPair, encodePublicKey } from "@metacensus/api/signing";
|
|
155
|
+
import { SPEC, sign, verify, keyId, generateKeyPair, encodePublicKey } from "@metacensus/api/signing";
|
|
98
156
|
|
|
99
157
|
const { privateKey, publicKey } = await generateKeyPair(); // ECDSA P-384
|
|
100
|
-
|
|
101
|
-
const content = { name: "A review", description: "" };
|
|
102
|
-
const userSignature = {
|
|
103
|
-
signerId,
|
|
104
|
-
keyId: await keyId(publicKey),
|
|
105
|
-
alg: "Es384",
|
|
106
|
-
publicKey: "", // inline only on sign-up, which is what enrols the key
|
|
107
|
-
signingTime: new Date().toISOString(),
|
|
108
|
-
spec: SPEC,
|
|
109
|
-
contentType: "metacensus.v1.TopicContent",
|
|
110
|
-
value: "",
|
|
111
|
-
};
|
|
112
|
-
userSignature.value = await sign(privateKey, content, userSignature);
|
|
113
|
-
|
|
114
|
-
await api.createTopic({ content, userSignature });
|
|
115
158
|
```
|
|
116
159
|
|
|
117
|
-
The digest is SHA-384 over RFC 8785 canonical JSON of
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
`
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
Sign-up is the one request whose signature carries its own public key: there is
|
|
124
|
-
no id yet to look one up by. Set `publicKey` there, leave `signerId` empty, and
|
|
125
|
-
keep the password out of `content` — content is what gets stored.
|
|
126
|
-
|
|
127
|
-
`routes` carries a `signed` flag per route, so "which routes need a key?" is a
|
|
128
|
-
lookup rather than a guess.
|
|
160
|
+
The digest is SHA-384 over RFC 8785 canonical JSON of `{content, signature}`,
|
|
161
|
+
with `value` emptied. Every field but `value` is inside it, so a signature cannot
|
|
162
|
+
be re-attributed or re-dated — which is why `contentType` has to name the content
|
|
163
|
+
you actually signed and `signingTime` has to be set. `routes` carries a `signed`
|
|
164
|
+
flag per route, so "which routes need a key?" is a lookup rather than a guess.
|
|
129
165
|
|
|
130
166
|
The full account of the chain, and `go/signing`, the other half that has to
|
|
131
167
|
compute the same digest, are in the repository README.
|
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ export * from "./src/metacensus/v1/topic.js";
|
|
|
5
5
|
export * from "./src/metacensus/v1/user.js";
|
|
6
6
|
export * from "./src/route-manifest.js";
|
|
7
7
|
export { protobufPackage } from "./src/metacensus/v1/common.js";
|
|
8
|
-
export { Client, ApiError, type
|
|
8
|
+
export { Client, ApiError, type ClientOptions, type Signer, type TopicRecord, type PropRecord, type VoteRecord, type UserRecord, } from "./src/client.js";
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAOA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AAGxC,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAOA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AAGxC,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAMhE,OAAO,EACL,MAAM,EACN,QAAQ,EACR,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,UAAU,GAChB,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,8 @@ export * from "./src/route-manifest.js";
|
|
|
13
13
|
// `export *` can't pick one file's `protobufPackage` over another's.
|
|
14
14
|
export { protobufPackage } from "./src/metacensus/v1/common.js";
|
|
15
15
|
// Named, not `export *`: src/client.ts has one class per surface, and this
|
|
16
|
-
// entry point wants only the authenticated one.
|
|
16
|
+
// entry point wants only the authenticated one. `Client` is batteries-included;
|
|
17
|
+
// the `…Record` types are its flat reads and `Signer` its write seam. See
|
|
18
|
+
// ts/README.md, "The generated client".
|
|
17
19
|
export { Client, ApiError, } from "./src/client.js";
|
|
18
20
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,qEAAqE;AACrE,kDAAkD;AAClD,EAAE;AACF,0EAA0E;AAC1E,0CAA0C;AAE1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AAExC,qEAAqE;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,2EAA2E;AAC3E,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,qEAAqE;AACrE,kDAAkD;AAClD,EAAE;AACF,0EAA0E;AAC1E,0CAA0C;AAE1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AAExC,qEAAqE;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,2EAA2E;AAC3E,gFAAgF;AAChF,0EAA0E;AAC1E,wCAAwC;AACxC,OAAO,EACL,MAAM,EACN,QAAQ,GAOT,MAAM,iBAAiB,CAAC"}
|
package/dist/public.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export * from "./src/metacensus/public/v1/common.js";
|
|
|
2
2
|
export * from "./src/metacensus/public/v1/partner.js";
|
|
3
3
|
export * from "./src/route-manifest.js";
|
|
4
4
|
export { protobufPackage } from "./src/metacensus/public/v1/common.js";
|
|
5
|
-
export { PublicClient, ApiError, type
|
|
5
|
+
export { PublicClient, ApiError, type PublicClientOptions, } from "./src/client.js";
|
|
6
6
|
//# sourceMappingURL=public.d.ts.map
|
package/dist/public.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../public.ts"],"names":[],"mappings":"AAIA,cAAc,sCAAsC,CAAC;AACrD,cAAc,uCAAuC,CAAC;AACtD,cAAc,yBAAyB,CAAC;AAGxC,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAMvE,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,KAAK,
|
|
1
|
+
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../public.ts"],"names":[],"mappings":"AAIA,cAAc,sCAAsC,CAAC;AACrD,cAAc,uCAAuC,CAAC;AACtD,cAAc,yBAAyB,CAAC;AAGxC,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAMvE,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,KAAK,mBAAmB,GACzB,MAAM,iBAAiB,CAAC"}
|
package/dist/public.js
CHANGED
|
@@ -7,8 +7,8 @@ export * from "./src/route-manifest.js";
|
|
|
7
7
|
// `export *` can't pick one file's `protobufPackage` over another's.
|
|
8
8
|
export { protobufPackage } from "./src/metacensus/public/v1/common.js";
|
|
9
9
|
// Named, not `export *`: src/client.ts has one class per surface, and this
|
|
10
|
-
// entry point wants only PublicClient. A public-only consumer still carries
|
|
11
|
-
//
|
|
10
|
+
// entry point wants only PublicClient. A public-only consumer still carries the
|
|
11
|
+
// authenticated Client as dead code (a bundler drops it), but not the
|
|
12
12
|
// authenticated types, which is what the split is for.
|
|
13
13
|
export { PublicClient, ApiError, } from "./src/client.js";
|
|
14
14
|
//# sourceMappingURL=public.js.map
|
package/dist/public.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public.js","sourceRoot":"","sources":["../public.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,0EAA0E;AAC1E,iEAAiE;AAEjE,cAAc,sCAAsC,CAAC;AACrD,cAAc,uCAAuC,CAAC;AACtD,cAAc,yBAAyB,CAAC;AAExC,qEAAqE;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAEvE,2EAA2E;AAC3E,
|
|
1
|
+
{"version":3,"file":"public.js","sourceRoot":"","sources":["../public.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,0EAA0E;AAC1E,iEAAiE;AAEjE,cAAc,sCAAsC,CAAC;AACrD,cAAc,uCAAuC,CAAC;AACtD,cAAc,yBAAyB,CAAC;AAExC,qEAAqE;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAEvE,2EAA2E;AAC3E,gFAAgF;AAChF,sEAAsE;AACtE,uDAAuD;AACvD,OAAO,EACL,YAAY,EACZ,QAAQ,GAET,MAAM,iBAAiB,CAAC"}
|
package/dist/src/client.d.ts
CHANGED
|
@@ -1,54 +1,66 @@
|
|
|
1
1
|
import type { PartnerReceipt, PartnerSubmission } from "./metacensus/public/v1/partner.js";
|
|
2
2
|
import type { LoginRequest, LogoutRequest, LogoutResponse, Session, SignUpRequest } from "./metacensus/v1/auth.js";
|
|
3
|
-
import type { HealthcheckRequest, HealthcheckResponse } from "./metacensus/v1/common.js";
|
|
4
|
-
import type { Prop, PropCreateRequest, PropGetRequest,
|
|
5
|
-
import type { Member, MemberGetRequest,
|
|
6
|
-
import type { SelfGetRequest,
|
|
7
|
-
export interface ClientRequest {
|
|
8
|
-
readonly method: string;
|
|
9
|
-
readonly path: string;
|
|
10
|
-
readonly body?: string;
|
|
11
|
-
}
|
|
12
|
-
export interface ClientResponse {
|
|
13
|
-
readonly status: number;
|
|
14
|
-
readonly body: string;
|
|
15
|
-
}
|
|
16
|
-
export type Transport = (req: ClientRequest) => Promise<ClientResponse>;
|
|
3
|
+
import type { HealthcheckRequest, HealthcheckResponse, User, UserSignature } from "./metacensus/v1/common.js";
|
|
4
|
+
import type { Prop, PropCreateRequest, PropGetRequest, PropListRequest, PropSigned, Vote, VoteListRequest, VoteSetRequest, VoteSigned } from "./metacensus/v1/prop.js";
|
|
5
|
+
import type { Member, MemberGetRequest, MemberListRequest, Topic, TopicCreateRequest, TopicGetRequest, TopicListRequest, TopicSigned } from "./metacensus/v1/topic.js";
|
|
6
|
+
import type { SelfGetRequest, UserGetRequest, UserListRequest, UserSigned } from "./metacensus/v1/user.js";
|
|
17
7
|
export declare class ApiError extends Error {
|
|
18
8
|
readonly method: string;
|
|
19
|
-
readonly
|
|
9
|
+
readonly url: string;
|
|
20
10
|
readonly status: number;
|
|
21
11
|
readonly body: string;
|
|
22
|
-
constructor(method: string,
|
|
12
|
+
constructor(method: string, url: string, status: number, body: string);
|
|
13
|
+
}
|
|
14
|
+
export type Signer = (content: unknown, contentType: string) => Promise<UserSignature>;
|
|
15
|
+
export type PropRecord = Pick<PropSigned, "id" | "recorded"> & Prop;
|
|
16
|
+
export type TopicRecord = Pick<TopicSigned, "id" | "recorded"> & Topic;
|
|
17
|
+
export type UserRecord = Pick<UserSigned, "id" | "recorded"> & User;
|
|
18
|
+
export type VoteRecord = Pick<VoteSigned, "recorded"> & Vote;
|
|
19
|
+
export interface ClientOptions {
|
|
20
|
+
readonly baseUrl: string;
|
|
21
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
22
|
+
readonly signer?: Signer;
|
|
23
|
+
readonly token?: string;
|
|
24
|
+
readonly prefix?: string;
|
|
23
25
|
}
|
|
24
26
|
export declare class Client {
|
|
25
|
-
private
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
private call;
|
|
27
|
+
#private;
|
|
28
|
+
constructor(options: ClientOptions);
|
|
29
|
+
get token(): string | undefined;
|
|
29
30
|
login(req: LoginRequest): Promise<Session>;
|
|
30
|
-
signUp(req: SignUpRequest): Promise<Session>;
|
|
31
|
+
signUp(req: Omit<SignUpRequest, "userSignature">): Promise<Session>;
|
|
31
32
|
logout(req: LogoutRequest): Promise<LogoutResponse>;
|
|
32
33
|
healthcheck(req: HealthcheckRequest): Promise<HealthcheckResponse>;
|
|
33
|
-
listProps(req: PropListRequest): Promise<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
listProps(req: PropListRequest): Promise<PropRecord[]>;
|
|
35
|
+
listPropsSigned(req: PropListRequest): Promise<PropSigned[]>;
|
|
36
|
+
getProp(req: PropGetRequest): Promise<PropRecord>;
|
|
37
|
+
getPropSigned(req: PropGetRequest): Promise<PropSigned>;
|
|
38
|
+
createProp(req: Omit<PropCreateRequest, "userSignature">): Promise<PropRecord>;
|
|
39
|
+
listVotes(req: VoteListRequest): Promise<VoteRecord[]>;
|
|
40
|
+
listVotesSigned(req: VoteListRequest): Promise<VoteSigned[]>;
|
|
41
|
+
setVote(req: Omit<VoteSetRequest, "userSignature">): Promise<VoteRecord>;
|
|
42
|
+
listTopics(req: TopicListRequest): Promise<TopicRecord[]>;
|
|
43
|
+
listTopicsSigned(req: TopicListRequest): Promise<TopicSigned[]>;
|
|
44
|
+
getTopic(req: TopicGetRequest): Promise<TopicRecord>;
|
|
45
|
+
getTopicSigned(req: TopicGetRequest): Promise<TopicSigned>;
|
|
46
|
+
createTopic(req: Omit<TopicCreateRequest, "userSignature">): Promise<TopicRecord>;
|
|
47
|
+
listMembers(req: MemberListRequest): Promise<Member[]>;
|
|
42
48
|
getMember(req: MemberGetRequest): Promise<Member>;
|
|
43
|
-
listUsers(req: UserListRequest): Promise<
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
listUsers(req: UserListRequest): Promise<UserRecord[]>;
|
|
50
|
+
listUsersSigned(req: UserListRequest): Promise<UserSigned[]>;
|
|
51
|
+
getUser(req: UserGetRequest): Promise<UserRecord>;
|
|
52
|
+
getUserSigned(req: UserGetRequest): Promise<UserSigned>;
|
|
53
|
+
getSelf(req: SelfGetRequest): Promise<UserRecord>;
|
|
54
|
+
getSelfSigned(req: SelfGetRequest): Promise<UserSigned>;
|
|
55
|
+
}
|
|
56
|
+
export interface PublicClientOptions {
|
|
57
|
+
readonly baseUrl: string;
|
|
58
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
59
|
+
readonly prefix?: string;
|
|
46
60
|
}
|
|
47
61
|
export declare class PublicClient {
|
|
48
|
-
private
|
|
49
|
-
|
|
50
|
-
constructor(transport: Transport, prefix?: string);
|
|
51
|
-
private call;
|
|
62
|
+
#private;
|
|
63
|
+
constructor(options: PublicClientOptions);
|
|
52
64
|
submitPartnerInterest(req: PartnerSubmission): Promise<PartnerReceipt>;
|
|
53
65
|
}
|
|
54
66
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/src/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAC3F,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACnH,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAC3F,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACnH,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EA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