@witbitz/sdk 0.0.0-stage → 4.3.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/LICENSE +21 -0
- package/README.md +20 -2
- package/a2aCore.js +200 -0
- package/a2aShared.js +27 -0
- package/accountErase.js +223 -0
- package/accountIndexDoc.js +122 -0
- package/accountOwner.js +59 -0
- package/accountRecord.js +90 -0
- package/accountScope.js +114 -0
- package/accountSeal.js +42 -0
- package/accountStores.js +173 -0
- package/acctV2App.js +619 -0
- package/acctV2Check.js +29 -0
- package/acctV2Client.js +382 -0
- package/acctV2Keys.js +43 -0
- package/acctV2Legacy.js +14 -0
- package/acctV2Switch.js +80 -0
- package/acctV2UiCore.js +857 -0
- package/acctV2WebAuthn.js +61 -0
- package/acctV2Wire.js +59 -0
- package/address.js +42 -0
- package/attestedBox.js +30 -0
- package/attestedRooms.js +78 -0
- package/awsKey.js +98 -0
- package/backupRecord.js +106 -0
- package/backupVault.js +97 -0
- package/blocks.js +115 -0
- package/blocksPush.js +64 -0
- package/browseSeal.js +103 -0
- package/cbor.js +225 -0
- package/changePush.js +75 -0
- package/chatLock.js +149 -0
- package/chatLockSw.js +13 -0
- package/cloudDeviceBuilds.js +11 -0
- package/cloudDevicePins.js +33 -0
- package/cloudDeviceSeal.js +53 -0
- package/codeBrowse.js +224 -0
- package/codeCloud.js +652 -0
- package/codeCloudKeys.js +112 -0
- package/codeCommands.js +167 -0
- package/codeComputers.js +388 -0
- package/codeEgress.js +123 -0
- package/codeFilesRoutes.js +17 -0
- package/codeMkdir.js +8 -0
- package/codeModes.js +57 -0
- package/codeOrphanKeys.js +42 -0
- package/codeOutputs.js +141 -0
- package/codeRelay.js +505 -0
- package/codeSentinel.js +86 -0
- package/codeTransport.js +295 -0
- package/codeUndo.js +48 -0
- package/compress.js +24 -0
- package/config.js +11 -0
- package/connCatalog.js +164 -0
- package/connDisp.js +76 -0
- package/connOtherWays.js +74 -0
- package/connPending.js +16 -0
- package/connWrap.js +53 -0
- package/connectionEntry.js +89 -0
- package/connections.js +562 -0
- package/credits.js +30 -0
- package/csAttest.js +112 -0
- package/decrypt.html +384 -0
- package/deviceAttest.js +521 -0
- package/deviceCall.js +54 -0
- package/deviceKeyCore.js +41 -0
- package/deviceSeal.js +59 -0
- package/e2ee.js +323 -0
- package/eat.js +103 -0
- package/emailFork.js +275 -0
- package/emailSignIn.js +81 -0
- package/emptySpaces.js +111 -0
- package/encSource.js +55 -0
- package/enclaveAccept.js +214 -0
- package/enclaveClaim.js +241 -0
- package/enclaveRoute.js +102 -0
- package/enclaveSnapshotMerge.js +44 -0
- package/entrySig.js +165 -0
- package/env.js +73 -0
- package/eraseFile.js +58 -0
- package/followImage.js +86 -0
- package/healNames.js +45 -0
- package/idb.js +97 -0
- package/idbSeal.js +119 -0
- package/indexGone.js +12 -0
- package/invite.js +51 -0
- package/inviteEnroll.js +67 -0
- package/inviteSend.js +68 -0
- package/jobAgents.js +87 -0
- package/keptMerge.js +84 -0
- package/l1-worker-src.js +2 -0
- package/l1-worker.js +831 -0
- package/laneConfig.js +57 -0
- package/laneLinkCore.js +177 -0
- package/ledgerView.js +64 -0
- package/manifest.json +220 -0
- package/mcpRecommended.js +25 -0
- package/memberChange.js +123 -0
- package/mkseal.js +101 -0
- package/nativePush.js +153 -0
- package/nitroVerify.js +220 -0
- package/noble-p256.js +27 -0
- package/notice.js +116 -0
- package/notifKey.js +58 -0
- package/offlineBundle.js +62 -0
- package/ohttp.js +177 -0
- package/opencodeWire.js +282 -0
- package/oprf.js +70 -0
- package/ownAgentLink.js +96 -0
- package/ownerPolicy.js +117 -0
- package/package.json +254 -4
- package/pollVerdict.js +33 -0
- package/prefetchPoll.js +60 -0
- package/protectedLocal.js +410 -0
- package/pushCore.js +42 -0
- package/recovery.js +107 -0
- package/regions.js +42 -0
- package/removedMessage.js +11 -0
- package/renameRefusal.js +9 -0
- package/replyQuote.js +34 -0
- package/reqEnvelope.js +126 -0
- package/roomDefaultPrefs.js +76 -0
- package/roomDelete.js +109 -0
- package/roomName.js +177 -0
- package/roomPass.js +256 -0
- package/roomRoster.js +289 -0
- package/roomSettings.js +61 -0
- package/roomState.js +58 -0
- package/roomStreamClient.js +115 -0
- package/rosterCount.js +49 -0
- package/rosterHash.js +13 -0
- package/rowSchema.js +113 -0
- package/safeMedia.js +116 -0
- package/safeMediaPins.js +17 -0
- package/schedulesDoc.js +78 -0
- package/sdkA2A.js +404 -0
- package/sdkAccount.js +470 -0
- package/sdkAccountDoc.js +81 -0
- package/sdkAccountSections.js +223 -0
- package/sdkAgui.js +141 -0
- package/sdkAttest.js +34 -0
- package/sdkBackup.js +480 -0
- package/sdkBackupV2.js +630 -0
- package/sdkBrowserPrivate.js +28 -0
- package/sdkBuilds.js +208 -0
- package/sdkCloudDevice.js +215 -0
- package/sdkComputers.js +480 -0
- package/sdkDictation.js +142 -0
- package/sdkErase.js +283 -0
- package/sdkExports.js +69 -0
- package/sdkInvitations.js +34 -0
- package/sdkKeptAgent.js +188 -0
- package/sdkLaneLink.js +205 -0
- package/sdkPlan.js +94 -0
- package/sdkProtect.js +228 -0
- package/sdkRedact.js +36 -0
- package/sdkRekey.js +307 -0
- package/sdkReport.js +68 -0
- package/sdkSafeMedia.js +255 -0
- package/sdkSchedules.js +39 -0
- package/sdkSpeech.js +54 -0
- package/sdkTurn.js +117 -0
- package/sdkVault.js +124 -0
- package/sealShare.js +18 -0
- package/sealedNames.js +64 -0
- package/sealedReceipt.js +17 -0
- package/sentinelRelease.js +154 -0
- package/shamir.js +85 -0
- package/sharedViews.js +38 -0
- package/sheetChrome.js +450 -0
- package/siri.js +171 -0
- package/spaceClient.js +1418 -0
- package/spaceConfig.js +81 -0
- package/spaceEmailGate.js +813 -0
- package/spaceExport.js +125 -0
- package/spaceFork.js +216 -0
- package/spaceLock.js +358 -0
- package/spacePasskey.js +180 -0
- package/speechOut.js +100 -0
- package/splitKeyClient.js +90 -0
- package/store.js +587 -0
- package/streamHint.js +36 -0
- package/sttCloud.js +220 -0
- package/sttWorklet.js +38 -0
- package/sw-notif-core.js +538 -0
- package/tempList.js +48 -0
- package/tinfoilVerifier.js +78 -0
- package/toolBooks.js +31 -0
- package/toolRules.js +52 -0
- package/turnCerts.js +254 -0
- package/turnFeed.js +58 -0
- package/turnVerdict.js +36 -0
- package/usageReceipts.js +176 -0
- package/usageSummary.js +90 -0
- package/util.js +181 -0
- package/vault-core.js +1958 -0
- package/vault-kit.mjs +354 -0
- package/vault-screens.js +263 -0
- package/vaultAtRest.js +177 -0
- package/vaultCoreLock.js +111 -0
- package/vaultCorePush.js +140 -0
- package/vaultDeviceKey.js +95 -0
- package/vaultEnclaveHandoff.js +114 -0
- package/vaultKeep.js +281 -0
- package/vaultSealedStore.js +77 -0
- package/vaultWorkerHost.js +98 -0
- package/vcWorker.js +34 -0
- package/voiceAttest.js +50 -0
- package/voiceCert.js +51 -0
- package/witbitz-admin.d.ts +135 -0
- package/witbitz-admin.js +529 -0
- package/witbitz-admin.mjs +1459 -0
- package/witbitz-sdk.d.ts +1106 -0
- package/witbitz-sdk.js +3835 -0
- package/workerClient.js +16 -0
- package/workerLiveness.js +21 -0
- package/x509.js +218 -0
package/package.json
CHANGED
|
@@ -1,6 +1,256 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@witbitz/sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "4.3.0",
|
|
4
|
+
"description": "The Witbitz SDK: Spaces — end-to-end encrypted rooms with an AI assistant — in your own app. The same bytes as https://witbitz.chat/sdk/4.3.0/",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./witbitz-sdk.js",
|
|
7
|
+
"types": "./witbitz-sdk.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./witbitz-sdk.d.ts",
|
|
11
|
+
"default": "./witbitz-sdk.js"
|
|
12
|
+
},
|
|
13
|
+
"./admin": {
|
|
14
|
+
"types": "./witbitz-admin.d.ts",
|
|
15
|
+
"default": "./witbitz-admin.mjs"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json",
|
|
18
|
+
"./*": "./*"
|
|
19
|
+
},
|
|
20
|
+
"bin": {
|
|
21
|
+
"witbitz-vault-kit": "vault-kit.mjs"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"a2aCore.js",
|
|
25
|
+
"a2aShared.js",
|
|
26
|
+
"accountErase.js",
|
|
27
|
+
"accountIndexDoc.js",
|
|
28
|
+
"accountOwner.js",
|
|
29
|
+
"accountRecord.js",
|
|
30
|
+
"accountScope.js",
|
|
31
|
+
"accountSeal.js",
|
|
32
|
+
"accountStores.js",
|
|
33
|
+
"acctV2App.js",
|
|
34
|
+
"acctV2Check.js",
|
|
35
|
+
"acctV2Client.js",
|
|
36
|
+
"acctV2Keys.js",
|
|
37
|
+
"acctV2Legacy.js",
|
|
38
|
+
"acctV2Switch.js",
|
|
39
|
+
"acctV2UiCore.js",
|
|
40
|
+
"acctV2WebAuthn.js",
|
|
41
|
+
"acctV2Wire.js",
|
|
42
|
+
"address.js",
|
|
43
|
+
"attestedBox.js",
|
|
44
|
+
"attestedRooms.js",
|
|
45
|
+
"awsKey.js",
|
|
46
|
+
"backupRecord.js",
|
|
47
|
+
"backupVault.js",
|
|
48
|
+
"blocks.js",
|
|
49
|
+
"blocksPush.js",
|
|
50
|
+
"browseSeal.js",
|
|
51
|
+
"cbor.js",
|
|
52
|
+
"changePush.js",
|
|
53
|
+
"chatLock.js",
|
|
54
|
+
"chatLockSw.js",
|
|
55
|
+
"cloudDeviceBuilds.js",
|
|
56
|
+
"cloudDevicePins.js",
|
|
57
|
+
"cloudDeviceSeal.js",
|
|
58
|
+
"codeBrowse.js",
|
|
59
|
+
"codeCloud.js",
|
|
60
|
+
"codeCloudKeys.js",
|
|
61
|
+
"codeCommands.js",
|
|
62
|
+
"codeComputers.js",
|
|
63
|
+
"codeEgress.js",
|
|
64
|
+
"codeFilesRoutes.js",
|
|
65
|
+
"codeMkdir.js",
|
|
66
|
+
"codeModes.js",
|
|
67
|
+
"codeOrphanKeys.js",
|
|
68
|
+
"codeOutputs.js",
|
|
69
|
+
"codeRelay.js",
|
|
70
|
+
"codeSentinel.js",
|
|
71
|
+
"codeTransport.js",
|
|
72
|
+
"codeUndo.js",
|
|
73
|
+
"compress.js",
|
|
74
|
+
"config.js",
|
|
75
|
+
"connCatalog.js",
|
|
76
|
+
"connDisp.js",
|
|
77
|
+
"connOtherWays.js",
|
|
78
|
+
"connPending.js",
|
|
79
|
+
"connWrap.js",
|
|
80
|
+
"connectionEntry.js",
|
|
81
|
+
"connections.js",
|
|
82
|
+
"credits.js",
|
|
83
|
+
"csAttest.js",
|
|
84
|
+
"decrypt.html",
|
|
85
|
+
"deviceAttest.js",
|
|
86
|
+
"deviceCall.js",
|
|
87
|
+
"deviceKeyCore.js",
|
|
88
|
+
"deviceSeal.js",
|
|
89
|
+
"e2ee.js",
|
|
90
|
+
"eat.js",
|
|
91
|
+
"emailFork.js",
|
|
92
|
+
"emailSignIn.js",
|
|
93
|
+
"emptySpaces.js",
|
|
94
|
+
"encSource.js",
|
|
95
|
+
"enclaveAccept.js",
|
|
96
|
+
"enclaveClaim.js",
|
|
97
|
+
"enclaveRoute.js",
|
|
98
|
+
"enclaveSnapshotMerge.js",
|
|
99
|
+
"entrySig.js",
|
|
100
|
+
"env.js",
|
|
101
|
+
"eraseFile.js",
|
|
102
|
+
"followImage.js",
|
|
103
|
+
"healNames.js",
|
|
104
|
+
"idb.js",
|
|
105
|
+
"idbSeal.js",
|
|
106
|
+
"indexGone.js",
|
|
107
|
+
"invite.js",
|
|
108
|
+
"inviteEnroll.js",
|
|
109
|
+
"inviteSend.js",
|
|
110
|
+
"jobAgents.js",
|
|
111
|
+
"keptMerge.js",
|
|
112
|
+
"l1-worker-src.js",
|
|
113
|
+
"l1-worker.js",
|
|
114
|
+
"laneConfig.js",
|
|
115
|
+
"laneLinkCore.js",
|
|
116
|
+
"ledgerView.js",
|
|
117
|
+
"manifest.json",
|
|
118
|
+
"mcpRecommended.js",
|
|
119
|
+
"memberChange.js",
|
|
120
|
+
"mkseal.js",
|
|
121
|
+
"nativePush.js",
|
|
122
|
+
"nitroVerify.js",
|
|
123
|
+
"noble-p256.js",
|
|
124
|
+
"notice.js",
|
|
125
|
+
"notifKey.js",
|
|
126
|
+
"offlineBundle.js",
|
|
127
|
+
"ohttp.js",
|
|
128
|
+
"opencodeWire.js",
|
|
129
|
+
"oprf.js",
|
|
130
|
+
"ownAgentLink.js",
|
|
131
|
+
"ownerPolicy.js",
|
|
132
|
+
"pollVerdict.js",
|
|
133
|
+
"prefetchPoll.js",
|
|
134
|
+
"protectedLocal.js",
|
|
135
|
+
"pushCore.js",
|
|
136
|
+
"recovery.js",
|
|
137
|
+
"regions.js",
|
|
138
|
+
"removedMessage.js",
|
|
139
|
+
"renameRefusal.js",
|
|
140
|
+
"replyQuote.js",
|
|
141
|
+
"reqEnvelope.js",
|
|
142
|
+
"roomDefaultPrefs.js",
|
|
143
|
+
"roomDelete.js",
|
|
144
|
+
"roomName.js",
|
|
145
|
+
"roomPass.js",
|
|
146
|
+
"roomRoster.js",
|
|
147
|
+
"roomSettings.js",
|
|
148
|
+
"roomState.js",
|
|
149
|
+
"roomStreamClient.js",
|
|
150
|
+
"rosterCount.js",
|
|
151
|
+
"rosterHash.js",
|
|
152
|
+
"rowSchema.js",
|
|
153
|
+
"safeMedia.js",
|
|
154
|
+
"safeMediaPins.js",
|
|
155
|
+
"schedulesDoc.js",
|
|
156
|
+
"sdkA2A.js",
|
|
157
|
+
"sdkAccount.js",
|
|
158
|
+
"sdkAccountDoc.js",
|
|
159
|
+
"sdkAccountSections.js",
|
|
160
|
+
"sdkAgui.js",
|
|
161
|
+
"sdkAttest.js",
|
|
162
|
+
"sdkBackup.js",
|
|
163
|
+
"sdkBackupV2.js",
|
|
164
|
+
"sdkBrowserPrivate.js",
|
|
165
|
+
"sdkBuilds.js",
|
|
166
|
+
"sdkCloudDevice.js",
|
|
167
|
+
"sdkComputers.js",
|
|
168
|
+
"sdkDictation.js",
|
|
169
|
+
"sdkErase.js",
|
|
170
|
+
"sdkExports.js",
|
|
171
|
+
"sdkInvitations.js",
|
|
172
|
+
"sdkKeptAgent.js",
|
|
173
|
+
"sdkLaneLink.js",
|
|
174
|
+
"sdkPlan.js",
|
|
175
|
+
"sdkProtect.js",
|
|
176
|
+
"sdkRedact.js",
|
|
177
|
+
"sdkRekey.js",
|
|
178
|
+
"sdkReport.js",
|
|
179
|
+
"sdkSafeMedia.js",
|
|
180
|
+
"sdkSchedules.js",
|
|
181
|
+
"sdkSpeech.js",
|
|
182
|
+
"sdkTurn.js",
|
|
183
|
+
"sdkVault.js",
|
|
184
|
+
"sealShare.js",
|
|
185
|
+
"sealedNames.js",
|
|
186
|
+
"sealedReceipt.js",
|
|
187
|
+
"sentinelRelease.js",
|
|
188
|
+
"shamir.js",
|
|
189
|
+
"sharedViews.js",
|
|
190
|
+
"sheetChrome.js",
|
|
191
|
+
"siri.js",
|
|
192
|
+
"spaceClient.js",
|
|
193
|
+
"spaceConfig.js",
|
|
194
|
+
"spaceEmailGate.js",
|
|
195
|
+
"spaceExport.js",
|
|
196
|
+
"spaceFork.js",
|
|
197
|
+
"spaceLock.js",
|
|
198
|
+
"spacePasskey.js",
|
|
199
|
+
"speechOut.js",
|
|
200
|
+
"splitKeyClient.js",
|
|
201
|
+
"store.js",
|
|
202
|
+
"streamHint.js",
|
|
203
|
+
"sttCloud.js",
|
|
204
|
+
"sttWorklet.js",
|
|
205
|
+
"sw-notif-core.js",
|
|
206
|
+
"tempList.js",
|
|
207
|
+
"tinfoilVerifier.js",
|
|
208
|
+
"toolBooks.js",
|
|
209
|
+
"toolRules.js",
|
|
210
|
+
"turnCerts.js",
|
|
211
|
+
"turnFeed.js",
|
|
212
|
+
"turnVerdict.js",
|
|
213
|
+
"usageReceipts.js",
|
|
214
|
+
"usageSummary.js",
|
|
215
|
+
"util.js",
|
|
216
|
+
"vault-core.js",
|
|
217
|
+
"vault-kit.mjs",
|
|
218
|
+
"vault-screens.js",
|
|
219
|
+
"vaultAtRest.js",
|
|
220
|
+
"vaultCoreLock.js",
|
|
221
|
+
"vaultCorePush.js",
|
|
222
|
+
"vaultDeviceKey.js",
|
|
223
|
+
"vaultEnclaveHandoff.js",
|
|
224
|
+
"vaultKeep.js",
|
|
225
|
+
"vaultSealedStore.js",
|
|
226
|
+
"vaultWorkerHost.js",
|
|
227
|
+
"vcWorker.js",
|
|
228
|
+
"voiceAttest.js",
|
|
229
|
+
"voiceCert.js",
|
|
230
|
+
"witbitz-admin.d.ts",
|
|
231
|
+
"witbitz-admin.js",
|
|
232
|
+
"witbitz-admin.mjs",
|
|
233
|
+
"witbitz-sdk.d.ts",
|
|
234
|
+
"witbitz-sdk.js",
|
|
235
|
+
"workerClient.js",
|
|
236
|
+
"workerLiveness.js",
|
|
237
|
+
"x509.js"
|
|
238
|
+
],
|
|
239
|
+
"license": "MIT",
|
|
240
|
+
"homepage": "https://witbitz.chat/docs/sdk",
|
|
241
|
+
"repository": {
|
|
242
|
+
"type": "git",
|
|
243
|
+
"url": "git+https://github.com/witbitzchat/witbitz-sdk.git"
|
|
244
|
+
},
|
|
245
|
+
"keywords": [
|
|
246
|
+
"witbitz",
|
|
247
|
+
"spaces",
|
|
248
|
+
"end-to-end encryption",
|
|
249
|
+
"ai",
|
|
250
|
+
"chat",
|
|
251
|
+
"sdk"
|
|
252
|
+
],
|
|
253
|
+
"engines": {
|
|
254
|
+
"node": ">=18"
|
|
255
|
+
}
|
|
256
|
+
}
|
package/pollVerdict.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// pollVerdict.js — what a poll answer MEANS, decided one way for the Spaces app and the SDK (docs/sdk-convergence.md,
|
|
2
|
+
// phase 4a). Each used to classify refusals itself, and they drifted: the SDK read a refusal inside a 200 (a host front
|
|
3
|
+
// that flattened every status) as a refusal, the app as an empty room. Each side still decides what to SHOW for a verdict.
|
|
4
|
+
// ok · cannot_open (422 — this key opens nothing; code 'no_key' when nothing here holds a key) · no_key (401, the
|
|
5
|
+
// worker's own refusal of a keyless read) · stale_key (the enclave cannot open the key or the envelope we sealed to it) ·
|
|
6
|
+
// verified_client · gated (an email gate) · warming (the enclave is starting) · unavailable (not judged just now: retry) ·
|
|
7
|
+
// not_found · refused (anything else) ·
|
|
8
|
+
// no_answer
|
|
9
|
+
export function pollVerdict (r) {
|
|
10
|
+
if (!r) return { kind: 'no_answer', code: 'no_answer' }
|
|
11
|
+
if (r.status === 200 && !r.error) return { kind: 'ok' }
|
|
12
|
+
const code = r.error ? String(r.error) : r.status === 422 ? 'undecodable' : 'http_' + r.status
|
|
13
|
+
const v = (kind) => ({ kind, code, ...(r.reason ? { reason: r.reason } : {}) })
|
|
14
|
+
if (r.status === 422) return v('cannot_open')
|
|
15
|
+
if (r.error === 'no_key') return v('no_key')
|
|
16
|
+
// bad_envelope: the request ENVELOPE (reqEnvelope) was sealed to an enclave since replaced — the same stale key, one layer out
|
|
17
|
+
// (2026-11-09: after a turn cutover the app read 400 bad_envelope once a second and never re-attested until relaunched).
|
|
18
|
+
if (r.error === 'bad_mkseal' || r.error === 'bad_envelope') return v('stale_key')
|
|
19
|
+
if (r.error === 'envelope_stale') return { kind: 'refused', code: 'envelope_stale', reason: 'This device’s clock is more than a minute off, so the confidential Space refused the request — set the clock to the right time (automatic), then try again.' } // the device's clock (pass 7, T#2; the same words as turnVerdict CLOCK_REASON)
|
|
20
|
+
if (r.error === 'no_verified_client') return v('verified_client')
|
|
21
|
+
// ★ ONLY THE EMAIL GATE'S REFUSAL IS "gated" (sync sweep, 2026-10-10). Every 403 used to read as gated, and the app then
|
|
22
|
+
// marked the room verified FOR GOOD — but a read is also refused 403 for an enclave build the room has not accepted
|
|
23
|
+
// (enclave_not_accepted) or an owner policy that does not verify (policy_invalid): an open room then asked for a
|
|
24
|
+
// sign-in for ever. The gate answers not_authorized (no or wrong sign-in, revoked) or gate_unreadable.
|
|
25
|
+
if (r.status === 403 && (r.error === 'not_authorized' || r.error === 'gate_unreadable')) return v('gated')
|
|
26
|
+
if (r.error === 'enclave_warming' || r.warming) return v('warming')
|
|
27
|
+
// NOT JUDGED (sync sweep 11-11): the sign-in's verifier, the room's tier or its store could not be checked just now — a retryable 503,
|
|
28
|
+
// never a refusal (no banner, no slowed poll): ask again
|
|
29
|
+
if (r.status === 503 && (r.error === 'verifier_unavailable' || r.error === 'tier_unknown' || r.error === 'store_unavailable')) return v('unavailable')
|
|
30
|
+
if (r.error === 'deleting') return v('unavailable') // its creator's delete is finishing (agent/roomDeleting.mjs): the next read hears 410, or the room again
|
|
31
|
+
if (r.status === 404 && r.error === 'not_found') return v('not_found')
|
|
32
|
+
return v('refused')
|
|
33
|
+
}
|
package/prefetchPoll.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// spaces/public/prefetchPoll.js — the rules for answering a room's first poll from what the service worker PREFETCHED
|
|
2
|
+
// when the push arrived (the owner, 2026-10-02: a tapped notification took over a second to show its message — the
|
|
3
|
+
// room was drawn from cache, THEN the server was asked). Pure, so the L1 worker's use of it is testable here.
|
|
4
|
+
// • the worker records the room's position after every successful poll: cnt:<room> = { etag, count }
|
|
5
|
+
// • the push handler asks pollsealed since that count and stores prefetch:<room> = { at, sinceCount, r }
|
|
6
|
+
// • the first poll since then, asking from the SAME count, is answered from `r` (decoded with mk, the same decoder
|
|
7
|
+
// the network path uses) — once; the network is still asked right after, so nothing can go stale.
|
|
8
|
+
// • NO POSITION (2026-10-20 — the owner's phone, protected storage: every push said "no position known", so a tapped message
|
|
9
|
+
// waited 9 s for the network): the push handler asks the room's COUNT, then the last PREFETCH_TAIL entries, and keeps
|
|
10
|
+
// them as a TAIL under a hash of the room (prefetchHashKey — nothing kept under the room's name). The first poll
|
|
11
|
+
// takes the part from ITS position on, when the tail reaches back that far.
|
|
12
|
+
export const PREFETCH_MAX_AGE_MS = 15 * 60 * 1000
|
|
13
|
+
export const PREFETCH_TAIL = 30
|
|
14
|
+
|
|
15
|
+
/** Where a TAIL prefetch is kept: a hash of the room, the same in the service worker (sw-notif-core.js wbxPrefetchHashKey). */
|
|
16
|
+
export async function prefetchHashKey (room) {
|
|
17
|
+
const d = new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode('wb-prefetch\n' + String(room || ''))))
|
|
18
|
+
return 'prefetch:h:' + Array.from(d.slice(0, 16), (b) => b.toString(16).padStart(2, '0')).join('')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Is this prefetched answer usable for a poll asking from `sinceCount`? A reason string when not. */
|
|
22
|
+
export function prefetchUsable(pf, sinceCount, now = Date.now()) {
|
|
23
|
+
if (!pf || typeof pf !== 'object' || !pf.r || typeof pf.r !== 'object') return 'none'
|
|
24
|
+
if (!Number.isFinite(pf.at) || now - pf.at > PREFETCH_MAX_AGE_MS) return 'stale'
|
|
25
|
+
if (pf.tail) { // a tail covers any position from where it starts to the count it saw
|
|
26
|
+
if (!Number.isInteger(pf.sinceCount) || pf.sinceCount > (sinceCount | 0) || !Number.isInteger(pf.r.count) || (sinceCount | 0) > pf.r.count) return 'position moved'
|
|
27
|
+
} else if (!Number.isInteger(pf.sinceCount) || pf.sinceCount !== (sinceCount | 0)) return 'position moved'
|
|
28
|
+
if (!pf.r.changed || typeof pf.r.sealed !== 'string') return 'nothing new in it'
|
|
29
|
+
return ''
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The position record to keep after a poll answered: null when the answer carries none. */
|
|
33
|
+
export function positionOf(result) {
|
|
34
|
+
if (!result || result.status !== 200 || !Number.isInteger(result.version)) return null
|
|
35
|
+
return { etag: typeof result.etag === 'string' ? result.etag : '', count: result.version, at: Date.now() }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** What the push handler stores — or null when the server's answer has nothing worth keeping (bounded in size). */
|
|
39
|
+
export function prefetchRecord(j, sinceCount, { maxBytes = 400000, now = Date.now() } = {}) {
|
|
40
|
+
if (!j || !j.changed || typeof j.sealed !== 'string' || j.sealed.length > maxBytes || !Number.isInteger(sinceCount)) return null
|
|
41
|
+
const { notif, ...r } = j // the preview envelope is the notification's business, not the ledger's
|
|
42
|
+
return { at: now, sinceCount, r }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The stored answer as the client's decoder expects it: the service worker kept the response BODY, and the client's own
|
|
46
|
+
* fetch path adds `status` from the response — without it `decodeSealed` sees "not 200" and hands the body back undecoded
|
|
47
|
+
* (the owner's trail, 2026-10-02 19:24: "prefetch: decoded to status undefined"). */
|
|
48
|
+
export function prefetchAnswer(pf, sinceCount) {
|
|
49
|
+
let r0 = pf && pf.r && typeof pf.r === 'object' ? pf.r : null
|
|
50
|
+
if (!r0) return null
|
|
51
|
+
if (pf.tail && Number.isInteger(sinceCount) && sinceCount > pf.sinceCount) { // a TAIL: only the entries after the page's position
|
|
52
|
+
let sl = null; try { sl = JSON.parse(r0.sealed) } catch { return null }
|
|
53
|
+
if (!sl || !Array.isArray(sl.boxes) || sl.from !== pf.sinceCount || sinceCount > sl.from + sl.boxes.length) return null
|
|
54
|
+
r0 = { ...r0, sealed: JSON.stringify({ ...sl, boxes: sl.boxes.slice(sinceCount - sl.from), from: sinceCount }), from: sinceCount }
|
|
55
|
+
}
|
|
56
|
+
// A turn's progress is LIVE — never replayed from storage (2026-10-03: a push mid-turn stored "working", and the first
|
|
57
|
+
// poll on return showed "Working on it… 104s" under the finished reply). The entries are what a stored answer is for.
|
|
58
|
+
const { partialStatus, partial, partialSeq, ...r } = r0
|
|
59
|
+
return Number.isInteger(r.status) ? r : { status: 200, ...r }
|
|
60
|
+
}
|