ag-common 0.0.893 → 0.0.895
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/helpers/acm.js +7 -17
- package/dist/api/helpers/api.js +28 -23
- package/dist/api/helpers/apigw.js +54 -71
- package/dist/api/helpers/cosmos/delete.js +81 -94
- package/dist/api/helpers/cosmos/get.js +170 -195
- package/dist/api/helpers/cosmos/index.js +23 -53
- package/dist/api/helpers/cosmos/write.js +88 -92
- package/dist/api/helpers/dynamo/delete.js +22 -52
- package/dist/api/helpers/dynamo/get.js +145 -135
- package/dist/api/helpers/dynamo/index.d.ts +2 -2
- package/dist/api/helpers/dynamo/set.js +22 -29
- package/dist/api/helpers/enforceDynamoProvisionCap.js +5 -5
- package/dist/api/helpers/google/apikey.js +1 -2
- package/dist/api/helpers/google/gemini.js +26 -37
- package/dist/api/helpers/retryOnError.js +15 -26
- package/dist/api/helpers/s3.d.ts +2 -2
- package/dist/api/helpers/s3.js +102 -121
- package/dist/api/helpers/ses.js +19 -26
- package/dist/api/helpers/sqs.js +5 -15
- package/dist/api/helpers/ssmInfra/dynamo.js +9 -5
- package/dist/api/helpers/sts.js +26 -37
- package/dist/api/helpers/validations.js +7 -17
- package/dist/api/helpers/zod.js +1 -2
- package/dist/common/helpers/async.js +27 -42
- package/dist/common/helpers/csv.js +1 -4
- package/dist/common/helpers/date.js +2 -2
- package/dist/common/helpers/fetch.js +42 -55
- package/dist/common/helpers/generator.js +11 -22
- package/dist/common/helpers/i18n.js +3 -5
- package/dist/common/helpers/log.js +4 -4
- package/dist/common/helpers/math.js +1 -2
- package/dist/common/helpers/node-cache.js +10 -2
- package/dist/common/helpers/random.js +2 -2
- package/dist/common/helpers/secondsInNearest.js +1 -2
- package/dist/common/helpers/stream.js +24 -35
- package/dist/common/helpers/string/redact.js +1 -2
- package/dist/common/helpers/withRetry.js +5 -14
- package/dist/common/helpers/xml.js +9 -22
- package/dist/node/helpers/fetch.js +22 -33
- package/dist/ui/components/DarkMode/Base.js +10 -5
- package/dist/ui/components/Markdown/index.js +4 -5
- package/dist/ui/components/shadcn/accordion.js +13 -36
- package/dist/ui/components/shadcn/alert.d.ts +1 -1
- package/dist/ui/components/shadcn/alert.js +3 -23
- package/dist/ui/components/shadcn/avatar.js +4 -24
- package/dist/ui/components/shadcn/button.d.ts +1 -1
- package/dist/ui/components/shadcn/button.js +2 -14
- package/dist/ui/components/shadcn/card.js +6 -35
- package/dist/ui/components/shadcn/checkbox.js +4 -18
- package/dist/ui/components/shadcn/dialog.js +17 -46
- package/dist/ui/components/shadcn/dropdown-list.js +2 -2
- package/dist/ui/components/shadcn/dropdown-menu.js +22 -58
- package/dist/ui/components/shadcn/input-selector.js +4 -5
- package/dist/ui/components/shadcn/input.js +2 -14
- package/dist/ui/components/shadcn/label.d.ts +1 -1
- package/dist/ui/components/shadcn/label.js +2 -16
- package/dist/ui/components/shadcn/popover.js +3 -17
- package/dist/ui/components/shadcn/radio-group.js +4 -17
- package/dist/ui/components/shadcn/scroll-area.js +9 -26
- package/dist/ui/components/shadcn/select.js +23 -55
- package/dist/ui/components/shadcn/sheet.d.ts +1 -1
- package/dist/ui/components/shadcn/sheet.js +13 -42
- package/dist/ui/components/shadcn/switch.js +3 -17
- package/dist/ui/components/shadcn/textarea.js +2 -14
- package/dist/ui/components/shadcn/toast.js +6 -4
- package/dist/ui/helpers/cookie/get.js +5 -1
- package/dist/ui/helpers/cookie/raw.js +1 -2
- package/dist/ui/helpers/cookie/set.js +2 -2
- package/dist/ui/helpers/cookie/use.js +19 -9
- package/dist/ui/helpers/date.js +3 -4
- package/dist/ui/helpers/debounce.js +1 -1
- package/dist/ui/helpers/extractAttributes.js +1 -2
- package/dist/ui/helpers/openDialog.js +1 -2
- package/dist/ui/helpers/routes.js +6 -4
- package/dist/ui/helpers/serviceWorker.js +7 -18
- package/dist/ui/helpers/useContextMenu.js +2 -3
- package/dist/ui/helpers/useElementAttribute.js +1 -1
- package/dist/ui/helpers/useGranularHook.js +2 -2
- package/dist/ui/helpers/useInterval.js +5 -7
- package/dist/ui/helpers/useLocalStorage.js +1 -1
- package/dist/ui/helpers/useOnClickOutside.js +2 -3
- package/dist/ui/helpers/useOnScroll.js +6 -8
- package/dist/ui/helpers/useOverloadPageSearch.js +1 -1
- package/dist/ui/helpers/useQueryString.js +2 -2
- package/dist/ui/helpers/useResize.js +1 -1
- package/dist/ui/helpers/useTimeout.js +1 -1
- package/dist/ui/helpers/useTooltip.js +8 -5
- package/dist/ui/icons/Checkmark.js +2 -5
- package/dist/ui/icons/Circle.js +2 -5
- package/dist/ui/icons/Magnify.js +2 -5
- package/dist/ui/icons/Sun.js +8 -11
- package/dist/ui/icons/Warning.js +7 -10
- package/dist/ui/styles/common.js +8 -20
- package/package.json +56 -65
package/dist/api/helpers/acm.js
CHANGED
|
@@ -1,13 +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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.findCertificateByDomain = exports.acm = exports.setAcm = void 0;
|
|
13
4
|
/* eslint-disable no-await-in-loop */
|
|
@@ -26,24 +17,23 @@ exports.acm = (0, exports.setAcm)('us-east-1');
|
|
|
26
17
|
* @returns The certificate ARN
|
|
27
18
|
* @throws Error if no matching certificate is found
|
|
28
19
|
*/
|
|
29
|
-
const findCertificateByDomain =
|
|
30
|
-
|
|
31
|
-
const ar = yield exports.acm.config.region();
|
|
20
|
+
const findCertificateByDomain = async (domain, region = 'us-east-1') => {
|
|
21
|
+
const ar = await exports.acm.config.region();
|
|
32
22
|
if (ar !== region) {
|
|
33
23
|
(0, exports.setAcm)(region);
|
|
34
24
|
}
|
|
35
25
|
const requiredDomains = new Set([domain, `*.${domain}`]);
|
|
36
|
-
const listResponse =
|
|
37
|
-
if (!
|
|
26
|
+
const listResponse = await exports.acm.send(new client_acm_1.ListCertificatesCommand({}));
|
|
27
|
+
if (!listResponse.CertificateSummaryList?.length) {
|
|
38
28
|
throw new Error(`No ACM certificates found in region ${region}`);
|
|
39
29
|
}
|
|
40
30
|
for (const cert of listResponse.CertificateSummaryList) {
|
|
41
31
|
if (!cert.CertificateArn)
|
|
42
32
|
continue;
|
|
43
|
-
const describeResponse =
|
|
33
|
+
const describeResponse = await exports.acm.send(new client_acm_1.DescribeCertificateCommand({
|
|
44
34
|
CertificateArn: cert.CertificateArn,
|
|
45
35
|
}));
|
|
46
|
-
const sans =
|
|
36
|
+
const sans = describeResponse.Certificate?.SubjectAlternativeNames ?? [];
|
|
47
37
|
const sanSet = new Set(sans);
|
|
48
38
|
const hasAllDomains = [...requiredDomains].every((d) => sanSet.has(d));
|
|
49
39
|
if (hasAllDomains) {
|
|
@@ -51,5 +41,5 @@ const findCertificateByDomain = (domain_1, ...args_1) => __awaiter(void 0, [doma
|
|
|
51
41
|
}
|
|
52
42
|
}
|
|
53
43
|
throw new Error(`No ACM certificate found covering both "${domain}" and "*.${domain}" in region ${region}`);
|
|
54
|
-
}
|
|
44
|
+
};
|
|
55
45
|
exports.findCertificateByDomain = findCertificateByDomain;
|
package/dist/api/helpers/api.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.generateDynamoPKS = exports.stripPKs = exports.returnCode = void 0;
|
|
15
4
|
const array_1 = require("../../common/helpers/array");
|
|
@@ -21,7 +10,10 @@ const returnCode = (statusCode, body, extraHeaders, fullSiteUrl) => {
|
|
|
21
10
|
'Access-Control-Allow-Credentials': true, // Required for cookies, authorization headers with HTTPS
|
|
22
11
|
};
|
|
23
12
|
if (extraHeaders && Object.keys(extraHeaders).length > 0) {
|
|
24
|
-
headers =
|
|
13
|
+
headers = {
|
|
14
|
+
...headers,
|
|
15
|
+
...extraHeaders,
|
|
16
|
+
};
|
|
25
17
|
}
|
|
26
18
|
return {
|
|
27
19
|
headers,
|
|
@@ -44,7 +36,7 @@ const stripPKs = (record, keepPk = true) => {
|
|
|
44
36
|
}
|
|
45
37
|
// @ts-ignore
|
|
46
38
|
// eslint-disable-next-line
|
|
47
|
-
const { PK, PK1, PK2, PK3, PK4, PK5, L1, L2, L3, L4, L5, L6, type
|
|
39
|
+
const { PK, PK1, PK2, PK3, PK4, PK5, L1, L2, L3, L4, L5, L6, type, ...rest } = record;
|
|
48
40
|
if (keepPk) {
|
|
49
41
|
//@ts-ignore
|
|
50
42
|
rest.PK = PK;
|
|
@@ -69,15 +61,28 @@ const generateDynamoPKS = ({ type, L1, L2, L3, L4, L5, L6, additionalPKValues, }
|
|
|
69
61
|
const additionalPK = additionalPKValues && additionalPKValues.length > 0
|
|
70
62
|
? `#${additionalPKValues.join(c)}`
|
|
71
63
|
: '';
|
|
72
|
-
return
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
64
|
+
return {
|
|
65
|
+
PK: keys.join(c) + additionalPK,
|
|
66
|
+
type,
|
|
67
|
+
L1,
|
|
68
|
+
...(L2 && { L2 }),
|
|
69
|
+
...(L3 && { L3 }),
|
|
70
|
+
...(L4 && { L4 }),
|
|
71
|
+
...(L5 && { L5 }),
|
|
72
|
+
...(L6 && { L6 }),
|
|
73
|
+
PK1: L1,
|
|
74
|
+
...(keys.length >= 2 && {
|
|
75
|
+
PK2: [keys[0], keys[1]].join(c),
|
|
76
|
+
}),
|
|
77
|
+
...(keys.length >= 3 && {
|
|
78
|
+
PK3: [keys[0], keys[1], keys[2]].join(c),
|
|
79
|
+
}),
|
|
80
|
+
...(keys.length >= 4 && {
|
|
81
|
+
PK4: [keys[0], keys[1], keys[2], keys[3]].join(c),
|
|
82
|
+
}),
|
|
83
|
+
...(keys.length >= 5 && {
|
|
84
|
+
PK5: [keys[0], keys[1], keys[2], keys[3], keys[4]].join(c),
|
|
85
|
+
}),
|
|
86
|
+
};
|
|
82
87
|
};
|
|
83
88
|
exports.generateDynamoPKS = generateDynamoPKS;
|
|
@@ -1,13 +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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.sendWebSocketMessage = sendWebSocketMessage;
|
|
13
4
|
exports.deleteConnection = deleteConnection;
|
|
@@ -18,81 +9,73 @@ const common_1 = require("../../common");
|
|
|
18
9
|
/**
|
|
19
10
|
* Sends a message to a specific WebSocket connection
|
|
20
11
|
*/
|
|
21
|
-
function sendWebSocketMessage(p) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
throw new Error('Error:' + JSON.stringify(s));
|
|
33
|
-
}
|
|
34
|
-
catch (e) {
|
|
35
|
-
(0, common_1.warn)('Failed to send WebSocket message:', p, e);
|
|
36
|
-
return false;
|
|
12
|
+
async function sendWebSocketMessage(p) {
|
|
13
|
+
const wsClient = new client_apigatewaymanagementapi_1.ApiGatewayManagementApiClient(p);
|
|
14
|
+
try {
|
|
15
|
+
const s = await wsClient.send(new client_apigatewaymanagementapi_1.PostToConnectionCommand({
|
|
16
|
+
ConnectionId: p.connectionId,
|
|
17
|
+
Data: JSON.stringify(p.message),
|
|
18
|
+
}));
|
|
19
|
+
if (s.$metadata.httpStatusCode === 200) {
|
|
20
|
+
return true;
|
|
37
21
|
}
|
|
38
|
-
|
|
22
|
+
throw new Error('Error:' + JSON.stringify(s));
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
(0, common_1.warn)('Failed to send WebSocket message:', p, e);
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
39
28
|
}
|
|
40
29
|
/**
|
|
41
30
|
* Deletes a WebSocket connection
|
|
42
31
|
*/
|
|
43
|
-
function deleteConnection(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
endpoint,
|
|
47
|
-
});
|
|
48
|
-
try {
|
|
49
|
-
const s = yield wsClient.send(new client_apigatewaymanagementapi_1.DeleteConnectionCommand({
|
|
50
|
-
ConnectionId: connectionId,
|
|
51
|
-
}));
|
|
52
|
-
if (s.$metadata.httpStatusCode === 200) {
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
catch (e) {
|
|
58
|
-
(0, common_1.warn)('Failed to delete WebSocket connection:', e.message);
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
32
|
+
async function deleteConnection({ connectionId, endpoint, }) {
|
|
33
|
+
const wsClient = new client_apigatewaymanagementapi_1.ApiGatewayManagementApiClient({
|
|
34
|
+
endpoint,
|
|
61
35
|
});
|
|
36
|
+
try {
|
|
37
|
+
const s = await wsClient.send(new client_apigatewaymanagementapi_1.DeleteConnectionCommand({
|
|
38
|
+
ConnectionId: connectionId,
|
|
39
|
+
}));
|
|
40
|
+
if (s.$metadata.httpStatusCode === 200) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
(0, common_1.warn)('Failed to delete WebSocket connection:', e.message);
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
62
49
|
}
|
|
63
50
|
/**
|
|
64
51
|
* Checks if a WebSocket connection is still active
|
|
65
52
|
*/
|
|
66
|
-
function isConnectionActive(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
endpoint,
|
|
70
|
-
});
|
|
71
|
-
try {
|
|
72
|
-
const s = yield wsClient.send(new client_apigatewaymanagementapi_1.GetConnectionCommand({
|
|
73
|
-
ConnectionId: connectionId,
|
|
74
|
-
}));
|
|
75
|
-
if (s.$metadata.httpStatusCode === 200) {
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
catch (e) {
|
|
81
|
-
(0, common_1.warn)('Failed to check if WebSocket connection is active:', e.message);
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
53
|
+
async function isConnectionActive({ connectionId, endpoint, }) {
|
|
54
|
+
const wsClient = new client_apigatewaymanagementapi_1.ApiGatewayManagementApiClient({
|
|
55
|
+
endpoint,
|
|
84
56
|
});
|
|
57
|
+
try {
|
|
58
|
+
const s = await wsClient.send(new client_apigatewaymanagementapi_1.GetConnectionCommand({
|
|
59
|
+
ConnectionId: connectionId,
|
|
60
|
+
}));
|
|
61
|
+
if (s.$metadata.httpStatusCode === 200) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
(0, common_1.warn)('Failed to check if WebSocket connection is active:', e.message);
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
85
70
|
}
|
|
86
71
|
/**
|
|
87
72
|
* Broadcasts a message to multiple WebSocket connections
|
|
88
73
|
*/
|
|
89
|
-
function broadcastMessage(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return results.every((r) => r);
|
|
97
|
-
});
|
|
74
|
+
async function broadcastMessage({ connectionIds, message, endpoint, }) {
|
|
75
|
+
const results = await Promise.all(connectionIds.map((connectionId) => sendWebSocketMessage({
|
|
76
|
+
connectionId,
|
|
77
|
+
message,
|
|
78
|
+
endpoint,
|
|
79
|
+
})));
|
|
80
|
+
return results.every((r) => r);
|
|
98
81
|
}
|
|
@@ -1,111 +1,98 @@
|
|
|
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.deleteItemCosmos = deleteItemCosmos;
|
|
13
4
|
exports.deleteItemsByField = deleteItemsByField;
|
|
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 deleteItemCosmos(container, pk) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
yield container.item(item.id, pk).delete();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
catch (e) {
|
|
35
|
-
const em = e.message;
|
|
36
|
-
(0, log_1.error)('Error deleting item:', em);
|
|
37
|
-
throw e;
|
|
8
|
+
async function deleteItemCosmos(container, pk) {
|
|
9
|
+
try {
|
|
10
|
+
// First query to find items with matching PK
|
|
11
|
+
const querySpec = {
|
|
12
|
+
query: 'SELECT * FROM c WHERE c.PK = @pk',
|
|
13
|
+
parameters: [{ name: '@pk', value: pk }],
|
|
14
|
+
};
|
|
15
|
+
const { resources: items } = await container.items
|
|
16
|
+
.query(querySpec)
|
|
17
|
+
.fetchAll();
|
|
18
|
+
// Delete each found item and collect their IDs
|
|
19
|
+
for (const item of items) {
|
|
20
|
+
(0, log_1.warn)('deleting items:', item.id, pk);
|
|
21
|
+
await container.item(item.id, pk).delete();
|
|
38
22
|
}
|
|
39
|
-
}
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
const em = e.message;
|
|
26
|
+
(0, log_1.error)('Error deleting item:', em);
|
|
27
|
+
throw e;
|
|
28
|
+
}
|
|
40
29
|
}
|
|
41
|
-
function deleteItemsByField(container, field, value) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const query = `
|
|
30
|
+
async function deleteItemsByField(container, field, value) {
|
|
31
|
+
try {
|
|
32
|
+
const query = `
|
|
45
33
|
SELECT c.id, c.PK
|
|
46
34
|
FROM c
|
|
47
35
|
WHERE c.${field} = @value
|
|
48
36
|
`;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return {};
|
|
57
|
-
}
|
|
58
|
-
(0, log_1.info)(`Deleting ${resources.length} items where ${field} = ${value} from Cosmos`);
|
|
59
|
-
//throw if item.id or PK doesn't exist on an item
|
|
60
|
-
resources.forEach((item) => {
|
|
61
|
-
if (!item.id || !item.PK) {
|
|
62
|
-
throw new Error('Item missing required fields: ' + JSON.stringify(item));
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
const operations = resources.map((item) => ({
|
|
66
|
-
id: item.id,
|
|
67
|
-
partitionKey: item.PK,
|
|
68
|
-
operationType: 'Delete',
|
|
69
|
-
}));
|
|
70
|
-
for (let i = 0; i < operations.length; i += utils_1.BULK_CHUNK_SIZE) {
|
|
71
|
-
const chunk = operations.slice(i, i + utils_1.BULK_CHUNK_SIZE);
|
|
72
|
-
// Execute bulk operation with retry
|
|
73
|
-
yield (0, withRetry_1.withRetry)(() => __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
(0, log_1.info)(`Deleting chunk ${i / utils_1.BULK_CHUNK_SIZE + 1} of ${Math.ceil(operations.length / utils_1.BULK_CHUNK_SIZE)}`);
|
|
75
|
-
const bulkResponse = yield container.items.bulk(chunk);
|
|
76
|
-
//if an item contains a statuscode 429, then throw an error
|
|
77
|
-
bulkResponse.forEach((response) => {
|
|
78
|
-
if (response.statusCode === 429) {
|
|
79
|
-
throw new Error('429');
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
// Process results
|
|
83
|
-
let successCount = 0;
|
|
84
|
-
let failureCount = 0;
|
|
85
|
-
bulkResponse.forEach((response, index) => {
|
|
86
|
-
if (response.statusCode === 204) {
|
|
87
|
-
successCount++;
|
|
88
|
-
}
|
|
89
|
-
else if (response.statusCode === 404) {
|
|
90
|
-
failureCount++;
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
const item = chunk[index];
|
|
94
|
-
(0, log_1.error)(`Failed to delete item - ID: ${item.id}, PK: ${item.partitionKey}, Status: ${response.statusCode}`, response.resourceBody);
|
|
95
|
-
failureCount++;
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
(0, log_1.info)(`Chunk ${i / utils_1.BULK_CHUNK_SIZE + 1}/${Math.ceil(operations.length / utils_1.BULK_CHUNK_SIZE)} results - Success: ${successCount}, Failed: ${failureCount}`);
|
|
99
|
-
return bulkResponse;
|
|
100
|
-
}), `bulk_delete_chunk_${i / utils_1.BULK_CHUNK_SIZE + 1}`);
|
|
101
|
-
}
|
|
102
|
-
(0, log_1.info)('All items deleted successfully');
|
|
37
|
+
const { resources } = await container.items
|
|
38
|
+
.query({
|
|
39
|
+
query,
|
|
40
|
+
parameters: [{ name: '@value', value }],
|
|
41
|
+
})
|
|
42
|
+
.fetchAll();
|
|
43
|
+
if (resources.length === 0) {
|
|
103
44
|
return {};
|
|
104
45
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
46
|
+
(0, log_1.info)(`Deleting ${resources.length} items where ${field} = ${value} from Cosmos`);
|
|
47
|
+
//throw if item.id or PK doesn't exist on an item
|
|
48
|
+
resources.forEach((item) => {
|
|
49
|
+
if (!item.id || !item.PK) {
|
|
50
|
+
throw new Error('Item missing required fields: ' + JSON.stringify(item));
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const operations = resources.map((item) => ({
|
|
54
|
+
id: item.id,
|
|
55
|
+
partitionKey: item.PK,
|
|
56
|
+
operationType: 'Delete',
|
|
57
|
+
}));
|
|
58
|
+
for (let i = 0; i < operations.length; i += utils_1.BULK_CHUNK_SIZE) {
|
|
59
|
+
const chunk = operations.slice(i, i + utils_1.BULK_CHUNK_SIZE);
|
|
60
|
+
// Execute bulk operation with retry
|
|
61
|
+
await (0, withRetry_1.withRetry)(async () => {
|
|
62
|
+
(0, log_1.info)(`Deleting chunk ${i / utils_1.BULK_CHUNK_SIZE + 1} of ${Math.ceil(operations.length / utils_1.BULK_CHUNK_SIZE)}`);
|
|
63
|
+
const bulkResponse = await container.items.bulk(chunk);
|
|
64
|
+
//if an item contains a statuscode 429, then throw an error
|
|
65
|
+
bulkResponse.forEach((response) => {
|
|
66
|
+
if (response.statusCode === 429) {
|
|
67
|
+
throw new Error('429');
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
// Process results
|
|
71
|
+
let successCount = 0;
|
|
72
|
+
let failureCount = 0;
|
|
73
|
+
bulkResponse.forEach((response, index) => {
|
|
74
|
+
if (response.statusCode === 204) {
|
|
75
|
+
successCount++;
|
|
76
|
+
}
|
|
77
|
+
else if (response.statusCode === 404) {
|
|
78
|
+
failureCount++;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const item = chunk[index];
|
|
82
|
+
(0, log_1.error)(`Failed to delete item - ID: ${item.id}, PK: ${item.partitionKey}, Status: ${response.statusCode}`, response.resourceBody);
|
|
83
|
+
failureCount++;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
(0, log_1.info)(`Chunk ${i / utils_1.BULK_CHUNK_SIZE + 1}/${Math.ceil(operations.length / utils_1.BULK_CHUNK_SIZE)} results - Success: ${successCount}, Failed: ${failureCount}`);
|
|
87
|
+
return bulkResponse;
|
|
88
|
+
}, `bulk_delete_chunk_${i / utils_1.BULK_CHUNK_SIZE + 1}`);
|
|
109
89
|
}
|
|
110
|
-
|
|
90
|
+
(0, log_1.info)('All items deleted successfully');
|
|
91
|
+
return {};
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
const em = e.message;
|
|
95
|
+
(0, log_1.error)('Error deleting items:', em);
|
|
96
|
+
throw e;
|
|
97
|
+
}
|
|
111
98
|
}
|