diff --git a/types/jsforce/connection.d.ts b/types/jsforce/connection.d.ts new file mode 100644 index 0000000000..f3864eb5d8 --- /dev/null +++ b/types/jsforce/connection.d.ts @@ -0,0 +1,28 @@ +import { SObjectCreateOptions } from './create-options'; +import { DescribeSObjectResult } from './describe-result'; +import { Query } from './query'; +import { RecordResult } from './record-result'; +import { SObject } from './salesforce-object'; + +export interface ConnectionOptions { + instanceUrl?: string; + accessToken?: string; + refreshToken?: string; + oauth2?: { + clientId: string, + clientSecret: string, + redirectUri?: string, + }; + sessionId?: string; + serverUrl?: string; + redirectUri?: string; +} + +export type ConnectionEvent = "refresh"; + +export class Connection { + constructor(params: ConnectionOptions) + + sobject(resource: string): SObject; + on(eventName: ConnectionEvent, callback: Function): void; +} diff --git a/types/jsforce/create-options.d.ts b/types/jsforce/create-options.d.ts new file mode 100644 index 0000000000..e72de859c7 --- /dev/null +++ b/types/jsforce/create-options.d.ts @@ -0,0 +1,42 @@ +import { SalesforceId } from './salesforce-id'; +import { SObjectOptions } from './salesforce-object-options'; + +export interface SObjectCreateOptions extends SObjectOptions { + IsDeleted?: boolean; + MasterRecordId?: SalesforceId; + Name?: string; + Type?: string; + ParentId?: SalesforceId; + BillingStreet?: string; + BillingCity?: string; + BillingState?: string; + BillingPostalCode?: string; + BillingCountry?: string; + BillingLatitude?: number; + BillingLongitude?: number; + ShippingStreet?: string; + ShippingCity?: string; + ShippingState?: string; + ShippingPostalCode?: string; + ShippingCountry?: string; + ShippingLatitude?: number; + ShippingLongitude?: number; + Phone?: string; + Website?: string; + Industry?: string; + NumberOfEmployees?: number; + Description?: string; + OwnerId?: SalesforceId; + CreatedDate?: Date; + CreatedById?: SalesforceId; + LastModifiedDate?: Date; + LastModifiedById?: SalesforceId; + SystemModstamp?: Date; + LastActivityDate?: Date; + LastViewedDate?: Date; + LastReferencedDate?: Date; + Jigsaw?: string; + JigsawCompanyId?: string; + AccountSource?: string; + SicDesc?: string; +} diff --git a/types/jsforce/date-enum.d.ts b/types/jsforce/date-enum.d.ts new file mode 100644 index 0000000000..0833be0f98 --- /dev/null +++ b/types/jsforce/date-enum.d.ts @@ -0,0 +1,39 @@ +export enum Date { + YESTERDAY, + TODAY, + TOMORROW, + LAST_WEEK, + THIS_WEEK, + NEXT_WEEK, + LAST_MONTH, + THIS_MONTH, + NEXT_MONTH, + LAST_90_DAYS, + NEXT_90_DAYS, + LAST_N_DAYS, + NEXT_N_DAYS, + NEXT_N_WEEKS, + LAST_N_WEEKS, + NEXT_N_MONTHS, + LAST_N_MONTHS, + THIS_QUARTER, + LAST_QUARTER, + NEXT_QUARTER, + NEXT_N_QUARTERS, + LAST_N_QUARTERS, + THIS_YEAR, + LAST_YEAR, + NEXT_YEAR, + NEXT_N_YEARS, + LAST_N_YEARS, + THIS_FISCAL_QUARTER, + LAST_FISCAL_QUARTER, + NEXT_FISCAL_QUARTER, + NEXT_N_FISCAL_QUARTERS, + LAST_N_FISCAL_QUARTERS, + THIS_FISCAL_YEAR, + LAST_FISCAL_YEAR, + NEXT_FISCAL_YEAR, + NEXT_N_FISCAL_YEARS, + LAST_N_FISCAL_YEARS +} diff --git a/types/jsforce/describe-result.d.ts b/types/jsforce/describe-result.d.ts new file mode 100644 index 0000000000..584a62d3bf --- /dev/null +++ b/types/jsforce/describe-result.d.ts @@ -0,0 +1,4 @@ +export interface DescribeSObjectResult { + label: string; + fields: string[]; +} diff --git a/types/jsforce/index.d.ts b/types/jsforce/index.d.ts new file mode 100644 index 0000000000..4c0f82b626 --- /dev/null +++ b/types/jsforce/index.d.ts @@ -0,0 +1,14 @@ +// Type definitions for archiver 1.8 +// Project: https://github.com/jsforce/jsforce +// Definitions by: Dolan Miu +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import * as fs from 'fs'; +import * as stream from 'stream'; +import * as express from 'express'; +import * as glob from 'glob'; + +export { Date } from './date-enum'; +export { RecordResult } from './record-result'; +export { Connection } from './connection'; +export { SObject } from './salesforce-object'; diff --git a/types/jsforce/jsforce-tests.ts b/types/jsforce/jsforce-tests.ts new file mode 100644 index 0000000000..70a41ec934 --- /dev/null +++ b/types/jsforce/jsforce-tests.ts @@ -0,0 +1,54 @@ +import * as sf from 'jsforce'; + +const salesforceConnection: sf.Connection = new sf.Connection({ + instanceUrl: '', + refreshToken: '', + oauth2: { + clientId: '', + clientSecret: '', + }, +}); + +salesforceConnection.sobject("Account").create({ + Name: "Test Acc 2", + BillingStreet: "Maplestory street", + BillingPostalCode: "ME4 666" +}, (err: Error, ret: sf.RecordResult) => { + if (err || !ret.success) { + return; + } +}); + +salesforceConnection.sobject("ContentVersion").create({ + OwnerId: '', + Title: 'hello', + PathOnClient: './hello-world.jpg', + VersionData: '{ Test: Data }' +}, (err: Error, ret: sf.RecordResult) => { + if (err || !ret.success) { + return; + } +}); + +salesforceConnection.sobject("ContentVersion").retrieve("world", { + test: "test" +}, (err: Error, ret: sf.RecordResult) => { + if (err || !ret.success) { + return; + } +}); + +salesforceConnection.sobject("ContentVersion").findOne({ Id: '' }, (err, contentVersion) => { +}); + +salesforceConnection.sobject("ContentDocumentLink").create({ + ContentDocumentId: '', + LinkedEntityId: '', + ShareType: "I" +}, (err: Error, ret: sf.RecordResult) => { + if (err || !ret.success) { + return; + } +}); + +sf.Date.YESTERDAY; diff --git a/types/jsforce/query.d.ts b/types/jsforce/query.d.ts new file mode 100644 index 0000000000..0d716c28da --- /dev/null +++ b/types/jsforce/query.d.ts @@ -0,0 +1,34 @@ +import { SalesforceId } from './salesforce-id'; +import { RecordResult } from './record-result'; + +export interface ExecuteOptions { + autoFetch?: boolean; + maxFetch?: number; + scanAll?: number; +} + +export class Query { + filter(filter: Object): Query; + hint(hint: Object): Query; + limit(value: number): Query; + maxFetch(value: number): Query; + offset(value: number): Query; + skip(value: number): Query; + sort(keyOrList: string | Object[] | Object, direction?: "ASC" | "DESC" | number): Query; + run(options?: ExecuteOptions, callback?: (err: Error, records: T[]) => void): Query; + execute(options?: ExecuteOptions, callback?: (err: Error, records: T[]) => void): Query; + exec(options?: ExecuteOptions, callback?: (err: Error, records: T[]) => void): Query; + del(callback?: (err: Error, ret: RecordResult) => void): any; + delete(callback?: (err: Error, ret: RecordResult) => void): any; + destroy(callback?: (err: Error, ret: RecordResult) => void): Promise; + explain(callback?: (err: Error, info: ExplainInfo) => void): Promise; + scanAll(value: boolean): Query; + select(fields: Object | string[] | string): Query; + then(onSuccess?: Function, onRejected?: Function): Promise; + thenCall(callback?: (err: Error, records: T) => void): Query; + toSOQL(callback: (err: Error, soql: string) => void): Promise; + update(mapping: any, type: string, callback: (err: Error, records: RecordResult[]) => void): Promise; + where(conditions: Object | string): Query; +} + +export class ExplainInfo { } diff --git a/types/jsforce/record-result.d.ts b/types/jsforce/record-result.d.ts new file mode 100644 index 0000000000..bf53a5bf98 --- /dev/null +++ b/types/jsforce/record-result.d.ts @@ -0,0 +1,7 @@ +import { SalesforceId } from './salesforce-id'; + +export interface RecordResult { + id: SalesforceId; + success: boolean; + anys: Object[]; +} diff --git a/types/jsforce/salesforce-id.d.ts b/types/jsforce/salesforce-id.d.ts new file mode 100644 index 0000000000..87d086880f --- /dev/null +++ b/types/jsforce/salesforce-id.d.ts @@ -0,0 +1,2 @@ +export class SalesforceId extends String { +} diff --git a/types/jsforce/salesforce-object-options.d.ts b/types/jsforce/salesforce-object-options.d.ts new file mode 100644 index 0000000000..2cc6e46f39 --- /dev/null +++ b/types/jsforce/salesforce-object-options.d.ts @@ -0,0 +1,7 @@ +import { SalesforceId } from './salesforce-id'; + +export interface SObjectOptions { + Id?: SalesforceId; + Name?: string; + ExtId__c?: string; +} diff --git a/types/jsforce/salesforce-object.d.ts b/types/jsforce/salesforce-object.d.ts new file mode 100644 index 0000000000..ac2288fe33 --- /dev/null +++ b/types/jsforce/salesforce-object.d.ts @@ -0,0 +1,90 @@ +import * as stream from 'stream'; + +import { SObjectCreateOptions } from './create-options'; +import { DescribeSObjectResult } from './describe-result'; +import { Query } from './query'; +import { RecordResult } from './record-result'; +import { Connection } from './connection'; +import { SalesforceId } from './salesforce-id'; + +export class SObject { + record(options: any, callback?: (err: Error, ret: any) => void): void; + update(options: SObjectCreateOptions, callback?: (err: Error, ret: any) => void): void; + retrieve(ids: string | string[], callback?: (err: Error, ret: any) => void): void; + retrieve(ids: string | string[], options?: Object, callback?: (err: Error, ret: any) => void): void; + // upsert(options: SObjectOptions): void; + describeGlobal(callback: (err: Error, res: any) => void): void; + describe$(callback: (err: Error, ret: DescribeSObjectResult) => void): void; + describeGlobal$(callback: (err: Error, res: any) => void): void; + + find(query?: any, callback?: (err: Error, ret: T[]) => void): Query; + find(query?: any, fields?: Object | string[] | string, callback?: (err: Error, ret: T[]) => void): Query; + find(query?: any, fields?: Object | string[] | string, options?: Object, callback?: (err: Error, ret: T[]) => void): Query; + + findOne(query?: any, callback?: (err: Error, ret: T) => void): void; + findOne(query?: any, fields?: Object | string[] | string, callback?: (err: Error, ret: T) => void): void; + findOne(query?: any, fields?: Object | string[] | string, options?: Object, callback?: (err: Error, ret: T) => void): void; + + approvalLayouts(callback?: (layoutInfo: ApprovalLayoutInfo) => void): Promise; + bulkload(operation: string, options?: { extIdField?: string }, input?: Record[] | stream.Stream[] | string[], callback?: (err: Error, ret: RecordResult) => void): Batch; + compactLayouts(callback?: CompactLayoutInfo): Promise; + count(conditions?: Object | string, callback?: (err: Error, num: number) => void): Promise; + create(options: any | any[], callback?: (err: Error, ret: RecordResult | RecordResult[]) => void): Promise; + createBulk(input?: Record[] | stream.Stream | String, callback?: (err: Error, ret: RecordResult) => void): Batch; + del(ids: string | string[], callback?: (err: Error, ret: any) => void): void; + destroy(ids: string | string[], callback?: (err: Error, ret: any) => void): void; + delete(ids: string | string[], callback?: (err: Error, ret: any) => void): void; + deleteBulk(input?: Record[] | stream.Stream | String, callback?: (err: Error, ret: RecordResult) => void): Batch; + destroyBulk(input?: Record[] | stream.Stream | String, callback?: (err: Error, ret: RecordResult) => void): Batch; + destroyHardBulk(input?: Record[] | stream.Stream | String, callback?: (err: Error, ret: RecordResult) => void): Batch; + deleted(start: Date | string, end: Date | string, callback?: (info: DeletedRecordsInfo) => void): Promise; + deleteHardBulk(input?: Record[] | stream.Stream | String, callback?: (err: Error, ret: RecordResult) => void): Batch; + describe(callback?: (err: Error, ret: DescribeSObjectResult) => void): Promise; + insert(options: any | any[], callback?: (err: Error, ret: RecordResult | RecordResult[]) => void): Promise; + insertBulk(input?: Record[] | stream.Stream | String, callback?: (err: Error, ret: RecordResult) => void): Batch; + layouts(layoutName?: string, callback?: (err: Error, info: LayoutInfo) => void): Promise; + listview(id: string): ListView; + listviews(callback?: (err: Error, info: ListViewsInfo) => void): Promise; + quickAction(actionName: string): QuickAction; + quickActions(callback?: (err: Error, info: any) => void): Promise; + recent(callback?: (err: Error, ret: RecordResult) => void): Promise; + select(field?: Object | string[] | string, callback?: (err: Error, ret: T[]) => void): Query; +} + +export interface ApprovalLayoutInfo { + approvalLayouts: Object[]; +} + +export class Record extends Object { + constructor(connection: Connection, type: SObject, id: SalesforceId) +} + +export class Batch extends stream.Writable { +} + +export interface CompactLayoutInfo { + compactLayouts: Object[]; + defaultCompactLayoutId: string; + recordTypeCompactLayoutMappings: Object[]; +} + +export interface DeletedRecordsInfo { + earliestDateAvailable: string; + latestDateCovered: string; + deletedRecords: { + id: string, + deletedDate: string, + }; +} + +export interface LayoutInfo { + layouts: Object[]; + recordTypeMappings: Object[]; +} + +export class ListView { + constructor(connection: Connection, type: SObject, id: SalesforceId) +} + +export class ListViewsInfo { } +export class QuickAction { } diff --git a/types/jsforce/tsconfig.json b/types/jsforce/tsconfig.json new file mode 100644 index 0000000000..63812424be --- /dev/null +++ b/types/jsforce/tsconfig.json @@ -0,0 +1,30 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "connection.d.ts", + "create-options.d.ts", + "date-enum.d.ts", + "salesforce-object-options.d.ts", + "salesforce-object.d.ts", + "salesforce-id.d.ts", + "query.d.ts", + "describe-result.d.ts", + "jsforce-tests.ts" + ] +} \ No newline at end of file diff --git a/types/jsforce/tslint.json b/types/jsforce/tslint.json new file mode 100644 index 0000000000..a62d0d4e68 --- /dev/null +++ b/types/jsforce/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "ban-types": false + } +}