@atol-sh/js 0.1.2 → 0.4.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/CHANGELOG.md +184 -6
- package/EXAMPLES.md +316 -0
- package/README.md +208 -30
- package/RESPONSE_VAULT_PROTOCOL.md +843 -0
- package/dist/device.cjs +224 -58
- package/dist/device.cjs.map +1 -1
- package/dist/device.d.cts +69 -25
- package/dist/device.d.ts +69 -25
- package/dist/device.js +224 -58
- package/dist/device.js.map +1 -1
- package/dist/index.cjs +13201 -999
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +259 -245
- package/dist/index.d.ts +259 -245
- package/dist/index.js +13198 -999
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
package/dist/device.cjs
CHANGED
|
@@ -16,31 +16,93 @@ var initialDeviceState = {
|
|
|
16
16
|
|
|
17
17
|
// src/device/collector.ts
|
|
18
18
|
var DEFAULT_DEVICE_API_URL = "https://api.atol.sh";
|
|
19
|
+
var DeviceDiagnosticError = class extends Error {
|
|
20
|
+
constructor(code, message) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.name = "DeviceDiagnosticError";
|
|
24
|
+
}
|
|
25
|
+
};
|
|
19
26
|
function parseSignals(raw) {
|
|
20
|
-
|
|
27
|
+
const expectedKeys = [
|
|
28
|
+
"anomaly_score",
|
|
29
|
+
"bot",
|
|
30
|
+
"device_mismatch",
|
|
31
|
+
"device_shared",
|
|
32
|
+
"emulator",
|
|
33
|
+
"geo_mismatch",
|
|
34
|
+
"incognito",
|
|
35
|
+
"proxy",
|
|
36
|
+
"rooted",
|
|
37
|
+
"shared_user_count",
|
|
38
|
+
"tampered",
|
|
39
|
+
"tor",
|
|
40
|
+
"vpn"
|
|
41
|
+
];
|
|
42
|
+
if (!isExactRecord(raw, expectedKeys)) {
|
|
43
|
+
throw invalidDeviceResponse();
|
|
44
|
+
}
|
|
21
45
|
const r = raw;
|
|
46
|
+
if (typeof r.bot !== "boolean" || typeof r.vpn !== "boolean" || typeof r.proxy !== "boolean" || typeof r.tor !== "boolean" || typeof r.incognito !== "boolean" || typeof r.tampered !== "boolean" || typeof r.emulator !== "boolean" || typeof r.rooted !== "boolean" || typeof r.geo_mismatch !== "boolean" || typeof r.device_mismatch !== "boolean" || typeof r.device_shared !== "boolean" || typeof r.shared_user_count !== "number" || !Number.isSafeInteger(r.shared_user_count) || r.shared_user_count < 0 || !isProbability(r.anomaly_score)) {
|
|
47
|
+
throw invalidDeviceResponse();
|
|
48
|
+
}
|
|
22
49
|
return {
|
|
23
|
-
bot: r.bot
|
|
24
|
-
vpn: r.vpn
|
|
25
|
-
proxy: r.proxy
|
|
26
|
-
tor: r.tor
|
|
27
|
-
incognito: r.incognito
|
|
28
|
-
tampered: r.tampered
|
|
29
|
-
emulator: r.emulator
|
|
30
|
-
rooted: r.rooted
|
|
31
|
-
geo_mismatch: r.geo_mismatch
|
|
32
|
-
|
|
50
|
+
bot: r.bot,
|
|
51
|
+
vpn: r.vpn,
|
|
52
|
+
proxy: r.proxy,
|
|
53
|
+
tor: r.tor,
|
|
54
|
+
incognito: r.incognito,
|
|
55
|
+
tampered: r.tampered,
|
|
56
|
+
emulator: r.emulator,
|
|
57
|
+
rooted: r.rooted,
|
|
58
|
+
geo_mismatch: r.geo_mismatch,
|
|
59
|
+
device_mismatch: r.device_mismatch,
|
|
60
|
+
device_shared: r.device_shared,
|
|
61
|
+
shared_user_count: r.shared_user_count,
|
|
62
|
+
anomaly_score: r.anomaly_score
|
|
33
63
|
};
|
|
34
64
|
}
|
|
65
|
+
function isExactRecord(value, expectedKeys) {
|
|
66
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
const actualKeys = Object.keys(value).sort();
|
|
70
|
+
return actualKeys.length === expectedKeys.length && actualKeys.every((key, index) => key === expectedKeys[index]);
|
|
71
|
+
}
|
|
72
|
+
function isProbability(value) {
|
|
73
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 1;
|
|
74
|
+
}
|
|
75
|
+
function invalidDeviceResponse() {
|
|
76
|
+
return new DeviceDiagnosticError(
|
|
77
|
+
"device_response_invalid",
|
|
78
|
+
"Device intelligence returned an invalid response."
|
|
79
|
+
);
|
|
80
|
+
}
|
|
35
81
|
function deviceStateFromResult(result) {
|
|
82
|
+
const expectedKeys = [
|
|
83
|
+
"browser",
|
|
84
|
+
"confidence",
|
|
85
|
+
"device_id",
|
|
86
|
+
"known",
|
|
87
|
+
"new_device",
|
|
88
|
+
"os_version",
|
|
89
|
+
"platform",
|
|
90
|
+
"signals"
|
|
91
|
+
];
|
|
92
|
+
if (!isExactRecord(result, expectedKeys)) {
|
|
93
|
+
throw invalidDeviceResponse();
|
|
94
|
+
}
|
|
95
|
+
if (typeof result.device_id !== "string" || result.device_id.length === 0 || typeof result.known !== "boolean" || typeof result.new_device !== "boolean" || result.known === result.new_device || !isProbability(result.confidence) || typeof result.platform !== "string" || typeof result.browser !== "string" || typeof result.os_version !== "string") {
|
|
96
|
+
throw invalidDeviceResponse();
|
|
97
|
+
}
|
|
36
98
|
return {
|
|
37
|
-
deviceId: result.device_id
|
|
38
|
-
known: result.known
|
|
39
|
-
confidence: result.confidence
|
|
40
|
-
newDevice: result.new_device
|
|
41
|
-
platform: result.platform
|
|
42
|
-
browser: result.browser
|
|
43
|
-
osVersion: result.os_version
|
|
99
|
+
deviceId: result.device_id,
|
|
100
|
+
known: result.known,
|
|
101
|
+
confidence: result.confidence,
|
|
102
|
+
newDevice: result.new_device,
|
|
103
|
+
platform: result.platform,
|
|
104
|
+
browser: result.browser,
|
|
105
|
+
osVersion: result.os_version,
|
|
44
106
|
signals: parseSignals(result.signals),
|
|
45
107
|
loading: false,
|
|
46
108
|
error: null
|
|
@@ -51,59 +113,163 @@ var DeviceCollector = class {
|
|
|
51
113
|
this.apiUrl = apiUrl;
|
|
52
114
|
this.onState = onState;
|
|
53
115
|
this.agent = null;
|
|
54
|
-
this.
|
|
55
|
-
this.inFlight =
|
|
56
|
-
this.
|
|
116
|
+
this.agentLoad = null;
|
|
117
|
+
this.inFlight = /* @__PURE__ */ new Map();
|
|
118
|
+
this.highestCredentialGeneration = 0;
|
|
119
|
+
this.invalidatedGenerationFloor = 0;
|
|
120
|
+
this.latestIntent = 0;
|
|
57
121
|
}
|
|
58
122
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* Concurrent calls with the same token share one in-flight promise.
|
|
123
|
+
* Pre-load the fingerprint agent without changing credential authority.
|
|
124
|
+
* A later collect or invalidate operation fences this preparation's state.
|
|
62
125
|
*/
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
126
|
+
async prepare() {
|
|
127
|
+
const intent = this.latestIntent;
|
|
128
|
+
try {
|
|
129
|
+
await this.loadAgent();
|
|
130
|
+
this.publishPreparation(intent, {
|
|
131
|
+
...initialDeviceState,
|
|
132
|
+
loading: false
|
|
133
|
+
});
|
|
134
|
+
} catch (err) {
|
|
135
|
+
const error = err instanceof DeviceDiagnosticError ? err : new DeviceDiagnosticError(
|
|
136
|
+
"device_collection_failed",
|
|
137
|
+
"Device intelligence collection failed. Retry the request."
|
|
138
|
+
);
|
|
139
|
+
this.publishPreparation(intent, {
|
|
140
|
+
...initialDeviceState,
|
|
141
|
+
loading: false,
|
|
142
|
+
error
|
|
143
|
+
});
|
|
67
144
|
}
|
|
68
|
-
|
|
69
|
-
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Submit one credential generation's identify operation. Generations are
|
|
148
|
+
* strictly monotonic for this collector's lifetime. A lower delayed
|
|
149
|
+
* generation is ignored before authorization or network dispatch, while a
|
|
150
|
+
* newer generation immediately fences every older result.
|
|
151
|
+
*/
|
|
152
|
+
collect(request) {
|
|
153
|
+
const {
|
|
154
|
+
credentialGeneration: generation,
|
|
155
|
+
authorize
|
|
156
|
+
} = request;
|
|
157
|
+
if (!Number.isSafeInteger(generation) || generation <= 0) {
|
|
158
|
+
return Promise.reject(
|
|
159
|
+
new DeviceDiagnosticError(
|
|
160
|
+
"device_credential_generation_invalid",
|
|
161
|
+
"Device intelligence requires a positive credential generation."
|
|
162
|
+
)
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
if (generation < this.highestCredentialGeneration || generation <= this.invalidatedGenerationFloor) {
|
|
166
|
+
return Promise.resolve();
|
|
167
|
+
}
|
|
168
|
+
const existing = this.inFlight.get(generation);
|
|
169
|
+
if (existing) {
|
|
170
|
+
return existing;
|
|
171
|
+
}
|
|
172
|
+
if (generation > this.highestCredentialGeneration) {
|
|
173
|
+
this.highestCredentialGeneration = generation;
|
|
174
|
+
}
|
|
175
|
+
const intent = ++this.latestIntent;
|
|
176
|
+
const operation = (async () => {
|
|
177
|
+
this.publish(intent, { ...initialDeviceState, loading: true });
|
|
70
178
|
try {
|
|
71
|
-
|
|
179
|
+
const agent = await this.loadAgent();
|
|
180
|
+
let result;
|
|
72
181
|
try {
|
|
73
|
-
|
|
74
|
-
} catch
|
|
75
|
-
throw new
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
const AtolFingerprint = mod.AtolFingerprint ?? mod.default;
|
|
80
|
-
if (!AtolFingerprint) {
|
|
81
|
-
throw new Error(
|
|
82
|
-
"@atol-sh/fingerprint loaded but exports no AtolFingerprint -- check the installed package version"
|
|
182
|
+
result = await agent.identify({ authorize });
|
|
183
|
+
} catch {
|
|
184
|
+
throw new DeviceDiagnosticError(
|
|
185
|
+
"device_collection_failed",
|
|
186
|
+
"Device intelligence collection failed. Retry the request."
|
|
83
187
|
);
|
|
84
188
|
}
|
|
85
|
-
|
|
86
|
-
this.agent = await AtolFingerprint.load({ endpoint: this.apiUrl });
|
|
87
|
-
this.agentApiUrl = this.apiUrl;
|
|
88
|
-
}
|
|
89
|
-
if (token) {
|
|
90
|
-
const result = await this.agent.identify({ token });
|
|
91
|
-
this.onState(deviceStateFromResult(result));
|
|
92
|
-
} else {
|
|
93
|
-
this.onState({ ...initialDeviceState, loading: false });
|
|
94
|
-
}
|
|
189
|
+
this.publish(intent, deviceStateFromResult(result));
|
|
95
190
|
} catch (err) {
|
|
96
|
-
const error = err instanceof
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
this.
|
|
191
|
+
const error = err instanceof DeviceDiagnosticError ? err : new DeviceDiagnosticError(
|
|
192
|
+
"device_collection_failed",
|
|
193
|
+
"Device intelligence collection failed. Retry the request."
|
|
194
|
+
);
|
|
195
|
+
this.publish(intent, { ...initialDeviceState, loading: false, error });
|
|
101
196
|
}
|
|
102
197
|
})();
|
|
103
|
-
|
|
104
|
-
|
|
198
|
+
let run;
|
|
199
|
+
run = operation.finally(() => {
|
|
200
|
+
if (this.inFlight.get(generation) === run) {
|
|
201
|
+
this.inFlight.delete(generation);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
this.inFlight.set(generation, run);
|
|
105
205
|
return run;
|
|
106
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Fence every in-flight identify and clear published device state. Future
|
|
209
|
+
* credentials must continue with a generation higher than any accepted one.
|
|
210
|
+
*/
|
|
211
|
+
invalidate() {
|
|
212
|
+
this.latestIntent++;
|
|
213
|
+
this.invalidatedGenerationFloor = Math.max(
|
|
214
|
+
this.invalidatedGenerationFloor,
|
|
215
|
+
this.highestCredentialGeneration
|
|
216
|
+
);
|
|
217
|
+
this.onState(initialDeviceState);
|
|
218
|
+
}
|
|
219
|
+
publishPreparation(intent, state) {
|
|
220
|
+
if (this.highestCredentialGeneration === 0) {
|
|
221
|
+
this.publish(intent, state);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
publish(intent, state) {
|
|
225
|
+
if (intent === this.latestIntent) {
|
|
226
|
+
this.onState(state);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
async loadAgent() {
|
|
230
|
+
if (this.agent) {
|
|
231
|
+
return this.agent;
|
|
232
|
+
}
|
|
233
|
+
if (this.agentLoad) {
|
|
234
|
+
return this.agentLoad;
|
|
235
|
+
}
|
|
236
|
+
const load = (async () => {
|
|
237
|
+
let mod;
|
|
238
|
+
try {
|
|
239
|
+
mod = await import('@atol-sh/fingerprint');
|
|
240
|
+
} catch {
|
|
241
|
+
throw new DeviceDiagnosticError(
|
|
242
|
+
"device_dependency_unavailable",
|
|
243
|
+
"device intelligence is enabled but @atol-sh/fingerprint is not installed -- run `npm i @atol-sh/fingerprint` or disable device intelligence"
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
const AtolFingerprint = mod.AtolFingerprint ?? mod.default;
|
|
247
|
+
if (!AtolFingerprint) {
|
|
248
|
+
throw new DeviceDiagnosticError(
|
|
249
|
+
"device_dependency_invalid",
|
|
250
|
+
"@atol-sh/fingerprint loaded but exports no AtolFingerprint -- check the installed package version"
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
try {
|
|
254
|
+
const agent = await AtolFingerprint.load({ endpoint: this.apiUrl });
|
|
255
|
+
this.agent = agent;
|
|
256
|
+
return agent;
|
|
257
|
+
} catch {
|
|
258
|
+
throw new DeviceDiagnosticError(
|
|
259
|
+
"device_initialization_failed",
|
|
260
|
+
"Device intelligence could not be initialized. Retry or disable device intelligence."
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
})();
|
|
264
|
+
this.agentLoad = load;
|
|
265
|
+
try {
|
|
266
|
+
return await load;
|
|
267
|
+
} finally {
|
|
268
|
+
if (this.agentLoad === load) {
|
|
269
|
+
this.agentLoad = null;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
107
273
|
};
|
|
108
274
|
|
|
109
275
|
exports.DEFAULT_DEVICE_API_URL = DEFAULT_DEVICE_API_URL;
|
package/dist/device.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/device/types.ts","../src/device/collector.ts"],"names":[],"mappings":";;;AAmG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A,IAAA,CAAK,aAAA,GAAgB,GAAA;AACrB,IAAA,OAAO,GAAA;AAAA,EACT;AACF","file":"device.cjs","sourcesContent":["/**\n * Device intelligence types.\n *\n * Wire shapes mirror the Atol control plane's identify endpoint\n * (`POST /api/v1/devices/identify`) -- the same shapes\n * `@atol-sh/fingerprint` returns from `identify()`, since that SDK\n * passes the server response through verbatim. The fingerprint package\n * is an optional peer dependency that is not statically resolvable\n * here, so the contract is mirrored locally instead of imported.\n */\n\n/** Configuration for device intelligence collection. */\nexport interface DeviceConfig {\n /** Whether device intelligence is enabled. */\n enabled: boolean\n\n /**\n * Base URL of the Atol API host that serves\n * `POST /api/v1/devices/identify`. This is the API host\n * (https://api.atol.sh), NOT the OIDC authority (https://auth.atol.sh).\n * Default: \"https://api.atol.sh\".\n */\n apiUrl?: string\n\n /** Collect device signals on mount. Default: true. */\n collectOnMount?: boolean\n\n /** Interval in ms to re-collect signals. 0 = disabled. Default: 0. */\n recheckInterval?: number\n}\n\n/**\n * Smart signals computed server-side. Keys match the server's signals\n * map exactly (snake_case); no client-side fabrication.\n */\nexport interface SmartSignals {\n bot: boolean\n vpn: boolean\n proxy: boolean\n tor: boolean\n incognito: boolean\n tampered: boolean\n emulator: boolean\n rooted: boolean\n geo_mismatch: boolean\n anomaly_score: number\n}\n\n/**\n * Raw identify response from the control plane (snake_case, verbatim).\n * `signals` is null when the server computed no smart signals.\n */\nexport interface IdentifyResult {\n device_id: string\n known: boolean\n confidence: number\n new_device: boolean\n platform: string\n browser: string\n os_version: string\n signals: SmartSignals | null\n}\n\n/** Device intelligence state (binding-facing, camelCase). */\nexport interface DeviceState {\n /** Unique device identifier assigned by the Atol control plane. */\n deviceId: string | null\n\n /** Whether this device has been seen before. */\n known: boolean\n\n /** Confidence score (0-1) for the device fingerprint match. */\n confidence: number\n\n /** Whether the server created a new device record for this identify. */\n newDevice: boolean\n\n /** Platform reported by the server (e.g. \"macOS\"). Null before identify. */\n platform: string | null\n\n /** Browser family reported by the server. Null before identify. */\n browser: string | null\n\n /** OS version reported by the server. Null before identify. */\n osVersion: string | null\n\n /** Smart signals from server-side analysis. Null before identify or\n * when the server returned none. */\n signals: SmartSignals | null\n\n /** Whether device intelligence is currently loading. */\n loading: boolean\n\n /** Error from device intelligence collection, if any. */\n error: Error | null\n}\n\n/** Initial / not-collected device state. Shared by bindings' context\n * default and the no-provider fallback. */\nexport const initialDeviceState: DeviceState = {\n deviceId: null,\n known: false,\n confidence: 0,\n newDevice: false,\n platform: null,\n browser: null,\n osVersion: null,\n signals: null,\n loading: false,\n error: null,\n}\n","/**\n * Framework-agnostic device intelligence collector.\n *\n * Owns the `@atol-sh/fingerprint` agent lifecycle and the identify call,\n * plus the mapping from the server's snake_case response to the\n * binding-facing DeviceState. React (and any other) bindings wrap this\n * with their own reactive state; the collector itself has no framework\n * dependency.\n *\n * This module lives under the optional `@atol-sh/js/device` subpath so a\n * consumer that never uses device intelligence never pulls\n * `@atol-sh/fingerprint` (an optional peer dependency, dynamic-imported\n * here) into their bundle.\n */\n\nimport {\n initialDeviceState,\n type DeviceState,\n type IdentifyResult,\n type SmartSignals,\n} from './types'\n\n/** Default Atol API host serving POST /api/v1/devices/identify. */\nexport const DEFAULT_DEVICE_API_URL = 'https://api.atol.sh'\n\n/**\n * Structural surface of `@atol-sh/fingerprint` consumed here. The package\n * is an OPTIONAL peer dependency, so it cannot be statically imported\n * without breaking installs that skip it. These interfaces mirror the\n * published package API (`AtolFingerprint.load` / `identify`) and the wire\n * shapes are pinned to the server contract -- the fingerprint SDK returns\n * the server JSON verbatim.\n */\ninterface FingerprintAgent {\n identify(options?: { token?: string }): Promise<IdentifyResult>\n}\n\ninterface FingerprintStatic {\n load(config?: { endpoint?: string; apiKey?: string }): Promise<FingerprintAgent>\n}\n\ninterface FingerprintModule {\n AtolFingerprint?: FingerprintStatic\n default?: FingerprintStatic\n}\n\n/**\n * Map the server's signals object onto SmartSignals. Only the keys the\n * server actually emits are read -- nothing is fabricated. Returns null\n * when the server sent no signals.\n */\nexport function parseSignals(raw: unknown): SmartSignals | null {\n if (!raw || typeof raw !== 'object') return null\n const r = raw as Record<string, unknown>\n return {\n bot: r.bot === true,\n vpn: r.vpn === true,\n proxy: r.proxy === true,\n tor: r.tor === true,\n incognito: r.incognito === true,\n tampered: r.tampered === true,\n emulator: r.emulator === true,\n rooted: r.rooted === true,\n geo_mismatch: r.geo_mismatch === true,\n anomaly_score: typeof r.anomaly_score === 'number' ? r.anomaly_score : 0,\n }\n}\n\n/** Map a raw identify result to the fully-populated DeviceState. */\nexport function deviceStateFromResult(result: IdentifyResult): DeviceState {\n return {\n deviceId: result.device_id ?? null,\n known: result.known ?? false,\n confidence: result.confidence ?? 0,\n newDevice: result.new_device ?? false,\n platform: result.platform || null,\n browser: result.browser || null,\n osVersion: result.os_version || null,\n signals: parseSignals(result.signals),\n loading: false,\n error: null,\n }\n}\n\n/**\n * DeviceCollector loads and caches the fingerprint agent, and performs\n * identify calls. It is stateless with respect to the reactive UI: callers\n * pass an `onState` sink that receives DeviceState transitions, and drive\n * `collect()` in response to token changes / intervals.\n *\n * The agent is (re)loaded when missing or bound to a stale endpoint, so a\n * changed API host does not pin to the first host seen. A single-flight\n * guard keyed by token prevents duplicate concurrent identify POSTs (e.g.\n * React Strict Mode's double invoke).\n */\nexport class DeviceCollector {\n private agent: FingerprintAgent | null = null\n private agentApiUrl: string | null = null\n private inFlight: Promise<void> | null = null\n private inFlightToken: string | null = null\n\n constructor(\n private readonly apiUrl: string,\n private readonly onState: (state: DeviceState) => void,\n ) {}\n\n /**\n * Collect device signals. With a token, submits an identify call and\n * emits the mapped DeviceState; without one, just pre-loads the agent.\n * Concurrent calls with the same token share one in-flight promise.\n */\n collect(token?: string): Promise<void> {\n const key = token ?? null\n if (this.inFlight && this.inFlightToken === key) {\n return this.inFlight\n }\n\n const run = (async () => {\n this.onState({ ...initialDeviceState, loading: true })\n try {\n let mod: FingerprintModule\n try {\n mod = (await import('@atol-sh/fingerprint')) as FingerprintModule\n } catch (importErr) {\n throw new Error(\n 'device intelligence is enabled but @atol-sh/fingerprint is not ' +\n 'installed -- run `npm i @atol-sh/fingerprint` or disable device ' +\n `intelligence (${String(importErr)})`,\n )\n }\n const AtolFingerprint = mod.AtolFingerprint ?? mod.default\n if (!AtolFingerprint) {\n throw new Error(\n '@atol-sh/fingerprint loaded but exports no AtolFingerprint -- ' +\n 'check the installed package version',\n )\n }\n\n // (Re)load the agent when missing or bound to a stale endpoint.\n if (!this.agent || this.agentApiUrl !== this.apiUrl) {\n this.agent = await AtolFingerprint.load({ endpoint: this.apiUrl })\n this.agentApiUrl = this.apiUrl\n }\n\n if (token) {\n const result = await this.agent.identify({ token })\n this.onState(deviceStateFromResult(result))\n } else {\n // No token yet -- agent pre-loaded, nothing to identify.\n this.onState({ ...initialDeviceState, loading: false })\n }\n } catch (err) {\n const error =\n err instanceof Error\n ? err\n : new Error(`Device intelligence collection failed: ${String(err)}`)\n this.onState({ ...initialDeviceState, loading: false, error })\n } finally {\n this.inFlight = null\n this.inFlightToken = null\n }\n })()\n\n this.inFlight = run\n this.inFlightToken = key\n return run\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/device/types.ts","../src/device/collector.ts"],"names":[],"mappings":";;;AAsGO,IAAM,kBAAA,GAAkC;AAAA,EAC7C,QAAA,EAAU,IAAA;AAAA,EACV,KAAA,EAAO,KAAA;AAAA,EACP,UAAA,EAAY,CAAA;AAAA,EACZ,SAAA,EAAW,KAAA;AAAA,EACX,QAAA,EAAU,IAAA;AAAA,EACV,OAAA,EAAS,IAAA;AAAA,EACT,SAAA,EAAW,IAAA;AAAA,EACX,OAAA,EAAS,IAAA;AAAA,EACT,OAAA,EAAS,KAAA;AAAA,EACT,KAAA,EAAO;AACT;;;AC3FO,IAAM,sBAAA,GAAyB;AAkEtC,IAAM,qBAAA,GAAN,cAAoC,KAAA,CAAM;AAAA,EAGxC,WAAA,CAAY,MAA4B,OAAA,EAAiB;AACvD,IAAA,KAAA,CAAM,O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AA;AACJ,MAAA,IAAI;AACF,QAAA,GAAA,GAAO,MAAM,OAAO,sBAAsB,CAAA;AAAA,MAC5C,CAAA,CAAA,MAAQ;AACN,QAAA,MAAM,IAAI,qBAAA;AAAA,UACR,+BAAA;AAAA,UACA;AAAA,SAGF;AAAA,MACF;AACA,MAAA,MAAM,eAAA,GAAkB,GAAA,CAAI,eAAA,IAAmB,GAAA,CAAI,OAAA;AACnD,MAAA,IAAI,CAAC,eAAA,EAAiB;AACpB,QAAA,MAAM,IAAI,qBAAA;AAAA,UACR,2BAAA;AAAA,UACA;AAAA,SAEF;AAAA,MACF;AAEA,MAAA,IAAI;AACF,QAAA,MAAM,KAAA,GAAQ,MAAM,eAAA,CAAgB,IAAA,CAAK,EAAE,QAAA,EAAU,IAAA,CAAK,QAAQ,CAAA;AAClE,QAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AACb,QAAA,OAAO,KAAA;AAAA,MACT,CAAA,CAAA,MAAQ;AACN,QAAA,MAAM,IAAI,qBAAA;AAAA,UACR,8BAAA;AAAA,UACA;AAAA,SACF;AAAA,MACF;AAAA,IACF,CAAA,GAAG;AAEH,IAAA,IAAA,CAAK,SAAA,GAAY,IAAA;AACjB,IAAA,IAAI;AACF,MAAA,OAAO,MAAM,IAAA;AAAA,IACf,CAAA,SAAE;AACA,MAAA,IAAI,IAAA,CAAK,cAAc,IAAA,EAAM;AAC3B,QAAA,IAAA,CAAK,SAAA,GAAY,IAAA;AAAA,MACnB;AAAA,IACF;AAAA,EACF;AACF","file":"device.cjs","sourcesContent":["/**\n * Device intelligence types.\n *\n * Wire shapes mirror the Atol control plane's identify endpoint\n * (`POST /api/v1/devices/identify`) -- the same shapes\n * `@atol-sh/fingerprint` returns from `identify()`. Both packages validate\n * the response before exposing it. The fingerprint package\n * is an optional peer dependency that is not statically resolvable\n * here, so the contract is mirrored locally instead of imported.\n */\n\n/** Configuration for device intelligence collection. */\nexport interface DeviceConfig {\n /** Whether device intelligence is enabled. */\n enabled: boolean\n\n /**\n * Base URL of the Atol API host that serves\n * `POST /api/v1/devices/identify`. This is the API host\n * (https://api.atol.sh), NOT the OIDC authority (https://auth.atol.sh).\n * Default: \"https://api.atol.sh\".\n */\n apiUrl?: string\n\n /** Collect device signals on mount. Default: true. */\n collectOnMount?: boolean\n\n /** Interval in ms to re-collect signals. 0 = disabled. Default: 0. */\n recheckInterval?: number\n}\n\n/**\n * Smart signals computed server-side. Keys match the server's signals\n * map exactly (snake_case); no client-side fabrication.\n */\nexport interface SmartSignals {\n bot: boolean\n vpn: boolean\n proxy: boolean\n tor: boolean\n incognito: boolean\n tampered: boolean\n emulator: boolean\n rooted: boolean\n geo_mismatch: boolean\n device_mismatch: boolean\n device_shared: boolean\n shared_user_count: number\n anomaly_score: number\n}\n\n/**\n * Raw identify response from the control plane (snake_case, verbatim).\n * The server always returns the exact smart-signal evaluation.\n */\nexport interface IdentifyResult {\n device_id: string\n known: boolean\n confidence: number\n new_device: boolean\n platform: string\n browser: string\n os_version: string\n signals: SmartSignals\n}\n\n/** Device intelligence state (binding-facing, camelCase). */\nexport interface DeviceState {\n /** Unique device identifier assigned by the Atol control plane. */\n deviceId: string | null\n\n /** Whether this device has been seen before. */\n known: boolean\n\n /** Confidence score (0-1) for the device fingerprint match. */\n confidence: number\n\n /** Whether the server created a new device record for this identify. */\n newDevice: boolean\n\n /** Platform reported by the server (e.g. \"macOS\"). Null before identify. */\n platform: string | null\n\n /** Browser family reported by the server. Null before identify. */\n browser: string | null\n\n /** OS version reported by the server. Null before identify. */\n osVersion: string | null\n\n /** Smart signals from server-side analysis. Null before identify, reset,\n * or failure; every successful server response contains the exact object. */\n signals: SmartSignals | null\n\n /** Whether device intelligence is currently loading. */\n loading: boolean\n\n /** Error from device intelligence collection, if any. */\n error: Error | null\n}\n\n/** Initial / not-collected device state. Shared by bindings' context\n * default and the no-provider fallback. */\nexport const initialDeviceState: DeviceState = {\n deviceId: null,\n known: false,\n confidence: 0,\n newDevice: false,\n platform: null,\n browser: null,\n osVersion: null,\n signals: null,\n loading: false,\n error: null,\n}\n","/**\n * Framework-agnostic device intelligence collector.\n *\n * Owns the `@atol-sh/fingerprint` agent lifecycle and the identify call,\n * plus the mapping from the server's snake_case response to the\n * binding-facing DeviceState. React (and any other) bindings wrap this\n * with their own reactive state; the collector itself has no framework\n * dependency.\n *\n * This module lives under the optional `@atol-sh/js/device` subpath so a\n * consumer that never uses device intelligence never pulls\n * `@atol-sh/fingerprint` (an optional peer dependency, dynamic-imported\n * here) into their bundle.\n */\n\nimport {\n initialDeviceState,\n type DeviceState,\n type SmartSignals,\n} from './types'\n\n/** Default Atol API host serving POST /api/v1/devices/identify. */\nexport const DEFAULT_DEVICE_API_URL = 'https://api.atol.sh'\n\n/**\n * Structural surface of `@atol-sh/fingerprint` consumed here. The package\n * is an OPTIONAL peer dependency, so it cannot be statically imported\n * without breaking installs that skip it. These interfaces mirror the\n * published package API (`AtolFingerprint.load` / `identify`) and the wire\n * shapes are pinned to the server contract. This boundary validates the\n * dynamically loaded package result independently before exposing state.\n */\ninterface FingerprintAgent {\n identify(options?: { authorize?: DeviceAuthorizationOwner }): Promise<unknown>\n}\n\ninterface FingerprintStatic {\n load(config?: { endpoint?: string }): Promise<FingerprintAgent>\n}\n\ninterface FingerprintModule {\n AtolFingerprint?: FingerprintStatic\n default?: FingerprintStatic\n}\n\n/** Exact identify request presented to the credential owner. */\nexport interface DeviceAuthorizationRequest {\n method: 'POST'\n url: string\n}\n\n/** One request's exact Bearer or DPoP authorization material. */\nexport type DeviceAuthorization =\n | {\n scheme: 'Bearer'\n accessToken: string\n }\n | {\n scheme: 'DPoP'\n accessToken: string\n dpopProof: string\n }\n\n/**\n * Acquire authorization for the exact identify request. The collector passes\n * this owner through for one operation and does not retain its result.\n */\nexport type DeviceAuthorizationOwner = (\n request: Readonly<DeviceAuthorizationRequest>,\n) => Promise<DeviceAuthorization>\n\n/**\n * One credential generation's identify authority. Increment the non-secret\n * generation whenever the owning session rotates or changes organization.\n */\nexport interface DeviceCollectionRequest {\n credentialGeneration: number\n authorize: DeviceAuthorizationOwner\n}\n\ntype DeviceDiagnosticCode =\n | 'device_dependency_unavailable'\n | 'device_dependency_invalid'\n | 'device_initialization_failed'\n | 'device_collection_failed'\n | 'device_credential_generation_invalid'\n | 'device_response_invalid'\n\nclass DeviceDiagnosticError extends Error {\n readonly code: DeviceDiagnosticCode\n\n constructor(code: DeviceDiagnosticCode, message: string) {\n super(message)\n this.code = code\n this.name = 'DeviceDiagnosticError'\n }\n}\n\n/**\n * Map the exact server signals object onto SmartSignals. Missing, null,\n * unknown, or mistyped members are a contract failure.\n */\nexport function parseSignals(raw: unknown): SmartSignals {\n const expectedKeys = [\n 'anomaly_score',\n 'bot',\n 'device_mismatch',\n 'device_shared',\n 'emulator',\n 'geo_mismatch',\n 'incognito',\n 'proxy',\n 'rooted',\n 'shared_user_count',\n 'tampered',\n 'tor',\n 'vpn',\n ]\n if (!isExactRecord(raw, expectedKeys)) {\n throw invalidDeviceResponse()\n }\n const r = raw as Record<string, unknown>\n if (\n typeof r.bot !== 'boolean' ||\n typeof r.vpn !== 'boolean' ||\n typeof r.proxy !== 'boolean' ||\n typeof r.tor !== 'boolean' ||\n typeof r.incognito !== 'boolean' ||\n typeof r.tampered !== 'boolean' ||\n typeof r.emulator !== 'boolean' ||\n typeof r.rooted !== 'boolean' ||\n typeof r.geo_mismatch !== 'boolean' ||\n typeof r.device_mismatch !== 'boolean' ||\n typeof r.device_shared !== 'boolean' ||\n typeof r.shared_user_count !== 'number' ||\n !Number.isSafeInteger(r.shared_user_count) ||\n r.shared_user_count < 0 ||\n !isProbability(r.anomaly_score)\n ) {\n throw invalidDeviceResponse()\n }\n return {\n bot: r.bot,\n vpn: r.vpn,\n proxy: r.proxy,\n tor: r.tor,\n incognito: r.incognito,\n tampered: r.tampered,\n emulator: r.emulator,\n rooted: r.rooted,\n geo_mismatch: r.geo_mismatch,\n device_mismatch: r.device_mismatch,\n device_shared: r.device_shared,\n shared_user_count: r.shared_user_count,\n anomaly_score: r.anomaly_score,\n }\n}\n\nfunction isExactRecord(\n value: unknown,\n expectedKeys: readonly string[],\n): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n return false\n }\n const actualKeys = Object.keys(value).sort()\n return (\n actualKeys.length === expectedKeys.length &&\n actualKeys.every((key, index) => key === expectedKeys[index])\n )\n}\n\nfunction isProbability(value: unknown): value is number {\n return (\n typeof value === 'number' &&\n Number.isFinite(value) &&\n value >= 0 &&\n value <= 1\n )\n}\n\nfunction invalidDeviceResponse(): DeviceDiagnosticError {\n return new DeviceDiagnosticError(\n 'device_response_invalid',\n 'Device intelligence returned an invalid response.',\n )\n}\n\n/** Validate and map a raw identify result to the fully-populated DeviceState. */\nexport function deviceStateFromResult(result: unknown): DeviceState {\n const expectedKeys = [\n 'browser',\n 'confidence',\n 'device_id',\n 'known',\n 'new_device',\n 'os_version',\n 'platform',\n 'signals',\n ]\n if (!isExactRecord(result, expectedKeys)) {\n throw invalidDeviceResponse()\n }\n if (\n typeof result.device_id !== 'string' ||\n result.device_id.length === 0 ||\n typeof result.known !== 'boolean' ||\n typeof result.new_device !== 'boolean' ||\n result.known === result.new_device ||\n !isProbability(result.confidence) ||\n typeof result.platform !== 'string' ||\n typeof result.browser !== 'string' ||\n typeof result.os_version !== 'string'\n ) {\n throw invalidDeviceResponse()\n }\n return {\n deviceId: result.device_id,\n known: result.known,\n confidence: result.confidence,\n newDevice: result.new_device,\n platform: result.platform,\n browser: result.browser,\n osVersion: result.os_version,\n signals: parseSignals(result.signals),\n loading: false,\n error: null,\n }\n}\n\n/**\n * DeviceCollector loads and caches the fingerprint agent, and performs\n * identify calls. It is stateless with respect to the reactive UI: callers\n * pass an `onState` sink that receives DeviceState transitions, and drive\n * `collect()` in response to credential-generation changes or intervals.\n *\n * The agent is loaded once for this endpoint-bound collector. Calls for one\n * credential generation are single-flight. A newer generation becomes the\n * latest intent immediately, so a late older result cannot publish state.\n */\nexport class DeviceCollector {\n private agent: FingerprintAgent | null = null\n private agentLoad: Promise<FingerprintAgent> | null = null\n private readonly inFlight = new Map<number, Promise<void>>()\n private highestCredentialGeneration = 0\n private invalidatedGenerationFloor = 0\n private latestIntent = 0\n\n constructor(\n private readonly apiUrl: string,\n private readonly onState: (state: DeviceState) => void,\n ) {}\n\n /**\n * Pre-load the fingerprint agent without changing credential authority.\n * A later collect or invalidate operation fences this preparation's state.\n */\n async prepare(): Promise<void> {\n const intent = this.latestIntent\n try {\n await this.loadAgent()\n this.publishPreparation(intent, {\n ...initialDeviceState,\n loading: false,\n })\n } catch (err) {\n const error =\n err instanceof DeviceDiagnosticError\n ? err\n : new DeviceDiagnosticError(\n 'device_collection_failed',\n 'Device intelligence collection failed. Retry the request.',\n )\n this.publishPreparation(intent, {\n ...initialDeviceState,\n loading: false,\n error,\n })\n }\n }\n\n /**\n * Submit one credential generation's identify operation. Generations are\n * strictly monotonic for this collector's lifetime. A lower delayed\n * generation is ignored before authorization or network dispatch, while a\n * newer generation immediately fences every older result.\n */\n collect(request: DeviceCollectionRequest): Promise<void> {\n const {\n credentialGeneration: generation,\n authorize,\n } = request\n if (!Number.isSafeInteger(generation) || generation <= 0) {\n return Promise.reject(\n new DeviceDiagnosticError(\n 'device_credential_generation_invalid',\n 'Device intelligence requires a positive credential generation.',\n ),\n )\n }\n if (\n generation < this.highestCredentialGeneration ||\n generation <= this.invalidatedGenerationFloor\n ) {\n return Promise.resolve()\n }\n const existing = this.inFlight.get(generation)\n if (existing) {\n return existing\n }\n if (generation > this.highestCredentialGeneration) {\n this.highestCredentialGeneration = generation\n }\n const intent = ++this.latestIntent\n\n const operation = (async () => {\n this.publish(intent, { ...initialDeviceState, loading: true })\n try {\n const agent = await this.loadAgent()\n let result: unknown\n try {\n result = await agent.identify({ authorize })\n } catch {\n throw new DeviceDiagnosticError(\n 'device_collection_failed',\n 'Device intelligence collection failed. Retry the request.',\n )\n }\n this.publish(intent, deviceStateFromResult(result))\n } catch (err) {\n const error =\n err instanceof DeviceDiagnosticError\n ? err\n : new DeviceDiagnosticError(\n 'device_collection_failed',\n 'Device intelligence collection failed. Retry the request.',\n )\n this.publish(intent, { ...initialDeviceState, loading: false, error })\n }\n })()\n\n let run: Promise<void>\n run = operation.finally(() => {\n if (this.inFlight.get(generation) === run) {\n this.inFlight.delete(generation)\n }\n })\n this.inFlight.set(generation, run)\n return run\n }\n\n /**\n * Fence every in-flight identify and clear published device state. Future\n * credentials must continue with a generation higher than any accepted one.\n */\n invalidate(): void {\n this.latestIntent++\n this.invalidatedGenerationFloor = Math.max(\n this.invalidatedGenerationFloor,\n this.highestCredentialGeneration,\n )\n this.onState(initialDeviceState)\n }\n\n private publishPreparation(intent: number, state: DeviceState): void {\n if (this.highestCredentialGeneration === 0) {\n this.publish(intent, state)\n }\n }\n\n private publish(intent: number, state: DeviceState): void {\n if (intent === this.latestIntent) {\n this.onState(state)\n }\n }\n\n private async loadAgent(): Promise<FingerprintAgent> {\n if (this.agent) {\n return this.agent\n }\n if (this.agentLoad) {\n return this.agentLoad\n }\n\n const load = (async () => {\n let mod: FingerprintModule\n try {\n mod = (await import('@atol-sh/fingerprint')) as FingerprintModule\n } catch {\n throw new DeviceDiagnosticError(\n 'device_dependency_unavailable',\n 'device intelligence is enabled but @atol-sh/fingerprint is not ' +\n 'installed -- run `npm i @atol-sh/fingerprint` or disable device ' +\n 'intelligence',\n )\n }\n const AtolFingerprint = mod.AtolFingerprint ?? mod.default\n if (!AtolFingerprint) {\n throw new DeviceDiagnosticError(\n 'device_dependency_invalid',\n '@atol-sh/fingerprint loaded but exports no AtolFingerprint -- ' +\n 'check the installed package version',\n )\n }\n\n try {\n const agent = await AtolFingerprint.load({ endpoint: this.apiUrl })\n this.agent = agent\n return agent\n } catch {\n throw new DeviceDiagnosticError(\n 'device_initialization_failed',\n 'Device intelligence could not be initialized. Retry or disable device intelligence.',\n )\n }\n })()\n\n this.agentLoad = load\n try {\n return await load\n } finally {\n if (this.agentLoad === load) {\n this.agentLoad = null\n }\n }\n }\n}\n"]}
|
package/dist/device.d.cts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Wire shapes mirror the Atol control plane's identify endpoint
|
|
5
5
|
* (`POST /api/v1/devices/identify`) -- the same shapes
|
|
6
|
-
* `@atol-sh/fingerprint` returns from `identify()
|
|
7
|
-
*
|
|
6
|
+
* `@atol-sh/fingerprint` returns from `identify()`. Both packages validate
|
|
7
|
+
* the response before exposing it. The fingerprint package
|
|
8
8
|
* is an optional peer dependency that is not statically resolvable
|
|
9
9
|
* here, so the contract is mirrored locally instead of imported.
|
|
10
10
|
*/
|
|
@@ -38,11 +38,14 @@ interface SmartSignals {
|
|
|
38
38
|
emulator: boolean;
|
|
39
39
|
rooted: boolean;
|
|
40
40
|
geo_mismatch: boolean;
|
|
41
|
+
device_mismatch: boolean;
|
|
42
|
+
device_shared: boolean;
|
|
43
|
+
shared_user_count: number;
|
|
41
44
|
anomaly_score: number;
|
|
42
45
|
}
|
|
43
46
|
/**
|
|
44
47
|
* Raw identify response from the control plane (snake_case, verbatim).
|
|
45
|
-
*
|
|
48
|
+
* The server always returns the exact smart-signal evaluation.
|
|
46
49
|
*/
|
|
47
50
|
interface IdentifyResult {
|
|
48
51
|
device_id: string;
|
|
@@ -52,7 +55,7 @@ interface IdentifyResult {
|
|
|
52
55
|
platform: string;
|
|
53
56
|
browser: string;
|
|
54
57
|
os_version: string;
|
|
55
|
-
signals: SmartSignals
|
|
58
|
+
signals: SmartSignals;
|
|
56
59
|
}
|
|
57
60
|
/** Device intelligence state (binding-facing, camelCase). */
|
|
58
61
|
interface DeviceState {
|
|
@@ -70,8 +73,8 @@ interface DeviceState {
|
|
|
70
73
|
browser: string | null;
|
|
71
74
|
/** OS version reported by the server. Null before identify. */
|
|
72
75
|
osVersion: string | null;
|
|
73
|
-
/** Smart signals from server-side analysis. Null before identify
|
|
74
|
-
*
|
|
76
|
+
/** Smart signals from server-side analysis. Null before identify, reset,
|
|
77
|
+
* or failure; every successful server response contains the exact object. */
|
|
75
78
|
signals: SmartSignals | null;
|
|
76
79
|
/** Whether device intelligence is currently loading. */
|
|
77
80
|
loading: boolean;
|
|
@@ -99,39 +102,80 @@ declare const initialDeviceState: DeviceState;
|
|
|
99
102
|
|
|
100
103
|
/** Default Atol API host serving POST /api/v1/devices/identify. */
|
|
101
104
|
declare const DEFAULT_DEVICE_API_URL = "https://api.atol.sh";
|
|
105
|
+
/** Exact identify request presented to the credential owner. */
|
|
106
|
+
interface DeviceAuthorizationRequest {
|
|
107
|
+
method: 'POST';
|
|
108
|
+
url: string;
|
|
109
|
+
}
|
|
110
|
+
/** One request's exact Bearer or DPoP authorization material. */
|
|
111
|
+
type DeviceAuthorization = {
|
|
112
|
+
scheme: 'Bearer';
|
|
113
|
+
accessToken: string;
|
|
114
|
+
} | {
|
|
115
|
+
scheme: 'DPoP';
|
|
116
|
+
accessToken: string;
|
|
117
|
+
dpopProof: string;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Acquire authorization for the exact identify request. The collector passes
|
|
121
|
+
* this owner through for one operation and does not retain its result.
|
|
122
|
+
*/
|
|
123
|
+
type DeviceAuthorizationOwner = (request: Readonly<DeviceAuthorizationRequest>) => Promise<DeviceAuthorization>;
|
|
124
|
+
/**
|
|
125
|
+
* One credential generation's identify authority. Increment the non-secret
|
|
126
|
+
* generation whenever the owning session rotates or changes organization.
|
|
127
|
+
*/
|
|
128
|
+
interface DeviceCollectionRequest {
|
|
129
|
+
credentialGeneration: number;
|
|
130
|
+
authorize: DeviceAuthorizationOwner;
|
|
131
|
+
}
|
|
102
132
|
/**
|
|
103
|
-
* Map the server
|
|
104
|
-
*
|
|
105
|
-
* when the server sent no signals.
|
|
133
|
+
* Map the exact server signals object onto SmartSignals. Missing, null,
|
|
134
|
+
* unknown, or mistyped members are a contract failure.
|
|
106
135
|
*/
|
|
107
|
-
declare function parseSignals(raw: unknown): SmartSignals
|
|
108
|
-
/**
|
|
109
|
-
declare function deviceStateFromResult(result:
|
|
136
|
+
declare function parseSignals(raw: unknown): SmartSignals;
|
|
137
|
+
/** Validate and map a raw identify result to the fully-populated DeviceState. */
|
|
138
|
+
declare function deviceStateFromResult(result: unknown): DeviceState;
|
|
110
139
|
/**
|
|
111
140
|
* DeviceCollector loads and caches the fingerprint agent, and performs
|
|
112
141
|
* identify calls. It is stateless with respect to the reactive UI: callers
|
|
113
142
|
* pass an `onState` sink that receives DeviceState transitions, and drive
|
|
114
|
-
* `collect()` in response to
|
|
143
|
+
* `collect()` in response to credential-generation changes or intervals.
|
|
115
144
|
*
|
|
116
|
-
* The agent is
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* React Strict Mode's double invoke).
|
|
145
|
+
* The agent is loaded once for this endpoint-bound collector. Calls for one
|
|
146
|
+
* credential generation are single-flight. A newer generation becomes the
|
|
147
|
+
* latest intent immediately, so a late older result cannot publish state.
|
|
120
148
|
*/
|
|
121
149
|
declare class DeviceCollector {
|
|
122
150
|
private readonly apiUrl;
|
|
123
151
|
private readonly onState;
|
|
124
152
|
private agent;
|
|
125
|
-
private
|
|
126
|
-
private inFlight;
|
|
127
|
-
private
|
|
153
|
+
private agentLoad;
|
|
154
|
+
private readonly inFlight;
|
|
155
|
+
private highestCredentialGeneration;
|
|
156
|
+
private invalidatedGenerationFloor;
|
|
157
|
+
private latestIntent;
|
|
128
158
|
constructor(apiUrl: string, onState: (state: DeviceState) => void);
|
|
129
159
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
|
|
160
|
+
* Pre-load the fingerprint agent without changing credential authority.
|
|
161
|
+
* A later collect or invalidate operation fences this preparation's state.
|
|
162
|
+
*/
|
|
163
|
+
prepare(): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Submit one credential generation's identify operation. Generations are
|
|
166
|
+
* strictly monotonic for this collector's lifetime. A lower delayed
|
|
167
|
+
* generation is ignored before authorization or network dispatch, while a
|
|
168
|
+
* newer generation immediately fences every older result.
|
|
169
|
+
*/
|
|
170
|
+
collect(request: DeviceCollectionRequest): Promise<void>;
|
|
171
|
+
/**
|
|
172
|
+
* Fence every in-flight identify and clear published device state. Future
|
|
173
|
+
* credentials must continue with a generation higher than any accepted one.
|
|
133
174
|
*/
|
|
134
|
-
|
|
175
|
+
invalidate(): void;
|
|
176
|
+
private publishPreparation;
|
|
177
|
+
private publish;
|
|
178
|
+
private loadAgent;
|
|
135
179
|
}
|
|
136
180
|
|
|
137
|
-
export { DEFAULT_DEVICE_API_URL, DeviceCollector, type DeviceConfig, type DeviceState, type IdentifyResult, type SmartSignals, deviceStateFromResult, initialDeviceState, parseSignals };
|
|
181
|
+
export { DEFAULT_DEVICE_API_URL, type DeviceAuthorization, type DeviceAuthorizationOwner, type DeviceAuthorizationRequest, type DeviceCollectionRequest, DeviceCollector, type DeviceConfig, type DeviceState, type IdentifyResult, type SmartSignals, deviceStateFromResult, initialDeviceState, parseSignals };
|