@mootup/moot-sdk 0.1.0-rc.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 ADDED
@@ -0,0 +1,82 @@
1
+ # @mootup/moot-sdk
2
+
3
+ Typed HTTP client for the [convo](https://mootup.io) API, generated from
4
+ OpenAPI 3.1 at build time. Runtime wrapper is ~6 KB on top of
5
+ [`openapi-fetch`](https://openapi-ts.dev/openapi-fetch/).
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @mootup/moot-sdk
11
+ ```
12
+
13
+ Requires Node 20+ (native `fetch`).
14
+
15
+ ## Usage
16
+
17
+ ```ts
18
+ import { createMootupClient } from '@mootup/moot-sdk';
19
+
20
+ const client = createMootupClient({
21
+ baseUrl: 'https://mootup.io',
22
+ apiKey: process.env.MOOTUP_API_KEY, // optional; adds `Authorization: Bearer <key>`
23
+ });
24
+
25
+ const { data, error, response } = await client.GET('/health');
26
+ if (error) {
27
+ throw new Error(`health check failed: ${response.status}`);
28
+ }
29
+ // `data` is typed from the OAS schema.
30
+ ```
31
+
32
+ ### Auth via session cookie (Node only)
33
+
34
+ The `/auth/request` → `/api/actors/me` flow uses an HTTP-only session cookie.
35
+ Browsers manage cookies natively, but in Node you must opt in:
36
+
37
+ ```ts
38
+ const client = createMootupClient({
39
+ baseUrl: 'https://mootup.io',
40
+ persistCookies: true, // enable tough-cookie jar for Node
41
+ });
42
+
43
+ await client.POST('/auth/request', { body: { email: 'me@example.com' } });
44
+ const me = await client.GET('/api/actors/me');
45
+ ```
46
+
47
+ ### Custom fetch
48
+
49
+ ```ts
50
+ const client = createMootupClient({
51
+ baseUrl: 'https://mootup.io',
52
+ fetch: myInstrumentedFetch,
53
+ });
54
+ ```
55
+
56
+ ## Response types
57
+
58
+ At present, convo's OpenAPI spec declares `additionalProperties: true` on
59
+ every response schema, so response bodies from this SDK arrive typed as
60
+ `unknown` / `Record<string, unknown>`. If you need stronger types, cast at
61
+ the call site or plug in a runtime validator (e.g. `zod`, `valibot`). See
62
+ convo F-1 for the upstream fix.
63
+
64
+ ## Regenerating types
65
+
66
+ `src/generated/paths.ts` is committed. To refresh after the convo OAS
67
+ changes:
68
+
69
+ ```bash
70
+ # 1. pull in the latest OAS from a sibling convo checkout
71
+ npm run sync:oas
72
+
73
+ # 2. regenerate TypeScript types
74
+ npm run -w @mootup/moot-sdk generate
75
+
76
+ # 3. rebuild
77
+ npm run build
78
+ ```
79
+
80
+ ## License
81
+
82
+ MIT.
@@ -0,0 +1,11 @@
1
+ import type { paths } from './generated/paths.js';
2
+ export interface MootupClientOptions {
3
+ baseUrl: string;
4
+ apiKey?: string;
5
+ fetch?: typeof globalThis.fetch;
6
+ persistCookies?: boolean;
7
+ }
8
+ export type MootupClient = ReturnType<typeof createMootupClient>;
9
+ export declare function createMootupClient(opts: MootupClientOptions): import("openapi-fetch").Client<paths, `${string}/${string}`>;
10
+ export type { paths, components, operations } from './generated/paths.js';
11
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAGlD,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEjE,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,mBAAmB,gEAqB3D;AAED,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC"}
package/dist/client.js ADDED
@@ -0,0 +1,22 @@
1
+ import createClient from 'openapi-fetch';
2
+ import { makeCookieJarMiddleware } from './cookies.js';
3
+ export function createMootupClient(opts) {
4
+ const client = createClient({
5
+ baseUrl: opts.baseUrl,
6
+ fetch: opts.fetch,
7
+ });
8
+ if (opts.apiKey) {
9
+ const token = opts.apiKey;
10
+ client.use({
11
+ async onRequest({ request }) {
12
+ request.headers.set('Authorization', `Bearer ${token}`);
13
+ return request;
14
+ },
15
+ });
16
+ }
17
+ if (opts.persistCookies) {
18
+ client.use(makeCookieJarMiddleware());
19
+ }
20
+ return client;
21
+ }
22
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAWvD,MAAM,UAAU,kBAAkB,CAAC,IAAyB;IAC1D,MAAM,MAAM,GAAG,YAAY,CAAQ;QACjC,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,KAAK,EAAE,IAAI,CAAC,KAAK;KAClB,CAAC,CAAC;IAEH,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,MAAM,CAAC,GAAG,CAAC;YACT,KAAK,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE;gBACzB,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,KAAK,EAAE,CAAC,CAAC;gBACxD,OAAO,OAAO,CAAC;YACjB,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;QACxB,MAAM,CAAC,GAAG,CAAC,uBAAuB,EAAE,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { CookieJar } from 'tough-cookie';
2
+ import type { Middleware } from 'openapi-fetch';
3
+ /**
4
+ * Build an openapi-fetch middleware that persists Set-Cookie headers across
5
+ * requests using an in-memory tough-cookie jar. Used by the /auth/request →
6
+ * /api/actors/me session flow in Node environments (browsers handle cookies
7
+ * natively).
8
+ */
9
+ export declare function makeCookieJarMiddleware(jar?: CookieJar): Middleware;
10
+ //# sourceMappingURL=cookies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../src/cookies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,YAAkB,GAAG,UAAU,CAmBzE"}
@@ -0,0 +1,35 @@
1
+ import { CookieJar } from 'tough-cookie';
2
+ /**
3
+ * Build an openapi-fetch middleware that persists Set-Cookie headers across
4
+ * requests using an in-memory tough-cookie jar. Used by the /auth/request →
5
+ * /api/actors/me session flow in Node environments (browsers handle cookies
6
+ * natively).
7
+ */
8
+ export function makeCookieJarMiddleware(jar = new CookieJar()) {
9
+ return {
10
+ async onRequest({ request }) {
11
+ const cookieHeader = await jar.getCookieString(request.url);
12
+ if (cookieHeader) {
13
+ request.headers.set('Cookie', cookieHeader);
14
+ }
15
+ return request;
16
+ },
17
+ async onResponse({ response, request }) {
18
+ const setCookie = response.headers.get('set-cookie');
19
+ if (setCookie) {
20
+ for (const cookie of splitSetCookieHeader(setCookie)) {
21
+ await jar.setCookie(cookie, request.url);
22
+ }
23
+ }
24
+ return response;
25
+ },
26
+ };
27
+ }
28
+ function splitSetCookieHeader(value) {
29
+ // Set-Cookie values can include commas inside expires/date attributes,
30
+ // which is why most stdlibs expose the raw header array separately. Node's
31
+ // fetch flattens to a single string. Split on commas that are followed by
32
+ // a cookie-attribute-looking prefix (word chars + '=').
33
+ return value.split(/,(?=\s*[A-Za-z0-9_-]+=)/);
34
+ }
35
+ //# sourceMappingURL=cookies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookies.js","sourceRoot":"","sources":["../src/cookies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,GAAG,GAAG,IAAI,SAAS,EAAE;IAC3D,OAAO;QACL,KAAK,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE;YACzB,MAAM,YAAY,GAAG,MAAM,GAAG,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAC5D,IAAI,YAAY,EAAE,CAAC;gBACjB,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;YAC9C,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,KAAK,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE;YACpC,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;YACrD,IAAI,SAAS,EAAE,CAAC;gBACd,KAAK,MAAM,MAAM,IAAI,oBAAoB,CAAC,SAAS,CAAC,EAAE,CAAC;oBACrD,MAAM,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;gBAC3C,CAAC;YACH,CAAC;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAa;IACzC,uEAAuE;IACvE,2EAA2E;IAC3E,0EAA0E;IAC1E,wDAAwD;IACxD,OAAO,KAAK,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;AAChD,CAAC"}