-
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.
feat: add resource methods [DANTE-1405] (#2436)
* feat: add Resource Type to contentful-management [DANTE-1832] * feat: add tests * feat: add getMany and orgId to ResourceType APIs * fix: unit test * fix: remove resource type id in test * feat: update comments, add more tests * feat: add resource methods * fix: unit tests * fix: lint * fix: improve the mocked data in functions for a better integration test * feat: export the resource related types * fix: wait 1s after deletion * fix: remove type id from getMany * fix: make the query params optional for resources and resourceTypes --------- Co-authored-by: Maya <maya.karabulastysiak@gmail.com>
- Loading branch information
1 parent
2b67208
commit dd4e663
Showing
21 changed files
with
721 additions
and
10 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
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,16 @@ | ||
import type { CursorPaginatedCollectionProp, GetResourceParams } from '../../../common-types' | ||
import type { RestEndpoint } from '../types' | ||
import type { AxiosInstance } from 'contentful-sdk-core' | ||
import * as raw from './raw' | ||
import type { ResourceProps, ResourceQueryOptions } from '../../../entities/resource' | ||
|
||
const getBaseUrl = (params: GetResourceParams) => | ||
`/spaces/${params.spaceId}/environments/${params.environmentId}/resource_types/${params.resourceTypeId}/resources` | ||
|
||
export const getMany: RestEndpoint<'Resource', 'getMany'> = ( | ||
http: AxiosInstance, | ||
params: GetResourceParams & { query?: ResourceQueryOptions } | ||
) => | ||
raw.get<CursorPaginatedCollectionProp<ResourceProps>>(http, getBaseUrl(params), { | ||
params: params.query, | ||
}) |
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
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
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,50 @@ | ||
import type { | ||
BasicCursorPaginationOptions, | ||
CursorPaginatedCollectionProp, | ||
MakeRequest, | ||
SysLink, | ||
} from '../common-types' | ||
import { wrapCursorPaginatedCollection } from '../common-utils' | ||
import { freezeSys, toPlainObject } from 'contentful-sdk-core' | ||
|
||
export type ResourceQueryOptions = LookupQueryOptions | SearchQueryOptions | ||
|
||
type LookupQueryOptions = { | ||
'sys.urn[in]': string | ||
} & BasicCursorPaginationOptions | ||
|
||
type SearchQueryOptions = { | ||
query: string | ||
} & BasicCursorPaginationOptions | ||
|
||
export type ResourceProps = { | ||
sys: { | ||
type: 'Resource' | ||
urn: string | ||
resourceType: SysLink | ||
resourceProvider: SysLink | ||
appDefinition: SysLink | ||
} | ||
fields: { | ||
title: string | ||
subtitle?: string | ||
description?: string | ||
externalUrl?: string | ||
image?: { | ||
url: string | ||
altText?: string | ||
} | ||
badge?: { | ||
label: string | ||
variant: 'primary' | 'negative' | 'positive' | 'warning' | 'secondary' | ||
} | ||
} | ||
} | ||
export function wrapResource(makeRequest: MakeRequest, data: ResourceProps) { | ||
const resource = toPlainObject(data) | ||
return freezeSys(resource) | ||
} | ||
export const wrapResourceCollection: ( | ||
makeRequest: MakeRequest, | ||
data: CursorPaginatedCollectionProp<ResourceProps> | ||
) => CursorPaginatedCollectionProp<ResourceProps> = wrapCursorPaginatedCollection(wrapResource) |
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.