@whatfix_mobile/ionic-sdk 0.0.0-stage → 1.1.1
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 +33 -0
- package/LICENSE.pdf +0 -0
- package/Package.swift +27 -0
- package/README.md +303 -2
- package/docs/npm-release.md +149 -0
- package/index.d.ts +44 -0
- package/index.js +3 -0
- package/package.json +19 -4
- package/plugin.xml +39 -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,33 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.1.1
|
|
4
|
+
|
|
5
|
+
- Pins the production native dependencies to Android SDK 1.1.1 and iOS SDK 1.1.1.
|
|
6
|
+
- Provides one typed JavaScript bridge for Cordova and Capacitor's Cordova
|
|
7
|
+
compatibility layer: initialization, user identity, locale, text/number/date
|
|
8
|
+
properties, flush, logout, and disable.
|
|
9
|
+
- Supports iOS integration through CocoaPods or Swift Package Manager without
|
|
10
|
+
linking a second copy of the native SDK.
|
|
11
|
+
- Documents npm registry installation, native prerequisites, dispatch semantics,
|
|
12
|
+
and release information directly in the package README.
|
|
13
|
+
- Includes the supplied Whatfix Mobile SDK License Agreement as `LICENSE.pdf`.
|
|
14
|
+
|
|
15
|
+
### Integration Notes
|
|
16
|
+
|
|
17
|
+
- Install with `npm install @whatfix_mobile/ionic-sdk` for Capacitor or
|
|
18
|
+
`cordova plugin add @whatfix_mobile/ionic-sdk` for Cordova. An exact `@1.1.1` pin is
|
|
19
|
+
optional for reproducible builds.
|
|
20
|
+
- The documented host matrix is Cordova Android 13, Cordova iOS 7 with
|
|
21
|
+
CocoaPods or 8.2+ with SPM, and Capacitor 7. iOS requires deployment target
|
|
22
|
+
15.0 or later; the native SPM package requires Swift 6 / Xcode 16 or later.
|
|
23
|
+
- Wait for the framework's native-ready event before calling the plugin.
|
|
24
|
+
Promise resolution acknowledges dispatch, not configuration acceptance,
|
|
25
|
+
overlay/Creator readiness, or telemetry delivery. Native iOS start returns
|
|
26
|
+
no acceptance result; Android can synchronously reject startup.
|
|
27
|
+
- `disable()` is terminal until app relaunch. Navigation does not reset or
|
|
28
|
+
restart the native SDK.
|
|
29
|
+
- Native configuration, consent and telemetry gates remain in force. Inspection
|
|
30
|
+
follows native policy; Android WebView debugging is process-wide. No wrapper
|
|
31
|
+
error forces an upload or bypasses native permissions.
|
|
32
|
+
- Browser-only execution is unsupported. The wrapper does not contain native
|
|
33
|
+
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.1.1")
|
|
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,304 @@
|
|
|
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.1.1` from Maven Central |
|
|
13
|
+
| iOS | `WhatfixMobileSDK` `1.1.1` through CocoaPods or 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 7 (CocoaPods) / 8.2+ (SPM), and
|
|
20
|
+
Capacitor 7 on Android/iOS. iOS requires deployment target 15.0 or newer.
|
|
21
|
+
The native SDK's SPM manifest requires Swift 6 tooling (Xcode 16 or newer).
|
|
22
|
+
Browser-only execution is not supported. Installation requires the native Android
|
|
23
|
+
or iOS build toolchain; adding the JavaScript package alone does not enable a browser runtime.
|
|
24
|
+
|
|
25
|
+
## Install From npm
|
|
26
|
+
|
|
27
|
+
Install from the root of an existing Capacitor or Cordova application. You do not
|
|
28
|
+
need a repository checkout or a locally built tarball.
|
|
29
|
+
|
|
30
|
+
### Capacitor
|
|
31
|
+
|
|
32
|
+
For iOS, prepare the native project **before installing the plugin and syncing**:
|
|
33
|
+
set the app deployment target to at least iOS 15.0, and, for CocoaPods, set the
|
|
34
|
+
Podfile platform to at least iOS 15.0. Capacitor 7 defaults to iOS 14.0, which is
|
|
35
|
+
too low for this native SDK.
|
|
36
|
+
|
|
37
|
+
Keep the iOS project's selected dependency manager. If the app does not yet have
|
|
38
|
+
an iOS platform, add it first; for a new SPM host, use
|
|
39
|
+
`npx cap add ios --packagemanager SPM`, then raise the app deployment target.
|
|
40
|
+
Existing CocoaPods hosts continue using CocoaPods; upgrading Capacitor does not
|
|
41
|
+
automatically migrate them.
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
npm install @whatfix_mobile/ionic-sdk
|
|
45
|
+
npx cap sync
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Cordova
|
|
49
|
+
|
|
50
|
+
Before installing on iOS, set these preferences in the app's `config.xml`:
|
|
51
|
+
|
|
52
|
+
```xml
|
|
53
|
+
<preference name="deployment-target" value="15.0" />
|
|
54
|
+
<preference name="SwiftVersion" value="5.0" />
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Then install the published plugin:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
cordova plugin add @whatfix_mobile/ionic-sdk
|
|
61
|
+
cordova prepare
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Cordova iOS 7 uses the pod declaration. Use **cordova-ios 8.2.0 or newer** for
|
|
65
|
+
SPM: 8.0.0 hardcodes an iOS 13 target in its generated package and does not apply
|
|
66
|
+
the app's deployment-target preference there. Cordova iOS 8.2+ uses the plugin's
|
|
67
|
+
`Package.swift`; the pod is marked `nospm="true"` to avoid linking the SDK twice.
|
|
68
|
+
Both dependency declarations use the same production iOS SDK version.
|
|
69
|
+
Do not manually add a second Whatfix SDK dependency
|
|
70
|
+
to the host project. SPM support is a build-tool choice, not an iOS device-version
|
|
71
|
+
check or a runtime fallback when a download fails.
|
|
72
|
+
See [Cordova SPM support](https://cordova.apache.org/docs/en/latest/guide/platforms/ios/plugin.html#supporting-swift-package-manager-spm)
|
|
73
|
+
and [Capacitor's dependency-manager setup](https://capacitorjs.com/docs/ios/spm).
|
|
74
|
+
|
|
75
|
+
The commands above select the current npm release. For reproducible builds, an
|
|
76
|
+
exact package version is optional: use `npm install @whatfix_mobile/ionic-sdk@1.1.1`
|
|
77
|
+
or `cordova plugin add @whatfix_mobile/ionic-sdk@1.1.1` instead. Commit the host
|
|
78
|
+
application's lockfile and keep its platform and dependency-manager configuration.
|
|
79
|
+
|
|
80
|
+
Keep the native SDK's merged Android startup provider enabled. It registers
|
|
81
|
+
lifecycle observation before the Activity resumes; invoking the wrapper later
|
|
82
|
+
must not require replacing the host Activity, WebView clients, or delegates.
|
|
83
|
+
For iOS Creator QR scanning, add a camera purpose string inside the host app's
|
|
84
|
+
`Info.plist` dictionary and handle the normal system permission prompt. For example:
|
|
85
|
+
|
|
86
|
+
```xml
|
|
87
|
+
<key>NSCameraUsageDescription</key>
|
|
88
|
+
<string>Scan Whatfix QR codes for content previews.</string>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Use purpose text appropriate to your app. The plugin does not add camera
|
|
92
|
+
permission text or arbitrary network exceptions to your app. Camera permission
|
|
93
|
+
is needed for QR scanning, not for every initialization.
|
|
94
|
+
|
|
95
|
+
## Usage
|
|
96
|
+
|
|
97
|
+
Use the enterprise UUID issued by Whatfix for your account. It must use the
|
|
98
|
+
hyphenated `8-4-4-4-12` hexadecimal form, with no braces or surrounding whitespace;
|
|
99
|
+
upper- and lowercase hexadecimal are accepted. Replace the placeholder in the
|
|
100
|
+
examples before running them. This is not the app's bundle ID or package name.
|
|
101
|
+
|
|
102
|
+
Choose your enterprise's production region: `US` (default) or `EU`. Set
|
|
103
|
+
`creatorModeEnabled: true` only when you want the native Creator interface;
|
|
104
|
+
it defaults to `false`. There are no public custom-endpoint or dev/UAT options.
|
|
105
|
+
|
|
106
|
+
Importing the npm module before initialization is safe. Invoke it only after the
|
|
107
|
+
native runtime is ready, once from app startup rather than on every route change.
|
|
108
|
+
|
|
109
|
+
### Ionic Angular With Capacitor
|
|
110
|
+
|
|
111
|
+
Create an application helper, for example `whatfix.ts`. Its `Platform` argument
|
|
112
|
+
is supplied by Ionic dependency injection in the root component shown below.
|
|
113
|
+
The helper waits for `Platform.ready()` before making any native calls.
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { Platform } from '@ionic/angular';
|
|
117
|
+
import { WhatfixMobile } from '@whatfix_mobile/ionic-sdk';
|
|
118
|
+
|
|
119
|
+
export async function initializeWhatfix(platform: Platform): Promise<void> {
|
|
120
|
+
await platform.ready();
|
|
121
|
+
await WhatfixMobile.start({
|
|
122
|
+
enterpriseId: 'YOUR-ENTERPRISE-UUID',
|
|
123
|
+
creatorModeEnabled: false,
|
|
124
|
+
region: 'US',
|
|
125
|
+
});
|
|
126
|
+
await WhatfixMobile.setUserId('user-123');
|
|
127
|
+
await WhatfixMobile.setAppLocale('en');
|
|
128
|
+
await WhatfixMobile.addTextProperty('plan', 'standard');
|
|
129
|
+
await WhatfixMobile.addNumberProperty('orders', 3);
|
|
130
|
+
await WhatfixMobile.addDateProperty('joined', new Date(), 'YYYYMMDD');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function handleWhatfixError(error: unknown): void {
|
|
134
|
+
const code = (error as { code?: string } | null)?.code;
|
|
135
|
+
switch (code) {
|
|
136
|
+
case 'INVALID_ARGUMENT':
|
|
137
|
+
console.warn('Whatfix: check the enterprise UUID and method arguments.');
|
|
138
|
+
break;
|
|
139
|
+
case 'UNAVAILABLE':
|
|
140
|
+
console.warn('Whatfix: install/sync the plugin and wait for native readiness.');
|
|
141
|
+
break;
|
|
142
|
+
case 'UNSUPPORTED_PLATFORM':
|
|
143
|
+
console.warn('Whatfix: use a native Android or iOS application.');
|
|
144
|
+
break;
|
|
145
|
+
case 'NATIVE_START_REJECTED':
|
|
146
|
+
console.warn('Whatfix: Android rejected initialization; check native configuration.');
|
|
147
|
+
break;
|
|
148
|
+
default:
|
|
149
|
+
console.warn('Whatfix: the native operation could not be dispatched.');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
In your existing root component, keep its template/decorator and merge this into
|
|
155
|
+
its imports and constructor. Do not call it from a repeatedly created page:
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
import { Platform } from '@ionic/angular';
|
|
159
|
+
import { initializeWhatfix, handleWhatfixError } from './whatfix';
|
|
160
|
+
|
|
161
|
+
// Inside the existing AppComponent class:
|
|
162
|
+
constructor(platform: Platform) {
|
|
163
|
+
void initializeWhatfix(platform).catch(handleWhatfixError);
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
For another Ionic UI framework, put the same SDK calls in that application's
|
|
168
|
+
native-ready startup lifecycle; Ionic Angular's `Platform` service is not a
|
|
169
|
+
general Capacitor API. A page load in a desktop browser is not native readiness.
|
|
170
|
+
|
|
171
|
+
### Plain Cordova
|
|
172
|
+
|
|
173
|
+
Keep the generated app's `cordova.js` script. Load the following application
|
|
174
|
+
JavaScript before `deviceready` fires; the installed plugin supplies
|
|
175
|
+
`window.WhatfixMobile`, so a separate npm import is unnecessary:
|
|
176
|
+
|
|
177
|
+
```js
|
|
178
|
+
document.addEventListener('deviceready', async function () {
|
|
179
|
+
const sdk = window.WhatfixMobile;
|
|
180
|
+
if (!sdk) {
|
|
181
|
+
console.warn('Whatfix: plugin is unavailable; check installation and prepare.');
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
await sdk.start({
|
|
186
|
+
enterpriseId: 'YOUR-ENTERPRISE-UUID',
|
|
187
|
+
creatorModeEnabled: false,
|
|
188
|
+
region: 'US',
|
|
189
|
+
});
|
|
190
|
+
await sdk.setUserId('user-123');
|
|
191
|
+
await sdk.setAppLocale('en');
|
|
192
|
+
await sdk.addTextProperty('plan', 'standard');
|
|
193
|
+
await sdk.addNumberProperty('orders', 3);
|
|
194
|
+
await sdk.addDateProperty('joined', new Date(), 'YYYYMMDD');
|
|
195
|
+
} catch (error) {
|
|
196
|
+
// Handle the stable code; do not log user/property values or raw native errors.
|
|
197
|
+
console.warn('Whatfix SDK error:', error && error.code || 'NATIVE_ERROR');
|
|
198
|
+
}
|
|
199
|
+
}, { once: true });
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Flush, Logout And Disable
|
|
203
|
+
|
|
204
|
+
These example application handlers are for separate user/app actions, not a
|
|
205
|
+
sequence to run automatically at startup. In plain Cordova, use the same methods
|
|
206
|
+
on `window.WhatfixMobile` after `deviceready`.
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
import { WhatfixMobile } from '@whatfix_mobile/ionic-sdk';
|
|
210
|
+
|
|
211
|
+
export async function requestWhatfixFlush(): Promise<void> {
|
|
212
|
+
await WhatfixMobile.flush();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export async function notifyWhatfixOfLogout(): Promise<void> {
|
|
216
|
+
await WhatfixMobile.logout();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export async function disableWhatfixForThisProcess(): Promise<void> {
|
|
220
|
+
await WhatfixMobile.disable();
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Catch rejected promises from these handlers using the error handling above.
|
|
225
|
+
`flush()` respects native consent/network policy and does not promise delivery.
|
|
226
|
+
Call `logout()` when the host user signs out; it is not a stop/reset API.
|
|
227
|
+
Use `disable()` only for an intentional terminal shutdown: calling `start()`
|
|
228
|
+
afterward cannot re-enable the SDK in that app process. Relaunch the app instead.
|
|
229
|
+
|
|
230
|
+
All methods return `Promise<void>`. Resolution acknowledges native dispatch, **not
|
|
231
|
+
successful configuration, Creator initialization, or overlay readiness**. Android
|
|
232
|
+
can synchronously reject startup; the native iOS start API returns no result.
|
|
233
|
+
|
|
234
|
+
| Method | Contract |
|
|
235
|
+
| --- | --- |
|
|
236
|
+
| `start(options)` | Required enterprise UUID; Creator defaults to `false`, region to `US`; `EU` also supported |
|
|
237
|
+
| `setUserId(userId)` | Nonblank string |
|
|
238
|
+
| `setAppLocale(localeCode)` | Nonblank string, interpreted by the native SDK |
|
|
239
|
+
| `addTextProperty(key, value)` | Nonblank key; string value (native SDK may ignore empty values) |
|
|
240
|
+
| `addNumberProperty(key, value)` | Nonblank key; finite number, not numeric text or boolean |
|
|
241
|
+
| `addDateProperty(key, value, format)` | Date or integer Unix milliseconds within the JavaScript Date range |
|
|
242
|
+
| `flush()` | Requests native flush subject to native consent/runtime policy; not a delivery receipt |
|
|
243
|
+
| `logout()` | Forwards native logout; not an overlay stop/reset API |
|
|
244
|
+
| `disable()` | Terminal for the app process, even before start; app relaunch required |
|
|
245
|
+
|
|
246
|
+
Date formats: `DDMMYYYY`, `MMDDYYYY`, `YYYYMMDD`, `YYYYDDMM`, `DDMonthYYYY`,
|
|
247
|
+
`MonthDDYYYY`. The format is required; dates cross the bridge as milliseconds.
|
|
248
|
+
Await calls when their order matters. Navigation/reset does not call `disable()`.
|
|
249
|
+
Repeated `start()` behavior remains native-owned; there is no wrapper restart API.
|
|
250
|
+
|
|
251
|
+
Errors have a stable `code`: `INVALID_ARGUMENT`, `UNAVAILABLE`,
|
|
252
|
+
`UNSUPPORTED_PLATFORM`, `NATIVE_START_REJECTED`, or `NATIVE_ERROR`. Messages are
|
|
253
|
+
fixed and do not include enterprise IDs, property values, or raw native errors.
|
|
254
|
+
`NATIVE_START_REJECTED` is Android-only; iOS does not report native startup
|
|
255
|
+
acceptance through this API. The example handler's default covers `NATIVE_ERROR`.
|
|
256
|
+
JavaScript cannot contain native process crashes or Objective-C exceptions.
|
|
257
|
+
|
|
258
|
+
## Troubleshooting
|
|
259
|
+
|
|
260
|
+
| Symptom | What to check |
|
|
261
|
+
| --- | --- |
|
|
262
|
+
| `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. |
|
|
263
|
+
| 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. |
|
|
264
|
+
| `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. |
|
|
265
|
+
| 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. |
|
|
266
|
+
| iOS dependency requires a higher deployment target | Set the app and, for CocoaPods, Podfile target to iOS 15.0 or newer. Use Xcode 16+ for native SPM and Cordova iOS 8.2+ for Cordova SPM. Do not install both dependency-manager variants. |
|
|
267
|
+
| Gradle, CocoaPods 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; CocoaPods uses its CDN; SPM downloads the published native package/binary. Do not silently substitute another AAR/framework or bypass TLS checks. |
|
|
268
|
+
| 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. |
|
|
269
|
+
|
|
270
|
+
## Observer And Safety
|
|
271
|
+
|
|
272
|
+
Native initialization, configuration, recovery and shutdown retain the existing
|
|
273
|
+
SDK Observer pipeline, consent, buffering, and delivery policy. The wrapper does
|
|
274
|
+
not force a flush on errors or build a second telemetry transport. Input failures
|
|
275
|
+
are returned to the caller without logging user values. There is no public native
|
|
276
|
+
Observer adapter exposed by this wrapper for wrapper-only failures. Do not assume
|
|
277
|
+
that a rejected JavaScript call creates an Observer event, or that mock dispatch
|
|
278
|
+
tests prove native event delivery.
|
|
279
|
+
|
|
280
|
+
The native production SDK's WebView-inspection policy is inherited unchanged.
|
|
281
|
+
Check your enterprise configuration before distributing the host: on Android,
|
|
282
|
+
WebView debugging is process-wide, not restricted to the SDK overlay.
|
|
283
|
+
|
|
284
|
+
## Release Notes
|
|
285
|
+
|
|
286
|
+
### 1.1.1
|
|
287
|
+
|
|
288
|
+
- Uses production Android and iOS native SDK dependencies pinned to 1.1.1.
|
|
289
|
+
- Provides the shared typed Cordova/Capacitor bridge for initialization, identity,
|
|
290
|
+
properties, flush, logout, and terminal disable.
|
|
291
|
+
- Supports the CocoaPods/SPM integration choices and minimum toolchains described
|
|
292
|
+
above. JavaScript promises acknowledge dispatch, not native readiness or delivery.
|
|
293
|
+
|
|
294
|
+
The package includes `CHANGELOG.md`. Its
|
|
295
|
+
[full changelog](https://unpkg.com/@whatfix_mobile/ionic-sdk@1.1.1/CHANGELOG.md) is also
|
|
296
|
+
available from the public package CDN after version 1.1.1 is published. These
|
|
297
|
+
inline notes do not require repository access or a separate npm changelog tab.
|
|
298
|
+
|
|
299
|
+
## License
|
|
300
|
+
|
|
301
|
+
The Whatfix Mobile SDK License Agreement is included unchanged as `LICENSE.pdf`
|
|
302
|
+
in this package. Read the full agreement before downloading, installing or using
|
|
303
|
+
the SDK. After publication, the PDF is also available from the
|
|
304
|
+
[public package CDN](https://unpkg.com/@whatfix_mobile/ionic-sdk@1.1.1/LICENSE.pdf).
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# Ionic npm release
|
|
2
|
+
|
|
3
|
+
Tracking: [FIX-139953](https://whatfix.atlassian.net/browse/FIX-139953).
|
|
4
|
+
Package: `@whatfix_mobile/ionic-sdk`. Both Capacitor and Cordova use this package.
|
|
5
|
+
|
|
6
|
+
## Trigger and versions
|
|
7
|
+
|
|
8
|
+
- `.github/workflows/npm-publish.yml` follows the native SDK release convention:
|
|
9
|
+
a closed, **merged**, same-repository PR whose source starts with `FIX-` or `SUCC-` (case-insensitive)
|
|
10
|
+
and whose target equals the `native` entry in the organization `ARGUS_PODS` JSON
|
|
11
|
+
variable. It does not hard-code a pod branch or publish from arbitrary pushes.
|
|
12
|
+
- Open/reopened/updated PRs and manual `workflow_dispatch` runs only validate and
|
|
13
|
+
dry-run. They receive neither npm publishing credentials nor native-repo tokens.
|
|
14
|
+
- Change **only `sdkVersion` in `version.properties`** for the wrapper version.
|
|
15
|
+
The preparation helper stamps `package.json`, both root lockfile version fields,
|
|
16
|
+
and the root `plugin.xml` version in the CI checkout before validation. It does
|
|
17
|
+
not commit generated metadata or change the native SDK versions in source.
|
|
18
|
+
- For an eligible merge, preparation resolves `/releases/latest` once from each
|
|
19
|
+
of `whatfix/wfx-android-sdk` and `whatfix/wfx-ios-sdk`. Both responses must be
|
|
20
|
+
published, non-prerelease releases with valid version tags. A missing release,
|
|
21
|
+
authentication error, or invalid response stops the build; there is no fallback.
|
|
22
|
+
- Before releasing, CI also checks that the selected Android production POM and
|
|
23
|
+
AAR are available from Maven Central, with bounded propagation retries. Missing
|
|
24
|
+
artifacts stop the release before GitHub/npm publication, not customer installs.
|
|
25
|
+
- The tarball's Android Maven dependency and both iOS dependency-manager paths
|
|
26
|
+
are pinned to these independently resolved versions. Android and iOS need not
|
|
27
|
+
match the wrapper or each other, but the iOS CocoaPods and SPM pins must match.
|
|
28
|
+
Local/PR dry-runs retain the checked-in native pins.
|
|
29
|
+
- SPM consumes the public `https://github.com/whatfix/WhatfixMobileSDK.git`
|
|
30
|
+
package with an exact version. The private SDK repository is used only to
|
|
31
|
+
discover release versions, never as a customer dependency.
|
|
32
|
+
- Stable wrapper versions use npm `latest`; prerelease versions use `next`.
|
|
33
|
+
Build metadata (`+...`) is not supported for release versions.
|
|
34
|
+
|
|
35
|
+
Open PR validation uses the event's `github.sha`, not the possibly stale
|
|
36
|
+
`pull_request.merge_commit_sha`. Published releases use the immutable approved
|
|
37
|
+
merge SHA throughout. Release jobs are serialized,
|
|
38
|
+
and running publication is not canceled by another merge. GitHub may replace a
|
|
39
|
+
pending concurrency-group run with a newer pending run; check Actions when
|
|
40
|
+
merging several release-version PRs close together.
|
|
41
|
+
|
|
42
|
+
## Repository setup before the first release
|
|
43
|
+
|
|
44
|
+
1. Grant this repository access to organization variable `ARGUS_PODS`, for example
|
|
45
|
+
`[{"pod_name":"native","branch_name":"feature/pod_native_v2"}]`.
|
|
46
|
+
2. Make **`WFX_BUILD_DEPLOY_APP_ID`** and **`WFX_BUILD_DEPLOY_APP_PRIVATE_KEY`**
|
|
47
|
+
available as repository secrets or organization secrets accessible to
|
|
48
|
+
`ionic-sdk`, using the same GitHub App as MAUI. Its installation must include
|
|
49
|
+
`whatfix/wfx-android-sdk` and `whatfix/wfx-ios-sdk` with Contents read access.
|
|
50
|
+
These secrets must be available to the preparation job, not only the `npm`
|
|
51
|
+
environment. The workflow generates a short-lived installation token scoped
|
|
52
|
+
to those two repositories with Contents read permission; it retains the
|
|
53
|
+
action's default post-job token revocation. Token creation and use are gated
|
|
54
|
+
to eligible merged PRs in `whatfix/ionic-sdk`, never open PRs or manual dry-runs.
|
|
55
|
+
No `NATIVE_SDK_RELEASE_TOKEN` personal token is needed. The automatic
|
|
56
|
+
repository `GITHUB_TOKEN` cannot read these other private repositories.
|
|
57
|
+
3. Create protected GitHub environment **`npm`**. Restrict deployment branches to
|
|
58
|
+
the approved Native pod branch, require a release reviewer, and prevent
|
|
59
|
+
self-approval where available. Keep this aligned when `ARGUS_PODS` changes.
|
|
60
|
+
4. In that environment add **`NPM_TOKEN`**, a granular npm token with permission
|
|
61
|
+
to publish `@whatfix_mobile/ionic-sdk` under the approved `@whatfix_mobile` organization.
|
|
62
|
+
For the first version it must permit creating that package. Configure the
|
|
63
|
+
supported noninteractive/2FA publishing permission per organization policy,
|
|
64
|
+
not an interactive npm login. Set an expiry and rotate the secret before it.
|
|
65
|
+
PR validation and package preparation never receive this write token.
|
|
66
|
+
5. Confirm package-name ownership, public-distribution approval, and license.
|
|
67
|
+
The user requested **public** publication with the supplied Whatfix Mobile SDK
|
|
68
|
+
License Agreement. The unchanged PDF ships as `LICENSE.pdf`, referenced by
|
|
69
|
+
`SEE LICENSE IN LICENSE.pdf` metadata. Before publishing, confirm with the
|
|
70
|
+
license owner that its binary-form SDK definition covers this package's
|
|
71
|
+
JavaScript and native bridge source files; do not rewrite the agreement.
|
|
72
|
+
6. Verify the resolved production versions are actually available in Maven
|
|
73
|
+
Central, CocoaPods and the SPM distribution and pass generated-host validation
|
|
74
|
+
for both iOS managers. A GitHub release alone is not proof consumers can
|
|
75
|
+
resolve its dependencies without private repository credentials.
|
|
76
|
+
7. Permit the release job's repository `GITHUB_TOKEN` to write Contents. Only
|
|
77
|
+
the GitHub Release job requests this permission; no extra PAT is needed.
|
|
78
|
+
|
|
79
|
+
This private GitHub repository does not support npm provenance attestation;
|
|
80
|
+
the workflow does not claim provenance. It retains the source SHA, native release
|
|
81
|
+
metadata, package contents report, runtime test evidence, and tarball SHA-256.
|
|
82
|
+
See [npm publishing in CI](https://docs.npmjs.com/using-private-packages-in-a-ci-cd-workflow/)
|
|
83
|
+
and [provenance requirements](https://docs.npmjs.com/generating-provenance-statements/).
|
|
84
|
+
|
|
85
|
+
## Validation and release
|
|
86
|
+
|
|
87
|
+
1. Bump `sdkVersion` in the PR. Run `python3 scripts/prepare-release.py` locally
|
|
88
|
+
to prepare matching local manifests before packaging (do not unintentionally
|
|
89
|
+
commit these generated version changes).
|
|
90
|
+
2. CI runs release-tool tests, locked dependency installation, `npm run check`,
|
|
91
|
+
package validation, both existing JavaScript bridge checks against the packed
|
|
92
|
+
snapshot, and a clean tarball install with TypeScript consumer checks.
|
|
93
|
+
3. The exact validated tarball is passed through `npm publish --dry-run`. The
|
|
94
|
+
version, checksum, and source commit appear in the Actions summary.
|
|
95
|
+
4. After an eligible merge, the GitHub Release job creates `v<version>` at the
|
|
96
|
+
merge commit. It uploads the validated tarball and evidence to a draft, then
|
|
97
|
+
publishes the completed release. Existing tags must match the merge SHA;
|
|
98
|
+
existing assets are never overwritten and an existing archive must match.
|
|
99
|
+
5. Review the `npm` environment gate. The npm job runs only after GitHub Release
|
|
100
|
+
succeeds. It downloads that release's tarball and report, checks the archive
|
|
101
|
+
against the SHA-256 passed independently from the package job, rechecks
|
|
102
|
+
merge eligibility, checks the registry for the exact version, then publishes
|
|
103
|
+
without lifecycle scripts. It never repacks or rewrites dist-tags.
|
|
104
|
+
6. Verify the npm page and install the exact version in a clean consumer:
|
|
105
|
+
`npm install --ignore-scripts @whatfix_mobile/ionic-sdk@<version>`.
|
|
106
|
+
Confirm native registry availability and generated-host integration before
|
|
107
|
+
calling the release ready for customers. JavaScript tests are not device or
|
|
108
|
+
live Observer delivery tests. SDK runtime and Observer behavior are unchanged.
|
|
109
|
+
|
|
110
|
+
Local dry-run (no secrets, no publication):
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
python3 scripts/prepare-release.py
|
|
114
|
+
npm ci --ignore-scripts
|
|
115
|
+
npm run check
|
|
116
|
+
node tests/integration/verify-package.mjs --out /tmp/ionic-npm-candidate
|
|
117
|
+
node tests/integration/verify-consumer.mjs --report /tmp/ionic-npm-candidate/package-report.json
|
|
118
|
+
node scripts/npm-release.mjs --report /tmp/ionic-npm-candidate/package-report.json --version 0.1.0 --tag next
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Use a fresh output directory and the version from `version.properties`.
|
|
122
|
+
Manual Actions dry-run becomes selectable when this workflow reaches the
|
|
123
|
+
repository's default branch; it never publishes.
|
|
124
|
+
|
|
125
|
+
## Failures and retries
|
|
126
|
+
|
|
127
|
+
- A version already present in npm stops publication with an explicit duplicate
|
|
128
|
+
message. No automatic version bump, unpublish, overwrite or dist-tag change
|
|
129
|
+
occurs. Bump `sdkVersion` if there is new content to release.
|
|
130
|
+
- Only a structured npm `E404` for the exact version permits the publish attempt.
|
|
131
|
+
Authentication, throttling, network and unknown errors fail closed.
|
|
132
|
+
- npm publication failure/timeout can mean the upload succeeded but its response
|
|
133
|
+
was lost. Check the exact registry version before rerunning. Never resolve
|
|
134
|
+
ambiguity by unpublishing or changing an unrelated dist-tag.
|
|
135
|
+
- A complete rerun resolves native latest releases again. Compare the new
|
|
136
|
+
`release-inputs.json` and checksum before approving it. Rerunning only the
|
|
137
|
+
failed npm job reuses the original GitHub Release archive, even if Actions
|
|
138
|
+
artifacts have expired. If a rebuild differs from the existing release, it
|
|
139
|
+
fails rather than replacing that release; use a new sdkVersion for new content.
|
|
140
|
+
- An interrupted GitHub upload leaves a draft. Rerun the failed GitHub Release
|
|
141
|
+
job with the original Actions artifact (retained for 30 days) to verify existing
|
|
142
|
+
files and upload missing files. A partial published release fails validation;
|
|
143
|
+
investigate rather than overwriting assets. No npm upload runs before this gate.
|
|
144
|
+
- If native registry publication is delayed, wait for it and rerun validation;
|
|
145
|
+
do not substitute local AAR/XCFramework paths into the npm package.
|
|
146
|
+
|
|
147
|
+
The first actual npm publish and post-publication installation require approved
|
|
148
|
+
credentials and a release run. Local tests/dry-runs do not establish that these
|
|
149
|
+
external permissions are configured or that npm accepted a release.
|
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,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whatfix_mobile/ionic-sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "Whatfix native SDK bridge for Ionic apps using Cordova or Capacitor",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"files": ["index.js", "index.d.ts", "www/", "src/android/", "src/ios/", "plugin.xml", "Package.swift", "README.md", "CHANGELOG.md", "LICENSE.pdf", "docs/npm-release.md"],
|
|
8
|
+
"cordova": { "id": "com.whatfix.ionic", "platforms": ["android", "ios"] },
|
|
9
|
+
"repository": { "type": "git", "url": "https://github.com/whatfix/ionic-sdk.git" },
|
|
10
|
+
"license": "SEE LICENSE IN LICENSE.pdf",
|
|
11
|
+
"keywords": ["ionic", "cordova", "capacitor", "ecosystem:cordova", "cordova-android", "cordova-ios", "whatfix"],
|
|
12
|
+
"engines": { "node": ">=20" },
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "node --test tests/js/*.test.cjs",
|
|
15
|
+
"test:types": "tsc -p tests/types/tsconfig.json",
|
|
16
|
+
"test:package": "node tests/integration/verify-package.mjs",
|
|
17
|
+
"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_prepare_release.py'",
|
|
18
|
+
"check": "npm test && npm run test:types && npm run test:package"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": { "typescript": "5.9.3" }
|
|
21
|
+
}
|
package/plugin.xml
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
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.1.1">
|
|
4
|
+
<name>WhatfixMobile</name>
|
|
5
|
+
<description>Whatfix native SDK bridge for Cordova and Capacitor</description>
|
|
6
|
+
<license>UNLICENSED</license>
|
|
7
|
+
<engines>
|
|
8
|
+
<engine name="cordova-android" version=">=13.0.0" />
|
|
9
|
+
<engine name="cordova-ios" version=">=7.0.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.1.1" />
|
|
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
|
+
<podspec>
|
|
31
|
+
<config>
|
|
32
|
+
<source url="https://cdn.cocoapods.org/" />
|
|
33
|
+
</config>
|
|
34
|
+
<pods use-frameworks="true">
|
|
35
|
+
<pod name="WhatfixMobileSDK" spec="1.1.1" nospm="true" />
|
|
36
|
+
</pods>
|
|
37
|
+
</podspec>
|
|
38
|
+
</platform>
|
|
39
|
+
</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
|
+
};
|