@jsforce/jsforce-node 0.0.1 → 3.0.0-next.2
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 +253 -0
- package/lib/api/bulk.js +678 -0
- package/lib/api/bulk2.d.ts +324 -0
- package/lib/api/bulk2.js +800 -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 +356 -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 +295 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +32 -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 +257 -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/get-body-size.d.ts +4 -0
- package/lib/util/get-body-size.js +39 -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 +262 -6
- package/typings/faye/index.d.ts +16 -0
- package/typings/index.d.ts +1 -0
package/lib/http-api.js
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HttpApi = void 0;
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
const events_1 = require("events");
|
|
11
|
+
const xml2js_1 = __importDefault(require("xml2js"));
|
|
12
|
+
const logger_1 = require("./util/logger");
|
|
13
|
+
const promise_1 = require("./util/promise");
|
|
14
|
+
const csv_1 = require("./csv");
|
|
15
|
+
const stream_1 = require("./util/stream");
|
|
16
|
+
const get_body_size_1 = require("./util/get-body-size");
|
|
17
|
+
/** @private */
|
|
18
|
+
function parseJSON(str) {
|
|
19
|
+
return JSON.parse(str);
|
|
20
|
+
}
|
|
21
|
+
/** @private */
|
|
22
|
+
async function parseXML(str) {
|
|
23
|
+
return xml2js_1.default.parseStringPromise(str, { explicitArray: false });
|
|
24
|
+
}
|
|
25
|
+
/** @private */
|
|
26
|
+
function parseText(str) {
|
|
27
|
+
return str;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* HTTP based API class with authorization hook
|
|
31
|
+
*/
|
|
32
|
+
class HttpApi extends events_1.EventEmitter {
|
|
33
|
+
static _logger = (0, logger_1.getLogger)('http-api');
|
|
34
|
+
_conn;
|
|
35
|
+
_logger;
|
|
36
|
+
_transport;
|
|
37
|
+
_responseType;
|
|
38
|
+
_noContentResponse;
|
|
39
|
+
_options;
|
|
40
|
+
constructor(conn, options) {
|
|
41
|
+
super();
|
|
42
|
+
this._conn = conn;
|
|
43
|
+
this._logger = conn._logLevel
|
|
44
|
+
? HttpApi._logger.createInstance(conn._logLevel)
|
|
45
|
+
: HttpApi._logger;
|
|
46
|
+
this._responseType = options.responseType;
|
|
47
|
+
this._transport = options.transport || conn._transport;
|
|
48
|
+
this._noContentResponse = options.noContentResponse;
|
|
49
|
+
this._options = options;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Callout to API endpoint using http
|
|
53
|
+
*/
|
|
54
|
+
request(request) {
|
|
55
|
+
return promise_1.StreamPromise.create(() => {
|
|
56
|
+
const { stream, setStream } = (0, stream_1.createLazyStream)();
|
|
57
|
+
const promise = (async () => {
|
|
58
|
+
const refreshDelegate = this.getRefreshDelegate();
|
|
59
|
+
/* TODO decide remove or not this section */
|
|
60
|
+
/*
|
|
61
|
+
// remember previous instance url in case it changes after a refresh
|
|
62
|
+
const lastInstanceUrl = conn.instanceUrl;
|
|
63
|
+
|
|
64
|
+
// check to see if the token refresh has changed the instance url
|
|
65
|
+
if(lastInstanceUrl !== conn.instanceUrl){
|
|
66
|
+
// if the instance url has changed
|
|
67
|
+
// then replace the current request urls instance url fragment
|
|
68
|
+
// with the updated instance url
|
|
69
|
+
request.url = request.url.replace(lastInstanceUrl,conn.instanceUrl);
|
|
70
|
+
}
|
|
71
|
+
*/
|
|
72
|
+
if (refreshDelegate && refreshDelegate.isRefreshing()) {
|
|
73
|
+
await refreshDelegate.waitRefresh();
|
|
74
|
+
const bodyPromise = this.request(request);
|
|
75
|
+
setStream(bodyPromise.stream());
|
|
76
|
+
const body = await bodyPromise;
|
|
77
|
+
return body;
|
|
78
|
+
}
|
|
79
|
+
// hook before sending
|
|
80
|
+
this.beforeSend(request);
|
|
81
|
+
this.emit('request', request);
|
|
82
|
+
this._logger.debug(`<request> method=${request.method}, url=${request.url}`);
|
|
83
|
+
const requestTime = Date.now();
|
|
84
|
+
const requestPromise = this._transport.httpRequest(request, this._options);
|
|
85
|
+
setStream(requestPromise.stream());
|
|
86
|
+
let response;
|
|
87
|
+
try {
|
|
88
|
+
response = await requestPromise;
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
this._logger.error(err);
|
|
92
|
+
throw err;
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
const responseTime = Date.now();
|
|
96
|
+
this._logger.debug(`elapsed time: ${responseTime - requestTime} msec`);
|
|
97
|
+
}
|
|
98
|
+
if (!response) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this._logger.debug(`<response> status=${String(response.statusCode)}, url=${request.url}`);
|
|
102
|
+
this.emit('response', response);
|
|
103
|
+
// Refresh token if session has been expired and requires authentication
|
|
104
|
+
// when session refresh delegate is available
|
|
105
|
+
if (this.isSessionExpired(response) && refreshDelegate) {
|
|
106
|
+
await refreshDelegate.refresh(requestTime);
|
|
107
|
+
/* remove the `content-length` header after token refresh
|
|
108
|
+
*
|
|
109
|
+
* SOAP requests include the access token their the body,
|
|
110
|
+
* if the first req had an invalid token and jsforce successfully
|
|
111
|
+
* refreshed it we need to remove the `content-length` header
|
|
112
|
+
* so that it get's re-calculated again with the new body.
|
|
113
|
+
*
|
|
114
|
+
* REST request aren't affected by this because the access token
|
|
115
|
+
* is sent via HTTP headers
|
|
116
|
+
*
|
|
117
|
+
* `_message` is only present in SOAP requests
|
|
118
|
+
*/
|
|
119
|
+
if ('_message' in request &&
|
|
120
|
+
request.headers &&
|
|
121
|
+
'content-length' in request.headers) {
|
|
122
|
+
delete request.headers['content-length'];
|
|
123
|
+
}
|
|
124
|
+
return this.request(request);
|
|
125
|
+
}
|
|
126
|
+
if (this.isErrorResponse(response)) {
|
|
127
|
+
const err = await this.getError(response);
|
|
128
|
+
throw err;
|
|
129
|
+
}
|
|
130
|
+
const body = await this.getResponseBody(response);
|
|
131
|
+
return body;
|
|
132
|
+
})();
|
|
133
|
+
return { stream, promise };
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* @protected
|
|
138
|
+
*/
|
|
139
|
+
getRefreshDelegate() {
|
|
140
|
+
return this._conn._refreshDelegate;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* @protected
|
|
144
|
+
*/
|
|
145
|
+
beforeSend(request) {
|
|
146
|
+
/* eslint-disable no-param-reassign */
|
|
147
|
+
const headers = request.headers || {};
|
|
148
|
+
if (this._conn.accessToken) {
|
|
149
|
+
headers.Authorization = `Bearer ${this._conn.accessToken}`;
|
|
150
|
+
}
|
|
151
|
+
if (this._conn._callOptions) {
|
|
152
|
+
const callOptions = [];
|
|
153
|
+
for (const name of Object.keys(this._conn._callOptions)) {
|
|
154
|
+
callOptions.push(`${name}=${this._conn._callOptions[name]}`);
|
|
155
|
+
}
|
|
156
|
+
headers['Sforce-Call-Options'] = callOptions.join(', ');
|
|
157
|
+
}
|
|
158
|
+
const bodySize = (0, get_body_size_1.getBodySize)(request.body, headers);
|
|
159
|
+
const cannotHaveBody = ['GET', 'HEAD', 'OPTIONS'].includes(request.method);
|
|
160
|
+
if (!cannotHaveBody &&
|
|
161
|
+
!!request.body &&
|
|
162
|
+
!('transfer-encoding' in headers) &&
|
|
163
|
+
!('content-length' in headers) &&
|
|
164
|
+
!!bodySize) {
|
|
165
|
+
this._logger.debug(`missing 'content-length' header, setting it to: ${bodySize}`);
|
|
166
|
+
headers['content-length'] = String(bodySize);
|
|
167
|
+
}
|
|
168
|
+
request.headers = headers;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Detect response content mime-type
|
|
172
|
+
* @protected
|
|
173
|
+
*/
|
|
174
|
+
getResponseContentType(response) {
|
|
175
|
+
return (this._responseType ||
|
|
176
|
+
(response.headers && response.headers['content-type']));
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* @private
|
|
180
|
+
*/
|
|
181
|
+
async parseResponseBody(response) {
|
|
182
|
+
const contentType = this.getResponseContentType(response) || '';
|
|
183
|
+
const parseBody = /^(text|application)\/xml(;|$)/.test(contentType)
|
|
184
|
+
? parseXML
|
|
185
|
+
: /^application\/json(;|$)/.test(contentType)
|
|
186
|
+
? parseJSON
|
|
187
|
+
: /^text\/csv(;|$)/.test(contentType)
|
|
188
|
+
? csv_1.parseCSV
|
|
189
|
+
: parseText;
|
|
190
|
+
try {
|
|
191
|
+
return parseBody(response.body);
|
|
192
|
+
}
|
|
193
|
+
catch (e) {
|
|
194
|
+
return response.body;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Get response body
|
|
199
|
+
* @protected
|
|
200
|
+
*/
|
|
201
|
+
async getResponseBody(response) {
|
|
202
|
+
if (response.statusCode === 204) {
|
|
203
|
+
// No Content
|
|
204
|
+
return this._noContentResponse;
|
|
205
|
+
}
|
|
206
|
+
const body = await this.parseResponseBody(response);
|
|
207
|
+
let err;
|
|
208
|
+
if (this.hasErrorInResponseBody(body)) {
|
|
209
|
+
err = await this.getError(response, body);
|
|
210
|
+
throw err;
|
|
211
|
+
}
|
|
212
|
+
if (response.statusCode === 300) {
|
|
213
|
+
// Multiple Choices
|
|
214
|
+
throw new HttpApiError('Multiple records found', 'MULTIPLE_CHOICES', body);
|
|
215
|
+
}
|
|
216
|
+
return body;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Detect session expiry
|
|
220
|
+
* @protected
|
|
221
|
+
*/
|
|
222
|
+
isSessionExpired(response) {
|
|
223
|
+
return response.statusCode === 401;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Detect error response
|
|
227
|
+
* @protected
|
|
228
|
+
*/
|
|
229
|
+
isErrorResponse(response) {
|
|
230
|
+
return response.statusCode >= 400;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Detect error in response body
|
|
234
|
+
* @protected
|
|
235
|
+
*/
|
|
236
|
+
hasErrorInResponseBody(_body) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Parsing error message in response
|
|
241
|
+
* @protected
|
|
242
|
+
*/
|
|
243
|
+
parseError(body) {
|
|
244
|
+
const errors = body;
|
|
245
|
+
// XML response
|
|
246
|
+
if (errors.Errors) {
|
|
247
|
+
return errors.Errors.Error;
|
|
248
|
+
}
|
|
249
|
+
return Array.isArray(errors) ? errors[0] : errors;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Get error message in response
|
|
253
|
+
* @protected
|
|
254
|
+
*/
|
|
255
|
+
async getError(response, body) {
|
|
256
|
+
let error;
|
|
257
|
+
try {
|
|
258
|
+
error = this.parseError(body || (await this.parseResponseBody(response)));
|
|
259
|
+
}
|
|
260
|
+
catch (e) {
|
|
261
|
+
// eslint-disable no-empty
|
|
262
|
+
}
|
|
263
|
+
error =
|
|
264
|
+
typeof error === 'object' &&
|
|
265
|
+
error !== null &&
|
|
266
|
+
typeof error.message === 'string'
|
|
267
|
+
? error
|
|
268
|
+
: {
|
|
269
|
+
errorCode: `ERROR_HTTP_${response.statusCode}`,
|
|
270
|
+
message: response.body,
|
|
271
|
+
};
|
|
272
|
+
if (response.headers['content-type'] === 'text/html') {
|
|
273
|
+
this._logger.debug(`html response.body: ${response.body}`);
|
|
274
|
+
return new HttpApiError(`HTTP response contains html content.
|
|
275
|
+
Check that the org exists and can be reached.
|
|
276
|
+
See error.content for the full html response.`, error.errorCode, error.message);
|
|
277
|
+
}
|
|
278
|
+
return new HttpApiError(error.message, error.errorCode);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
exports.HttpApi = HttpApi;
|
|
282
|
+
/**
|
|
283
|
+
*
|
|
284
|
+
*/
|
|
285
|
+
class HttpApiError extends Error {
|
|
286
|
+
errorCode;
|
|
287
|
+
content;
|
|
288
|
+
constructor(message, errorCode, content) {
|
|
289
|
+
super(message);
|
|
290
|
+
this.name = errorCode || this.name;
|
|
291
|
+
this.errorCode = this.name;
|
|
292
|
+
this.content = content;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
exports.default = HttpApi;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import jsforce from './jsforce';
|
|
2
|
+
import './api/analytics';
|
|
3
|
+
import './api/apex';
|
|
4
|
+
import './api/bulk';
|
|
5
|
+
import './api/bulk2';
|
|
6
|
+
import './api/chatter';
|
|
7
|
+
import './api/metadata';
|
|
8
|
+
import './api/soap';
|
|
9
|
+
import './api/streaming';
|
|
10
|
+
import './api/tooling';
|
|
11
|
+
export * from './types';
|
|
12
|
+
export * from './core';
|
|
13
|
+
export default jsforce;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
const jsforce_1 = __importDefault(require("./jsforce"));
|
|
21
|
+
require("./api/analytics");
|
|
22
|
+
require("./api/apex");
|
|
23
|
+
require("./api/bulk");
|
|
24
|
+
require("./api/bulk2");
|
|
25
|
+
require("./api/chatter");
|
|
26
|
+
require("./api/metadata");
|
|
27
|
+
require("./api/soap");
|
|
28
|
+
require("./api/streaming");
|
|
29
|
+
require("./api/tooling");
|
|
30
|
+
__exportStar(require("./types"), exports);
|
|
31
|
+
__exportStar(require("./core"), exports);
|
|
32
|
+
exports.default = jsforce_1.default;
|
package/lib/jsforce.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import VERSION from './VERSION';
|
|
4
|
+
import Connection from './connection';
|
|
5
|
+
import OAuth2 from './oauth2';
|
|
6
|
+
import SfDate from './date';
|
|
7
|
+
import { Registry } from './registry';
|
|
8
|
+
import { BrowserClient } from './browser/client';
|
|
9
|
+
import { JwtOAuth2 } from './jwtOAuth2';
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
declare class JSforce extends EventEmitter {
|
|
14
|
+
VERSION: typeof VERSION;
|
|
15
|
+
Connection: typeof Connection;
|
|
16
|
+
OAuth2: typeof OAuth2;
|
|
17
|
+
JwtOAuth2: typeof JwtOAuth2;
|
|
18
|
+
SfDate: typeof SfDate;
|
|
19
|
+
Date: typeof SfDate;
|
|
20
|
+
BrowserClient: typeof BrowserClient;
|
|
21
|
+
registry: Registry;
|
|
22
|
+
browser: BrowserClient;
|
|
23
|
+
}
|
|
24
|
+
export declare function registerModule(name: string, factory: (conn: Connection) => any): void;
|
|
25
|
+
declare const jsforce: JSforce;
|
|
26
|
+
export default jsforce;
|
package/lib/jsforce.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.registerModule = void 0;
|
|
30
|
+
const events_1 = require("events");
|
|
31
|
+
const VERSION_1 = __importDefault(require("./VERSION"));
|
|
32
|
+
const connection_1 = __importDefault(require("./connection"));
|
|
33
|
+
const oauth2_1 = __importDefault(require("./oauth2"));
|
|
34
|
+
const date_1 = __importDefault(require("./date"));
|
|
35
|
+
const registry_1 = __importDefault(require("./registry"));
|
|
36
|
+
const client_1 = __importStar(require("./browser/client"));
|
|
37
|
+
const jwtOAuth2_1 = require("./jwtOAuth2");
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
*/
|
|
41
|
+
class JSforce extends events_1.EventEmitter {
|
|
42
|
+
VERSION = VERSION_1.default;
|
|
43
|
+
Connection = connection_1.default;
|
|
44
|
+
OAuth2 = oauth2_1.default;
|
|
45
|
+
JwtOAuth2 = jwtOAuth2_1.JwtOAuth2;
|
|
46
|
+
SfDate = date_1.default;
|
|
47
|
+
Date = date_1.default;
|
|
48
|
+
BrowserClient = client_1.BrowserClient;
|
|
49
|
+
registry = registry_1.default;
|
|
50
|
+
browser = client_1.default;
|
|
51
|
+
}
|
|
52
|
+
function registerModule(name, factory) {
|
|
53
|
+
jsforce.on('connection:new', (conn) => {
|
|
54
|
+
let obj = undefined;
|
|
55
|
+
Object.defineProperty(conn, name, {
|
|
56
|
+
get() {
|
|
57
|
+
obj = obj ?? factory(conn);
|
|
58
|
+
return obj;
|
|
59
|
+
},
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: true,
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
exports.registerModule = registerModule;
|
|
66
|
+
const jsforce = new JSforce();
|
|
67
|
+
exports.default = jsforce;
|
package/lib/jwtOAuth2.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.JwtOAuth2 = void 0;
|
|
7
|
+
const oauth2_1 = __importDefault(require("./oauth2"));
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated
|
|
10
|
+
*/
|
|
11
|
+
class JwtOAuth2 extends oauth2_1.default {
|
|
12
|
+
constructor(config) {
|
|
13
|
+
console.warn('JwtOAuth2 is deprecated and will be removed in next stable release, please use OAuth2 instead.');
|
|
14
|
+
super(config);
|
|
15
|
+
}
|
|
16
|
+
jwtAuthorize(innerToken) {
|
|
17
|
+
return super._postParams({
|
|
18
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
|
19
|
+
assertion: innerToken,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.JwtOAuth2 = JwtOAuth2;
|
package/lib/oauth2.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import Transport from './transport';
|
|
2
|
+
import { Optional } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* type defs
|
|
5
|
+
*/
|
|
6
|
+
export type OAuth2Config = {
|
|
7
|
+
clientId?: string;
|
|
8
|
+
clientSecret?: string;
|
|
9
|
+
redirectUri?: string;
|
|
10
|
+
loginUrl?: string;
|
|
11
|
+
authzServiceUrl?: string;
|
|
12
|
+
tokenServiceUrl?: string;
|
|
13
|
+
revokeServiceUrl?: string;
|
|
14
|
+
proxyUrl?: string;
|
|
15
|
+
httpProxy?: string;
|
|
16
|
+
useVerifier?: boolean;
|
|
17
|
+
};
|
|
18
|
+
export type AuthzRequestParams = {
|
|
19
|
+
scope?: string;
|
|
20
|
+
state?: string;
|
|
21
|
+
code_challenge?: string;
|
|
22
|
+
} & {
|
|
23
|
+
[attr: string]: string;
|
|
24
|
+
};
|
|
25
|
+
export type TokenResponse = {
|
|
26
|
+
token_type: 'Bearer';
|
|
27
|
+
/**
|
|
28
|
+
* Identity URL
|
|
29
|
+
*
|
|
30
|
+
* The format of the URL is https://login.salesforce.com/id/orgID/userID.
|
|
31
|
+
*/
|
|
32
|
+
id: string;
|
|
33
|
+
access_token: string;
|
|
34
|
+
refresh_token?: string;
|
|
35
|
+
signature: string;
|
|
36
|
+
issued_at: string;
|
|
37
|
+
instance_url: string;
|
|
38
|
+
sfdc_community_url?: string;
|
|
39
|
+
sfdc_community_id?: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* OAuth2 class
|
|
43
|
+
*/
|
|
44
|
+
export declare class OAuth2 {
|
|
45
|
+
loginUrl: string;
|
|
46
|
+
authzServiceUrl: string;
|
|
47
|
+
tokenServiceUrl: string;
|
|
48
|
+
revokeServiceUrl: string;
|
|
49
|
+
clientId: Optional<string>;
|
|
50
|
+
clientSecret: Optional<string>;
|
|
51
|
+
redirectUri: Optional<string>;
|
|
52
|
+
codeVerifier: Optional<string>;
|
|
53
|
+
_transport: Transport;
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
*/
|
|
57
|
+
constructor(config: OAuth2Config);
|
|
58
|
+
/**
|
|
59
|
+
* Get Salesforce OAuth2 authorization page URL to redirect user agent.
|
|
60
|
+
*/
|
|
61
|
+
getAuthorizationUrl(params?: AuthzRequestParams): string;
|
|
62
|
+
/**
|
|
63
|
+
* OAuth2 Refresh Token Flow
|
|
64
|
+
*/
|
|
65
|
+
refreshToken(refreshToken: string): Promise<TokenResponse>;
|
|
66
|
+
/**
|
|
67
|
+
* Send access token request to the token endpoint.
|
|
68
|
+
* When a code (string) is passed in first argument, it will use Web Server Authentication Flow (Authorization Code Grant).
|
|
69
|
+
* Otherwise, it will use the specified `grant_type` and pass parameters to the endpoint.
|
|
70
|
+
*/
|
|
71
|
+
requestToken(codeOrParams: string | {
|
|
72
|
+
grant_type: string;
|
|
73
|
+
[name: string]: string;
|
|
74
|
+
}, params?: {
|
|
75
|
+
[prop: string]: string;
|
|
76
|
+
}): Promise<TokenResponse>;
|
|
77
|
+
/**
|
|
78
|
+
* OAuth2 Username-Password Flow (Resource Owner Password Credentials)
|
|
79
|
+
*/
|
|
80
|
+
authenticate(username: string, password: string): Promise<TokenResponse>;
|
|
81
|
+
/**
|
|
82
|
+
* OAuth2 Revoke Session Token
|
|
83
|
+
*/
|
|
84
|
+
revokeToken(token: string): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* @private
|
|
87
|
+
*/
|
|
88
|
+
_postParams(params: {
|
|
89
|
+
[name: string]: string;
|
|
90
|
+
}): Promise<any>;
|
|
91
|
+
}
|
|
92
|
+
export default OAuth2;
|