@watchtowerobservability/capacitor 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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/Package.swift ADDED
@@ -0,0 +1,23 @@
1
+ // swift-tools-version:5.9
2
+ import PackageDescription
3
+
4
+ let package = Package(
5
+ name: "WatchtowerobservabilityCapacitor",
6
+ platforms: [.iOS(.v13)],
7
+ products: [.library(name: "WatchtowerobservabilityCapacitor", targets: ["WatchtowerPlugin"])],
8
+ dependencies: [
9
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "6.0.0"),
10
+ .package(url: "https://github.com/watchtowerobservability/watchtower-ios", from: "0.1.0"),
11
+ ],
12
+ targets: [
13
+ .target(
14
+ name: "WatchtowerPlugin",
15
+ dependencies: [
16
+ .product(name: "Capacitor", package: "capacitor-swift-pm"),
17
+ .product(name: "Cordova", package: "capacitor-swift-pm"),
18
+ .product(name: "Watchtower", package: "watchtower-ios"),
19
+ ],
20
+ path: "ios/Sources/WatchtowerPlugin"
21
+ ),
22
+ ]
23
+ )
package/README.md CHANGED
@@ -1,3 +1,61 @@
1
- # Temporary Holding Version
1
+ # @watchtowerobservability/capacitor
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ One `init` for a Capacitor app: the [browser SDK](https://github.com/watchtowerobservability/watchtower-browser) runs
4
+ in the webview (JS errors, vitals, sessions), and inside the iOS/Android shell the native
5
+ [iOS](https://github.com/watchtowerobservability/watchtower-ios) and
6
+ [Android](https://github.com/watchtowerobservability/watchtower-android) SDKs add native crashes, ANR/hangs and screenshot replay.
7
+ Written in TypeScript; the package ships ESM with type declarations.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install @watchtowerobservability/capacitor @watchtowerobservability/browser
13
+ npx cap sync
14
+ ```
15
+
16
+ iOS pulls the native SDK through Swift Package Manager. Android needs the `:watchtower-android` module from
17
+ `watchtower-android` (no Maven registry yet): in `android/settings.gradle` add
18
+ `include ':watchtower-android'` and point `project(':watchtower-android').projectDir` at the downloaded sources.
19
+
20
+ ## Quick start
21
+
22
+ ```js
23
+ import { init } from '@watchtowerobservability/capacitor';
24
+
25
+ await init({
26
+ publishableKey: 'PUBLISHABLE_KEY',
27
+ endpoint: 'https://edge.example.com',
28
+ service: 'my-app',
29
+ release: '1.2.3',
30
+ environment: 'production',
31
+ });
32
+ ```
33
+
34
+ ## Integrations
35
+
36
+ | Layer | Provides |
37
+ |---|---|
38
+ | Browser SDK (always) | JS errors, web vitals, sessions, journeys, `beforeSend` redaction |
39
+ | iOS SDK (device) | crashes, hangs, app start, frame metrics, masked screenshot replay |
40
+ | Android SDK (device) | crashes, ANR, app start, frame metrics, masked screenshot replay |
41
+
42
+ On a device the DOM replay recorder is turned off and `replay` switches on the native screenshot replay instead.
43
+
44
+ ## Configuration
45
+
46
+ | Option | Meaning |
47
+ |---|---|
48
+ | `publishableKey` | required; sent as `Authorization: Bearer`, never logged |
49
+ | `endpoint` | required; edge base URL (the app has no env vars; read it from your build config) |
50
+ | `service`, `environment`, `release` | resource attributes (the `WT_SERVICE`, `WT_ENVIRONMENT`, `WT_RELEASE` equivalents) |
51
+ | `beforeSend` | redaction hook, return `null` to drop |
52
+ | `replay` | masked replay options |
53
+ | `native` | `false` skips the native SDKs |
54
+
55
+ ## Provenance
56
+
57
+ `gh attestation verify <file> --repo watchtowerobservability/watchtower-capacitor`
58
+
59
+ ## License
60
+
61
+ Apache-2.0
@@ -0,0 +1,16 @@
1
+ require 'json'
2
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
3
+
4
+ Pod::Spec.new do |s|
5
+ s.name = 'WatchtowerobservabilityCapacitor'
6
+ s.version = package['version']
7
+ s.summary = package['description']
8
+ s.license = 'Apache-2.0'
9
+ s.homepage = 'https://github.com/watchtowerobservability/watchtower-capacitor'
10
+ s.author = 'Watchtower'
11
+ s.source = { :git => 'https://github.com/watchtowerobservability/watchtower-capacitor.git', :tag => "v#{s.version}" }
12
+ s.source_files = 'ios/Sources/WatchtowerPlugin/**/*.{swift,h,m}'
13
+ s.ios.deployment_target = '13.0'
14
+ s.dependency 'Capacitor'
15
+ s.swift_version = '5.9'
16
+ end
@@ -0,0 +1,27 @@
1
+ plugins {
2
+ id("com.android.library")
3
+ id("org.jetbrains.kotlin.android")
4
+ }
5
+
6
+ android {
7
+ namespace = "dev.watchtower.capacitor"
8
+ compileSdk = 34
9
+ defaultConfig { minSdk = 24 }
10
+ compileOptions {
11
+ sourceCompatibility = JavaVersion.VERSION_17
12
+ targetCompatibility = JavaVersion.VERSION_17
13
+ }
14
+ kotlinOptions { jvmTarget = "17" }
15
+ }
16
+
17
+ repositories {
18
+ google()
19
+ mavenCentral()
20
+ }
21
+
22
+ dependencies {
23
+ implementation(project(":capacitor-android"))
24
+ // The native SDK (sdks/android) as a local module until it is on a Maven registry:
25
+ // add `include(":watchtower-android")` in the app's settings.gradle with projectDir at the downloaded sources.
26
+ implementation(project(":watchtower-android"))
27
+ }
@@ -0,0 +1,42 @@
1
+ package dev.watchtower.capacitor
2
+
3
+ import com.getcapacitor.Plugin
4
+ import com.getcapacitor.PluginCall
5
+ import com.getcapacitor.PluginMethod
6
+ import com.getcapacitor.annotation.CapacitorPlugin
7
+ import dev.watchtower.Config
8
+ import dev.watchtower.ReplayConfig
9
+ import dev.watchtower.Watchtower
10
+
11
+ /** Bridge to the native Android SDK: crashes, ANR, app start, frame metrics and screenshot replay. */
12
+ @CapacitorPlugin(name = "Watchtower")
13
+ class WatchtowerPlugin : Plugin() {
14
+ @PluginMethod
15
+ fun init(call: PluginCall) {
16
+ val key = call.getString("key")
17
+ val service = call.getString("service")
18
+ val endpoint = call.getString("endpoint")
19
+ if (key == null || service == null || endpoint == null) {
20
+ call.reject("key, service and endpoint are required")
21
+ return
22
+ }
23
+ Watchtower.init(
24
+ activity.application,
25
+ Config(
26
+ key = key,
27
+ service = service,
28
+ endpoint = endpoint,
29
+ release = call.getString("release"),
30
+ environment = call.getString("environment"),
31
+ replay = ReplayConfig(enabled = call.getBoolean("replay", false) == true),
32
+ ),
33
+ )
34
+ call.resolve()
35
+ }
36
+
37
+ @PluginMethod
38
+ fun flush(call: PluginCall) {
39
+ Watchtower.flush()
40
+ call.resolve()
41
+ }
42
+ }
package/dist/core.d.ts ADDED
@@ -0,0 +1,43 @@
1
+ import type { WatchtowerClient, WatchtowerConfig } from "@watchtowerobservability/browser";
2
+ export interface InitOptions {
3
+ /** Publishable ingest key. Sent as `Authorization: Bearer`, never logged. */
4
+ publishableKey: string;
5
+ /** Edge base URL. */
6
+ endpoint: string;
7
+ service: string;
8
+ release?: string;
9
+ environment?: string;
10
+ /** Redaction hook of the browser SDK. */
11
+ beforeSend?: WatchtowerConfig["beforeSend"];
12
+ /** Masked replay: DOM recording on the web, screenshot replay inside the native shell. */
13
+ replay?: WatchtowerConfig["replay"];
14
+ /** Set false to skip the native SDK inside the iOS/Android shell (default true). */
15
+ native?: boolean;
16
+ }
17
+ /** What the native bridge receives (registerPlugin('Watchtower')). */
18
+ export interface NativeOptions {
19
+ key: string;
20
+ endpoint: string;
21
+ service: string;
22
+ release?: string;
23
+ environment?: string;
24
+ replay: boolean;
25
+ }
26
+ export interface NativePlugin {
27
+ init(o: NativeOptions): Promise<void>;
28
+ flush(): Promise<void>;
29
+ }
30
+ export interface Deps {
31
+ browser: {
32
+ init(c: WatchtowerConfig): WatchtowerClient;
33
+ };
34
+ plugin: NativePlugin;
35
+ /** Whether the webview runs inside the iOS/Android shell. */
36
+ isNative: boolean;
37
+ }
38
+ export declare function createWatchtower({ browser, plugin, isNative }: Deps): {
39
+ /** Starts the browser SDK in the webview and, on devices, the native SDK (crashes, ANR/hangs, replay). */
40
+ init(o: InitOptions): Promise<WatchtowerClient>;
41
+ captureError(err: unknown, ctx?: Record<string, string | number | boolean>): void;
42
+ flush(): Promise<void>;
43
+ };
@@ -0,0 +1,5 @@
1
+ import * as browser from "@watchtowerobservability/browser";
2
+ export type { InitOptions } from "./core";
3
+ export declare const init: (o: import("./core").InitOptions) => Promise<browser.WatchtowerClient>;
4
+ export declare const captureError: (err: unknown, ctx?: Record<string, string | number | boolean>) => void;
5
+ export declare const flush: () => Promise<void>;
package/dist/index.js ADDED
@@ -0,0 +1,56 @@
1
+ // src/index.ts
2
+ import { Capacitor, registerPlugin } from "@capacitor/core";
3
+ import * as browser from "@watchtowerobservability/browser";
4
+
5
+ // src/core.ts
6
+ var REQUIRED = ["publishableKey", "endpoint", "service"];
7
+ function createWatchtower({ browser: browser2, plugin, isNative }) {
8
+ let web;
9
+ return {
10
+ /** Starts the browser SDK in the webview and, on devices, the native SDK (crashes, ANR/hangs, replay). */
11
+ async init(o) {
12
+ for (const k of REQUIRED) if (!o?.[k]) throw new Error(`${k} is required`);
13
+ const native = isNative && o.native !== false;
14
+ web = browser2.init({
15
+ publishableKey: o.publishableKey,
16
+ endpoint: o.endpoint,
17
+ service: o.service,
18
+ release: o.release,
19
+ environment: o.environment,
20
+ beforeSend: o.beforeSend,
21
+ // on a device the native SDK records the screen; the DOM recorder would duplicate it
22
+ replay: native ? void 0 : o.replay
23
+ });
24
+ if (native) {
25
+ await plugin.init({
26
+ key: o.publishableKey,
27
+ endpoint: o.endpoint,
28
+ service: o.service,
29
+ release: o.release,
30
+ environment: o.environment,
31
+ replay: !!o.replay
32
+ });
33
+ }
34
+ return web;
35
+ },
36
+ captureError(err, ctx) {
37
+ web?.captureError(err, ctx);
38
+ },
39
+ async flush() {
40
+ if (isNative) await plugin.flush();
41
+ if (web) await web.replay.flush();
42
+ }
43
+ };
44
+ }
45
+
46
+ // src/index.ts
47
+ var wt = createWatchtower({ browser, plugin: registerPlugin("Watchtower"), isNative: Capacitor.isNativePlatform() });
48
+ var init = wt.init;
49
+ var captureError = wt.captureError;
50
+ var flush = wt.flush;
51
+ export {
52
+ captureError,
53
+ flush,
54
+ init
55
+ };
56
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts", "../src/core.ts"],
4
+ "sourcesContent": ["import { Capacitor, registerPlugin } from \"@capacitor/core\";\nimport * as browser from \"@watchtowerobservability/browser\";\nimport { createWatchtower, type NativePlugin } from \"./core\";\n\nexport type { InitOptions } from \"./core\";\n\nconst wt = createWatchtower({ browser, plugin: registerPlugin<NativePlugin>(\"Watchtower\"), isNative: Capacitor.isNativePlatform() });\n\nexport const init = wt.init;\nexport const captureError = wt.captureError;\nexport const flush = wt.flush;\n", "// Plugin logic with injected dependencies so it runs under vitest (no Capacitor runtime).\nimport type { WatchtowerClient, WatchtowerConfig } from \"@watchtowerobservability/browser\";\n\nexport interface InitOptions {\n /** Publishable ingest key. Sent as `Authorization: Bearer`, never logged. */\n publishableKey: string;\n /** Edge base URL. */\n endpoint: string;\n service: string;\n release?: string;\n environment?: string;\n /** Redaction hook of the browser SDK. */\n beforeSend?: WatchtowerConfig[\"beforeSend\"];\n /** Masked replay: DOM recording on the web, screenshot replay inside the native shell. */\n replay?: WatchtowerConfig[\"replay\"];\n /** Set false to skip the native SDK inside the iOS/Android shell (default true). */\n native?: boolean;\n}\n\n/** What the native bridge receives (registerPlugin('Watchtower')). */\nexport interface NativeOptions {\n key: string;\n endpoint: string;\n service: string;\n release?: string;\n environment?: string;\n replay: boolean;\n}\n\nexport interface NativePlugin {\n init(o: NativeOptions): Promise<void>;\n flush(): Promise<void>;\n}\n\nexport interface Deps {\n browser: { init(c: WatchtowerConfig): WatchtowerClient };\n plugin: NativePlugin;\n /** Whether the webview runs inside the iOS/Android shell. */\n isNative: boolean;\n}\n\nconst REQUIRED = [\"publishableKey\", \"endpoint\", \"service\"] as const;\n\nexport function createWatchtower({ browser, plugin, isNative }: Deps) {\n let web: WatchtowerClient | undefined;\n return {\n /** Starts the browser SDK in the webview and, on devices, the native SDK (crashes, ANR/hangs, replay). */\n async init(o: InitOptions): Promise<WatchtowerClient> {\n for (const k of REQUIRED) if (!o?.[k]) throw new Error(`${k} is required`);\n const native = isNative && o.native !== false;\n web = browser.init({\n publishableKey: o.publishableKey,\n endpoint: o.endpoint,\n service: o.service,\n release: o.release,\n environment: o.environment,\n beforeSend: o.beforeSend,\n // on a device the native SDK records the screen; the DOM recorder would duplicate it\n replay: native ? undefined : o.replay,\n });\n if (native) {\n await plugin.init({\n key: o.publishableKey,\n endpoint: o.endpoint,\n service: o.service,\n release: o.release,\n environment: o.environment,\n replay: !!o.replay,\n });\n }\n return web;\n },\n captureError(err: unknown, ctx?: Record<string, string | number | boolean>): void {\n web?.captureError(err, ctx);\n },\n async flush(): Promise<void> {\n if (isNative) await plugin.flush();\n if (web) await web.replay.flush();\n },\n };\n}\n"],
5
+ "mappings": ";AAAA,SAAS,WAAW,sBAAsB;AAC1C,YAAY,aAAa;;;ACwCzB,IAAM,WAAW,CAAC,kBAAkB,YAAY,SAAS;AAElD,SAAS,iBAAiB,EAAE,SAAAA,UAAS,QAAQ,SAAS,GAAS;AACpE,MAAI;AACJ,SAAO;AAAA;AAAA,IAEL,MAAM,KAAK,GAA2C;AACpD,iBAAW,KAAK,SAAU,KAAI,CAAC,IAAI,CAAC,EAAG,OAAM,IAAI,MAAM,GAAG,CAAC,cAAc;AACzE,YAAM,SAAS,YAAY,EAAE,WAAW;AACxC,YAAMA,SAAQ,KAAK;AAAA,QACjB,gBAAgB,EAAE;AAAA,QAClB,UAAU,EAAE;AAAA,QACZ,SAAS,EAAE;AAAA,QACX,SAAS,EAAE;AAAA,QACX,aAAa,EAAE;AAAA,QACf,YAAY,EAAE;AAAA;AAAA,QAEd,QAAQ,SAAS,SAAY,EAAE;AAAA,MACjC,CAAC;AACD,UAAI,QAAQ;AACV,cAAM,OAAO,KAAK;AAAA,UAChB,KAAK,EAAE;AAAA,UACP,UAAU,EAAE;AAAA,UACZ,SAAS,EAAE;AAAA,UACX,SAAS,EAAE;AAAA,UACX,aAAa,EAAE;AAAA,UACf,QAAQ,CAAC,CAAC,EAAE;AAAA,QACd,CAAC;AAAA,MACH;AACA,aAAO;AAAA,IACT;AAAA,IACA,aAAa,KAAc,KAAuD;AAChF,WAAK,aAAa,KAAK,GAAG;AAAA,IAC5B;AAAA,IACA,MAAM,QAAuB;AAC3B,UAAI,SAAU,OAAM,OAAO,MAAM;AACjC,UAAI,IAAK,OAAM,IAAI,OAAO,MAAM;AAAA,IAClC;AAAA,EACF;AACF;;;AD1EA,IAAM,KAAK,iBAAiB,EAAE,SAAS,QAAQ,eAA6B,YAAY,GAAG,UAAU,UAAU,iBAAiB,EAAE,CAAC;AAE5H,IAAM,OAAO,GAAG;AAChB,IAAM,eAAe,GAAG;AACxB,IAAM,QAAQ,GAAG;",
6
+ "names": ["browser"]
7
+ }
@@ -0,0 +1,33 @@
1
+ import Capacitor
2
+ import Watchtower
3
+
4
+ /// Bridge to the native iOS SDK: crashes, hangs, app start, frame metrics and screenshot replay.
5
+ @objc(WatchtowerPlugin)
6
+ public class WatchtowerPlugin: CAPPlugin, CAPBridgedPlugin {
7
+ public let identifier = "WatchtowerPlugin"
8
+ public let jsName = "Watchtower"
9
+ public let pluginMethods: [CAPPluginMethod] = [
10
+ CAPPluginMethod(name: "init", returnType: CAPPluginReturnPromise),
11
+ CAPPluginMethod(name: "flush", returnType: CAPPluginReturnPromise),
12
+ ]
13
+
14
+ @objc func `init`(_ call: CAPPluginCall) {
15
+ guard let key = call.getString("key"), let service = call.getString("service"),
16
+ let endpoint = call.getString("endpoint") else {
17
+ call.reject("key, service and endpoint are required")
18
+ return
19
+ }
20
+ var cfg = Config(key: key, service: service)
21
+ cfg.endpoint = endpoint
22
+ cfg.release = call.getString("release")
23
+ cfg.environment = call.getString("environment")
24
+ cfg.replay.enabled = call.getBool("replay") ?? false
25
+ Watchtower.start(cfg)
26
+ call.resolve()
27
+ }
28
+
29
+ @objc func flush(_ call: CAPPluginCall) {
30
+ Watchtower.shared.flush()
31
+ call.resolve()
32
+ }
33
+ }
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "@watchtowerobservability/capacitor",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "repository": { "type": "git", "url": "git+https://github.com/watchtowerobservability/watchtower-capacitor.git" },
5
+ "publishConfig": {
6
+ "access": "public",
7
+ "registry": "https://registry.npmjs.org/"
8
+ },
9
+ "description": "Watchtower Capacitor plugin: browser SDK in the webview plus native iOS and Android SDKs",
10
+ "type": "module",
11
+ "packageManager": "pnpm@11.2.2",
12
+ "sideEffects": false,
13
+ "main": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" }
17
+ },
18
+ "files": ["dist", "android", "ios", "Package.swift", "WatchtowerobservabilityCapacitor.podspec"],
19
+ "license": "Apache-2.0",
20
+ "engines": { "node": ">=18" },
21
+ "capacitor": {
22
+ "ios": { "src": "ios" },
23
+ "android": { "src": "android" }
24
+ },
25
+ "peerDependencies": {
26
+ "@capacitor/core": ">=6",
27
+ "@watchtowerobservability/browser": ">=0.1.0"
28
+ },
29
+ "scripts": {
30
+ "prebuild": "node scripts/browser-src.mjs",
31
+ "build": "node esbuild.config.mjs && tsgo -p tsconfig.build.json",
32
+ "typecheck": "tsgo --noEmit",
33
+ "test": "vitest run"
34
+ },
35
+ "devDependencies": {
36
+ "@capacitor/core": "6.2.0",
37
+ "@types/node": "22.10.2",
38
+ "@typescript/native-preview": "7.0.0-dev.20260707.2",
39
+ "esbuild": "0.25.10",
40
+ "vitest": "5.0.5"
41
+ }
42
+ }