@livx.cc/native-kit 0.32.3 → 0.34.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/README.md +1 -1
- package/package.json +1 -1
- package/src/core/NativeKit.ts +2 -0
- package/src/core/types.ts +6 -0
- package/src/index.ts +1 -0
- package/src/modules/lifecycle.ts +11 -0
- package/src/modules/tracking.ts +73 -0
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ mixpanel.register(await kit.context());
|
|
|
26
26
|
|
|
27
27
|
The kit detects whether it's running inside the appwrap shell and routes each call to the native bridge or a web fallback, so a single web build works everywhere. Capabilities advertise their real backing (`native` / `web` / `none`) so your UI can be honest about what's available.
|
|
28
28
|
|
|
29
|
-
Covers haptics, share, storage, notifications, OAuth, billing (IAP), health, geo, camera, photos, contacts, calendar, motion, reviews, and more.
|
|
29
|
+
Covers haptics, share, storage, notifications, OAuth, billing (IAP), health, geo, camera, photos, contacts, calendar, motion, reviews, tracking (iOS App Tracking Transparency), and more.
|
|
30
30
|
|
|
31
31
|
**Full documentation, capability model, and the bridge protocol:** see the [appwrap README](https://github.com/Livshitz/appwrap#readme).
|
|
32
32
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livx.cc/native-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"description": "Isomorphic native-capabilities kit for PWAs \u2014 same API in browser and in an appwrap native shell. Zero dependencies.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Elya Livshitz",
|
package/src/core/NativeKit.ts
CHANGED
|
@@ -30,6 +30,7 @@ import { ShareModule } from '../modules/share';
|
|
|
30
30
|
import { SpeechModule } from '../modules/speech';
|
|
31
31
|
import { StorageModule } from '../modules/storage';
|
|
32
32
|
import { ToastModule } from '../modules/toast';
|
|
33
|
+
import { TrackingModule } from '../modules/tracking';
|
|
33
34
|
import { UiModule } from '../modules/ui';
|
|
34
35
|
import { UpdatesModule } from '../modules/updates';
|
|
35
36
|
|
|
@@ -103,6 +104,7 @@ export class NativeKit {
|
|
|
103
104
|
public readonly billing = new BillingModule(this);
|
|
104
105
|
public readonly updates = new UpdatesModule(this);
|
|
105
106
|
public readonly backgroundTask = new BackgroundTaskModule(this);
|
|
107
|
+
public readonly tracking = new TrackingModule(this);
|
|
106
108
|
|
|
107
109
|
public handshakeInfo: Handshake | null = null;
|
|
108
110
|
public options: NativeKitOptions;
|
package/src/core/types.ts
CHANGED
|
@@ -29,6 +29,12 @@ export interface Handshake {
|
|
|
29
29
|
* reads it from {@link NativeKit.handshakeInfo} and dispatches the registered handler. Absent on a
|
|
30
30
|
* normal foreground launch. See {@link BackgroundTaskModule}. */
|
|
31
31
|
backgroundTaskId?: string;
|
|
32
|
+
/** Set ONLY on a cold launch FROM a deep link (url-scheme open or notification tap that started the
|
|
33
|
+
* app): the link that launched us, handed back synchronously so the PWA can route to the target
|
|
34
|
+
* route BEFORE first paint — avoiding a brief home-screen flash. A WARM deep link (app already
|
|
35
|
+
* running) is NOT carried here; it arrives via the `deeplink.open` event. Read it at `ready()` via
|
|
36
|
+
* {@link LifecycleModule.launchDeepLink}. Absent on a normal launch. */
|
|
37
|
+
deepLink?: string;
|
|
32
38
|
/** Optional diagnostic payload (breadcrumbs, etc.). */
|
|
33
39
|
debug?: Record<string, unknown>;
|
|
34
40
|
}
|
package/src/index.ts
CHANGED
|
@@ -41,6 +41,7 @@ export type { SpeechVoice, SpeakOptions, ListenOptions, SpeechPartial } from './
|
|
|
41
41
|
export type { CalendarEventOptions } from './modules/calendar';
|
|
42
42
|
export type { BrowserOptions } from './modules/browser';
|
|
43
43
|
export type { OAuthAuthorizeParams, OAuthResult } from './modules/oauth';
|
|
44
|
+
export type { TrackingStatus } from './modules/tracking';
|
|
44
45
|
export { ClientTrustedValidator, HttpValidator, HttpValidatorOptions } from './modules/billing/validators';
|
|
45
46
|
export { HttpBillingProvider, HttpBillingProviderOptions } from './modules/billing/providers';
|
|
46
47
|
export type { HeaderProvider } from './modules/billing/http';
|
package/src/modules/lifecycle.ts
CHANGED
|
@@ -20,4 +20,15 @@ export class LifecycleModule {
|
|
|
20
20
|
onDeepLink(cb: (url: string) => void): Unsubscribe {
|
|
21
21
|
return this.kit.on('deeplink.open', (p) => cb((p as { url: string }).url));
|
|
22
22
|
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The deep link the app was COLD-LAUNCHED from (url-scheme open / notification tap that started the
|
|
26
|
+
* app), if any — exposed synchronously from the handshake so the app can route to the target route
|
|
27
|
+
* BEFORE first paint and skip the brief home flash. Returns null on a normal launch or on web.
|
|
28
|
+
* Available once `kit.ready()` has resolved. Warm deep links (app already open) do NOT appear here —
|
|
29
|
+
* subscribe to {@link onDeepLink} for those.
|
|
30
|
+
*/
|
|
31
|
+
get launchDeepLink(): string | null {
|
|
32
|
+
return this.kit.handshakeInfo?.deepLink ?? null;
|
|
33
|
+
}
|
|
23
34
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { NativeKit } from '../core/NativeKit';
|
|
2
|
+
|
|
3
|
+
/** App Tracking Transparency authorization status (iOS ATTrackingManager). Mirrors Apple's enum.
|
|
4
|
+
* - `notDetermined` — the user hasn't been asked yet (call {@link TrackingModule.requestPermission}).
|
|
5
|
+
* - `restricted` — tracking is disallowed by device policy (e.g. parental controls / MDM).
|
|
6
|
+
* - `denied` — the user declined; you MUST NOT track / read the IDFA.
|
|
7
|
+
* - `authorized` — the user allowed tracking; {@link TrackingModule.idfa} returns the IDFA. */
|
|
8
|
+
export type TrackingStatus = 'notDetermined' | 'restricted' | 'denied' | 'authorized';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* App Tracking Transparency (iOS, `tracking` module — opt-in). The native-only compliance seam for
|
|
12
|
+
* apps that track the user across other companies' apps/sites (IDFA, cross-app identity): Apple
|
|
13
|
+
* REQUIRES the ATT prompt + `NSUserTrackingUsageDescription` and forbids tracking before consent.
|
|
14
|
+
*
|
|
15
|
+
* Provider-agnostic, like `kit.push`/`kit.oauth`: the shell owns only the device-side primitive
|
|
16
|
+
* (show the prompt, report status, hand back the IDFA when authorized). What you DO with consent —
|
|
17
|
+
* init an ad SDK, set an analytics super-prop — is the PWA's job.
|
|
18
|
+
*
|
|
19
|
+
* Capability gating (honest):
|
|
20
|
+
* - iOS (14.5+): `'native'`.
|
|
21
|
+
* - Android / web / iOS < 14.5: `'none'` — there is NO ATT. The methods still resolve safely:
|
|
22
|
+
* `requestPermission()`/`status()` → `'authorized'` (no consent gate exists, so tracking is not
|
|
23
|
+
* blocked by the OS — Play's Advertising-ID consent is a separate, app-declared concern), and
|
|
24
|
+
* `idfa()` → `undefined` (the IDFA is iOS-only; GAID needs the AD_ID permission + Play's own flow).
|
|
25
|
+
*
|
|
26
|
+
* Most apps need only first-party analytics and should NOT enable this module (no string = Apple
|
|
27
|
+
* assumes no tracking). Ship it only when the app genuinely tracks across companies.
|
|
28
|
+
*/
|
|
29
|
+
export class TrackingModule {
|
|
30
|
+
constructor(private kit: NativeKit) {}
|
|
31
|
+
|
|
32
|
+
get capability() {
|
|
33
|
+
return this.kit.capability('tracking');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Honest fallback when ATT doesn't exist (Android/web/iOS<14.5): nothing gates tracking at the OS
|
|
37
|
+
* level, so report `authorized` rather than a misleading `notDetermined`. */
|
|
38
|
+
private get fallback(): TrackingStatus {
|
|
39
|
+
return 'authorized';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Show the iOS ATT prompt and resolve with the resulting status. The prompt only appears once per
|
|
44
|
+
* install while status is `notDetermined`; subsequent calls resolve immediately with the prior
|
|
45
|
+
* choice. Dismiss-bound (the user decides at their leisure) → no watchdog timeout.
|
|
46
|
+
* On a non-ATT platform resolves to {@link fallback} without showing UI.
|
|
47
|
+
*/
|
|
48
|
+
requestPermission(): Promise<TrackingStatus> {
|
|
49
|
+
if (this.capability !== 'native') return Promise.resolve(this.fallback);
|
|
50
|
+
return this.kit.invoke<TrackingStatus>('tracking.requestPermission', undefined, { timeoutMs: 'none' });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Current ATT authorization status WITHOUT prompting. {@link fallback} on a non-ATT platform. */
|
|
54
|
+
status(): Promise<TrackingStatus> {
|
|
55
|
+
if (this.capability !== 'native') return Promise.resolve(this.fallback);
|
|
56
|
+
return this.kit.invoke<TrackingStatus>('tracking.status');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Alias of {@link status} (parity with other permissioned modules' `permissionStatus`). */
|
|
60
|
+
permissionStatus(): Promise<TrackingStatus> {
|
|
61
|
+
return this.status();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The IDFA (iOS advertising identifier) — returned ONLY while ATT status is `authorized`; otherwise
|
|
66
|
+
* (denied/restricted/notDetermined, or the all-zero placeholder) resolves `undefined`. Always
|
|
67
|
+
* `undefined` off iOS (no IDFA exists — use Play's Advertising ID via your own flow if needed).
|
|
68
|
+
*/
|
|
69
|
+
idfa(): Promise<string | undefined> {
|
|
70
|
+
if (this.capability !== 'native') return Promise.resolve(undefined);
|
|
71
|
+
return this.kit.invoke<string | undefined>('tracking.idfa');
|
|
72
|
+
}
|
|
73
|
+
}
|