@dl2app/react-native 0.0.0-stage → 0.1.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 +308 -2
- package/android/build.gradle +24 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/app/dl2/reactnative/DL2Module.kt +107 -0
- package/app.plugin.js +3 -0
- package/build/plugin/src/withDL2.d.ts +62 -0
- package/build/plugin/src/withDL2.js +169 -0
- package/build/src/PasteButton.d.ts +14 -0
- package/build/src/PasteButton.js +44 -0
- package/build/src/core.d.ts +32 -0
- package/build/src/core.js +833 -0
- package/build/src/index.d.ts +22 -0
- package/build/src/index.js +33 -0
- package/build/src/types.d.ts +120 -0
- package/build/src/types.js +2 -0
- package/expo-module.config.json +5 -0
- package/ios/DL2.podspec +22 -0
- package/ios/DL2Module.swift +50 -0
- package/ios/DL2PasteButtonView.swift +41 -0
- package/ios/PrivacyInfo.xcprivacy +67 -0
- package/package.json +35 -4
- package/plugin/src/withDL2.ts +194 -0
- package/src/PasteButton.ts +48 -0
- package/src/core.ts +827 -0
- package/src/index.ts +41 -0
- package/src/types.ts +117 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Dimensions, Linking, PixelRatio, Platform } from "react-native";
|
|
2
|
+
import { requireOptionalNativeModule } from "expo-modules-core";
|
|
3
|
+
import { createDL2 } from "./core";
|
|
4
|
+
import type { DL2Native } from "./types";
|
|
5
|
+
|
|
6
|
+
function loadNative(): DL2Native | null {
|
|
7
|
+
try {
|
|
8
|
+
return requireOptionalNativeModule<DL2Native>("DL2");
|
|
9
|
+
} catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const DL2 = createDL2({
|
|
15
|
+
native: loadNative(),
|
|
16
|
+
linking: Linking,
|
|
17
|
+
platform: Platform.OS,
|
|
18
|
+
screen: () => {
|
|
19
|
+
// Points (iOS) and dp (Android): the same unit as `screen.width` in the browser that clicked.
|
|
20
|
+
const s = Dimensions.get("screen");
|
|
21
|
+
return { w: Math.round(s.width), h: Math.round(s.height), dpr: PixelRatio.get() };
|
|
22
|
+
},
|
|
23
|
+
fetch: (url, init) => fetch(url, init as RequestInit),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export default DL2;
|
|
27
|
+
export { DL2 };
|
|
28
|
+
export { DL2PasteButton } from "./PasteButton";
|
|
29
|
+
export type { DL2PasteButtonProps } from "./PasteButton";
|
|
30
|
+
export { parseUrl, extractClipboardToken, SDK_VERSION } from "./core";
|
|
31
|
+
export type {
|
|
32
|
+
DL2Config,
|
|
33
|
+
DL2CreateLinkInput,
|
|
34
|
+
DL2DebugInfo,
|
|
35
|
+
DL2Error,
|
|
36
|
+
DL2ErrorCode,
|
|
37
|
+
DL2LinkEvent,
|
|
38
|
+
DL2LinkSource,
|
|
39
|
+
DL2MatchMethod,
|
|
40
|
+
DL2TrackOptions,
|
|
41
|
+
} from "./types";
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export type DL2ErrorCode =
|
|
2
|
+
| "not_configured"
|
|
3
|
+
| "network"
|
|
4
|
+
| "timeout"
|
|
5
|
+
| "invalid_key"
|
|
6
|
+
| "app_mismatch"
|
|
7
|
+
| "link_not_found"
|
|
8
|
+
| "rate_limited"
|
|
9
|
+
| "unknown";
|
|
10
|
+
|
|
11
|
+
export type DL2Error = {
|
|
12
|
+
code: DL2ErrorCode;
|
|
13
|
+
message: string;
|
|
14
|
+
cause?: unknown;
|
|
15
|
+
/** HTTP status when the error came from an API response. */
|
|
16
|
+
status?: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type DL2LinkSource = "universal_link" | "app_link" | "uri_scheme" | "deferred";
|
|
20
|
+
export type DL2MatchMethod = "install_referrer" | "fingerprint" | "clipboard";
|
|
21
|
+
|
|
22
|
+
export type DL2LinkEvent = {
|
|
23
|
+
/** The URL that opened the app, or the short link that was matched. */
|
|
24
|
+
url: string | null;
|
|
25
|
+
/** Path to navigate to, for example "/invite/42". */
|
|
26
|
+
path: string;
|
|
27
|
+
/** Query parameters of the link. */
|
|
28
|
+
params: Record<string, string>;
|
|
29
|
+
/** The link's deep link data. */
|
|
30
|
+
data: Record<string, unknown>;
|
|
31
|
+
source: DL2LinkSource;
|
|
32
|
+
isFirstOpen: boolean;
|
|
33
|
+
matchMethod?: DL2MatchMethod;
|
|
34
|
+
confidence?: number;
|
|
35
|
+
linkId?: string;
|
|
36
|
+
utm?: Record<string, string>;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type DL2Config = {
|
|
40
|
+
publishableKey: string;
|
|
41
|
+
/** Every host your links use: the default host, the "-alt" host and custom domains. */
|
|
42
|
+
linkDomains: string[];
|
|
43
|
+
/** Optional custom URL scheme, without "://". */
|
|
44
|
+
uriScheme?: string;
|
|
45
|
+
/** Defaults: enabled true, timeoutMs 4000, useClipboard false. */
|
|
46
|
+
deferred?: { enabled?: boolean; timeoutMs?: number; useClipboard?: boolean };
|
|
47
|
+
/** Default https://api.dl2.app */
|
|
48
|
+
apiBaseUrl?: string;
|
|
49
|
+
debug?: boolean;
|
|
50
|
+
onError?: (e: DL2Error) => void;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type DL2TrackOptions = {
|
|
54
|
+
value?: number;
|
|
55
|
+
/** ISO 4217 code, for example "USD". */
|
|
56
|
+
currency?: string;
|
|
57
|
+
props?: Record<string, unknown>;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type DL2CreateLinkInput = {
|
|
61
|
+
path: string;
|
|
62
|
+
data?: Record<string, unknown>;
|
|
63
|
+
og?: { title?: string; description?: string; image?: string };
|
|
64
|
+
utm?: Record<string, string>;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type DL2DebugInfo = {
|
|
68
|
+
sdkVersion: string;
|
|
69
|
+
configured: boolean;
|
|
70
|
+
nativeModule: boolean;
|
|
71
|
+
installId: string | null;
|
|
72
|
+
isFirstLaunch: boolean;
|
|
73
|
+
queuedEvents: number;
|
|
74
|
+
lastOpenResponse: unknown;
|
|
75
|
+
lastResolveResponse: unknown;
|
|
76
|
+
lastError: DL2Error | null;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export type DL2DeviceInfo = {
|
|
80
|
+
osVersion?: string;
|
|
81
|
+
appId?: string;
|
|
82
|
+
appVersion?: string;
|
|
83
|
+
lang?: string;
|
|
84
|
+
tz?: string;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/** The native module (Expo Modules API). Every function is asynchronous. */
|
|
88
|
+
export interface DL2Native {
|
|
89
|
+
getItem(key: string): Promise<string | null>;
|
|
90
|
+
setItem(key: string, value: string): Promise<void>;
|
|
91
|
+
removeItem(key: string): Promise<void>;
|
|
92
|
+
/** Android: Play Install Referrer string. iOS: always null. */
|
|
93
|
+
getInstallReferrer(): Promise<string | null>;
|
|
94
|
+
getDeviceInfo(): Promise<DL2DeviceInfo>;
|
|
95
|
+
uuid?(): Promise<string>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export type DL2FetchResponse = { ok: boolean; status: number; json(): Promise<unknown> };
|
|
99
|
+
|
|
100
|
+
/** Everything the core needs from the platform. Injected so the core runs in plain Node for tests. */
|
|
101
|
+
export interface DL2Deps {
|
|
102
|
+
/** null when the native module is not linked (for example in Expo Go). */
|
|
103
|
+
native: DL2Native | null;
|
|
104
|
+
linking: {
|
|
105
|
+
getInitialURL(): Promise<string | null>;
|
|
106
|
+
addEventListener(type: "url", handler: (e: { url: string }) => void): { remove(): void } | void;
|
|
107
|
+
};
|
|
108
|
+
platform: string;
|
|
109
|
+
screen(): { w: number; h: number; dpr: number };
|
|
110
|
+
fetch(
|
|
111
|
+
url: string,
|
|
112
|
+
init: { method: string; headers: Record<string, string>; body: string; signal?: unknown },
|
|
113
|
+
): Promise<DL2FetchResponse>;
|
|
114
|
+
sleep?(ms: number): Promise<void>;
|
|
115
|
+
now?(): number;
|
|
116
|
+
random?(): number;
|
|
117
|
+
}
|