@sendmux/cli 1.2.0 → 1.3.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.
@@ -14,14 +14,26 @@ const clientFactories = {
14
14
  };
15
15
  export async function runSdkOperation(command, operation, flags) {
16
16
  validateAttachmentConvenienceFlags(command, operation, flags);
17
- const auth = await command.resolveAuth(flags, operation.requiredKeyKind);
18
- const clientConfig = {
19
- apiKey: auth.apiKey,
20
- ...(auth.baseUrl ? { baseUrl: auth.baseUrl } : {}),
21
- };
22
- const client = clientFactories[operation.surface](clientConfig);
17
+ let baseUrl;
18
+ let client;
19
+ if (operation.requiredKeyKind === "none") {
20
+ baseUrl = flags["base-url"] ?? process.env.SENDMUX_BASE_URL;
21
+ }
22
+ else {
23
+ const auth = await command.resolveAuth(flags, operation.requiredKeyKind);
24
+ baseUrl = auth.baseUrl;
25
+ client = clientFactories[operation.surface]({
26
+ apiKey: auth.apiKey,
27
+ ...(baseUrl ? { baseUrl } : {}),
28
+ });
29
+ }
23
30
  const operationOptions = await parseOperationOptions(command, operation, flags);
24
31
  const sdkOperation = operationFor(operation);
32
+ const baseRequestOptions = {
33
+ ...(client ? { client } : {}),
34
+ ...operationOptions,
35
+ ...(!client && baseUrl ? { baseUrl } : {}),
36
+ };
25
37
  if (operation.operationId === "mailboxCreateAttachmentUpload" && flags.file) {
26
38
  return createMailboxAttachmentUploadFromFile(command, client, operationOptions, flags);
27
39
  }
@@ -31,7 +43,7 @@ export async function runSdkOperation(command, operation, flags) {
31
43
  if ((operation.operationId === "mailboxSendMessage" || operation.operationId === "sendingSendEmail") && flags.attach?.length) {
32
44
  const nextOptions = await withAttachedFiles(command, operation, client, operationOptions, flags);
33
45
  const response = await sdkOperation({
34
- client,
46
+ ...baseRequestOptions,
35
47
  ...nextOptions,
36
48
  });
37
49
  return command.renderResult(rawResponseData(response));
@@ -39,8 +51,7 @@ export async function runSdkOperation(command, operation, flags) {
39
51
  if (operation.operationId === "mailboxStreamEvents") {
40
52
  const controller = new AbortController();
41
53
  const response = await sdkOperation({
42
- client,
43
- ...operationOptions,
54
+ ...baseRequestOptions,
44
55
  signal: controller.signal,
45
56
  });
46
57
  if (flags.follow) {
@@ -50,8 +61,7 @@ export async function runSdkOperation(command, operation, flags) {
50
61
  }
51
62
  if (operation.operationId === "mailboxGetMessageAttachment") {
52
63
  const response = await sdkOperation({
53
- client,
54
- ...operationOptions,
64
+ ...baseRequestOptions,
55
65
  parseAs: "arrayBuffer",
56
66
  });
57
67
  const data = rawResponseData(response);
@@ -60,10 +70,7 @@ export async function runSdkOperation(command, operation, flags) {
60
70
  }
61
71
  throw new Error("SDK operation mailboxGetMessageAttachment did not return binary content");
62
72
  }
63
- const response = await sdkOperation({
64
- client,
65
- ...operationOptions,
66
- });
73
+ const response = await sdkOperation(baseRequestOptions);
67
74
  const data = rawResponseData(response);
68
75
  if (operation.responseKind === "text" && typeof data === "string") {
69
76
  return command.renderTextResult(data);
@@ -186,6 +193,34 @@ async function withAttachedFiles(command, operation, client, operationOptions, f
186
193
  },
187
194
  };
188
195
  }
196
+ if (operation.operationId === "sendingSendEmail") {
197
+ const uploaded = [];
198
+ for (const file of files) {
199
+ const uploadResponse = await sdk.sending.sendingUploadAttachment({
200
+ client: client,
201
+ body: blobFor(file),
202
+ headers: {
203
+ "Content-Length": file.sizeBytes,
204
+ "Content-Type": file.contentType,
205
+ },
206
+ query: {
207
+ content_type: file.contentType,
208
+ filename: file.filename,
209
+ },
210
+ });
211
+ const result = envelopeData(uploadResponse, "sendingUploadAttachment");
212
+ uploaded.push({
213
+ attachment_id: stringField(result, "attachment_id", "sendingUploadAttachment"),
214
+ });
215
+ }
216
+ return {
217
+ ...operationOptions,
218
+ body: {
219
+ ...body,
220
+ attachments: [...existingAttachments, ...uploaded],
221
+ },
222
+ };
223
+ }
189
224
  return {
190
225
  ...operationOptions,
191
226
  body: {