-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support OAuth Application Endpoints [AHOY-3610] (#2526)
* support oauth application endpoints
- Loading branch information
Showing
12 changed files
with
662 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
import type { RawAxiosRequestHeaders } from 'axios' | ||
import type { AxiosInstance } from 'contentful-sdk-core' | ||
import type { | ||
CursorPaginatedCollectionProp, | ||
GetOAuthApplicationParams, | ||
GetUserParams, | ||
QueryParams, | ||
} from '../../../common-types' | ||
import type { RestEndpoint } from '../types' | ||
import * as raw from './raw' | ||
import type { | ||
OAuthApplicationProps, | ||
CreateOAuthApplicationProps, | ||
UpdateOAuthApplicationProps, | ||
} from '../../../entities/oauth-application' | ||
|
||
/** | ||
* Retrieves details of a specific OAuth application. by its unique user ID and oauth application ID. | ||
* | ||
* @param {AxiosInstance} http - An Axios HTTP client instance. | ||
* @param {Object} params - Parameters for the request. | ||
* @param {string} params.userId - The unique user ID of the user. | ||
* @param {string} params.oauthApplicationId - The unique application ID of the OAuth application. | ||
* @returns {Promise<OAuthApplicationProps>} A Promise that resolves with the retrieved OAuth Application. | ||
* @example ```javascript | ||
* const contentful = require('contentful-management') | ||
* | ||
* const plainClient = contentful.createClient( | ||
* { | ||
* accessToken: '<content_management_api_key>' | ||
* }, | ||
* { type: 'plain' } | ||
* ) | ||
* plainClient.get({userId: 'TestUserId', oauthApplicationId: 'TestOAuthAppId'}) | ||
* .then(oauthApplication => console.log(oauthApplication)) | ||
* .catch(console.error) | ||
* ``` | ||
*/ | ||
export const get: RestEndpoint<'OAuthApplication', 'get'> = ( | ||
http: AxiosInstance, | ||
params: GetOAuthApplicationParams | ||
) => { | ||
return raw.get<OAuthApplicationProps>( | ||
http, | ||
`/users/${params.userId}/oauth_applications/${params.oauthApplicationId}` | ||
) | ||
} | ||
|
||
/** | ||
* Retrieves a list of OAuth applications associated with the current user. | ||
* | ||
* @param {AxiosInstance} http - An Axios HTTP client instance. | ||
* @param {Object} params - Parameters for the request. | ||
* @param {string} params.userId - The unique user ID of the user. | ||
* @param {QueryParams} params - Query parameters to filter and customize the request. | ||
* @returns {Promise<CursorPaginatedCollectionProp<OAuthApplicationProps>>} A Promise that resolves with a collection of oauth application properties. | ||
* @example ```javascript | ||
* const contentful = require('contentful-management') | ||
* | ||
* const plainClient = contentful.createClient( | ||
* { | ||
* accessToken: '<content_management_api_key>' | ||
* }, | ||
* { type: 'plain' } | ||
* ) | ||
* plainClient.getManyForUser({userId: 'TestUserId'}) | ||
* .then(result => console.log(result.items)) | ||
* .catch(console.error) | ||
* ``` | ||
*/ | ||
export const getManyForUser: RestEndpoint<'OAuthApplication', 'getManyForUser'> = ( | ||
http: AxiosInstance, | ||
params: GetUserParams & QueryParams | ||
) => { | ||
return raw.get<CursorPaginatedCollectionProp<OAuthApplicationProps>>( | ||
http, | ||
`/users/${params.userId}/oauth_applications`, | ||
{ | ||
params: params.query, | ||
} | ||
) | ||
} | ||
|
||
/** | ||
* Creates a new OAuth application for current authenticated user. | ||
* | ||
* @param {AxiosInstance} http - Axios instance for making the HTTP request. | ||
* @param {Object} params - Parameters for the request. | ||
* @param {string} params.userId - The unique user ID of the user. | ||
* @param {RawAxiosRequestHeaders} [headers] - Optional HTTP headers for the request. | ||
* @returns {Promise<OAuthApplicationProps>} A Promise that resolves with the created oauth application. | ||
* @example ```javascript | ||
* const contentful = require('contentful-management') | ||
* | ||
* const plainClient = contentful.createClient( | ||
* { | ||
* accessToken: '<content_management_api_key>', | ||
* }, | ||
* { type: 'plain' } | ||
* ) | ||
* plainClient.create( | ||
* {userId: 'TestUserId'}, | ||
* {name: 'Test-Name', description: 'Test-Desc', scopes: ['content_management_manage'], redirectUri: 'https://redirect.uri.com', confidential: true} | ||
* ) | ||
* .then(oauthApplication => console.log(oauthApplication)) | ||
* .catch(console.error) | ||
* ``` | ||
*/ | ||
export const create: RestEndpoint<'OAuthApplication', 'create'> = ( | ||
http: AxiosInstance, | ||
params: GetUserParams, | ||
rawData: CreateOAuthApplicationProps, | ||
headers?: RawAxiosRequestHeaders | ||
) => { | ||
return raw.post<OAuthApplicationProps>( | ||
http, | ||
`/users/${params.userId}/oauth_applications`, | ||
rawData, | ||
{ | ||
headers, | ||
} | ||
) | ||
} | ||
|
||
/** | ||
* Updates details of a specific OAuth application. | ||
* | ||
* @param {AxiosInstance} http - The Axios HTTP client instance. | ||
* @param {Object} params - The parameters for updating oauth application. | ||
* @param {string} params.userId - The unique user ID of the user. | ||
* @param {string} params.oauthApplicationId - The unique application ID of the OAuth application. | ||
* @returns {Promise<OAuthApplicationProps>} A Promise that resolves with the updated oauth application. | ||
* @example ```javascript | ||
* const contentful = require('contentful-management') | ||
* | ||
* const plainClient = contentful.createClient( | ||
* { | ||
* accessToken: '<content_management_api_key>' | ||
* }, | ||
* { type: 'plain' } | ||
* ) | ||
* plainClient.update( | ||
* {userId: 'TestUserId', oauthApplicationId: 'TestOAuthAppId'}, | ||
* {name: 'Test-Name', description: 'Test-Desc', scope: ['content_management_manage'], redirectUri: 'https://redirect.uri.com', confidential: true} | ||
* ) | ||
* .then(oauthApplication => console.log(oauthApplication)) | ||
* .catch(console.error) | ||
* ``` | ||
*/ | ||
export const update: RestEndpoint<'OAuthApplication', 'update'> = ( | ||
http: AxiosInstance, | ||
params: GetOAuthApplicationParams, | ||
rawData: UpdateOAuthApplicationProps, | ||
headers?: RawAxiosRequestHeaders | ||
) => { | ||
return raw.put<OAuthApplicationProps>( | ||
http, | ||
`/users/${params.userId}/oauth_applications/${params.oauthApplicationId}`, | ||
rawData, | ||
{ | ||
headers, | ||
} | ||
) | ||
} | ||
|
||
/** | ||
* Deletes a specific OAuth application. | ||
* | ||
* @param {AxiosInstance} http - The Axios HTTP client instance. | ||
* @param {Object} params - The parameters for deleting oauth application. | ||
* @param {string} params.userId - The unique user ID of the user. | ||
* @param {string} params.oauthApplicationId - The unique application ID of the OAuth application. | ||
* @returns {Promise<void>} | ||
* @example ```javascript | ||
* const contentful = require('contentful-management') | ||
* | ||
* const plainClient = contentful.createClient( | ||
* { | ||
* accessToken: '<content_management_api_key>' | ||
* }, | ||
* { type: 'plain' } | ||
* ) | ||
* plainClient.del({userId: 'TestUserId', oauthApplicationId: 'TestOAuthAppId'}) }) | ||
* .then(result => console.log(result.items)) | ||
* .catch(console.error) | ||
* ``` | ||
*/ | ||
export const del: RestEndpoint<'OAuthApplication', 'delete'> = ( | ||
http: AxiosInstance, | ||
params: GetOAuthApplicationParams | ||
) => { | ||
return raw.del<void>( | ||
http, | ||
`/users/${params.userId}/oauth_applications/${params.oauthApplicationId}` | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.