@adobe/spacecat-shared-data-access 1.41.1 → 1.41.3

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,17 @@
1
+ # [@adobe/spacecat-shared-data-access-v1.41.3](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.41.2...@adobe/spacecat-shared-data-access-v1.41.3) (2024-08-15)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * refactor hashed api key and query to retrieve API key ([#325](https://github.com/adobe/spacecat-shared/issues/325)) ([a99fc76](https://github.com/adobe/spacecat-shared/commit/a99fc76963fdcd6bce8de7d5b315dbefbb03fd95))
7
+
8
+ # [@adobe/spacecat-shared-data-access-v1.41.2](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.41.1...@adobe/spacecat-shared-data-access-v1.41.2) (2024-08-14)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * add query changes ([#324](https://github.com/adobe/spacecat-shared/issues/324)) ([6104f65](https://github.com/adobe/spacecat-shared/commit/6104f65620f8f020e70494c2c2138ae2afefe15e))
14
+
1
15
  # [@adobe/spacecat-shared-data-access-v1.41.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.41.0...@adobe/spacecat-shared-data-access-v1.41.1) (2024-08-14)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-data-access",
3
- "version": "1.41.1",
3
+ "version": "1.41.3",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -21,7 +21,7 @@ export const ApiKeyDto = {
21
21
  * imsOrgId: *, expiresAt: *}}
22
22
  */
23
23
  toDynamoItem: (apiKey) => ({
24
- hashedKey: apiKey.getHashedKey(),
24
+ hashedApiKey: apiKey.getHashedApiKey(),
25
25
  name: apiKey.getName(),
26
26
  imsUserId: apiKey.getImsUserId(),
27
27
  imsOrgId: apiKey.getImsOrgId(),
@@ -38,7 +38,7 @@ export const ApiKeyDto = {
38
38
  */
39
39
  fromDynamoItem: (dynamoItem) => {
40
40
  const apiKeyData = {
41
- hashedKey: dynamoItem.hashedKey,
41
+ hashedApiKey: dynamoItem.hashedApiKey,
42
42
  name: dynamoItem.name,
43
43
  imsUserId: dynamoItem.imsUserId,
44
44
  imsOrgId: dynamoItem.imsOrgId,
package/src/index.d.ts CHANGED
@@ -546,7 +546,7 @@ export interface ApiKey {
546
546
  /**
547
547
  * Retrieves the hashed key value of the API Key.
548
548
  */
549
- getHashedKey: () => string;
549
+ getHashedApiKey: () => string;
550
550
 
551
551
  /**
552
552
  * Retrieves the name of the API Key.
@@ -581,7 +581,7 @@ export interface ApiKey {
581
581
  /**
582
582
  * Retrieves the scopes of the API Key.
583
583
  */
584
- getScopes: () => string;
584
+ getScopes: () => Array<string>;
585
585
 
586
586
  }
587
587
 
@@ -773,8 +773,8 @@ export interface DataAccess {
773
773
  jobId: string,
774
774
  status: string,
775
775
  ) => Promise<ImportUrl[]>;
776
- getApiKeyByHashedKey: (
777
- hashedKey: string,
776
+ getApiKeyByHashedApiKey: (
777
+ hashedApiKey: string,
778
778
  ) => Promise<ApiKey | null>;
779
779
  createNewApiKey: (
780
780
  apiKeyData: object,
@@ -832,7 +832,7 @@ interface DataAccessConfig {
832
832
  indexNameAllImportJobsByStatus: string,
833
833
  indexNameAllImportJobsByDateRange: string,
834
834
  indexNameAllImportUrlsByJobIdAndStatus: string,
835
- indexNameApiKeyByHashedKey: string,
835
+ indexNameApiKeyByHashedApiKey: string,
836
836
  pkAllSites: string;
837
837
  pkAllLatestAudits: string;
838
838
  pkAllOrganizations: string;
package/src/index.js CHANGED
@@ -37,7 +37,7 @@ const INDEX_NAME_ALL_SITES_ORGANIZATIONS = 'spacecat-services-all-sites-organiza
37
37
  const INDEX_NAME_ALL_IMPORT_JOBS_BY_STATUS = 'spacecat-services-all-import-jobs-by-status-dev';
38
38
  const INDEX_NAME_ALL_IMPORT_JOBS_BY_DATE_RANGE = 'spacecat-services-all-import-jobs-by-date-range-dev';
39
39
  const INDEX_NAME_ALL_IMPORT_URLS_BY_JOB_ID_AND_STATUS = 'spacecat-services-all-import-urls-by-job-id-and-status-dev';
40
- const INDEX_NAME_API_KEY_BY_HASHED_KEY = 'spacecat-services-api-key-by-hashed-key-dev';
40
+ const INDEX_NAME_API_KEY_BY_HASHED_API_KEY = 'spacecat-services-api-key-by-hashed-api-key-dev';
41
41
 
42
42
  const PK_ALL_SITES = 'ALL_SITES';
43
43
  const PK_ALL_CONFIGURATIONS = 'ALL_CONFIGURATIONS';
@@ -75,7 +75,7 @@ export default function dataAccessWrapper(fn) {
75
75
  DYNAMO_INDEX_NAME_ALL_IMPORT_JOBS_BY_DATE_RANGE = INDEX_NAME_ALL_IMPORT_JOBS_BY_DATE_RANGE,
76
76
  DYNAMO_INDEX_NAME_ALL_IMPORT_URLS_BY_JOB_ID_AND_STATUS =
77
77
  INDEX_NAME_ALL_IMPORT_URLS_BY_JOB_ID_AND_STATUS,
78
- DYNAMO_INDEX_NAME_API_KEY_BY_HASHED_KEY = INDEX_NAME_API_KEY_BY_HASHED_KEY,
78
+ DYNAMO_INDEX_NAME_API_KEY_BY_HASHED_API_KEY = INDEX_NAME_API_KEY_BY_HASHED_API_KEY,
79
79
  } = context.env;
80
80
 
81
81
  context.dataAccess = createDataAccess({
@@ -101,7 +101,7 @@ export default function dataAccessWrapper(fn) {
101
101
  indexNameAllImportJobsByStatus: DYNAMO_INDEX_NAME_ALL_IMPORT_JOBS_BY_STATUS,
102
102
  indexNameAllImportJobsByDateRange: DYNAMO_INDEX_NAME_ALL_IMPORT_JOBS_BY_DATE_RANGE,
103
103
  indexNameImportUrlsByJobIdAndStatus: DYNAMO_INDEX_NAME_ALL_IMPORT_URLS_BY_JOB_ID_AND_STATUS,
104
- indexNameApiKeyByHashedKey: DYNAMO_INDEX_NAME_API_KEY_BY_HASHED_KEY,
104
+ indexNameApiKeyByHashedApiKey: DYNAMO_INDEX_NAME_API_KEY_BY_HASHED_API_KEY,
105
105
  pkAllSites: PK_ALL_SITES,
106
106
  pkAllOrganizations: PK_ALL_ORGANIZATIONS,
107
107
  pkAllLatestAudits: PK_ALL_LATEST_AUDITS,
@@ -21,7 +21,7 @@ const scopeNames = ['sites.read_all', 'sites.write_all', 'organizations.read_all
21
21
  const ApiKey = (data) => {
22
22
  const self = Base(data);
23
23
 
24
- self.getHashedKey = () => self.state.hashedKey;
24
+ self.getHashedApiKey = () => self.state.hashedApiKey;
25
25
  self.getName = () => self.state.name;
26
26
  self.getImsUserId = () => self.state.imsUserId;
27
27
  self.getImsOrgId = () => self.state.imsOrgId;
@@ -41,8 +41,8 @@ const ApiKey = (data) => {
41
41
  export const createApiKey = (data) => {
42
42
  const newState = { ...data };
43
43
 
44
- if (!hasText(newState.hashedKey)) {
45
- throw new Error(`Invalid Hashed Key: ${newState.hashedKey}`);
44
+ if (!hasText(newState.hashedApiKey)) {
45
+ throw new Error(`Invalid Hashed API Key: ${newState.hashedApiKey}`);
46
46
  }
47
47
 
48
48
  if (!hasText(newState.name)) {
@@ -14,26 +14,26 @@ import { ApiKeyDto } from '../../dto/api-key.js';
14
14
 
15
15
  /**
16
16
  * Get ApiKey by Hashed Key
17
- * @param {string} hashedKey
17
+ * @param {string} hashedApiKey
18
18
  * @param {DynamoClient} dynamoClient
19
19
  * @param {Object} config
20
20
  * @param {Logger} log
21
21
  * @returns {Promise<ApiKeyDto>}
22
22
  */
23
- export const getApiKeyByHashedKey = async (hashedKey, dynamoClient, log, config) => {
24
- const item = await dynamoClient.query({
23
+ export const getApiKeyByHashedApiKey = async (hashedApiKey, dynamoClient, log, config) => {
24
+ const items = await dynamoClient.query({
25
25
  TableName: config.tableNameApiKeys,
26
- IndexName: config.indexNameApiKeyByHashedKey,
27
- KeyConditionExpression: '#hashedKey = :hashedKey',
26
+ IndexName: config.indexNameApiKeyByHashedApiKey,
27
+ KeyConditionExpression: '#hashedApiKey = :hashedApiKey',
28
28
  ExpressionAttributeNames: {
29
- '#hashedKey': 'hashedKey',
29
+ '#hashedApiKey': 'hashedApiKey',
30
30
  },
31
31
  ExpressionAttributeValues: {
32
- ':gsi1pk': config.pkApiKey,
33
- ':hashedKey': hashedKey,
32
+ ':hashedApiKey': hashedApiKey,
34
33
  },
34
+ Limit: 1,
35
35
  });
36
- return item ? ApiKeyDto.fromDynamoItem(item) : null;
36
+ return items.length > 0 ? ApiKeyDto.fromDynamoItem(items[0]) : null;
37
37
  };
38
38
 
39
39
  /**
@@ -10,9 +10,14 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import { createNewApiKey, getApiKeyByHashedKey } from './accessPatterns.js';
13
+ import { createNewApiKey, getApiKeyByHashedApiKey } from './accessPatterns.js';
14
14
 
15
15
  export const apiKeyFunctions = (dynamoClient, config, log) => ({
16
- getApiKeyByHashedKey: (hashedKey) => getApiKeyByHashedKey(hashedKey, dynamoClient, log, config),
16
+ getApiKeyByHashedApiKey: (hashedApiKey) => getApiKeyByHashedApiKey(
17
+ hashedApiKey,
18
+ dynamoClient,
19
+ log,
20
+ config,
21
+ ),
17
22
  createNewApiKey: (apiKey) => createNewApiKey(apiKey, dynamoClient, config, log),
18
23
  });