Skip to content

Commit de873be

Browse files
authored
feat: add release.entry.createWithId method [DX-61] (#2724)
* feat: add release.entry.createWithId method [DX-61] * fix: update types for release entry params * test: debug integration tests * test: update unit tests and remove changes to integration tests
1 parent d419513 commit de873be

File tree

5 files changed

+229
-61
lines changed

5 files changed

+229
-61
lines changed

lib/adapters/REST/endpoints/release-entry.ts

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import type { AxiosInstance } from 'contentful-sdk-core'
22
import type {
33
GetReleaseEntryParams,
4-
GetSpaceEnvironmentParams,
4+
GetManyReleaseEntryParams,
55
KeyValueMap,
66
PatchReleaseEntryParams,
77
QueryParams,
88
UpdateReleaseEntryParams,
9+
CreateWithIdReleaseEntryParams,
910
} from '../../../common-types'
10-
import type { EntryProps } from '../../../entities/entry'
11+
import type { CreateEntryProps, EntryProps } from '../../../entities/entry'
1112
import copy from 'fast-copy'
1213
import type { RestEndpoint } from '../types'
1314
import * as raw from './raw'
@@ -28,7 +29,7 @@ export const get: RestEndpoint<'ReleaseEntry', 'get'> = (
2829

2930
export const getMany: RestEndpoint<'ReleaseEntry', 'getMany'> = (
3031
http: AxiosInstance,
31-
params: GetSpaceEnvironmentParams & QueryParams & { releaseId: string }
32+
params: GetManyReleaseEntryParams & QueryParams
3233
) => {
3334
params.query = { ...params.query, 'sys.schemaVersion': 'Release.V2' }
3435

@@ -40,7 +41,7 @@ export const getMany: RestEndpoint<'ReleaseEntry', 'getMany'> = (
4041

4142
export const update: RestEndpoint<'ReleaseEntry', 'update'> = <T extends KeyValueMap = KeyValueMap>(
4243
http: AxiosInstance,
43-
params: UpdateReleaseEntryParams & { entryId: string } & QueryParams & { releaseId: string },
44+
params: UpdateReleaseEntryParams & QueryParams,
4445
rawData: EntryProps<T>,
4546
headers?: RawAxiosRequestHeaders
4647
) => {
@@ -75,10 +76,7 @@ export const update: RestEndpoint<'ReleaseEntry', 'update'> = <T extends KeyValu
7576

7677
export const patch: RestEndpoint<'ReleaseEntry', 'patch'> = <T extends KeyValueMap = KeyValueMap>(
7778
http: AxiosInstance,
78-
params: PatchReleaseEntryParams & {
79-
entryId: string
80-
version: number
81-
} & QueryParams,
79+
params: PatchReleaseEntryParams & QueryParams,
8280
data: OpPatch[],
8381
headers?: RawAxiosRequestHeaders
8482
) => {
@@ -96,3 +94,40 @@ export const patch: RestEndpoint<'ReleaseEntry', 'patch'> = <T extends KeyValueM
9694
}
9795
)
9896
}
97+
98+
export const createWithId: RestEndpoint<'ReleaseEntry', 'createWithId'> = <
99+
T extends KeyValueMap = KeyValueMap
100+
>(
101+
http: AxiosInstance,
102+
params: CreateWithIdReleaseEntryParams & QueryParams,
103+
rawData: CreateEntryProps<T>,
104+
headers?: RawAxiosRequestHeaders
105+
) => {
106+
params.query = { ...params.query, 'sys.schemaVersion': 'Release.V2' }
107+
const data = copy(rawData)
108+
109+
return raw.put<
110+
EntryProps<
111+
T,
112+
{
113+
release: {
114+
sys: {
115+
type: 'Link'
116+
linkType: 'Entry' | 'Asset'
117+
id: string
118+
}
119+
}
120+
}
121+
>
122+
>(
123+
http,
124+
`/spaces/${params.spaceId}/environments/${params.environmentId}/releases/${params.releaseId}/entries/${params.entryId}`,
125+
data,
126+
{
127+
headers: {
128+
'X-Contentful-Content-Type': params.contentTypeId,
129+
...headers,
130+
},
131+
}
132+
)
133+
}

lib/common-types.ts

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,13 @@ type MRInternal<UA extends boolean> = {
714714
'ReleaseAction',
715715
'queryForRelease'
716716
>
717+
718+
(opts: MROpts<'ReleaseEntry', 'get', UA>): MRReturn<'ReleaseEntry', 'get'>
719+
(opts: MROpts<'ReleaseEntry', 'getMany', UA>): MRReturn<'ReleaseEntry', 'getMany'>
720+
(opts: MROpts<'ReleaseEntry', 'update', UA>): MRReturn<'ReleaseEntry', 'update'>
721+
(opts: MROpts<'ReleaseEntry', 'patch', UA>): MRReturn<'ReleaseEntry', 'patch'>
722+
(opts: MROpts<'ReleaseEntry', 'createWithId', UA>): MRReturn<'ReleaseEntry', 'createWithId'>
723+
717724
(opts: MROpts<'Resource', 'getMany', UA>): MRReturn<'Resource', 'getMany'>
718725
(opts: MROpts<'ResourceProvider', 'get', UA>): MRReturn<'ResourceProvider', 'get'>
719726
(opts: MROpts<'ResourceProvider', 'upsert', UA>): MRReturn<'ResourceProvider', 'upsert'>
@@ -1892,6 +1899,27 @@ export type MRActions = {
18921899
}
18931900
>
18941901
}
1902+
createWithId: {
1903+
params: GetSpaceEnvironmentParams & {
1904+
releaseId: string
1905+
entryId: string
1906+
contentTypeId: string
1907+
}
1908+
payload: CreateEntryProps<any>
1909+
headers?: RawAxiosRequestHeaders
1910+
return: EntryProps<
1911+
any,
1912+
{
1913+
release: {
1914+
sys: {
1915+
type: 'Link'
1916+
linkType: 'Entry' | 'Asset'
1917+
id: string
1918+
}
1919+
}
1920+
}
1921+
>
1922+
}
18951923
}
18961924
ReleaseAction: {
18971925
get: {
@@ -2376,19 +2404,21 @@ export type GetReleaseEntryParams = GetSpaceEnvironmentParams & {
23762404
releaseId?: string
23772405
entryId: string
23782406
}
2379-
2380-
export type GetManyReleaseEntryParams = GetSpaceEnvironmentParams & {
2381-
releaseId: string
2382-
}
2383-
2407+
export type GetManyReleaseEntryParams = GetSpaceEnvironmentParams & { releaseId: string }
23842408
export type UpdateReleaseEntryParams = GetSpaceEnvironmentParams & {
23852409
releaseId: string
2410+
entryId: string
23862411
}
2387-
23882412
export type PatchReleaseEntryParams = GetSpaceEnvironmentParams & {
23892413
releaseId: string
2414+
entryId: string
2415+
version: number
2416+
}
2417+
export type CreateWithIdReleaseEntryParams = GetSpaceEnvironmentParams & {
2418+
releaseId: string
2419+
entryId: string
2420+
contentTypeId: string
23902421
}
2391-
23922422
export type GetSnapshotForContentTypeParams = GetSpaceEnvironmentParams & { contentTypeId: string }
23932423
export type GetSnapshotForEntryParams = GetSpaceEnvironmentParams & { entryId: string }
23942424
export type GetSpaceEnvAliasParams = GetSpaceParams & { environmentAliasId: string }

lib/plain/common-types.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { OpPatch } from 'json-patch'
33
import type {
44
BasicCursorPaginationOptions,
55
CollectionProp,
6+
CreateWithIdReleaseEntryParams,
67
CursorPaginatedCollectionProp,
78
EnvironmentTemplateParams,
89
GetBulkActionParams,
@@ -456,7 +457,7 @@ export type PlainClientAPI = {
456457
release: {
457458
entry: {
458459
get<T extends KeyValueMap = KeyValueMap>(
459-
params: OptionalDefaults<GetReleaseEntryParams>
460+
params: OptionalDefaults<GetReleaseEntryParams & QueryParams>
460461
): Promise<
461462
EntryProps<
462463
T,
@@ -472,7 +473,7 @@ export type PlainClientAPI = {
472473
>
473474
>
474475
getMany<T extends KeyValueMap = KeyValueMap>(
475-
params: OptionalDefaults<GetManyReleaseEntryParams>
476+
params: OptionalDefaults<GetManyReleaseEntryParams & QueryParams>
476477
): Promise<
477478
CollectionProp<
478479
EntryProps<
@@ -490,7 +491,7 @@ export type PlainClientAPI = {
490491
>
491492
>
492493
update<T extends KeyValueMap = KeyValueMap>(
493-
params: OptionalDefaults<UpdateReleaseEntryParams & { entryId: string }>,
494+
params: OptionalDefaults<UpdateReleaseEntryParams & QueryParams>,
494495
rawData: EntryProps<T>,
495496
headers?: RawAxiosRequestHeaders
496497
): Promise<
@@ -508,7 +509,7 @@ export type PlainClientAPI = {
508509
>
509510
>
510511
patch<T extends KeyValueMap = KeyValueMap>(
511-
params: OptionalDefaults<PatchReleaseEntryParams & { entryId: string; version: number }>,
512+
params: OptionalDefaults<PatchReleaseEntryParams & QueryParams>,
512513
rawData: OpPatch[],
513514
headers?: RawAxiosRequestHeaders
514515
): Promise<
@@ -525,6 +526,24 @@ export type PlainClientAPI = {
525526
}
526527
>
527528
>
529+
createWithId<T extends KeyValueMap = KeyValueMap>(
530+
params: OptionalDefaults<CreateWithIdReleaseEntryParams & QueryParams>,
531+
rawData: CreateEntryProps<T>,
532+
headers?: RawAxiosRequestHeaders
533+
): Promise<
534+
EntryProps<
535+
T,
536+
{
537+
release: {
538+
sys: {
539+
type: 'Link'
540+
linkType: 'Entry' | 'Asset'
541+
id: string
542+
}
543+
}
544+
}
545+
>
546+
>
528547
}
529548
archive(params: OptionalDefaults<GetReleaseParams & { version: number }>): Promise<ReleaseProps>
530549
get(params: OptionalDefaults<GetReleaseParams>): Promise<ReleaseProps>

lib/plain/plain-client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ export const createPlainClient = (
347347
getMany: wrap(wrapParams, 'ReleaseEntry', 'getMany'),
348348
update: wrap(wrapParams, 'ReleaseEntry', 'update'),
349349
patch: wrap(wrapParams, 'ReleaseEntry', 'patch'),
350+
createWithId: wrap(wrapParams, 'ReleaseEntry', 'createWithId'),
350351
},
351352
archive: wrap(wrapParams, 'Release', 'archive'),
352353
get: wrap(wrapParams, 'Release', 'get'),

0 commit comments

Comments
 (0)