swizi

6.7.0 • Public • Published

Swizi JS SDK

npm version downloads

This package provides a JavaScript interface to interact with native Swizi features on mobile devices (iOS/Android). It exposes a unified API for calling native capabilities such as clipboard, navigation, storage, geolocation, and more.

📦 Installation

npm install swizi
# Or with yarn
yarn add swizi

🏁 Initialization

To use this package, simply import it once at the beginning of your app:

import("swizi");

This will attach the swizi object to the global window object:

window.swizi.copyToClipboard("Hello", false);

Note: you don't need to assign the result of the import. Just importing it will make swizi globally available.

🔧 Basic Usage

await swizi.copyToClipboard("Hello World", true);

const platform = await swizi.getPlatform();
console.log(`Running on ${platform}`);

📘 API Documentation

📋 Clipboard

copyToClipboard(text: string, sensitive: boolean): Promise<void>

Copy text to clipboard.

await swizi.copyToClipboard("secret", true);

🌐 Wifi

connectToWifi(...)

Connect to a secure or open Wifi network.

await swizi.connectToWifi("MySSID", "identity", "password", 1, "PEAP", "MSCHAPv2", false);

📦 Storage

const storage = swizi.createStorage("plugin_");

await storage.setItem("foo", "bar");
const value = await storage.getItem("foo");
await storage.removeItem("foo");
await storage.clear();
const allKeys = await storage.keys();

🧭 Navigation

navigate(deeplink: string)

await swizi.navigate("swz://views/home");

goBack()

await swizi.goBack();

openAppSettings()

Opens the app settings on the device.

await swizi.openAppSettings();

💬 UI

displayPopup(title: string, content: string)

await swizi.displayPopup("Alert", "Something went wrong");

displayMenu(title: string, actions: Array)

await swizi.displayMenu("Options", [{ label: "Delete", color: "danger", event: "delete_item" }]);

setViewTitle(title: string)

Change the title of the current view.

await swizi.setViewTitle("My new title");

setViewActions(actions: Array)

Set the action buttons on the current view.

await swizi.setViewActions([
  {
    icon: "business",
    color: "primary_base",
    event: "select_site",
    badge: true,
  },
]);

🌍 Device Info

getPlatform()

Returns "ios" or "android".

getPlatformVersion()

Returns OS version object.

getLang()

Returns current language: { lang: "fr" }

getLocation(forceRefresh: boolean)

Retrieve the device's location. Returns { result: "success", lat, lon } or { result: "location_unauthorized" }.

const location = await swizi.getLocation(true);
console.log(location);

📍 Location

getLocation()

Returns { result: "success", lat, lon } or { result: "location_unauthorized" }

trackUserLocation() / stopTrackUserLocation()

await swizi.trackUserLocation();
await swizi.stopTrackUserLocation();

👤 User

getUser()

Returns the connected user object.

getToken()

Returns current user JWT.


📑 Manifest

getManifest()

Returns plugin manifest + parsed configuration.


📊 Analytics

sendStat(key: string, segmentation: object)

await swizi.sendStat("search", { query: "hello" });

📎 Miscellaneous

  • downloadFile(url, fileName)
  • readQRCode(...)
  • getWifiInfos()
  • log(type, message)
  • openAppSettings()
  • share(content)
  • onEvent(listener) / removeEvent(listener)
  • performGenericAction(actionID, params)

Readme

Keywords

none

Package Sidebar

Install

npm i swizi

Weekly Downloads

60

Version

6.7.0

License

ISC

Unpacked Size

24.6 kB

Total Files

3

Last publish

Collaborators

  • npm-swizi-user