@mdbase-dev/connect 0.1.0-beta.83 → 0.1.0-beta.84
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/browser/integrity.json +1 -1
- package/dist/browser/mdbase-connect.min.js +3 -3
- package/dist/browser/mdbase-connect.min.js.sha384 +1 -1
- package/dist/connection-transport.js +7 -4
- package/dist/hosted-operation-response.d.ts +5 -0
- package/dist/hosted-operation-response.js +26 -0
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
sha384-
|
|
1
|
+
sha384-l1syvCOespqx2xGAwlKWRSmphqrCw5zoEJLrsvcdCqadK8gQTQcTZJuGTJ7NtIZm
|
|
@@ -12,6 +12,7 @@ import { sendAuthoritySyncRequest } from "./authority-sync-request.js";
|
|
|
12
12
|
import { freshEncryptedRequest } from "./fresh-encrypted-request.js";
|
|
13
13
|
import { isExplicitConnectorBusyResponse, retryExplicitConnectorBusy } from "./transient-retry.js";
|
|
14
14
|
import { probeLoopbackAccess, tokenSupportsDirectAccess } from "./direct-access.js";
|
|
15
|
+
import { decodeHostedOperationResponse } from "./hosted-operation-response.js";
|
|
15
16
|
export class ConnectionTransport {
|
|
16
17
|
serverUrl;
|
|
17
18
|
storage;
|
|
@@ -192,17 +193,19 @@ export class ConnectionTransport {
|
|
|
192
193
|
clearPending: (requestId) => this.clearPendingMutation(requestId),
|
|
193
194
|
retry: (pending, knownRejected) => this.performOperationWithinBudget(operation, input, options, pending, freshReadRetried, connectorBusyRetries + 1, knownRejected)
|
|
194
195
|
});
|
|
195
|
-
let
|
|
196
|
+
let decoded;
|
|
196
197
|
try {
|
|
197
|
-
|
|
198
|
+
decoded = await decodeHostedOperationResponse(response, token.authority !== undefined);
|
|
198
199
|
}
|
|
199
200
|
catch (cause) {
|
|
200
201
|
if (attempt.pendingMutation)
|
|
201
202
|
throw unknownMutationOutcome(attempt.requestId, cause);
|
|
202
|
-
throw
|
|
203
|
+
throw cause;
|
|
203
204
|
}
|
|
205
|
+
const body = decoded.body;
|
|
204
206
|
if (!response.ok) {
|
|
205
|
-
const error =
|
|
207
|
+
const error = decoded.httpError
|
|
208
|
+
?? apiError(body, "operation_failed", "Collection operation failed.", response.status);
|
|
206
209
|
const recovery = await retryBusy(error);
|
|
207
210
|
if (recovery.retried)
|
|
208
211
|
return recovery.result;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { connectError, serverConnectError } from "./errors.js";
|
|
2
|
+
import { decodeJsonResponse } from "./runtime-utils.js";
|
|
3
|
+
export async function decodeHostedOperationResponse(response, hosted) {
|
|
4
|
+
try {
|
|
5
|
+
return {
|
|
6
|
+
body: await decodeJsonResponse(response, "invalid_operation_response", "The collection authority returned a response that is not valid JSON.")
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
catch (cause) {
|
|
10
|
+
if (!response.ok && hosted && isDefinitiveHostedHttpRejection(response.status)) {
|
|
11
|
+
return {
|
|
12
|
+
body: undefined,
|
|
13
|
+
httpError: serverConnectError("operation_failed", "Collection operation failed.", {
|
|
14
|
+
status: response.status,
|
|
15
|
+
operationOutcome: "rejected"
|
|
16
|
+
})
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
throw connectError("invalid_operation_response", "The collection authority returned a response that is not valid JSON.", { cause });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function isDefinitiveHostedHttpRejection(status) {
|
|
23
|
+
return status >= 400
|
|
24
|
+
&& status < 500
|
|
25
|
+
&& ![408, 425, 429].includes(status);
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdbase-dev/connect",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.84",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"README.md"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@mdbase-dev/connect-protocol": "0.1.0-beta.
|
|
36
|
+
"@mdbase-dev/connect-protocol": "0.1.0-beta.84"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"esbuild": "^0.28.1",
|