@chipmobilesdk/rn-core 0.0.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.
Files changed (158) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/lib/commonjs/diagnostics/index.js +81 -0
  3. package/lib/commonjs/diagnostics/index.js.map +1 -0
  4. package/lib/commonjs/errors/index.js +86 -0
  5. package/lib/commonjs/errors/index.js.map +1 -0
  6. package/lib/commonjs/index.js +305 -0
  7. package/lib/commonjs/index.js.map +1 -0
  8. package/lib/commonjs/intl/index.js +98 -0
  9. package/lib/commonjs/intl/index.js.map +1 -0
  10. package/lib/commonjs/kv/index.js +83 -0
  11. package/lib/commonjs/kv/index.js.map +1 -0
  12. package/lib/commonjs/lazy/index.js +63 -0
  13. package/lib/commonjs/lazy/index.js.map +1 -0
  14. package/lib/commonjs/listeners/index.js +110 -0
  15. package/lib/commonjs/listeners/index.js.map +1 -0
  16. package/lib/commonjs/messages/index.js +53 -0
  17. package/lib/commonjs/messages/index.js.map +1 -0
  18. package/lib/commonjs/package.json +1 -0
  19. package/lib/commonjs/react/index.js +93 -0
  20. package/lib/commonjs/react/index.js.map +1 -0
  21. package/lib/commonjs/redact/index.js +128 -0
  22. package/lib/commonjs/redact/index.js.map +1 -0
  23. package/lib/commonjs/runtime/index.js +77 -0
  24. package/lib/commonjs/runtime/index.js.map +1 -0
  25. package/lib/commonjs/runtime/lifecycle.js +105 -0
  26. package/lib/commonjs/runtime/lifecycle.js.map +1 -0
  27. package/lib/commonjs/scheduler/index.js +216 -0
  28. package/lib/commonjs/scheduler/index.js.map +1 -0
  29. package/lib/commonjs/store/index.js +39 -0
  30. package/lib/commonjs/store/index.js.map +1 -0
  31. package/lib/commonjs/testing/conformance.js +79 -0
  32. package/lib/commonjs/testing/conformance.js.map +1 -0
  33. package/lib/commonjs/testing/index.js +58 -0
  34. package/lib/commonjs/testing/index.js.map +1 -0
  35. package/lib/commonjs/testing/lifecycle.js +37 -0
  36. package/lib/commonjs/testing/lifecycle.js.map +1 -0
  37. package/lib/commonjs/testing/redaction.js +118 -0
  38. package/lib/commonjs/testing/redaction.js.map +1 -0
  39. package/lib/commonjs/testing/scheduler.js +51 -0
  40. package/lib/commonjs/testing/scheduler.js.map +1 -0
  41. package/lib/module/diagnostics/index.js +75 -0
  42. package/lib/module/diagnostics/index.js.map +1 -0
  43. package/lib/module/errors/index.js +78 -0
  44. package/lib/module/errors/index.js.map +1 -0
  45. package/lib/module/index.js +24 -0
  46. package/lib/module/index.js.map +1 -0
  47. package/lib/module/intl/index.js +91 -0
  48. package/lib/module/intl/index.js.map +1 -0
  49. package/lib/module/kv/index.js +76 -0
  50. package/lib/module/kv/index.js.map +1 -0
  51. package/lib/module/lazy/index.js +59 -0
  52. package/lib/module/lazy/index.js.map +1 -0
  53. package/lib/module/listeners/index.js +104 -0
  54. package/lib/module/listeners/index.js.map +1 -0
  55. package/lib/module/messages/index.js +48 -0
  56. package/lib/module/messages/index.js.map +1 -0
  57. package/lib/module/package.json +1 -0
  58. package/lib/module/react/index.js +86 -0
  59. package/lib/module/react/index.js.map +1 -0
  60. package/lib/module/redact/index.js +118 -0
  61. package/lib/module/redact/index.js.map +1 -0
  62. package/lib/module/runtime/index.js +52 -0
  63. package/lib/module/runtime/index.js.map +1 -0
  64. package/lib/module/runtime/lifecycle.js +99 -0
  65. package/lib/module/runtime/lifecycle.js.map +1 -0
  66. package/lib/module/scheduler/index.js +203 -0
  67. package/lib/module/scheduler/index.js.map +1 -0
  68. package/lib/module/store/index.js +33 -0
  69. package/lib/module/store/index.js.map +1 -0
  70. package/lib/module/testing/conformance.js +72 -0
  71. package/lib/module/testing/conformance.js.map +1 -0
  72. package/lib/module/testing/index.js +12 -0
  73. package/lib/module/testing/index.js.map +1 -0
  74. package/lib/module/testing/lifecycle.js +32 -0
  75. package/lib/module/testing/lifecycle.js.map +1 -0
  76. package/lib/module/testing/redaction.js +113 -0
  77. package/lib/module/testing/redaction.js.map +1 -0
  78. package/lib/module/testing/scheduler.js +47 -0
  79. package/lib/module/testing/scheduler.js.map +1 -0
  80. package/lib/typescript/commonjs/diagnostics/index.d.ts +49 -0
  81. package/lib/typescript/commonjs/diagnostics/index.d.ts.map +1 -0
  82. package/lib/typescript/commonjs/errors/index.d.ts +59 -0
  83. package/lib/typescript/commonjs/errors/index.d.ts.map +1 -0
  84. package/lib/typescript/commonjs/index.d.ts +22 -0
  85. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  86. package/lib/typescript/commonjs/intl/index.d.ts +25 -0
  87. package/lib/typescript/commonjs/intl/index.d.ts.map +1 -0
  88. package/lib/typescript/commonjs/kv/index.d.ts +38 -0
  89. package/lib/typescript/commonjs/kv/index.d.ts.map +1 -0
  90. package/lib/typescript/commonjs/lazy/index.d.ts +36 -0
  91. package/lib/typescript/commonjs/lazy/index.d.ts.map +1 -0
  92. package/lib/typescript/commonjs/listeners/index.d.ts +61 -0
  93. package/lib/typescript/commonjs/listeners/index.d.ts.map +1 -0
  94. package/lib/typescript/commonjs/messages/index.d.ts +39 -0
  95. package/lib/typescript/commonjs/messages/index.d.ts.map +1 -0
  96. package/lib/typescript/commonjs/package.json +1 -0
  97. package/lib/typescript/commonjs/react/index.d.ts +38 -0
  98. package/lib/typescript/commonjs/react/index.d.ts.map +1 -0
  99. package/lib/typescript/commonjs/redact/index.d.ts +47 -0
  100. package/lib/typescript/commonjs/redact/index.d.ts.map +1 -0
  101. package/lib/typescript/commonjs/runtime/index.d.ts +21 -0
  102. package/lib/typescript/commonjs/runtime/index.d.ts.map +1 -0
  103. package/lib/typescript/commonjs/runtime/lifecycle.d.ts +34 -0
  104. package/lib/typescript/commonjs/runtime/lifecycle.d.ts.map +1 -0
  105. package/lib/typescript/commonjs/scheduler/index.d.ts +108 -0
  106. package/lib/typescript/commonjs/scheduler/index.d.ts.map +1 -0
  107. package/lib/typescript/commonjs/store/index.d.ts +18 -0
  108. package/lib/typescript/commonjs/store/index.d.ts.map +1 -0
  109. package/lib/typescript/commonjs/testing/conformance.d.ts +35 -0
  110. package/lib/typescript/commonjs/testing/conformance.d.ts.map +1 -0
  111. package/lib/typescript/commonjs/testing/index.d.ts +10 -0
  112. package/lib/typescript/commonjs/testing/index.d.ts.map +1 -0
  113. package/lib/typescript/commonjs/testing/lifecycle.d.ts +15 -0
  114. package/lib/typescript/commonjs/testing/lifecycle.d.ts.map +1 -0
  115. package/lib/typescript/commonjs/testing/redaction.d.ts +35 -0
  116. package/lib/typescript/commonjs/testing/redaction.d.ts.map +1 -0
  117. package/lib/typescript/commonjs/testing/scheduler.d.ts +15 -0
  118. package/lib/typescript/commonjs/testing/scheduler.d.ts.map +1 -0
  119. package/lib/typescript/module/diagnostics/index.d.ts +49 -0
  120. package/lib/typescript/module/diagnostics/index.d.ts.map +1 -0
  121. package/lib/typescript/module/errors/index.d.ts +59 -0
  122. package/lib/typescript/module/errors/index.d.ts.map +1 -0
  123. package/lib/typescript/module/index.d.ts +22 -0
  124. package/lib/typescript/module/index.d.ts.map +1 -0
  125. package/lib/typescript/module/intl/index.d.ts +25 -0
  126. package/lib/typescript/module/intl/index.d.ts.map +1 -0
  127. package/lib/typescript/module/kv/index.d.ts +38 -0
  128. package/lib/typescript/module/kv/index.d.ts.map +1 -0
  129. package/lib/typescript/module/lazy/index.d.ts +36 -0
  130. package/lib/typescript/module/lazy/index.d.ts.map +1 -0
  131. package/lib/typescript/module/listeners/index.d.ts +61 -0
  132. package/lib/typescript/module/listeners/index.d.ts.map +1 -0
  133. package/lib/typescript/module/messages/index.d.ts +39 -0
  134. package/lib/typescript/module/messages/index.d.ts.map +1 -0
  135. package/lib/typescript/module/package.json +1 -0
  136. package/lib/typescript/module/react/index.d.ts +38 -0
  137. package/lib/typescript/module/react/index.d.ts.map +1 -0
  138. package/lib/typescript/module/redact/index.d.ts +47 -0
  139. package/lib/typescript/module/redact/index.d.ts.map +1 -0
  140. package/lib/typescript/module/runtime/index.d.ts +21 -0
  141. package/lib/typescript/module/runtime/index.d.ts.map +1 -0
  142. package/lib/typescript/module/runtime/lifecycle.d.ts +34 -0
  143. package/lib/typescript/module/runtime/lifecycle.d.ts.map +1 -0
  144. package/lib/typescript/module/scheduler/index.d.ts +108 -0
  145. package/lib/typescript/module/scheduler/index.d.ts.map +1 -0
  146. package/lib/typescript/module/store/index.d.ts +18 -0
  147. package/lib/typescript/module/store/index.d.ts.map +1 -0
  148. package/lib/typescript/module/testing/conformance.d.ts +35 -0
  149. package/lib/typescript/module/testing/conformance.d.ts.map +1 -0
  150. package/lib/typescript/module/testing/index.d.ts +10 -0
  151. package/lib/typescript/module/testing/index.d.ts.map +1 -0
  152. package/lib/typescript/module/testing/lifecycle.d.ts +15 -0
  153. package/lib/typescript/module/testing/lifecycle.d.ts.map +1 -0
  154. package/lib/typescript/module/testing/redaction.d.ts +35 -0
  155. package/lib/typescript/module/testing/redaction.d.ts.map +1 -0
  156. package/lib/typescript/module/testing/scheduler.d.ts +15 -0
  157. package/lib/typescript/module/testing/scheduler.d.ts.map +1 -0
  158. package/package.json +154 -46
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.clearIntlCaches = clearIntlCaches;
7
+ exports.getDateTimeFormat = getDateTimeFormat;
8
+ exports.getNumberFormat = getNumberFormat;
9
+ exports.isValidTimeZone = isValidTimeZone;
10
+ /**
11
+ * Cached `Intl` formatters (PERF-01, PERF-08, I18N-03, NOT-20).
12
+ *
13
+ * Constructing an `Intl.DateTimeFormat` or `Intl.NumberFormat` is expensive on
14
+ * Hermes, and rn-notification built one per time-zone calculation (thousands in a
15
+ * recurrence expansion) while rn-i18n built one per formatted value. Formatters
16
+ * are immutable once built, so one per (locale, options) is shared. Each cache is
17
+ * a small LRU: the working set is a few locales and zones, and an app that cycles
18
+ * through many still holds a bounded number.
19
+ */
20
+
21
+ const CAPACITY = 32;
22
+ function lru(capacity) {
23
+ const entries = new Map();
24
+ return {
25
+ get(key, create) {
26
+ const hit = entries.get(key);
27
+ if (hit !== undefined) {
28
+ // Re-insert to mark it most recently used.
29
+ entries.delete(key);
30
+ entries.set(key, hit);
31
+ return hit;
32
+ }
33
+ const value = create();
34
+ entries.set(key, value);
35
+ if (entries.size > capacity) {
36
+ const oldest = entries.keys().next().value;
37
+ if (oldest !== undefined) entries.delete(oldest);
38
+ }
39
+ return value;
40
+ },
41
+ clear: () => entries.clear(),
42
+ size: () => entries.size
43
+ };
44
+ }
45
+
46
+ /** A stable key for an options object: keys sorted, so `{a, b}` and `{b, a}` share. */
47
+ function keyOf(locale, options) {
48
+ if (!options) return `${locale ?? ''}|`;
49
+ const sorted = Object.keys(options).sort().map(key => `${key}=${String(options[key])}`);
50
+ return `${locale ?? ''}|${sorted.join(',')}`;
51
+ }
52
+ const numberFormats = lru(CAPACITY);
53
+ const dateTimeFormats = lru(CAPACITY);
54
+ const timeZones = new Map();
55
+ const TIME_ZONE_MEMO_LIMIT = 256;
56
+
57
+ /**
58
+ * A shared `Intl.NumberFormat`. Throws what the constructor throws (an unknown
59
+ * currency, say): callers decide how a bad option is reported.
60
+ */
61
+ function getNumberFormat(locale, options) {
62
+ return numberFormats.get(keyOf(locale, options), () => new Intl.NumberFormat(locale, options));
63
+ }
64
+
65
+ /** A shared `Intl.DateTimeFormat`. Throws what the constructor throws. */
66
+ function getDateTimeFormat(locale, options) {
67
+ return dateTimeFormats.get(keyOf(locale, options), () => new Intl.DateTimeFormat(locale, options));
68
+ }
69
+
70
+ /**
71
+ * Whether `Intl` accepts the IANA zone, memoized. Hermes raises a hard error for
72
+ * an unknown zone, so a stored zone is checked here before it reaches `Intl`.
73
+ */
74
+ function isValidTimeZone(timeZone) {
75
+ if (timeZone.length === 0) return false;
76
+ const known = timeZones.get(timeZone);
77
+ if (known !== undefined) return known;
78
+ let valid;
79
+ try {
80
+ getDateTimeFormat('en-US', {
81
+ timeZone
82
+ }).format(0);
83
+ valid = true;
84
+ } catch {
85
+ valid = false;
86
+ }
87
+ if (timeZones.size >= TIME_ZONE_MEMO_LIMIT) timeZones.clear();
88
+ timeZones.set(timeZone, valid);
89
+ return valid;
90
+ }
91
+
92
+ /** Test seam: drops every cached formatter and zone check. */
93
+ function clearIntlCaches() {
94
+ numberFormats.clear();
95
+ dateTimeFormats.clear();
96
+ timeZones.clear();
97
+ }
98
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["CAPACITY","lru","capacity","entries","Map","get","key","create","hit","undefined","delete","set","value","size","oldest","keys","next","clear","keyOf","locale","options","sorted","Object","sort","map","String","join","numberFormats","dateTimeFormats","timeZones","TIME_ZONE_MEMO_LIMIT","getNumberFormat","Intl","NumberFormat","getDateTimeFormat","DateTimeFormat","isValidTimeZone","timeZone","length","known","valid","format","clearIntlCaches"],"sourceRoot":"../../../src","sources":["intl/index.ts"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMA,QAAQ,GAAG,EAAE;AAEnB,SAASC,GAAGA,CAAIC,QAAgB,EAAE;EACjC,MAAMC,OAAO,GAAG,IAAIC,GAAG,CAAY,CAAC;EACpC,OAAO;IACNC,GAAGA,CAACC,GAAW,EAAEC,MAAe,EAAK;MACpC,MAAMC,GAAG,GAAGL,OAAO,CAACE,GAAG,CAACC,GAAG,CAAC;MAC5B,IAAIE,GAAG,KAAKC,SAAS,EAAE;QACtB;QACAN,OAAO,CAACO,MAAM,CAACJ,GAAG,CAAC;QACnBH,OAAO,CAACQ,GAAG,CAACL,GAAG,EAAEE,GAAG,CAAC;QACrB,OAAOA,GAAG;MACX;MACA,MAAMI,KAAK,GAAGL,MAAM,CAAC,CAAC;MACtBJ,OAAO,CAACQ,GAAG,CAACL,GAAG,EAAEM,KAAK,CAAC;MACvB,IAAIT,OAAO,CAACU,IAAI,GAAGX,QAAQ,EAAE;QAC5B,MAAMY,MAAM,GAAGX,OAAO,CAACY,IAAI,CAAC,CAAC,CAACC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a,KAAK,CAACC,MAAM,EAAEC,OAAO,CAAC,EACtB,MAAM,IAAIY,IAAI,CAACG,cAAc,CAAChB,MAAM,EAAEC,OAAO,CAC9C,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACO,SAASgB,eAAeA,CAACC,QAAgB,EAAW;EAC1D,IAAIA,QAAQ,CAACC,MAAM,KAAK,CAAC,EAAE,OAAO,KAAK;EACvC,MAAMC,KAAK,GAAGV,SAAS,CAACxB,GAAG,CAACgC,QAAQ,CAAC;EACrC,IAAIE,KAAK,KAAK9B,SAAS,EAAE,OAAO8B,KAAK;EACrC,IAAIC,KAAc;EAClB,IAAI;IACHN,iBAAiB,CAAC,OAAO,EAAE;MAAEG;IAAS,CAAC,CAAC,CAACI,MAAM,CAAC,CAAC,CAAC;IAClDD,KAAK,GAAG,IAAI;EACb,CAAC,CAAC,MAAM;IACPA,KAAK,GAAG,KAAK;EACd;EACA,IAAIX,SAAS,CAAChB,IAAI,IAAIiB,oBAAoB,EAAED,SAAS,CAACZ,KAAK,CAAC,CAAC;EAC7DY,SAAS,CAAClB,GAAG,CAAC0B,QAAQ,EAAEG,KAAK,CAAC;EAC9B,OAAOA,KAAK;AACb;;AAEA;AACO,SAASE,eAAeA,CAAA,EAAS;EACvCf,aAAa,CAACV,KAAK,CAAC,CAAC;EACrBW,eAAe,CAACX,KAAK,CAAC,CAAC;EACvBY,SAAS,CAACZ,KAAK,CAAC,CAAC;AAClB","ignoreList":[]}
@@ -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,CA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ACF","ignoreList":[]}
@@ -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,EAAQ;IACnC,IAAIQ,SAAS,EAAE;IACfA,SA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MAC1B,MAAMG,GAAG,GAAGJ,MAAM,EAAEI,GAAG,CAACD,KAAK,CAAC;MAC9B,IAAIC,GAAG,KAAKC,SAAS,IAAIL,MAAM,EAAE;QAChC,IAAIF,IAAI,CAACJ,GAAG,CAACU,GAAG,CAAC,EAAE,OAAO,KAAK;QAC/BN,IAAI,CAACQ,GAAG,CAACF,GAAG,EAAE,IAAI,CAAC;QACnB,IAAIN,IAAI,CAACH,IAAI,GAAGK,MAAM,CAACO,QAAQ,EAAE;UAChC,MAAMC,MAAM,GAAGV,IAAI,CAACW,IAAI,CAAC,CAAC,CAACC,IAAI,CAAC,CAAC,CAACC,KAAK;UACvC,IAAIH,MAAM,KAAKH,SAAS,EAAEP,IAAI,CAACP,MAAM,CAACiB,MAAM,CAAC;QAC9C;MACD;MACA3B,SAAS,CAACW,MAAM,CAACW,KAAK,CAAC;MACvB,OAAO,IAAI;IACZ,CAAC;IACDS,SAAS,EAAEvB,QAAQ,IAAIR,SAAS,CAACO,GAAG,CAACC,QAAQ,CAAC;IAC9CwB,MAAMA,CAACC,OAAO,EAAE;MACf,KAAK,MAAMV,GAAG,IAAI,CAAC,GAAGN,IAAI,CAACW,IAAI,CAAC,CAAC,CAAC,EAAE;QACnC,IAAIK,OAAO,CAACV,GAAG,CAAC,EAAEN,IAAI,CAACP,MAAM,CAACa,GAAG,CAAC;MACnC;IACD,CAAC;IACDW,OAAOA,CAAA,EAAG;MACTd,QAAQ,GAAG,IAAI;MACfpB,SAAS,CAACe,KAAK,CAAC,CAAC;MACjBE,IAAI,CAACF,KAAK,CAAC,CAAC;IACb,CAAC;IACDoB,aAAa,EAAEA,CAAA,KAAMnC,SAAS,CAACc;EAChC,CAAC;AACF","ignoreList":[]}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
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;AAC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AAG,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,IAA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,WAAW,GAAGH,IAAI;EAE1B,SAASI,QAAQA,CAAC;IAAE1B,KAAK;IAAE2B;EAA6C,CAAC,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