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

feat: change the folder patch operation type into a discriminated union #142

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e35acbf
added display_timezone to workflow model
Nickm615 Jan 31, 2024
9cea528
added IListLanguageVariantsBySpaceResponseContract
Nickm615 Jan 31, 2024
1cfe53c
added ListLanguageVariantsByCollectionResponse
Nickm615 Jan 31, 2024
5102496
added listLanguageVariantsBySpaceAsync to query service
Nickm615 Jan 31, 2024
6b08a2e
added mapLanguageVariantsByCollectionResponse to mapper
Nickm615 Jan 31, 2024
260541e
added listLanguageVariantsBySpace to api-endpoints. Added list-langua…
Nickm615 Jan 31, 2024
a3c36e0
added fake-list-language-variants-by-space
Nickm615 Feb 1, 2024
978d5c2
added list-language-variants-by-space.spec
Nickm615 Feb 1, 2024
0e0cf84
added listLanguageVariantsByCollection() to imanagement-client.interf…
Nickm615 Feb 1, 2024
652280b
local tests successful, final changes
Nickm615 Feb 7, 2024
d6d183f
updated space.models.ts with collections property
Nickm615 Feb 7, 2024
b65161f
updated space-contract.ts with collections property
Nickm615 Feb 7, 2024
9e74ec4
updated space fake responses with collections property
Nickm615 Feb 7, 2024
d948ef7
updated space tests to validate collections property
Nickm615 Feb 7, 2024
b36ebaf
added collection property to mapSpace, updated test cases. All tests …
Nickm615 Feb 20, 2024
fa565a0
added IModifyAssetFolderOperations and operation types to asset-folde…
Nickm615 Feb 28, 2024
309238a
changed IAddOrModifyAssetFolderData to IAssetFolderData updated manag…
Nickm615 Feb 28, 2024
c31bf35
updated references in client, query and service. Tests passing
Nickm615 Feb 29, 2024
58a45d9
Removes commented code, adds more sample to spec
Enngage Mar 1, 2024
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
8 changes: 7 additions & 1 deletion lib/client/imanagement-client.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import {
ListLanguageVariantsOfContentTypeQuery,
ListLanguageVariantsOfContentTypeWithComponentsQuery,
ListLanguageVariantsOfItemQuery,
ListLanguageVariantsBySpaceQuery,
ListSpacesQuery,
ListTaxonomiesQuery,
ListLegacyWebhooksQuery,
Expand Down Expand Up @@ -570,7 +571,7 @@ export interface IManagementClient<TCancelToken> {
/**
* Query to modify asset folders
*/
modifyAssetFolders(): DataQuery<ModifyAssetFoldersQuery, AssetFolderModels.IModifyAssetFoldersData[]>;
modifyAssetFolders(): DataQuery<ModifyAssetFoldersQuery, AssetFolderModels.IModifyAssetFolderData[]>;

/**
* Query to list collections
Expand All @@ -582,6 +583,11 @@ export interface IManagementClient<TCancelToken> {
*/
listLanguageVariantsByCollection(): CollectionIdentifierQuery<ListLanguageVariantsByCollectionQuery>;

/**
* Query to list language variants of given space
*/
listLanguageVariantsBySpace(): SpaceIdentifierQuery<ListLanguageVariantsBySpaceQuery>;

/**
* Query to set collections
*/
Expand Down
15 changes: 13 additions & 2 deletions lib/client/management-client.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {
ListLanguageVariantsOfContentTypeQuery,
ListLanguageVariantsOfContentTypeWithComponentsQuery,
ListLanguageVariantsOfItemQuery,
ListLanguageVariantsBySpaceQuery,
ListTaxonomiesQuery,
ListWebhooksQuery,
ListLegacyWebhooksQuery,
Expand Down Expand Up @@ -955,6 +956,16 @@ export class ManagementClient implements IManagementClient<CancelToken> {
);
}

listLanguageVariantsBySpace(): SpaceIdentifierQuery<ListLanguageVariantsBySpaceQuery> {
return new SpaceIdentifierQuery<ListLanguageVariantsBySpaceQuery>(
this.config,
this.queryService,
(config, queryService, identifier) =>
new ListLanguageVariantsBySpaceQuery(config, queryService, identifier)
);
}


listLanguageVariantsOfContentTypeWithComponents(): ContentTypeCodenameAndIdIdentifierQuery<ListLanguageVariantsOfContentTypeWithComponentsQuery> {
return new ContentTypeCodenameAndIdIdentifierQuery<ListLanguageVariantsOfContentTypeWithComponentsQuery>(
this.config,
Expand Down Expand Up @@ -1102,8 +1113,8 @@ export class ManagementClient implements IManagementClient<CancelToken> {
);
}

modifyAssetFolders(): DataQuery<ModifyAssetFoldersQuery, AssetFolderModels.IModifyAssetFoldersData[]> {
return new DataQuery<ModifyAssetFoldersQuery, AssetFolderModels.IModifyAssetFoldersData[]>(
modifyAssetFolders(): DataQuery<ModifyAssetFoldersQuery, AssetFolderModels.IModifyAssetFolderData[]> {
return new DataQuery<ModifyAssetFoldersQuery, AssetFolderModels.IModifyAssetFolderData[]>(
this.config,
this.queryService,
(config, queryService, data) => new ModifyAssetFoldersQuery(config, queryService, data)
Expand Down
5 changes: 5 additions & 0 deletions lib/contracts/language-variant-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export namespace LanguageVariantContracts {
pagination: SharedContracts.IPaginationModelContract;
}

export interface IListLanguageVariantsBySpaceResponseContract {
variants: ILanguageVariantModelContract[];
pagination: SharedContracts.IPaginationModelContract;
}

export interface IListLanguageVariantsOfContentTypeResponseContract {
variants: ILanguageVariantModelContract[];
pagination: SharedContracts.IPaginationModelContract;
Expand Down
2 changes: 2 additions & 0 deletions lib/contracts/space-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export namespace SpaceContracts {
name: string;
codename: string;
web_spotlight_root_item?: SharedContracts.IReferenceObjectContract;
collections?: SharedContracts.IReferenceObjectContract[];
}

export type ISpacesListingResponseContract = ISpaceContract[];
Expand All @@ -27,5 +28,6 @@ export namespace SpaceContracts {
name: string;
codename: string;
webSpotlightRootItem?: SharedContracts.IReferenceObjectContract;
collections?: SharedContracts.IReferenceObjectContract;
}
}
17 changes: 17 additions & 0 deletions lib/mappers/language-variant-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ export class LanguageVariantMapper extends BaseMapper {
);
}

mapLanguageVariantsBySpaceResponse(
response: IResponse<LanguageVariantContracts.IListLanguageVariantsBySpaceResponseContract>
): LanguageVariantResponses.ListLanguageVariantsBySpaceResponse {
const variants = response.data.variants.map((m) => this.mapLanguageVariant(m));
return new LanguageVariantResponses.ListLanguageVariantsBySpaceResponse(
super.mapResponseDebug(response),
response.data,
{
items: variants,
pagination: super.mapPagination(response.data.pagination)
}
);
}


mapLanguageVariantsOfContentTypeResponse(
response: IResponse<LanguageVariantContracts.IListLanguageVariantsOfContentTypeResponseContract>
): LanguageVariantResponses.ListLanguageVariantsOfContentTypeResponse {
Expand All @@ -70,6 +85,8 @@ export class LanguageVariantMapper extends BaseMapper {
);
}



mapLanguageVariantsOfContentTypeWithComponentsResponse(
response: IResponse<LanguageVariantContracts.IListLanguageVariantsOfContentTypeWithComponentsResponseContract>
): LanguageVariantResponses.ListLanguageVariantsOfContentTypeWithComponentsResponse {
Expand Down
1 change: 1 addition & 0 deletions lib/mappers/space-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class SpacesMapper extends BaseMapper {
id: rawItem.id,
name: rawItem.name,
webSpotlightRootItem: rawItem.web_spotlight_root_item,
collections: rawItem.collections,
_raw: rawItem
});
}
Expand Down
38 changes: 25 additions & 13 deletions lib/models/asset-folders/asset-folder.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { AssetFolderContracts } from '../../contracts';
import { SharedModels } from '../shared/shared-models';

export namespace AssetFolderModels {

export class AssetFolder implements SharedModels.IBaseModel<AssetFolderContracts.IAssetFolderContract> {
public id: string;
public name: string;
Expand All @@ -25,30 +24,43 @@ export namespace AssetFolderModels {
}
}

export interface IAddOrModifyAssetFolderData {
export interface IAssetFolderValue {
name: string;
folders: IAddOrModifyAssetFolderData[];
folders: IAssetFolderValue[];
external_id?: string;
}

export interface IAddAssetFoldersData {
folders: IAddOrModifyAssetFolderData[];
folders: IAssetFolderValue[];
}

export interface IModifyAssetFoldersData {
op: 'addInto' | 'remove' | 'rename';
value?: IAddOrModifyAssetFolderData;
after?: {
external_id?: string;
export type IModifyAssetFolderData = AddIntoOperation | RemoveOperation | RenameOperation;

export type AddIntoOperation = {
op: 'addInto';
reference?: {
id?: string;
external_id?: string;
};
value: IAssetFolderValue;
before?: {
external_id?: string;
id?: string;
};
reference?: {
external_id?: string;
};
after?: {
id?: string;
external_id?: string;
};
}
};

export type RemoveOperation = {
op: 'remove';
reference: SharedModels.ReferenceObject;
};

export type RenameOperation = {
op: 'rename';
reference: SharedModels.ReferenceObject;
value: string;
};
}
5 changes: 5 additions & 0 deletions lib/models/content-management-api-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ export class ContentManagementApiEndpoints {
listLanguageVariantsByCollection(identifier: Identifiers.CollectionIdentifier): string {
return `${this.getEnvironmentsPath()}/collections/${identifier.getParamValue()}/variants`;
}

listLanguageVariantsBySpace(identifier: Identifiers.SpaceIdentifier): string {
return `${this.getEnvironmentsPath()}/spaces/${identifier.getParamValue()}/variants`;
}


listLanguageVariantsOfContentTypeWithComponents(identifier: Identifiers.ContentTypeIdentifier): string {
return `${this.getEnvironmentsPath()}/types/${identifier.getParamValue()}/components`;
Expand Down
3 changes: 3 additions & 0 deletions lib/models/spaces/space.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@ export namespace SpaceModels {
name: string;
codename?: string;
web_spotlight_root_item?: SharedContracts.IReferenceObjectContract;
collections?: SharedContracts.IReferenceObjectContract[];
}

export class Space implements SharedModels.IBaseModel<SpaceContracts.ISpaceContract> {
public id!: string;
public name!: string;
public codename!: string;
public webSpotlightRootItem?: SharedModels.ReferenceObject;
public collections?: SharedModels.ReferenceObject[];
public _raw!: SpaceContracts.ISpaceContract;

constructor(data: {
id: string;
name: string;
codename: string;
webSpotlightRootItem?: SharedModels.ReferenceObject;
collections?: SharedModels.ReferenceObject[];
_raw: SpaceContracts.ISpaceContract;
}) {
Object.assign(this, data);
Expand Down
2 changes: 2 additions & 0 deletions lib/models/workflow/workflow.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export namespace WorkflowModels {
* If you do not provide this property, the specified language variant is published immediately.
*/
scheduled_to?: string;
display_timezone?: string;
}

export interface IUnpublishLanguageVarianthData {
Expand All @@ -66,6 +67,7 @@ export namespace WorkflowModels {
* If you do not provide this property, the specified language variant is published immediately.
*/
scheduled_to?: string;
display_timezone?: string;
}

export interface IChangeWorkflowOfLanguageVariantData {
Expand Down
2 changes: 1 addition & 1 deletion lib/queries/asset-folders/modify-asset-folders.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class ModifyAssetFoldersQuery extends BaseQuery<AssetFolderResponses.Modi
constructor(
protected config: IManagementClientConfig,
protected queryService: ManagementQueryService,
public data: AssetFolderModels.IModifyAssetFoldersData[]
public data: AssetFolderModels.IModifyAssetFolderData[]
) {
super(config, queryService);
}
Expand Down
1 change: 1 addition & 0 deletions lib/queries/language-variants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './upsert-language-variant-query.class';
export * from './view-language-variant-query.class';
export * from './delete-language-variant-query.class';
export * from './list-language-variants-by-collection-query.class';
export * from './list-language-variants-by-space-query.class';
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { IManagementClientConfig } from '../../config';
import { Identifiers } from '../../models';
import { LanguageVariantResponses } from '../../responses';
import { ManagementQueryService } from '../../services';
import { BaseListingQuery } from '../base-listing-query';

export class ListLanguageVariantsBySpaceQuery extends BaseListingQuery<
LanguageVariantResponses.ListLanguageVariantsBySpaceResponse,
LanguageVariantResponses.ListAllLanguageVariantsBySpaceResponse
> {
constructor(
protected config: IManagementClientConfig,
protected queryService: ManagementQueryService,
protected identifier: Identifiers.SpaceIdentifier
) {
super(config, queryService);
}

toPromise(): Promise<LanguageVariantResponses.ListLanguageVariantsBySpaceResponse> {
return this.queryService.listLanguageVariantsBySpaceAsync(this.getUrl(), this.queryConfig);
}

protected getAction(): string {
return this.apiEndpoints.listLanguageVariantsBySpace(this.identifier);
}

protected allResponseFactory(
items: any[],
responses: LanguageVariantResponses.ListLanguageVariantsBySpaceResponse[]
): LanguageVariantResponses.ListAllLanguageVariantsBySpaceResponse {
return new LanguageVariantResponses.ListAllLanguageVariantsBySpaceResponse({
items: items,
responses: responses
});
}
}
29 changes: 29 additions & 0 deletions lib/responses/language-variants/language-variant-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ export namespace LanguageVariantResponses {
}
}

export class ListLanguageVariantsBySpaceResponse extends BaseResponses.BaseContentManagementListResponse<
LanguageVariantContracts.IListLanguageVariantsBySpaceResponseContract,
LanguageVariantModels.ContentItemLanguageVariant
> {
constructor(
debug: BaseResponses.IContentManagementResponseDebug,
rawData: LanguageVariantContracts.IListLanguageVariantsBySpaceResponseContract,
data: {
items: LanguageVariantModels.ContentItemLanguageVariant[];
pagination: SharedModels.Pagination;
}
) {
super(debug, rawData, data);
}
}


export class ListAllLanguageVariantsOfContentTypeResponse extends BaseResponses.ContentManagementListAllResponse<ListLanguageVariantsOfContentTypeResponse, LanguageVariantModels.ContentItemLanguageVariant> {
constructor(
data: {
Expand All @@ -101,6 +118,18 @@ export namespace LanguageVariantResponses {
}
}

export class ListAllLanguageVariantsBySpaceResponse extends BaseResponses.ContentManagementListAllResponse<ListLanguageVariantsBySpaceResponse, LanguageVariantModels.ContentItemLanguageVariant> {
constructor(
data: {
items: LanguageVariantModels.ContentItemLanguageVariant[],
responses: ListLanguageVariantsBySpaceResponse[]
}
) {
super(data);
}
}


export class UpsertLanguageVariantResponse extends BaseResponses.BaseContentManagementResponse<
LanguageVariantContracts.IUpsertLanguageVariantResponseContract,
LanguageVariantModels.ContentItemLanguageVariant
Expand Down
20 changes: 18 additions & 2 deletions lib/services/management-query-service.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,23 @@ export class ManagementQueryService extends BaseManagementQueryService<any> {
config
)
);
}
}

async listLanguageVariantsBySpaceAsync(
url: string,
config: IContentManagementQueryConfig
): Promise<LanguageVariantResponses.ListLanguageVariantsBySpaceResponse> {
return languageVariantMapper.mapLanguageVariantsBySpaceResponse(
await this.getResponseAsync<LanguageVariantContracts.IListLanguageVariantsBySpaceResponseContract>(
url,
{},
config
)
);
}




async listLanguagesAsync(
url: string,
Expand Down Expand Up @@ -988,7 +1004,7 @@ export class ManagementQueryService extends BaseManagementQueryService<any> {
async modifyAssetFoldersAsync(
url: string,
config: IContentManagementQueryConfig,
data: AssetFolderModels.IModifyAssetFoldersData[]
data: AssetFolderModels.IModifyAssetFolderData[]
): Promise<AssetFolderResponses.ModifyAssetFoldersResponse> {
return assetFolderMapper.mapModifyAssetFoldersResponse(
await this.patchResponseAsync<AssetFolderContracts.IModifyAssetFoldersDataResponseContract>(
Expand Down
Loading
Loading