@adobe/spacecat-shared-data-access 3.58.0 → 3.59.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,9 @@
1
+ ## [@adobe/spacecat-shared-data-access-v3.59.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v3.58.0...@adobe/spacecat-shared-data-access-v3.59.0) (2026-05-07)
2
+
3
+ ### Features
4
+
5
+ * **data-access:** add Token.allBySiteId with optional tokenTypes/cycle filters ([#1572](https://github.com/adobe/spacecat-shared/issues/1572)) ([241607e](https://github.com/adobe/spacecat-shared/commit/241607e58c6b040eeaba134d51345ccd88910756))
6
+
1
7
  ## [@adobe/spacecat-shared-data-access-v3.58.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v3.57.0...@adobe/spacecat-shared-data-access-v3.58.0) (2026-05-05)
2
8
 
3
9
  ### Features
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-data-access",
3
- "version": "3.58.0",
3
+ "version": "3.59.0",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "engines": {
@@ -10,7 +10,7 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import { hasText, getTokenGrantConfig } from '@adobe/spacecat-shared-utils';
13
+ import { hasText, isNonEmptyArray, getTokenGrantConfig } from '@adobe/spacecat-shared-utils';
14
14
 
15
15
  import BaseCollection from '../base/base.collection.js';
16
16
  import DataAccessError from '../../errors/data-access.error.js';
@@ -66,6 +66,44 @@ class TokenCollection extends BaseCollection {
66
66
  used: 0,
67
67
  });
68
68
  }
69
+
70
+ /**
71
+ * Finds Tokens for the given siteId, optionally narrowed by tokenTypes and/or
72
+ * cycle. Issued as a single PostgREST query; all combinations are index-backed:
73
+ * - siteId + cycle → (site_id, cycle) index
74
+ * - siteId + cycle + types → (site_id, cycle) index + IN filter
75
+ * - siteId + types → (site_id, token_type, cycle) unique index prefix
76
+ * - siteId only → (site_id, …) prefix scan
77
+ *
78
+ * @param {string} siteId - Site ID (UUID).
79
+ * @param {Object} [options={}] - Query and filter options.
80
+ * @param {string[]} [options.tokenTypes] - Optional non-empty array of token
81
+ * type strings. When omitted, returns rows for all token types.
82
+ * @param {string} [options.cycle] - Optional cycle string (e.g. '2025-03').
83
+ * When omitted, returns rows for all cycles.
84
+ * @returns {Promise<import('./token.model.js').default[]>} Array of Token instances.
85
+ */
86
+ async allBySiteId(siteId, options = {}) {
87
+ if (!hasText(siteId)) {
88
+ throw new DataAccessError('TokenCollection.allBySiteId: siteId is required');
89
+ }
90
+ const { tokenTypes, cycle, ...queryOptions } = options;
91
+ const hasTypeFilter = tokenTypes != null;
92
+ if (hasTypeFilter && (!isNonEmptyArray(tokenTypes) || !tokenTypes.every(hasText))) {
93
+ throw new DataAccessError('TokenCollection.allBySiteId: tokenTypes must be a non-empty array of strings when provided');
94
+ }
95
+ if (cycle != null && !hasText(cycle)) {
96
+ throw new DataAccessError('TokenCollection.allBySiteId: cycle must be a non-empty string when provided');
97
+ }
98
+ const keys = { siteId };
99
+ if (hasText(cycle)) {
100
+ keys.cycle = cycle;
101
+ }
102
+ if (hasTypeFilter) {
103
+ queryOptions.where = (attrs, op) => op.in(attrs.tokenType, tokenTypes);
104
+ }
105
+ return this.all(keys, queryOptions);
106
+ }
69
107
  }
70
108
 
71
109
  export default TokenCollection;