@chipmobilesdk/rn-core 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/CHANGELOG.md +64 -0
- package/lib/commonjs/diagnostics/index.js +81 -0
- package/lib/commonjs/diagnostics/index.js.map +1 -0
- package/lib/commonjs/errors/index.js +86 -0
- package/lib/commonjs/errors/index.js.map +1 -0
- package/lib/commonjs/index.js +305 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/intl/index.js +98 -0
- package/lib/commonjs/intl/index.js.map +1 -0
- package/lib/commonjs/kv/index.js +83 -0
- package/lib/commonjs/kv/index.js.map +1 -0
- package/lib/commonjs/lazy/index.js +63 -0
- package/lib/commonjs/lazy/index.js.map +1 -0
- package/lib/commonjs/listeners/index.js +110 -0
- package/lib/commonjs/listeners/index.js.map +1 -0
- package/lib/commonjs/messages/index.js +53 -0
- package/lib/commonjs/messages/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/react/index.js +93 -0
- package/lib/commonjs/react/index.js.map +1 -0
- package/lib/commonjs/redact/index.js +128 -0
- package/lib/commonjs/redact/index.js.map +1 -0
- package/lib/commonjs/runtime/index.js +77 -0
- package/lib/commonjs/runtime/index.js.map +1 -0
- package/lib/commonjs/runtime/lifecycle.js +105 -0
- package/lib/commonjs/runtime/lifecycle.js.map +1 -0
- package/lib/commonjs/scheduler/index.js +216 -0
- package/lib/commonjs/scheduler/index.js.map +1 -0
- package/lib/commonjs/store/index.js +39 -0
- package/lib/commonjs/store/index.js.map +1 -0
- package/lib/commonjs/testing/conformance.js +79 -0
- package/lib/commonjs/testing/conformance.js.map +1 -0
- package/lib/commonjs/testing/index.js +58 -0
- package/lib/commonjs/testing/index.js.map +1 -0
- package/lib/commonjs/testing/lifecycle.js +37 -0
- package/lib/commonjs/testing/lifecycle.js.map +1 -0
- package/lib/commonjs/testing/redaction.js +118 -0
- package/lib/commonjs/testing/redaction.js.map +1 -0
- package/lib/commonjs/testing/scheduler.js +51 -0
- package/lib/commonjs/testing/scheduler.js.map +1 -0
- package/lib/module/diagnostics/index.js +75 -0
- package/lib/module/diagnostics/index.js.map +1 -0
- package/lib/module/errors/index.js +78 -0
- package/lib/module/errors/index.js.map +1 -0
- package/lib/module/index.js +24 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/intl/index.js +91 -0
- package/lib/module/intl/index.js.map +1 -0
- package/lib/module/kv/index.js +76 -0
- package/lib/module/kv/index.js.map +1 -0
- package/lib/module/lazy/index.js +59 -0
- package/lib/module/lazy/index.js.map +1 -0
- package/lib/module/listeners/index.js +104 -0
- package/lib/module/listeners/index.js.map +1 -0
- package/lib/module/messages/index.js +48 -0
- package/lib/module/messages/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/react/index.js +86 -0
- package/lib/module/react/index.js.map +1 -0
- package/lib/module/redact/index.js +118 -0
- package/lib/module/redact/index.js.map +1 -0
- package/lib/module/runtime/index.js +52 -0
- package/lib/module/runtime/index.js.map +1 -0
- package/lib/module/runtime/lifecycle.js +99 -0
- package/lib/module/runtime/lifecycle.js.map +1 -0
- package/lib/module/scheduler/index.js +203 -0
- package/lib/module/scheduler/index.js.map +1 -0
- package/lib/module/store/index.js +33 -0
- package/lib/module/store/index.js.map +1 -0
- package/lib/module/testing/conformance.js +72 -0
- package/lib/module/testing/conformance.js.map +1 -0
- package/lib/module/testing/index.js +12 -0
- package/lib/module/testing/index.js.map +1 -0
- package/lib/module/testing/lifecycle.js +32 -0
- package/lib/module/testing/lifecycle.js.map +1 -0
- package/lib/module/testing/redaction.js +113 -0
- package/lib/module/testing/redaction.js.map +1 -0
- package/lib/module/testing/scheduler.js +47 -0
- package/lib/module/testing/scheduler.js.map +1 -0
- package/lib/typescript/commonjs/diagnostics/index.d.ts +49 -0
- package/lib/typescript/commonjs/diagnostics/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/errors/index.d.ts +59 -0
- package/lib/typescript/commonjs/errors/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +22 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/intl/index.d.ts +25 -0
- package/lib/typescript/commonjs/intl/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/kv/index.d.ts +38 -0
- package/lib/typescript/commonjs/kv/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/lazy/index.d.ts +36 -0
- package/lib/typescript/commonjs/lazy/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/listeners/index.d.ts +61 -0
- package/lib/typescript/commonjs/listeners/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/messages/index.d.ts +39 -0
- package/lib/typescript/commonjs/messages/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/react/index.d.ts +38 -0
- package/lib/typescript/commonjs/react/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/redact/index.d.ts +47 -0
- package/lib/typescript/commonjs/redact/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/runtime/index.d.ts +21 -0
- package/lib/typescript/commonjs/runtime/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/runtime/lifecycle.d.ts +34 -0
- package/lib/typescript/commonjs/runtime/lifecycle.d.ts.map +1 -0
- package/lib/typescript/commonjs/scheduler/index.d.ts +108 -0
- package/lib/typescript/commonjs/scheduler/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/store/index.d.ts +18 -0
- package/lib/typescript/commonjs/store/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/conformance.d.ts +35 -0
- package/lib/typescript/commonjs/testing/conformance.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/index.d.ts +10 -0
- package/lib/typescript/commonjs/testing/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/lifecycle.d.ts +15 -0
- package/lib/typescript/commonjs/testing/lifecycle.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/redaction.d.ts +35 -0
- package/lib/typescript/commonjs/testing/redaction.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/scheduler.d.ts +15 -0
- package/lib/typescript/commonjs/testing/scheduler.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/index.d.ts +49 -0
- package/lib/typescript/module/diagnostics/index.d.ts.map +1 -0
- package/lib/typescript/module/errors/index.d.ts +59 -0
- package/lib/typescript/module/errors/index.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +22 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/intl/index.d.ts +25 -0
- package/lib/typescript/module/intl/index.d.ts.map +1 -0
- package/lib/typescript/module/kv/index.d.ts +38 -0
- package/lib/typescript/module/kv/index.d.ts.map +1 -0
- package/lib/typescript/module/lazy/index.d.ts +36 -0
- package/lib/typescript/module/lazy/index.d.ts.map +1 -0
- package/lib/typescript/module/listeners/index.d.ts +61 -0
- package/lib/typescript/module/listeners/index.d.ts.map +1 -0
- package/lib/typescript/module/messages/index.d.ts +39 -0
- package/lib/typescript/module/messages/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/react/index.d.ts +38 -0
- package/lib/typescript/module/react/index.d.ts.map +1 -0
- package/lib/typescript/module/redact/index.d.ts +47 -0
- package/lib/typescript/module/redact/index.d.ts.map +1 -0
- package/lib/typescript/module/runtime/index.d.ts +21 -0
- package/lib/typescript/module/runtime/index.d.ts.map +1 -0
- package/lib/typescript/module/runtime/lifecycle.d.ts +34 -0
- package/lib/typescript/module/runtime/lifecycle.d.ts.map +1 -0
- package/lib/typescript/module/scheduler/index.d.ts +108 -0
- package/lib/typescript/module/scheduler/index.d.ts.map +1 -0
- package/lib/typescript/module/store/index.d.ts +18 -0
- package/lib/typescript/module/store/index.d.ts.map +1 -0
- package/lib/typescript/module/testing/conformance.d.ts +35 -0
- package/lib/typescript/module/testing/conformance.d.ts.map +1 -0
- package/lib/typescript/module/testing/index.d.ts +10 -0
- package/lib/typescript/module/testing/index.d.ts.map +1 -0
- package/lib/typescript/module/testing/lifecycle.d.ts +15 -0
- package/lib/typescript/module/testing/lifecycle.d.ts.map +1 -0
- package/lib/typescript/module/testing/redaction.d.ts +35 -0
- package/lib/typescript/module/testing/redaction.d.ts.map +1 -0
- package/lib/typescript/module/testing/scheduler.d.ts +15 -0
- package/lib/typescript/module/testing/scheduler.d.ts.map +1 -0
- package/package.json +154 -46
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createMemoryKeyValue = createMemoryKeyValue;
|
|
7
|
+
exports.fromMmkvLike = fromMmkvLike;
|
|
8
|
+
exports.namespaced = namespaced;
|
|
9
|
+
exports.openDurable = openDurable;
|
|
10
|
+
/**
|
|
11
|
+
* A synchronous key-value port (DEP-09, NOT-15, PERF-09).
|
|
12
|
+
*
|
|
13
|
+
* rn-payment and rn-notification each wrapped MMKV themselves, and one of them
|
|
14
|
+
* fell back to memory without telling anyone. Here the port says whether it is
|
|
15
|
+
* `durable`, and `openDurable` reports the fallback through `onDegraded`, so a
|
|
16
|
+
* package can emit its own diagnostic instead of silently losing state.
|
|
17
|
+
*
|
|
18
|
+
* rn-core never requires a storage peer itself: the package opens MMKV (or any
|
|
19
|
+
* store with the same shape) and hands it over as an `MmkvLike`.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** The slice of a react-native-mmkv v4 instance the port uses. */
|
|
23
|
+
|
|
24
|
+
function createMemoryKeyValue() {
|
|
25
|
+
const map = new Map();
|
|
26
|
+
return {
|
|
27
|
+
getString: key => map.get(key),
|
|
28
|
+
set: (key, value) => {
|
|
29
|
+
map.set(key, value);
|
|
30
|
+
},
|
|
31
|
+
remove: key => {
|
|
32
|
+
map.delete(key);
|
|
33
|
+
},
|
|
34
|
+
keys: () => [...map.keys()],
|
|
35
|
+
clearAll: () => map.clear(),
|
|
36
|
+
durable: false
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function fromMmkvLike(store) {
|
|
40
|
+
return {
|
|
41
|
+
getString: key => store.getString(key),
|
|
42
|
+
set: (key, value) => store.set(key, value),
|
|
43
|
+
remove: key => {
|
|
44
|
+
store.remove(key);
|
|
45
|
+
},
|
|
46
|
+
keys: () => store.getAllKeys(),
|
|
47
|
+
clearAll: () => store.clearAll(),
|
|
48
|
+
durable: true
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Opens the durable store, or falls back to memory and says so: `onDegraded`
|
|
54
|
+
* receives the reason once, and the returned port reports `durable: false`.
|
|
55
|
+
*/
|
|
56
|
+
function openDurable(open, onDegraded) {
|
|
57
|
+
try {
|
|
58
|
+
return fromMmkvLike(open());
|
|
59
|
+
} catch (cause) {
|
|
60
|
+
onDegraded?.(cause);
|
|
61
|
+
return createMemoryKeyValue();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Keys under `prefix:` only, so several owners can share one store. */
|
|
66
|
+
function namespaced(port, prefix) {
|
|
67
|
+
const scope = `${prefix}:`;
|
|
68
|
+
return {
|
|
69
|
+
getString: key => port.getString(scope + key),
|
|
70
|
+
set: (key, value) => port.set(scope + key, value),
|
|
71
|
+
remove: key => port.remove(scope + key),
|
|
72
|
+
keys: () => port.keys().filter(key => key.startsWith(scope)).map(key => key.slice(scope.length)),
|
|
73
|
+
clearAll: () => {
|
|
74
|
+
for (const key of port.keys()) {
|
|
75
|
+
if (key.startsWith(scope)) port.remove(key);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
get durable() {
|
|
79
|
+
return port.durable;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createMemoryKeyValue","map","Map","getString","key","get","set","value","remove","delete","keys","clearAll","clear","durable","fromMmkvLike","store","getAllKeys","openDurable","open","onDegraded","cause","namespaced","port","prefix","scope","filter","startsWith","slice","length"],"sourceRoot":"../../../src","sources":["kv/index.ts"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA;;AASO,SAASA,oBAAoBA,CAAA,EAAiB;EACpD,MAAMC,GAAG,GAAG,IAAIC,GAAG,CAAiB,CAAC;EACrC,OAAO;IACNC,SAAS,EAAEC,GAAG,IAAIH,GAAG,CAACI,GAAG,CAACD,GAAG,CAAC;IAC9BE,GAAG,EAAEA,CAACF,GAAG,EAAEG,KAAK,KAAK;MACpBN,GAAG,CAACK,GAAG,CAACF,GAAG,EAAEG,KAAK,CAAC;IACpB,CAAC;IACDC,MAAM,EAAEJ,GAAG,IAAI;MACdH,GAAG,CAACQ,MAAM,CAACL,GAAG,CAAC;IAChB,CAAC;IACDM,IAAI,EAAEA,CAAA,KAAM,CAAC,GAAGT,GAAG,CAACS,IAAI,CAAC,CAAC,CAAC;IAC3BC,QAAQ,EAAEA,CAAA,KAAMV,GAAG,CAACW,KAAK,CAAC,CAAC;IAC3BC,OAAO,EAAE;EACV,CAAC;AACF;AAEO,SAASC,YAAYA,CAACC,KAAe,EAAgB;EAC3D,OAAO;IACNZ,SAAS,EAAEC,GAAG,IAAIW,KAAK,CAACZ,SAAS,CAACC,GAAG,CAAC;IACtCE,GAAG,EAAEA,CAACF,GAAG,EAAEG,KAAK,KAAKQ,KAAK,CAACT,GAAG,CAACF,GAAG,EAAEG,KAAK,CAAC;IAC1CC,MAAM,EAAEJ,GAAG,IAAI;MACdW,KAAK,CAACP,MAAM,CAACJ,GAAG,CAAC;IAClB,CAAC;IACDM,IAAI,EAAEA,CAAA,KAAMK,KAAK,CAACC,UAAU,CAAC,CAAC;IAC9BL,QAAQ,EAAEA,CAAA,KAAMI,KAAK,CAACJ,QAAQ,CAAC,CAAC;IAChCE,OAAO,EAA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@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.lazyPeer = lazyPeer;
|
|
7
|
+
/**
|
|
8
|
+
* Lazy native peers (CORE-06).
|
|
9
|
+
*
|
|
10
|
+
* Every package loads its native peer on first use, so importing a package where
|
|
11
|
+
* the peer is absent (an unsupported platform, a build that excludes it) costs
|
|
12
|
+
* nothing and crashes nothing. There were 18 hand-written `require()` sites with
|
|
13
|
+
* four different failure policies, some silent. Here, one: the load runs once,
|
|
14
|
+
* its result (module or failure) is cached, and a missing peer is a typed result
|
|
15
|
+
* the package maps to its own error code.
|
|
16
|
+
*
|
|
17
|
+
* The `load` thunk must contain the literal `require('peer-name')` and live in the
|
|
18
|
+
* package that depends on the peer, so Metro sees and bundles it there.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
function lazyPeer(name, load) {
|
|
22
|
+
let cached;
|
|
23
|
+
let forced;
|
|
24
|
+
function get() {
|
|
25
|
+
if (forced) return forced;
|
|
26
|
+
if (!cached) {
|
|
27
|
+
try {
|
|
28
|
+
cached = {
|
|
29
|
+
ok: true,
|
|
30
|
+
module: load()
|
|
31
|
+
};
|
|
32
|
+
} catch (cause) {
|
|
33
|
+
cached = {
|
|
34
|
+
ok: false,
|
|
35
|
+
peer: name,
|
|
36
|
+
cause
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return cached;
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
name,
|
|
44
|
+
get,
|
|
45
|
+
require(fail) {
|
|
46
|
+
const result = get();
|
|
47
|
+
if (result.ok) return result.module;
|
|
48
|
+
throw fail(result.peer, result.cause);
|
|
49
|
+
},
|
|
50
|
+
isAvailable: () => get().ok,
|
|
51
|
+
override(fake) {
|
|
52
|
+
forced = fake === undefined ? undefined : fake === null ? {
|
|
53
|
+
ok: false,
|
|
54
|
+
peer: name,
|
|
55
|
+
cause: new Error(`${name} is overridden as absent`)
|
|
56
|
+
} : {
|
|
57
|
+
ok: true,
|
|
58
|
+
module: fake
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["lazyPeer","name","load","cached","forced","get","ok","module","cause","peer","require","fail","result","isAvailable","override","fake","undefined","Error"],"sourceRoot":"../../../src","sources":["lazy/index.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAoBO,SAASA,QAAQA,CAAIC,IAAY,EAAEC,IAAa,EAAe;EACrE,IAAIC,MAAiC;EACrC,IAAIC,MAAiC;EAErC,SAASC,GAAGA,CAAA,EAAkB;IAC7B,IAAID,MAAM,EAAE,OAAOA,MAAM;IACzB,IAAI,CAACD,MAAM,EAAE;MACZ,IAAI;QACHA,MAAM,GAAG;UAAEG,EAAE,EAAE,IAAI;UAAEC,MAAM,EAAEL,IAAI,CAAC;QAAE,CAAC;MACtC,CAAC,CAAC,OAAOM,KAAK,EAAE;QACfL,MAAM,GAAG;UAAEG,EAAE,EAAE,KAAK;UAAEG,IAAI,EAAER,IAAI;UAAEO;QAAM,CAAC;MAC1C;IACD;IACA,OAAOL,MAAM;EACd;EAEA,OAAO;IACNF,IAAI;IACJI,GAAG;IACHK,OAAOA,CAACC,IAAI,EAAE;MACb,MAAMC,MAAM,GAAGP,GAAG,CAAC,CAAC;MACpB,IAAIO,MAAM,CAACN,EAAE,EAAE,OAAOM,MAAM,CAACL,MAAM;MACnC,MAAMI,IAAI,CAACC,MAAM,CAACH,IAAI,EAAEG,MAAM,CAACJ,KAAK,CAAC;IACtC,CAAC;IACDK,WAAW,EAAEA,CAAA,KAAMR,GAAG,CAAC,CAAC,CAACC,EAAE;IAC3BQ,QAAQA,CAACC,IAAI,EAAE;MACdX,MAAM,GACLW,IAAI,KAAKC,SAAS,GACfA,SAAS,GACTD,IAAI,KAAK,IAAI,GACZ;QAAET,EAAE,EAAE,KAAK;QAAEG,IAAI,EAAER,IAAI;QAAEO,KAAK,EAAE,IAAIS,KAAK,CAAC,GAAGhB,IAAI,0BAA0B;MAAE,CAAC,GAC9E;QAAEK,EAAE,EAAE,IAAI;QAAEC,MAAM,EAAEQ;MAAK,CAAC;IAChC;EACD,CAAC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createEmitter = createEmitter;
|
|
7
|
+
exports.createListenerSet = createListenerSet;
|
|
8
|
+
exports.reportAsynchronously = reportAsynchronously;
|
|
9
|
+
/**
|
|
10
|
+
* Listener sets and event emitters (CORE-03, CORE-08, CORE-12).
|
|
11
|
+
*
|
|
12
|
+
* Every package used to keep its own `Set<listener>` and loop over it. Three of
|
|
13
|
+
* them let a throwing subscriber escape into the code that was notifying, which
|
|
14
|
+
* left a state machine half-updated. Here, once:
|
|
15
|
+
*
|
|
16
|
+
* - `notify` iterates a snapshot: a listener added during a round waits for the
|
|
17
|
+
* next one, and a listener removed during a round is not called, so a consumer
|
|
18
|
+
* that unsubscribed (an unmounted component) is never reached;
|
|
19
|
+
* - each listener runs in its own try/catch, so one throwing subscriber neither
|
|
20
|
+
* stops the others nor reaches the caller;
|
|
21
|
+
* - a listener's error is reported, never swallowed: to `onListenerError` when
|
|
22
|
+
* given, otherwise rethrown on a fresh task, where the app's global error
|
|
23
|
+
* handler and crash reporter see it;
|
|
24
|
+
* - unsubscribing twice is a no-op.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/** Rethrows on a fresh task: outside every caller, inside the app's error handler. */
|
|
28
|
+
function reportAsynchronously(error) {
|
|
29
|
+
setTimeout(() => {
|
|
30
|
+
throw error;
|
|
31
|
+
}, 0);
|
|
32
|
+
}
|
|
33
|
+
function createListenerSet(options = {}) {
|
|
34
|
+
const listeners = new Set();
|
|
35
|
+
const report = options.onListenerError ?? reportAsynchronously;
|
|
36
|
+
let reporting = false;
|
|
37
|
+
function fail(error) {
|
|
38
|
+
if (reporting) return;
|
|
39
|
+
reporting = true;
|
|
40
|
+
try {
|
|
41
|
+
report(error);
|
|
42
|
+
} catch (reportError) {
|
|
43
|
+
reportAsynchronously(reportError);
|
|
44
|
+
} finally {
|
|
45
|
+
reporting = false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
add(listener) {
|
|
50
|
+
listeners.add(listener);
|
|
51
|
+
let active = true;
|
|
52
|
+
return () => {
|
|
53
|
+
if (!active) return;
|
|
54
|
+
active = false;
|
|
55
|
+
listeners.delete(listener);
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
notify(...args) {
|
|
59
|
+
for (const listener of [...listeners]) {
|
|
60
|
+
if (!listeners.has(listener)) continue;
|
|
61
|
+
try {
|
|
62
|
+
listener(...args);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
fail(error);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
get size() {
|
|
69
|
+
return listeners.size;
|
|
70
|
+
},
|
|
71
|
+
clear() {
|
|
72
|
+
listeners.clear();
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function createEmitter(options = {}) {
|
|
77
|
+
const listeners = createListenerSet(options);
|
|
78
|
+
const seen = new Map();
|
|
79
|
+
const dedupe = options.dedupe;
|
|
80
|
+
let disposed = false;
|
|
81
|
+
return {
|
|
82
|
+
emit(event) {
|
|
83
|
+
if (disposed) return false;
|
|
84
|
+
const key = dedupe?.key(event);
|
|
85
|
+
if (key !== undefined && dedupe) {
|
|
86
|
+
if (seen.has(key)) return false;
|
|
87
|
+
seen.set(key, true);
|
|
88
|
+
if (seen.size > dedupe.capacity) {
|
|
89
|
+
const oldest = seen.keys().next().value;
|
|
90
|
+
if (oldest !== undefined) seen.delete(oldest);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
listeners.notify(event);
|
|
94
|
+
return true;
|
|
95
|
+
},
|
|
96
|
+
subscribe: listener => listeners.add(listener),
|
|
97
|
+
forget(matches) {
|
|
98
|
+
for (const key of [...seen.keys()]) {
|
|
99
|
+
if (matches(key)) seen.delete(key);
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
dispose() {
|
|
103
|
+
disposed = true;
|
|
104
|
+
listeners.clear();
|
|
105
|
+
seen.clear();
|
|
106
|
+
},
|
|
107
|
+
listenerCount: () => listeners.size
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["reportAsynchronously","error","setTimeout","createListenerSet","options","listeners","Set","report","onListenerError","reporting","fail","reportError","add","listener","active","delete","notify","args","has","size","clear","createEmitter","seen","Map","dedupe","disposed","emit","event","key","undefined","set","capacity","oldest","keys","next","value","subscribe","forget","matches","dispose","listenerCount"],"sourceRoot":"../../../src","sources":["listeners/index.ts"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA;AACO,SAASA,oBAAoBA,CAACC,KAAc,EAAQ;EAC1DC,UAAU,CAAC,MAAM;IAChB,MAAMD,KAAK;EACZ,CAAC,EAAE,CAAC,CAAC;AACN;AAWO,SAASE,iBAAiBA,CAChCC,OAA6B,GAAG,CAAC,CAAC,EACd;EACpB,MAAMC,SAAS,GAAG,IAAIC,GAAG,CAA0B,CAAC;EACpD,MAAMC,MAAM,GAAGH,OAAO,CAACI,eAAe,IAAIR,oBAAoB;EAC9D,IAAIS,SAAS,GAAG,KAAK;EAErB,SAASC,IAAIA,CAACT,KAAc,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
|
|
6
|
+
exports.defineMessages = defineMessages;
|
|
7
|
+
exports.formatMessage = formatMessage;
|
|
8
|
+
/**
|
|
9
|
+
* Message catalogs (CORE-15, I18N-13, AUTH-16, AI-15).
|
|
10
|
+
*
|
|
11
|
+
* rn-ai, rn-auth and rn-payment each kept their copy keys in a different shape.
|
|
12
|
+
* One shape now: a catalog of default texts split by audience. `user` copy may
|
|
13
|
+
* reach an end user; `developer` copy describes a configuration fault and must
|
|
14
|
+
* never be shown to one. A catalog is plain data (`key -> default text`), so rn-i18n
|
|
15
|
+
* can register any package's catalog in one call and translate it like app copy.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** Message key to default text. `{name}` marks a variable. */
|
|
19
|
+
|
|
20
|
+
/** Any object whose every key maps to a string; interfaces qualify, unlike an index signature. */
|
|
21
|
+
|
|
22
|
+
/** Fills `{name}` placeholders; a placeholder with no value is left as written. */
|
|
23
|
+
function formatMessage(template, vars) {
|
|
24
|
+
if (!vars) return template;
|
|
25
|
+
return template.replace(/\{(\w+)\}/g, (placeholder, name) => Object.prototype.hasOwnProperty.call(vars, name) ? String(vars[name]) : placeholder);
|
|
26
|
+
}
|
|
27
|
+
function defineMessages(catalog) {
|
|
28
|
+
const user = catalog.user;
|
|
29
|
+
const developer = catalog.developer ?? {};
|
|
30
|
+
const defaults = Object.freeze({
|
|
31
|
+
...user,
|
|
32
|
+
...developer
|
|
33
|
+
});
|
|
34
|
+
const developerKeys = new Set(Object.keys(developer));
|
|
35
|
+
return {
|
|
36
|
+
defaults,
|
|
37
|
+
user: Object.freeze({
|
|
38
|
+
...user
|
|
39
|
+
}),
|
|
40
|
+
developer: Object.freeze({
|
|
41
|
+
...developer
|
|
42
|
+
}),
|
|
43
|
+
userKeys: Object.freeze(Object.keys(user)),
|
|
44
|
+
developerKeys: Object.freeze(Object.keys(developer)),
|
|
45
|
+
resolve: overrides => ({
|
|
46
|
+
...defaults,
|
|
47
|
+
...overrides
|
|
48
|
+
}),
|
|
49
|
+
audienceOf: key => developerKeys.has(key) ? 'developer' : 'user',
|
|
50
|
+
format: (key, vars) => formatMessage(defaults[key] ?? String(key), vars)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["formatMessage","template","vars","replace","placeholder","name","Object","prototype","hasOwnProperty","call","String","defineMessages","catalog","user","developer","defaults","freeze","developerKeys","Set","keys","userKeys","resolve","overrides","audienceOf","key","has","format"],"sourceRoot":"../../../src","sources":["messages/index.ts"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAKA;;AAqBA;AACO,SAASA,aAAaA,CAACC,QAAgB,EAAEC,IAAkB,EAAU;EAC3E,IAAI,CAACA,IAAI,EAAE,OAAOD,QAAQ;EAC1B,OAAOA,QAAQ,CAACE,OAAO,CAAC,YAAY,EAAE,CAACC,WAAW,EAAEC,IAAY,KAC/DC,MAAM,CAACC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACP,IAAI,EAAEG,IAAI,CAAC,GAAGK,MAAM,CAACR,IAAI,CAACG,IAAI,CAAC,CAAC,GAAGD,WACzE,CAAC;AACF;AAEO,SAASO,cAAcA,CAG5BC,OAAgE,EAA+B;EAChG,MAAMC,IAAI,GAAGD,OAAO,CAACC,IAAI;EACzB,MAAMC,SAAS,GAAIF,OAAO,CAACE,SAAS,IAAI,CAAC,CAAe;EACxD,MAAMC,QAAQ,GAAGT,MAAM,CAACU,MAAM,CAAC;IAAE,GAAGH,IAAI;IAAE,GAAGC;EAAU,CAAC,CAA+B;EACvF,MAAMG,aAAa,GAAG,IAAIC,GAAG,CAACZ,MAAM,CAACa,IAAI,CAACL,SAAS,CAAC,CAAC;EAErD,OAAO;IACNC,QAAQ;IACRF,IAAI,EAAEP,MAAM,CAACU,MAAM,CAAC;MAAE,GAAGH;IAAK,CAAC,CAAC;IAChCC,SAAS,EAAER,MAAM,CAACU,MAAM,CAAC;MAAE,GAAGF;IAAU,CAAC,CAAC;IAC1CM,QAAQ,EAAEd,MAAM,CAACU,MAAM,CAACV,MAAM,CAACa,IAAI,CAACN,IAAI,CAAC,CAAqC;IAC9EI,aAAa,EAAEX,MAAM,CAACU,MAAM,CAACV,MAAM,CAACa,IAAI,CAACL,SAAS,CAAC,CAA0C;IAC7FO,OAAO,EAAEC,SAAS,KAAK;MAAE,GAAGP,QAAQ;MAAE,GAAGO;IAAU,CAAC,CAAqB;IACzEC,UAAU,EAAEC,GAAG,IAAKP,aAAa,CAACQ,GAAG,CAACD,GAAa,CAAC,GAAG,WAAW,GAAG,MAAO;IAC5EE,MAAM,EAAEA,CAACF,GAAG,EAAEtB,IAAI,KACjBF,aAAa,CAAEe,QAAQ,CAA4BS,GAAG,CAAW,IAAId,MAAM,CAACc,GAAG,CAAC,EAAEtB,IAAI;EACxF,CAAC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createSdkContext = createSdkContext;
|
|
7
|
+
exports.useExternalStore = useExternalStore;
|
|
8
|
+
exports.useLatestCallback = useLatestCallback;
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
/**
|
|
11
|
+
* React glue every package shares (CORE-07, PERF-04).
|
|
12
|
+
*
|
|
13
|
+
* Packages used to mirror their state into `useState` from a `useEffect`
|
|
14
|
+
* subscription: one render late, a tearing risk under concurrent rendering, and
|
|
15
|
+
* every consumer re-rendered on every change. Here, one way:
|
|
16
|
+
* `useSyncExternalStore` over a store whose snapshot keeps its identity until it
|
|
17
|
+
* actually changes, with a selector so a component re-renders only when the part
|
|
18
|
+
* it reads changes.
|
|
19
|
+
*
|
|
20
|
+
* `react` is an optional peer of rn-core, needed only for this entrypoint.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
function identity(value) {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Reads an external store. With `select`, the component re-renders only when the
|
|
29
|
+
* selected value changes by `isEqual` (default `Object.is`), however often the
|
|
30
|
+
* store itself changes.
|
|
31
|
+
*/
|
|
32
|
+
function useExternalStore(subscribe, getSnapshot, select = identity, isEqual = Object.is) {
|
|
33
|
+
const memo = (0, _react.useRef)(null);
|
|
34
|
+
const getSelected = (0, _react.useCallback)(() => {
|
|
35
|
+
const snapshot = getSnapshot();
|
|
36
|
+
const previous = memo.current;
|
|
37
|
+
if (previous && Object.is(previous.snapshot, snapshot)) return previous.selected;
|
|
38
|
+
const selected = select(snapshot);
|
|
39
|
+
if (previous && isEqual(previous.selected, selected)) {
|
|
40
|
+
memo.current = {
|
|
41
|
+
snapshot,
|
|
42
|
+
selected: previous.selected
|
|
43
|
+
};
|
|
44
|
+
return previous.selected;
|
|
45
|
+
}
|
|
46
|
+
memo.current = {
|
|
47
|
+
snapshot,
|
|
48
|
+
selected
|
|
49
|
+
};
|
|
50
|
+
return selected;
|
|
51
|
+
}, [getSnapshot, select, isEqual]);
|
|
52
|
+
return (0, _react.useSyncExternalStore)(subscribe, getSelected, getSelected);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A callback whose identity never changes but which always calls the latest
|
|
57
|
+
* `fn`, for listeners an app passes inline that must not re-run an effect.
|
|
58
|
+
*/
|
|
59
|
+
function useLatestCallback(fn) {
|
|
60
|
+
const latest = (0, _react.useRef)(fn);
|
|
61
|
+
latest.current = fn;
|
|
62
|
+
return (0, _react.useCallback)((...args) => latest.current(...args), []);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A context with a Provider and a hook that throws a clear error outside it,
|
|
67
|
+
* instead of returning `undefined` for a missing provider.
|
|
68
|
+
*/
|
|
69
|
+
function createSdkContext(name) {
|
|
70
|
+
const Context = /*#__PURE__*/(0, _react.createContext)(null);
|
|
71
|
+
Context.displayName = name;
|
|
72
|
+
function Provider({
|
|
73
|
+
value,
|
|
74
|
+
children
|
|
75
|
+
}) {
|
|
76
|
+
return /*#__PURE__*/(0, _react.createElement)(Context.Provider, {
|
|
77
|
+
value
|
|
78
|
+
}, children);
|
|
79
|
+
}
|
|
80
|
+
function use() {
|
|
81
|
+
const value = (0, _react.useContext)(Context);
|
|
82
|
+
if (value === null) {
|
|
83
|
+
throw new Error(`${name} is not available: wrap the tree in its <${name}Provider>.`);
|
|
84
|
+
}
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
Context,
|
|
89
|
+
Provider,
|
|
90
|
+
use
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","identity","value","useExternalStore","subscribe","getSnapshot","select","isEqual","Object","is","memo","useRef","getSelected","useCallback","snapshot","previous","current","selected","useSyncExternalStore","useLatestCallback","fn","latest","args","createSdkContext","name","Context","createContext","displayName","Provider","children","createElement","use","useContext","Error"],"sourceRoot":"../../../src","sources":["react/index.ts"],"mappings":";;;;;;;;AAYA,IAAAA,MAAA,GAAAC,OAAA;AAZA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA,SAASC,QAAQA,CAAIC,KAAQ,EAAK;EACjC,OAAOA,KAAK;AACb;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,gBAAgBA,CAC/BC,SAAgD,EAChDC,WAA2B,EAC3BC,MAAwC,GAAGL,QAA4C,EACvFM,OAA8C,GAAGC,MAAM,CAACC,EAAE,EAC/C;EACX,MAAMC,IAAI,GAAG,IAAAC,aAAM,EAAoD,IAAI,CAAC;EAC5E,MAAMC,WAAW,GAAG,IAAAC,kBAAW,EAAC,MAA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AC,EAAE;IAC1E,oBAAO,IAAAC,oBAAa,EAACL,OAAO,CAACG,QAAQ,EAAE;MAAE1B;IAAM,CAAC,EAAE2B,QAAQ,CAAC;EAC5D;EAEA,SAASE,GAAGA,CAAA,EAAM;IACjB,MAAM7B,KAAK,GAAG,IAAA8B,iBAAU,EAACP,OAAO,CAAC;IACjC,IAAIvB,KAAK,KAAK,IAAI,EAAE;MACnB,MAAM,IAAI+B,KAAK,CAAC,GAAGT,IAAI,4CAA4CA,IAAI,YAAY,CAAC;IACrF;IACA,OAAOtB,KAAK;EACb;EAEA,OAAO;IAAEuB,OAAO;IAAEG,QAAQ;IAAEG;EAAI,CAAC;AAClC","ignoreList":[]}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.REDACTED = exports.PATH_PATTERN = exports.COMMON_PATTERNS = void 0;
|
|
7
|
+
exports.createRedactor = createRedactor;
|
|
8
|
+
exports.describeShape = describeShape;
|
|
9
|
+
exports.leadingIdentifier = leadingIdentifier;
|
|
10
|
+
exports.pickAllowed = pickAllowed;
|
|
11
|
+
exports.redactPatterns = redactPatterns;
|
|
12
|
+
var _index = require("../errors/index.js");
|
|
13
|
+
/**
|
|
14
|
+
* Redaction primitives shared by every package (CORE-02).
|
|
15
|
+
*
|
|
16
|
+
* Packages differ in policy, not in mechanism, so the mechanism lives here once:
|
|
17
|
+
*
|
|
18
|
+
* - `identifier` text keeps only a leading engine constant (`SQLITE_BUSY`,
|
|
19
|
+
* `E_USER_CANCELLED`) and drops everything else. It is the default, and the
|
|
20
|
+
* only safe choice for text that may carry user data in free prose.
|
|
21
|
+
* - `patterns` text keeps prose but replaces anything shaped like a secret or an
|
|
22
|
+
* identifier: URLs, JWTs, e-mail addresses, UUIDs, long base64 runs, plus a
|
|
23
|
+
* package's own patterns.
|
|
24
|
+
* - `detail` keeps an allowlist of keys with primitive values.
|
|
25
|
+
* - `context` replaces the values of content keys by their shape (`[string:12]`)
|
|
26
|
+
* and pattern-redacts every other string.
|
|
27
|
+
*
|
|
28
|
+
* Every package's redaction runs through `redactionConformance`
|
|
29
|
+
* (`@chipmobilesdk/rn-core/testing`), so a policy that lets a token through fails
|
|
30
|
+
* that package's tests.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
const REDACTED = exports.REDACTED = '[redacted]';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Shapes that are a secret or an identifier wherever they appear. Order matters:
|
|
37
|
+
* a URL is replaced whole before its parts could match anything narrower.
|
|
38
|
+
*/
|
|
39
|
+
const COMMON_PATTERNS = exports.COMMON_PATTERNS = Object.freeze([/** Anything URL-like; query strings carry tokens and identifiers. */
|
|
40
|
+
/[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^\s"'<>]+/g, /** JWTs: three base64url segments separated by dots. */
|
|
41
|
+
/[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g, /** E-mail addresses. */
|
|
42
|
+
/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g, /** UUIDs, including advertising ids. */
|
|
43
|
+
/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/g, /** Base64-ish runs long enough to be an encoded payload or an opaque token. */
|
|
44
|
+
/[A-Za-z0-9+/=_-]{40,}/g]);
|
|
45
|
+
|
|
46
|
+
/** File paths: file URIs are URLs already; this adds POSIX and Windows paths. */
|
|
47
|
+
const PATH_PATTERN = exports.PATH_PATTERN = /(?:[a-zA-Z]:[\\/][^\s"']+)|(?:\/[^\s"']*\/[^\s"']*)/g;
|
|
48
|
+
const IDENTIFIER_TOKEN = /^([A-Z][A-Z0-9_]{2,})\b/;
|
|
49
|
+
|
|
50
|
+
/** Replaces every match of every pattern with `[redacted]`. */
|
|
51
|
+
function redactPatterns(text, patterns = COMMON_PATTERNS) {
|
|
52
|
+
return patterns.reduce((out, pattern) => out.replace(pattern, REDACTED), text);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Reduces text this package did not write to a leading engine identifier, or to
|
|
57
|
+
* `[redacted]`. No shape test separates prose describing a failure from prose
|
|
58
|
+
* describing a person, so prose never survives.
|
|
59
|
+
*/
|
|
60
|
+
function leadingIdentifier(text) {
|
|
61
|
+
if (!text) return '';
|
|
62
|
+
const token = IDENTIFIER_TOKEN.exec(text.split('\n')[0]?.trim() ?? '');
|
|
63
|
+
return token?.[1] ?? REDACTED;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** A value's shape without its content: `[string:12]`, `[array:3]`, `[object:2]`. */
|
|
67
|
+
function describeShape(value) {
|
|
68
|
+
if (value === null) return '[null]';
|
|
69
|
+
if (value === undefined) return '[undefined]';
|
|
70
|
+
if (typeof value === 'string') return `[string:${value.length}]`;
|
|
71
|
+
if (Array.isArray(value)) return `[array:${value.length}]`;
|
|
72
|
+
if (typeof value === 'object') return `[object:${Object.keys(value).length}]`;
|
|
73
|
+
return REDACTED;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Keeps only allowlisted keys, and only their primitive values. */
|
|
77
|
+
function pickAllowed(detail, allow) {
|
|
78
|
+
if (!detail) return undefined;
|
|
79
|
+
const safe = {};
|
|
80
|
+
for (const [key, value] of Object.entries(detail)) {
|
|
81
|
+
if (allow.has(key) && (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean')) {
|
|
82
|
+
safe[key] = value;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return safe;
|
|
86
|
+
}
|
|
87
|
+
function createRedactor(policy = {}) {
|
|
88
|
+
const mode = policy.text ?? 'identifier';
|
|
89
|
+
const patterns = [...COMMON_PATTERNS, ...(policy.patterns ?? [])];
|
|
90
|
+
const dropKeys = new Set(policy.dropKeys ?? []);
|
|
91
|
+
const allow = new Set(policy.allowDetailKeys ?? []);
|
|
92
|
+
const shapeKeys = new Set(policy.shapeKeys ?? []);
|
|
93
|
+
const textDepth = policy.maxDepth ?? 2;
|
|
94
|
+
const contextDepth = policy.maxDepth ?? 6;
|
|
95
|
+
const string = value => mode === 'identifier' ? leadingIdentifier(value) : redactPatterns(value, patterns);
|
|
96
|
+
function text(value, depth = 0) {
|
|
97
|
+
if (value === null || value === undefined) return '';
|
|
98
|
+
if (typeof value === 'string') return string(value);
|
|
99
|
+
if (typeof value === 'number' || typeof value === 'boolean') return String(value);
|
|
100
|
+
if ((0, _index.isSdkError)(value)) return value.code;
|
|
101
|
+
if (value instanceof Error) {
|
|
102
|
+
return mode === 'identifier' ? value.name : string(value.message);
|
|
103
|
+
}
|
|
104
|
+
if (mode === 'identifier' || depth >= textDepth) return REDACTED;
|
|
105
|
+
if (Array.isArray(value)) return value.map(item => text(item, depth + 1)).join(', ');
|
|
106
|
+
if (typeof value === 'object') {
|
|
107
|
+
return Object.entries(value).map(([key, entry]) => `${key}=${dropKeys.has(key) ? REDACTED : text(entry, depth + 1)}`).join(' ');
|
|
108
|
+
}
|
|
109
|
+
return REDACTED;
|
|
110
|
+
}
|
|
111
|
+
function walk(value, depth) {
|
|
112
|
+
if (typeof value === 'string') return redactPatterns(value, patterns);
|
|
113
|
+
if (value instanceof Error) return text(value);
|
|
114
|
+
if (value === null || typeof value !== 'object' || depth > contextDepth) return value;
|
|
115
|
+
if (Array.isArray(value)) return value.map(item => walk(item, depth + 1));
|
|
116
|
+
const out = {};
|
|
117
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
118
|
+
out[key] = shapeKeys.has(key) ? describeShape(inner) : dropKeys.has(key) ? REDACTED : walk(inner, depth + 1);
|
|
119
|
+
}
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
text: value => text(value),
|
|
124
|
+
detail: detail => pickAllowed(detail, allow),
|
|
125
|
+
context: context => context === undefined ? undefined : walk(context, 0)
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_index","require","REDACTED","exports","COMMON_PATTERNS","Object","freeze","PATH_PATTERN","IDENTIFIER_TOKEN","redactPatterns","text","patterns","reduce","out","pattern","replace","leadingIdentifier","token","exec","split","trim","describeShape","value","undefined","length","Array","isArray","keys","pickAllowed","detail","allow","safe","key","entries","has","createRedactor","policy","mode","dropKeys","Set","allowDetailKeys","shapeKeys","textDepth","maxDepth","contextDepth","string","depth","String","isSdkError","code","Error","name","message","map","item","join","entry","walk","inner","context"],"sourceRoot":"../../../src","sources":["redact/index.ts"],"mappings":";;;;;;;;;;;AAmBA,IAAAA,MAAA,GAAAC,OAAA;AAnBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGO,MAAMC,QAAQ,GAAAC,OAAA,CAAAD,QAAA,GAAG,YAAY;;AAEpC;AACA;AACA;AACA;AACO,MAAME,eAAkC,GAAAD,OAAA,CAAAC,eAAA,GAAGC,MAAM,CAACC,MAAM,CAAC,CAC/D;AACA,yCAAyC,EACzC;AACA,0DAA0D,EAC1D;AACA,iDAAiD,EACjD;AACA,8EAA8E,EAC9E;AACA,wBAAwB,CACxB,CAAC;;AAEF;AACO,MAAMC,YAAY,GAAAJ,OAAA,CAAAI,YAAA,GAAG,sDAAsD;AAElF,MAAMC,gBAAgB,GAAG,yBAAyB;;AAElD;AACO,SAASC,cAAcA,CAC7BC,IAAY,EACZC,QAA2B,GAAGP,eAAe,EACpC;EACT,OAAOO,QAAQ,CAACC,MAAM,CAAC,CAACC,GAAG,EAAEC,OAAO,KAAKD,GAAG,CAACE,OAAO,CAACD,OAAO,EAAEZ,QAAQ,CAAC,EAAEQ,IAAI,CAAC;AAC/E;;AAEA;AACA;AACA;AAC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A4B,GAAG,CAAC,CAAC;IACvC,KAAK,MAAM,CAACmB,GAAG,EAAE0B,KAAK,CAAC,IAAIrD,MAAM,CAAC4B,OAAO,CAACX,KAAgC,CAAC,EAAE;MAC5ET,GAAG,CAACmB,GAAG,CAAC,GAAGS,SAAS,CAACP,GAAG,CAACF,GAAG,CAAC,GAC1BX,aAAa,CAACqC,KAAK,CAAC,GACpBpB,QAAQ,CAACJ,GAAG,CAACF,GAAG,CAAC,GAChB9B,QAAQ,GACRuD,IAAI,CAACC,KAAK,EAAEZ,KAAK,GAAG,CAAC,CAAC;IAC3B;IACA,OAAOjC,GAAG;EACX;EAEA,OAAO;IACNH,IAAI,EAAEY,KAAK,IAAIZ,IAAI,CAACY,KAAK,CAAC;IAC1BO,MAAM,EAAEA,MAAM,IAAID,WAAW,CAACC,MAAM,EAAEC,KAAK,CAAC;IAC5C6B,OAAO,EAAEA,OAAO,IACfA,OAAO,KAAKpC,SAAS,GAAGA,SAAS,GAAIkC,IAAI,CAACE,OAAO,EAAE,CAAC;EACtD,CAAC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "appLifecycle", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _lifecycle.appLifecycle;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
exports.byPlatform = byPlatform;
|
|
13
|
+
Object.defineProperty(exports, "createAppLifecycle", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _lifecycle.createAppLifecycle;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
exports.currentPlatform = currentPlatform;
|
|
20
|
+
exports.isDevBuild = isDevBuild;
|
|
21
|
+
Object.defineProperty(exports, "onForeground", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _lifecycle.onForeground;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
exports.setPlatformOverride = setPlatformOverride;
|
|
28
|
+
var _index = require("../lazy/index.js");
|
|
29
|
+
var _lifecycle = require("./lifecycle.js");
|
|
30
|
+
/**
|
|
31
|
+
* Where the code is running (CORE-09, IOS-11).
|
|
32
|
+
*
|
|
33
|
+
* Five packages detected the platform five ways, with contradicting fallbacks
|
|
34
|
+
* (rn-payment assumed Android, rn-auth assumed iOS). One source now: it reads
|
|
35
|
+
* React Native's `Platform` lazily, so this module also loads under plain Node,
|
|
36
|
+
* where it reports `unsupported`.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/** What a build is for. A package may refuse production configuration elsewhere. */
|
|
40
|
+
|
|
41
|
+
const reactNative = (0, _index.lazyPeer)('react-native', () => require('react-native'));
|
|
42
|
+
let platformOverride;
|
|
43
|
+
|
|
44
|
+
/** The OS the app runs on, or `unsupported` (web, Node, a platform with no adapter). */
|
|
45
|
+
function currentPlatform() {
|
|
46
|
+
if (platformOverride) return platformOverride;
|
|
47
|
+
const result = reactNative.get();
|
|
48
|
+
const os = result.ok ? result.module.Platform?.OS : undefined;
|
|
49
|
+
return os === 'android' || os === 'ios' ? os : 'unsupported';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Test seam: pins `currentPlatform()`; `undefined` goes back to the real one. */
|
|
53
|
+
function setPlatformOverride(platform) {
|
|
54
|
+
platformOverride = platform;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Picks a value for the current platform, falling back to `default`. */
|
|
58
|
+
function byPlatform(values) {
|
|
59
|
+
const platform = currentPlatform();
|
|
60
|
+
if (platform === 'android' && values.android !== undefined) return values.android;
|
|
61
|
+
if (platform === 'ios' && values.ios !== undefined) return values.ios;
|
|
62
|
+
return values.default;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Whether this is a development build: React Native's `__DEV__`, or, where that
|
|
67
|
+
* global does not exist (plain Node, some test runners), `NODE_ENV` not being
|
|
68
|
+
* `production`.
|
|
69
|
+
*/
|
|
70
|
+
function isDevBuild() {
|
|
71
|
+
if (typeof __DEV__ !== 'undefined') return __DEV__ === true;
|
|
72
|
+
const {
|
|
73
|
+
process
|
|
74
|
+
} = globalThis;
|
|
75
|
+
return process?.env?.NODE_ENV !== 'production';
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_index","require","_lifecycle","reactNative","lazyPeer","platformOverride","currentPlatform","result","get","os","ok","module","Platform","OS","undefined","setPlatformOverride","platform","byPlatform","values","android","ios","default","isDevBuild","__DEV__","process","globalThis","env","NODE_ENV"],"sourceRoot":"../../../src","sources":["runtime/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,IAAAA,MAAA,GAAAC,OAAA;AAsDA,IAAAC,UAAA,GAAAD,OAAA;AA9DA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA;;AAOA,MAAME,WAAW,GAAG,IAAAC,eAAQ,EAC3B,cAAc,EACd,MAAMH,OAAO,CAAC,cAAc,CAC7B,CAAC;AAED,IAAII,gBAA6C;;AAEjD;AACO,SAASC,eAAeA,CAAA,EAAoB;EAClD,IAAID,gBAAgB,EAAE,OAAOA,gBAAgB;EAC7C,MAAME,MAAM,GAAGJ,WAAW,CAACK,GAAG,CAAC,CAAC;EAChC,MAAMC,EAAE,GAAGF,MAAM,CAACG,EAAE,GAAGH,MAAM,CAACI,MAAM,CAACC,QAAQ,EAAEC,EAAE,GAAGC,SAAS;EAC7D,OAAOL,EAAE,KAAK,SAAS,IAAIA,EAAE,KAAK,KAAK,GAAGA,EAAE,GAAG,aAAa;AAC7D;;AAEA;AACO,SAASM,mBAAmBA,CAACC,QAAqC,EAAQ;EAChFX,gBAAgB,GAAGW,QAAQ;AAC5B;;AA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