Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api-keys): adds ApiKeyACL type #1126

Merged
merged 3 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/algoliasearch/src/builds/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
addApiKey,
AddApiKeyOptions,
AddApiKeyResponse,
ApiKeyACLType,
assignUserID,
AssignUserIDResponse,
assignUserIDs,
Expand Down Expand Up @@ -539,7 +540,7 @@ export type SearchClient = BaseSearchClient & {
requestOptions?: RequestOptions
) => Readonly<Promise<GetApiKeyResponse>>;
readonly addApiKey: (
acl: readonly string[],
acl: readonly ApiKeyACLType[],
requestOptions?: AddApiKeyOptions &
Pick<RequestOptions, Exclude<keyof RequestOptions, 'queryParameters'>>
) => Readonly<WaitablePromise<AddApiKeyResponse>>;
Expand Down
3 changes: 2 additions & 1 deletion packages/algoliasearch/src/builds/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
addApiKey,
AddApiKeyOptions,
AddApiKeyResponse,
ApiKeyACLType,
assignUserID,
AssignUserIDResponse,
assignUserIDs,
Expand Down Expand Up @@ -542,7 +543,7 @@ export type SearchClient = BaseSearchClient & {
requestOptions?: RequestOptions
) => Readonly<Promise<GetApiKeyResponse>>;
readonly addApiKey: (
acl: readonly string[],
acl: readonly ApiKeyACLType[],
requestOptions?: AddApiKeyOptions &
Pick<RequestOptions, Exclude<keyof RequestOptions, 'queryParameters'>>
) => Readonly<WaitablePromise<AddApiKeyResponse>>;
Expand Down
3 changes: 2 additions & 1 deletion packages/client-search/src/methods/client/addApiKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import { ApiError, RequestOptions } from '@algolia/transporter';
import {
AddApiKeyOptions,
AddApiKeyResponse,
ApiKeyACLType,
getApiKey,
GetApiKeyResponse,
SearchClient,
} from '../..';

export const addApiKey = (base: SearchClient) => {
return (
acl: readonly string[],
acl: readonly ApiKeyACLType[],
requestOptions?: AddApiKeyOptions &
Pick<RequestOptions, Exclude<keyof RequestOptions, 'queryParameters'>>
): Readonly<WaitablePromise<AddApiKeyResponse>> => {
Expand Down
30 changes: 30 additions & 0 deletions packages/client-search/src/types/ApiKeyType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export const ApiKeyACLEnum: Readonly<Record<string, ApiKeyACLType>> = {
AddObject: 'addObject',
Analytics: 'analytics',
Browser: 'browse',
DeleteIndex: 'deleteIndex',
DeleteObject: 'deleteObject',
EditSettings: 'editSettings',
ListIndexes: 'listIndexes',
Logs: 'logs',
Recommendation: 'recommendation',
Search: 'search',
SeeUnretrievableAttributes: 'seeUnretrievableAttributes',
Settings: 'settings',
Usage: 'usage',
};

export type ApiKeyACLType =
| 'addObject'
| 'analytics'
| 'browse'
| 'deleteIndex'
| 'deleteObject'
| 'editSettings'
| 'listIndexes'
| 'logs'
| 'recommendation'
| 'search'
| 'seeUnretrievableAttributes'
| 'settings'
| 'usage';
4 changes: 3 additions & 1 deletion packages/client-search/src/types/GetApiKeyResponse.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ApiKeyACLType } from '.';

export type GetApiKeyResponse = {
/**
* A Unix timestamp used to define the expiration date of the API key.
Expand All @@ -12,7 +14,7 @@ export type GetApiKeyResponse = {
/**
* List of permissions the key contains.
*/
acl: string[];
acl: ApiKeyACLType[];

/**
* A Unix timestamp used to define the expiration date of the API key.
Expand Down
1 change: 1 addition & 0 deletions packages/client-search/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

export * from './AddApiKeyOptions';
export * from './AddApiKeyResponse';
export * from './ApiKeyType';
export * from './AssignUserIDResponse';
export * from './AssignUserIDsResponse';
export * from './BatchActionType';
Expand Down