@possibl/rcrt-sdk 0.1.1 → 0.1.3
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/CHANGELOG.md +23 -67
- package/LICENSE +21 -0
- package/README.md +2 -20
- package/dist/auth.d.ts +45 -0
- package/dist/auth.d.ts.map +1 -0
- package/{src/auth.ts → dist/auth.js} +9 -24
- package/dist/auth.js.map +1 -0
- package/dist/authn.d.ts +84 -0
- package/dist/authn.d.ts.map +1 -0
- package/dist/authn.js +75 -0
- package/dist/authn.js.map +1 -0
- package/dist/breadcrumbs.d.ts +32 -0
- package/dist/breadcrumbs.d.ts.map +1 -0
- package/dist/breadcrumbs.js +96 -0
- package/dist/breadcrumbs.js.map +1 -0
- package/dist/cards.d.ts +28 -0
- package/dist/cards.d.ts.map +1 -0
- package/dist/cards.js +106 -0
- package/dist/cards.js.map +1 -0
- package/dist/chat.d.ts +50 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +58 -0
- package/dist/chat.js.map +1 -0
- package/dist/client.d.ts +45 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +69 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +76 -0
- package/dist/errors.js.map +1 -0
- package/dist/generated/conformance.d.ts +48 -0
- package/dist/generated/conformance.d.ts.map +1 -0
- package/dist/generated/conformance.js +24 -0
- package/dist/generated/conformance.js.map +1 -0
- package/dist/generated/index.d.ts +34 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +34 -0
- package/dist/generated/index.js.map +1 -0
- package/dist/generated/openapi.d.ts +3900 -0
- package/dist/generated/openapi.d.ts.map +1 -0
- package/dist/generated/openapi.js +6 -0
- package/dist/generated/openapi.js.map +1 -0
- package/dist/grants.d.ts +41 -0
- package/dist/grants.d.ts.map +1 -0
- package/dist/grants.js +50 -0
- package/dist/grants.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/fetch.d.ts +41 -0
- package/dist/internal/fetch.d.ts.map +1 -0
- package/dist/internal/fetch.js +106 -0
- package/dist/internal/fetch.js.map +1 -0
- package/dist/internal/sse.d.ts +82 -0
- package/dist/internal/sse.d.ts.map +1 -0
- package/dist/internal/sse.js +161 -0
- package/dist/internal/sse.js.map +1 -0
- package/dist/types/breadcrumb.d.ts +70 -0
- package/dist/types/breadcrumb.d.ts.map +1 -0
- package/dist/types/breadcrumb.js +8 -0
- package/dist/types/breadcrumb.js.map +1 -0
- package/dist/types/card.d.ts +251 -0
- package/dist/types/card.d.ts.map +1 -0
- package/dist/types/card.js +10 -0
- package/dist/types/card.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/{src/types/index.ts → dist/types/index.js} +1 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +35 -6
- package/src/authn.ts +0 -159
- package/src/breadcrumbs.ts +0 -111
- package/src/capabilities.ts +0 -93
- package/src/cards.ts +0 -109
- package/src/chat.ts +0 -83
- package/src/client.ts +0 -97
- package/src/errors.ts +0 -101
- package/src/files.ts +0 -135
- package/src/grants.ts +0 -99
- package/src/index.ts +0 -103
- package/src/internal/fetch.ts +0 -133
- package/src/internal/sse.ts +0 -236
- package/src/sessions.ts +0 -110
- package/src/types/breadcrumb.ts +0 -77
- package/src/types/card.ts +0 -298
package/dist/cards.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cards module — resolve an `interpret:pending-action` breadcrumb.
|
|
3
|
+
*
|
|
4
|
+
* The card's footer action ids correspond to values the SDK writes
|
|
5
|
+
* to `content.status`. See
|
|
6
|
+
* `packages/docs/guides/06-rendering-cards.md`.
|
|
7
|
+
*/
|
|
8
|
+
import { request } from './internal/fetch.js';
|
|
9
|
+
import { ApiError } from './errors.js';
|
|
10
|
+
export class CardsModule {
|
|
11
|
+
ctx;
|
|
12
|
+
constructor(ctx) {
|
|
13
|
+
this.ctx = ctx;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* PATCH the card breadcrumb with a resolution. Handles optimistic
|
|
17
|
+
* locking transparently — refetches + retries on 409.
|
|
18
|
+
*/
|
|
19
|
+
async resolve(breadcrumbId, resolution) {
|
|
20
|
+
const current = await request(this.ctx, `/v1/breadcrumbs/${breadcrumbId}`);
|
|
21
|
+
const nextContent = {
|
|
22
|
+
...(current.content ?? {}),
|
|
23
|
+
status: resolution.status,
|
|
24
|
+
user_response: resolution.user_response,
|
|
25
|
+
resolved_at: new Date().toISOString(),
|
|
26
|
+
};
|
|
27
|
+
const nextTags = ensureStatusTag(current.tags, resolution.status);
|
|
28
|
+
return request(this.ctx, `/v1/breadcrumbs/${breadcrumbId}`, {
|
|
29
|
+
method: 'PATCH',
|
|
30
|
+
body: {
|
|
31
|
+
version: current.version,
|
|
32
|
+
content: nextContent,
|
|
33
|
+
tags: nextTags,
|
|
34
|
+
},
|
|
35
|
+
maxConflictRetries: 2,
|
|
36
|
+
refetchBeforeRetry: async () => {
|
|
37
|
+
const fresh = await request(this.ctx, `/v1/breadcrumbs/${breadcrumbId}`);
|
|
38
|
+
return {
|
|
39
|
+
body: {
|
|
40
|
+
version: fresh.version,
|
|
41
|
+
content: {
|
|
42
|
+
...(fresh.content ?? {}),
|
|
43
|
+
status: resolution.status,
|
|
44
|
+
user_response: resolution.user_response,
|
|
45
|
+
resolved_at: new Date().toISOString(),
|
|
46
|
+
},
|
|
47
|
+
tags: ensureStatusTag(fresh.tags, resolution.status),
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** Pending cards for the current user's current workspace. */
|
|
54
|
+
async listPending(limit = 50) {
|
|
55
|
+
const list = await request(this.ctx, '/v1/breadcrumbs', {
|
|
56
|
+
query: { tags: 'interpret:pending-action,status:pending', limit },
|
|
57
|
+
});
|
|
58
|
+
return Array.isArray(list) ? list : (list.breadcrumbs ?? []);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Extract the Card object from a breadcrumb's content, normalising
|
|
62
|
+
* over legacy shapes (old breadcrumbs stored `card.type` + flat
|
|
63
|
+
* fields instead of `card.layout` + structured body).
|
|
64
|
+
*/
|
|
65
|
+
static extractCard(bc) {
|
|
66
|
+
const content = (bc.content ?? {});
|
|
67
|
+
const raw = content.card ?? undefined;
|
|
68
|
+
if (!raw)
|
|
69
|
+
return undefined;
|
|
70
|
+
if (typeof raw.layout === 'string')
|
|
71
|
+
return raw;
|
|
72
|
+
// Legacy — fall back to a minimal info card.
|
|
73
|
+
if (typeof raw.type === 'string') {
|
|
74
|
+
const card = {
|
|
75
|
+
layout: legacyTypeToLayout(raw.type),
|
|
76
|
+
header: { title: typeof content.title === 'string' ? content.title : bc.title },
|
|
77
|
+
};
|
|
78
|
+
if (typeof content.summary === 'string') {
|
|
79
|
+
card.body = { text: content.summary };
|
|
80
|
+
}
|
|
81
|
+
return card;
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function ensureStatusTag(existing, status) {
|
|
87
|
+
const withoutStatus = existing.filter((t) => !t.startsWith('status:'));
|
|
88
|
+
withoutStatus.push(`status:${status}`);
|
|
89
|
+
return withoutStatus;
|
|
90
|
+
}
|
|
91
|
+
function legacyTypeToLayout(type) {
|
|
92
|
+
switch (type) {
|
|
93
|
+
case 'connect':
|
|
94
|
+
return 'connect';
|
|
95
|
+
case 'confirm':
|
|
96
|
+
case 'choice':
|
|
97
|
+
case 'multi-choice':
|
|
98
|
+
case 'approval':
|
|
99
|
+
return 'decision';
|
|
100
|
+
case 'text-input':
|
|
101
|
+
return 'input';
|
|
102
|
+
default:
|
|
103
|
+
return 'info';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceM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,EAAE,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE;aAChF,CAAC;YACF,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;gBACxC,IAAI,CAAC,IAAI,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC;YACxC,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAED,SAAS,eAAe,CAAC,QAAkB,EAAE,MAAc;IACzD,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;IACvE,aAAa,CAAC,IAAI,CAAC,UAAU,MAAM,EAAE,CAAC,CAAC;IACvC,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,SAAS,kBAAkB,CAAC,IAAY;IACtC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB,KAAK,SAAS,CAAC;QACf,KAAK,QAAQ,CAAC;QACd,KAAK,cAAc,CAAC;QACpB,KAAK,UAAU;YACb,OAAO,UAAU,CAAC;QACpB,KAAK,YAAY;YACf,OAAO,OAAO,CAAC;QACjB;YACE,OAAO,MAAM,CAAC;IAClB,CAAC;AACH,CAAC"}
|
package/dist/chat.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chat module — `POST /v1/chat` + per-session / global SSE streams.
|
|
3
|
+
*
|
|
4
|
+
* See `packages/docs/guides/03-chat-and-sse.md`.
|
|
5
|
+
*/
|
|
6
|
+
import type { FetchContext } from './internal/fetch.js';
|
|
7
|
+
import type { SseConnection, SseConnectConfig, SseHandlers } from './internal/sse.js';
|
|
8
|
+
export interface SendChatRequest {
|
|
9
|
+
message: string;
|
|
10
|
+
/** The agent to route this turn to. `life-coordinator` by default in the Ritual bundle. */
|
|
11
|
+
target_agent: string;
|
|
12
|
+
/** Resume an existing session; omit to start a new one. */
|
|
13
|
+
session_id?: string;
|
|
14
|
+
/** Extra tags stamped on the user's message breadcrumb. */
|
|
15
|
+
extra_tags?: string[];
|
|
16
|
+
}
|
|
17
|
+
export interface SendChatResponse {
|
|
18
|
+
id: string;
|
|
19
|
+
session_id: string;
|
|
20
|
+
}
|
|
21
|
+
export interface SseStreamOptions {
|
|
22
|
+
/** Override the EventSource constructor (required in React Native). */
|
|
23
|
+
eventSource?: SseConnectConfig['eventSource'];
|
|
24
|
+
useHeaderAuth?: boolean;
|
|
25
|
+
maxBackoffMs?: number;
|
|
26
|
+
/** Supply a Last-Event-ID-style resume token if your server supports it. */
|
|
27
|
+
last_event_id?: string;
|
|
28
|
+
}
|
|
29
|
+
export declare class ChatModule {
|
|
30
|
+
private readonly ctx;
|
|
31
|
+
constructor(ctx: FetchContext);
|
|
32
|
+
/**
|
|
33
|
+
* Send a user message to an agent. Returns immediately with the
|
|
34
|
+
* breadcrumb id + session id. The agent reply arrives via the SSE
|
|
35
|
+
* stream — call `stream(session_id)` before posting, not after.
|
|
36
|
+
*/
|
|
37
|
+
send(req: SendChatRequest): Promise<SendChatResponse>;
|
|
38
|
+
/** Per-session SSE — just this session's events. Recommended for chat views. */
|
|
39
|
+
sessionStream(sessionId: string, handlers: SseHandlers, options?: SseStreamOptions): SseConnection;
|
|
40
|
+
/** Global SSE — everything the user can see. Useful for home feeds / awaiting-you. */
|
|
41
|
+
globalStream(handlers: SseHandlers, options?: SseStreamOptions): SseConnection;
|
|
42
|
+
private buildConfig;
|
|
43
|
+
/**
|
|
44
|
+
* Clear a session's suspend flag after the loop detector fired.
|
|
45
|
+
*
|
|
46
|
+
* @see `packages/docs/operations/loop-detector.md`
|
|
47
|
+
*/
|
|
48
|
+
resumeSession(sessionId: string): Promise<void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AC,WAAW;IAcnB;;;;OAIG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGtD"}
|
package/dist/chat.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chat module — `POST /v1/chat` + per-session / global SSE streams.
|
|
3
|
+
*
|
|
4
|
+
* See `packages/docs/guides/03-chat-and-sse.md`.
|
|
5
|
+
*/
|
|
6
|
+
import { request } from './internal/fetch.js';
|
|
7
|
+
import { connect as sseConnect } from './internal/sse.js';
|
|
8
|
+
export class ChatModule {
|
|
9
|
+
ctx;
|
|
10
|
+
constructor(ctx) {
|
|
11
|
+
this.ctx = ctx;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Send a user message to an agent. Returns immediately with the
|
|
15
|
+
* breadcrumb id + session id. The agent reply arrives via the SSE
|
|
16
|
+
* stream — call `stream(session_id)` before posting, not after.
|
|
17
|
+
*/
|
|
18
|
+
async send(req) {
|
|
19
|
+
return request(this.ctx, '/v1/chat', {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
body: req,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/** Per-session SSE — just this session's events. Recommended for chat views. */
|
|
25
|
+
sessionStream(sessionId, handlers, options = {}) {
|
|
26
|
+
return sseConnect(this.buildConfig(`/v1/sessions/${sessionId}/stream`, options), handlers);
|
|
27
|
+
}
|
|
28
|
+
/** Global SSE — everything the user can see. Useful for home feeds / awaiting-you. */
|
|
29
|
+
globalStream(handlers, options = {}) {
|
|
30
|
+
return sseConnect(this.buildConfig('/v1/events', options), handlers);
|
|
31
|
+
}
|
|
32
|
+
buildConfig(path, options) {
|
|
33
|
+
const config = {
|
|
34
|
+
apiUrl: this.ctx.apiUrl,
|
|
35
|
+
path,
|
|
36
|
+
tenantId: this.ctx.tenantId,
|
|
37
|
+
getToken: () => this.ctx.tokenProvider.getIdToken(),
|
|
38
|
+
};
|
|
39
|
+
if (options.eventSource)
|
|
40
|
+
config.eventSource = options.eventSource;
|
|
41
|
+
if (options.useHeaderAuth !== undefined)
|
|
42
|
+
config.useHeaderAuth = options.useHeaderAuth;
|
|
43
|
+
if (options.maxBackoffMs !== undefined)
|
|
44
|
+
config.maxBackoffMs = options.maxBackoffMs;
|
|
45
|
+
if (options.last_event_id)
|
|
46
|
+
config.query = { last_event_id: options.last_event_id };
|
|
47
|
+
return config;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Clear a session's suspend flag after the loop detector fired.
|
|
51
|
+
*
|
|
52
|
+
* @see `packages/docs/operations/loop-detector.md`
|
|
53
|
+
*/
|
|
54
|
+
async resumeSession(sessionId) {
|
|
55
|
+
await request(this.ctx, `/v1/sessions/${sessionId}/resume`, { method: 'POST' });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=chat.js.map
|
package/dist/chat.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../src/chat.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAC;AA0B1D,MAAM,OAAO,UAAU;IACQ;IAA7B,YAA6B,GAAiB;QAAjB,QAAG,GAAH,GAAG,CAAc;IAAG,CAAC;IAElD;;;;OAIG;IACH,KAAK,CAAC,IAAI,CAAC,GAAoB;QAC7B,OAAO,OAAO,CAAmB,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE;YACrD,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,GAAG;SACV,CAAC,CAAC;IACL,CAAC;IAED,gFAAgF;IAChF,aAAa,CAAC,SAAiB,EAAE,QAAqB,EAAE,UAA4B,EAAE;QACpF,OAAO,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,SAAS,SAAS,EAAE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tClient, staticTokenProvider } from '@possibl/rcrt-sdk';
|
|
5
|
+
*
|
|
6
|
+
* const rcrt = new RcrtClient({
|
|
7
|
+
* apiUrl: 'https://rcrt-api-gateway-<hash>.run.app',
|
|
8
|
+
* tokenProvider: firebaseTokenProvider(auth),
|
|
9
|
+
* });
|
|
10
|
+
*
|
|
11
|
+
* rcrt.setTenantId(workspaceId);
|
|
12
|
+
* const me = await rcrt.auth.me();
|
|
13
|
+
* const stream = rcrt.chat.sessionStream(sessionId, { ...handlers });
|
|
14
|
+
*
|
|
15
|
+
* Every module on the client shares the same fetch context — one
|
|
16
|
+
* bearer refresh path, one tenant header, one error envelope.
|
|
17
|
+
*/
|
|
18
|
+
import type { TokenProvider } from './auth.js';
|
|
19
|
+
import { BreadcrumbsModule } from './breadcrumbs.js';
|
|
20
|
+
import { ChatModule } from './chat.js';
|
|
21
|
+
import { CardsModule } from './cards.js';
|
|
22
|
+
import { GrantsModule } from './grants.js';
|
|
23
|
+
import { IdentityModule } from './authn.js';
|
|
24
|
+
export interface RcrtClientConfig {
|
|
25
|
+
apiUrl: string;
|
|
26
|
+
tokenProvider: TokenProvider;
|
|
27
|
+
/** Optional workspace UUID. Can be set later via `setTenantId()`. */
|
|
28
|
+
tenantId?: string;
|
|
29
|
+
/** Optional fetch override (SSR, custom retry, mock). */
|
|
30
|
+
fetchImpl?: typeof fetch;
|
|
31
|
+
}
|
|
32
|
+
export declare class RcrtClient {
|
|
33
|
+
private readonly ctx;
|
|
34
|
+
readonly auth: IdentityModule;
|
|
35
|
+
readonly breadcrumbs: BreadcrumbsModule;
|
|
36
|
+
readonly chat: ChatModule;
|
|
37
|
+
readonly cards: CardsModule;
|
|
38
|
+
readonly grants: GrantsModule;
|
|
39
|
+
constructor(config: RcrtClientConfig);
|
|
40
|
+
/** Switch workspaces. Subsequent requests carry the new `X-Tenant-ID`. */
|
|
41
|
+
setTenantId(tenantId: string | null): void;
|
|
42
|
+
/** Read the workspace id this client is currently scoped to. */
|
|
43
|
+
getTenantId(): string | null;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5C,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,aAAa,CAAC;IAC7B,qEAAqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yDAAyD;IACzD,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IAEnC,SAAgB,IAAI,EAAE,cAAc,CAAC;IACrC,SAAgB,WAAW,EAAE,iBAAiB,CAAC;IAC/C,SAAgB,IAAI,EAAE,UAAU,CAAC;IACjC,SAAgB,KAAK,EAAE,WAAW,CAAC;IACnC,SAAgB,MAAM,EAAE,YAAY,CAAC;gBAEzB,MAAM,EAAE,gBAAgB;IAiCpC,0EAA0E;IAC1E,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAI1C,gEAAgE;IAChE,WAAW,IAAI,MAAM,GAAG,IAAI;CAG7B"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RcrtClient — the single entry-point to the SDK.
|
|
3
|
+
*
|
|
4
|
+
* import { RcrtClient, staticTokenProvider } from '@possibl/rcrt-sdk';
|
|
5
|
+
*
|
|
6
|
+
* const rcrt = new RcrtClient({
|
|
7
|
+
* apiUrl: 'https://rcrt-api-gateway-<hash>.run.app',
|
|
8
|
+
* tokenProvider: firebaseTokenProvider(auth),
|
|
9
|
+
* });
|
|
10
|
+
*
|
|
11
|
+
* rcrt.setTenantId(workspaceId);
|
|
12
|
+
* const me = await rcrt.auth.me();
|
|
13
|
+
* const stream = rcrt.chat.sessionStream(sessionId, { ...handlers });
|
|
14
|
+
*
|
|
15
|
+
* Every module on the client shares the same fetch context — one
|
|
16
|
+
* bearer refresh path, one tenant header, one error envelope.
|
|
17
|
+
*/
|
|
18
|
+
import { BreadcrumbsModule } from './breadcrumbs.js';
|
|
19
|
+
import { ChatModule } from './chat.js';
|
|
20
|
+
import { CardsModule } from './cards.js';
|
|
21
|
+
import { GrantsModule } from './grants.js';
|
|
22
|
+
import { IdentityModule } from './authn.js';
|
|
23
|
+
import { SdkError } from './errors.js';
|
|
24
|
+
export class RcrtClient {
|
|
25
|
+
ctx;
|
|
26
|
+
auth;
|
|
27
|
+
breadcrumbs;
|
|
28
|
+
chat;
|
|
29
|
+
cards;
|
|
30
|
+
grants;
|
|
31
|
+
constructor(config) {
|
|
32
|
+
if (!config.apiUrl) {
|
|
33
|
+
throw new SdkError('MISSING_API_URL', 'RcrtClient requires `apiUrl`');
|
|
34
|
+
}
|
|
35
|
+
if (!config.tokenProvider) {
|
|
36
|
+
throw new SdkError('MISSING_TOKEN_PROVIDER', 'RcrtClient requires a `tokenProvider`');
|
|
37
|
+
}
|
|
38
|
+
const ctxInternal = {
|
|
39
|
+
apiUrl: config.apiUrl,
|
|
40
|
+
tenantId: config.tenantId ?? null,
|
|
41
|
+
tokenProvider: config.tokenProvider,
|
|
42
|
+
fetchImpl: config.fetchImpl ?? undefined,
|
|
43
|
+
};
|
|
44
|
+
// Use a Proxy so module instances can read the current `tenantId`
|
|
45
|
+
// at request time without us having to rebuild them on every
|
|
46
|
+
// `setTenantId` call.
|
|
47
|
+
this.ctx = new Proxy({}, {
|
|
48
|
+
get: (_target, prop) => ctxInternal[prop],
|
|
49
|
+
set: (_target, prop, value) => {
|
|
50
|
+
ctxInternal[prop] = value;
|
|
51
|
+
return true;
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
this.auth = new IdentityModule(this.ctx);
|
|
55
|
+
this.breadcrumbs = new BreadcrumbsModule(this.ctx);
|
|
56
|
+
this.chat = new ChatModule(this.ctx);
|
|
57
|
+
this.cards = new CardsModule(this.ctx);
|
|
58
|
+
this.grants = new GrantsModule(this.ctx);
|
|
59
|
+
}
|
|
60
|
+
/** Switch workspaces. Subsequent requests carry the new `X-Tenant-ID`. */
|
|
61
|
+
setTenantId(tenantId) {
|
|
62
|
+
this.ctx.tenantId = tenantId;
|
|
63
|
+
}
|
|
64
|
+
/** Read the workspace id this client is currently scoped to. */
|
|
65
|
+
getTenantId() {
|
|
66
|
+
return this.ctx.tenantId;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAWvC,MAAM,OAAO,UAAU;IACJ,GAAG,CAAe;IAEnB,IAAI,CAAiB;IACrB,WAAW,CAAoB;IAC/B,IAAI,CAAa;IACjB,KAA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IAAI,CAAC,GAAG,CAAC,CAAC;IAC3C,CAAC;IAED,0EAA0E;IAC1E,WAAW,CAAC,QAAuB;QAChC,IAAI,CAAC,GAA8C,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3E,CAAC;IAED,gEAAgE;IAChE,WAAW;QACT,OAAQ,IAAI,CAAC,GAA8C,CAAC,QAAQ,CAAC;IACvE,CAAC;CACF"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error taxonomy.
|
|
3
|
+
*
|
|
4
|
+
* The RCRT backend is mid-migration from a flat `{"error": "string"}`
|
|
5
|
+
* envelope to a typed `{"error": {"code", "message", "details"}}`
|
|
6
|
+
* shape. This module normalises both into one `ApiError` that app
|
|
7
|
+
* code can switch on.
|
|
8
|
+
*
|
|
9
|
+
* See `packages/docs/guides/07-error-handling.md`.
|
|
10
|
+
*/
|
|
11
|
+
/** Stable machine-readable error codes recognised by the SDK. */
|
|
12
|
+
export type KnownErrorCode = 'UNAUTHORIZED' | 'FORBIDDEN' | 'NOT_FOUND' | 'CONFLICT' | 'INVALID_REQUEST' | 'TOO_MANY_REQUESTS' | 'INTERNAL' | 'SERVICE_UNAVAILABLE' | 'UNKNOWN';
|
|
13
|
+
export interface ApiErrorDetail {
|
|
14
|
+
/** Machine-readable code if the server sent one. Otherwise derived from status. */
|
|
15
|
+
code: KnownErrorCode | string;
|
|
16
|
+
message: string;
|
|
17
|
+
details?: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
export declare class ApiError extends Error {
|
|
20
|
+
readonly status: number;
|
|
21
|
+
readonly detail: ApiErrorDetail;
|
|
22
|
+
readonly rawBody: string | undefined;
|
|
23
|
+
constructor(status: number, detail: ApiErrorDetail, rawBody?: string);
|
|
24
|
+
static fromResponse(status: number, rawBody: string): ApiError;
|
|
25
|
+
}
|
|
26
|
+
/** Errors thrown by the SDK before we even reach the server. */
|
|
27
|
+
export declare class SdkError extends Error {
|
|
28
|
+
readonly code: string;
|
|
29
|
+
constructor(code: string, message: string);
|
|
30
|
+
}
|
|
31
|
+
export declare function parseErrorBody(status: number, rawBody: string): ApiErrorDetail;
|
|
32
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,iEAAiE;AACjE,MAAM,MAAM,cAAc,GACtB,cAAc,GACd,WAAW,GACX,WAAW,GACX,UAAU,GACV,iBAAiB,GACjB,mBAAmB,GACnB,UAAU,GACV,qBAAqB,GACrB,SAAS,CAAC;AAEd,MAAM,WAAW,cAAc;IAC7B,mFAAmF;IACnF,IAAI,EAAE,cAAc,GAAG,MAAM,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,qBAAa,QAAS,SAAQ,KAAK;IACjC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,MAAM,EAAE,cAAc,CAAC;IACvC,SAAgB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;gBAEhC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,MAAM;IAQpE,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ;CAG/D;AAED,gEAAgE;AAChE,qBAAa,QAAS,SAAQ,KAAK;IACjC,SAAgB,IAAI,EAAE,MAAM,CAAC;gBAEjB,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK1C;AAeD,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,cAAc,CA4B9E"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error taxonomy.
|
|
3
|
+
*
|
|
4
|
+
* The RCRT backend is mid-migration from a flat `{"error": "string"}`
|
|
5
|
+
* envelope to a typed `{"error": {"code", "message", "details"}}`
|
|
6
|
+
* shape. This module normalises both into one `ApiError` that app
|
|
7
|
+
* code can switch on.
|
|
8
|
+
*
|
|
9
|
+
* See `packages/docs/guides/07-error-handling.md`.
|
|
10
|
+
*/
|
|
11
|
+
export class ApiError extends Error {
|
|
12
|
+
status;
|
|
13
|
+
detail;
|
|
14
|
+
rawBody;
|
|
15
|
+
constructor(status, detail, rawBody) {
|
|
16
|
+
super(detail.message);
|
|
17
|
+
this.name = 'ApiError';
|
|
18
|
+
this.status = status;
|
|
19
|
+
this.detail = detail;
|
|
20
|
+
this.rawBody = rawBody;
|
|
21
|
+
}
|
|
22
|
+
static fromResponse(status, rawBody) {
|
|
23
|
+
return new ApiError(status, parseErrorBody(status, rawBody), rawBody);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Errors thrown by the SDK before we even reach the server. */
|
|
27
|
+
export class SdkError extends Error {
|
|
28
|
+
code;
|
|
29
|
+
constructor(code, message) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = 'SdkError';
|
|
32
|
+
this.code = code;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// ── Internal helpers ─────────────────────────────────────────────
|
|
36
|
+
const STATUS_TO_CODE = {
|
|
37
|
+
400: 'INVALID_REQUEST',
|
|
38
|
+
401: 'UNAUTHORIZED',
|
|
39
|
+
403: 'FORBIDDEN',
|
|
40
|
+
404: 'NOT_FOUND',
|
|
41
|
+
409: 'CONFLICT',
|
|
42
|
+
429: 'TOO_MANY_REQUESTS',
|
|
43
|
+
500: 'INTERNAL',
|
|
44
|
+
503: 'SERVICE_UNAVAILABLE',
|
|
45
|
+
};
|
|
46
|
+
export function parseErrorBody(status, rawBody) {
|
|
47
|
+
const fallbackCode = STATUS_TO_CODE[status] ?? 'UNKNOWN';
|
|
48
|
+
if (!rawBody.trim()) {
|
|
49
|
+
return { code: fallbackCode, message: `HTTP ${status}` };
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const parsed = JSON.parse(rawBody);
|
|
53
|
+
if (parsed && typeof parsed === 'object' && 'error' in parsed) {
|
|
54
|
+
const err = parsed.error;
|
|
55
|
+
if (typeof err === 'string') {
|
|
56
|
+
return { code: fallbackCode, message: err };
|
|
57
|
+
}
|
|
58
|
+
if (err && typeof err === 'object') {
|
|
59
|
+
const e = err;
|
|
60
|
+
const detail = {
|
|
61
|
+
code: typeof e.code === 'string' ? e.code : fallbackCode,
|
|
62
|
+
message: typeof e.message === 'string' ? e.message : `HTTP ${status}`,
|
|
63
|
+
};
|
|
64
|
+
if (typeof e.details === 'object' && e.details !== null) {
|
|
65
|
+
detail.details = e.details;
|
|
66
|
+
}
|
|
67
|
+
return detail;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return { code: fallbackCode, message: rawBody.slice(0, 200) };
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return { code: fallbackCode, message: rawBody.slice(0, 200) };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAqBH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjB,MAAM,CAAS;IACf,MAAM,CAAiB;IACvB,OAAO,CAAqB;IAE5C,YAAY,MAAc,EAAE,MAAsB,EAAE,OAAgB;QAClE,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAA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AAI,EAAE,YAAY,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;YAC9C,CAAC;YACD,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;gBACnC,MAAM,CAAC,GAAG,GAA8B,CAAC;gBACzC,MAAM,MAAM,GAAmB;oBAC7B,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY;oBACxD,OAAO,EAAE,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,MAAM,EAAE;iBACtE,CAAC;gBACF,IAAI,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ,IAAI,CAAC,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;oBACxD,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC,OAAkC,CAAC;gBACxD,CAAC;gBACD,OAAO,MAAM,CAAC;YAChB,CAAC;QACH,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;IAChE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;IAChE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract conformance guardrail.
|
|
3
|
+
*
|
|
4
|
+
* Asserts at compile time that the hand-written domain types in
|
|
5
|
+
* `@possibl/rcrt-sdk/types` are structurally compatible with the
|
|
6
|
+
* OpenAPI spec. If the spec drifts (new required field, renamed prop,
|
|
7
|
+
* changed enum) without a matching hand-written update, `tsc` fails
|
|
8
|
+
* here and the PR is blocked until the two are re-aligned.
|
|
9
|
+
*
|
|
10
|
+
* The asserts are one-directional. They check that our domain shape
|
|
11
|
+
* ⊇ the wire shape (we accept everything the server sends). We do
|
|
12
|
+
* NOT check the reverse — by design, hand-written types can be richer
|
|
13
|
+
* (flexible rows, normalised error envelope, etc.).
|
|
14
|
+
*
|
|
15
|
+
* If this file fails to compile:
|
|
16
|
+
* - Read the error message carefully — it points at the specific
|
|
17
|
+
* property that diverged.
|
|
18
|
+
* - Either update the hand-written type to accept the new shape, or
|
|
19
|
+
* update the OpenAPI spec if the code changed first (more common).
|
|
20
|
+
* - Re-run `pnpm run codegen` and commit the regenerated
|
|
21
|
+
* `src/generated/openapi.ts` in the same PR.
|
|
22
|
+
*/
|
|
23
|
+
import type { components } from './openapi.js';
|
|
24
|
+
import type { Card, Breadcrumb } from '../types/index.js';
|
|
25
|
+
/**
|
|
26
|
+
* Compile-time assertion that `Got` extends `Expected`.
|
|
27
|
+
* Produces a type error at the `_check_*` declaration if not.
|
|
28
|
+
*/
|
|
29
|
+
type AssertExtends<Got, Expected> = Got extends Expected ? true : never;
|
|
30
|
+
/**
|
|
31
|
+
* Our hand-written `Card` must accept every property required by the
|
|
32
|
+
* spec's `components.schemas.Card`. If you see an error here, the spec
|
|
33
|
+
* gained a required field that our type doesn't model. Update the type
|
|
34
|
+
* (preferred) or relax the spec.
|
|
35
|
+
*
|
|
36
|
+
* We use Pick<…, X> so the assertion only covers the fields we've
|
|
37
|
+
* explicitly opted into. Ignoring fields we don't surface (e.g. legacy
|
|
38
|
+
* spec-level extras) is intentional.
|
|
39
|
+
*/
|
|
40
|
+
type _check_card_layout = AssertExtends<Pick<Card, 'layout' | 'header'>, Pick<components['schemas']['Card'], 'layout' | 'header'>>;
|
|
41
|
+
/**
|
|
42
|
+
* Breadcrumb.content is an open `Record<string, unknown>` — intentional.
|
|
43
|
+
* Only check the metadata fields that are load-bearing for the SDK.
|
|
44
|
+
*/
|
|
45
|
+
type _check_breadcrumb_core = AssertExtends<Pick<Breadcrumb, 'id' | 'tags' | 'content'>, Pick<components['schemas']['Breadcrumb'], 'id' | 'tags' | 'content'>>;
|
|
46
|
+
export type __conformanceGuards = [_check_card_layout, _check_breadcrumb_core];
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=conformance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conformance.d.ts","sourceRoot":"","sources":["../../src/generated/conformance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI1D;;;GAGG;AACH,KAAK,aAAa,CAAC,GAAG,EAAE,QAAQ,IAAI,GAAG,SAAS,QAAQ,GAAG,IAAI,GAAG,KAAK,CAAC;AAIxE;;;;;;;;;GASG;AACH,KAAK,kBAAkB,GAAG,aAAa,CACrC,IAAI,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC,EAC/B,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC,CACzD,CAAC;AAEF;;;GAGG;AACH,KAAK,sBAAsB,GAAG,aAAa,CACzC,IAAI,CAAC,UAAU,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAAC,EAC3C,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAAC,CACrE,CAAC;AAGF,MAAM,MAAM,mBAAmB,GAAG,CAAC,kBAAkB,EAAE,sBAAsB,CAAC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract conformance guardrail.
|
|
3
|
+
*
|
|
4
|
+
* Asserts at compile time that the hand-written domain types in
|
|
5
|
+
* `@possibl/rcrt-sdk/types` are structurally compatible with the
|
|
6
|
+
* OpenAPI spec. If the spec drifts (new required field, renamed prop,
|
|
7
|
+
* changed enum) without a matching hand-written update, `tsc` fails
|
|
8
|
+
* here and the PR is blocked until the two are re-aligned.
|
|
9
|
+
*
|
|
10
|
+
* The asserts are one-directional. They check that our domain shape
|
|
11
|
+
* ⊇ the wire shape (we accept everything the server sends). We do
|
|
12
|
+
* NOT check the reverse — by design, hand-written types can be richer
|
|
13
|
+
* (flexible rows, normalised error envelope, etc.).
|
|
14
|
+
*
|
|
15
|
+
* If this file fails to compile:
|
|
16
|
+
* - Read the error message carefully — it points at the specific
|
|
17
|
+
* property that diverged.
|
|
18
|
+
* - Either update the hand-written type to accept the new shape, or
|
|
19
|
+
* update the OpenAPI spec if the code changed first (more common).
|
|
20
|
+
* - Re-run `pnpm run codegen` and commit the regenerated
|
|
21
|
+
* `src/generated/openapi.ts` in the same PR.
|
|
22
|
+
*/
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=conformance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conformance.js","sourceRoot":"","sources":["../../src/generated/conformance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated OpenAPI types.
|
|
3
|
+
*
|
|
4
|
+
* This module is produced by `pnpm run codegen` against
|
|
5
|
+
* `packages/docs/openapi/v1.yaml` — the hand-maintained API contract.
|
|
6
|
+
* Do NOT edit the generated file by hand. Edit the spec, then regenerate.
|
|
7
|
+
*
|
|
8
|
+
* ## When to use these types
|
|
9
|
+
*
|
|
10
|
+
* - **Raw fetch-level type safety** — e.g. you're bypassing the `RcrtClient`
|
|
11
|
+
* and calling the HTTP endpoints directly. Use `paths`, `operations`, or
|
|
12
|
+
* `components` to type request bodies + response shapes.
|
|
13
|
+
* - **Contract conformance checks** — asserting at compile time that a
|
|
14
|
+
* hand-written type is a structural subset of the wire shape.
|
|
15
|
+
*
|
|
16
|
+
* ## When NOT to use these types
|
|
17
|
+
*
|
|
18
|
+
* - **Domain modelling in app code.** Prefer the hand-written types in
|
|
19
|
+
* `@possibl/rcrt-sdk/types` (`Card`, `Breadcrumb`, `Row`, `ChartSpec`).
|
|
20
|
+
* They are richer: documented flexibly (e.g. `FlexibleTextRow`),
|
|
21
|
+
* discriminated-union-friendly, and wear the `ApiErrorDetail` shape
|
|
22
|
+
* normalised across both the canonical and legacy error envelopes.
|
|
23
|
+
*
|
|
24
|
+
* ## Usage
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* import type { components, operations } from '@possibl/rcrt-sdk/generated';
|
|
28
|
+
*
|
|
29
|
+
* type RawCard = components['schemas']['Card'];
|
|
30
|
+
* type ChatRequest = operations['post_v1_chat']['requestBody']['content']['application/json'];
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export type { paths, components, operations, webhooks } from './openapi.js';
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generated/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated OpenAPI types.
|
|
3
|
+
*
|
|
4
|
+
* This module is produced by `pnpm run codegen` against
|
|
5
|
+
* `packages/docs/openapi/v1.yaml` — the hand-maintained API contract.
|
|
6
|
+
* Do NOT edit the generated file by hand. Edit the spec, then regenerate.
|
|
7
|
+
*
|
|
8
|
+
* ## When to use these types
|
|
9
|
+
*
|
|
10
|
+
* - **Raw fetch-level type safety** — e.g. you're bypassing the `RcrtClient`
|
|
11
|
+
* and calling the HTTP endpoints directly. Use `paths`, `operations`, or
|
|
12
|
+
* `components` to type request bodies + response shapes.
|
|
13
|
+
* - **Contract conformance checks** — asserting at compile time that a
|
|
14
|
+
* hand-written type is a structural subset of the wire shape.
|
|
15
|
+
*
|
|
16
|
+
* ## When NOT to use these types
|
|
17
|
+
*
|
|
18
|
+
* - **Domain modelling in app code.** Prefer the hand-written types in
|
|
19
|
+
* `@possibl/rcrt-sdk/types` (`Card`, `Breadcrumb`, `Row`, `ChartSpec`).
|
|
20
|
+
* They are richer: documented flexibly (e.g. `FlexibleTextRow`),
|
|
21
|
+
* discriminated-union-friendly, and wear the `ApiErrorDetail` shape
|
|
22
|
+
* normalised across both the canonical and legacy error envelopes.
|
|
23
|
+
*
|
|
24
|
+
* ## Usage
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* import type { components, operations } from '@possibl/rcrt-sdk/generated';
|
|
28
|
+
*
|
|
29
|
+
* type RawCard = components['schemas']['Card'];
|
|
30
|
+
* type ChatRequest = operations['post_v1_chat']['requestBody']['content']['application/json'];
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generated/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG"}
|