mailgun.js 10.1.0 → 10.2.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [10.2.0](https://github.com/mailgun/mailgun.js/compare/v10.1.0...v10.2.0) (2024-02-15)
6
+
7
+
8
+ ### Features
9
+
10
+ * Better types and handling for different FormData implementations ([c547be9](https://github.com/mailgun/mailgun.js/commits/c547be9895dc1fcfb625ddf0aadc82778e82a259))
11
+
5
12
  ## [10.1.0](https://github.com/mailgun/mailgun.js/compare/v10.0.1...v10.1.0) (2024-01-31)
6
13
 
7
14
 
@@ -32,11 +32,13 @@ export declare class MultipleValidationJob implements MultipleValidationJobResul
32
32
  }
33
33
  export default class MultipleValidationClient extends NavigationThruPages<MultipleValidationJobsListResult> implements IMultipleValidationClient {
34
34
  request: Request;
35
+ private attachmentsHandler;
35
36
  constructor(request: Request);
36
37
  private handleResponse;
37
38
  protected parseList(response: MultipleValidationJobsListResponse): MultipleValidationJobsListResult;
38
39
  list(query?: MultipleValidationJobsListQuery): Promise<MultipleValidationJobsListResult>;
39
40
  get(listId: string): Promise<MultipleValidationJob>;
41
+ private convertToExpectedShape;
40
42
  create(listId: string, data: MultipleValidationCreationData): Promise<CreatedMultipleValidationJob>;
41
43
  destroy(listId: string): Promise<CanceledMultipleValidationJob>;
42
44
  }
@@ -0,0 +1,27 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import { Readable } from 'stream';
5
+ import { CustomFile, CustomFileData } from '../../Types';
6
+ import { AttachmentInfo, StreamValue } from '../../Types/Common/Attachments';
7
+ declare class BlobFromStream {
8
+ private _stream;
9
+ size: number;
10
+ constructor(stream: Readable, size: number);
11
+ stream(): Readable;
12
+ get [Symbol.toStringTag](): string;
13
+ }
14
+ declare class AttachmentsHandler {
15
+ private getAttachmentOptions;
16
+ private getFileInfo;
17
+ private getCustomFileInfo;
18
+ private getBufferInfo;
19
+ isStream(data: unknown): data is StreamValue;
20
+ isCustomFile(obj: unknown): obj is CustomFile;
21
+ isBrowserFile(obj: unknown): obj is File;
22
+ isBuffer(data: unknown): data is Buffer;
23
+ getAttachmentInfo(attachment: CustomFile | File | string | CustomFileData): AttachmentInfo;
24
+ convertToFDexpectedShape(userProvidedValue: CustomFile | File | string | CustomFileData): string | Blob | Buffer | NodeJS.ReadableStream | (CustomFile & StreamValue);
25
+ getBlobFromStream(stream: Readable, size: number): BlobFromStream;
26
+ }
27
+ export default AttachmentsHandler;
@@ -4,5 +4,6 @@ export default class APIError extends Error implements APIErrorType {
4
4
  stack: string;
5
5
  details: string;
6
6
  type: string;
7
+ static getUserDataError(statusText: string, message: string): APIError;
7
8
  constructor({ status, statusText, message, body }: APIErrorOptions);
8
9
  }
@@ -1,14 +1,17 @@
1
1
  import * as NodeFormData from 'form-data';
2
- import { InputFormData } from '../../Types/Common';
2
+ import { FormDataInput, InputFormData } from '../../Types/Common';
3
+ import { MimeMessage } from '../../Types';
3
4
  declare class FormDataBuilder {
4
5
  private FormDataConstructor;
6
+ private fileKeys;
7
+ private attachmentsHandler;
5
8
  constructor(FormDataConstructor: InputFormData);
6
- createFormData(data: any): NodeFormData | FormData;
7
- private isFormDataPackage;
8
- private getAttachmentOptions;
9
+ createFormData(data: FormDataInput): NodeFormData | FormData;
9
10
  private addMimeDataToFD;
11
+ isMIME(data: unknown): data is MimeMessage;
12
+ private isFormDataPackage;
13
+ private isMessageAttachment;
10
14
  private addFilesToFD;
11
- private isStream;
12
15
  private addCommonPropertyToFD;
13
16
  }
14
17
  export default FormDataBuilder;
@@ -1,5 +1,5 @@
1
1
  import * as NodeFormData from 'form-data';
2
- import { RequestOptions, InputFormData, APIResponse, IpPoolDeleteData } from '../../Types';
2
+ import { RequestOptions, InputFormData, APIResponse, IpPoolDeleteData, FormDataInput } from '../../Types';
3
3
  declare class Request {
4
4
  private username;
5
5
  private key;
@@ -20,10 +20,10 @@ declare class Request {
20
20
  command(method: string, url: string, data?: Record<string, unknown> | Record<string, unknown>[] | string | NodeFormData | FormData, options?: Record<string, unknown>, addDefaultHeaders?: boolean): Promise<APIResponse>;
21
21
  get(url: string, query?: Record<string, unknown> | Array<Array<string>>, options?: Record<string, unknown>): Promise<APIResponse>;
22
22
  post(url: string, data?: Record<string, unknown> | string, options?: Record<string, unknown>): Promise<APIResponse>;
23
- postWithFD(url: string, data: Record<string, unknown> | Record<string, unknown>[]): Promise<APIResponse>;
24
- putWithFD(url: string, data: Record<string, unknown>): Promise<APIResponse>;
25
- patchWithFD(url: string, data: Record<string, unknown>): Promise<APIResponse>;
26
- put(url: string, data?: Record<string, unknown> | string, options?: Record<string, unknown>): Promise<APIResponse>;
23
+ postWithFD(url: string, data: FormDataInput): Promise<APIResponse>;
24
+ putWithFD(url: string, data: FormDataInput): Promise<APIResponse>;
25
+ patchWithFD(url: string, data: FormDataInput): Promise<APIResponse>;
26
+ put(url: string, data?: FormDataInput | string, options?: Record<string, unknown>): Promise<APIResponse>;
27
27
  delete(url: string, data?: IpPoolDeleteData): Promise<APIResponse>;
28
28
  }
29
29
  export default Request;
@@ -0,0 +1,12 @@
1
+ export type NodePipeFunction = (destination: WritableStream, options?: {
2
+ end?: boolean;
3
+ }) => void;
4
+ export type BrowserPipeFunction = (destination: WritableStream) => void;
5
+ export type StreamValue = {
6
+ pipe: NodePipeFunction | BrowserPipeFunction;
7
+ };
8
+ export type AttachmentInfo = {
9
+ filename?: string;
10
+ contentType?: string;
11
+ knownLength?: number;
12
+ };
@@ -1,7 +1,13 @@
1
1
  import * as NodeFormData from 'form-data';
2
+ import { FormDataInputValue } from '../Messages';
2
3
  export type FormDataOptions = {
3
- [key: string]: any;
4
+ [key: string]: NodeFormData;
4
5
  };
5
6
  export type InputFormData = {
6
- new (options?: HTMLFormElement | FormDataOptions): NodeFormData | FormData;
7
+ new (form?: HTMLFormElement | undefined, submitter?: HTMLElement | null | undefined): FormData;
8
+ } | {
9
+ new (options?: FormDataOptions): NodeFormData;
10
+ };
11
+ export type FormDataInput = {
12
+ [key: string]: FormDataInputValue;
7
13
  };
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  /**
3
4
  * Ensures the object has least one key present and not undefined
4
5
  *
@@ -7,6 +8,17 @@
7
8
  export type AtLeastOneKeyPresent<Object_, Keys extends keyof Object_ = keyof Object_> = Pick<Object_, Exclude<keyof Object_, Keys>> & {
8
9
  [K in Keys]-?: Required<Pick<Object_, K>> & Partial<Pick<Object_, Exclude<Keys, K>>>;
9
10
  }[Keys];
11
+ export type MimeMessage = string | Blob | Buffer | NodeJS.ReadableStream;
12
+ export type CustomFileData = string | Blob | File | Buffer | NodeJS.ReadableStream;
13
+ export type CustomFile = {
14
+ data: CustomFileData;
15
+ filename?: string;
16
+ contentType?: string;
17
+ knownLength?: number;
18
+ [key: string]: unknown;
19
+ };
20
+ export type MessageAttachment = CustomFile | CustomFile[] | File | File[] | string | CustomFileData | CustomFileData[];
21
+ export type FormDataInputValue = MimeMessage | CustomFileData | string | string[] | boolean | MessageAttachment | undefined | number;
10
22
  export type MailgunMessageContent = AtLeastOneKeyPresent<{
11
23
  /**
12
24
  * Body of the message. (text version)
@@ -19,7 +31,7 @@ export type MailgunMessageContent = AtLeastOneKeyPresent<{
19
31
  /**
20
32
  * Body of the message. (MIME version)
21
33
  */
22
- message?: string | Buffer | Blob;
34
+ message?: MimeMessage;
23
35
  /**
24
36
  * Name of a template stored via [template API](https://documentation.mailgun.com/en/latest/api-templates.html#api-templates). See [Templates](https://documentation.mailgun.com/en/latest/user_manual.html#templating) for more information
25
37
  */
@@ -57,7 +69,7 @@ export type MailgunMessageData = MailgunMessageContent & {
57
69
  *
58
70
  * **Important:** You must use `multipart/form-data` encoding when sending attachments.
59
71
  */
60
- attachment?: any;
72
+ attachment?: MessageAttachment;
61
73
  /**
62
74
  * Attachment with `inline` disposition. Can be used to send inline images (see example).
63
75
  *
@@ -163,7 +175,7 @@ export type MailgunMessageData = MailgunMessageContent & {
163
175
  * `v:` prefix followed by an arbitrary name allows to attach a custom JSON data to the message. See [Attaching Data to Messages](https://documentation.mailgun.com/en/latest/user_manual.html#manual-customdata) for more information.
164
176
  */
165
177
  'v:my-var'?: string;
166
- [key: string]: unknown;
178
+ [key: string]: FormDataInputValue;
167
179
  };
168
180
  export type MessagesSendAPIResponse = {
169
181
  status: number;
@@ -1,4 +1,5 @@
1
1
  import { PagesList, ParsedPagesList } from '../Common';
2
+ import { CustomFile, CustomFileData } from '../Messages';
2
3
  export type MultipleValidationJobData = {
3
4
  created_at: number;
4
5
  id: string;
@@ -57,12 +58,10 @@ export type CreatedMultipleValidationJob = {
57
58
  message: string;
58
59
  };
59
60
  export type MultipleValidationCreationData = {
60
- file: Record<string, unknown>;
61
- [key: string]: unknown | undefined;
61
+ file: CustomFileData | CustomFile;
62
62
  };
63
63
  export type MultipleValidationCreationDataUpdated = {
64
- multipleValidationFile: Record<string, unknown>;
65
- [key: string]: unknown | undefined;
64
+ multipleValidationFile: CustomFileData | CustomFile;
66
65
  };
67
66
  export type MultipleValidationJobsListResult = {
68
67
  jobs: MultipleValidationJobResult[];