jamespot-user-api 1.0.42 → 1.0.43
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/documentation/.nojekyll +1 -0
- package/documentation/assets/highlight.css +50 -0
- package/documentation/assets/icons.css +1043 -0
- package/documentation/assets/icons.png +0 -0
- package/documentation/assets/icons@2x.png +0 -0
- package/documentation/assets/main.js +52 -0
- package/documentation/assets/search.js +1 -0
- package/documentation/assets/style.css +1413 -0
- package/documentation/assets/widgets.png +0 -0
- package/documentation/assets/widgets@2x.png +0 -0
- package/documentation/classes/JApplication.html +1 -0
- package/documentation/classes/JApplicationApi.html +30 -0
- package/documentation/classes/JArticleApi.html +1 -0
- package/documentation/classes/JAudienceApi.html +4 -0
- package/documentation/classes/JBaseApi.html +1 -0
- package/documentation/classes/JBaseObject.html +4 -0
- package/documentation/classes/JBookmark.html +1 -0
- package/documentation/classes/JBookmarkApi.html +1 -0
- package/documentation/classes/JCommunityApi.html +1 -0
- package/documentation/classes/JConcept.html +1 -0
- package/documentation/classes/JConceptApi.html +7 -0
- package/documentation/classes/JDiapazoneApi.html +1 -0
- package/documentation/classes/JFileApi.html +1 -0
- package/documentation/classes/JFilebankApi.html +1 -0
- package/documentation/classes/JGroupApi.html +12 -0
- package/documentation/classes/JLandApi.html +1 -0
- package/documentation/classes/JMessengerApi.html +1 -0
- package/documentation/classes/JSearchApi.html +18 -0
- package/documentation/classes/JUser.html +1 -0
- package/documentation/classes/JUserApi.html +17 -0
- package/documentation/classes/JWedocApi.html +1 -0
- package/documentation/classes/JamespotUserApi.html +6 -0
- package/documentation/classes/Network.html +1 -0
- package/documentation/enums/JApplicationStatus.html +1 -0
- package/documentation/index.html +79 -0
- package/documentation/interfaces/ApiError.html +1 -0
- package/documentation/interfaces/ApiWrapper.html +1 -0
- package/documentation/interfaces/AseiGroups.html +1 -0
- package/documentation/interfaces/AseiInstitution.html +1 -0
- package/documentation/interfaces/AseiRights.html +1 -0
- package/documentation/interfaces/AseiTicket.html +1 -0
- package/documentation/interfaces/BaseAutocomplete.html +1 -0
- package/documentation/interfaces/BaseMessage.html +1 -0
- package/documentation/interfaces/Category.html +1 -0
- package/documentation/interfaces/CreateGroup.html +1 -0
- package/documentation/interfaces/FileBankProps.html +1 -0
- package/documentation/interfaces/FileOption.html +1 -0
- package/documentation/interfaces/FolderProps.html +1 -0
- package/documentation/interfaces/ListFilterSpec.html +1 -0
- package/documentation/interfaces/OF.html +1 -0
- package/documentation/interfaces/PagingResults.html +1 -0
- package/documentation/interfaces/Result.html +1 -0
- package/documentation/interfaces/RootFolderProps.html +1 -0
- package/documentation/interfaces/SearchCategoryModel.html +1 -0
- package/documentation/interfaces/SearchConfig.html +1 -0
- package/documentation/interfaces/SearchFacetModel.html +1 -0
- package/documentation/interfaces/SearchFacetValueModel.html +1 -0
- package/documentation/interfaces/SearchQuery.html +1 -0
- package/documentation/interfaces/SearchQueryFilterModel.html +6 -0
- package/documentation/interfaces/SearchQueryOption.html +4 -0
- package/documentation/interfaces/SearchQueryResult.html +1 -0
- package/documentation/interfaces/SearchQuerySortModel.html +5 -0
- package/documentation/interfaces/SearchResultCatProps.html +1 -0
- package/documentation/interfaces/SearchResultProps.html +1 -0
- package/documentation/interfaces/SpotProps.html +1 -0
- package/documentation/interfaces/Taxonomy.html +1 -0
- package/documentation/interfaces/TaxonomyCreate.html +1 -0
- package/documentation/interfaces/TmpApplication.html +1 -0
- package/documentation/interfaces/TmpUser.html +1 -0
- package/documentation/interfaces/UserModel.html +1 -0
- package/documentation/modules.html +1 -0
- package/lib/src/apis/application.d.ts +60 -0
- package/lib/src/apis/article.d.ts +38 -0
- package/lib/src/apis/asei.d.ts +25 -0
- package/lib/src/apis/audience.d.ts +9 -0
- package/lib/src/apis/base.d.ts +5 -0
- package/lib/src/apis/bookmark.d.ts +21 -0
- package/lib/src/apis/community.d.ts +9 -0
- package/lib/src/apis/concept.d.ts +10 -0
- package/lib/src/apis/diapazone.d.ts +8 -0
- package/lib/src/apis/file.d.ts +5 -0
- package/lib/src/apis/filebank.d.ts +34 -0
- package/lib/src/apis/group.d.ts +16 -0
- package/lib/src/apis/index.d.ts +17 -0
- package/lib/src/apis/jamespotUserApi.d.ts +47 -0
- package/lib/src/apis/jland.d.ts +24 -0
- package/lib/src/apis/messenger.d.ts +6 -0
- package/lib/src/apis/search.d.ts +47 -0
- package/lib/src/apis/taxonomy.d.ts +9 -0
- package/lib/src/apis/user.d.ts +27 -0
- package/lib/src/apis/wedoc.d.ts +32 -0
- package/lib/src/classes/JApplication.d.ts +16 -0
- package/lib/src/classes/JBaseObject.d.ts +15 -0
- package/lib/src/classes/JBookmark.d.ts +16 -0
- package/lib/src/classes/JConcept.d.ts +3 -0
- package/lib/src/classes/JDiapazone.d.ts +16 -0
- package/lib/src/classes/JFile.d.ts +13 -0
- package/lib/src/classes/JUser.d.ts +4 -0
- package/lib/src/classes/index.d.ts +5 -0
- package/lib/src/index.d.ts +13 -0
- package/lib/src/indexMock.d.ts +9 -0
- package/lib/src/mock/windowMock.d.ts +9 -0
- package/lib/src/types/asei.d.ts +28 -0
- package/lib/src/types/autocomplete.d.ts +16 -0
- package/lib/src/types/group.d.ts +22 -0
- package/lib/src/types/index.d.ts +7 -0
- package/lib/src/types/listWrapper.d.ts +6 -0
- package/lib/src/types/search.d.ts +96 -0
- package/lib/src/types/taxonomy.d.ts +46 -0
- package/lib/src/types/user.d.ts +14 -0
- package/lib/src/types/utils.d.ts +56 -0
- package/lib/src/util/network.d.ts +23 -0
- package/package.json +1 -1
- package/src/apis/application.ts +132 -0
- package/src/apis/article.ts +74 -0
- package/src/apis/asei.ts +73 -0
- package/src/apis/audience.ts +18 -0
- package/src/apis/base.ts +9 -0
- package/src/apis/bookmark.ts +110 -0
- package/src/apis/community.ts +20 -0
- package/src/apis/concept.ts +31 -0
- package/src/apis/diapazone.ts +65 -0
- package/src/apis/file.ts +14 -0
- package/src/apis/filebank.ts +50 -0
- package/src/apis/group.ts +48 -0
- package/src/apis/index.ts +17 -0
- package/src/apis/jamespotUserApi.ts +69 -0
- package/src/apis/jland.ts +51 -0
- package/src/apis/messenger.ts +25 -0
- package/src/apis/search.ts +85 -0
- package/src/apis/taxonomy.ts +30 -0
- package/src/apis/user.ts +53 -0
- package/src/apis/wedoc.ts +77 -0
- package/src/classes/JApplication.ts +55 -0
- package/src/classes/JBaseObject.ts +64 -0
- package/src/classes/JBookmark.ts +44 -0
- package/src/classes/JConcept.ts +3 -0
- package/src/classes/JDiapazone.ts +42 -0
- package/src/classes/JFile.ts +37 -0
- package/src/classes/JUser.ts +7 -0
- package/src/classes/index.ts +5 -0
- package/src/index.ts +21 -0
- package/src/indexMock.ts +17 -0
- package/src/mock/data/autocomplete/audience/data.json +191 -0
- package/src/mock/data/autocomplete/community/data.json +47 -0
- package/src/mock/data/autocomplete/taxonomy/data.json +35 -0
- package/src/mock/data/autocomplete/user/data.json +107 -0
- package/src/mock/data/bookmarks/addBookmark/data.json +54 -0
- package/src/mock/data/bookmarks/addLink/data.json +63 -0
- package/src/mock/data/bookmarks/bookmarkList/data.json +271 -0
- package/src/mock/data/bookmarks/delete/data.json +12 -0
- package/src/mock/data/community/sendRequest/data.json +12 -0
- package/src/mock/data/file/create/data.json +18 -0
- package/src/mock/data/messenger/newMessage/data.json +47 -0
- package/src/mock/data/misc/tokenCSRF/data.json +7 -0
- package/src/mock/data/search/getConfig/data.json +318 -0
- package/src/mock/data/search/lastQueries/data.json +7 -0
- package/src/mock/data/search/proposition/data.json +125 -0
- package/src/mock/data/spot/create/data.json +7 -0
- package/src/mock/data/spot/get-available-widget/data.json +56 -0
- package/src/mock/data/spot/get-categories/data.json +28 -0
- package/src/mock/data/user/signIn/data.json +197 -0
- package/src/mock/windowMock.ts +113 -0
- package/src/types/asei.ts +33 -0
- package/src/types/autocomplete.ts +17 -0
- package/src/types/group.ts +27 -0
- package/src/types/index.ts +7 -0
- package/src/types/listWrapper.ts +6 -0
- package/src/types/search.ts +105 -0
- package/src/types/taxonomy.ts +47 -0
- package/src/types/user.ts +14 -0
- package/src/types/utils.ts +66 -0
- package/src/util/network.ts +96 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { ApiWrapper } from '../types';
|
|
2
|
+
|
|
3
|
+
export interface FileOption {
|
|
4
|
+
makeImage: boolean;
|
|
5
|
+
size: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface OF {
|
|
9
|
+
o: string;
|
|
10
|
+
f: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class Network {
|
|
14
|
+
private readonly backUrl: string;
|
|
15
|
+
private readonly apiUrl: string;
|
|
16
|
+
private readonly window: Window;
|
|
17
|
+
|
|
18
|
+
public constructor(window: Window, suffix = '/user-api') {
|
|
19
|
+
this.window = window;
|
|
20
|
+
const location = window.location;
|
|
21
|
+
this.backUrl = `${location.protocol}//${location.host}`;
|
|
22
|
+
this.apiUrl = this.backUrl + suffix;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public static _formatPostOptions(body: object): RequestInit {
|
|
26
|
+
return Object.assign({ method: 'POST', credentials: 'same-origin' as const }, { body: JSON.stringify(body) });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public static _formatQueryOptions(options: Record<string, string | boolean | number>): string {
|
|
30
|
+
return Object.entries(options)
|
|
31
|
+
.reduce((acc, [optKey, optValue]) => {
|
|
32
|
+
acc.append(optKey, optValue.toString());
|
|
33
|
+
return acc;
|
|
34
|
+
}, new URLSearchParams())
|
|
35
|
+
.toString();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// FIXME Promise<Response> should depend of T
|
|
39
|
+
public fetch(body: OF, signal?: AbortSignal): Promise<Response> {
|
|
40
|
+
return this.window.fetch(this.apiUrl, { ...Network._formatPostOptions(body), signal });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public post<T, U = string[]>(body: OF, signal?: AbortSignal): Promise<ApiWrapper<T, U>> {
|
|
44
|
+
return this.fetch(body, signal)
|
|
45
|
+
.then((res: Response) => res.json() as Promise<ApiWrapper<T, U>>)
|
|
46
|
+
.then((res) => {
|
|
47
|
+
if (res.error === 0) {
|
|
48
|
+
return res;
|
|
49
|
+
}
|
|
50
|
+
throw {
|
|
51
|
+
error: res.error,
|
|
52
|
+
errorMsg: res.errorMsg,
|
|
53
|
+
messages: res.messages,
|
|
54
|
+
};
|
|
55
|
+
})
|
|
56
|
+
.catch((err) => {
|
|
57
|
+
if (signal && signal.aborted) {
|
|
58
|
+
throw {
|
|
59
|
+
error: -1,
|
|
60
|
+
aborted: true,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
throw err;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// FIXME when doing the first file upload
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
+
public postFile(body: FormData, options: FileOption): Promise<any> {
|
|
70
|
+
return this.window
|
|
71
|
+
.fetch(`${this.apiUrl}?o=file&f=create&${Network._formatQueryOptions(Object.freeze(options))}`, {
|
|
72
|
+
method: 'POST',
|
|
73
|
+
credentials: 'same-origin',
|
|
74
|
+
body,
|
|
75
|
+
})
|
|
76
|
+
.then((resp) => resp.json())
|
|
77
|
+
.then((response) => {
|
|
78
|
+
if (response.error === 0) {
|
|
79
|
+
return response.result;
|
|
80
|
+
}
|
|
81
|
+
throw response.error;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public postCSRF<T, U = string[]>(body: OF): Promise<ApiWrapper<T, U>> {
|
|
86
|
+
return this.tokenCSRF().then((tokenCSRF) => this.post(Object.assign(body, { tokenCSRF: tokenCSRF.result })));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public token(): Promise<ApiWrapper<string>> {
|
|
90
|
+
return this.post({ o: 'misc', f: 'token' });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public tokenCSRF(): Promise<ApiWrapper<string>> {
|
|
94
|
+
return this.post({ o: 'misc', f: 'tokenCSRF' });
|
|
95
|
+
}
|
|
96
|
+
}
|