@jsforce/jsforce-node 3.8.1 → 3.9.0
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/lib/VERSION.d.ts +1 -1
- package/lib/VERSION.js +1 -1
- package/lib/connection.d.ts +4 -0
- package/lib/connection.js +45 -0
- package/lib/soap.js +6 -0
- package/lib/util/jwt.d.ts +7 -0
- package/lib/util/jwt.js +23 -0
- package/package.json +1 -1
package/lib/VERSION.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "3.
|
|
1
|
+
declare const _default: "3.9.0";
|
|
2
2
|
export default _default;
|
package/lib/VERSION.js
CHANGED
package/lib/connection.d.ts
CHANGED
|
@@ -267,6 +267,10 @@ export declare class Connection<S extends Schema = Schema> extends EventEmitter
|
|
|
267
267
|
upsert<N extends SObjectNames<S>, InputRecord extends SObjectInputRecord<S, N> = SObjectInputRecord<S, N>, FieldNames extends SObjectFieldNames<S, N> = SObjectFieldNames<S, N>>(type: N, records: InputRecord[], extIdField: FieldNames, options?: DmlOptions): Promise<UpsertResult[]>;
|
|
268
268
|
upsert<N extends SObjectNames<S>, InputRecord extends SObjectInputRecord<S, N> = SObjectInputRecord<S, N>, FieldNames extends SObjectFieldNames<S, N> = SObjectFieldNames<S, N>>(type: N, record: InputRecord, extIdField: FieldNames, options?: DmlOptions): Promise<UpsertResult>;
|
|
269
269
|
upsert<N extends SObjectNames<S>, InputRecord extends SObjectInputRecord<S, N> = SObjectInputRecord<S, N>, FieldNames extends SObjectFieldNames<S, N> = SObjectFieldNames<S, N>>(type: N, records: InputRecord | InputRecord[], extIdField: FieldNames, options?: DmlOptions): Promise<UpsertResult | UpsertResult[]>;
|
|
270
|
+
/** @private */
|
|
271
|
+
_upsertMany(type: string, records: Record | Record[], extIdField: string, options?: DmlOptions): Promise<SaveResult | SaveResult[]>;
|
|
272
|
+
/** @private */
|
|
273
|
+
_upsertParallel(type: string, records: Record | Record[], extIdField: string, options?: DmlOptions): Promise<SaveResult | SaveResult[]>;
|
|
270
274
|
/**
|
|
271
275
|
* Delete records
|
|
272
276
|
*/
|
package/lib/connection.js
CHANGED
|
@@ -917,6 +917,51 @@ class Connection extends events_1.EventEmitter {
|
|
|
917
917
|
* @param options
|
|
918
918
|
*/
|
|
919
919
|
async upsert(type, records, extIdField, options = {}) {
|
|
920
|
+
return Array.isArray(records)
|
|
921
|
+
? // check the version whether SObject collection API is supported (46.0)
|
|
922
|
+
this._ensureVersion(46)
|
|
923
|
+
? this._upsertMany(type, records, extIdField, options)
|
|
924
|
+
: this._upsertParallel(type, records, extIdField, options)
|
|
925
|
+
: this._upsertParallel(type, records, extIdField, options);
|
|
926
|
+
}
|
|
927
|
+
/** @private */
|
|
928
|
+
async _upsertMany(type, records, extIdField, options = {}) {
|
|
929
|
+
if (records.length === 0) {
|
|
930
|
+
return [];
|
|
931
|
+
}
|
|
932
|
+
if (records.length > MAX_DML_COUNT && options.allowRecursive) {
|
|
933
|
+
return [
|
|
934
|
+
...(await this._upsertMany(type, records.slice(0, MAX_DML_COUNT), extIdField, options)),
|
|
935
|
+
...(await this._upsertMany(type, records.slice(MAX_DML_COUNT), extIdField, options)),
|
|
936
|
+
];
|
|
937
|
+
}
|
|
938
|
+
const _records = records.map((recordItem) => {
|
|
939
|
+
const { [extIdField]: extId, type: recordType, attributes, ...rec } = recordItem;
|
|
940
|
+
const sobjectType = recordType || attributes?.type || type;
|
|
941
|
+
if (!extId) {
|
|
942
|
+
throw new Error('External ID is not found in record.');
|
|
943
|
+
}
|
|
944
|
+
if (!sobjectType) {
|
|
945
|
+
throw new Error('No SObject Type defined in record');
|
|
946
|
+
}
|
|
947
|
+
return { [extIdField]: extId, attributes: { type: sobjectType }, ...rec };
|
|
948
|
+
});
|
|
949
|
+
const url = [this._baseUrl(), 'composite', 'sobjects', type, extIdField].join('/');
|
|
950
|
+
return this.request({
|
|
951
|
+
method: 'PATCH',
|
|
952
|
+
url,
|
|
953
|
+
body: JSON.stringify({
|
|
954
|
+
allOrNone: options.allOrNone || false,
|
|
955
|
+
records: _records,
|
|
956
|
+
}),
|
|
957
|
+
headers: {
|
|
958
|
+
...(options.headers || {}),
|
|
959
|
+
'content-type': 'application/json',
|
|
960
|
+
}
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
/** @private */
|
|
964
|
+
async _upsertParallel(type, records, extIdField, options = {}) {
|
|
920
965
|
const isArray = Array.isArray(records);
|
|
921
966
|
const _records = Array.isArray(records) ? records : [records];
|
|
922
967
|
if (_records.length > this._maxRequest) {
|
package/lib/soap.js
CHANGED
|
@@ -11,6 +11,7 @@ exports.SOAP = exports.castTypeUsingSchema = void 0;
|
|
|
11
11
|
const http_api_1 = __importDefault(require("./http-api"));
|
|
12
12
|
const function_1 = require("./util/function");
|
|
13
13
|
const get_body_size_1 = require("./util/get-body-size");
|
|
14
|
+
const jwt_1 = require("./util/jwt");
|
|
14
15
|
/**
|
|
15
16
|
*
|
|
16
17
|
*/
|
|
@@ -180,6 +181,11 @@ class SOAP extends http_api_1.default {
|
|
|
180
181
|
_xmlns;
|
|
181
182
|
constructor(conn, options) {
|
|
182
183
|
super(conn, options);
|
|
184
|
+
if (this._conn.accessToken && (0, jwt_1.isJWTToken)(this._conn.accessToken)) {
|
|
185
|
+
// We need to block SOAP requests with JWT tokens because the response is:
|
|
186
|
+
// statusCode=500 | body="INVALID_SESSION_ID" (xml), which triggers session refresh and enters in an infinite loop
|
|
187
|
+
throw new Error('SOAP API does not support JWT-based access tokens. You must disable the "Issue JSON Web Token (JWT)-based access tokens" setting in your Connected App or External Client App');
|
|
188
|
+
}
|
|
183
189
|
this._endpointUrl = options.endpointUrl;
|
|
184
190
|
this._xmlns = options.xmlns || 'urn:partner.soap.sforce.com';
|
|
185
191
|
}
|
package/lib/util/jwt.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isJWTToken = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a given access token is a JWT.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} accessToken - The access token to check
|
|
8
|
+
* @returns {boolean} True if the token is a valid JWT token, false otherwise.
|
|
9
|
+
*/
|
|
10
|
+
function isJWTToken(accessToken) {
|
|
11
|
+
const parts = accessToken.split('.');
|
|
12
|
+
if (parts.length !== 3)
|
|
13
|
+
return false;
|
|
14
|
+
const header = parts[0];
|
|
15
|
+
try {
|
|
16
|
+
JSON.parse(atob(header));
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.isJWTToken = isJWTToken;
|