Skip to content

Commit

Permalink
extended typings support
Browse files Browse the repository at this point in the history
  • Loading branch information
muratgozel committed Feb 13, 2024
1 parent c973e20 commit aadcd28
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 1 deletion.
73 changes: 73 additions & 0 deletions build/MIMEMessage.d.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import type { Email, MailboxAddrObject, MailboxAddrText, MailboxConfig } from './Mailbox.js';
import { type HeadersObject, MIMEMessageHeader } from './MIMEMessageHeader.js';
import { Mailbox } from './Mailbox.js';
import { MIMEMessageContent } from './MIMEMessageContent.js';
export declare class MIMEMessage {
envctx: EnvironmentContext;
headers: MIMEMessageHeader;
boundaries: Boundaries;
validTypes: string[];
validContentTransferEncodings: string[];
messages: MIMEMessageContent[];
constructor(envctx: EnvironmentContext);
asRaw(): string;
asEncoded(): string;
dumpTextContent(plaintext: MIMEMessageContent | undefined, html: MIMEMessageContent | undefined, boundary: string): string;
hasInlineAttachments(): boolean;
hasAttachments(): boolean;
getAttachments(): MIMEMessageContent[] | [];
getInlineAttachments(): MIMEMessageContent[] | [];
getMessageByType(type: string): MIMEMessageContent | undefined;
addAttachment(opts: AttachmentOptions): MIMEMessageContent;
addMessage(opts: ContentOptions): MIMEMessageContent;
private _addMessage;
setSender(input: MailboxAddrObject | MailboxAddrText | Email, config?: MailboxConfig): Mailbox;
getSender(): string | Mailbox | undefined;
setRecipients(input: MailboxAddrObject | MailboxAddrText | Email | MailboxAddrObject[] | MailboxAddrText[] | Email[], config?: MailboxConfig): Mailbox[];
getRecipients(config?: MailboxConfig): string | Mailbox | undefined;
setRecipient(input: MailboxAddrObject | MailboxAddrText | Email | MailboxAddrObject[] | MailboxAddrText[] | Email[], config?: MailboxConfig): Mailbox[];
setTo(input: MailboxAddrObject | MailboxAddrText | Email | MailboxAddrObject[] | MailboxAddrText[] | Email[], config?: MailboxConfig): Mailbox[];
setCc(input: MailboxAddrObject | MailboxAddrText | Email | MailboxAddrObject[] | MailboxAddrText[] | Email[], config?: MailboxConfig): Mailbox[];
setBcc(input: MailboxAddrObject | MailboxAddrText | Email | MailboxAddrObject[] | MailboxAddrText[] | Email[], config?: MailboxConfig): Mailbox[];
setSubject(value: string): string;
getSubject(): string | Mailbox | undefined;
setHeader(name: string, value: any): string;
getHeader(name: string): string | Mailbox | undefined;
setHeaders(obj: Record<string, any>): string[];
getHeaders(): HeadersObject;
toBase64(v: string): string;
toBase64WebSafe(v: string): string;
generateBoundaries(): void;
isArray(v: unknown): v is any[];
isObject(v: unknown): v is object;
}
export interface EnvironmentContext {
toBase64: (v: string) => string;
toBase64WebSafe: (v: string) => string;
eol: string;
validateContentType: (v: string) => string | false;
}
export interface Boundaries {
mixed: string;
alt: string;
related: string;
}
export type ContentTransferEncoding = '7bit' | '8bit' | 'binary' | 'quoted-printable' | 'base64';
export interface ContentHeaders {
'Content-Type'?: string;
'Content-Transfer-Encoding'?: ContentTransferEncoding;
'Content-Disposition'?: string;
'Content-ID'?: string;
[index: string]: string | undefined;
}
export interface ContentOptions {
data: string;
encoding?: ContentTransferEncoding;
contentType: string;
headers?: ContentHeaders;
charset?: string;
}
export interface AttachmentOptions extends ContentOptions {
inline?: boolean;
filename: string;
}
16 changes: 16 additions & 0 deletions build/MIMEMessageContent.d.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { EnvironmentContext } from './MIMEMessage';
import type { Mailbox } from './Mailbox';
import { type HeadersObject, MIMEMessageContentHeader } from './MIMEMessageHeader.js';
export declare class MIMEMessageContent {
envctx: EnvironmentContext;
headers: MIMEMessageContentHeader;
data: string;
constructor(envctx: EnvironmentContext, data: string, headers?: {});
dump(): string;
isAttachment(): boolean;
isInlineAttachment(): boolean;
setHeader(name: string, value: any): string;
getHeader(name: string): string | Mailbox | undefined;
setHeaders(obj: Record<string, any>): string[];
getHeaders(): HeadersObject;
}
37 changes: 37 additions & 0 deletions build/MIMEMessageHeader.d.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { EnvironmentContext } from './MIMEMessage';
import { Mailbox } from './Mailbox.js';
export declare class MIMEMessageHeader {
envctx: EnvironmentContext;
fields: HeaderField[];
constructor(envctx: EnvironmentContext);
dump(): string;
toObject(): HeadersObject;
get(name: string): string | Mailbox | undefined;
set(name: string, value: any): HeaderField;
setCustom(obj: HeaderField): HeaderField;
validateMailboxSingle(v: unknown): v is Mailbox;
validateMailboxMulti(v: unknown): boolean;
dumpMailboxMulti(v: unknown): string;
dumpMailboxSingle(v: unknown): string;
isHeaderField(v: unknown): v is HeaderField;
isObject(v: unknown): v is object;
isArrayOfMailboxes(v: unknown): v is Mailbox[];
isArray(v: unknown): v is any[];
}
export declare class MIMEMessageContentHeader extends MIMEMessageHeader {
fields: {
name: string;
}[];
constructor(envctx: EnvironmentContext);
}
export type HeadersObject = Record<string, string | Mailbox | undefined>;
export interface HeaderField {
name: string;
dump?: (v: string | Mailbox | Mailbox[] | undefined) => string;
value?: string | Mailbox | undefined;
validate?: (v: unknown) => boolean;
required?: boolean;
disabled?: boolean;
generator?: () => string;
custom?: boolean;
}
5 changes: 5 additions & 0 deletions build/MIMETextError.d.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export declare class MIMETextError extends Error {
name: string;
description: string;
constructor(message: string, description?: string);
}
24 changes: 24 additions & 0 deletions build/Mailbox.d.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export declare class Mailbox {
reSpecCompliantAddr: RegExp;
name: string;
addr: string;
type: MailboxType;
constructor(input: MailboxAddrObject | MailboxAddrText | Email, config?: MailboxConfig);
getAddrDomain(): string;
dump(): string;
parse(input: MailboxAddrObject | MailboxAddrText | Email): this;
isMailboxAddrText(v: unknown): v is MailboxAddrText;
isMailboxAddrObject(v: unknown): v is MailboxAddrObject;
isObject(v: unknown): v is object;
}
export interface MailboxConfig {
type: MailboxType;
}
export interface MailboxAddrObject {
addr: string;
name?: string;
type?: MailboxType;
}
export type MailboxType = 'To' | 'From' | 'Cc' | 'Bcc';
export type Email = string;
export type MailboxAddrText = string;
12 changes: 12 additions & 0 deletions build/entrypoints/browser.d.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { MIMEMessage } from '../MIMEMessage.js';
export declare function createMimeMessage(): MIMEMessage;
export { MIMEMessage } from '../MIMEMessage.js';
export { Mailbox } from '../Mailbox.js';
export { MIMETextError } from '../MIMETextError.js';
export { MIMEMessageHeader } from '../MIMEMessageHeader.js';
export { MIMEMessageContent } from '../MIMEMessageContent.js';
export type * from '../MIMEMessage.js';
export type * from '../Mailbox.js';
export type * from '../MIMETextError.js';
export type * from '../MIMEMessageHeader.js';
export type * from '../MIMEMessageContent.js';
12 changes: 12 additions & 0 deletions build/entrypoints/gas.d.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { MIMEMessage } from '../MIMEMessage.js';
export declare function createMimeMessage(): MIMEMessage;
export { MIMEMessage } from '../MIMEMessage.js';
export { Mailbox } from '../Mailbox.js';
export { MIMETextError } from '../MIMETextError.js';
export { MIMEMessageHeader } from '../MIMEMessageHeader.js';
export { MIMEMessageContent } from '../MIMEMessageContent.js';
export type * from '../MIMEMessage.js';
export type * from '../Mailbox.js';
export type * from '../MIMETextError.js';
export type * from '../MIMEMessageHeader.js';
export type * from '../MIMEMessageContent.js';
12 changes: 12 additions & 0 deletions build/entrypoints/node.d.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { MIMEMessage } from '../MIMEMessage.js';
export declare function createMimeMessage(): MIMEMessage;
export { MIMEMessage } from '../MIMEMessage.js';
export { Mailbox } from '../Mailbox.js';
export { MIMETextError } from '../MIMETextError.js';
export { MIMEMessageHeader } from '../MIMEMessageHeader.js';
export { MIMEMessageContent } from '../MIMEMessageContent.js';
export type * from '../MIMEMessage.js';
export type * from '../Mailbox.js';
export type * from '../MIMETextError.js';
export type * from '../MIMEMessageHeader.js';
export type * from '../MIMEMessageContent.js';
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mimetext",
"version": "v3.0.20",
"version": "v3.0.21",
"description": "RFC 2822 compliant raw email message generator written in node.js",
"type": "module",
"exports": {
Expand Down Expand Up @@ -39,12 +39,14 @@
"default": "./build/bundles/mimetext.gas.js"
}
},
"types": "./build/entrypoints/node.d.ts",
"main": "./build/entrypoints/node.cjs",
"module": "./build/entrypoints/node.js",
"scripts": {
"setup": "exit 0",
"precompile": "rm -rf build/*",
"compile": "tsc -p tsconfig.json && babel build --out-dir build --out-file-extension .cjs",
"create-cts": "for f in build/**/*.d.ts; do cp -- \"$f\" \"${f%.ts}.cts\"; done && for f in build/*.d.ts; do cp -- \"$f\" \"${f%.ts}.cts\"; done",
"build": "rollup --config rollup.config.js",
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"docs": "typedoc --entryPointStrategy expand --includeVersion --excludePrivate ./src/entrypoints/node.ts ./src/entrypoints/gas.ts ./src/entrypoints/browser.ts"
Expand Down

0 comments on commit aadcd28

Please sign in to comment.