@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.
Files changed (127) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +54 -0
  3. package/index.d.ts +4 -0
  4. package/index.js +1 -0
  5. package/lib/VERSION.d.ts +2 -0
  6. package/lib/VERSION.js +3 -0
  7. package/lib/api/analytics/types.d.ts +509 -0
  8. package/lib/api/analytics/types.js +2 -0
  9. package/lib/api/analytics.d.ts +163 -0
  10. package/lib/api/analytics.js +342 -0
  11. package/lib/api/apex.d.ts +44 -0
  12. package/lib/api/apex.js +86 -0
  13. package/lib/api/bulk.d.ts +444 -0
  14. package/lib/api/bulk.js +1372 -0
  15. package/lib/api/chatter.d.ts +133 -0
  16. package/lib/api/chatter.js +248 -0
  17. package/lib/api/metadata/schema.d.ts +16117 -0
  18. package/lib/api/metadata/schema.js +9094 -0
  19. package/lib/api/metadata.d.ts +189 -0
  20. package/lib/api/metadata.js +406 -0
  21. package/lib/api/soap/schema.d.ts +3167 -0
  22. package/lib/api/soap/schema.js +1787 -0
  23. package/lib/api/soap.d.ts +76 -0
  24. package/lib/api/soap.js +155 -0
  25. package/lib/api/streaming/extension.d.ts +94 -0
  26. package/lib/api/streaming/extension.js +151 -0
  27. package/lib/api/streaming.d.ts +160 -0
  28. package/lib/api/streaming.js +252 -0
  29. package/lib/api/tooling.d.ts +284 -0
  30. package/lib/api/tooling.js +202 -0
  31. package/lib/api/wsdl/wsdl2schema.d.ts +1 -0
  32. package/lib/api/wsdl/wsdl2schema.js +354 -0
  33. package/lib/browser/canvas.d.ts +12 -0
  34. package/lib/browser/canvas.js +77 -0
  35. package/lib/browser/client.d.ts +82 -0
  36. package/lib/browser/client.js +244 -0
  37. package/lib/browser/jsonp.d.ts +12 -0
  38. package/lib/browser/jsonp.js +69 -0
  39. package/lib/browser/registry.d.ts +3 -0
  40. package/lib/browser/registry.js +5 -0
  41. package/lib/browser/request.d.ts +10 -0
  42. package/lib/browser/request.js +202 -0
  43. package/lib/cache.d.ts +74 -0
  44. package/lib/cache.js +159 -0
  45. package/lib/connection.d.ts +355 -0
  46. package/lib/connection.js +1153 -0
  47. package/lib/core.d.ts +17 -0
  48. package/lib/core.js +55 -0
  49. package/lib/csv.d.ts +23 -0
  50. package/lib/csv.js +35 -0
  51. package/lib/date.d.ts +82 -0
  52. package/lib/date.js +201 -0
  53. package/lib/http-api.d.ts +75 -0
  54. package/lib/http-api.js +257 -0
  55. package/lib/index.d.ts +12 -0
  56. package/lib/index.js +31 -0
  57. package/lib/jsforce.d.ts +26 -0
  58. package/lib/jsforce.js +67 -0
  59. package/lib/jwtOAuth2.d.ts +8 -0
  60. package/lib/jwtOAuth2.js +23 -0
  61. package/lib/oauth2.d.ts +92 -0
  62. package/lib/oauth2.js +245 -0
  63. package/lib/process.d.ts +157 -0
  64. package/lib/process.js +143 -0
  65. package/lib/query.d.ts +341 -0
  66. package/lib/query.js +817 -0
  67. package/lib/quick-action.d.ts +44 -0
  68. package/lib/quick-action.js +46 -0
  69. package/lib/record-reference.d.ts +46 -0
  70. package/lib/record-reference.js +65 -0
  71. package/lib/record-stream.d.ts +83 -0
  72. package/lib/record-stream.js +233 -0
  73. package/lib/registry/base.d.ts +43 -0
  74. package/lib/registry/base.js +96 -0
  75. package/lib/registry/empty.d.ts +7 -0
  76. package/lib/registry/empty.js +13 -0
  77. package/lib/registry/file.d.ts +11 -0
  78. package/lib/registry/file.js +51 -0
  79. package/lib/registry/index.d.ts +8 -0
  80. package/lib/registry/index.js +21 -0
  81. package/lib/registry/sfdx.d.ts +56 -0
  82. package/lib/registry/sfdx.js +133 -0
  83. package/lib/registry/types.d.ts +47 -0
  84. package/lib/registry/types.js +2 -0
  85. package/lib/request-helper.d.ts +23 -0
  86. package/lib/request-helper.js +102 -0
  87. package/lib/request.d.ts +11 -0
  88. package/lib/request.js +75 -0
  89. package/lib/session-refresh-delegate.d.ts +31 -0
  90. package/lib/session-refresh-delegate.js +69 -0
  91. package/lib/soap.d.ts +60 -0
  92. package/lib/soap.js +246 -0
  93. package/lib/sobject.d.ts +258 -0
  94. package/lib/sobject.js +376 -0
  95. package/lib/soql-builder.d.ts +25 -0
  96. package/lib/soql-builder.js +226 -0
  97. package/lib/transport.d.ts +63 -0
  98. package/lib/transport.js +175 -0
  99. package/lib/types/common.d.ts +560 -0
  100. package/lib/types/common.js +2 -0
  101. package/lib/types/index.d.ts +7 -0
  102. package/lib/types/index.js +23 -0
  103. package/lib/types/projection.d.ts +26 -0
  104. package/lib/types/projection.js +2 -0
  105. package/lib/types/record.d.ts +44 -0
  106. package/lib/types/record.js +2 -0
  107. package/lib/types/schema.d.ts +50 -0
  108. package/lib/types/schema.js +2 -0
  109. package/lib/types/soap.d.ts +43 -0
  110. package/lib/types/soap.js +2 -0
  111. package/lib/types/standard-schema.d.ts +16199 -0
  112. package/lib/types/standard-schema.js +2 -0
  113. package/lib/types/util.d.ts +7 -0
  114. package/lib/types/util.js +2 -0
  115. package/lib/util/formatter.d.ts +8 -0
  116. package/lib/util/formatter.js +24 -0
  117. package/lib/util/function.d.ts +32 -0
  118. package/lib/util/function.js +52 -0
  119. package/lib/util/logger.d.ts +29 -0
  120. package/lib/util/logger.js +102 -0
  121. package/lib/util/promise.d.ts +19 -0
  122. package/lib/util/promise.js +25 -0
  123. package/lib/util/stream.d.ts +12 -0
  124. package/lib/util/stream.js +88 -0
  125. package/package.json +260 -6
  126. package/typings/faye/index.d.ts +16 -0
  127. package/typings/index.d.ts +1 -0
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @file Represents Salesforce QuickAction
3
+ * @author Shinichi Tomita <shinichi.tomita@gmail.com>
4
+ */
5
+ import Connection from './connection';
6
+ import { DescribeQuickActionDetailResult, Record, Optional, Schema } from './types';
7
+ /**
8
+ * type definitions
9
+ */
10
+ export type QuickActionDefaultValues = {
11
+ [name: string]: any;
12
+ };
13
+ export type QuickActionResult = {
14
+ id: string;
15
+ feedItemIds: Optional<string[]>;
16
+ success: boolean;
17
+ created: boolean;
18
+ contextId: string;
19
+ errors: Object[];
20
+ };
21
+ /**
22
+ * A class for quick action
23
+ */
24
+ export declare class QuickAction<S extends Schema> {
25
+ _conn: Connection<S>;
26
+ _path: string;
27
+ /**
28
+ *
29
+ */
30
+ constructor(conn: Connection<S>, path: string);
31
+ /**
32
+ * Describe the action's information (including layout, etc.)
33
+ */
34
+ describe(): Promise<DescribeQuickActionDetailResult>;
35
+ /**
36
+ * Retrieve default field values in the action (for given record, if specified)
37
+ */
38
+ defaultValues(contextId?: string): Promise<QuickActionDefaultValues>;
39
+ /**
40
+ * Execute the action for given context Id and record information
41
+ */
42
+ execute(contextId: string, record: Record): Promise<QuickActionResult>;
43
+ }
44
+ export default QuickAction;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QuickAction = void 0;
4
+ /**
5
+ * A class for quick action
6
+ */
7
+ class QuickAction {
8
+ _conn;
9
+ _path;
10
+ /**
11
+ *
12
+ */
13
+ constructor(conn, path) {
14
+ this._conn = conn;
15
+ this._path = path;
16
+ }
17
+ /**
18
+ * Describe the action's information (including layout, etc.)
19
+ */
20
+ async describe() {
21
+ const url = `${this._path}/describe`;
22
+ const body = await this._conn.request(url);
23
+ return body;
24
+ }
25
+ /**
26
+ * Retrieve default field values in the action (for given record, if specified)
27
+ */
28
+ async defaultValues(contextId) {
29
+ let url = `${this._path}/defaultValues`;
30
+ if (contextId) {
31
+ url += `/${contextId}`;
32
+ }
33
+ const body = await this._conn.request(url);
34
+ return body;
35
+ }
36
+ /**
37
+ * Execute the action for given context Id and record information
38
+ */
39
+ async execute(contextId, record) {
40
+ const requestBody = { contextId, record };
41
+ const resBody = await this._conn.requestPost(this._path, requestBody);
42
+ return resBody;
43
+ }
44
+ }
45
+ exports.QuickAction = QuickAction;
46
+ exports.default = QuickAction;
@@ -0,0 +1,46 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ *
4
+ */
5
+ import Connection from './connection';
6
+ import { RetrieveOptions, DmlOptions, Schema, SObjectNames, SObjectInputRecord, SObjectUpdateRecord } from './types';
7
+ /**
8
+ * Remote reference to record information
9
+ */
10
+ export declare class RecordReference<S extends Schema, N extends SObjectNames<S>, InputRecord extends SObjectInputRecord<S, N> = SObjectInputRecord<S, N>, RetrieveRecord extends SObjectUpdateRecord<S, N> = SObjectUpdateRecord<S, N>> {
11
+ type: N;
12
+ id: string;
13
+ _conn: Connection<S>;
14
+ /**
15
+ *
16
+ */
17
+ constructor(conn: Connection<S>, type: N, id: string);
18
+ /**
19
+ * Retrieve record field information
20
+ */
21
+ retrieve(options?: RetrieveOptions): Promise<RetrieveRecord>;
22
+ /**
23
+ * Update record field information
24
+ */
25
+ update(record: InputRecord, options?: DmlOptions): Promise<import("./types").SaveResult>;
26
+ /**
27
+ * Delete record field
28
+ */
29
+ destroy(options?: DmlOptions): Promise<import("./types").SaveResult>;
30
+ /**
31
+ * Synonym of Record#destroy()
32
+ */
33
+ delete: (options?: DmlOptions) => Promise<import("./types").SaveResult>;
34
+ /**
35
+ * Synonym of Record#destroy()
36
+ */
37
+ del: (options?: DmlOptions) => Promise<import("./types").SaveResult>;
38
+ /**
39
+ * Get blob field as stream
40
+ *
41
+ * @param {String} fieldName - Blob field name
42
+ * @returns {stream.Stream}
43
+ */
44
+ blob(fieldName: string): import("stream").Duplex;
45
+ }
46
+ export default RecordReference;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RecordReference = void 0;
4
+ /**
5
+ * Remote reference to record information
6
+ */
7
+ class RecordReference {
8
+ type;
9
+ id;
10
+ _conn;
11
+ /**
12
+ *
13
+ */
14
+ constructor(conn, type, id) {
15
+ this._conn = conn;
16
+ this.type = type;
17
+ this.id = id;
18
+ }
19
+ /**
20
+ * Retrieve record field information
21
+ */
22
+ async retrieve(options) {
23
+ const rec = await this._conn.retrieve(this.type, this.id, options);
24
+ return rec;
25
+ }
26
+ /**
27
+ * Update record field information
28
+ */
29
+ async update(record, options) {
30
+ const record_ = { ...record, Id: this.id };
31
+ return this._conn.update(this.type, record_, options);
32
+ }
33
+ /**
34
+ * Delete record field
35
+ */
36
+ destroy(options) {
37
+ return this._conn.destroy(this.type, this.id, options);
38
+ }
39
+ /**
40
+ * Synonym of Record#destroy()
41
+ */
42
+ delete = this.destroy;
43
+ /**
44
+ * Synonym of Record#destroy()
45
+ */
46
+ del = this.destroy;
47
+ /**
48
+ * Get blob field as stream
49
+ *
50
+ * @param {String} fieldName - Blob field name
51
+ * @returns {stream.Stream}
52
+ */
53
+ blob(fieldName) {
54
+ const url = [
55
+ this._conn._baseUrl(),
56
+ 'sobjects',
57
+ this.type,
58
+ this.id,
59
+ fieldName,
60
+ ].join('/');
61
+ return this._conn.request(url).stream();
62
+ }
63
+ }
64
+ exports.RecordReference = RecordReference;
65
+ exports.default = RecordReference;
@@ -0,0 +1,83 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * @file Represents stream that handles Salesforce record as stream data
4
+ * @author Shinichi Tomita <shinichi.tomita@gmail.com>
5
+ */
6
+ import { Readable, Writable, Duplex, Transform, PassThrough } from 'stream';
7
+ import { Record, Optional } from './types';
8
+ /**
9
+ * type defs
10
+ */
11
+ export type RecordStreamSerializeOption = {
12
+ nullValue?: any;
13
+ };
14
+ export type RecordStreamParseOption = {};
15
+ /**
16
+ * Class for Record Stream
17
+ *
18
+ * @class
19
+ * @constructor
20
+ * @extends stream.Transform
21
+ */
22
+ export declare class RecordStream<R extends Record = Record> extends PassThrough {
23
+ /**
24
+ *
25
+ */
26
+ constructor();
27
+ /**
28
+ * Get record stream of queried records applying the given mapping function
29
+ */
30
+ map<RR extends Record>(fn: (rec: R) => Optional<RR>): Transform;
31
+ /**
32
+ * Get record stream of queried records, applying the given filter function
33
+ */
34
+ filter(fn: (rec: R) => boolean): Duplex;
35
+ on(ev: string, fn: (...args: any[]) => void): this;
36
+ addListener: (ev: string, fn: (...args: any[]) => void) => this;
37
+ /**
38
+ * Create a record stream which maps records and pass them to downstream
39
+ */
40
+ static map<R1 extends Record = Record, R2 extends Record = Record>(fn: (rec: R1) => Optional<R2>): Transform;
41
+ /**
42
+ * Create mapping stream using given record template
43
+ */
44
+ static recordMapStream<R1 extends Record = Record, R2 extends Record = Record>(record: R2, noeval?: boolean): Transform;
45
+ /**
46
+ * Create a record stream which filters records and pass them to downstream
47
+ *
48
+ * @param {RecordFilterFunction} fn - Record filtering function
49
+ * @returns {RecordStream.Serializable}
50
+ */
51
+ static filter<R1 extends Record = Record>(fn: (rec: R1) => boolean): Duplex;
52
+ }
53
+ /**
54
+ * @class RecordStream.Serializable
55
+ * @extends {RecordStream}
56
+ */
57
+ export declare class Serializable<R extends Record = Record> extends RecordStream<R> {
58
+ _dataStreams: {
59
+ [type: string]: Duplex;
60
+ };
61
+ /**
62
+ * Get readable data stream which emits serialized record data
63
+ */
64
+ stream(type?: string, options?: Object): Duplex;
65
+ }
66
+ /**
67
+ * @class RecordStream.Parsable
68
+ * @extends {RecordStream}
69
+ */
70
+ export declare class Parsable<R extends Record = Record> extends RecordStream<R> {
71
+ _dataStreams: {
72
+ [type: string]: Duplex;
73
+ };
74
+ _execParse: boolean;
75
+ _incomings: Array<[Readable, Writable]>;
76
+ /**
77
+ * Get writable data stream which accepts serialized record data
78
+ */
79
+ stream(type?: string, options?: Object): Duplex;
80
+ on(ev: string, fn: (...args: any[]) => void): this;
81
+ addListener: (ev: string, fn: (...args: any[]) => void) => this;
82
+ }
83
+ export default RecordStream;
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Parsable = exports.Serializable = exports.RecordStream = void 0;
4
+ /**
5
+ * @file Represents stream that handles Salesforce record as stream data
6
+ * @author Shinichi Tomita <shinichi.tomita@gmail.com>
7
+ */
8
+ const stream_1 = require("stream");
9
+ const csv_1 = require("./csv");
10
+ const stream_2 = require("./util/stream");
11
+ /**
12
+ * @private
13
+ */
14
+ function evalMapping(value, mapping) {
15
+ if (typeof value === 'string') {
16
+ const m = /^\$\{(\w+)\}$/.exec(value);
17
+ if (m) {
18
+ return mapping[m[1]];
19
+ }
20
+ return value.replace(/\$\{(\w+)\}/g, ($0, prop) => {
21
+ const v = mapping[prop];
22
+ return typeof v === 'undefined' || v === null ? '' : String(v);
23
+ });
24
+ }
25
+ return value;
26
+ }
27
+ /**
28
+ * @private
29
+ */
30
+ function convertRecordForSerialization(record, options = {}) {
31
+ return Object.keys(record).reduce((rec, key) => {
32
+ const value = rec[key];
33
+ let urec;
34
+ if (key === 'attributes') {
35
+ // 'attributes' prop will be ignored
36
+ urec = { ...rec };
37
+ delete urec[key];
38
+ return urec;
39
+ }
40
+ else if (options.nullValue && value === null) {
41
+ return { ...rec, [key]: options.nullValue };
42
+ }
43
+ else if (value !== null && typeof value === 'object') {
44
+ const precord = convertRecordForSerialization(value, options);
45
+ return Object.keys(precord).reduce((prec, pkey) => {
46
+ prec[`${key}.${pkey}`] = precord[pkey]; // eslint-disable-line no-param-reassign
47
+ return prec;
48
+ }, { ...rec });
49
+ }
50
+ return rec;
51
+ }, record);
52
+ }
53
+ /**
54
+ * @private
55
+ */
56
+ function createPipelineStream(s1, s2) {
57
+ s1.pipe(s2);
58
+ return (0, stream_2.concatStreamsAsDuplex)(s1, s2, { writableObjectMode: true });
59
+ }
60
+ /**
61
+ * @private
62
+ */
63
+ const CSVStreamConverter = {
64
+ serialize(options = {}) {
65
+ const { nullValue, ...csvOpts } = options;
66
+ return createPipelineStream(
67
+ // eslint-disable-next-line no-use-before-define
68
+ RecordStream.map((record) => convertRecordForSerialization(record, options)), (0, csv_1.serializeCSVStream)(csvOpts));
69
+ },
70
+ parse(options = {}) {
71
+ return (0, csv_1.parseCSVStream)(options);
72
+ },
73
+ };
74
+ /**
75
+ * @private
76
+ */
77
+ const DataStreamConverters = {
78
+ csv: CSVStreamConverter,
79
+ };
80
+ /**
81
+ * Class for Record Stream
82
+ *
83
+ * @class
84
+ * @constructor
85
+ * @extends stream.Transform
86
+ */
87
+ class RecordStream extends stream_1.PassThrough {
88
+ /**
89
+ *
90
+ */
91
+ constructor() {
92
+ super({ objectMode: true });
93
+ }
94
+ /**
95
+ * Get record stream of queried records applying the given mapping function
96
+ */
97
+ map(fn) {
98
+ return this.pipe(RecordStream.map(fn));
99
+ }
100
+ /**
101
+ * Get record stream of queried records, applying the given filter function
102
+ */
103
+ filter(fn) {
104
+ return this.pipe(RecordStream.filter(fn));
105
+ }
106
+ /* @override */
107
+ on(ev, fn) {
108
+ return super.on(ev === 'record' ? 'data' : ev, fn);
109
+ }
110
+ /* @override */
111
+ addListener = this.on;
112
+ /* --------------------------------------------------- */
113
+ /**
114
+ * Create a record stream which maps records and pass them to downstream
115
+ */
116
+ static map(fn) {
117
+ const mapStream = new stream_1.Transform({
118
+ objectMode: true,
119
+ transform(record, enc, callback) {
120
+ const rec = fn(record) || record; // if not returned record, use same record
121
+ mapStream.push(rec);
122
+ callback();
123
+ },
124
+ });
125
+ return mapStream;
126
+ }
127
+ /**
128
+ * Create mapping stream using given record template
129
+ */
130
+ static recordMapStream(record, noeval) {
131
+ return RecordStream.map((rec) => {
132
+ const mapped = { Id: rec.Id };
133
+ for (const prop of Object.keys(record)) {
134
+ mapped[prop] = noeval ? record[prop] : evalMapping(record[prop], rec);
135
+ }
136
+ return mapped;
137
+ });
138
+ }
139
+ /**
140
+ * Create a record stream which filters records and pass them to downstream
141
+ *
142
+ * @param {RecordFilterFunction} fn - Record filtering function
143
+ * @returns {RecordStream.Serializable}
144
+ */
145
+ static filter(fn) {
146
+ const filterStream = new stream_1.Transform({
147
+ objectMode: true,
148
+ transform(record, enc, callback) {
149
+ if (fn(record)) {
150
+ filterStream.push(record);
151
+ }
152
+ callback();
153
+ },
154
+ });
155
+ return filterStream;
156
+ }
157
+ }
158
+ exports.RecordStream = RecordStream;
159
+ /**
160
+ * @class RecordStream.Serializable
161
+ * @extends {RecordStream}
162
+ */
163
+ class Serializable extends RecordStream {
164
+ _dataStreams = {};
165
+ /**
166
+ * Get readable data stream which emits serialized record data
167
+ */
168
+ stream(type = 'csv', options = {}) {
169
+ if (this._dataStreams[type]) {
170
+ return this._dataStreams[type];
171
+ }
172
+ const converter = DataStreamConverters[type];
173
+ if (!converter) {
174
+ throw new Error(`Converting [${type}] data stream is not supported.`);
175
+ }
176
+ const dataStream = new stream_1.PassThrough();
177
+ this.pipe(converter.serialize(options)).pipe(dataStream);
178
+ this._dataStreams[type] = dataStream;
179
+ return dataStream;
180
+ }
181
+ }
182
+ exports.Serializable = Serializable;
183
+ /**
184
+ * @class RecordStream.Parsable
185
+ * @extends {RecordStream}
186
+ */
187
+ class Parsable extends RecordStream {
188
+ _dataStreams = {};
189
+ _execParse = false;
190
+ _incomings = [];
191
+ /**
192
+ * Get writable data stream which accepts serialized record data
193
+ */
194
+ stream(type = 'csv', options = {}) {
195
+ if (this._dataStreams[type]) {
196
+ return this._dataStreams[type];
197
+ }
198
+ const converter = DataStreamConverters[type];
199
+ if (!converter) {
200
+ throw new Error(`Converting [${type}] data stream is not supported.`);
201
+ }
202
+ const dataStream = new stream_1.PassThrough();
203
+ const parserStream = converter.parse(options);
204
+ parserStream.on('error', (err) => this.emit('error', err));
205
+ parserStream
206
+ .pipe(this)
207
+ .pipe(new stream_1.PassThrough({ objectMode: true, highWaterMark: 500 * 1000 }));
208
+ if (this._execParse) {
209
+ dataStream.pipe(parserStream);
210
+ }
211
+ else {
212
+ this._incomings.push([dataStream, parserStream]);
213
+ }
214
+ this._dataStreams[type] = dataStream;
215
+ return dataStream;
216
+ }
217
+ /* @override */
218
+ on(ev, fn) {
219
+ if (ev === 'readable' || ev === 'record') {
220
+ if (!this._execParse) {
221
+ this._execParse = true;
222
+ for (const [dataStream, parserStream] of this._incomings) {
223
+ dataStream.pipe(parserStream);
224
+ }
225
+ }
226
+ }
227
+ return super.on(ev, fn);
228
+ }
229
+ /* @override */
230
+ addListener = this.on;
231
+ }
232
+ exports.Parsable = Parsable;
233
+ exports.default = RecordStream;
@@ -0,0 +1,43 @@
1
+ import Connection from '../connection';
2
+ import { RegistryConfig, Registry, ConnectionConfig, PersistConnectionConfig, ClientConfig } from './types';
3
+ import { Schema } from '../types';
4
+ /**
5
+ *
6
+ */
7
+ export declare class BaseRegistry implements Registry {
8
+ _registryConfig: RegistryConfig;
9
+ _saveConfig(): void;
10
+ _getClients(): {
11
+ [name: string]: ClientConfig;
12
+ };
13
+ _getConnections(): {
14
+ [name: string]: PersistConnectionConfig;
15
+ };
16
+ getConnectionNames(): Promise<string[]>;
17
+ getConnection<S extends Schema = Schema>(name: string): Promise<Connection<S> | null>;
18
+ getConnectionConfig(name?: string): Promise<{
19
+ instanceUrl?: string | undefined;
20
+ accessToken?: string | undefined;
21
+ } | {
22
+ oauth2: {
23
+ clientId?: string | undefined;
24
+ clientSecret?: string | undefined;
25
+ redirectUri?: string | undefined;
26
+ loginUrl?: string | undefined;
27
+ };
28
+ instanceUrl?: string | undefined;
29
+ accessToken?: string | undefined;
30
+ } | null>;
31
+ saveConnectionConfig(name: string, connConfig: ConnectionConfig): Promise<void>;
32
+ _findClientName({ clientId, loginUrl }: ClientConfig): string | null;
33
+ setDefaultConnection(name: string): Promise<void>;
34
+ removeConnectionConfig(name: string): Promise<void>;
35
+ getClientConfig(name: string): Promise<{
36
+ clientId?: string | undefined;
37
+ clientSecret?: string | undefined;
38
+ redirectUri?: string | undefined;
39
+ loginUrl?: string | undefined;
40
+ }>;
41
+ getClientNames(): Promise<string[]>;
42
+ registerClientConfig(name: string, clientConfig: ClientConfig): Promise<void>;
43
+ }
@@ -0,0 +1,96 @@
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.BaseRegistry = void 0;
7
+ const connection_1 = __importDefault(require("../connection"));
8
+ /**
9
+ *
10
+ */
11
+ class BaseRegistry {
12
+ _registryConfig = {};
13
+ _saveConfig() {
14
+ throw new Error('_saveConfig must be implemented in subclass');
15
+ }
16
+ _getClients() {
17
+ return this._registryConfig.clients || (this._registryConfig.clients = {});
18
+ }
19
+ _getConnections() {
20
+ return (this._registryConfig.connections ||
21
+ (this._registryConfig.connections = {}));
22
+ }
23
+ async getConnectionNames() {
24
+ return Object.keys(this._getConnections());
25
+ }
26
+ async getConnection(name) {
27
+ const config = await this.getConnectionConfig(name);
28
+ return config ? new connection_1.default(config) : null;
29
+ }
30
+ async getConnectionConfig(name) {
31
+ if (!name) {
32
+ name = this._registryConfig['default'];
33
+ }
34
+ const connections = this._getConnections();
35
+ const connConfig = name ? connections[name] : undefined;
36
+ if (!connConfig) {
37
+ return null;
38
+ }
39
+ const { client, ...connConfig_ } = connConfig;
40
+ if (client) {
41
+ return {
42
+ ...connConfig_,
43
+ oauth2: { ...(await this.getClientConfig(client)) },
44
+ };
45
+ }
46
+ return connConfig_;
47
+ }
48
+ async saveConnectionConfig(name, connConfig) {
49
+ const connections = this._getConnections();
50
+ const { oauth2, ...connConfig_ } = connConfig;
51
+ let persistConnConfig = connConfig_;
52
+ if (oauth2) {
53
+ const clientName = this._findClientName(oauth2);
54
+ if (clientName) {
55
+ persistConnConfig = { ...persistConnConfig, client: clientName };
56
+ }
57
+ delete connConfig.oauth2;
58
+ }
59
+ connections[name] = persistConnConfig;
60
+ this._saveConfig();
61
+ }
62
+ _findClientName({ clientId, loginUrl }) {
63
+ const clients = this._getClients();
64
+ for (const name of Object.keys(clients)) {
65
+ const client = clients[name];
66
+ if (client.clientId === clientId &&
67
+ (client.loginUrl || 'https://login.salesforce.com') === loginUrl) {
68
+ return name;
69
+ }
70
+ }
71
+ return null;
72
+ }
73
+ async setDefaultConnection(name) {
74
+ this._registryConfig['default'] = name;
75
+ this._saveConfig();
76
+ }
77
+ async removeConnectionConfig(name) {
78
+ const connections = this._getConnections();
79
+ delete connections[name];
80
+ this._saveConfig();
81
+ }
82
+ async getClientConfig(name) {
83
+ const clients = this._getClients();
84
+ const clientConfig = clients[name];
85
+ return clientConfig && { ...clientConfig };
86
+ }
87
+ async getClientNames() {
88
+ return Object.keys(this._getClients());
89
+ }
90
+ async registerClientConfig(name, clientConfig) {
91
+ const clients = this._getClients();
92
+ clients[name] = clientConfig;
93
+ this._saveConfig();
94
+ }
95
+ }
96
+ exports.BaseRegistry = BaseRegistry;
@@ -0,0 +1,7 @@
1
+ import { BaseRegistry } from './base';
2
+ /**
3
+ *
4
+ */
5
+ export declare class EmptyRegistry extends BaseRegistry {
6
+ _saveConfig(): void;
7
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EmptyRegistry = void 0;
4
+ const base_1 = require("./base");
5
+ /**
6
+ *
7
+ */
8
+ class EmptyRegistry extends base_1.BaseRegistry {
9
+ _saveConfig() {
10
+ // ignore all call requests
11
+ }
12
+ }
13
+ exports.EmptyRegistry = EmptyRegistry;
@@ -0,0 +1,11 @@
1
+ import { BaseRegistry } from './base';
2
+ /**
3
+ *
4
+ */
5
+ export declare class FileRegistry extends BaseRegistry {
6
+ _configFilePath: string;
7
+ constructor({ configFilePath }: {
8
+ configFilePath?: string;
9
+ });
10
+ _saveConfig(): void;
11
+ }