@jolibox/sdk 1.1.27 → 1.1.28

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.
@@ -1,34 +1,73 @@
1
1
  import { BaseSDK } from './sdk';
2
- import { Router, ResponseType, StandardResponse, NavigateToNativePageType } from '@jolibox/types';
2
+ import { Router, StandardResponse, ResponseType, NavigateToNativePageType } from '@jolibox/types';
3
3
 
4
4
  const NavigateToNativePageTypeTypes = ['openHistory'];
5
+
6
+ /**
7
+ * @private
8
+ * Provides routing and navigation functionalities within the Jolibox SDK.
9
+ * This includes opening schemas, web pages, and navigating to native application pages.
10
+ * @implements {Router}
11
+ */
5
12
  export class RouterSDK extends BaseSDK implements Router {
6
- async openSchema(schema: string) {
13
+ /**
14
+ * @public
15
+ * Opens a given schema URL.
16
+ * This is often used for deep linking or triggering specific actions within the host application or other apps.
17
+ * @param schema - The schema URL string to open (e.g., 'yourapp://action?param=value').
18
+ * @returns A promise that resolves with a StandardResponse, or an error object if the capability is not available.
19
+ */
20
+ async openSchema(
21
+ schema: string
22
+ ): Promise<StandardResponse<void> | { code: ResponseType; message: string }> {
7
23
  const errMsg = this.canIUseIfThrow('router.openSchema');
8
24
  if (errMsg) {
9
25
  return errMsg;
10
26
  }
11
27
  return await this.commands.executeCommand('RouterSDK.openSchema', schema);
12
28
  }
13
- async openPage(url: string): Promise<
14
- StandardResponse<{
15
- webviewId: number;
16
- }>
17
- > {
29
+
30
+ /**
31
+ * @public
32
+ * Opens a web page in a new view (e.g., an in-app browser or a new tab).
33
+ * @param url - The URL of the web page to open.
34
+ * @returns A promise that resolves with a StandardResponse containing the webviewId, or an error object if the capability is not available.
35
+ */
36
+ async openPage(
37
+ url: string
38
+ ): Promise<StandardResponse<{ webviewId: number }> | { code: ResponseType; message: string }> {
18
39
  const errMsg = this.canIUseIfThrow('router.openPage');
19
40
  if (errMsg) {
20
41
  return errMsg;
21
42
  }
22
43
  return await this.commands.executeCommand('RouterSDK.openPage', url);
23
44
  }
24
- async closePage(webviewId: number) {
45
+
46
+ /**
47
+ * @public
48
+ * Closes a previously opened web page/view, identified by its webviewId.
49
+ * @param webviewId - The ID of the webview to close.
50
+ * @returns A promise that resolves with a StandardResponse, or an error object if the capability is not available.
51
+ */
52
+ async closePage(
53
+ webviewId: number
54
+ ): Promise<StandardResponse<void> | { code: ResponseType; message: string }> {
25
55
  const errMsg = this.canIUseIfThrow('router.closePage');
26
56
  if (errMsg) {
27
57
  return errMsg;
28
58
  }
29
59
  return await this.commands.executeCommand('RouterSDK.closePage', webviewId);
30
60
  }
31
- async interceptSystemExit(intercept: boolean) {
61
+
62
+ /**
63
+ * @public
64
+ * Intercepts the system's back button or exit gesture.
65
+ * @param intercept - A boolean indicating whether to intercept the exit (true) or allow default behavior (false).
66
+ * @returns A promise that resolves with a StandardResponse, or an error object if the capability is not available.
67
+ */
68
+ async interceptSystemExit(
69
+ intercept: boolean
70
+ ): Promise<StandardResponse<void> | { code: ResponseType; message: string }> {
32
71
  const errMsg = this.canIUseIfThrow('router.interceptSystemExit');
33
72
  if (errMsg) {
34
73
  return errMsg;
@@ -36,7 +75,17 @@ export class RouterSDK extends BaseSDK implements Router {
36
75
  return await this.commands.executeCommand('RouterSDK.interceptSystemExit', intercept);
37
76
  }
38
77
 
39
- async navigateToNativePage(path: string, params: Record<string, unknown>) {
78
+ /**
79
+ * @public
80
+ * Navigates to a specific native page within the host application.
81
+ * @param path - The identifier for the native page to navigate to. Currently, only 'openHistory' is explicitly supported by this client-side check.
82
+ * @param params - A record of parameters to pass to the native page.
83
+ * @returns A promise that resolves with a StandardResponse, or an error object if the capability is not available or the path is invalid.
84
+ */
85
+ async navigateToNativePage(
86
+ path: string,
87
+ params: Record<string, unknown>
88
+ ): Promise<StandardResponse<void> | { code: ResponseType; message: string }> {
40
89
  const errMsg = this.canIUseIfThrow('router.navigateToNativePage');
41
90
  if (errMsg) {
42
91
  return errMsg;
@@ -15,9 +15,10 @@ export enum JoliboxRuntimeEvents {
15
15
  LOAD_PROGRESS = 'JOLIBOX_RUNTIME_LOAD_PROGRESS'
16
16
  }
17
17
  /**
18
+ * @public
18
19
  * Default implementation of JoliboxRuntime, in case the JoliboxRuntime is not available
19
20
  */
20
- class FallbackJoliboxRuntime {
21
+ export class FallbackJoliboxRuntime {
21
22
  /**
22
23
  * Notify the end of the loading, will close the loading splash screen
23
24
  */
package/src/sdks/sdk.ts CHANGED
@@ -6,7 +6,16 @@ export interface BaseSDKEventMap {
6
6
  }
7
7
 
8
8
  export abstract class BaseSDK<T = BaseSDKEventMap> {
9
+ /**
10
+ * @private
11
+ * Instance for executing commands. Intended for internal SDK use.
12
+ */
9
13
  readonly commands = createCommands();
14
+
15
+ /**
16
+ * @private
17
+ * Event emitter instance for handling internal events. Intended for internal SDK use.
18
+ */
10
19
  readonly _emitter = new EventEmitter();
11
20
 
12
21
  addEventListener<K extends keyof T & string>(event: K, callback: (data: T[K]) => void) {
@@ -1,18 +1,38 @@
1
1
  import { BaseSDK } from './sdk';
2
2
  import { StandardResponse, Storage } from '@jolibox/types';
3
3
 
4
+ /**
5
+ * @private
6
+ * Provides functionalities for persistent key-value storage within the Jolibox SDK.
7
+ * Allows setting, getting, removing items, and clearing the entire storage.
8
+ * @implements {Storage}
9
+ */
4
10
  export class StorageSDK extends BaseSDK implements Storage {
5
- async getItem(key: string) {
11
+ /**
12
+ * @public
13
+ * Retrieves an item from storage based on its key.
14
+ * @param key - The key of the item to retrieve.
15
+ * @returns A promise that resolves with the value of the item, or null if the key is not found. The specific structure of the resolved value (e.g., if wrapped in StandardResponse) depends on the command execution result.
16
+ */
17
+ async getItem(key: string): Promise<StandardResponse<string | null>> {
6
18
  const result = await this.commands.executeCommand('StorageSDK.getItem', key);
7
- return result;
19
+ return result as StandardResponse<string | null>;
8
20
  }
9
21
 
22
+ /**
23
+ * @public
24
+ * Sets an item in storage with a given key and value.
25
+ * There are limitations on the length of the key and the combined length of key and value.
26
+ * @param key - The key for the item. Should be less than 128 characters.
27
+ * @param value - The value to store. Can be a number, string, or boolean. It will be converted to a string for storage.
28
+ * @returns A promise that resolves with a StandardResponse. It might contain an error object if validation fails (e.g., key/value length exceeded).
29
+ */
10
30
  async setItem(key: string, value: number | string | boolean): Promise<StandardResponse<void>> {
11
31
  if (key.length > 128) {
12
32
  return {
13
33
  code: 'PARAMETER_ERROR',
14
34
  message: '[SDK] cloud storage setItem error: length of key should be less than 128'
15
- };
35
+ } as StandardResponse<void>;
16
36
  }
17
37
 
18
38
  const valueToStore = typeof value == 'string' ? value : String(value);
@@ -20,16 +40,27 @@ export class StorageSDK extends BaseSDK implements Storage {
20
40
  return {
21
41
  code: 'PARAMETER_ERROR',
22
42
  message: '[SDK] cloud storage setItem error: length of key and value should be less than 1024'
23
- };
43
+ } as StandardResponse<void>;
24
44
  }
25
- return await this.commands.executeCommand('StorageSDK.setItem', key, value);
45
+ return await this.commands.executeCommand('StorageSDK.setItem', key, valueToStore);
26
46
  }
27
47
 
28
- async removeItem(key: string) {
48
+ /**
49
+ * @public
50
+ * Removes an item from storage based on its key.
51
+ * @param key - The key of the item to remove.
52
+ * @returns A promise that resolves with a StandardResponse (or the direct result of command execution).
53
+ */
54
+ async removeItem(key: string): Promise<StandardResponse<void>> {
29
55
  return this.commands.executeCommand('StorageSDK.removeItem', key);
30
56
  }
31
57
 
32
- async clear() {
58
+ /**
59
+ * @public
60
+ * Clears all items from the storage.
61
+ * @returns A promise that resolves with a StandardResponse (or the direct result of command execution).
62
+ */
63
+ async clear(): Promise<StandardResponse<void>> {
33
64
  return this.commands.executeCommand('StorageSDK.clear');
34
65
  }
35
66
  }
package/src/sdks/task.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import { BaseSDK } from './sdk';
2
2
  import { TaskTracker, TaskResponse, type ResponseType } from '@jolibox/types';
3
3
 
4
+ /**
5
+ * @public
6
+ * Provides functionalities for task tracking within the Jolibox SDK.
7
+ * Allows tracking of game levels, gameplay sessions, and level upgrades.
8
+ * @implements {TaskTracker}
9
+ */
4
10
  export class TaskTrackerSDK extends BaseSDK implements TaskTracker {
5
11
  /**
6
12
  * Handles completion of a game level by sending analytics data to the backend