@adobe/spacecat-shared-data-access 1.59.2 → 1.60.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 (102) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/package.json +2 -2
  3. package/src/models/site/config.js +1 -1
  4. package/src/service/audits/accessPatterns.js +7 -7
  5. package/src/service/experiments/accessPatterns.js +2 -2
  6. package/src/service/import-job/accessPatterns.js +1 -1
  7. package/src/service/import-url/accessPatterns.js +2 -2
  8. package/src/service/index.js +10 -18
  9. package/src/service/key-events/accessPatterns.js +3 -3
  10. package/src/service/organizations/accessPatterns.js +3 -3
  11. package/src/service/site-candidates/accessPatterns.js +1 -1
  12. package/src/service/sites/accessPatterns.js +11 -11
  13. package/src/v2/models/api-key/api-key.collection.js +26 -0
  14. package/src/v2/models/api-key/api-key.model.js +59 -0
  15. package/src/v2/models/api-key/api-key.schema.js +82 -0
  16. package/src/v2/models/api-key/index.d.ts +37 -0
  17. package/src/v2/models/api-key/index.js +19 -0
  18. package/src/v2/models/audit/audit.collection.js +26 -0
  19. package/src/v2/models/audit/audit.model.js +89 -0
  20. package/src/v2/models/audit/audit.schema.js +66 -0
  21. package/src/v2/models/audit/index.d.ts +40 -0
  22. package/src/v2/models/audit/index.js +19 -0
  23. package/src/v2/models/base/base.collection.js +450 -0
  24. package/src/v2/models/{base.model.js → base/base.model.js} +109 -89
  25. package/src/v2/models/base/constants.js +17 -0
  26. package/src/v2/models/base/entity.registry.js +137 -0
  27. package/src/v2/models/base/index.d.ts +83 -0
  28. package/src/v2/models/base/index.js +27 -0
  29. package/src/v2/models/base/reference.js +159 -0
  30. package/src/v2/models/base/schema.builder.js +420 -0
  31. package/src/v2/models/base/schema.js +283 -0
  32. package/src/v2/models/configuration/configuration.collection.js +39 -0
  33. package/src/v2/models/configuration/configuration.model.js +160 -0
  34. package/src/v2/models/configuration/configuration.schema.js +103 -0
  35. package/src/v2/models/configuration/index.d.ts +111 -0
  36. package/src/v2/models/configuration/index.js +19 -0
  37. package/src/v2/models/experiment/experiment.collection.js +26 -0
  38. package/src/v2/models/experiment/experiment.model.js +28 -0
  39. package/src/v2/models/experiment/experiment.schema.js +70 -0
  40. package/src/v2/models/experiment/index.d.ts +49 -0
  41. package/src/v2/models/experiment/index.js +19 -0
  42. package/src/v2/models/import-job/import-job.collection.js +45 -0
  43. package/src/v2/models/import-job/import-job.model.js +55 -0
  44. package/src/v2/models/import-job/import-job.schema.js +152 -0
  45. package/src/v2/models/import-job/index.d.ts +51 -0
  46. package/src/v2/models/import-job/index.js +19 -0
  47. package/src/v2/models/import-url/import-url.collection.js +26 -0
  48. package/src/v2/models/import-url/import-url.model.js +28 -0
  49. package/src/v2/models/import-url/import-url.schema.js +59 -0
  50. package/src/v2/models/import-url/index.d.ts +35 -0
  51. package/src/v2/models/import-url/index.js +19 -0
  52. package/src/v2/models/index.d.ts +11 -99
  53. package/src/v2/models/index.js +14 -15
  54. package/src/v2/models/key-event/index.d.ts +28 -0
  55. package/src/v2/models/key-event/index.js +19 -0
  56. package/src/v2/models/key-event/key-event.collection.js +26 -0
  57. package/src/v2/models/key-event/key-event.model.js +37 -0
  58. package/src/v2/models/key-event/key-event.schema.js +45 -0
  59. package/src/v2/models/opportunity/index.d.ts +46 -0
  60. package/src/v2/models/opportunity/index.js +19 -0
  61. package/src/v2/models/opportunity/opportunity.collection.js +26 -0
  62. package/src/v2/models/{opportunity.model.js → opportunity/opportunity.model.js} +15 -2
  63. package/src/v2/models/opportunity/opportunity.schema.js +69 -0
  64. package/src/v2/models/organization/index.d.ts +28 -0
  65. package/src/v2/models/organization/index.js +19 -0
  66. package/src/v2/models/organization/organization.collection.js +26 -0
  67. package/src/v2/models/organization/organization.model.js +31 -0
  68. package/src/v2/models/organization/organization.schema.js +51 -0
  69. package/src/v2/models/site/index.d.ts +43 -0
  70. package/src/v2/models/site/index.js +20 -0
  71. package/src/v2/models/site/site.collection.js +28 -0
  72. package/src/v2/models/site/site.model.js +47 -0
  73. package/src/v2/models/site/site.schema.js +91 -0
  74. package/src/v2/models/site-candidate/index.d.ts +38 -0
  75. package/src/v2/models/site-candidate/index.js +19 -0
  76. package/src/v2/models/site-candidate/site-candidate.collection.js +27 -0
  77. package/src/v2/models/site-candidate/site-candidate.model.js +41 -0
  78. package/src/v2/models/site-candidate/site-candidate.schema.js +59 -0
  79. package/src/v2/models/site-top-page/index.d.ts +35 -0
  80. package/src/v2/models/site-top-page/index.js +19 -0
  81. package/src/v2/models/site-top-page/site-top-page.collection.js +44 -0
  82. package/src/v2/models/site-top-page/site-top-page.model.js +28 -0
  83. package/src/v2/models/site-top-page/site-top-page.schema.js +65 -0
  84. package/src/v2/models/suggestion/index.d.ts +34 -0
  85. package/src/v2/models/suggestion/index.js +19 -0
  86. package/src/v2/models/suggestion/suggestion.collection.js +55 -0
  87. package/src/v2/models/{suggestion.model.js → suggestion/suggestion.model.js} +16 -1
  88. package/src/v2/models/suggestion/suggestion.schema.js +53 -0
  89. package/src/v2/readme.md +201 -256
  90. package/src/v2/util/accessor.utils.js +158 -0
  91. package/src/v2/util/guards.d.ts +7 -0
  92. package/src/v2/util/guards.js +21 -4
  93. package/src/v2/util/index.js +1 -0
  94. package/src/v2/util/patcher.js +54 -25
  95. package/src/v2/util/util.js +84 -0
  96. package/src/v2/models/base.collection.js +0 -275
  97. package/src/v2/models/model.factory.js +0 -74
  98. package/src/v2/models/opportunity.collection.js +0 -74
  99. package/src/v2/models/suggestion.collection.js +0 -104
  100. package/src/v2/schema/opportunity.schema.js +0 -159
  101. package/src/v2/schema/suggestion.schema.js +0 -132
  102. package/src/v2/util/reference.js +0 -41
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright 2024 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 Configuration from './configuration.model.js';
14
+ import ConfigurationCollection from './configuration.collection.js';
15
+
16
+ export {
17
+ Configuration,
18
+ ConfigurationCollection,
19
+ };
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Copyright 2024 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
+ * ExperimentCollection - A collection class responsible for managing Experiment entities.
17
+ * Extends the BaseCollection to provide specific methods for interacting with Experiment records.
18
+ *
19
+ * @class ExperimentCollection
20
+ * @extends BaseCollection
21
+ */
22
+ class ExperimentCollection extends BaseCollection {
23
+ // add custom methods here
24
+ }
25
+
26
+ export default ExperimentCollection;
@@ -0,0 +1,28 @@
1
+ /*
2
+ * Copyright 2024 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
+ export const DEFAULT_UPDATED_BY = 'spacecat';
16
+
17
+ /**
18
+ * Experiment - A class representing an Experiment entity.
19
+ * Provides methods to access and manipulate Experiment-specific data.
20
+ *
21
+ * @class Experiment
22
+ * @extends BaseModel
23
+ */
24
+ class Experiment extends BaseModel {
25
+ // add your custom methods or overrides here
26
+ }
27
+
28
+ export default Experiment;
@@ -0,0 +1,70 @@
1
+ /*
2
+ * Copyright 2024 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 { isIsoDate, isNonEmptyObject, isValidUrl } from '@adobe/spacecat-shared-utils';
16
+
17
+ import SchemaBuilder from '../base/schema.builder.js';
18
+ import Experiment, { DEFAULT_UPDATED_BY } from './experiment.model.js';
19
+ import ExperimentCollection from './experiment.collection.js';
20
+
21
+ /*
22
+ Schema Doc: https://electrodb.dev/en/modeling/schema/
23
+ Attribute Doc: https://electrodb.dev/en/modeling/attributes/
24
+ Indexes Doc: https://electrodb.dev/en/modeling/indexes/
25
+ */
26
+
27
+ const schema = new SchemaBuilder(Experiment, ExperimentCollection)
28
+ .addReference('belongs_to', 'Site', ['expId', 'url', 'updatedAt'])
29
+ .addAttribute('conversionEventName', {
30
+ type: 'string',
31
+ })
32
+ .addAttribute('conversionEventValue', { type: 'string' })
33
+ .addAttribute('endDate', {
34
+ type: 'string',
35
+ validate: (value) => !value || isIsoDate(value),
36
+ })
37
+ .addAttribute('expId', {
38
+ type: 'string',
39
+ required: true,
40
+ })
41
+ .addAttribute('name', { type: 'string' })
42
+ .addAttribute('startDate', {
43
+ type: 'string',
44
+ validate: (value) => !value || isIsoDate(value),
45
+ })
46
+ .addAttribute('status', {
47
+ type: ['ACTIVE', 'INACTIVE'],
48
+ required: true,
49
+ })
50
+ .addAttribute('type', { type: 'string' })
51
+ .addAttribute('url', {
52
+ type: 'string',
53
+ required: true,
54
+ validate: (value) => isValidUrl(value),
55
+ })
56
+ .addAttribute('updatedBy', {
57
+ type: 'string',
58
+ required: true,
59
+ default: DEFAULT_UPDATED_BY,
60
+ })
61
+ .addAttribute('variants', {
62
+ type: 'list',
63
+ items: {
64
+ type: 'any',
65
+ validate: (value) => isNonEmptyObject(value),
66
+ },
67
+ required: true,
68
+ });
69
+
70
+ export default schema.build();
@@ -0,0 +1,49 @@
1
+ /*
2
+ * Copyright 2024 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, Site } from '../index';
14
+
15
+ export interface Experiment extends BaseModel {
16
+ getConversionEventName(): string;
17
+ getConversionEventValue(): string;
18
+ getEndDate(): number;
19
+ getExpId(): string;
20
+ getName(): string;
21
+ getSite(): Promise<Site>;
22
+ getSiteId(): string;
23
+ getStartDate(): number;
24
+ getStatus(): string;
25
+ getType(): string;
26
+ getUrl(): string;
27
+ getVariants(): object;
28
+ setConversionEventName(conversionEventName: string): Experiment;
29
+ setConversionEventValue(conversionEventValue: string): Experiment;
30
+ setEndDate(endDate: number): Experiment;
31
+ setExpId(expId: string): Experiment;
32
+ setName(name: string): Experiment;
33
+ setStartDate(startDate: number): Experiment;
34
+ setStatus(status: string): Experiment;
35
+ setType(type: string): Experiment;
36
+ setUrl(url: string): Experiment;
37
+ setVariants(variants: object): Experiment;
38
+ }
39
+
40
+ export interface ExperimentCollection extends BaseCollection<Experiment> {
41
+ allBySiteId(siteId: string): Promise<Experiment[]>;
42
+ allBySiteIdAndExpId(siteId: string, expId: string): Promise<Experiment[]>;
43
+ findBySiteIdAndExpId(siteId: string, expId: string): Promise<Experiment | null>;
44
+ findBySiteIdAndExpIdAndUrl(
45
+ siteId: string,
46
+ expId: string,
47
+ url: string,
48
+ ): Promise<Experiment | null>;
49
+ }
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright 2024 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 Experiment from './experiment.model.js';
14
+ import ExperimentCollection from './experiment.collection.js';
15
+
16
+ export {
17
+ Experiment,
18
+ ExperimentCollection,
19
+ };
@@ -0,0 +1,45 @@
1
+ /*
2
+ * Copyright 2024 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 { isIsoDate } from '@adobe/spacecat-shared-utils';
14
+
15
+ import BaseCollection from '../base/base.collection.js';
16
+ import { ValidationError } from '../../errors/index.js';
17
+
18
+ /**
19
+ * ImportJobCollection - A collection class responsible for managing ImportJob entities.
20
+ * Extends the BaseCollection to provide specific methods for interacting with ImportJob records.
21
+ *
22
+ * @class ImportJobCollection
23
+ * @extends BaseCollection
24
+ */
25
+ class ImportJobCollection extends BaseCollection {
26
+ async allByDateRange(startDate, endDate) {
27
+ if (!isIsoDate(startDate)) {
28
+ throw new ValidationError(`Invalid start date: ${startDate}`);
29
+ }
30
+
31
+ if (!isIsoDate(endDate)) {
32
+ throw new ValidationError(`Invalid end date: ${endDate}`);
33
+ }
34
+
35
+ return this.all({}, {
36
+ between: {
37
+ attribute: 'startedAt',
38
+ start: startDate,
39
+ end: endDate,
40
+ },
41
+ });
42
+ }
43
+ }
44
+
45
+ export default ImportJobCollection;
@@ -0,0 +1,55 @@
1
+ /*
2
+ * Copyright 2024 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
+ * Supported Import Options.
17
+ */
18
+ export const ImportOptions = {
19
+ ENABLE_JAVASCRIPT: 'enableJavascript',
20
+ PAGE_LOAD_TIMEOUT: 'pageLoadTimeout',
21
+ };
22
+
23
+ /**
24
+ * Import Job Status types.
25
+ * Any changes to this object needs to be reflected in the index.d.ts file as well.
26
+ */
27
+ export const ImportJobStatus = {
28
+ RUNNING: 'RUNNING',
29
+ COMPLETE: 'COMPLETE',
30
+ FAILED: 'FAILED',
31
+ STOPPED: 'STOPPED',
32
+ };
33
+
34
+ /**
35
+ * ImportURL Status types.
36
+ * Any changes to this object needs to be reflected in the index.d.ts file as well.
37
+ */
38
+ export const ImportUrlStatus = {
39
+ PENDING: 'PENDING',
40
+ REDIRECT: 'REDIRECT',
41
+ ...ImportJobStatus,
42
+ };
43
+
44
+ /**
45
+ * ImportJob - A class representing an ImportJob entity.
46
+ * Provides methods to access and manipulate ImportJob-specific data.
47
+ *
48
+ * @class ImportJob
49
+ * @extends BaseModel
50
+ */
51
+ class ImportJob extends BaseModel {
52
+ // add your custom methods or overrides here
53
+ }
54
+
55
+ export default ImportJob;
@@ -0,0 +1,152 @@
1
+ /*
2
+ * Copyright 2024 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 {
16
+ isInteger,
17
+ isIsoDate,
18
+ isNumber,
19
+ isObject,
20
+ isValidUrl,
21
+ } from '@adobe/spacecat-shared-utils';
22
+
23
+ import SchemaBuilder from '../base/schema.builder.js';
24
+ import ImportJob, { ImportJobStatus, ImportOptions } from './import-job.model.js';
25
+ import ImportJobCollection from './import-job.collection.js';
26
+
27
+ const ImportOptionTypeValidator = {
28
+ [ImportOptions.ENABLE_JAVASCRIPT]: (value) => {
29
+ if (value !== true && value !== false) {
30
+ throw new Error(`Invalid value for ${ImportOptions.ENABLE_JAVASCRIPT}: ${value}`);
31
+ }
32
+ },
33
+ [ImportOptions.PAGE_LOAD_TIMEOUT]: (value) => {
34
+ if (!isInteger(value) || value < 0) {
35
+ throw new Error(`Invalid value for ${ImportOptions.PAGE_LOAD_TIMEOUT}: ${value}`);
36
+ }
37
+ },
38
+ };
39
+
40
+ const validateOptions = (options) => {
41
+ if (!isObject(options)) {
42
+ throw new Error(`Invalid options: ${options}`);
43
+ }
44
+
45
+ const invalidOptions = Object.keys(options).filter(
46
+ (key) => !Object.values(ImportOptions)
47
+ .some((value) => value.toLowerCase() === key.toLowerCase()),
48
+ );
49
+
50
+ if (invalidOptions.length > 0) {
51
+ throw new Error(`Invalid options: ${invalidOptions}`);
52
+ }
53
+
54
+ // validate each option for it's expected data type
55
+ Object.keys(options).forEach((key) => {
56
+ if (ImportOptionTypeValidator[key]) {
57
+ ImportOptionTypeValidator[key](options[key]);
58
+ }
59
+ });
60
+
61
+ return true;
62
+ };
63
+
64
+ /*
65
+ Schema Doc: https://electrodb.dev/en/modeling/schema/
66
+ Attribute Doc: https://electrodb.dev/en/modeling/attributes/
67
+ Indexes Doc: https://electrodb.dev/en/modeling/indexes/
68
+ */
69
+
70
+ const schema = new SchemaBuilder(ImportJob, ImportJobCollection)
71
+ .addReference('has_many', 'ImportUrls')
72
+ .addAttribute('baseURL', {
73
+ type: 'string',
74
+ required: true,
75
+ validate: (value) => isValidUrl(value),
76
+ })
77
+ .addAttribute('duration', {
78
+ type: 'number',
79
+ default: 0,
80
+ validate: (value) => !value || isNumber(value),
81
+ })
82
+ .addAttribute('endedAt', {
83
+ type: 'string',
84
+ validate: (value) => !value || isIsoDate(value),
85
+ })
86
+ .addAttribute('failedCount', {
87
+ type: 'number',
88
+ default: 0,
89
+ validate: (value) => !value || isInteger(value),
90
+ })
91
+ .addAttribute('hasCustomHeaders', {
92
+ type: 'boolean',
93
+ default: false,
94
+ })
95
+ .addAttribute('hasCustomImportJs', {
96
+ type: 'boolean',
97
+ default: false,
98
+ })
99
+ .addAttribute('hashedApiKey', {
100
+ type: 'string',
101
+ required: true,
102
+ })
103
+ .addAttribute('importQueueId', {
104
+ type: 'string',
105
+ })
106
+ .addAttribute('initiatedBy', {
107
+ type: 'map',
108
+ properties: {
109
+ apiKeyName: { type: 'string' },
110
+ imsOrgId: { type: 'string' },
111
+ imsUserId: { type: 'string' },
112
+ userAgent: { type: 'string' },
113
+ },
114
+ })
115
+ .addAttribute('options', {
116
+ type: 'any',
117
+ validate: (value) => !value || validateOptions(value),
118
+ })
119
+ .addAttribute('redirectCount', {
120
+ type: 'number',
121
+ default: 0,
122
+ validate: (value) => !value || isInteger(value),
123
+ })
124
+ .addAttribute('status', {
125
+ type: Object.values(ImportJobStatus),
126
+ required: true,
127
+ })
128
+ .addAttribute('startedAt', {
129
+ type: 'string',
130
+ required: true,
131
+ readOnly: true,
132
+ default: () => new Date().toISOString(),
133
+ validate: (value) => isIsoDate(value),
134
+ })
135
+ .addAttribute('successCount', {
136
+ type: 'number',
137
+ default: 0,
138
+ validate: (value) => !value || isInteger(value),
139
+ })
140
+ .addAttribute('urlCount', {
141
+ type: 'number',
142
+ default: 0,
143
+ validate: (value) => !value || isInteger(value),
144
+ })
145
+ .addAllIndexWithComposite('startedAt')
146
+ .addIndex(
147
+ 'byStatus',
148
+ { composite: ['status'] },
149
+ { composite: ['updatedAt'] },
150
+ );
151
+
152
+ export default schema.build();
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Copyright 2024 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 } from '../base';
14
+
15
+ export interface ImportJob extends BaseModel {
16
+ getBaseURL(): string,
17
+ getDuration(): number,
18
+ getEndedAt(): number,
19
+ getFailedCount(): number,
20
+ getHasCustomHeaders(): boolean,
21
+ getHasCustomImportJs(): boolean,
22
+ getHashedApiKey(): string,
23
+ getImportQueueId(): string,
24
+ getInitiatedBy(): string,
25
+ getOptions(): string,
26
+ getRedirectCount(): number,
27
+ getStatus(): string,
28
+ getStartedAt(): number,
29
+ getSuccessCount(): number,
30
+ getUrlCount(): number,
31
+ setBaseURL(baseURL: string): void,
32
+ setDuration(duration: number): void,
33
+ setEndedAt(endTime: number): void,
34
+ setFailedCount(failedCount: number): void,
35
+ setHasCustomHeaders(hasCustomHeaders: boolean): void,
36
+ setHasCustomImportJs(hasCustomImportJs: boolean): void,
37
+ setHashedApiKey(hashedApiKey: string): void,
38
+ setImportQueueId(importQueueId: string): void,
39
+ setInitiatedBy(initiatedBy: string): void,
40
+ setOptions(options: string): void,
41
+ setRedirectCount(redirectCount: number): void,
42
+ setStatus(status: string): void,
43
+ setStartedAt(startTime: number): void,
44
+ setSuccessCount(successCount: number): void,
45
+ setUrlCount(urlCount: number): void,
46
+ }
47
+
48
+ export interface ImportJobCollection extends BaseCollection<ImportJob> {
49
+ allByDateRange(startDate: number, endDate: number): Promise<ImportJob[]>;
50
+ allByStatus(status: string): Promise<ImportJob[]>;
51
+ }
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright 2024 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 ImportJob from './import-job.model.js';
14
+ import ImportJobCollection from './import-job.collection.js';
15
+
16
+ export {
17
+ ImportJob,
18
+ ImportJobCollection,
19
+ };
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Copyright 2024 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
+ * ImportUrlCollection - A collection class responsible for managing ImportUrl entities.
17
+ * Extends the BaseCollection to provide specific methods for interacting with ImportUrl records.
18
+ *
19
+ * @class ImportUrlCollection
20
+ * @extends BaseCollection
21
+ */
22
+ class ImportUrlCollection extends BaseCollection {
23
+ // add custom methods here
24
+ }
25
+
26
+ export default ImportUrlCollection;
@@ -0,0 +1,28 @@
1
+ /*
2
+ * Copyright 2024 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
+ export const IMPORT_URL_EXPIRES_IN_DAYS = 30;
16
+
17
+ /**
18
+ * ImportUrl - A class representing an ImportUrl entity.
19
+ * Provides methods to access and manipulate ImportUrl-specific data.
20
+ *
21
+ * @class ImportUrl
22
+ * @extends BaseModel
23
+ */
24
+ class ImportUrl extends BaseModel {
25
+ // add your custom methods or overrides here
26
+ }
27
+
28
+ export default ImportUrl;
@@ -0,0 +1,59 @@
1
+ /*
2
+ * Copyright 2024 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 { isIsoDate, isValidUrl } from '@adobe/spacecat-shared-utils';
16
+
17
+ import { ImportUrlStatus } from '../import-job/import-job.model.js';
18
+ import SchemaBuilder from '../base/schema.builder.js';
19
+ import ImportUrl, { IMPORT_URL_EXPIRES_IN_DAYS } from './import-url.model.js';
20
+ import ImportUrlCollection from './import-url.collection.js';
21
+
22
+ /*
23
+ Schema Doc: https://electrodb.dev/en/modeling/schema/
24
+ Attribute Doc: https://electrodb.dev/en/modeling/attributes/
25
+ Indexes Doc: https://electrodb.dev/en/modeling/indexes/
26
+ */
27
+
28
+ const schema = new SchemaBuilder(ImportUrl, ImportUrlCollection)
29
+ .addReference('belongs_to', 'ImportJob', ['status'])
30
+ .addAttribute('expiresAt', {
31
+ type: 'string',
32
+ required: true,
33
+ validate: (value) => isIsoDate(value),
34
+ default: () => {
35
+ const date = new Date();
36
+ date.setDate(date.getDate() + IMPORT_URL_EXPIRES_IN_DAYS);
37
+ return date.toISOString();
38
+ },
39
+ })
40
+ .addAttribute('file', {
41
+ type: 'string',
42
+ })
43
+ .addAttribute('path', {
44
+ type: 'string',
45
+ })
46
+ .addAttribute('reason', {
47
+ type: 'string',
48
+ })
49
+ .addAttribute('status', {
50
+ type: Object.values(ImportUrlStatus),
51
+ required: true,
52
+ })
53
+ .addAttribute('url', {
54
+ type: 'string',
55
+ required: true,
56
+ validate: (value) => isValidUrl(value),
57
+ });
58
+
59
+ export default schema.build();