@whatfix_mobile/ionic-sdk 0.0.0-stage → 1.2.0
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/CHANGELOG.md +55 -0
- package/LICENSE.pdf +0 -0
- package/Package.swift +27 -0
- package/README.md +326 -2
- package/index.d.ts +44 -0
- package/index.js +3 -0
- package/package.json +53 -4
- package/plugin.xml +31 -0
- package/src/android/WhatfixMobilePlugin.java +228 -0
- package/src/ios/WhatfixMobilePlugin.swift +168 -0
- package/www/whatfix-mobile.js +103 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
- **Breaking:** CocoaPods integration is removed. iOS hosts must use Swift Package
|
|
6
|
+
Manager. Native iOS SDK 1.2.0 is published as a Swift package only, so the
|
|
7
|
+
plugin no longer declares a pod.
|
|
8
|
+
- Cordova: iOS platform `cordova-ios` 8.2.0 or newer is required by the
|
|
9
|
+
plugin's engine requirement. On an older iOS platform Cordova skips the
|
|
10
|
+
plugin for iOS and reports the failed version requirement. Cordova iOS 7
|
|
11
|
+
hosts must upgrade the platform before installing this version.
|
|
12
|
+
- Capacitor: the iOS project must use SPM
|
|
13
|
+
(`npx cap add ios --packagemanager SPM` for a new platform). An existing
|
|
14
|
+
CocoaPods iOS project must be migrated to SPM first; otherwise the build
|
|
15
|
+
fails with `No such module 'WhatfixMobileSDK'`.
|
|
16
|
+
- Xcode 16 or newer and an iOS 15.0 deployment target are required, as before
|
|
17
|
+
for SPM hosts. Android hosts are not affected.
|
|
18
|
+
- Pins the production native dependencies to Android SDK 1.2.0 and iOS SDK 1.2.0.
|
|
19
|
+
- With native SDK 1.2.0, an overlay fault no longer shuts the whole SDK down by
|
|
20
|
+
default: only the overlay is switched off, and it restarts the next time the
|
|
21
|
+
app returns to the foreground. An explicit `safety.kill_switch: true` in the
|
|
22
|
+
remote configuration keeps the SDK-wide shutdown.
|
|
23
|
+
- No change to the JavaScript API.
|
|
24
|
+
|
|
25
|
+
## 1.1.1
|
|
26
|
+
|
|
27
|
+
- Pins the production native dependencies to Android SDK 1.1.1 and iOS SDK 1.1.1.
|
|
28
|
+
- Provides one typed JavaScript bridge for Cordova and Capacitor's Cordova
|
|
29
|
+
compatibility layer: initialization, user identity, locale, text/number/date
|
|
30
|
+
properties, flush, logout, and disable.
|
|
31
|
+
- Supports iOS integration through CocoaPods or Swift Package Manager without
|
|
32
|
+
linking a second copy of the native SDK.
|
|
33
|
+
- Documents npm registry installation, native prerequisites, dispatch semantics,
|
|
34
|
+
and release information directly in the package README.
|
|
35
|
+
- Includes the supplied Whatfix Mobile SDK License Agreement as `LICENSE.pdf`.
|
|
36
|
+
|
|
37
|
+
### Integration Notes
|
|
38
|
+
|
|
39
|
+
- Install with `npm install @whatfix_mobile/ionic-sdk` for Capacitor or
|
|
40
|
+
`cordova plugin add @whatfix_mobile/ionic-sdk` for Cordova. An exact `@1.1.1` pin is
|
|
41
|
+
optional for reproducible builds.
|
|
42
|
+
- The documented host matrix is Cordova Android 13, Cordova iOS 7 with
|
|
43
|
+
CocoaPods or 8.2+ with SPM, and Capacitor 7. iOS requires deployment target
|
|
44
|
+
15.0 or later; the native SPM package requires Swift 6 / Xcode 16 or later.
|
|
45
|
+
- Wait for the framework's native-ready event before calling the plugin.
|
|
46
|
+
Promise resolution acknowledges dispatch, not configuration acceptance,
|
|
47
|
+
overlay/Creator readiness, or telemetry delivery. Native iOS start returns
|
|
48
|
+
no acceptance result; Android can synchronously reject startup.
|
|
49
|
+
- `disable()` is terminal until app relaunch. Navigation does not reset or
|
|
50
|
+
restart the native SDK.
|
|
51
|
+
- Native configuration, consent and telemetry gates remain in force. Inspection
|
|
52
|
+
follows native policy; Android WebView debugging is process-wide. No wrapper
|
|
53
|
+
error forces an upload or bypasses native permissions.
|
|
54
|
+
- Browser-only execution is unsupported. The wrapper does not contain native
|
|
55
|
+
process crashes or Objective-C exceptions.
|
package/LICENSE.pdf
ADDED
|
Binary file
|
package/Package.swift
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "WhatfixMobilePlugin",
|
|
6
|
+
platforms: [.iOS(.v15)],
|
|
7
|
+
products: [
|
|
8
|
+
// Cordova uses plugin.xml's ID; Capacitor uses the scoped npm package ID.
|
|
9
|
+
.library(name: "com.whatfix.ionic", targets: ["WhatfixMobilePlugin"]),
|
|
10
|
+
.library(name: "@whatfix_mobile/ionic-sdk", targets: ["WhatfixMobilePlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
// Cordova 8 substitutes its local runtime; Capacitor substitutes its compatibility package.
|
|
14
|
+
.package(url: "https://github.com/apache/cordova-ios.git", from: "8.0.0"),
|
|
15
|
+
.package(url: "https://github.com/whatfix/WhatfixMobileSDK.git", exact: "1.2.0")
|
|
16
|
+
],
|
|
17
|
+
targets: [
|
|
18
|
+
.target(
|
|
19
|
+
name: "WhatfixMobilePlugin",
|
|
20
|
+
dependencies: [
|
|
21
|
+
.product(name: "Cordova", package: "cordova-ios"),
|
|
22
|
+
.product(name: "WhatfixMobileSDK", package: "whatfixmobilesdk")
|
|
23
|
+
],
|
|
24
|
+
path: "src/ios"
|
|
25
|
+
)
|
|
26
|
+
]
|
|
27
|
+
)
|
package/README.md
CHANGED
|
@@ -1,3 +1,327 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Whatfix Mobile SDK for Ionic
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Typed JavaScript bridge to the Whatfix Android and iOS SDKs. One Cordova plugin
|
|
4
|
+
runs in Cordova and in Capacitor's Cordova compatibility layer. The wrapper does
|
|
5
|
+
not implement its own overlay, hierarchy extractor, configuration, kill switch,
|
|
6
|
+
or telemetry transport.
|
|
7
|
+
|
|
8
|
+
## Native Dependencies
|
|
9
|
+
|
|
10
|
+
| Platform | Production dependency |
|
|
11
|
+
| --- | --- |
|
|
12
|
+
| Android | `com.whatfix.android:whatfix-mobile-sdk:1.2.0` from Maven Central |
|
|
13
|
+
| iOS | `WhatfixMobileSDK` `1.2.0` through Swift Package Manager |
|
|
14
|
+
|
|
15
|
+
The Android dependency resolves from Maven Central. A missing Maven artifact is
|
|
16
|
+
a build prerequisite failure, not a reason to silently bundle another AAR.
|
|
17
|
+
The plugin consumes the published native SDKs rather than copying their implementation.
|
|
18
|
+
|
|
19
|
+
Host matrix: Cordova Android 13, Cordova iOS 8.2 or newer, and Capacitor 7 on
|
|
20
|
+
Android/iOS. On iOS the plugin integrates through Swift Package Manager (SPM) only;
|
|
21
|
+
CocoaPods integration is not supported. iOS requires deployment target 15.0 or
|
|
22
|
+
newer, and the native SDK's SPM manifest requires Swift 6 tooling (Xcode 16 or newer).
|
|
23
|
+
Browser-only execution is not supported. Installation requires the native Android
|
|
24
|
+
or iOS build toolchain; adding the JavaScript package alone does not enable a browser runtime.
|
|
25
|
+
|
|
26
|
+
## Install From npm
|
|
27
|
+
|
|
28
|
+
Install from the root of an existing Capacitor or Cordova application. You do not
|
|
29
|
+
need a repository checkout or a locally built tarball.
|
|
30
|
+
|
|
31
|
+
### Capacitor
|
|
32
|
+
|
|
33
|
+
The iOS project must use Swift Package Manager. If the app does not yet have an
|
|
34
|
+
iOS platform, add it with `npx cap add ios --packagemanager SPM`; Capacitor 7
|
|
35
|
+
creates a CocoaPods project unless SPM is requested. An existing CocoaPods iOS
|
|
36
|
+
project must be migrated to SPM first: follow
|
|
37
|
+
[Capacitor's dependency-manager setup](https://capacitorjs.com/docs/ios/spm).
|
|
38
|
+
A CocoaPods project cannot resolve the native SDK and fails to compile with
|
|
39
|
+
`No such module 'WhatfixMobileSDK'`.
|
|
40
|
+
|
|
41
|
+
Prepare the native project **before installing the plugin and syncing**: set the
|
|
42
|
+
app deployment target to at least iOS 15.0. Capacitor 7 defaults to iOS 14.0,
|
|
43
|
+
which is too low for this native SDK. Capacitor copies the app's deployment
|
|
44
|
+
target into its generated Swift package when it syncs, so the order matters. If
|
|
45
|
+
the project was synced first, the build fails with
|
|
46
|
+
`requires minimum platform version 15.0 for the iOS platform, but this target supports 14.0`:
|
|
47
|
+
raise the deployment target in Xcode, then run `npx cap sync ios` again.
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
npm install @whatfix_mobile/ionic-sdk
|
|
51
|
+
npx cap sync
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Cordova
|
|
55
|
+
|
|
56
|
+
Before installing on iOS, set these preferences in the app's `config.xml`:
|
|
57
|
+
|
|
58
|
+
```xml
|
|
59
|
+
<preference name="deployment-target" value="15.0" />
|
|
60
|
+
<preference name="SwiftVersion" value="5.0" />
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Then install the published plugin:
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
cordova plugin add @whatfix_mobile/ionic-sdk
|
|
67
|
+
cordova prepare
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The iOS platform requires **cordova-ios 8.2.0 or newer**; the plugin declares
|
|
71
|
+
this as its engine requirement. On an older iOS platform Cordova reports the failed
|
|
72
|
+
version requirement and skips the plugin for iOS, so `window.WhatfixMobile` is
|
|
73
|
+
unavailable there until the platform is upgraded. Earlier releases either have no Swift package support for plugins or,
|
|
74
|
+
in 8.0.0, hardcode an iOS 13 target in the generated package and do not apply the
|
|
75
|
+
app's deployment-target preference there. Cordova resolves the native SDK through
|
|
76
|
+
the plugin's `Package.swift`; the plugin has no CocoaPods declaration. Upgrade an
|
|
77
|
+
older iOS platform with `cordova platform rm ios` followed by
|
|
78
|
+
`cordova platform add ios@8.2.0` (or newer) before adding the plugin.
|
|
79
|
+
Do not manually add a second Whatfix SDK dependency to the host project. SPM is
|
|
80
|
+
the build-time dependency manager, not an iOS device-version check or a runtime
|
|
81
|
+
fallback when a download fails.
|
|
82
|
+
See [Cordova SPM support](https://cordova.apache.org/docs/en/latest/guide/platforms/ios/plugin.html#supporting-swift-package-manager-spm)
|
|
83
|
+
and [Capacitor's dependency-manager setup](https://capacitorjs.com/docs/ios/spm).
|
|
84
|
+
|
|
85
|
+
The commands above select the current npm release. For reproducible builds, an
|
|
86
|
+
exact package version is optional: use `npm install @whatfix_mobile/ionic-sdk@1.2.0`
|
|
87
|
+
or `cordova plugin add @whatfix_mobile/ionic-sdk@1.2.0` instead. Commit the host
|
|
88
|
+
application's lockfile and keep its platform and dependency-manager configuration.
|
|
89
|
+
|
|
90
|
+
Keep the native SDK's merged Android startup provider enabled. It registers
|
|
91
|
+
lifecycle observation before the Activity resumes; invoking the wrapper later
|
|
92
|
+
must not require replacing the host Activity, WebView clients, or delegates.
|
|
93
|
+
For iOS Creator QR scanning, add a camera purpose string inside the host app's
|
|
94
|
+
`Info.plist` dictionary and handle the normal system permission prompt. For example:
|
|
95
|
+
|
|
96
|
+
```xml
|
|
97
|
+
<key>NSCameraUsageDescription</key>
|
|
98
|
+
<string>Scan Whatfix QR codes for content previews.</string>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Use purpose text appropriate to your app. The plugin does not add camera
|
|
102
|
+
permission text or arbitrary network exceptions to your app. Camera permission
|
|
103
|
+
is needed for QR scanning, not for every initialization.
|
|
104
|
+
|
|
105
|
+
## Usage
|
|
106
|
+
|
|
107
|
+
Use the enterprise UUID issued by Whatfix for your account. It must use the
|
|
108
|
+
hyphenated `8-4-4-4-12` hexadecimal form, with no braces or surrounding whitespace;
|
|
109
|
+
upper- and lowercase hexadecimal are accepted. Replace the placeholder in the
|
|
110
|
+
examples before running them. This is not the app's bundle ID or package name.
|
|
111
|
+
|
|
112
|
+
Choose your enterprise's production region: `US` (default) or `EU`. Set
|
|
113
|
+
`creatorModeEnabled: true` only when you want the native Creator interface;
|
|
114
|
+
it defaults to `false`. There are no public custom-endpoint or dev/UAT options.
|
|
115
|
+
|
|
116
|
+
Importing the npm module before initialization is safe. Invoke it only after the
|
|
117
|
+
native runtime is ready, once from app startup rather than on every route change.
|
|
118
|
+
|
|
119
|
+
### Ionic Angular With Capacitor
|
|
120
|
+
|
|
121
|
+
Create an application helper, for example `whatfix.ts`. Its `Platform` argument
|
|
122
|
+
is supplied by Ionic dependency injection in the root component shown below.
|
|
123
|
+
The helper waits for `Platform.ready()` before making any native calls.
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { Platform } from '@ionic/angular';
|
|
127
|
+
import { WhatfixMobile } from '@whatfix_mobile/ionic-sdk';
|
|
128
|
+
|
|
129
|
+
export async function initializeWhatfix(platform: Platform): Promise<void> {
|
|
130
|
+
await platform.ready();
|
|
131
|
+
await WhatfixMobile.start({
|
|
132
|
+
enterpriseId: 'YOUR-ENTERPRISE-UUID',
|
|
133
|
+
creatorModeEnabled: false,
|
|
134
|
+
region: 'US',
|
|
135
|
+
});
|
|
136
|
+
await WhatfixMobile.setUserId('user-123');
|
|
137
|
+
await WhatfixMobile.setAppLocale('en');
|
|
138
|
+
await WhatfixMobile.addTextProperty('plan', 'standard');
|
|
139
|
+
await WhatfixMobile.addNumberProperty('orders', 3);
|
|
140
|
+
await WhatfixMobile.addDateProperty('joined', new Date(), 'YYYYMMDD');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function handleWhatfixError(error: unknown): void {
|
|
144
|
+
const code = (error as { code?: string } | null)?.code;
|
|
145
|
+
switch (code) {
|
|
146
|
+
case 'INVALID_ARGUMENT':
|
|
147
|
+
console.warn('Whatfix: check the enterprise UUID and method arguments.');
|
|
148
|
+
break;
|
|
149
|
+
case 'UNAVAILABLE':
|
|
150
|
+
console.warn('Whatfix: install/sync the plugin and wait for native readiness.');
|
|
151
|
+
break;
|
|
152
|
+
case 'UNSUPPORTED_PLATFORM':
|
|
153
|
+
console.warn('Whatfix: use a native Android or iOS application.');
|
|
154
|
+
break;
|
|
155
|
+
case 'NATIVE_START_REJECTED':
|
|
156
|
+
console.warn('Whatfix: Android rejected initialization; check native configuration.');
|
|
157
|
+
break;
|
|
158
|
+
default:
|
|
159
|
+
console.warn('Whatfix: the native operation could not be dispatched.');
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
In your existing root component, keep its template/decorator and merge this into
|
|
165
|
+
its imports and constructor. Do not call it from a repeatedly created page:
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
import { Platform } from '@ionic/angular';
|
|
169
|
+
import { initializeWhatfix, handleWhatfixError } from './whatfix';
|
|
170
|
+
|
|
171
|
+
// Inside the existing AppComponent class:
|
|
172
|
+
constructor(platform: Platform) {
|
|
173
|
+
void initializeWhatfix(platform).catch(handleWhatfixError);
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
For another Ionic UI framework, put the same SDK calls in that application's
|
|
178
|
+
native-ready startup lifecycle; Ionic Angular's `Platform` service is not a
|
|
179
|
+
general Capacitor API. A page load in a desktop browser is not native readiness.
|
|
180
|
+
|
|
181
|
+
### Plain Cordova
|
|
182
|
+
|
|
183
|
+
Keep the generated app's `cordova.js` script. Load the following application
|
|
184
|
+
JavaScript before `deviceready` fires; the installed plugin supplies
|
|
185
|
+
`window.WhatfixMobile`, so a separate npm import is unnecessary:
|
|
186
|
+
|
|
187
|
+
```js
|
|
188
|
+
document.addEventListener('deviceready', async function () {
|
|
189
|
+
const sdk = window.WhatfixMobile;
|
|
190
|
+
if (!sdk) {
|
|
191
|
+
console.warn('Whatfix: plugin is unavailable; check installation and prepare.');
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
try {
|
|
195
|
+
await sdk.start({
|
|
196
|
+
enterpriseId: 'YOUR-ENTERPRISE-UUID',
|
|
197
|
+
creatorModeEnabled: false,
|
|
198
|
+
region: 'US',
|
|
199
|
+
});
|
|
200
|
+
await sdk.setUserId('user-123');
|
|
201
|
+
await sdk.setAppLocale('en');
|
|
202
|
+
await sdk.addTextProperty('plan', 'standard');
|
|
203
|
+
await sdk.addNumberProperty('orders', 3);
|
|
204
|
+
await sdk.addDateProperty('joined', new Date(), 'YYYYMMDD');
|
|
205
|
+
} catch (error) {
|
|
206
|
+
// Handle the stable code; do not log user/property values or raw native errors.
|
|
207
|
+
console.warn('Whatfix SDK error:', error && error.code || 'NATIVE_ERROR');
|
|
208
|
+
}
|
|
209
|
+
}, { once: true });
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Flush, Logout And Disable
|
|
213
|
+
|
|
214
|
+
These example application handlers are for separate user/app actions, not a
|
|
215
|
+
sequence to run automatically at startup. In plain Cordova, use the same methods
|
|
216
|
+
on `window.WhatfixMobile` after `deviceready`.
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
import { WhatfixMobile } from '@whatfix_mobile/ionic-sdk';
|
|
220
|
+
|
|
221
|
+
export async function requestWhatfixFlush(): Promise<void> {
|
|
222
|
+
await WhatfixMobile.flush();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export async function notifyWhatfixOfLogout(): Promise<void> {
|
|
226
|
+
await WhatfixMobile.logout();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export async function disableWhatfixForThisProcess(): Promise<void> {
|
|
230
|
+
await WhatfixMobile.disable();
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Catch rejected promises from these handlers using the error handling above.
|
|
235
|
+
`flush()` respects native consent/network policy and does not promise delivery.
|
|
236
|
+
Call `logout()` when the host user signs out; it is not a stop/reset API.
|
|
237
|
+
Use `disable()` only for an intentional terminal shutdown: calling `start()`
|
|
238
|
+
afterward cannot re-enable the SDK in that app process. Relaunch the app instead.
|
|
239
|
+
|
|
240
|
+
All methods return `Promise<void>`. Resolution acknowledges native dispatch, **not
|
|
241
|
+
successful configuration, Creator initialization, or overlay readiness**. Android
|
|
242
|
+
can synchronously reject startup; the native iOS start API returns no result.
|
|
243
|
+
|
|
244
|
+
| Method | Contract |
|
|
245
|
+
| --- | --- |
|
|
246
|
+
| `start(options)` | Required enterprise UUID; Creator defaults to `false`, region to `US`; `EU` also supported |
|
|
247
|
+
| `setUserId(userId)` | Nonblank string |
|
|
248
|
+
| `setAppLocale(localeCode)` | Nonblank string, interpreted by the native SDK |
|
|
249
|
+
| `addTextProperty(key, value)` | Nonblank key; string value (native SDK may ignore empty values) |
|
|
250
|
+
| `addNumberProperty(key, value)` | Nonblank key; finite number, not numeric text or boolean |
|
|
251
|
+
| `addDateProperty(key, value, format)` | Date or integer Unix milliseconds within the JavaScript Date range |
|
|
252
|
+
| `flush()` | Requests native flush subject to native consent/runtime policy; not a delivery receipt |
|
|
253
|
+
| `logout()` | Forwards native logout; not an overlay stop/reset API |
|
|
254
|
+
| `disable()` | Terminal for the app process, even before start; app relaunch required |
|
|
255
|
+
|
|
256
|
+
Date formats: `DDMMYYYY`, `MMDDYYYY`, `YYYYMMDD`, `YYYYDDMM`, `DDMonthYYYY`,
|
|
257
|
+
`MonthDDYYYY`. The format is required; dates cross the bridge as milliseconds.
|
|
258
|
+
Await calls when their order matters. Navigation/reset does not call `disable()`.
|
|
259
|
+
Repeated `start()` behavior remains native-owned; there is no wrapper restart API.
|
|
260
|
+
|
|
261
|
+
Errors have a stable `code`: `INVALID_ARGUMENT`, `UNAVAILABLE`,
|
|
262
|
+
`UNSUPPORTED_PLATFORM`, `NATIVE_START_REJECTED`, or `NATIVE_ERROR`. Messages are
|
|
263
|
+
fixed and do not include enterprise IDs, property values, or raw native errors.
|
|
264
|
+
`NATIVE_START_REJECTED` is Android-only; iOS does not report native startup
|
|
265
|
+
acceptance through this API. The example handler's default covers `NATIVE_ERROR`.
|
|
266
|
+
JavaScript cannot contain native process crashes or Objective-C exceptions.
|
|
267
|
+
|
|
268
|
+
## Troubleshooting
|
|
269
|
+
|
|
270
|
+
| Symptom | What to check |
|
|
271
|
+
| --- | --- |
|
|
272
|
+
| `UNAVAILABLE`, or `window.WhatfixMobile` is missing | Install the package in the host app, run `npx cap sync` or `cordova prepare`, rebuild the native app, and wait for the framework's native-ready lifecycle before calling. A web-only reload cannot install native code. |
|
|
273
|
+
| Works in a native app but not `ionic serve` or a desktop browser | Browser-only execution is unsupported. Use an Android/iOS simulator or device build with the plugin installed; `UNAVAILABLE` is expected without a native bridge. |
|
|
274
|
+
| `INVALID_ARGUMENT` | Replace the enterprise placeholder with the issued UUID, use `US` or `EU`, and check the method table and required date format. Numbers must be finite numbers; dates must be valid dates or integer milliseconds. |
|
|
275
|
+
| Native start resolves but Creator/overlays do not appear | Resolution means dispatch only. Confirm the enterprise, region, native configuration, and whether Creator was requested. A prior `disable()` requires app relaunch; repeated start is not a restart API. |
|
|
276
|
+
| iOS dependency requires a higher deployment target | Set the app deployment target to iOS 15.0 or newer. Use Xcode 16 or newer, and Cordova iOS 8.2 or newer for Cordova hosts. |
|
|
277
|
+
| iOS build fails with `No such module 'WhatfixMobileSDK'`, or Cordova skips the plugin for iOS with a failed `cordova-ios` version requirement | The iOS project is not using Swift Package Manager. Upgrade Cordova iOS to 8.2 or newer, or migrate the Capacitor iOS project from CocoaPods to SPM. CocoaPods integration is not supported from 1.2.0. |
|
|
278
|
+
| iOS build fails with `requires minimum platform version 15.0 for the iOS platform` | The Capacitor iOS project was synced while its deployment target was below 15.0. Set the app deployment target to 15.0 or newer, then run `npx cap sync ios` again. |
|
|
279
|
+
| Gradle or SPM cannot find/download the native artifact | Check the exact native pin above, repository access, connectivity and the first dependency-resolution error. Android uses Maven Central; SPM downloads the published native package/binary from GitHub. Do not silently substitute another AAR/framework or bypass TLS checks. |
|
|
280
|
+
| iOS QR scanning does not request/open the camera | Supply `NSCameraUsageDescription`, enable the intended Creator flow, and check system camera permission. Do not add arbitrary network exceptions to address a camera-permission problem. |
|
|
281
|
+
|
|
282
|
+
## Observer And Safety
|
|
283
|
+
|
|
284
|
+
Native initialization, configuration, recovery and shutdown retain the existing
|
|
285
|
+
SDK Observer pipeline, consent, buffering, and delivery policy. The wrapper does
|
|
286
|
+
not force a flush on errors or build a second telemetry transport. Input failures
|
|
287
|
+
are returned to the caller without logging user values. There is no public native
|
|
288
|
+
Observer adapter exposed by this wrapper for wrapper-only failures. Do not assume
|
|
289
|
+
that a rejected JavaScript call creates an Observer event, or that mock dispatch
|
|
290
|
+
tests prove native event delivery.
|
|
291
|
+
|
|
292
|
+
The native production SDK's WebView-inspection policy is inherited unchanged.
|
|
293
|
+
Check your enterprise configuration before distributing the host: on Android,
|
|
294
|
+
WebView debugging is process-wide, not restricted to the SDK overlay.
|
|
295
|
+
|
|
296
|
+
## Release Notes
|
|
297
|
+
|
|
298
|
+
### 1.2.0
|
|
299
|
+
|
|
300
|
+
- **Breaking:** CocoaPods integration is removed. iOS hosts must use Swift Package
|
|
301
|
+
Manager: Cordova iOS 8.2 or newer, or a Capacitor iOS project created with or
|
|
302
|
+
migrated to SPM. Android hosts are not affected.
|
|
303
|
+
- Uses production Android and iOS native SDK dependencies pinned to 1.2.0.
|
|
304
|
+
- With native SDK 1.2.0, an overlay fault switches off only the overlay by default
|
|
305
|
+
and it restarts when the app next returns to the foreground. An explicit
|
|
306
|
+
`safety.kill_switch: true` in the remote configuration keeps the SDK-wide shutdown.
|
|
307
|
+
- No change to the JavaScript API.
|
|
308
|
+
|
|
309
|
+
### 1.1.1
|
|
310
|
+
|
|
311
|
+
- Uses production Android and iOS native SDK dependencies pinned to 1.1.1.
|
|
312
|
+
- Provides the shared typed Cordova/Capacitor bridge for initialization, identity,
|
|
313
|
+
properties, flush, logout, and terminal disable.
|
|
314
|
+
- Supported iOS integration through CocoaPods or SPM. JavaScript promises
|
|
315
|
+
acknowledge dispatch, not native readiness or delivery.
|
|
316
|
+
|
|
317
|
+
The package includes `CHANGELOG.md`. Its
|
|
318
|
+
[full changelog](https://unpkg.com/@whatfix_mobile/ionic-sdk@1.2.0/CHANGELOG.md) is also
|
|
319
|
+
available from the public package CDN after version 1.2.0 is published. These
|
|
320
|
+
inline notes do not require repository access or a separate npm changelog tab.
|
|
321
|
+
|
|
322
|
+
## License
|
|
323
|
+
|
|
324
|
+
The Whatfix Mobile SDK License Agreement is included unchanged as `LICENSE.pdf`
|
|
325
|
+
in this package. Read the full agreement before downloading, installing or using
|
|
326
|
+
the SDK. After publication, the PDF is also available from the
|
|
327
|
+
[public package CDN](https://unpkg.com/@whatfix_mobile/ionic-sdk@1.2.0/LICENSE.pdf).
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type WhatfixRegion = 'US' | 'EU';
|
|
2
|
+
export type WhatfixDateFormat =
|
|
3
|
+
| 'DDMMYYYY' | 'MMDDYYYY' | 'YYYYMMDD' | 'YYYYDDMM'
|
|
4
|
+
| 'DDMonthYYYY' | 'MonthDDYYYY';
|
|
5
|
+
|
|
6
|
+
export interface WhatfixStartOptions {
|
|
7
|
+
/** Enterprise UUID supplied by Whatfix. */
|
|
8
|
+
enterpriseId: string;
|
|
9
|
+
creatorModeEnabled?: boolean;
|
|
10
|
+
/** Defaults to US. Applies to production native SDK artifacts. */
|
|
11
|
+
region?: WhatfixRegion;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface WhatfixError extends Error {
|
|
15
|
+
code: 'INVALID_ARGUMENT' | 'UNAVAILABLE' | 'UNSUPPORTED_PLATFORM' |
|
|
16
|
+
'NATIVE_START_REJECTED' | 'NATIVE_ERROR';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface WhatfixMobilePlugin {
|
|
20
|
+
/**
|
|
21
|
+
* Resolves after native dispatch, not after configuration or overlay readiness.
|
|
22
|
+
* NATIVE_START_REJECTED is Android-only; the iOS SDK's start method returns void.
|
|
23
|
+
*/
|
|
24
|
+
start(options: WhatfixStartOptions): Promise<void>;
|
|
25
|
+
setUserId(userId: string): Promise<void>;
|
|
26
|
+
setAppLocale(localeCode: string): Promise<void>;
|
|
27
|
+
addTextProperty(key: string, value: string): Promise<void>;
|
|
28
|
+
addNumberProperty(key: string, value: number): Promise<void>;
|
|
29
|
+
/** Date or integer Unix timestamp in milliseconds; format is explicitly required. */
|
|
30
|
+
addDateProperty(key: string, value: Date | number, format: WhatfixDateFormat): Promise<void>;
|
|
31
|
+
flush(): Promise<void>;
|
|
32
|
+
logout(): Promise<void>;
|
|
33
|
+
/** Terminal for this app process, even before start. Not a restartable stop API. */
|
|
34
|
+
disable(): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const WhatfixMobile: WhatfixMobilePlugin;
|
|
38
|
+
|
|
39
|
+
declare global {
|
|
40
|
+
interface Window {
|
|
41
|
+
/** Available after the Cordova-compatible runtime has initialized the plugin. */
|
|
42
|
+
WhatfixMobile?: WhatfixMobilePlugin;
|
|
43
|
+
}
|
|
44
|
+
}
|
package/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whatfix_mobile/ionic-sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Whatfix native SDK bridge for Ionic apps using Cordova or Capacitor",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"index.js",
|
|
9
|
+
"index.d.ts",
|
|
10
|
+
"www/",
|
|
11
|
+
"src/android/",
|
|
12
|
+
"src/ios/",
|
|
13
|
+
"plugin.xml",
|
|
14
|
+
"Package.swift",
|
|
15
|
+
"README.md",
|
|
16
|
+
"CHANGELOG.md",
|
|
17
|
+
"LICENSE.pdf"
|
|
18
|
+
],
|
|
19
|
+
"cordova": {
|
|
20
|
+
"id": "com.whatfix.ionic",
|
|
21
|
+
"platforms": [
|
|
22
|
+
"android",
|
|
23
|
+
"ios"
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/whatfix/ionic-sdk.git"
|
|
29
|
+
},
|
|
30
|
+
"license": "SEE LICENSE IN LICENSE.pdf",
|
|
31
|
+
"keywords": [
|
|
32
|
+
"ionic",
|
|
33
|
+
"cordova",
|
|
34
|
+
"capacitor",
|
|
35
|
+
"ecosystem:cordova",
|
|
36
|
+
"cordova-android",
|
|
37
|
+
"cordova-ios",
|
|
38
|
+
"whatfix"
|
|
39
|
+
],
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": "^20.19.0 || ^22.13.0 || >=24.0.0"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"lint": "eslint index.js www/ scripts/ --max-warnings 0",
|
|
45
|
+
"test": "node --test tests/js/*.test.cjs",
|
|
46
|
+
"test:types": "tsc -p tests/types/tsconfig.json",
|
|
47
|
+
"test:package": "node tests/integration/verify-package.mjs",
|
|
48
|
+
"test:release": "node --test tests/integration/npm-release.test.mjs tests/integration/github-release.test.mjs tests/integration/package-validation.test.cjs && python3 -m unittest discover -s tests/integration -p 'test_*release.py'",
|
|
49
|
+
"check": "npm test && npm run test:types && npm run test:package"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"eslint": "10.15.0",
|
|
53
|
+
"typescript": "5.9.3"
|
|
54
|
+
}
|
|
55
|
+
}
|
package/plugin.xml
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
|
3
|
+
id="com.whatfix.ionic" version="1.2.0">
|
|
4
|
+
<name>WhatfixMobile</name>
|
|
5
|
+
<description>Whatfix native SDK bridge for Cordova and Capacitor</description>
|
|
6
|
+
<license>SEE LICENSE IN LICENSE.pdf</license>
|
|
7
|
+
<engines>
|
|
8
|
+
<engine name="cordova-android" version=">=13.0.0" />
|
|
9
|
+
<engine name="cordova-ios" version=">=8.2.0" />
|
|
10
|
+
</engines>
|
|
11
|
+
<js-module src="www/whatfix-mobile.js" name="WhatfixMobile">
|
|
12
|
+
<clobbers target="WhatfixMobile" />
|
|
13
|
+
</js-module>
|
|
14
|
+
<platform name="android">
|
|
15
|
+
<config-file target="res/xml/config.xml" parent="/*">
|
|
16
|
+
<feature name="WhatfixMobile">
|
|
17
|
+
<param name="android-package" value="com.whatfix.ionic.WhatfixMobilePlugin" />
|
|
18
|
+
</feature>
|
|
19
|
+
</config-file>
|
|
20
|
+
<source-file src="src/android/WhatfixMobilePlugin.java" target-dir="src/com/whatfix/ionic" />
|
|
21
|
+
<framework src="com.whatfix.android:whatfix-mobile-sdk:1.2.0" />
|
|
22
|
+
</platform>
|
|
23
|
+
<platform name="ios" package="swift">
|
|
24
|
+
<config-file target="config.xml" parent="/*">
|
|
25
|
+
<feature name="WhatfixMobile">
|
|
26
|
+
<param name="ios-package" value="WhatfixMobilePlugin" />
|
|
27
|
+
</feature>
|
|
28
|
+
</config-file>
|
|
29
|
+
<source-file src="src/ios/WhatfixMobilePlugin.swift" />
|
|
30
|
+
</platform>
|
|
31
|
+
</plugin>
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
package com.whatfix.ionic;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.os.Handler;
|
|
5
|
+
import android.os.Looper;
|
|
6
|
+
|
|
7
|
+
import com.whatfix.sdk.WhatfixMobile;
|
|
8
|
+
import com.whatfix.sdk.model.WhatfixDateFormat;
|
|
9
|
+
import com.whatfix.sdk.model.WhatfixRegion;
|
|
10
|
+
|
|
11
|
+
import org.apache.cordova.CallbackContext;
|
|
12
|
+
import org.apache.cordova.CordovaPlugin;
|
|
13
|
+
import org.json.JSONArray;
|
|
14
|
+
import org.json.JSONException;
|
|
15
|
+
import org.json.JSONObject;
|
|
16
|
+
|
|
17
|
+
import java.util.Date;
|
|
18
|
+
import java.util.Iterator;
|
|
19
|
+
import java.util.Locale;
|
|
20
|
+
import java.util.regex.Pattern;
|
|
21
|
+
import java.math.BigDecimal;
|
|
22
|
+
|
|
23
|
+
/** A dispatch-only bridge. SDK readiness, consent and lifecycle remain native-owned. */
|
|
24
|
+
public final class WhatfixMobilePlugin extends CordovaPlugin {
|
|
25
|
+
private static final Pattern ENTERPRISE_ID = Pattern.compile(
|
|
26
|
+
"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}");
|
|
27
|
+
// Match the whitespace accepted by JavaScript String.trim(), without changing values.
|
|
28
|
+
private static final Pattern BLANK = Pattern.compile(
|
|
29
|
+
"[\\x09-\\x0d\\x20\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000\\ufeff]*");
|
|
30
|
+
private static final long MAX_DATE_MILLIS = 8640000000000000L;
|
|
31
|
+
private final Handler mainThread = new Handler(Looper.getMainLooper());
|
|
32
|
+
|
|
33
|
+
@Override
|
|
34
|
+
public boolean execute(String action, JSONArray args, CallbackContext callback) {
|
|
35
|
+
if (!knownAction(action)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
final NativeCall call;
|
|
40
|
+
try {
|
|
41
|
+
call = parse(action, args);
|
|
42
|
+
} catch (IllegalArgumentException | JSONException exception) {
|
|
43
|
+
fail(callback, "INVALID_ARGUMENT", "Invalid Whatfix arguments.");
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Always post, including calls already on Main, to retain FIFO dispatch.
|
|
48
|
+
Runnable dispatch = () -> {
|
|
49
|
+
try {
|
|
50
|
+
Activity activity = cordova == null ? null : cordova.getActivity();
|
|
51
|
+
if (activity == null || activity.isFinishing() || activity.isDestroyed()) {
|
|
52
|
+
fail(callback, "UNAVAILABLE", "A live host Activity is required.");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (!call.run(activity)) {
|
|
56
|
+
fail(callback, "NATIVE_START_REJECTED", "Whatfix startup was rejected.");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
callback.success();
|
|
60
|
+
} catch (Exception exception) {
|
|
61
|
+
fail(callback, "NATIVE_ERROR", "Whatfix native dispatch failed.");
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
try {
|
|
65
|
+
if (!mainThread.post(dispatch)) {
|
|
66
|
+
fail(callback, "UNAVAILABLE", "The host main thread is unavailable.");
|
|
67
|
+
}
|
|
68
|
+
} catch (RuntimeException exception) {
|
|
69
|
+
fail(callback, "NATIVE_ERROR", "Whatfix native dispatch failed.");
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private static boolean knownAction(String action) {
|
|
75
|
+
return "start".equals(action) || "setUserId".equals(action)
|
|
76
|
+
|| "setAppLocale".equals(action) || "addTextProperty".equals(action)
|
|
77
|
+
|| "addNumberProperty".equals(action) || "addDateProperty".equals(action)
|
|
78
|
+
|| "flush".equals(action) || "logout".equals(action) || "disable".equals(action);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private static NativeCall parse(String action, JSONArray args) throws JSONException {
|
|
82
|
+
if (args == null) {
|
|
83
|
+
throw new IllegalArgumentException();
|
|
84
|
+
}
|
|
85
|
+
if ("flush".equals(action) || "logout".equals(action) || "disable".equals(action)) {
|
|
86
|
+
if (args.length() != 0) {
|
|
87
|
+
throw new IllegalArgumentException();
|
|
88
|
+
}
|
|
89
|
+
return activity -> {
|
|
90
|
+
switch (action) {
|
|
91
|
+
case "flush": WhatfixMobile.flush(); break;
|
|
92
|
+
case "logout": WhatfixMobile.logout(); break;
|
|
93
|
+
default: WhatfixMobile.disable(); break;
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (args.length() != 1 || !(args.get(0) instanceof JSONObject)) {
|
|
99
|
+
throw new IllegalArgumentException();
|
|
100
|
+
}
|
|
101
|
+
JSONObject payload = (JSONObject) args.get(0);
|
|
102
|
+
switch (action) {
|
|
103
|
+
case "start": {
|
|
104
|
+
keys(payload, "enterpriseId", "creatorModeEnabled", "region");
|
|
105
|
+
String enterpriseId = string(payload, "enterpriseId");
|
|
106
|
+
if (!ENTERPRISE_ID.matcher(enterpriseId).matches()) {
|
|
107
|
+
throw new IllegalArgumentException();
|
|
108
|
+
}
|
|
109
|
+
String canonicalEnterpriseId = enterpriseId.toLowerCase(Locale.ROOT);
|
|
110
|
+
boolean creator = false;
|
|
111
|
+
if (payload.has("creatorModeEnabled")) {
|
|
112
|
+
Object value = payload.get("creatorModeEnabled");
|
|
113
|
+
if (!(value instanceof Boolean)) throw new IllegalArgumentException();
|
|
114
|
+
creator = (Boolean) value;
|
|
115
|
+
}
|
|
116
|
+
String region = payload.has("region") ? string(payload, "region") : "US";
|
|
117
|
+
if (!"US".equals(region) && !"EU".equals(region)) {
|
|
118
|
+
throw new IllegalArgumentException();
|
|
119
|
+
}
|
|
120
|
+
boolean creatorMode = creator;
|
|
121
|
+
WhatfixRegion nativeRegion = "EU".equals(region)
|
|
122
|
+
? WhatfixRegion.EU : WhatfixRegion.UNSPECIFIED;
|
|
123
|
+
return activity -> WhatfixMobile.startWithApplicationContext(
|
|
124
|
+
activity.getApplication(), canonicalEnterpriseId, creatorMode, nativeRegion);
|
|
125
|
+
}
|
|
126
|
+
case "setUserId": {
|
|
127
|
+
keys(payload, "userId");
|
|
128
|
+
String value = nonBlank(payload, "userId");
|
|
129
|
+
return activity -> { WhatfixMobile.setUserId(value); return true; };
|
|
130
|
+
}
|
|
131
|
+
case "setAppLocale": {
|
|
132
|
+
keys(payload, "localeCode");
|
|
133
|
+
String value = nonBlank(payload, "localeCode");
|
|
134
|
+
return activity -> { WhatfixMobile.setAppLocale(value); return true; };
|
|
135
|
+
}
|
|
136
|
+
case "addTextProperty": {
|
|
137
|
+
keys(payload, "key", "value");
|
|
138
|
+
String key = nonBlank(payload, "key");
|
|
139
|
+
String value = string(payload, "value");
|
|
140
|
+
return activity -> { WhatfixMobile.addTextProperty(key, value); return true; };
|
|
141
|
+
}
|
|
142
|
+
case "addNumberProperty": {
|
|
143
|
+
keys(payload, "key", "value");
|
|
144
|
+
String key = nonBlank(payload, "key");
|
|
145
|
+
Number value = number(payload, "value");
|
|
146
|
+
return activity -> { WhatfixMobile.addNumberProperty(key, value); return true; };
|
|
147
|
+
}
|
|
148
|
+
case "addDateProperty": {
|
|
149
|
+
keys(payload, "key", "value", "format");
|
|
150
|
+
String key = nonBlank(payload, "key");
|
|
151
|
+
long millis;
|
|
152
|
+
try {
|
|
153
|
+
millis = new BigDecimal(number(payload, "value").toString()).longValueExact();
|
|
154
|
+
} catch (ArithmeticException exception) {
|
|
155
|
+
throw new IllegalArgumentException();
|
|
156
|
+
}
|
|
157
|
+
if (millis < -MAX_DATE_MILLIS || millis > MAX_DATE_MILLIS) {
|
|
158
|
+
throw new IllegalArgumentException();
|
|
159
|
+
}
|
|
160
|
+
Date value = new Date(millis);
|
|
161
|
+
WhatfixDateFormat format = dateFormat(string(payload, "format"));
|
|
162
|
+
return activity -> { WhatfixMobile.addDateProperty(key, value, format); return true; };
|
|
163
|
+
}
|
|
164
|
+
default: throw new IllegalArgumentException();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private static void keys(JSONObject object, String... allowed) {
|
|
169
|
+
Iterator<String> iterator = object.keys();
|
|
170
|
+
while (iterator.hasNext()) {
|
|
171
|
+
String key = iterator.next();
|
|
172
|
+
boolean found = false;
|
|
173
|
+
for (String candidate : allowed) {
|
|
174
|
+
if (candidate.equals(key)) { found = true; break; }
|
|
175
|
+
}
|
|
176
|
+
if (!found) throw new IllegalArgumentException();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private static String string(JSONObject object, String key) throws JSONException {
|
|
181
|
+
Object value = object.get(key);
|
|
182
|
+
if (!(value instanceof String)) throw new IllegalArgumentException();
|
|
183
|
+
return (String) value;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
private static Number number(JSONObject object, String key) throws JSONException {
|
|
187
|
+
Object value = object.get(key);
|
|
188
|
+
if (!(value instanceof Number)) throw new IllegalArgumentException();
|
|
189
|
+
double numeric = ((Number) value).doubleValue();
|
|
190
|
+
if (Double.isNaN(numeric) || Double.isInfinite(numeric)) {
|
|
191
|
+
throw new IllegalArgumentException();
|
|
192
|
+
}
|
|
193
|
+
return (Number) value;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private static String nonBlank(JSONObject object, String key) throws JSONException {
|
|
197
|
+
String value = string(object, key);
|
|
198
|
+
if (BLANK.matcher(value).matches()) throw new IllegalArgumentException();
|
|
199
|
+
return value;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private static WhatfixDateFormat dateFormat(String format) {
|
|
203
|
+
switch (format) {
|
|
204
|
+
case "DDMMYYYY": return WhatfixDateFormat.DDMMYYYY;
|
|
205
|
+
case "MMDDYYYY": return WhatfixDateFormat.MMDDYYYY;
|
|
206
|
+
case "YYYYMMDD": return WhatfixDateFormat.YYYYMMDD;
|
|
207
|
+
case "YYYYDDMM": return WhatfixDateFormat.YYYYDDMM;
|
|
208
|
+
case "DDMonthYYYY": return WhatfixDateFormat.DD_MONTH_YYYY;
|
|
209
|
+
case "MonthDDYYYY": return WhatfixDateFormat.MONTH_DD_YYYY;
|
|
210
|
+
default: throw new IllegalArgumentException();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private static void fail(CallbackContext callback, String code, String message) {
|
|
215
|
+
JSONObject error = new JSONObject();
|
|
216
|
+
try {
|
|
217
|
+
error.put("code", code);
|
|
218
|
+
error.put("message", message);
|
|
219
|
+
} catch (JSONException impossible) {
|
|
220
|
+
throw new IllegalStateException("Unable to encode bridge error.");
|
|
221
|
+
}
|
|
222
|
+
callback.error(error);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
private interface NativeCall {
|
|
226
|
+
boolean run(Activity activity);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import CoreFoundation
|
|
3
|
+
#if canImport(Cordova)
|
|
4
|
+
import Cordova
|
|
5
|
+
#endif
|
|
6
|
+
import WhatfixMobileSDK
|
|
7
|
+
|
|
8
|
+
enum WhatfixAction {
|
|
9
|
+
case start, setUserId, setAppLocale, addTextProperty, addNumberProperty, addDateProperty
|
|
10
|
+
case flush, logout, disable
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
enum WhatfixBridgeError: Error {
|
|
14
|
+
case invalidArgument
|
|
15
|
+
|
|
16
|
+
var payload: [String: String] {
|
|
17
|
+
["code": "INVALID_ARGUMENT", "message": "Invalid arguments for the requested operation."]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/// Validated calls only. The native SDK owns lifecycle, threading after invocation, and Observer.
|
|
22
|
+
enum WhatfixInvocation: Equatable {
|
|
23
|
+
case start(String, Bool, WFRegion)
|
|
24
|
+
case setUserId(String)
|
|
25
|
+
case setAppLocale(String)
|
|
26
|
+
case addTextProperty(String, String)
|
|
27
|
+
case addNumberProperty(String, Double)
|
|
28
|
+
case addDateProperty(String, Date, WFDateFormat)
|
|
29
|
+
case flush, logout, disable
|
|
30
|
+
|
|
31
|
+
static func decode(_ action: WhatfixAction, arguments: [Any]) throws -> WhatfixInvocation {
|
|
32
|
+
switch action {
|
|
33
|
+
case .flush, .logout, .disable:
|
|
34
|
+
guard arguments.isEmpty else { throw WhatfixBridgeError.invalidArgument }
|
|
35
|
+
switch action {
|
|
36
|
+
case .flush: return .flush
|
|
37
|
+
case .logout: return .logout
|
|
38
|
+
default: return .disable
|
|
39
|
+
}
|
|
40
|
+
default: break
|
|
41
|
+
}
|
|
42
|
+
guard arguments.count == 1, let object = arguments[0] as? [String: Any] else {
|
|
43
|
+
throw WhatfixBridgeError.invalidArgument
|
|
44
|
+
}
|
|
45
|
+
let allowedKeys: Set<String>
|
|
46
|
+
switch action {
|
|
47
|
+
case .start: allowedKeys = ["enterpriseId", "creatorModeEnabled", "region"]
|
|
48
|
+
case .setUserId: allowedKeys = ["userId"]
|
|
49
|
+
case .setAppLocale: allowedKeys = ["localeCode"]
|
|
50
|
+
case .addTextProperty, .addNumberProperty: allowedKeys = ["key", "value"]
|
|
51
|
+
case .addDateProperty: allowedKeys = ["key", "value", "format"]
|
|
52
|
+
case .flush, .logout, .disable: allowedKeys = []
|
|
53
|
+
}
|
|
54
|
+
guard object.keys.allSatisfy(allowedKeys.contains) else { throw WhatfixBridgeError.invalidArgument }
|
|
55
|
+
switch action {
|
|
56
|
+
case .start:
|
|
57
|
+
let enterprise = try string(object["enterpriseId"])
|
|
58
|
+
guard enterprise.utf8.count == 36, UUID(uuidString: enterprise) != nil else {
|
|
59
|
+
throw WhatfixBridgeError.invalidArgument
|
|
60
|
+
}
|
|
61
|
+
var creator = false
|
|
62
|
+
if let value = object["creatorModeEnabled"] {
|
|
63
|
+
guard let number = value as? NSNumber, CFGetTypeID(number) == CFBooleanGetTypeID() else {
|
|
64
|
+
throw WhatfixBridgeError.invalidArgument
|
|
65
|
+
}
|
|
66
|
+
creator = number.boolValue
|
|
67
|
+
}
|
|
68
|
+
var region = WFRegion.unspecified
|
|
69
|
+
if let value = object["region"] {
|
|
70
|
+
guard let value = value as? String, value == "US" || value == "EU" else {
|
|
71
|
+
throw WhatfixBridgeError.invalidArgument
|
|
72
|
+
}
|
|
73
|
+
region = value == "EU" ? .eu : .unspecified
|
|
74
|
+
}
|
|
75
|
+
return .start(enterprise.lowercased(), creator, region)
|
|
76
|
+
case .setUserId: return .setUserId(try string(object["userId"]))
|
|
77
|
+
case .setAppLocale: return .setAppLocale(try string(object["localeCode"]))
|
|
78
|
+
case .addTextProperty:
|
|
79
|
+
guard let value = object["value"] as? String else { throw WhatfixBridgeError.invalidArgument }
|
|
80
|
+
return .addTextProperty(try string(object["key"]), value)
|
|
81
|
+
case .addNumberProperty:
|
|
82
|
+
return .addNumberProperty(try string(object["key"]), try number(object["value"]))
|
|
83
|
+
case .addDateProperty:
|
|
84
|
+
let key = try string(object["key"]), milliseconds = try number(object["value"])
|
|
85
|
+
guard milliseconds.rounded() == milliseconds, abs(milliseconds) <= 8_640_000_000_000_000,
|
|
86
|
+
let name = object["format"] as? String else { throw WhatfixBridgeError.invalidArgument }
|
|
87
|
+
let format: WFDateFormat
|
|
88
|
+
switch name {
|
|
89
|
+
case "DDMMYYYY": format = .DDMMYYYY
|
|
90
|
+
case "MMDDYYYY": format = .MMDDYYYY
|
|
91
|
+
case "YYYYMMDD": format = .YYYYMMDD
|
|
92
|
+
case "YYYYDDMM": format = .YYYYDDMM
|
|
93
|
+
case "DDMonthYYYY": format = .DDMonthYYYY
|
|
94
|
+
case "MonthDDYYYY": format = .MonthDDYYYY
|
|
95
|
+
default: throw WhatfixBridgeError.invalidArgument
|
|
96
|
+
}
|
|
97
|
+
return .addDateProperty(key, Date(timeIntervalSince1970: milliseconds / 1000), format)
|
|
98
|
+
case .flush, .logout, .disable: throw WhatfixBridgeError.invalidArgument
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private static func string(_ value: Any?) throws -> String {
|
|
103
|
+
guard let value = value as? String, !value.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
|
|
104
|
+
throw WhatfixBridgeError.invalidArgument
|
|
105
|
+
}
|
|
106
|
+
return value
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private static func number(_ value: Any?) throws -> Double {
|
|
110
|
+
guard let number = value as? NSNumber, CFGetTypeID(number) != CFBooleanGetTypeID(),
|
|
111
|
+
number.doubleValue.isFinite else { throw WhatfixBridgeError.invalidArgument }
|
|
112
|
+
return number.doubleValue
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
func dispatch() {
|
|
116
|
+
let sdk = WhatfixMobile.shared
|
|
117
|
+
switch self {
|
|
118
|
+
case let .start(enterprise, creator, region): sdk.start(entId: enterprise, creatorModeEnabled: creator, region: region)
|
|
119
|
+
case let .setUserId(value): sdk.setUserId(value)
|
|
120
|
+
case let .setAppLocale(value): sdk.setAppLocale(value)
|
|
121
|
+
case let .addTextProperty(key, value): sdk.addTextProperty(key, value)
|
|
122
|
+
case let .addNumberProperty(key, value): sdk.addNumberProperty(key, NSNumber(value: value))
|
|
123
|
+
case let .addDateProperty(key, value, format): sdk.addDateProperty(key, value, format: format)
|
|
124
|
+
case .flush: sdk.flush()
|
|
125
|
+
case .logout: sdk.logout()
|
|
126
|
+
case .disable: sdk.disable()
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@objc(WhatfixMobilePlugin)
|
|
132
|
+
final class WhatfixMobilePlugin: CDVPlugin {
|
|
133
|
+
// Internal seams exercise the actual command entry points without initializing a tenant.
|
|
134
|
+
var dispatchNative: (WhatfixInvocation) throws -> Void = { $0.dispatch() }
|
|
135
|
+
var sendResult: ((CDVPluginResult, String) -> Void)?
|
|
136
|
+
|
|
137
|
+
@objc(start:) func start(_ command: CDVInvokedUrlCommand) { enqueue(.start, command) }
|
|
138
|
+
@objc(setUserId:) func setUserId(_ command: CDVInvokedUrlCommand) { enqueue(.setUserId, command) }
|
|
139
|
+
@objc(setAppLocale:) func setAppLocale(_ command: CDVInvokedUrlCommand) { enqueue(.setAppLocale, command) }
|
|
140
|
+
@objc(addTextProperty:) func addTextProperty(_ command: CDVInvokedUrlCommand) { enqueue(.addTextProperty, command) }
|
|
141
|
+
@objc(addNumberProperty:) func addNumberProperty(_ command: CDVInvokedUrlCommand) { enqueue(.addNumberProperty, command) }
|
|
142
|
+
@objc(addDateProperty:) func addDateProperty(_ command: CDVInvokedUrlCommand) { enqueue(.addDateProperty, command) }
|
|
143
|
+
@objc(flush:) func flush(_ command: CDVInvokedUrlCommand) { enqueue(.flush, command) }
|
|
144
|
+
@objc(logout:) func logout(_ command: CDVInvokedUrlCommand) { enqueue(.logout, command) }
|
|
145
|
+
@objc(disable:) func disable(_ command: CDVInvokedUrlCommand) { enqueue(.disable, command) }
|
|
146
|
+
|
|
147
|
+
private func enqueue(_ action: WhatfixAction, _ command: CDVInvokedUrlCommand) {
|
|
148
|
+
// Always enqueue, including main-thread callers, to preserve native invocation FIFO.
|
|
149
|
+
DispatchQueue.main.async { [self] in
|
|
150
|
+
let result: CDVPluginResult
|
|
151
|
+
do {
|
|
152
|
+
let invocation = try WhatfixInvocation.decode(action, arguments: command.arguments ?? [])
|
|
153
|
+
try dispatchNative(invocation)
|
|
154
|
+
// Public SDK calls return void: OK acknowledges dispatch, never readiness.
|
|
155
|
+
result = CDVPluginResult(status: .ok)
|
|
156
|
+
} catch let error as WhatfixBridgeError {
|
|
157
|
+
result = CDVPluginResult(status: .error, messageAs: error.payload)
|
|
158
|
+
} catch {
|
|
159
|
+
result = CDVPluginResult(status: .error, messageAs: [
|
|
160
|
+
"code": "NATIVE_ERROR", "message": "The native SDK call could not be dispatched."
|
|
161
|
+
])
|
|
162
|
+
}
|
|
163
|
+
guard let callback = command.callbackId else { return }
|
|
164
|
+
if let sendResult { sendResult(result, callback) }
|
|
165
|
+
else { commandDelegate?.send(result, callbackId: callback) }
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var messages = {
|
|
4
|
+
INVALID_ARGUMENT: 'Invalid Whatfix SDK arguments.',
|
|
5
|
+
UNAVAILABLE: 'Whatfix requires an initialized native Cordova or Capacitor runtime.',
|
|
6
|
+
UNSUPPORTED_PLATFORM: 'Whatfix supports Android and iOS only.',
|
|
7
|
+
NATIVE_START_REJECTED: 'The native Whatfix SDK rejected initialization.',
|
|
8
|
+
NATIVE_ERROR: 'The native Whatfix operation could not be dispatched.'
|
|
9
|
+
};
|
|
10
|
+
var dateFormats = ['DDMMYYYY', 'MMDDYYYY', 'YYYYMMDD', 'YYYYDDMM', 'DDMonthYYYY', 'MonthDDYYYY'];
|
|
11
|
+
var uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
12
|
+
|
|
13
|
+
function error(code) {
|
|
14
|
+
var value = new Error(messages[code]);
|
|
15
|
+
value.name = 'WhatfixError';
|
|
16
|
+
value.code = code;
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function check(condition) {
|
|
21
|
+
if (!condition) throw error('INVALID_ARGUMENT');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function nonBlank(value) {
|
|
25
|
+
check(typeof value === 'string' && value.trim().length > 0);
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function invoke(action, argumentsFactory) {
|
|
30
|
+
return new Promise(function (resolve, reject) {
|
|
31
|
+
var args = argumentsFactory();
|
|
32
|
+
// Resolve the bridge at call time so importing before deviceready is safe.
|
|
33
|
+
var bridge = typeof globalThis !== 'undefined' && globalThis.cordova;
|
|
34
|
+
if (!bridge || typeof bridge.exec !== 'function') {
|
|
35
|
+
reject(error('UNAVAILABLE'));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (bridge.platformId !== 'android' && bridge.platformId !== 'ios') {
|
|
39
|
+
reject(error('UNSUPPORTED_PLATFORM'));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
bridge.exec(function () { resolve(); }, function (failure) {
|
|
44
|
+
var code = failure && typeof failure.code === 'string' &&
|
|
45
|
+
Object.prototype.hasOwnProperty.call(messages, failure.code) ? failure.code : 'NATIVE_ERROR';
|
|
46
|
+
reject(error(code));
|
|
47
|
+
}, 'WhatfixMobile', action, args);
|
|
48
|
+
} catch (_) {
|
|
49
|
+
reject(error('NATIVE_ERROR'));
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = {
|
|
55
|
+
start: function (options) {
|
|
56
|
+
return invoke('start', function () {
|
|
57
|
+
check(options !== null && typeof options === 'object' && !Array.isArray(options));
|
|
58
|
+
check(Object.keys(options).every(function (key) {
|
|
59
|
+
return ['enterpriseId', 'creatorModeEnabled', 'region'].indexOf(key) !== -1;
|
|
60
|
+
}));
|
|
61
|
+
check(typeof options.enterpriseId === 'string' && uuid.test(options.enterpriseId));
|
|
62
|
+
check(options.creatorModeEnabled === undefined || typeof options.creatorModeEnabled === 'boolean');
|
|
63
|
+
check(options.region === undefined || options.region === 'US' || options.region === 'EU');
|
|
64
|
+
return [{
|
|
65
|
+
enterpriseId: options.enterpriseId.toLowerCase(),
|
|
66
|
+
creatorModeEnabled: options.creatorModeEnabled === undefined ? false : options.creatorModeEnabled,
|
|
67
|
+
region: options.region === undefined ? 'US' : options.region
|
|
68
|
+
}];
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
setUserId: function (userId) {
|
|
72
|
+
return invoke('setUserId', function () { return [{ userId: nonBlank(userId) }]; });
|
|
73
|
+
},
|
|
74
|
+
setAppLocale: function (localeCode) {
|
|
75
|
+
return invoke('setAppLocale', function () { return [{ localeCode: nonBlank(localeCode) }]; });
|
|
76
|
+
},
|
|
77
|
+
addTextProperty: function (key, value) {
|
|
78
|
+
return invoke('addTextProperty', function () {
|
|
79
|
+
nonBlank(key);
|
|
80
|
+
check(typeof value === 'string');
|
|
81
|
+
return [{ key: key, value: value }];
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
addNumberProperty: function (key, value) {
|
|
85
|
+
return invoke('addNumberProperty', function () {
|
|
86
|
+
nonBlank(key);
|
|
87
|
+
check(typeof value === 'number' && Number.isFinite(value));
|
|
88
|
+
return [{ key: key, value: value }];
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
addDateProperty: function (key, value, format) {
|
|
92
|
+
return invoke('addDateProperty', function () {
|
|
93
|
+
nonBlank(key);
|
|
94
|
+
var timestamp = value instanceof Date ? value.getTime() : value;
|
|
95
|
+
check(typeof timestamp === 'number' && Number.isSafeInteger(timestamp) && Math.abs(timestamp) <= 8640000000000000);
|
|
96
|
+
check(dateFormats.indexOf(format) !== -1);
|
|
97
|
+
return [{ key: key, value: timestamp, format: format }];
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
flush: function () { return invoke('flush', function () { return []; }); },
|
|
101
|
+
logout: function () { return invoke('logout', function () { return []; }); },
|
|
102
|
+
disable: function () { return invoke('disable', function () { return []; }); }
|
|
103
|
+
};
|