@mdbase-dev/connect 0.1.0-beta.21 → 0.1.0-beta.23
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/README.md +108 -38
- package/dist/authorization-url.d.ts +2 -1
- package/dist/authorization-url.js +5 -7
- 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/collection-client.d.ts +34 -31
- package/dist/collection-client.js +107 -61
- package/dist/connect.d.ts +4 -3
- package/dist/connect.js +53 -38
- package/dist/connection-file-transport.d.ts +31 -0
- package/dist/connection-file-transport.js +42 -0
- package/dist/connection-notifications.js +21 -21
- package/dist/connection-transport.d.ts +2 -0
- package/dist/connection-transport.js +95 -37
- package/dist/connection-types.d.ts +2 -1
- package/dist/connection.d.ts +49 -45
- package/dist/connection.js +73 -33
- package/dist/crypto.d.ts +5 -6
- package/dist/crypto.js +13 -13
- package/dist/errors.d.ts +38 -24
- package/dist/errors.js +130 -71
- package/dist/file-crypto.d.ts +25 -0
- package/dist/file-crypto.js +132 -0
- package/dist/file-sha256.d.ts +12 -0
- package/dist/file-sha256.js +143 -0
- package/dist/file-stream-source.d.ts +17 -0
- package/dist/file-stream-source.js +157 -0
- package/dist/files.d.ts +91 -0
- package/dist/files.js +644 -0
- package/dist/hosted-file-request.d.ts +6 -0
- package/dist/hosted-file-request.js +63 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -0
- package/dist/internal-types.d.ts +3 -1
- package/dist/local-file-transport.d.ts +30 -0
- package/dist/local-file-transport.js +367 -0
- package/dist/notifications.js +5 -5
- package/dist/operation-helpers.d.ts +2 -2
- package/dist/operation-helpers.js +22 -18
- package/dist/operation-types.d.ts +3 -4
- package/dist/outcomes.d.ts +51 -0
- package/dist/outcomes.js +168 -0
- package/dist/runtime-utils.d.ts +6 -1
- package/dist/runtime-utils.js +90 -11
- package/dist/selection.js +3 -3
- package/dist/session.d.ts +9 -8
- package/dist/session.js +31 -20
- package/package.json +2 -2
package/dist/session.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { authorizationReturnToFromProblem, isAuthorizationCallbackUrl } from "./authorization-url.js";
|
|
2
|
+
import { connectProblem } from "./errors.js";
|
|
3
3
|
import { DEFAULT_OPERATIONS } from "./internal-types.js";
|
|
4
4
|
import { uniqueOperations } from "./operation-helpers.js";
|
|
5
|
+
import { connectFailure, connectSuccess } from "./outcomes.js";
|
|
5
6
|
export class MdbaseSession {
|
|
6
7
|
connect;
|
|
7
8
|
operations;
|
|
@@ -38,12 +39,15 @@ export class MdbaseSession {
|
|
|
38
39
|
});
|
|
39
40
|
}
|
|
40
41
|
const callback = this.selection.authorizationCallback();
|
|
41
|
-
if (callback)
|
|
42
|
-
await this.handleAuthorizationCallback(callback);
|
|
42
|
+
if (callback) {
|
|
43
|
+
const completed = await this.handleAuthorizationCallback(callback);
|
|
44
|
+
if (!completed.ok)
|
|
45
|
+
return completed;
|
|
46
|
+
}
|
|
43
47
|
else
|
|
44
48
|
this.autoSelectOnlyConnection();
|
|
45
49
|
this.refresh();
|
|
46
|
-
return this.snapshot;
|
|
50
|
+
return connectSuccess(this.snapshot);
|
|
47
51
|
}
|
|
48
52
|
destroy() {
|
|
49
53
|
this.stopConnections?.();
|
|
@@ -65,12 +69,12 @@ export class MdbaseSession {
|
|
|
65
69
|
select(collectionId, options = {}) {
|
|
66
70
|
const connection = this.connect.connection(collectionId);
|
|
67
71
|
if (!connection) {
|
|
68
|
-
|
|
72
|
+
return connectFailure(connectProblem("unknown_collection", "This collection is not authorized for this application."));
|
|
69
73
|
}
|
|
70
74
|
this.unavailableReason = "not_authorized";
|
|
71
75
|
this.selection.select(collectionId, options);
|
|
72
76
|
this.refresh();
|
|
73
|
-
return connection;
|
|
77
|
+
return connectSuccess(connection);
|
|
74
78
|
}
|
|
75
79
|
clearSelection(options = {}) {
|
|
76
80
|
this.unavailableReason = "not_authorized";
|
|
@@ -93,7 +97,7 @@ export class MdbaseSession {
|
|
|
93
97
|
async authorize(target, options = {}) {
|
|
94
98
|
const selectedCollectionId = this.selection.selectedCollectionId();
|
|
95
99
|
if (target === "selected" && !selectedCollectionId) {
|
|
96
|
-
|
|
100
|
+
return connectFailure(connectProblem("collection_not_selected", "Choose a collection before updating its access."));
|
|
97
101
|
}
|
|
98
102
|
const targetCollectionId = typeof target === "object"
|
|
99
103
|
? target.collectionId
|
|
@@ -110,8 +114,8 @@ export class MdbaseSession {
|
|
|
110
114
|
: { kind: "collection", collectionId: targetCollectionId },
|
|
111
115
|
returnTo: this.selection.authorizationReturnTo()
|
|
112
116
|
});
|
|
113
|
-
if (outcome.kind === "connected") {
|
|
114
|
-
this.selection.finishAuthorization(outcome.returnTo, outcome.connection.collectionId);
|
|
117
|
+
if (outcome.ok && outcome.value.kind === "connected") {
|
|
118
|
+
this.selection.finishAuthorization(outcome.value.returnTo, outcome.value.connection.collectionId);
|
|
115
119
|
}
|
|
116
120
|
return outcome;
|
|
117
121
|
}
|
|
@@ -123,12 +127,13 @@ export class MdbaseSession {
|
|
|
123
127
|
async ensureOperations(requiredOperations) {
|
|
124
128
|
const current = this.snapshot;
|
|
125
129
|
if (current.status !== "ready") {
|
|
126
|
-
|
|
130
|
+
return connectFailure(connectProblem("collection_not_ready", "Choose an authorized collection first."));
|
|
127
131
|
}
|
|
128
132
|
const required = uniqueOperations(requiredOperations);
|
|
129
133
|
const capabilities = current.connection.authorizationCapabilities(required);
|
|
130
|
-
if (capabilities.sufficient)
|
|
131
|
-
return { kind: "unchanged", connection: current.connection };
|
|
134
|
+
if (capabilities.sufficient) {
|
|
135
|
+
return connectSuccess({ kind: "unchanged", connection: current.connection });
|
|
136
|
+
}
|
|
132
137
|
this.transactionDepth += 1;
|
|
133
138
|
try {
|
|
134
139
|
const outcome = await this.connect.authorize({
|
|
@@ -136,8 +141,8 @@ export class MdbaseSession {
|
|
|
136
141
|
target: { kind: "collection", collectionId: current.collectionId },
|
|
137
142
|
returnTo: this.selection.authorizationReturnTo()
|
|
138
143
|
});
|
|
139
|
-
if (outcome.kind === "connected") {
|
|
140
|
-
this.selection.finishAuthorization(outcome.returnTo, outcome.connection.collectionId);
|
|
144
|
+
if (outcome.ok && outcome.value.kind === "connected") {
|
|
145
|
+
this.selection.finishAuthorization(outcome.value.returnTo, outcome.value.connection.collectionId);
|
|
141
146
|
}
|
|
142
147
|
return outcome;
|
|
143
148
|
}
|
|
@@ -148,21 +153,27 @@ export class MdbaseSession {
|
|
|
148
153
|
}
|
|
149
154
|
handleAuthorizationCallback(callbackUrl) {
|
|
150
155
|
if (!isAuthorizationCallbackUrl(callbackUrl)) {
|
|
151
|
-
return Promise.
|
|
156
|
+
return Promise.resolve(connectFailure(connectProblem("invalid_callback", "This URL is not an authorization callback.")));
|
|
152
157
|
}
|
|
153
158
|
if (this.callbackPromise)
|
|
154
159
|
return this.callbackPromise;
|
|
155
160
|
this.transactionDepth += 1;
|
|
156
161
|
const completion = this.connect.completeAuthorization(callbackUrl)
|
|
157
|
-
.then((
|
|
162
|
+
.then((outcome) => {
|
|
163
|
+
if (!outcome.ok) {
|
|
164
|
+
const returnTo = authorizationReturnToFromProblem(outcome.problem);
|
|
165
|
+
this.selection.clearAuthorizationCallback(returnTo);
|
|
166
|
+
this.refresh();
|
|
167
|
+
return outcome;
|
|
168
|
+
}
|
|
169
|
+
const result = outcome.value;
|
|
158
170
|
this.unavailableReason = "not_authorized";
|
|
159
171
|
this.selection.finishAuthorization(result.returnTo, result.connection.collectionId);
|
|
160
172
|
this.refresh();
|
|
161
|
-
return result.connection;
|
|
173
|
+
return connectSuccess(result.connection, outcome.diagnostics);
|
|
162
174
|
})
|
|
163
175
|
.catch((error) => {
|
|
164
|
-
|
|
165
|
-
this.selection.clearAuthorizationCallback(returnTo);
|
|
176
|
+
this.selection.clearAuthorizationCallback();
|
|
166
177
|
this.refresh();
|
|
167
178
|
throw error;
|
|
168
179
|
})
|
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.23",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"README.md"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@mdbase-dev/connect-protocol": "0.1.0-beta.
|
|
28
|
+
"@mdbase-dev/connect-protocol": "0.1.0-beta.23"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"esbuild": "^0.28.1",
|