@executor-js/emulate 0.6.0 → 0.7.0

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.
@@ -154,14 +154,14 @@ function emailRoutes(ctx) {
154
154
  return c.json(resendList(allEmails.map(formatEmail)));
155
155
  });
156
156
  app.get("/emails/:id", (c) => {
157
- const id = c.req.param("id");
158
- const email = rs().emails.findOneBy("uuid", id);
157
+ const id2 = c.req.param("id");
158
+ const email = rs().emails.findOneBy("uuid", id2);
159
159
  if (!email) return resendError(c, 404, "not_found", "Email not found");
160
160
  return c.json(formatEmail(email));
161
161
  });
162
162
  app.post("/emails/:id/cancel", (c) => {
163
- const id = c.req.param("id");
164
- const email = rs().emails.findOneBy("uuid", id);
163
+ const id2 = c.req.param("id");
164
+ const email = rs().emails.findOneBy("uuid", id2);
165
165
  if (!email) return resendError(c, 404, "not_found", "Email not found");
166
166
  if (email.status !== "scheduled") {
167
167
  return resendError(c, 422, "validation_error", "Only scheduled emails can be canceled");
@@ -255,14 +255,14 @@ function domainRoutes(ctx) {
255
255
  return c.json(resendList(allDomains.map(formatDomain)));
256
256
  });
257
257
  app.get("/domains/:id", (c) => {
258
- const id = c.req.param("id");
259
- const domain = rs().domains.findOneBy("uuid", id);
258
+ const id2 = c.req.param("id");
259
+ const domain = rs().domains.findOneBy("uuid", id2);
260
260
  if (!domain) return resendError(c, 404, "not_found", "Domain not found");
261
261
  return c.json(formatDomain(domain));
262
262
  });
263
263
  app.delete("/domains/:id", async (c) => {
264
- const id = c.req.param("id");
265
- const domain = rs().domains.findOneBy("uuid", id);
264
+ const id2 = c.req.param("id");
265
+ const domain = rs().domains.findOneBy("uuid", id2);
266
266
  if (!domain) return resendError(c, 404, "not_found", "Domain not found");
267
267
  rs().domains.delete(domain.id);
268
268
  await webhooks.dispatch(
@@ -274,8 +274,8 @@ function domainRoutes(ctx) {
274
274
  return c.json({ object: "domain", id: domain.uuid, deleted: true });
275
275
  });
276
276
  app.post("/domains/:id/verify", (c) => {
277
- const id = c.req.param("id");
278
- const domain = rs().domains.findOneBy("uuid", id);
277
+ const id2 = c.req.param("id");
278
+ const domain = rs().domains.findOneBy("uuid", id2);
279
279
  if (!domain) return resendError(c, 404, "not_found", "Domain not found");
280
280
  const verifiedRecords = domain.records.map((r) => ({ ...r, status: "verified" }));
281
281
  rs().domains.update(domain.id, {
@@ -331,8 +331,8 @@ function apiKeyRoutes(ctx) {
331
331
  );
332
332
  });
333
333
  app.delete("/api-keys/:id", (c) => {
334
- const id = c.req.param("id");
335
- const apiKey = rs().apiKeys.findOneBy("uuid", id);
334
+ const id2 = c.req.param("id");
335
+ const apiKey = rs().apiKeys.findOneBy("uuid", id2);
336
336
  if (!apiKey) return resendError(c, 404, "not_found", "API key not found");
337
337
  rs().apiKeys.delete(apiKey.id);
338
338
  return c.json({ deleted: true });
@@ -371,15 +371,15 @@ function contactRoutes(ctx) {
371
371
  );
372
372
  });
373
373
  app.delete("/audiences/:id", (c) => {
374
- const id = c.req.param("id");
375
- const audience = rs().audiences.findOneBy("uuid", id);
374
+ const id2 = c.req.param("id");
375
+ const audience = rs().audiences.findOneBy("uuid", id2);
376
376
  if (!audience) return resendError(c, 404, "not_found", "Audience not found");
377
377
  rs().audiences.delete(audience.id);
378
378
  return c.json({ object: "audience", id: audience.uuid, deleted: true });
379
379
  });
380
380
  app.post("/audiences/:audience_id/contacts", async (c) => {
381
- const audienceId = c.req.param("audience_id");
382
- const audience = rs().audiences.findOneBy("uuid", audienceId);
381
+ const audienceId2 = c.req.param("audience_id");
382
+ const audience = rs().audiences.findOneBy("uuid", audienceId2);
383
383
  if (!audience) return resendError(c, 404, "not_found", "Audience not found");
384
384
  const body = await parseResendBody(c);
385
385
  const email = body.email;
@@ -387,7 +387,7 @@ function contactRoutes(ctx) {
387
387
  const uuid = generateUuid();
388
388
  const contact = rs().contacts.insert({
389
389
  uuid,
390
- audience_id: audienceId,
390
+ audience_id: audienceId2,
391
391
  email,
392
392
  first_name: body.first_name ?? null,
393
393
  last_name: body.last_name ?? null,
@@ -396,7 +396,7 @@ function contactRoutes(ctx) {
396
396
  await webhooks.dispatch(
397
397
  "contact.created",
398
398
  void 0,
399
- { type: "contact.created", data: { id: uuid, email, audience_id: audienceId } },
399
+ { type: "contact.created", data: { id: uuid, email, audience_id: audienceId2 } },
400
400
  "resend"
401
401
  );
402
402
  return c.json(
@@ -409,10 +409,10 @@ function contactRoutes(ctx) {
409
409
  );
410
410
  });
411
411
  app.get("/audiences/:audience_id/contacts", (c) => {
412
- const audienceId = c.req.param("audience_id");
413
- const audience = rs().audiences.findOneBy("uuid", audienceId);
412
+ const audienceId2 = c.req.param("audience_id");
413
+ const audience = rs().audiences.findOneBy("uuid", audienceId2);
414
414
  if (!audience) return resendError(c, 404, "not_found", "Audience not found");
415
- const contacts = rs().contacts.findBy("audience_id", audienceId);
415
+ const contacts = rs().contacts.findBy("audience_id", audienceId2);
416
416
  return c.json(
417
417
  resendList(
418
418
  contacts.map((ct) => ({
@@ -428,17 +428,17 @@ function contactRoutes(ctx) {
428
428
  );
429
429
  });
430
430
  app.delete("/audiences/:audience_id/contacts/:id", async (c) => {
431
- const audienceId = c.req.param("audience_id");
431
+ const audienceId2 = c.req.param("audience_id");
432
432
  const contactId = c.req.param("id");
433
433
  const contact = rs().contacts.findOneBy("uuid", contactId);
434
- if (!contact || contact.audience_id !== audienceId) {
434
+ if (!contact || contact.audience_id !== audienceId2) {
435
435
  return resendError(c, 404, "not_found", "Contact not found");
436
436
  }
437
437
  rs().contacts.delete(contact.id);
438
438
  await webhooks.dispatch(
439
439
  "contact.deleted",
440
440
  void 0,
441
- { type: "contact.deleted", data: { id: contact.uuid, email: contact.email, audience_id: audienceId } },
441
+ { type: "contact.deleted", data: { id: contact.uuid, email: contact.email, audience_id: audienceId2 } },
442
442
  "resend"
443
443
  );
444
444
  return c.json({ object: "contact", id: contact.uuid, deleted: true });
@@ -809,8 +809,8 @@ function inboxRoutes(ctx) {
809
809
  return c.html(html);
810
810
  });
811
811
  app.get("/inbox/:id", (c) => {
812
- const id = c.req.param("id");
813
- const email = rs().emails.findOneBy("uuid", id);
812
+ const id2 = c.req.param("id");
813
+ const email = rs().emails.findOneBy("uuid", id2);
814
814
  if (!email) {
815
815
  const html2 = renderCardPage(
816
816
  "Not Found",
@@ -866,6 +866,242 @@ ${previewContent}
866
866
  return c.html(html);
867
867
  });
868
868
  }
869
+ function openapiRoutes({ app, baseUrl }) {
870
+ app.get("/openapi.json", (c) => c.json(buildSpec(baseUrl)));
871
+ }
872
+ var ok = (description) => ({
873
+ description,
874
+ content: { "application/json": { schema: { type: "object" } } }
875
+ });
876
+ var id = { name: "id", in: "path", required: true, schema: { type: "string" } };
877
+ var audienceId = { name: "audience_id", in: "path", required: true, schema: { type: "string" } };
878
+ var jsonBody = (properties, required, description) => ({
879
+ required: true,
880
+ description,
881
+ content: {
882
+ "application/json": {
883
+ schema: { type: "object", properties, required: [...required] }
884
+ }
885
+ }
886
+ });
887
+ function buildSpec(baseUrl) {
888
+ return {
889
+ openapi: "3.1.0",
890
+ info: {
891
+ title: "Resend API (Emulated)",
892
+ version: "1.0.0",
893
+ description: "Emulated subset of the Resend REST API. Authenticate with a bearer API key (mint one at POST /_emulate/credentials)."
894
+ },
895
+ servers: [{ url: baseUrl }],
896
+ components: {
897
+ securitySchemes: {
898
+ bearerAuth: {
899
+ type: "http",
900
+ scheme: "bearer",
901
+ description: "Resend API key, sent as `Authorization: Bearer re_\u2026`."
902
+ }
903
+ }
904
+ },
905
+ security: [{ bearerAuth: [] }],
906
+ paths: {
907
+ "/emails": {
908
+ post: {
909
+ operationId: "emails.send",
910
+ tags: ["emails"],
911
+ summary: "Send an email",
912
+ requestBody: jsonBody(
913
+ {
914
+ from: { type: "string" },
915
+ to: { type: ["string", "array"], items: { type: "string" } },
916
+ subject: { type: "string" },
917
+ html: { type: "string" },
918
+ text: { type: "string" },
919
+ cc: { type: ["string", "array"], items: { type: "string" } },
920
+ bcc: { type: ["string", "array"], items: { type: "string" } },
921
+ reply_to: { type: ["string", "array"], items: { type: "string" } },
922
+ scheduled_at: { type: "string" }
923
+ },
924
+ ["from", "to", "subject"],
925
+ "The email to send."
926
+ ),
927
+ responses: { "200": ok("The created email."), "422": ok("Validation error.") }
928
+ },
929
+ get: {
930
+ operationId: "emails.list",
931
+ tags: ["emails"],
932
+ summary: "List sent emails",
933
+ responses: { "200": ok("Email list.") }
934
+ }
935
+ },
936
+ "/emails/batch": {
937
+ post: {
938
+ operationId: "emails.sendBatch",
939
+ tags: ["emails"],
940
+ summary: "Send up to 100 emails at once",
941
+ requestBody: {
942
+ required: true,
943
+ description: "An array of email objects (same shape as emails.send).",
944
+ content: {
945
+ "application/json": {
946
+ schema: { type: "array", items: { type: "object" } }
947
+ }
948
+ }
949
+ },
950
+ responses: { "200": ok("The created emails."), "422": ok("Validation error.") }
951
+ }
952
+ },
953
+ "/emails/{id}": {
954
+ get: {
955
+ operationId: "emails.get",
956
+ tags: ["emails"],
957
+ summary: "Retrieve a sent email",
958
+ parameters: [id],
959
+ responses: { "200": ok("The email."), "404": ok("Not found.") }
960
+ }
961
+ },
962
+ "/emails/{id}/cancel": {
963
+ post: {
964
+ operationId: "emails.cancel",
965
+ tags: ["emails"],
966
+ summary: "Cancel a scheduled email",
967
+ parameters: [id],
968
+ responses: { "200": ok("The canceled email."), "404": ok("Not found.") }
969
+ }
970
+ },
971
+ "/domains": {
972
+ post: {
973
+ operationId: "domains.create",
974
+ tags: ["domains"],
975
+ summary: "Add a sending domain",
976
+ requestBody: jsonBody(
977
+ { name: { type: "string" }, region: { type: "string" } },
978
+ ["name"],
979
+ "The domain to add."
980
+ ),
981
+ responses: { "201": ok("The created domain."), "422": ok("Validation error.") }
982
+ },
983
+ get: {
984
+ operationId: "domains.list",
985
+ tags: ["domains"],
986
+ summary: "List domains",
987
+ responses: { "200": ok("Domain list.") }
988
+ }
989
+ },
990
+ "/domains/{id}": {
991
+ get: {
992
+ operationId: "domains.get",
993
+ tags: ["domains"],
994
+ summary: "Retrieve a domain",
995
+ parameters: [id],
996
+ responses: { "200": ok("The domain."), "404": ok("Not found.") }
997
+ },
998
+ delete: {
999
+ operationId: "domains.remove",
1000
+ tags: ["domains"],
1001
+ summary: "Remove a domain",
1002
+ parameters: [id],
1003
+ responses: { "200": ok("Deletion confirmation."), "404": ok("Not found.") }
1004
+ }
1005
+ },
1006
+ "/domains/{id}/verify": {
1007
+ post: {
1008
+ operationId: "domains.verify",
1009
+ tags: ["domains"],
1010
+ summary: "Trigger domain verification",
1011
+ parameters: [id],
1012
+ responses: { "200": ok("Verification state."), "404": ok("Not found.") }
1013
+ }
1014
+ },
1015
+ "/api-keys": {
1016
+ post: {
1017
+ operationId: "apiKeys.create",
1018
+ tags: ["api-keys"],
1019
+ summary: "Create an API key",
1020
+ requestBody: jsonBody(
1021
+ { name: { type: "string" }, permission: { type: "string" } },
1022
+ ["name"],
1023
+ "The API key to create."
1024
+ ),
1025
+ responses: { "201": ok("The created key (token shown once).") }
1026
+ },
1027
+ get: {
1028
+ operationId: "apiKeys.list",
1029
+ tags: ["api-keys"],
1030
+ summary: "List API keys",
1031
+ responses: { "200": ok("API key list.") }
1032
+ }
1033
+ },
1034
+ "/api-keys/{id}": {
1035
+ delete: {
1036
+ operationId: "apiKeys.remove",
1037
+ tags: ["api-keys"],
1038
+ summary: "Remove an API key",
1039
+ parameters: [id],
1040
+ responses: { "200": ok("Deletion confirmation."), "404": ok("Not found.") }
1041
+ }
1042
+ },
1043
+ "/audiences": {
1044
+ post: {
1045
+ operationId: "audiences.create",
1046
+ tags: ["audiences"],
1047
+ summary: "Create an audience",
1048
+ requestBody: jsonBody({ name: { type: "string" } }, ["name"], "The audience to create."),
1049
+ responses: { "201": ok("The created audience.") }
1050
+ },
1051
+ get: {
1052
+ operationId: "audiences.list",
1053
+ tags: ["audiences"],
1054
+ summary: "List audiences",
1055
+ responses: { "200": ok("Audience list.") }
1056
+ }
1057
+ },
1058
+ "/audiences/{id}": {
1059
+ delete: {
1060
+ operationId: "audiences.remove",
1061
+ tags: ["audiences"],
1062
+ summary: "Remove an audience",
1063
+ parameters: [id],
1064
+ responses: { "200": ok("Deletion confirmation."), "404": ok("Not found.") }
1065
+ }
1066
+ },
1067
+ "/audiences/{audience_id}/contacts": {
1068
+ post: {
1069
+ operationId: "contacts.create",
1070
+ tags: ["contacts"],
1071
+ summary: "Add a contact to an audience",
1072
+ parameters: [audienceId],
1073
+ requestBody: jsonBody(
1074
+ {
1075
+ email: { type: "string" },
1076
+ first_name: { type: "string" },
1077
+ last_name: { type: "string" },
1078
+ unsubscribed: { type: "boolean" }
1079
+ },
1080
+ ["email"],
1081
+ "The contact to add."
1082
+ ),
1083
+ responses: { "201": ok("The created contact."), "422": ok("Validation error.") }
1084
+ },
1085
+ get: {
1086
+ operationId: "contacts.list",
1087
+ tags: ["contacts"],
1088
+ summary: "List contacts in an audience",
1089
+ parameters: [audienceId],
1090
+ responses: { "200": ok("Contact list."), "404": ok("Audience not found.") }
1091
+ }
1092
+ },
1093
+ "/audiences/{audience_id}/contacts/{id}": {
1094
+ delete: {
1095
+ operationId: "contacts.remove",
1096
+ tags: ["contacts"],
1097
+ summary: "Remove a contact from an audience",
1098
+ parameters: [audienceId, id],
1099
+ responses: { "200": ok("Deletion confirmation."), "404": ok("Not found.") }
1100
+ }
1101
+ }
1102
+ }
1103
+ };
1104
+ }
869
1105
  var manifest = {
870
1106
  id: "resend",
871
1107
  name: "Resend",
@@ -882,6 +1118,7 @@ var manifest = {
882
1118
  kind: "openapi",
883
1119
  title: "Resend REST API subset",
884
1120
  coverage: "hand-authored",
1121
+ url: "/openapi.json",
885
1122
  operations: [
886
1123
  { operationId: "emails.send", method: "POST", path: "/emails", status: "hand-authored" },
887
1124
  { operationId: "emails.sendBatch", method: "POST", path: "/emails/batch", status: "hand-authored" },
@@ -1047,17 +1284,17 @@ function seedFromConfig(store, _baseUrl, config) {
1047
1284
  defaultAudience = rs.audiences.insert({ uuid: generateUuid(), name: "Default" });
1048
1285
  }
1049
1286
  for (const ct of config.contacts) {
1050
- let audienceId = defaultAudience.uuid;
1287
+ let audienceId2 = defaultAudience.uuid;
1051
1288
  if (ct.audience) {
1052
1289
  let audience = rs.audiences.findOneBy("name", ct.audience);
1053
1290
  if (!audience) {
1054
1291
  audience = rs.audiences.insert({ uuid: generateUuid(), name: ct.audience });
1055
1292
  }
1056
- audienceId = audience.uuid;
1293
+ audienceId2 = audience.uuid;
1057
1294
  }
1058
1295
  rs.contacts.insert({
1059
1296
  uuid: generateUuid(),
1060
- audience_id: audienceId,
1297
+ audience_id: audienceId2,
1061
1298
  email: ct.email,
1062
1299
  first_name: ct.first_name ?? null,
1063
1300
  last_name: ct.last_name ?? null,
@@ -1075,6 +1312,7 @@ var resendPlugin = {
1075
1312
  apiKeyRoutes(ctx);
1076
1313
  contactRoutes(ctx);
1077
1314
  inboxRoutes(ctx);
1315
+ openapiRoutes(ctx);
1078
1316
  },
1079
1317
  seed(_store, _baseUrl) {
1080
1318
  }
@@ -1087,4 +1325,4 @@ export {
1087
1325
  resendPlugin,
1088
1326
  seedFromConfig
1089
1327
  };
1090
- //# sourceMappingURL=dist-XM5HSBDC.js.map
1328
+ //# sourceMappingURL=dist-TWJXVA7X.js.map