@smartico/public-api 0.0.46 → 0.0.47

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartico/public-api",
3
- "version": "0.0.46",
3
+ "version": "0.0.47",
4
4
  "description": "Smartico public API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,7 +23,8 @@
23
23
  "bump-tracker": "cd ../tracker && npm install @smartico/public-api@latest --legacy-peer-deps",
24
24
  "bump-ach": "cd ../tracker/ach && npm install @smartico/public-api@latest --legacy-peer-deps",
25
25
  "bump-bo-server": "cd ../bo_server/server && source ~/.nvm/nvm.sh && nvm use v13.13.0 && npm install @smartico/public-api@latest",
26
- "bump-bo-client": "cd ../bo_server/client && source ~/.nvm/nvm.sh && nvm use v13.13.0 && npm install @smartico/public-api@latest"
26
+ "bump-bo-client": "cd ../bo_server/client && source ~/.nvm/nvm.sh && nvm use v13.13.0 && npm install @smartico/public-api@latest",
27
+ "doc": "typedoc"
27
28
  },
28
29
  "author": "",
29
30
  "license": "ISC",
@@ -34,6 +35,9 @@
34
35
  "devDependencies": {
35
36
  "@types/node-fetch": "^2.6.2",
36
37
  "microbundle": "0.15.0",
37
- "npm-run-all": "4.1.5"
38
+ "npm-run-all": "4.1.5",
39
+ "typedoc": "^0.24.8",
40
+ "typedoc-plugin-markdown": "^3.15.4",
41
+ "typedoc-plugin-merge-modules": "^5.0.1"
38
42
  }
39
43
  }
@@ -16,7 +16,7 @@ import { AchievementType, GetAchievementMapRequest, GetAchievementMapResponse }
16
16
  import { GetTournamentInfoRequest, GetTournamentInfoResponse, GetTournamentsRequest, GetTournamentsResponse } from './Tournaments';
17
17
  import { GetLeaderBoardsRequest, GetLeaderBoardsResponse, LeaderBoardDetails, LeaderBoardPeriodType } from "./Leaderboard";
18
18
  import { GetLevelMapResponse } from "./Level";
19
-
19
+ import { WSAPI } from "./WSAPI/WSAPI";
20
20
 
21
21
  const PUBLIC_API_URL = 'https://papi{ENV_ID}.smartico.ai/services/public';
22
22
  const C_SOCKET_PROD = 'wss://api{ENV_ID}.smartico.ai/websocket/services';
@@ -29,7 +29,7 @@ interface IOptions {
29
29
  logHTTPTiming?: boolean;
30
30
  }
31
31
 
32
- type MessageSender = (message: any, publicApuUrl: string) => Promise<any>;
32
+ type MessageSender = (message: any, publicApuUrl?: string, expectCID?: ClassId) => Promise<any>;
33
33
 
34
34
 
35
35
  class SmarticoAPI {
@@ -101,7 +101,7 @@ class SmarticoAPI {
101
101
 
102
102
  try {
103
103
  const timeStart = new Date().getTime();
104
- result = await this.messageSender(message, this.publicUrl);
104
+ result = await this.messageSender(message, this.publicUrl, expectCID);
105
105
  const timeEnd = new Date().getTime();
106
106
 
107
107
  if (this.logHTTPTiming) {
@@ -410,9 +410,13 @@ class SmarticoAPI {
410
410
 
411
411
  }
412
412
 
413
- public async levelsGet(user_ext_id: string): Promise<GetLevelMapResponse> {
413
+ public async levelsGet(user_ext_id?: string ): Promise<GetLevelMapResponse> {
414
414
  const message = this.buildMessage<any, GetLevelMapResponse>(user_ext_id, ClassId.GET_LEVEL_MAP_REQUEST);
415
- return await this.send<GetLevelMapResponse>(message);
415
+ return await this.send<GetLevelMapResponse>(message, ClassId.GET_LEVEL_MAP_RESPONSE);
416
+ }
417
+
418
+ public getWSCalls(): WSAPI {
419
+ return new WSAPI(this);
416
420
  }
417
421
 
418
422
  }
@@ -0,0 +1,18 @@
1
+ import { SmarticoAPI } from "../SmarticoAPI";
2
+
3
+ import { GetLevelMapClearedResponse, levelCleaner } from "./WSAPITypes";
4
+
5
+ /** @group General API */
6
+ export class WSAPI {
7
+ private static api: SmarticoAPI;
8
+
9
+ /** @private */
10
+ constructor(api: SmarticoAPI) {
11
+ WSAPI.api = api;
12
+ }
13
+
14
+ public async getLevelsTransformed(): Promise<GetLevelMapClearedResponse[]> {
15
+ const levels = await WSAPI.api.levelsGet(null);
16
+ return levelCleaner(levels);
17
+ }
18
+ }
@@ -0,0 +1,29 @@
1
+ import { GetLevelMapResponse } from "../Level"
2
+
3
+ // Levels
4
+
5
+ /** @group Levels response */
6
+ export interface GetLevelMapClearedResponse {
7
+
8
+ id: number,
9
+ name: string,
10
+ description: string,
11
+ image: string,
12
+ required_points: number,
13
+ required_level_counter_1: number,
14
+ required_level_counter_2: number,
15
+ }
16
+
17
+ /** @hidden */
18
+ export const levelCleaner = (levels: GetLevelMapResponse): GetLevelMapClearedResponse[] => {
19
+
20
+ return levels?.levels.map((l => ({
21
+ id: l.level_id,
22
+ name: l.level_public_meta.name,
23
+ description: l.level_public_meta.description,
24
+ image: l.level_public_meta.image_url,
25
+ required_points: l.required_points,
26
+ required_level_counter_1: l.required_level_counter_1,
27
+ required_level_counter_2: l.required_level_counter_2,
28
+ })));
29
+ }
package/tsconfig.json CHANGED
@@ -12,6 +12,15 @@
12
12
  },
13
13
  "include": [
14
14
  "src/**/*"
15
- ]
15
+ ],
16
+ "typedocOptions": {
17
+ "name": "Smartico API documentation",
18
+ "entryPoints": ["src/WSAPI/WSAPI.ts", "src/WSAPI/WSAPITypes.ts"],
19
+ "out": "docs_test",
20
+ "plugin": ["typedoc-plugin-markdown", "typedoc-plugin-merge-modules"],
21
+ "entryDocument": "README_TWO.md",
22
+ "disableSources": true,
23
+ "excludePrivate": true,
24
+ }
16
25
  }
17
26