build.gradle + generated SDK
This commit is contained in:
commit
2922250364
21 changed files with 1329 additions and 0 deletions
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
wwwroot/*.js
|
||||
node_modules
|
||||
typings
|
||||
dist
|
||||
.gradle
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "guichet"]
|
||||
path = guichet
|
||||
url = https://git.deuxfleurs.fr/deuxfleurs/guichet
|
1
.npmignore
Normal file
1
.npmignore
Normal file
|
@ -0,0 +1 @@
|
|||
README.md
|
26
.openapi-generator-ignore
Normal file
26
.openapi-generator-ignore
Normal file
|
@ -0,0 +1,26 @@
|
|||
# OpenAPI Generator Ignore
|
||||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
||||
|
||||
# Use this file to prevent files from being overwritten by the generator.
|
||||
# The patterns follow closely to .gitignore or .dockerignore.
|
||||
|
||||
# As an example, the C# client generator defines ApiClient.cs.
|
||||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
|
||||
#ApiClient.cs
|
||||
|
||||
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||
#foo/*/qux
|
||||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||
|
||||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||
#foo/**/qux
|
||||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||
|
||||
# You can also negate patterns with an exclamation (!).
|
||||
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||
#docs/*.md
|
||||
# Then explicitly reverse the ignore rule for a single file:
|
||||
#!docs/README.md
|
||||
|
||||
.gitignore
|
||||
build.gradle
|
16
.openapi-generator/FILES
Normal file
16
.openapi-generator/FILES
Normal file
|
@ -0,0 +1,16 @@
|
|||
.gitignore
|
||||
.npmignore
|
||||
.openapi-generator-ignore
|
||||
README.md
|
||||
package.json
|
||||
src/apis/WebsiteApi.ts
|
||||
src/apis/index.ts
|
||||
src/index.ts
|
||||
src/models/ConfigureWebsiteRequest.ts
|
||||
src/models/ListWebsites200Response.ts
|
||||
src/models/Quota.ts
|
||||
src/models/Vhost.ts
|
||||
src/models/WebsiteInfo.ts
|
||||
src/models/index.ts
|
||||
src/runtime.ts
|
||||
tsconfig.json
|
1
.openapi-generator/VERSION
Normal file
1
.openapi-generator/VERSION
Normal file
|
@ -0,0 +1 @@
|
|||
7.11.0
|
46
README.md
Normal file
46
README.md
Normal file
|
@ -0,0 +1,46 @@
|
|||
## guichet-sdk-ts@v0.1.0
|
||||
|
||||
This generator creates TypeScript/JavaScript client that utilizes [Fetch API](https://fetch.spec.whatwg.org/). The generated Node module can be used in the following environments:
|
||||
|
||||
Environment
|
||||
* Node.js
|
||||
* Webpack
|
||||
* Browserify
|
||||
|
||||
Language level
|
||||
* ES5 - you must have a Promises/A+ library installed
|
||||
* ES6
|
||||
|
||||
Module system
|
||||
* CommonJS
|
||||
* ES6 module system
|
||||
|
||||
It can be used in both TypeScript and JavaScript. In TypeScript, the definition will be automatically resolved via `package.json`. ([Reference](https://www.typescriptlang.org/docs/handbook/declaration-files/consumption.html))
|
||||
|
||||
### Building
|
||||
|
||||
To build and compile the typescript sources to javascript use:
|
||||
```
|
||||
npm install
|
||||
npm run build
|
||||
```
|
||||
|
||||
### Publishing
|
||||
|
||||
First build the package then run `npm publish`
|
||||
|
||||
### Consuming
|
||||
|
||||
navigate to the folder of your consuming project and run one of the following commands.
|
||||
|
||||
_published:_
|
||||
|
||||
```
|
||||
npm install guichet-sdk-ts@v0.1.0 --save
|
||||
```
|
||||
|
||||
_unPublished (not recommended):_
|
||||
|
||||
```
|
||||
npm install PATH_TO_GENERATED_PACKAGE --save
|
||||
```
|
22
build.gradle
Normal file
22
build.gradle
Normal file
|
@ -0,0 +1,22 @@
|
|||
plugins {
|
||||
id "org.openapi.generator" version "7.11.0"
|
||||
}
|
||||
|
||||
task validate(type: org.openapitools.generator.gradle.plugin.tasks.ValidateTask){
|
||||
inputSpec = "./guichet/openapi/guichet-api.yml"
|
||||
recommend = true
|
||||
}
|
||||
|
||||
task buildTypescriptClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
|
||||
generatorName = "typescript-fetch"
|
||||
inputSpec = "./guichet/openapi/guichet-api.yml"
|
||||
outputDir = "$rootDir"
|
||||
configOptions = [
|
||||
packageName: "guichet-sdk-ts",
|
||||
moduleName: "guichet",
|
||||
npmName: "guichet-sdk-ts",
|
||||
npmRepository: "@dxflrs/guichet-sdk-ts",
|
||||
packageVersion: "0.0.1",
|
||||
usePromises: "true",
|
||||
]
|
||||
}
|
1
guichet
Submodule
1
guichet
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 30a6a4695eb8d834fc1564d6ac668e122b1e843b
|
22
package.json
Normal file
22
package.json
Normal file
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "guichet-sdk-ts",
|
||||
"version": "v0.1.0",
|
||||
"description": "OpenAPI client for guichet-sdk-ts",
|
||||
"author": "OpenAPI-Generator",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/GIT_USER_ID/GIT_REPO_ID.git"
|
||||
},
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"prepare": "npm run build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^4.0 || ^5.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"registry": "@dxflrs/guichet-sdk-ts"
|
||||
}
|
||||
}
|
245
src/apis/WebsiteApi.ts
Normal file
245
src/apis/WebsiteApi.ts
Normal file
|
@ -0,0 +1,245 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Guichet API
|
||||
* Programmatic API for managing a user account in Deuxfleurs\' Guichet. *Disclaimer: this API is currently unstable and does not yet cover all the features availble from Guichet\'s web interface.*
|
||||
*
|
||||
* The version of the OpenAPI document: v0.1.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
import * as runtime from '../runtime';
|
||||
import type {
|
||||
ConfigureWebsiteRequest,
|
||||
ListWebsites200Response,
|
||||
WebsiteInfo,
|
||||
} from '../models/index';
|
||||
import {
|
||||
ConfigureWebsiteRequestFromJSON,
|
||||
ConfigureWebsiteRequestToJSON,
|
||||
ListWebsites200ResponseFromJSON,
|
||||
ListWebsites200ResponseToJSON,
|
||||
WebsiteInfoFromJSON,
|
||||
WebsiteInfoToJSON,
|
||||
} from '../models/index';
|
||||
|
||||
export interface ConfigureWebsiteOperationRequest {
|
||||
vhost: string;
|
||||
configureWebsiteRequest: ConfigureWebsiteRequest;
|
||||
}
|
||||
|
||||
export interface CreateWebsiteRequest {
|
||||
vhost: string;
|
||||
}
|
||||
|
||||
export interface DeleteWebsiteRequest {
|
||||
vhost: string;
|
||||
}
|
||||
|
||||
export interface GetWebsiteRequest {
|
||||
vhost: string;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
export class WebsiteApi extends runtime.BaseAPI {
|
||||
|
||||
/**
|
||||
* Modifies configuration of the website with identifier `vhost`.
|
||||
* Configure website
|
||||
*/
|
||||
async configureWebsiteRaw(requestParameters: ConfigureWebsiteOperationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<WebsiteInfo>> {
|
||||
if (requestParameters['vhost'] == null) {
|
||||
throw new runtime.RequiredError(
|
||||
'vhost',
|
||||
'Required parameter "vhost" was null or undefined when calling configureWebsite().'
|
||||
);
|
||||
}
|
||||
|
||||
if (requestParameters['configureWebsiteRequest'] == null) {
|
||||
throw new runtime.RequiredError(
|
||||
'configureWebsiteRequest',
|
||||
'Required parameter "configureWebsiteRequest" was null or undefined when calling configureWebsite().'
|
||||
);
|
||||
}
|
||||
|
||||
const queryParameters: any = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
headerParameters['Content-Type'] = 'application/json';
|
||||
|
||||
if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
|
||||
headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
|
||||
}
|
||||
const response = await this.request({
|
||||
path: `/website/{vhost}`.replace(`{${"vhost"}}`, encodeURIComponent(String(requestParameters['vhost']))),
|
||||
method: 'PATCH',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
body: ConfigureWebsiteRequestToJSON(requestParameters['configureWebsiteRequest']),
|
||||
}, initOverrides);
|
||||
|
||||
return new runtime.JSONApiResponse(response, (jsonValue) => WebsiteInfoFromJSON(jsonValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies configuration of the website with identifier `vhost`.
|
||||
* Configure website
|
||||
*/
|
||||
async configureWebsite(requestParameters: ConfigureWebsiteOperationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<WebsiteInfo> {
|
||||
const response = await this.configureWebsiteRaw(requestParameters, initOverrides);
|
||||
return await response.value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new website with identifier `vhost`.
|
||||
* Create a new website
|
||||
*/
|
||||
async createWebsiteRaw(requestParameters: CreateWebsiteRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<WebsiteInfo>> {
|
||||
if (requestParameters['vhost'] == null) {
|
||||
throw new runtime.RequiredError(
|
||||
'vhost',
|
||||
'Required parameter "vhost" was null or undefined when calling createWebsite().'
|
||||
);
|
||||
}
|
||||
|
||||
const queryParameters: any = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
|
||||
headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
|
||||
}
|
||||
const response = await this.request({
|
||||
path: `/website/{vhost}`.replace(`{${"vhost"}}`, encodeURIComponent(String(requestParameters['vhost']))),
|
||||
method: 'POST',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
}, initOverrides);
|
||||
|
||||
return new runtime.JSONApiResponse(response, (jsonValue) => WebsiteInfoFromJSON(jsonValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new website with identifier `vhost`.
|
||||
* Create a new website
|
||||
*/
|
||||
async createWebsite(requestParameters: CreateWebsiteRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<WebsiteInfo> {
|
||||
const response = await this.createWebsiteRaw(requestParameters, initOverrides);
|
||||
return await response.value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the website with identifier `vhost`.
|
||||
* Delete Website
|
||||
*/
|
||||
async deleteWebsiteRaw(requestParameters: DeleteWebsiteRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
|
||||
if (requestParameters['vhost'] == null) {
|
||||
throw new runtime.RequiredError(
|
||||
'vhost',
|
||||
'Required parameter "vhost" was null or undefined when calling deleteWebsite().'
|
||||
);
|
||||
}
|
||||
|
||||
const queryParameters: any = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
|
||||
headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
|
||||
}
|
||||
const response = await this.request({
|
||||
path: `/website/{vhost}`.replace(`{${"vhost"}}`, encodeURIComponent(String(requestParameters['vhost']))),
|
||||
method: 'DELETE',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
}, initOverrides);
|
||||
|
||||
return new runtime.VoidApiResponse(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the website with identifier `vhost`.
|
||||
* Delete Website
|
||||
*/
|
||||
async deleteWebsite(requestParameters: DeleteWebsiteRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
|
||||
await this.deleteWebsiteRaw(requestParameters, initOverrides);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the configuration and status for the website `vhost`. This includes information about domains, bucket access keys, and quotas. `quota_size` is given in bytes. `quota_files` indicates a number of files.
|
||||
* Details on a website
|
||||
*/
|
||||
async getWebsiteRaw(requestParameters: GetWebsiteRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<WebsiteInfo>> {
|
||||
if (requestParameters['vhost'] == null) {
|
||||
throw new runtime.RequiredError(
|
||||
'vhost',
|
||||
'Required parameter "vhost" was null or undefined when calling getWebsite().'
|
||||
);
|
||||
}
|
||||
|
||||
const queryParameters: any = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
|
||||
headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
|
||||
}
|
||||
const response = await this.request({
|
||||
path: `/website/{vhost}`.replace(`{${"vhost"}}`, encodeURIComponent(String(requestParameters['vhost']))),
|
||||
method: 'GET',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
}, initOverrides);
|
||||
|
||||
return new runtime.JSONApiResponse(response, (jsonValue) => WebsiteInfoFromJSON(jsonValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the configuration and status for the website `vhost`. This includes information about domains, bucket access keys, and quotas. `quota_size` is given in bytes. `quota_files` indicates a number of files.
|
||||
* Details on a website
|
||||
*/
|
||||
async getWebsite(requestParameters: GetWebsiteRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<WebsiteInfo> {
|
||||
const response = await this.getWebsiteRaw(requestParameters, initOverrides);
|
||||
return await response.value();
|
||||
}
|
||||
|
||||
/**
|
||||
* List all the user\'s websites
|
||||
* List all websites
|
||||
*/
|
||||
async listWebsitesRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ListWebsites200Response>> {
|
||||
const queryParameters: any = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
|
||||
if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
|
||||
headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
|
||||
}
|
||||
const response = await this.request({
|
||||
path: `/website`,
|
||||
method: 'GET',
|
||||
headers: headerParameters,
|
||||
query: queryParameters,
|
||||
}, initOverrides);
|
||||
|
||||
return new runtime.JSONApiResponse(response, (jsonValue) => ListWebsites200ResponseFromJSON(jsonValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* List all the user\'s websites
|
||||
* List all websites
|
||||
*/
|
||||
async listWebsites(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ListWebsites200Response> {
|
||||
const response = await this.listWebsitesRaw(initOverrides);
|
||||
return await response.value();
|
||||
}
|
||||
|
||||
}
|
3
src/apis/index.ts
Normal file
3
src/apis/index.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export * from './WebsiteApi';
|
5
src/index.ts
Normal file
5
src/index.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export * from './runtime';
|
||||
export * from './apis/index';
|
||||
export * from './models/index';
|
81
src/models/ConfigureWebsiteRequest.ts
Normal file
81
src/models/ConfigureWebsiteRequest.ts
Normal file
|
@ -0,0 +1,81 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Guichet API
|
||||
* Programmatic API for managing a user account in Deuxfleurs\' Guichet. *Disclaimer: this API is currently unstable and does not yet cover all the features availble from Guichet\'s web interface.*
|
||||
*
|
||||
* The version of the OpenAPI document: v0.1.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import { mapValues } from '../runtime';
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @interface ConfigureWebsiteRequest
|
||||
*/
|
||||
export interface ConfigureWebsiteRequest {
|
||||
/**
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof ConfigureWebsiteRequest
|
||||
*/
|
||||
quotaSize?: number | null;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof ConfigureWebsiteRequest
|
||||
*/
|
||||
vhost?: string | null;
|
||||
/**
|
||||
*
|
||||
* @type {boolean}
|
||||
* @memberof ConfigureWebsiteRequest
|
||||
*/
|
||||
rotateKey?: boolean | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given object implements the ConfigureWebsiteRequest interface.
|
||||
*/
|
||||
export function instanceOfConfigureWebsiteRequest(value: object): value is ConfigureWebsiteRequest {
|
||||
return true;
|
||||
}
|
||||
|
||||
export function ConfigureWebsiteRequestFromJSON(json: any): ConfigureWebsiteRequest {
|
||||
return ConfigureWebsiteRequestFromJSONTyped(json, false);
|
||||
}
|
||||
|
||||
export function ConfigureWebsiteRequestFromJSONTyped(json: any, ignoreDiscriminator: boolean): ConfigureWebsiteRequest {
|
||||
if (json == null) {
|
||||
return json;
|
||||
}
|
||||
return {
|
||||
|
||||
'quotaSize': json['quota_size'] == null ? undefined : json['quota_size'],
|
||||
'vhost': json['vhost'] == null ? undefined : json['vhost'],
|
||||
'rotateKey': json['rotate_key'] == null ? undefined : json['rotate_key'],
|
||||
};
|
||||
}
|
||||
|
||||
export function ConfigureWebsiteRequestToJSON(json: any): ConfigureWebsiteRequest {
|
||||
return ConfigureWebsiteRequestToJSONTyped(json, false);
|
||||
}
|
||||
|
||||
export function ConfigureWebsiteRequestToJSONTyped(value?: ConfigureWebsiteRequest | null, ignoreDiscriminator: boolean = false): any {
|
||||
if (value == null) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
'quota_size': value['quotaSize'],
|
||||
'vhost': value['vhost'],
|
||||
'rotate_key': value['rotateKey'],
|
||||
};
|
||||
}
|
||||
|
104
src/models/ListWebsites200Response.ts
Normal file
104
src/models/ListWebsites200Response.ts
Normal file
|
@ -0,0 +1,104 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Guichet API
|
||||
* Programmatic API for managing a user account in Deuxfleurs\' Guichet. *Disclaimer: this API is currently unstable and does not yet cover all the features availble from Guichet\'s web interface.*
|
||||
*
|
||||
* The version of the OpenAPI document: v0.1.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import { mapValues } from '../runtime';
|
||||
import type { Vhost } from './Vhost';
|
||||
import {
|
||||
VhostFromJSON,
|
||||
VhostFromJSONTyped,
|
||||
VhostToJSON,
|
||||
VhostToJSONTyped,
|
||||
} from './Vhost';
|
||||
import type { Quota } from './Quota';
|
||||
import {
|
||||
QuotaFromJSON,
|
||||
QuotaFromJSONTyped,
|
||||
QuotaToJSON,
|
||||
QuotaToJSONTyped,
|
||||
} from './Quota';
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @interface ListWebsites200Response
|
||||
*/
|
||||
export interface ListWebsites200Response {
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof ListWebsites200Response
|
||||
*/
|
||||
username?: string;
|
||||
/**
|
||||
*
|
||||
* @type {Quota}
|
||||
* @memberof ListWebsites200Response
|
||||
*/
|
||||
quotaWebsiteCount?: Quota;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof ListWebsites200Response
|
||||
*/
|
||||
burstBucketQuotaSize?: string;
|
||||
/**
|
||||
*
|
||||
* @type {Array<Vhost>}
|
||||
* @memberof ListWebsites200Response
|
||||
*/
|
||||
vhosts?: Array<Vhost>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given object implements the ListWebsites200Response interface.
|
||||
*/
|
||||
export function instanceOfListWebsites200Response(value: object): value is ListWebsites200Response {
|
||||
return true;
|
||||
}
|
||||
|
||||
export function ListWebsites200ResponseFromJSON(json: any): ListWebsites200Response {
|
||||
return ListWebsites200ResponseFromJSONTyped(json, false);
|
||||
}
|
||||
|
||||
export function ListWebsites200ResponseFromJSONTyped(json: any, ignoreDiscriminator: boolean): ListWebsites200Response {
|
||||
if (json == null) {
|
||||
return json;
|
||||
}
|
||||
return {
|
||||
|
||||
'username': json['username'] == null ? undefined : json['username'],
|
||||
'quotaWebsiteCount': json['quota_website_count'] == null ? undefined : QuotaFromJSON(json['quota_website_count']),
|
||||
'burstBucketQuotaSize': json['burst_bucket_quota_size'] == null ? undefined : json['burst_bucket_quota_size'],
|
||||
'vhosts': json['vhosts'] == null ? undefined : ((json['vhosts'] as Array<any>).map(VhostFromJSON)),
|
||||
};
|
||||
}
|
||||
|
||||
export function ListWebsites200ResponseToJSON(json: any): ListWebsites200Response {
|
||||
return ListWebsites200ResponseToJSONTyped(json, false);
|
||||
}
|
||||
|
||||
export function ListWebsites200ResponseToJSONTyped(value?: ListWebsites200Response | null, ignoreDiscriminator: boolean = false): any {
|
||||
if (value == null) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
'username': value['username'],
|
||||
'quota_website_count': QuotaToJSON(value['quotaWebsiteCount']),
|
||||
'burst_bucket_quota_size': value['burstBucketQuotaSize'],
|
||||
'vhosts': value['vhosts'] == null ? undefined : ((value['vhosts'] as Array<any>).map(VhostToJSON)),
|
||||
};
|
||||
}
|
||||
|
89
src/models/Quota.ts
Normal file
89
src/models/Quota.ts
Normal file
|
@ -0,0 +1,89 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Guichet API
|
||||
* Programmatic API for managing a user account in Deuxfleurs\' Guichet. *Disclaimer: this API is currently unstable and does not yet cover all the features availble from Guichet\'s web interface.*
|
||||
*
|
||||
* The version of the OpenAPI document: v0.1.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import { mapValues } from '../runtime';
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @interface Quota
|
||||
*/
|
||||
export interface Quota {
|
||||
/**
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof Quota
|
||||
*/
|
||||
current?: number;
|
||||
/**
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof Quota
|
||||
*/
|
||||
max?: number;
|
||||
/**
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof Quota
|
||||
*/
|
||||
ratio?: number;
|
||||
/**
|
||||
*
|
||||
* @type {boolean}
|
||||
* @memberof Quota
|
||||
*/
|
||||
burstable?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given object implements the Quota interface.
|
||||
*/
|
||||
export function instanceOfQuota(value: object): value is Quota {
|
||||
return true;
|
||||
}
|
||||
|
||||
export function QuotaFromJSON(json: any): Quota {
|
||||
return QuotaFromJSONTyped(json, false);
|
||||
}
|
||||
|
||||
export function QuotaFromJSONTyped(json: any, ignoreDiscriminator: boolean): Quota {
|
||||
if (json == null) {
|
||||
return json;
|
||||
}
|
||||
return {
|
||||
|
||||
'current': json['current'] == null ? undefined : json['current'],
|
||||
'max': json['max'] == null ? undefined : json['max'],
|
||||
'ratio': json['ratio'] == null ? undefined : json['ratio'],
|
||||
'burstable': json['burstable'] == null ? undefined : json['burstable'],
|
||||
};
|
||||
}
|
||||
|
||||
export function QuotaToJSON(json: any): Quota {
|
||||
return QuotaToJSONTyped(json, false);
|
||||
}
|
||||
|
||||
export function QuotaToJSONTyped(value?: Quota | null, ignoreDiscriminator: boolean = false): any {
|
||||
if (value == null) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
'current': value['current'],
|
||||
'max': value['max'],
|
||||
'ratio': value['ratio'],
|
||||
'burstable': value['burstable'],
|
||||
};
|
||||
}
|
||||
|
89
src/models/Vhost.ts
Normal file
89
src/models/Vhost.ts
Normal file
|
@ -0,0 +1,89 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Guichet API
|
||||
* Programmatic API for managing a user account in Deuxfleurs\' Guichet. *Disclaimer: this API is currently unstable and does not yet cover all the features availble from Guichet\'s web interface.*
|
||||
*
|
||||
* The version of the OpenAPI document: v0.1.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import { mapValues } from '../runtime';
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @interface Vhost
|
||||
*/
|
||||
export interface Vhost {
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Vhost
|
||||
*/
|
||||
name?: string;
|
||||
/**
|
||||
*
|
||||
* @type {Array<string>}
|
||||
* @memberof Vhost
|
||||
*/
|
||||
altName?: Array<string>;
|
||||
/**
|
||||
*
|
||||
* @type {boolean}
|
||||
* @memberof Vhost
|
||||
*/
|
||||
expanded?: boolean;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Vhost
|
||||
*/
|
||||
domain?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given object implements the Vhost interface.
|
||||
*/
|
||||
export function instanceOfVhost(value: object): value is Vhost {
|
||||
return true;
|
||||
}
|
||||
|
||||
export function VhostFromJSON(json: any): Vhost {
|
||||
return VhostFromJSONTyped(json, false);
|
||||
}
|
||||
|
||||
export function VhostFromJSONTyped(json: any, ignoreDiscriminator: boolean): Vhost {
|
||||
if (json == null) {
|
||||
return json;
|
||||
}
|
||||
return {
|
||||
|
||||
'name': json['name'] == null ? undefined : json['name'],
|
||||
'altName': json['alt_name'] == null ? undefined : json['alt_name'],
|
||||
'expanded': json['expanded'] == null ? undefined : json['expanded'],
|
||||
'domain': json['domain'] == null ? undefined : json['domain'],
|
||||
};
|
||||
}
|
||||
|
||||
export function VhostToJSON(json: any): Vhost {
|
||||
return VhostToJSONTyped(json, false);
|
||||
}
|
||||
|
||||
export function VhostToJSONTyped(value?: Vhost | null, ignoreDiscriminator: boolean = false): any {
|
||||
if (value == null) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
'name': value['name'],
|
||||
'alt_name': value['altName'],
|
||||
'expanded': value['expanded'],
|
||||
'domain': value['domain'],
|
||||
};
|
||||
}
|
||||
|
112
src/models/WebsiteInfo.ts
Normal file
112
src/models/WebsiteInfo.ts
Normal file
|
@ -0,0 +1,112 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Guichet API
|
||||
* Programmatic API for managing a user account in Deuxfleurs\' Guichet. *Disclaimer: this API is currently unstable and does not yet cover all the features availble from Guichet\'s web interface.*
|
||||
*
|
||||
* The version of the OpenAPI document: v0.1.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import { mapValues } from '../runtime';
|
||||
import type { Vhost } from './Vhost';
|
||||
import {
|
||||
VhostFromJSON,
|
||||
VhostFromJSONTyped,
|
||||
VhostToJSON,
|
||||
VhostToJSONTyped,
|
||||
} from './Vhost';
|
||||
import type { Quota } from './Quota';
|
||||
import {
|
||||
QuotaFromJSON,
|
||||
QuotaFromJSONTyped,
|
||||
QuotaToJSON,
|
||||
QuotaToJSONTyped,
|
||||
} from './Quota';
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @interface WebsiteInfo
|
||||
*/
|
||||
export interface WebsiteInfo {
|
||||
/**
|
||||
*
|
||||
* @type {Vhost}
|
||||
* @memberof WebsiteInfo
|
||||
*/
|
||||
vhost?: Vhost;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof WebsiteInfo
|
||||
*/
|
||||
accessKeyId?: string;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof WebsiteInfo
|
||||
*/
|
||||
secretAccessKey?: string;
|
||||
/**
|
||||
*
|
||||
* @type {Quota}
|
||||
* @memberof WebsiteInfo
|
||||
*/
|
||||
quotaSize?: Quota;
|
||||
/**
|
||||
*
|
||||
* @type {Quota}
|
||||
* @memberof WebsiteInfo
|
||||
*/
|
||||
quotaFiles?: Quota;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given object implements the WebsiteInfo interface.
|
||||
*/
|
||||
export function instanceOfWebsiteInfo(value: object): value is WebsiteInfo {
|
||||
return true;
|
||||
}
|
||||
|
||||
export function WebsiteInfoFromJSON(json: any): WebsiteInfo {
|
||||
return WebsiteInfoFromJSONTyped(json, false);
|
||||
}
|
||||
|
||||
export function WebsiteInfoFromJSONTyped(json: any, ignoreDiscriminator: boolean): WebsiteInfo {
|
||||
if (json == null) {
|
||||
return json;
|
||||
}
|
||||
return {
|
||||
|
||||
'vhost': json['vhost'] == null ? undefined : VhostFromJSON(json['vhost']),
|
||||
'accessKeyId': json['access_key_id'] == null ? undefined : json['access_key_id'],
|
||||
'secretAccessKey': json['secret_access_key'] == null ? undefined : json['secret_access_key'],
|
||||
'quotaSize': json['quota_size'] == null ? undefined : QuotaFromJSON(json['quota_size']),
|
||||
'quotaFiles': json['quota_files'] == null ? undefined : QuotaFromJSON(json['quota_files']),
|
||||
};
|
||||
}
|
||||
|
||||
export function WebsiteInfoToJSON(json: any): WebsiteInfo {
|
||||
return WebsiteInfoToJSONTyped(json, false);
|
||||
}
|
||||
|
||||
export function WebsiteInfoToJSONTyped(value?: WebsiteInfo | null, ignoreDiscriminator: boolean = false): any {
|
||||
if (value == null) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
'vhost': VhostToJSON(value['vhost']),
|
||||
'access_key_id': value['accessKeyId'],
|
||||
'secret_access_key': value['secretAccessKey'],
|
||||
'quota_size': QuotaToJSON(value['quotaSize']),
|
||||
'quota_files': QuotaToJSON(value['quotaFiles']),
|
||||
};
|
||||
}
|
||||
|
7
src/models/index.ts
Normal file
7
src/models/index.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export * from './ConfigureWebsiteRequest';
|
||||
export * from './ListWebsites200Response';
|
||||
export * from './Quota';
|
||||
export * from './Vhost';
|
||||
export * from './WebsiteInfo';
|
431
src/runtime.ts
Normal file
431
src/runtime.ts
Normal file
|
@ -0,0 +1,431 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Guichet API
|
||||
* Programmatic API for managing a user account in Deuxfleurs\' Guichet. *Disclaimer: this API is currently unstable and does not yet cover all the features availble from Guichet\'s web interface.*
|
||||
*
|
||||
* The version of the OpenAPI document: v0.1.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
export const BASE_PATH = "https://guichet.deuxfleurs.fr/api/unstable".replace(/\/+$/, "");
|
||||
|
||||
export interface ConfigurationParameters {
|
||||
basePath?: string; // override base path
|
||||
fetchApi?: FetchAPI; // override for fetch implementation
|
||||
middleware?: Middleware[]; // middleware to apply before/after fetch requests
|
||||
queryParamsStringify?: (params: HTTPQuery) => string; // stringify function for query strings
|
||||
username?: string; // parameter for basic security
|
||||
password?: string; // parameter for basic security
|
||||
apiKey?: string | Promise<string> | ((name: string) => string | Promise<string>); // parameter for apiKey security
|
||||
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string | Promise<string>); // parameter for oauth2 security
|
||||
headers?: HTTPHeaders; //header params we want to use on every request
|
||||
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
|
||||
}
|
||||
|
||||
export class Configuration {
|
||||
constructor(private configuration: ConfigurationParameters = {}) {}
|
||||
|
||||
set config(configuration: Configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
get basePath(): string {
|
||||
return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH;
|
||||
}
|
||||
|
||||
get fetchApi(): FetchAPI | undefined {
|
||||
return this.configuration.fetchApi;
|
||||
}
|
||||
|
||||
get middleware(): Middleware[] {
|
||||
return this.configuration.middleware || [];
|
||||
}
|
||||
|
||||
get queryParamsStringify(): (params: HTTPQuery) => string {
|
||||
return this.configuration.queryParamsStringify || querystring;
|
||||
}
|
||||
|
||||
get username(): string | undefined {
|
||||
return this.configuration.username;
|
||||
}
|
||||
|
||||
get password(): string | undefined {
|
||||
return this.configuration.password;
|
||||
}
|
||||
|
||||
get apiKey(): ((name: string) => string | Promise<string>) | undefined {
|
||||
const apiKey = this.configuration.apiKey;
|
||||
if (apiKey) {
|
||||
return typeof apiKey === 'function' ? apiKey : () => apiKey;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
get accessToken(): ((name?: string, scopes?: string[]) => string | Promise<string>) | undefined {
|
||||
const accessToken = this.configuration.accessToken;
|
||||
if (accessToken) {
|
||||
return typeof accessToken === 'function' ? accessToken : async () => accessToken;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
get headers(): HTTPHeaders | undefined {
|
||||
return this.configuration.headers;
|
||||
}
|
||||
|
||||
get credentials(): RequestCredentials | undefined {
|
||||
return this.configuration.credentials;
|
||||
}
|
||||
}
|
||||
|
||||
export const DefaultConfig = new Configuration();
|
||||
|
||||
/**
|
||||
* This is the base class for all generated API classes.
|
||||
*/
|
||||
export class BaseAPI {
|
||||
|
||||
private static readonly jsonRegex = new RegExp('^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$', 'i');
|
||||
private middleware: Middleware[];
|
||||
|
||||
constructor(protected configuration = DefaultConfig) {
|
||||
this.middleware = configuration.middleware;
|
||||
}
|
||||
|
||||
withMiddleware<T extends BaseAPI>(this: T, ...middlewares: Middleware[]) {
|
||||
const next = this.clone<T>();
|
||||
next.middleware = next.middleware.concat(...middlewares);
|
||||
return next;
|
||||
}
|
||||
|
||||
withPreMiddleware<T extends BaseAPI>(this: T, ...preMiddlewares: Array<Middleware['pre']>) {
|
||||
const middlewares = preMiddlewares.map((pre) => ({ pre }));
|
||||
return this.withMiddleware<T>(...middlewares);
|
||||
}
|
||||
|
||||
withPostMiddleware<T extends BaseAPI>(this: T, ...postMiddlewares: Array<Middleware['post']>) {
|
||||
const middlewares = postMiddlewares.map((post) => ({ post }));
|
||||
return this.withMiddleware<T>(...middlewares);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given MIME is a JSON MIME.
|
||||
* JSON MIME examples:
|
||||
* application/json
|
||||
* application/json; charset=UTF8
|
||||
* APPLICATION/JSON
|
||||
* application/vnd.company+json
|
||||
* @param mime - MIME (Multipurpose Internet Mail Extensions)
|
||||
* @return True if the given MIME is JSON, false otherwise.
|
||||
*/
|
||||
protected isJsonMime(mime: string | null | undefined): boolean {
|
||||
if (!mime) {
|
||||
return false;
|
||||
}
|
||||
return BaseAPI.jsonRegex.test(mime);
|
||||
}
|
||||
|
||||
protected async request(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction): Promise<Response> {
|
||||
const { url, init } = await this.createFetchParams(context, initOverrides);
|
||||
const response = await this.fetchApi(url, init);
|
||||
if (response && (response.status >= 200 && response.status < 300)) {
|
||||
return response;
|
||||
}
|
||||
throw new ResponseError(response, 'Response returned an error code');
|
||||
}
|
||||
|
||||
private async createFetchParams(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction) {
|
||||
let url = this.configuration.basePath + context.path;
|
||||
if (context.query !== undefined && Object.keys(context.query).length !== 0) {
|
||||
// only add the querystring to the URL if there are query parameters.
|
||||
// this is done to avoid urls ending with a "?" character which buggy webservers
|
||||
// do not handle correctly sometimes.
|
||||
url += '?' + this.configuration.queryParamsStringify(context.query);
|
||||
}
|
||||
|
||||
const headers = Object.assign({}, this.configuration.headers, context.headers);
|
||||
Object.keys(headers).forEach(key => headers[key] === undefined ? delete headers[key] : {});
|
||||
|
||||
const initOverrideFn =
|
||||
typeof initOverrides === "function"
|
||||
? initOverrides
|
||||
: async () => initOverrides;
|
||||
|
||||
const initParams = {
|
||||
method: context.method,
|
||||
headers,
|
||||
body: context.body,
|
||||
credentials: this.configuration.credentials,
|
||||
};
|
||||
|
||||
const overriddenInit: RequestInit = {
|
||||
...initParams,
|
||||
...(await initOverrideFn({
|
||||
init: initParams,
|
||||
context,
|
||||
}))
|
||||
};
|
||||
|
||||
let body: any;
|
||||
if (isFormData(overriddenInit.body)
|
||||
|| (overriddenInit.body instanceof URLSearchParams)
|
||||
|| isBlob(overriddenInit.body)) {
|
||||
body = overriddenInit.body;
|
||||
} else if (this.isJsonMime(headers['Content-Type'])) {
|
||||
body = JSON.stringify(overriddenInit.body);
|
||||
} else {
|
||||
body = overriddenInit.body;
|
||||
}
|
||||
|
||||
const init: RequestInit = {
|
||||
...overriddenInit,
|
||||
body
|
||||
};
|
||||
|
||||
return { url, init };
|
||||
}
|
||||
|
||||
private fetchApi = async (url: string, init: RequestInit) => {
|
||||
let fetchParams = { url, init };
|
||||
for (const middleware of this.middleware) {
|
||||
if (middleware.pre) {
|
||||
fetchParams = await middleware.pre({
|
||||
fetch: this.fetchApi,
|
||||
...fetchParams,
|
||||
}) || fetchParams;
|
||||
}
|
||||
}
|
||||
let response: Response | undefined = undefined;
|
||||
try {
|
||||
response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init);
|
||||
} catch (e) {
|
||||
for (const middleware of this.middleware) {
|
||||
if (middleware.onError) {
|
||||
response = await middleware.onError({
|
||||
fetch: this.fetchApi,
|
||||
url: fetchParams.url,
|
||||
init: fetchParams.init,
|
||||
error: e,
|
||||
response: response ? response.clone() : undefined,
|
||||
}) || response;
|
||||
}
|
||||
}
|
||||
if (response === undefined) {
|
||||
if (e instanceof Error) {
|
||||
throw new FetchError(e, 'The request failed and the interceptors did not return an alternative response');
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const middleware of this.middleware) {
|
||||
if (middleware.post) {
|
||||
response = await middleware.post({
|
||||
fetch: this.fetchApi,
|
||||
url: fetchParams.url,
|
||||
init: fetchParams.init,
|
||||
response: response.clone(),
|
||||
}) || response;
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a shallow clone of `this` by constructing a new instance
|
||||
* and then shallow cloning data members.
|
||||
*/
|
||||
private clone<T extends BaseAPI>(this: T): T {
|
||||
const constructor = this.constructor as any;
|
||||
const next = new constructor(this.configuration);
|
||||
next.middleware = this.middleware.slice();
|
||||
return next;
|
||||
}
|
||||
};
|
||||
|
||||
function isBlob(value: any): value is Blob {
|
||||
return typeof Blob !== 'undefined' && value instanceof Blob;
|
||||
}
|
||||
|
||||
function isFormData(value: any): value is FormData {
|
||||
return typeof FormData !== "undefined" && value instanceof FormData;
|
||||
}
|
||||
|
||||
export class ResponseError extends Error {
|
||||
override name: "ResponseError" = "ResponseError";
|
||||
constructor(public response: Response, msg?: string) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
|
||||
export class FetchError extends Error {
|
||||
override name: "FetchError" = "FetchError";
|
||||
constructor(public cause: Error, msg?: string) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
|
||||
export class RequiredError extends Error {
|
||||
override name: "RequiredError" = "RequiredError";
|
||||
constructor(public field: string, msg?: string) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
|
||||
export const COLLECTION_FORMATS = {
|
||||
csv: ",",
|
||||
ssv: " ",
|
||||
tsv: "\t",
|
||||
pipes: "|",
|
||||
};
|
||||
|
||||
export type FetchAPI = WindowOrWorkerGlobalScope['fetch'];
|
||||
|
||||
export type Json = any;
|
||||
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
||||
export type HTTPHeaders = { [key: string]: string };
|
||||
export type HTTPQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery };
|
||||
export type HTTPBody = Json | FormData | URLSearchParams;
|
||||
export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody };
|
||||
export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original';
|
||||
|
||||
export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise<RequestInit>
|
||||
|
||||
export interface FetchParams {
|
||||
url: string;
|
||||
init: RequestInit;
|
||||
}
|
||||
|
||||
export interface RequestOpts {
|
||||
path: string;
|
||||
method: HTTPMethod;
|
||||
headers: HTTPHeaders;
|
||||
query?: HTTPQuery;
|
||||
body?: HTTPBody;
|
||||
}
|
||||
|
||||
export function querystring(params: HTTPQuery, prefix: string = ''): string {
|
||||
return Object.keys(params)
|
||||
.map(key => querystringSingleKey(key, params[key], prefix))
|
||||
.filter(part => part.length > 0)
|
||||
.join('&');
|
||||
}
|
||||
|
||||
function querystringSingleKey(key: string, value: string | number | null | undefined | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery, keyPrefix: string = ''): string {
|
||||
const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key);
|
||||
if (value instanceof Array) {
|
||||
const multiValue = value.map(singleValue => encodeURIComponent(String(singleValue)))
|
||||
.join(`&${encodeURIComponent(fullKey)}=`);
|
||||
return `${encodeURIComponent(fullKey)}=${multiValue}`;
|
||||
}
|
||||
if (value instanceof Set) {
|
||||
const valueAsArray = Array.from(value);
|
||||
return querystringSingleKey(key, valueAsArray, keyPrefix);
|
||||
}
|
||||
if (value instanceof Date) {
|
||||
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`;
|
||||
}
|
||||
if (value instanceof Object) {
|
||||
return querystring(value as HTTPQuery, fullKey);
|
||||
}
|
||||
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
|
||||
}
|
||||
|
||||
export function exists(json: any, key: string) {
|
||||
const value = json[key];
|
||||
return value !== null && value !== undefined;
|
||||
}
|
||||
|
||||
export function mapValues(data: any, fn: (item: any) => any) {
|
||||
return Object.keys(data).reduce(
|
||||
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
|
||||
{}
|
||||
);
|
||||
}
|
||||
|
||||
export function canConsumeForm(consumes: Consume[]): boolean {
|
||||
for (const consume of consumes) {
|
||||
if ('multipart/form-data' === consume.contentType) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export interface Consume {
|
||||
contentType: string;
|
||||
}
|
||||
|
||||
export interface RequestContext {
|
||||
fetch: FetchAPI;
|
||||
url: string;
|
||||
init: RequestInit;
|
||||
}
|
||||
|
||||
export interface ResponseContext {
|
||||
fetch: FetchAPI;
|
||||
url: string;
|
||||
init: RequestInit;
|
||||
response: Response;
|
||||
}
|
||||
|
||||
export interface ErrorContext {
|
||||
fetch: FetchAPI;
|
||||
url: string;
|
||||
init: RequestInit;
|
||||
error: unknown;
|
||||
response?: Response;
|
||||
}
|
||||
|
||||
export interface Middleware {
|
||||
pre?(context: RequestContext): Promise<FetchParams | void>;
|
||||
post?(context: ResponseContext): Promise<Response | void>;
|
||||
onError?(context: ErrorContext): Promise<Response | void>;
|
||||
}
|
||||
|
||||
export interface ApiResponse<T> {
|
||||
raw: Response;
|
||||
value(): Promise<T>;
|
||||
}
|
||||
|
||||
export interface ResponseTransformer<T> {
|
||||
(json: any): T;
|
||||
}
|
||||
|
||||
export class JSONApiResponse<T> {
|
||||
constructor(public raw: Response, private transformer: ResponseTransformer<T> = (jsonValue: any) => jsonValue) {}
|
||||
|
||||
async value(): Promise<T> {
|
||||
return this.transformer(await this.raw.json());
|
||||
}
|
||||
}
|
||||
|
||||
export class VoidApiResponse {
|
||||
constructor(public raw: Response) {}
|
||||
|
||||
async value(): Promise<void> {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export class BlobApiResponse {
|
||||
constructor(public raw: Response) {}
|
||||
|
||||
async value(): Promise<Blob> {
|
||||
return await this.raw.blob();
|
||||
};
|
||||
}
|
||||
|
||||
export class TextApiResponse {
|
||||
constructor(public raw: Response) {}
|
||||
|
||||
async value(): Promise<string> {
|
||||
return await this.raw.text();
|
||||
};
|
||||
}
|
20
tsconfig.json
Normal file
20
tsconfig.json
Normal file
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "dist",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"typeRoots": [
|
||||
"node_modules/@types"
|
||||
]
|
||||
},
|
||||
"exclude": [
|
||||
"dist",
|
||||
"node_modules"
|
||||
]
|
||||
}
|
Loading…
Add table
Reference in a new issue