@dxos/edge-client 0.8.4-main.ae835ea → 0.8.4-main.bc674ce

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.
@@ -868,6 +868,7 @@ import * as Effect2 from "effect/Effect";
868
868
  import * as Function from "effect/Function";
869
869
  import { sleep } from "@dxos/async";
870
870
  import { Context as Context3 } from "@dxos/context";
871
+ import { runAndForwardErrors } from "@dxos/effect";
871
872
  import { invariant as invariant4 } from "@dxos/invariant";
872
873
  import { log as log4 } from "@dxos/log";
873
874
  import { EdgeAuthChallengeError, EdgeCallFailedError } from "@dxos/protocols";
@@ -901,14 +902,16 @@ var withRetryConfig = (effect) => Effect.gen(function* () {
901
902
  const config = yield* HttpConfig;
902
903
  return yield* withRetry(effect, config);
903
904
  });
904
- var withLogging = (effect) => effect.pipe(Effect.tap((res) => log3.info("response", {
905
- status: res.status
906
- }, {
907
- F: __dxlog_file5,
908
- L: 64,
909
- S: void 0,
910
- C: (f, a) => f(...a)
911
- })));
905
+ var withLogging = (effect) => effect.pipe(Effect.tap((res) => {
906
+ log3.info("response", {
907
+ status: res.status
908
+ }, {
909
+ F: __dxlog_file5,
910
+ L: 66,
911
+ S: void 0,
912
+ C: (f, a) => f(...a)
913
+ });
914
+ }));
912
915
  var encodeAuthHeader = (challenge) => {
913
916
  const encodedChallenge = Buffer.from(challenge).toString("base64");
914
917
  return `VerifiablePresentation pb;base64,${encodedChallenge}`;
@@ -933,7 +936,7 @@ var EdgeHttpClient = class {
933
936
  url: this._baseUrl
934
937
  }, {
935
938
  F: __dxlog_file6,
936
- L: 101,
939
+ L: 107,
937
940
  S: this,
938
941
  C: (f, a) => f(...a)
939
942
  });
@@ -953,7 +956,8 @@ var EdgeHttpClient = class {
953
956
  async getStatus(args) {
954
957
  return this._call(new URL("/status", this.baseUrl), {
955
958
  ...args,
956
- method: "GET"
959
+ method: "GET",
960
+ auth: true
957
961
  });
958
962
  }
959
963
  //
@@ -1032,7 +1036,16 @@ var EdgeHttpClient = class {
1032
1036
  // Queues
1033
1037
  //
1034
1038
  async queryQueue(subspaceTag, spaceId, query, args) {
1035
- const { queueId } = query;
1039
+ const queueId = query.queueIds?.[0];
1040
+ invariant4(queueId, "queueId required", {
1041
+ F: __dxlog_file6,
1042
+ L: 216,
1043
+ S: this,
1044
+ A: [
1045
+ "queueId",
1046
+ "'queueId required'"
1047
+ ]
1048
+ });
1036
1049
  return this._call(createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query`, this.baseUrl), {
1037
1050
  after: query.after,
1038
1051
  before: query.before,
@@ -1070,6 +1083,7 @@ var EdgeHttpClient = class {
1070
1083
  formData.append("version", body.version);
1071
1084
  formData.append("ownerPublicKey", body.ownerPublicKey);
1072
1085
  formData.append("entryPoint", body.entryPoint);
1086
+ body.runtime && formData.append("runtime", body.runtime);
1073
1087
  for (const [filename, content] of Object.entries(body.assets)) {
1074
1088
  formData.append("assets", new Blob([
1075
1089
  content
@@ -1113,8 +1127,7 @@ var EdgeHttpClient = class {
1113
1127
  return this._call(url, {
1114
1128
  ...args,
1115
1129
  body: input,
1116
- method: "POST",
1117
- rawResponse: true
1130
+ method: "POST"
1118
1131
  });
1119
1132
  }
1120
1133
  //
@@ -1135,6 +1148,11 @@ var EdgeHttpClient = class {
1135
1148
  method: "GET"
1136
1149
  });
1137
1150
  }
1151
+ async forceRunCronTrigger(spaceId, triggerId) {
1152
+ return this._call(new URL(`/test/functions/${spaceId}/triggers/crons/${triggerId}/run`, this.baseUrl), {
1153
+ method: "POST"
1154
+ });
1155
+ }
1138
1156
  //
1139
1157
  // Import/Export space.
1140
1158
  //
@@ -1155,73 +1173,88 @@ var EdgeHttpClient = class {
1155
1173
  //
1156
1174
  // Internal
1157
1175
  //
1158
- async _fetch(url, args) {
1159
- return Function.pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"), Effect2.runPromise);
1176
+ async _fetch(url, _args) {
1177
+ return Function.pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"), runAndForwardErrors);
1160
1178
  }
1161
1179
  // TODO(burdon): Refactor with effect (see edge-http-client.test.ts).
1162
1180
  async _call(url, args) {
1163
1181
  const shouldRetry = createRetryHandler(args);
1164
1182
  const requestContext = args.context ?? Context3.default(void 0, {
1165
1183
  F: __dxlog_file6,
1166
- L: 393
1184
+ L: 408
1167
1185
  });
1168
1186
  log4("fetch", {
1169
1187
  url,
1170
1188
  request: args.body
1171
1189
  }, {
1172
1190
  F: __dxlog_file6,
1173
- L: 394,
1191
+ L: 409,
1174
1192
  S: this,
1175
1193
  C: (f, a) => f(...a)
1176
1194
  });
1177
1195
  let handledAuth = false;
1196
+ const tryCount = 1;
1178
1197
  while (true) {
1179
1198
  let processingError = void 0;
1180
1199
  try {
1200
+ if (!this._authHeader && args.auth) {
1201
+ const response2 = await fetch(new URL(`/auth`, this.baseUrl));
1202
+ if (response2.status === 401) {
1203
+ this._authHeader = await this._handleUnauthorized(response2);
1204
+ }
1205
+ }
1181
1206
  const request = createRequest(args, this._authHeader);
1207
+ log4("call edge", {
1208
+ url,
1209
+ tryCount,
1210
+ authHeader: !!this._authHeader
1211
+ }, {
1212
+ F: __dxlog_file6,
1213
+ L: 424,
1214
+ S: this,
1215
+ C: (f, a) => f(...a)
1216
+ });
1182
1217
  const response = await fetch(url, request);
1183
- const body = response.headers.get("Content-Type") === "application/json" ? await response.clone().json() : void 0;
1184
1218
  if (response.ok) {
1185
- if (args.rawResponse) {
1186
- return body;
1187
- }
1188
- invariant4(body, "Expected body to be present", {
1219
+ const body2 = await response.clone().json();
1220
+ invariant4(body2, "Expected body to be present", {
1189
1221
  F: __dxlog_file6,
1190
- L: 409,
1222
+ L: 429,
1191
1223
  S: this,
1192
1224
  A: [
1193
1225
  "body",
1194
1226
  "'Expected body to be present'"
1195
1227
  ]
1196
1228
  });
1197
- if (!("success" in body)) {
1198
- return body;
1229
+ if (!("success" in body2)) {
1230
+ return body2;
1199
1231
  }
1200
- if (body.success) {
1201
- return body.data;
1232
+ if (body2.success) {
1233
+ return body2.data;
1202
1234
  }
1203
1235
  } else if (response.status === 401 && !handledAuth) {
1204
1236
  this._authHeader = await this._handleUnauthorized(response);
1205
1237
  handledAuth = true;
1206
1238
  continue;
1207
1239
  }
1240
+ const body = response.headers.get("Content-Type") === "application/json" ? await response.clone().json() : void 0;
1208
1241
  invariant4(!body?.success, "Expected body to not be a failure response or undefined.", {
1209
1242
  F: __dxlog_file6,
1210
- L: 422,
1243
+ L: 445,
1211
1244
  S: this,
1212
1245
  A: [
1213
1246
  "!body?.success",
1214
1247
  "'Expected body to not be a failure response or undefined.'"
1215
1248
  ]
1216
1249
  });
1217
- if (body?.errorData?.type === "auth_challenge" && typeof body?.errorData?.challenge === "string") {
1218
- processingError = new EdgeAuthChallengeError(body.errorData.challenge, body.errorData);
1250
+ if (body?.data?.type === "auth_challenge" && typeof body?.data?.challenge === "string") {
1251
+ processingError = new EdgeAuthChallengeError(body.data.challenge, body.data);
1219
1252
  } else if (body?.success === false) {
1220
1253
  processingError = EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
1221
1254
  } else {
1222
1255
  invariant4(!response.ok, "Expected response to not be ok.", {
1223
1256
  F: __dxlog_file6,
1224
- L: 429,
1257
+ L: 452,
1225
1258
  S: this,
1226
1259
  A: [
1227
1260
  "!response.ok",
@@ -1234,12 +1267,12 @@ var EdgeHttpClient = class {
1234
1267
  processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
1235
1268
  }
1236
1269
  if (processingError?.isRetryable && await shouldRetry(requestContext, processingError.retryAfterMs)) {
1237
- log4("retrying edge request", {
1270
+ log4.verbose("retrying edge request", {
1238
1271
  url,
1239
1272
  processingError
1240
1273
  }, {
1241
1274
  F: __dxlog_file6,
1242
- L: 437,
1275
+ L: 460,
1243
1276
  S: this,
1244
1277
  C: (f, a) => f(...a)
1245
1278
  });
@@ -1252,7 +1285,7 @@ var EdgeHttpClient = class {
1252
1285
  if (!this._edgeIdentity) {
1253
1286
  log4.warn("unauthorized response received before identity was set", void 0, {
1254
1287
  F: __dxlog_file6,
1255
- L: 446,
1288
+ L: 469,
1256
1289
  S: this,
1257
1290
  C: (f, a) => f(...a)
1258
1291
  });
@@ -1276,7 +1309,7 @@ var createRequest = ({ method, body, json = true }, authHeader) => {
1276
1309
  bodySize: requestBody.length
1277
1310
  }, {
1278
1311
  F: __dxlog_file6,
1279
- L: 470,
1312
+ L: 493,
1280
1313
  S: void 0,
1281
1314
  C: (f, a) => f(...a)
1282
1315
  });