Skip to content

Commit

Permalink
fix: align types to API and normalize naming (#2375)
Browse files Browse the repository at this point in the history
  • Loading branch information
axe312ger authored Sep 26, 2024
1 parent dd4e663 commit d2ed401
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 107 deletions.
22 changes: 11 additions & 11 deletions lib/adapters/REST/endpoints/access-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { AxiosInstance } from 'contentful-sdk-core'
import type { CollectionProp, GetOrganizationParams, QueryParams } from '../../../common-types'
import type {
CreatePersonalAccessTokenProps,
AccessTokenProp,
AccessTokenProps,
} from '../../../entities/access-token'
import type { RestEndpoint } from '../types'
import * as raw from './raw'
Expand All @@ -14,7 +14,7 @@ import * as raw from './raw'
* @param {AxiosInstance} http - An Axios HTTP client instance.
* @param {Object} params - Parameters for the request.
* @param {string} params.tokenId - The unique token ID of the access token to retrieve.
* @returns {Promise<AccessTokenProp>} A Promise that resolves with the retrieved access token information.
* @returns {Promise<AccessTokenProps>} A Promise that resolves with the retrieved access token information.
* @example ```javascript
* const contentful = require('contentful-management')
*
Expand All @@ -33,15 +33,15 @@ export const get: RestEndpoint<'AccessToken', 'get'> = (
http: AxiosInstance,
params: { tokenId: string }
) => {
return raw.get<AccessTokenProp>(http, `/users/me/access_tokens/${params.tokenId}`)
return raw.get<AccessTokenProps>(http, `/users/me/access_tokens/${params.tokenId}`)
}

/**
* Retrieves multiple access tokens associated with the currently authenticated user.
*
* @param {AxiosInstance} http - An Axios HTTP client instance.
* @param {QueryParams} params - Query parameters to filter and customize the request.
* @returns {Promise<CollectionProp<AccessTokenProp>>} A Promise that resolves with a collection of access token properties.
* @returns {Promise<CollectionProp<AccessTokenProps>>} A Promise that resolves with a collection of access token properties.
* @example ```javascript
* const contentful = require('contentful-management')
*
Expand All @@ -60,7 +60,7 @@ export const getMany: RestEndpoint<'AccessToken', 'getMany'> = (
http: AxiosInstance,
params: QueryParams
) => {
return raw.get<CollectionProp<AccessTokenProp>>(http, '/users/me/access_tokens', {
return raw.get<CollectionProp<AccessTokenProps>>(http, '/users/me/access_tokens', {
params: params.query,
})
}
Expand All @@ -72,7 +72,7 @@ export const getMany: RestEndpoint<'AccessToken', 'getMany'> = (
* @param {Object} _params - Unused parameters (can be an empty object).
* @param {CreatePersonalAccessTokenProps} rawData - Data for creating the personal access token.
* @param {RawAxiosRequestHeaders} [headers] - Optional HTTP headers for the request.
* @returns {Promise<AccessTokenProp>} A Promise that resolves with the created personal access token.
* @returns {Promise<AccessTokenProps>} A Promise that resolves with the created personal access token.
* @example ```javascript
* const contentful = require('contentful-management')
*
Expand All @@ -93,7 +93,7 @@ export const createPersonalAccessToken: RestEndpoint<'AccessToken', 'createPerso
rawData: CreatePersonalAccessTokenProps,
headers?: RawAxiosRequestHeaders
) => {
return raw.post<AccessTokenProp>(http, '/users/me/access_tokens', rawData, {
return raw.post<AccessTokenProps>(http, '/users/me/access_tokens', rawData, {
headers,
})
}
Expand All @@ -104,7 +104,7 @@ export const createPersonalAccessToken: RestEndpoint<'AccessToken', 'createPerso
* @param {AxiosInstance} http - The Axios HTTP client instance.
* @param {Object} params - The parameters for revoking the access token.
* @param {string} params.tokenId - The unique identifier of the access token to revoke.
* @returns {Promise<AccessTokenProp>} A Promise that resolves with the updated access token information after revocation.
* @returns {Promise<AccessTokenProps>} A Promise that resolves with the updated access token information after revocation.
* @example ```javascript
* const contentful = require('contentful-management')
*
Expand All @@ -123,7 +123,7 @@ export const revoke: RestEndpoint<'AccessToken', 'revoke'> = (
http: AxiosInstance,
params: { tokenId: string }
) => {
return raw.put<AccessTokenProp>(http, `/users/me/access_tokens/${params.tokenId}/revoked`, null)
return raw.put<AccessTokenProps>(http, `/users/me/access_tokens/${params.tokenId}/revoked`, null)
}

/**
Expand All @@ -132,7 +132,7 @@ export const revoke: RestEndpoint<'AccessToken', 'revoke'> = (
* @param {AxiosInstance} http - The Axios HTTP client instance.
* @param {GetOrganizationParams & QueryParams} params - Parameters for the request, including organization ID and query parameters.
* @param {string} params.organizationId - The unique identifier of the organization.
* @returns {Promise<CollectionProp<AccessTokenProp>>} A promise that resolves to a collection of access tokens.
* @returns {Promise<CollectionProp<AccessTokenProps>>} A promise that resolves to a collection of access tokens.
* @example ```javascript
* const contentful = require('contentful-management')
*
Expand All @@ -151,7 +151,7 @@ export const getManyForOrganization: RestEndpoint<'AccessToken', 'getManyForOrga
http: AxiosInstance,
params: GetOrganizationParams & QueryParams
) => {
return raw.get<CollectionProp<AccessTokenProp>>(
return raw.get<CollectionProp<AccessTokenProps>>(
http,
`/organizations/${params.organizationId}/access_tokens`,
{
Expand Down
4 changes: 2 additions & 2 deletions lib/adapters/REST/endpoints/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import type {
GetOrganizationParams,
PaginationQueryParams,
} from '../../../common-types'
import type { OrganizationProp } from '../../../entities/organization'
import type { OrganizationProps } from '../../../entities/organization'
import type { RestEndpoint } from '../types'
import * as raw from './raw'

export const getMany: RestEndpoint<'Organization', 'getMany'> = (
http: AxiosInstance,
params?: PaginationQueryParams
) => {
return raw.get<CollectionProp<OrganizationProp>>(http, `/organizations`, {
return raw.get<CollectionProp<OrganizationProps>>(http, `/organizations`, {
params: params?.query,
})
}
Expand Down
10 changes: 5 additions & 5 deletions lib/adapters/REST/endpoints/personal-access-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { AxiosInstance } from 'contentful-sdk-core'
import type { CollectionProp, QueryParams } from '../../../common-types'
import type {
CreatePersonalAccessTokenProps,
PersonalAccessTokenProp,
PersonalAccessTokenProps,
} from '../../../entities/personal-access-token'
import type { RestEndpoint } from '../types'
import * as raw from './raw'
Expand All @@ -15,7 +15,7 @@ export const get: RestEndpoint<'PersonalAccessToken', 'get'> = (
http: AxiosInstance,
params: { tokenId: string }
) => {
return raw.get<PersonalAccessTokenProp>(http, `/users/me/access_tokens/${params.tokenId}`)
return raw.get<PersonalAccessTokenProps>(http, `/users/me/access_tokens/${params.tokenId}`)
}

/**
Expand All @@ -25,7 +25,7 @@ export const getMany: RestEndpoint<'PersonalAccessToken', 'getMany'> = (
http: AxiosInstance,
params: QueryParams
) => {
return raw.get<CollectionProp<PersonalAccessTokenProp>>(http, '/users/me/access_tokens', {
return raw.get<CollectionProp<PersonalAccessTokenProps>>(http, '/users/me/access_tokens', {
params: params.query,
})
}
Expand All @@ -39,7 +39,7 @@ export const create: RestEndpoint<'PersonalAccessToken', 'create'> = (
rawData: CreatePersonalAccessTokenProps,
headers?: RawAxiosRequestHeaders
) => {
return raw.post<PersonalAccessTokenProp>(http, '/users/me/access_tokens', rawData, {
return raw.post<PersonalAccessTokenProps>(http, '/users/me/access_tokens', rawData, {
headers,
})
}
Expand All @@ -51,7 +51,7 @@ export const revoke: RestEndpoint<'PersonalAccessToken', 'revoke'> = (
http: AxiosInstance,
params: { tokenId: string }
) => {
return raw.put<PersonalAccessTokenProp>(
return raw.put<PersonalAccessTokenProps>(
http,
`/users/me/access_tokens/${params.tokenId}/revoked`,
null
Expand Down
32 changes: 16 additions & 16 deletions lib/common-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ import type {
} from './entities/environment-alias'
import type { CreateLocaleProps, LocaleProps } from './entities/locale'
import type { AppInstallationsForOrganizationProps } from './entities/app-definition'
import type { OrganizationProp } from './entities/organization'
import type { OrganizationProps } from './entities/organization'
import type {
CreateOrganizationInvitationProps,
OrganizationInvitationProps,
} from './entities/organization-invitation'
import type { OrganizationMembershipProps } from './entities/organization-membership'
import type {
CreatePersonalAccessTokenProps,
PersonalAccessTokenProp,
PersonalAccessTokenProps,
} from './entities/personal-access-token'
import type {
AccessTokenProp,
AccessTokenProps,
CreatePersonalAccessTokenProps as CreatePATProps,
} from './entities/access-token'
import type { PreviewApiKeyProps } from './entities/preview-api-key'
Expand Down Expand Up @@ -246,7 +246,6 @@ export interface BasicMetaSysProps {

export interface MetaSysProps extends BasicMetaSysProps {
space?: SysLink
status?: SysLink
publishedVersion?: number
archivedVersion?: number
archivedBy?: SysLink
Expand All @@ -258,7 +257,7 @@ export interface MetaSysProps extends BasicMetaSysProps {

export interface EntityMetaSysProps extends MetaSysProps {
space: SysLink
contentType: SysLink
status?: SysLink
environment: SysLink
publishedBy?: Link<'User'> | Link<'AppDefinition'>
publishedAt?: string
Expand All @@ -268,6 +267,7 @@ export interface EntityMetaSysProps extends MetaSysProps {
}

export interface EntryMetaSysProps extends EntityMetaSysProps {
contentType: SysLink
automationTags: Link<'Tag'>[]
}

Expand Down Expand Up @@ -1515,8 +1515,8 @@ export type MRActions = {
}
}
Organization: {
getMany: { params: PaginationQueryParams; return: CollectionProp<OrganizationProp> }
get: { params: GetOrganizationParams; return: OrganizationProp }
getMany: { params: PaginationQueryParams; return: CollectionProp<OrganizationProps> }
get: { params: GetOrganizationParams; return: OrganizationProps }
}
OrganizationInvitation: {
get: {
Expand Down Expand Up @@ -1546,29 +1546,29 @@ export type MRActions = {
delete: { params: GetOrganizationMembershipParams; return: any }
}
PersonalAccessToken: {
get: { params: { tokenId: string }; return: PersonalAccessTokenProp }
getMany: { params: QueryParams; return: CollectionProp<PersonalAccessTokenProp> }
get: { params: { tokenId: string }; return: PersonalAccessTokenProps }
getMany: { params: QueryParams; return: CollectionProp<PersonalAccessTokenProps> }
create: {
params: {}
payload: CreatePersonalAccessTokenProps
headers?: RawAxiosRequestHeaders
return: PersonalAccessTokenProp
return: PersonalAccessTokenProps
}
revoke: { params: { tokenId: string }; return: PersonalAccessTokenProp }
revoke: { params: { tokenId: string }; return: PersonalAccessTokenProps }
}
AccessToken: {
get: { params: { tokenId: string }; return: AccessTokenProp }
getMany: { params: QueryParams; return: CollectionProp<AccessTokenProp> }
get: { params: { tokenId: string }; return: AccessTokenProps }
getMany: { params: QueryParams; return: CollectionProp<AccessTokenProps> }
createPersonalAccessToken: {
params: {}
payload: CreatePATProps
headers?: RawAxiosRequestHeaders
return: AccessTokenProp
return: AccessTokenProps
}
revoke: { params: { tokenId: string }; return: AccessTokenProp }
revoke: { params: { tokenId: string }; return: AccessTokenProps }
getManyForOrganization: {
params: GetOrganizationParams & QueryParams
return: CollectionProp<AccessTokenProp>
return: CollectionProp<AccessTokenProps>
}
}
PreviewApiKey: {
Expand Down
4 changes: 2 additions & 2 deletions lib/create-contentful-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
BasicCursorPaginationOptions,
} from './common-types'
import entities from './entities'
import type { Organization, OrganizationProp } from './entities/organization'
import type { Organization, OrganizationProps } from './entities/organization'
import type { CreatePersonalAccessTokenProps } from './entities/personal-access-token'
import type { Space, SpaceProps } from './entities/space'
import type { AppDefinition } from './entities/app-definition'
Expand Down Expand Up @@ -260,7 +260,7 @@ export default function createClientApi(makeRequest: MakeRequest) {
*/
getOrganizations: function getOrganizations(
query: PaginationQueryParams['query'] = {}
): Promise<Collection<Organization, OrganizationProp>> {
): Promise<Collection<Organization, OrganizationProps>> {
return makeRequest({
entityType: 'Organization',
action: 'getMany',
Expand Down
Loading

0 comments on commit d2ed401

Please sign in to comment.