diff --git a/renovate.json b/renovate.json index 928abc99..e45f7ad1 100644 --- a/renovate.json +++ b/renovate.json @@ -1,7 +1,12 @@ { "$schema": "https://docs.renovatebot.com/renovate-schema.json", "enabled": true, - "extends": ["github>coveo/renovate-presets", ":semanticPrefixFixDepsChoreOthers", "helpers:pinGitHubActionDigests", "schedule:earlyMondays"], + "extends": [ + "github>coveo/renovate-presets", + ":semanticPrefixFixDepsChoreOthers", + "helpers:pinGitHubActionDigests", + "schedule:earlyMondays" + ], "packageRules": [ { "matchPackagePatterns": ["*"], diff --git a/src/resources/ApiKeys/ApiKeys.ts b/src/resources/ApiKeys/ApiKeys.ts index 668e993c..b354cb5e 100644 --- a/src/resources/ApiKeys/ApiKeys.ts +++ b/src/resources/ApiKeys/ApiKeys.ts @@ -1,7 +1,6 @@ import API from '../../APICore.js'; -import {New} from '../BaseInterfaces.js'; import Resource from '../Resource.js'; -import {ApiKeyModel, CreateApiKeyOptions, DuplicateApiKeyOptions} from './ApiKeysInterfaces.js'; +import {ApiKeyModel, CreateApiKeyModel, CreateApiKeyOptions, DuplicateApiKeyOptions} from './ApiKeysInterfaces.js'; export default class ApiKey extends Resource { static baseUrl = `/rest/organizations/${API.orgPlaceholder}/apikeys`; @@ -10,7 +9,7 @@ export default class ApiKey extends Resource { return this.api.get(ApiKey.baseUrl); } - create(apiKey: New, options?: CreateApiKeyOptions) { + create(apiKey: CreateApiKeyModel, options?: CreateApiKeyOptions) { return this.api.post(this.buildPath(ApiKey.baseUrl, options), apiKey); } diff --git a/src/resources/ApiKeys/ApiKeysInterfaces.ts b/src/resources/ApiKeys/ApiKeysInterfaces.ts index 14f1fbe9..b360bee4 100644 --- a/src/resources/ApiKeys/ApiKeysInterfaces.ts +++ b/src/resources/ApiKeys/ApiKeysInterfaces.ts @@ -1,14 +1,53 @@ import {GranularResource, PrivilegeModel} from '../BaseInterfaces.js'; import {ApiKeyStatus} from '../Enums.js'; -export interface ApiKeyModel extends GranularResource { + +export interface ApiKeyBaseModel extends GranularResource { + /** + * The display name for the API key. + * @example PushApiKey + */ + displayName?: string; + /** + * A brief description of the API key. + * @example API key used for managing sources. + */ + description?: string; + /** + * A set of IP addresses allowed to use the API key. + * + * Notes: + * - IP ranges using CIDR notation are also supported. + * - If an IP address is included in both the `allowedIps` and the `deniedIps`, the IP address will be denied. + * @example ["192.168.0.0/16", "29.186.225.13"] + */ + allowedIps?: string[]; + /** + * A set of IP addresses that will be denied access when attempting to use the API key. + * + * Notes: + * - IP ranges using CIDR notation are also supported. + * - If an IP address is included in both the `allowedIps` as well as the `deniedIps`, the IP address will be denied. + * @example [`"192.168.0.0/16"`, `"29.186.225.13"`] + */ + deniedIps?: string[]; + /** + * A set of privileges. + */ + privileges?: PrivilegeModel[]; + /** + * Additional configuration to be included in an API key. [to be revised] + */ + additionalConfiguration?: AdditionalConfigurationModel; +} + +export interface ApiKeyModel extends ApiKeyBaseModel { /** * The unique identifier of the [organization](https://docs.coveo.com/en/222/) the API key was created for. */ organizationId?: string; /** * The unique identifier of the API key. - * - * **Example:** t4hk287bfj5sg6wskg64ckk5a + * @example t4hk287bfj5sg6wskg64ckk5a */ id: string; /** @@ -17,22 +56,9 @@ export interface ApiKeyModel extends GranularResource { enabled?: boolean; /** * The value of the API key. - * - * **Example:** xx65151ec3-7b30-4772-a99a-09b4c0f71343 + * @example xx65151ec3-7b30-4772-a99a-09b4c0f71343 */ value?: string; - /** - * The display name for the API key. - * - * **Example:** PushApiKey - */ - displayName?: string; - /** - * A brief description of the API key. - * - * **Example:** API key used for managing sources. - */ - description?: string; /** * The username or the email address that was used to create this API key. */ @@ -40,50 +66,19 @@ export interface ApiKeyModel extends GranularResource { createdBy?: any; /** * The API key creation date in Unix timestamp in milliseconds. - * - * **Example:** 1614969486000 + * @example 1614969486000 */ createdDate?: number; /** * The approximate API key last used date in Unix timestamp in milliseconds. - * - * **Example:** 1624575600000 + * @example 1624575600000 */ lastUsedDate?: number; - /** - * A set of IP addresses allowed to use the API key. - * - * **Notes:** - * - IP ranges using CIDR notation are also supported. - * - If an IP address is included in both the `allowedIps` as well as the `deniedIps`, the IP address will be denied. - * - * **Example:** [`"192.168.0.0/16"`, `"29.186.225.13"`] - */ - allowedIps?: string[]; - /** - * A set of IP addresses that will be denied access when attempting to use the API key. - * - * **Notes:** - * - IP ranges using CIDR notation are also supported. - * - If an IP address is included in both the `allowedIps` as well as the `deniedIps`, the IP address will be denied. - * - * **Example:** [`"192.168.0.0/16"`, `"29.186.225.13"`] - */ - deniedIps?: string[]; - /** - * A set of privileges. - */ - privileges?: PrivilegeModel[]; /** * The unique identifier of the API key. - * - * **Example:** t4hk287bfj5sg6wskg64ckk5a + * @example t4hk287bfj5sg6wskg64ckk5a */ resourceId?: string; - /** - * Additional configuration to be included in an API key. [to be revised] - */ - additionalConfiguration?: AdditionalConfigurationModel; /** * The expiration date of the API key. */ @@ -106,6 +101,18 @@ export interface ApiKeyModel extends GranularResource { disabledDate?: number; } +export interface CreateApiKeyModel extends ApiKeyBaseModel { + /** + * The duration of the API key in ISO-8601 format. Once the duration is reached the key expires and cannot be used anymore. + * @example + * 'P1Y' for 1 year + * 'P14D' for 14 days + * 'P1M' for 1 month. + * 'P1Y3M14D' for 1 year, 3 months, and 14 days. + */ + lifetimeDuration?: string; +} + export interface CreateApiKeyOptions { /** * The unique identifier of the template on which to base the API key. diff --git a/src/resources/ApiKeys/test/ApiKeys.spec.ts b/src/resources/ApiKeys/test/ApiKeys.spec.ts index 0838fb94..bccb9fca 100644 --- a/src/resources/ApiKeys/test/ApiKeys.spec.ts +++ b/src/resources/ApiKeys/test/ApiKeys.spec.ts @@ -1,7 +1,6 @@ import API from '../../../APICore.js'; -import {New} from '../../BaseInterfaces.js'; import ApiKey from '../ApiKeys.js'; -import {ApiKeyModel} from '../ApiKeysInterfaces.js'; +import {ApiKeyModel, CreateApiKeyModel} from '../ApiKeysInterfaces.js'; jest.mock('../../../APICore.js'); @@ -25,9 +24,11 @@ describe('ApiKey', () => { describe('create', () => { it('should make a POST call to the ApiKeys base url', async () => { - const apiKeyModel: New = { - organizationId: 'a-smol-org', - value: '', + const apiKeyModel: CreateApiKeyModel = { + displayName: 'Cool key', + description: 'My super cool API key', + lifetimeDuration: 'P1M', + allowedIps: ['192.168.0.0/24'], }; await apiKey.create(apiKeyModel);