@awiki/dsh-plugin 0.3.7 → 0.3.10

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 (213) hide show
  1. package/README.md +109 -71
  2. package/README.zh.md +89 -61
  3. package/THIRD_PARTY_NOTICES.md +1 -1
  4. package/cordis.patch.yml +6 -5
  5. package/lib/builtin-tenants.json +22 -0
  6. package/lib/builtin-tenants.sha256 +1 -0
  7. package/lib/client.js +7973 -2264
  8. package/lib/client.js.map +1 -1
  9. package/lib/index.js +3481 -1145
  10. package/lib/model-proxy-contract.js +11 -3
  11. package/lib/provider.js +73 -17
  12. package/lib/{sdk-adapter--trNlr-T.mjs → sdk-adapter-CYcJH7sM.mjs} +374 -101
  13. package/lib/typert.host.js +1595 -168
  14. package/lib/typert.remote-client.d.ts +43 -7
  15. package/lib/typert.remote-client.d.ts.map +1 -1
  16. package/lib/typert.remote-client.js +1595 -168
  17. package/lib/types/builtin-tenant-config.d.ts +19 -0
  18. package/lib/types/builtin-tenant-config.d.ts.map +1 -0
  19. package/lib/types/builtin-tenant-config.js +57 -0
  20. package/lib/types/builtin-tenant-config.js.map +1 -0
  21. package/lib/types/client/AwikiDeviceJoinReminder.d.ts +15 -0
  22. package/lib/types/client/AwikiDeviceJoinReminder.d.ts.map +1 -0
  23. package/lib/types/client/AwikiDeviceJoinReminder.js +74 -0
  24. package/lib/types/client/AwikiDeviceJoinReminder.js.map +1 -0
  25. package/lib/types/client/AwikiDevices.d.ts +33 -0
  26. package/lib/types/client/AwikiDevices.d.ts.map +1 -0
  27. package/lib/types/client/AwikiDevices.js +141 -0
  28. package/lib/types/client/AwikiDevices.js.map +1 -0
  29. package/lib/types/client/AwikiGroupDetails.d.ts.map +1 -1
  30. package/lib/types/client/AwikiGroupDetails.js +16 -13
  31. package/lib/types/client/AwikiGroupDetails.js.map +1 -1
  32. package/lib/types/client/AwikiIdentityAccess.d.ts +15 -8
  33. package/lib/types/client/AwikiIdentityAccess.d.ts.map +1 -1
  34. package/lib/types/client/AwikiIdentityAccess.js +203 -39
  35. package/lib/types/client/AwikiIdentityAccess.js.map +1 -1
  36. package/lib/types/client/AwikiIntegrationSettings.d.ts +21 -0
  37. package/lib/types/client/AwikiIntegrationSettings.d.ts.map +1 -0
  38. package/lib/types/client/AwikiIntegrationSettings.js +105 -0
  39. package/lib/types/client/AwikiIntegrationSettings.js.map +1 -0
  40. package/lib/types/client/AwikiMail.d.ts +1 -1
  41. package/lib/types/client/AwikiMail.d.ts.map +1 -1
  42. package/lib/types/client/AwikiMail.js +17 -137
  43. package/lib/types/client/AwikiMail.js.map +1 -1
  44. package/lib/types/client/AwikiOverlay.d.ts +0 -1
  45. package/lib/types/client/AwikiOverlay.d.ts.map +1 -1
  46. package/lib/types/client/AwikiOverlay.js +26 -28
  47. package/lib/types/client/AwikiOverlay.js.map +1 -1
  48. package/lib/types/client/AwikiProfileCard.d.ts.map +1 -1
  49. package/lib/types/client/AwikiProfileCard.js +17 -18
  50. package/lib/types/client/AwikiProfileCard.js.map +1 -1
  51. package/lib/types/client/AwikiRecoveryForm.d.ts +5 -1
  52. package/lib/types/client/AwikiRecoveryForm.d.ts.map +1 -1
  53. package/lib/types/client/AwikiRecoveryForm.js +73 -30
  54. package/lib/types/client/AwikiRecoveryForm.js.map +1 -1
  55. package/lib/types/client/AwikiSettingsSection.d.ts +28 -13
  56. package/lib/types/client/AwikiSettingsSection.d.ts.map +1 -1
  57. package/lib/types/client/AwikiSettingsSection.js +93 -61
  58. package/lib/types/client/AwikiSettingsSection.js.map +1 -1
  59. package/lib/types/client/AwikiUpdates.d.ts +10 -0
  60. package/lib/types/client/AwikiUpdates.d.ts.map +1 -0
  61. package/lib/types/client/AwikiUpdates.js +57 -0
  62. package/lib/types/client/AwikiUpdates.js.map +1 -0
  63. package/lib/types/client/awiki-client-bridge.d.ts +1 -1
  64. package/lib/types/client/awiki-client-bridge.d.ts.map +1 -1
  65. package/lib/types/client/awiki-client-bridge.js +4 -1
  66. package/lib/types/client/awiki-client-bridge.js.map +1 -1
  67. package/lib/types/client/controller.d.ts +84 -44
  68. package/lib/types/client/controller.d.ts.map +1 -1
  69. package/lib/types/client/controller.js +515 -309
  70. package/lib/types/client/controller.js.map +1 -1
  71. package/lib/types/client/drafts.d.ts +31 -0
  72. package/lib/types/client/drafts.d.ts.map +1 -0
  73. package/lib/types/client/drafts.js +94 -0
  74. package/lib/types/client/drafts.js.map +1 -0
  75. package/lib/types/client/image-cache.d.ts +2 -2
  76. package/lib/types/client/image-cache.d.ts.map +1 -1
  77. package/lib/types/client/image-cache.js +15 -2
  78. package/lib/types/client/image-cache.js.map +1 -1
  79. package/lib/types/client/index.d.ts.map +1 -1
  80. package/lib/types/client/index.js +63 -19
  81. package/lib/types/client/index.js.map +1 -1
  82. package/lib/types/client/integration-operation.d.ts +9 -0
  83. package/lib/types/client/integration-operation.d.ts.map +1 -0
  84. package/lib/types/client/integration-operation.js +54 -0
  85. package/lib/types/client/integration-operation.js.map +1 -0
  86. package/lib/types/client/mail-list-cache.d.ts +2 -0
  87. package/lib/types/client/mail-list-cache.d.ts.map +1 -1
  88. package/lib/types/client/mail-list-cache.js +18 -0
  89. package/lib/types/client/mail-list-cache.js.map +1 -1
  90. package/lib/types/client/otp-cooldown.d.ts +6 -0
  91. package/lib/types/client/otp-cooldown.d.ts.map +1 -0
  92. package/lib/types/client/otp-cooldown.js +18 -0
  93. package/lib/types/client/otp-cooldown.js.map +1 -0
  94. package/lib/types/client/settings-controller.d.ts +34 -0
  95. package/lib/types/client/settings-controller.d.ts.map +1 -1
  96. package/lib/types/client/settings-controller.js +182 -2
  97. package/lib/types/client/settings-controller.js.map +1 -1
  98. package/lib/types/client/settings-locales.d.ts +1 -1
  99. package/lib/types/client/settings-locales.d.ts.map +1 -1
  100. package/lib/types/client/settings-locales.js +192 -14
  101. package/lib/types/client/settings-locales.js.map +1 -1
  102. package/lib/types/client/slots.d.ts +20 -10
  103. package/lib/types/client/slots.d.ts.map +1 -1
  104. package/lib/types/client/slots.js +0 -1
  105. package/lib/types/client/slots.js.map +1 -1
  106. package/lib/types/conversation-preferences.d.ts.map +1 -1
  107. package/lib/types/conversation-preferences.js +0 -17
  108. package/lib/types/conversation-preferences.js.map +1 -1
  109. package/lib/types/desktop-distribution.d.ts +25 -0
  110. package/lib/types/desktop-distribution.d.ts.map +1 -0
  111. package/lib/types/desktop-distribution.js +57 -0
  112. package/lib/types/desktop-distribution.js.map +1 -0
  113. package/lib/types/domain.d.ts +1 -1
  114. package/lib/types/domain.d.ts.map +1 -1
  115. package/lib/types/domain.js +2 -1
  116. package/lib/types/domain.js.map +1 -1
  117. package/lib/types/index.d.ts +164 -41
  118. package/lib/types/index.d.ts.map +1 -1
  119. package/lib/types/index.js +1562 -529
  120. package/lib/types/index.js.map +1 -1
  121. package/lib/types/integration-client.d.ts +17 -0
  122. package/lib/types/integration-client.d.ts.map +1 -0
  123. package/lib/types/integration-client.js +233 -0
  124. package/lib/types/integration-client.js.map +1 -0
  125. package/lib/types/legacy-sent-mail-cache.d.ts +4 -0
  126. package/lib/types/legacy-sent-mail-cache.d.ts.map +1 -0
  127. package/lib/types/legacy-sent-mail-cache.js +29 -0
  128. package/lib/types/legacy-sent-mail-cache.js.map +1 -0
  129. package/lib/types/listener-state.d.ts +5 -3
  130. package/lib/types/listener-state.d.ts.map +1 -1
  131. package/lib/types/listener-state.js +28 -13
  132. package/lib/types/listener-state.js.map +1 -1
  133. package/lib/types/listener.d.ts +9 -32
  134. package/lib/types/listener.d.ts.map +1 -1
  135. package/lib/types/listener.js +11 -127
  136. package/lib/types/listener.js.map +1 -1
  137. package/lib/types/mail-list-client.d.ts +12 -0
  138. package/lib/types/mail-list-client.d.ts.map +1 -0
  139. package/lib/types/mail-list-client.js +254 -0
  140. package/lib/types/mail-list-client.js.map +1 -0
  141. package/lib/types/mail-recovery-observability.d.ts +8 -0
  142. package/lib/types/mail-recovery-observability.d.ts.map +1 -0
  143. package/lib/types/mail-recovery-observability.js +119 -0
  144. package/lib/types/mail-recovery-observability.js.map +1 -0
  145. package/lib/types/mail.d.ts +2 -28
  146. package/lib/types/mail.d.ts.map +1 -1
  147. package/lib/types/mail.js +2 -79
  148. package/lib/types/mail.js.map +1 -1
  149. package/lib/types/model-proxy-contract.d.ts.map +1 -1
  150. package/lib/types/model-proxy-contract.js +7 -0
  151. package/lib/types/model-proxy-contract.js.map +1 -1
  152. package/lib/types/package-version.generated.d.ts +4 -0
  153. package/lib/types/package-version.generated.d.ts.map +1 -0
  154. package/lib/types/package-version.generated.js +4 -0
  155. package/lib/types/package-version.generated.js.map +1 -0
  156. package/lib/types/profile-state.d.ts +2 -13
  157. package/lib/types/profile-state.d.ts.map +1 -1
  158. package/lib/types/profile-state.js +3 -20
  159. package/lib/types/profile-state.js.map +1 -1
  160. package/lib/types/provider-api.d.ts +134 -43
  161. package/lib/types/provider-api.d.ts.map +1 -1
  162. package/lib/types/provider.d.ts +8 -2
  163. package/lib/types/provider.d.ts.map +1 -1
  164. package/lib/types/provider.js +76 -16
  165. package/lib/types/provider.js.map +1 -1
  166. package/lib/types/realtime-supervisor.d.ts +60 -0
  167. package/lib/types/realtime-supervisor.d.ts.map +1 -0
  168. package/lib/types/realtime-supervisor.js +255 -0
  169. package/lib/types/realtime-supervisor.js.map +1 -0
  170. package/lib/types/sdk-adapter.d.ts +62 -11
  171. package/lib/types/sdk-adapter.d.ts.map +1 -1
  172. package/lib/types/sdk-adapter.js +285 -123
  173. package/lib/types/sdk-adapter.js.map +1 -1
  174. package/lib/types/settings-rpc-contract.d.ts +58 -0
  175. package/lib/types/settings-rpc-contract.d.ts.map +1 -1
  176. package/lib/types/settings-rpc-contract.js +103 -0
  177. package/lib/types/settings-rpc-contract.js.map +1 -1
  178. package/lib/types/settings-rpc.d.ts +14 -1
  179. package/lib/types/settings-rpc.d.ts.map +1 -1
  180. package/lib/types/settings-rpc.js +130 -1
  181. package/lib/types/settings-rpc.js.map +1 -1
  182. package/lib/types/tenant-registry.d.ts +74 -0
  183. package/lib/types/tenant-registry.d.ts.map +1 -0
  184. package/lib/types/tenant-registry.js +440 -0
  185. package/lib/types/tenant-registry.js.map +1 -0
  186. package/lib/types/tools.d.ts +1 -1
  187. package/lib/types/tools.d.ts.map +1 -1
  188. package/lib/types/tools.js +4 -20
  189. package/lib/types/tools.js.map +1 -1
  190. package/lib/types/types.d.ts +249 -66
  191. package/lib/types/types.d.ts.map +1 -1
  192. package/lib/types/types.js.map +1 -1
  193. package/lib/types/update-policy.d.ts +51 -0
  194. package/lib/types/update-policy.d.ts.map +1 -0
  195. package/lib/types/update-policy.js +379 -0
  196. package/lib/types/update-policy.js.map +1 -0
  197. package/lib/types/version.d.ts +4 -0
  198. package/lib/types/version.d.ts.map +1 -0
  199. package/lib/types/version.js +44 -0
  200. package/lib/types/version.js.map +1 -0
  201. package/package.json +26 -8
  202. package/lib/types/base64.d.ts +0 -4
  203. package/lib/types/base64.d.ts.map +0 -1
  204. package/lib/types/base64.js +0 -28
  205. package/lib/types/base64.js.map +0 -1
  206. package/lib/types/client/mail-attachment.d.ts +0 -40
  207. package/lib/types/client/mail-attachment.d.ts.map +0 -1
  208. package/lib/types/client/mail-attachment.js +0 -187
  209. package/lib/types/client/mail-attachment.js.map +0 -1
  210. package/lib/types/sent-mail-store.d.ts +0 -27
  211. package/lib/types/sent-mail-store.d.ts.map +0 -1
  212. package/lib/types/sent-mail-store.js +0 -348
  213. package/lib/types/sent-mail-store.js.map +0 -1
@@ -1,3 +1,105 @@
1
+ //#region lib/types/mail-recovery-observability.js
2
+ const MAIL_INGRESS_CLASSIFICATIONS = /* @__PURE__ */ new Set([
3
+ "reached",
4
+ "not_reached",
5
+ "unknown"
6
+ ]);
7
+ const AUTH_STATUS_CLASSES = /* @__PURE__ */ new Set([
8
+ "accepted",
9
+ "rejected",
10
+ "dependency_unavailable",
11
+ "unknown"
12
+ ]);
13
+ const MAIL_CLOSED_CLASSIFICATIONS = /* @__PURE__ */ new Set([
14
+ "success",
15
+ "authentication_rejected",
16
+ "dependency_unavailable",
17
+ "no_active_handle",
18
+ "multiple_active_handles",
19
+ "no_mailbox",
20
+ "owner_conflict",
21
+ "unknown"
22
+ ]);
23
+ const STABLE_MACHINE_CODE = /^[a-z0-9](?:[a-z0-9._-]{0,126}[a-z0-9])?$/u;
24
+ const CLOSED_FAILURE_TUPLES = /* @__PURE__ */ new Set([
25
+ "reached:rejected:authentication_rejected",
26
+ "reached:dependency_unavailable:dependency_unavailable",
27
+ "not_reached:dependency_unavailable:dependency_unavailable",
28
+ "reached:accepted:no_active_handle",
29
+ "reached:accepted:multiple_active_handles",
30
+ "reached:accepted:no_mailbox",
31
+ "reached:accepted:owner_conflict"
32
+ ]);
33
+ function property(value, key) {
34
+ try {
35
+ return typeof value === "object" && value !== null ? value[key] : void 0;
36
+ } catch {
37
+ return;
38
+ }
39
+ }
40
+ function optionalProperty(value, key) {
41
+ try {
42
+ if (typeof value !== "object" || value === null || !(key in value)) return { status: "absent" };
43
+ return {
44
+ status: "present",
45
+ value: value[key]
46
+ };
47
+ } catch {
48
+ return { status: "unreadable" };
49
+ }
50
+ }
51
+ /** Copy only a complete upstream closed classification; arbitrary errors fail closed. */
52
+ function mailRecoveryFailureFields(error) {
53
+ const ingress = property(error, "mail_ingress_classification");
54
+ const authStatus = property(error, "auth_status_class");
55
+ const closed = property(error, "mail_closed_classification");
56
+ const retryable = property(error, "retryable");
57
+ if (typeof ingress !== "string" || !MAIL_INGRESS_CLASSIFICATIONS.has(ingress) || typeof authStatus !== "string" || !AUTH_STATUS_CLASSES.has(authStatus) || typeof closed !== "string" || !MAIL_CLOSED_CLASSIFICATIONS.has(closed) || ingress === "unknown" || authStatus === "unknown" || closed === "unknown" || closed === "success" || typeof retryable !== "boolean") return void 0;
58
+ const tuple = `${ingress}:${authStatus}:${closed}`;
59
+ if (!CLOSED_FAILURE_TUPLES.has(tuple)) return void 0;
60
+ const stableCode = optionalProperty(error, "auth_stable_machine_code");
61
+ if (stableCode.status === "unreadable" || stableCode.status === "present" && (typeof stableCode.value !== "string" || !STABLE_MACHINE_CODE.test(stableCode.value)) || stableCode.status === "present" && authStatus === "accepted") return void 0;
62
+ return {
63
+ mail_ingress_classification: ingress,
64
+ auth_status_class: authStatus,
65
+ ...stableCode.status === "present" ? { auth_stable_machine_code: stableCode.value } : {},
66
+ retryable,
67
+ mail_closed_classification: closed
68
+ };
69
+ }
70
+ function successfulMailRecoveryObservability() {
71
+ return {
72
+ current_principal_matches_recovery: true,
73
+ request_generation_classification: "current",
74
+ mail_ingress_classification: "reached",
75
+ auth_status_class: "accepted",
76
+ retryable: false,
77
+ mail_closed_classification: "success"
78
+ };
79
+ }
80
+ function failedMailRecoveryObservability(error) {
81
+ return {
82
+ current_principal_matches_recovery: true,
83
+ request_generation_classification: "current",
84
+ ...mailRecoveryFailureFields(error) ?? {
85
+ mail_ingress_classification: "unknown",
86
+ auth_status_class: "unknown",
87
+ retryable: false,
88
+ mail_closed_classification: "unknown"
89
+ }
90
+ };
91
+ }
92
+ function fencedMailRecoveryObservability(currentPrincipalMatchesRecovery, requestGenerationClassification) {
93
+ return {
94
+ current_principal_matches_recovery: currentPrincipalMatchesRecovery,
95
+ request_generation_classification: requestGenerationClassification,
96
+ mail_ingress_classification: currentPrincipalMatchesRecovery ? "unknown" : "not_reached",
97
+ auth_status_class: "unknown",
98
+ retryable: false,
99
+ mail_closed_classification: "unknown"
100
+ };
101
+ }
102
+ //#endregion
1
103
  //#region lib/types/sdk-adapter.js
2
104
  /** Rust IM Core adapter that copies native values into Host-owned public DTOs. */
3
105
  const GROUP_LOOKUP_LIMIT = 100;
@@ -17,14 +119,16 @@ const RUST_FAILURE_CODES = {
17
119
  permission_denied: "forbidden",
18
120
  group_not_member: "group-membership-required",
19
121
  group_identity_stale: "group-identity-stale",
20
- auth_revoked: "identity-recovery-required",
122
+ auth_revoked: "device-rejoin-required",
123
+ local_identity_recovery_required: "identity-recovery-required",
21
124
  conflict: "conflict",
22
125
  join_required: "handle-unavailable",
23
- state_in_use: "state-in-use",
126
+ state_in_use: "conflict",
24
127
  rate_limited: "rate-limited",
25
128
  timeout: "network",
26
129
  transport_unavailable: "network",
27
130
  sync_failed: "network",
131
+ sync_blocked: "conflict",
28
132
  session_expired: "network",
29
133
  attachment_transfer_network: "network",
30
134
  recovery_reconciliation_unavailable: "network",
@@ -33,15 +137,54 @@ const RUST_FAILURE_CODES = {
33
137
  /** Closed provider error consumed by the Host's fixed public failure mapping. */
34
138
  var AwikiSdkError = class extends Error {
35
139
  code;
140
+ realtimeFailureCode;
36
141
  name = "AwikiSdkError";
37
- constructor(code) {
142
+ mail_ingress_classification;
143
+ auth_status_class;
144
+ auth_stable_machine_code;
145
+ retryable;
146
+ mail_closed_classification;
147
+ constructor(code, realtimeFailureCode, mailRecoveryFailure) {
38
148
  super(`AWiki SDK operation failed: ${code}`);
39
149
  this.code = code;
150
+ this.realtimeFailureCode = realtimeFailureCode;
151
+ if (mailRecoveryFailure !== void 0) Object.assign(this, mailRecoveryFailure);
40
152
  }
41
153
  };
42
154
  function fail(code = "remote") {
43
155
  throw new AwikiSdkError(code);
44
156
  }
157
+ const REALTIME_RETRY_WARNING_PRIORITY = [
158
+ "sync.retry.local_state.actor_closed",
159
+ "sync.retry.local_state.database_busy",
160
+ "sync.retry.local_state.constraint_failed",
161
+ "sync.retry.local_state.schema_unavailable",
162
+ "sync.retry.local_state.storage_unavailable",
163
+ "sync.retry.local_state.codec_unavailable",
164
+ "sync.retry.local_state.other",
165
+ "sync.retry.transport_unavailable",
166
+ "sync.retry.service_unavailable",
167
+ "sync.retry.local_state_unavailable"
168
+ ];
169
+ function realtimeSyncFailureCode(status, warnings, errorCode) {
170
+ if (status === "retryable_failure") return REALTIME_RETRY_WARNING_PRIORITY.find((code) => warnings.includes(code)) ?? "sync.retryable_failure";
171
+ if (status === "recovery_required") return "sync.recovery_required";
172
+ if (status === "auth_revoked") return "sync.auth_revoked";
173
+ if (status === "blocked") {
174
+ if (errorCode === "sync.client_upgrade_required") return "sync.blocked.client_upgrade_required";
175
+ if (errorCode === "device_reprovision_required") return "sync.blocked.device_reprovision_required";
176
+ if (errorCode === "server_repair_required") return "sync.blocked.server_repair_required";
177
+ if (errorCode === "sync.snapshot_item_too_large" || errorCode === "sync.snapshot_required_state_too_large") return "sync.blocked.snapshot_capacity";
178
+ if (errorCode === "sync.invalid_request") return "sync.blocked.invalid_request";
179
+ if (errorCode === "sync.invalid_cursor") return "sync.blocked.invalid_cursor";
180
+ return errorCode === void 0 ? "sync.blocked" : "sync.blocked.other";
181
+ }
182
+ return "sync.unexpected_status";
183
+ }
184
+ function syncResultErrorCode(result) {
185
+ if (!("errorCode" in result)) return void 0;
186
+ return typeof result.errorCode === "string" ? result.errorCode : void 0;
187
+ }
45
188
  function mapError(error, ambiguousSend = false) {
46
189
  if (error instanceof AwikiSdkError) throw error;
47
190
  let code = "remote";
@@ -51,7 +194,7 @@ function mapError(error, ambiguousSend = false) {
51
194
  if (value.name === "ImCoreNodeError" && typeof value.code === "string") code = ambiguousSend && (value.code === "timeout" || value.code === "transport_unavailable") ? "delivery-unknown" : RUST_FAILURE_CODES[value.code] ?? "remote";
52
195
  }
53
196
  } catch {}
54
- fail(code);
197
+ throw new AwikiSdkError(code, void 0, mailRecoveryFailureFields(error));
55
198
  }
56
199
  function safeInteger(value, minimum = 0) {
57
200
  if (!/^(?:0|[1-9]\d*)$/u.test(value)) fail();
@@ -89,14 +232,6 @@ function mailAddress(value) {
89
232
  if (length < 3 || length > 320 || !value.includes("@") || /[\s\u0000-\u001f\u007f-\u009f]/u.test(value)) fail();
90
233
  return value;
91
234
  }
92
- function mailFileName(value) {
93
- if (typeof value !== "string" || value.length === 0 || value.trim() !== value || value.replace(/[. ]+$/u, "") !== value || value === "." || value === ".." || Buffer.byteLength(value, "utf8") > 255 || /[\\/\p{C}]/u.test(value)) fail();
94
- return value;
95
- }
96
- function mailContentType(value) {
97
- if (typeof value !== "string" || !/^[A-Za-z0-9!#$&^_.+-]+\/[A-Za-z0-9!#$&^_.+-]+$/u.test(value)) fail();
98
- return value;
99
- }
100
235
  function mailAddresses(value) {
101
236
  if (!Array.isArray(value) || value.length > 100) fail();
102
237
  return value.map(mailAddress);
@@ -111,11 +246,6 @@ function uint32(value) {
111
246
  if (!Number.isSafeInteger(value) || value < 0 || value > 4294967295) fail();
112
247
  return value;
113
248
  }
114
- function recoveryE2eeGroupCount(impact) {
115
- if (typeof impact !== "object" || impact === null) fail();
116
- const value = impact;
117
- return uint32(value.unsupportedE2eeGroupCount !== void 0 ? value.unsupportedE2eeGroupCount : value.unsupportedE2EeGroupCount);
118
- }
119
249
  function boolean(value) {
120
250
  if (typeof value !== "boolean") fail();
121
251
  return value;
@@ -205,6 +335,26 @@ function identity(value) {
205
335
  registeredAt: safeInteger(value.registeredAtMs)
206
336
  };
207
337
  }
338
+ function joinProgress(value) {
339
+ return {
340
+ joinSessionId: required(value.joinSessionId),
341
+ localPhase: value.localPhase,
342
+ remoteState: value.remoteState,
343
+ expiresAt: required(value.expiresAt),
344
+ ...value.sas === void 0 ? {} : { sas: required(value.sas) },
345
+ completed: boolean(value.completed),
346
+ ...value.identity === void 0 ? {} : { identity: identity(value.identity) }
347
+ };
348
+ }
349
+ function adminJoinProgress(value) {
350
+ return {
351
+ joinSessionId: required(value.joinSessionId),
352
+ localPhase: value.localPhase,
353
+ remoteState: value.remoteState,
354
+ expiresAt: required(value.expiresAt),
355
+ ...value.sas === void 0 ? {} : { sas: required(value.sas) }
356
+ };
357
+ }
208
358
  function profile(value) {
209
359
  return {
210
360
  did: required(value.did),
@@ -312,20 +462,51 @@ function externalHttpAttempt(value) {
312
462
  }
313
463
  /** Adapt the Rust Node bridge to the frozen Host provider interface. */
314
464
  var RustSdkAdapter = class {
465
+ trustedUserPresenceSupported = process.platform === "darwin" && process.arch === "x64";
315
466
  client;
467
+ refreshingDisplayPeers = /* @__PURE__ */ new Set();
468
+ scheduleDisplayRefresh(client, peers) {
469
+ if (this.disposal !== void 0) return;
470
+ const pending = [...new Set(peers)].filter((peer) => peer.startsWith("did:") && !this.refreshingDisplayPeers.has(peer)).slice(0, 100);
471
+ if (pending.length === 0) return;
472
+ for (const peer of pending) this.refreshingDisplayPeers.add(peer);
473
+ client.refreshDisplayProfiles({ peers: pending }).catch(() => void 0).finally(() => {
474
+ for (const peer of pending) this.refreshingDisplayPeers.delete(peer);
475
+ });
476
+ }
477
+ getDisplayProfiles(peers) {
478
+ return this.run(async (client) => {
479
+ const profiles = await client.hydrateDisplayProfiles({ peers });
480
+ this.scheduleDisplayRefresh(client, peers);
481
+ return profiles.flatMap((profile) => profile.did === void 0 ? [] : [{
482
+ did: profile.did,
483
+ cacheHit: profile.cacheHit,
484
+ ...profile.handle === void 0 ? {} : { handle: profile.handle },
485
+ ...profile.displayName === void 0 ? {} : { displayName: profile.displayName }
486
+ }]);
487
+ });
488
+ }
316
489
  attachmentConversations = /* @__PURE__ */ new Map();
317
490
  disposal;
491
+ realtime;
492
+ agentInbox;
318
493
  listener;
319
494
  constructor(client) {
320
495
  this.client = Promise.resolve(client);
321
- this.listener = {
496
+ this.realtime = {
322
497
  syncNow: (reason) => this.listenerSyncNow(reason),
323
- startRealtime: () => this.listenerStartRealtime(),
498
+ startRealtime: () => this.listenerStartRealtime()
499
+ };
500
+ this.agentInbox = {
324
501
  listConversations: (request) => this.listenerConversations(request),
325
502
  getHistory: (request) => this.listenerHistory(request),
326
503
  markConversationRead: (conversationId) => this.markConversationRead(conversationId),
327
504
  sendText: (request) => this.sendText(request)
328
505
  };
506
+ this.listener = {
507
+ ...this.realtime,
508
+ ...this.agentInbox
509
+ };
329
510
  }
330
511
  async run(operation, ambiguousSend = false) {
331
512
  try {
@@ -336,16 +517,18 @@ var RustSdkAdapter = class {
336
517
  }
337
518
  async displayableMessages(client, values) {
338
519
  const messages = values.filter(displayableMessage);
339
- const peers = [...new Set(messages.filter((message) => message.conversationKind === "group" && !message.outgoing && message.senderHandle === void 0 && message.senderDisplayName === void 0).map((message) => message.senderDid))];
520
+ const peers = [...new Set(messages.filter((message) => message.conversationKind === "group" && !message.outgoing).map((message) => message.senderDid))];
340
521
  if (peers.length === 0) return [...messages];
341
522
  const profiles = await client.hydrateDisplayProfiles({ peers });
523
+ this.scheduleDisplayRefresh(client, peers);
342
524
  const byDid = /* @__PURE__ */ new Map();
343
525
  for (const profile of profiles) if (profile.did !== void 0) byDid.set(profile.did, profile);
344
526
  return messages.map((message) => {
345
527
  const profile = byDid.get(message.senderDid);
346
- if (profile === void 0) return message;
528
+ if (profile === void 0 || !profile.cacheHit) return message;
529
+ const { senderDisplayName: _snapshot, ...rest } = message;
347
530
  return {
348
- ...message,
531
+ ...rest,
349
532
  ...profile.handle === void 0 ? {} : { senderHandle: profile.handle },
350
533
  ...profile.displayName === void 0 ? {} : { senderDisplayName: profile.displayName }
351
534
  };
@@ -478,7 +661,7 @@ var RustSdkAdapter = class {
478
661
  ...value.peerPersonaId === void 0 ? {} : { peerPersonaId: value.peerPersonaId },
479
662
  ...value.did === void 0 ? {} : { did: value.did },
480
663
  ...value.credentialDid === void 0 ? {} : { credentialDid: value.credentialDid },
481
- ...value.handle === void 0 ? {} : { handle: value.handle },
664
+ ...(profile?.handle ?? value.handle) === void 0 ? {} : { handle: profile?.handle ?? value.handle },
482
665
  ...profile?.displayName === void 0 ? {} : { displayName: profile.displayName },
483
666
  ...value.role === void 0 ? {} : { role: value.role },
484
667
  ...value.status === void 0 ? {} : { status: value.status },
@@ -527,9 +710,12 @@ var RustSdkAdapter = class {
527
710
  listenerSyncNow(reason) {
528
711
  return this.run(async (client) => {
529
712
  const result = await client.syncNow({ reason });
530
- if (result.status === "idle" || result.status === "changed") return;
531
- if (result.status === "auth_revoked") fail("identity-recovery-required");
532
- fail("network");
713
+ if (result.status === "idle" || result.status === "changed") return {
714
+ pagesFetched: uint32(result.pagesFetched),
715
+ messagesHydrated: uint32(result.messagesHydrated),
716
+ olderHistoryExcluded: boolean(result.olderHistoryExcluded)
717
+ };
718
+ throw new AwikiSdkError(result.status === "auth_revoked" ? "device-rejoin-required" : "network", realtimeSyncFailureCode(result.status, result.warnings, syncResultErrorCode(result)));
533
719
  });
534
720
  }
535
721
  listenerStartRealtime() {
@@ -537,6 +723,9 @@ var RustSdkAdapter = class {
537
723
  const session = await client.startRealtime();
538
724
  return {
539
725
  nextEvent: () => this.run(() => session.nextEvent()),
726
+ getStatus: () => this.run(async () => {
727
+ return { connected: (await session.getStatus()).connected };
728
+ }),
540
729
  stop: () => this.run(() => session.stop())
541
730
  };
542
731
  });
@@ -599,7 +788,144 @@ var RustSdkAdapter = class {
599
788
  });
600
789
  }
601
790
  registerIdentity(request) {
602
- return this.run(async (client) => identity(await client.completeRegistration(request)));
791
+ return this.run(async (client) => {
792
+ const value = await client.completeRegistrationWithOutcome(request);
793
+ if (value.status === "registered") return {
794
+ status: "registered",
795
+ identity: identity(value.identity)
796
+ };
797
+ return {
798
+ status: "join-required",
799
+ continuationId: required(value.existingHandle.continuationId),
800
+ fullHandle: required(value.existingHandle.fullHandle),
801
+ mode: value.existingHandle.mode === "handle_recovery_rebind" ? "handle-recovery-rebind" : "ordinary",
802
+ requiresUserPresence: boolean(value.existingHandle.requiresUserPresence)
803
+ };
804
+ });
805
+ }
806
+ beginDeviceJoin(request) {
807
+ return this.run(async (client) => joinProgress(await client.beginPreparedRegistrationJoin(request)));
808
+ }
809
+ getDeviceJoinStatus(joinSessionId) {
810
+ return this.run(async (client) => joinProgress(await client.resumePreparedRegistrationJoin({ joinSessionId })));
811
+ }
812
+ listLocalDeviceJoinSessions() {
813
+ return this.run(async (client) => (await client.listLocalDeviceJoinSessions()).map((value) => ({
814
+ joinSessionId: required(value.joinSessionId),
815
+ side: value.side,
816
+ localPhase: value.localPhase,
817
+ expiresAt: required(value.expiresAt)
818
+ })));
819
+ }
820
+ cancelDeviceJoin(joinSessionId) {
821
+ return this.run(async (client) => {
822
+ const value = await client.cancelPreparedRegistrationJoin({ joinSessionId });
823
+ return {
824
+ joinSessionId: required(value.joinSessionId),
825
+ side: value.side,
826
+ localPhase: value.localPhase,
827
+ expiresAt: required(value.expiresAt)
828
+ };
829
+ });
830
+ }
831
+ getCurrentDeviceSummary() {
832
+ return this.run(async (client) => {
833
+ const value = await client.getCurrentDeviceSummary();
834
+ return {
835
+ ...value.role === void 0 ? {} : { role: value.role },
836
+ readiness: value.readiness,
837
+ canManage: boolean(value.canManage)
838
+ };
839
+ });
840
+ }
841
+ syncDeviceManagement() {
842
+ return this.run(async (client) => {
843
+ await client.syncNow({ reason: "foreground_reconcile" });
844
+ });
845
+ }
846
+ getDeviceRegistry() {
847
+ return this.run(async (client) => (await client.getDeviceRegistry()).devices.map((value) => ({
848
+ deviceId: required(value.protocolDeviceId),
849
+ status: value.status,
850
+ role: value.role,
851
+ managementReady: boolean(value.managementReady),
852
+ isCurrent: boolean(value.isCurrent)
853
+ })));
854
+ }
855
+ listLocalDeviceJoinRequests() {
856
+ return this.run(async (client) => (await client.listLocalDeviceJoinRequests()).map((value) => ({
857
+ joinSessionId: required(value.joinSessionId),
858
+ protocolDeviceId: required(value.protocolDeviceId),
859
+ candidateKeyFingerprint: required(value.candidateKeyFingerprint),
860
+ issuedAt: required(value.issuedAt),
861
+ expiresAt: required(value.expiresAt),
862
+ state: value.state,
863
+ claimedByCurrentDevice: boolean(value.claimedByCurrentDevice),
864
+ canStartVerification: boolean(value.canStartVerification)
865
+ })));
866
+ }
867
+ startDeviceJoinVerification(request) {
868
+ return this.run(async (client) => adminJoinProgress(await client.startDeviceJoinVerification(request)));
869
+ }
870
+ getLocalDeviceJoinVerificationProgress(joinSessionId) {
871
+ return this.run(async (client) => adminJoinProgress(await client.getLocalDeviceJoinVerificationProgress({ joinSessionId })));
872
+ }
873
+ prepareDeviceJoinApproval(joinSessionId) {
874
+ return this.run(async (client) => {
875
+ return { approvalHandle: required((await client.prepareDeviceJoinApproval({
876
+ joinSessionId,
877
+ sasConfirmed: true
878
+ })).approvalHandle) };
879
+ });
880
+ }
881
+ confirmDeviceJoinApproval(approvalHandle) {
882
+ return this.run(async (client) => adminJoinProgress(await client.confirmDeviceJoinApproval({
883
+ approvalHandle,
884
+ userPresenceConfirmed: true
885
+ })));
886
+ }
887
+ rejectDeviceJoin(joinSessionId, reason) {
888
+ return this.run(async (client) => adminJoinProgress(await client.rejectDeviceJoin({
889
+ joinSessionId,
890
+ reason
891
+ })));
892
+ }
893
+ revokeDevice(deviceId) {
894
+ return this.run(async (client) => {
895
+ await client.revokeDevice({
896
+ targetDeviceId: deviceId,
897
+ userPresenceConfirmed: true
898
+ });
899
+ });
900
+ }
901
+ confirmUserPresence(reason) {
902
+ return this.run((client) => client.confirmUserPresence({ reason }));
903
+ }
904
+ prepareRootKeyTransfer(deviceId) {
905
+ return this.run(async (client) => {
906
+ const value = await client.prepareRootKeyTransfer({ recipientDeviceId: deviceId });
907
+ return {
908
+ authorizationHandle: required(value.authorizationHandle),
909
+ recipient: {
910
+ did: required(value.recipient.did),
911
+ deviceId: required(value.recipient.deviceId),
912
+ registryVersion: required(value.recipient.registryVersion)
913
+ },
914
+ expiresAt: required(value.expiresAt)
915
+ };
916
+ });
917
+ }
918
+ confirmAndSendRootKeyTransfer(authorizationHandle) {
919
+ return this.run(async (client) => {
920
+ const value = await client.confirmAndSendRootKeyTransfer({
921
+ authorizationHandle,
922
+ userPresenceConfirmed: true
923
+ });
924
+ return {
925
+ recipientDeviceId: required(value.recipientDeviceId),
926
+ acceptedAt: required(value.acceptedAt)
927
+ };
928
+ });
603
929
  }
604
930
  updateDisplayName(request) {
605
931
  return this.run(async (client) => identity(await client.updateDisplayName(request.displayName)));
@@ -621,12 +947,11 @@ var RustSdkAdapter = class {
621
947
  ...value.previousDid === void 0 ? {} : { previousDid: value.previousDid },
622
948
  currentDid: required(value.currentDid),
623
949
  phase: value.phase,
950
+ allowedActions: [...value.allowedActions ?? []],
624
951
  ...value.failureCode === void 0 ? {} : { failureCode: value.failureCode },
625
952
  retryable: boolean(value.retryable),
626
953
  localOrdinaryDataWillMigrate: boolean(value.impact.localOrdinaryDataWillMigrate),
627
- otherDevicesMustRejoin: boolean(value.impact.otherDevicesMustRejoin),
628
- unsupportedE2eeGroupCount: recoveryE2eeGroupCount(value.impact),
629
- unsupportedDidOnlyGroupCount: uint32(value.impact.unsupportedDidOnlyGroupCount)
954
+ otherDevicesMustRejoin: boolean(value.impact.otherDevicesMustRejoin)
630
955
  };
631
956
  }
632
957
  sendRecoveryOtp(request) {
@@ -646,21 +971,18 @@ var RustSdkAdapter = class {
646
971
  activateRecovery(request) {
647
972
  return this.run(async (client) => this.recoveryProgress(await client.activateHandleRecovery(request)));
648
973
  }
974
+ listPendingRecoveries() {
975
+ return this.run(async (client) => (await client.listPendingHandleRecoveryOperations()).map((value) => ({
976
+ operationId: required(value.operationId),
977
+ fullHandle: required(value.fullHandle)
978
+ })));
979
+ }
649
980
  getRecoveryStatus(request) {
650
981
  return this.run(async (client) => this.recoveryProgress(await client.getHandleRecoveryStatus(request)));
651
982
  }
652
983
  resumeRecovery(request) {
653
984
  return this.run(async (client) => this.recoveryProgress(await client.resumeHandleRecovery(request)));
654
985
  }
655
- issueRecoveryAttestation(request) {
656
- return this.run(async (client) => {
657
- const value = await client.issueHandleRecoveryAttestation(request);
658
- return {
659
- attestation: required(value.attestation),
660
- expiresAt: required(value.expiresAt)
661
- };
662
- });
663
- }
664
986
  discardRecovery(request) {
665
987
  return this.run(async (client) => {
666
988
  await client.discardHandleRecovery(request);
@@ -704,6 +1026,7 @@ var RustSdkAdapter = class {
704
1026
  });
705
1027
  const peers = [...new Set(value.items.flatMap((member) => member.did ?? member.handle ?? []))];
706
1028
  const profiles = peers.length === 0 ? [] : await client.hydrateDisplayProfiles({ peers });
1029
+ this.scheduleDisplayRefresh(client, peers);
707
1030
  const byPeer = /* @__PURE__ */ new Map();
708
1031
  for (const [index, profile] of profiles.entries()) {
709
1032
  const requested = peers[index];
@@ -728,41 +1051,6 @@ var RustSdkAdapter = class {
728
1051
  member
729
1052
  })));
730
1053
  }
731
- resumeGroupRebindRecovery() {
732
- return this.run(async (client) => {
733
- const value = await client.resumeGroupRebindRecovery(100);
734
- const journal = value;
735
- const statuses = /* @__PURE__ */ new Map();
736
- for (const item of journal.items ?? []) {
737
- const { groupDid: rawGroupDid, layer: rawLayer, phase: rawPhase } = item;
738
- if (typeof rawGroupDid !== "string" || typeof rawLayer !== "string" || typeof rawPhase !== "string" || typeof item.blocked !== "boolean") throw new TypeError("invalid group recovery item");
739
- const groupDid = required(rawGroupDid);
740
- const layer = required(rawLayer);
741
- const phase = required(rawPhase);
742
- if (layer !== "p4" && layer !== "p6") throw new TypeError("invalid group recovery item");
743
- if (phase === "complete") continue;
744
- const status = item.blocked || phase === "blocked" ? "blocked" : "pending";
745
- if (statuses.get(groupDid) !== "blocked") statuses.set(groupDid, status);
746
- }
747
- for (const group of journal.sendPausedGroups ?? []) {
748
- if (typeof group !== "string") throw new TypeError("invalid paused recovery group");
749
- const groupDid = required(group);
750
- if (!statuses.has(groupDid)) statuses.set(groupDid, "pending");
751
- }
752
- const items = [...statuses].map(([groupDid, status]) => ({
753
- groupDid,
754
- status
755
- }));
756
- const hasJournal = journal.items !== void 0 || journal.sendPausedGroups !== void 0;
757
- return {
758
- processed: uint32(value.processed),
759
- completed: uint32(value.completed),
760
- pending: hasJournal ? items.filter((item) => item.status === "pending").length : uint32(value.pending),
761
- blocked: hasJournal ? items.filter((item) => item.status === "blocked").length : uint32(value.blocked),
762
- items
763
- };
764
- });
765
- }
766
1054
  listConversations(request) {
767
1055
  return this.run(async (client) => {
768
1056
  const conversations = await client.listConversations(request);
@@ -884,21 +1172,12 @@ var RustSdkAdapter = class {
884
1172
  });
885
1173
  }
886
1174
  sendMail(request) {
887
- const attachments = request.attachments?.map((attachment) => ({
888
- fileName: attachment.fileName,
889
- contentType: attachment.contentType,
890
- bytes: Uint8Array.from(attachment.bytes)
891
- }));
892
1175
  return this.run(async (client) => {
893
- const input = {
1176
+ const value = await client.sendMail({
894
1177
  to: [...request.to],
895
1178
  ...request.cc === void 0 ? {} : { cc: [...request.cc] },
896
1179
  subject: request.subject,
897
1180
  bodyText: request.bodyText
898
- };
899
- const value = await client.sendMail({
900
- ...input,
901
- ...attachments === void 0 || attachments.length === 0 ? {} : { attachments }
902
1181
  });
903
1182
  if (!Array.isArray(value.warnings) || value.warnings.length > 100) fail();
904
1183
  const messageId = value.messageId === void 0 ? void 0 : mailToken(value.messageId, 2048);
@@ -909,25 +1188,19 @@ var RustSdkAdapter = class {
909
1188
  };
910
1189
  }, true);
911
1190
  }
912
- downloadMailAttachment(request) {
913
- return this.run(async (client) => {
914
- const value = await client.downloadMailAttachment({
915
- messageId: mailToken(request.messageId, 2048),
916
- attachmentIndex: uint32(request.attachmentIndex)
917
- });
918
- const sizeBytes = safeInteger(remoteString(value.sizeBytes, 20));
919
- if (!(value.bytes instanceof Uint8Array) || value.bytes.byteLength !== sizeBytes) fail();
920
- return {
921
- fileName: mailFileName(value.fileName),
922
- contentType: mailContentType(value.contentType),
923
- sizeBytes,
924
- bytes: Uint8Array.from(value.bytes)
925
- };
926
- });
927
- }
928
1191
  clearLocalData() {
929
1192
  return this.run((client) => client.clearLocalData());
930
1193
  }
1194
+ retireDefaultIdentityForRejoin() {
1195
+ return this.run((client) => {
1196
+ const retire = client.retireDefaultIdentityForRejoin;
1197
+ if (typeof retire !== "function") throw Object.assign(/* @__PURE__ */ new Error("device rejoin is unavailable in this IM Core build"), {
1198
+ name: "AwikiSdkError",
1199
+ code: "remote"
1200
+ });
1201
+ return retire.call(client);
1202
+ });
1203
+ }
931
1204
  dispose() {
932
1205
  this.disposal ??= this.client.then(async (client) => {
933
1206
  try {
@@ -951,4 +1224,4 @@ function downloadedAttachment(value) {
951
1224
  };
952
1225
  }
953
1226
  //#endregion
954
- export { downloadedAttachment as n, RustSdkAdapter as t };
1227
+ export { fencedMailRecoveryObservability as a, failedMailRecoveryObservability as i, RustSdkAdapter as n, successfulMailRecoveryObservability as o, downloadedAttachment as r, AwikiSdkError as t };