@adobe/spacecat-shared-data-access 3.5.0 → 3.6.1
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 +12 -0
- package/CLAUDE.md +18 -1
- package/README.md +29 -2
- package/package.json +1 -1
- package/src/index.d.ts +1 -0
- package/src/models/index.d.ts +13 -8
- package/src/models/site/config.js +6 -0
- package/src/service/index.d.ts +76 -1
- package/src/service/index.js +6 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## [@adobe/spacecat-shared-data-access-v3.6.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v3.6.0...@adobe/spacecat-shared-data-access-v3.6.1) (2026-03-03)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* stage changes wrt to spacecat-shared ([#1394](https://github.com/adobe/spacecat-shared/issues/1394)) ([7145fb0](https://github.com/adobe/spacecat-shared/commit/7145fb037e5b809d4552889c291b6f8688655b88))
|
|
6
|
+
|
|
7
|
+
## [@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)
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **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))
|
|
12
|
+
|
|
1
13
|
## [@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)
|
|
2
14
|
|
|
3
15
|
### Features
|
package/CLAUDE.md
CHANGED
|
@@ -21,7 +21,8 @@ Lambda/ECS service
|
|
|
21
21
|
| File | Purpose |
|
|
22
22
|
|------|---------|
|
|
23
23
|
| `src/index.js` | Default export: `dataAccessWrapper(fn)` for Helix/Lambda handlers |
|
|
24
|
-
| `src/service/index.js` | `createDataAccess(config, log?, client?)` factory |
|
|
24
|
+
| `src/service/index.js` | `createDataAccess(config, log?, client?)` factory — returns entity collections + `services.postgrestClient` |
|
|
25
|
+
| `src/service/index.d.ts` | `DataAccess` and `DataAccessServices` type definitions |
|
|
25
26
|
| `src/models/base/schema.builder.js` | DSL for defining entity schemas (attributes, references, indexes) |
|
|
26
27
|
| `src/models/base/base.model.js` | Base entity class (auto-generated getters/setters, save, remove) |
|
|
27
28
|
| `src/models/base/base.collection.js` | Base collection class (findById, all, query, count) |
|
|
@@ -152,6 +153,22 @@ npm run test:it
|
|
|
152
153
|
- PostgREST calls are stubbed via sinon
|
|
153
154
|
- Each entity model and collection has its own test file
|
|
154
155
|
|
|
156
|
+
## Direct PostgREST Queries
|
|
157
|
+
|
|
158
|
+
`dataAccess.services.postgrestClient` exposes the raw `@supabase/postgrest-js` `PostgrestClient` for querying tables that don't have entity models (e.g. analytics views, reporting tables):
|
|
159
|
+
|
|
160
|
+
```js
|
|
161
|
+
const { postgrestClient } = context.dataAccess.services;
|
|
162
|
+
|
|
163
|
+
const { data, error } = await postgrestClient
|
|
164
|
+
.from('brand_presence_executions')
|
|
165
|
+
.select('*')
|
|
166
|
+
.eq('site_id', siteId)
|
|
167
|
+
.limit(100);
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
This is the same client instance used internally by entity collections — same URL, auth, and schema.
|
|
171
|
+
|
|
155
172
|
## Common Patterns
|
|
156
173
|
|
|
157
174
|
### Collection query with WHERE clause
|
package/README.md
CHANGED
|
@@ -16,9 +16,10 @@ npm install @adobe/spacecat-shared-data-access
|
|
|
16
16
|
## What You Get
|
|
17
17
|
|
|
18
18
|
The package provides:
|
|
19
|
-
- `createDataAccess(config, log?, client?)`
|
|
19
|
+
- `createDataAccess(config, log?, client?)` — returns entity collections + `services.postgrestClient`
|
|
20
20
|
- `dataAccessWrapper(fn)` (default export) for Helix/Lambda style handlers
|
|
21
21
|
- Entity collections/models with stable external API shape for services
|
|
22
|
+
- `services.postgrestClient` for direct PostgREST queries against non-entity tables
|
|
22
23
|
|
|
23
24
|
## Quick Start
|
|
24
25
|
|
|
@@ -89,6 +90,29 @@ The wrapper reads from `context.env`:
|
|
|
89
90
|
- `S3_CONFIG_BUCKET`
|
|
90
91
|
- `AWS_REGION`
|
|
91
92
|
|
|
93
|
+
## Direct PostgREST Queries
|
|
94
|
+
|
|
95
|
+
For querying PostgREST tables that are not modeled as entities (e.g. analytics views, reporting tables), the `postgrestClient` is available under `dataAccess.services`:
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
const { Site } = dataAccess; // entity collections
|
|
99
|
+
const { postgrestClient } = dataAccess.services; // raw PostgREST client
|
|
100
|
+
|
|
101
|
+
// Use entity collections as usual
|
|
102
|
+
const site = await Site.findById(siteId);
|
|
103
|
+
|
|
104
|
+
// Direct queries against non-entity tables
|
|
105
|
+
const { data, error } = await postgrestClient
|
|
106
|
+
.from('brand_presence_executions')
|
|
107
|
+
.select('execution_date, visibility_score, sentiment')
|
|
108
|
+
.eq('site_id', siteId)
|
|
109
|
+
.gte('execution_date', '2025-01-01')
|
|
110
|
+
.order('execution_date', { ascending: false })
|
|
111
|
+
.limit(100);
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
This is the same `@supabase/postgrest-js` `PostgrestClient` instance used internally by the entity collections. Full IDE autocomplete is available for the query builder chain.
|
|
115
|
+
|
|
92
116
|
## Field Mapping Behavior
|
|
93
117
|
|
|
94
118
|
Public model API remains camelCase while Postgres/PostgREST tables are snake_case.
|
|
@@ -383,7 +407,10 @@ export MYSTICAT_DATA_SERVICE_REPOSITORY=682033462621.dkr.ecr.us-east-1.amazonaws
|
|
|
383
407
|
|
|
384
408
|
Type definitions are shipped from:
|
|
385
409
|
- `src/index.d.ts`
|
|
386
|
-
- `src/
|
|
410
|
+
- `src/service/index.d.ts` — `DataAccess` and `DataAccessServices` interfaces
|
|
411
|
+
- `src/models/**/index.d.ts` — per-entity collection and model interfaces
|
|
412
|
+
|
|
413
|
+
The `DataAccess` interface provides full typing for all entity collections and `services.postgrestClient` (typed as `PostgrestClient` from `@supabase/postgrest-js`).
|
|
387
414
|
|
|
388
415
|
Use the package directly in TS projects; no extra setup required.
|
|
389
416
|
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
package/src/models/index.d.ts
CHANGED
|
@@ -10,31 +10,36 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
export type * from './
|
|
13
|
+
export type * from './api-key';
|
|
14
14
|
export type * from './async-job';
|
|
15
|
-
export type * from './
|
|
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';
|
|
@@ -344,6 +344,12 @@ export const configSchema = Joi.object({
|
|
|
344
344
|
edgeOptimizeConfig: Joi.object({
|
|
345
345
|
enabled: Joi.boolean().optional(),
|
|
346
346
|
opted: Joi.number().optional(),
|
|
347
|
+
stagingDomains: Joi.array().items(
|
|
348
|
+
Joi.object({
|
|
349
|
+
domain: Joi.string().required(),
|
|
350
|
+
id: Joi.string().required(),
|
|
351
|
+
}),
|
|
352
|
+
).optional(),
|
|
347
353
|
}).optional(),
|
|
348
354
|
contentAiConfig: Joi.object({
|
|
349
355
|
index: Joi.string().optional(),
|
package/src/service/index.d.ts
CHANGED
|
@@ -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
|
-
):
|
|
101
|
+
): DataAccess;
|
package/src/service/index.js
CHANGED
|
@@ -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
|
|
101
|
+
return {
|
|
102
|
+
...entityRegistry.getCollections(),
|
|
103
|
+
services: {
|
|
104
|
+
postgrestClient: postgrestService,
|
|
105
|
+
},
|
|
106
|
+
};
|
|
102
107
|
};
|