@jsforce/jsforce-node 0.0.1 → 3.0.0-next.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/LICENSE +22 -0
- package/README.md +54 -0
- package/index.d.ts +4 -0
- package/index.js +1 -0
- package/lib/VERSION.d.ts +2 -0
- package/lib/VERSION.js +3 -0
- package/lib/api/analytics/types.d.ts +509 -0
- package/lib/api/analytics/types.js +2 -0
- package/lib/api/analytics.d.ts +163 -0
- package/lib/api/analytics.js +342 -0
- package/lib/api/apex.d.ts +44 -0
- package/lib/api/apex.js +86 -0
- package/lib/api/bulk.d.ts +444 -0
- package/lib/api/bulk.js +1372 -0
- package/lib/api/chatter.d.ts +133 -0
- package/lib/api/chatter.js +248 -0
- package/lib/api/metadata/schema.d.ts +16117 -0
- package/lib/api/metadata/schema.js +9094 -0
- package/lib/api/metadata.d.ts +189 -0
- package/lib/api/metadata.js +406 -0
- package/lib/api/soap/schema.d.ts +3167 -0
- package/lib/api/soap/schema.js +1787 -0
- package/lib/api/soap.d.ts +76 -0
- package/lib/api/soap.js +155 -0
- package/lib/api/streaming/extension.d.ts +94 -0
- package/lib/api/streaming/extension.js +151 -0
- package/lib/api/streaming.d.ts +160 -0
- package/lib/api/streaming.js +252 -0
- package/lib/api/tooling.d.ts +284 -0
- package/lib/api/tooling.js +202 -0
- package/lib/api/wsdl/wsdl2schema.d.ts +1 -0
- package/lib/api/wsdl/wsdl2schema.js +354 -0
- package/lib/browser/canvas.d.ts +12 -0
- package/lib/browser/canvas.js +77 -0
- package/lib/browser/client.d.ts +82 -0
- package/lib/browser/client.js +244 -0
- package/lib/browser/jsonp.d.ts +12 -0
- package/lib/browser/jsonp.js +69 -0
- package/lib/browser/registry.d.ts +3 -0
- package/lib/browser/registry.js +5 -0
- package/lib/browser/request.d.ts +10 -0
- package/lib/browser/request.js +202 -0
- package/lib/cache.d.ts +74 -0
- package/lib/cache.js +159 -0
- package/lib/connection.d.ts +355 -0
- package/lib/connection.js +1153 -0
- package/lib/core.d.ts +17 -0
- package/lib/core.js +55 -0
- package/lib/csv.d.ts +23 -0
- package/lib/csv.js +35 -0
- package/lib/date.d.ts +82 -0
- package/lib/date.js +201 -0
- package/lib/http-api.d.ts +75 -0
- package/lib/http-api.js +257 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +31 -0
- package/lib/jsforce.d.ts +26 -0
- package/lib/jsforce.js +67 -0
- package/lib/jwtOAuth2.d.ts +8 -0
- package/lib/jwtOAuth2.js +23 -0
- package/lib/oauth2.d.ts +92 -0
- package/lib/oauth2.js +245 -0
- package/lib/process.d.ts +157 -0
- package/lib/process.js +143 -0
- package/lib/query.d.ts +341 -0
- package/lib/query.js +817 -0
- package/lib/quick-action.d.ts +44 -0
- package/lib/quick-action.js +46 -0
- package/lib/record-reference.d.ts +46 -0
- package/lib/record-reference.js +65 -0
- package/lib/record-stream.d.ts +83 -0
- package/lib/record-stream.js +233 -0
- package/lib/registry/base.d.ts +43 -0
- package/lib/registry/base.js +96 -0
- package/lib/registry/empty.d.ts +7 -0
- package/lib/registry/empty.js +13 -0
- package/lib/registry/file.d.ts +11 -0
- package/lib/registry/file.js +51 -0
- package/lib/registry/index.d.ts +8 -0
- package/lib/registry/index.js +21 -0
- package/lib/registry/sfdx.d.ts +56 -0
- package/lib/registry/sfdx.js +133 -0
- package/lib/registry/types.d.ts +47 -0
- package/lib/registry/types.js +2 -0
- package/lib/request-helper.d.ts +23 -0
- package/lib/request-helper.js +102 -0
- package/lib/request.d.ts +11 -0
- package/lib/request.js +75 -0
- package/lib/session-refresh-delegate.d.ts +31 -0
- package/lib/session-refresh-delegate.js +69 -0
- package/lib/soap.d.ts +60 -0
- package/lib/soap.js +246 -0
- package/lib/sobject.d.ts +258 -0
- package/lib/sobject.js +376 -0
- package/lib/soql-builder.d.ts +25 -0
- package/lib/soql-builder.js +226 -0
- package/lib/transport.d.ts +63 -0
- package/lib/transport.js +175 -0
- package/lib/types/common.d.ts +560 -0
- package/lib/types/common.js +2 -0
- package/lib/types/index.d.ts +7 -0
- package/lib/types/index.js +23 -0
- package/lib/types/projection.d.ts +26 -0
- package/lib/types/projection.js +2 -0
- package/lib/types/record.d.ts +44 -0
- package/lib/types/record.js +2 -0
- package/lib/types/schema.d.ts +50 -0
- package/lib/types/schema.js +2 -0
- package/lib/types/soap.d.ts +43 -0
- package/lib/types/soap.js +2 -0
- package/lib/types/standard-schema.d.ts +16199 -0
- package/lib/types/standard-schema.js +2 -0
- package/lib/types/util.d.ts +7 -0
- package/lib/types/util.js +2 -0
- package/lib/util/formatter.d.ts +8 -0
- package/lib/util/formatter.js +24 -0
- package/lib/util/function.d.ts +32 -0
- package/lib/util/function.js +52 -0
- package/lib/util/logger.d.ts +29 -0
- package/lib/util/logger.js +102 -0
- package/lib/util/promise.d.ts +19 -0
- package/lib/util/promise.js +25 -0
- package/lib/util/stream.d.ts +12 -0
- package/lib/util/stream.js +88 -0
- package/package.json +260 -6
- package/typings/faye/index.d.ts +16 -0
- package/typings/index.d.ts +1 -0
package/lib/core.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import jsforce from './jsforce';
|
|
2
|
+
import SfDate from './date';
|
|
3
|
+
import registry, { Registry } from './registry';
|
|
4
|
+
import browser, { BrowserClient } from './browser/client';
|
|
5
|
+
import VERSION from './VERSION';
|
|
6
|
+
import RecordReference from './record-reference';
|
|
7
|
+
import RecordStream from './record-stream';
|
|
8
|
+
export * from './oauth2';
|
|
9
|
+
export * from './jwtOAuth2';
|
|
10
|
+
export * from './connection';
|
|
11
|
+
export * from './query';
|
|
12
|
+
export * from './quick-action';
|
|
13
|
+
export * from './sobject';
|
|
14
|
+
export * from './types';
|
|
15
|
+
export { VERSION, SfDate as Date, SfDate, BrowserClient, RecordReference, RecordStream, registry, browser, };
|
|
16
|
+
export type { Registry };
|
|
17
|
+
export default jsforce;
|
package/lib/core.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.browser = exports.registry = exports.RecordStream = exports.RecordReference = exports.BrowserClient = exports.SfDate = exports.Date = exports.VERSION = void 0;
|
|
33
|
+
const jsforce_1 = __importDefault(require("./jsforce"));
|
|
34
|
+
const date_1 = __importDefault(require("./date"));
|
|
35
|
+
exports.Date = date_1.default;
|
|
36
|
+
exports.SfDate = date_1.default;
|
|
37
|
+
const registry_1 = __importDefault(require("./registry"));
|
|
38
|
+
exports.registry = registry_1.default;
|
|
39
|
+
const client_1 = __importStar(require("./browser/client"));
|
|
40
|
+
exports.browser = client_1.default;
|
|
41
|
+
Object.defineProperty(exports, "BrowserClient", { enumerable: true, get: function () { return client_1.BrowserClient; } });
|
|
42
|
+
const VERSION_1 = __importDefault(require("./VERSION"));
|
|
43
|
+
exports.VERSION = VERSION_1.default;
|
|
44
|
+
const record_reference_1 = __importDefault(require("./record-reference"));
|
|
45
|
+
exports.RecordReference = record_reference_1.default;
|
|
46
|
+
const record_stream_1 = __importDefault(require("./record-stream"));
|
|
47
|
+
exports.RecordStream = record_stream_1.default;
|
|
48
|
+
__exportStar(require("./oauth2"), exports);
|
|
49
|
+
__exportStar(require("./jwtOAuth2"), exports);
|
|
50
|
+
__exportStar(require("./connection"), exports);
|
|
51
|
+
__exportStar(require("./query"), exports);
|
|
52
|
+
__exportStar(require("./quick-action"), exports);
|
|
53
|
+
__exportStar(require("./sobject"), exports);
|
|
54
|
+
__exportStar(require("./types"), exports);
|
|
55
|
+
exports.default = jsforce_1.default;
|
package/lib/csv.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
import { Transform } from 'stream';
|
|
6
|
+
import { Options as ParseOpts } from 'csv-parse/sync';
|
|
7
|
+
import { Options as StringifyOpts } from 'csv-stringify';
|
|
8
|
+
/**
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseCSV(str: string, options?: ParseOpts): Object[];
|
|
12
|
+
/**
|
|
13
|
+
* @private
|
|
14
|
+
*/
|
|
15
|
+
export declare function toCSV(records: Object[], options?: StringifyOpts): string;
|
|
16
|
+
/**
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseCSVStream(options?: ParseOpts): Transform;
|
|
20
|
+
/**
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
export declare function serializeCSVStream(options?: StringifyOpts): Transform;
|
package/lib/csv.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeCSVStream = exports.parseCSVStream = exports.toCSV = exports.parseCSV = void 0;
|
|
4
|
+
const csv_parse_1 = require("csv-parse");
|
|
5
|
+
const sync_1 = require("csv-parse/sync");
|
|
6
|
+
const csv_stringify_1 = require("csv-stringify");
|
|
7
|
+
const sync_2 = require("csv-stringify/sync");
|
|
8
|
+
/**
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
function parseCSV(str, options) {
|
|
12
|
+
return (0, sync_1.parse)(str, { ...options, columns: true });
|
|
13
|
+
}
|
|
14
|
+
exports.parseCSV = parseCSV;
|
|
15
|
+
/**
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
function toCSV(records, options) {
|
|
19
|
+
return (0, sync_2.stringify)(records, { ...options, header: true });
|
|
20
|
+
}
|
|
21
|
+
exports.toCSV = toCSV;
|
|
22
|
+
/**
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
function parseCSVStream(options) {
|
|
26
|
+
return new csv_parse_1.Parser({ ...options, columns: true });
|
|
27
|
+
}
|
|
28
|
+
exports.parseCSVStream = parseCSVStream;
|
|
29
|
+
/**
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
function serializeCSVStream(options) {
|
|
33
|
+
return (0, csv_stringify_1.stringify)({ ...options, header: true });
|
|
34
|
+
}
|
|
35
|
+
exports.serializeCSVStream = serializeCSVStream;
|
package/lib/date.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A date object to keep Salesforce date literal
|
|
3
|
+
*
|
|
4
|
+
* @class
|
|
5
|
+
* @constructor
|
|
6
|
+
* @see http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_soql_select_dateformats.htm
|
|
7
|
+
*/
|
|
8
|
+
export declare class SfDate {
|
|
9
|
+
private _literal;
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
constructor(literal: string);
|
|
14
|
+
/**
|
|
15
|
+
* Returns literal when converted to string
|
|
16
|
+
*/
|
|
17
|
+
toJSON(): string;
|
|
18
|
+
toString: () => string;
|
|
19
|
+
/**
|
|
20
|
+
* Convert JavaScript date object to ISO8601 Date format (e.g. 2012-10-31)
|
|
21
|
+
*
|
|
22
|
+
* @param {String|Number|Date} date - Input date
|
|
23
|
+
* @returns {SfDate} - Salesforce date literal with ISO8601 date format
|
|
24
|
+
*/
|
|
25
|
+
static toDateLiteral(date: string | number | Date): SfDate;
|
|
26
|
+
/**
|
|
27
|
+
* Convert JavaScript date object to ISO8601 DateTime format
|
|
28
|
+
* (e.g. 2012-10-31T12:34:56Z)
|
|
29
|
+
*/
|
|
30
|
+
static toDateTimeLiteral(date: string | number | Date): SfDate;
|
|
31
|
+
/**
|
|
32
|
+
* Convert JavaScript date object to ISO8601 time format
|
|
33
|
+
* (e.g. 12:34:56.789Z)
|
|
34
|
+
*/
|
|
35
|
+
static toTimeLiteral(time: string | number | Date): SfDate;
|
|
36
|
+
/**
|
|
37
|
+
* Parse IS08601 date(time) formatted string and return date instance
|
|
38
|
+
*/
|
|
39
|
+
static parseDate(str: string): Date;
|
|
40
|
+
/**
|
|
41
|
+
* Parse IS08601 time formatted string and convert to parse string
|
|
42
|
+
*/
|
|
43
|
+
static parseTime(str: string): Date;
|
|
44
|
+
static YESTERDAY: SfDate;
|
|
45
|
+
static TODAY: SfDate;
|
|
46
|
+
static TOMORROW: SfDate;
|
|
47
|
+
static LAST_WEEK: SfDate;
|
|
48
|
+
static THIS_WEEK: SfDate;
|
|
49
|
+
static NEXT_WEEK: SfDate;
|
|
50
|
+
static LAST_MONTH: SfDate;
|
|
51
|
+
static THIS_MONTH: SfDate;
|
|
52
|
+
static NEXT_MONTH: SfDate;
|
|
53
|
+
static LAST_90_DAYS: SfDate;
|
|
54
|
+
static NEXT_90_DAYS: SfDate;
|
|
55
|
+
static LAST_N_DAYS: (num: number) => SfDate;
|
|
56
|
+
static NEXT_N_DAYS: (num: number) => SfDate;
|
|
57
|
+
static NEXT_N_WEEKS: (num: number) => SfDate;
|
|
58
|
+
static LAST_N_WEEKS: (num: number) => SfDate;
|
|
59
|
+
static NEXT_N_MONTHS: (num: number) => SfDate;
|
|
60
|
+
static LAST_N_MONTHS: (num: number) => SfDate;
|
|
61
|
+
static THIS_QUARTER: SfDate;
|
|
62
|
+
static LAST_QUARTER: SfDate;
|
|
63
|
+
static NEXT_QUARTER: SfDate;
|
|
64
|
+
static NEXT_N_QUARTERS: (num: number) => SfDate;
|
|
65
|
+
static LAST_N_QUARTERS: (num: number) => SfDate;
|
|
66
|
+
static THIS_YEAR: SfDate;
|
|
67
|
+
static LAST_YEAR: SfDate;
|
|
68
|
+
static NEXT_YEAR: SfDate;
|
|
69
|
+
static NEXT_N_YEARS: (num: number) => SfDate;
|
|
70
|
+
static LAST_N_YEARS: (num: number) => SfDate;
|
|
71
|
+
static THIS_FISCAL_QUARTER: SfDate;
|
|
72
|
+
static LAST_FISCAL_QUARTER: SfDate;
|
|
73
|
+
static NEXT_FISCAL_QUARTER: SfDate;
|
|
74
|
+
static THIS_FISCAL_YEAR: SfDate;
|
|
75
|
+
static NEXT_N_FISCAL_QUARTERS: (num: number) => SfDate;
|
|
76
|
+
static LAST_N_FISCAL_QUARTERS: (num: number) => SfDate;
|
|
77
|
+
static LAST_FISCAL_YEAR: SfDate;
|
|
78
|
+
static NEXT_FISCAL_YEAR: SfDate;
|
|
79
|
+
static NEXT_N_FISCAL_YEARS: (num: number) => SfDate;
|
|
80
|
+
static LAST_N_FISCAL_YEARS: (num: number) => SfDate;
|
|
81
|
+
}
|
|
82
|
+
export default SfDate;
|
package/lib/date.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SfDate = void 0;
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
const formatter_1 = require("./util/formatter");
|
|
8
|
+
/** @private **/
|
|
9
|
+
function createLiteralBuilder(literal) {
|
|
10
|
+
return (num) => new SfDate(`${literal}:${String(num)}`); // eslint-disable-line no-use-before-define
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A date object to keep Salesforce date literal
|
|
14
|
+
*
|
|
15
|
+
* @class
|
|
16
|
+
* @constructor
|
|
17
|
+
* @see http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_soql_select_dateformats.htm
|
|
18
|
+
*/
|
|
19
|
+
class SfDate {
|
|
20
|
+
_literal;
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
constructor(literal) {
|
|
25
|
+
this._literal = literal;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns literal when converted to string
|
|
29
|
+
*/
|
|
30
|
+
toJSON() {
|
|
31
|
+
return this._literal;
|
|
32
|
+
}
|
|
33
|
+
toString = this.toJSON;
|
|
34
|
+
/**
|
|
35
|
+
* Convert JavaScript date object to ISO8601 Date format (e.g. 2012-10-31)
|
|
36
|
+
*
|
|
37
|
+
* @param {String|Number|Date} date - Input date
|
|
38
|
+
* @returns {SfDate} - Salesforce date literal with ISO8601 date format
|
|
39
|
+
*/
|
|
40
|
+
static toDateLiteral(date) {
|
|
41
|
+
let _date;
|
|
42
|
+
if (typeof date === 'number') {
|
|
43
|
+
_date = new Date(date);
|
|
44
|
+
}
|
|
45
|
+
else if (typeof date === 'string') {
|
|
46
|
+
_date = SfDate.parseDate(date);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
_date = date;
|
|
50
|
+
}
|
|
51
|
+
const yy = _date.getFullYear();
|
|
52
|
+
const mm = _date.getMonth() + 1;
|
|
53
|
+
const dd = _date.getDate();
|
|
54
|
+
const dstr = [yy, (0, formatter_1.zeroPad)(mm), (0, formatter_1.zeroPad)(dd)].join('-');
|
|
55
|
+
return new SfDate(dstr);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Convert JavaScript date object to ISO8601 DateTime format
|
|
59
|
+
* (e.g. 2012-10-31T12:34:56Z)
|
|
60
|
+
*/
|
|
61
|
+
static toDateTimeLiteral(date) {
|
|
62
|
+
let _date;
|
|
63
|
+
if (typeof date === 'number') {
|
|
64
|
+
_date = new Date(date);
|
|
65
|
+
}
|
|
66
|
+
else if (typeof date === 'string') {
|
|
67
|
+
_date = SfDate.parseDate(date);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
_date = date;
|
|
71
|
+
}
|
|
72
|
+
const yy = _date.getUTCFullYear();
|
|
73
|
+
const mm = _date.getUTCMonth() + 1;
|
|
74
|
+
const dd = _date.getUTCDate();
|
|
75
|
+
const hh = _date.getUTCHours();
|
|
76
|
+
const mi = _date.getUTCMinutes();
|
|
77
|
+
const ss = _date.getUTCSeconds();
|
|
78
|
+
const dtstr = `${[yy, (0, formatter_1.zeroPad)(mm), (0, formatter_1.zeroPad)(dd)].join('-')}T${[
|
|
79
|
+
(0, formatter_1.zeroPad)(hh),
|
|
80
|
+
(0, formatter_1.zeroPad)(mi),
|
|
81
|
+
(0, formatter_1.zeroPad)(ss),
|
|
82
|
+
].join(':')}Z`;
|
|
83
|
+
return new SfDate(dtstr);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Convert JavaScript date object to ISO8601 time format
|
|
87
|
+
* (e.g. 12:34:56.789Z)
|
|
88
|
+
*/
|
|
89
|
+
static toTimeLiteral(time) {
|
|
90
|
+
let _date = new Date(0);
|
|
91
|
+
if (typeof time === 'string') {
|
|
92
|
+
_date = SfDate.parseTime(time);
|
|
93
|
+
}
|
|
94
|
+
else if (typeof time === 'number') {
|
|
95
|
+
_date = new Date(time);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
_date = time;
|
|
99
|
+
}
|
|
100
|
+
const hh = _date.getUTCHours();
|
|
101
|
+
const mi = _date.getUTCMinutes();
|
|
102
|
+
const ss = _date.getUTCSeconds();
|
|
103
|
+
const sss = _date.getUTCMilliseconds();
|
|
104
|
+
const tstr = `${(0, formatter_1.zeroPad)(hh)}:${(0, formatter_1.zeroPad)(mi)}:${(0, formatter_1.zeroPad)(ss)}.${(0, formatter_1.zeroPad)(sss, 3)}Z`;
|
|
105
|
+
return new SfDate(tstr);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Parse IS08601 date(time) formatted string and return date instance
|
|
109
|
+
*/
|
|
110
|
+
static parseDate(str) {
|
|
111
|
+
let d = new Date();
|
|
112
|
+
const regexp = /^([\d]{4})-?([\d]{2})-?([\d]{2})(T([\d]{2}):?([\d]{2}):?([\d]{2})(.([\d]{3}))?(Z|([+-])([\d]{2}):?([\d]{2})))?$/;
|
|
113
|
+
const m = str.match(regexp);
|
|
114
|
+
if (m) {
|
|
115
|
+
d = new Date(0);
|
|
116
|
+
if (!m[4]) {
|
|
117
|
+
d.setFullYear(parseInt(m[1], 10));
|
|
118
|
+
d.setDate(parseInt(m[3], 10));
|
|
119
|
+
d.setMonth(parseInt(m[2], 10) - 1);
|
|
120
|
+
d.setHours(0);
|
|
121
|
+
d.setMinutes(0);
|
|
122
|
+
d.setSeconds(0);
|
|
123
|
+
d.setMilliseconds(0);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
d.setUTCFullYear(parseInt(m[1], 10));
|
|
127
|
+
d.setUTCDate(parseInt(m[3], 10));
|
|
128
|
+
d.setUTCMonth(parseInt(m[2], 10) - 1);
|
|
129
|
+
d.setUTCHours(parseInt(m[5], 10));
|
|
130
|
+
d.setUTCMinutes(parseInt(m[6], 10));
|
|
131
|
+
d.setUTCSeconds(parseInt(m[7], 10));
|
|
132
|
+
d.setUTCMilliseconds(parseInt(m[9] || '0', 10));
|
|
133
|
+
if (m[10] && m[10] !== 'Z') {
|
|
134
|
+
const offset = parseInt(m[12], 10) * 60 + parseInt(m[13], 10);
|
|
135
|
+
d.setTime((m[11] === '+' ? -1 : 1) * offset * 60 * 1000 + d.getTime());
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return d;
|
|
139
|
+
}
|
|
140
|
+
throw new Error(`Invalid date format is specified : ${str}`);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Parse IS08601 time formatted string and convert to parse string
|
|
144
|
+
*/
|
|
145
|
+
static parseTime(str) {
|
|
146
|
+
const regexp = /^([\d]{2}):?([\d]{2}):?([\d]{2})(.([\d]{3}))?Z?$/;
|
|
147
|
+
const m = str.match(regexp);
|
|
148
|
+
if (m) {
|
|
149
|
+
const d = new Date(0);
|
|
150
|
+
const hh = parseInt(m[1], 10);
|
|
151
|
+
const mi = parseInt(m[2], 10);
|
|
152
|
+
const ss = parseInt(m[3], 10);
|
|
153
|
+
const sss = parseInt(m[5] || '0', 10);
|
|
154
|
+
d.setUTCHours(hh);
|
|
155
|
+
d.setUTCMinutes(mi);
|
|
156
|
+
d.setUTCSeconds(ss);
|
|
157
|
+
d.setUTCMilliseconds(sss);
|
|
158
|
+
return d;
|
|
159
|
+
}
|
|
160
|
+
throw new Error(`Invalid time format is specified : ${str}`);
|
|
161
|
+
}
|
|
162
|
+
static YESTERDAY = new SfDate('YESTERDAY');
|
|
163
|
+
static TODAY = new SfDate('TODAY');
|
|
164
|
+
static TOMORROW = new SfDate('TOMORROW');
|
|
165
|
+
static LAST_WEEK = new SfDate('LAST_WEEK');
|
|
166
|
+
static THIS_WEEK = new SfDate('THIS_WEEK');
|
|
167
|
+
static NEXT_WEEK = new SfDate('NEXT_WEEK');
|
|
168
|
+
static LAST_MONTH = new SfDate('LAST_MONTH');
|
|
169
|
+
static THIS_MONTH = new SfDate('THIS_MONTH');
|
|
170
|
+
static NEXT_MONTH = new SfDate('NEXT_MONTH');
|
|
171
|
+
static LAST_90_DAYS = new SfDate('LAST_90_DAYS');
|
|
172
|
+
static NEXT_90_DAYS = new SfDate('NEXT_90_DAYS');
|
|
173
|
+
static LAST_N_DAYS = createLiteralBuilder('LAST_N_DAYS');
|
|
174
|
+
static NEXT_N_DAYS = createLiteralBuilder('NEXT_N_DAYS');
|
|
175
|
+
static NEXT_N_WEEKS = createLiteralBuilder('NEXT_N_WEEKS');
|
|
176
|
+
static LAST_N_WEEKS = createLiteralBuilder('LAST_N_WEEKS');
|
|
177
|
+
static NEXT_N_MONTHS = createLiteralBuilder('NEXT_N_MONTHS');
|
|
178
|
+
static LAST_N_MONTHS = createLiteralBuilder('LAST_N_MONTHS');
|
|
179
|
+
static THIS_QUARTER = new SfDate('THIS_QUARTER');
|
|
180
|
+
static LAST_QUARTER = new SfDate('LAST_QUARTER');
|
|
181
|
+
static NEXT_QUARTER = new SfDate('NEXT_QUARTER');
|
|
182
|
+
static NEXT_N_QUARTERS = createLiteralBuilder('NEXT_N_QUARTERS');
|
|
183
|
+
static LAST_N_QUARTERS = createLiteralBuilder('LAST_N_QUARTERS');
|
|
184
|
+
static THIS_YEAR = new SfDate('THIS_YEAR');
|
|
185
|
+
static LAST_YEAR = new SfDate('LAST_YEAR');
|
|
186
|
+
static NEXT_YEAR = new SfDate('NEXT_YEAR');
|
|
187
|
+
static NEXT_N_YEARS = createLiteralBuilder('NEXT_N_YEARS');
|
|
188
|
+
static LAST_N_YEARS = createLiteralBuilder('LAST_N_YEARS');
|
|
189
|
+
static THIS_FISCAL_QUARTER = new SfDate('THIS_FISCAL_QUARTER');
|
|
190
|
+
static LAST_FISCAL_QUARTER = new SfDate('LAST_FISCAL_QUARTER');
|
|
191
|
+
static NEXT_FISCAL_QUARTER = new SfDate('NEXT_FISCAL_QUARTER');
|
|
192
|
+
static THIS_FISCAL_YEAR = new SfDate('THIS_FISCAL_YEAR');
|
|
193
|
+
static NEXT_N_FISCAL_QUARTERS = createLiteralBuilder('NEXT_N_FISCAL_QUARTERS');
|
|
194
|
+
static LAST_N_FISCAL_QUARTERS = createLiteralBuilder('LAST_N_FISCAL_QUARTERS');
|
|
195
|
+
static LAST_FISCAL_YEAR = new SfDate('LAST_FISCAL_YEAR');
|
|
196
|
+
static NEXT_FISCAL_YEAR = new SfDate('NEXT_FISCAL_YEAR');
|
|
197
|
+
static NEXT_N_FISCAL_YEARS = createLiteralBuilder('NEXT_N_FISCAL_YEARS');
|
|
198
|
+
static LAST_N_FISCAL_YEARS = createLiteralBuilder('LAST_N_FISCAL_YEARS');
|
|
199
|
+
}
|
|
200
|
+
exports.SfDate = SfDate;
|
|
201
|
+
exports.default = SfDate;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
6
|
+
import { Logger } from './util/logger';
|
|
7
|
+
import { StreamPromise } from './util/promise';
|
|
8
|
+
import Connection from './connection';
|
|
9
|
+
import Transport from './transport';
|
|
10
|
+
import { HttpRequest, HttpRequestOptions, HttpResponse, Optional, Schema } from './types';
|
|
11
|
+
/**
|
|
12
|
+
* HTTP based API class with authorization hook
|
|
13
|
+
*/
|
|
14
|
+
export declare class HttpApi<S extends Schema> extends EventEmitter {
|
|
15
|
+
static _logger: Logger;
|
|
16
|
+
_conn: Connection<S>;
|
|
17
|
+
_logger: Logger;
|
|
18
|
+
_transport: Transport;
|
|
19
|
+
_responseType: string | void;
|
|
20
|
+
_noContentResponse: string | void;
|
|
21
|
+
_options: HttpRequestOptions;
|
|
22
|
+
constructor(conn: Connection<S>, options: any);
|
|
23
|
+
/**
|
|
24
|
+
* Callout to API endpoint using http
|
|
25
|
+
*/
|
|
26
|
+
request<R = unknown>(request: HttpRequest): StreamPromise<R>;
|
|
27
|
+
/**
|
|
28
|
+
* @protected
|
|
29
|
+
*/
|
|
30
|
+
getRefreshDelegate(): Optional<import("./session-refresh-delegate").SessionRefreshDelegate<S>>;
|
|
31
|
+
/**
|
|
32
|
+
* @protected
|
|
33
|
+
*/
|
|
34
|
+
beforeSend(request: HttpRequest): void;
|
|
35
|
+
/**
|
|
36
|
+
* Detect response content mime-type
|
|
37
|
+
* @protected
|
|
38
|
+
*/
|
|
39
|
+
getResponseContentType(response: HttpResponse): Optional<string>;
|
|
40
|
+
/**
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
parseResponseBody(response: HttpResponse): Promise<any>;
|
|
44
|
+
/**
|
|
45
|
+
* Get response body
|
|
46
|
+
* @protected
|
|
47
|
+
*/
|
|
48
|
+
getResponseBody(response: HttpResponse): Promise<any>;
|
|
49
|
+
/**
|
|
50
|
+
* Detect session expiry
|
|
51
|
+
* @protected
|
|
52
|
+
*/
|
|
53
|
+
isSessionExpired(response: HttpResponse): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Detect error response
|
|
56
|
+
* @protected
|
|
57
|
+
*/
|
|
58
|
+
isErrorResponse(response: HttpResponse): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Detect error in response body
|
|
61
|
+
* @protected
|
|
62
|
+
*/
|
|
63
|
+
hasErrorInResponseBody(_body: Optional<string>): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Parsing error message in response
|
|
66
|
+
* @protected
|
|
67
|
+
*/
|
|
68
|
+
parseError(body: any): any;
|
|
69
|
+
/**
|
|
70
|
+
* Get error message in response
|
|
71
|
+
* @protected
|
|
72
|
+
*/
|
|
73
|
+
getError(response: HttpResponse, body?: any): Promise<Error>;
|
|
74
|
+
}
|
|
75
|
+
export default HttpApi;
|