@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
package/lib/oauth2.js ADDED
@@ -0,0 +1,245 @@
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.OAuth2 = void 0;
30
+ /**
31
+ *
32
+ */
33
+ const crypto_1 = require("crypto");
34
+ const querystring_1 = __importDefault(require("querystring"));
35
+ const transport_1 = __importStar(require("./transport"));
36
+ const defaultOAuth2Config = {
37
+ loginUrl: 'https://login.salesforce.com',
38
+ };
39
+ // Makes a nodejs base64 encoded string compatible with rfc4648 alternative encoding for urls.
40
+ // @param base64Encoded a nodejs base64 encoded string
41
+ function base64UrlEscape(base64Encoded) {
42
+ // builtin node js base 64 encoding is not 64 url compatible.
43
+ // See https://toolsn.ietf.org/html/rfc4648#section-5
44
+ return base64Encoded
45
+ .replace(/\+/g, '-')
46
+ .replace(/\//g, '_')
47
+ .replace(/=/g, '');
48
+ }
49
+ /**
50
+ * OAuth2 class
51
+ */
52
+ class OAuth2 {
53
+ loginUrl;
54
+ authzServiceUrl;
55
+ tokenServiceUrl;
56
+ revokeServiceUrl;
57
+ clientId;
58
+ clientSecret;
59
+ redirectUri;
60
+ codeVerifier;
61
+ _transport;
62
+ /**
63
+ *
64
+ */
65
+ constructor(config) {
66
+ const { loginUrl, authzServiceUrl, tokenServiceUrl, revokeServiceUrl, clientId, clientSecret, redirectUri, proxyUrl, httpProxy, useVerifier, } = config;
67
+ if (authzServiceUrl && tokenServiceUrl) {
68
+ this.loginUrl = authzServiceUrl.split('/').slice(0, 3).join('/');
69
+ this.authzServiceUrl = authzServiceUrl;
70
+ this.tokenServiceUrl = tokenServiceUrl;
71
+ this.revokeServiceUrl =
72
+ revokeServiceUrl || `${this.loginUrl}/services/oauth2/revoke`;
73
+ }
74
+ else {
75
+ this.loginUrl = loginUrl || defaultOAuth2Config.loginUrl;
76
+ this.authzServiceUrl = `${this.loginUrl}/services/oauth2/authorize`;
77
+ this.tokenServiceUrl = `${this.loginUrl}/services/oauth2/token`;
78
+ this.revokeServiceUrl = `${this.loginUrl}/services/oauth2/revoke`;
79
+ }
80
+ this.clientId = clientId;
81
+ this.clientSecret = clientSecret;
82
+ this.redirectUri = redirectUri;
83
+ if (proxyUrl) {
84
+ this._transport = new transport_1.XdProxyTransport(proxyUrl);
85
+ }
86
+ else if (httpProxy) {
87
+ this._transport = new transport_1.HttpProxyTransport(httpProxy);
88
+ }
89
+ else {
90
+ this._transport = new transport_1.default();
91
+ }
92
+ if (useVerifier) {
93
+ // Set a code verifier string for OAuth authorization
94
+ this.codeVerifier = base64UrlEscape((0, crypto_1.randomBytes)(Math.ceil(128)).toString('base64'));
95
+ }
96
+ }
97
+ /**
98
+ * Get Salesforce OAuth2 authorization page URL to redirect user agent.
99
+ */
100
+ getAuthorizationUrl(params = {}) {
101
+ if (this.codeVerifier) {
102
+ // code verifier must be a base 64 url encoded hash of 128 bytes of random data. Our random data is also
103
+ // base 64 url encoded. See Connection.create();
104
+ const codeChallenge = base64UrlEscape((0, crypto_1.createHash)('sha256').update(this.codeVerifier).digest('base64'));
105
+ params.code_challenge = codeChallenge;
106
+ }
107
+ const _params = {
108
+ ...params,
109
+ response_type: 'code',
110
+ client_id: this.clientId,
111
+ redirect_uri: this.redirectUri,
112
+ };
113
+ return (this.authzServiceUrl +
114
+ (this.authzServiceUrl.indexOf('?') >= 0 ? '&' : '?') +
115
+ querystring_1.default.stringify(_params));
116
+ }
117
+ /**
118
+ * OAuth2 Refresh Token Flow
119
+ */
120
+ async refreshToken(refreshToken) {
121
+ if (!this.clientId) {
122
+ throw new Error('No OAuth2 client id information is specified');
123
+ }
124
+ const params = {
125
+ grant_type: 'refresh_token',
126
+ refresh_token: refreshToken,
127
+ client_id: this.clientId,
128
+ };
129
+ if (this.clientSecret) {
130
+ params.client_secret = this.clientSecret;
131
+ }
132
+ const ret = await this._postParams(params);
133
+ return ret;
134
+ }
135
+ /**
136
+ * Send access token request to the token endpoint.
137
+ * When a code (string) is passed in first argument, it will use Web Server Authentication Flow (Authorization Code Grant).
138
+ * Otherwise, it will use the specified `grant_type` and pass parameters to the endpoint.
139
+ */
140
+ async requestToken(codeOrParams, params = {}) {
141
+ if (typeof codeOrParams === 'string' &&
142
+ (!this.clientId || !this.redirectUri)) {
143
+ throw new Error('No OAuth2 client id or redirect uri configuration is specified');
144
+ }
145
+ const _params = {
146
+ ...params,
147
+ ...(typeof codeOrParams === 'string'
148
+ ? { grant_type: 'authorization_code', code: codeOrParams }
149
+ : codeOrParams),
150
+ };
151
+ if (this.clientId) {
152
+ _params.client_id = this.clientId;
153
+ }
154
+ if (this.clientSecret) {
155
+ _params.client_secret = this.clientSecret;
156
+ }
157
+ if (this.redirectUri) {
158
+ _params.redirect_uri = this.redirectUri;
159
+ }
160
+ const ret = await this._postParams(_params);
161
+ return ret;
162
+ }
163
+ /**
164
+ * OAuth2 Username-Password Flow (Resource Owner Password Credentials)
165
+ */
166
+ async authenticate(username, password) {
167
+ if (!this.clientId || !this.clientSecret || !this.redirectUri) {
168
+ throw new Error('No valid OAuth2 client configuration set');
169
+ }
170
+ const ret = await this._postParams({
171
+ grant_type: 'password',
172
+ username,
173
+ password,
174
+ client_id: this.clientId,
175
+ client_secret: this.clientSecret,
176
+ redirect_uri: this.redirectUri,
177
+ });
178
+ return ret;
179
+ }
180
+ /**
181
+ * OAuth2 Revoke Session Token
182
+ */
183
+ async revokeToken(token) {
184
+ const response = await this._transport.httpRequest({
185
+ method: 'POST',
186
+ url: this.revokeServiceUrl,
187
+ body: querystring_1.default.stringify({ token }),
188
+ headers: {
189
+ 'content-type': 'application/x-www-form-urlencoded',
190
+ },
191
+ });
192
+ if (response.statusCode >= 400) {
193
+ let res = querystring_1.default.parse(response.body);
194
+ if (!res || !res.error) {
195
+ res = {
196
+ error: `ERROR_HTTP_${response.statusCode}`,
197
+ error_description: response.body,
198
+ };
199
+ }
200
+ throw new (class extends Error {
201
+ constructor({ error, error_description, }) {
202
+ super(error_description);
203
+ this.name = error;
204
+ }
205
+ })(res);
206
+ }
207
+ }
208
+ /**
209
+ * @private
210
+ */
211
+ async _postParams(params) {
212
+ if (this.codeVerifier)
213
+ params.code_verifier = this.codeVerifier;
214
+ const response = await this._transport.httpRequest({
215
+ method: 'POST',
216
+ url: this.tokenServiceUrl,
217
+ body: querystring_1.default.stringify(params),
218
+ headers: {
219
+ 'content-type': 'application/x-www-form-urlencoded',
220
+ },
221
+ });
222
+ let res;
223
+ try {
224
+ res = JSON.parse(response.body);
225
+ }
226
+ catch (e) {
227
+ /* eslint-disable no-empty */
228
+ }
229
+ if (response.statusCode >= 400) {
230
+ res = res || {
231
+ error: `ERROR_HTTP_${response.statusCode}`,
232
+ error_description: response.body,
233
+ };
234
+ throw new (class extends Error {
235
+ constructor({ error, error_description, }) {
236
+ super(error_description);
237
+ this.name = error;
238
+ }
239
+ })(res);
240
+ }
241
+ return res;
242
+ }
243
+ }
244
+ exports.OAuth2 = OAuth2;
245
+ exports.default = OAuth2;
@@ -0,0 +1,157 @@
1
+ /**
2
+ * @file Process class to manage/run workflow rule and approval process
3
+ * @author Shinichi Tomita <shinichi.tomita@gmail.com>
4
+ */
5
+ import Connection from './connection';
6
+ import { ProcessRules, Schema } from './types';
7
+ /**
8
+ *
9
+ */
10
+ export type ProcessRuleDefinition = {
11
+ id: string;
12
+ name: string;
13
+ object: string;
14
+ };
15
+ /**
16
+ *
17
+ */
18
+ export type ProcessRuleTriggerResult = {
19
+ success: true;
20
+ } | {
21
+ success: false;
22
+ errors: Array<{
23
+ message: string;
24
+ }>;
25
+ };
26
+ /**
27
+ * A class which manages process (workflow) rules
28
+ */
29
+ export declare class ProcessRule<S extends Schema> {
30
+ _conn: Connection<S>;
31
+ /**
32
+ *
33
+ */
34
+ constructor(conn: Connection<S>);
35
+ /**
36
+ * Get all process rule definitions registered to sobjects
37
+ */
38
+ list(): Promise<ProcessRules>;
39
+ /**
40
+ * Trigger process rule for given entities
41
+ */
42
+ trigger(contextIds: string | string[]): import("./util/promise").StreamPromise<{
43
+ errors: null;
44
+ success: true;
45
+ } | {
46
+ errors: any[];
47
+ success: false;
48
+ }>;
49
+ }
50
+ /**
51
+ *
52
+ */
53
+ export type ApprovalProcessDefinition = {
54
+ id: string;
55
+ name: string;
56
+ object: string;
57
+ sortOrder: number;
58
+ description: string | null;
59
+ };
60
+ /**
61
+ *
62
+ */
63
+ export type ApprovalProcessRequestResult = {
64
+ success: true;
65
+ actorIds: string[];
66
+ entityId: string;
67
+ instanceId: string;
68
+ instanceStatus: string;
69
+ newWorkItemIds: string[];
70
+ } | {
71
+ success: false;
72
+ errors: Array<{
73
+ message: string;
74
+ }>;
75
+ };
76
+ /**
77
+ *
78
+ */
79
+ export type ApprovalProcessActionOptions = {
80
+ processDefinitionNameOrId?: string;
81
+ skipEntryCriteria?: boolean;
82
+ };
83
+ /**
84
+ * A class which manages approval processes
85
+ */
86
+ export declare class ApprovalProcess<S extends Schema> {
87
+ _conn: Connection<S>;
88
+ /**
89
+ *
90
+ */
91
+ constructor(conn: Connection<S>);
92
+ /**
93
+ * Get all approval process definitions registered to sobjects
94
+ */
95
+ list(): Promise<{
96
+ [index: string]: ApprovalProcessDefinition;
97
+ }>;
98
+ /**
99
+ * Send bulk requests for approval process
100
+ */
101
+ request(requests: Array<ApprovalProcessRequestConfig | ApprovalProcessRequest<S>>): import("./util/promise").StreamPromise<ApprovalProcessRequestResult[]>;
102
+ /**
103
+ * Create approval process request
104
+ *
105
+ * @private
106
+ */
107
+ _createRequest(actionType: 'Submit' | 'Approve' | 'Reject', contextId: string, comments?: string, options?: ApprovalProcessActionOptions): ApprovalProcessRequest<S>;
108
+ /**
109
+ * Submit approval request for an item
110
+ */
111
+ submit(contextId: string, comments?: string, options?: ApprovalProcessActionOptions): ApprovalProcessRequest<S>;
112
+ /**
113
+ * Approve approval request for an item
114
+ */
115
+ approve(workitemId: string, comments?: string, options?: ApprovalProcessActionOptions): ApprovalProcessRequest<S>;
116
+ /**
117
+ * Reject approval request for an item
118
+ */
119
+ reject(workitemId: string, comments?: string, options?: ApprovalProcessActionOptions): ApprovalProcessRequest<S>;
120
+ }
121
+ /**
122
+ *
123
+ */
124
+ export type ApprovalProcessRequestConfig = {
125
+ actionType: 'Submit' | 'Approve' | 'Reject';
126
+ contextId: string;
127
+ comments?: string;
128
+ nextApproverIds?: string[];
129
+ processDefinitionNameOrId?: string;
130
+ skipEntryCriteria?: boolean;
131
+ };
132
+ /**
133
+ * A class representing approval process request
134
+ */
135
+ declare class ApprovalProcessRequest<S extends Schema> {
136
+ _process: ApprovalProcess<S>;
137
+ _request: ApprovalProcessRequestConfig;
138
+ _promise: Promise<ApprovalProcessRequestResult> | undefined;
139
+ constructor(process: ApprovalProcess<S>, request: ApprovalProcessRequestConfig);
140
+ /**
141
+ * Promise/A+ interface
142
+ * http://promises-aplus.github.io/promises-spec/
143
+ */
144
+ then<U>(onResolve?: (res: ApprovalProcessRequestResult) => U | PromiseLike<U> | null, onReject?: (err: any) => U | PromiseLike<U> | null): void;
145
+ }
146
+ /**
147
+ * A class which manages process rules and approval processes
148
+ */
149
+ export declare class Process<S extends Schema> {
150
+ rule: ProcessRule<S>;
151
+ approval: ApprovalProcess<S>;
152
+ /**
153
+ *
154
+ */
155
+ constructor(conn: Connection<S>);
156
+ }
157
+ export default Process;
package/lib/process.js ADDED
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Process = exports.ApprovalProcess = exports.ProcessRule = void 0;
4
+ /**
5
+ * A class which manages process (workflow) rules
6
+ */
7
+ class ProcessRule {
8
+ _conn;
9
+ /**
10
+ *
11
+ */
12
+ constructor(conn) {
13
+ this._conn = conn;
14
+ }
15
+ /**
16
+ * Get all process rule definitions registered to sobjects
17
+ */
18
+ async list() {
19
+ const res = await this._conn.request('/process/rules');
20
+ return res.rules;
21
+ }
22
+ /**
23
+ * Trigger process rule for given entities
24
+ */
25
+ trigger(contextIds) {
26
+ const contextIds_ = Array.isArray(contextIds) ? contextIds : [contextIds];
27
+ // https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_process_rules_trigger.htm
28
+ return this._conn.request({
29
+ method: 'POST',
30
+ url: '/process/rules/',
31
+ body: JSON.stringify({
32
+ contextIds: contextIds_,
33
+ }),
34
+ headers: {
35
+ 'content-type': 'application/json',
36
+ },
37
+ });
38
+ }
39
+ }
40
+ exports.ProcessRule = ProcessRule;
41
+ /**
42
+ * A class which manages approval processes
43
+ */
44
+ class ApprovalProcess {
45
+ _conn;
46
+ /**
47
+ *
48
+ */
49
+ constructor(conn) {
50
+ this._conn = conn;
51
+ }
52
+ /**
53
+ * Get all approval process definitions registered to sobjects
54
+ */
55
+ async list() {
56
+ const res = await this._conn.request('/process/approvals');
57
+ return res.approvals;
58
+ }
59
+ /**
60
+ * Send bulk requests for approval process
61
+ */
62
+ request(requests) {
63
+ const requests_ = requests.map((req) => '_request' in req ? req._request : req);
64
+ return this._conn.request({
65
+ method: 'POST',
66
+ url: '/process/approvals',
67
+ headers: { 'content-type': 'application/json' },
68
+ body: JSON.stringify({ requests: requests_ }),
69
+ });
70
+ }
71
+ /**
72
+ * Create approval process request
73
+ *
74
+ * @private
75
+ */
76
+ _createRequest(actionType, contextId, comments, options = {}) {
77
+ return new ApprovalProcessRequest(this, {
78
+ actionType,
79
+ contextId,
80
+ comments,
81
+ ...options,
82
+ });
83
+ }
84
+ /**
85
+ * Submit approval request for an item
86
+ */
87
+ submit(contextId, comments, options) {
88
+ return this._createRequest('Submit', contextId, comments, options);
89
+ }
90
+ /**
91
+ * Approve approval request for an item
92
+ */
93
+ approve(workitemId, comments, options = {}) {
94
+ return this._createRequest('Approve', workitemId, comments, options);
95
+ }
96
+ /**
97
+ * Reject approval request for an item
98
+ */
99
+ reject(workitemId, comments, options = {}) {
100
+ return this._createRequest('Reject', workitemId, comments, options);
101
+ }
102
+ }
103
+ exports.ApprovalProcess = ApprovalProcess;
104
+ /**
105
+ * A class representing approval process request
106
+ */
107
+ class ApprovalProcessRequest {
108
+ _process;
109
+ _request;
110
+ _promise;
111
+ constructor(process, request) {
112
+ this._process = process;
113
+ this._request = request;
114
+ }
115
+ /**
116
+ * Promise/A+ interface
117
+ * http://promises-aplus.github.io/promises-spec/
118
+ */
119
+ then(onResolve, onReject) {
120
+ if (!this._promise) {
121
+ this._promise = this._process
122
+ .request([this])
123
+ .then((rets) => rets[0]);
124
+ }
125
+ this._promise.then(onResolve, onReject);
126
+ }
127
+ }
128
+ /**
129
+ * A class which manages process rules and approval processes
130
+ */
131
+ class Process {
132
+ rule;
133
+ approval;
134
+ /**
135
+ *
136
+ */
137
+ constructor(conn) {
138
+ this.rule = new ProcessRule(conn);
139
+ this.approval = new ApprovalProcess(conn);
140
+ }
141
+ }
142
+ exports.Process = Process;
143
+ exports.default = Process;