From fa2d30ed14172c5594ee6728dc51b1ca253c7eb8 Mon Sep 17 00:00:00 2001 From: Seth Westphal Date: Tue, 30 Aug 2016 16:17:53 -0500 Subject: [PATCH 1/5] Add opentok typings with tests. --- opentok/opentok-tests.ts | 63 +++++++++++++++++++++++++++++++ opentok/opentok.d.ts | 80 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 opentok/opentok-tests.ts create mode 100644 opentok/opentok.d.ts diff --git a/opentok/opentok-tests.ts b/opentok/opentok-tests.ts new file mode 100644 index 0000000000..c6cdfbca66 --- /dev/null +++ b/opentok/opentok-tests.ts @@ -0,0 +1,63 @@ +import * as OpenTok from 'opentok'; + +const client = new OpenTok('API_KEY', 'API_SECRET'); + +const sessionOptions: OpenTok.SessionOptions = { + mediaMode: 'routed', + archiveMode: 'manual', + location: '12.34.56.78', +}; + +client.createSession(sessionOptions, (err: Error, session: OpenTok.Session) => { + if (err) return console.log(err); + console.log(session.sessionId); +}); + +const tokenOptions: OpenTok.TokenOptions = { + role: 'subscriber', + data: 'name=Seth', + expireTime: 123456, +}; + +const token = client.generateToken('SESSION_ID', tokenOptions); + +const archiveOptions: OpenTok.ArchiveOptions = { + name: 'name', + hasAudio: true, + hasVideo: true, + outputMode: 'individual', +}; + +client.startArchive('SESSION_ID', archiveOptions, (err: Error, archive: OpenTok.Archive) => { + if (err) return console.log(err); + console.log(archive.id); +}); + +client.stopArchive('ARCHIVE_ID', (err: Error, archive: OpenTok.Archive) => { + if (err) return console.log(err); + console.log('Stopped archive:' + archive.id); +}); + +client.getArchive('ARCHIVE_ID', (err: Error, archive: OpenTok.Archive) => { + if (err) return console.log(err); + console.log(archive); +}); + +client.deleteArchive('ARCHIVE_ID', (err: Error) => { + if (err) return console.log(err); + console.log('success'); +}); + +const listArchivesOptions: OpenTok.ListArchivesOptions = { + count: 10, + offset: 5, +} + +client.listArchives(listArchivesOptions, (err: Error, archives: OpenTok.Archive[], totalCount: number) => { + if (err) return console.log(err); + + console.log(totalCount + ' archives'); + for (var i = 0; i < archives.length; i++) { + console.log(archives[i].id); + } +}); diff --git a/opentok/opentok.d.ts b/opentok/opentok.d.ts new file mode 100644 index 0000000000..d41e50b3e5 --- /dev/null +++ b/opentok/opentok.d.ts @@ -0,0 +1,80 @@ +// Type definitions for opentok v2.3.2 +// Project: https://github.com/opentok/opentok-node +// Definitions by: Seth Westphal +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module 'opentok' { + + namespace OpenTok { + + export type OutputMode = 'composed' | 'individual'; + + export type ArchiveStatus = 'available' | 'expired' | 'failed' | 'paused' | 'started' | 'stopped' | 'uploaded'; + + export interface Archive { + createdAt: number; + duration: string; + id: string; + name: string; + partnerId: string; + reason: string; + sessionId: string; + size: number; + status: ArchiveStatus; + hasAudio: boolean; + hasVideo: boolean; + outputMode: OutputMode; + url: string; + } + + export interface ArchiveOptions { + name?: string; + hasAudio?: boolean; + hasVideo?: boolean; + outputMode?: OutputMode; + } + + export type MediaMode = 'relayed' | 'routed'; + + export type ArchiveMode = 'manual' | 'always'; + + export interface SessionOptions { + mediaMode?: MediaMode; + archiveMode?: ArchiveMode; + location?: string; + } + + export interface Session { + sessionId: string; + } + + export type Token = string; + + export type Role = 'subscriber' | 'publisher' | 'moderator'; + + export interface TokenOptions { + role?: Role; + data?: string; + expireTime?: number; + } + + export interface ListArchivesOptions { + count?: number; + offset?: number; + } + } + + class OpenTok { + constructor(apiKey: string, apiSecret: string); + + public createSession(options: OpenTok.SessionOptions, callback: (err: Error, session: OpenTok.Session) => void): void; + public generateToken(sessionId: string, options: OpenTok.TokenOptions): OpenTok.Token; + public startArchive(sessionId: string, options: OpenTok.ArchiveOptions, callback: (err: Error, archive: OpenTok.Archive) => void): void; + public stopArchive(archiveId: string, callback: (err: Error, archive: OpenTok.Archive) => void): void; + public getArchive(archiveId: string, callback: (err: Error, archive: OpenTok.Archive) => void): void; + public deleteArchive(archiveId: string, callback: (err: Error) => void): void; + public listArchives(options: OpenTok.ListArchivesOptions, callback: (err: Error, archives: OpenTok.Archive[], totalCount: number) => void): void; + } + + export = OpenTok; +} From 6b369e37586e78f4439c79adc750f1eb6ce5e79a Mon Sep 17 00:00:00 2001 From: Seth Westphal Date: Tue, 30 Aug 2016 17:07:22 -0500 Subject: [PATCH 2/5] Add fill-pdf with tests. --- fill-pdf/fill-pdf-tests.ts | 15 +++++++++++++++ fill-pdf/fill-pdf.d.ts | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 fill-pdf/fill-pdf-tests.ts create mode 100644 fill-pdf/fill-pdf.d.ts diff --git a/fill-pdf/fill-pdf-tests.ts b/fill-pdf/fill-pdf-tests.ts new file mode 100644 index 0000000000..44b4f23531 --- /dev/null +++ b/fill-pdf/fill-pdf-tests.ts @@ -0,0 +1,15 @@ +import * as fillPdf from 'fill-pdf'; + +var formData: fillPdf.FormData = { FieldName: 'Text to put into form field' }; +var pdfTemplatePath = 'templates.pdf'; +var extendArgs: string[] = []; + +fillPdf.generatePdf(formData, pdfTemplatePath, extendArgs, (err: Error, output: Buffer) => { + if ( !err ) { + console.log('Success!'); + // output is a buffer + } +}); + +var result = fillPdf.generateFdf(formData); +// result is a buffer diff --git a/fill-pdf/fill-pdf.d.ts b/fill-pdf/fill-pdf.d.ts new file mode 100644 index 0000000000..d35057f934 --- /dev/null +++ b/fill-pdf/fill-pdf.d.ts @@ -0,0 +1,16 @@ +// Type definitions for fill-pdf v0.5.0 +// Project: https://github.com/dommmel/fill-pdf +// Definitions by: Seth Westphal +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare module 'fill-pdf' { + + export interface FormData { + [name: string]: string; + } + + export function generatePdf(data: FormData, templatePath: string, extendArgs: string[], callback?: (err: Error, output: Buffer) => void): void; + export function generateFdf(data: FormData): Buffer; +} From 5f2539f4a0b10cc4bb894bff6107491f0e5a4a4b Mon Sep 17 00:00:00 2001 From: Seth Westphal Date: Tue, 30 Aug 2016 17:15:40 -0500 Subject: [PATCH 3/5] Add html-pdf typings and tests. --- html-pdf/html-pdf-tests.ts | 10 +++++ html-pdf/html-pdf.d.ts | 80 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 html-pdf/html-pdf-tests.ts create mode 100644 html-pdf/html-pdf.d.ts diff --git a/html-pdf/html-pdf-tests.ts b/html-pdf/html-pdf-tests.ts new file mode 100644 index 0000000000..f6a5ad6e1b --- /dev/null +++ b/html-pdf/html-pdf-tests.ts @@ -0,0 +1,10 @@ +import * as fs from 'fs'; +import * as pdf from 'html-pdf'; + +var html = fs.readFileSync('./test/businesscard.html', 'utf8'); +var options: pdf.CreateOptions = { format: 'Letter' }; + +pdf.create(html, options).toFile('./businesscard.pdf', (err: Error, res: pdf.FileInfo) => { + if (err) return console.log(err); + console.log(res); // { filename: '/app/businesscard.pdf' } +}); diff --git a/html-pdf/html-pdf.d.ts b/html-pdf/html-pdf.d.ts new file mode 100644 index 0000000000..07c4be9f71 --- /dev/null +++ b/html-pdf/html-pdf.d.ts @@ -0,0 +1,80 @@ +// Type definitions for html-pdf v2.1.0 +// Project: https://github.com/marcbachmann/node-html-pdf +// Definitions by: Seth Westphal +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare module 'html-pdf' { + + import * as fs from 'fs'; + + export interface CreateOptions { + + // Export options + directory?: string; + + // Papersize Options: http://phantomjs.org/api/webpage/property/paper-size.html + height?: string; + width?: string; + format?: 'A3' | 'A4' | 'A5' | 'Legal' | 'Letter' | 'Tabloid'; + orientation?: 'portrait' | 'landscape'; + + // Page options + border?: string | { + top?: string; + right?: string; + bottom?: string; + left?: string; + }; + + header?: { + height?: string; + contents?: string; + }; + footer?: { + height?: string; + contents?: { + first?: string; + [page: number]: string; + default?: string; + last?: string; + }; + }; + + // Rendering options + base?: string; + + // Zooming option, can be used to scale images if `options.type` is not pdf + zoomFactor?: string; + + // File options + type?: 'png' | 'jpeg' | 'pdf'; + quality?: string; + + // Script options + phantomPath?: string; + phantomArgs?: string[]; + script?: string; + timeout?: number; + + // HTTP Headers that are used for requests + httpHeaders?: { + [header: string]: string; + }; + + } + + export interface FileInfo { + filename: string; + } + + export interface CreateResult { + toBuffer(callback: (err: Error, buffer: Buffer) => void): void; + toFile(callback: (err: Error, res: FileInfo) => void): void; + toFile(filename?: string, callback?: (err: Error, res: FileInfo) => void): void; + toStream(callback: (err: Error, stream: fs.ReadStream) => void): void; + } + + export function create(html: string, options?: CreateOptions): CreateResult; +} From a6474285c37274633f9ec548962e7de29f0489a5 Mon Sep 17 00:00:00 2001 From: Seth Westphal Date: Tue, 30 Aug 2016 17:21:52 -0500 Subject: [PATCH 4/5] Add phone-formatter typings and tests. --- phone-formatter/phone-formatter-tests.ts | 7 +++++++ phone-formatter/phone-formatter.d.ts | 14 ++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 phone-formatter/phone-formatter-tests.ts create mode 100644 phone-formatter/phone-formatter.d.ts diff --git a/phone-formatter/phone-formatter-tests.ts b/phone-formatter/phone-formatter-tests.ts new file mode 100644 index 0000000000..1912fbf23a --- /dev/null +++ b/phone-formatter/phone-formatter-tests.ts @@ -0,0 +1,7 @@ +import * as phoneFormatter from 'phone-formatter'; + +phoneFormatter.normalize('212.555.1212'); +phoneFormatter.normalize('+1 (212) 555-1212'); + +phoneFormatter.format('(212) 555-1212', 'NNN.NNN.NNNN'); +phoneFormatter.format('(212) 555-1212', 'NNN.NNN.NNNN', {normalize: false}); diff --git a/phone-formatter/phone-formatter.d.ts b/phone-formatter/phone-formatter.d.ts new file mode 100644 index 0000000000..2626616657 --- /dev/null +++ b/phone-formatter/phone-formatter.d.ts @@ -0,0 +1,14 @@ +// Type definitions for phone-formatter v0.0.2 +// Project: https://github.com/stevekinney/node-phone-formatter +// Definitions by: Seth Westphal +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module 'phone-formatter' { + + export interface FormatOptions { + normalize: boolean; + } + + export function normalize(digits: string): string; + export function format(digits: string, format: string, options?: FormatOptions): string; +} From 208abb5b313e1f0701918761a6b2e3d8131c68b6 Mon Sep 17 00:00:00 2001 From: Seth Westphal Date: Tue, 30 Aug 2016 17:28:00 -0500 Subject: [PATCH 5/5] Fix imports for typing tests. --- fill-pdf/fill-pdf-tests.ts | 2 ++ html-pdf/html-pdf-tests.ts | 3 +++ opentok/opentok-tests.ts | 2 ++ phone-formatter/phone-formatter-tests.ts | 2 ++ 4 files changed, 9 insertions(+) diff --git a/fill-pdf/fill-pdf-tests.ts b/fill-pdf/fill-pdf-tests.ts index 44b4f23531..e5b34cd943 100644 --- a/fill-pdf/fill-pdf-tests.ts +++ b/fill-pdf/fill-pdf-tests.ts @@ -1,3 +1,5 @@ +/// + import * as fillPdf from 'fill-pdf'; var formData: fillPdf.FormData = { FieldName: 'Text to put into form field' }; diff --git a/html-pdf/html-pdf-tests.ts b/html-pdf/html-pdf-tests.ts index f6a5ad6e1b..6a214ef231 100644 --- a/html-pdf/html-pdf-tests.ts +++ b/html-pdf/html-pdf-tests.ts @@ -1,3 +1,6 @@ +/// +/// + import * as fs from 'fs'; import * as pdf from 'html-pdf'; diff --git a/opentok/opentok-tests.ts b/opentok/opentok-tests.ts index c6cdfbca66..dcbb1f8aa0 100644 --- a/opentok/opentok-tests.ts +++ b/opentok/opentok-tests.ts @@ -1,3 +1,5 @@ +/// + import * as OpenTok from 'opentok'; const client = new OpenTok('API_KEY', 'API_SECRET'); diff --git a/phone-formatter/phone-formatter-tests.ts b/phone-formatter/phone-formatter-tests.ts index 1912fbf23a..89b84c04a0 100644 --- a/phone-formatter/phone-formatter-tests.ts +++ b/phone-formatter/phone-formatter-tests.ts @@ -1,3 +1,5 @@ +/// + import * as phoneFormatter from 'phone-formatter'; phoneFormatter.normalize('212.555.1212');