@metarisc/metarisc-js 0.0.1-alpha.4 → 0.0.1-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core.d.ts +22 -0
- package/lib/core.js +41 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +5 -1
- package/lib/metarisc.d.ts +3 -18
- package/lib/metarisc.js +11 -34
- package/lib/oauth2.d.ts +13 -0
- package/lib/oauth2.js +14 -0
- package/package.json +1 -1
- package/src/core.ts +74 -0
- package/src/index.ts +3 -1
- package/src/metarisc.ts +12 -64
- package/src/oauth2.ts +20 -0
package/lib/core.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
|
+
interface RequestConfig {
|
|
3
|
+
body?: any;
|
|
4
|
+
headers?: {
|
|
5
|
+
[name: string]: string | string[];
|
|
6
|
+
};
|
|
7
|
+
params?: {
|
|
8
|
+
[param: string]: string | string[];
|
|
9
|
+
};
|
|
10
|
+
endpoint?: string;
|
|
11
|
+
method?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface MetariscConfig {
|
|
14
|
+
metarisc_url?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare class Core {
|
|
17
|
+
private axios;
|
|
18
|
+
constructor(config: MetariscConfig);
|
|
19
|
+
request<T>(config: RequestConfig): Promise<AxiosResponse<T>>;
|
|
20
|
+
autoPagingIterator<T>(config: RequestConfig): AsyncGenerator<T, void, unknown>;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
package/lib/core.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Core = void 0;
|
|
4
|
+
const axios_1 = require("axios");
|
|
5
|
+
const axios_retry_1 = require("axios-retry");
|
|
6
|
+
class Core {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.axios = axios_1.default.create({
|
|
9
|
+
baseURL: config.metarisc_url ?? 'https://api.metarisc.fr/'
|
|
10
|
+
});
|
|
11
|
+
// Axios interceptor : Retry strategy
|
|
12
|
+
(0, axios_retry_1.default)(this.axios, {
|
|
13
|
+
retries: 3,
|
|
14
|
+
retryDelay: axios_retry_1.default.exponentialDelay
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
async request(config) {
|
|
18
|
+
return this.axios.request({
|
|
19
|
+
method: config.method || 'GET',
|
|
20
|
+
url: config.endpoint || '/',
|
|
21
|
+
params: config.params,
|
|
22
|
+
data: config.body,
|
|
23
|
+
headers: config.headers
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async *autoPagingIterator(config) {
|
|
27
|
+
let current_page = config.params && 'page' in config.params ? parseInt(config.params['page'].toString()) : 1;
|
|
28
|
+
const per_page = config.params && 'per_page' in config.params ? parseInt(config.params['per_page'].toString()) : 25;
|
|
29
|
+
while (true) {
|
|
30
|
+
const response = await this.request({ ...config, ...{ params: { page: current_page.toString(), per_page: per_page.toString() } } });
|
|
31
|
+
for (const element of response.data.data) {
|
|
32
|
+
yield element;
|
|
33
|
+
}
|
|
34
|
+
if (response.data.meta.pagination.current_page === response.data.meta.pagination.total_pages) {
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
current_page++;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.Core = Core;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Metarisc = void 0;
|
|
3
|
+
exports.Core = exports.OAuth2 = exports.Metarisc = void 0;
|
|
4
4
|
var metarisc_1 = require("./metarisc");
|
|
5
5
|
Object.defineProperty(exports, "Metarisc", { enumerable: true, get: function () { return metarisc_1.Metarisc; } });
|
|
6
|
+
var oauth2_1 = require("./oauth2");
|
|
7
|
+
Object.defineProperty(exports, "OAuth2", { enumerable: true, get: function () { return oauth2_1.OAuth2; } });
|
|
8
|
+
var core_1 = require("./core");
|
|
9
|
+
Object.defineProperty(exports, "Core", { enumerable: true, get: function () { return core_1.Core; } });
|
package/lib/metarisc.d.ts
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
headers?: {
|
|
5
|
-
[name: string]: string | string[];
|
|
6
|
-
};
|
|
7
|
-
params?: {
|
|
8
|
-
[param: string]: string | string[];
|
|
9
|
-
};
|
|
10
|
-
endpoint?: string;
|
|
11
|
-
method?: string;
|
|
1
|
+
import { Core, MetariscConfig } from "./core";
|
|
2
|
+
export declare class Metarisc extends Core {
|
|
3
|
+
constructor(config: MetariscConfig);
|
|
12
4
|
}
|
|
13
|
-
export declare class Metarisc {
|
|
14
|
-
private axios;
|
|
15
|
-
constructor();
|
|
16
|
-
request<T>(config: RequestConfig): Promise<AxiosResponse<T>>;
|
|
17
|
-
autoPagingIterator<T>(config: RequestConfig): AsyncGenerator<T, void, unknown>;
|
|
18
|
-
}
|
|
19
|
-
export {};
|
package/lib/metarisc.js
CHANGED
|
@@ -1,41 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Metarisc = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
retryDelay: axios_retry_1.default.exponentialDelay
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
async request(config) {
|
|
18
|
-
return this.axios.request({
|
|
19
|
-
method: config.method || 'GET',
|
|
20
|
-
url: config.endpoint || '/',
|
|
21
|
-
params: config.params,
|
|
22
|
-
data: config.body,
|
|
23
|
-
headers: config.headers
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
async *autoPagingIterator(config) {
|
|
27
|
-
let current_page = config.params && 'page' in config.params ? parseInt(config.params['page'].toString()) : 1;
|
|
28
|
-
const per_page = config.params && 'per_page' in config.params ? parseInt(config.params['per_page'].toString()) : 25;
|
|
29
|
-
while (true) {
|
|
30
|
-
const response = await this.request({ ...config, ...{ params: { page: current_page.toString(), per_page: per_page.toString() } } });
|
|
31
|
-
for (const element of response.data.data) {
|
|
32
|
-
yield element;
|
|
33
|
-
}
|
|
34
|
-
if (response.data.meta.pagination.current_page === response.data.meta.pagination.total_pages) {
|
|
35
|
-
break;
|
|
4
|
+
const core_1 = require("./core");
|
|
5
|
+
class Metarisc extends core_1.Core {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
super(config);
|
|
8
|
+
return new Proxy(this, {
|
|
9
|
+
get: function (metarisc, name) {
|
|
10
|
+
switch (name) {
|
|
11
|
+
default:
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
36
14
|
}
|
|
37
|
-
|
|
38
|
-
}
|
|
15
|
+
});
|
|
39
16
|
}
|
|
40
17
|
}
|
|
41
18
|
exports.Metarisc = Metarisc;
|
package/lib/oauth2.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class OAuth2 {
|
|
2
|
+
/**
|
|
3
|
+
* OAuth2 Authorize URL Generator helper.
|
|
4
|
+
*/
|
|
5
|
+
authorizeUrl(options: {
|
|
6
|
+
response_type: string;
|
|
7
|
+
client_id: string;
|
|
8
|
+
redirect_uri?: string;
|
|
9
|
+
state?: string;
|
|
10
|
+
scope?: string;
|
|
11
|
+
[name: string]: string;
|
|
12
|
+
}): string;
|
|
13
|
+
}
|
package/lib/oauth2.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OAuth2 = void 0;
|
|
4
|
+
class OAuth2 {
|
|
5
|
+
/**
|
|
6
|
+
* OAuth2 Authorize URL Generator helper.
|
|
7
|
+
*/
|
|
8
|
+
authorizeUrl(options) {
|
|
9
|
+
const authorize_url = 'https://lemur-17.cloud-iam.com/auth/realms/metariscoidc/protocol/openid-connect/auth';
|
|
10
|
+
const params = new URLSearchParams(options);
|
|
11
|
+
return authorize_url + '?' + params.toString();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.OAuth2 = OAuth2;
|
package/package.json
CHANGED
package/src/core.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import axios, { AxiosInstance, AxiosResponse } from "axios";
|
|
2
|
+
import axiosRetry from 'axios-retry';
|
|
3
|
+
|
|
4
|
+
interface RequestConfig {
|
|
5
|
+
body ?: any,
|
|
6
|
+
headers ?: {[name: string]: string | string[]},
|
|
7
|
+
params ?: {[param: string]: string | string[]},
|
|
8
|
+
endpoint ?: string,
|
|
9
|
+
method ?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface MetariscConfig {
|
|
13
|
+
metarisc_url ?: string,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class Core
|
|
17
|
+
{
|
|
18
|
+
private axios : AxiosInstance;
|
|
19
|
+
|
|
20
|
+
constructor(config : MetariscConfig)
|
|
21
|
+
{
|
|
22
|
+
this.axios = axios.create({
|
|
23
|
+
baseURL: config.metarisc_url ?? 'https://api.metarisc.fr/'
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Axios interceptor : Retry strategy
|
|
27
|
+
axiosRetry(this.axios, {
|
|
28
|
+
retries: 3,
|
|
29
|
+
retryDelay: axiosRetry.exponentialDelay
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async request<T>(config : RequestConfig) : Promise<AxiosResponse<T>>
|
|
34
|
+
{
|
|
35
|
+
return this.axios.request<T>({
|
|
36
|
+
method: config.method || 'GET',
|
|
37
|
+
url: config.endpoint || '/',
|
|
38
|
+
params: config.params,
|
|
39
|
+
data: config.body,
|
|
40
|
+
headers: config.headers
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async * autoPagingIterator<T>(config : RequestConfig) : AsyncGenerator<T, void, unknown>
|
|
45
|
+
{
|
|
46
|
+
let current_page : number = config.params && 'page' in config.params ? parseInt(config.params['page'].toString()) : 1;
|
|
47
|
+
const per_page : number = config.params && 'per_page' in config.params ? parseInt(config.params['per_page'].toString()) : 25;
|
|
48
|
+
|
|
49
|
+
while (true) {
|
|
50
|
+
const response = <AxiosResponse<{
|
|
51
|
+
data?: Array<T>;
|
|
52
|
+
meta?: {
|
|
53
|
+
pagination?: {
|
|
54
|
+
total?: number;
|
|
55
|
+
count?: number;
|
|
56
|
+
per_page?: number;
|
|
57
|
+
current_page?: number;
|
|
58
|
+
total_pages?: number;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
}>> await this.request({...config, ...{params: {page: current_page.toString(), per_page: per_page.toString()}}});
|
|
62
|
+
|
|
63
|
+
for (const element of response.data.data) {
|
|
64
|
+
yield element;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (response.data.meta.pagination.current_page === response.data.meta.pagination.total_pages) {
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
current_page++;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
package/src/index.ts
CHANGED
package/src/metarisc.ts
CHANGED
|
@@ -1,70 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import axiosRetry from 'axios-retry';
|
|
1
|
+
import { Core, MetariscConfig } from "./core";
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
body ?: any,
|
|
6
|
-
headers ?: {[name: string]: string | string[]},
|
|
7
|
-
params ?: {[param: string]: string | string[]},
|
|
8
|
-
endpoint ?: string,
|
|
9
|
-
method ?: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class Metarisc
|
|
3
|
+
export class Metarisc extends Core
|
|
13
4
|
{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
constructor()
|
|
17
|
-
{
|
|
18
|
-
this.axios = axios.create({
|
|
19
|
-
baseURL: 'https://api.metarisc.fr/'
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
// Axios interceptor : Retry strategy
|
|
23
|
-
axiosRetry(this.axios, {
|
|
24
|
-
retries: 3,
|
|
25
|
-
retryDelay: axiosRetry.exponentialDelay
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async request<T>(config : RequestConfig) : Promise<AxiosResponse<T>>
|
|
30
|
-
{
|
|
31
|
-
return this.axios.request<T>({
|
|
32
|
-
method: config.method || 'GET',
|
|
33
|
-
url: config.endpoint || '/',
|
|
34
|
-
params: config.params,
|
|
35
|
-
data: config.body,
|
|
36
|
-
headers: config.headers
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async * autoPagingIterator<T>(config : RequestConfig) : AsyncGenerator<T, void, unknown>
|
|
5
|
+
constructor(config : MetariscConfig)
|
|
41
6
|
{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
total?: number;
|
|
51
|
-
count?: number;
|
|
52
|
-
per_page?: number;
|
|
53
|
-
current_page?: number;
|
|
54
|
-
total_pages?: number;
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
}>> await this.request({...config, ...{params: {page: current_page.toString(), per_page: per_page.toString()}}});
|
|
58
|
-
|
|
59
|
-
for (const element of response.data.data) {
|
|
60
|
-
yield element;
|
|
7
|
+
super(config);
|
|
8
|
+
|
|
9
|
+
return new Proxy(this, {
|
|
10
|
+
get: function(metarisc, name) {
|
|
11
|
+
switch(name) {
|
|
12
|
+
default:
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
61
15
|
}
|
|
62
|
-
|
|
63
|
-
if (response.data.meta.pagination.current_page === response.data.meta.pagination.total_pages) {
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
current_page++;
|
|
68
|
-
}
|
|
16
|
+
});
|
|
69
17
|
}
|
|
70
18
|
}
|
package/src/oauth2.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export class OAuth2
|
|
2
|
+
{
|
|
3
|
+
/**
|
|
4
|
+
* OAuth2 Authorize URL Generator helper.
|
|
5
|
+
*/
|
|
6
|
+
authorizeUrl(options : {
|
|
7
|
+
response_type : string,
|
|
8
|
+
client_id : string,
|
|
9
|
+
redirect_uri ?: string,
|
|
10
|
+
state ?: string,
|
|
11
|
+
scope ?: string,
|
|
12
|
+
[name: string]: string
|
|
13
|
+
}) : string
|
|
14
|
+
{
|
|
15
|
+
const authorize_url = 'https://lemur-17.cloud-iam.com/auth/realms/metariscoidc/protocol/openid-connect/auth';
|
|
16
|
+
const params = new URLSearchParams(options);
|
|
17
|
+
|
|
18
|
+
return authorize_url + '?' + params.toString();
|
|
19
|
+
}
|
|
20
|
+
}
|