Skip to content

Commit

Permalink
refactor for v3
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscdn committed May 1, 2024
1 parent 20d8c20 commit 72e025e
Show file tree
Hide file tree
Showing 41 changed files with 717 additions and 75 deletions.
36 changes: 31 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
Expand Down Expand Up @@ -41,8 +42,8 @@ build/Release
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo
Expand All @@ -53,6 +54,9 @@ typings/
# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
Expand All @@ -68,29 +72,41 @@ typings/
# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
# dotenv environment variable files
.env
.env.test
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

Expand All @@ -102,3 +118,13 @@ dist

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
20 changes: 5 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,21 @@ Simple authentication and REST calls for OpenText Content Server.
Using npm:

```bash
$ npm install @kweli/cs-rest
npm install @kweli/cs-rest
```

Using yarn:

```bash
$ yarn add @kweli/cs-rest
```

Using unpkg CDN:

```html
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/@kweli/cs-rest"></script>
yarn add @kweli/cs-rest
```

## Example

Authenticate with a username and password and get the details of a node:

```js
const { Session } = require("@kweli/cs-rest");
import { Session } from "@kweli/cs-rest";

// session wraps an axios instance
const session = new Session({
Expand Down Expand Up @@ -100,7 +92,7 @@ The underlying `axios` instance is available if these methods don't suffice:
const axios = session.axios;
```

#### Thin Wrapper
#### Convenience Wrapper

The `Session` class provides a few convenience methods for performing commonly used REST requests. By no means is this complete, and it's possible the API will change in the future.

Expand All @@ -119,11 +111,9 @@ A method also exists for uploading a document, where `file` is either:
const response = await session.nodes.addDocument(2000, file);
```

See the `src/` directory for more examples.

## Credits

- [OpenText Content Server REST API](https://developer.opentext.com/webaccess/#url=%2Fawd%2Fresources%2Fapis%2Fcs-rest-api-for-cs-16-s&tab=501)
- [OpenText Content Server REST API](https://developer.opentext.com/ce/products/extended-ecm/apis/content-server-233-rest-api)
- [Kwe.li GmbH](https://kwe.li/)

## License
Expand Down
55 changes: 55 additions & 0 deletions lib/Session.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { DataTypesEnum } from "./utils/data-types-enum";
import { CSRestOptions } from "./utils/axios-factory";
import Auth from "./handlers/auth";
import Nodes from "./handlers/nodes";
import Workflow from "./handlers/workflow";
import RHCore from "./handlers/rhcore";
import Search from "./handlers/search";
import Members from "./handlers/members";
import Versions from "./handlers/versions";
import WebReports from "./handlers/webreports";
import RPCClient from "./rpc-client/index";
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
export default class Session {
protected readonly axios: AxiosInstance;
protected _nodes: Nodes;
protected _auth: Auth;
protected _workflow: any;
protected _rhcore: RHCore;
protected _members: Members;
protected _search: Search;
protected _webreports: WebReports;
protected _versions: Versions;
readonly baseUrl: string;
constructor(options: CSRestOptions);
get nodes(): Nodes;
get auth(): Auth;
get workflow(): Workflow;
get rhcore(): RHCore;
get members(): Members;
get search(): Search;
get webreports(): WebReports;
get versions(): Versions;
get dataTypesEnum(): typeof DataTypesEnum;
rpcClient(relativePath?: string): RPCClient;
_isObject(value: unknown): value is Object;
_isString(value: unknown): value is string;
_isBoolean(value: unknown): value is boolean;
_isFile(value: any): value is File;
objectToForm(obj: Record<string, any>): any;
putForm(url: any, params: any): Promise<AxiosResponse<any, any>>;
postForm(url: any, params: any): Promise<AxiosResponse<any, any>>;
patchForm(url: any, params: any): Promise<AxiosResponse<any, any>>;
deleteForm(url: any, params: any): Promise<AxiosResponse<any, any>>;
putBody(url: any, body: any): Promise<AxiosResponse<any, any>>;
postBody(url: any, body: any): Promise<AxiosResponse<any, any>>;
patchBody(url: any, body: any): Promise<AxiosResponse<any, any>>;
deleteBody(url: any, body: any): Promise<AxiosResponse<any, any>>;
get<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
post<T = any, R = AxiosResponse<T>>(url: string, data?: T, config?: AxiosRequestConfig): Promise<R>;
put<T = any, R = AxiosResponse<T>>(url: string, data?: T, config?: AxiosRequestConfig): Promise<R>;
patch<T = any, R = AxiosResponse<T>>(url: string, data?: T, config?: AxiosRequestConfig): Promise<R>;
options<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
delete<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
$get<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
}
2 changes: 2 additions & 0 deletions lib/cs-rest.cjs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/cs-rest.cjs.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/cs-rest.esm.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/cs-rest.esm.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/cs-rest.modern.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/cs-rest.modern.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions lib/handlers/auth.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import ServiceAbstract from "./service-abstract";
declare class Auth extends ServiceAbstract {
auth(): Promise<import("axios").AxiosResponse<any, any>>;
}
export default Auth;
10 changes: 10 additions & 0 deletions lib/handlers/members.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Session from "../Session";
import ServiceAbstract from "./service-abstract";
declare class Members extends ServiceAbstract {
readonly USER: number;
readonly GROUP: number;
constructor(session: Session);
userQuery(query: any, options?: {}, version?: string): Promise<import("axios").AxiosResponse<any, any>>;
member(id: any, version?: string): Promise<import("axios").AxiosResponse<any, any>>;
}
export default Members;
43 changes: 43 additions & 0 deletions lib/handlers/nodes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import ServiceAbstract from "./service-abstract";
declare class Nodes extends ServiceAbstract {
addablenodetypes(dataid: any): Promise<import("axios").AxiosResponse<any, any>>;
addDocument({ parent_id, fileHandler, apiVersion, name, options, }: {
parent_id: number;
fileHandler: File | string;
apiVersion?: "v1" | "v2";
name?: string;
options?: Record<string, any>;
}): Promise<import("axios").AxiosResponse<any, any>>;
addDocumentMajor({ parent_id, fileHandler, name, description, options, }: {
parent_id: number;
fileHandler: File | string;
name?: string;
description?: string;
options: Record<string, any>;
}): Promise<import("axios").AxiosResponse<any, any>>;
addItem(type: any, parent_id: any, name: any, params?: {}): Promise<import("axios").AxiosResponse<any, any>>;
node({ dataid, apiVersion, params }: {
dataid: any;
apiVersion?: string;
params?: {};
}): Promise<import("axios").AxiosResponse<any, any>>;
ancestors(dataid: any, params?: {}): Promise<import("axios").AxiosResponse<any, any>>;
volumeInfo(objType: any): Promise<import("axios").AxiosResponse<any, any>>;
volumes(): Promise<import("axios").AxiosResponse<any, any>>;
addFolder(parent_id: any, name: any, params?: {}): Promise<import("axios").AxiosResponse<any, any>>;
addGeneration(parent_id: any, name: any, original_id: any, version_number: any, params?: {}): Promise<import("axios").AxiosResponse<any, any>>;
nodes(dataid: any, params?: {}): Promise<import("axios").AxiosResponse<any, any>>;
children(dataid: any, params?: {}): Promise<import("axios").AxiosResponse<any, any>>;
delete(dataid: any): Promise<import("axios").AxiosResponse<any, any>>;
download({ dataid, apiVersion, filePath }: {
dataid: any;
apiVersion?: string;
filePath: any;
}): Promise<unknown>;
audit({ dataid, apiVersion, params }: {
dataid: any;
apiVersion?: string;
params?: {};
}): Promise<import("axios").AxiosResponse<any, any>>;
}
export default Nodes;
5 changes: 5 additions & 0 deletions lib/handlers/rhcore.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import ServiceAbstract from "./service-abstract";
declare class RHCore extends ServiceAbstract {
scriptNode(id: any, body?: {}): Promise<import("axios").AxiosResponse<any, any>>;
}
export default RHCore;
6 changes: 6 additions & 0 deletions lib/handlers/search.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import ServiceAbstract from "./service-abstract";
declare class Search extends ServiceAbstract {
search(where: any, params?: {}): Promise<import("axios").AxiosResponse<any, any>>;
regions(params?: {}): Promise<import("axios").AxiosResponse<any, any>>;
}
export default Search;
7 changes: 7 additions & 0 deletions lib/handlers/service-abstract.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type Session from "../Session";
declare class ServiceAbstract {
protected _session: Session;
constructor(session: Session);
get session(): Session;
}
export default ServiceAbstract;
32 changes: 32 additions & 0 deletions lib/handlers/versions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import ServiceAbstract from "./service-abstract";
declare class Versions extends ServiceAbstract {
addVersion({ dataid, fileHandler, apiVersion, fileName, options, }: {
dataid: number;
fileHandler: File | string;
apiVersion?: "v1" | "v2";
fileName?: string;
options?: Record<string, any>;
}): Promise<import("axios").AxiosResponse<any, any>>;
download({ dataid, version, filePath }: {
dataid: any;
version: any;
filePath: any;
}): Promise<unknown>;
list(dataid: number): Promise<import("axios").AxiosResponse<any, any>>;
version(dataid: any, version_number?: string): Promise<import("axios").AxiosResponse<any, any>>;
promote({ dataid, versionNumber, description }: {
dataid: any;
versionNumber: any;
description?: any;
}): Promise<import("axios").AxiosResponse<any, any>>;
deleteVersion({ dataid, versionNumber, apiVersion }: {
dataid: any;
versionNumber: any;
apiVersion?: string;
}): Promise<import("axios").AxiosResponse<any, any>>;
purge({ dataid, number_to_keep }: {
dataid: any;
number_to_keep?: number;
}): Promise<import("axios").AxiosResponse<any, any>>;
}
export default Versions;
5 changes: 5 additions & 0 deletions lib/handlers/webreports.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import ServiceAbstract from "./service-abstract";
declare class WebReports extends ServiceAbstract {
run(dataid: any, params?: {}): Promise<import("axios").AxiosResponse<any, any>>;
}
export default WebReports;
15 changes: 15 additions & 0 deletions lib/handlers/workflow.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import ServiceAbstract from "./service-abstract";
import { components } from "../types/cs-rest-types/schema";
type forms_WorkflowPropertiesFormInfo = components["schemas"]["forms_WorkflowPropertiesFormInfo"];
type draftprocesses_DraftProcess_Put = components["schemas"]["draftprocesses_DraftProcess_Put"];
import { TDraftProcess, TWorkflowPut, WorkflowInitiator } from "../utils/workflow-initiator";
declare class Workflow extends ServiceAbstract {
workflowInitiator(mapId: number): WorkflowInitiator;
start(mapId: number): Promise<forms_WorkflowPropertiesFormInfo>;
draftprocesses(workflowId: number): Promise<TDraftProcess>;
draftprocessesUpdate(draftprocessId: number): Promise<forms_WorkflowPropertiesFormInfo>;
draftprocessesPut(draftprocessId: number, body: TWorkflowPut): Promise<{
results: draftprocesses_DraftProcess_Put;
}>;
}
export default Workflow;
5 changes: 5 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import RPCClient from "./rpc-client";
import { RPCError } from "./rpc-client/error-codes";
import Session from "./Session";
declare const isRPCError: (e: RPCError | any) => e is RPCError;
export { isRPCError, RPCError, Session, RPCClient };
33 changes: 33 additions & 0 deletions lib/rpc-client/error-codes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
declare const ErrorCodes: {
readonly PARSEERROR: {
readonly code: -32700;
readonly message: "Parse error";
};
readonly INVALIDREQUEST: {
readonly code: -32600;
readonly message: "Invalid Request";
};
readonly METHODNOTFOUND: {
readonly code: -32601;
readonly message: "Method not found";
};
readonly INVALIDPARAMS: {
readonly code: -32602;
readonly message: "Invalid params";
};
readonly INTERNALERROR: {
readonly code: -32603;
readonly message: "Internal error";
};
};
type ErrorMessage = {
message: string;
code: number;
data: Array<any> | Record<string, any>;
};
declare class RPCError extends Error {
code: number;
data: Array<any> | Record<string, any>;
constructor(message?: string | ErrorMessage, data?: any, code?: number);
}
export { RPCError, ErrorCodes };
22 changes: 22 additions & 0 deletions lib/rpc-client/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Session from "../Session";
type requestObjectType = {
jsonrpc: string;
method: string;
id: number;
params: Record<string, any> | Array<any>;
};
export default class RPCClient {
session: Session;
relativePath: string;
_batchQueue: Array<requestObjectType>;
constructor(session: Session, relativePath: string);
requestObject(method: string, params: Record<string, any> | Array<any>, id: number): requestObjectType;
handleResponse(data: any): any;
request(method: string, params: any, id?: number): Promise<any>;
resetQueue(): void;
queue(method: string, params: any, id?: number): RPCClient;
batch(throwOnError?: boolean): Promise<any>;
rhnode(dataid: any, method: any, args?: any[], id?: number): Promise<any>;
rhnodeQueue(dataid: any, method: any, args?: any[], id?: number): RPCClient;
}
export {};
Loading

0 comments on commit 72e025e

Please sign in to comment.