@dxos/edge-client 0.8.4-main.03d5cd7b56 → 0.8.4-main.05e74ebcff

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,8 +1,105 @@
1
- MIT License
2
- Copyright (c) 2022 DXOS
1
+ # Functional Source License, Version 1.1, ALv2 Future License
3
2
 
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ ## Abbreviation
5
4
 
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ FSL-1.1-Apache-2.0
7
6
 
8
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+ ## Notice
8
+
9
+ Copyright 2026 DXOS
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
@@ -742,6 +742,7 @@ var DEFAULT_RETRY_TIMEOUT = 1500;
742
742
  var DEFAULT_RETRY_JITTER = 500;
743
743
  var DEFAULT_MAX_RETRIES_COUNT = 3;
744
744
  var WARNING_BODY_SIZE = 10 * 1024 * 1024;
745
+ var LEGACY_CORS_PROXY_URL = "https://cors-proxy.dxos.workers.dev";
745
746
  var EdgeHttpClient = class {
746
747
  _baseUrl;
747
748
  _clientTag;
@@ -755,7 +756,7 @@ var EdgeHttpClient = class {
755
756
  this._clientTag = options?.clientTag;
756
757
  log4("created", {
757
758
  url: this._baseUrl
758
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 32, S: this });
759
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 37, S: this });
759
760
  }
760
761
  get baseUrl() {
761
762
  return this._baseUrl;
@@ -853,7 +854,7 @@ var EdgeHttpClient = class {
853
854
  //
854
855
  async queryQueue(ctx, subspaceTag, spaceId, query, args) {
855
856
  const queueId = query.queueIds?.[0];
856
- invariant4(queueId, "queueId required", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 132, S: this, A: ["queueId", "'queueId required'"] });
857
+ invariant4(queueId, "queueId required", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 137, S: this, A: ["queueId", "'queueId required'"] });
857
858
  return this._call(ctx, createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query`, this.baseUrl), {
858
859
  after: query.after,
859
860
  before: query.before,
@@ -1018,6 +1019,31 @@ var EdgeHttpClient = class {
1018
1019
  });
1019
1020
  }
1020
1021
  //
1022
+ // Integration proxy.
1023
+ //
1024
+ /**
1025
+ * Fetch through the edge proxy, used by integration plugins (Discord, ...)
1026
+ * to call third-party REST APIs that don't set permissive CORS headers.
1027
+ *
1028
+ * `init.headers.Authorization` (caller-supplied) is preserved by prefixing
1029
+ * with `X-Cors-Proxy-Authorization`, since the proxy strips `Authorization`
1030
+ * on forwarding to avoid leaking the DXOS presentation upstream — the
1031
+ * prefix carries the upstream's bot token / token through.
1032
+ *
1033
+ * TEMPORARY: routed through the legacy standalone proxy at
1034
+ * `cors-proxy.dxos.workers.dev` (open, unauthenticated, path
1035
+ * `/<host>/<path>`) so that integration plugins can be tested before the
1036
+ * authenticated `/proxy/*` route on the main edge worker ships
1037
+ * (https://github.com/dxos/edge/pull/576). When that PR deploys, restore
1038
+ * the commented-out block below — it rewrites the target under
1039
+ * `${this.baseUrl}/proxy/...` and signs the request with the cached
1040
+ * verifiable presentation. The header-remap and `x-cors-proxy-*` override
1041
+ * conventions are unchanged between the two paths.
1042
+ */
1043
+ async proxyFetch(target, init = {}) {
1044
+ return proxyFetchLegacy(target, init, this._clientTag);
1045
+ }
1046
+ //
1021
1047
  // Internal
1022
1048
  //
1023
1049
  async _fetch(url, _args) {
@@ -1029,7 +1055,7 @@ var EdgeHttpClient = class {
1029
1055
  log4("fetch", {
1030
1056
  url,
1031
1057
  request: args.body
1032
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 302, S: this });
1058
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 362, S: this });
1033
1059
  const traceHeaders = getTraceHeaders(ctx);
1034
1060
  let handledAuth = false;
1035
1061
  const tryCount = 1;
@@ -1047,11 +1073,11 @@ var EdgeHttpClient = class {
1047
1073
  url,
1048
1074
  tryCount,
1049
1075
  authHeader: !!this._authHeader
1050
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 319, S: this });
1076
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 379, S: this });
1051
1077
  const response = await fetch(url, request);
1052
1078
  if (response.ok) {
1053
1079
  const body2 = await response.clone().json();
1054
- invariant4(body2, "Expected body to be present", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 327, S: this, A: ["body", "'Expected body to be present'"] });
1080
+ invariant4(body2, "Expected body to be present", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 387, S: this, A: ["body", "'Expected body to be present'"] });
1055
1081
  if (!("success" in body2)) {
1056
1082
  return body2;
1057
1083
  }
@@ -1064,13 +1090,13 @@ var EdgeHttpClient = class {
1064
1090
  continue;
1065
1091
  }
1066
1092
  const body = response.headers.get("Content-Type") === "application/json" ? await response.clone().json() : void 0;
1067
- invariant4(!body?.success, "Expected body to not be a failure response or undefined.", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 340, S: this, A: ["!body?.success", "'Expected body to not be a failure response or undefined.'"] });
1093
+ invariant4(!body?.success, "Expected body to not be a failure response or undefined.", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 400, S: this, A: ["!body?.success", "'Expected body to not be a failure response or undefined.'"] });
1068
1094
  if (body?.data?.type === "auth_challenge" && typeof body?.data?.challenge === "string") {
1069
1095
  processingError = new EdgeAuthChallengeError(body.data.challenge, body.data);
1070
1096
  } else if (body?.success === false) {
1071
1097
  processingError = EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
1072
1098
  } else {
1073
- invariant4(!response.ok, "Expected response to not be ok.", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 346, S: this, A: ["!response.ok", "'Expected response to not be ok.'"] });
1099
+ invariant4(!response.ok, "Expected response to not be ok.", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 406, S: this, A: ["!response.ok", "'Expected response to not be ok.'"] });
1074
1100
  processingError = await EdgeCallFailedError.fromHttpFailure(response);
1075
1101
  }
1076
1102
  } catch (error) {
@@ -1080,7 +1106,7 @@ var EdgeHttpClient = class {
1080
1106
  log4.verbose("retrying edge request", {
1081
1107
  url,
1082
1108
  processingError
1083
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 353, S: this });
1109
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 413, S: this });
1084
1110
  } else {
1085
1111
  throw processingError;
1086
1112
  }
@@ -1088,7 +1114,7 @@ var EdgeHttpClient = class {
1088
1114
  }
1089
1115
  async _handleUnauthorized(response) {
1090
1116
  if (!this._edgeIdentity) {
1091
- log4.warn("unauthorized response received before identity was set", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 364, S: this });
1117
+ log4.warn("unauthorized response received before identity was set", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 424, S: this });
1092
1118
  throw await EdgeCallFailedError.fromHttpFailure(response);
1093
1119
  }
1094
1120
  const challenge = await handleAuthChallenge(response, this._edgeIdentity);
@@ -1107,7 +1133,7 @@ var createRequest = ({ method, body, json = true }, authHeader, traceHeaders, cl
1107
1133
  if (typeof requestBody === "string" && requestBody.length > WARNING_BODY_SIZE) {
1108
1134
  log4.warn("Request with large body", {
1109
1135
  bodySize: requestBody.length
1110
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 381, S: void 0 });
1136
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 441, S: void 0 });
1111
1137
  }
1112
1138
  if (authHeader) {
1113
1139
  headers["Authorization"] = authHeader;
@@ -1162,6 +1188,28 @@ var getFileMimeType = (filename) => [
1162
1188
  ".js",
1163
1189
  ".mjs"
1164
1190
  ].some((codeExtension) => filename.endsWith(codeExtension)) ? "application/javascript+module" : filename.endsWith(".wasm") ? "application/wasm" : "application/octet-stream";
1191
+ var remapAuthorizationForProxy = (headers) => {
1192
+ const callerAuth = headers.get("Authorization");
1193
+ if (callerAuth !== null) {
1194
+ headers.delete("Authorization");
1195
+ headers.set("X-Cors-Proxy-Authorization", callerAuth);
1196
+ }
1197
+ return headers;
1198
+ };
1199
+ var proxyFetchLegacy = (target, init = {}, clientTag) => {
1200
+ const proxyUrl = new URL(`/${target.host}${target.pathname}${target.search}`, LEGACY_CORS_PROXY_URL);
1201
+ if (target.protocol === "http:") {
1202
+ proxyUrl.searchParams.set("scheme", "http");
1203
+ }
1204
+ const requestHeaders = remapAuthorizationForProxy(new Headers(init.headers ?? void 0));
1205
+ if (clientTag) {
1206
+ requestHeaders.set(EDGE_CLIENT_TAG_HEADER, clientTag);
1207
+ }
1208
+ return fetch(proxyUrl, {
1209
+ ...init,
1210
+ headers: requestHeaders
1211
+ });
1212
+ };
1165
1213
  export {
1166
1214
  CLOUDFLARE_MESSAGE_MAX_BYTES,
1167
1215
  CLOUDFLARE_RPC_MAX_BYTES,
@@ -1181,6 +1229,7 @@ export {
1181
1229
  getTypename,
1182
1230
  handleAuthChallenge,
1183
1231
  protocol,
1232
+ proxyFetchLegacy,
1184
1233
  toUint8Array,
1185
1234
  withLogging,
1186
1235
  withRetry,