@tinycloud/sdk-core 3.1.0-beta.1 → 3.1.0-beta.11
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/dist/delegations/index.cjs +35 -9
- package/dist/delegations/index.cjs.map +1 -1
- package/dist/delegations/index.d.cts +2 -2
- package/dist/delegations/index.d.ts +2 -2
- package/dist/delegations/index.js +33 -7
- package/dist/delegations/index.js.map +1 -1
- package/dist/index.cjs +464 -358
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -9
- package/dist/index.d.ts +42 -9
- package/dist/index.js +300 -186
- package/dist/index.js.map +1 -1
- package/dist/policy/index.cjs +36 -16
- package/dist/policy/index.cjs.map +1 -1
- package/dist/policy/index.js +36 -16
- package/dist/policy/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/{recipient-types.schema-D9AI8tjN.d.cts → recipient-types.schema-_JkBDZB6.d.cts} +2 -2
- package/dist/{recipient-types.schema-D9AI8tjN.d.ts → recipient-types.schema-_JkBDZB6.d.ts} +2 -2
package/dist/index.cjs
CHANGED
|
@@ -43,6 +43,7 @@ __export(index_exports, {
|
|
|
43
43
|
ACCOUNT_MANIFEST_PERMISSIONS: () => import_bootstrap4.ACCOUNT_MANIFEST_PERMISSIONS,
|
|
44
44
|
ACCOUNT_REGISTRY_PATH: () => ACCOUNT_REGISTRY_PATH,
|
|
45
45
|
ACCOUNT_REGISTRY_SPACE: () => ACCOUNT_REGISTRY_SPACE,
|
|
46
|
+
AGENTS_SPACE: () => import_bootstrap4.AGENTS_SPACE,
|
|
46
47
|
ATTESTED_ENFORCER_BINDING_V2_SCHEMA: () => ATTESTED_ENFORCER_BINDING_V2_SCHEMA,
|
|
47
48
|
AccountService: () => AccountService,
|
|
48
49
|
AutoApproveSpaceCreationHandler: () => AutoApproveSpaceCreationHandler,
|
|
@@ -73,13 +74,13 @@ __export(index_exports, {
|
|
|
73
74
|
ClientSessionSchema: () => ClientSessionSchema,
|
|
74
75
|
CloudLocationResolutionError: () => CloudLocationResolutionError,
|
|
75
76
|
CredentialError: () => CredentialError,
|
|
76
|
-
DECRYPT_ACTION: () =>
|
|
77
|
-
DECRYPT_FACT_TYPE: () =>
|
|
78
|
-
DECRYPT_RESULT_TYPE: () =>
|
|
77
|
+
DECRYPT_ACTION: () => import_sdk_services9.DECRYPT_ACTION,
|
|
78
|
+
DECRYPT_FACT_TYPE: () => import_sdk_services9.DECRYPT_FACT_TYPE,
|
|
79
|
+
DECRYPT_RESULT_TYPE: () => import_sdk_services9.DECRYPT_RESULT_TYPE,
|
|
79
80
|
DEFAULT_DEFAULTS: () => DEFAULT_DEFAULTS,
|
|
80
|
-
DEFAULT_ENCRYPTION_ALG: () =>
|
|
81
|
+
DEFAULT_ENCRYPTION_ALG: () => import_sdk_services9.DEFAULT_ENCRYPTION_ALG,
|
|
81
82
|
DEFAULT_EXPIRY: () => DEFAULT_EXPIRY,
|
|
82
|
-
DEFAULT_KEY_VERSION: () =>
|
|
83
|
+
DEFAULT_KEY_VERSION: () => import_sdk_services9.DEFAULT_KEY_VERSION,
|
|
83
84
|
DEFAULT_KNOWLEDGE_ROOT: () => DEFAULT_KNOWLEDGE_ROOT,
|
|
84
85
|
DEFAULT_LOCAL_NODE_PIN_STORAGE_KEY: () => DEFAULT_LOCAL_NODE_PIN_STORAGE_KEY,
|
|
85
86
|
DEFAULT_LOCAL_NODE_URL: () => DEFAULT_LOCAL_NODE_URL,
|
|
@@ -90,36 +91,36 @@ __export(index_exports, {
|
|
|
90
91
|
DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL: () => DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL,
|
|
91
92
|
DELIVERY_ADMISSION_DOMAIN: () => DELIVERY_ADMISSION_DOMAIN,
|
|
92
93
|
DUCKDB: () => import_bootstrap4.DUCKDB,
|
|
93
|
-
DataVaultService: () =>
|
|
94
|
-
DatabaseHandle: () =>
|
|
95
|
-
DecryptTransportResponseError: () =>
|
|
94
|
+
DataVaultService: () => import_sdk_services9.DataVaultService,
|
|
95
|
+
DatabaseHandle: () => import_sdk_services9.DatabaseHandle,
|
|
96
|
+
DecryptTransportResponseError: () => import_sdk_services9.DecryptTransportResponseError,
|
|
96
97
|
DelegationErrorCodes: () => DelegationErrorCodes,
|
|
97
98
|
DelegationManager: () => DelegationManager,
|
|
98
|
-
DuckDbAction: () =>
|
|
99
|
-
DuckDbDatabaseHandle: () =>
|
|
100
|
-
DuckDbService: () =>
|
|
99
|
+
DuckDbAction: () => import_sdk_services9.DuckDbAction,
|
|
100
|
+
DuckDbDatabaseHandle: () => import_sdk_services9.DuckDbDatabaseHandle,
|
|
101
|
+
DuckDbService: () => import_sdk_services9.DuckDbService,
|
|
101
102
|
ED25519_JCS_SIGNATURE_SUITE: () => ED25519_JCS_SIGNATURE_SUITE,
|
|
102
103
|
EIP191_JCS_SIGNATURE_SUITE: () => EIP191_JCS_SIGNATURE_SUITE,
|
|
103
104
|
EMAIL_CREDENTIAL_MAX_AGE_SECONDS: () => EMAIL_CREDENTIAL_MAX_AGE_SECONDS,
|
|
104
105
|
EMAIL_DOMAIN_CREDENTIAL_MAX_AGE_SECONDS: () => EMAIL_DOMAIN_CREDENTIAL_MAX_AGE_SECONDS,
|
|
105
106
|
ENCRYPTION: () => import_bootstrap4.ENCRYPTION,
|
|
106
107
|
ENCRYPTION_MANIFEST_SPACE: () => ENCRYPTION_MANIFEST_SPACE,
|
|
107
|
-
ENCRYPTION_NETWORK_URN_PREFIX: () =>
|
|
108
|
+
ENCRYPTION_NETWORK_URN_PREFIX: () => import_sdk_services9.ENCRYPTION_NETWORK_URN_PREFIX,
|
|
108
109
|
ENCRYPTION_PERMISSION_SERVICE: () => ENCRYPTION_PERMISSION_SERVICE,
|
|
109
|
-
ENCRYPTION_SERVICE: () =>
|
|
110
|
-
ENCRYPTION_SERVICE_SHORT: () =>
|
|
111
|
-
ENVELOPE_VERSION: () =>
|
|
110
|
+
ENCRYPTION_SERVICE: () => import_sdk_services9.ENCRYPTION_SERVICE,
|
|
111
|
+
ENCRYPTION_SERVICE_SHORT: () => import_sdk_services9.ENCRYPTION_SERVICE_SHORT,
|
|
112
|
+
ENVELOPE_VERSION: () => import_sdk_services9.ENVELOPE_VERSION,
|
|
112
113
|
EXPIRY: () => EXPIRY,
|
|
113
|
-
EncryptionService: () =>
|
|
114
|
+
EncryptionService: () => import_sdk_services9.EncryptionService,
|
|
114
115
|
EnsDataSchema: () => EnsDataSchema,
|
|
115
|
-
ErrorCodes: () =>
|
|
116
|
+
ErrorCodes: () => import_sdk_services9.ErrorCodes,
|
|
116
117
|
HOLDER_BINDING_DOMAIN: () => HOLDER_BINDING_DOMAIN,
|
|
117
118
|
HOLDER_KEY_BINDING_PRESENTATION_SCHEMA: () => HOLDER_KEY_BINDING_PRESENTATION_SCHEMA,
|
|
118
119
|
HOOKS: () => import_bootstrap4.HOOKS,
|
|
119
|
-
HooksService: () =>
|
|
120
|
+
HooksService: () => import_sdk_services9.HooksService,
|
|
120
121
|
IdentityParseError: () => IdentityParseError,
|
|
121
122
|
KV: () => import_bootstrap4.KV,
|
|
122
|
-
KVService: () =>
|
|
123
|
+
KVService: () => import_sdk_services9.KVService,
|
|
123
124
|
LAST_V2_CREATE_AT: () => LAST_V2_CREATE_AT,
|
|
124
125
|
LAST_V2_READ_AT: () => LAST_V2_READ_AT,
|
|
125
126
|
LISTEN_SQL_STATEMENT_CATALOG: () => LISTEN_SQL_STATEMENT_CATALOG,
|
|
@@ -138,8 +139,8 @@ __export(index_exports, {
|
|
|
138
139
|
MemorySenderShareRecordStorage: () => MemorySenderShareRecordStorage,
|
|
139
140
|
MemoryShareCache: () => MemoryShareCache,
|
|
140
141
|
NATIVE_PROJECTION_V1_DOMAIN: () => NATIVE_PROJECTION_V1_DOMAIN,
|
|
141
|
-
NETWORK_NAME_PATTERN: () =>
|
|
142
|
-
NetworkIdError: () =>
|
|
142
|
+
NETWORK_NAME_PATTERN: () => import_sdk_services9.NETWORK_NAME_PATTERN,
|
|
143
|
+
NetworkIdError: () => import_sdk_services9.NetworkIdError,
|
|
143
144
|
OPENKEY_ACTION_ID_SEPARATOR: () => OPENKEY_ACTION_ID_SEPARATOR,
|
|
144
145
|
OWNER_NODE_BINDING_TIMEOUT_MS: () => OWNER_NODE_BINDING_TIMEOUT_MS,
|
|
145
146
|
OpenKeyManageKeyError: () => OpenKeyManageKeyError,
|
|
@@ -166,7 +167,7 @@ __export(index_exports, {
|
|
|
166
167
|
POLICY_V2_SCHEMA: () => POLICY_V2_SCHEMA,
|
|
167
168
|
PORTABLE_DELEGATION_SCHEMA: () => PORTABLE_DELEGATION_SCHEMA,
|
|
168
169
|
PermissionNotInManifestError: () => PermissionNotInManifestError,
|
|
169
|
-
PrefixedKVService: () =>
|
|
170
|
+
PrefixedKVService: () => import_sdk_services9.PrefixedKVService,
|
|
170
171
|
ProtocolMismatchError: () => ProtocolMismatchError,
|
|
171
172
|
REQUESTER_ENGINE_RETRY_ATTEMPTS: () => REQUESTER_ENGINE_RETRY_ATTEMPTS,
|
|
172
173
|
REQUESTER_ENGINE_RETRY_MAX_DELAY_MS: () => REQUESTER_ENGINE_RETRY_MAX_DELAY_MS,
|
|
@@ -177,17 +178,19 @@ __export(index_exports, {
|
|
|
177
178
|
ROOT_STATUS_RENEWAL_V1_DOMAIN: () => ROOT_STATUS_RENEWAL_V1_DOMAIN,
|
|
178
179
|
ROOT_STATUS_V1_DOMAIN: () => ROOT_STATUS_V1_DOMAIN,
|
|
179
180
|
SECRETS_SPACE: () => SECRETS_SPACE,
|
|
180
|
-
SECRET_NAME_RE: () =>
|
|
181
|
+
SECRET_NAME_RE: () => import_sdk_services9.SECRET_NAME_RE,
|
|
181
182
|
SECRET_RECORDS_SCHEMA: () => import_bootstrap4.SECRET_RECORDS_SCHEMA,
|
|
182
183
|
SERVICE_LONG_TO_SHORT: () => SERVICE_LONG_TO_SHORT,
|
|
183
184
|
SERVICE_SHORT_TO_LONG: () => SERVICE_SHORT_TO_LONG,
|
|
184
185
|
SPACE: () => import_bootstrap4.SPACE,
|
|
185
186
|
SQL: () => import_bootstrap4.SQL,
|
|
186
|
-
SQLAction: () =>
|
|
187
|
-
SQLService: () =>
|
|
188
|
-
|
|
187
|
+
SQLAction: () => import_sdk_services9.SQLAction,
|
|
188
|
+
SQLService: () => import_sdk_services9.SQLService,
|
|
189
|
+
STORAGE_FULL_MESSAGE: () => import_sdk_services9.STORAGE_FULL_MESSAGE,
|
|
190
|
+
STORAGE_WRITE_TOO_LARGE_MESSAGE: () => import_sdk_services9.STORAGE_WRITE_TOO_LARGE_MESSAGE,
|
|
191
|
+
SecretsService: () => import_sdk_services9.SecretsService,
|
|
189
192
|
SenderShareStore: () => SenderShareStore,
|
|
190
|
-
ServiceContext: () =>
|
|
193
|
+
ServiceContext: () => import_sdk_services9.ServiceContext,
|
|
191
194
|
SessionExpiredError: () => SessionExpiredError,
|
|
192
195
|
ShareAccessError: () => ShareAccessError,
|
|
193
196
|
ShareAddressedDelegationEnvelopeV2Schema: () => ShareAddressedDelegationEnvelopeV2Schema,
|
|
@@ -213,6 +216,7 @@ __export(index_exports, {
|
|
|
213
216
|
SpaceErrorCodes: () => SpaceErrorCodes,
|
|
214
217
|
SpaceService: () => SpaceService,
|
|
215
218
|
TINYCLOUD_ACCOUNT_SPACE_MANIFEST: () => import_bootstrap4.TINYCLOUD_ACCOUNT_SPACE_MANIFEST,
|
|
219
|
+
TINYCLOUD_AGENTS_SPACE_MANIFEST: () => import_bootstrap4.TINYCLOUD_AGENTS_SPACE_MANIFEST,
|
|
216
220
|
TINYCLOUD_APPLICATIONS_SPACE_MANIFEST: () => import_bootstrap4.TINYCLOUD_APPLICATIONS_SPACE_MANIFEST,
|
|
217
221
|
TINYCLOUD_CANONICAL_IDENTITY_CLAIM: () => TINYCLOUD_CANONICAL_IDENTITY_CLAIM,
|
|
218
222
|
TINYCLOUD_DEFAULT_SPACE_MANIFEST: () => import_bootstrap4.TINYCLOUD_DEFAULT_SPACE_MANIFEST,
|
|
@@ -220,14 +224,14 @@ __export(index_exports, {
|
|
|
220
224
|
TINYCLOUD_PUBLIC_SPACE_MANIFEST: () => import_bootstrap4.TINYCLOUD_PUBLIC_SPACE_MANIFEST,
|
|
221
225
|
TINYCLOUD_SECRETS_BOOTSTRAP_MANIFEST: () => import_bootstrap4.TINYCLOUD_SECRETS_BOOTSTRAP_MANIFEST,
|
|
222
226
|
TinyCloud: () => TinyCloud,
|
|
223
|
-
TinyCloudDebugLogger: () =>
|
|
227
|
+
TinyCloudDebugLogger: () => import_sdk_services9.TinyCloudDebugLogger,
|
|
224
228
|
TranscriptRequester: () => TranscriptRequester,
|
|
225
229
|
TranscriptRequesterError: () => TranscriptRequesterError,
|
|
226
230
|
UnsupportedFeatureError: () => UnsupportedFeatureError,
|
|
227
231
|
UnsupportedSignatureSuiteError: () => UnsupportedSignatureSuiteError,
|
|
228
232
|
VAULT_PERMISSION_SERVICE: () => VAULT_PERMISSION_SERVICE,
|
|
229
|
-
VaultHeaders: () =>
|
|
230
|
-
VaultPublicSpaceKVActions: () =>
|
|
233
|
+
VaultHeaders: () => import_sdk_services9.VaultHeaders,
|
|
234
|
+
VaultPublicSpaceKVActions: () => import_sdk_services9.VaultPublicSpaceKVActions,
|
|
231
235
|
VersionCheckError: () => VersionCheckError,
|
|
232
236
|
actionContains: () => actionContains,
|
|
233
237
|
activateSessionWithHost: () => activateSessionWithHost,
|
|
@@ -235,37 +239,37 @@ __export(index_exports, {
|
|
|
235
239
|
admitPolicyCredentialV3: () => admitPolicyCredentialV3,
|
|
236
240
|
admitPolicyCredentialV4: () => admitPolicyCredentialV4,
|
|
237
241
|
applyPrefix: () => applyPrefix,
|
|
238
|
-
authorizationVerdictOf: () =>
|
|
242
|
+
authorizationVerdictOf: () => import_sdk_services9.authorizationVerdictOf,
|
|
239
243
|
bootstrapEncryptionNetworkId: () => import_bootstrap4.bootstrapEncryptionNetworkId,
|
|
240
244
|
bootstrapSpaceId: () => import_bootstrap4.bootstrapSpaceId,
|
|
241
245
|
bootstrapSteps: () => import_bootstrap4.bootstrapSteps,
|
|
242
|
-
buildCanonicalDecryptRequest: () =>
|
|
243
|
-
buildDecryptAttenuation: () =>
|
|
244
|
-
buildDecryptFacts: () =>
|
|
245
|
-
buildDecryptInvocation: () =>
|
|
246
|
-
buildNetworkId: () =>
|
|
246
|
+
buildCanonicalDecryptRequest: () => import_sdk_services9.buildCanonicalDecryptRequest,
|
|
247
|
+
buildDecryptAttenuation: () => import_sdk_services9.buildDecryptAttenuation,
|
|
248
|
+
buildDecryptFacts: () => import_sdk_services9.buildDecryptFacts,
|
|
249
|
+
buildDecryptInvocation: () => import_sdk_services9.buildDecryptInvocation,
|
|
250
|
+
buildNetworkId: () => import_sdk_services9.buildNetworkId,
|
|
247
251
|
buildPolicyCredentialPresentationV3: () => buildPolicyCredentialPresentationV3,
|
|
248
252
|
buildPolicyCredentialPresentationV4: () => buildPolicyCredentialPresentationV4,
|
|
249
253
|
buildSpaceUri: () => buildSpaceUri,
|
|
250
254
|
canonicalDigest: () => canonicalDigest,
|
|
251
255
|
canonicalEmailDomain: () => import_share_envelope.canonicalEmailDomain,
|
|
252
|
-
canonicalHashHex: () =>
|
|
256
|
+
canonicalHashHex: () => import_sdk_services9.canonicalHashHex,
|
|
253
257
|
canonicalLocationPayload: () => canonicalLocationPayload,
|
|
254
258
|
canonicalMailbox: () => import_share_envelope.canonicalMailbox,
|
|
255
259
|
canonicalOwnerSharePolicy: () => canonicalOwnerSharePolicy,
|
|
256
|
-
canonicalSignedResponse: () =>
|
|
260
|
+
canonicalSignedResponse: () => import_sdk_services9.canonicalSignedResponse,
|
|
257
261
|
canonicalizeAddress: () => canonicalizeAddress,
|
|
258
262
|
canonicalizeDid: () => canonicalizeDid,
|
|
259
263
|
canonicalizeDidUrl: () => canonicalizeDidUrl,
|
|
260
|
-
canonicalizeEncryptionJson: () =>
|
|
264
|
+
canonicalizeEncryptionJson: () => import_sdk_services9.canonicalizeEncryptionJson,
|
|
261
265
|
canonicalizeNetworkId: () => canonicalizeNetworkId,
|
|
262
266
|
canonicalizeRecapCaveats: () => canonicalizeRecapCaveats,
|
|
263
|
-
canonicalizeSecretScope: () =>
|
|
267
|
+
canonicalizeSecretScope: () => import_sdk_services9.canonicalizeSecretScope,
|
|
264
268
|
canonicalizeSignedObjectUnsigned: () => canonicalizeSignedObjectUnsigned,
|
|
265
269
|
canonicalizeUnifiedPolicyCapability: () => canonicalizeUnifiedPolicyCapability,
|
|
266
|
-
checkDecryptInvocationInput: () =>
|
|
270
|
+
checkDecryptInvocationInput: () => import_sdk_services9.checkDecryptInvocationInput,
|
|
267
271
|
checkNodeInfo: () => checkNodeInfo,
|
|
268
|
-
clearTinyCloudDebugLogs: () =>
|
|
272
|
+
clearTinyCloudDebugLogs: () => import_sdk_services9.clearTinyCloudDebugLogs,
|
|
269
273
|
compactAttenuationContains: () => compactAttenuationContains,
|
|
270
274
|
composeBootstrapSpaceManifest: () => import_bootstrap4.composeBootstrapSpaceManifest,
|
|
271
275
|
composeManifestRequest: () => composeManifestRequest,
|
|
@@ -294,7 +298,7 @@ __export(index_exports, {
|
|
|
294
298
|
createStorageReceipt: () => createStorageReceipt,
|
|
295
299
|
createStoredCredentialRecord: () => createStoredCredentialRecord,
|
|
296
300
|
createTranscriptRequester: () => createTranscriptRequester,
|
|
297
|
-
createVaultCrypto: () =>
|
|
301
|
+
createVaultCrypto: () => import_sdk_services9.createVaultCrypto,
|
|
298
302
|
credentialEndpointPath: () => credentialEndpointPath,
|
|
299
303
|
credentialError: () => credentialError,
|
|
300
304
|
credentialIndexKey: () => credentialIndexKey,
|
|
@@ -302,37 +306,37 @@ __export(index_exports, {
|
|
|
302
306
|
credentialRecordKey: () => credentialRecordKey,
|
|
303
307
|
credentialRequirementDigest: () => credentialRequirementDigest,
|
|
304
308
|
decodeBase64Url: () => decodeBase64Url,
|
|
305
|
-
decryptEnvelopeWithKey: () =>
|
|
309
|
+
decryptEnvelopeWithKey: () => import_sdk_services9.decryptEnvelopeWithKey,
|
|
306
310
|
decryptShareBytesAsync: () => decryptShareBytesAsync,
|
|
307
|
-
defaultRetryPolicy: () =>
|
|
311
|
+
defaultRetryPolicy: () => import_sdk_services9.defaultRetryPolicy,
|
|
308
312
|
defaultSignStrategy: () => defaultSignStrategy,
|
|
309
313
|
defaultSpaceCreationHandler: () => defaultSpaceCreationHandler,
|
|
310
314
|
delegatePortablePolicySession: () => delegatePortablePolicySession,
|
|
311
315
|
deriveDelegationCid: () => deriveDelegationCid,
|
|
312
316
|
deriveSignedObjectMaterial: () => deriveSignedObjectMaterial,
|
|
313
|
-
deriveSignedReceiverKey: () =>
|
|
317
|
+
deriveSignedReceiverKey: () => import_sdk_services9.deriveSignedReceiverKey,
|
|
314
318
|
descriptorSatisfiesRequirement: () => descriptorSatisfiesRequirement,
|
|
315
319
|
didCacheKey: () => didCacheKey,
|
|
316
320
|
didEquals: () => didEquals,
|
|
317
321
|
diffImmutableSiweFields: () => diffImmutableSiweFields,
|
|
318
|
-
disableTinyCloudDebug: () =>
|
|
322
|
+
disableTinyCloudDebug: () => import_sdk_services9.disableTinyCloudDebug,
|
|
319
323
|
discoverLocalTinyCloudNode: () => discoverLocalTinyCloudNode,
|
|
320
|
-
discoverNetwork: () =>
|
|
321
|
-
enableTinyCloudDebug: () =>
|
|
324
|
+
discoverNetwork: () => import_sdk_services9.discoverNetwork,
|
|
325
|
+
enableTinyCloudDebug: () => import_sdk_services9.enableTinyCloudDebug,
|
|
322
326
|
encodeBase64Url: () => encodeBase64Url,
|
|
323
327
|
encodeInlineShareUrl: () => encodeInlineShareUrl,
|
|
324
328
|
encodeShareArtifact: () => encodeShareArtifact,
|
|
325
329
|
encodeShareUrl: () => encodeShareUrl,
|
|
326
330
|
encryptShareBytes: () => encryptShareBytes,
|
|
327
331
|
encryptShareBytesAsync: () => encryptShareBytesAsync,
|
|
328
|
-
encryptToNetwork: () =>
|
|
329
|
-
encryptionBase64Decode: () =>
|
|
330
|
-
encryptionBase64Encode: () =>
|
|
331
|
-
encryptionError: () =>
|
|
332
|
-
encryptionUtf8Decode: () =>
|
|
333
|
-
encryptionUtf8Encode: () =>
|
|
334
|
-
ensureNetworkUsableForDecrypt: () =>
|
|
335
|
-
err: () =>
|
|
332
|
+
encryptToNetwork: () => import_sdk_services9.encryptToNetwork,
|
|
333
|
+
encryptionBase64Decode: () => import_sdk_services9.base64Decode,
|
|
334
|
+
encryptionBase64Encode: () => import_sdk_services9.base64Encode,
|
|
335
|
+
encryptionError: () => import_sdk_services9.encryptionError,
|
|
336
|
+
encryptionUtf8Decode: () => import_sdk_services9.utf8Decode,
|
|
337
|
+
encryptionUtf8Encode: () => import_sdk_services9.utf8Encode,
|
|
338
|
+
ensureNetworkUsableForDecrypt: () => import_sdk_services9.ensureNetworkUsableForDecrypt,
|
|
339
|
+
err: () => import_sdk_services9.err,
|
|
336
340
|
expandActionShortNames: () => expandActionShortNames,
|
|
337
341
|
expandPermissionEntries: () => expandPermissionEntries,
|
|
338
342
|
expandPermissionEntry: () => expandPermissionEntry,
|
|
@@ -340,24 +344,27 @@ __export(index_exports, {
|
|
|
340
344
|
extractRecapAttenuations: () => extractRecapAttenuations,
|
|
341
345
|
fetchLocationRecord: () => fetchLocationRecord,
|
|
342
346
|
fetchPeerId: () => fetchPeerId,
|
|
343
|
-
generateRandomReceiverKey: () =>
|
|
347
|
+
generateRandomReceiverKey: () => import_sdk_services9.generateRandomReceiverKey,
|
|
344
348
|
getPolicyRootStatusV3: () => getPolicyRootStatusV3,
|
|
345
|
-
getTinyCloudDebugLogs: () =>
|
|
349
|
+
getTinyCloudDebugLogs: () => import_sdk_services9.getTinyCloudDebugLogs,
|
|
346
350
|
hasTinyCloudManageKeyScope: () => hasTinyCloudManageKeyScope,
|
|
347
|
-
hexDecode: () =>
|
|
348
|
-
hexEncode: () =>
|
|
351
|
+
hexDecode: () => import_sdk_services9.hexDecode,
|
|
352
|
+
hexEncode: () => import_sdk_services9.hexEncode,
|
|
349
353
|
holderBindingCanonicalBytes: () => holderBindingCanonicalBytes,
|
|
350
354
|
holderBindingSigningBytes: () => holderBindingSigningBytes,
|
|
355
|
+
httpResponseError: () => httpResponseError,
|
|
351
356
|
httpUrlToMultiaddr: () => httpUrlToMultiaddr,
|
|
352
357
|
importPortableDelegation: () => importPortableDelegation,
|
|
353
|
-
installTinyCloudDebugGlobals: () =>
|
|
358
|
+
installTinyCloudDebugGlobals: () => import_sdk_services9.installTinyCloudDebugGlobals,
|
|
354
359
|
intersectShareCapabilities: () => intersectShareCapabilities,
|
|
355
360
|
isCanonicalEmailDomain: () => import_share_envelope.isCanonicalEmailDomain,
|
|
356
361
|
isCapabilitySubset: () => isCapabilitySubset,
|
|
357
362
|
isDigest: () => isDigest,
|
|
358
363
|
isEvmAddress: () => isEvmAddress,
|
|
359
|
-
|
|
364
|
+
isExplicitOnlyAction: () => isExplicitOnlyAction,
|
|
365
|
+
isNetworkId: () => import_sdk_services9.isNetworkId,
|
|
360
366
|
isPlausibleOpenKeyActionId: () => isPlausibleOpenKeyActionId,
|
|
367
|
+
isStorageFullError: () => import_sdk_services9.isStorageFullError,
|
|
361
368
|
isV2ShareLink: () => isV2ShareLink,
|
|
362
369
|
issuedCredentialEnvelopeFromVerified: () => issuedCredentialEnvelopeFromVerified,
|
|
363
370
|
jcsCanonicalize: () => jcsCanonicalize,
|
|
@@ -368,28 +375,29 @@ __export(index_exports, {
|
|
|
368
375
|
makePublicSpaceId: () => makePublicSpaceId,
|
|
369
376
|
manifestAbilitiesUnion: () => manifestAbilitiesUnion,
|
|
370
377
|
multiaddrToHttpUrl: () => multiaddrToHttpUrl,
|
|
371
|
-
networkDiscoveryKey: () =>
|
|
378
|
+
networkDiscoveryKey: () => import_sdk_services9.networkDiscoveryKey,
|
|
372
379
|
normalizeDefaults: () => normalizeDefaults,
|
|
373
380
|
normalizeJson: () => normalizeJson,
|
|
374
381
|
normalizeShareActions: () => normalizeShareActions,
|
|
375
382
|
normalizeShareRecipientTarget: () => normalizeShareRecipientTarget,
|
|
376
383
|
normalizeShareResource: () => normalizeShareResource,
|
|
377
384
|
normalizeUnifiedPolicyCapability: () => normalizeUnifiedPolicyCapability,
|
|
378
|
-
ok: () =>
|
|
379
|
-
openWrappedKey: () =>
|
|
385
|
+
ok: () => import_sdk_services9.ok,
|
|
386
|
+
openWrappedKey: () => import_sdk_services9.openWrappedKey,
|
|
380
387
|
parseCanonicalNetworkId: () => parseCanonicalNetworkId,
|
|
381
388
|
parseCanonicalRecapResource: () => parseCanonicalRecapResource,
|
|
382
389
|
parseCanonicalTinyCloudIdentity: () => parseCanonicalTinyCloudIdentity,
|
|
383
390
|
parseCanonicalTinyCloudIdentityClaims: () => parseCanonicalTinyCloudIdentityClaims,
|
|
391
|
+
parseCapabilityResource: () => import_sdk_services9.parseCapabilityResource,
|
|
384
392
|
parseCompactUcanAuthorization: () => parseCompactUcanAuthorization,
|
|
385
393
|
parseExpiry: () => parseExpiry,
|
|
386
|
-
parseNetworkId: () =>
|
|
394
|
+
parseNetworkId: () => import_sdk_services9.parseNetworkId,
|
|
387
395
|
parseNodeNativePortableDelegation: () => parseNodeNativePortableDelegation,
|
|
388
396
|
parsePkhDid: () => parsePkhDid,
|
|
389
397
|
parsePolicySessionUcan: () => parsePolicySessionUcan,
|
|
390
398
|
parsePortableDelegation: () => parsePortableDelegation,
|
|
391
399
|
parseRecapCapabilities: () => parseRecapCapabilities,
|
|
392
|
-
parseSecretCatalogKey: () =>
|
|
400
|
+
parseSecretCatalogKey: () => import_sdk_services9.parseSecretCatalogKey,
|
|
393
401
|
parseShareArtifact: () => parseShareArtifact,
|
|
394
402
|
parseShareUrl: () => parseShareUrl,
|
|
395
403
|
parseSpaceUri: () => parseSpaceUri,
|
|
@@ -410,8 +418,8 @@ __export(index_exports, {
|
|
|
410
418
|
resolveCloudLocation: () => resolveCloudLocation,
|
|
411
419
|
resolveManifest: () => resolveManifest,
|
|
412
420
|
resolveManifestKnowledgeRoot: () => resolveManifestKnowledgeRoot,
|
|
413
|
-
resolveSecretListPrefix: () =>
|
|
414
|
-
resolveSecretPath: () =>
|
|
421
|
+
resolveSecretListPrefix: () => import_sdk_services9.resolveSecretListPrefix,
|
|
422
|
+
resolveSecretPath: () => import_sdk_services9.resolveSecretPath,
|
|
415
423
|
resolveTinyCloudHosts: () => resolveTinyCloudHosts,
|
|
416
424
|
resourceCapabilitiesToAbilitiesMap: () => resourceCapabilitiesToAbilitiesMap,
|
|
417
425
|
resourceCapabilitiesToSpaceAbilitiesMap: () => resourceCapabilitiesToSpaceAbilitiesMap,
|
|
@@ -419,7 +427,7 @@ __export(index_exports, {
|
|
|
419
427
|
revokePolicyRootV3: () => revokePolicyRootV3,
|
|
420
428
|
serializeJcsJson: () => serialize,
|
|
421
429
|
serializePortableDelegation: () => serializePortableDelegation,
|
|
422
|
-
serviceError: () =>
|
|
430
|
+
serviceError: () => import_sdk_services9.serviceError,
|
|
423
431
|
sha256Base64Url: () => sha256Base64Url,
|
|
424
432
|
shareCapabilityAllows: () => shareCapabilityAllows,
|
|
425
433
|
signCompactPolicyDescendant: () => signCompactPolicyDescendant,
|
|
@@ -430,7 +438,7 @@ __export(index_exports, {
|
|
|
430
438
|
signShareEnvelope: () => signShareEnvelope,
|
|
431
439
|
signedObjectIdFor: () => signedObjectIdFor,
|
|
432
440
|
submitHostDelegation: () => submitHostDelegation,
|
|
433
|
-
tinyCloudDebugLogger: () =>
|
|
441
|
+
tinyCloudDebugLogger: () => import_sdk_services9.tinyCloudDebugLogger,
|
|
434
442
|
toSignedObjectError: () => toSignedObjectError,
|
|
435
443
|
unauthorizedRecapCapabilities: () => unauthorizedRecapCapabilities,
|
|
436
444
|
unifiedNativeProjectionHashHex: () => unifiedNativeProjectionHashHex,
|
|
@@ -442,7 +450,7 @@ __export(index_exports, {
|
|
|
442
450
|
validateCredentialFlowDescriptor: () => validateCredentialFlowDescriptor,
|
|
443
451
|
validateCredentialHolderBinding: () => validateCredentialHolderBinding,
|
|
444
452
|
validateCredentialRequirement: () => validateCredentialRequirement,
|
|
445
|
-
validateEnvelope: () =>
|
|
453
|
+
validateEnvelope: () => import_sdk_services9.validateEnvelope,
|
|
446
454
|
validateLocationRecord: () => validateLocationRecord,
|
|
447
455
|
validateLocationRecordPayload: () => validateLocationRecordPayload,
|
|
448
456
|
validateManifest: () => validateManifest,
|
|
@@ -461,7 +469,8 @@ __export(index_exports, {
|
|
|
461
469
|
validatePolicyUnsigned: () => validatePolicyUnsigned,
|
|
462
470
|
validateShareDeliveryAuthorizationV3Bytes: () => validateShareDeliveryAuthorizationV3Bytes,
|
|
463
471
|
validateUnifiedPolicyV2: () => validateUnifiedPolicyV2,
|
|
464
|
-
|
|
472
|
+
validatedCapabilityOf: () => import_sdk_services9.validatedCapabilityOf,
|
|
473
|
+
verifyDecryptResponse: () => import_sdk_services9.verifyDecryptResponse,
|
|
465
474
|
verifyDidKeyEd25519Signature: () => verifyDidKeyEd25519Signature,
|
|
466
475
|
verifyEip191MessageSignature: () => verifyEip191MessageSignature,
|
|
467
476
|
verifyIssuedCredential: () => verifyIssuedCredential,
|
|
@@ -3903,6 +3912,32 @@ var import_sha256 = require("@noble/hashes/sha256");
|
|
|
3903
3912
|
var import_blake3 = require("@noble/hashes/blake3");
|
|
3904
3913
|
var import_ed255193 = require("@noble/curves/ed25519");
|
|
3905
3914
|
var import_zod2 = require("zod");
|
|
3915
|
+
|
|
3916
|
+
// src/http-error.ts
|
|
3917
|
+
var import_sdk_services = require("@tinycloud/sdk-services");
|
|
3918
|
+
async function httpResponseError(response, context) {
|
|
3919
|
+
let body;
|
|
3920
|
+
try {
|
|
3921
|
+
body = await response.text();
|
|
3922
|
+
} catch {
|
|
3923
|
+
body = response.statusText;
|
|
3924
|
+
}
|
|
3925
|
+
body = body.trim().slice(0, 512);
|
|
3926
|
+
return Object.assign(new Error(`${context}: HTTP ${response.status}${body ? ` - ${body}` : ""}`), {
|
|
3927
|
+
status: response.status
|
|
3928
|
+
});
|
|
3929
|
+
}
|
|
3930
|
+
async function serviceHttpError(response, code3, context, service) {
|
|
3931
|
+
const failure = await httpResponseError(response, context);
|
|
3932
|
+
return (0, import_sdk_services.serviceError)(
|
|
3933
|
+
response.status === 401 || response.status === 403 ? import_sdk_services.ErrorCodes.AUTH_UNAUTHORIZED : code3,
|
|
3934
|
+
failure.message,
|
|
3935
|
+
service,
|
|
3936
|
+
{ meta: { status: response.status } }
|
|
3937
|
+
);
|
|
3938
|
+
}
|
|
3939
|
+
|
|
3940
|
+
// src/policy/unified.ts
|
|
3906
3941
|
var POLICY_V1_SCHEMA = "xyz.tinycloud.policy/policy/v1";
|
|
3907
3942
|
var POLICY_CAPABILITY_V1_SCHEMA = "xyz.tinycloud.policy/capability/v1";
|
|
3908
3943
|
var POLICY_ENFORCEMENT_DELEGATION_V2_SCHEMA = "xyz.tinycloud.policy/enforcement-delegation/v2";
|
|
@@ -3930,7 +3965,7 @@ async function requestPolicyChallengeV3(input) {
|
|
|
3930
3965
|
headers: { accept: "application/json", "content-type": "application/json" },
|
|
3931
3966
|
body: JSON.stringify({ policyCid: input.policyCid, recipientDid: input.recipientDid, requestedCapabilities: input.requestedCapabilities.map(normalizeUnifiedPolicyCapability) })
|
|
3932
3967
|
});
|
|
3933
|
-
if (!response.ok) throw
|
|
3968
|
+
if (!response.ok) throw await httpResponseError(response, "policy challenge rejected");
|
|
3934
3969
|
const value = object2(await response.json(), "policy challenge");
|
|
3935
3970
|
if (typeof value.challengeId !== "string" || typeof value.nonce !== "string" || value.policyCid !== input.policyCid || value.recipientDid !== input.recipientDid)
|
|
3936
3971
|
throw new Error("policy challenge binding is invalid");
|
|
@@ -3993,7 +4028,7 @@ async function getPolicyRootStatusV3(input) {
|
|
|
3993
4028
|
redirect: "error",
|
|
3994
4029
|
headers: { accept: "application/json" }
|
|
3995
4030
|
});
|
|
3996
|
-
if (!response.ok) throw
|
|
4031
|
+
if (!response.ok) throw await httpResponseError(response, "policy root status rejected");
|
|
3997
4032
|
const value = object2(await response.json(), "policy root status");
|
|
3998
4033
|
const checkpoint = object2(value.checkpoint, "policy root checkpoint");
|
|
3999
4034
|
if (value.rootCid !== input.rootCid || value.state !== "active" && value.state !== "revoked" || value.state !== checkpoint.state || !verifyPolicyRootStatusCheckpointV3({ rootCid: input.rootCid, checkpoint, expectedNodeAudience: input.expectedNodeAudience, now: input.now }))
|
|
@@ -4053,9 +4088,12 @@ async function renewPolicyRootStatusV3(input) {
|
|
|
4053
4088
|
headers: { accept: "application/json", "content-type": "application/json" },
|
|
4054
4089
|
body: JSON.stringify({ rootCid: input.rootCid, renewal: { ...unsigned, signature: { suite: "Ed25519", signerDid: input.ownerDid, value: encodeBase64Url2(signature) } } })
|
|
4055
4090
|
});
|
|
4056
|
-
if (!response.ok) throw
|
|
4091
|
+
if (!response.ok) throw await httpResponseError(response, "policy root renewal rejected");
|
|
4057
4092
|
return object2(await response.json(), "policy root renewal");
|
|
4058
4093
|
}
|
|
4094
|
+
function rfc3339Seconds(value) {
|
|
4095
|
+
return new Date(Math.floor(value.getTime() / 1e3) * 1e3).toISOString().replace(/\.000Z$/, "Z");
|
|
4096
|
+
}
|
|
4059
4097
|
async function revokePolicyRootV3(input) {
|
|
4060
4098
|
if (input.reason.length === 0) throw new Error("policy root revocation reason is required");
|
|
4061
4099
|
const unsigned = {
|
|
@@ -4064,7 +4102,7 @@ async function revokePolicyRootV3(input) {
|
|
|
4064
4102
|
targetRole: input.targetRole,
|
|
4065
4103
|
ownerDid: input.ownerDid,
|
|
4066
4104
|
nodeAudience: input.nodeAudience,
|
|
4067
|
-
revokedAt: (input.now ?? /* @__PURE__ */ new Date())
|
|
4105
|
+
revokedAt: rfc3339Seconds(input.now ?? /* @__PURE__ */ new Date()),
|
|
4068
4106
|
reason: input.reason,
|
|
4069
4107
|
issuerDid: input.issuerDid
|
|
4070
4108
|
};
|
|
@@ -4077,7 +4115,7 @@ async function revokePolicyRootV3(input) {
|
|
|
4077
4115
|
headers: { accept: "application/json", "content-type": "application/json" },
|
|
4078
4116
|
body: JSON.stringify({ revocation: { ...unsigned, signature: { suite: "Ed25519", signerDid: input.issuerDid, value: encodeBase64Url2(signature) } } })
|
|
4079
4117
|
});
|
|
4080
|
-
if (!response.ok) throw
|
|
4118
|
+
if (!response.ok) throw await httpResponseError(response, "policy root revocation rejected");
|
|
4081
4119
|
return object2(await response.json(), "policy root revocation");
|
|
4082
4120
|
}
|
|
4083
4121
|
var POLICY_SESSION_FACT_KEYS = [
|
|
@@ -4346,7 +4384,7 @@ async function registerPolicyV3(input) {
|
|
|
4346
4384
|
}
|
|
4347
4385
|
);
|
|
4348
4386
|
if (!bindingResponse.ok) {
|
|
4349
|
-
throw
|
|
4387
|
+
throw await httpResponseError(bindingResponse, "policy enforcer binding rejected");
|
|
4350
4388
|
}
|
|
4351
4389
|
const binding = exactObject(
|
|
4352
4390
|
await bindingResponse.json(),
|
|
@@ -4412,7 +4450,7 @@ async function registerPolicyV3(input) {
|
|
|
4412
4450
|
}
|
|
4413
4451
|
);
|
|
4414
4452
|
if (!response.ok) {
|
|
4415
|
-
throw
|
|
4453
|
+
throw await httpResponseError(response, "policy registration rejected");
|
|
4416
4454
|
}
|
|
4417
4455
|
const receipt = exactObject(
|
|
4418
4456
|
await response.json(),
|
|
@@ -4815,7 +4853,7 @@ function date(value, label) {
|
|
|
4815
4853
|
if (!Number.isFinite(Date.parse(text2))) throw new Error(`${label} is invalid`);
|
|
4816
4854
|
return text2;
|
|
4817
4855
|
}
|
|
4818
|
-
function
|
|
4856
|
+
function rfc3339Seconds2(value) {
|
|
4819
4857
|
return new Date(Math.floor(value.getTime() / 1e3) * 1e3).toISOString().replace(/\.000Z$/, "Z");
|
|
4820
4858
|
}
|
|
4821
4859
|
function validateUnifiedPolicyV2(value, expectedPolicyCid) {
|
|
@@ -4980,8 +5018,8 @@ async function buildPolicyCredentialPresentationV4(input) {
|
|
|
4980
5018
|
requirementDigest,
|
|
4981
5019
|
descriptorDigest: input.credential.descriptorDigest,
|
|
4982
5020
|
requestedCapabilities: Object.freeze(requestedCapabilities),
|
|
4983
|
-
issuedAt:
|
|
4984
|
-
expiresAt:
|
|
5021
|
+
issuedAt: rfc3339Seconds2(now),
|
|
5022
|
+
expiresAt: rfc3339Seconds2(new Date(expiresAtMs))
|
|
4985
5023
|
}), input.sign);
|
|
4986
5024
|
}
|
|
4987
5025
|
async function buildPolicyCredentialPresentationV3(input) {
|
|
@@ -5035,8 +5073,8 @@ async function buildPolicyCredentialPresentationV3(input) {
|
|
|
5035
5073
|
requirementDigest,
|
|
5036
5074
|
descriptorDigest: input.credential.descriptorDigest,
|
|
5037
5075
|
requestedCapabilities: Object.freeze(requestedCapabilities),
|
|
5038
|
-
issuedAt:
|
|
5039
|
-
expiresAt:
|
|
5076
|
+
issuedAt: rfc3339Seconds2(now),
|
|
5077
|
+
expiresAt: rfc3339Seconds2(new Date(expiresAtMs))
|
|
5040
5078
|
});
|
|
5041
5079
|
const digest4 = (0, import_sha2562.sha256)(
|
|
5042
5080
|
new TextEncoder().encode(
|
|
@@ -5098,7 +5136,7 @@ async function admitPolicyCredentialV3(input) {
|
|
|
5098
5136
|
requestedSessionExpiry(input.requestedExpiresAt, policy),
|
|
5099
5137
|
input.signal
|
|
5100
5138
|
);
|
|
5101
|
-
if (!response.ok) throw
|
|
5139
|
+
if (!response.ok) throw await httpResponseError(response, "policy delegation rejected");
|
|
5102
5140
|
const value = record(await response.json(), "policy delegation");
|
|
5103
5141
|
if (value.admitted !== true || typeof value.sessionCid !== "string" || typeof value.authorization !== "string") {
|
|
5104
5142
|
throw new Error("policy delegation response is invalid");
|
|
@@ -5151,7 +5189,7 @@ async function admitPolicyCredentialV4(input) {
|
|
|
5151
5189
|
requestedSessionExpiry(input.requestedExpiresAt, policy),
|
|
5152
5190
|
input.signal
|
|
5153
5191
|
);
|
|
5154
|
-
if (!response.ok) throw
|
|
5192
|
+
if (!response.ok) throw await httpResponseError(response, "policy delegation rejected");
|
|
5155
5193
|
const value = record(await response.json(), "policy delegation");
|
|
5156
5194
|
if (value.admitted !== true || typeof value.sessionCid !== "string" || typeof value.authorization !== "string") throw new Error("policy delegation response is invalid");
|
|
5157
5195
|
const session = parsePolicySessionUcan(value.authorization, [
|
|
@@ -5170,7 +5208,7 @@ async function admitPolicyCredentialV4(input) {
|
|
|
5170
5208
|
signal: input.signal,
|
|
5171
5209
|
headers: { Authorization: session.authorization }
|
|
5172
5210
|
});
|
|
5173
|
-
if (!importResponse.ok) throw
|
|
5211
|
+
if (!importResponse.ok) throw await httpResponseError(importResponse, "delegation import rejected");
|
|
5174
5212
|
input.signal?.throwIfAborted();
|
|
5175
5213
|
return Object.freeze({ challenge, presentation, session, delegationImported: true });
|
|
5176
5214
|
}
|
|
@@ -7754,7 +7792,7 @@ function validateEncodedShareData(data) {
|
|
|
7754
7792
|
// src/manifest.ts
|
|
7755
7793
|
var import_ms = __toESM(require("ms"), 1);
|
|
7756
7794
|
var import_bootstrap2 = require("@tinycloud/bootstrap");
|
|
7757
|
-
var
|
|
7795
|
+
var import_sdk_services2 = require("@tinycloud/sdk-services");
|
|
7758
7796
|
var DEFAULT_KNOWLEDGE_ROOT = "knowledge/index.md";
|
|
7759
7797
|
var ManifestValidationError = class extends Error {
|
|
7760
7798
|
constructor(message) {
|
|
@@ -8025,13 +8063,13 @@ function validateManifestSecrets(secrets) {
|
|
|
8025
8063
|
throw new ManifestValidationError("manifest.secrets must be an object");
|
|
8026
8064
|
}
|
|
8027
8065
|
for (const [name2, spec] of Object.entries(secrets)) {
|
|
8028
|
-
if (!
|
|
8066
|
+
if (!import_sdk_services2.SECRET_NAME_RE.test(name2)) {
|
|
8029
8067
|
throw new ManifestValidationError(
|
|
8030
|
-
`manifest.secrets.${name2} must match ${
|
|
8068
|
+
`manifest.secrets.${name2} must match ${import_sdk_services2.SECRET_NAME_RE.source}`
|
|
8031
8069
|
);
|
|
8032
8070
|
}
|
|
8033
8071
|
try {
|
|
8034
|
-
(0,
|
|
8072
|
+
(0, import_sdk_services2.resolveSecretPath)(
|
|
8035
8073
|
secretNameFromSpec(name2, spec),
|
|
8036
8074
|
{ scope: secretScopeFromSpec(spec) }
|
|
8037
8075
|
);
|
|
@@ -8248,7 +8286,7 @@ function secretEntriesForManifest(secrets) {
|
|
|
8248
8286
|
const entries = [];
|
|
8249
8287
|
for (const [name2, spec] of Object.entries(secrets)) {
|
|
8250
8288
|
const actions = secretActionsFromSpec(name2, spec);
|
|
8251
|
-
const secretPath = (0,
|
|
8289
|
+
const secretPath = (0, import_sdk_services2.resolveSecretPath)(
|
|
8252
8290
|
secretNameFromSpec(name2, spec),
|
|
8253
8291
|
{ scope: secretScopeFromSpec(spec) }
|
|
8254
8292
|
);
|
|
@@ -8626,8 +8664,17 @@ function canonicalizeRecapCaveats(caveats) {
|
|
|
8626
8664
|
}
|
|
8627
8665
|
return `[${branches.join(",")}]`;
|
|
8628
8666
|
}
|
|
8667
|
+
var EXPLICIT_ONLY_ACTIONS = {
|
|
8668
|
+
"tinycloud.kv/sync": true,
|
|
8669
|
+
"tinycloud.kv/retain": true
|
|
8670
|
+
};
|
|
8671
|
+
function isExplicitOnlyAction(action) {
|
|
8672
|
+
return Object.prototype.hasOwnProperty.call(EXPLICIT_ONLY_ACTIONS, action);
|
|
8673
|
+
}
|
|
8629
8674
|
function actionContains(grantedAction, requestedAction) {
|
|
8630
|
-
if (grantedAction ===
|
|
8675
|
+
if (grantedAction === requestedAction) return true;
|
|
8676
|
+
if (isExplicitOnlyAction(requestedAction)) return false;
|
|
8677
|
+
if (grantedAction === "*") return true;
|
|
8631
8678
|
if (!grantedAction.endsWith("/*")) return false;
|
|
8632
8679
|
const service = grantedAction.slice(0, -2);
|
|
8633
8680
|
return requestedAction === service || requestedAction.startsWith(`${service}/`);
|
|
@@ -8690,7 +8737,7 @@ function parseRecapCapabilities(parseWasm, siwe) {
|
|
|
8690
8737
|
var import_ed255197 = require("@noble/curves/ed25519");
|
|
8691
8738
|
|
|
8692
8739
|
// src/delegations/ShareRecipientClient.ts
|
|
8693
|
-
var
|
|
8740
|
+
var import_sdk_services3 = require("@tinycloud/sdk-services");
|
|
8694
8741
|
var import_ed255196 = require("@noble/curves/ed25519");
|
|
8695
8742
|
var import_sha2565 = require("@noble/hashes/sha256");
|
|
8696
8743
|
|
|
@@ -9808,7 +9855,7 @@ async function importPortableDelegation(fetchFn, host, delegation) {
|
|
|
9808
9855
|
headers: { Authorization: parsed.delegationHeader.Authorization }
|
|
9809
9856
|
});
|
|
9810
9857
|
if (!response.ok)
|
|
9811
|
-
throw
|
|
9858
|
+
throw await httpResponseError(response, "node rejected delegation import");
|
|
9812
9859
|
const body = await response.json().catch(() => ({}));
|
|
9813
9860
|
if (body === null || typeof body !== "object" || Array.isArray(body))
|
|
9814
9861
|
return {};
|
|
@@ -9877,7 +9924,7 @@ function redactedCode(error) {
|
|
|
9877
9924
|
if (error instanceof ShareConflict) return error.code;
|
|
9878
9925
|
const code3 = error && typeof error === "object" && "code" in error ? error.code : void 0;
|
|
9879
9926
|
if (typeof code3 !== "string") return "SHARE_INVALID";
|
|
9880
|
-
if (code3 ===
|
|
9927
|
+
if (code3 === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED || code3 === import_sdk_services3.ErrorCodes.KV_CONFLICT || code3 === "412") return "SHARE_CONFLICT";
|
|
9881
9928
|
if (code3 === "KV_NOT_FOUND" || code3 === "NOT_FOUND" || code3 === "404") return "SHARE_NOT_FOUND";
|
|
9882
9929
|
if (code3.includes("EXPIRED") || code3 === "expired") return "SHARE_EXPIRED";
|
|
9883
9930
|
if (code3.includes("REVOK")) return "SHARE_REVOKED";
|
|
@@ -10116,7 +10163,7 @@ var ShareRecipientClient = class {
|
|
|
10116
10163
|
if (portableDelegation !== void 0 && kv !== void 0) {
|
|
10117
10164
|
const result2 = await kv.put(resolvedPath, bytes2, { contentType: input.contentType ?? envelope.content.mimeType, ifMatch: input.etag });
|
|
10118
10165
|
if (!result2.ok) {
|
|
10119
|
-
if (result2.error.code ===
|
|
10166
|
+
if (result2.error.code === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED || result2.error.code === import_sdk_services3.ErrorCodes.KV_CONFLICT) throw new ShareConflict(resolvedPath, result2.error.meta?.etag);
|
|
10120
10167
|
throw result2.error;
|
|
10121
10168
|
}
|
|
10122
10169
|
return { etag: result2.data.headers.etag };
|
|
@@ -10124,7 +10171,7 @@ var ShareRecipientClient = class {
|
|
|
10124
10171
|
if (policySession !== void 0) return this.nativeSave(envelope, policySession, resolvedPath, bytes2, input);
|
|
10125
10172
|
const result = await kv.put(resolvedPath, bytes2, { contentType: input.contentType ?? envelope.content.mimeType, ifMatch: input.etag });
|
|
10126
10173
|
if (!result.ok) {
|
|
10127
|
-
if (result.error.code ===
|
|
10174
|
+
if (result.error.code === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED || result.error.code === import_sdk_services3.ErrorCodes.KV_CONFLICT) throw new ShareConflict(resolvedPath, result.error.meta?.etag);
|
|
10128
10175
|
throw result.error;
|
|
10129
10176
|
}
|
|
10130
10177
|
return { etag: result.data.headers.etag };
|
|
@@ -10208,8 +10255,8 @@ var ShareRecipientClient = class {
|
|
|
10208
10255
|
if (this.options.createKVService !== void 0) {
|
|
10209
10256
|
return this.options.createKVService({ hosts: [origin2], session, invoke, fetch: this.fetchFn });
|
|
10210
10257
|
}
|
|
10211
|
-
const context = new
|
|
10212
|
-
const service = new
|
|
10258
|
+
const context = new import_sdk_services3.ServiceContext({ hosts: [origin2], session, invoke, fetch: this.fetchFn });
|
|
10259
|
+
const service = new import_sdk_services3.KVService({ prefix: "" });
|
|
10213
10260
|
context.registerService("kv", service);
|
|
10214
10261
|
service.initialize(context);
|
|
10215
10262
|
return service;
|
|
@@ -11310,7 +11357,9 @@ var SharingService = class {
|
|
|
11310
11357
|
if (delegation.allowSubDelegation === false) continue;
|
|
11311
11358
|
if (!this.pathMatches(delegation.path || "", path)) continue;
|
|
11312
11359
|
const delegationActions = delegation.actions || [];
|
|
11313
|
-
if (!actions.every(
|
|
11360
|
+
if (!actions.every(
|
|
11361
|
+
(action) => delegationActions.some((granted) => actionContains(granted, action))
|
|
11362
|
+
)) {
|
|
11314
11363
|
continue;
|
|
11315
11364
|
}
|
|
11316
11365
|
if ((delegation.caveats?.length ?? 0) > 0) {
|
|
@@ -12468,14 +12517,14 @@ var import_share_sdk = require("@tinycloud/share-sdk");
|
|
|
12468
12517
|
var import_share_sdk2 = require("@tinycloud/share-sdk");
|
|
12469
12518
|
|
|
12470
12519
|
// src/networkId.ts
|
|
12471
|
-
var
|
|
12520
|
+
var import_sdk_services4 = require("@tinycloud/sdk-services");
|
|
12472
12521
|
function canonicalizeNetworkId(networkId) {
|
|
12473
|
-
const parsed = (0,
|
|
12474
|
-
return (0,
|
|
12522
|
+
const parsed = (0, import_sdk_services4.parseNetworkId)(networkId);
|
|
12523
|
+
return (0, import_sdk_services4.buildNetworkId)(canonicalizeDid(parsed.ownerDid), parsed.name);
|
|
12475
12524
|
}
|
|
12476
12525
|
function parseCanonicalNetworkId(networkId) {
|
|
12477
12526
|
const canonical = canonicalizeNetworkId(networkId);
|
|
12478
|
-
return (0,
|
|
12527
|
+
return (0, import_sdk_services4.parseNetworkId)(canonical);
|
|
12479
12528
|
}
|
|
12480
12529
|
|
|
12481
12530
|
// src/storage.schema.ts
|
|
@@ -12574,10 +12623,10 @@ function validatePersistedSessionData(data) {
|
|
|
12574
12623
|
}
|
|
12575
12624
|
|
|
12576
12625
|
// src/TinyCloud.ts
|
|
12577
|
-
var
|
|
12626
|
+
var import_sdk_services6 = require("@tinycloud/sdk-services");
|
|
12578
12627
|
|
|
12579
12628
|
// src/spaces/SpaceService.ts
|
|
12580
|
-
var
|
|
12629
|
+
var import_sdk_services5 = require("@tinycloud/sdk-services");
|
|
12581
12630
|
|
|
12582
12631
|
// src/spaces/Space.ts
|
|
12583
12632
|
function unavailableSecretsService() {
|
|
@@ -13006,8 +13055,8 @@ var SpaceService = class {
|
|
|
13006
13055
|
*/
|
|
13007
13056
|
async list() {
|
|
13008
13057
|
if (!this.session) {
|
|
13009
|
-
return (0,
|
|
13010
|
-
(0,
|
|
13058
|
+
return (0, import_sdk_services5.err)(
|
|
13059
|
+
(0, import_sdk_services5.serviceError)(SpaceErrorCodes.AUTH_REQUIRED, "Authentication required", SERVICE_NAME)
|
|
13011
13060
|
);
|
|
13012
13061
|
}
|
|
13013
13062
|
try {
|
|
@@ -13015,6 +13064,9 @@ var SpaceService = class {
|
|
|
13015
13064
|
const ownedResult = await this.listOwnedSpaces();
|
|
13016
13065
|
if (ownedResult.ok) {
|
|
13017
13066
|
spaces.push(...ownedResult.data);
|
|
13067
|
+
} else {
|
|
13068
|
+
const verdict = (0, import_sdk_services5.authorizationVerdictOf)(ownedResult.error);
|
|
13069
|
+
if (verdict === "unauthenticated" || verdict === "forbidden") return (0, import_sdk_services5.err)(ownedResult.error);
|
|
13018
13070
|
}
|
|
13019
13071
|
if (this.capabilityRegistry) {
|
|
13020
13072
|
const delegatedSpaces = this.discoverDelegatedSpaces();
|
|
@@ -13024,10 +13076,10 @@ var SpaceService = class {
|
|
|
13024
13076
|
for (const space of uniqueSpaces) {
|
|
13025
13077
|
this.notifySpaceRegistered(space);
|
|
13026
13078
|
}
|
|
13027
|
-
return (0,
|
|
13079
|
+
return (0, import_sdk_services5.ok)(uniqueSpaces);
|
|
13028
13080
|
} catch (error) {
|
|
13029
|
-
return (0,
|
|
13030
|
-
(0,
|
|
13081
|
+
return (0, import_sdk_services5.err)(
|
|
13082
|
+
(0, import_sdk_services5.serviceError)(
|
|
13031
13083
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
13032
13084
|
`Failed to list spaces: ${String(error)}`,
|
|
13033
13085
|
SERVICE_NAME,
|
|
@@ -13047,21 +13099,18 @@ var SpaceService = class {
|
|
|
13047
13099
|
headers
|
|
13048
13100
|
});
|
|
13049
13101
|
if (!response.ok) {
|
|
13050
|
-
|
|
13051
|
-
|
|
13052
|
-
|
|
13053
|
-
|
|
13054
|
-
|
|
13055
|
-
|
|
13056
|
-
{ meta: { status: response.status } }
|
|
13057
|
-
)
|
|
13058
|
-
);
|
|
13102
|
+
return (0, import_sdk_services5.err)(await serviceHttpError(
|
|
13103
|
+
response,
|
|
13104
|
+
SpaceErrorCodes.NETWORK_ERROR,
|
|
13105
|
+
"Failed to list owned spaces",
|
|
13106
|
+
SERVICE_NAME
|
|
13107
|
+
));
|
|
13059
13108
|
}
|
|
13060
13109
|
const rawData = await response.json();
|
|
13061
13110
|
const validationResult = validateServerOwnedSpacesResponse(rawData);
|
|
13062
13111
|
if (!validationResult.ok) {
|
|
13063
|
-
return (0,
|
|
13064
|
-
(0,
|
|
13112
|
+
return (0, import_sdk_services5.err)(
|
|
13113
|
+
(0, import_sdk_services5.serviceError)(
|
|
13065
13114
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
13066
13115
|
validationResult.error.message,
|
|
13067
13116
|
SERVICE_NAME,
|
|
@@ -13077,10 +13126,10 @@ var SpaceService = class {
|
|
|
13077
13126
|
permissions: ["*"]
|
|
13078
13127
|
// Full permissions for owned spaces
|
|
13079
13128
|
}));
|
|
13080
|
-
return (0,
|
|
13129
|
+
return (0, import_sdk_services5.ok)(spaces);
|
|
13081
13130
|
} catch (error) {
|
|
13082
|
-
return (0,
|
|
13083
|
-
(0,
|
|
13131
|
+
return (0, import_sdk_services5.err)(
|
|
13132
|
+
(0, import_sdk_services5.serviceError)(
|
|
13084
13133
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
13085
13134
|
`Network error listing owned spaces: ${String(error)}`,
|
|
13086
13135
|
SERVICE_NAME,
|
|
@@ -13161,13 +13210,13 @@ var SpaceService = class {
|
|
|
13161
13210
|
*/
|
|
13162
13211
|
async create(name2) {
|
|
13163
13212
|
if (!this.session) {
|
|
13164
|
-
return (0,
|
|
13165
|
-
(0,
|
|
13213
|
+
return (0, import_sdk_services5.err)(
|
|
13214
|
+
(0, import_sdk_services5.serviceError)(SpaceErrorCodes.AUTH_REQUIRED, "Authentication required", SERVICE_NAME)
|
|
13166
13215
|
);
|
|
13167
13216
|
}
|
|
13168
13217
|
if (!name2 || !/^[a-zA-Z0-9_-]+$/.test(name2)) {
|
|
13169
|
-
return (0,
|
|
13170
|
-
(0,
|
|
13218
|
+
return (0, import_sdk_services5.err)(
|
|
13219
|
+
(0, import_sdk_services5.serviceError)(
|
|
13171
13220
|
SpaceErrorCodes.INVALID_NAME,
|
|
13172
13221
|
"Space name must contain only alphanumeric characters, underscores, and hyphens",
|
|
13173
13222
|
SERVICE_NAME
|
|
@@ -13182,30 +13231,26 @@ var SpaceService = class {
|
|
|
13182
13231
|
body: JSON.stringify({ name: name2 })
|
|
13183
13232
|
});
|
|
13184
13233
|
if (!response.ok) {
|
|
13185
|
-
const errorText = await response.text();
|
|
13186
13234
|
if (response.status === 409) {
|
|
13187
|
-
return (0,
|
|
13188
|
-
|
|
13189
|
-
|
|
13190
|
-
|
|
13191
|
-
|
|
13192
|
-
|
|
13193
|
-
);
|
|
13235
|
+
return (0, import_sdk_services5.err)(await serviceHttpError(
|
|
13236
|
+
response,
|
|
13237
|
+
SpaceErrorCodes.ALREADY_EXISTS,
|
|
13238
|
+
`Space "${name2}" already exists`,
|
|
13239
|
+
SERVICE_NAME
|
|
13240
|
+
));
|
|
13194
13241
|
}
|
|
13195
|
-
return (0,
|
|
13196
|
-
|
|
13197
|
-
|
|
13198
|
-
|
|
13199
|
-
|
|
13200
|
-
|
|
13201
|
-
)
|
|
13202
|
-
);
|
|
13242
|
+
return (0, import_sdk_services5.err)(await serviceHttpError(
|
|
13243
|
+
response,
|
|
13244
|
+
SpaceErrorCodes.CREATION_FAILED,
|
|
13245
|
+
"Failed to create space",
|
|
13246
|
+
SERVICE_NAME
|
|
13247
|
+
));
|
|
13203
13248
|
}
|
|
13204
13249
|
const rawData = await response.json();
|
|
13205
13250
|
const validationResult = validateServerCreateSpaceResponse(rawData);
|
|
13206
13251
|
if (!validationResult.ok) {
|
|
13207
|
-
return (0,
|
|
13208
|
-
(0,
|
|
13252
|
+
return (0, import_sdk_services5.err)(
|
|
13253
|
+
(0, import_sdk_services5.serviceError)(
|
|
13209
13254
|
SpaceErrorCodes.CREATION_FAILED,
|
|
13210
13255
|
validationResult.error.message,
|
|
13211
13256
|
SERVICE_NAME,
|
|
@@ -13222,10 +13267,10 @@ var SpaceService = class {
|
|
|
13222
13267
|
};
|
|
13223
13268
|
this.infoCache.set(spaceInfo.id, { info: spaceInfo, cachedAt: Date.now() });
|
|
13224
13269
|
this.notifySpaceRegistered(spaceInfo);
|
|
13225
|
-
return (0,
|
|
13270
|
+
return (0, import_sdk_services5.ok)(spaceInfo);
|
|
13226
13271
|
} catch (error) {
|
|
13227
|
-
return (0,
|
|
13228
|
-
(0,
|
|
13272
|
+
return (0, import_sdk_services5.err)(
|
|
13273
|
+
(0, import_sdk_services5.serviceError)(
|
|
13229
13274
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
13230
13275
|
`Network error creating space: ${String(error)}`,
|
|
13231
13276
|
SERVICE_NAME,
|
|
@@ -13295,10 +13340,10 @@ var SpaceService = class {
|
|
|
13295
13340
|
const spaceId = this.resolveSpaceId(nameOrUri);
|
|
13296
13341
|
const cached = this.infoCache.get(spaceId);
|
|
13297
13342
|
if (cached && Date.now() - cached.cachedAt < this.cacheTTL) {
|
|
13298
|
-
return (0,
|
|
13343
|
+
return (0, import_sdk_services5.ok)(true);
|
|
13299
13344
|
}
|
|
13300
13345
|
const infoResult = await this.getSpaceInfo(spaceId);
|
|
13301
|
-
return (0,
|
|
13346
|
+
return (0, import_sdk_services5.ok)(infoResult.ok);
|
|
13302
13347
|
}
|
|
13303
13348
|
// ===========================================================================
|
|
13304
13349
|
// Space Info
|
|
@@ -13309,11 +13354,11 @@ var SpaceService = class {
|
|
|
13309
13354
|
async getSpaceInfo(spaceId) {
|
|
13310
13355
|
const cached = this.infoCache.get(spaceId);
|
|
13311
13356
|
if (cached && Date.now() - cached.cachedAt < this.cacheTTL) {
|
|
13312
|
-
return (0,
|
|
13357
|
+
return (0, import_sdk_services5.ok)(cached.info);
|
|
13313
13358
|
}
|
|
13314
13359
|
if (!this.session) {
|
|
13315
|
-
return (0,
|
|
13316
|
-
(0,
|
|
13360
|
+
return (0, import_sdk_services5.err)(
|
|
13361
|
+
(0, import_sdk_services5.serviceError)(SpaceErrorCodes.AUTH_REQUIRED, "Authentication required", SERVICE_NAME)
|
|
13317
13362
|
);
|
|
13318
13363
|
}
|
|
13319
13364
|
try {
|
|
@@ -13325,24 +13370,25 @@ var SpaceService = class {
|
|
|
13325
13370
|
});
|
|
13326
13371
|
if (!response.ok) {
|
|
13327
13372
|
if (response.status === 404) {
|
|
13328
|
-
return (0,
|
|
13329
|
-
|
|
13330
|
-
|
|
13331
|
-
|
|
13332
|
-
const errorText = await response.text();
|
|
13333
|
-
return (0, import_sdk_services4.err)(
|
|
13334
|
-
(0, import_sdk_services4.serviceError)(
|
|
13335
|
-
SpaceErrorCodes.NETWORK_ERROR,
|
|
13336
|
-
`Failed to get space info: ${response.status} - ${errorText}`,
|
|
13373
|
+
return (0, import_sdk_services5.err)(await serviceHttpError(
|
|
13374
|
+
response,
|
|
13375
|
+
SpaceErrorCodes.NOT_FOUND,
|
|
13376
|
+
`Space not found: ${spaceId}`,
|
|
13337
13377
|
SERVICE_NAME
|
|
13338
|
-
)
|
|
13339
|
-
|
|
13378
|
+
));
|
|
13379
|
+
}
|
|
13380
|
+
return (0, import_sdk_services5.err)(await serviceHttpError(
|
|
13381
|
+
response,
|
|
13382
|
+
SpaceErrorCodes.NETWORK_ERROR,
|
|
13383
|
+
"Failed to get space info",
|
|
13384
|
+
SERVICE_NAME
|
|
13385
|
+
));
|
|
13340
13386
|
}
|
|
13341
13387
|
const rawData = await response.json();
|
|
13342
13388
|
const validationResult = validateServerSpaceInfoResponse(rawData);
|
|
13343
13389
|
if (!validationResult.ok) {
|
|
13344
|
-
return (0,
|
|
13345
|
-
(0,
|
|
13390
|
+
return (0, import_sdk_services5.err)(
|
|
13391
|
+
(0, import_sdk_services5.serviceError)(
|
|
13346
13392
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
13347
13393
|
validationResult.error.message,
|
|
13348
13394
|
SERVICE_NAME,
|
|
@@ -13360,10 +13406,10 @@ var SpaceService = class {
|
|
|
13360
13406
|
expiresAt: data.expiresAt ? new Date(data.expiresAt) : void 0
|
|
13361
13407
|
};
|
|
13362
13408
|
this.infoCache.set(spaceId, { info: spaceInfo, cachedAt: Date.now() });
|
|
13363
|
-
return (0,
|
|
13409
|
+
return (0, import_sdk_services5.ok)(spaceInfo);
|
|
13364
13410
|
} catch (error) {
|
|
13365
|
-
return (0,
|
|
13366
|
-
(0,
|
|
13411
|
+
return (0, import_sdk_services5.err)(
|
|
13412
|
+
(0, import_sdk_services5.serviceError)(
|
|
13367
13413
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
13368
13414
|
`Network error getting space info: ${String(error)}`,
|
|
13369
13415
|
SERVICE_NAME,
|
|
@@ -13448,20 +13494,18 @@ var SpaceService = class {
|
|
|
13448
13494
|
headers
|
|
13449
13495
|
});
|
|
13450
13496
|
if (!response.ok) {
|
|
13451
|
-
|
|
13452
|
-
|
|
13453
|
-
|
|
13454
|
-
|
|
13455
|
-
|
|
13456
|
-
|
|
13457
|
-
)
|
|
13458
|
-
);
|
|
13497
|
+
return (0, import_sdk_services5.err)(await serviceHttpError(
|
|
13498
|
+
response,
|
|
13499
|
+
SpaceErrorCodes.NETWORK_ERROR,
|
|
13500
|
+
"Failed to list delegations",
|
|
13501
|
+
SERVICE_NAME
|
|
13502
|
+
));
|
|
13459
13503
|
}
|
|
13460
13504
|
const rawData = await response.json();
|
|
13461
13505
|
const validationResult = validateServerDelegationsResponse(rawData);
|
|
13462
13506
|
if (!validationResult.ok) {
|
|
13463
|
-
return (0,
|
|
13464
|
-
(0,
|
|
13507
|
+
return (0, import_sdk_services5.err)(
|
|
13508
|
+
(0, import_sdk_services5.serviceError)(
|
|
13465
13509
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
13466
13510
|
validationResult.error.message,
|
|
13467
13511
|
SERVICE_NAME,
|
|
@@ -13470,10 +13514,10 @@ var SpaceService = class {
|
|
|
13470
13514
|
);
|
|
13471
13515
|
}
|
|
13472
13516
|
const delegations = transformServerDelegations(validationResult.data, spaceId);
|
|
13473
|
-
return (0,
|
|
13517
|
+
return (0, import_sdk_services5.ok)(delegations);
|
|
13474
13518
|
} catch (error) {
|
|
13475
|
-
return (0,
|
|
13476
|
-
(0,
|
|
13519
|
+
return (0, import_sdk_services5.err)(
|
|
13520
|
+
(0, import_sdk_services5.serviceError)(
|
|
13477
13521
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
13478
13522
|
`Network error listing delegations: ${String(error)}`,
|
|
13479
13523
|
SERVICE_NAME
|
|
@@ -13503,20 +13547,18 @@ var SpaceService = class {
|
|
|
13503
13547
|
headers
|
|
13504
13548
|
});
|
|
13505
13549
|
if (!response.ok) {
|
|
13506
|
-
|
|
13507
|
-
|
|
13508
|
-
|
|
13509
|
-
|
|
13510
|
-
|
|
13511
|
-
|
|
13512
|
-
)
|
|
13513
|
-
);
|
|
13550
|
+
return (0, import_sdk_services5.err)(await serviceHttpError(
|
|
13551
|
+
response,
|
|
13552
|
+
SpaceErrorCodes.NETWORK_ERROR,
|
|
13553
|
+
"Failed to list received delegations",
|
|
13554
|
+
SERVICE_NAME
|
|
13555
|
+
));
|
|
13514
13556
|
}
|
|
13515
13557
|
const rawData = await response.json();
|
|
13516
13558
|
const validationResult = validateServerDelegationsResponse(rawData);
|
|
13517
13559
|
if (!validationResult.ok) {
|
|
13518
|
-
return (0,
|
|
13519
|
-
(0,
|
|
13560
|
+
return (0, import_sdk_services5.err)(
|
|
13561
|
+
(0, import_sdk_services5.serviceError)(
|
|
13520
13562
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
13521
13563
|
validationResult.error.message,
|
|
13522
13564
|
SERVICE_NAME,
|
|
@@ -13525,10 +13567,10 @@ var SpaceService = class {
|
|
|
13525
13567
|
);
|
|
13526
13568
|
}
|
|
13527
13569
|
const delegations = transformServerDelegations(validationResult.data, spaceId);
|
|
13528
|
-
return (0,
|
|
13570
|
+
return (0, import_sdk_services5.ok)(delegations);
|
|
13529
13571
|
} catch (error) {
|
|
13530
|
-
return (0,
|
|
13531
|
-
(0,
|
|
13572
|
+
return (0, import_sdk_services5.err)(
|
|
13573
|
+
(0, import_sdk_services5.serviceError)(
|
|
13532
13574
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
13533
13575
|
`Network error listing received delegations: ${String(error)}`,
|
|
13534
13576
|
SERVICE_NAME
|
|
@@ -13540,8 +13582,8 @@ var SpaceService = class {
|
|
|
13540
13582
|
if (self.createDelegationFn) {
|
|
13541
13583
|
return self.createDelegationFn({ ...params, spaceId });
|
|
13542
13584
|
}
|
|
13543
|
-
return (0,
|
|
13544
|
-
(0,
|
|
13585
|
+
return (0, import_sdk_services5.err)(
|
|
13586
|
+
(0, import_sdk_services5.serviceError)(
|
|
13545
13587
|
SpaceErrorCodes.NOT_INITIALIZED,
|
|
13546
13588
|
"Delegation creation requires a createDelegation function. This should be provided by the platform SDK (web-sdk or node-sdk).",
|
|
13547
13589
|
SERVICE_NAME
|
|
@@ -13562,19 +13604,17 @@ var SpaceService = class {
|
|
|
13562
13604
|
body: JSON.stringify({ cid: cid2, spaceId })
|
|
13563
13605
|
});
|
|
13564
13606
|
if (!response.ok) {
|
|
13565
|
-
|
|
13566
|
-
|
|
13567
|
-
|
|
13568
|
-
|
|
13569
|
-
|
|
13570
|
-
|
|
13571
|
-
)
|
|
13572
|
-
);
|
|
13607
|
+
return (0, import_sdk_services5.err)(await serviceHttpError(
|
|
13608
|
+
response,
|
|
13609
|
+
SpaceErrorCodes.NETWORK_ERROR,
|
|
13610
|
+
"Failed to revoke delegation",
|
|
13611
|
+
SERVICE_NAME
|
|
13612
|
+
));
|
|
13573
13613
|
}
|
|
13574
|
-
return (0,
|
|
13614
|
+
return (0, import_sdk_services5.ok)(void 0);
|
|
13575
13615
|
} catch (error) {
|
|
13576
|
-
return (0,
|
|
13577
|
-
(0,
|
|
13616
|
+
return (0, import_sdk_services5.err)(
|
|
13617
|
+
(0, import_sdk_services5.serviceError)(
|
|
13578
13618
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
13579
13619
|
`Network error revoking delegation: ${String(error)}`,
|
|
13580
13620
|
SERVICE_NAME
|
|
@@ -13597,18 +13637,18 @@ var SpaceService = class {
|
|
|
13597
13637
|
if (self.sharingService) {
|
|
13598
13638
|
const result = await self.sharingService.generate(params);
|
|
13599
13639
|
if (!result.ok) {
|
|
13600
|
-
return (0,
|
|
13601
|
-
(0,
|
|
13640
|
+
return (0, import_sdk_services5.err)(
|
|
13641
|
+
(0, import_sdk_services5.serviceError)(
|
|
13602
13642
|
SpaceErrorCodes.NETWORK_ERROR,
|
|
13603
13643
|
result.error.message || "Failed to generate share link",
|
|
13604
13644
|
SERVICE_NAME
|
|
13605
13645
|
)
|
|
13606
13646
|
);
|
|
13607
13647
|
}
|
|
13608
|
-
return (0,
|
|
13648
|
+
return (0, import_sdk_services5.ok)(result.data);
|
|
13609
13649
|
}
|
|
13610
|
-
return (0,
|
|
13611
|
-
(0,
|
|
13650
|
+
return (0, import_sdk_services5.err)(
|
|
13651
|
+
(0, import_sdk_services5.serviceError)(
|
|
13612
13652
|
SpaceErrorCodes.NOT_INITIALIZED,
|
|
13613
13653
|
"SharingService not configured. V2 sharing requires a SharingService instance.",
|
|
13614
13654
|
SERVICE_NAME
|
|
@@ -13616,8 +13656,8 @@ var SpaceService = class {
|
|
|
13616
13656
|
);
|
|
13617
13657
|
},
|
|
13618
13658
|
async list() {
|
|
13619
|
-
return (0,
|
|
13620
|
-
(0,
|
|
13659
|
+
return (0, import_sdk_services5.err)(
|
|
13660
|
+
(0, import_sdk_services5.serviceError)(
|
|
13621
13661
|
SpaceErrorCodes.NOT_INITIALIZED,
|
|
13622
13662
|
"Listing share links is not supported in v2. Share links are self-contained tokens that are not tracked on the server.",
|
|
13623
13663
|
SERVICE_NAME
|
|
@@ -13625,8 +13665,8 @@ var SpaceService = class {
|
|
|
13625
13665
|
);
|
|
13626
13666
|
},
|
|
13627
13667
|
async revoke(token) {
|
|
13628
|
-
return (0,
|
|
13629
|
-
(0,
|
|
13668
|
+
return (0, import_sdk_services5.err)(
|
|
13669
|
+
(0, import_sdk_services5.serviceError)(
|
|
13630
13670
|
SpaceErrorCodes.NOT_INITIALIZED,
|
|
13631
13671
|
"Revoking share links by token is not supported in v2. To revoke access, revoke the underlying delegation using space.delegations.revoke(cid).",
|
|
13632
13672
|
SERVICE_NAME
|
|
@@ -13686,7 +13726,7 @@ var TinyCloud = class _TinyCloud {
|
|
|
13686
13726
|
"hosts are required to initialize services. Provide them via config.hosts or initializeServices()."
|
|
13687
13727
|
);
|
|
13688
13728
|
}
|
|
13689
|
-
this._serviceContext = new
|
|
13729
|
+
this._serviceContext = new import_sdk_services6.ServiceContext({
|
|
13690
13730
|
invoke: effectiveInvoke,
|
|
13691
13731
|
invokeAny: this.config.invokeAny,
|
|
13692
13732
|
fetch: fetchFn ?? this.config.fetch ?? globalThis.fetch.bind(globalThis),
|
|
@@ -13695,10 +13735,10 @@ var TinyCloud = class _TinyCloud {
|
|
|
13695
13735
|
telemetry: this.config.telemetry
|
|
13696
13736
|
});
|
|
13697
13737
|
const serviceConstructors = {
|
|
13698
|
-
kv:
|
|
13699
|
-
sql:
|
|
13700
|
-
duckdb:
|
|
13701
|
-
hooks:
|
|
13738
|
+
kv: import_sdk_services6.KVService,
|
|
13739
|
+
sql: import_sdk_services6.SQLService,
|
|
13740
|
+
duckdb: import_sdk_services6.DuckDbService,
|
|
13741
|
+
hooks: import_sdk_services6.HooksService,
|
|
13702
13742
|
...this.config.services
|
|
13703
13743
|
};
|
|
13704
13744
|
for (const [name2, ServiceClass] of Object.entries(serviceConstructors)) {
|
|
@@ -13962,18 +14002,18 @@ var TinyCloud = class _TinyCloud {
|
|
|
13962
14002
|
const address = this.address();
|
|
13963
14003
|
const chainId = this.chainId();
|
|
13964
14004
|
if (!address || !chainId) {
|
|
13965
|
-
return (0,
|
|
13966
|
-
(0,
|
|
13967
|
-
|
|
14005
|
+
return (0, import_sdk_services6.err)(
|
|
14006
|
+
(0, import_sdk_services6.serviceError)(
|
|
14007
|
+
import_sdk_services6.ErrorCodes.AUTH_REQUIRED,
|
|
13968
14008
|
"Must be signed in to ensure public space",
|
|
13969
14009
|
"public-space"
|
|
13970
14010
|
)
|
|
13971
14011
|
);
|
|
13972
14012
|
}
|
|
13973
14013
|
if (!this._serviceContext) {
|
|
13974
|
-
return (0,
|
|
13975
|
-
(0,
|
|
13976
|
-
|
|
14014
|
+
return (0, import_sdk_services6.err)(
|
|
14015
|
+
(0, import_sdk_services6.serviceError)(
|
|
14016
|
+
import_sdk_services6.ErrorCodes.AUTH_REQUIRED,
|
|
13977
14017
|
"Services not initialized. Call initializeServices() or signIn() first.",
|
|
13978
14018
|
"public-space"
|
|
13979
14019
|
)
|
|
@@ -13983,9 +14023,9 @@ var TinyCloud = class _TinyCloud {
|
|
|
13983
14023
|
try {
|
|
13984
14024
|
const session = this._serviceContext.session;
|
|
13985
14025
|
if (!session) {
|
|
13986
|
-
return (0,
|
|
13987
|
-
(0,
|
|
13988
|
-
|
|
14026
|
+
return (0, import_sdk_services6.err)(
|
|
14027
|
+
(0, import_sdk_services6.serviceError)(
|
|
14028
|
+
import_sdk_services6.ErrorCodes.AUTH_REQUIRED,
|
|
13989
14029
|
"No active session",
|
|
13990
14030
|
"public-space"
|
|
13991
14031
|
)
|
|
@@ -14002,7 +14042,7 @@ var TinyCloud = class _TinyCloud {
|
|
|
14002
14042
|
{ method: "POST", headers, body: JSON.stringify({ spaceId }) }
|
|
14003
14043
|
);
|
|
14004
14044
|
if (response.ok) {
|
|
14005
|
-
return (0,
|
|
14045
|
+
return (0, import_sdk_services6.ok)(void 0);
|
|
14006
14046
|
}
|
|
14007
14047
|
if (response.status === 404) {
|
|
14008
14048
|
const createHeaders = this._serviceContext.invoke(
|
|
@@ -14021,31 +14061,27 @@ var TinyCloud = class _TinyCloud {
|
|
|
14021
14061
|
);
|
|
14022
14062
|
if (!createResponse.ok) {
|
|
14023
14063
|
if (createResponse.status === 409) {
|
|
14024
|
-
return (0,
|
|
14064
|
+
return (0, import_sdk_services6.ok)(void 0);
|
|
14025
14065
|
}
|
|
14026
|
-
|
|
14027
|
-
|
|
14028
|
-
|
|
14029
|
-
|
|
14030
|
-
|
|
14031
|
-
|
|
14032
|
-
)
|
|
14033
|
-
);
|
|
14066
|
+
return (0, import_sdk_services6.err)(await serviceHttpError(
|
|
14067
|
+
createResponse,
|
|
14068
|
+
import_sdk_services6.ErrorCodes.NETWORK_ERROR,
|
|
14069
|
+
"Failed to create public space",
|
|
14070
|
+
"public-space"
|
|
14071
|
+
));
|
|
14034
14072
|
}
|
|
14035
|
-
return (0,
|
|
14073
|
+
return (0, import_sdk_services6.ok)(void 0);
|
|
14036
14074
|
}
|
|
14037
|
-
|
|
14038
|
-
|
|
14039
|
-
|
|
14040
|
-
|
|
14041
|
-
|
|
14042
|
-
|
|
14043
|
-
)
|
|
14044
|
-
);
|
|
14075
|
+
return (0, import_sdk_services6.err)(await serviceHttpError(
|
|
14076
|
+
response,
|
|
14077
|
+
import_sdk_services6.ErrorCodes.NETWORK_ERROR,
|
|
14078
|
+
"Failed to check public space",
|
|
14079
|
+
"public-space"
|
|
14080
|
+
));
|
|
14045
14081
|
} catch (error) {
|
|
14046
|
-
return (0,
|
|
14047
|
-
(0,
|
|
14048
|
-
|
|
14082
|
+
return (0, import_sdk_services6.err)(
|
|
14083
|
+
(0, import_sdk_services6.serviceError)(
|
|
14084
|
+
import_sdk_services6.ErrorCodes.NETWORK_ERROR,
|
|
14049
14085
|
`Network error ensuring public space: ${String(error)}`,
|
|
14050
14086
|
"public-space",
|
|
14051
14087
|
{ cause: error instanceof Error ? error : void 0 }
|
|
@@ -14078,8 +14114,8 @@ var TinyCloud = class _TinyCloud {
|
|
|
14078
14114
|
if (!session) {
|
|
14079
14115
|
throw new Error("No active session. Sign in first.");
|
|
14080
14116
|
}
|
|
14081
|
-
const publicKV = new
|
|
14082
|
-
const publicContext = new
|
|
14117
|
+
const publicKV = new import_sdk_services6.KVService({ prefix: "" });
|
|
14118
|
+
const publicContext = new import_sdk_services6.ServiceContext({
|
|
14083
14119
|
invoke: this._serviceContext.invoke,
|
|
14084
14120
|
fetch: this._serviceContext.fetch,
|
|
14085
14121
|
hosts: this._serviceContext.hosts,
|
|
@@ -14112,23 +14148,19 @@ var TinyCloud = class _TinyCloud {
|
|
|
14112
14148
|
const response = await doFetch(url, { method: "GET" });
|
|
14113
14149
|
if (!response.ok) {
|
|
14114
14150
|
if (response.status === 404) {
|
|
14115
|
-
return (0,
|
|
14116
|
-
|
|
14117
|
-
|
|
14118
|
-
|
|
14119
|
-
|
|
14120
|
-
|
|
14121
|
-
);
|
|
14151
|
+
return (0, import_sdk_services6.err)(await serviceHttpError(
|
|
14152
|
+
response,
|
|
14153
|
+
import_sdk_services6.ErrorCodes.NOT_FOUND,
|
|
14154
|
+
`Key not found: ${key} in space ${spaceId}`,
|
|
14155
|
+
"public-space"
|
|
14156
|
+
));
|
|
14122
14157
|
}
|
|
14123
|
-
|
|
14124
|
-
|
|
14125
|
-
|
|
14126
|
-
|
|
14127
|
-
|
|
14128
|
-
|
|
14129
|
-
{ meta: { status: response.status } }
|
|
14130
|
-
)
|
|
14131
|
-
);
|
|
14158
|
+
return (0, import_sdk_services6.err)(await serviceHttpError(
|
|
14159
|
+
response,
|
|
14160
|
+
import_sdk_services6.ErrorCodes.NETWORK_ERROR,
|
|
14161
|
+
"Failed to read public space",
|
|
14162
|
+
"public-space"
|
|
14163
|
+
));
|
|
14132
14164
|
}
|
|
14133
14165
|
const contentType = response.headers.get("content-type");
|
|
14134
14166
|
let data;
|
|
@@ -14142,11 +14174,11 @@ var TinyCloud = class _TinyCloud {
|
|
|
14142
14174
|
data = text2;
|
|
14143
14175
|
}
|
|
14144
14176
|
}
|
|
14145
|
-
return (0,
|
|
14177
|
+
return (0, import_sdk_services6.ok)(data);
|
|
14146
14178
|
} catch (error) {
|
|
14147
|
-
return (0,
|
|
14148
|
-
(0,
|
|
14149
|
-
|
|
14179
|
+
return (0, import_sdk_services6.err)(
|
|
14180
|
+
(0, import_sdk_services6.serviceError)(
|
|
14181
|
+
import_sdk_services6.ErrorCodes.NETWORK_ERROR,
|
|
14150
14182
|
`Network error reading public space: ${String(error)}`,
|
|
14151
14183
|
"public-space",
|
|
14152
14184
|
{ cause: error instanceof Error ? error : void 0 }
|
|
@@ -14172,7 +14204,7 @@ var TinyCloud = class _TinyCloud {
|
|
|
14172
14204
|
};
|
|
14173
14205
|
|
|
14174
14206
|
// src/account/AccountService.ts
|
|
14175
|
-
var
|
|
14207
|
+
var import_sdk_services7 = require("@tinycloud/sdk-services");
|
|
14176
14208
|
var import_bootstrap3 = require("@tinycloud/bootstrap");
|
|
14177
14209
|
var SERVICE_NAME2 = "account";
|
|
14178
14210
|
var ACCOUNT_INDEX_DB = "account";
|
|
@@ -14185,10 +14217,10 @@ var AccountService = class {
|
|
|
14185
14217
|
* Per-account-space memo for {@link ensureAccountIndex}.
|
|
14186
14218
|
*
|
|
14187
14219
|
* Applying the index migration is a no-op once the schema exists, but the
|
|
14188
|
-
* SQL service still spends
|
|
14189
|
-
*
|
|
14190
|
-
*
|
|
14191
|
-
*
|
|
14220
|
+
* SQL service still spends a round trip discovering that (reading the
|
|
14221
|
+
* applied-migration rows). Account bootstrap touches the index eight times,
|
|
14222
|
+
* so without a memo that is ~7 wasted requests on the cold sign-in path.
|
|
14223
|
+
* The in-flight dedupe inside SQLService
|
|
14192
14224
|
* never helps here: the node SDK builds a fresh SQLService per
|
|
14193
14225
|
* `getAccountDb()` call, so its lock map is always empty.
|
|
14194
14226
|
*
|
|
@@ -14220,7 +14252,7 @@ var AccountService = class {
|
|
|
14220
14252
|
applications.push(applicationFromRecord(key, loaded.data.data));
|
|
14221
14253
|
}
|
|
14222
14254
|
applications.sort((a, b) => a.appId.localeCompare(b.appId));
|
|
14223
|
-
return (0,
|
|
14255
|
+
return (0, import_sdk_services7.ok)(applications);
|
|
14224
14256
|
},
|
|
14225
14257
|
get: async (appId) => {
|
|
14226
14258
|
const kvResult = this.accountKV();
|
|
@@ -14228,14 +14260,14 @@ var AccountService = class {
|
|
|
14228
14260
|
const key = applicationKey(appId);
|
|
14229
14261
|
const loaded = await kvResult.data.get(key);
|
|
14230
14262
|
if (!loaded.ok) return accountErr(loaded.error);
|
|
14231
|
-
return (0,
|
|
14263
|
+
return (0, import_sdk_services7.ok)(applicationFromRecord(key, loaded.data.data));
|
|
14232
14264
|
},
|
|
14233
14265
|
register: async (manifest, options2 = {}) => {
|
|
14234
14266
|
const manifests = Array.isArray(manifest) ? manifest : [manifest];
|
|
14235
14267
|
const request = composeManifestRequest(manifests);
|
|
14236
14268
|
if (request.registryRecords.length === 0) {
|
|
14237
|
-
return (0,
|
|
14238
|
-
(0,
|
|
14269
|
+
return (0, import_sdk_services7.err)(
|
|
14270
|
+
(0, import_sdk_services7.serviceError)(
|
|
14239
14271
|
"INVALID_MANIFEST",
|
|
14240
14272
|
"Manifest did not produce an account application registry record",
|
|
14241
14273
|
SERVICE_NAME2
|
|
@@ -14269,7 +14301,7 @@ var AccountService = class {
|
|
|
14269
14301
|
registered = applicationFromRecord(record2.key, stored);
|
|
14270
14302
|
await this.upsertApplicationIndexQuietly(registered);
|
|
14271
14303
|
}
|
|
14272
|
-
return (0,
|
|
14304
|
+
return (0, import_sdk_services7.ok)(registered);
|
|
14273
14305
|
},
|
|
14274
14306
|
remove: async (appId) => {
|
|
14275
14307
|
const kvResult = this.accountKV();
|
|
@@ -14277,7 +14309,7 @@ var AccountService = class {
|
|
|
14277
14309
|
const removed = await kvResult.data.delete(applicationKey(appId));
|
|
14278
14310
|
if (!removed.ok) return accountErr(removed.error);
|
|
14279
14311
|
await this.deleteApplicationIndexQuietly(appId);
|
|
14280
|
-
return (0,
|
|
14312
|
+
return (0, import_sdk_services7.ok)(void 0);
|
|
14281
14313
|
}
|
|
14282
14314
|
};
|
|
14283
14315
|
this.spaces = {
|
|
@@ -14286,11 +14318,12 @@ var AccountService = class {
|
|
|
14286
14318
|
const indexed = await this.index.spaces.list();
|
|
14287
14319
|
if (indexed.ok && indexed.data.length > 0) return indexed;
|
|
14288
14320
|
if (!indexed.ok && !isMissingIndexError(indexed.error)) return indexed;
|
|
14289
|
-
const canonical = await this.
|
|
14290
|
-
if (canonical.ok
|
|
14291
|
-
|
|
14321
|
+
const canonical = await this.syncAccessibleSpaces({ tolerateStorageFull: true });
|
|
14322
|
+
if (!canonical.ok) return canonical;
|
|
14323
|
+
if (canonical.data.allRegistered && options2.refreshIndex !== false) {
|
|
14324
|
+
await this.replaceSpacesIndexQuietly(canonical.data.spaces);
|
|
14292
14325
|
}
|
|
14293
|
-
return canonical;
|
|
14326
|
+
return (0, import_sdk_services7.ok)(canonical.data.spaces);
|
|
14294
14327
|
}
|
|
14295
14328
|
const kvResult = this.accountKV();
|
|
14296
14329
|
if (!kvResult.ok) return kvResult;
|
|
@@ -14303,14 +14336,14 @@ var AccountService = class {
|
|
|
14303
14336
|
spaces.push(spaceFromRecord(key, loaded.data.data));
|
|
14304
14337
|
}
|
|
14305
14338
|
spaces.sort((a, b) => a.name.localeCompare(b.name) || a.spaceId.localeCompare(b.spaceId));
|
|
14306
|
-
return (0,
|
|
14339
|
+
return (0, import_sdk_services7.ok)(spaces);
|
|
14307
14340
|
},
|
|
14308
14341
|
get: async (spaceId) => {
|
|
14309
14342
|
const kvResult = this.accountKV();
|
|
14310
14343
|
if (!kvResult.ok) return kvResult;
|
|
14311
14344
|
const loaded = await kvResult.data.get(spaceKey(spaceId));
|
|
14312
14345
|
if (!loaded.ok) return accountErr(loaded.error);
|
|
14313
|
-
return (0,
|
|
14346
|
+
return (0, import_sdk_services7.ok)(spaceFromRecord(spaceKey(spaceId), loaded.data.data));
|
|
14314
14347
|
},
|
|
14315
14348
|
register: async (space) => {
|
|
14316
14349
|
await this.config.ensureAccountSpaceHosted?.();
|
|
@@ -14321,7 +14354,7 @@ var AccountService = class {
|
|
|
14321
14354
|
if (!written.ok) return accountErr(written.error);
|
|
14322
14355
|
const registered = spaceFromRecord(spaceKey(stored.space_id), stored);
|
|
14323
14356
|
await this.upsertSpaceIndexQuietly(registered);
|
|
14324
|
-
return (0,
|
|
14357
|
+
return (0, import_sdk_services7.ok)(registered);
|
|
14325
14358
|
},
|
|
14326
14359
|
/**
|
|
14327
14360
|
* Register multiple spaces in one KV batch write + one multi-row index
|
|
@@ -14334,7 +14367,7 @@ var AccountService = class {
|
|
|
14334
14367
|
* leave the first attempt's blocks orphaned.
|
|
14335
14368
|
*/
|
|
14336
14369
|
registerBatch: async (spaces) => {
|
|
14337
|
-
if (spaces.length === 0) return (0,
|
|
14370
|
+
if (spaces.length === 0) return (0, import_sdk_services7.ok)({ spaces: [] });
|
|
14338
14371
|
await this.config.ensureAccountSpaceHosted?.();
|
|
14339
14372
|
const kvResult = this.accountKV();
|
|
14340
14373
|
if (!kvResult.ok) return kvResult;
|
|
@@ -14349,7 +14382,7 @@ var AccountService = class {
|
|
|
14349
14382
|
const batchResult = await kvResult.data.batchPut(items);
|
|
14350
14383
|
if (batchResult.ok) {
|
|
14351
14384
|
await this.upsertSpacesIndexQuietly(registered);
|
|
14352
|
-
return (0,
|
|
14385
|
+
return (0, import_sdk_services7.ok)({ spaces: registered });
|
|
14353
14386
|
}
|
|
14354
14387
|
if (!isAmbiguousBatchFailure(batchResult.error)) {
|
|
14355
14388
|
return accountErr(batchResult.error);
|
|
@@ -14362,8 +14395,8 @@ var AccountService = class {
|
|
|
14362
14395
|
}
|
|
14363
14396
|
}
|
|
14364
14397
|
if (reconcileFailures.length > 0) {
|
|
14365
|
-
return (0,
|
|
14366
|
-
(0,
|
|
14398
|
+
return (0, import_sdk_services7.err)(
|
|
14399
|
+
(0, import_sdk_services7.serviceError)(
|
|
14367
14400
|
"KV_BATCH_RECONCILE_FAILED",
|
|
14368
14401
|
`KV batch write for ${items.length} space(s) failed ambiguously (${batchResult.error.message}) and per-space reconciliation also failed for: ${reconcileFailures.join("; ")}`,
|
|
14369
14402
|
SERVICE_NAME2,
|
|
@@ -14375,18 +14408,61 @@ var AccountService = class {
|
|
|
14375
14408
|
`[AccountService] KV batch write for ${items.length} space(s) returned an ambiguous error and was reconciled via per-space fallback. Original error: ${batchResult.error.message}`
|
|
14376
14409
|
);
|
|
14377
14410
|
await this.upsertSpacesIndexQuietly(registered);
|
|
14378
|
-
return (0,
|
|
14411
|
+
return (0, import_sdk_services7.ok)({ spaces: registered, recoveredFromBatchError: batchResult.error });
|
|
14379
14412
|
},
|
|
14380
|
-
|
|
14381
|
-
|
|
14382
|
-
|
|
14383
|
-
|
|
14384
|
-
|
|
14385
|
-
|
|
14386
|
-
|
|
14387
|
-
|
|
14413
|
+
/**
|
|
14414
|
+
* Register only spaces without a registry record (TC-800). Existing
|
|
14415
|
+
* records, including renamed or archived ones, are kept byte-for-byte.
|
|
14416
|
+
* Bootstrap repair uses this on populated accounts.
|
|
14417
|
+
*/
|
|
14418
|
+
registerMissing: async (spaces) => {
|
|
14419
|
+
if (spaces.length === 0) return (0, import_sdk_services7.ok)([]);
|
|
14420
|
+
await this.config.ensureAccountSpaceHosted?.();
|
|
14421
|
+
const kvResult = this.accountKV();
|
|
14422
|
+
if (!kvResult.ok) return kvResult;
|
|
14423
|
+
const kv = kvResult.data;
|
|
14424
|
+
const stored = spaces.map((space) => spaceRecordFromInput(space));
|
|
14425
|
+
const keys = stored.map((record2) => spaceKey(record2.space_id));
|
|
14426
|
+
const read2 = await kv.batchGet(keys);
|
|
14427
|
+
if (!read2.ok) return accountErr(read2.error);
|
|
14428
|
+
const byKey = new Map(read2.data.results.map((result) => [result.key, result.result]));
|
|
14429
|
+
const final = new Array(keys.length);
|
|
14430
|
+
const missing = [];
|
|
14431
|
+
for (let i = 0; i < keys.length; i++) {
|
|
14432
|
+
const key = keys[i];
|
|
14433
|
+
const result = byKey.get(key);
|
|
14434
|
+
if (!result) {
|
|
14435
|
+
return (0, import_sdk_services7.err)((0, import_sdk_services7.serviceError)(
|
|
14436
|
+
import_sdk_services7.ErrorCodes.NETWORK_ERROR,
|
|
14437
|
+
`KV batch read omitted requested key ${JSON.stringify(key)}`,
|
|
14438
|
+
SERVICE_NAME2
|
|
14439
|
+
));
|
|
14440
|
+
}
|
|
14441
|
+
if (result.ok) {
|
|
14442
|
+
final[i] = spaceFromRecord(key, result.data.data);
|
|
14443
|
+
} else if (result.error.code === import_sdk_services7.ErrorCodes.KV_NOT_FOUND) {
|
|
14444
|
+
missing.push({ index: i, key, record: stored[i] });
|
|
14445
|
+
} else {
|
|
14446
|
+
return accountErr(result.error);
|
|
14447
|
+
}
|
|
14388
14448
|
}
|
|
14389
|
-
|
|
14449
|
+
const creates = await Promise.all(missing.map(async ({ index, key, record: record2 }) => {
|
|
14450
|
+
const written = await kv.put(key, record2, { ifNoneMatch: "*" });
|
|
14451
|
+
if (written.ok) return { index, result: (0, import_sdk_services7.ok)(spaceFromRecord(key, record2)) };
|
|
14452
|
+
const raced = await kv.get(key);
|
|
14453
|
+
if (raced.ok) return { index, result: (0, import_sdk_services7.ok)(spaceFromRecord(key, raced.data.data)) };
|
|
14454
|
+
return { index, result: (0, import_sdk_services7.err)(written.error) };
|
|
14455
|
+
}));
|
|
14456
|
+
for (const { index, result } of creates) {
|
|
14457
|
+
if (!result.ok) return accountErr(result.error);
|
|
14458
|
+
final[index] = result.data;
|
|
14459
|
+
}
|
|
14460
|
+
await this.upsertSpacesIndexQuietly(final);
|
|
14461
|
+
return (0, import_sdk_services7.ok)(final);
|
|
14462
|
+
},
|
|
14463
|
+
syncAccessible: async () => {
|
|
14464
|
+
const synced = await this.syncAccessibleSpaces({ tolerateStorageFull: false });
|
|
14465
|
+
return synced.ok ? (0, import_sdk_services7.ok)(synced.data.spaces) : synced;
|
|
14390
14466
|
},
|
|
14391
14467
|
remove: async (spaceId) => {
|
|
14392
14468
|
const kvResult = this.accountKV();
|
|
@@ -14394,21 +14470,21 @@ var AccountService = class {
|
|
|
14394
14470
|
const removed = await kvResult.data.delete(spaceKey(spaceId));
|
|
14395
14471
|
if (!removed.ok) return accountErr(removed.error);
|
|
14396
14472
|
await this.deleteSpaceIndexQuietly(spaceId);
|
|
14397
|
-
return (0,
|
|
14473
|
+
return (0, import_sdk_services7.ok)(void 0);
|
|
14398
14474
|
}
|
|
14399
14475
|
};
|
|
14400
14476
|
this.delegations = {
|
|
14401
14477
|
query: async (options2 = {}) => {
|
|
14402
14478
|
const manager = this.config.getDelegationManager?.();
|
|
14403
14479
|
if (!manager) {
|
|
14404
|
-
return (0,
|
|
14480
|
+
return (0, import_sdk_services7.err)((0, import_sdk_services7.serviceError)(
|
|
14405
14481
|
"NOT_INITIALIZED",
|
|
14406
14482
|
"Delegation history requires an authenticated delegation manager",
|
|
14407
14483
|
SERVICE_NAME2
|
|
14408
14484
|
));
|
|
14409
14485
|
}
|
|
14410
14486
|
const queried = await manager.query(options2);
|
|
14411
|
-
return queried.ok ? (0,
|
|
14487
|
+
return queried.ok ? (0, import_sdk_services7.ok)(queried.data) : accountErr(queried.error);
|
|
14412
14488
|
},
|
|
14413
14489
|
list: async (options2 = {}) => {
|
|
14414
14490
|
if (options2.preferIndex) {
|
|
@@ -14442,17 +14518,17 @@ var AccountService = class {
|
|
|
14442
14518
|
}
|
|
14443
14519
|
}
|
|
14444
14520
|
delegations.sort((a, b) => a.spaceId.localeCompare(b.spaceId) || a.cid.localeCompare(b.cid));
|
|
14445
|
-
return (0,
|
|
14521
|
+
return (0, import_sdk_services7.ok)(delegations);
|
|
14446
14522
|
},
|
|
14447
14523
|
revoke: async (input) => {
|
|
14448
14524
|
const cid2 = typeof input === "string" ? input : input.cid;
|
|
14449
14525
|
const manager = this.config.getDelegationManager?.();
|
|
14450
14526
|
if (manager) {
|
|
14451
14527
|
const revoked2 = await manager.revoke(cid2);
|
|
14452
|
-
return revoked2.ok ? (0,
|
|
14528
|
+
return revoked2.ok ? (0, import_sdk_services7.ok)(revoked2.data) : accountErr(revoked2.error);
|
|
14453
14529
|
}
|
|
14454
14530
|
if (typeof input === "string") {
|
|
14455
|
-
return (0,
|
|
14531
|
+
return (0, import_sdk_services7.err)((0, import_sdk_services7.serviceError)(
|
|
14456
14532
|
"NOT_INITIALIZED",
|
|
14457
14533
|
"CID-only revocation requires an authenticated delegation manager",
|
|
14458
14534
|
SERVICE_NAME2
|
|
@@ -14462,7 +14538,7 @@ var AccountService = class {
|
|
|
14462
14538
|
if (!space.ok) return space;
|
|
14463
14539
|
const revoked = await this.config.getSpaces().get(space.data.id).delegations.revoke(cid2);
|
|
14464
14540
|
if (!revoked.ok) return accountErr(revoked.error);
|
|
14465
|
-
return (0,
|
|
14541
|
+
return (0, import_sdk_services7.ok)(void 0);
|
|
14466
14542
|
}
|
|
14467
14543
|
};
|
|
14468
14544
|
this.index = {
|
|
@@ -14471,7 +14547,7 @@ var AccountService = class {
|
|
|
14471
14547
|
if (!dbResult.ok) return dbResult;
|
|
14472
14548
|
const schema = await this.ensureAccountIndex(dbResult.data);
|
|
14473
14549
|
if (!schema.ok) return schema;
|
|
14474
|
-
return (0,
|
|
14550
|
+
return (0, import_sdk_services7.ok)({ database: ACCOUNT_INDEX_DB });
|
|
14475
14551
|
},
|
|
14476
14552
|
rebuild: async () => {
|
|
14477
14553
|
const dbResult = this.accountDb();
|
|
@@ -14553,7 +14629,7 @@ var AccountService = class {
|
|
|
14553
14629
|
];
|
|
14554
14630
|
const rebuilt = await dbResult.data.batch(statements);
|
|
14555
14631
|
if (!rebuilt.ok) return accountErr(rebuilt.error);
|
|
14556
|
-
return (0,
|
|
14632
|
+
return (0, import_sdk_services7.ok)({
|
|
14557
14633
|
database: ACCOUNT_INDEX_DB,
|
|
14558
14634
|
applications: applications.data.length,
|
|
14559
14635
|
spaces: spaces.data.length,
|
|
@@ -14569,7 +14645,7 @@ var AccountService = class {
|
|
|
14569
14645
|
"SELECT applications.app_id, name, description, updated_at, manifest_json, application_state.manifest_hash FROM applications LEFT JOIN application_state ON applications.app_id = application_state.app_id ORDER BY applications.app_id"
|
|
14570
14646
|
);
|
|
14571
14647
|
if (!queried.ok) return accountErr(queried.error);
|
|
14572
|
-
return (0,
|
|
14648
|
+
return (0, import_sdk_services7.ok)(queried.data.rows.map(indexedApplicationFromRow));
|
|
14573
14649
|
}
|
|
14574
14650
|
},
|
|
14575
14651
|
spaces: {
|
|
@@ -14580,7 +14656,7 @@ var AccountService = class {
|
|
|
14580
14656
|
"SELECT space_id, name, owner_did, type, permissions_json, status, registered_at, updated_at, expires_at FROM spaces ORDER BY name, space_id"
|
|
14581
14657
|
);
|
|
14582
14658
|
if (!queried.ok) return accountErr(queried.error);
|
|
14583
|
-
return (0,
|
|
14659
|
+
return (0, import_sdk_services7.ok)(queried.data.rows.map(indexedSpaceFromRow));
|
|
14584
14660
|
}
|
|
14585
14661
|
},
|
|
14586
14662
|
delegations: {
|
|
@@ -14602,7 +14678,7 @@ var AccountService = class {
|
|
|
14602
14678
|
params
|
|
14603
14679
|
);
|
|
14604
14680
|
if (!queried.ok) return accountErr(queried.error);
|
|
14605
|
-
return (0,
|
|
14681
|
+
return (0, import_sdk_services7.ok)(queried.data.rows.map(indexedDelegationFromRow));
|
|
14606
14682
|
}
|
|
14607
14683
|
},
|
|
14608
14684
|
query: async (sql, params) => {
|
|
@@ -14610,7 +14686,7 @@ var AccountService = class {
|
|
|
14610
14686
|
if (!dbResult.ok) return dbResult;
|
|
14611
14687
|
const queried = await dbResult.data.query(sql, params);
|
|
14612
14688
|
if (!queried.ok) return accountErr(queried.error);
|
|
14613
|
-
return (0,
|
|
14689
|
+
return (0, import_sdk_services7.ok)(queried.data);
|
|
14614
14690
|
},
|
|
14615
14691
|
status: async () => {
|
|
14616
14692
|
const dbResult = this.accountDb();
|
|
@@ -14620,11 +14696,11 @@ var AccountService = class {
|
|
|
14620
14696
|
);
|
|
14621
14697
|
if (!queried.ok) {
|
|
14622
14698
|
if (isMissingIndexError(queried.error)) {
|
|
14623
|
-
return (0,
|
|
14699
|
+
return (0, import_sdk_services7.ok)({ database: ACCOUNT_INDEX_DB, state: "missing", sources: [] });
|
|
14624
14700
|
}
|
|
14625
14701
|
return accountErr(queried.error);
|
|
14626
14702
|
}
|
|
14627
|
-
return (0,
|
|
14703
|
+
return (0, import_sdk_services7.ok)({
|
|
14628
14704
|
database: ACCOUNT_INDEX_DB,
|
|
14629
14705
|
state: "ready",
|
|
14630
14706
|
sources: queried.data.rows.map(([source, syncedAt, count]) => ({
|
|
@@ -14643,7 +14719,7 @@ var AccountService = class {
|
|
|
14643
14719
|
if (!delegations.ok) return delegations;
|
|
14644
14720
|
const spaces = await this.spaces.list();
|
|
14645
14721
|
if (!spaces.ok) return spaces;
|
|
14646
|
-
return (0,
|
|
14722
|
+
return (0, import_sdk_services7.ok)({
|
|
14647
14723
|
did: this.config.getDid(),
|
|
14648
14724
|
host: this.config.getHost(),
|
|
14649
14725
|
primarySpaceId: this.config.getPrimarySpaceId(),
|
|
@@ -14657,28 +14733,28 @@ var AccountService = class {
|
|
|
14657
14733
|
accountKV() {
|
|
14658
14734
|
const accountSpaceId = this.config.getAccountSpaceId();
|
|
14659
14735
|
if (!accountSpaceId) {
|
|
14660
|
-
return (0,
|
|
14661
|
-
(0,
|
|
14736
|
+
return (0, import_sdk_services7.err)(
|
|
14737
|
+
(0, import_sdk_services7.serviceError)(
|
|
14662
14738
|
"ACCOUNT_SPACE_UNAVAILABLE",
|
|
14663
14739
|
"Account space is unavailable. Sign in with a wallet-backed profile first.",
|
|
14664
14740
|
SERVICE_NAME2
|
|
14665
14741
|
)
|
|
14666
14742
|
);
|
|
14667
14743
|
}
|
|
14668
|
-
return (0,
|
|
14744
|
+
return (0, import_sdk_services7.ok)(this.config.getSpaces().get(accountSpaceId).kv);
|
|
14669
14745
|
}
|
|
14670
14746
|
accountDb() {
|
|
14671
14747
|
const db = this.config.getAccountDb?.();
|
|
14672
14748
|
if (!db) {
|
|
14673
|
-
return (0,
|
|
14674
|
-
(0,
|
|
14749
|
+
return (0, import_sdk_services7.err)(
|
|
14750
|
+
(0, import_sdk_services7.serviceError)(
|
|
14675
14751
|
"ACCOUNT_INDEX_UNAVAILABLE",
|
|
14676
14752
|
"Account index database is unavailable. Sign in with a wallet-backed profile first.",
|
|
14677
14753
|
SERVICE_NAME2
|
|
14678
14754
|
)
|
|
14679
14755
|
);
|
|
14680
14756
|
}
|
|
14681
|
-
return (0,
|
|
14757
|
+
return (0, import_sdk_services7.ok)(db);
|
|
14682
14758
|
}
|
|
14683
14759
|
async indexHasApplicationHash(appId, manifestHash) {
|
|
14684
14760
|
const dbResult = this.accountDb();
|
|
@@ -14696,7 +14772,7 @@ var AccountService = class {
|
|
|
14696
14772
|
}
|
|
14697
14773
|
async upsertApplicationIndex(app) {
|
|
14698
14774
|
const dbResult = this.accountDb();
|
|
14699
|
-
if (!dbResult.ok) return (0,
|
|
14775
|
+
if (!dbResult.ok) return (0, import_sdk_services7.ok)(void 0);
|
|
14700
14776
|
const schema = await this.ensureAccountIndex(dbResult.data);
|
|
14701
14777
|
if (!schema.ok) return schema;
|
|
14702
14778
|
const updatedAt = app.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -14718,14 +14794,14 @@ var AccountService = class {
|
|
|
14718
14794
|
}
|
|
14719
14795
|
]);
|
|
14720
14796
|
if (!written.ok) return accountErr(written.error);
|
|
14721
|
-
return (0,
|
|
14797
|
+
return (0, import_sdk_services7.ok)(void 0);
|
|
14722
14798
|
}
|
|
14723
14799
|
async deleteApplicationIndexQuietly(appId) {
|
|
14724
14800
|
await ignoreIndexFailure(() => this.deleteApplicationIndex(appId));
|
|
14725
14801
|
}
|
|
14726
14802
|
async deleteApplicationIndex(appId) {
|
|
14727
14803
|
const dbResult = this.accountDb();
|
|
14728
|
-
if (!dbResult.ok) return (0,
|
|
14804
|
+
if (!dbResult.ok) return (0, import_sdk_services7.ok)(void 0);
|
|
14729
14805
|
const schema = await this.ensureAccountIndex(dbResult.data);
|
|
14730
14806
|
if (!schema.ok) return schema;
|
|
14731
14807
|
const deleted = await dbResult.data.batch([
|
|
@@ -14733,14 +14809,14 @@ var AccountService = class {
|
|
|
14733
14809
|
{ sql: "DELETE FROM application_state WHERE app_id = ?", params: [appId] }
|
|
14734
14810
|
]);
|
|
14735
14811
|
if (!deleted.ok) return accountErr(deleted.error);
|
|
14736
|
-
return (0,
|
|
14812
|
+
return (0, import_sdk_services7.ok)(void 0);
|
|
14737
14813
|
}
|
|
14738
14814
|
async upsertSpaceIndexQuietly(space) {
|
|
14739
14815
|
await ignoreIndexFailure(() => this.upsertSpaceIndex(space));
|
|
14740
14816
|
}
|
|
14741
14817
|
async upsertSpaceIndex(space) {
|
|
14742
14818
|
const dbResult = this.accountDb();
|
|
14743
|
-
if (!dbResult.ok) return (0,
|
|
14819
|
+
if (!dbResult.ok) return (0, import_sdk_services7.ok)(void 0);
|
|
14744
14820
|
const schema = await this.ensureAccountIndex(dbResult.data);
|
|
14745
14821
|
if (!schema.ok) return schema;
|
|
14746
14822
|
const updatedAt = space.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -14761,7 +14837,7 @@ var AccountService = class {
|
|
|
14761
14837
|
}
|
|
14762
14838
|
]);
|
|
14763
14839
|
if (!written.ok) return accountErr(written.error);
|
|
14764
|
-
return (0,
|
|
14840
|
+
return (0, import_sdk_services7.ok)(void 0);
|
|
14765
14841
|
}
|
|
14766
14842
|
async upsertSpacesIndexQuietly(spaces) {
|
|
14767
14843
|
await ignoreIndexFailure(() => this.upsertSpacesIndex(spaces));
|
|
@@ -14775,9 +14851,9 @@ var AccountService = class {
|
|
|
14775
14851
|
* atomically: all rows or none.
|
|
14776
14852
|
*/
|
|
14777
14853
|
async upsertSpacesIndex(spaces) {
|
|
14778
|
-
if (spaces.length === 0) return (0,
|
|
14854
|
+
if (spaces.length === 0) return (0, import_sdk_services7.ok)(void 0);
|
|
14779
14855
|
const dbResult = this.accountDb();
|
|
14780
|
-
if (!dbResult.ok) return (0,
|
|
14856
|
+
if (!dbResult.ok) return (0, import_sdk_services7.ok)(void 0);
|
|
14781
14857
|
const schema = await this.ensureAccountIndex(dbResult.data);
|
|
14782
14858
|
if (!schema.ok) return schema;
|
|
14783
14859
|
const placeholders = spaces.map(() => "(?, ?, ?, ?, ?, ?, ?, ?, ?)").join(", ");
|
|
@@ -14802,32 +14878,60 @@ var AccountService = class {
|
|
|
14802
14878
|
}
|
|
14803
14879
|
]);
|
|
14804
14880
|
if (!written.ok) return accountErr(written.error);
|
|
14805
|
-
return (0,
|
|
14881
|
+
return (0, import_sdk_services7.ok)(void 0);
|
|
14806
14882
|
}
|
|
14807
14883
|
async deleteSpaceIndexQuietly(spaceId) {
|
|
14808
14884
|
await ignoreIndexFailure(() => this.deleteSpaceIndex(spaceId));
|
|
14809
14885
|
}
|
|
14810
14886
|
async deleteSpaceIndex(spaceId) {
|
|
14811
14887
|
const dbResult = this.accountDb();
|
|
14812
|
-
if (!dbResult.ok) return (0,
|
|
14888
|
+
if (!dbResult.ok) return (0, import_sdk_services7.ok)(void 0);
|
|
14813
14889
|
const schema = await this.ensureAccountIndex(dbResult.data);
|
|
14814
14890
|
if (!schema.ok) return schema;
|
|
14815
14891
|
const deleted = await dbResult.data.batch([
|
|
14816
14892
|
{ sql: "DELETE FROM spaces WHERE space_id = ?", params: [spaceId] }
|
|
14817
14893
|
]);
|
|
14818
14894
|
if (!deleted.ok) return accountErr(deleted.error);
|
|
14819
|
-
return (0,
|
|
14895
|
+
return (0, import_sdk_services7.ok)(void 0);
|
|
14896
|
+
}
|
|
14897
|
+
/**
|
|
14898
|
+
* Register every space the session can reach and return them. With
|
|
14899
|
+
* `tolerateStorageFull`, a full account space stops the registration
|
|
14900
|
+
* writes but not the listing: the remaining spaces are returned as they
|
|
14901
|
+
* would have been registered, and `allRegistered` is false.
|
|
14902
|
+
*/
|
|
14903
|
+
async syncAccessibleSpaces(options2) {
|
|
14904
|
+
const listed = await this.config.getSpaces().list();
|
|
14905
|
+
if (!listed.ok) return accountErr(listed.error);
|
|
14906
|
+
const spaces = [];
|
|
14907
|
+
let allRegistered = true;
|
|
14908
|
+
for (const space of listed.data) {
|
|
14909
|
+
if (allRegistered) {
|
|
14910
|
+
const result = await this.spaces.register(space);
|
|
14911
|
+
if (result.ok) {
|
|
14912
|
+
spaces.push(result.data);
|
|
14913
|
+
continue;
|
|
14914
|
+
}
|
|
14915
|
+
if (!options2.tolerateStorageFull || !(0, import_sdk_services7.isStorageFullError)(result.error)) {
|
|
14916
|
+
return result;
|
|
14917
|
+
}
|
|
14918
|
+
allRegistered = false;
|
|
14919
|
+
}
|
|
14920
|
+
const record2 = spaceRecordFromInput(space);
|
|
14921
|
+
spaces.push(spaceFromRecord(spaceKey(record2.space_id), record2));
|
|
14922
|
+
}
|
|
14923
|
+
return (0, import_sdk_services7.ok)({ spaces, allRegistered });
|
|
14820
14924
|
}
|
|
14821
14925
|
async resolveSpace(space) {
|
|
14822
14926
|
const listed = await this.config.getSpaces().list();
|
|
14823
14927
|
if (!listed.ok) return accountErr(listed.error);
|
|
14824
14928
|
const found = listed.data.find((candidate) => candidate.id === space || candidate.name === space);
|
|
14825
14929
|
if (!found) {
|
|
14826
|
-
return (0,
|
|
14827
|
-
(0,
|
|
14930
|
+
return (0, import_sdk_services7.err)(
|
|
14931
|
+
(0, import_sdk_services7.serviceError)("SPACE_NOT_FOUND", `No account space found for ${JSON.stringify(space)}`, SERVICE_NAME2)
|
|
14828
14932
|
);
|
|
14829
14933
|
}
|
|
14830
|
-
return (0,
|
|
14934
|
+
return (0, import_sdk_services7.ok)(found);
|
|
14831
14935
|
}
|
|
14832
14936
|
async replaceApplicationsIndexQuietly(applications) {
|
|
14833
14937
|
await ignoreIndexFailure(async () => {
|
|
@@ -14969,7 +15073,7 @@ var AccountService = class {
|
|
|
14969
15073
|
]
|
|
14970
15074
|
});
|
|
14971
15075
|
if (!migrated.ok) return accountErr(migrated.error);
|
|
14972
|
-
return (0,
|
|
15076
|
+
return (0, import_sdk_services7.ok)(void 0);
|
|
14973
15077
|
}
|
|
14974
15078
|
};
|
|
14975
15079
|
function applicationKey(appId) {
|
|
@@ -15125,17 +15229,17 @@ function mapDelegation(delegation, space, direction) {
|
|
|
15125
15229
|
};
|
|
15126
15230
|
}
|
|
15127
15231
|
function accountErr(error) {
|
|
15128
|
-
return (0,
|
|
15232
|
+
return (0, import_sdk_services7.err)((0, import_sdk_services7.serviceError)(error.code, error.message, SERVICE_NAME2, { cause: error.cause, meta: error.meta }));
|
|
15129
15233
|
}
|
|
15130
15234
|
function isMissingIndexError(error) {
|
|
15131
15235
|
return /no such table:/i.test(error.message);
|
|
15132
15236
|
}
|
|
15133
15237
|
var AMBIGUOUS_WRITE_STATUSES = /* @__PURE__ */ new Set([500, 502, 503, 504, 520, 522, 524]);
|
|
15134
15238
|
function isAmbiguousBatchFailure(error) {
|
|
15135
|
-
if (error.code ===
|
|
15239
|
+
if (error.code === import_sdk_services7.ErrorCodes.NETWORK_ERROR || error.code === import_sdk_services7.ErrorCodes.TIMEOUT) {
|
|
15136
15240
|
return error.meta?.requestMayHaveDispatched === true;
|
|
15137
15241
|
}
|
|
15138
|
-
if (error.code ===
|
|
15242
|
+
if (error.code === import_sdk_services7.ErrorCodes.KV_WRITE_FAILED) {
|
|
15139
15243
|
const status = error.meta?.status;
|
|
15140
15244
|
return typeof status === "number" && AMBIGUOUS_WRITE_STATUSES.has(status);
|
|
15141
15245
|
}
|
|
@@ -15149,7 +15253,7 @@ async function ignoreIndexFailure(task) {
|
|
|
15149
15253
|
}
|
|
15150
15254
|
|
|
15151
15255
|
// src/index.ts
|
|
15152
|
-
var
|
|
15256
|
+
var import_sdk_services9 = require("@tinycloud/sdk-services");
|
|
15153
15257
|
|
|
15154
15258
|
// src/space.ts
|
|
15155
15259
|
async function fetchPeerId(host, spaceId) {
|
|
@@ -15158,7 +15262,9 @@ async function fetchPeerId(host, spaceId) {
|
|
|
15158
15262
|
);
|
|
15159
15263
|
if (!res.ok) {
|
|
15160
15264
|
const error = await res.text().catch(() => res.statusText);
|
|
15161
|
-
throw new Error(`Failed to get peer ID: ${res.status} - ${error}`)
|
|
15265
|
+
throw Object.assign(new Error(`Failed to get peer ID: ${res.status} - ${error}`), {
|
|
15266
|
+
status: res.status
|
|
15267
|
+
});
|
|
15162
15268
|
}
|
|
15163
15269
|
return res.text();
|
|
15164
15270
|
}
|
|
@@ -15248,7 +15354,7 @@ async function postSessionActivation(host, delegationHeader) {
|
|
|
15248
15354
|
}
|
|
15249
15355
|
|
|
15250
15356
|
// src/authorization/CapabilityKeyRegistry.ts
|
|
15251
|
-
var
|
|
15357
|
+
var import_sdk_services8 = require("@tinycloud/sdk-services");
|
|
15252
15358
|
var SERVICE_NAME3 = "capability-key-registry";
|
|
15253
15359
|
var CapabilityKeyRegistryErrorCodes = {
|
|
15254
15360
|
/** Key not found in registry */
|
|
@@ -15473,8 +15579,8 @@ var CapabilityKeyRegistry = class {
|
|
|
15473
15579
|
revokeDelegation(cid2) {
|
|
15474
15580
|
const stored = this.store.byCid.get(cid2);
|
|
15475
15581
|
if (!stored || stored.length === 0) {
|
|
15476
|
-
return (0,
|
|
15477
|
-
(0,
|
|
15582
|
+
return (0, import_sdk_services8.err)(
|
|
15583
|
+
(0, import_sdk_services8.serviceError)(
|
|
15478
15584
|
CapabilityKeyRegistryErrorCodes.KEY_NOT_FOUND,
|
|
15479
15585
|
`Delegation not found: ${cid2}`,
|
|
15480
15586
|
SERVICE_NAME3
|
|
@@ -15494,7 +15600,7 @@ var CapabilityKeyRegistry = class {
|
|
|
15494
15600
|
}
|
|
15495
15601
|
}
|
|
15496
15602
|
}
|
|
15497
|
-
return (0,
|
|
15603
|
+
return (0, import_sdk_services8.ok)(void 0);
|
|
15498
15604
|
}
|
|
15499
15605
|
// ===========================================================================
|
|
15500
15606
|
// Search
|