@krischoichoi/channel-web 0.6.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.
@@ -0,0 +1,149 @@
1
+ /**
2
+ * dsh-channels host API v2 control-plane routes (M4-M5 host side).
3
+ *
4
+ * Lives on `/dsh-channels/api/v2` and delegates every operation to the
5
+ * ChannelControlService (doc §28–§33). This is deliberately a THIN layer:
6
+ *
7
+ * ```text
8
+ * HTTP → validate (strict schema) → ChannelControlLike → serialize public DTO
9
+ * ```
10
+ *
11
+ * The web layer never knows credential ref names: setup descriptors carry
12
+ * credential fields, and `saveCredential` maps a field name to its ref
13
+ * server-side (doc §31). Secret values are never echoed — the credential PUT
14
+ * returns only `{ configured, writable }`.
15
+ *
16
+ * The service is injected as a structural seam ([ChannelControlLike]) so this
17
+ * package ships no hard dependency on the concrete control-plane plugin; when
18
+ * the seam is absent (standalone web profile) the caller registers a 503 stub
19
+ * instead.
20
+ */
21
+ import type { AuthBeginInput, AuthInput, BundleUpdateStatus, ChannelAccessState, ChannelSetupDescriptor, ChannelSetupInput, ChannelSetupResult, ChannelSummary, ConfiguredState, PublicAuthSession, PublicAuthStatus, PublicConversationIdentity, PublicOwnerClaimSession } from '@krischoichoi/channel-control';
22
+ import type { ChannelAccessPolicy } from '@krischoichoi/channel-core';
23
+ import { z } from 'zod';
24
+ /** Minimal structural view of the ChannelControlService surface we consume. */
25
+ export interface ChannelControlLike {
26
+ listChannels(): Promise<ChannelSummary[]>;
27
+ getSetup(channelId: string): Promise<ChannelSetupDescriptor>;
28
+ getConfiguredState(channelId: string): Promise<ConfiguredState>;
29
+ setEnabled(channelId: string, enabled: boolean): Promise<ChannelSummary>;
30
+ saveConfig(channelId: string, patch: Record<string, unknown>): Promise<void>;
31
+ describeCredential(channelId: string, field: string): Promise<{
32
+ configured: boolean;
33
+ writable: boolean;
34
+ source?: string;
35
+ }>;
36
+ saveCredential(channelId: string, field: string, value: string): Promise<{
37
+ configured: boolean;
38
+ writable: boolean;
39
+ }>;
40
+ applySetup(channelId: string, input: ChannelSetupInput): Promise<ChannelSetupResult>;
41
+ beginAuth(channelId: string, input: AuthBeginInput): Promise<PublicAuthSession>;
42
+ pollAuth(sessionId: string): Promise<PublicAuthStatus>;
43
+ submitAuthInput(sessionId: string, input: AuthInput): Promise<PublicAuthStatus>;
44
+ cancelAuth(sessionId: string): Promise<void>;
45
+ getAccess(channelId: string, accountId?: string): Promise<ChannelAccessState>;
46
+ saveAccess(channelId: string, policy: ChannelAccessPolicy, accountId?: string): Promise<ChannelAccessState>;
47
+ beginOwnerClaim(channelId: string, accountId?: string): Promise<PublicOwnerClaimSession>;
48
+ getOwnerClaim(channelId: string, claimId: string): Promise<PublicOwnerClaimSession>;
49
+ confirmOwnerClaim(channelId: string, claimId: string): Promise<ChannelAccessState>;
50
+ cancelOwnerClaim(channelId: string, claimId: string): Promise<void>;
51
+ listConversations(channelId: string, accountId?: string): Promise<PublicConversationIdentity[]>;
52
+ findConversation(channelId: string, externalId: string, accountId?: string): Promise<PublicConversationIdentity | undefined>;
53
+ getUpdateStatus(): Promise<BundleUpdateStatus>;
54
+ }
55
+ export interface ApiResultV2 {
56
+ status: number;
57
+ body: unknown;
58
+ }
59
+ export declare class ChannelApiV2 {
60
+ private readonly control;
61
+ constructor(control: ChannelControlLike);
62
+ /**
63
+ * Resolve whether a channel id exists (via the setup descriptor). Returns a
64
+ * 404 result for unknown channels so every channel-scoped endpoint reports a
65
+ * stable code.
66
+ */
67
+ private channelOr404;
68
+ /** GET /channels → { channels: ChannelSummary[] } (doc §29). */
69
+ listChannels(): Promise<ApiResultV2>;
70
+ /**
71
+ * GET /update-check → BundleUpdateStatus. Panel-level read-only DTO (no
72
+ * secrets); the host performs the registry check so the browser never
73
+ * contacts npm itself.
74
+ */
75
+ getUpdateCheck(): Promise<ApiResultV2>;
76
+ /** GET /channels/:channelId/setup → ChannelSetupDescriptor (doc §29). */
77
+ getSetup(channelId: string): Promise<ApiResultV2>;
78
+ /**
79
+ * PUT /channels/:channelId/enabled → ChannelSummary (doc §23).
80
+ * Body: `{ enabled: boolean }`. The control plane persists the intent and
81
+ * starts/stops the runtime accordingly.
82
+ */
83
+ setEnabled(channelId: string, body: unknown): Promise<ApiResultV2>;
84
+ /** PUT /channels/:channelId/setup → save the whole form and reconcile. */
85
+ applySetup(channelId: string, body: unknown): Promise<ApiResultV2>;
86
+ /** PATCH /channels/:channelId/config → { configured, fields } (doc §30). */
87
+ saveConfig(channelId: string, body: unknown): Promise<ApiResultV2>;
88
+ /** PUT /channels/:channelId/credentials/:field → { configured, writable } (doc §31). */
89
+ saveCredential(channelId: string, field: string, body: unknown): Promise<ApiResultV2>;
90
+ /** POST /channels/:channelId/auth/sessions → 201 PublicAuthSession (doc §32). */
91
+ beginAuth(channelId: string, body: unknown): Promise<ApiResultV2>;
92
+ /** GET /channels/:channelId/auth/sessions/:sessionId → PublicAuthStatus (doc §32). */
93
+ pollAuth(channelId: string, sessionId: unknown): Promise<ApiResultV2>;
94
+ /** POST /channels/:channelId/auth/sessions/:sessionId/input → PublicAuthStatus (doc §32). */
95
+ submitInput(channelId: string, sessionId: unknown, body: unknown): Promise<ApiResultV2>;
96
+ /** DELETE /channels/:channelId/auth/sessions/:sessionId → 204 (doc §32). */
97
+ cancelAuth(channelId: string, sessionId: unknown): Promise<ApiResultV2>;
98
+ /** GET /channels/:channelId/access → ChannelAccessState. */
99
+ getAccess(channelId: string): Promise<ApiResultV2>;
100
+ /**
101
+ * PUT /channels/:channelId/access → ChannelAccessState.
102
+ * Body is a strict ChannelAccessPolicy; malformed input is a 400 INVALID_INPUT
103
+ * before it reaches the control plane.
104
+ */
105
+ saveAccess(channelId: string, body: unknown): Promise<ApiResultV2>;
106
+ /** POST /channels/:channelId/access/owner-claims → 201 PublicOwnerClaimSession. */
107
+ beginOwnerClaim(channelId: string): Promise<ApiResultV2>;
108
+ /** GET /channels/:channelId/access/owner-claims/:claimId → PublicOwnerClaimSession. */
109
+ getOwnerClaim(channelId: string, claimId: unknown): Promise<ApiResultV2>;
110
+ /** POST /channels/:channelId/access/owner-claims/:claimId/confirm → ChannelAccessState. */
111
+ confirmOwnerClaim(channelId: string, claimId: unknown): Promise<ApiResultV2>;
112
+ /** DELETE /channels/:channelId/access/owner-claims/:claimId → 204. */
113
+ cancelOwnerClaim(channelId: string, claimId: unknown): Promise<ApiResultV2>;
114
+ /**
115
+ * GET /channels/:channelId/conversations → { conversations } — observed
116
+ * conversation identities (plan §35). Display/mapping metadata only.
117
+ */
118
+ listConversations(channelId: string): Promise<ApiResultV2>;
119
+ /**
120
+ * GET /channels/:channelId/conversations/by-external/:externalId → the one
121
+ * observed identity matching an optional human-facing id, or 404 when
122
+ * the bot has never seen it. Callers must not guess a canonical id.
123
+ */
124
+ findConversation(channelId: string, externalId: unknown): Promise<ApiResultV2>;
125
+ /**
126
+ * Match a path under `/dsh-channels/api/v2` (the prefix is stripped by the
127
+ * caller) and dispatch. Returns 404 for unknown routes.
128
+ */
129
+ handle(method: string, pathname: string, body: unknown): Promise<ApiResultV2>;
130
+ /** PATCH config body: a flat JSON object (never nested). */
131
+ private configPatch;
132
+ /** PUT credentials body: `{ value: string }` (empty string clears). */
133
+ private credentialValue;
134
+ /** PUT setup body: `{ config: object, credentials: Record<string,string> }`. */
135
+ private setupInput;
136
+ /** POST auth/sessions body: `{ method: AuthMethod, accountId?: string }`. */
137
+ private authBeginInput;
138
+ /** POST session/input body: `{ kind: 'verification-code', value: string }`. */
139
+ private authInput;
140
+ }
141
+ /**
142
+ * POST session/input body: `{ kind: 'verification-code', value: string }`.
143
+ * Shared with the v1 routes so both API generations check the same shape.
144
+ */
145
+ export declare const authInputSchema: z.ZodObject<{
146
+ kind: z.ZodLiteral<"verification-code">;
147
+ value: z.ZodString;
148
+ }, z.core.$loose>;
149
+ //# sourceMappingURL=routes-v2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes-v2.d.ts","sourceRoot":"","sources":["../../src/host/routes-v2.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