@adobe/spacecat-shared-data-access 4.6.0 → 4.8.0
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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## [@adobe/spacecat-shared-data-access-v4.8.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v4.7.0...@adobe/spacecat-shared-data-access-v4.8.0) (2026-07-14)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* add temporary replaceHandlerEnabledDisabled method for cleanup. ([#1328](https://github.com/adobe/spacecat-shared/issues/1328)) ([be9234f](https://github.com/adobe/spacecat-shared/commit/be9234fa67dc9960d4abbb0b0425e621b7ad33c7))
|
|
6
|
+
|
|
7
|
+
## [@adobe/spacecat-shared-data-access-v4.7.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v4.6.0...@adobe/spacecat-shared-data-access-v4.7.0) (2026-07-13)
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **data-access:** add TicketSuggestion bulk accessors allBySuggestionIds and allByTicketIds (SITES-44690) ([#1804](https://github.com/adobe/spacecat-shared/issues/1804)) ([99387f6](https://github.com/adobe/spacecat-shared/commit/99387f64423c822c0f377014d245549bed68cd40))
|
|
12
|
+
|
|
1
13
|
## [@adobe/spacecat-shared-data-access-v4.6.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v4.5.0...@adobe/spacecat-shared-data-access-v4.6.0) (2026-07-12)
|
|
2
14
|
|
|
3
15
|
### Features
|
package/package.json
CHANGED
|
@@ -554,6 +554,84 @@ class Configuration {
|
|
|
554
554
|
this.setHandlers(handlers);
|
|
555
555
|
}
|
|
556
556
|
|
|
557
|
+
/**
|
|
558
|
+
* Replaces enabled/disabled lists for a handler.
|
|
559
|
+
* This method replaces (not merges) the provided arrays.
|
|
560
|
+
* Only the arrays provided in the data object will be replaced.
|
|
561
|
+
*
|
|
562
|
+
* TEMPORARY: This method was created to support a temporary API endpoint for
|
|
563
|
+
* cleaning up enabled and disabled lists (SITES-40312). It will be removed once the cleanup
|
|
564
|
+
* task is completed. SITES-40878 is the ticket to remove this temporary endpoint.
|
|
565
|
+
*
|
|
566
|
+
* @deprecated Temporary method for cleanup. See SITES-40312. Will be removed (SITES-40878).
|
|
567
|
+
* @param {string} type - The handler type to update
|
|
568
|
+
* @param {object} data - Object containing enabled/disabled arrays to replace
|
|
569
|
+
* @param {object} [data.enabled] - Enabled lists to replace (use null-safe check)
|
|
570
|
+
* @param {string[]} [data.enabled.sites] - Sites array to replace (if provided, must be array)
|
|
571
|
+
* @param {string[]} [data.enabled.orgs] - Orgs array to replace (if provided, must be array)
|
|
572
|
+
* @param {object} [data.disabled] - Disabled lists to replace (use null-safe check)
|
|
573
|
+
* @param {string[]} [data.disabled.sites] - Sites array to replace (if provided, must be array)
|
|
574
|
+
* @param {string[]} [data.disabled.orgs] - Orgs array to replace (if provided, must be array)
|
|
575
|
+
* @throws {Error} If data is empty, handler not found, or non-array value provided for sites/orgs
|
|
576
|
+
*/
|
|
577
|
+
replaceHandlerEnabledDisabled(type, data) {
|
|
578
|
+
if (!isNonEmptyObject(data)) {
|
|
579
|
+
throw new Error('Data cannot be empty');
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
this.log.warn('replaceHandlerEnabledDisabled invoked (temporary method - see SITES-40312)');
|
|
583
|
+
|
|
584
|
+
const handlers = this.getHandlers();
|
|
585
|
+
if (!handlers[type]) {
|
|
586
|
+
throw new Error(`Handler "${type}" not found in configuration`);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
const handler = handlers[type];
|
|
590
|
+
|
|
591
|
+
// Initialize enabled/disabled objects if they don't exist
|
|
592
|
+
if (!isNonEmptyObject(handler.enabled)) {
|
|
593
|
+
handler.enabled = { orgs: [], sites: [] };
|
|
594
|
+
}
|
|
595
|
+
if (!isNonEmptyObject(handler.disabled)) {
|
|
596
|
+
handler.disabled = { orgs: [], sites: [] };
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// Replace enabled arrays if provided (use != null to catch both null and undefined)
|
|
600
|
+
if (data.enabled != null) {
|
|
601
|
+
if (data.enabled.sites !== undefined) {
|
|
602
|
+
if (!Array.isArray(data.enabled.sites)) {
|
|
603
|
+
throw new Error('enabled.sites must be an array');
|
|
604
|
+
}
|
|
605
|
+
handler.enabled.sites = data.enabled.sites;
|
|
606
|
+
}
|
|
607
|
+
if (data.enabled.orgs !== undefined) {
|
|
608
|
+
if (!Array.isArray(data.enabled.orgs)) {
|
|
609
|
+
throw new Error('enabled.orgs must be an array');
|
|
610
|
+
}
|
|
611
|
+
handler.enabled.orgs = data.enabled.orgs;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// Replace disabled arrays if provided (use != null to catch both null and undefined)
|
|
616
|
+
if (data.disabled != null) {
|
|
617
|
+
if (data.disabled.sites !== undefined) {
|
|
618
|
+
if (!Array.isArray(data.disabled.sites)) {
|
|
619
|
+
throw new Error('disabled.sites must be an array');
|
|
620
|
+
}
|
|
621
|
+
handler.disabled.sites = data.disabled.sites;
|
|
622
|
+
}
|
|
623
|
+
if (data.disabled.orgs !== undefined) {
|
|
624
|
+
if (!Array.isArray(data.disabled.orgs)) {
|
|
625
|
+
throw new Error('disabled.orgs must be an array');
|
|
626
|
+
}
|
|
627
|
+
handler.disabled.orgs = data.disabled.orgs;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
handlers[type] = handler;
|
|
632
|
+
this.setHandlers(handlers);
|
|
633
|
+
}
|
|
634
|
+
|
|
557
635
|
/**
|
|
558
636
|
* Updates the configuration by merging changes into existing sections.
|
|
559
637
|
* This is a flexible update method that allows updating one or more sections at once.
|
|
@@ -40,6 +40,10 @@ export interface Configuration {
|
|
|
40
40
|
isHandlerEnabledForOrg(type: string, org: Organization): boolean;
|
|
41
41
|
isHandlerEnabledForSite(type: string, site: Site): boolean;
|
|
42
42
|
registerAudit(type: string, enabledByDefault?: boolean, interval?: string, productCodes?: string[]): void;
|
|
43
|
+
replaceHandlerEnabledDisabled(
|
|
44
|
+
type: string,
|
|
45
|
+
data: { enabled?: { sites?: string[]; orgs?: string[] }; disabled?: { sites?: string[]; orgs?: string[] } }
|
|
46
|
+
): void;
|
|
43
47
|
save(): Promise<Configuration>;
|
|
44
48
|
setHandlers(handlers: object): void;
|
|
45
49
|
setJobs(jobs: object[]): void;
|
|
@@ -10,8 +10,12 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
import { DataAccessError } from '../../errors/index.js';
|
|
14
|
+
import { guardArray } from '../../util/guards.js';
|
|
13
15
|
import BaseCollection from '../base/base.collection.js';
|
|
14
16
|
|
|
17
|
+
const IN_FILTER_CHUNK_SIZE = 50;
|
|
18
|
+
|
|
15
19
|
/**
|
|
16
20
|
* TicketSuggestionCollection — manages TicketSuggestion bridge records.
|
|
17
21
|
*
|
|
@@ -24,6 +28,80 @@ import BaseCollection from '../base/base.collection.js';
|
|
|
24
28
|
*/
|
|
25
29
|
class TicketSuggestionCollection extends BaseCollection {
|
|
26
30
|
static COLLECTION_NAME = 'TicketSuggestionCollection';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Returns all bridge records whose suggestion_id is in the given array.
|
|
34
|
+
* Used for bulk pre-flight checks before ticket creation.
|
|
35
|
+
*
|
|
36
|
+
* @param {string[]} suggestionIds
|
|
37
|
+
* @returns {Promise<import('./ticket-suggestion.model.js').default[]>}
|
|
38
|
+
*/
|
|
39
|
+
async allBySuggestionIds(suggestionIds) {
|
|
40
|
+
guardArray('suggestionIds', suggestionIds, 'TicketSuggestionCollection', 'string');
|
|
41
|
+
|
|
42
|
+
if (suggestionIds.length === 0) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const uniqueIds = [...new Set(suggestionIds)];
|
|
48
|
+
const chunks = [];
|
|
49
|
+
for (let i = 0; i < uniqueIds.length; i += IN_FILTER_CHUNK_SIZE) {
|
|
50
|
+
chunks.push(uniqueIds.slice(i, i + IN_FILTER_CHUNK_SIZE));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const results = await Promise.all(
|
|
54
|
+
chunks.map((chunk) => this.all(
|
|
55
|
+
{},
|
|
56
|
+
{ where: (attrs, op) => op.in(attrs.suggestionId, chunk) },
|
|
57
|
+
)),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
return results.flat();
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (error instanceof DataAccessError) {
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
throw new DataAccessError('Failed to load ticket suggestions by suggestion IDs', this, error);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Returns all bridge records whose ticket_id is in the given array.
|
|
71
|
+
* Used to bulk-load suggestion mappings when listing tickets.
|
|
72
|
+
*
|
|
73
|
+
* @param {string[]} ticketIds
|
|
74
|
+
* @returns {Promise<import('./ticket-suggestion.model.js').default[]>}
|
|
75
|
+
*/
|
|
76
|
+
async allByTicketIds(ticketIds) {
|
|
77
|
+
guardArray('ticketIds', ticketIds, 'TicketSuggestionCollection', 'string');
|
|
78
|
+
|
|
79
|
+
if (ticketIds.length === 0) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
const uniqueIds = [...new Set(ticketIds)];
|
|
85
|
+
const chunks = [];
|
|
86
|
+
for (let i = 0; i < uniqueIds.length; i += IN_FILTER_CHUNK_SIZE) {
|
|
87
|
+
chunks.push(uniqueIds.slice(i, i + IN_FILTER_CHUNK_SIZE));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const results = await Promise.all(
|
|
91
|
+
chunks.map((chunk) => this.all(
|
|
92
|
+
{},
|
|
93
|
+
{ where: (attrs, op) => op.in(attrs.ticketId, chunk) },
|
|
94
|
+
)),
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
return results.flat();
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (error instanceof DataAccessError) {
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
throw new DataAccessError('Failed to load ticket suggestions by ticket IDs', this, error);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
27
105
|
}
|
|
28
106
|
|
|
29
107
|
export default TicketSuggestionCollection;
|