-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Upload (Client, Profile, Hierarchy)
- Loading branch information
Showing
10 changed files
with
434 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/cjs | ||
/esm |
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,5 @@ | ||
# T4.ts | ||
A TypeScript wrapper for TerminalFour's REST API | ||
|
||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,23 @@ | ||
{ | ||
"name": "t4ts", | ||
"version": "0.0.1", | ||
"description": "A simple terminalfour web api wrapper.", | ||
"type": "module", | ||
"exports": { | ||
"require": "./cjs/index.js", | ||
"import": "./esm/index.js", | ||
"default": "./esm/index.js" | ||
}, | ||
"typesVersions": { | ||
"*": { | ||
"index.d.ts": ["./esm/index.d.ts"] | ||
} | ||
}, | ||
"main": "./cjs/index.js", | ||
"dependencies": { | ||
"node-fetch": "^3.3.1" | ||
}, | ||
"scripts": { | ||
"build": "npx tsc --module es2022 --outDir esm/ && npx tsc --module commonjs --outDir cjs/" | ||
} | ||
} |
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 @@ | ||
export { Client } from './lib/Client.js' |
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,52 @@ | ||
import { Elements } from "./utility/Global.js" | ||
import { Hierarchy } from "./Hierarchy.js" | ||
import { Profile } from "./Profile.js" | ||
|
||
export class Client { | ||
url: String | ||
private token: String | ||
hierarchy: Hierarchy | ||
profile: Profile | ||
constructor(url: String, token: String) { | ||
this.url = url | ||
this.token = token | ||
|
||
this.hierarchy = new Hierarchy(this) | ||
this.profile = new Profile(this) | ||
} | ||
|
||
async call(method: string, endpoint: string, options: any) { | ||
if (!this.token) throw Error('Token not specified') | ||
try { | ||
let headers: Elements = { | ||
'authorization': `Bearer ${this.token}`, | ||
'accept': 'application/json, text/javascript, */*; q=0.01', | ||
'accept-language': 'en-US,en;q=0.9' | ||
} | ||
if (options?.body && typeof options.body == 'object') { | ||
options.body = JSON.stringify(options.body) | ||
headers['content-type'] = 'application/json' | ||
} | ||
const request = await fetch(`${this.url}/${endpoint}`, { | ||
...options, | ||
headers, | ||
method, | ||
}) | ||
return request | ||
} catch (error) { | ||
throw Error(`Request failed due to:\n${error}`) | ||
} | ||
} | ||
|
||
setToken(token: string) { | ||
this.token = token | ||
} | ||
|
||
setURL(url: string) { | ||
this.url = url | ||
} | ||
|
||
verify() { | ||
// Check if client can make requests | ||
} | ||
} |
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,78 @@ | ||
import { Client } from './Client.js'; | ||
import { Channels, ContentTypeScopes, MetaDatas, MetaData, | ||
LinkInfo, AccessControl, sortLock, InheritedPageLayouts } from './utility/Global.js'; | ||
|
||
export const HierarchyEndpoint = 'hierarchy' | ||
export class Hierarchy { | ||
private client: Client; | ||
constructor(client: Client) { | ||
this.client = client | ||
} | ||
|
||
async get(id: number, language: string) { | ||
const response = await this.client.call('GET', `${HierarchyEndpoint}/${id}/${language}`, null) | ||
return response?.ok ? await response.json() as SectionDTO : null | ||
} | ||
|
||
async delete(section:number | SectionDTO) { | ||
const id = typeof section == 'number' ? section : section.id | ||
|
||
} | ||
|
||
} | ||
|
||
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; | ||
} |
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,38 @@ | ||
import { Client } from "./Client.js" | ||
|
||
export const ProfileEndpoint = 'profile' | ||
export class Profile { | ||
private client: Client | ||
constructor(client: Client) { | ||
this.client = client | ||
} | ||
|
||
async get() { | ||
const response = await this.client.call('GET', ProfileEndpoint, null) | ||
return response?.ok ? await response.json() : null | ||
} | ||
|
||
async update(body: Partial<UserProfileView>) { | ||
const currentProfile = await this.get() | ||
if (!currentProfile) throw Error('Failed to get client profile') | ||
const response = await this.client.call('POST', ProfileEndpoint, { | ||
body: Object.assign(currentProfile, body), | ||
}) | ||
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; | ||
} |
Oops, something went wrong.