@encodeagent/platform-helper-util 1.2603.1221241 → 1.2603.1311023

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.
Files changed (69) hide show
  1. package/README.md +277 -153
  2. package/dist/api.d.ts +38 -0
  3. package/dist/api.d.ts.map +1 -1
  4. package/dist/api.js +38 -2
  5. package/dist/api.js.map +1 -1
  6. package/dist/auth.d.ts +93 -0
  7. package/dist/auth.d.ts.map +1 -1
  8. package/dist/auth.js +93 -2
  9. package/dist/auth.js.map +1 -1
  10. package/dist/colors.d.ts +41 -0
  11. package/dist/colors.d.ts.map +1 -1
  12. package/dist/colors.js +41 -0
  13. package/dist/colors.js.map +1 -1
  14. package/dist/core.d.ts +262 -0
  15. package/dist/core.d.ts.map +1 -1
  16. package/dist/core.js +264 -2
  17. package/dist/core.js.map +1 -1
  18. package/dist/cost.d.ts +26 -0
  19. package/dist/cost.d.ts.map +1 -1
  20. package/dist/cost.js +27 -1
  21. package/dist/cost.js.map +1 -1
  22. package/dist/file.d.ts +38 -0
  23. package/dist/file.d.ts.map +1 -1
  24. package/dist/file.js +42 -2
  25. package/dist/file.js.map +1 -1
  26. package/dist/html.d.ts +83 -0
  27. package/dist/html.d.ts.map +1 -1
  28. package/dist/html.js +88 -35
  29. package/dist/html.js.map +1 -1
  30. package/dist/logger.d.ts +17 -0
  31. package/dist/logger.d.ts.map +1 -1
  32. package/dist/logger.js +28 -2
  33. package/dist/logger.js.map +1 -1
  34. package/dist/markdown.d.ts +20 -0
  35. package/dist/markdown.d.ts.map +1 -1
  36. package/dist/markdown.js +20 -0
  37. package/dist/markdown.js.map +1 -1
  38. package/dist/metadata.js +1 -1
  39. package/dist/metadata.js.map +1 -1
  40. package/dist/record.d.ts +137 -5
  41. package/dist/record.d.ts.map +1 -1
  42. package/dist/record.js +184 -19
  43. package/dist/record.js.map +1 -1
  44. package/dist/shortid.d.ts +21 -8
  45. package/dist/shortid.d.ts.map +1 -1
  46. package/dist/shortid.js +9 -5
  47. package/dist/shortid.js.map +1 -1
  48. package/dist/slug.d.ts +10 -0
  49. package/dist/slug.d.ts.map +1 -1
  50. package/dist/slug.js +10 -0
  51. package/dist/slug.js.map +1 -1
  52. package/dist/token.d.ts +1 -1
  53. package/dist/tree.d.ts +43 -0
  54. package/dist/tree.d.ts.map +1 -1
  55. package/dist/tree.js +43 -5
  56. package/dist/tree.js.map +1 -1
  57. package/dist/value-of-object.d.ts +41 -0
  58. package/dist/value-of-object.d.ts.map +1 -1
  59. package/dist/value-of-object.js +59 -17
  60. package/dist/value-of-object.js.map +1 -1
  61. package/dist/web-content.d.ts +52 -0
  62. package/dist/web-content.d.ts.map +1 -1
  63. package/dist/web-content.js +52 -0
  64. package/dist/web-content.js.map +1 -1
  65. package/dist/web.d.ts +51 -0
  66. package/dist/web.d.ts.map +1 -1
  67. package/dist/web.js +54 -1
  68. package/dist/web.js.map +1 -1
  69. package/package.json +10 -5
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @encodeagent/platform-helper-util
2
2
 
3
- Comprehensive TypeScript utility library for the EncodeAgent platform with AI services, authentication, file handling, web content processing, and more.
3
+ TypeScript utility library for the EncodeAgent platform. Covers string/GUID validation, ID generation, web/URL handling, file type detection, color constants, AI cost calculation, HTML/Markdown conversion, tree data structures, authentication helpers, and structured logging.
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,7 +10,7 @@ npm install @encodeagent/platform-helper-util
10
10
 
11
11
  ## Requirements
12
12
 
13
- - Node.js >20.0.0 <23.0.0
13
+ - Node.js >=20.0.0 <23.0.0
14
14
  - TypeScript 5.2+
15
15
 
16
16
  ## Usage
@@ -18,261 +18,385 @@ npm install @encodeagent/platform-helper-util
18
18
  ### Core Utilities
19
19
 
20
20
  ```typescript
21
- import {
22
- isNonEmptyString,
23
- isGuid,
24
- isEmail,
25
- formatString,
21
+ import {
22
+ isNonEmptyString,
23
+ isGuid,
24
+ isEmail,
25
+ formatString,
26
26
  getTimestamp,
27
- numberWithCommas,
28
- readableFileSize
27
+ readableFileSize
29
28
  } from '@encodeagent/platform-helper-util';
30
29
 
31
- isNonEmptyString('hello'); // true
32
- isGuid('550e8400-e29b-41d4-a716-446655440000'); // true
33
- isEmail('user@example.com'); // true
34
- formatString('Hello {0}!', 'World'); // 'Hello World!'
35
- numberWithCommas(1234567); // '1,234,567'
36
- readableFileSize(1024); // '1.00 KB'
30
+ isNonEmptyString('hello'); // true
31
+ isGuid('550e8400-e29b-41d4-a716-446655440000'); // true
32
+ isEmail('user@example.com'); // true
33
+ formatString('Hello {0}!', 'World'); // 'Hello World!'
34
+ readableFileSize(1024); // '1.00 KB'
37
35
  ```
38
36
 
39
- ### Authentication & Authorization
37
+ ### ID Generation
40
38
 
41
39
  ```typescript
42
- import {
43
- checkRecordPrivilege,
44
- hasRole,
45
- isOwner,
46
- checkPrivileges
47
- } from '@encodeagent/platform-helper-util';
40
+ import { newGuid, newShortId, slug } from '@encodeagent/platform-helper-util';
48
41
 
49
- const hasAccess = checkRecordPrivilege(record, context, 'read');
50
- const userHasRole = hasRole(user, 'admin');
51
- const isRecordOwner = isOwner(record, userId);
42
+ const guid = newGuid(); // '550e8400-e29b-41d4-a716-446655440000'
43
+ const shortId = newShortId(); // 'rJUWbIHOWM'
44
+
45
+ // slug — URL-safe identifier from arbitrary text
46
+ slug('Hello World!'); // 'hello-world'
47
+ slug('file.name', { keepPeriod: true }); // 'file.name'
48
+ slug('my_key', { keepUnderscore: true }); // 'my_key'
49
+
50
+ // newShortId — same special-character opts apply
51
+ newShortId({ keepUnderscore: true }); // preserves underscores from shortid output
52
52
  ```
53
53
 
54
- ### AI Services & LLM Integration
54
+ ### Web & URL Utilities
55
55
 
56
56
  ```typescript
57
- import {
58
- getAIService,
59
- getLLMRequest,
60
- getAIContext,
61
- calculateCost
57
+ import {
58
+ isValidUrl,
59
+ getBaseDomain,
60
+ getRootDomainFromUrl,
61
+ getWebLocation,
62
+ getWebRootUrl,
63
+ getWebQueryValue,
64
+ setWebQueryValue,
65
+ fixUrl
62
66
  } from '@encodeagent/platform-helper-util';
63
67
 
64
- const aiService = getAIService('gpt-4');
65
- const llmRequest = getLLMRequest(prompt, parameters);
66
- const context = getAIContext(userId, organizationId);
67
- const cost = calculateCost({ service: aiService, inputQuantity: 1000 });
68
+ isValidUrl('https://example.com'); // truthy
69
+ getBaseDomain('sub.example.com'); // 'example.com'
70
+ getRootDomainFromUrl('https://sub.example.com/path'); // 'example.com'
71
+ getWebQueryValue('https://example.com?page=2', 'page'); // '2'
72
+ setWebQueryValue('https://example.com?page=1', 'page', '2'); // 'https://example.com?page=2'
73
+
74
+ // fixUrl: promotes protocol-relative and root-relative URLs to absolute
75
+ fixUrl('//cdn.example.com/img.png', 'https', ''); // 'https://cdn.example.com/img.png'
76
+ fixUrl('/about', 'https', 'example.com'); // 'https://example.com/about'
68
77
  ```
69
78
 
70
- ### File & Content Processing
79
+ ### File & Content Type Detection
71
80
 
72
81
  ```typescript
73
- import {
74
- getFileType,
82
+ import {
83
+ getFileType,
75
84
  getContentType,
76
- processWebPage,
77
- markdownToHtml,
78
- htmlToMarkdown,
79
- cleanHtml
85
+ getFileExtension,
86
+ getAcceptMIMEs,
87
+ getAcceptExtension,
88
+ getAcceptFileExtensions,
89
+ fileExtensionInTheList,
90
+ FILE_IMAGE_LIST,
91
+ FILE_PDF_LIST
80
92
  } from '@encodeagent/platform-helper-util';
81
93
 
82
- const fileType = getFileType('document.pdf');
83
- const contentType = getContentType('.json');
84
- const webContent = await processWebPage(url, settings);
85
- const html = markdownToHtml('# Hello World');
86
- const markdown = htmlToMarkdown('<h1>Hello World</h1>');
94
+ getFileType('photo.jpg'); // 'Photo'
95
+ getFileType('report.pdf'); // 'Document'
96
+ getContentType('data.json'); // 'application/json'
97
+ getFileExtension('archive.tar.gz'); // 'gz'
98
+
99
+ // Accepted MIME / extension strings for <input accept="...">
100
+ getAcceptMIMEs('image'); // 'image/gif, image/jpeg, ...'
101
+ getAcceptExtension('document'); // '.pdf, .docx, .xlsx, .pptx'
102
+ getAcceptFileExtensions('image'); // '*.gif, *.jpg, ...'
103
+
104
+ fileExtensionInTheList('photo.png', FILE_IMAGE_LIST); // true
87
105
  ```
88
106
 
89
107
  ### Color Utilities
90
108
 
91
109
  ```typescript
92
- import {
93
- getColor,
94
- hexToRgb,
110
+ import {
111
+ getColor,
112
+ getColorTheme,
113
+ setColorTheme,
114
+ hexToRgb,
115
+ hexToRgba,
116
+ hexToRgbString,
117
+ hexToRgbaString,
118
+ rgbToHex,
95
119
  isValidHex,
120
+ isValidRGB,
121
+ intToHex,
96
122
  BLUE,
97
- RED
123
+ RED,
124
+ COLORS
98
125
  } from '@encodeagent/platform-helper-util';
99
126
 
100
- const color = getColor('primary');
101
- const rgb = hexToRgb('#FF0000'); // { r: 255, g: 0, b: 0 }
102
- const isValid = isValidHex('#FF0000'); // true
127
+ // Tailwind-style palette lookup (shades: 50–950)
128
+ getColor('blue', 500); // '#3b82f6'
129
+ getColor('unknown', 500, 'sky'); // falls back to sky-500
130
+
131
+ // Full theme object
132
+ getColorTheme('red'); // RED constant
133
+
134
+ // Hex ↔ RGB conversion
135
+ hexToRgb('#FF0000'); // { r: 255, g: 0, b: 0 }
136
+ hexToRgba('#FF0000', 0.5); // { r: 255, g: 0, b: 0, a: 0.5 }
137
+ hexToRgbString('#3b82f6'); // 'rgba(59,130,246)'
138
+ rgbToHex('rgb(59, 130, 246)'); // '#3b82f6'
139
+ isValidHex('#3b82f6'); // true
140
+ isValidRGB('rgba(0,0,0,0.5)'); // true
103
141
  ```
104
142
 
105
- ### Web & URL Utilities
143
+ ### Authentication & Authorization
144
+
145
+ ```typescript
146
+ import {
147
+ checkRecordPrivilege,
148
+ hasRole,
149
+ hasAllRoles,
150
+ hasAnyRole,
151
+ isOwner,
152
+ isMember,
153
+ checkPrivileges,
154
+ checkPrivilege,
155
+ checkLicenses,
156
+ hasLicense,
157
+ isReader,
158
+ isAuthor
159
+ } from '@encodeagent/platform-helper-util';
160
+
161
+ const canEdit = checkRecordPrivilege(record, context, 'update');
162
+ const userHasRole = hasRole(user, 'admin');
163
+ const owned = isOwner(record, userId);
164
+ ```
165
+
166
+ ### AI Services & LLM Integration
106
167
 
107
168
  ```typescript
108
- import {
109
- isValidUrl,
110
- getBaseDomain,
111
- fixUrl,
112
- getWebQueryValue
169
+ import {
170
+ getAiService,
171
+ getAiServices,
172
+ getAiModel,
173
+ getAiModels,
174
+ getAiPlatform,
175
+ getAiProvider,
176
+ getDefaultAiService,
177
+ getLLMRequest,
178
+ getLLMParameters,
179
+ getLLMPrompt,
180
+ calculateCost
113
181
  } from '@encodeagent/platform-helper-util';
114
182
 
115
- const isValid = isValidUrl('https://example.com');
116
- const domain = getBaseDomain('https://sub.example.com/path');
117
- const fixedUrl = fixUrl('example.com'); // 'https://example.com'
183
+ const service = getAiService('gpt-4');
184
+ const request = getLLMRequest({ ... });
185
+ const cost = calculateCost({ service, inputQuantity: 1000, outputQuantity: 200 });
118
186
  ```
119
187
 
120
188
  ### Record & Data Management
121
189
 
122
190
  ```typescript
123
- import {
124
- getRecordDisplay,
191
+ import {
192
+ getRecordDisplay,
125
193
  convertRecordForCreate,
126
194
  getContextFromRecord,
127
- applyRecordSlug
195
+ applyRecordSlug,
196
+ getRecordSlug,
197
+ getRecordAbstract,
198
+ getRecordPageMetadata,
199
+ fromOtherOrganization,
200
+ isFavorite
201
+ } from '@encodeagent/platform-helper-util';
202
+
203
+ const display = getRecordDisplay(record, entity);
204
+ const createReady = convertRecordForCreate(record);
205
+ const context = getContextFromRecord(record);
206
+ ```
207
+
208
+ ### HTML & Markdown Processing
209
+
210
+ ```typescript
211
+ import {
212
+ markdownToHtml,
213
+ htmlToMarkdown,
214
+ normalizeHtmlForMarkdown,
215
+ cleanHtml,
216
+ beautifyHtml,
217
+ removeHtmlAttributes,
218
+ removeHtmlComments,
219
+ removeHtmlElements
128
220
  } from '@encodeagent/platform-helper-util';
129
221
 
130
- const display = getRecordDisplay(record, entity);
131
- const createRecord = convertRecordForCreate(record);
132
- const context = getContextFromRecord(record);
222
+ const html = markdownToHtml('# Hello World');
223
+ const markdown = htmlToMarkdown('<h1>Hello World</h1>');
224
+ ```
225
+
226
+ ### Web Content Processing
227
+
228
+ ```typescript
229
+ import { processWebPage, getMetadata, getRSSFeed } from '@encodeagent/platform-helper-util';
230
+
231
+ const result = await processWebPage(url, settings);
232
+ const meta = await getMetadata(url);
233
+ const feed = await getRSSFeed(feedUrl);
133
234
  ```
134
235
 
135
236
  ### Tree Operations
136
237
 
137
238
  ```typescript
138
- import {
139
- getTreeItem,
140
- insertTreeItem,
239
+ import {
240
+ getTreeItem,
241
+ insertTreeItem,
141
242
  removeTreeItem,
142
- updateTreeItem
243
+ replaceTreeItem,
244
+ updateTreeItem,
245
+ updateAllTreeItems,
246
+ getTreeItemPath,
247
+ getTreeItemHavingPropValue,
248
+ getTreeItemAndChildrenIds
143
249
  } from '@encodeagent/platform-helper-util';
144
250
 
145
- const item = getTreeItem(tree, itemId);
146
- const newTree = insertTreeItem(tree, parentId, newItem);
147
- const updatedTree = removeTreeItem(tree, itemId);
251
+ // Find a node by predicate
252
+ const item = getTreeItem(tree, (n) => n.id === targetId);
253
+
254
+ // Insert relative to a known node
255
+ const updated = insertTreeItem(tree, parentId, newItem, 'children');
256
+
257
+ // Remove a node by ID
258
+ const pruned = removeTreeItem(tree, itemId);
148
259
  ```
149
260
 
150
261
  ### Caching
151
262
 
152
263
  ```typescript
153
- import {
154
- getCache,
155
- setCache,
156
- removeCache
264
+ import {
265
+ getCache,
266
+ setCache,
267
+ removeCache,
268
+ getCacheByGroupId,
269
+ setCacheByGroupId,
270
+ removeCacheByGroupId,
271
+ resetCacheByGroupId
157
272
  } from '@encodeagent/platform-helper-util';
158
273
 
274
+ setCache('myKey', data);
159
275
  const cached = getCache('myKey');
160
- setCache('myKey', data, 60); // Cache for 60 minutes
161
276
  removeCache('myKey');
162
277
  ```
163
278
 
164
- ### ID Generation
279
+ ### Object Property Access
165
280
 
166
281
  ```typescript
167
- import {
168
- newGuid,
169
- newShortId,
170
- slug
282
+ import {
283
+ getPropValueOfObject,
284
+ getIntValueOfObject,
285
+ getFloatValueOfObject,
286
+ getBooleanValueOfObject,
287
+ getArrayPropValueOfObject,
288
+ getBooleanPropValue,
289
+ getObjectPropValue
171
290
  } from '@encodeagent/platform-helper-util';
172
291
 
173
- const guid = newGuid(); // '550e8400-e29b-41d4-a716-446655440000'
174
- const shortId = newShortId(); // 'rJUWbIHOWM'
175
- const urlSlug = slug('Hello World!'); // 'hello-world'
292
+ // Supports dot-notation for nested paths
293
+ getPropValueOfObject(obj, 'user.address.city');
294
+
295
+ // Type-coercing accessors with optional defaults
296
+ getIntValueOfObject(obj, 'count', 0);
297
+ getBooleanValueOfObject(obj, 'enabled', false);
298
+ ```
299
+
300
+ ### Logging
301
+
302
+ ```typescript
303
+ import { logger, createLogger, LogLevel, Logger } from '@encodeagent/platform-helper-util';
304
+ import type { ILoggerConfig } from '@encodeagent/platform-helper-util';
305
+
306
+ // Default logger (INFO level)
307
+ logger.info('Starting up');
308
+ logger.warn('Low memory');
309
+ logger.error('Something failed');
310
+
311
+ // Custom logger
312
+ const log = createLogger({ level: 'debug' });
313
+ log.debug('Detailed trace', { payload });
314
+ log.setLevel('warn');
176
315
  ```
177
316
 
178
- ## Type Definitions
317
+ ### API Helpers
179
318
 
180
- The library exports comprehensive TypeScript types:
319
+ ```typescript
320
+ import {
321
+ sendApiSuccess,
322
+ sendApiError,
323
+ sendValidationError,
324
+ validateContentType,
325
+ getPostData,
326
+ getHeaderData,
327
+ getApiRequestInfo
328
+ } from '@encodeagent/platform-helper-util';
329
+ ```
330
+
331
+ ## Key Types
181
332
 
182
333
  ```typescript
183
- import type {
184
- IContext,
185
- IError,
186
- IService,
334
+ import type {
335
+ IContext,
336
+ IError,
337
+ IService,
187
338
  ICost,
339
+ ICostItem,
340
+ ISurcharge,
341
+ ICostKey,
188
342
  TKeyOwner,
189
- TToken,
190
- TLLMMessage
343
+ IRecord,
344
+ ILLMRequest,
345
+ ILLMMessage,
346
+ IAiModel,
347
+ TAiModelPlatform,
348
+ ILoggerConfig,
349
+ TWebLocation,
350
+ TColor,
351
+ TRGB,
352
+ TRGBA,
353
+ TFileInfo
191
354
  } from '@encodeagent/platform-helper-util';
192
355
  ```
193
356
 
194
357
  ## Constants
195
358
 
196
- Access platform constants and configurations:
197
-
198
359
  ```typescript
199
- import {
360
+ import {
200
361
  GUID_EMPTY,
201
362
  DEFAULT_PASSWORD_RULE,
202
363
  COUNTRIES,
203
364
  LANGUAGES,
204
- ERROR_HTTP_LIST
365
+ GENDERS,
366
+ SURCHARGE,
367
+ CREDIT_EXCHANGE_RATE,
368
+ ERROR_HTTP_LIST,
369
+ // Color palettes
370
+ BLUE, RED, GREEN, GRAY, SLATE, ZINC, COLORS
205
371
  } from '@encodeagent/platform-helper-util';
206
372
  ```
207
373
 
208
374
  ## Development
209
375
 
210
- ### Setup
211
-
212
376
  ```bash
213
377
  npm install
214
- ```
215
-
216
- ### Build
217
-
218
- ```bash
219
- npm run build
220
- npm run build:watch
221
- ```
222
-
223
- ### Test
224
-
225
- ```bash
226
- npm test
378
+ npm run build # compile TypeScript → dist/
379
+ npm run build:watch # watch mode
380
+ npm test # run Jest
227
381
  npm run test:watch
228
- ```
229
-
230
- ### Lint
231
-
232
- ```bash
233
382
  npm run lint
234
383
  npm run lint:fix
235
- ```
236
-
237
- ### Clean
238
-
239
- ```bash
240
- npm run clean
384
+ npm run format # auto-format all source files with Prettier
385
+ npm run format:check # CI check — exits 1 if any file needs formatting
386
+ npm run clean # remove dist/
241
387
  ```
242
388
 
243
389
  ## Publishing
244
390
 
245
- ### Automated Publishing (Recommended)
246
-
247
391
  ```bash
248
- sh publish.sh
249
- ```
250
-
251
- This script will:
252
- 1. Clean previous builds
253
- 2. Run tests
254
- 3. Build the project
255
- 4. Update version automatically
256
- 5. Publish to npm
392
+ # Automated (recommended): clean → test → build → version bump → publish
393
+ sh run-publish.sh
257
394
 
258
- ### Manual Publishing
259
-
260
- ```bash
395
+ # Manual
261
396
  npm run prepublishOnly
262
397
  npm publish
263
398
  ```
264
399
 
265
- ## Scripts
266
-
267
- - `build` - Compile TypeScript to JavaScript
268
- - `build:watch` - Watch mode compilation
269
- - `clean` - Remove dist directory
270
- - `test` - Run Jest tests
271
- - `test:watch` - Run tests in watch mode
272
- - `lint` - Run ESLint
273
- - `lint:fix` - Fix ESLint issues
274
- - `prepublishOnly` - Clean and build before publishing
275
-
276
400
  ## License
277
401
 
278
- UNLICENSED - PrimeObjects Software Inc. All rights reserved.
402
+ UNLICENSED PrimeObjects Software Inc. All rights reserved.
package/dist/api.d.ts CHANGED
@@ -41,21 +41,41 @@ export interface IApiRequestInfo {
41
41
  organizationId?: string;
42
42
  solutionId?: string;
43
43
  }
44
+ /**
45
+ * Extracts a minimal, loggable request-identity snapshot from a full `IApiRequestProps` object.
46
+ * Pulls `userId`, `organizationId`, and `solutionId` from the nested `context` if present.
47
+ */
44
48
  export declare const getApiRequestInfo: (props: IApiRequestProps) => IApiRequestInfo;
45
49
  export interface ISendInvalidContentTypeErrorProps extends IApiRequestProps {
46
50
  value: string;
47
51
  }
52
+ /**
53
+ * Sends an HTTP 415 Unsupported Media Type error response, informing the client
54
+ * which `Content-Type` value is required.
55
+ * @param props.value - The expected Content-Type value (e.g. `"application/json"`)
56
+ */
48
57
  export declare const sendInvalidContentTypeError: (props: ISendInvalidContentTypeErrorProps) => any;
49
58
  export interface IValidateContentTypeProps extends IApiRequestProps {
50
59
  error: IError;
51
60
  value: string;
52
61
  }
62
+ /**
63
+ * Checks that the request's `Content-Type` header contains `props.value`.
64
+ * Delegates to `validateHeader` with `headerName` fixed to `"Content-Type"`.
65
+ * Returns `false` (and sends a 415 response via the error prop) when the header does not match.
66
+ */
53
67
  export declare const validateContentType: (props: IValidateContentTypeProps) => boolean;
54
68
  export interface IValidateHeaderProps extends IApiRequestProps {
55
69
  error: IError;
56
70
  headerName: string;
57
71
  headerValue: string;
58
72
  }
73
+ /**
74
+ * Checks that a specific request header contains the expected value.
75
+ * Reads the header using the platform-appropriate API (express / next.js).
76
+ * Lambda and Azure are not yet implemented and always return `false`.
77
+ * @returns `true` when the header value contains `props.headerValue`
78
+ */
59
79
  export declare const validateHeader: (props: IValidateHeaderProps) => boolean;
60
80
  export interface IApiRequestSuccessProps extends IApiRequestProps {
61
81
  }
@@ -75,6 +95,12 @@ export interface IApiRequestErrorResult extends IApiRequestErrorProps {
75
95
  /**
76
96
  * Send an error API response
77
97
  */
98
+ /**
99
+ * Sends a structured error API response. Merges `package`, `module`, `source`, and `platform`
100
+ * from `props` into the error object if not already set. Logs the error detail when `logDetail`
101
+ * is true, and optionally includes the original request body in the response via `includeRequest`.
102
+ * Lambda and Azure platforms are not yet implemented.
103
+ */
78
104
  export declare const sendApiError: (props: IApiRequestErrorProps) => any;
79
105
  /**
80
106
  * Handle validation errors from Zod
@@ -93,6 +119,12 @@ export interface IGetPostDataResult {
93
119
  error?: any;
94
120
  data: Record<string, any>;
95
121
  }
122
+ /**
123
+ * Reads and parses the request body based on platform and `Content-Type` header.
124
+ * Supports `express` (pre-parsed `req.body` or raw stream fallback) and `nextjs` (`request.json()`).
125
+ * Lambda and Azure are not yet implemented and return `{ data: {} }`.
126
+ * Returns `{ error, data: {} }` on parse failure.
127
+ */
96
128
  export declare const getPostData: (props: IGetPostDataProps) => Promise<IGetPostDataResult>;
97
129
  export interface IGetHeaderDataProps extends IApiRequestProps {
98
130
  }
@@ -104,5 +136,11 @@ export interface IGetHeaderDataResult {
104
136
  error?: any;
105
137
  data: Record<string, any>;
106
138
  }
139
+ /**
140
+ * Extracts all request headers into a plain lowercase-keyed object.
141
+ * - `express`: reads from `request.headers` (Node `IncomingHttpHeaders`)
142
+ * - `nextjs`: reads from `request.headers` (Web `Headers` instance)
143
+ * Lambda and Azure are not yet implemented and return `{ data: {} }`.
144
+ */
107
145
  export declare const getHeaderData: (props: IGetHeaderDataProps) => Promise<IGetHeaderDataResult>;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