@kya-os/mcp-i-cloudflare 1.6.62 → 1.7.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/dist/agent.d.ts +4 -2
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +121 -94
- package/dist/agent.js.map +1 -1
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +9 -95
- package/dist/app.js.map +1 -1
- package/dist/services/consent-config.service.d.ts +9 -3
- package/dist/services/consent-config.service.d.ts.map +1 -1
- package/dist/services/consent-config.service.js +90 -100
- package/dist/services/consent-config.service.js.map +1 -1
- package/dist/services/consent-page-renderer.d.ts.map +1 -1
- package/dist/services/consent-page-renderer.js +0 -5
- package/dist/services/consent-page-renderer.js.map +1 -1
- package/dist/services/consent-templates/base/base-template.d.ts +79 -0
- package/dist/services/consent-templates/base/base-template.d.ts.map +1 -0
- package/dist/services/consent-templates/base/base-template.js +283 -0
- package/dist/services/consent-templates/base/base-template.js.map +1 -0
- package/dist/services/consent-templates/base/components.d.ts +120 -0
- package/dist/services/consent-templates/base/components.d.ts.map +1 -0
- package/dist/services/consent-templates/base/components.js +278 -0
- package/dist/services/consent-templates/base/components.js.map +1 -0
- package/dist/services/consent-templates/base/escape.d.ts +53 -0
- package/dist/services/consent-templates/base/escape.d.ts.map +1 -0
- package/dist/services/consent-templates/base/escape.js +115 -0
- package/dist/services/consent-templates/base/escape.js.map +1 -0
- package/dist/services/consent-templates/base/index.d.ts +10 -0
- package/dist/services/consent-templates/base/index.d.ts.map +1 -0
- package/dist/services/consent-templates/base/index.js +10 -0
- package/dist/services/consent-templates/base/index.js.map +1 -0
- package/dist/services/consent-templates/base/styles.d.ts +80 -0
- package/dist/services/consent-templates/base/styles.d.ts.map +1 -0
- package/dist/services/consent-templates/base/styles.js +226 -0
- package/dist/services/consent-templates/base/styles.js.map +1 -0
- package/dist/services/consent-templates/helpers.d.ts +60 -0
- package/dist/services/consent-templates/helpers.d.ts.map +1 -0
- package/dist/services/consent-templates/helpers.js +121 -0
- package/dist/services/consent-templates/helpers.js.map +1 -0
- package/dist/services/consent-templates/index.d.ts +28 -0
- package/dist/services/consent-templates/index.d.ts.map +1 -0
- package/dist/services/consent-templates/index.js +36 -0
- package/dist/services/consent-templates/index.js.map +1 -0
- package/dist/services/consent-templates/modes/consent-only.template.d.ts +36 -0
- package/dist/services/consent-templates/modes/consent-only.template.d.ts.map +1 -0
- package/dist/services/consent-templates/modes/consent-only.template.js +69 -0
- package/dist/services/consent-templates/modes/consent-only.template.js.map +1 -0
- package/dist/services/consent-templates/modes/credentials.template.d.ts +59 -0
- package/dist/services/consent-templates/modes/credentials.template.d.ts.map +1 -0
- package/dist/services/consent-templates/modes/credentials.template.js +393 -0
- package/dist/services/consent-templates/modes/credentials.template.js.map +1 -0
- package/dist/services/consent-templates/modes/index.d.ts +13 -0
- package/dist/services/consent-templates/modes/index.d.ts.map +1 -0
- package/dist/services/consent-templates/modes/index.js +13 -0
- package/dist/services/consent-templates/modes/index.js.map +1 -0
- package/dist/services/consent-templates/modes/magic-link.template.d.ts +33 -0
- package/dist/services/consent-templates/modes/magic-link.template.d.ts.map +1 -0
- package/dist/services/consent-templates/modes/magic-link.template.js +191 -0
- package/dist/services/consent-templates/modes/magic-link.template.js.map +1 -0
- package/dist/services/consent-templates/modes/oauth.template.d.ts +40 -0
- package/dist/services/consent-templates/modes/oauth.template.d.ts.map +1 -0
- package/dist/services/consent-templates/modes/oauth.template.js +151 -0
- package/dist/services/consent-templates/modes/oauth.template.js.map +1 -0
- package/dist/services/consent-templates/modes/otp.template.d.ts +35 -0
- package/dist/services/consent-templates/modes/otp.template.d.ts.map +1 -0
- package/dist/services/consent-templates/modes/otp.template.js +311 -0
- package/dist/services/consent-templates/modes/otp.template.js.map +1 -0
- package/dist/services/consent-templates/registry.d.ts +61 -0
- package/dist/services/consent-templates/registry.d.ts.map +1 -0
- package/dist/services/consent-templates/registry.js +136 -0
- package/dist/services/consent-templates/registry.js.map +1 -0
- package/dist/services/consent-templates/template-renderer.d.ts +118 -0
- package/dist/services/consent-templates/template-renderer.d.ts.map +1 -0
- package/dist/services/consent-templates/template-renderer.js +334 -0
- package/dist/services/consent-templates/template-renderer.js.map +1 -0
- package/dist/services/consent-templates/types.d.ts +194 -0
- package/dist/services/consent-templates/types.d.ts.map +1 -0
- package/dist/services/consent-templates/types.js +23 -0
- package/dist/services/consent-templates/types.js.map +1 -0
- package/dist/services/consent.service.d.ts +9 -0
- package/dist/services/consent.service.d.ts.map +1 -1
- package/dist/services/consent.service.js +50 -6
- package/dist/services/consent.service.js.map +1 -1
- package/package.json +4 -3
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OTP Template
|
|
3
|
+
*
|
|
4
|
+
* One-Time Password authentication via SMS/email.
|
|
5
|
+
*
|
|
6
|
+
* @module consent-templates/modes/otp
|
|
7
|
+
*/
|
|
8
|
+
import { BaseConsentTemplate } from "../base/base-template";
|
|
9
|
+
import { renderInput, renderFullWidthButton, renderErrorContainer, } from "../base/components";
|
|
10
|
+
import { escapeJs, escapeHtml } from "../base/escape";
|
|
11
|
+
/**
|
|
12
|
+
* OTP Template
|
|
13
|
+
*
|
|
14
|
+
* Renders a two-step OTP flow:
|
|
15
|
+
* 1. Phone/email input to request code
|
|
16
|
+
* 2. Code input to verify
|
|
17
|
+
*/
|
|
18
|
+
export class OTPTemplate extends BaseConsentTemplate {
|
|
19
|
+
get authMode() {
|
|
20
|
+
return "otp";
|
|
21
|
+
}
|
|
22
|
+
get otpConfig() {
|
|
23
|
+
return this.config.modeConfig?.otp;
|
|
24
|
+
}
|
|
25
|
+
renderAuthContent() {
|
|
26
|
+
const config = this.otpConfig;
|
|
27
|
+
const digits = config?.digits || 6;
|
|
28
|
+
return `
|
|
29
|
+
<div id="otp-request-container">
|
|
30
|
+
<form id="otp-request-form" class="space-y-4">
|
|
31
|
+
${this.renderPhoneField(config)}
|
|
32
|
+
${renderErrorContainer("otp-request-error")}
|
|
33
|
+
${renderFullWidthButton("Send verification code", "submit")}
|
|
34
|
+
</form>
|
|
35
|
+
</div>
|
|
36
|
+
<div id="otp-verify-container" class="hidden">
|
|
37
|
+
<form id="otp-verify-form" class="space-y-4">
|
|
38
|
+
<div class="text-center mb-4">
|
|
39
|
+
<p class="text-sm text-gray-600">
|
|
40
|
+
${escapeHtml(config?.instructions || `Enter the ${digits}-digit code sent to your phone`)}
|
|
41
|
+
</p>
|
|
42
|
+
</div>
|
|
43
|
+
<div class="flex justify-center gap-2" id="otp-inputs">
|
|
44
|
+
${this.renderOTPInputs(digits)}
|
|
45
|
+
</div>
|
|
46
|
+
${renderErrorContainer("otp-verify-error")}
|
|
47
|
+
${renderFullWidthButton("Verify", "submit")}
|
|
48
|
+
<div class="text-center">
|
|
49
|
+
<button type="button" id="resend-otp" class="text-sm link-primary disabled:opacity-50">
|
|
50
|
+
Resend code
|
|
51
|
+
</button>
|
|
52
|
+
</div>
|
|
53
|
+
</form>
|
|
54
|
+
</div>
|
|
55
|
+
`;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Render phone/email input field.
|
|
59
|
+
*/
|
|
60
|
+
renderPhoneField(config) {
|
|
61
|
+
return renderInput("tel", "phone", config?.phoneLabel || "Phone number", config?.phonePlaceholder || "+1 (555) 123-4567", true, "tel");
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Render OTP digit input boxes.
|
|
65
|
+
*/
|
|
66
|
+
renderOTPInputs(digits) {
|
|
67
|
+
const inputs = [];
|
|
68
|
+
for (let i = 0; i < digits; i++) {
|
|
69
|
+
inputs.push(`
|
|
70
|
+
<input type="text" inputmode="numeric" pattern="[0-9]" maxlength="1"
|
|
71
|
+
class="w-12 h-14 text-center text-2xl font-bold border border-gray-300 rounded-lg shadow-sm focus-primary"
|
|
72
|
+
data-otp-index="${i}"
|
|
73
|
+
autocomplete="one-time-code" />
|
|
74
|
+
`);
|
|
75
|
+
}
|
|
76
|
+
return inputs.join("");
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Override action buttons - form has its own submit.
|
|
80
|
+
*/
|
|
81
|
+
renderActionButtons() {
|
|
82
|
+
return "";
|
|
83
|
+
}
|
|
84
|
+
renderModeScript() {
|
|
85
|
+
const serverUrl = escapeJs(this.config.serverUrl);
|
|
86
|
+
const projectId = escapeJs(this.config.projectId);
|
|
87
|
+
const sessionId = escapeJs(this.config.sessionId);
|
|
88
|
+
const agentDid = escapeJs(this.config.agentDid);
|
|
89
|
+
const tool = escapeJs(this.config.tool);
|
|
90
|
+
const scopes = JSON.stringify(this.config.scopes);
|
|
91
|
+
const digits = this.otpConfig?.digits || 6;
|
|
92
|
+
const resendCooldown = this.otpConfig?.resendCooldown || 60;
|
|
93
|
+
return `
|
|
94
|
+
<script>
|
|
95
|
+
(function() {
|
|
96
|
+
const requestContainer = document.getElementById('otp-request-container');
|
|
97
|
+
const verifyContainer = document.getElementById('otp-verify-container');
|
|
98
|
+
const requestForm = document.getElementById('otp-request-form');
|
|
99
|
+
const verifyForm = document.getElementById('otp-verify-form');
|
|
100
|
+
const resendBtn = document.getElementById('resend-otp');
|
|
101
|
+
const otpInputs = document.querySelectorAll('[data-otp-index]');
|
|
102
|
+
|
|
103
|
+
const serverUrl = ${serverUrl};
|
|
104
|
+
const digits = ${digits};
|
|
105
|
+
const cooldown = ${resendCooldown};
|
|
106
|
+
let lastPhone = '';
|
|
107
|
+
let verificationId = '';
|
|
108
|
+
|
|
109
|
+
function getError(id) {
|
|
110
|
+
const container = document.getElementById(id);
|
|
111
|
+
return { container, div: container?.querySelector('div') };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function showError(id, message) {
|
|
115
|
+
const { container, div } = getError(id);
|
|
116
|
+
if (div) {
|
|
117
|
+
div.textContent = message;
|
|
118
|
+
container.classList.remove('hidden');
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function hideError(id) {
|
|
123
|
+
const { container } = getError(id);
|
|
124
|
+
if (container) container.classList.add('hidden');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// OTP input auto-focus behavior
|
|
128
|
+
otpInputs.forEach((input, idx) => {
|
|
129
|
+
input.addEventListener('input', (e) => {
|
|
130
|
+
const value = e.target.value;
|
|
131
|
+
if (value && idx < otpInputs.length - 1) {
|
|
132
|
+
otpInputs[idx + 1].focus();
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
input.addEventListener('keydown', (e) => {
|
|
137
|
+
if (e.key === 'Backspace' && !e.target.value && idx > 0) {
|
|
138
|
+
otpInputs[idx - 1].focus();
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
input.addEventListener('paste', (e) => {
|
|
143
|
+
e.preventDefault();
|
|
144
|
+
const paste = (e.clipboardData || window.clipboardData).getData('text');
|
|
145
|
+
const chars = paste.replace(/\\D/g, '').slice(0, digits).split('');
|
|
146
|
+
chars.forEach((char, i) => {
|
|
147
|
+
if (otpInputs[i]) otpInputs[i].value = char;
|
|
148
|
+
});
|
|
149
|
+
if (chars.length > 0 && otpInputs[chars.length - 1]) {
|
|
150
|
+
otpInputs[chars.length - 1].focus();
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// Request OTP
|
|
156
|
+
requestForm?.addEventListener('submit', async (e) => {
|
|
157
|
+
e.preventDefault();
|
|
158
|
+
hideError('otp-request-error');
|
|
159
|
+
|
|
160
|
+
const button = requestForm.querySelector('button[type="submit"]');
|
|
161
|
+
const phoneInput = requestForm.querySelector('input[name="phone"]');
|
|
162
|
+
lastPhone = phoneInput.value;
|
|
163
|
+
|
|
164
|
+
button.disabled = true;
|
|
165
|
+
button.textContent = 'Sending...';
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
const response = await fetch(serverUrl + '/consent/otp/request', {
|
|
169
|
+
method: 'POST',
|
|
170
|
+
headers: { 'Content-Type': 'application/json' },
|
|
171
|
+
body: JSON.stringify({
|
|
172
|
+
phone: lastPhone,
|
|
173
|
+
tool: ${tool},
|
|
174
|
+
scopes: ${scopes},
|
|
175
|
+
agent_did: ${agentDid},
|
|
176
|
+
session_id: ${sessionId},
|
|
177
|
+
project_id: ${projectId},
|
|
178
|
+
})
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const result = await response.json();
|
|
182
|
+
|
|
183
|
+
if (result.success) {
|
|
184
|
+
verificationId = result.verificationId || '';
|
|
185
|
+
requestContainer.classList.add('hidden');
|
|
186
|
+
verifyContainer.classList.remove('hidden');
|
|
187
|
+
otpInputs[0]?.focus();
|
|
188
|
+
startResendCooldown();
|
|
189
|
+
} else {
|
|
190
|
+
showError('otp-request-error', result.error || 'Failed to send code');
|
|
191
|
+
button.disabled = false;
|
|
192
|
+
button.textContent = 'Send verification code';
|
|
193
|
+
}
|
|
194
|
+
} catch (err) {
|
|
195
|
+
showError('otp-request-error', 'Network error. Please try again.');
|
|
196
|
+
button.disabled = false;
|
|
197
|
+
button.textContent = 'Send verification code';
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// Verify OTP
|
|
202
|
+
verifyForm?.addEventListener('submit', async (e) => {
|
|
203
|
+
e.preventDefault();
|
|
204
|
+
hideError('otp-verify-error');
|
|
205
|
+
|
|
206
|
+
const button = verifyForm.querySelector('button[type="submit"]');
|
|
207
|
+
const code = Array.from(otpInputs).map(i => i.value).join('');
|
|
208
|
+
|
|
209
|
+
if (code.length !== digits) {
|
|
210
|
+
showError('otp-verify-error', 'Please enter the full code');
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
button.disabled = true;
|
|
215
|
+
button.textContent = 'Verifying...';
|
|
216
|
+
|
|
217
|
+
try {
|
|
218
|
+
const response = await fetch(serverUrl + '/consent/otp/verify', {
|
|
219
|
+
method: 'POST',
|
|
220
|
+
headers: { 'Content-Type': 'application/json' },
|
|
221
|
+
body: JSON.stringify({
|
|
222
|
+
phone: lastPhone,
|
|
223
|
+
code: code,
|
|
224
|
+
verification_id: verificationId,
|
|
225
|
+
tool: ${tool},
|
|
226
|
+
scopes: ${scopes},
|
|
227
|
+
agent_did: ${agentDid},
|
|
228
|
+
session_id: ${sessionId},
|
|
229
|
+
project_id: ${projectId},
|
|
230
|
+
})
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
const result = await response.json();
|
|
234
|
+
|
|
235
|
+
if (result.success) {
|
|
236
|
+
button.textContent = 'Success!';
|
|
237
|
+
button.style.backgroundColor = '#10B981';
|
|
238
|
+
|
|
239
|
+
if (result.redirectUrl) {
|
|
240
|
+
window.location.href = result.redirectUrl;
|
|
241
|
+
} else if (result.delegation_id) {
|
|
242
|
+
window.location.href = serverUrl + '/consent/success?delegation_id=' +
|
|
243
|
+
encodeURIComponent(result.delegation_id) +
|
|
244
|
+
'&project_id=' + encodeURIComponent(${projectId});
|
|
245
|
+
}
|
|
246
|
+
} else {
|
|
247
|
+
showError('otp-verify-error', result.error || 'Invalid code');
|
|
248
|
+
button.disabled = false;
|
|
249
|
+
button.textContent = 'Verify';
|
|
250
|
+
}
|
|
251
|
+
} catch (err) {
|
|
252
|
+
showError('otp-verify-error', 'Network error. Please try again.');
|
|
253
|
+
button.disabled = false;
|
|
254
|
+
button.textContent = 'Verify';
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// Resend cooldown
|
|
259
|
+
function startResendCooldown() {
|
|
260
|
+
resendBtn.disabled = true;
|
|
261
|
+
let remaining = cooldown;
|
|
262
|
+
resendBtn.textContent = 'Resend code (' + remaining + 's)';
|
|
263
|
+
|
|
264
|
+
const timer = setInterval(() => {
|
|
265
|
+
remaining--;
|
|
266
|
+
if (remaining <= 0) {
|
|
267
|
+
clearInterval(timer);
|
|
268
|
+
resendBtn.disabled = false;
|
|
269
|
+
resendBtn.textContent = 'Resend code';
|
|
270
|
+
} else {
|
|
271
|
+
resendBtn.textContent = 'Resend code (' + remaining + 's)';
|
|
272
|
+
}
|
|
273
|
+
}, 1000);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
resendBtn?.addEventListener('click', async () => {
|
|
277
|
+
if (resendBtn.disabled) return;
|
|
278
|
+
|
|
279
|
+
resendBtn.disabled = true;
|
|
280
|
+
try {
|
|
281
|
+
const response = await fetch(serverUrl + '/consent/otp/request', {
|
|
282
|
+
method: 'POST',
|
|
283
|
+
headers: { 'Content-Type': 'application/json' },
|
|
284
|
+
body: JSON.stringify({
|
|
285
|
+
phone: lastPhone,
|
|
286
|
+
tool: ${tool},
|
|
287
|
+
scopes: ${scopes},
|
|
288
|
+
agent_did: ${agentDid},
|
|
289
|
+
session_id: ${sessionId},
|
|
290
|
+
project_id: ${projectId},
|
|
291
|
+
})
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
const result = await response.json();
|
|
295
|
+
if (result.success) {
|
|
296
|
+
verificationId = result.verificationId || verificationId;
|
|
297
|
+
startResendCooldown();
|
|
298
|
+
} else {
|
|
299
|
+
resendBtn.disabled = false;
|
|
300
|
+
alert(result.error || 'Failed to resend');
|
|
301
|
+
}
|
|
302
|
+
} catch (err) {
|
|
303
|
+
resendBtn.disabled = false;
|
|
304
|
+
alert('Network error');
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
})();
|
|
308
|
+
</script>`;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
//# sourceMappingURL=otp.template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otp.template.js","sourceRoot":"","sources":["../../../../src/services/consent-templates/modes/otp.template.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EACL,WAAW,EACX,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,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ACF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template Registry
|
|
3
|
+
*
|
|
4
|
+
* Central registry for consent page templates.
|
|
5
|
+
* Provides factory methods for creating templates by auth mode.
|
|
6
|
+
*
|
|
7
|
+
* @module consent-templates/registry
|
|
8
|
+
*/
|
|
9
|
+
import { BaseConsentTemplate } from "./base/base-template";
|
|
10
|
+
import type { AuthMode, ExtendedConsentPageConfig, ConsentConfigWithMeta } from "./types";
|
|
11
|
+
import type { ConsentPageConfig } from "@kya-os/contracts/consent";
|
|
12
|
+
/**
|
|
13
|
+
* Get a template instance for the specified auth mode.
|
|
14
|
+
*
|
|
15
|
+
* @param authMode - The authentication mode
|
|
16
|
+
* @param config - Extended page config with mode-specific settings
|
|
17
|
+
* @param remoteConfig - Remote consent configuration from AgentShield
|
|
18
|
+
* @returns Template instance ready to render
|
|
19
|
+
*/
|
|
20
|
+
export declare function getTemplateForMode(authMode: AuthMode, config: ExtendedConsentPageConfig, remoteConfig?: ConsentConfigWithMeta): BaseConsentTemplate;
|
|
21
|
+
/**
|
|
22
|
+
* Determine the auth mode from config.
|
|
23
|
+
*
|
|
24
|
+
* @param config - Page config with optional OAuth settings
|
|
25
|
+
* @returns Detected auth mode
|
|
26
|
+
*/
|
|
27
|
+
export declare function detectAuthMode(config: ConsentPageConfig): AuthMode;
|
|
28
|
+
/**
|
|
29
|
+
* Check if an auth mode is valid.
|
|
30
|
+
*
|
|
31
|
+
* @param mode - Mode string to check
|
|
32
|
+
* @returns True if valid auth mode
|
|
33
|
+
*/
|
|
34
|
+
export declare function isValidAuthMode(mode: string): mode is AuthMode;
|
|
35
|
+
/**
|
|
36
|
+
* Get all registered auth modes.
|
|
37
|
+
*
|
|
38
|
+
* @returns Array of auth mode identifiers
|
|
39
|
+
*/
|
|
40
|
+
export declare function getRegisteredModes(): AuthMode[];
|
|
41
|
+
/**
|
|
42
|
+
* Render a consent page for the given config.
|
|
43
|
+
*
|
|
44
|
+
* This is the main entry point for rendering consent pages.
|
|
45
|
+
*
|
|
46
|
+
* @param config - Extended page config
|
|
47
|
+
* @param remoteConfig - Remote consent configuration from AgentShield
|
|
48
|
+
* @param authMode - Optional explicit auth mode (auto-detected if not provided)
|
|
49
|
+
* @returns Rendered HTML string
|
|
50
|
+
*/
|
|
51
|
+
export declare function renderConsentPage(config: ExtendedConsentPageConfig, remoteConfig?: ConsentConfigWithMeta, authMode?: AuthMode): string;
|
|
52
|
+
/**
|
|
53
|
+
* Render an OAuth consent page with pre-configured OAuth URL.
|
|
54
|
+
*
|
|
55
|
+
* @param config - Extended page config
|
|
56
|
+
* @param oauthUrl - OAuth authorization URL
|
|
57
|
+
* @param remoteConfig - Remote consent configuration from AgentShield
|
|
58
|
+
* @returns Rendered HTML string
|
|
59
|
+
*/
|
|
60
|
+
export declare function renderOAuthConsentPage(config: ExtendedConsentPageConfig, oauthUrl: string, remoteConfig?: ConsentConfigWithMeta): string;
|
|
61
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/services/consent-templates/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAS3D,OAAO,KAAK,EACV,QAAQ,EAER,yBAAyB,EACzB,qBAAqB,EAEtB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAqBnE;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,yBAAyB,EACjC,YAAY,CAAC,EAAE,qBAAqB,GACnC,mBAAmB,CAyBrB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,iBAAiB,GAAG,QAAQ,CAkClE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,QAAQ,CAQ9D;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,QAAQ,EAAE,CAE/C;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,yBAAyB,EACjC,YAAY,CAAC,EAAE,qBAAqB,EACpC,QAAQ,CAAC,EAAE,QAAQ,GAClB,MAAM,CAIR;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,yBAAyB,EACjC,QAAQ,EAAE,MAAM,EAChB,YAAY,CAAC,EAAE,qBAAqB,GACnC,MAAM,CAOR"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template Registry
|
|
3
|
+
*
|
|
4
|
+
* Central registry for consent page templates.
|
|
5
|
+
* Provides factory methods for creating templates by auth mode.
|
|
6
|
+
*
|
|
7
|
+
* @module consent-templates/registry
|
|
8
|
+
*/
|
|
9
|
+
import { ConsentOnlyTemplate, CredentialsTemplate, OAuthTemplate, MagicLinkTemplate, OTPTemplate, } from "./modes";
|
|
10
|
+
import { resolveConsentConfig, getDefaultConsentConfig } from "./helpers";
|
|
11
|
+
/**
|
|
12
|
+
* Template registry mapping auth modes to their templates.
|
|
13
|
+
*/
|
|
14
|
+
const TEMPLATE_REGISTRY = {
|
|
15
|
+
"consent-only": ConsentOnlyTemplate,
|
|
16
|
+
credentials: CredentialsTemplate,
|
|
17
|
+
oauth: OAuthTemplate,
|
|
18
|
+
"magic-link": MagicLinkTemplate,
|
|
19
|
+
otp: OTPTemplate,
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Get a template instance for the specified auth mode.
|
|
23
|
+
*
|
|
24
|
+
* @param authMode - The authentication mode
|
|
25
|
+
* @param config - Extended page config with mode-specific settings
|
|
26
|
+
* @param remoteConfig - Remote consent configuration from AgentShield
|
|
27
|
+
* @returns Template instance ready to render
|
|
28
|
+
*/
|
|
29
|
+
export function getTemplateForMode(authMode, config, remoteConfig) {
|
|
30
|
+
const TemplateClass = TEMPLATE_REGISTRY[authMode];
|
|
31
|
+
if (!TemplateClass) {
|
|
32
|
+
// Fallback to consent-only for unknown modes
|
|
33
|
+
console.warn(`Unknown auth mode: ${authMode}, falling back to consent-only`);
|
|
34
|
+
return getTemplateForMode("consent-only", config, remoteConfig);
|
|
35
|
+
}
|
|
36
|
+
// Resolve config values
|
|
37
|
+
const mergedRemoteConfig = remoteConfig || getDefaultConsentConfig();
|
|
38
|
+
const resolved = resolveConsentConfig(mergedRemoteConfig, config.tool);
|
|
39
|
+
// Special handling for credentials template to pass remote credentials config
|
|
40
|
+
if (authMode === "credentials") {
|
|
41
|
+
return new CredentialsTemplate(config, resolved, mergedRemoteConfig.credentials);
|
|
42
|
+
}
|
|
43
|
+
return new TemplateClass(config, resolved);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Determine the auth mode from config.
|
|
47
|
+
*
|
|
48
|
+
* @param config - Page config with optional OAuth settings
|
|
49
|
+
* @returns Detected auth mode
|
|
50
|
+
*/
|
|
51
|
+
export function detectAuthMode(config) {
|
|
52
|
+
// Check for OAuth requirement
|
|
53
|
+
if (config.oauthRequired || config.oauthUrl) {
|
|
54
|
+
return "oauth";
|
|
55
|
+
}
|
|
56
|
+
// Check for provider hint
|
|
57
|
+
if (config.provider) {
|
|
58
|
+
const provider = config.provider.toLowerCase();
|
|
59
|
+
// Credentials provider uses form-based auth, not OAuth
|
|
60
|
+
if (provider === "credentials") {
|
|
61
|
+
return "credentials";
|
|
62
|
+
}
|
|
63
|
+
if (provider.includes("oauth") ||
|
|
64
|
+
["github", "google", "microsoft", "slack", "auth0"].includes(provider)) {
|
|
65
|
+
return "oauth";
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Check mode config
|
|
69
|
+
const modeConfig = config.modeConfig;
|
|
70
|
+
if (modeConfig) {
|
|
71
|
+
if (modeConfig.oauth)
|
|
72
|
+
return "oauth";
|
|
73
|
+
if (modeConfig.credentials)
|
|
74
|
+
return "credentials";
|
|
75
|
+
if (modeConfig.magicLink?.enabled)
|
|
76
|
+
return "magic-link";
|
|
77
|
+
if (modeConfig.otp?.enabled)
|
|
78
|
+
return "otp";
|
|
79
|
+
}
|
|
80
|
+
// Default to consent-only
|
|
81
|
+
return "consent-only";
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Check if an auth mode is valid.
|
|
85
|
+
*
|
|
86
|
+
* @param mode - Mode string to check
|
|
87
|
+
* @returns True if valid auth mode
|
|
88
|
+
*/
|
|
89
|
+
export function isValidAuthMode(mode) {
|
|
90
|
+
return Object.values({
|
|
91
|
+
CONSENT_ONLY: "consent-only",
|
|
92
|
+
CREDENTIALS: "credentials",
|
|
93
|
+
OAUTH: "oauth",
|
|
94
|
+
MAGIC_LINK: "magic-link",
|
|
95
|
+
OTP: "otp",
|
|
96
|
+
}).includes(mode);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get all registered auth modes.
|
|
100
|
+
*
|
|
101
|
+
* @returns Array of auth mode identifiers
|
|
102
|
+
*/
|
|
103
|
+
export function getRegisteredModes() {
|
|
104
|
+
return Object.keys(TEMPLATE_REGISTRY);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Render a consent page for the given config.
|
|
108
|
+
*
|
|
109
|
+
* This is the main entry point for rendering consent pages.
|
|
110
|
+
*
|
|
111
|
+
* @param config - Extended page config
|
|
112
|
+
* @param remoteConfig - Remote consent configuration from AgentShield
|
|
113
|
+
* @param authMode - Optional explicit auth mode (auto-detected if not provided)
|
|
114
|
+
* @returns Rendered HTML string
|
|
115
|
+
*/
|
|
116
|
+
export function renderConsentPage(config, remoteConfig, authMode) {
|
|
117
|
+
const mode = authMode || detectAuthMode(config);
|
|
118
|
+
const template = getTemplateForMode(mode, config, remoteConfig);
|
|
119
|
+
return template.render();
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Render an OAuth consent page with pre-configured OAuth URL.
|
|
123
|
+
*
|
|
124
|
+
* @param config - Extended page config
|
|
125
|
+
* @param oauthUrl - OAuth authorization URL
|
|
126
|
+
* @param remoteConfig - Remote consent configuration from AgentShield
|
|
127
|
+
* @returns Rendered HTML string
|
|
128
|
+
*/
|
|
129
|
+
export function renderOAuthConsentPage(config, oauthUrl, remoteConfig) {
|
|
130
|
+
const mergedRemoteConfig = remoteConfig || getDefaultConsentConfig();
|
|
131
|
+
const resolved = resolveConsentConfig(mergedRemoteConfig, config.tool);
|
|
132
|
+
const template = new OAuthTemplate(config, resolved);
|
|
133
|
+
template.setOAuthUrl(oauthUrl);
|
|
134
|
+
return template.render();
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/services/consent-templates/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,WAAW,GACZ,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAkB1E;;GAEG;AACH,MAAM,iBAAiB,GAA0C;IAC/D,cAAc,EAAE,mBAAmB;IACnC,WAAW,EAAE,mBAAmB;IAChC,KAAK,EAAE,aAAa;IACpB,YAAY,EAAE,iBAAiB;IAC/B,GAAG,EAAE,WAAW;CACjB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAAkB,EAClB,MAAiC,EACjC,YAAoC;IAEpC,MAAM,aAAa,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAElD,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,6CAA6C;QAC7C,OAAO,CAAC,IAAI,CACV,sBAAsB,QAAQ,gCAAgC,CAC/D,CAAC;QACF,OAAO,kBAAk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C,QAAQ,CAAC,CAAC;IAC/B,OAAO,QAAQ,CAAC,MAAM,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template-Based Consent Page Renderer
|
|
3
|
+
*
|
|
4
|
+
* Adapter that provides the same interface as ConsentPageRenderer
|
|
5
|
+
* but uses the new modular template system internally.
|
|
6
|
+
*
|
|
7
|
+
* Now supports CSR (Client-Side Rendering) mode using @kya-os/consent
|
|
8
|
+
* Lit Web Components for pixel-perfect AgentShield parity.
|
|
9
|
+
*
|
|
10
|
+
* @module consent-templates/template-renderer
|
|
11
|
+
*/
|
|
12
|
+
import type { ConsentPageConfig, OAuthIdentity } from "@kya-os/contracts/consent";
|
|
13
|
+
import type { CredentialProviderConfig } from "@kya-os/contracts/config";
|
|
14
|
+
/**
|
|
15
|
+
* Template-based consent page renderer.
|
|
16
|
+
*
|
|
17
|
+
* Drop-in replacement for ConsentPageRenderer that uses the new
|
|
18
|
+
* modular template system with pixel-perfect AgentShield parity.
|
|
19
|
+
*
|
|
20
|
+
* Supports two rendering modes:
|
|
21
|
+
* - SSR (Server-Side Rendering) - Default, renders full HTML on server
|
|
22
|
+
* - CSR (Client-Side Rendering) - Serves HTML shell, Lit renders in browser
|
|
23
|
+
*/
|
|
24
|
+
export declare class TemplateRenderer {
|
|
25
|
+
private useCSR;
|
|
26
|
+
private bundlePath;
|
|
27
|
+
constructor(options?: {
|
|
28
|
+
useCSR?: boolean;
|
|
29
|
+
bundlePath?: string;
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Render consent page HTML.
|
|
33
|
+
*
|
|
34
|
+
* If CSR mode is enabled, generates a minimal HTML shell that loads
|
|
35
|
+
* the @kya-os/consent Lit components. Otherwise, uses SSR templates.
|
|
36
|
+
*
|
|
37
|
+
* @param config - Consent page configuration
|
|
38
|
+
* @param oauthIdentity - Optional OAuth identity from cookie
|
|
39
|
+
* @returns HTML string
|
|
40
|
+
*/
|
|
41
|
+
render(config: ConsentPageConfig & {
|
|
42
|
+
oauthRequired?: boolean;
|
|
43
|
+
oauthUrl?: string;
|
|
44
|
+
}, oauthIdentity?: OAuthIdentity): string;
|
|
45
|
+
/**
|
|
46
|
+
* Render consent page using Client-Side Rendering (CSR).
|
|
47
|
+
*
|
|
48
|
+
* Generates a minimal HTML shell that:
|
|
49
|
+
* 1. Loads the bundled consent.js from @kya-os/consent
|
|
50
|
+
* 2. Renders the <mcp-consent> Lit Web Component
|
|
51
|
+
* 3. Provides a loading skeleton while JS loads
|
|
52
|
+
* 4. Falls back to basic form for no-JS users
|
|
53
|
+
*
|
|
54
|
+
* @param config - Consent page configuration
|
|
55
|
+
* @param oauthIdentity - Optional OAuth identity from cookie
|
|
56
|
+
* @returns HTML string
|
|
57
|
+
*/
|
|
58
|
+
private renderCSR;
|
|
59
|
+
/**
|
|
60
|
+
* Render credential login page.
|
|
61
|
+
*
|
|
62
|
+
* @param config - Consent page configuration
|
|
63
|
+
* @param credentialConfig - Credential provider configuration
|
|
64
|
+
* @param provider - Provider name
|
|
65
|
+
* @param csrfToken - CSRF token for form security
|
|
66
|
+
* @returns HTML string
|
|
67
|
+
*/
|
|
68
|
+
renderCredentialPage(config: ConsentPageConfig, credentialConfig: CredentialProviderConfig, provider: string, csrfToken: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* Render credential login page using CSR (Client-Side Rendering).
|
|
71
|
+
*
|
|
72
|
+
* @param config - Consent page configuration
|
|
73
|
+
* @param credentialConfig - Credential provider configuration
|
|
74
|
+
* @param provider - Provider name
|
|
75
|
+
* @returns HTML string
|
|
76
|
+
*/
|
|
77
|
+
private renderCredentialPageCSR;
|
|
78
|
+
/**
|
|
79
|
+
* Render success page after consent approval.
|
|
80
|
+
* (Legacy signature for backward compatibility)
|
|
81
|
+
*
|
|
82
|
+
* @param options - Success page options
|
|
83
|
+
* @returns HTML string
|
|
84
|
+
*/
|
|
85
|
+
renderSuccess(options: {
|
|
86
|
+
delegationId: string;
|
|
87
|
+
autoClose?: boolean;
|
|
88
|
+
}): string;
|
|
89
|
+
/**
|
|
90
|
+
* Render success page after consent approval.
|
|
91
|
+
*
|
|
92
|
+
* @param delegationId - The created delegation ID
|
|
93
|
+
* @param projectId - Project ID
|
|
94
|
+
* @param autoClose - Whether to auto-close the window
|
|
95
|
+
* @returns HTML string
|
|
96
|
+
*/
|
|
97
|
+
renderSuccessPage(delegationId: string, projectId: string, autoClose?: boolean): string;
|
|
98
|
+
/**
|
|
99
|
+
* Build ExtendedConsentPageConfig from ConsentPageConfig.
|
|
100
|
+
*/
|
|
101
|
+
private buildExtendedConfig;
|
|
102
|
+
/**
|
|
103
|
+
* Build ConsentConfigWithMeta from page config's branding/terms/ui.
|
|
104
|
+
*/
|
|
105
|
+
private buildRemoteConfig;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Factory function for creating a template renderer.
|
|
109
|
+
*
|
|
110
|
+
* @param options - Optional configuration for CSR mode
|
|
111
|
+
* @param options.useCSR - Enable Client-Side Rendering (default: false)
|
|
112
|
+
* @param options.bundlePath - Path to consent.js bundle (default: '/consent.js')
|
|
113
|
+
*/
|
|
114
|
+
export declare function createTemplateRenderer(options?: {
|
|
115
|
+
useCSR?: boolean;
|
|
116
|
+
bundlePath?: string;
|
|
117
|
+
}): TemplateRenderer;
|
|
118
|
+
//# sourceMappingURL=template-renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-renderer.d.ts","sourceRoot":"","sources":["../../../src/services/consent-templates/template-renderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAYH,OAAO,KAAK,EACV,iBAAiB,EACjB,aAAa,EACd,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAazE;;;;;;;;;GASG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,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