@adobe/spacecat-shared-data-access 3.80.0 → 4.0.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +1 -1
  3. package/src/models/async-job/index.d.ts +11 -0
  4. package/src/models/base/entity.registry.js +15 -0
  5. package/src/models/idempotency-key/idempotency-key.collection.js +89 -0
  6. package/src/models/idempotency-key/idempotency-key.model.js +41 -0
  7. package/src/models/idempotency-key/idempotency-key.schema.js +51 -0
  8. package/src/models/idempotency-key/index.d.ts +41 -0
  9. package/src/models/idempotency-key/index.js +19 -0
  10. package/src/models/index.d.ts +5 -0
  11. package/src/models/index.js +5 -0
  12. package/src/models/oauth-nonce/index.d.ts +26 -0
  13. package/src/models/oauth-nonce/index.js +19 -0
  14. package/src/models/oauth-nonce/oauth-nonce.collection.js +59 -0
  15. package/src/models/oauth-nonce/oauth-nonce.model.js +35 -0
  16. package/src/models/oauth-nonce/oauth-nonce.schema.js +50 -0
  17. package/src/models/organization/index.d.ts +3 -1
  18. package/src/models/organization/organization.schema.js +1 -0
  19. package/src/models/preflight/index.d.ts +4 -7
  20. package/src/models/preflight/preflight.schema.js +13 -20
  21. package/src/models/task-management-connection/index.d.ts +82 -0
  22. package/src/models/task-management-connection/index.js +21 -0
  23. package/src/models/task-management-connection/metadata-validator.js +97 -0
  24. package/src/models/task-management-connection/task-management-connection.collection.js +61 -0
  25. package/src/models/task-management-connection/task-management-connection.model.js +119 -0
  26. package/src/models/task-management-connection/task-management-connection.schema.js +111 -0
  27. package/src/models/ticket/index.d.ts +40 -0
  28. package/src/models/ticket/index.js +19 -0
  29. package/src/models/ticket/ticket.collection.js +30 -0
  30. package/src/models/ticket/ticket.model.js +44 -0
  31. package/src/models/ticket/ticket.schema.js +72 -0
  32. package/src/models/ticket-suggestion/index.d.ts +26 -0
  33. package/src/models/ticket-suggestion/index.js +19 -0
  34. package/src/models/ticket-suggestion/ticket-suggestion.collection.js +29 -0
  35. package/src/models/ticket-suggestion/ticket-suggestion.model.js +36 -0
  36. package/src/models/ticket-suggestion/ticket-suggestion.schema.js +53 -0
  37. package/src/service/index.d.ts +10 -0
@@ -0,0 +1,44 @@
1
+ /*
2
+ * Copyright 2026 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import BaseModel from '../base/base.model.js';
14
+
15
+ /**
16
+ * Ticket — one Jira issue created by ASO via a TaskManagementConnection.
17
+ *
18
+ * Preserves the provider-side identifiers needed for future operations:
19
+ * externalTicketId — Jira's internal numeric ID (data.id). Required for PATCH/update calls.
20
+ * ticketKey — Human-readable issue key, e.g. 'ASO-42'. Used in UI links.
21
+ * ticketUrl — Direct browser URL, e.g. 'https://acme.atlassian.net/browse/ASO-42'.
22
+ * ticketProvider — Provider that created the ticket (e.g. 'jira_cloud'). Denormalized from
23
+ * the connection so the audit record is self-contained even if the connection
24
+ * is later deleted.
25
+ * createdBy — IMS user ID of the person who initiated ticket creation (JWT sub claim).
26
+ *
27
+ * ticketStatus mirrors the Jira column heading ('To Do', 'In Progress', 'Done').
28
+ * It is updated asynchronously by a future status-sync job (v2); write directly via
29
+ * setTicketStatus() + save() only from that job.
30
+ *
31
+ * v1 scope — intentional deviations from the architecture spec:
32
+ * - No status_synced_at: Jira webhook status sync is a v2 feature. UI links to ticketUrl
33
+ * for live status.
34
+ * - opportunityId is kept as an optional FK on Ticket in addition to the TicketSuggestion
35
+ * bridge so single-suggestion queries don't require a JOIN.
36
+ *
37
+ * @class Ticket
38
+ * @extends BaseModel
39
+ */
40
+ class Ticket extends BaseModel {
41
+ static ENTITY_NAME = 'Ticket';
42
+ }
43
+
44
+ export default Ticket;
@@ -0,0 +1,72 @@
1
+ /*
2
+ * Copyright 2026 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ /* c8 ignore start */
14
+
15
+ import { isValidUUID, isValidUrl } from '@adobe/spacecat-shared-utils';
16
+
17
+ import SchemaBuilder from '../base/schema.builder.js';
18
+ import Ticket from './ticket.model.js';
19
+ import TicketCollection from './ticket.collection.js';
20
+
21
+ const schema = new SchemaBuilder(Ticket, TicketCollection)
22
+ // tickets table has updated_at but no updated_by column. Suppress updatedBy so
23
+ // it is not included in INSERTs.
24
+ .addAttribute('updatedBy', { type: 'string', required: false, postgrestIgnore: true })
25
+ .addReference('belongs_to', 'Organization')
26
+ .addReference('belongs_to', 'TaskManagementConnection')
27
+ // The DB column for the TaskManagementConnection FK is `connection_id` (not
28
+ // `task_management_connection_id`). Override the auto-generated attribute to
29
+ // point to the correct column so PostgREST queries and INSERTs use the right name.
30
+ .addAttribute('taskManagementConnectionId', {
31
+ type: 'string',
32
+ required: true,
33
+ readOnly: true,
34
+ postgrestField: 'connection_id',
35
+ validate: (value) => isValidUUID(value),
36
+ })
37
+ // Optional FK — a ticket may not be linked to an opportunity in future flows.
38
+ .addReference('belongs_to', 'Opportunity', ['ticketKey'], { required: false })
39
+ .addReference('has_many', 'TicketSuggestions', ['createdAt'], { removeDependents: true })
40
+ .addAttribute('externalTicketId', {
41
+ type: 'string',
42
+ required: true,
43
+ readOnly: true,
44
+ })
45
+ .addAttribute('ticketKey', {
46
+ type: 'string',
47
+ required: true,
48
+ readOnly: true,
49
+ })
50
+ .addAttribute('ticketUrl', {
51
+ type: 'string',
52
+ required: true,
53
+ readOnly: true,
54
+ validate: (value) => isValidUrl(value),
55
+ })
56
+ .addAttribute('ticketStatus', {
57
+ type: 'string',
58
+ required: false,
59
+ default: null,
60
+ })
61
+ .addAttribute('ticketProvider', {
62
+ type: 'string',
63
+ required: true,
64
+ readOnly: true,
65
+ })
66
+ .addAttribute('createdBy', {
67
+ type: 'string',
68
+ required: true,
69
+ readOnly: true,
70
+ });
71
+
72
+ export default schema.build();
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Copyright 2026 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import type { BaseCollection, BaseModel, Ticket } from '../index';
14
+
15
+ export interface TicketSuggestion extends BaseModel {
16
+ getCreatedBy(): string;
17
+ getOpportunityId(): string | undefined;
18
+ getSuggestionId(): string;
19
+ getTicketId(): string;
20
+ getTicket(): Promise<Ticket>;
21
+ }
22
+
23
+ export interface TicketSuggestionCollection extends BaseCollection<TicketSuggestion> {
24
+ allByTicketId(ticketId: string): Promise<TicketSuggestion[]>;
25
+ findBySuggestionId(suggestionId: string): Promise<TicketSuggestion | null>;
26
+ }
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright 2026 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import TicketSuggestion from './ticket-suggestion.model.js';
14
+ import TicketSuggestionCollection from './ticket-suggestion.collection.js';
15
+
16
+ export {
17
+ TicketSuggestion,
18
+ TicketSuggestionCollection,
19
+ };
@@ -0,0 +1,29 @@
1
+ /*
2
+ * Copyright 2026 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import BaseCollection from '../base/base.collection.js';
14
+
15
+ /**
16
+ * TicketSuggestionCollection — manages TicketSuggestion bridge records.
17
+ *
18
+ * Auto-generated query methods (via schema references and indexes):
19
+ * allByTicketId(ticketId) — all suggestions linked to a ticket
20
+ * findBySuggestionId(suggestionId) — look up whether a suggestion has been ticketed
21
+ *
22
+ * @class TicketSuggestionCollection
23
+ * @extends BaseCollection
24
+ */
25
+ class TicketSuggestionCollection extends BaseCollection {
26
+ static COLLECTION_NAME = 'TicketSuggestionCollection';
27
+ }
28
+
29
+ export default TicketSuggestionCollection;
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright 2026 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import BaseModel from '../base/base.model.js';
14
+
15
+ /**
16
+ * TicketSuggestion — bridge record linking a Suggestion to the Ticket created for it.
17
+ *
18
+ * Enforces 1:1 in v1: `UNIQUE (suggestion_id)` at the DB level prevents the same
19
+ * suggestion from being ticketed twice. In v2, the constraint relaxes to
20
+ * `UNIQUE (suggestion_id, ticket_id)` to support grouped ticket creation (M:N).
21
+ *
22
+ * `suggestionId` is a logical reference (stored as TEXT), not a Postgres FK.
23
+ * Suggestions live in DynamoDB/ElectroDB — there is no Postgres FK to enforce.
24
+ * Application-layer validation ensures the suggestion exists before creating this record.
25
+ *
26
+ * `opportunityId` is stored for direct opportunity-scoped queries without requiring
27
+ * a JOIN through the Ticket row.
28
+ *
29
+ * @class TicketSuggestion
30
+ * @extends BaseModel
31
+ */
32
+ class TicketSuggestion extends BaseModel {
33
+ static ENTITY_NAME = 'TicketSuggestion';
34
+ }
35
+
36
+ export default TicketSuggestion;
@@ -0,0 +1,53 @@
1
+ /*
2
+ * Copyright 2026 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ /* c8 ignore start */
14
+
15
+ import SchemaBuilder from '../base/schema.builder.js';
16
+ import TicketSuggestion from './ticket-suggestion.model.js';
17
+ import TicketSuggestionCollection from './ticket-suggestion.collection.js';
18
+
19
+ // GSI on suggestionId powers findBySuggestionId() — used to check if a
20
+ // suggestion has already been ticketed before attempting to create a duplicate.
21
+ const schema = new SchemaBuilder(TicketSuggestion, TicketSuggestionCollection)
22
+ // ticket_suggestions is append-only — the DB grants no UPDATE privilege (bridge rows are
23
+ // immutable once created; delete and recreate if wrong). Disabling updates at the model
24
+ // layer surfaces a clean ValidationError instead of an opaque PostgREST 403.
25
+ .allowUpdates(false)
26
+ // ticket_suggestions is append-only — no updated_at or updated_by columns in the DB.
27
+ // Suppress the SchemaBuilder auto-added attributes so they are not included in INSERTs.
28
+ .addAttribute('updatedAt', {
29
+ type: 'string', required: false, readOnly: true, postgrestIgnore: true,
30
+ })
31
+ .addAttribute('updatedBy', { type: 'string', required: false, postgrestIgnore: true })
32
+ .addReference('belongs_to', 'Ticket')
33
+ .addAttribute('suggestionId', {
34
+ type: 'string',
35
+ required: true,
36
+ readOnly: true,
37
+ })
38
+ .addAttribute('opportunityId', {
39
+ type: 'string',
40
+ required: true,
41
+ readOnly: true,
42
+ })
43
+ .addAttribute('createdBy', {
44
+ type: 'string',
45
+ required: true,
46
+ readOnly: true,
47
+ })
48
+ .addIndex(
49
+ { composite: ['suggestionId'] },
50
+ { composite: [] },
51
+ );
52
+
53
+ export default schema.build();
@@ -44,6 +44,11 @@ import type { SiteEnrollmentCollection } from '../models/site-enrollment';
44
44
  import type { SiteTopFormCollection } from '../models/site-top-form';
45
45
  import type { SiteTopPageCollection } from '../models/site-top-page';
46
46
  import type { SuggestionCollection } from '../models/suggestion';
47
+ import type { IdempotencyKeyCollection } from '../models/idempotency-key';
48
+ import type { OAuthNonceCollection } from '../models/oauth-nonce';
49
+ import type { TaskManagementConnectionCollection } from '../models/task-management-connection';
50
+ import type { TicketCollection } from '../models/ticket';
51
+ import type { TicketSuggestionCollection } from '../models/ticket-suggestion';
47
52
  import type { TrialUserCollection } from '../models/trial-user';
48
53
  import type { TrialUserActivityCollection } from '../models/trial-user-activity';
49
54
 
@@ -94,6 +99,11 @@ export interface DataAccess {
94
99
  SiteTopForm: SiteTopFormCollection;
95
100
  SiteTopPage: SiteTopPageCollection;
96
101
  Suggestion: SuggestionCollection;
102
+ IdempotencyKey: IdempotencyKeyCollection;
103
+ OAuthNonce: OAuthNonceCollection;
104
+ TaskManagementConnection: TaskManagementConnectionCollection;
105
+ Ticket: TicketCollection;
106
+ TicketSuggestion: TicketSuggestionCollection;
97
107
  TrialUser: TrialUserCollection;
98
108
  TrialUserActivity: TrialUserActivityCollection;
99
109
  }