mailgun.js 10.1.0 → 10.2.1

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,20 @@
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.1](https://github.com/mailgun/mailgun.js/compare/v10.2.0...v10.2.1) (2024-02-16)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * Source.on is not a function for t:variables ([e647143](https://github.com/mailgun/mailgun.js/commits/e64714326b443b70022c646ab4d0c123d1bf6abe))
11
+
12
+ ## [10.2.0](https://github.com/mailgun/mailgun.js/compare/v10.1.0...v10.2.0) (2024-02-15)
13
+
14
+
15
+ ### Features
16
+
17
+ * Better types and handling for different FormData implementations ([c547be9](https://github.com/mailgun/mailgun.js/commits/c547be9895dc1fcfb625ddf0aadc82778e82a259))
18
+
5
19
  ## [10.1.0](https://github.com/mailgun/mailgun.js/compare/v10.0.1...v10.1.0) (2024-01-31)
6
20
 
7
21
 
@@ -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,24 @@
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 | JsonObject;
22
+ export type JsonPrimitive = string | number | boolean | null;
23
+ export type JsonArray = Json[];
24
+ export type JsonObject = {
25
+ [key: string]: Json;
26
+ };
27
+ export type JsonComposite = JsonArray | JsonObject;
28
+ export type Json = JsonPrimitive | JsonComposite;
10
29
  export type MailgunMessageContent = AtLeastOneKeyPresent<{
11
30
  /**
12
31
  * Body of the message. (text version)
@@ -19,7 +38,7 @@ export type MailgunMessageContent = AtLeastOneKeyPresent<{
19
38
  /**
20
39
  * Body of the message. (MIME version)
21
40
  */
22
- message?: string | Buffer | Blob;
41
+ message?: MimeMessage;
23
42
  /**
24
43
  * 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
44
  */
@@ -57,7 +76,7 @@ export type MailgunMessageData = MailgunMessageContent & {
57
76
  *
58
77
  * **Important:** You must use `multipart/form-data` encoding when sending attachments.
59
78
  */
60
- attachment?: any;
79
+ attachment?: MessageAttachment;
61
80
  /**
62
81
  * Attachment with `inline` disposition. Can be used to send inline images (see example).
63
82
  *
@@ -73,6 +92,11 @@ export type MailgunMessageData = MailgunMessageContent & {
73
92
  * in the text part of the message in case of template sending
74
93
  */
75
94
  't:text'?: boolean | 'yes' | 'no';
95
+ /**
96
+ * A valid JSON-encoded dictionary used as the input for template variable expansion.
97
+ * See [Templates](https://documentation.mailgun.com/en/latest/api-templates.html#api-templates) for more information.
98
+ */
99
+ 't:variables'?: string | JsonObject;
76
100
  /**
77
101
  * Tag string. See [Tagging](https://documentation.mailgun.com/en/latest/user_manual.html#tagging) for more information.
78
102
  */
@@ -163,7 +187,7 @@ export type MailgunMessageData = MailgunMessageContent & {
163
187
  * `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
188
  */
165
189
  'v:my-var'?: string;
166
- [key: string]: unknown;
190
+ [key: string]: FormDataInputValue;
167
191
  };
168
192
  export type MessagesSendAPIResponse = {
169
193
  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[];