@kya-os/consent 0.1.6 → 0.1.7

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,63 @@
1
+ /**
2
+ * Credential Form Field Utilities
3
+ *
4
+ * Utilities for parsing and rendering dynamic credential form fields
5
+ * based on the provider's requestBodyTemplate configuration.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const template = { email: '{{email}}', password: '{{password}}' };
10
+ * const fields = parseCredentialFields(template);
11
+ * // Returns:
12
+ * // [
13
+ * // { name: 'email', apiName: 'email', type: 'email', label: 'Email', required: true },
14
+ * // { name: 'password', apiName: 'password', type: 'password', label: 'Password', required: true }
15
+ * // ]
16
+ * ```
17
+ */
18
+ /**
19
+ * Credential form field metadata for dynamic form rendering
20
+ */
21
+ export interface CredentialField {
22
+ /** Form field name (used in FormData submission) */
23
+ name: string;
24
+ /** API field name in requestBodyTemplate (may differ from form name) */
25
+ apiName: string;
26
+ /** Human-readable label for the input */
27
+ label: string;
28
+ /** Placeholder text for the input */
29
+ placeholder: string;
30
+ /** HTML input type */
31
+ type: "text" | "password" | "email" | "tel" | "date" | "number";
32
+ /** HTML autocomplete attribute */
33
+ autocomplete: string;
34
+ /** Whether field is required */
35
+ required: boolean;
36
+ }
37
+ /**
38
+ * Parse credential fields from a requestBodyTemplate.
39
+ *
40
+ * Extracts field definitions from template placeholders like `{{fieldName}}`
41
+ * and infers appropriate input types, labels, and autocomplete attributes.
42
+ *
43
+ * @param requestBodyTemplate - Template object with API field names as keys and `{{fieldName}}` as values
44
+ * @returns Array of CredentialField objects for form rendering
45
+ */
46
+ export declare function parseCredentialFields(requestBodyTemplate: Record<string, string>): CredentialField[];
47
+ /**
48
+ * Infer HTML input type from field name
49
+ */
50
+ export declare function inferInputType(fieldName: string): "text" | "password" | "email" | "tel" | "date" | "number";
51
+ /**
52
+ * Convert field name to human-readable label
53
+ */
54
+ export declare function humanizeFieldName(name: string): string;
55
+ /**
56
+ * Get appropriate placeholder text for a field
57
+ */
58
+ export declare function getPlaceholder(fieldName: string, inputType: string): string;
59
+ /**
60
+ * Get appropriate autocomplete attribute for a field
61
+ */
62
+ export declare function getAutocomplete(fieldName: string, inputType: string): string;
63
+ //# sourceMappingURL=credential-fields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential-fields.d.ts","sourceRoot":"","sources":["../../src/utils/credential-fields.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,wEAAwE;IACxE,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,sBAAsB;IACtB,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,CAAC;IAChE,kCAAkC;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,gCAAgC;IAChC,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC1C,eAAe,EAAE,CA6BnB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,GAChB,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,CAkD3D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMtD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,MAAM,CAeR;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,MAAM,CAwCR"}
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Credential Form Field Utilities
3
+ *
4
+ * Utilities for parsing and rendering dynamic credential form fields
5
+ * based on the provider's requestBodyTemplate configuration.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const template = { email: '{{email}}', password: '{{password}}' };
10
+ * const fields = parseCredentialFields(template);
11
+ * // Returns:
12
+ * // [
13
+ * // { name: 'email', apiName: 'email', type: 'email', label: 'Email', required: true },
14
+ * // { name: 'password', apiName: 'password', type: 'password', label: 'Password', required: true }
15
+ * // ]
16
+ * ```
17
+ */
18
+ /**
19
+ * Parse credential fields from a requestBodyTemplate.
20
+ *
21
+ * Extracts field definitions from template placeholders like `{{fieldName}}`
22
+ * and infers appropriate input types, labels, and autocomplete attributes.
23
+ *
24
+ * @param requestBodyTemplate - Template object with API field names as keys and `{{fieldName}}` as values
25
+ * @returns Array of CredentialField objects for form rendering
26
+ */
27
+ export function parseCredentialFields(requestBodyTemplate) {
28
+ const fields = [];
29
+ for (const [apiFieldName, template] of Object.entries(requestBodyTemplate)) {
30
+ const match = template.match(/\{\{(\w+)\}\}/);
31
+ if (match && match[1]) {
32
+ const formFieldName = match[1];
33
+ const inputType = inferInputType(formFieldName);
34
+ fields.push({
35
+ name: formFieldName,
36
+ apiName: apiFieldName,
37
+ label: humanizeFieldName(formFieldName),
38
+ placeholder: getPlaceholder(formFieldName, inputType),
39
+ type: inputType,
40
+ autocomplete: getAutocomplete(formFieldName, inputType),
41
+ required: true,
42
+ });
43
+ }
44
+ }
45
+ // Sort fields: non-password fields first, password fields last
46
+ return fields.sort((a, b) => {
47
+ const aIsPassword = a.type === "password";
48
+ const bIsPassword = b.type === "password";
49
+ if (aIsPassword && !bIsPassword)
50
+ return 1;
51
+ if (!aIsPassword && bIsPassword)
52
+ return -1;
53
+ return 0;
54
+ });
55
+ }
56
+ /**
57
+ * Infer HTML input type from field name
58
+ */
59
+ export function inferInputType(fieldName) {
60
+ const lower = fieldName.toLowerCase();
61
+ // Password-like fields
62
+ if (lower.includes("password") ||
63
+ lower.includes("pass") ||
64
+ lower.includes("secret") ||
65
+ lower.includes("pin")) {
66
+ return "password";
67
+ }
68
+ // Email fields
69
+ if (lower.includes("email") || lower.includes("mail")) {
70
+ return "email";
71
+ }
72
+ // Phone fields
73
+ if (lower.includes("phone") ||
74
+ lower.includes("tel") ||
75
+ lower.includes("mobile") ||
76
+ lower.includes("cell")) {
77
+ return "tel";
78
+ }
79
+ // Date fields
80
+ if (lower.includes("date") ||
81
+ lower.includes("dob") ||
82
+ lower.includes("birthday") ||
83
+ lower.includes("birth")) {
84
+ return "date";
85
+ }
86
+ // Number fields
87
+ if (lower.includes("age") ||
88
+ lower.includes("zip") ||
89
+ lower.includes("ssn") ||
90
+ lower.includes("code") ||
91
+ lower.includes("otp")) {
92
+ return "number";
93
+ }
94
+ return "text";
95
+ }
96
+ /**
97
+ * Convert field name to human-readable label
98
+ */
99
+ export function humanizeFieldName(name) {
100
+ return name
101
+ .replace(/([A-Z])/g, " $1") // Add space before capitals (camelCase)
102
+ .replace(/[_-]/g, " ") // Replace underscores/hyphens with spaces
103
+ .replace(/^\w/, (c) => c.toUpperCase()) // Capitalize first letter
104
+ .trim();
105
+ }
106
+ /**
107
+ * Get appropriate placeholder text for a field
108
+ */
109
+ export function getPlaceholder(fieldName, inputType) {
110
+ const label = humanizeFieldName(fieldName);
111
+ switch (inputType) {
112
+ case "email":
113
+ return "you@example.com";
114
+ case "password":
115
+ return "••••••••";
116
+ case "tel":
117
+ return "+1 (555) 123-4567";
118
+ case "date":
119
+ return "YYYY-MM-DD";
120
+ default:
121
+ return `Enter your ${label.toLowerCase()}`;
122
+ }
123
+ }
124
+ /**
125
+ * Get appropriate autocomplete attribute for a field
126
+ */
127
+ export function getAutocomplete(fieldName, inputType) {
128
+ const lower = fieldName.toLowerCase();
129
+ // Explicit mappings
130
+ if (lower.includes("username") || lower.includes("user")) {
131
+ return "username";
132
+ }
133
+ if (lower.includes("email")) {
134
+ return "email";
135
+ }
136
+ if (lower.includes("phone") || lower.includes("tel") || lower.includes("mobile")) {
137
+ return "tel";
138
+ }
139
+ if (lower.includes("password") || lower.includes("pass")) {
140
+ return "current-password";
141
+ }
142
+ if (lower.includes("dob") || lower.includes("birthday") || lower.includes("birth")) {
143
+ return "bday";
144
+ }
145
+ if (lower.includes("name") && lower.includes("first")) {
146
+ return "given-name";
147
+ }
148
+ if (lower.includes("name") && lower.includes("last")) {
149
+ return "family-name";
150
+ }
151
+ if (lower.includes("name")) {
152
+ return "name";
153
+ }
154
+ // Fallback based on type
155
+ switch (inputType) {
156
+ case "email":
157
+ return "email";
158
+ case "password":
159
+ return "current-password";
160
+ case "tel":
161
+ return "tel";
162
+ default:
163
+ return "off";
164
+ }
165
+ }
166
+ //# sourceMappingURL=credential-fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential-fields.js","sourceRoot":"","sources":["../../src/utils/credential-fields.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAsBH;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CACnC,mBAA2C;IAE3C,MAAM,MAAM,GAAsB,EAAE,CAAC;IAErC,KAAK,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,CAAC;QAC3E,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QAC9C,IAAI,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YACtB,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YAC/B,MAAM,SAAS,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;YAEhD,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,EAAE,aAAa;gBACnB,OAAO,EAAE,YAAY;gBACrB,KAAK,EAAE,iBAAiB,CAAC,aAAa,CAAC;gBACvC,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,CAAC,MAAM,CAAC,EAAE,CAAC;QACrD,OAAO,aAAa,CAAC;IACvB,CAAC;IACD,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,yBAAyB;IACzB,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,OAAO;YACV,OAAO,OAAO,CAAC;QACjB,KAAK,UAAU;YACb,OAAO,kBAAkB,CAAC;QAC5B,KAAK,KAAK;YACR,OAAO,KAAK,CAAC;QACf;YACE,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Utility functions for consent components
3
+ */
4
+ export { parseCredentialFields, inferInputType, humanizeFieldName, getPlaceholder, getAutocomplete, type CredentialField, } from "./credential-fields.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,KAAK,eAAe,GACrB,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Utility functions for consent components
3
+ */
4
+ export { parseCredentialFields, inferInputType, humanizeFieldName, getPlaceholder, getAutocomplete, } from "./credential-fields.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,eAAe,GAEhB,MAAM,wBAAwB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kya-os/consent",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Canonical consent page types, styles, and utilities for MCP-I and AgentShield",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",