pika-shared 1.0.2

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 (75) hide show
  1. package/LICENSE +9 -0
  2. package/dist/index.d.mts +15 -0
  3. package/dist/index.d.ts +15 -0
  4. package/dist/index.js +11 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.mjs +9 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/dist/types/chatbot/bedrock-lambda-error.d.mts +12 -0
  9. package/dist/types/chatbot/bedrock-lambda-error.d.ts +12 -0
  10. package/dist/types/chatbot/bedrock-lambda-error.js +12 -0
  11. package/dist/types/chatbot/bedrock-lambda-error.js.map +1 -0
  12. package/dist/types/chatbot/bedrock-lambda-error.mjs +10 -0
  13. package/dist/types/chatbot/bedrock-lambda-error.mjs.map +1 -0
  14. package/dist/types/chatbot/bedrock.d.mts +489 -0
  15. package/dist/types/chatbot/bedrock.d.ts +489 -0
  16. package/dist/types/chatbot/bedrock.js +4 -0
  17. package/dist/types/chatbot/bedrock.js.map +1 -0
  18. package/dist/types/chatbot/bedrock.mjs +3 -0
  19. package/dist/types/chatbot/bedrock.mjs.map +1 -0
  20. package/dist/types/chatbot/chatbot-types.d.mts +2240 -0
  21. package/dist/types/chatbot/chatbot-types.d.ts +2240 -0
  22. package/dist/types/chatbot/chatbot-types.js +358 -0
  23. package/dist/types/chatbot/chatbot-types.js.map +1 -0
  24. package/dist/types/chatbot/chatbot-types.mjs +301 -0
  25. package/dist/types/chatbot/chatbot-types.mjs.map +1 -0
  26. package/dist/types/upload-types.d.mts +29 -0
  27. package/dist/types/upload-types.d.ts +29 -0
  28. package/dist/types/upload-types.js +4 -0
  29. package/dist/types/upload-types.js.map +1 -0
  30. package/dist/types/upload-types.mjs +3 -0
  31. package/dist/types/upload-types.mjs.map +1 -0
  32. package/dist/util/api-gateway-utils.d.mts +133 -0
  33. package/dist/util/api-gateway-utils.d.ts +133 -0
  34. package/dist/util/api-gateway-utils.js +77 -0
  35. package/dist/util/api-gateway-utils.js.map +1 -0
  36. package/dist/util/api-gateway-utils.mjs +73 -0
  37. package/dist/util/api-gateway-utils.mjs.map +1 -0
  38. package/dist/util/bedrock.d.mts +53 -0
  39. package/dist/util/bedrock.d.ts +53 -0
  40. package/dist/util/bedrock.js +80 -0
  41. package/dist/util/bedrock.js.map +1 -0
  42. package/dist/util/bedrock.mjs +74 -0
  43. package/dist/util/bedrock.mjs.map +1 -0
  44. package/dist/util/chatbot-shared-utils.d.mts +42 -0
  45. package/dist/util/chatbot-shared-utils.d.ts +42 -0
  46. package/dist/util/chatbot-shared-utils.js +44 -0
  47. package/dist/util/chatbot-shared-utils.js.map +1 -0
  48. package/dist/util/chatbot-shared-utils.mjs +33 -0
  49. package/dist/util/chatbot-shared-utils.mjs.map +1 -0
  50. package/dist/util/http-status-error.d.mts +9 -0
  51. package/dist/util/http-status-error.d.ts +9 -0
  52. package/dist/util/http-status-error.js +13 -0
  53. package/dist/util/http-status-error.js.map +1 -0
  54. package/dist/util/http-status-error.mjs +11 -0
  55. package/dist/util/http-status-error.mjs.map +1 -0
  56. package/dist/util/jwt.d.mts +24 -0
  57. package/dist/util/jwt.d.ts +24 -0
  58. package/dist/util/jwt.js +54 -0
  59. package/dist/util/jwt.js.map +1 -0
  60. package/dist/util/jwt.mjs +31 -0
  61. package/dist/util/jwt.mjs.map +1 -0
  62. package/dist/util/server-client-utils.d.mts +15 -0
  63. package/dist/util/server-client-utils.d.ts +15 -0
  64. package/dist/util/server-client-utils.js +37 -0
  65. package/dist/util/server-client-utils.js.map +1 -0
  66. package/dist/util/server-client-utils.mjs +34 -0
  67. package/dist/util/server-client-utils.mjs.map +1 -0
  68. package/dist/util/server-utils.d.mts +4 -0
  69. package/dist/util/server-utils.d.ts +4 -0
  70. package/dist/util/server-utils.js +20 -0
  71. package/dist/util/server-utils.js.map +1 -0
  72. package/dist/util/server-utils.mjs +17 -0
  73. package/dist/util/server-utils.mjs.map +1 -0
  74. package/package.json +70 -0
  75. package/readme.md +3 -0
@@ -0,0 +1,42 @@
1
+ /**
2
+ * These utilities are meant to be shared both client and server.
3
+ * Don't add anything that can't be shared (especially dependencies)
4
+ */
5
+ /**
6
+ * Generate a unique S3 key name for a chat file upload.
7
+ *
8
+ * Use the uuid module to generate the v7 uuid as in
9
+ *
10
+ * Replace punctation that isn't _ or - with a _
11
+ *
12
+ * import { v7 as uuidv7 } from 'uuid';
13
+ * uuidv7()
14
+ *
15
+ * @param userId - The user id of the user uploading the file
16
+ * @param fileName - The name of the file to upload. it should already be sanitized by calling sanitizeFileName
17
+ * @param v7Uuid - The uuidv7 uuid of the file
18
+ * @returns The S3 key name for the file
19
+ */
20
+ declare function generateChatFileUploadS3KeyName(userId: string, fileName: string, v7Uuid: string): string;
21
+ /**
22
+ * Remove all punctuation from a file name except for the ending period for the file extension if it exists
23
+ *
24
+ * @param fileName - The name of the file to sanitize
25
+ * @returns The sanitized file name
26
+ */
27
+ declare function sanitizeFileName(fileName: string): string;
28
+ type ToSnakeCase<S extends string> = S extends `${infer T}${infer U}` ? `${T extends Capitalize<T> ? '_' : ''}${Lowercase<T>}${ToSnakeCase<U>}` : S;
29
+ type ToCamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}` ? `${Lowercase<P1>}${Uppercase<P2>}${ToCamelCase<P3>}` : Lowercase<S>;
30
+ type SnakeCase<T> = {
31
+ [K in keyof T as K extends string ? ToSnakeCase<K> : K]: T[K] extends object ? SnakeCase<T[K]> : T[K];
32
+ };
33
+ type CamelCase<T> = {
34
+ [K in keyof T as K extends string ? ToCamelCase<K> : K]: T[K] extends object ? CamelCase<T[K]> : T[K];
35
+ };
36
+ declare function convertToCamelCase<T extends object>(data: SnakeCase<T>): T;
37
+ declare function convertToSnakeCase<T extends {
38
+ [key: string]: any;
39
+ }>(data: T): SnakeCase<T>;
40
+ declare function convertStringToSnakeCase(str: string): string;
41
+
42
+ export { type CamelCase, type SnakeCase, convertStringToSnakeCase, convertToCamelCase, convertToSnakeCase, generateChatFileUploadS3KeyName, sanitizeFileName };
@@ -0,0 +1,42 @@
1
+ /**
2
+ * These utilities are meant to be shared both client and server.
3
+ * Don't add anything that can't be shared (especially dependencies)
4
+ */
5
+ /**
6
+ * Generate a unique S3 key name for a chat file upload.
7
+ *
8
+ * Use the uuid module to generate the v7 uuid as in
9
+ *
10
+ * Replace punctation that isn't _ or - with a _
11
+ *
12
+ * import { v7 as uuidv7 } from 'uuid';
13
+ * uuidv7()
14
+ *
15
+ * @param userId - The user id of the user uploading the file
16
+ * @param fileName - The name of the file to upload. it should already be sanitized by calling sanitizeFileName
17
+ * @param v7Uuid - The uuidv7 uuid of the file
18
+ * @returns The S3 key name for the file
19
+ */
20
+ declare function generateChatFileUploadS3KeyName(userId: string, fileName: string, v7Uuid: string): string;
21
+ /**
22
+ * Remove all punctuation from a file name except for the ending period for the file extension if it exists
23
+ *
24
+ * @param fileName - The name of the file to sanitize
25
+ * @returns The sanitized file name
26
+ */
27
+ declare function sanitizeFileName(fileName: string): string;
28
+ type ToSnakeCase<S extends string> = S extends `${infer T}${infer U}` ? `${T extends Capitalize<T> ? '_' : ''}${Lowercase<T>}${ToSnakeCase<U>}` : S;
29
+ type ToCamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}` ? `${Lowercase<P1>}${Uppercase<P2>}${ToCamelCase<P3>}` : Lowercase<S>;
30
+ type SnakeCase<T> = {
31
+ [K in keyof T as K extends string ? ToSnakeCase<K> : K]: T[K] extends object ? SnakeCase<T[K]> : T[K];
32
+ };
33
+ type CamelCase<T> = {
34
+ [K in keyof T as K extends string ? ToCamelCase<K> : K]: T[K] extends object ? CamelCase<T[K]> : T[K];
35
+ };
36
+ declare function convertToCamelCase<T extends object>(data: SnakeCase<T>): T;
37
+ declare function convertToSnakeCase<T extends {
38
+ [key: string]: any;
39
+ }>(data: T): SnakeCase<T>;
40
+ declare function convertStringToSnakeCase(str: string): string;
41
+
42
+ export { type CamelCase, type SnakeCase, convertStringToSnakeCase, convertToCamelCase, convertToSnakeCase, generateChatFileUploadS3KeyName, sanitizeFileName };
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ var camelcaseKeys = require('camelcase-keys');
4
+ var snakecaseKeys = require('snakecase-keys');
5
+
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
+
8
+ var camelcaseKeys__default = /*#__PURE__*/_interopDefault(camelcaseKeys);
9
+ var snakecaseKeys__default = /*#__PURE__*/_interopDefault(snakecaseKeys);
10
+
11
+ // src/util/chatbot-shared-utils.ts
12
+ function generateChatFileUploadS3KeyName(userId, fileName, v7Uuid) {
13
+ return `uploads/${userId}/${v7Uuid}_${fileName}`;
14
+ }
15
+ function sanitizeFileName(fileName) {
16
+ const lastDotIndex = fileName.lastIndexOf(".");
17
+ if (lastDotIndex === -1 || lastDotIndex === fileName.length - 1 || lastDotIndex === 0) {
18
+ return fileName.replace(/[^a-zA-Z0-9_-]/g, "");
19
+ }
20
+ const nameWithoutExtension = fileName.substring(0, lastDotIndex);
21
+ const extension = fileName.substring(lastDotIndex + 1);
22
+ const sanitizedName = nameWithoutExtension.replace(/[^a-zA-Z0-9_-]/g, "");
23
+ const sanitizedExtension = extension.replace(/[^a-zA-Z0-9_-]/g, "");
24
+ return sanitizedName + "." + sanitizedExtension;
25
+ }
26
+ function convertToCamelCase(data) {
27
+ return camelcaseKeys__default.default(data, { deep: true });
28
+ }
29
+ function convertToSnakeCase(data) {
30
+ return snakecaseKeys__default.default(data, { deep: true });
31
+ }
32
+ function convertStringToSnakeCase(str) {
33
+ const tempObj = { [str]: true };
34
+ const converted = snakecaseKeys__default.default(tempObj);
35
+ return Object.keys(converted)[0];
36
+ }
37
+
38
+ exports.convertStringToSnakeCase = convertStringToSnakeCase;
39
+ exports.convertToCamelCase = convertToCamelCase;
40
+ exports.convertToSnakeCase = convertToSnakeCase;
41
+ exports.generateChatFileUploadS3KeyName = generateChatFileUploadS3KeyName;
42
+ exports.sanitizeFileName = sanitizeFileName;
43
+ //# sourceMappingURL=chatbot-shared-utils.js.map
44
+ //# sourceMappingURL=chatbot-shared-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/chatbot-shared-utils.ts"],"names":["camelcaseKeys","snakecaseKeys"],"mappings":";;;;;;;;;;;AAwBO,SAAS,+BAAA,CAAgC,MAAgB,EAAA,QAAA,EAAkB,MAAwB,EAAA;AACtG,EAAA,OAAO,CAAW,QAAA,EAAA,MAAM,CAAI,CAAA,EAAA,MAAM,IAAI,QAAQ,CAAA,CAAA;AAClD;AAQO,SAAS,iBAAiB,QAA0B,EAAA;AACvD,EAAM,MAAA,YAAA,GAAe,QAAS,CAAA,WAAA,CAAY,GAAG,CAAA;AAG7C,EAAA,IAAI,iBAAiB,EAAM,IAAA,YAAA,KAAiB,SAAS,MAAS,GAAA,CAAA,IAAK,iBAAiB,CAAG,EAAA;AACnF,IAAO,OAAA,QAAA,CAAS,OAAQ,CAAA,iBAAA,EAAmB,EAAE,CAAA;AAAA;AAGjD,EAAA,MAAM,oBAAuB,GAAA,QAAA,CAAS,SAAU,CAAA,CAAA,EAAG,YAAY,CAAA;AAC/D,EAAA,MAAM,SAAY,GAAA,QAAA,CAAS,SAAU,CAAA,YAAA,GAAe,CAAC,CAAA;AAErD,EAAA,MAAM,aAAgB,GAAA,oBAAA,CAAqB,OAAQ,CAAA,iBAAA,EAAmB,EAAE,CAAA;AACxE,EAAA,MAAM,kBAAqB,GAAA,SAAA,CAAU,OAAQ,CAAA,iBAAA,EAAmB,EAAE,CAAA;AAElE,EAAA,OAAO,gBAAgB,GAAM,GAAA,kBAAA;AACjC;AAcO,SAAS,mBAAqC,IAAuB,EAAA;AACxE,EAAA,OAAOA,8BAAc,CAAA,IAAA,EAAM,EAAE,IAAA,EAAM,MAAM,CAAA;AAC7C;AAEO,SAAS,mBAAqD,IAAuB,EAAA;AACxF,EAAA,OAAOC,8BAAc,CAAA,IAAA,EAAM,EAAE,IAAA,EAAM,MAAM,CAAA;AAC7C;AAEO,SAAS,yBAAyB,GAAqB,EAAA;AAC1D,EAAA,MAAM,OAAU,GAAA,EAAE,CAAC,GAAG,GAAG,IAAK,EAAA;AAC9B,EAAM,MAAA,SAAA,GAAYA,+BAAc,OAAO,CAAA;AACvC,EAAA,OAAO,MAAO,CAAA,IAAA,CAAK,SAAS,CAAA,CAAE,CAAC,CAAA;AACnC","file":"chatbot-shared-utils.js","sourcesContent":["/**\n * These utilities are meant to be shared both client and server.\n * Don't add anything that can't be shared (especially dependencies)\n */\n\nimport type { ChatApp, ChatAppFeature, FeatureIdType } from '../types/chatbot/chatbot-types';\nimport camelcaseKeys from 'camelcase-keys';\nimport snakecaseKeys from 'snakecase-keys';\n\n/**\n * Generate a unique S3 key name for a chat file upload.\n *\n * Use the uuid module to generate the v7 uuid as in\n *\n * Replace punctation that isn't _ or - with a _\n *\n * import { v7 as uuidv7 } from 'uuid';\n * uuidv7()\n *\n * @param userId - The user id of the user uploading the file\n * @param fileName - The name of the file to upload. it should already be sanitized by calling sanitizeFileName\n * @param v7Uuid - The uuidv7 uuid of the file\n * @returns The S3 key name for the file\n */\nexport function generateChatFileUploadS3KeyName(userId: string, fileName: string, v7Uuid: string): string {\n return `uploads/${userId}/${v7Uuid}_${fileName}`;\n}\n\n/**\n * Remove all punctuation from a file name except for the ending period for the file extension if it exists\n *\n * @param fileName - The name of the file to sanitize\n * @returns The sanitized file name\n */\nexport function sanitizeFileName(fileName: string): string {\n const lastDotIndex = fileName.lastIndexOf('.');\n\n // If there's no dot, or the dot is at the end, or the dot is at the beginning, just remove all punctuation\n if (lastDotIndex === -1 || lastDotIndex === fileName.length - 1 || lastDotIndex === 0) {\n return fileName.replace(/[^a-zA-Z0-9_-]/g, '');\n }\n\n const nameWithoutExtension = fileName.substring(0, lastDotIndex);\n const extension = fileName.substring(lastDotIndex + 1);\n\n const sanitizedName = nameWithoutExtension.replace(/[^a-zA-Z0-9_-]/g, '');\n const sanitizedExtension = extension.replace(/[^a-zA-Z0-9_-]/g, '');\n\n return sanitizedName + '.' + sanitizedExtension;\n}\n\ntype ToSnakeCase<S extends string> = S extends `${infer T}${infer U}` ? `${T extends Capitalize<T> ? '_' : ''}${Lowercase<T>}${ToSnakeCase<U>}` : S;\n\ntype ToCamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}` ? `${Lowercase<P1>}${Uppercase<P2>}${ToCamelCase<P3>}` : Lowercase<S>;\n\nexport type SnakeCase<T> = {\n [K in keyof T as K extends string ? ToSnakeCase<K> : K]: T[K] extends object ? SnakeCase<T[K]> : T[K];\n};\n\nexport type CamelCase<T> = {\n [K in keyof T as K extends string ? ToCamelCase<K> : K]: T[K] extends object ? CamelCase<T[K]> : T[K];\n};\n\nexport function convertToCamelCase<T extends object>(data: SnakeCase<T>): T {\n return camelcaseKeys(data, { deep: true }) as unknown as T;\n}\n\nexport function convertToSnakeCase<T extends { [key: string]: any }>(data: T): SnakeCase<T> {\n return snakecaseKeys(data, { deep: true }) as SnakeCase<T>;\n}\n\nexport function convertStringToSnakeCase(str: string): string {\n const tempObj = { [str]: true };\n const converted = snakecaseKeys(tempObj);\n return Object.keys(converted)[0];\n}\n\n// /**\n// * This lets us get a feature from a chat app and make sure it is the correct type.\n// */\n// export function getFeature<T extends FeatureIdType>(chatApp: ChatApp, featureId: T): Extract<ChatAppFeature, { featureId: T }> | undefined {\n// const feature = chatApp.features?.[featureId];\n\n// if (feature && feature.featureId === featureId) {\n// return feature as Extract<ChatAppFeature, { featureId: T }>;\n// }\n\n// return undefined;\n// }\n"]}
@@ -0,0 +1,33 @@
1
+ import camelcaseKeys from 'camelcase-keys';
2
+ import snakecaseKeys from 'snakecase-keys';
3
+
4
+ // src/util/chatbot-shared-utils.ts
5
+ function generateChatFileUploadS3KeyName(userId, fileName, v7Uuid) {
6
+ return `uploads/${userId}/${v7Uuid}_${fileName}`;
7
+ }
8
+ function sanitizeFileName(fileName) {
9
+ const lastDotIndex = fileName.lastIndexOf(".");
10
+ if (lastDotIndex === -1 || lastDotIndex === fileName.length - 1 || lastDotIndex === 0) {
11
+ return fileName.replace(/[^a-zA-Z0-9_-]/g, "");
12
+ }
13
+ const nameWithoutExtension = fileName.substring(0, lastDotIndex);
14
+ const extension = fileName.substring(lastDotIndex + 1);
15
+ const sanitizedName = nameWithoutExtension.replace(/[^a-zA-Z0-9_-]/g, "");
16
+ const sanitizedExtension = extension.replace(/[^a-zA-Z0-9_-]/g, "");
17
+ return sanitizedName + "." + sanitizedExtension;
18
+ }
19
+ function convertToCamelCase(data) {
20
+ return camelcaseKeys(data, { deep: true });
21
+ }
22
+ function convertToSnakeCase(data) {
23
+ return snakecaseKeys(data, { deep: true });
24
+ }
25
+ function convertStringToSnakeCase(str) {
26
+ const tempObj = { [str]: true };
27
+ const converted = snakecaseKeys(tempObj);
28
+ return Object.keys(converted)[0];
29
+ }
30
+
31
+ export { convertStringToSnakeCase, convertToCamelCase, convertToSnakeCase, generateChatFileUploadS3KeyName, sanitizeFileName };
32
+ //# sourceMappingURL=chatbot-shared-utils.mjs.map
33
+ //# sourceMappingURL=chatbot-shared-utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/chatbot-shared-utils.ts"],"names":[],"mappings":";;;;AAwBO,SAAS,+BAAA,CAAgC,MAAgB,EAAA,QAAA,EAAkB,MAAwB,EAAA;AACtG,EAAA,OAAO,CAAW,QAAA,EAAA,MAAM,CAAI,CAAA,EAAA,MAAM,IAAI,QAAQ,CAAA,CAAA;AAClD;AAQO,SAAS,iBAAiB,QAA0B,EAAA;AACvD,EAAM,MAAA,YAAA,GAAe,QAAS,CAAA,WAAA,CAAY,GAAG,CAAA;AAG7C,EAAA,IAAI,iBAAiB,EAAM,IAAA,YAAA,KAAiB,SAAS,MAAS,GAAA,CAAA,IAAK,iBAAiB,CAAG,EAAA;AACnF,IAAO,OAAA,QAAA,CAAS,OAAQ,CAAA,iBAAA,EAAmB,EAAE,CAAA;AAAA;AAGjD,EAAA,MAAM,oBAAuB,GAAA,QAAA,CAAS,SAAU,CAAA,CAAA,EAAG,YAAY,CAAA;AAC/D,EAAA,MAAM,SAAY,GAAA,QAAA,CAAS,SAAU,CAAA,YAAA,GAAe,CAAC,CAAA;AAErD,EAAA,MAAM,aAAgB,GAAA,oBAAA,CAAqB,OAAQ,CAAA,iBAAA,EAAmB,EAAE,CAAA;AACxE,EAAA,MAAM,kBAAqB,GAAA,SAAA,CAAU,OAAQ,CAAA,iBAAA,EAAmB,EAAE,CAAA;AAElE,EAAA,OAAO,gBAAgB,GAAM,GAAA,kBAAA;AACjC;AAcO,SAAS,mBAAqC,IAAuB,EAAA;AACxE,EAAA,OAAO,aAAc,CAAA,IAAA,EAAM,EAAE,IAAA,EAAM,MAAM,CAAA;AAC7C;AAEO,SAAS,mBAAqD,IAAuB,EAAA;AACxF,EAAA,OAAO,aAAc,CAAA,IAAA,EAAM,EAAE,IAAA,EAAM,MAAM,CAAA;AAC7C;AAEO,SAAS,yBAAyB,GAAqB,EAAA;AAC1D,EAAA,MAAM,OAAU,GAAA,EAAE,CAAC,GAAG,GAAG,IAAK,EAAA;AAC9B,EAAM,MAAA,SAAA,GAAY,cAAc,OAAO,CAAA;AACvC,EAAA,OAAO,MAAO,CAAA,IAAA,CAAK,SAAS,CAAA,CAAE,CAAC,CAAA;AACnC","file":"chatbot-shared-utils.mjs","sourcesContent":["/**\n * These utilities are meant to be shared both client and server.\n * Don't add anything that can't be shared (especially dependencies)\n */\n\nimport type { ChatApp, ChatAppFeature, FeatureIdType } from '../types/chatbot/chatbot-types';\nimport camelcaseKeys from 'camelcase-keys';\nimport snakecaseKeys from 'snakecase-keys';\n\n/**\n * Generate a unique S3 key name for a chat file upload.\n *\n * Use the uuid module to generate the v7 uuid as in\n *\n * Replace punctation that isn't _ or - with a _\n *\n * import { v7 as uuidv7 } from 'uuid';\n * uuidv7()\n *\n * @param userId - The user id of the user uploading the file\n * @param fileName - The name of the file to upload. it should already be sanitized by calling sanitizeFileName\n * @param v7Uuid - The uuidv7 uuid of the file\n * @returns The S3 key name for the file\n */\nexport function generateChatFileUploadS3KeyName(userId: string, fileName: string, v7Uuid: string): string {\n return `uploads/${userId}/${v7Uuid}_${fileName}`;\n}\n\n/**\n * Remove all punctuation from a file name except for the ending period for the file extension if it exists\n *\n * @param fileName - The name of the file to sanitize\n * @returns The sanitized file name\n */\nexport function sanitizeFileName(fileName: string): string {\n const lastDotIndex = fileName.lastIndexOf('.');\n\n // If there's no dot, or the dot is at the end, or the dot is at the beginning, just remove all punctuation\n if (lastDotIndex === -1 || lastDotIndex === fileName.length - 1 || lastDotIndex === 0) {\n return fileName.replace(/[^a-zA-Z0-9_-]/g, '');\n }\n\n const nameWithoutExtension = fileName.substring(0, lastDotIndex);\n const extension = fileName.substring(lastDotIndex + 1);\n\n const sanitizedName = nameWithoutExtension.replace(/[^a-zA-Z0-9_-]/g, '');\n const sanitizedExtension = extension.replace(/[^a-zA-Z0-9_-]/g, '');\n\n return sanitizedName + '.' + sanitizedExtension;\n}\n\ntype ToSnakeCase<S extends string> = S extends `${infer T}${infer U}` ? `${T extends Capitalize<T> ? '_' : ''}${Lowercase<T>}${ToSnakeCase<U>}` : S;\n\ntype ToCamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}` ? `${Lowercase<P1>}${Uppercase<P2>}${ToCamelCase<P3>}` : Lowercase<S>;\n\nexport type SnakeCase<T> = {\n [K in keyof T as K extends string ? ToSnakeCase<K> : K]: T[K] extends object ? SnakeCase<T[K]> : T[K];\n};\n\nexport type CamelCase<T> = {\n [K in keyof T as K extends string ? ToCamelCase<K> : K]: T[K] extends object ? CamelCase<T[K]> : T[K];\n};\n\nexport function convertToCamelCase<T extends object>(data: SnakeCase<T>): T {\n return camelcaseKeys(data, { deep: true }) as unknown as T;\n}\n\nexport function convertToSnakeCase<T extends { [key: string]: any }>(data: T): SnakeCase<T> {\n return snakecaseKeys(data, { deep: true }) as SnakeCase<T>;\n}\n\nexport function convertStringToSnakeCase(str: string): string {\n const tempObj = { [str]: true };\n const converted = snakecaseKeys(tempObj);\n return Object.keys(converted)[0];\n}\n\n// /**\n// * This lets us get a feature from a chat app and make sure it is the correct type.\n// */\n// export function getFeature<T extends FeatureIdType>(chatApp: ChatApp, featureId: T): Extract<ChatAppFeature, { featureId: T }> | undefined {\n// const feature = chatApp.features?.[featureId];\n\n// if (feature && feature.featureId === featureId) {\n// return feature as Extract<ChatAppFeature, { featureId: T }>;\n// }\n\n// return undefined;\n// }\n"]}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Throw this error to return a specific HTTP status code from an API Gateway Lambda function.
3
+ */
4
+ declare class HttpStatusError extends Error {
5
+ readonly statusCode: number;
6
+ constructor(message: string, statusCode: number);
7
+ }
8
+
9
+ export { HttpStatusError };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Throw this error to return a specific HTTP status code from an API Gateway Lambda function.
3
+ */
4
+ declare class HttpStatusError extends Error {
5
+ readonly statusCode: number;
6
+ constructor(message: string, statusCode: number);
7
+ }
8
+
9
+ export { HttpStatusError };
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ // src/util/http-status-error.ts
4
+ var HttpStatusError = class extends Error {
5
+ constructor(message, statusCode) {
6
+ super(message);
7
+ this.statusCode = statusCode;
8
+ }
9
+ };
10
+
11
+ exports.HttpStatusError = HttpStatusError;
12
+ //# sourceMappingURL=http-status-error.js.map
13
+ //# sourceMappingURL=http-status-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/http-status-error.ts"],"names":[],"mappings":";;;AAGa,IAAA,eAAA,GAAN,cAA8B,KAAM,CAAA;AAAA,EACvC,WAAA,CACI,SACgB,UAClB,EAAA;AACE,IAAA,KAAA,CAAM,OAAO,CAAA;AAFG,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AAAA;AAIxB","file":"http-status-error.js","sourcesContent":["/**\n * Throw this error to return a specific HTTP status code from an API Gateway Lambda function.\n */\nexport class HttpStatusError extends Error {\n constructor(\n message: string,\n public readonly statusCode: number\n ) {\n super(message);\n }\n}\n"]}
@@ -0,0 +1,11 @@
1
+ // src/util/http-status-error.ts
2
+ var HttpStatusError = class extends Error {
3
+ constructor(message, statusCode) {
4
+ super(message);
5
+ this.statusCode = statusCode;
6
+ }
7
+ };
8
+
9
+ export { HttpStatusError };
10
+ //# sourceMappingURL=http-status-error.mjs.map
11
+ //# sourceMappingURL=http-status-error.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/http-status-error.ts"],"names":[],"mappings":";AAGa,IAAA,eAAA,GAAN,cAA8B,KAAM,CAAA;AAAA,EACvC,WAAA,CACI,SACgB,UAClB,EAAA;AACE,IAAA,KAAA,CAAM,OAAO,CAAA;AAFG,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AAAA;AAIxB","file":"http-status-error.mjs","sourcesContent":["/**\n * Throw this error to return a specific HTTP status code from an API Gateway Lambda function.\n */\nexport class HttpStatusError extends Error {\n constructor(\n message: string,\n public readonly statusCode: number\n ) {\n super(message);\n }\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import { RecordOrUndef, SimpleAuthenticatedUser } from '../types/chatbot/chatbot-types.mjs';
2
+ import '@aws-sdk/client-bedrock-agent-runtime';
3
+
4
+ /**
5
+ * Converts a payload containing a userId and optional customUserData into a JWT string.
6
+ *
7
+ * Here the generic T is the type of the customUserData field. If not known, pass unknown.
8
+ *
9
+ * @param payload The payload to convert to a JWT string.
10
+ * @returns A JWT string.
11
+ */
12
+ declare function convertToJwtString<T extends RecordOrUndef = undefined>(payload: SimpleAuthenticatedUser<T>, jwtSecret: string): string;
13
+ /**
14
+ * Extracts the payload from a JWT string. If successful, the first value in the tuple will be the SimpleAuthenticatedUser<T> object.
15
+ * If not successful, the first value in the tuple will be the number of the HTTP status code and the second value will be the error message,
16
+ * so check the first value to see if it is a number and if it is, then the second value will be the error message.
17
+ *
18
+ * Here the generic T is the type of the customUserData field. If not known, pass unknown.
19
+ * @param jwtToken - The JWT string to decode. Can include "Bearer " prefix which will be stripped.
20
+ * @returns An object containing the userId and optional customUserData or the number of the HTTP status code and the error message.
21
+ */
22
+ declare function extractFromJwtString<T extends RecordOrUndef = undefined>(jwtToken: string, jwtSecret: string): [SimpleAuthenticatedUser<T> | number, string | undefined];
23
+
24
+ export { convertToJwtString, extractFromJwtString };
@@ -0,0 +1,24 @@
1
+ import { RecordOrUndef, SimpleAuthenticatedUser } from '../types/chatbot/chatbot-types.js';
2
+ import '@aws-sdk/client-bedrock-agent-runtime';
3
+
4
+ /**
5
+ * Converts a payload containing a userId and optional customUserData into a JWT string.
6
+ *
7
+ * Here the generic T is the type of the customUserData field. If not known, pass unknown.
8
+ *
9
+ * @param payload The payload to convert to a JWT string.
10
+ * @returns A JWT string.
11
+ */
12
+ declare function convertToJwtString<T extends RecordOrUndef = undefined>(payload: SimpleAuthenticatedUser<T>, jwtSecret: string): string;
13
+ /**
14
+ * Extracts the payload from a JWT string. If successful, the first value in the tuple will be the SimpleAuthenticatedUser<T> object.
15
+ * If not successful, the first value in the tuple will be the number of the HTTP status code and the second value will be the error message,
16
+ * so check the first value to see if it is a number and if it is, then the second value will be the error message.
17
+ *
18
+ * Here the generic T is the type of the customUserData field. If not known, pass unknown.
19
+ * @param jwtToken - The JWT string to decode. Can include "Bearer " prefix which will be stripped.
20
+ * @returns An object containing the userId and optional customUserData or the number of the HTTP status code and the error message.
21
+ */
22
+ declare function extractFromJwtString<T extends RecordOrUndef = undefined>(jwtToken: string, jwtSecret: string): [SimpleAuthenticatedUser<T> | number, string | undefined];
23
+
24
+ export { convertToJwtString, extractFromJwtString };
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ var jwt2 = require('jsonwebtoken');
4
+
5
+ function _interopNamespace(e) {
6
+ if (e && e.__esModule) return e;
7
+ var n = Object.create(null);
8
+ if (e) {
9
+ Object.keys(e).forEach(function (k) {
10
+ if (k !== 'default') {
11
+ var d = Object.getOwnPropertyDescriptor(e, k);
12
+ Object.defineProperty(n, k, d.get ? d : {
13
+ enumerable: true,
14
+ get: function () { return e[k]; }
15
+ });
16
+ }
17
+ });
18
+ }
19
+ n.default = e;
20
+ return Object.freeze(n);
21
+ }
22
+
23
+ var jwt2__namespace = /*#__PURE__*/_interopNamespace(jwt2);
24
+
25
+ // src/util/jwt.ts
26
+ var jwt = jwt2__namespace;
27
+ if ("default" in jwt) {
28
+ jwt = jwt["default"];
29
+ }
30
+ function convertToJwtString(payload, jwtSecret) {
31
+ return jwt.sign(payload, jwtSecret, { expiresIn: "1h" });
32
+ }
33
+ function extractFromJwtString(jwtToken, jwtSecret) {
34
+ try {
35
+ const token = jwtToken.startsWith("Bearer ") ? jwtToken.substring(7) : jwtToken;
36
+ const decoded = jwt.verify(token, jwtSecret);
37
+ let userId;
38
+ let customUserData;
39
+ if (typeof decoded === "object" && decoded !== null && "userId" in decoded) {
40
+ userId = decoded.userId;
41
+ customUserData = decoded.customUserData ?? void 0;
42
+ return [{ userId, customUserData }, void 0];
43
+ }
44
+ return [401, "Unauthorized: Invalid or expired JWT token: code 1A"];
45
+ } catch (error) {
46
+ console.log("extractFromJwtString - Error message:", error instanceof Error ? error.message : "Unknown error");
47
+ return [401, `Unauthorized: Invalid or expired JWT token: code 1B`];
48
+ }
49
+ }
50
+
51
+ exports.convertToJwtString = convertToJwtString;
52
+ exports.extractFromJwtString = extractFromJwtString;
53
+ //# sourceMappingURL=jwt.js.map
54
+ //# sourceMappingURL=jwt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/jwt.ts"],"names":["jwt2"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAI,GAAM,GAAAA,eAAA;AACV,IAAI,aAAa,GAAK,EAAA;AAClB,EAAA,GAAA,GAAM,IAAI,SAAS,CAAA;AACvB;AAUO,SAAS,kBAAA,CAAwD,SAAqC,SAA2B,EAAA;AACpI,EAAA,OAAO,IAAI,IAAK,CAAA,OAAA,EAAS,WAAW,EAAE,SAAA,EAAW,MAAM,CAAA;AAC3D;AAWO,SAAS,oBAAA,CAA0D,UAAkB,SAA8E,EAAA;AACtK,EAAI,IAAA;AAEA,IAAM,MAAA,KAAA,GAAQ,SAAS,UAAW,CAAA,SAAS,IAAI,QAAS,CAAA,SAAA,CAAU,CAAC,CAAI,GAAA,QAAA;AACvE,IAAA,MAAM,OAAU,GAAA,GAAA,CAAI,MAAO,CAAA,KAAA,EAAO,SAAS,CAAA;AAE3C,IAAI,IAAA,MAAA;AACJ,IAAI,IAAA,cAAA;AAEJ,IAAA,IAAI,OAAO,OAAY,KAAA,QAAA,IAAY,OAAY,KAAA,IAAA,IAAQ,YAAY,OAAS,EAAA;AACxE,MAAA,MAAA,GAAU,OAA+B,CAAA,MAAA;AACzC,MAAA,cAAA,GAAkB,QAAkC,cAAkB,IAAA,KAAA,CAAA;AACtE,MAAA,OAAO,CAAC,EAAE,MAAQ,EAAA,cAAA,IAAkB,KAAS,CAAA,CAAA;AAAA;AAGjD,IAAO,OAAA,CAAC,KAAK,qDAAqD,CAAA;AAAA,WAC7D,KAAO,EAAA;AACZ,IAAA,OAAA,CAAQ,IAAI,uCAAyC,EAAA,KAAA,YAAiB,KAAQ,GAAA,KAAA,CAAM,UAAU,eAAe,CAAA;AAC7G,IAAO,OAAA,CAAC,KAAK,CAAqD,mDAAA,CAAA,CAAA;AAAA;AAE1E","file":"jwt.js","sourcesContent":["import type { RecordOrUndef, SimpleAuthenticatedUser } from '../types/chatbot/chatbot-types';\nimport * as jwt2 from 'jsonwebtoken';\n\n// Added this because running locally did not import default correctly\nlet jwt = jwt2;\nif ('default' in jwt) {\n jwt = jwt['default'] as any;\n}\n\n/**\n * Converts a payload containing a userId and optional customUserData into a JWT string.\n *\n * Here the generic T is the type of the customUserData field. If not known, pass unknown.\n *\n * @param payload The payload to convert to a JWT string.\n * @returns A JWT string.\n */\nexport function convertToJwtString<T extends RecordOrUndef = undefined>(payload: SimpleAuthenticatedUser<T>, jwtSecret: string): string {\n return jwt.sign(payload, jwtSecret, { expiresIn: '1h' });\n}\n\n/**\n * Extracts the payload from a JWT string. If successful, the first value in the tuple will be the SimpleAuthenticatedUser<T> object.\n * If not successful, the first value in the tuple will be the number of the HTTP status code and the second value will be the error message,\n * so check the first value to see if it is a number and if it is, then the second value will be the error message.\n *\n * Here the generic T is the type of the customUserData field. If not known, pass unknown.\n * @param jwtToken - The JWT string to decode. Can include \"Bearer \" prefix which will be stripped.\n * @returns An object containing the userId and optional customUserData or the number of the HTTP status code and the error message.\n */\nexport function extractFromJwtString<T extends RecordOrUndef = undefined>(jwtToken: string, jwtSecret: string): [SimpleAuthenticatedUser<T> | number, string | undefined] {\n try {\n // Strip \"Bearer \" prefix if present\n const token = jwtToken.startsWith('Bearer ') ? jwtToken.substring(7) : jwtToken;\n const decoded = jwt.verify(token, jwtSecret);\n\n let userId: string;\n let customUserData: T | undefined;\n\n if (typeof decoded === 'object' && decoded !== null && 'userId' in decoded) {\n userId = (decoded as { userId: string }).userId;\n customUserData = (decoded as { customUserData: T }).customUserData ?? undefined;\n return [{ userId, customUserData }, undefined];\n }\n\n return [401, 'Unauthorized: Invalid or expired JWT token: code 1A'];\n } catch (error) {\n console.log('extractFromJwtString - Error message:', error instanceof Error ? error.message : 'Unknown error');\n return [401, `Unauthorized: Invalid or expired JWT token: code 1B`];\n }\n}\n"]}
@@ -0,0 +1,31 @@
1
+ import * as jwt2 from 'jsonwebtoken';
2
+
3
+ // src/util/jwt.ts
4
+ var jwt = jwt2;
5
+ if ("default" in jwt) {
6
+ jwt = jwt["default"];
7
+ }
8
+ function convertToJwtString(payload, jwtSecret) {
9
+ return jwt.sign(payload, jwtSecret, { expiresIn: "1h" });
10
+ }
11
+ function extractFromJwtString(jwtToken, jwtSecret) {
12
+ try {
13
+ const token = jwtToken.startsWith("Bearer ") ? jwtToken.substring(7) : jwtToken;
14
+ const decoded = jwt.verify(token, jwtSecret);
15
+ let userId;
16
+ let customUserData;
17
+ if (typeof decoded === "object" && decoded !== null && "userId" in decoded) {
18
+ userId = decoded.userId;
19
+ customUserData = decoded.customUserData ?? void 0;
20
+ return [{ userId, customUserData }, void 0];
21
+ }
22
+ return [401, "Unauthorized: Invalid or expired JWT token: code 1A"];
23
+ } catch (error) {
24
+ console.log("extractFromJwtString - Error message:", error instanceof Error ? error.message : "Unknown error");
25
+ return [401, `Unauthorized: Invalid or expired JWT token: code 1B`];
26
+ }
27
+ }
28
+
29
+ export { convertToJwtString, extractFromJwtString };
30
+ //# sourceMappingURL=jwt.mjs.map
31
+ //# sourceMappingURL=jwt.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/jwt.ts"],"names":[],"mappings":";;;AAIA,IAAI,GAAM,GAAA,IAAA;AACV,IAAI,aAAa,GAAK,EAAA;AAClB,EAAA,GAAA,GAAM,IAAI,SAAS,CAAA;AACvB;AAUO,SAAS,kBAAA,CAAwD,SAAqC,SAA2B,EAAA;AACpI,EAAA,OAAO,IAAI,IAAK,CAAA,OAAA,EAAS,WAAW,EAAE,SAAA,EAAW,MAAM,CAAA;AAC3D;AAWO,SAAS,oBAAA,CAA0D,UAAkB,SAA8E,EAAA;AACtK,EAAI,IAAA;AAEA,IAAM,MAAA,KAAA,GAAQ,SAAS,UAAW,CAAA,SAAS,IAAI,QAAS,CAAA,SAAA,CAAU,CAAC,CAAI,GAAA,QAAA;AACvE,IAAA,MAAM,OAAU,GAAA,GAAA,CAAI,MAAO,CAAA,KAAA,EAAO,SAAS,CAAA;AAE3C,IAAI,IAAA,MAAA;AACJ,IAAI,IAAA,cAAA;AAEJ,IAAA,IAAI,OAAO,OAAY,KAAA,QAAA,IAAY,OAAY,KAAA,IAAA,IAAQ,YAAY,OAAS,EAAA;AACxE,MAAA,MAAA,GAAU,OAA+B,CAAA,MAAA;AACzC,MAAA,cAAA,GAAkB,QAAkC,cAAkB,IAAA,KAAA,CAAA;AACtE,MAAA,OAAO,CAAC,EAAE,MAAQ,EAAA,cAAA,IAAkB,KAAS,CAAA,CAAA;AAAA;AAGjD,IAAO,OAAA,CAAC,KAAK,qDAAqD,CAAA;AAAA,WAC7D,KAAO,EAAA;AACZ,IAAA,OAAA,CAAQ,IAAI,uCAAyC,EAAA,KAAA,YAAiB,KAAQ,GAAA,KAAA,CAAM,UAAU,eAAe,CAAA;AAC7G,IAAO,OAAA,CAAC,KAAK,CAAqD,mDAAA,CAAA,CAAA;AAAA;AAE1E","file":"jwt.mjs","sourcesContent":["import type { RecordOrUndef, SimpleAuthenticatedUser } from '../types/chatbot/chatbot-types';\nimport * as jwt2 from 'jsonwebtoken';\n\n// Added this because running locally did not import default correctly\nlet jwt = jwt2;\nif ('default' in jwt) {\n jwt = jwt['default'] as any;\n}\n\n/**\n * Converts a payload containing a userId and optional customUserData into a JWT string.\n *\n * Here the generic T is the type of the customUserData field. If not known, pass unknown.\n *\n * @param payload The payload to convert to a JWT string.\n * @returns A JWT string.\n */\nexport function convertToJwtString<T extends RecordOrUndef = undefined>(payload: SimpleAuthenticatedUser<T>, jwtSecret: string): string {\n return jwt.sign(payload, jwtSecret, { expiresIn: '1h' });\n}\n\n/**\n * Extracts the payload from a JWT string. If successful, the first value in the tuple will be the SimpleAuthenticatedUser<T> object.\n * If not successful, the first value in the tuple will be the number of the HTTP status code and the second value will be the error message,\n * so check the first value to see if it is a number and if it is, then the second value will be the error message.\n *\n * Here the generic T is the type of the customUserData field. If not known, pass unknown.\n * @param jwtToken - The JWT string to decode. Can include \"Bearer \" prefix which will be stripped.\n * @returns An object containing the userId and optional customUserData or the number of the HTTP status code and the error message.\n */\nexport function extractFromJwtString<T extends RecordOrUndef = undefined>(jwtToken: string, jwtSecret: string): [SimpleAuthenticatedUser<T> | number, string | undefined] {\n try {\n // Strip \"Bearer \" prefix if present\n const token = jwtToken.startsWith('Bearer ') ? jwtToken.substring(7) : jwtToken;\n const decoded = jwt.verify(token, jwtSecret);\n\n let userId: string;\n let customUserData: T | undefined;\n\n if (typeof decoded === 'object' && decoded !== null && 'userId' in decoded) {\n userId = (decoded as { userId: string }).userId;\n customUserData = (decoded as { customUserData: T }).customUserData ?? undefined;\n return [{ userId, customUserData }, undefined];\n }\n\n return [401, 'Unauthorized: Invalid or expired JWT token: code 1A'];\n } catch (error) {\n console.log('extractFromJwtString - Error message:', error instanceof Error ? error.message : 'Unknown error');\n return [401, `Unauthorized: Invalid or expired JWT token: code 1B`];\n }\n}\n"]}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Helper function to redact sensitive data from specified attributes
3
+ * @param data - The object containing data to redact
4
+ * @param attributesToRedact - Single attribute name or array of attribute names to redact
5
+ * @returns A new object with specified attributes redacted
6
+ */
7
+ declare function redactData(data: any, attributesToRedact: string | string[]): any;
8
+ /**
9
+ * Recursively redacts a value based on its type
10
+ * @param value - The value to redact
11
+ * @returns The redacted value
12
+ */
13
+ declare function redactValue(value: any): any;
14
+
15
+ export { redactData, redactValue };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Helper function to redact sensitive data from specified attributes
3
+ * @param data - The object containing data to redact
4
+ * @param attributesToRedact - Single attribute name or array of attribute names to redact
5
+ * @returns A new object with specified attributes redacted
6
+ */
7
+ declare function redactData(data: any, attributesToRedact: string | string[]): any;
8
+ /**
9
+ * Recursively redacts a value based on its type
10
+ * @param value - The value to redact
11
+ * @returns The redacted value
12
+ */
13
+ declare function redactValue(value: any): any;
14
+
15
+ export { redactData, redactValue };
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ // src/util/server-client-utils.ts
4
+ function redactData(data, attributesToRedact) {
5
+ if (!data || typeof data !== "object") {
6
+ return data;
7
+ }
8
+ const attributes = Array.isArray(attributesToRedact) ? attributesToRedact : [attributesToRedact];
9
+ const redacted = { ...data };
10
+ for (const attr of attributes) {
11
+ if (attr in redacted) {
12
+ redacted[attr] = redactValue(redacted[attr]);
13
+ }
14
+ }
15
+ return redacted;
16
+ }
17
+ function redactValue(value) {
18
+ if (typeof value === "string") {
19
+ return "[REDACTED]";
20
+ } else if (Array.isArray(value)) {
21
+ return value.map((item) => redactValue(item));
22
+ } else if (value && typeof value === "object") {
23
+ const redactedObj = {};
24
+ for (const key in value) {
25
+ if (value.hasOwnProperty(key)) {
26
+ redactedObj[key] = redactValue(value[key]);
27
+ }
28
+ }
29
+ return redactedObj;
30
+ }
31
+ return value;
32
+ }
33
+
34
+ exports.redactData = redactData;
35
+ exports.redactValue = redactValue;
36
+ //# sourceMappingURL=server-client-utils.js.map
37
+ //# sourceMappingURL=server-client-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/server-client-utils.ts"],"names":[],"mappings":";;;AAUA,SAAS,UAAA,CAAW,MAAW,kBAA4C,EAAA;AACvE,EAAA,IAAI,CAAC,IAAA,IAAQ,OAAO,IAAA,KAAS,QAAU,EAAA;AACnC,IAAO,OAAA,IAAA;AAAA;AAGX,EAAA,MAAM,aAAa,KAAM,CAAA,OAAA,CAAQ,kBAAkB,CAAI,GAAA,kBAAA,GAAqB,CAAC,kBAAkB,CAAA;AAC/F,EAAM,MAAA,QAAA,GAAW,EAAE,GAAG,IAAK,EAAA;AAE3B,EAAA,KAAA,MAAW,QAAQ,UAAY,EAAA;AAC3B,IAAA,IAAI,QAAQ,QAAU,EAAA;AAClB,MAAA,QAAA,CAAS,IAAI,CAAA,GAAI,WAAY,CAAA,QAAA,CAAS,IAAI,CAAC,CAAA;AAAA;AAC/C;AAGJ,EAAO,OAAA,QAAA;AACX;AAOA,SAAS,YAAY,KAAiB,EAAA;AAClC,EAAI,IAAA,OAAO,UAAU,QAAU,EAAA;AAC3B,IAAO,OAAA,YAAA;AAAA,GACA,MAAA,IAAA,KAAA,CAAM,OAAQ,CAAA,KAAK,CAAG,EAAA;AAC7B,IAAA,OAAO,MAAM,GAAI,CAAA,CAAC,IAAS,KAAA,WAAA,CAAY,IAAI,CAAC,CAAA;AAAA,GACrC,MAAA,IAAA,KAAA,IAAS,OAAO,KAAA,KAAU,QAAU,EAAA;AAC3C,IAAA,MAAM,cAAmB,EAAC;AAC1B,IAAA,KAAA,MAAW,OAAO,KAAO,EAAA;AACrB,MAAI,IAAA,KAAA,CAAM,cAAe,CAAA,GAAG,CAAG,EAAA;AAC3B,QAAA,WAAA,CAAY,GAAG,CAAA,GAAI,WAAY,CAAA,KAAA,CAAM,GAAG,CAAC,CAAA;AAAA;AAC7C;AAEJ,IAAO,OAAA,WAAA;AAAA;AAEX,EAAO,OAAA,KAAA;AACX","file":"server-client-utils.js","sourcesContent":["/*\n * These are utils that are safe to use both on the server and the client.\n */\n\n/**\n * Helper function to redact sensitive data from specified attributes\n * @param data - The object containing data to redact\n * @param attributesToRedact - Single attribute name or array of attribute names to redact\n * @returns A new object with specified attributes redacted\n */\nfunction redactData(data: any, attributesToRedact: string | string[]): any {\n if (!data || typeof data !== 'object') {\n return data;\n }\n\n const attributes = Array.isArray(attributesToRedact) ? attributesToRedact : [attributesToRedact];\n const redacted = { ...data };\n\n for (const attr of attributes) {\n if (attr in redacted) {\n redacted[attr] = redactValue(redacted[attr]);\n }\n }\n\n return redacted;\n}\n\n/**\n * Recursively redacts a value based on its type\n * @param value - The value to redact\n * @returns The redacted value\n */\nfunction redactValue(value: any): any {\n if (typeof value === 'string') {\n return '[REDACTED]';\n } else if (Array.isArray(value)) {\n return value.map((item) => redactValue(item));\n } else if (value && typeof value === 'object') {\n const redactedObj: any = {};\n for (const key in value) {\n if (value.hasOwnProperty(key)) {\n redactedObj[key] = redactValue(value[key]);\n }\n }\n return redactedObj;\n }\n return value; // Return as-is for other types (numbers, booleans, null, etc.)\n}\n\n// Export both functions\nexport { redactData, redactValue };\n"]}
@@ -0,0 +1,34 @@
1
+ // src/util/server-client-utils.ts
2
+ function redactData(data, attributesToRedact) {
3
+ if (!data || typeof data !== "object") {
4
+ return data;
5
+ }
6
+ const attributes = Array.isArray(attributesToRedact) ? attributesToRedact : [attributesToRedact];
7
+ const redacted = { ...data };
8
+ for (const attr of attributes) {
9
+ if (attr in redacted) {
10
+ redacted[attr] = redactValue(redacted[attr]);
11
+ }
12
+ }
13
+ return redacted;
14
+ }
15
+ function redactValue(value) {
16
+ if (typeof value === "string") {
17
+ return "[REDACTED]";
18
+ } else if (Array.isArray(value)) {
19
+ return value.map((item) => redactValue(item));
20
+ } else if (value && typeof value === "object") {
21
+ const redactedObj = {};
22
+ for (const key in value) {
23
+ if (value.hasOwnProperty(key)) {
24
+ redactedObj[key] = redactValue(value[key]);
25
+ }
26
+ }
27
+ return redactedObj;
28
+ }
29
+ return value;
30
+ }
31
+
32
+ export { redactData, redactValue };
33
+ //# sourceMappingURL=server-client-utils.mjs.map
34
+ //# sourceMappingURL=server-client-utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/server-client-utils.ts"],"names":[],"mappings":";AAUA,SAAS,UAAA,CAAW,MAAW,kBAA4C,EAAA;AACvE,EAAA,IAAI,CAAC,IAAA,IAAQ,OAAO,IAAA,KAAS,QAAU,EAAA;AACnC,IAAO,OAAA,IAAA;AAAA;AAGX,EAAA,MAAM,aAAa,KAAM,CAAA,OAAA,CAAQ,kBAAkB,CAAI,GAAA,kBAAA,GAAqB,CAAC,kBAAkB,CAAA;AAC/F,EAAM,MAAA,QAAA,GAAW,EAAE,GAAG,IAAK,EAAA;AAE3B,EAAA,KAAA,MAAW,QAAQ,UAAY,EAAA;AAC3B,IAAA,IAAI,QAAQ,QAAU,EAAA;AAClB,MAAA,QAAA,CAAS,IAAI,CAAA,GAAI,WAAY,CAAA,QAAA,CAAS,IAAI,CAAC,CAAA;AAAA;AAC/C;AAGJ,EAAO,OAAA,QAAA;AACX;AAOA,SAAS,YAAY,KAAiB,EAAA;AAClC,EAAI,IAAA,OAAO,UAAU,QAAU,EAAA;AAC3B,IAAO,OAAA,YAAA;AAAA,GACA,MAAA,IAAA,KAAA,CAAM,OAAQ,CAAA,KAAK,CAAG,EAAA;AAC7B,IAAA,OAAO,MAAM,GAAI,CAAA,CAAC,IAAS,KAAA,WAAA,CAAY,IAAI,CAAC,CAAA;AAAA,GACrC,MAAA,IAAA,KAAA,IAAS,OAAO,KAAA,KAAU,QAAU,EAAA;AAC3C,IAAA,MAAM,cAAmB,EAAC;AAC1B,IAAA,KAAA,MAAW,OAAO,KAAO,EAAA;AACrB,MAAI,IAAA,KAAA,CAAM,cAAe,CAAA,GAAG,CAAG,EAAA;AAC3B,QAAA,WAAA,CAAY,GAAG,CAAA,GAAI,WAAY,CAAA,KAAA,CAAM,GAAG,CAAC,CAAA;AAAA;AAC7C;AAEJ,IAAO,OAAA,WAAA;AAAA;AAEX,EAAO,OAAA,KAAA;AACX","file":"server-client-utils.mjs","sourcesContent":["/*\n * These are utils that are safe to use both on the server and the client.\n */\n\n/**\n * Helper function to redact sensitive data from specified attributes\n * @param data - The object containing data to redact\n * @param attributesToRedact - Single attribute name or array of attribute names to redact\n * @returns A new object with specified attributes redacted\n */\nfunction redactData(data: any, attributesToRedact: string | string[]): any {\n if (!data || typeof data !== 'object') {\n return data;\n }\n\n const attributes = Array.isArray(attributesToRedact) ? attributesToRedact : [attributesToRedact];\n const redacted = { ...data };\n\n for (const attr of attributes) {\n if (attr in redacted) {\n redacted[attr] = redactValue(redacted[attr]);\n }\n }\n\n return redacted;\n}\n\n/**\n * Recursively redacts a value based on its type\n * @param value - The value to redact\n * @returns The redacted value\n */\nfunction redactValue(value: any): any {\n if (typeof value === 'string') {\n return '[REDACTED]';\n } else if (Array.isArray(value)) {\n return value.map((item) => redactValue(item));\n } else if (value && typeof value === 'object') {\n const redactedObj: any = {};\n for (const key in value) {\n if (value.hasOwnProperty(key)) {\n redactedObj[key] = redactValue(value[key]);\n }\n }\n return redactedObj;\n }\n return value; // Return as-is for other types (numbers, booleans, null, etc.)\n}\n\n// Export both functions\nexport { redactData, redactValue };\n"]}
@@ -0,0 +1,4 @@
1
+ declare function gunzipBase64EncodedString(base64EncodedString: string): string;
2
+ declare function gzipAndBase64EncodeString(string: string): string;
3
+
4
+ export { gunzipBase64EncodedString, gzipAndBase64EncodeString };
@@ -0,0 +1,4 @@
1
+ declare function gunzipBase64EncodedString(base64EncodedString: string): string;
2
+ declare function gzipAndBase64EncodeString(string: string): string;
3
+
4
+ export { gunzipBase64EncodedString, gzipAndBase64EncodeString };
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ var zlib = require('zlib');
4
+
5
+ // src/util/server-utils.ts
6
+ function gunzipBase64EncodedString(base64EncodedString) {
7
+ const gzippedHexEncodedString = Buffer.from(base64EncodedString, "base64").toString("hex");
8
+ const gzippedHexDecodedString = zlib.gunzipSync(Buffer.from(gzippedHexEncodedString, "hex")).toString();
9
+ return gzippedHexDecodedString;
10
+ }
11
+ function gzipAndBase64EncodeString(string) {
12
+ const gzippedHexEncodedString = zlib.gzipSync(string).toString("hex");
13
+ const gzippedBase64EncodedString = Buffer.from(gzippedHexEncodedString, "hex").toString("base64");
14
+ return gzippedBase64EncodedString;
15
+ }
16
+
17
+ exports.gunzipBase64EncodedString = gunzipBase64EncodedString;
18
+ exports.gzipAndBase64EncodeString = gzipAndBase64EncodeString;
19
+ //# sourceMappingURL=server-utils.js.map
20
+ //# sourceMappingURL=server-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/server-utils.ts"],"names":["gunzipSync","gzipSync"],"mappings":";;;;;AAEO,SAAS,0BAA0B,mBAAqC,EAAA;AAC3E,EAAA,MAAM,0BAA0B,MAAO,CAAA,IAAA,CAAK,qBAAqB,QAAQ,CAAA,CAAE,SAAS,KAAK,CAAA;AACzF,EAAM,MAAA,uBAAA,GAA0BA,gBAAW,MAAO,CAAA,IAAA,CAAK,yBAAyB,KAAK,CAAC,EAAE,QAAS,EAAA;AACjG,EAAO,OAAA,uBAAA;AACX;AAEO,SAAS,0BAA0B,MAAwB,EAAA;AAC9D,EAAA,MAAM,uBAA0B,GAAAC,aAAA,CAAS,MAAM,CAAA,CAAE,SAAS,KAAK,CAAA;AAC/D,EAAA,MAAM,6BAA6B,MAAO,CAAA,IAAA,CAAK,yBAAyB,KAAK,CAAA,CAAE,SAAS,QAAQ,CAAA;AAChG,EAAO,OAAA,0BAAA;AACX","file":"server-utils.js","sourcesContent":["import { gunzipSync, gzipSync } from 'zlib';\n\nexport function gunzipBase64EncodedString(base64EncodedString: string): string {\n const gzippedHexEncodedString = Buffer.from(base64EncodedString, 'base64').toString('hex');\n const gzippedHexDecodedString = gunzipSync(Buffer.from(gzippedHexEncodedString, 'hex')).toString();\n return gzippedHexDecodedString;\n}\n\nexport function gzipAndBase64EncodeString(string: string): string {\n const gzippedHexEncodedString = gzipSync(string).toString('hex');\n const gzippedBase64EncodedString = Buffer.from(gzippedHexEncodedString, 'hex').toString('base64');\n return gzippedBase64EncodedString;\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import { gunzipSync, gzipSync } from 'zlib';
2
+
3
+ // src/util/server-utils.ts
4
+ function gunzipBase64EncodedString(base64EncodedString) {
5
+ const gzippedHexEncodedString = Buffer.from(base64EncodedString, "base64").toString("hex");
6
+ const gzippedHexDecodedString = gunzipSync(Buffer.from(gzippedHexEncodedString, "hex")).toString();
7
+ return gzippedHexDecodedString;
8
+ }
9
+ function gzipAndBase64EncodeString(string) {
10
+ const gzippedHexEncodedString = gzipSync(string).toString("hex");
11
+ const gzippedBase64EncodedString = Buffer.from(gzippedHexEncodedString, "hex").toString("base64");
12
+ return gzippedBase64EncodedString;
13
+ }
14
+
15
+ export { gunzipBase64EncodedString, gzipAndBase64EncodeString };
16
+ //# sourceMappingURL=server-utils.mjs.map
17
+ //# sourceMappingURL=server-utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/server-utils.ts"],"names":[],"mappings":";;;AAEO,SAAS,0BAA0B,mBAAqC,EAAA;AAC3E,EAAA,MAAM,0BAA0B,MAAO,CAAA,IAAA,CAAK,qBAAqB,QAAQ,CAAA,CAAE,SAAS,KAAK,CAAA;AACzF,EAAM,MAAA,uBAAA,GAA0B,WAAW,MAAO,CAAA,IAAA,CAAK,yBAAyB,KAAK,CAAC,EAAE,QAAS,EAAA;AACjG,EAAO,OAAA,uBAAA;AACX;AAEO,SAAS,0BAA0B,MAAwB,EAAA;AAC9D,EAAA,MAAM,uBAA0B,GAAA,QAAA,CAAS,MAAM,CAAA,CAAE,SAAS,KAAK,CAAA;AAC/D,EAAA,MAAM,6BAA6B,MAAO,CAAA,IAAA,CAAK,yBAAyB,KAAK,CAAA,CAAE,SAAS,QAAQ,CAAA;AAChG,EAAO,OAAA,0BAAA;AACX","file":"server-utils.mjs","sourcesContent":["import { gunzipSync, gzipSync } from 'zlib';\n\nexport function gunzipBase64EncodedString(base64EncodedString: string): string {\n const gzippedHexEncodedString = Buffer.from(base64EncodedString, 'base64').toString('hex');\n const gzippedHexDecodedString = gunzipSync(Buffer.from(gzippedHexEncodedString, 'hex')).toString();\n return gzippedHexDecodedString;\n}\n\nexport function gzipAndBase64EncodeString(string: string): string {\n const gzippedHexEncodedString = gzipSync(string).toString('hex');\n const gzippedBase64EncodedString = Buffer.from(gzippedHexEncodedString, 'hex').toString('base64');\n return gzippedBase64EncodedString;\n}\n"]}