jsforce2 1.11.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 (80) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +74 -0
  3. package/bin/jsforce +3 -0
  4. package/bower.json +30 -0
  5. package/build/jsforce-api-analytics.js +393 -0
  6. package/build/jsforce-api-analytics.min.js +2 -0
  7. package/build/jsforce-api-analytics.min.js.map +1 -0
  8. package/build/jsforce-api-apex.js +183 -0
  9. package/build/jsforce-api-apex.min.js +2 -0
  10. package/build/jsforce-api-apex.min.js.map +1 -0
  11. package/build/jsforce-api-bulk.js +1054 -0
  12. package/build/jsforce-api-bulk.min.js +2 -0
  13. package/build/jsforce-api-bulk.min.js.map +1 -0
  14. package/build/jsforce-api-chatter.js +320 -0
  15. package/build/jsforce-api-chatter.min.js +2 -0
  16. package/build/jsforce-api-chatter.min.js.map +1 -0
  17. package/build/jsforce-api-metadata.js +3020 -0
  18. package/build/jsforce-api-metadata.min.js +2 -0
  19. package/build/jsforce-api-metadata.min.js.map +1 -0
  20. package/build/jsforce-api-soap.js +403 -0
  21. package/build/jsforce-api-soap.min.js +2 -0
  22. package/build/jsforce-api-soap.min.js.map +1 -0
  23. package/build/jsforce-api-streaming.js +3479 -0
  24. package/build/jsforce-api-streaming.min.js +2 -0
  25. package/build/jsforce-api-streaming.min.js.map +1 -0
  26. package/build/jsforce-api-tooling.js +319 -0
  27. package/build/jsforce-api-tooling.min.js +2 -0
  28. package/build/jsforce-api-tooling.min.js.map +1 -0
  29. package/build/jsforce-core.js +25250 -0
  30. package/build/jsforce-core.min.js +2 -0
  31. package/build/jsforce-core.min.js.map +1 -0
  32. package/build/jsforce.js +31637 -0
  33. package/build/jsforce.min.js +2 -0
  34. package/build/jsforce.min.js.map +1 -0
  35. package/core.js +1 -0
  36. package/index.js +1 -0
  37. package/lib/VERSION.js +2 -0
  38. package/lib/_required.js +29 -0
  39. package/lib/api/analytics.js +387 -0
  40. package/lib/api/apex.js +177 -0
  41. package/lib/api/bulk.js +862 -0
  42. package/lib/api/chatter.js +314 -0
  43. package/lib/api/index.js +8 -0
  44. package/lib/api/metadata.js +848 -0
  45. package/lib/api/soap.js +397 -0
  46. package/lib/api/streaming-extension.js +136 -0
  47. package/lib/api/streaming.js +270 -0
  48. package/lib/api/tooling.js +313 -0
  49. package/lib/browser/canvas.js +90 -0
  50. package/lib/browser/client.js +241 -0
  51. package/lib/browser/core.js +5 -0
  52. package/lib/browser/jsforce.js +6 -0
  53. package/lib/browser/jsonp.js +52 -0
  54. package/lib/browser/request.js +70 -0
  55. package/lib/cache.js +252 -0
  56. package/lib/cli/cli.js +431 -0
  57. package/lib/cli/repl.js +337 -0
  58. package/lib/connection.js +1881 -0
  59. package/lib/core.js +16 -0
  60. package/lib/csv.js +50 -0
  61. package/lib/date.js +163 -0
  62. package/lib/http-api.js +300 -0
  63. package/lib/jsforce.js +10 -0
  64. package/lib/logger.js +52 -0
  65. package/lib/oauth2.js +206 -0
  66. package/lib/process.js +275 -0
  67. package/lib/promise.js +164 -0
  68. package/lib/query.js +881 -0
  69. package/lib/quick-action.js +90 -0
  70. package/lib/record-stream.js +305 -0
  71. package/lib/record.js +107 -0
  72. package/lib/registry/file-registry.js +48 -0
  73. package/lib/registry/index.js +3 -0
  74. package/lib/registry/registry.js +111 -0
  75. package/lib/require.js +14 -0
  76. package/lib/soap.js +207 -0
  77. package/lib/sobject.js +558 -0
  78. package/lib/soql-builder.js +236 -0
  79. package/lib/transport.js +233 -0
  80. package/package.json +110 -0
@@ -0,0 +1,337 @@
1
+ /*global process, global */
2
+ /**
3
+ * @file Creates REPL interface with built in Salesforce API objects and automatically resolves promise object
4
+ * @author Shinichi Tomita <shinichi.tomita@gmail.com>
5
+ * @private
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ var stream = require('readable-stream'),
11
+ Readable = stream.Readable,
12
+ Writable = stream.Writable,
13
+ Transform = stream.Transform,
14
+ _ = require('lodash/core'),
15
+ jsforce = require('../jsforce');
16
+
17
+ /**
18
+ * Intercept the evaled value returned from repl evaluator, convert and send back to output.
19
+ * @private
20
+ */
21
+ function injectBefore(replServer, method, beforeFn) {
22
+ var _orig = replServer[method];
23
+ replServer[method] = function() {
24
+ var args = Array.prototype.slice.call(arguments);
25
+ var callback = args.pop();
26
+ beforeFn.apply(null, args.concat(function(err, res) {
27
+ if (err || res) {
28
+ callback(err, res);
29
+ } else {
30
+ _orig.apply(replServer, args.concat(callback));
31
+ }
32
+ }));
33
+ };
34
+ return replServer;
35
+ }
36
+
37
+ /**
38
+ * @private
39
+ */
40
+ function injectAfter(replServer, method, afterFn) {
41
+ var _orig = replServer[method];
42
+ replServer[method] = function() {
43
+ var args = Array.prototype.slice.call(arguments);
44
+ var callback = args.pop();
45
+ _orig.apply(replServer, args.concat(function() {
46
+ var args = Array.prototype.slice.call(arguments);
47
+ try {
48
+ afterFn.apply(null, args.concat(callback));
49
+ } catch(e) {
50
+ callback(e);
51
+ }
52
+ }));
53
+ };
54
+ return replServer;
55
+ }
56
+
57
+
58
+ /**
59
+ * When the result was "promise", resolve its value
60
+ * @private
61
+ */
62
+ function promisify(err, value, callback) {
63
+ if (err) { throw err; }
64
+ if (isPromiseLike(value)) {
65
+ value.then(function(v) {
66
+ callback(null, v);
67
+ }, function(err) {
68
+ callback(err);
69
+ });
70
+ } else {
71
+ callback(null, value);
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Detect whether the value has CommonJS Promise/A+ interface or not
77
+ * @private
78
+ */
79
+ function isPromiseLike(v) {
80
+ return _.isObject(v) && _.isFunction(v.then);
81
+ }
82
+
83
+ /**
84
+ * Output object to stdout in JSON representation
85
+ * @private
86
+ */
87
+ function outputToStdout(prettyPrint) {
88
+ if (prettyPrint && !_.isNumber(prettyPrint)) {
89
+ prettyPrint = 4;
90
+ }
91
+ return function(err, value, callback) {
92
+ if (err) {
93
+ console.error(err);
94
+ } else {
95
+ var str = JSON.stringify(value, null, prettyPrint);
96
+ console.log(str);
97
+ }
98
+ callback(err, value);
99
+ };
100
+ }
101
+
102
+
103
+ /**
104
+ * define get accessor using Object.defineProperty
105
+ * @private
106
+ */
107
+ function defineProp(obj, prop, getter) {
108
+ if (Object.defineProperty) {
109
+ Object.defineProperty(obj, prop, { get: getter });
110
+ }
111
+ }
112
+
113
+
114
+ /**
115
+ * @private
116
+ */
117
+ var Repl = module.exports = function(cli, replModule) {
118
+ this._cli = cli;
119
+ this._replModule = replModule;
120
+ this._in = new Transform();
121
+ this._out = new Transform();
122
+ var self = this;
123
+ this._in._transform = function(chunk, encoding, callback) {
124
+ if (!self._paused) { this.push(chunk); }
125
+ callback();
126
+ };
127
+ this._out._transform = function(chunk, encoding, callback) {
128
+ if (!self._paused && self._interactive !== false) { this.push(chunk); }
129
+ callback();
130
+ };
131
+ };
132
+
133
+ /**
134
+ *
135
+ */
136
+ Repl.prototype.start = function(options) {
137
+ var self = this;
138
+ var cli = this._cli;
139
+ options = options || {};
140
+
141
+ process.stdin.resume();
142
+ process.stdin.setRawMode(true);
143
+ process.stdin.pipe(this._in);
144
+
145
+ this._interactive = options.interactive;
146
+
147
+ this._out.pipe(process.stdout);
148
+ defineProp(this._out, "columns", function() { return process.stdout.columns; });
149
+
150
+ var replServer = this._replModule.start({
151
+ input: this._in,
152
+ output: this._out,
153
+ terminal: true
154
+ });
155
+
156
+ this._defineAdditionalCommands(replServer);
157
+
158
+ replServer = injectBefore(replServer, "completer", function() {
159
+ self.complete.apply(self, arguments);
160
+ });
161
+ replServer = injectAfter(replServer, "eval", promisify);
162
+
163
+ if (options.interactive === false) {
164
+ replServer = injectAfter(replServer, "eval", outputToStdout(options.prettyPrint));
165
+ replServer = injectAfter(replServer, "eval", function() { process.exit(); });
166
+ }
167
+ replServer.on('exit', function() { process.exit(); });
168
+
169
+ this._defineBuiltinVars(replServer.context);
170
+
171
+ if (options.evalScript) {
172
+ this._in.write(options.evalScript + "\n", "utf-8");
173
+ }
174
+ return this;
175
+ };
176
+
177
+ /**
178
+ * @private
179
+ */
180
+ Repl.prototype._defineAdditionalCommands = function(replServer) {
181
+ var cli = this._cli;
182
+ replServer.defineCommand('connections', {
183
+ help: 'List currenty registered Salesforce connections',
184
+ action: function(name) {
185
+ cli.listConnections();
186
+ replServer.displayPrompt();
187
+ }
188
+ });
189
+ replServer.defineCommand('connect', {
190
+ help: 'Connect to Salesforce instance',
191
+ action: function(name, password) {
192
+ var options = null;
193
+ if (password) {
194
+ options = { username: name, password: password };
195
+ }
196
+ cli.connect(name, options, function(err, res) {
197
+ if (err) { console.error(err.message); }
198
+ replServer.displayPrompt();
199
+ });
200
+ }
201
+ });
202
+ replServer.defineCommand('disconnect', {
203
+ help: 'Disconnect connection and erase it from registry',
204
+ action: function(name) {
205
+ cli.disconnect(name);
206
+ replServer.displayPrompt();
207
+ }
208
+ });
209
+ replServer.defineCommand('use', {
210
+ help: 'Specify login server to establish connection',
211
+ action: function(loginServer) {
212
+ cli.setLoginServer(loginServer);
213
+ replServer.displayPrompt();
214
+ }
215
+ });
216
+ replServer.defineCommand('authorize', {
217
+ help: 'Connect to Salesforce using OAuth2 authorization flow',
218
+ action: function(clientName) {
219
+ cli.authorize(clientName, function(err, res) {
220
+ if (err) { console.error(err.message); }
221
+ replServer.displayPrompt();
222
+ });
223
+ }
224
+ });
225
+ replServer.defineCommand('register', {
226
+ help: 'Register OAuth2 client information',
227
+ action: function(clientName, clientId, clientSecret, redirectUri, loginUrl) {
228
+ var config = {
229
+ clientId: clientId,
230
+ clientSecret: clientSecret,
231
+ redirectUri: redirectUri,
232
+ loginUrl: loginUrl
233
+ };
234
+ cli.register(clientName, config, function(err, res) {
235
+ if (err) { console.error(err.message); }
236
+ replServer.displayPrompt();
237
+ });
238
+ }
239
+ });
240
+ replServer.defineCommand('open', {
241
+ help: 'Open Salesforce web page using established connection',
242
+ action: function(url) {
243
+ cli.openUrl(url);
244
+ replServer.displayPrompt();
245
+ }
246
+ });
247
+ };
248
+
249
+ /**
250
+ *
251
+ */
252
+ Repl.prototype.pause = function() {
253
+ this._paused = true;
254
+ process.stdin.setRawMode(false);
255
+ };
256
+
257
+ /**
258
+ *
259
+ */
260
+ Repl.prototype.resume = function() {
261
+ this._paused = false;
262
+ process.stdin.resume();
263
+ process.stdin.setRawMode(true);
264
+ };
265
+
266
+ /**
267
+ *
268
+ */
269
+ Repl.prototype.complete = function(line, callback) {
270
+ var tokens = line.replace(/^\s+/, '').split(/\s+/);
271
+ var command = tokens[0];
272
+ var keyword = tokens[1] || '';
273
+ if (command[0] === '.' && tokens.length === 2) {
274
+ var candidates = [];
275
+ if (command === '.connect' || command === '.disconnect') {
276
+ candidates = this._cli.getConnectionNames();
277
+ } else if (command === '.authorize') {
278
+ candidates = this._cli.getClientNames();
279
+ } else if (command === '.use') {
280
+ candidates = [ 'production', 'sandbox' ];
281
+ }
282
+ candidates = candidates.filter(function(name) {
283
+ return name.indexOf(keyword) === 0;
284
+ });
285
+ callback(null, [ candidates, keyword ]);
286
+ } else {
287
+ callback();
288
+ }
289
+ };
290
+
291
+ /**
292
+ * Map all node-salesforce object to REPL context
293
+ * @private
294
+ */
295
+ Repl.prototype._defineBuiltinVars = function(context) {
296
+ var cli = this._cli;
297
+
298
+ // define salesforce package root objects
299
+ for (var key in jsforce) {
300
+ if (jsforce.hasOwnProperty(key) && !global[key]) {
301
+ context[key] = jsforce[key];
302
+ }
303
+ }
304
+ // expose jsforce package root object in context.
305
+ context.jsforce = jsforce;
306
+
307
+ function createProxyFunc(prop) {
308
+ return function() {
309
+ var conn = cli.getCurrentConnection();
310
+ return conn[prop].apply(conn, arguments);
311
+ };
312
+ }
313
+
314
+ function createProxyAccessor(prop) {
315
+ return function() {
316
+ var conn = cli.getCurrentConnection();
317
+ return conn[prop];
318
+ };
319
+ }
320
+
321
+ var conn = cli.getCurrentConnection();
322
+ // define connection prototype functions as proxy
323
+ for (var prop in conn) {
324
+ if (prop.indexOf('_') === 0) { // ignore private
325
+ continue;
326
+ }
327
+ if (_.isFunction(conn[prop])) {
328
+ context[prop] = createProxyFunc(prop);
329
+ } else if (_.isObject(conn[prop])) {
330
+ defineProp(context, prop, createProxyAccessor(prop));
331
+ }
332
+ }
333
+
334
+ // expose default connection as "$conn"
335
+ defineProp(context, "$conn", function(){ return cli.getCurrentConnection(); });
336
+
337
+ };