@hahnpro/hpc-api 3.6.7 → 3.7.1
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/dist/asset.interface.d.ts +2 -7
- package/dist/asset.service.d.ts +2 -1
- package/dist/asset.service.js +3 -0
- package/dist/http.service.d.ts +1 -1
- package/dist/http.service.js +3 -4
- package/dist/mock/asset.mock.service.d.ts +2 -1
- package/dist/mock/asset.mock.service.js +5 -0
- package/dist/token-set.d.ts +6 -5
- package/dist/token-set.js +12 -8
- package/package.json +3 -3
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Content } from './content.interface';
|
|
1
2
|
export interface AssetType {
|
|
2
3
|
id?: string;
|
|
3
4
|
name: string;
|
|
@@ -44,13 +45,7 @@ export interface Asset {
|
|
|
44
45
|
export type AssetRevision = Asset & {
|
|
45
46
|
originalId: string;
|
|
46
47
|
};
|
|
47
|
-
export
|
|
48
|
-
id?: string;
|
|
49
|
-
filename: string;
|
|
50
|
-
metadata: {
|
|
51
|
-
mimetype: string;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
48
|
+
export type Attachment = Content;
|
|
54
49
|
export interface Action {
|
|
55
50
|
id?: string;
|
|
56
51
|
name?: string;
|
package/dist/asset.service.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import FormData from 'form-data';
|
|
2
2
|
import { APIBase } from './api-base';
|
|
3
|
-
import { Asset, AssetRevision } from './asset.interface';
|
|
3
|
+
import { Asset, AssetRevision, Attachment } from './asset.interface';
|
|
4
4
|
import { Paginated, RequestParameter } from './data.interface';
|
|
5
5
|
import { DataService } from './data.service';
|
|
6
6
|
import { HttpClient } from './http.service';
|
|
@@ -14,6 +14,7 @@ export declare class AssetService extends BaseService {
|
|
|
14
14
|
deleteOne(id: string, force?: boolean): Promise<any>;
|
|
15
15
|
addAttachment: (id: string, form: FormData) => Promise<Asset>;
|
|
16
16
|
getChildren(assetId: string, params?: RequestParameter): Promise<Paginated<Asset[]>>;
|
|
17
|
+
getAttachments(assetId: string): Promise<Paginated<Attachment[]>>;
|
|
17
18
|
getRevisions(assetId: string): Promise<Paginated<AssetRevision[]>>;
|
|
18
19
|
rollback(assetId: string, revisionId: string): Promise<Asset>;
|
|
19
20
|
deleteRevision(assetId: string, revisionId: string): Promise<any>;
|
package/dist/asset.service.js
CHANGED
|
@@ -29,6 +29,9 @@ class AssetService extends BaseService {
|
|
|
29
29
|
getChildren(assetId, params = {}) {
|
|
30
30
|
return this.getManyFiltered({ parent: assetId }, params);
|
|
31
31
|
}
|
|
32
|
+
getAttachments(assetId) {
|
|
33
|
+
return this.httpClient.get(`${this.basePath}/${assetId}/attachments`);
|
|
34
|
+
}
|
|
32
35
|
getRevisions(assetId) {
|
|
33
36
|
return this.httpClient.get(`${this.basePath}/${assetId}/revisions`);
|
|
34
37
|
}
|
package/dist/http.service.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export declare class HttpClient {
|
|
|
30
30
|
addEventSource(url: string, listener: (event: MessageEvent) => void, errorListener?: (event: MessageEvent) => void): Promise<any>;
|
|
31
31
|
destroyEventSource(id: string): void;
|
|
32
32
|
destroyAllEventSources(): void;
|
|
33
|
-
getAccessToken: () => Promise<string>;
|
|
33
|
+
getAccessToken: (forceRefresh?: boolean) => Promise<string>;
|
|
34
34
|
private validateIssuer;
|
|
35
35
|
private discoverIssuer;
|
|
36
36
|
private requestAccessToken;
|
package/dist/http.service.js
CHANGED
|
@@ -9,7 +9,6 @@ const jose_1 = require("jose");
|
|
|
9
9
|
const Queue_1 = require("./Queue");
|
|
10
10
|
const token_set_1 = require("./token-set");
|
|
11
11
|
const querystring_1 = require("querystring");
|
|
12
|
-
const TOKEN_EXPIRATION_BUFFER = 30;
|
|
13
12
|
class HttpClient {
|
|
14
13
|
constructor(baseURL, authBaseURL, realm, clientId, clientSecret) {
|
|
15
14
|
this.baseURL = baseURL;
|
|
@@ -34,11 +33,11 @@ class HttpClient {
|
|
|
34
33
|
.catch(reject);
|
|
35
34
|
}));
|
|
36
35
|
};
|
|
37
|
-
this.getAccessToken = async () => {
|
|
38
|
-
if (
|
|
36
|
+
this.getAccessToken = async (forceRefresh = false) => {
|
|
37
|
+
if (forceRefresh || !this.tokenSet || this.tokenSet.isExpired()) {
|
|
39
38
|
return this.requestAccessToken();
|
|
40
39
|
}
|
|
41
|
-
return this.tokenSet.
|
|
40
|
+
return this.tokenSet.accessToken;
|
|
42
41
|
};
|
|
43
42
|
this.axiosInstance = axios_1.default.create({ baseURL, timeout: 60000 });
|
|
44
43
|
this.authAxiosInstance = axios_1.default.create({ baseURL: authBaseURL || baseURL, timeout: 10000 });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import FormData from 'form-data';
|
|
2
|
-
import { Asset, AssetRevision } from '../asset.interface';
|
|
2
|
+
import { Asset, AssetRevision, Attachment } from '../asset.interface';
|
|
3
3
|
import { AssetService } from '../asset.service';
|
|
4
4
|
import { Paginated, RequestParameter } from '../data.interface';
|
|
5
5
|
import { MockAPI } from './api.mock';
|
|
@@ -20,6 +20,7 @@ export declare class AssetMockService extends BaseService implements AssetServic
|
|
|
20
20
|
getMany(params?: RequestParameter): Promise<Paginated<Asset[]>>;
|
|
21
21
|
updateOne(assetId: string, dto: Asset): Promise<Asset>;
|
|
22
22
|
addAttachment(id: string, form: FormData): Promise<Asset>;
|
|
23
|
+
getAttachments(assetId: string): Promise<Paginated<Attachment[]>>;
|
|
23
24
|
getChildren(assetId: string, params?: RequestParameter): Promise<Paginated<Asset[]>>;
|
|
24
25
|
getRevisions(assetId: string): Promise<Paginated<AssetRevision[]>>;
|
|
25
26
|
rollback(assetId: string, revisionId: string): Promise<Asset>;
|
|
@@ -59,6 +59,11 @@ class AssetMockService extends BaseService {
|
|
|
59
59
|
asset.attachments.push(content.id);
|
|
60
60
|
return Promise.resolve(asset);
|
|
61
61
|
}
|
|
62
|
+
async getAttachments(assetId) {
|
|
63
|
+
const contents = await this.api.contentManager.getMany();
|
|
64
|
+
const docs = contents.docs.filter((c) => { var _a, _b; return (_b = (_a = c.assets) === null || _a === void 0 ? void 0 : _a.includes) === null || _b === void 0 ? void 0 : _b.call(_a, assetId); });
|
|
65
|
+
return { docs, total: docs.length, limit: 0 };
|
|
66
|
+
}
|
|
62
67
|
getChildren(assetId, params = {}) {
|
|
63
68
|
return this.getManyFiltered({ parent: assetId }, params);
|
|
64
69
|
}
|
package/dist/token-set.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export declare class TokenSet {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
private readonly _accessToken;
|
|
3
|
+
private readonly _expiresAt;
|
|
4
4
|
constructor(access_token: string, expires_in: number);
|
|
5
|
-
|
|
6
|
-
get
|
|
7
|
-
|
|
5
|
+
get accessToken(): string;
|
|
6
|
+
get expiresAt(): number;
|
|
7
|
+
get expiresIn(): number;
|
|
8
|
+
isExpired(): boolean;
|
|
8
9
|
}
|
package/dist/token-set.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TokenSet = void 0;
|
|
4
|
+
const TOKEN_EXPIRATION_BUFFER = 20;
|
|
4
5
|
class TokenSet {
|
|
5
6
|
constructor(access_token, expires_in) {
|
|
6
|
-
this.
|
|
7
|
-
this.
|
|
7
|
+
this._accessToken = access_token;
|
|
8
|
+
this._expiresAt = Math.floor(Date.now() / 1000) + Number(expires_in);
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
this.
|
|
10
|
+
get accessToken() {
|
|
11
|
+
return this._accessToken;
|
|
11
12
|
}
|
|
12
|
-
get
|
|
13
|
-
return
|
|
13
|
+
get expiresAt() {
|
|
14
|
+
return this._expiresAt;
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
-
return this.
|
|
16
|
+
get expiresIn() {
|
|
17
|
+
return Math.max(this.expiresAt - Math.ceil(Date.now() / 1000), 0);
|
|
18
|
+
}
|
|
19
|
+
isExpired() {
|
|
20
|
+
return this.expiresIn <= TOKEN_EXPIRATION_BUFFER;
|
|
17
21
|
}
|
|
18
22
|
}
|
|
19
23
|
exports.TokenSet = TokenSet;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hahnpro/hpc-api",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.1",
|
|
4
4
|
"description": "Module for easy access to the HahnPRO API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"axios": "~1.3.
|
|
27
|
+
"axios": "~1.3.4",
|
|
28
28
|
"eventsource": "^2.0.2",
|
|
29
29
|
"form-data": "^4.0.0",
|
|
30
|
-
"jose": "^4.
|
|
30
|
+
"jose": "^4.13.1",
|
|
31
31
|
"jwt-decode": "^3.1.2",
|
|
32
32
|
"p-queue": "^6.6.2",
|
|
33
33
|
"ts-mixer": "^6.0.3",
|