Started implementation of API client for ccm-core
parent
097412293f
commit
01444aa09e
|
|
@ -0,0 +1,11 @@
|
||||||
|
module.exports = {
|
||||||
|
root: true,
|
||||||
|
parser: '@typescript-eslint/parser',
|
||||||
|
plugins: [
|
||||||
|
'@typescript-eslint',
|
||||||
|
],
|
||||||
|
extends: [
|
||||||
|
'eslint:recommended',
|
||||||
|
'plugin:@typescript-eslint/recommended',
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
dist
|
||||||
|
node_modules
|
||||||
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
LibreCCM API Client Commons
|
||||||
|
===========================
|
||||||
|
|
||||||
|
This module provides basic classes for building clients for the RESTful APIs
|
||||||
|
provided by modules of LibreCCM. Details can be found in the documentation.
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,32 @@
|
||||||
|
{
|
||||||
|
"name": "@libreccm/ccm-apiclient-commons",
|
||||||
|
"version": "7.0.0",
|
||||||
|
"main": "target/dist/ccm-apiclient-commons.js",
|
||||||
|
"types": "dist/ccm-apiclient-commons.d.ts",
|
||||||
|
"description": "Client for the RESTful API provided by ccm-core.",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/libreccm/libreccm/ccm-apiclient-commons"
|
||||||
|
},
|
||||||
|
"author": "Jens Pelzetter",
|
||||||
|
"license": "GPL-3.0",
|
||||||
|
"scripts": {
|
||||||
|
"build": "tsc",
|
||||||
|
"check": "eslint",
|
||||||
|
"doc": "typedoc --out target/docs src/main/typescript"
|
||||||
|
},
|
||||||
|
"dependencies": {},
|
||||||
|
"devDependencies": {
|
||||||
|
"@typescript-eslint/eslint-plugin": "^3.6.0",
|
||||||
|
"@typescript-eslint/parser": "^3.6.0",
|
||||||
|
"eslint": "^7.4.0",
|
||||||
|
"typedoc": "^0.17.8",
|
||||||
|
"typescript": "^3.9.6"
|
||||||
|
},
|
||||||
|
"prettier": {
|
||||||
|
"trailingComma": "es5",
|
||||||
|
"tabWidth": 4,
|
||||||
|
"semi": true,
|
||||||
|
"singleQuote": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,105 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.libreccm</groupId>
|
||||||
|
<artifactId>libreccm-parent</artifactId>
|
||||||
|
<version>7.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<groupId>org.libreccm</groupId>
|
||||||
|
<artifactId>ccm-apiclient-commons</artifactId>
|
||||||
|
<version>7.0.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<name>LibreCCM API Client Commons</name>
|
||||||
|
<description>Provides basic classes and common datatypes for RESTful API clients</description>
|
||||||
|
<url>https://www.libreccm.org/ccm-apiclient-commons</url>
|
||||||
|
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>Lesser GPL 2.1</name>
|
||||||
|
<url>http://www.gnu.org/licenses/old-licenses/lgpl-2.1</url>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>ccm-apiclient-commons</finalName>
|
||||||
|
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/typescript</directory>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>${project.build.directory}/generated-resources</directory>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.github.eirslett</groupId>
|
||||||
|
<artifactId>frontend-maven-plugin</artifactId>
|
||||||
|
|
||||||
|
<configuration>
|
||||||
|
<installDirectory>../node</installDirectory>
|
||||||
|
</configuration>
|
||||||
|
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>Install node.js and NPM</id>
|
||||||
|
<goals>
|
||||||
|
<goal>install-node-and-npm</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<nodeVersion>v12.18.2</nodeVersion>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>npm install</id>
|
||||||
|
<goals>
|
||||||
|
<goal>npm</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<arguments>install</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>build</id>
|
||||||
|
<goals>
|
||||||
|
<goal>npm</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<arguments>run build</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
|
||||||
|
<execution>
|
||||||
|
<id>npm publish</id>
|
||||||
|
<goals>
|
||||||
|
<goal>npm</goal>
|
||||||
|
</goals>
|
||||||
|
|
||||||
|
<phase>deploy</phase>
|
||||||
|
|
||||||
|
<configuration>
|
||||||
|
<arguments>publish --userconfig ../libreccm.npmrc</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
export interface RequestInitProvider {
|
||||||
|
buildRequestInit(): RequestInit;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class EmbeddedRequestInitProvider implements RequestInitProvider {
|
||||||
|
buildRequestInit(): RequestInit {
|
||||||
|
return {
|
||||||
|
credentials: "include",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class RemoteRequestInitProvider implements RequestInitProvider {
|
||||||
|
#jwt: string;
|
||||||
|
|
||||||
|
constructor(jwt: string) {
|
||||||
|
this.#jwt = jwt;
|
||||||
|
}
|
||||||
|
|
||||||
|
buildRequestInit(): RequestInit {
|
||||||
|
return {
|
||||||
|
credentials: "omit",
|
||||||
|
headers: {
|
||||||
|
authorization: this.#jwt,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
export * from "./entities";
|
||||||
|
export * from "./RequestInitProvider";
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
export interface LocalizedString {
|
||||||
|
[language: string]: string;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "es6",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"outDir": "dist",
|
||||||
|
"declaration": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"strict": true,
|
||||||
|
"target": "es6"
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/main/typescript/**/*"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
module.exports = {
|
||||||
|
root: true,
|
||||||
|
parser: '@typescript-eslint/parser',
|
||||||
|
plugins: [
|
||||||
|
'@typescript-eslint',
|
||||||
|
],
|
||||||
|
extends: [
|
||||||
|
'eslint:recommended',
|
||||||
|
'plugin:@typescript-eslint/recommended',
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
dist
|
||||||
|
node_modules
|
||||||
|
target
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,33 @@
|
||||||
|
{
|
||||||
|
"name": "@libreccm/ccm-core-apiclient",
|
||||||
|
"version": "7.0.0",
|
||||||
|
"main": "target/dist/ccm-core-apiclient.js",
|
||||||
|
"types": "target/dist/ccm-core-apiclient.d.ts",
|
||||||
|
"description": "Client for the RESTful API provided by ccm-core.",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/libreccm/libreccm"
|
||||||
|
},
|
||||||
|
"author": "Jens Pelzetter",
|
||||||
|
"license": "GPL-3.0",
|
||||||
|
"scripts": {
|
||||||
|
"build": "tsc",
|
||||||
|
"doc": "typedoc --out target/docs src/main/typescript"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@libreccm/ccm-apiclient-commons": "file:../ccm-apiclient-commons"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@typescript-eslint/eslint-plugin": "^3.6.0",
|
||||||
|
"@typescript-eslint/parser": "^3.6.0",
|
||||||
|
"eslint": "^7.4.0",
|
||||||
|
"typedoc": "^0.17.8",
|
||||||
|
"typescript": "^3.9.6"
|
||||||
|
},
|
||||||
|
"prettier": {
|
||||||
|
"trailingComma": "es5",
|
||||||
|
"tabWidth": 4,
|
||||||
|
"semi": true,
|
||||||
|
"singleQuote": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,113 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.libreccm</groupId>
|
||||||
|
<artifactId>libreccm-parent</artifactId>
|
||||||
|
<version>7.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<groupId>org.libreccm</groupId>
|
||||||
|
<artifactId>ccm-core-apiclient</artifactId>
|
||||||
|
<version>7.0.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<name>LibreCCM RESTful Admin API Clients</name>
|
||||||
|
<url>https://www.libreccm.org/ccm-core/api</url>
|
||||||
|
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>Lesser GPL 2.1</name>
|
||||||
|
<url>http://www.gnu.org/licenses/old-licenses/lgpl-2.1</url>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>ccm-core-apiclient</finalName>
|
||||||
|
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/typescript</directory>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>${project.build.directory}/generated-resources</directory>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.github.eirslett</groupId>
|
||||||
|
<artifactId>frontend-maven-plugin</artifactId>
|
||||||
|
|
||||||
|
<configuration>
|
||||||
|
<installDirectory>../node</installDirectory>
|
||||||
|
</configuration>
|
||||||
|
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>Install node.js and NPM</id>
|
||||||
|
<goals>
|
||||||
|
<goal>install-node-and-npm</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<nodeVersion>v12.18.2</nodeVersion>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>npm install ../ccm-apiclient-commons</id>
|
||||||
|
<goals>
|
||||||
|
<goal>npm</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<arguments>install ../ccm-apiclient-commons</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>npm install</id>
|
||||||
|
<goals>
|
||||||
|
<goal>npm</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<arguments>install</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>build</id>
|
||||||
|
<goals>
|
||||||
|
<goal>npm</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<arguments>run build</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
|
||||||
|
<execution>
|
||||||
|
<id>npm publish</id>
|
||||||
|
<goals>
|
||||||
|
<goal>npm</goal>
|
||||||
|
</goals>
|
||||||
|
|
||||||
|
<phase>deploy</phase>
|
||||||
|
|
||||||
|
<configuration>
|
||||||
|
<arguments>publish --userconfig ../libreccm.npmrc</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
import { RequestInitProvider} from "@libreccm/ccm-apiclient-commons";
|
||||||
|
|
||||||
|
import { Category } from "./entities/categorization";
|
||||||
|
|
||||||
|
// interface RequestInitProvider {
|
||||||
|
// buildRequestInit(): RequestInit;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// export class CcmCoreAdminApiClient {
|
||||||
|
// libreCcmHost: string;
|
||||||
|
// jwt: string;
|
||||||
|
|
||||||
|
// constructor(libreCcmHost: string, jwt: string) {
|
||||||
|
// this.libreCcmHost = libreCcmHost;
|
||||||
|
// this.jwt = jwt;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// jwtRequired(): boolean {
|
||||||
|
// const documentUrl = new URL(document.documentURI);
|
||||||
|
// return documentUrl.host != this.libreCcmHost;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
export class CategorizationApiClient {
|
||||||
|
#requestInitProvider: RequestInitProvider;
|
||||||
|
|
||||||
|
constructor(requestInitProvider: RequestInitProvider) {
|
||||||
|
this.#requestInitProvider = requestInitProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getCategory(domain: string, path: string): Promise<Category> {
|
||||||
|
const fetchInit = this.#requestInitProvider.buildRequestInit();
|
||||||
|
fetchInit.method = "GET";
|
||||||
|
try {
|
||||||
|
const result = await fetch("localhost:8080", fetchInit);
|
||||||
|
if (result.ok) {
|
||||||
|
const category: Category = await result.json();
|
||||||
|
return category;
|
||||||
|
} else {
|
||||||
|
throw new Error(`Failed to get category ${path} of domain ${domain}: ${result.status} ${result.statusText}`);
|
||||||
|
}
|
||||||
|
} catch(err) {
|
||||||
|
throw new Error(`Failed to get category ${path} of domain ${domain}: ${err}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { LocalizedString } from "@libreccm/ccm-apiclient-commons";
|
||||||
|
|
||||||
|
export interface AssociatedCategory {
|
||||||
|
name: string;
|
||||||
|
title: LocalizedString;
|
||||||
|
description: LocalizedString;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Category {
|
||||||
|
categoryId: number;
|
||||||
|
uuid: string;
|
||||||
|
uniqueId: string;
|
||||||
|
name: string;
|
||||||
|
title: LocalizedString;
|
||||||
|
description: LocalizedString;
|
||||||
|
enabled: boolean;
|
||||||
|
abstractCategory: boolean;
|
||||||
|
parentCategory: AssociatedCategory;
|
||||||
|
categoryOrder: number;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "es6",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"outDir": "target/dist",
|
||||||
|
"declaration": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"strict": true,
|
||||||
|
"target": "es6"
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/main/typescript/**/*"
|
||||||
|
]
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue