@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.
Files changed (131) 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 +253 -0
  14. package/lib/api/bulk.js +678 -0
  15. package/lib/api/bulk2.d.ts +324 -0
  16. package/lib/api/bulk2.js +800 -0
  17. package/lib/api/chatter.d.ts +133 -0
  18. package/lib/api/chatter.js +248 -0
  19. package/lib/api/metadata/schema.d.ts +16117 -0
  20. package/lib/api/metadata/schema.js +9094 -0
  21. package/lib/api/metadata.d.ts +189 -0
  22. package/lib/api/metadata.js +406 -0
  23. package/lib/api/soap/schema.d.ts +3167 -0
  24. package/lib/api/soap/schema.js +1787 -0
  25. package/lib/api/soap.d.ts +76 -0
  26. package/lib/api/soap.js +155 -0
  27. package/lib/api/streaming/extension.d.ts +94 -0
  28. package/lib/api/streaming/extension.js +151 -0
  29. package/lib/api/streaming.d.ts +160 -0
  30. package/lib/api/streaming.js +252 -0
  31. package/lib/api/tooling.d.ts +284 -0
  32. package/lib/api/tooling.js +202 -0
  33. package/lib/api/wsdl/wsdl2schema.d.ts +1 -0
  34. package/lib/api/wsdl/wsdl2schema.js +354 -0
  35. package/lib/browser/canvas.d.ts +12 -0
  36. package/lib/browser/canvas.js +77 -0
  37. package/lib/browser/client.d.ts +82 -0
  38. package/lib/browser/client.js +244 -0
  39. package/lib/browser/jsonp.d.ts +12 -0
  40. package/lib/browser/jsonp.js +69 -0
  41. package/lib/browser/registry.d.ts +3 -0
  42. package/lib/browser/registry.js +5 -0
  43. package/lib/browser/request.d.ts +10 -0
  44. package/lib/browser/request.js +202 -0
  45. package/lib/cache.d.ts +74 -0
  46. package/lib/cache.js +159 -0
  47. package/lib/connection.d.ts +356 -0
  48. package/lib/connection.js +1153 -0
  49. package/lib/core.d.ts +17 -0
  50. package/lib/core.js +55 -0
  51. package/lib/csv.d.ts +23 -0
  52. package/lib/csv.js +35 -0
  53. package/lib/date.d.ts +82 -0
  54. package/lib/date.js +201 -0
  55. package/lib/http-api.d.ts +75 -0
  56. package/lib/http-api.js +295 -0
  57. package/lib/index.d.ts +13 -0
  58. package/lib/index.js +32 -0
  59. package/lib/jsforce.d.ts +26 -0
  60. package/lib/jsforce.js +67 -0
  61. package/lib/jwtOAuth2.d.ts +8 -0
  62. package/lib/jwtOAuth2.js +23 -0
  63. package/lib/oauth2.d.ts +92 -0
  64. package/lib/oauth2.js +245 -0
  65. package/lib/process.d.ts +157 -0
  66. package/lib/process.js +143 -0
  67. package/lib/query.d.ts +341 -0
  68. package/lib/query.js +817 -0
  69. package/lib/quick-action.d.ts +44 -0
  70. package/lib/quick-action.js +46 -0
  71. package/lib/record-reference.d.ts +46 -0
  72. package/lib/record-reference.js +65 -0
  73. package/lib/record-stream.d.ts +83 -0
  74. package/lib/record-stream.js +233 -0
  75. package/lib/registry/base.d.ts +43 -0
  76. package/lib/registry/base.js +96 -0
  77. package/lib/registry/empty.d.ts +7 -0
  78. package/lib/registry/empty.js +13 -0
  79. package/lib/registry/file.d.ts +11 -0
  80. package/lib/registry/file.js +51 -0
  81. package/lib/registry/index.d.ts +8 -0
  82. package/lib/registry/index.js +21 -0
  83. package/lib/registry/sfdx.d.ts +56 -0
  84. package/lib/registry/sfdx.js +133 -0
  85. package/lib/registry/types.d.ts +47 -0
  86. package/lib/registry/types.js +2 -0
  87. package/lib/request-helper.d.ts +23 -0
  88. package/lib/request-helper.js +102 -0
  89. package/lib/request.d.ts +11 -0
  90. package/lib/request.js +75 -0
  91. package/lib/session-refresh-delegate.d.ts +31 -0
  92. package/lib/session-refresh-delegate.js +69 -0
  93. package/lib/soap.d.ts +60 -0
  94. package/lib/soap.js +257 -0
  95. package/lib/sobject.d.ts +258 -0
  96. package/lib/sobject.js +376 -0
  97. package/lib/soql-builder.d.ts +25 -0
  98. package/lib/soql-builder.js +226 -0
  99. package/lib/transport.d.ts +63 -0
  100. package/lib/transport.js +175 -0
  101. package/lib/types/common.d.ts +560 -0
  102. package/lib/types/common.js +2 -0
  103. package/lib/types/index.d.ts +7 -0
  104. package/lib/types/index.js +23 -0
  105. package/lib/types/projection.d.ts +26 -0
  106. package/lib/types/projection.js +2 -0
  107. package/lib/types/record.d.ts +44 -0
  108. package/lib/types/record.js +2 -0
  109. package/lib/types/schema.d.ts +50 -0
  110. package/lib/types/schema.js +2 -0
  111. package/lib/types/soap.d.ts +43 -0
  112. package/lib/types/soap.js +2 -0
  113. package/lib/types/standard-schema.d.ts +16199 -0
  114. package/lib/types/standard-schema.js +2 -0
  115. package/lib/types/util.d.ts +7 -0
  116. package/lib/types/util.js +2 -0
  117. package/lib/util/formatter.d.ts +8 -0
  118. package/lib/util/formatter.js +24 -0
  119. package/lib/util/function.d.ts +32 -0
  120. package/lib/util/function.js +52 -0
  121. package/lib/util/get-body-size.d.ts +4 -0
  122. package/lib/util/get-body-size.js +39 -0
  123. package/lib/util/logger.d.ts +29 -0
  124. package/lib/util/logger.js +102 -0
  125. package/lib/util/promise.d.ts +19 -0
  126. package/lib/util/promise.js +25 -0
  127. package/lib/util/stream.d.ts +12 -0
  128. package/lib/util/stream.js +88 -0
  129. package/package.json +262 -6
  130. package/typings/faye/index.d.ts +16 -0
  131. package/typings/index.d.ts +1 -0
@@ -0,0 +1,202 @@
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.Tooling = void 0;
7
+ /**
8
+ * @file Manages Tooling APIs
9
+ * @author Shinichi Tomita <shinichi.tomita@gmail.com>
10
+ */
11
+ const jsforce_1 = require("../jsforce");
12
+ const connection_1 = __importDefault(require("../connection"));
13
+ const cache_1 = __importDefault(require("../cache"));
14
+ /**
15
+ *
16
+ */
17
+ const { query, queryMore, _ensureVersion, create, _createSingle, _createMany, _createParallel, retrieve, _retrieveSingle, _retrieveParallel, _retrieveMany, update, _updateSingle, _updateParallel, _updateMany, upsert, destroy, _destroySingle, _destroyParallel, _destroyMany, describe, describeGlobal, sobject, } = connection_1.default.prototype;
18
+ const describeCacheKey = (type) => type ? `describe.${type}` : 'describe';
19
+ /**
20
+ * API class for Tooling API call
21
+ */
22
+ class Tooling {
23
+ _conn;
24
+ get version() {
25
+ return this._conn.version;
26
+ }
27
+ /**
28
+ * Execute query by using SOQL
29
+ */
30
+ query = query;
31
+ /**
32
+ * Query next record set by using query locator
33
+ */
34
+ queryMore = queryMore;
35
+ _ensureVersion = _ensureVersion;
36
+ /**
37
+ * Create records
38
+ */
39
+ create = create;
40
+ _createSingle = _createSingle;
41
+ _createParallel = _createParallel;
42
+ _createMany = _createMany;
43
+ /**
44
+ * Synonym of Tooling#create()
45
+ */
46
+ insert = create;
47
+ /**
48
+ * Retrieve specified records
49
+ */
50
+ retrieve = retrieve;
51
+ _retrieveSingle = _retrieveSingle;
52
+ _retrieveParallel = _retrieveParallel;
53
+ _retrieveMany = _retrieveMany;
54
+ /**
55
+ * Update records
56
+ */
57
+ update = update;
58
+ _updateSingle = _updateSingle;
59
+ _updateParallel = _updateParallel;
60
+ _updateMany = _updateMany;
61
+ /**
62
+ * Upsert records
63
+ */
64
+ upsert = upsert;
65
+ /**
66
+ * Delete records
67
+ */
68
+ destroy = destroy;
69
+ _destroySingle = _destroySingle;
70
+ _destroyParallel = _destroyParallel;
71
+ _destroyMany = _destroyMany;
72
+ /**
73
+ * Synonym of Tooling#destroy()
74
+ */
75
+ delete = destroy;
76
+ /**
77
+ * Synonym of Tooling#destroy()
78
+ */
79
+ del = destroy;
80
+ cache = new cache_1.default();
81
+ /**
82
+ * Describe SObject metadata
83
+ */
84
+ describe = this.cache.createCachedFunction(describe, this, {
85
+ key: describeCacheKey,
86
+ strategy: 'NOCACHE',
87
+ });
88
+ describe$ = this.cache.createCachedFunction(describe, this, {
89
+ key: describeCacheKey,
90
+ strategy: 'HIT',
91
+ });
92
+ describe$$ = this.cache.createCachedFunction(describe, this, {
93
+ key: describeCacheKey,
94
+ strategy: 'IMMEDIATE',
95
+ });
96
+ /**
97
+ * Synonym of Tooling#describe()
98
+ */
99
+ describeSObject = this.describe;
100
+ describeSObject$ = this.describe$;
101
+ describeSObject$$ = this.describe$$;
102
+ /**
103
+ * Describe global SObjects
104
+ */
105
+ describeGlobal = this.cache.createCachedFunction(describeGlobal, this, {
106
+ key: 'describeGlobal',
107
+ strategy: 'NOCACHE',
108
+ });
109
+ describeGlobal$ = this.cache.createCachedFunction(describeGlobal, this, {
110
+ key: 'describeGlobal',
111
+ strategy: 'HIT',
112
+ });
113
+ describeGlobal$$ = this.cache.createCachedFunction(describeGlobal, this, {
114
+ key: 'describeGlobal',
115
+ strategy: 'IMMEDIATE',
116
+ });
117
+ /**
118
+ * Get SObject instance
119
+ */
120
+ sobject = sobject;
121
+ sobjects = {};
122
+ /**
123
+ *
124
+ */
125
+ constructor(conn) {
126
+ this._conn = conn;
127
+ }
128
+ /**
129
+ * @private
130
+ */
131
+ _establish() {
132
+ this.sobjects = {};
133
+ this.cache.clear();
134
+ this.cache.get('describeGlobal').removeAllListeners('value');
135
+ this.cache.get('describeGlobal').on('value', (res) => {
136
+ if (res.result) {
137
+ for (const { name: type } of res.result.sobjects) {
138
+ this.sobject(type);
139
+ }
140
+ }
141
+ });
142
+ }
143
+ /**
144
+ * @private
145
+ */
146
+ _baseUrl() {
147
+ return this._conn._baseUrl() + '/tooling';
148
+ }
149
+ /**
150
+ * @private
151
+ */
152
+ _supports(feature) {
153
+ return this._conn._supports(feature);
154
+ }
155
+ /**
156
+ *
157
+ */
158
+ request(request, options) {
159
+ return this._conn.request(request, options);
160
+ }
161
+ /**
162
+ * Executes Apex code anonymously
163
+ */
164
+ executeAnonymous(body) {
165
+ const url = this._baseUrl() +
166
+ '/executeAnonymous?anonymousBody=' +
167
+ encodeURIComponent(body);
168
+ return this.request(url);
169
+ }
170
+ /**
171
+ * Executes Apex tests asynchronously
172
+ */
173
+ runTestsAsynchronous(req) {
174
+ const url = this._baseUrl() + '/runTestsAsynchronous/';
175
+ return this._conn.requestPost(url, req);
176
+ }
177
+ /**
178
+ * Executes Apex tests synchronously
179
+ */
180
+ runTestsSynchronous(req) {
181
+ const url = this._baseUrl() + '/runTestsSynchronous/';
182
+ return this._conn.requestPost(url, req);
183
+ }
184
+ /**
185
+ * Retrieves available code completions of the referenced type
186
+ */
187
+ completions(type = 'apex') {
188
+ const url = this._baseUrl() + '/completions?type=' + encodeURIComponent(type);
189
+ return this.request({
190
+ method: 'GET',
191
+ url,
192
+ headers: { Accept: 'application/json' },
193
+ });
194
+ }
195
+ }
196
+ exports.Tooling = Tooling;
197
+ /*--------------------------------------------*/
198
+ /*
199
+ * Register hook in connection instantiation for dynamically adding this API module features
200
+ */
201
+ (0, jsforce_1.registerModule)('tooling', (conn) => new Tooling(conn));
202
+ exports.default = Tooling;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,354 @@
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
+ const fs_extra_1 = __importDefault(require("fs-extra"));
7
+ const xml2js_1 = __importDefault(require("xml2js"));
8
+ const soap_1 = require("../../soap");
9
+ const function_1 = require("../../util/function");
10
+ /**
11
+ *
12
+ */
13
+ const WSDLRestrictionSchema = {
14
+ $: { base: 'string' },
15
+ enumeration: [
16
+ {
17
+ $: { value: 'string' },
18
+ },
19
+ ],
20
+ 'xsd:enumeration': [
21
+ {
22
+ $: { value: 'string' },
23
+ },
24
+ ],
25
+ };
26
+ const WSDLSimpleTypeSchema = {
27
+ $: { name: 'string' },
28
+ restriction: WSDLRestrictionSchema,
29
+ 'xsd:restriction': WSDLRestrictionSchema,
30
+ };
31
+ const WSDLElementSchema = {
32
+ $: {
33
+ name: 'string',
34
+ type: 'string',
35
+ minOccurs: '?number',
36
+ maxOccurs: '?string',
37
+ nillable: '?boolean',
38
+ },
39
+ };
40
+ const WSDLSequenceSchema = {
41
+ element: ['?', WSDLElementSchema],
42
+ 'xsd:element': ['?', WSDLElementSchema],
43
+ };
44
+ const WSDLExtensionSchema = {
45
+ $: { base: 'string' },
46
+ sequence: { '?': WSDLSequenceSchema },
47
+ 'xsd:sequence': { '?': WSDLSequenceSchema },
48
+ };
49
+ const WSDLComplexContentSchema = {
50
+ extension: { '?': WSDLExtensionSchema },
51
+ 'xsd:extension': { '?': WSDLExtensionSchema },
52
+ };
53
+ const WSDLComplexTypeSchema = {
54
+ $: { name: 'string' },
55
+ sequence: { '?': WSDLSequenceSchema },
56
+ 'xsd:sequence': { '?': WSDLSequenceSchema },
57
+ complexContent: { '?': WSDLComplexContentSchema },
58
+ 'xsd:complexContent': { '?': WSDLComplexContentSchema },
59
+ };
60
+ const WSDLSchemaSchema = {
61
+ $: 'any',
62
+ complexType: ['?', 'any'],
63
+ simpleType: ['?', 'any'],
64
+ 'xsd:complexType': ['?', 'any'],
65
+ 'xsd:simpleType': ['?', 'any'],
66
+ };
67
+ const WSDLSchema = {
68
+ definitions: {
69
+ $: 'any',
70
+ types: {
71
+ schema: ['?', WSDLSchemaSchema],
72
+ 'xsd:schema': ['?', WSDLSchemaSchema],
73
+ },
74
+ message: ['any'],
75
+ portType: {
76
+ $: 'any',
77
+ operation: ['any'],
78
+ },
79
+ binding: {
80
+ $: 'any',
81
+ operation: ['any'],
82
+ },
83
+ service: {
84
+ $: 'any',
85
+ documentation: 'string',
86
+ operation: ['any'],
87
+ },
88
+ },
89
+ };
90
+ /**
91
+ *
92
+ */
93
+ function toJsType(xsdType, simpleTypes) {
94
+ switch (xsdType) {
95
+ case 'xsd:boolean':
96
+ return 'boolean';
97
+ case 'xsd:string':
98
+ case 'xsd:date':
99
+ case 'xsd:dateTime':
100
+ case 'xsd:time':
101
+ case 'xsd:base64Binary':
102
+ return 'string';
103
+ case 'xsd:int':
104
+ case 'xsd:long':
105
+ case 'xsd:double':
106
+ return 'number';
107
+ case 'xsd:anyType':
108
+ return 'any';
109
+ default: {
110
+ const [ns, type] = xsdType.split(':');
111
+ if (simpleTypes[type]) {
112
+ return simpleTypes[type];
113
+ }
114
+ if (ns) {
115
+ return type;
116
+ }
117
+ return xsdType;
118
+ }
119
+ }
120
+ }
121
+ /**
122
+ *
123
+ */
124
+ async function readWSDLFile(filePath) {
125
+ const xmlData = await fs_extra_1.default.readFile(filePath, 'utf8');
126
+ const json = await xml2js_1.default.parseStringPromise(xmlData, {
127
+ explicitArray: false,
128
+ });
129
+ return (0, soap_1.castTypeUsingSchema)(json, WSDLSchema);
130
+ }
131
+ /**
132
+ *
133
+ */
134
+ function getTypeInfo(el, simpleTypes) {
135
+ const type = toJsType(el.$.type, simpleTypes);
136
+ const isArray = el.$.maxOccurs === 'unbounded';
137
+ const nillable = (!isArray && el.$.minOccurs === 0) || el.$.nillable;
138
+ return isArray
139
+ ? nillable
140
+ ? ['?', type]
141
+ : [type]
142
+ : nillable
143
+ ? `?${type}`
144
+ : type;
145
+ }
146
+ /**
147
+ *
148
+ */
149
+ function extractComplexTypes(wsdl) {
150
+ console.log(wsdl.definitions.types['xsd:schema']);
151
+ const schemas = {};
152
+ const simpleTypes = {};
153
+ const types = wsdl.definitions.types;
154
+ for (const sc of types.schema ?? types['xsd:schema'] ?? []) {
155
+ for (const st of sc.simpleType ?? sc['xsd:simpleType'] ?? []) {
156
+ const simpleType = (0, soap_1.castTypeUsingSchema)(st, WSDLSimpleTypeSchema);
157
+ const rs = simpleType.restriction ?? simpleType['xsd:restriction'];
158
+ const base = rs.$.base.split(':')[1];
159
+ simpleTypes[simpleType.$.name] = base;
160
+ }
161
+ }
162
+ console.log({ simpleTypes });
163
+ for (const sc of types.schema ?? types['xsd:schema'] ?? []) {
164
+ for (const ct of sc.complexType ?? sc['xsd:complexType'] ?? []) {
165
+ const complexType = (0, soap_1.castTypeUsingSchema)(ct, WSDLComplexTypeSchema);
166
+ const schema = {
167
+ type: complexType.$.name,
168
+ props: {},
169
+ };
170
+ const seq = complexType.sequence ?? complexType['xsd:sequence'];
171
+ const els = seq?.element ?? seq?.['xsd:element'];
172
+ for (const el of els ?? []) {
173
+ schema.props[el.$.name] = getTypeInfo(el, simpleTypes);
174
+ }
175
+ const cc = complexType.complexContent ?? complexType['xsd:complexContent'];
176
+ if (cc) {
177
+ const extension = cc.extension ?? cc['xsd:extension'];
178
+ if (extension) {
179
+ schema.extends = extension.$.base.split(':')[1];
180
+ const seq = extension.sequence ?? extension['xsd:sequence'];
181
+ const els = seq?.element ?? seq?.['xsd:element'];
182
+ for (const el of els ?? []) {
183
+ schema.props[el.$.name] = getTypeInfo(el, simpleTypes);
184
+ }
185
+ }
186
+ }
187
+ schemas[complexType.$.name] = schema;
188
+ }
189
+ }
190
+ return schemas;
191
+ }
192
+ /**
193
+ *
194
+ */
195
+ const GENERATED_MESSAGE_COMMENT = `/**
196
+ * This file is generated from WSDL file by wsdl2schema.ts.
197
+ * Do not modify directly.
198
+ * To generate the file, run "ts-node path/to/wsdl2schema.ts path/to/wsdl.xml path/to/schema.ts"
199
+ */
200
+ `;
201
+ /**
202
+ *
203
+ */
204
+ async function dumpSchema(schemas, outFile) {
205
+ const out = fs_extra_1.default.createWriteStream(outFile, 'utf8');
206
+ const print = (str, indent = 0) => {
207
+ for (let i = 0; i < indent; i++) {
208
+ out.write(' ');
209
+ }
210
+ out.write(str);
211
+ };
212
+ const println = (str = '', indent = 0) => {
213
+ print(str + '\n', indent);
214
+ };
215
+ return new Promise((resolve, reject) => {
216
+ out.on('error', reject);
217
+ out.on('finish', () => resolve());
218
+ println(GENERATED_MESSAGE_COMMENT);
219
+ print('export const ApiSchemas = ');
220
+ writeSchema(schemas);
221
+ println(' as const;');
222
+ println();
223
+ writeTypeDefs(schemas);
224
+ out.end();
225
+ });
226
+ function writeSchema(o, indent = 0) {
227
+ if (indent > 20) {
228
+ print("'any'");
229
+ return;
230
+ }
231
+ if (Array.isArray(o)) {
232
+ print('[');
233
+ let i = 0;
234
+ for (const co of o) {
235
+ if (i > 0) {
236
+ print(', ');
237
+ }
238
+ writeSchema(co, indent);
239
+ i++;
240
+ }
241
+ print(']');
242
+ }
243
+ else if ((0, function_1.isMapObject)(o)) {
244
+ const keys = Object.keys(o);
245
+ if (keys.length > 0) {
246
+ println('{');
247
+ for (const name of keys) {
248
+ const co = o[name];
249
+ const nameId = /^[\w_$]+$/.test(name) ? name : `'${name}'`;
250
+ print(`${nameId}: `, indent + 2);
251
+ writeSchema(co, indent + 2);
252
+ println(',');
253
+ }
254
+ print('}', indent);
255
+ }
256
+ else {
257
+ print('{}');
258
+ }
259
+ }
260
+ else {
261
+ print(JSON.stringify(o).replace(/"/g, "'"));
262
+ }
263
+ }
264
+ function writeTypeDef(o, schemas, indent = 0) {
265
+ if (typeof o === 'string') {
266
+ print(o);
267
+ }
268
+ else if ((0, function_1.isMapObject)(o)) {
269
+ if ('type' in o && 'props' in o) {
270
+ if ('extends' in o && typeof o.extends === 'string') {
271
+ print(`${o.extends} & `);
272
+ }
273
+ writeTypeDef(o.props, schemas, indent);
274
+ return;
275
+ }
276
+ const keys = Object.keys(o);
277
+ if (keys.length > 0) {
278
+ println('{');
279
+ for (const prop of Object.keys(o)) {
280
+ let value = o[prop];
281
+ let nillable = false;
282
+ let isArray = false;
283
+ if (Array.isArray(value)) {
284
+ isArray = true;
285
+ const len = value.length;
286
+ if (len === 2 && value[0] === '?') {
287
+ nillable = true;
288
+ value = value[1];
289
+ }
290
+ else {
291
+ value = value[0];
292
+ }
293
+ }
294
+ else if ((0, function_1.isMapObject)(value)) {
295
+ if ('?' in value) {
296
+ nillable = true;
297
+ value = value['?'];
298
+ }
299
+ }
300
+ if (typeof value === 'string' && value[0] === '?') {
301
+ nillable = true;
302
+ value = value.substring(1);
303
+ }
304
+ print(`${prop}${nillable ? '?' : ''}: `, indent + 2);
305
+ writeTypeDef(value, schemas, indent + 2);
306
+ if (isArray) {
307
+ print('[]');
308
+ }
309
+ if (nillable) {
310
+ print(' | null | undefined');
311
+ }
312
+ println(';');
313
+ }
314
+ print('}', indent);
315
+ }
316
+ else {
317
+ print('{}');
318
+ }
319
+ }
320
+ }
321
+ function writeTypeDefs(schemas) {
322
+ for (const name of Object.keys(schemas)) {
323
+ const schema = schemas[name];
324
+ print(`export type ${name} = `);
325
+ writeTypeDef(schema, schemas);
326
+ println(';');
327
+ println();
328
+ }
329
+ println('export type ApiSchemaTypes = {');
330
+ for (const name of Object.keys(schemas)) {
331
+ println(`${name}: ${name};`, 2);
332
+ }
333
+ println('};');
334
+ }
335
+ }
336
+ /**
337
+ *
338
+ */
339
+ async function main() {
340
+ const wsdlFilePath = process.argv[2];
341
+ if (!wsdlFilePath) {
342
+ console.error('No input WSDL file is specified.');
343
+ return;
344
+ }
345
+ const outFilePath = process.argv[3];
346
+ if (!wsdlFilePath) {
347
+ console.error('No output typescript schema file is specified.');
348
+ return;
349
+ }
350
+ const wsdl = await readWSDLFile(wsdlFilePath);
351
+ const schemas = extractComplexTypes(wsdl);
352
+ dumpSchema(schemas, outFilePath);
353
+ }
354
+ main();
@@ -0,0 +1,12 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ *
4
+ */
5
+ import { Transform } from 'stream';
6
+ import { HttpRequest, SignedRequestObject } from '../types';
7
+ declare function createRequest(signedRequest: SignedRequestObject): (params: HttpRequest) => Transform;
8
+ declare const _default: {
9
+ supported: boolean;
10
+ createRequest: typeof createRequest;
11
+ };
12
+ export default _default;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ *
5
+ */
6
+ const stream_1 = require("stream");
7
+ function parseHeaders(hs) {
8
+ const headers = {};
9
+ for (const line of hs.split(/\n/)) {
10
+ const [name, value] = line.split(/\s*:\s*/);
11
+ headers[name.toLowerCase()] = value;
12
+ }
13
+ return headers;
14
+ }
15
+ async function processCanvasRequest(params, signedRequest, requestBody) {
16
+ const settings = {
17
+ client: signedRequest.client,
18
+ method: params.method,
19
+ data: requestBody,
20
+ };
21
+ const paramHeaders = params.headers;
22
+ if (paramHeaders) {
23
+ settings.headers = {};
24
+ for (const name of Object.keys(paramHeaders)) {
25
+ if (name.toLowerCase() === 'content-type') {
26
+ settings.contentType = paramHeaders[name];
27
+ }
28
+ else {
29
+ settings.headers[name] = paramHeaders[name];
30
+ }
31
+ }
32
+ }
33
+ const data = await new Promise((resolve, reject) => {
34
+ settings.success = resolve;
35
+ settings.failure = reject;
36
+ Sfdc.canvas.client.ajax(params.url, settings);
37
+ });
38
+ const headers = parseHeaders(data.responseHeaders);
39
+ let responseBody = data.payload;
40
+ if (typeof responseBody !== 'string') {
41
+ responseBody = JSON.stringify(responseBody);
42
+ }
43
+ return {
44
+ statusCode: data.status,
45
+ headers,
46
+ body: responseBody,
47
+ };
48
+ }
49
+ function createRequest(signedRequest) {
50
+ return (params) => {
51
+ const buf = [];
52
+ const stream = new stream_1.Transform({
53
+ transform(chunk, encoding, callback) {
54
+ buf.push(typeof chunk === 'string' ? chunk : chunk.toString('utf8'));
55
+ callback();
56
+ },
57
+ flush() {
58
+ (async () => {
59
+ const body = buf.join('');
60
+ const response = await processCanvasRequest(params, signedRequest, body);
61
+ stream.emit('response', response);
62
+ stream.emit('complete', response);
63
+ stream.push(response.body);
64
+ stream.push(null);
65
+ })();
66
+ },
67
+ });
68
+ if (params.body) {
69
+ stream.end(params.body);
70
+ }
71
+ return stream;
72
+ };
73
+ }
74
+ exports.default = {
75
+ supported: typeof Sfdc === 'object' && typeof Sfdc.canvas !== 'undefined',
76
+ createRequest,
77
+ };