Skip to content

Commit

Permalink
Added WIP Content and Finished Download modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierce01 committed Jul 3, 2023
1 parent 859cfe0 commit 594a193
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 86 deletions.
7 changes: 7 additions & 0 deletions src/lib/Client.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import { Elements } from "./utility/Global.js"
import { Hierarchy } from "./Hierarchy.js"
import { Profile } from "./Profile.js"
import { Content } from "./Content.js"
import { Download } from "./Download.js"

export class Client {
url: String
private token: String

hierarchy: Hierarchy
profile: Profile
content: Content
download: Download
constructor(url: String, token: String) {
this.url = url
this.token = token

this.hierarchy = new Hierarchy(this)
this.profile = new Profile(this)
this.content = new Content(this)
this.download = new Download(this)
}

async call(method: string, endpoint: string, options: any) {
Expand Down
26 changes: 26 additions & 0 deletions src/lib/Content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Client } from './Client.js'
import { ContentDTO } from './utility/Global.js'

export const ContentEndpoint = 'content'
export class Content {
private client: Client
constructor(client: Client) {
this.client = client
}

async getVersions(contentId: number, language: string): Promise<ContentDTO[]> {
const response = await this.client.call('GET', `${ContentEndpoint}/${contentId}/${language}/version`, null)
return response?.ok ? await response.json() : null
}

async get(contentId: number, language: string, sectionId: number): Promise<ContentDTO> {
const response = await this.client.call('GET', `${ContentEndpoint}/${sectionId}/${contentId}/${language}`, null)
return response?.ok ? await response.json() : null
}

async getWithoutSection(contentId: number, language: string, version?: string) {
if (!version) version = (await this.getVersions(contentId, language))[0].version
const response = await this.client.call('GET', `${ContentEndpoint}/${contentId}/${language}/version/${version}`, null)
return response?.ok ? await response.json() : null
}
}
22 changes: 22 additions & 0 deletions src/lib/Download.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Client } from "./Client"
import { FileDownload } from './utility/Global.js'


export const DownloadEndpoint = 'download'
export class Download {
private client: Client
constructor(client: Client) {
this.client = client
}

async getFileFromElement(element: string, contentId: number, language: string): Promise<FileDownload> {
const response = await this.client.call('GET', `${DownloadEndpoint}/${contentId}/${language}/${element}`, null)
return response?.ok ? await response.json() : null
}

async getFileFromElementVersion(element: string, contentId: number, language: string, version: number): Promise<FileDownload> {
const response = await this.client.call('GET', `${DownloadEndpoint}/${contentId}/${language}/${version}/${element}`, null)
return response?.ok ? await response.json() : null
}
}

69 changes: 6 additions & 63 deletions src/lib/Hierarchy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Client } from './Client.js';
import { Channels, ContentTypeScopes, MetaDatas, MetaData,
LinkInfo, AccessControl, sortLock, InheritedPageLayouts } from './utility/Global.js';
import { Client } from './Client.js'
import { SectionDTO } from './utility/Global.js'

export const HierarchyEndpoint = 'hierarchy'
export class Hierarchy {
Expand All @@ -14,65 +13,9 @@ export class Hierarchy {
return response?.ok ? await response.json() as SectionDTO : null
}

async delete(section:number | SectionDTO) {
async delete(section:number | SectionDTO, isMandatory?: boolean) {
const id = typeof section == 'number' ? section : section.id

const response = await this.client.call('DELETE', `${HierarchyEndpoint}/${id}${isMandatory ? '?mandatory=true' : ''}`, null)
return response?.ok
}

}

export interface SectionDTO {
id: string;
parent: string;
name: string;
description: string;
outputUrl: string;
outputFilename: string;
accessKey: string;
keyPhrase: string;
status: string;
workflow: string;
parentWorkflowName: string;
show: string;
iseForm: string;
archive: string;
lastModified: Date;
printSequence: string;
contentSortMethod: string;
sectionSortMethod: string;
path: string;
mirrorOf: string;
sourceOfMirror: string;
link: string;
channels: Channels;
userIDs: string;
inheritedUserIDs: string;
groupIDs: string;
inheritedGroupIDs: string;
viewUserIDs: string;
viewGroupIDs: string;
contentTypeScopes: ContentTypeScopes;
metaDatas: MetaDatas;
linkInfo: LinkInfo;
excludedMirrorSections: string;
workflowName: string;
parentWorkflowID: string;
accessControl: AccessControl;
metaData: MetaData;
pathMembers: string;
sortLock: sortLock;
editable: string;
inheritedLinkSection: string;
accessControlEnabled: string;
accessControlType: string;
metaDataType: string;
accessControlInherited: string;
allowedGroups: string;
mirrorOfPath: string;
inheritedPageLayouts: InheritedPageLayouts;
outputUriEnabled: string;
publishEnabled: string;
outputFilenameEnabled: string;
spellCheckEnabled: string;
pathAsOutputUriEnabled: string;
}
}
16 changes: 1 addition & 15 deletions src/lib/Profile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Client } from "./Client.js"
import { UserProfileView } from "./utility/Global.js"

export const ProfileEndpoint = 'profile'
export class Profile {
Expand All @@ -20,19 +21,4 @@ export class Profile {
})
return response?.ok ? await response.json() : false
}
}

export interface UserProfileView {
firstName: string;
lastName: string;
username: string;
emailAddress: string;
defaultLanguage: string;
oldPassword?: string;
newPassword?: string;
newPasswordConfirm?: string;
uiLocale: string;
htmlEditorId: string;
defaultPreviewChannelId: string;
userLevel: string;
}
Loading

0 comments on commit 594a193

Please sign in to comment.