@quipuscore/watson-core-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/android/build.gradle +1 -1
- package/android/src/main/java/com/quipuscore/watson/core/CapacitorPermissionRequester.java +10 -3
- package/android/src/main/java/com/quipuscore/watson/core/WatsonCorePlugin.java +158 -42
- package/dist/esm/definitions.d.ts +16 -0
- package/dist/esm/definitions.d.ts.map +1 -1
- package/dist/esm/definitions.js +15 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/service.d.ts +14 -5
- package/dist/esm/service.d.ts.map +1 -1
- package/dist/esm/service.js +14 -5
- package/dist/esm/service.js.map +1 -1
- package/dist/esm/web.js +1 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +32 -6
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +32 -6
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
package/android/build.gradle
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
ext {
|
|
2
2
|
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
|
|
3
3
|
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
4
|
-
watsonCoreVersion = project.hasProperty('watsonCoreVersion') ? rootProject.ext.watsonCoreVersion : '0.
|
|
4
|
+
watsonCoreVersion = project.hasProperty('watsonCoreVersion') ? rootProject.ext.watsonCoreVersion : '0.2.0'
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
buildscript {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
package com.quipuscore.watson.core;
|
|
2
2
|
|
|
3
3
|
import android.Manifest;
|
|
4
|
+
import android.content.Context;
|
|
4
5
|
|
|
5
6
|
import com.getcapacitor.PluginCall;
|
|
7
|
+
import com.getcapacitor.util.PermissionHelper;
|
|
6
8
|
|
|
7
9
|
import com.quipuscore.watson.core.PermissionRequester;
|
|
8
10
|
import com.quipuscore.watson.core.PermissionResultCallback;
|
|
@@ -34,7 +36,7 @@ final class CapacitorPermissionRequester implements PermissionRequester {
|
|
|
34
36
|
|
|
35
37
|
@Override
|
|
36
38
|
public void requestPermissions(List<String> permissions, PermissionResultCallback onComplete) {
|
|
37
|
-
String[] aliases = aliasesFor(permissions);
|
|
39
|
+
String[] aliases = aliasesFor(plugin.getContext(), permissions);
|
|
38
40
|
if (aliases.length == 0) {
|
|
39
41
|
// Nothing this wrapper knows how to prompt for; let the core proceed and gate per collector.
|
|
40
42
|
onComplete.onPermissionsResolved();
|
|
@@ -45,11 +47,16 @@ final class CapacitorPermissionRequester implements PermissionRequester {
|
|
|
45
47
|
|
|
46
48
|
/**
|
|
47
49
|
* Maps runtime permission strings to the aliases declared in {@link WatsonCorePlugin}. Unknown
|
|
48
|
-
* permissions are dropped (a new collector permission needs a new alias in the plugin)
|
|
50
|
+
* permissions are dropped (a new collector permission needs a new alias in the plugin), and so
|
|
51
|
+
* are permissions missing from the app manifest (e.g. removed with {@code tools:node="remove"}):
|
|
52
|
+
* Capacitor would reject such a prompt without ever calling back, stalling the prompt queue.
|
|
49
53
|
*/
|
|
50
|
-
private static String[] aliasesFor(List<String> permissions) {
|
|
54
|
+
private static String[] aliasesFor(Context context, List<String> permissions) {
|
|
51
55
|
Set<String> aliases = new LinkedHashSet<>();
|
|
52
56
|
for (String permission : permissions) {
|
|
57
|
+
if (!PermissionHelper.hasDefinedPermission(context, permission)) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
53
60
|
if (Manifest.permission.READ_SMS.equals(permission)) {
|
|
54
61
|
aliases.add("sms");
|
|
55
62
|
} else if (Manifest.permission.READ_CALENDAR.equals(permission)) {
|
|
@@ -15,10 +15,13 @@ import com.quipuscore.watson.core.CollectionCallback;
|
|
|
15
15
|
import com.quipuscore.watson.core.CollectionResult;
|
|
16
16
|
import com.quipuscore.watson.core.CollectorOutcome;
|
|
17
17
|
import com.quipuscore.watson.core.PermissionResultCallback;
|
|
18
|
+
import com.quipuscore.watson.core.WatsonRegistry;
|
|
18
19
|
import com.quipuscore.watson.core.WatsonService;
|
|
19
20
|
|
|
20
|
-
import org.json.
|
|
21
|
+
import org.json.JSONArray;
|
|
21
22
|
|
|
23
|
+
import java.util.ArrayDeque;
|
|
24
|
+
import java.util.ArrayList;
|
|
22
25
|
import java.util.List;
|
|
23
26
|
|
|
24
27
|
/**
|
|
@@ -32,6 +35,10 @@ import java.util.List;
|
|
|
32
35
|
* collector modules at compile time: the strings are Android constants, and the dangerous permission
|
|
33
36
|
* reaches the merged manifest through the collector artifact the developer installed. A new collector
|
|
34
37
|
* with a new permission means adding its alias here.
|
|
38
|
+
*
|
|
39
|
+
* <p>Every failure reaches JS as a rejected Promise with a stable {@code code} (mirrored by
|
|
40
|
+
* {@code WatsonErrorCode} in TypeScript); nothing is allowed to escape a plugin method, where the
|
|
41
|
+
* Capacitor bridge would rethrow it and crash the app.
|
|
35
42
|
*/
|
|
36
43
|
@CapacitorPlugin(
|
|
37
44
|
name = "WatsonCore",
|
|
@@ -43,49 +50,68 @@ import java.util.List;
|
|
|
43
50
|
)
|
|
44
51
|
public class WatsonCorePlugin extends Plugin {
|
|
45
52
|
|
|
46
|
-
/**
|
|
47
|
-
|
|
53
|
+
/** The {@code collectors} option is not an array of non-empty strings. */
|
|
54
|
+
static final String ERROR_INVALID_ARGUMENT = "WATSON_INVALID_ARGUMENT";
|
|
55
|
+
/** A collector id has no native module registered: package missing or not synced. */
|
|
56
|
+
static final String ERROR_COLLECTOR_NOT_INSTALLED = "WATSON_COLLECTOR_NOT_INSTALLED";
|
|
57
|
+
/** Any other native failure while starting the run. */
|
|
58
|
+
static final String ERROR_INTERNAL = "WATSON_INTERNAL";
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Permission prompts waiting for their turn. Android shows one permission dialog at a time and
|
|
62
|
+
* answers a second simultaneous request with an empty result, so overlapping collections (e.g.
|
|
63
|
+
* {@code Promise.all}) are prompted strictly one after the other, each resuming its own run.
|
|
64
|
+
* Guarded by itself: prompts are queued from the plugin thread and resolved on the main thread.
|
|
65
|
+
*/
|
|
66
|
+
private final ArrayDeque<PendingPrompt> queuedPrompts = new ArrayDeque<>();
|
|
67
|
+
private PendingPrompt activePrompt;
|
|
48
68
|
|
|
49
69
|
@PluginMethod
|
|
50
70
|
public void collect(PluginCall call) {
|
|
51
71
|
final WatsonService service;
|
|
52
72
|
try {
|
|
53
73
|
service = buildService(call);
|
|
54
|
-
} catch (
|
|
55
|
-
call.reject(
|
|
74
|
+
} catch (WatsonCallException e) {
|
|
75
|
+
call.reject(e.getMessage(), e.code);
|
|
76
|
+
return;
|
|
77
|
+
} catch (Exception e) {
|
|
78
|
+
call.reject(messageOf(e), ERROR_INTERNAL, e);
|
|
56
79
|
return;
|
|
57
80
|
}
|
|
58
81
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
82
|
+
try {
|
|
83
|
+
service.collect(new CollectionCallback() {
|
|
84
|
+
@Override
|
|
85
|
+
public void onSuccess(CollectionResult result) {
|
|
86
|
+
call.resolve(toJs(result));
|
|
87
|
+
}
|
|
64
88
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
89
|
+
@Override
|
|
90
|
+
public void onError(Exception error) {
|
|
91
|
+
call.reject(messageOf(error), error);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
} catch (Exception e) {
|
|
95
|
+
call.reject(messageOf(e), ERROR_INTERNAL, e);
|
|
96
|
+
}
|
|
70
97
|
}
|
|
71
98
|
|
|
72
99
|
@PluginMethod
|
|
73
100
|
public void getUngrantedPermissions(PluginCall call) {
|
|
74
|
-
final WatsonService service;
|
|
75
101
|
try {
|
|
76
|
-
service = buildService(call);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
102
|
+
WatsonService service = buildService(call);
|
|
103
|
+
JSArray permissions = new JSArray();
|
|
104
|
+
for (String permission : service.getUngrantedPermissions()) {
|
|
105
|
+
permissions.put(permission);
|
|
106
|
+
}
|
|
107
|
+
JSObject ret = new JSObject();
|
|
108
|
+
ret.put("permissions", permissions);
|
|
109
|
+
call.resolve(ret);
|
|
110
|
+
} catch (WatsonCallException e) {
|
|
111
|
+
call.reject(e.getMessage(), e.code);
|
|
112
|
+
} catch (Exception e) {
|
|
113
|
+
call.reject(messageOf(e), ERROR_INTERNAL, e);
|
|
85
114
|
}
|
|
86
|
-
JSObject ret = new JSObject();
|
|
87
|
-
ret.put("permissions", permissions);
|
|
88
|
-
call.resolve(ret);
|
|
89
115
|
}
|
|
90
116
|
|
|
91
117
|
/**
|
|
@@ -93,12 +119,9 @@ public class WatsonCorePlugin extends Plugin {
|
|
|
93
119
|
* {@link #load()}) so every collector plugin has already registered its factory in the core's
|
|
94
120
|
* registry by the time collection runs.
|
|
95
121
|
*/
|
|
96
|
-
private WatsonService buildService(PluginCall call) throws
|
|
122
|
+
private WatsonService buildService(PluginCall call) throws WatsonCallException {
|
|
97
123
|
WatsonService.Builder builder = new WatsonService.Builder(getContext());
|
|
98
|
-
|
|
99
|
-
List<String> idList = ids.toList();
|
|
100
|
-
for (String id : idList) {
|
|
101
|
-
// Resolves via the core's WatsonRegistry; throws if the matching module is not installed.
|
|
124
|
+
for (String id : collectorIds(call)) {
|
|
102
125
|
builder.addCollector(id);
|
|
103
126
|
}
|
|
104
127
|
WatsonService service = builder
|
|
@@ -110,25 +133,95 @@ public class WatsonCorePlugin extends Plugin {
|
|
|
110
133
|
}
|
|
111
134
|
|
|
112
135
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
136
|
+
* The {@code collectors} option, validated: an array of non-empty strings, each with a native
|
|
137
|
+
* module registered in the core. Checked up front so a missing module becomes a clear rejection
|
|
138
|
+
* instead of an exception from the core's registry.
|
|
139
|
+
*/
|
|
140
|
+
private static List<String> collectorIds(PluginCall call) throws WatsonCallException {
|
|
141
|
+
Object raw = call.getData().opt("collectors");
|
|
142
|
+
List<String> ids = new ArrayList<>();
|
|
143
|
+
if (raw == null) {
|
|
144
|
+
return ids;
|
|
145
|
+
}
|
|
146
|
+
if (!(raw instanceof JSONArray)) {
|
|
147
|
+
throw new WatsonCallException(ERROR_INVALID_ARGUMENT,
|
|
148
|
+
"'collectors' must be an array of collector ids.");
|
|
149
|
+
}
|
|
150
|
+
JSONArray array = (JSONArray) raw;
|
|
151
|
+
for (int i = 0; i < array.length(); i++) {
|
|
152
|
+
Object id = array.opt(i);
|
|
153
|
+
if (!(id instanceof String) || ((String) id).isEmpty()) {
|
|
154
|
+
throw new WatsonCallException(ERROR_INVALID_ARGUMENT,
|
|
155
|
+
"'collectors' must contain only non-empty strings; item " + i + " is " + id + ".");
|
|
156
|
+
}
|
|
157
|
+
if (!WatsonRegistry.isRegistered((String) id)) {
|
|
158
|
+
throw new WatsonCallException(ERROR_COLLECTOR_NOT_INSTALLED,
|
|
159
|
+
"No Watson collector is installed for id '" + id + "'. Install its Capacitor "
|
|
160
|
+
+ "package (@quipuscore/watson-" + id + "-capacitor) and run "
|
|
161
|
+
+ "`npx cap sync android`.");
|
|
162
|
+
}
|
|
163
|
+
ids.add((String) id);
|
|
164
|
+
}
|
|
165
|
+
return ids;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Queues the Capacitor permission prompt for {@code aliases}; {@code onComplete} resumes the parked
|
|
170
|
+
* collection once the user has answered. Called only by {@link CapacitorPermissionRequester}.
|
|
116
171
|
*/
|
|
117
172
|
void promptForAliases(String[] aliases, PluginCall call, PermissionResultCallback onComplete) {
|
|
118
|
-
|
|
119
|
-
|
|
173
|
+
PendingPrompt next = null;
|
|
174
|
+
synchronized (queuedPrompts) {
|
|
175
|
+
queuedPrompts.add(new PendingPrompt(aliases, call, onComplete));
|
|
176
|
+
if (activePrompt == null) {
|
|
177
|
+
activePrompt = queuedPrompts.poll();
|
|
178
|
+
next = activePrompt;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (next != null) {
|
|
182
|
+
launch(next);
|
|
183
|
+
}
|
|
120
184
|
}
|
|
121
185
|
|
|
122
186
|
@PermissionCallback
|
|
123
187
|
private void handleWatsonPermissions(PluginCall call) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
188
|
+
// Only one prompt is ever in flight, so this result answers the active one; Capacitor's own
|
|
189
|
+
// saved-call queue is in the same order.
|
|
190
|
+
finishActivePrompt();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Resumes the run whose prompt just ended and opens the next queued prompt, if any. */
|
|
194
|
+
private void finishActivePrompt() {
|
|
195
|
+
PendingPrompt finished;
|
|
196
|
+
PendingPrompt next;
|
|
197
|
+
synchronized (queuedPrompts) {
|
|
198
|
+
finished = activePrompt;
|
|
199
|
+
activePrompt = queuedPrompts.poll();
|
|
200
|
+
next = activePrompt;
|
|
201
|
+
}
|
|
202
|
+
if (finished != null) {
|
|
127
203
|
// The core re-reads live grant state per collector; no results are carried back here.
|
|
128
|
-
|
|
204
|
+
finished.onComplete.onPermissionsResolved();
|
|
205
|
+
}
|
|
206
|
+
if (next != null) {
|
|
207
|
+
launch(next);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private void launch(PendingPrompt prompt) {
|
|
212
|
+
try {
|
|
213
|
+
requestPermissionForAliases(prompt.aliases, prompt.call, "handleWatsonPermissions");
|
|
214
|
+
} catch (RuntimeException e) {
|
|
215
|
+
// The dialog never opened: let that run go on (the core gates what is still missing)
|
|
216
|
+
// and keep the queue moving rather than leaving every later prompt waiting.
|
|
217
|
+
finishActivePrompt();
|
|
129
218
|
}
|
|
130
219
|
}
|
|
131
220
|
|
|
221
|
+
private static String messageOf(Exception e) {
|
|
222
|
+
return e.getMessage() != null ? e.getMessage() : e.getClass().getSimpleName();
|
|
223
|
+
}
|
|
224
|
+
|
|
132
225
|
private JSObject toJs(CollectionResult result) {
|
|
133
226
|
JSObject res = new JSObject();
|
|
134
227
|
res.put("data", result.getData());
|
|
@@ -153,4 +246,27 @@ public class WatsonCorePlugin extends Plugin {
|
|
|
153
246
|
res.put("outcomes", outcomes);
|
|
154
247
|
return res;
|
|
155
248
|
}
|
|
249
|
+
|
|
250
|
+
/** One permission prompt waiting for its turn, with the run it resumes. */
|
|
251
|
+
private static final class PendingPrompt {
|
|
252
|
+
final String[] aliases;
|
|
253
|
+
final PluginCall call;
|
|
254
|
+
final PermissionResultCallback onComplete;
|
|
255
|
+
|
|
256
|
+
PendingPrompt(String[] aliases, PluginCall call, PermissionResultCallback onComplete) {
|
|
257
|
+
this.aliases = aliases;
|
|
258
|
+
this.call = call;
|
|
259
|
+
this.onComplete = onComplete;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** A rejection with a stable code, raised before the native service is built. */
|
|
264
|
+
private static final class WatsonCallException extends Exception {
|
|
265
|
+
final String code;
|
|
266
|
+
|
|
267
|
+
WatsonCallException(String code, String message) {
|
|
268
|
+
super(message);
|
|
269
|
+
this.code = code;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
156
272
|
}
|
|
@@ -25,6 +25,22 @@ export interface CollectionResult {
|
|
|
25
25
|
/** Per-collector outcomes, including the ones that were skipped or failed. */
|
|
26
26
|
outcomes: CollectorOutcome[];
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Stable `code` of the errors the native plugin rejects with, so callers can branch on
|
|
30
|
+
* `error.code` instead of parsing messages.
|
|
31
|
+
*/
|
|
32
|
+
export declare const WatsonErrorCode: {
|
|
33
|
+
/** The `collectors` option is not an array of non-empty strings. */
|
|
34
|
+
readonly INVALID_ARGUMENT: "WATSON_INVALID_ARGUMENT";
|
|
35
|
+
/**
|
|
36
|
+
* A collector was added in JS but its native module is not in the running app: its package is not
|
|
37
|
+
* installed or `npx cap sync android` was not run.
|
|
38
|
+
*/
|
|
39
|
+
readonly COLLECTOR_NOT_INSTALLED: "WATSON_COLLECTOR_NOT_INSTALLED";
|
|
40
|
+
/** Any other native failure while starting the run. */
|
|
41
|
+
readonly INTERNAL: "WATSON_INTERNAL";
|
|
42
|
+
};
|
|
43
|
+
export type WatsonErrorCode = (typeof WatsonErrorCode)[keyof typeof WatsonErrorCode];
|
|
28
44
|
/**
|
|
29
45
|
* Low-level bridge contract for the native `WatsonCore` plugin. Application code should use the
|
|
30
46
|
* {@link WatsonService} class instead of calling this plugin directly.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,mBAAmB,GACnB,+BAA+B,GAC/B,OAAO,CAAC;AAEZ,uFAAuF;AACvF,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,eAAe,CAAC;IACxB,kEAAkE;IAClE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,kBAAkB,EAAE,MAAM,EAAE,CAAC;CAC9B;AAED,yEAAyE;AACzE,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,0FAA0F;IAC1F,YAAY,EAAE,MAAM,CAAC;IACrB,+FAA+F;IAC/F,UAAU,EAAE,OAAO,CAAC;IACpB,8EAA8E;IAC9E,QAAQ,EAAE,gBAAgB,EAAE,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,8FAA8F;IAC9F,OAAO,CAAC,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACtE,4FAA4F;IAC5F,uBAAuB,CAAC,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,WAAW,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;CAChG"}
|
|
1
|
+
{"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,mBAAmB,GACnB,+BAA+B,GAC/B,OAAO,CAAC;AAEZ,uFAAuF;AACvF,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,eAAe,CAAC;IACxB,kEAAkE;IAClE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,kBAAkB,EAAE,MAAM,EAAE,CAAC;CAC9B;AAED,yEAAyE;AACzE,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,0FAA0F;IAC1F,YAAY,EAAE,MAAM,CAAC;IACrB,+FAA+F;IAC/F,UAAU,EAAE,OAAO,CAAC;IACpB,8EAA8E;IAC9E,QAAQ,EAAE,gBAAgB,EAAE,CAAC;CAC9B;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe;IAC1B,oEAAoE;;IAEpE;;;OAGG;;IAEH,uDAAuD;;CAE/C,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,OAAO,eAAe,CAAC,CAAC;AAErF;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,8FAA8F;IAC9F,OAAO,CAAC,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACtE,4FAA4F;IAC5F,uBAAuB,CAAC,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,WAAW,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;CAChG"}
|
package/dist/esm/definitions.js
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Stable `code` of the errors the native plugin rejects with, so callers can branch on
|
|
3
|
+
* `error.code` instead of parsing messages.
|
|
4
|
+
*/
|
|
5
|
+
export const WatsonErrorCode = {
|
|
6
|
+
/** The `collectors` option is not an array of non-empty strings. */
|
|
7
|
+
INVALID_ARGUMENT: 'WATSON_INVALID_ARGUMENT',
|
|
8
|
+
/**
|
|
9
|
+
* A collector was added in JS but its native module is not in the running app: its package is not
|
|
10
|
+
* installed or `npx cap sync android` was not run.
|
|
11
|
+
*/
|
|
12
|
+
COLLECTOR_NOT_INSTALLED: 'WATSON_COLLECTOR_NOT_INSTALLED',
|
|
13
|
+
/** Any other native failure while starting the run. */
|
|
14
|
+
INTERNAL: 'WATSON_INTERNAL',
|
|
15
|
+
};
|
|
2
16
|
//# sourceMappingURL=definitions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAkCA;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,oEAAoE;IACpE,gBAAgB,EAAE,yBAAyB;IAC3C;;;OAGG;IACH,uBAAuB,EAAE,gCAAgC;IACzD,uDAAuD;IACvD,QAAQ,EAAE,iBAAiB;CACnB,CAAC"}
|
package/dist/esm/service.d.ts
CHANGED
|
@@ -4,20 +4,29 @@ import type { CollectionResult } from './definitions';
|
|
|
4
4
|
* JS-side orchestrator, mirroring the native `WatsonService`. It accumulates the ids of the
|
|
5
5
|
* collectors you add and hands that list to the native `WatsonCore` plugin on {@link collect}.
|
|
6
6
|
*
|
|
7
|
-
* The always-on `device` baseline is added by the native core itself; you never add it here.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* The always-on `device` baseline is added by the native core itself; you never add it here.
|
|
8
|
+
* Differences with the native Android API: `new WatsonService()` takes no `context` (the plugin
|
|
9
|
+
* injects it); the permission prompt is always delivered by the plugin, so there is no
|
|
10
|
+
* `setActivity` / `handlePermissionResult` / custom requester; `collect()` always prompts for missing
|
|
11
|
+
* permissions (no `requestPermissionsIfNeeded = false` yet); collectors run with their default
|
|
12
|
+
* configuration (no SMS `FilterConfig` or custom calendar window yet); and errors arrive as a
|
|
13
|
+
* rejected Promise instead of `onError`.
|
|
10
14
|
*/
|
|
11
15
|
export declare class WatsonService {
|
|
12
16
|
private readonly collectorIds;
|
|
13
17
|
/**
|
|
14
|
-
* Registers a collector to run. Explicit by design: a collector you don't add is not collected
|
|
15
|
-
*
|
|
18
|
+
* Registers a collector to run. Explicit by design: a collector you don't add is not collected.
|
|
19
|
+
* Its runtime permission, though, reaches the app manifest by installing its package, whether or
|
|
20
|
+
* not you add it. Adding the same id twice is a no-op.
|
|
16
21
|
*/
|
|
17
22
|
addCollector(collector: WatsonCollector): void;
|
|
18
23
|
/**
|
|
19
24
|
* Runs every added collector natively and resolves with the compressed payload and the
|
|
20
25
|
* per-collector outcomes. A denied or failing collector never aborts the others.
|
|
26
|
+
*
|
|
27
|
+
* Overlapping calls (e.g. `Promise.all`) are fine: their permission prompts are shown one after
|
|
28
|
+
* the other and each call resolves with its own result. Rejects with a `WatsonErrorCode`
|
|
29
|
+
* `code` when the run cannot start, e.g. `WATSON_COLLECTOR_NOT_INSTALLED`.
|
|
21
30
|
*/
|
|
22
31
|
collect(): Promise<CollectionResult>;
|
|
23
32
|
/** The runtime permissions required by the added collectors that are not granted yet. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGtD
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGtD;;;;;;;;;;;GAWG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAgB;IAE7C;;;;OAIG;IACH,YAAY,CAAC,SAAS,EAAE,eAAe,GAAG,IAAI;IAS9C;;;;;;;OAOG;IACH,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAIpC,yFAAyF;IACnF,uBAAuB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAMnD"}
|
package/dist/esm/service.js
CHANGED
|
@@ -3,17 +3,22 @@ import { WatsonCore } from './plugin';
|
|
|
3
3
|
* JS-side orchestrator, mirroring the native `WatsonService`. It accumulates the ids of the
|
|
4
4
|
* collectors you add and hands that list to the native `WatsonCore` plugin on {@link collect}.
|
|
5
5
|
*
|
|
6
|
-
* The always-on `device` baseline is added by the native core itself; you never add it here.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* The always-on `device` baseline is added by the native core itself; you never add it here.
|
|
7
|
+
* Differences with the native Android API: `new WatsonService()` takes no `context` (the plugin
|
|
8
|
+
* injects it); the permission prompt is always delivered by the plugin, so there is no
|
|
9
|
+
* `setActivity` / `handlePermissionResult` / custom requester; `collect()` always prompts for missing
|
|
10
|
+
* permissions (no `requestPermissionsIfNeeded = false` yet); collectors run with their default
|
|
11
|
+
* configuration (no SMS `FilterConfig` or custom calendar window yet); and errors arrive as a
|
|
12
|
+
* rejected Promise instead of `onError`.
|
|
9
13
|
*/
|
|
10
14
|
export class WatsonService {
|
|
11
15
|
constructor() {
|
|
12
16
|
this.collectorIds = [];
|
|
13
17
|
}
|
|
14
18
|
/**
|
|
15
|
-
* Registers a collector to run. Explicit by design: a collector you don't add is not collected
|
|
16
|
-
*
|
|
19
|
+
* Registers a collector to run. Explicit by design: a collector you don't add is not collected.
|
|
20
|
+
* Its runtime permission, though, reaches the app manifest by installing its package, whether or
|
|
21
|
+
* not you add it. Adding the same id twice is a no-op.
|
|
17
22
|
*/
|
|
18
23
|
addCollector(collector) {
|
|
19
24
|
if (!collector || !collector.id) {
|
|
@@ -26,6 +31,10 @@ export class WatsonService {
|
|
|
26
31
|
/**
|
|
27
32
|
* Runs every added collector natively and resolves with the compressed payload and the
|
|
28
33
|
* per-collector outcomes. A denied or failing collector never aborts the others.
|
|
34
|
+
*
|
|
35
|
+
* Overlapping calls (e.g. `Promise.all`) are fine: their permission prompts are shown one after
|
|
36
|
+
* the other and each call resolves with its own result. Rejects with a `WatsonErrorCode`
|
|
37
|
+
* `code` when the run cannot start, e.g. `WATSON_COLLECTOR_NOT_INSTALLED`.
|
|
29
38
|
*/
|
|
30
39
|
collect() {
|
|
31
40
|
return WatsonCore.collect({ collectors: this.collectorIds });
|
package/dist/esm/service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,aAAa;IAA1B;QACmB,iBAAY,GAAa,EAAE,CAAC;IAmC/C,CAAC;IAjCC;;;;OAIG;IACH,YAAY,CAAC,SAA0B;QACrC,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;QAC3E,CAAC;QACD,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YACnD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACH,OAAO;QACL,OAAO,UAAU,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;IAC/D,CAAC;IAED,yFAAyF;IACzF,KAAK,CAAC,uBAAuB;QAC3B,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,UAAU,CAAC,uBAAuB,CAAC;YAC/D,UAAU,EAAE,IAAI,CAAC,YAAY;SAC9B,CAAC,CAAC;QACH,OAAO,WAAW,CAAC;IACrB,CAAC;CACF"}
|
package/dist/esm/web.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
-
const MESSAGE = 'Watson is only available on Android
|
|
2
|
+
const MESSAGE = 'Watson is only available on Android (iOS is not implemented yet).';
|
|
3
3
|
export class WatsonCoreWeb extends WebPlugin {
|
|
4
4
|
async collect() {
|
|
5
5
|
throw this.unimplemented(MESSAGE);
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,GAAG,mEAAmE,CAAC;AAEpF,MAAM,OAAO,aAAc,SAAQ,SAAS;IAC1C,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,uBAAuB;QAC3B,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;CACF"}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
var core = require('@capacitor/core');
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Stable `code` of the errors the native plugin rejects with, so callers can branch on
|
|
7
|
+
* `error.code` instead of parsing messages.
|
|
8
|
+
*/
|
|
9
|
+
const WatsonErrorCode = {
|
|
10
|
+
/** The `collectors` option is not an array of non-empty strings. */
|
|
11
|
+
INVALID_ARGUMENT: 'WATSON_INVALID_ARGUMENT',
|
|
12
|
+
/**
|
|
13
|
+
* A collector was added in JS but its native module is not in the running app: its package is not
|
|
14
|
+
* installed or `npx cap sync android` was not run.
|
|
15
|
+
*/
|
|
16
|
+
COLLECTOR_NOT_INSTALLED: 'WATSON_COLLECTOR_NOT_INSTALLED',
|
|
17
|
+
/** Any other native failure while starting the run. */
|
|
18
|
+
INTERNAL: 'WATSON_INTERNAL',
|
|
19
|
+
};
|
|
20
|
+
|
|
5
21
|
/**
|
|
6
22
|
* Base type for a collector descriptor.
|
|
7
23
|
*
|
|
@@ -25,17 +41,22 @@ const WatsonCore = core.registerPlugin('WatsonCore', {
|
|
|
25
41
|
* JS-side orchestrator, mirroring the native `WatsonService`. It accumulates the ids of the
|
|
26
42
|
* collectors you add and hands that list to the native `WatsonCore` plugin on {@link collect}.
|
|
27
43
|
*
|
|
28
|
-
* The always-on `device` baseline is added by the native core itself; you never add it here.
|
|
29
|
-
*
|
|
30
|
-
*
|
|
44
|
+
* The always-on `device` baseline is added by the native core itself; you never add it here.
|
|
45
|
+
* Differences with the native Android API: `new WatsonService()` takes no `context` (the plugin
|
|
46
|
+
* injects it); the permission prompt is always delivered by the plugin, so there is no
|
|
47
|
+
* `setActivity` / `handlePermissionResult` / custom requester; `collect()` always prompts for missing
|
|
48
|
+
* permissions (no `requestPermissionsIfNeeded = false` yet); collectors run with their default
|
|
49
|
+
* configuration (no SMS `FilterConfig` or custom calendar window yet); and errors arrive as a
|
|
50
|
+
* rejected Promise instead of `onError`.
|
|
31
51
|
*/
|
|
32
52
|
class WatsonService {
|
|
33
53
|
constructor() {
|
|
34
54
|
this.collectorIds = [];
|
|
35
55
|
}
|
|
36
56
|
/**
|
|
37
|
-
* Registers a collector to run. Explicit by design: a collector you don't add is not collected
|
|
38
|
-
*
|
|
57
|
+
* Registers a collector to run. Explicit by design: a collector you don't add is not collected.
|
|
58
|
+
* Its runtime permission, though, reaches the app manifest by installing its package, whether or
|
|
59
|
+
* not you add it. Adding the same id twice is a no-op.
|
|
39
60
|
*/
|
|
40
61
|
addCollector(collector) {
|
|
41
62
|
if (!collector || !collector.id) {
|
|
@@ -48,6 +69,10 @@ class WatsonService {
|
|
|
48
69
|
/**
|
|
49
70
|
* Runs every added collector natively and resolves with the compressed payload and the
|
|
50
71
|
* per-collector outcomes. A denied or failing collector never aborts the others.
|
|
72
|
+
*
|
|
73
|
+
* Overlapping calls (e.g. `Promise.all`) are fine: their permission prompts are shown one after
|
|
74
|
+
* the other and each call resolves with its own result. Rejects with a `WatsonErrorCode`
|
|
75
|
+
* `code` when the run cannot start, e.g. `WATSON_COLLECTOR_NOT_INSTALLED`.
|
|
51
76
|
*/
|
|
52
77
|
collect() {
|
|
53
78
|
return WatsonCore.collect({ collectors: this.collectorIds });
|
|
@@ -61,7 +86,7 @@ class WatsonService {
|
|
|
61
86
|
}
|
|
62
87
|
}
|
|
63
88
|
|
|
64
|
-
const MESSAGE = 'Watson is only available on Android
|
|
89
|
+
const MESSAGE = 'Watson is only available on Android (iOS is not implemented yet).';
|
|
65
90
|
class WatsonCoreWeb extends core.WebPlugin {
|
|
66
91
|
async collect() {
|
|
67
92
|
throw this.unimplemented(MESSAGE);
|
|
@@ -78,5 +103,6 @@ var web = /*#__PURE__*/Object.freeze({
|
|
|
78
103
|
|
|
79
104
|
exports.WatsonCollector = WatsonCollector;
|
|
80
105
|
exports.WatsonCore = WatsonCore;
|
|
106
|
+
exports.WatsonErrorCode = WatsonErrorCode;
|
|
81
107
|
exports.WatsonService = WatsonService;
|
|
82
108
|
//# sourceMappingURL=plugin.cjs.js.map
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/collector.js","esm/plugin.js","esm/service.js","esm/web.js"],"sourcesContent":["/**\n * Base type for a collector descriptor.\n *\n * Collector packages (for example `@quipuscore/watson-sms-capacitor`) extend this with the stable `id` their\n * native module registered with the Watson core. A descriptor carries no logic: it only tells the\n * core, across the bridge, which registered collector to run. This mirrors the explicit-registration\n * model of the native SDK — a collector you never add is never collected.\n */\nexport class WatsonCollector {\n}\n//# sourceMappingURL=collector.js.map","import { registerPlugin } from '@capacitor/core';\n/**\n * The registered native `WatsonCore` plugin proxy. Exposed for advanced use; prefer the\n * {@link WatsonService} class, which mirrors the native API surface.\n */\nexport const WatsonCore = registerPlugin('WatsonCore', {\n web: () => import('./web').then(m => new m.WatsonCoreWeb()),\n});\n//# sourceMappingURL=plugin.js.map","import { WatsonCore } from './plugin';\n/**\n * JS-side orchestrator, mirroring the native `WatsonService`. It accumulates the ids of the\n * collectors you add and hands that list to the native `WatsonCore` plugin on {@link collect}.\n *\n * The always-on `device` baseline is added by the native core itself; you never add it here
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/collector.js","esm/plugin.js","esm/service.js","esm/web.js"],"sourcesContent":["/**\n * Stable `code` of the errors the native plugin rejects with, so callers can branch on\n * `error.code` instead of parsing messages.\n */\nexport const WatsonErrorCode = {\n /** The `collectors` option is not an array of non-empty strings. */\n INVALID_ARGUMENT: 'WATSON_INVALID_ARGUMENT',\n /**\n * A collector was added in JS but its native module is not in the running app: its package is not\n * installed or `npx cap sync android` was not run.\n */\n COLLECTOR_NOT_INSTALLED: 'WATSON_COLLECTOR_NOT_INSTALLED',\n /** Any other native failure while starting the run. */\n INTERNAL: 'WATSON_INTERNAL',\n};\n//# sourceMappingURL=definitions.js.map","/**\n * Base type for a collector descriptor.\n *\n * Collector packages (for example `@quipuscore/watson-sms-capacitor`) extend this with the stable `id` their\n * native module registered with the Watson core. A descriptor carries no logic: it only tells the\n * core, across the bridge, which registered collector to run. This mirrors the explicit-registration\n * model of the native SDK — a collector you never add is never collected.\n */\nexport class WatsonCollector {\n}\n//# sourceMappingURL=collector.js.map","import { registerPlugin } from '@capacitor/core';\n/**\n * The registered native `WatsonCore` plugin proxy. Exposed for advanced use; prefer the\n * {@link WatsonService} class, which mirrors the native API surface.\n */\nexport const WatsonCore = registerPlugin('WatsonCore', {\n web: () => import('./web').then(m => new m.WatsonCoreWeb()),\n});\n//# sourceMappingURL=plugin.js.map","import { WatsonCore } from './plugin';\n/**\n * JS-side orchestrator, mirroring the native `WatsonService`. It accumulates the ids of the\n * collectors you add and hands that list to the native `WatsonCore` plugin on {@link collect}.\n *\n * The always-on `device` baseline is added by the native core itself; you never add it here.\n * Differences with the native Android API: `new WatsonService()` takes no `context` (the plugin\n * injects it); the permission prompt is always delivered by the plugin, so there is no\n * `setActivity` / `handlePermissionResult` / custom requester; `collect()` always prompts for missing\n * permissions (no `requestPermissionsIfNeeded = false` yet); collectors run with their default\n * configuration (no SMS `FilterConfig` or custom calendar window yet); and errors arrive as a\n * rejected Promise instead of `onError`.\n */\nexport class WatsonService {\n constructor() {\n this.collectorIds = [];\n }\n /**\n * Registers a collector to run. Explicit by design: a collector you don't add is not collected.\n * Its runtime permission, though, reaches the app manifest by installing its package, whether or\n * not you add it. Adding the same id twice is a no-op.\n */\n addCollector(collector) {\n if (!collector || !collector.id) {\n throw new Error('addCollector requires a collector with a non-empty id');\n }\n if (this.collectorIds.indexOf(collector.id) === -1) {\n this.collectorIds.push(collector.id);\n }\n }\n /**\n * Runs every added collector natively and resolves with the compressed payload and the\n * per-collector outcomes. A denied or failing collector never aborts the others.\n *\n * Overlapping calls (e.g. `Promise.all`) are fine: their permission prompts are shown one after\n * the other and each call resolves with its own result. Rejects with a `WatsonErrorCode`\n * `code` when the run cannot start, e.g. `WATSON_COLLECTOR_NOT_INSTALLED`.\n */\n collect() {\n return WatsonCore.collect({ collectors: this.collectorIds });\n }\n /** The runtime permissions required by the added collectors that are not granted yet. */\n async getUngrantedPermissions() {\n const { permissions } = await WatsonCore.getUngrantedPermissions({\n collectors: this.collectorIds,\n });\n return permissions;\n }\n}\n//# sourceMappingURL=service.js.map","import { WebPlugin } from '@capacitor/core';\nconst MESSAGE = 'Watson is only available on Android (iOS is not implemented yet).';\nexport class WatsonCoreWeb extends WebPlugin {\n async collect() {\n throw this.unimplemented(MESSAGE);\n }\n async getUngrantedPermissions() {\n throw this.unimplemented(MESSAGE);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACY,MAAC,eAAe,GAAG;AAC/B;AACA,IAAI,gBAAgB,EAAE,yBAAyB;AAC/C;AACA;AACA;AACA;AACA,IAAI,uBAAuB,EAAE,gCAAgC;AAC7D;AACA,IAAI,QAAQ,EAAE,iBAAiB;AAC/B;;ACdA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,eAAe,CAAC;AAC7B;;ACRA;AACA;AACA;AACA;AACY,MAAC,UAAU,GAAGA,mBAAc,CAAC,YAAY,EAAE;AACvD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;AAC/D,CAAC;;ACND;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,aAAa,CAAC;AAC3B,IAAI,WAAW,GAAG;AAClB,QAAQ,IAAI,CAAC,YAAY,GAAG,EAAE;AAC9B,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA,IAAI,YAAY,CAAC,SAAS,EAAE;AAC5B,QAAQ,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE;AACzC,YAAY,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC;AACpF,QAAQ;AACR,QAAQ,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;AAC5D,YAAY,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;AAChD,QAAQ;AACR,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,OAAO,GAAG;AACd,QAAQ,OAAO,UAAU,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,YAAY,EAAE,CAAC;AACpE,IAAI;AACJ;AACA,IAAI,MAAM,uBAAuB,GAAG;AACpC,QAAQ,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,UAAU,CAAC,uBAAuB,CAAC;AACzE,YAAY,UAAU,EAAE,IAAI,CAAC,YAAY;AACzC,SAAS,CAAC;AACV,QAAQ,OAAO,WAAW;AAC1B,IAAI;AACJ;;AC/CA,MAAM,OAAO,GAAG,mEAAmE;AAC5E,MAAM,aAAa,SAASC,cAAS,CAAC;AAC7C,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;AACzC,IAAI;AACJ,IAAI,MAAM,uBAAuB,GAAG;AACpC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;AACzC,IAAI;AACJ;;;;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
var capacitorWatsonCore = (function (exports, core) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Stable `code` of the errors the native plugin rejects with, so callers can branch on
|
|
6
|
+
* `error.code` instead of parsing messages.
|
|
7
|
+
*/
|
|
8
|
+
const WatsonErrorCode = {
|
|
9
|
+
/** The `collectors` option is not an array of non-empty strings. */
|
|
10
|
+
INVALID_ARGUMENT: 'WATSON_INVALID_ARGUMENT',
|
|
11
|
+
/**
|
|
12
|
+
* A collector was added in JS but its native module is not in the running app: its package is not
|
|
13
|
+
* installed or `npx cap sync android` was not run.
|
|
14
|
+
*/
|
|
15
|
+
COLLECTOR_NOT_INSTALLED: 'WATSON_COLLECTOR_NOT_INSTALLED',
|
|
16
|
+
/** Any other native failure while starting the run. */
|
|
17
|
+
INTERNAL: 'WATSON_INTERNAL',
|
|
18
|
+
};
|
|
19
|
+
|
|
4
20
|
/**
|
|
5
21
|
* Base type for a collector descriptor.
|
|
6
22
|
*
|
|
@@ -24,17 +40,22 @@ var capacitorWatsonCore = (function (exports, core) {
|
|
|
24
40
|
* JS-side orchestrator, mirroring the native `WatsonService`. It accumulates the ids of the
|
|
25
41
|
* collectors you add and hands that list to the native `WatsonCore` plugin on {@link collect}.
|
|
26
42
|
*
|
|
27
|
-
* The always-on `device` baseline is added by the native core itself; you never add it here.
|
|
28
|
-
*
|
|
29
|
-
*
|
|
43
|
+
* The always-on `device` baseline is added by the native core itself; you never add it here.
|
|
44
|
+
* Differences with the native Android API: `new WatsonService()` takes no `context` (the plugin
|
|
45
|
+
* injects it); the permission prompt is always delivered by the plugin, so there is no
|
|
46
|
+
* `setActivity` / `handlePermissionResult` / custom requester; `collect()` always prompts for missing
|
|
47
|
+
* permissions (no `requestPermissionsIfNeeded = false` yet); collectors run with their default
|
|
48
|
+
* configuration (no SMS `FilterConfig` or custom calendar window yet); and errors arrive as a
|
|
49
|
+
* rejected Promise instead of `onError`.
|
|
30
50
|
*/
|
|
31
51
|
class WatsonService {
|
|
32
52
|
constructor() {
|
|
33
53
|
this.collectorIds = [];
|
|
34
54
|
}
|
|
35
55
|
/**
|
|
36
|
-
* Registers a collector to run. Explicit by design: a collector you don't add is not collected
|
|
37
|
-
*
|
|
56
|
+
* Registers a collector to run. Explicit by design: a collector you don't add is not collected.
|
|
57
|
+
* Its runtime permission, though, reaches the app manifest by installing its package, whether or
|
|
58
|
+
* not you add it. Adding the same id twice is a no-op.
|
|
38
59
|
*/
|
|
39
60
|
addCollector(collector) {
|
|
40
61
|
if (!collector || !collector.id) {
|
|
@@ -47,6 +68,10 @@ var capacitorWatsonCore = (function (exports, core) {
|
|
|
47
68
|
/**
|
|
48
69
|
* Runs every added collector natively and resolves with the compressed payload and the
|
|
49
70
|
* per-collector outcomes. A denied or failing collector never aborts the others.
|
|
71
|
+
*
|
|
72
|
+
* Overlapping calls (e.g. `Promise.all`) are fine: their permission prompts are shown one after
|
|
73
|
+
* the other and each call resolves with its own result. Rejects with a `WatsonErrorCode`
|
|
74
|
+
* `code` when the run cannot start, e.g. `WATSON_COLLECTOR_NOT_INSTALLED`.
|
|
50
75
|
*/
|
|
51
76
|
collect() {
|
|
52
77
|
return WatsonCore.collect({ collectors: this.collectorIds });
|
|
@@ -60,7 +85,7 @@ var capacitorWatsonCore = (function (exports, core) {
|
|
|
60
85
|
}
|
|
61
86
|
}
|
|
62
87
|
|
|
63
|
-
const MESSAGE = 'Watson is only available on Android
|
|
88
|
+
const MESSAGE = 'Watson is only available on Android (iOS is not implemented yet).';
|
|
64
89
|
class WatsonCoreWeb extends core.WebPlugin {
|
|
65
90
|
async collect() {
|
|
66
91
|
throw this.unimplemented(MESSAGE);
|
|
@@ -77,6 +102,7 @@ var capacitorWatsonCore = (function (exports, core) {
|
|
|
77
102
|
|
|
78
103
|
exports.WatsonCollector = WatsonCollector;
|
|
79
104
|
exports.WatsonCore = WatsonCore;
|
|
105
|
+
exports.WatsonErrorCode = WatsonErrorCode;
|
|
80
106
|
exports.WatsonService = WatsonService;
|
|
81
107
|
|
|
82
108
|
return exports;
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/collector.js","esm/plugin.js","esm/service.js","esm/web.js"],"sourcesContent":["/**\n * Base type for a collector descriptor.\n *\n * Collector packages (for example `@quipuscore/watson-sms-capacitor`) extend this with the stable `id` their\n * native module registered with the Watson core. A descriptor carries no logic: it only tells the\n * core, across the bridge, which registered collector to run. This mirrors the explicit-registration\n * model of the native SDK — a collector you never add is never collected.\n */\nexport class WatsonCollector {\n}\n//# sourceMappingURL=collector.js.map","import { registerPlugin } from '@capacitor/core';\n/**\n * The registered native `WatsonCore` plugin proxy. Exposed for advanced use; prefer the\n * {@link WatsonService} class, which mirrors the native API surface.\n */\nexport const WatsonCore = registerPlugin('WatsonCore', {\n web: () => import('./web').then(m => new m.WatsonCoreWeb()),\n});\n//# sourceMappingURL=plugin.js.map","import { WatsonCore } from './plugin';\n/**\n * JS-side orchestrator, mirroring the native `WatsonService`. It accumulates the ids of the\n * collectors you add and hands that list to the native `WatsonCore` plugin on {@link collect}.\n *\n * The always-on `device` baseline is added by the native core itself; you never add it here
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/collector.js","esm/plugin.js","esm/service.js","esm/web.js"],"sourcesContent":["/**\n * Stable `code` of the errors the native plugin rejects with, so callers can branch on\n * `error.code` instead of parsing messages.\n */\nexport const WatsonErrorCode = {\n /** The `collectors` option is not an array of non-empty strings. */\n INVALID_ARGUMENT: 'WATSON_INVALID_ARGUMENT',\n /**\n * A collector was added in JS but its native module is not in the running app: its package is not\n * installed or `npx cap sync android` was not run.\n */\n COLLECTOR_NOT_INSTALLED: 'WATSON_COLLECTOR_NOT_INSTALLED',\n /** Any other native failure while starting the run. */\n INTERNAL: 'WATSON_INTERNAL',\n};\n//# sourceMappingURL=definitions.js.map","/**\n * Base type for a collector descriptor.\n *\n * Collector packages (for example `@quipuscore/watson-sms-capacitor`) extend this with the stable `id` their\n * native module registered with the Watson core. A descriptor carries no logic: it only tells the\n * core, across the bridge, which registered collector to run. This mirrors the explicit-registration\n * model of the native SDK — a collector you never add is never collected.\n */\nexport class WatsonCollector {\n}\n//# sourceMappingURL=collector.js.map","import { registerPlugin } from '@capacitor/core';\n/**\n * The registered native `WatsonCore` plugin proxy. Exposed for advanced use; prefer the\n * {@link WatsonService} class, which mirrors the native API surface.\n */\nexport const WatsonCore = registerPlugin('WatsonCore', {\n web: () => import('./web').then(m => new m.WatsonCoreWeb()),\n});\n//# sourceMappingURL=plugin.js.map","import { WatsonCore } from './plugin';\n/**\n * JS-side orchestrator, mirroring the native `WatsonService`. It accumulates the ids of the\n * collectors you add and hands that list to the native `WatsonCore` plugin on {@link collect}.\n *\n * The always-on `device` baseline is added by the native core itself; you never add it here.\n * Differences with the native Android API: `new WatsonService()` takes no `context` (the plugin\n * injects it); the permission prompt is always delivered by the plugin, so there is no\n * `setActivity` / `handlePermissionResult` / custom requester; `collect()` always prompts for missing\n * permissions (no `requestPermissionsIfNeeded = false` yet); collectors run with their default\n * configuration (no SMS `FilterConfig` or custom calendar window yet); and errors arrive as a\n * rejected Promise instead of `onError`.\n */\nexport class WatsonService {\n constructor() {\n this.collectorIds = [];\n }\n /**\n * Registers a collector to run. Explicit by design: a collector you don't add is not collected.\n * Its runtime permission, though, reaches the app manifest by installing its package, whether or\n * not you add it. Adding the same id twice is a no-op.\n */\n addCollector(collector) {\n if (!collector || !collector.id) {\n throw new Error('addCollector requires a collector with a non-empty id');\n }\n if (this.collectorIds.indexOf(collector.id) === -1) {\n this.collectorIds.push(collector.id);\n }\n }\n /**\n * Runs every added collector natively and resolves with the compressed payload and the\n * per-collector outcomes. A denied or failing collector never aborts the others.\n *\n * Overlapping calls (e.g. `Promise.all`) are fine: their permission prompts are shown one after\n * the other and each call resolves with its own result. Rejects with a `WatsonErrorCode`\n * `code` when the run cannot start, e.g. `WATSON_COLLECTOR_NOT_INSTALLED`.\n */\n collect() {\n return WatsonCore.collect({ collectors: this.collectorIds });\n }\n /** The runtime permissions required by the added collectors that are not granted yet. */\n async getUngrantedPermissions() {\n const { permissions } = await WatsonCore.getUngrantedPermissions({\n collectors: this.collectorIds,\n });\n return permissions;\n }\n}\n//# sourceMappingURL=service.js.map","import { WebPlugin } from '@capacitor/core';\nconst MESSAGE = 'Watson is only available on Android (iOS is not implemented yet).';\nexport class WatsonCoreWeb extends WebPlugin {\n async collect() {\n throw this.unimplemented(MESSAGE);\n }\n async getUngrantedPermissions() {\n throw this.unimplemented(MESSAGE);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;IAAA;IACA;IACA;IACA;AACY,UAAC,eAAe,GAAG;IAC/B;IACA,IAAI,gBAAgB,EAAE,yBAAyB;IAC/C;IACA;IACA;IACA;IACA,IAAI,uBAAuB,EAAE,gCAAgC;IAC7D;IACA,IAAI,QAAQ,EAAE,iBAAiB;IAC/B;;ICdA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACO,MAAM,eAAe,CAAC;IAC7B;;ICRA;IACA;IACA;IACA;AACY,UAAC,UAAU,GAAGA,mBAAc,CAAC,YAAY,EAAE;IACvD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;IAC/D,CAAC;;ICND;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACO,MAAM,aAAa,CAAC;IAC3B,IAAI,WAAW,GAAG;IAClB,QAAQ,IAAI,CAAC,YAAY,GAAG,EAAE;IAC9B,IAAI;IACJ;IACA;IACA;IACA;IACA;IACA,IAAI,YAAY,CAAC,SAAS,EAAE;IAC5B,QAAQ,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE;IACzC,YAAY,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC;IACpF,QAAQ;IACR,QAAQ,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;IAC5D,YAAY,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;IAChD,QAAQ;IACR,IAAI;IACJ;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,IAAI,OAAO,GAAG;IACd,QAAQ,OAAO,UAAU,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,YAAY,EAAE,CAAC;IACpE,IAAI;IACJ;IACA,IAAI,MAAM,uBAAuB,GAAG;IACpC,QAAQ,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,UAAU,CAAC,uBAAuB,CAAC;IACzE,YAAY,UAAU,EAAE,IAAI,CAAC,YAAY;IACzC,SAAS,CAAC;IACV,QAAQ,OAAO,WAAW;IAC1B,IAAI;IACJ;;IC/CA,MAAM,OAAO,GAAG,mEAAmE;IAC5E,MAAM,aAAa,SAASC,cAAS,CAAC;IAC7C,IAAI,MAAM,OAAO,GAAG;IACpB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;IACzC,IAAI;IACJ,IAAI,MAAM,uBAAuB,GAAG;IACpC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;IACzC,IAAI;IACJ;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED