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