@adobe/spacecat-shared-data-access 3.4.2 → 3.6.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-v3.6.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v3.5.0...@adobe/spacecat-shared-data-access-v3.6.0) (2026-03-02)
2
+
3
+ ### Features
4
+
5
+ * **data-access:** expose postgrestClient for direct PostgREST queries ([#1396](https://github.com/adobe/spacecat-shared/issues/1396)) ([307711c](https://github.com/adobe/spacecat-shared/commit/307711cfed7a3f2fc15f17afe31a48b21213a8e4))
6
+
7
+ ## [@adobe/spacecat-shared-data-access-v3.5.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v3.4.2...@adobe/spacecat-shared-data-access-v3.5.0) (2026-03-02)
8
+
9
+ ### Features
10
+
11
+ * **data-access:** auto-normalize enum values in PostgREST query filters ([#1392](https://github.com/adobe/spacecat-shared/issues/1392)) ([f44d0d2](https://github.com/adobe/spacecat-shared/commit/f44d0d257b0d47a719f592da13e91b2b01d89454))
12
+
1
13
  ## [@adobe/spacecat-shared-data-access-v3.4.2](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v3.4.1...@adobe/spacecat-shared-data-access-v3.4.2) (2026-03-02)
2
14
 
3
15
  ### Bug Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-data-access",
3
- "version": "3.4.2",
3
+ "version": "3.6.0",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "engines": {
package/src/index.d.ts CHANGED
@@ -13,3 +13,4 @@
13
13
  export type * from './errors';
14
14
  export type * from './models';
15
15
  export type * from './util';
16
+ export type { DataAccess } from './service';
@@ -92,6 +92,14 @@ class BaseCollection {
92
92
  return isSingleFieldAcrossAll ? field : null;
93
93
  }
94
94
 
95
+ #normalizeEnumValue(key, value) {
96
+ if (typeof value !== 'string') return value;
97
+ const attr = this.schema.getAttribute(key);
98
+ if (!Array.isArray(attr?.type)) return value;
99
+ const match = attr.type.find((v) => v.toLowerCase() === value.toLowerCase());
100
+ return match ?? value;
101
+ }
102
+
95
103
  // eslint-disable-next-line class-methods-use-this
96
104
  #isInvalidInputError(error) {
97
105
  let current = error;
@@ -378,7 +386,7 @@ class BaseCollection {
378
386
 
379
387
  let filtered = query;
380
388
  Object.entries(keys).forEach(([key, value]) => {
381
- filtered = filtered.eq(this.#toDbField(key), value);
389
+ filtered = filtered.eq(this.#toDbField(key), this.#normalizeEnumValue(key, value));
382
390
  });
383
391
  return filtered;
384
392
  }
@@ -615,7 +623,9 @@ class BaseCollection {
615
623
  const bulkKeyField = this.#resolveBulkKeyField(keys);
616
624
  if (bulkKeyField) {
617
625
  const dbField = this.#toDbField(bulkKeyField);
618
- const values = keys.map((key) => key[bulkKeyField]);
626
+ const values = keys.map(
627
+ (key) => this.#normalizeEnumValue(bulkKeyField, key[bulkKeyField]),
628
+ );
619
629
  const select = this.#buildSelect(options.attributes);
620
630
 
621
631
  // Chunk values to avoid 414 URI Too Large from PostgREST GET URLs.
@@ -967,7 +977,9 @@ class BaseCollection {
967
977
  const bulkKeyField = this.#resolveBulkKeyField(keys);
968
978
  if (bulkKeyField) {
969
979
  const dbField = this.#toDbField(bulkKeyField);
970
- const values = keys.map((key) => key[bulkKeyField]);
980
+ const values = keys.map(
981
+ (key) => this.#normalizeEnumValue(bulkKeyField, key[bulkKeyField]),
982
+ );
971
983
  const { error } = await this.postgrestService
972
984
  .from(this.tableName)
973
985
  .delete()
@@ -10,31 +10,36 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- export type * from './audit';
13
+ export type * from './api-key';
14
14
  export type * from './async-job';
15
- export type * from './configuration';
15
+ export type * from './audit';
16
+ export type * from './audit-url';
16
17
  export type * from './base';
18
+ export type * from './configuration';
17
19
  export type * from './consumer';
20
+ export type * from './entitlement';
21
+ export type * from './experiment';
18
22
  export type * from './fix-entity';
19
23
  export type * from './fix-entity-suggestion';
20
- export type * from './experiment';
21
- export type * from './entitlement';
22
24
  export type * from './import-job';
23
25
  export type * from './import-url';
24
26
  export type * from './key-event';
25
27
  export type * from './latest-audit';
26
28
  export type * from './opportunity';
27
29
  export type * from './organization';
30
+ export type * from './page-citability';
31
+ export type * from './page-intent';
32
+ export type * from './project';
33
+ export type * from './report';
28
34
  export type * from './scrape-job';
29
35
  export type * from './scrape-url';
36
+ export type * from './sentiment-guideline';
37
+ export type * from './sentiment-topic';
30
38
  export type * from './site';
31
39
  export type * from './site-candidate';
32
40
  export type * from './site-enrollment';
33
41
  export type * from './site-top-form';
34
42
  export type * from './site-top-page';
35
43
  export type * from './suggestion';
36
- export type * from './report';
37
44
  export type * from './trial-user';
38
- export type * from './trial-user-activity';
39
- export type * from './sentiment-guideline';
40
- export type * from './sentiment-topic';
45
+ export type * from './trial-user-activity';
@@ -10,6 +10,41 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
+ import type PostgrestClient from '@supabase/postgrest-js/dist/cjs/PostgrestClient';
14
+
15
+ import type { ApiKeyCollection } from '../models/api-key';
16
+ import type { AsyncJobCollection } from '../models/async-job';
17
+ import type { AuditCollection } from '../models/audit';
18
+ import type { AuditUrlCollection } from '../models/audit-url';
19
+ import type { ConfigurationCollection } from '../models/configuration';
20
+ import type { ConsumerCollection } from '../models/consumer';
21
+ import type { EntitlementCollection } from '../models/entitlement';
22
+ import type { ExperimentCollection } from '../models/experiment';
23
+ import type { FixEntityCollection } from '../models/fix-entity';
24
+ import type { FixEntitySuggestionCollection } from '../models/fix-entity-suggestion';
25
+ import type { ImportJobCollection } from '../models/import-job';
26
+ import type { ImportUrlCollection } from '../models/import-url';
27
+ import type { KeyEventCollection } from '../models/key-event';
28
+ import type { LatestAuditCollection } from '../models/latest-audit';
29
+ import type { OpportunityCollection } from '../models/opportunity';
30
+ import type { OrganizationCollection } from '../models/organization';
31
+ import type { PageCitabilityCollection } from '../models/page-citability';
32
+ import type { PageIntentCollection } from '../models/page-intent';
33
+ import type { ProjectCollection } from '../models/project';
34
+ import type { ReportCollection } from '../models/report';
35
+ import type { ScrapeJobCollection } from '../models/scrape-job';
36
+ import type { ScrapeUrlCollection } from '../models/scrape-url';
37
+ import type { SentimentGuidelineCollection } from '../models/sentiment-guideline';
38
+ import type { SentimentTopicCollection } from '../models/sentiment-topic';
39
+ import type { SiteCollection } from '../models/site';
40
+ import type { SiteCandidateCollection } from '../models/site-candidate';
41
+ import type { SiteEnrollmentCollection } from '../models/site-enrollment';
42
+ import type { SiteTopFormCollection } from '../models/site-top-form';
43
+ import type { SiteTopPageCollection } from '../models/site-top-page';
44
+ import type { SuggestionCollection } from '../models/suggestion';
45
+ import type { TrialUserCollection } from '../models/trial-user';
46
+ import type { TrialUserActivityCollection } from '../models/trial-user-activity';
47
+
13
48
  interface DataAccessConfig {
14
49
  postgrestUrl: string;
15
50
  postgrestSchema?: string;
@@ -19,8 +54,48 @@ interface DataAccessConfig {
19
54
  region?: string;
20
55
  }
21
56
 
57
+ export interface DataAccessServices {
58
+ postgrestClient: PostgrestClient;
59
+ }
60
+
61
+ export interface DataAccess {
62
+ services: DataAccessServices;
63
+ ApiKey: ApiKeyCollection;
64
+ AsyncJob: AsyncJobCollection;
65
+ Audit: AuditCollection;
66
+ AuditUrl: AuditUrlCollection;
67
+ Configuration: ConfigurationCollection;
68
+ Consumer: ConsumerCollection;
69
+ Entitlement: EntitlementCollection;
70
+ Experiment: ExperimentCollection;
71
+ FixEntity: FixEntityCollection;
72
+ FixEntitySuggestion: FixEntitySuggestionCollection;
73
+ ImportJob: ImportJobCollection;
74
+ ImportUrl: ImportUrlCollection;
75
+ KeyEvent: KeyEventCollection;
76
+ LatestAudit: LatestAuditCollection;
77
+ Opportunity: OpportunityCollection;
78
+ Organization: OrganizationCollection;
79
+ PageCitability: PageCitabilityCollection;
80
+ PageIntent: PageIntentCollection;
81
+ Project: ProjectCollection;
82
+ Report: ReportCollection;
83
+ ScrapeJob: ScrapeJobCollection;
84
+ ScrapeUrl: ScrapeUrlCollection;
85
+ SentimentGuideline: SentimentGuidelineCollection;
86
+ SentimentTopic: SentimentTopicCollection;
87
+ Site: SiteCollection;
88
+ SiteCandidate: SiteCandidateCollection;
89
+ SiteEnrollment: SiteEnrollmentCollection;
90
+ SiteTopForm: SiteTopFormCollection;
91
+ SiteTopPage: SiteTopPageCollection;
92
+ Suggestion: SuggestionCollection;
93
+ TrialUser: TrialUserCollection;
94
+ TrialUserActivity: TrialUserActivityCollection;
95
+ }
96
+
22
97
  export function createDataAccess(
23
98
  config: DataAccessConfig,
24
99
  logger: object,
25
100
  client?: object,
26
- ): object;
101
+ ): DataAccess;
@@ -98,5 +98,10 @@ export const createDataAccess = (config, log = console, client = undefined) => {
98
98
  const services = createServices(postgrestService, config);
99
99
  const entityRegistry = new EntityRegistry(services, config, log);
100
100
 
101
- return entityRegistry.getCollections();
101
+ return {
102
+ ...entityRegistry.getCollections(),
103
+ services: {
104
+ postgrestClient: postgrestService,
105
+ },
106
+ };
102
107
  };