@adobe/spacecat-shared-data-access 2.88.0 → 2.88.2

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/package.json +1 -1
  3. package/src/models/api-key/api-key.model.js +2 -0
  4. package/src/models/async-job/async-job.model.js +2 -0
  5. package/src/models/audit/audit.model.js +2 -0
  6. package/src/models/base/base.model.js +8 -0
  7. package/src/models/base/schema.builder.js +5 -1
  8. package/src/models/configuration/configuration.model.js +2 -0
  9. package/src/models/entitlement/entitlement.model.js +2 -0
  10. package/src/models/entitlement/entitlement.schema.js +1 -1
  11. package/src/models/experiment/experiment.model.js +2 -0
  12. package/src/models/fix-entity/fix-entity.model.js +2 -0
  13. package/src/models/fix-entity-suggestion/fix-entity-suggestion.model.js +2 -0
  14. package/src/models/import-job/import-job.model.js +2 -0
  15. package/src/models/import-url/import-url.model.js +2 -0
  16. package/src/models/key-event/key-event.model.js +2 -0
  17. package/src/models/latest-audit/latest-audit.model.js +2 -0
  18. package/src/models/opportunity/opportunity.model.js +2 -0
  19. package/src/models/organization/organization.model.js +2 -0
  20. package/src/models/page-citability/page-citability.model.js +2 -0
  21. package/src/models/page-intent/page-intent.model.js +2 -0
  22. package/src/models/project/project.model.js +2 -0
  23. package/src/models/report/report.model.js +2 -0
  24. package/src/models/scrape-job/scrape-job.model.js +2 -0
  25. package/src/models/scrape-url/scrape-url.model.js +2 -0
  26. package/src/models/site/site.model.js +2 -0
  27. package/src/models/site-candidate/site-candidate.model.js +2 -0
  28. package/src/models/site-enrollment/site-enrollment.model.js +2 -0
  29. package/src/models/site-top-form/site-top-form.model.js +2 -0
  30. package/src/models/site-top-page/site-top-page.model.js +2 -0
  31. package/src/models/suggestion/suggestion.model.js +2 -0
  32. package/src/models/trial-user/trial-user.model.js +2 -0
  33. package/src/models/trial-user-activity/trial-user-activity.model.js +2 -0
  34. package/src/readme.md +23 -4
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [@adobe/spacecat-shared-data-access-v2.88.2](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.88.1...@adobe/spacecat-shared-data-access-v2.88.2) (2025-11-26)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Make Entity Naming Bundler-Agnostic with Explicit ENTITY_NAME ([#1173](https://github.com/adobe/spacecat-shared/issues/1173)) ([c6cb69c](https://github.com/adobe/spacecat-shared/commit/c6cb69c6114db686f911afafe8d477b4556d9d49))
7
+
8
+ # [@adobe/spacecat-shared-data-access-v2.88.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.88.0...@adobe/spacecat-shared-data-access-v2.88.1) (2025-11-24)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * remove enrollments when entitlment are removed ([#1161](https://github.com/adobe/spacecat-shared/issues/1161)) ([b82e6c4](https://github.com/adobe/spacecat-shared/commit/b82e6c4c259543bd0d3e3a3ad2d3e2702956d85c))
14
+
1
15
  # [@adobe/spacecat-shared-data-access-v2.88.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.87.1...@adobe/spacecat-shared-data-access-v2.88.0) (2025-11-22)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-data-access",
3
- "version": "2.88.0",
3
+ "version": "2.88.2",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "engines": {
@@ -22,6 +22,8 @@ import BaseModel from '../base/base.model.js';
22
22
  * @extends BaseModel
23
23
  */
24
24
  class ApiKey extends BaseModel {
25
+ static ENTITY_NAME = 'ApiKey';
26
+
25
27
  static SCOPE_NAMES = [
26
28
  'sites.read_all',
27
29
  'sites.write_all',
@@ -20,6 +20,8 @@ import BaseModel from '../base/base.model.js';
20
20
  * @extends BaseModel
21
21
  */
22
22
  class AsyncJob extends BaseModel {
23
+ static ENTITY_NAME = 'AsyncJob';
24
+
23
25
  /**
24
26
  * Async Job Status types.
25
27
  * Any changes to this object needs to be reflected in the index.d.ts file as well.
@@ -28,6 +28,8 @@ import BaseModel from '../base/base.model.js';
28
28
  * @extends BaseModel
29
29
  */
30
30
  class Audit extends BaseModel {
31
+ static ENTITY_NAME = 'Audit';
32
+
31
33
  static AUDIT_TYPES = {
32
34
  APEX: 'apex',
33
35
  CWV: 'cwv',
@@ -39,6 +39,14 @@ import Reference from './reference.js';
39
39
  * @class BaseModel
40
40
  */
41
41
  class BaseModel {
42
+ /**
43
+ * The entity name for this model. Must be overridden by subclasses.
44
+ * This ensures the entity name is explicit and not dependent on class names
45
+ * which can be mangled by bundlers.
46
+ * @type {string}
47
+ */
48
+ static ENTITY_NAME = undefined;
49
+
42
50
  /**
43
51
  * Constructs an instance of BaseModel.
44
52
  * @constructor
@@ -111,10 +111,14 @@ class SchemaBuilder {
111
111
  throw new SchemaBuilderError(this, 'schemaVersion is required and must be a positive integer.');
112
112
  }
113
113
 
114
+ if (!hasText(modelClass.ENTITY_NAME)) {
115
+ throw new SchemaBuilderError(this, `Model class ${modelClass.name} must define a static ENTITY_NAME property.`);
116
+ }
117
+
114
118
  this.modelClass = modelClass;
115
119
  this.collectionClass = collectionClass;
116
120
  this.schemaVersion = schemaVersion;
117
- this.entityName = modelClass.name;
121
+ this.entityName = modelClass.ENTITY_NAME;
118
122
  this.serviceName = DEFAULT_SERVICE_NAME;
119
123
 
120
124
  this.idName = entityNameToIdName(this.entityName);
@@ -24,6 +24,8 @@ import { Entitlement } from '../entitlement/index.js';
24
24
  * @extends BaseModel
25
25
  */
26
26
  class Configuration extends BaseModel {
27
+ static ENTITY_NAME = 'Configuration';
28
+
27
29
  static JOB_GROUPS = {
28
30
  AUDITS: 'audits',
29
31
  IMPORTS: 'imports',
@@ -20,6 +20,8 @@ import BaseModel from '../base/base.model.js';
20
20
  * @extends BaseModel
21
21
  */
22
22
  class Entitlement extends BaseModel {
23
+ static ENTITY_NAME = 'Entitlement';
24
+
23
25
  static TIERS = {
24
26
  FREE_TRIAL: 'FREE_TRIAL',
25
27
  PAID: 'PAID',
@@ -24,7 +24,7 @@ const schema = new SchemaBuilder(Entitlement, EntitlementCollection)
24
24
  // Reference to Organization (many-to-one relationship)
25
25
  .addReference('belongs_to', 'Organization')
26
26
  // Reference to SiteEnrollments (one-to-many relationship)
27
- .addReference('has_many', 'SiteEnrollments')
27
+ .addReference('has_many', 'SiteEnrollments', [], { removeDependents: true })
28
28
  .addReference('has_many', 'TrialUserActivities')
29
29
  .addAttribute('productCode', {
30
30
  type: Object.values(Entitlement.PRODUCT_CODES),
@@ -20,6 +20,8 @@ import BaseModel from '../base/base.model.js';
20
20
  * @extends BaseModel
21
21
  */
22
22
  class Experiment extends BaseModel {
23
+ static ENTITY_NAME = 'Experiment';
24
+
23
25
  static DEFAULT_UPDATED_BY = 'spacecat';
24
26
 
25
27
  // add your custom methods or overrides here
@@ -19,6 +19,8 @@ import BaseModel from '../base/base.model.js';
19
19
  * @extends BaseModel
20
20
  */
21
21
  class FixEntity extends BaseModel {
22
+ static ENTITY_NAME = 'FixEntity';
23
+
22
24
  static DEFAULT_UPDATED_BY = 'spacecat';
23
25
 
24
26
  static STATUSES = {
@@ -21,6 +21,8 @@ import BaseModel from '../base/base.model.js';
21
21
  * @extends BaseModel
22
22
  */
23
23
  class FixEntitySuggestion extends BaseModel {
24
+ static ENTITY_NAME = 'FixEntitySuggestion';
25
+
24
26
  static DEFAULT_UPDATED_BY = 'spacecat';
25
27
 
26
28
  /**
@@ -20,6 +20,8 @@ import BaseModel from '../base/base.model.js';
20
20
  * @extends BaseModel
21
21
  */
22
22
  class ImportJob extends BaseModel {
23
+ static ENTITY_NAME = 'ImportJob';
24
+
23
25
  /**
24
26
  * Import Job Status types.
25
27
  * Any changes to this object needs to be reflected in the index.d.ts file as well.
@@ -20,6 +20,8 @@ import BaseModel from '../base/base.model.js';
20
20
  * @extends BaseModel
21
21
  */
22
22
  class ImportUrl extends BaseModel {
23
+ static ENTITY_NAME = 'ImportUrl';
24
+
23
25
  static IMPORT_URL_EXPIRES_IN_DAYS = 30;
24
26
 
25
27
  // add your custom methods or overrides here
@@ -20,6 +20,8 @@ import BaseModel from '../base/base.model.js';
20
20
  * @extends BaseModel
21
21
  */
22
22
  class KeyEvent extends BaseModel {
23
+ static ENTITY_NAME = 'KeyEvent';
24
+
23
25
  static KEY_EVENT_TYPES = {
24
26
  PERFORMANCE: 'PERFORMANCE',
25
27
  SEO: 'SEO',
@@ -20,6 +20,8 @@ import Audit from '../audit/audit.model.js';
20
20
  * @extends Audit
21
21
  */
22
22
  class LatestAudit extends Audit {
23
+ static ENTITY_NAME = 'LatestAudit';
24
+
23
25
  // add your custom methods or overrides here
24
26
  }
25
27
 
@@ -22,6 +22,8 @@ import BaseModel from '../base/base.model.js';
22
22
  */
23
23
 
24
24
  class Opportunity extends BaseModel {
25
+ static ENTITY_NAME = 'Opportunity';
26
+
25
27
  static ORIGINS = {
26
28
  ESS_OPS: 'ESS_OPS',
27
29
  AI: 'AI',
@@ -20,6 +20,8 @@ import BaseModel from '../base/base.model.js';
20
20
  * @extends BaseModel
21
21
  */
22
22
  class Organization extends BaseModel {
23
+ static ENTITY_NAME = 'Organization';
24
+
23
25
  static IMS_ORG_ID_REGEX = /[a-z0-9]{24}@AdobeOrg/i;
24
26
 
25
27
  // add your custom methods or overrides here
@@ -19,6 +19,8 @@ import BaseModel from '../base/base.model.js';
19
19
  * @extends BaseModel
20
20
  */
21
21
  class PageCitability extends BaseModel {
22
+ static ENTITY_NAME = 'PageCitability';
23
+
22
24
  static DEFAULT_UPDATED_BY = 'spacecat';
23
25
 
24
26
  // add any custom methods or overrides here
@@ -19,6 +19,8 @@ import BaseModel from '../base/base.model.js';
19
19
  * @extends BaseModel
20
20
  */
21
21
  class PageIntent extends BaseModel {
22
+ static ENTITY_NAME = 'PageIntent';
23
+
22
24
  static DEFAULT_UPDATED_BY = 'spacecat';
23
25
 
24
26
  static PAGE_INTENTS = {
@@ -20,6 +20,8 @@ import BaseModel from '../base/base.model.js';
20
20
  * @extends BaseModel
21
21
  */
22
22
  class Project extends BaseModel {
23
+ static ENTITY_NAME = 'Project';
24
+
23
25
  async getPrimaryLocaleSites() {
24
26
  const sites = await this.getSites();
25
27
  return sites.filter((site) => site.getIsPrimaryLocale());
@@ -13,6 +13,8 @@
13
13
  import BaseModel from '../base/base.model.js';
14
14
 
15
15
  class Report extends BaseModel {
16
+ static ENTITY_NAME = 'Report';
17
+
16
18
  static STATUSES = {
17
19
  PROCESSING: 'processing',
18
20
  SUCCESS: 'success',
@@ -20,6 +20,8 @@ import BaseModel from '../base/base.model.js';
20
20
  * @extends BaseModel
21
21
  */
22
22
  class ScrapeJob extends BaseModel {
23
+ static ENTITY_NAME = 'ScrapeJob';
24
+
23
25
  static SCRAPE_JOB_EXPIRES_IN_DAYS = 120;
24
26
 
25
27
  /**
@@ -20,6 +20,8 @@ import BaseModel from '../base/base.model.js';
20
20
  * @extends BaseModel
21
21
  */
22
22
  class ScrapeUrl extends BaseModel {
23
+ static ENTITY_NAME = 'ScrapeUrl';
24
+
23
25
  static SCRAPE_URL_EXPIRES_IN_DAYS = 120;
24
26
 
25
27
  // add your custom methods or overrides here
@@ -70,6 +70,8 @@ export const getAuthoringType = (hostname, authoringTypes) => {
70
70
  * @extends BaseModel
71
71
  */
72
72
  class Site extends BaseModel {
73
+ static ENTITY_NAME = 'Site';
74
+
73
75
  static DELIVERY_TYPES = DELIVERY_TYPES;
74
76
 
75
77
  static DEFAULT_DELIVERY_TYPE = DELIVERY_TYPES.AEM_EDGE;
@@ -20,6 +20,8 @@ import BaseModel from '../base/base.model.js';
20
20
  * @extends BaseModel
21
21
  */
22
22
  class SiteCandidate extends BaseModel {
23
+ static ENTITY_NAME = 'SiteCandidate';
24
+
23
25
  static DEFAULT_UPDATED_BY = 'spacecat';
24
26
 
25
27
  static SITE_CANDIDATE_SOURCES = {
@@ -20,6 +20,8 @@ import BaseModel from '../base/base.model.js';
20
20
  * @extends BaseModel
21
21
  */
22
22
  class SiteEnrollment extends BaseModel {
23
+ static ENTITY_NAME = 'SiteEnrollment';
24
+
23
25
  // add your custom methods or overrides here
24
26
  }
25
27
 
@@ -20,6 +20,8 @@ import BaseModel from '../base/base.model.js';
20
20
  * @extends BaseModel
21
21
  */
22
22
  class SiteTopForm extends BaseModel {
23
+ static ENTITY_NAME = 'SiteTopForm';
24
+
23
25
  // add your custom methods or overrides here
24
26
  }
25
27
 
@@ -20,6 +20,8 @@ import BaseModel from '../base/base.model.js';
20
20
  * @extends BaseModel
21
21
  */
22
22
  class SiteTopPage extends BaseModel {
23
+ static ENTITY_NAME = 'SiteTopPage';
24
+
23
25
  static DEFAULT_GEO = 'global';
24
26
 
25
27
  // add your custom methods or overrides here
@@ -21,6 +21,8 @@ import BaseModel from '../base/base.model.js';
21
21
  * @extends BaseModel
22
22
  */
23
23
  class Suggestion extends BaseModel {
24
+ static ENTITY_NAME = 'Suggestion';
25
+
24
26
  static STATUSES = {
25
27
  NEW: 'NEW',
26
28
  APPROVED: 'APPROVED',
@@ -20,6 +20,8 @@ import BaseModel from '../base/base.model.js';
20
20
  * @extends BaseModel
21
21
  */
22
22
  class TrialUser extends BaseModel {
23
+ static ENTITY_NAME = 'TrialUser';
24
+
23
25
  /**
24
26
  * Trial user status types.
25
27
  * Any change to this object needs to be reflected in the index.d.ts file as well.
@@ -20,6 +20,8 @@ import BaseModel from '../base/base.model.js';
20
20
  * @extends BaseModel
21
21
  */
22
22
  class TrialUserActivity extends BaseModel {
23
+ static ENTITY_NAME = 'TrialUserActivity';
24
+
23
25
  /**
24
26
  * Trial user activity types.
25
27
  * Any change to this object needs to be reflected in the index.d.ts file as well.
package/src/readme.md CHANGED
@@ -20,6 +20,8 @@ A *Model* is a class representing a single instance of an entity. It provides:
20
20
 
21
21
  Models extend `BaseModel`, which handles most of the common logic.
22
22
 
23
+ **Required:** All model classes must define a `static ENTITY_NAME` property to ensure bundler-agnostic operation.
24
+
23
25
  ### Collections
24
26
  A *Collection* operates on sets of entities. While `Model` focuses on individual records, `Collection` is for batch and query-level operations:
25
27
 
@@ -40,6 +42,21 @@ The `SchemaBuilder` enforces naming conventions and sets defaults, reducing repe
40
42
 
41
43
  **Note on Indexes:** Add indexes thoughtfully. Every extra index adds cost and complexity. Only create indexes for well-understood, frequently-needed query patterns.
42
44
 
45
+ ### Entity Naming (ENTITY_NAME)
46
+
47
+ All model classes **must** define a static `ENTITY_NAME` property:
48
+
49
+ ```js
50
+ class User extends BaseModel {
51
+ static ENTITY_NAME = 'User';
52
+ // ...
53
+ }
54
+ ```
55
+
56
+ This requirement ensures entity names remain consistent regardless of build tool transformations. Modern JavaScript bundlers (webpack, esbuild) may mangle class names during the build process (e.g., `Configuration` → `_Configuration`), which would break ElectroDB's key generation. By explicitly declaring the entity name, the framework operates correctly in all bundling scenarios.
57
+
58
+ The `SchemaBuilder` validates that `ENTITY_NAME` is defined and will throw a descriptive error if it's missing.
59
+
43
60
  ### Entity Registry
44
61
  The `EntityRegistry` aggregates all entities, their schemas, and their collections. It ensures consistent lookup and retrieval of any registered entity’s collection. When you add a new entity, you must register it with the `EntityRegistry` so the rest of the application can discover it.
45
62
 
@@ -348,20 +365,22 @@ Create `user.model.js`:
348
365
  ```js
349
366
  import BaseModel from '../base/base.model.js';
350
367
 
351
- class UserModel extends BaseModel {
368
+ class User extends BaseModel {
369
+ static ENTITY_NAME = 'User';
370
+
352
371
  // Additional domain logic methods can be added here if needed.
353
372
  }
354
373
 
355
- export default UserModel;
374
+ export default User;
356
375
  ```
357
376
 
377
+ **Important:** Every model class **must** define a `static ENTITY_NAME` property. This ensures the entity name is explicit and not affected by bundler transformations (like class name mangling in webpack/esbuild). The `SchemaBuilder` will throw an error if this property is missing.
378
+
358
379
  ### 3. Implement the Collection
359
380
  Create `user.collection.js`:
360
381
 
361
382
  ```js
362
383
  import BaseCollection from '../base/base.collection.js';
363
- import UserModel from './user.model.js';
364
- import userSchema from './user.schema.js';
365
384
 
366
385
  class UserCollection extends BaseCollection {
367
386
  // Additional domain logic collection methods can be added here if needed.