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

Update key management v0.28 #1266

Merged
merged 9 commits into from
Jun 22, 2022
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -626,11 +626,11 @@ Using the index object:

- [Create a key](https://docs.meilisearch.com/reference/api/keys.html#create-a-key):

`client.createKey(options: KeyPayload): Promise<Key>`
`client.createKey(options: KeyCreation): Promise<Key>`

- [Update a key](https://docs.meilisearch.com/reference/api/keys.html#update-a-key):

`client.updateKey(key: string, options: KeyPayload): Promise<Key>`
`client.updateKey(key: string, options: KeyUpdate): Promise<Key>`

- [Delete a key](https://docs.meilisearch.com/reference/api/keys.html#delete-a-key):

Expand Down
17 changes: 9 additions & 8 deletions src/clients/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import { Index } from '../indexes'
import {
KeyPayload,
KeyCreation,
Config,
IndexOptions,
IndexResponse,
Expand All @@ -26,6 +26,7 @@ import {
TokenOptions,
TaskParams,
WaitOptions,
KeyUpdate,
} from '../types'
import { HttpRequests } from '../http-requests'
import { TaskClient } from '../task'
Expand Down Expand Up @@ -257,11 +258,11 @@ class Client {
* @memberof MeiliSearch
* @method getKey
*
* @param {string} key - Key
* @param {string} keyOrUid - Key or uid of the API key
* @returns {Promise<Keys>} Promise returning a key
*/
async getKey(key: string): Promise<Key> {
const url = `keys/${key}`
async getKey(keyOrUid: string): Promise<Key> {
const url = `keys/${keyOrUid}`
return await this.httpRequest.get<Key>(url)
}

Expand All @@ -270,10 +271,10 @@ class Client {
* @memberof MeiliSearch
* @method createKey
*
* @param {KeyPayload} options - Key options
* @param {KeyCreation} options - Key options
* @returns {Promise<Key>} Promise returning an object with keys
*/
async createKey(options: KeyPayload): Promise<Key> {
async createKey(options: KeyCreation): Promise<Key> {
const url = `keys`
return await this.httpRequest.post(url, options)
}
Expand All @@ -284,10 +285,10 @@ class Client {
* @method updateKey
*
* @param {string} key - Key
* @param {KeyPayload} options - Key options
* @param {KeyUpdate} options - Key options
* @returns {Promise<Key>} Promise returning an object with keys
*/
async updateKey(key: string, options: KeyPayload): Promise<Key> {
async updateKey(key: string, options: KeyUpdate): Promise<Key> {
const url = `keys/${key}`
return await this.httpRequest.patch(url, options)
}
Expand Down
11 changes: 10 additions & 1 deletion src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ export type Stats = {
*/

export type Key = {
uid: string
description: string
name: string | null
mdubus marked this conversation as resolved.
Show resolved Hide resolved
key: string
actions: string[]
indexes: string[]
Expand All @@ -306,13 +308,20 @@ export type Key = {
updateAt: string
}

export type KeyPayload = {
export type KeyCreation = {
uid?: string
name?: string
description?: string
actions: string[]
indexes: string[]
expiresAt: string | null
}

export type KeyUpdate = {
name?: string
description?: string
}

/*
** version
*/
Expand Down
Loading