@straitlink/capacitor 0.1.0 → 0.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/Package.swift CHANGED
@@ -10,7 +10,7 @@ let package = Package(
10
10
  ],
11
11
  dependencies: [
12
12
  .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0"),
13
- .package(url: "https://github.com/strait-link/strait-sdk-swift.git", from: "0.9.3"),
13
+ .package(url: "https://github.com/strait-link/strait-sdk-swift.git", from: "0.9.4"),
14
14
  ],
15
15
  targets: [
16
16
  .target(
package/README.md CHANGED
@@ -92,6 +92,19 @@ The app opens on the link's screen and the console prints
92
92
  `Strait link: direct app_link true /p/42` (your path). The open shows up in the dashboard's
93
93
  Analytics within a minute. On a fresh install the first launch prints a `deferred` event instead.
94
94
 
95
+ ### Check your setup
96
+
97
+ In a debug build, after `start()`:
98
+
99
+ ```ts
100
+ const report = await strait.doctor();
101
+ for (const f of report.findings) console.log(f.severity, f.id, f.title, f.fix);
102
+ ```
103
+
104
+ **You should see** `ok key.ok`, `ok app.listed` and, on Android, `ok cert.listed`. Anything marked
105
+ `error` comes with the fix, for example `cert.missing`: "Add AB:CD:… in Dashboard → Apps & stores.
106
+ Debug, release and Play App Signing keys each have their own fingerprint."
107
+
95
108
  ## Platform features
96
109
 
97
110
  | Feature | Status | Notes |
@@ -118,6 +131,7 @@ Analytics within a minute. On a fresh install the first launch prints a `deferre
118
131
  | `trackEvent(name, { value, currency, linkId, clickId })` | Conversion or revenue event, placed on the tap of the last attributed open (7 days). Resolves `true` when accepted. |
119
132
  | `pendingOpenReports()` / `flushOpenReports()` | Open reports saved while offline (sent again on start and resume). |
120
133
  | `deviceClass()` | `phone` or `tablet` (iPad / 600 dp and up), as sent with open reports. |
134
+ | `doctor()` | Setup check for debug builds (key, endpoint, this app listed in your link domain's files, Android signing certificate). Resolves `{ ok, findings }`. |
121
135
  | `stop()` | Stops delivering events to this object. |
122
136
 
123
137
  `LinkEvent`: `id, kind (direct|deferred), route (app_link|custom_scheme|install_referrer|fingerprint|clipboard),
@@ -130,11 +144,11 @@ The plugin is a thin layer. All link logic (resolving short links, the once-per-
130
144
  check, open reports and their retry queue, app-state labels) runs in the native SDKs, which share
131
145
  golden test vectors with the Strait engine:
132
146
 
133
- - **Android:** `strait-sdk-android` **v0.8.1** from JitPack. The plugin adds JitPack to your Gradle
147
+ - **Android:** `strait-sdk-android` **v0.8.3** from JitPack. The plugin adds JitPack to your Gradle
134
148
  repositories, limited to the `com.github.strait-link` group, so nothing else is ever fetched from
135
149
  it. It reads the Play Install Referrer (`com.android.installreferrer:installreferrer:2.2`), the launch
136
150
  intent and `onNewIntent`, and keeps state in SharedPreferences (`strait`).
137
- - **iOS:** `StraitSDK` **0.9.3+** through Swift Package Manager. Links come from Capacitor's
151
+ - **iOS:** `StraitSDK` **0.9.4+** through Swift Package Manager. Links come from Capacitor's
138
152
  `capacitorOpenURL` / `capacitorOpenUniversalLink` notifications; state lives in `UserDefaults`.
139
153
 
140
154
  What gets recorded, the privacy details and the match methods are the same as the native SDKs:
@@ -1,6 +1,6 @@
1
1
  // @straitlink/capacitor, Android side: a thin Capacitor plugin over strait-sdk-android (JitPack).
2
2
  ext {
3
- straitSdkVersion = 'v0.8.1'
3
+ straitSdkVersion = 'v0.8.3'
4
4
  }
5
5
 
6
6
  buildscript {
@@ -4,6 +4,11 @@ import android.content.Context;
4
4
  import android.content.Intent;
5
5
  import android.content.SharedPreferences;
6
6
  import android.content.pm.ApplicationInfo;
7
+ import android.content.pm.PackageInfo;
8
+ import android.content.pm.PackageManager;
9
+ import android.content.pm.Signature;
10
+ import android.os.Build;
11
+ import android.util.Log;
7
12
  import android.util.DisplayMetrics;
8
13
 
9
14
  import com.android.installreferrer.api.InstallReferrerClient;
@@ -15,6 +20,7 @@ import com.getcapacitor.PluginCall;
15
20
  import com.getcapacitor.PluginMethod;
16
21
  import com.getcapacitor.annotation.CapacitorPlugin;
17
22
 
23
+ import java.security.MessageDigest;
18
24
  import java.util.ArrayList;
19
25
  import java.util.List;
20
26
  import java.util.Locale;
@@ -28,6 +34,8 @@ import java.util.concurrent.TimeUnit;
28
34
  import dev.strait.sdk.AppLifecycleState;
29
35
  import dev.strait.sdk.CoreKt;
30
36
  import dev.strait.sdk.DeviceFields;
37
+ import dev.strait.sdk.DoctorFinding;
38
+ import dev.strait.sdk.DoctorReport;
31
39
  import dev.strait.sdk.KeyValueStore;
32
40
  import dev.strait.sdk.LinkEvent;
33
41
  import dev.strait.sdk.LinkStart;
@@ -149,6 +157,58 @@ public class StraitPlugin extends Plugin {
149
157
  call.resolve(r);
150
158
  }
151
159
 
160
+ /** B23: setup check (debug builds). Sends this app's package and signing certificate(s). */
161
+ @PluginMethod
162
+ public void doctor(PluginCall call) {
163
+ StraitClient c = ready(call);
164
+ if (c == null) return;
165
+ Context ctx = getContext();
166
+ String pkg = ctx.getPackageName();
167
+ List<String> certs = signingCerts(ctx);
168
+ executor.execute(() -> {
169
+ DoctorReport r = c.doctor(pkg, certs);
170
+ JSArray list = new JSArray();
171
+ for (DoctorFinding f : r.getFindings()) {
172
+ JSObject o = new JSObject();
173
+ o.put("id", f.getId());
174
+ o.put("severity", f.getSeverity());
175
+ o.put("title", f.getTitle());
176
+ o.put("fix", f.getFix());
177
+ list.put(o);
178
+ Log.i("StraitDoctor", f.getSeverity() + " " + f.getId() + ": " + f.getTitle() + (f.getFix().isEmpty() ? "" : " → " + f.getFix()));
179
+ }
180
+ JSObject out = new JSObject();
181
+ out.put("ok", r.getOk());
182
+ out.put("findings", list);
183
+ call.resolve(out);
184
+ });
185
+ }
186
+
187
+ /** SHA-256 of this build's signing certificate(s), "AB:CD:…" (what assetlinks.json lists). */
188
+ @SuppressWarnings("deprecation")
189
+ private static List<String> signingCerts(Context ctx) {
190
+ List<String> out = new ArrayList<>();
191
+ try {
192
+ PackageManager pm = ctx.getPackageManager();
193
+ Signature[] sigs;
194
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
195
+ PackageInfo pi = pm.getPackageInfo(ctx.getPackageName(), PackageManager.GET_SIGNING_CERTIFICATES);
196
+ sigs = pi.signingInfo == null ? new Signature[0]
197
+ : pi.signingInfo.hasMultipleSigners() ? pi.signingInfo.getApkContentsSigners() : pi.signingInfo.getSigningCertificateHistory();
198
+ } else {
199
+ sigs = pm.getPackageInfo(ctx.getPackageName(), PackageManager.GET_SIGNATURES).signatures;
200
+ }
201
+ for (Signature sig : sigs) {
202
+ byte[] d = MessageDigest.getInstance("SHA-256").digest(sig.toByteArray());
203
+ StringBuilder b = new StringBuilder();
204
+ for (int i = 0; i < d.length; i++) b.append(i == 0 ? "" : ":").append(String.format("%02X", d[i]));
205
+ out.add(b.toString());
206
+ }
207
+ } catch (Exception ignored) {
208
+ }
209
+ return out;
210
+ }
211
+
152
212
  @Override
153
213
  protected void handleOnNewIntent(Intent intent) {
154
214
  super.handleOnNewIntent(intent);
package/dist/index.d.ts CHANGED
@@ -6,4 +6,4 @@ export declare const StraitNative: StraitNativePlugin;
6
6
  * Android and iOS only; on the web every call resolves a safe default (use @straitlink/web there).
7
7
  */
8
8
  export declare function createStrait(config: CreateStraitConfig, native?: StraitNativePlugin): Strait;
9
- export type { CreateStraitConfig, DeviceClass, LinkEvent, LinkStart, Strait, StraitNativePlugin, TrackEventExtra, } from './strait.js';
9
+ export type { CreateStraitConfig, DeviceClass, DoctorFinding, DoctorReport, LinkEvent, LinkStart, Strait, StraitNativePlugin, TrackEventExtra, } from './strait.js';
package/dist/strait.d.ts CHANGED
@@ -34,6 +34,19 @@ export interface LinkStart {
34
34
  at: number;
35
35
  }
36
36
  export type DeviceClass = 'phone' | 'tablet';
37
+ /** One setup check (contract B23, the same ids and wording in every Strait SDK). */
38
+ export interface DoctorFinding {
39
+ id: string;
40
+ severity: 'ok' | 'warn' | 'error';
41
+ title: string;
42
+ /** What to do; empty for `ok`. */
43
+ fix: string;
44
+ }
45
+ export interface DoctorReport {
46
+ /** No `error` finding. */
47
+ ok: boolean;
48
+ findings: DoctorFinding[];
49
+ }
37
50
  export interface CreateStraitConfig {
38
51
  /** Your workspace's publishable key (`st_pub_live_…`), Dashboard → Get started. Never the secret key. */
39
52
  publishableKey: string;
@@ -68,6 +81,7 @@ export interface StraitNativePlugin {
68
81
  deviceClass(): Promise<{
69
82
  deviceClass?: DeviceClass;
70
83
  }>;
84
+ doctor(): Promise<DoctorReport>;
71
85
  addListener(event: 'link', cb: (e: LinkEvent) => void): Promise<PluginListenerHandle>;
72
86
  addListener(event: 'linkStart', cb: (s: LinkStart) => void): Promise<PluginListenerHandle>;
73
87
  }
@@ -88,6 +102,12 @@ export interface Strait {
88
102
  flushOpenReports(): Promise<void>;
89
103
  /** What the app runs on, as sent with open reports (B14): iPad / sw600dp = tablet. */
90
104
  deviceClass(): Promise<DeviceClass | undefined>;
105
+ /**
106
+ * Setup check for debug builds (B23): key, endpoint, and whether your link domain's
107
+ * assetlinks.json / apple-app-site-association lists this app (Android: also this build's
108
+ * signing certificate). Call after start(). Never throws.
109
+ */
110
+ doctor(): Promise<DoctorReport>;
91
111
  /** Stop delivering events to this object. */
92
112
  stop(): void;
93
113
  }
package/dist/strait.js CHANGED
@@ -59,6 +59,7 @@ export function createStrait(config, native) {
59
59
  pendingOpenReports: () => safe(async () => (await native.pendingOpenReports()).count ?? 0, 0),
60
60
  flushOpenReports: () => safe(() => native.flushOpenReports(), undefined),
61
61
  deviceClass: () => safe(async () => (await native.deviceClass()).deviceClass, undefined),
62
+ doctor: () => safe(() => native.doctor(), { ok: false, findings: [] }),
62
63
  stop() {
63
64
  linkCbs.clear();
64
65
  startCbs.clear();
@@ -17,6 +17,7 @@ public class StraitPlugin: CAPPlugin, CAPBridgedPlugin {
17
17
  CAPPluginMethod(name: "pendingOpenReports", returnType: CAPPluginReturnPromise),
18
18
  CAPPluginMethod(name: "flushOpenReports", returnType: CAPPluginReturnPromise),
19
19
  CAPPluginMethod(name: "deviceClass", returnType: CAPPluginReturnPromise),
20
+ CAPPluginMethod(name: "doctor", returnType: CAPPluginReturnPromise),
20
21
  ]
21
22
 
22
23
  private var links: StraitLinks?
@@ -98,6 +99,18 @@ public class StraitPlugin: CAPPlugin, CAPBridgedPlugin {
98
99
  }
99
100
  }
100
101
 
102
+ /// B23: setup check (debug builds) for this app's bundle ID.
103
+ @objc func doctor(_ call: CAPPluginCall) {
104
+ guard let l = ready(call) else { return }
105
+ l.doctor(bundleId: Bundle.main.bundleIdentifier) { r in
106
+ for f in r.findings { print("[Strait doctor] \(f.severity) \(f.id): \(f.title)\(f.fix.isEmpty ? "" : " → \(f.fix)")") }
107
+ call.resolve([
108
+ "ok": r.ok,
109
+ "findings": r.findings.map { ["id": $0.id, "severity": $0.severity, "title": $0.title, "fix": $0.fix] },
110
+ ])
111
+ }
112
+ }
113
+
101
114
  private func ready(_ call: CAPPluginCall) -> StraitLinks? {
102
115
  guard let l = links else {
103
116
  call.reject("Strait: call start() first")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@straitlink/capacitor",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Deep linking for Capacitor and Ionic apps: direct links (App Links, Universal Links, custom schemes), deferred links that survive the install and link-open analytics. Wraps the Strait Android and iOS SDKs.",
5
5
  "keywords": [
6
6
  "capacitor",