Skip to content

JSSDK Usage

Prerequisites

Since JSSDK depends on the UGOS Pro system frontend desktop environment, it only supports use when the application frontend page is opened as an independent window within the UGOS Pro system desktop, i.e., the open type (open_type) in the application configuration needs to be set to inner.

Import Methods

Both ESM and CJS module import methods are supported. The specific import files are as follows:

shell
index.js    --- ESM (ECMAScript Modules)  Uses import and export statements
index.d.ts  --- Type definition file with specific exports
index.cjs   --- CJS (CommonJS) Uses require and module.exports statements

Interface Description

  • getUgInfo: Get the current logged-in user's settings information. The parameter is a callback function that receives an object with the following properties:
    • third_token: The third-party authentication token of the logged-in user, used for login authentication when calling backend services.
    • lang: The language used by the frontend interface, such as zh-CN, en-US, etc., used for frontend interface internationalization.
  • openAppDetail: Open the detail page of a specified application in the App Center. The parameter is the application ID, for example com.mycompany.myapp.

Usage Examples

  • info error type definitions
typescript
type errCodeType = {
  code: errCode;
  message: string;
};
declare enum errCode {
  NETWORK_ERR = 6704,
  TEMP_TOKEN_ERROR = 6703,
  REPEAT_REQUEST_ERROR = 6702,
  CLIENT_LOW = 6701,
}
type ugSdkType = {
  getUgInfo: (
    callback: (err: errCodeType | null, res: ugInfoType) => void,
  ) => void;
  ugFetch: {
    get(
      url: string,
      params?: Record<any, any>,
      headers?: Record<any, any>,
    ): Promise<any>;
    post(
      url: string,
      data?: Record<any, any>,
      headers?: Record<any, any>,
    ): Promise<any>;
  };
  LOGIN_FAILED_CODE: number[];
  openAppDetail: (appId: string) => void;
};
type __ugInfoType = {
  dateFormat?: string;
  timeFormat?: string;
  temperatureUnit?: number;
  third_token?: string;
  lang?: string;
};
type ugInfoType = null | __ugInfoType;
declare const ugSdk: ugSdkType;

export { ugInfoType, ugSdk };
  • Example: Get info information, open application details
js
import { ugSdk } from './index.js?v=1';
let ugToken = null;
// Callback
const callback = (error, _info) => {
   if (!error) {
       console.log(_info);
       if (_info && _info.third_token) {
           ugToken = _info.third_token;
       }
       fetchAPI();
   }
};
// Get login authentication token
ugSdk.getUgInfo(callback);

// Open application detail page
const appId = 'com.mycompany.myapp' // Application ID
ugSdk.openAppDetail(appId)

JSSDK Download

File NameSizeDownload LinkMD5
jssdk25 KBjssdk.zipE67990E18C8834D7CBBE6CDB5F3E6D87