ag-common 0.0.893 → 0.0.894

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 (92) hide show
  1. package/dist/api/helpers/acm.js +7 -17
  2. package/dist/api/helpers/api.js +28 -23
  3. package/dist/api/helpers/apigw.js +54 -71
  4. package/dist/api/helpers/cosmos/delete.js +81 -94
  5. package/dist/api/helpers/cosmos/get.js +170 -195
  6. package/dist/api/helpers/cosmos/index.js +23 -53
  7. package/dist/api/helpers/cosmos/write.js +88 -92
  8. package/dist/api/helpers/dynamo/delete.js +22 -52
  9. package/dist/api/helpers/dynamo/get.js +145 -135
  10. package/dist/api/helpers/dynamo/set.js +22 -29
  11. package/dist/api/helpers/enforceDynamoProvisionCap.js +5 -5
  12. package/dist/api/helpers/google/apikey.js +1 -2
  13. package/dist/api/helpers/google/gemini.js +26 -37
  14. package/dist/api/helpers/retryOnError.js +15 -26
  15. package/dist/api/helpers/s3.js +102 -121
  16. package/dist/api/helpers/ses.js +19 -26
  17. package/dist/api/helpers/sqs.js +5 -15
  18. package/dist/api/helpers/ssmInfra/dynamo.js +9 -5
  19. package/dist/api/helpers/sts.js +26 -37
  20. package/dist/api/helpers/validations.js +7 -17
  21. package/dist/api/helpers/zod.js +1 -2
  22. package/dist/common/helpers/async.js +27 -42
  23. package/dist/common/helpers/csv.js +1 -4
  24. package/dist/common/helpers/date.js +2 -2
  25. package/dist/common/helpers/fetch.js +42 -55
  26. package/dist/common/helpers/generator.js +11 -22
  27. package/dist/common/helpers/i18n.js +3 -5
  28. package/dist/common/helpers/log.js +4 -4
  29. package/dist/common/helpers/math.js +1 -2
  30. package/dist/common/helpers/node-cache.js +10 -2
  31. package/dist/common/helpers/random.js +2 -2
  32. package/dist/common/helpers/secondsInNearest.js +1 -2
  33. package/dist/common/helpers/stream.js +24 -35
  34. package/dist/common/helpers/string/redact.js +1 -2
  35. package/dist/common/helpers/withRetry.js +5 -14
  36. package/dist/common/helpers/xml.js +9 -22
  37. package/dist/node/helpers/fetch.js +22 -33
  38. package/dist/ui/components/DarkMode/Base.js +10 -5
  39. package/dist/ui/components/Markdown/index.js +4 -5
  40. package/dist/ui/components/shadcn/accordion.js +13 -36
  41. package/dist/ui/components/shadcn/alert.d.ts +1 -1
  42. package/dist/ui/components/shadcn/alert.js +3 -23
  43. package/dist/ui/components/shadcn/avatar.js +4 -24
  44. package/dist/ui/components/shadcn/button.d.ts +1 -1
  45. package/dist/ui/components/shadcn/button.js +2 -14
  46. package/dist/ui/components/shadcn/card.js +6 -35
  47. package/dist/ui/components/shadcn/checkbox.js +4 -18
  48. package/dist/ui/components/shadcn/dialog.js +17 -46
  49. package/dist/ui/components/shadcn/dropdown-list.js +2 -2
  50. package/dist/ui/components/shadcn/dropdown-menu.js +22 -58
  51. package/dist/ui/components/shadcn/input-selector.js +4 -5
  52. package/dist/ui/components/shadcn/input.js +2 -14
  53. package/dist/ui/components/shadcn/label.d.ts +1 -1
  54. package/dist/ui/components/shadcn/label.js +2 -16
  55. package/dist/ui/components/shadcn/popover.js +3 -17
  56. package/dist/ui/components/shadcn/radio-group.js +4 -17
  57. package/dist/ui/components/shadcn/scroll-area.js +9 -26
  58. package/dist/ui/components/shadcn/select.js +23 -55
  59. package/dist/ui/components/shadcn/sheet.d.ts +1 -1
  60. package/dist/ui/components/shadcn/sheet.js +13 -42
  61. package/dist/ui/components/shadcn/switch.js +3 -17
  62. package/dist/ui/components/shadcn/textarea.js +2 -14
  63. package/dist/ui/components/shadcn/toast.js +6 -4
  64. package/dist/ui/helpers/cookie/get.js +5 -1
  65. package/dist/ui/helpers/cookie/raw.js +1 -2
  66. package/dist/ui/helpers/cookie/set.js +2 -2
  67. package/dist/ui/helpers/cookie/use.js +19 -9
  68. package/dist/ui/helpers/date.js +3 -4
  69. package/dist/ui/helpers/debounce.js +1 -1
  70. package/dist/ui/helpers/extractAttributes.js +1 -2
  71. package/dist/ui/helpers/openDialog.js +1 -2
  72. package/dist/ui/helpers/routes.js +6 -4
  73. package/dist/ui/helpers/serviceWorker.js +7 -18
  74. package/dist/ui/helpers/useContextMenu.js +2 -3
  75. package/dist/ui/helpers/useElementAttribute.js +1 -1
  76. package/dist/ui/helpers/useGranularHook.js +2 -2
  77. package/dist/ui/helpers/useInterval.js +5 -7
  78. package/dist/ui/helpers/useLocalStorage.js +1 -1
  79. package/dist/ui/helpers/useOnClickOutside.js +2 -3
  80. package/dist/ui/helpers/useOnScroll.js +6 -8
  81. package/dist/ui/helpers/useOverloadPageSearch.js +1 -1
  82. package/dist/ui/helpers/useQueryString.js +2 -2
  83. package/dist/ui/helpers/useResize.js +1 -1
  84. package/dist/ui/helpers/useTimeout.js +1 -1
  85. package/dist/ui/helpers/useTooltip.js +8 -5
  86. package/dist/ui/icons/Checkmark.js +2 -5
  87. package/dist/ui/icons/Circle.js +2 -5
  88. package/dist/ui/icons/Magnify.js +2 -5
  89. package/dist/ui/icons/Sun.js +8 -11
  90. package/dist/ui/icons/Warning.js +7 -10
  91. package/dist/ui/styles/common.js +8 -20
  92. package/package.json +66 -65
@@ -1,107 +1,103 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.putItemCosmos = putItemCosmos;
13
4
  exports.putItemsCosmos = putItemsCosmos;
14
5
  const log_1 = require("../../../common/helpers/log");
15
6
  const withRetry_1 = require("../../../common/helpers/withRetry");
16
7
  const utils_1 = require("./utils");
17
- function putItemCosmos(container, item) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- try {
20
- // First, try to find existing item with the same PK
21
- const querySpec = {
22
- query: 'SELECT * FROM c WHERE c.PK = @pk',
23
- parameters: [{ name: '@pk', value: item.PK }],
8
+ async function putItemCosmos(container, item) {
9
+ try {
10
+ // First, try to find existing item with the same PK
11
+ const querySpec = {
12
+ query: 'SELECT * FROM c WHERE c.PK = @pk',
13
+ parameters: [{ name: '@pk', value: item.PK }],
14
+ };
15
+ const { resources: existingItems } = await container.items
16
+ .query(querySpec)
17
+ .fetchAll();
18
+ if (existingItems.length > 0) {
19
+ // If item exists, update it with the existing ID
20
+ const existingItem = existingItems[0];
21
+ const updatedItem = {
22
+ ...item,
23
+ id: existingItem.id, // Preserve the existing Cosmos DB id
24
24
  };
25
- const { resources: existingItems } = yield container.items
26
- .query(querySpec)
27
- .fetchAll();
28
- if (existingItems.length > 0) {
29
- // If item exists, update it with the existing ID
30
- const existingItem = existingItems[0];
31
- const updatedItem = Object.assign(Object.assign({}, item), { id: existingItem.id });
32
- const { resource: result } = yield container.items.upsert(updatedItem);
33
- return result;
34
- }
35
- else {
36
- // If no existing item, create new one (let Cosmos generate the id)
37
- const newItem = Object.assign(Object.assign({}, item), { id: undefined });
38
- const { resource: result } = yield container.items.create(newItem);
39
- return result;
40
- }
25
+ const { resource: result } = await container.items.upsert(updatedItem);
26
+ return result;
41
27
  }
42
- catch (e) {
43
- const em = e.message;
44
- (0, log_1.error)('Error upserting item:', em);
45
- throw e;
28
+ else {
29
+ // If no existing item, create new one (let Cosmos generate the id)
30
+ const newItem = {
31
+ ...item,
32
+ id: undefined, // Ensure we let Cosmos generate a new id
33
+ };
34
+ const { resource: result } = await container.items.create(newItem);
35
+ return result;
46
36
  }
47
- });
37
+ }
38
+ catch (e) {
39
+ const em = e.message;
40
+ (0, log_1.error)('Error upserting item:', em);
41
+ throw e;
42
+ }
48
43
  }
49
- function putItemsCosmos(container, items) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- try {
52
- if (items.length === 0) {
53
- return {};
54
- }
55
- (0, log_1.info)(`Bulk writing ${items.length} items to Cosmos`);
56
- for (let i = 0; i < items.length; i += utils_1.BULK_CHUNK_SIZE) {
57
- const chunk = items.slice(i, i + utils_1.BULK_CHUNK_SIZE);
58
- // Execute bulk operation with retry
59
- yield (0, withRetry_1.withRetry)(() => __awaiter(this, void 0, void 0, function* () {
60
- (0, log_1.info)(`Writing chunk ${i / utils_1.BULK_CHUNK_SIZE + 1} of ${Math.ceil(items.length / utils_1.BULK_CHUNK_SIZE)}`);
61
- const operations = yield Promise.all(chunk.map((item) => __awaiter(this, void 0, void 0, function* () {
62
- // Query to check if item exists
63
- const querySpec = {
64
- query: 'SELECT * FROM c WHERE c.PK = @pk',
65
- parameters: [{ name: '@pk', value: item.PK }],
66
- };
67
- const { resources: existingItems } = yield container.items
68
- .query(querySpec)
69
- .fetchAll();
70
- const existingItem = existingItems[0];
71
- return {
72
- operationType: 'Upsert',
73
- partitionKey: item.PK,
74
- resourceBody: Object.assign(Object.assign({}, item), { id: existingItem === null || existingItem === void 0 ? void 0 : existingItem.id }),
75
- };
76
- })));
77
- const bulkResponse = yield container.items.bulk(operations);
78
- // Process results
79
- let successCount = 0;
80
- let failureCount = 0;
81
- bulkResponse.forEach((response, index) => {
82
- if (response.statusCode === 429) {
83
- throw new Error('429');
84
- }
85
- if (response.statusCode >= 200 && response.statusCode < 300) {
86
- successCount++;
87
- }
88
- else {
89
- const item = chunk[index];
90
- (0, log_1.error)(`Failed to write item - PK: ${item.PK}, Status: ${response.statusCode}`, response.resourceBody);
91
- failureCount++;
92
- }
93
- });
94
- (0, log_1.info)(`Chunk ${i / utils_1.BULK_CHUNK_SIZE + 1}/${Math.ceil(items.length / utils_1.BULK_CHUNK_SIZE)} results - Success: ${successCount}, Failed: ${failureCount}`);
95
- return bulkResponse;
96
- }), `bulk_write_chunk_${i / utils_1.BULK_CHUNK_SIZE + 1}`);
97
- }
98
- (0, log_1.info)('All items written successfully');
44
+ async function putItemsCosmos(container, items) {
45
+ try {
46
+ if (items.length === 0) {
99
47
  return {};
100
48
  }
101
- catch (e) {
102
- const em = e.message;
103
- (0, log_1.error)('Error bulk writing items:', em);
104
- throw e;
49
+ (0, log_1.info)(`Bulk writing ${items.length} items to Cosmos`);
50
+ for (let i = 0; i < items.length; i += utils_1.BULK_CHUNK_SIZE) {
51
+ const chunk = items.slice(i, i + utils_1.BULK_CHUNK_SIZE);
52
+ // Execute bulk operation with retry
53
+ await (0, withRetry_1.withRetry)(async () => {
54
+ (0, log_1.info)(`Writing chunk ${i / utils_1.BULK_CHUNK_SIZE + 1} of ${Math.ceil(items.length / utils_1.BULK_CHUNK_SIZE)}`);
55
+ const operations = await Promise.all(chunk.map(async (item) => {
56
+ // Query to check if item exists
57
+ const querySpec = {
58
+ query: 'SELECT * FROM c WHERE c.PK = @pk',
59
+ parameters: [{ name: '@pk', value: item.PK }],
60
+ };
61
+ const { resources: existingItems } = await container.items
62
+ .query(querySpec)
63
+ .fetchAll();
64
+ const existingItem = existingItems[0];
65
+ return {
66
+ operationType: 'Upsert',
67
+ partitionKey: item.PK,
68
+ resourceBody: {
69
+ ...item,
70
+ id: existingItem?.id,
71
+ },
72
+ };
73
+ }));
74
+ const bulkResponse = await container.items.bulk(operations);
75
+ // Process results
76
+ let successCount = 0;
77
+ let failureCount = 0;
78
+ bulkResponse.forEach((response, index) => {
79
+ if (response.statusCode === 429) {
80
+ throw new Error('429');
81
+ }
82
+ if (response.statusCode >= 200 && response.statusCode < 300) {
83
+ successCount++;
84
+ }
85
+ else {
86
+ const item = chunk[index];
87
+ (0, log_1.error)(`Failed to write item - PK: ${item.PK}, Status: ${response.statusCode}`, response.resourceBody);
88
+ failureCount++;
89
+ }
90
+ });
91
+ (0, log_1.info)(`Chunk ${i / utils_1.BULK_CHUNK_SIZE + 1}/${Math.ceil(items.length / utils_1.BULK_CHUNK_SIZE)} results - Success: ${successCount}, Failed: ${failureCount}`);
92
+ return bulkResponse;
93
+ }, `bulk_write_chunk_${i / utils_1.BULK_CHUNK_SIZE + 1}`);
105
94
  }
106
- });
95
+ (0, log_1.info)('All items written successfully');
96
+ return {};
97
+ }
98
+ catch (e) {
99
+ const em = e.message;
100
+ (0, log_1.error)('Error bulk writing items:', em);
101
+ throw e;
102
+ }
107
103
  }
@@ -1,20 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __asyncValues = (this && this.__asyncValues) || function (o) {
12
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
- var m = o[Symbol.asyncIterator], i;
14
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
15
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
16
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
- };
18
2
  Object.defineProperty(exports, "__esModule", { value: true });
19
3
  exports.wipeTable = exports.batchDelete = void 0;
20
4
  const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
@@ -23,13 +7,12 @@ const async_1 = require("../../../common/helpers/async");
23
7
  const withRetry_1 = require("../../../common/helpers/withRetry");
24
8
  const _1 = require(".");
25
9
  const get_1 = require("./get");
26
- const batchDelete = (params) => __awaiter(void 0, void 0, void 0, function* () {
27
- var _a;
10
+ const batchDelete = async (params) => {
28
11
  try {
29
- const { batchSize = 20, maxRetries } = (_a = params.opt) !== null && _a !== void 0 ? _a : {};
12
+ const { batchSize = 20, maxRetries } = params.opt ?? {};
30
13
  const chunked = (0, array_1.chunk)(params.keys, batchSize);
31
14
  let processed = 0;
32
- yield (0, async_1.asyncForEach)(chunked, (chunk) => __awaiter(void 0, void 0, void 0, function* () {
15
+ await (0, async_1.asyncForEach)(chunked, async (chunk) => {
33
16
  const batchDeleteParams = {
34
17
  RequestItems: {
35
18
  [params.tableName]: chunk.map((key) => ({
@@ -37,58 +20,45 @@ const batchDelete = (params) => __awaiter(void 0, void 0, void 0, function* () {
37
20
  })),
38
21
  },
39
22
  };
40
- yield (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.BatchWriteCommand(batchDeleteParams)), `batchdelete ${processed}/${params.keys.length}. size=${batchSize}`, {
23
+ await (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.BatchWriteCommand(batchDeleteParams)), `batchdelete ${processed}/${params.keys.length}. size=${batchSize}`, {
41
24
  maxRetries: maxRetries === undefined ? 3 : maxRetries,
42
25
  });
43
26
  processed += chunk.length;
44
- }));
27
+ });
45
28
  return { data: undefined };
46
29
  }
47
30
  catch (e) {
48
31
  return { error: e.toString() };
49
32
  }
50
- });
33
+ };
51
34
  exports.batchDelete = batchDelete;
52
- const wipeTable = (tableName) => __awaiter(void 0, void 0, void 0, function* () {
53
- var _a, e_1, _b, _c;
35
+ const wipeTable = async (tableName) => {
54
36
  try {
55
37
  const generator = (0, get_1.scanWithGenerator)(tableName, {
56
38
  limit: 100, // Process in chunks of 100 items
57
39
  maxRetries: null, // Always retry on 429 since we want to ensure complete deletion
58
40
  });
59
- try {
60
- // Process each batch of items
61
- for (var _d = true, generator_1 = __asyncValues(generator), generator_1_1; generator_1_1 = yield generator_1.next(), _a = generator_1_1.done, !_a; _d = true) {
62
- _c = generator_1_1.value;
63
- _d = false;
64
- const batch = _c;
65
- const pks = batch.map((item) => item.PK);
66
- if (pks.length > 0) {
67
- const result = yield (0, exports.batchDelete)({
68
- tableName,
69
- keys: pks,
70
- pkName: 'PK',
71
- opt: {
72
- maxRetries: null, // Always retry on 429 since we want to ensure complete deletion
73
- },
74
- });
75
- if ('error' in result) {
76
- return result;
77
- }
41
+ // Process each batch of items
42
+ for await (const batch of generator) {
43
+ const pks = batch.map((item) => item.PK);
44
+ if (pks.length > 0) {
45
+ const result = await (0, exports.batchDelete)({
46
+ tableName,
47
+ keys: pks,
48
+ pkName: 'PK',
49
+ opt: {
50
+ maxRetries: null, // Always retry on 429 since we want to ensure complete deletion
51
+ },
52
+ });
53
+ if ('error' in result) {
54
+ return result;
78
55
  }
79
56
  }
80
57
  }
81
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
82
- finally {
83
- try {
84
- if (!_d && !_a && (_b = generator_1.return)) yield _b.call(generator_1);
85
- }
86
- finally { if (e_1) throw e_1.error; }
87
- }
88
58
  return { data: undefined };
89
59
  }
90
60
  catch (e) {
91
61
  return { error: e.toString() };
92
62
  }
93
- });
63
+ };
94
64
  exports.wipeTable = wipeTable;