@bonsae/node-red-salesforce 0.1.0 → 0.3.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/LICENSE +62 -0
- package/README.md +1 -1
- package/index.d.ts +18 -13
- package/index.html +65 -1
- package/index.mjs +446 -384
- package/index.mjs.map +1 -1
- package/locales/de/index.html +14 -0
- package/locales/en-US/index.html +14 -0
- package/locales/es-ES/index.html +14 -0
- package/locales/fr/index.html +14 -0
- package/locales/ja/index.html +14 -0
- package/locales/ko/index.html +14 -0
- package/locales/pt-BR/index.html +14 -0
- package/locales/ru/index.html +14 -0
- package/locales/zh-CN/index.html +14 -0
- package/locales/zh-TW/index.html +14 -0
- package/package.json +3 -3
- package/resources/index.e3npw131.js +1 -0
- package/resources/index.CfTW8fjc.js +0 -1
package/index.mjs
CHANGED
|
@@ -1,114 +1,114 @@
|
|
|
1
1
|
var P = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var f = (
|
|
4
|
-
var
|
|
5
|
-
import { fileURLToPath as
|
|
6
|
-
import { dirname as
|
|
7
|
-
import { registerTypes as
|
|
8
|
-
import { defineSchema as h, SchemaType as
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
var
|
|
12
|
-
const
|
|
2
|
+
var B = (a, o, n) => o in a ? P(a, o, { enumerable: !0, configurable: !0, writable: !0, value: n }) : a[o] = n;
|
|
3
|
+
var f = (a, o) => P(a, "name", { value: o, configurable: !0 });
|
|
4
|
+
var s = (a, o, n) => B(a, typeof o != "symbol" ? o + "" : o, n);
|
|
5
|
+
import { fileURLToPath as q } from "url";
|
|
6
|
+
import { dirname as J } from "path";
|
|
7
|
+
import { registerTypes as G } from "@bonsae/nrg/server";
|
|
8
|
+
import { defineSchema as h, SchemaType as e, ConfigNode as Q, IONode as A, defineModule as Y } from "@bonsae/nrg/server";
|
|
9
|
+
import K from "jsforce";
|
|
10
|
+
import M from "node:crypto";
|
|
11
|
+
var V = q(import.meta.url), Ae = J(V);
|
|
12
|
+
const W = h(
|
|
13
13
|
{
|
|
14
|
-
name:
|
|
15
|
-
loginUrl:
|
|
14
|
+
name: e.String({ default: "" }),
|
|
15
|
+
loginUrl: e.String({
|
|
16
16
|
default: "https://login.salesforce.com",
|
|
17
17
|
"x-nrg-form": { icon: "globe" }
|
|
18
18
|
}),
|
|
19
|
-
clientId:
|
|
19
|
+
clientId: e.String({
|
|
20
20
|
default: "",
|
|
21
21
|
"x-nrg-form": { icon: "key" }
|
|
22
22
|
}),
|
|
23
|
-
apiVersion:
|
|
23
|
+
apiVersion: e.Union(
|
|
24
24
|
[
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
e.Literal("62.0"),
|
|
26
|
+
e.Literal("61.0"),
|
|
27
|
+
e.Literal("60.0"),
|
|
28
|
+
e.Literal("59.0"),
|
|
29
|
+
e.Literal("58.0"),
|
|
30
|
+
e.Literal("57.0"),
|
|
31
|
+
e.Literal("56.0"),
|
|
32
|
+
e.Literal("55.0")
|
|
33
33
|
],
|
|
34
34
|
{ default: "62.0", "x-nrg-form": { icon: "code-fork" } }
|
|
35
35
|
),
|
|
36
|
-
callbackUrl:
|
|
37
|
-
|
|
36
|
+
callbackUrl: e.Optional(
|
|
37
|
+
e.String({
|
|
38
38
|
default: "",
|
|
39
39
|
"x-nrg-form": { icon: "exchange" }
|
|
40
40
|
})
|
|
41
41
|
)
|
|
42
42
|
},
|
|
43
43
|
{ $id: "salesforce-connection:config" }
|
|
44
|
-
),
|
|
44
|
+
), X = h(
|
|
45
45
|
{
|
|
46
|
-
accessToken:
|
|
47
|
-
refreshToken:
|
|
48
|
-
instanceUrl:
|
|
46
|
+
accessToken: e.String({ default: "", format: "password" }),
|
|
47
|
+
refreshToken: e.String({ default: "", format: "password" }),
|
|
48
|
+
instanceUrl: e.String({ default: "" })
|
|
49
49
|
},
|
|
50
50
|
{ $id: "salesforce-connection:credentials" }
|
|
51
|
-
),
|
|
52
|
-
function
|
|
53
|
-
return
|
|
51
|
+
), H = 600 * 1e3, F = /* @__PURE__ */ new Map();
|
|
52
|
+
function Z() {
|
|
53
|
+
return M.randomBytes(32).toString("base64url");
|
|
54
54
|
}
|
|
55
|
-
f(
|
|
56
|
-
function D(
|
|
57
|
-
return
|
|
55
|
+
f(Z, "generateCodeVerifier");
|
|
56
|
+
function D(a) {
|
|
57
|
+
return M.createHash("sha256").update(a).digest("base64url");
|
|
58
58
|
}
|
|
59
59
|
f(D, "generateCodeChallenge");
|
|
60
|
-
function _(
|
|
61
|
-
const o =
|
|
62
|
-
|
|
60
|
+
function _(a) {
|
|
61
|
+
const o = M.randomUUID(), n = Z(), t = D(n);
|
|
62
|
+
F.set(o, {
|
|
63
63
|
codeVerifier: n,
|
|
64
|
-
nodeId:
|
|
65
|
-
clientId:
|
|
66
|
-
loginUrl:
|
|
67
|
-
callbackUrl:
|
|
64
|
+
nodeId: a.nodeId,
|
|
65
|
+
clientId: a.clientId,
|
|
66
|
+
loginUrl: a.loginUrl,
|
|
67
|
+
callbackUrl: a.callbackUrl,
|
|
68
68
|
timestamp: Date.now()
|
|
69
69
|
});
|
|
70
|
-
for (const [
|
|
71
|
-
Date.now() -
|
|
72
|
-
return { state: o, codeChallenge:
|
|
70
|
+
for (const [i, r] of F)
|
|
71
|
+
Date.now() - r.timestamp > H && F.delete(i);
|
|
72
|
+
return { state: o, codeChallenge: t };
|
|
73
73
|
}
|
|
74
74
|
f(_, "createAuthState");
|
|
75
|
-
function
|
|
76
|
-
const o =
|
|
77
|
-
return !o || (
|
|
75
|
+
function ee(a) {
|
|
76
|
+
const o = F.get(a);
|
|
77
|
+
return !o || (F.delete(a), Date.now() - o.timestamp > H) ? null : o;
|
|
78
78
|
}
|
|
79
|
-
f(
|
|
80
|
-
function
|
|
81
|
-
return
|
|
79
|
+
f(ee, "consumeAuthState");
|
|
80
|
+
function te(a) {
|
|
81
|
+
return a.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
82
82
|
}
|
|
83
|
-
f(
|
|
84
|
-
function k(
|
|
83
|
+
f(te, "escapeHtml");
|
|
84
|
+
function k(a, o = !0) {
|
|
85
85
|
const n = o ? "<script>setTimeout(function(){window.close()},3000)</script>" : "";
|
|
86
|
-
return `<html><body><h2>Authorization Failed</h2><p>${
|
|
86
|
+
return `<html><body><h2>Authorization Failed</h2><p>${te(a)}</p>${n}</body></html>`;
|
|
87
87
|
}
|
|
88
88
|
f(k, "errorPage");
|
|
89
|
-
function
|
|
90
|
-
const o = (
|
|
89
|
+
function ne(a) {
|
|
90
|
+
const o = (a.settings.httpAdminRoot || "").replace(
|
|
91
91
|
/\/$/,
|
|
92
92
|
""
|
|
93
93
|
);
|
|
94
|
-
|
|
94
|
+
a.httpAdmin.post("/salesforce/auth/start", (n, t) => {
|
|
95
95
|
try {
|
|
96
96
|
const {
|
|
97
|
-
nodeId:
|
|
98
|
-
loginUrl:
|
|
97
|
+
nodeId: i,
|
|
98
|
+
loginUrl: r,
|
|
99
99
|
clientId: l,
|
|
100
100
|
callbackUrl: d
|
|
101
101
|
} = n.body;
|
|
102
|
-
if (!
|
|
103
|
-
|
|
102
|
+
if (!i || !r || !l) {
|
|
103
|
+
t.status(400).json({ error: "nodeId, loginUrl, and clientId are required" });
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
106
|
const c = d || `${n.protocol}://${n.get("host")}${o}/salesforce/auth/callback`, { state: g, codeChallenge: u } = _({
|
|
107
|
-
nodeId:
|
|
107
|
+
nodeId: i,
|
|
108
108
|
clientId: l,
|
|
109
|
-
loginUrl:
|
|
109
|
+
loginUrl: r,
|
|
110
110
|
callbackUrl: c
|
|
111
|
-
}),
|
|
111
|
+
}), m = new URLSearchParams({
|
|
112
112
|
response_type: "code",
|
|
113
113
|
client_id: l,
|
|
114
114
|
redirect_uri: c,
|
|
@@ -116,30 +116,30 @@ function nt(r) {
|
|
|
116
116
|
code_challenge: u,
|
|
117
117
|
code_challenge_method: "S256"
|
|
118
118
|
});
|
|
119
|
-
|
|
120
|
-
authorizationUrl: `${
|
|
119
|
+
t.json({
|
|
120
|
+
authorizationUrl: `${r}/services/oauth2/authorize?${m.toString()}`
|
|
121
121
|
});
|
|
122
|
-
} catch (
|
|
123
|
-
|
|
124
|
-
`salesforce-connection: auth/start error: ${
|
|
125
|
-
),
|
|
122
|
+
} catch (i) {
|
|
123
|
+
a.log.error(
|
|
124
|
+
`salesforce-connection: auth/start error: ${i instanceof Error ? i.message : String(i)}`
|
|
125
|
+
), t.status(500).json({ error: "Failed to start authorization" });
|
|
126
126
|
}
|
|
127
|
-
}),
|
|
127
|
+
}), a.httpAdmin.get("/salesforce/auth/callback", async (n, t) => {
|
|
128
128
|
try {
|
|
129
|
-
const { code:
|
|
129
|
+
const { code: i, state: r, error: l, error_description: d } = n.query;
|
|
130
130
|
if (l) {
|
|
131
|
-
|
|
131
|
+
a.log.error(
|
|
132
132
|
`salesforce-connection: OAuth error: ${l} - ${d}`
|
|
133
|
-
),
|
|
133
|
+
), t.status(400).send(k(String(d || l)));
|
|
134
134
|
return;
|
|
135
135
|
}
|
|
136
|
-
if (!
|
|
137
|
-
|
|
136
|
+
if (!i || !r) {
|
|
137
|
+
t.status(400).send(k("Missing code or state parameter"));
|
|
138
138
|
return;
|
|
139
139
|
}
|
|
140
|
-
const c =
|
|
140
|
+
const c = ee(r);
|
|
141
141
|
if (!c) {
|
|
142
|
-
|
|
142
|
+
t.status(400).send(
|
|
143
143
|
k(
|
|
144
144
|
"Invalid or expired authorization state. Please try again."
|
|
145
145
|
)
|
|
@@ -153,7 +153,7 @@ function nt(r) {
|
|
|
153
153
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
154
154
|
body: new URLSearchParams({
|
|
155
155
|
grant_type: "authorization_code",
|
|
156
|
-
code:
|
|
156
|
+
code: i,
|
|
157
157
|
client_id: c.clientId,
|
|
158
158
|
redirect_uri: c.callbackUrl,
|
|
159
159
|
code_verifier: c.codeVerifier
|
|
@@ -161,10 +161,10 @@ function nt(r) {
|
|
|
161
161
|
}
|
|
162
162
|
);
|
|
163
163
|
if (!g.ok) {
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
`salesforce-connection: Token exchange failed: ${
|
|
167
|
-
),
|
|
164
|
+
const p = await g.text();
|
|
165
|
+
a.log.error(
|
|
166
|
+
`salesforce-connection: Token exchange failed: ${p}`
|
|
167
|
+
), t.status(500).send(
|
|
168
168
|
k(
|
|
169
169
|
"Token exchange failed. Check the Node-RED logs for details."
|
|
170
170
|
)
|
|
@@ -172,62 +172,62 @@ function nt(r) {
|
|
|
172
172
|
return;
|
|
173
173
|
}
|
|
174
174
|
const u = await g.json();
|
|
175
|
-
|
|
175
|
+
a.nodes.addCredentials(c.nodeId, {
|
|
176
176
|
accessToken: u.access_token,
|
|
177
177
|
refreshToken: u.refresh_token,
|
|
178
178
|
instanceUrl: u.instance_url
|
|
179
|
-
}),
|
|
179
|
+
}), a.log.info(
|
|
180
180
|
`salesforce-connection: Successfully authorized node ${c.nodeId} for ${u.instance_url}`
|
|
181
181
|
);
|
|
182
|
-
const
|
|
182
|
+
const m = JSON.stringify({
|
|
183
183
|
type: "salesforce-auth-success",
|
|
184
184
|
nodeId: c.nodeId,
|
|
185
185
|
accessToken: u.access_token,
|
|
186
186
|
refreshToken: u.refresh_token,
|
|
187
187
|
instanceUrl: u.instance_url
|
|
188
188
|
});
|
|
189
|
-
|
|
189
|
+
t.send(`<!DOCTYPE html>
|
|
190
190
|
<html>
|
|
191
191
|
<body>
|
|
192
192
|
<h2>Authorization Successful</h2>
|
|
193
193
|
<p>You can close this window.</p>
|
|
194
194
|
<script>
|
|
195
195
|
if (window.opener) {
|
|
196
|
-
window.opener.postMessage(${
|
|
196
|
+
window.opener.postMessage(${m}, "*");
|
|
197
197
|
}
|
|
198
198
|
setTimeout(function() { window.close(); }, 1500);
|
|
199
199
|
</script>
|
|
200
200
|
</body>
|
|
201
201
|
</html>`);
|
|
202
|
-
} catch (
|
|
203
|
-
|
|
204
|
-
`salesforce-connection: auth/callback error: ${
|
|
205
|
-
),
|
|
202
|
+
} catch (i) {
|
|
203
|
+
a.log.error(
|
|
204
|
+
`salesforce-connection: auth/callback error: ${i instanceof Error ? i.message : String(i)}`
|
|
205
|
+
), t.status(500).send(k("An unexpected error occurred."));
|
|
206
206
|
}
|
|
207
|
-
}),
|
|
207
|
+
}), a.httpAdmin.get("/salesforce/auth/status/:nodeId", (n, t) => {
|
|
208
208
|
try {
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
authenticated:
|
|
212
|
-
instanceUrl:
|
|
209
|
+
const i = a.nodes.getCredentials(n.params.nodeId), r = !!(i != null && i.accessToken && (i != null && i.instanceUrl));
|
|
210
|
+
t.json({
|
|
211
|
+
authenticated: r,
|
|
212
|
+
instanceUrl: r ? i.instanceUrl : void 0
|
|
213
213
|
});
|
|
214
214
|
} catch {
|
|
215
|
-
|
|
215
|
+
t.json({ authenticated: !1 });
|
|
216
216
|
}
|
|
217
217
|
});
|
|
218
218
|
}
|
|
219
|
-
f(
|
|
220
|
-
function
|
|
221
|
-
|
|
219
|
+
f(ne, "initAuthRoutes");
|
|
220
|
+
function oe(a) {
|
|
221
|
+
ne(a);
|
|
222
222
|
}
|
|
223
|
-
f(
|
|
224
|
-
const L = class L extends
|
|
223
|
+
f(oe, "initRoutes");
|
|
224
|
+
const L = class L extends Q {
|
|
225
225
|
constructor() {
|
|
226
226
|
super(...arguments);
|
|
227
|
-
|
|
227
|
+
s(this, "conn", null);
|
|
228
228
|
}
|
|
229
229
|
static async registered(n) {
|
|
230
|
-
|
|
230
|
+
oe(n);
|
|
231
231
|
}
|
|
232
232
|
async getConnection() {
|
|
233
233
|
if (this.conn) return this.conn;
|
|
@@ -236,7 +236,7 @@ const L = class L extends G {
|
|
|
236
236
|
throw new Error(
|
|
237
237
|
"Salesforce connection not authorized. Please authorize in the node configuration."
|
|
238
238
|
);
|
|
239
|
-
return this.conn = new
|
|
239
|
+
return this.conn = new K.Connection({
|
|
240
240
|
oauth2: {
|
|
241
241
|
clientId: this.config.clientId,
|
|
242
242
|
loginUrl: this.config.loginUrl
|
|
@@ -245,10 +245,10 @@ const L = class L extends G {
|
|
|
245
245
|
accessToken: n.accessToken,
|
|
246
246
|
refreshToken: n.refreshToken,
|
|
247
247
|
version: this.config.apiVersion
|
|
248
|
-
}), this.conn.on("refresh", (
|
|
248
|
+
}), this.conn.on("refresh", (t) => {
|
|
249
249
|
this.RED.nodes.addCredentials(this.id, {
|
|
250
250
|
...this.credentials,
|
|
251
|
-
accessToken:
|
|
251
|
+
accessToken: t
|
|
252
252
|
});
|
|
253
253
|
}), this.conn;
|
|
254
254
|
}
|
|
@@ -264,15 +264,15 @@ const L = class L extends G {
|
|
|
264
264
|
this.conn = null;
|
|
265
265
|
}
|
|
266
266
|
};
|
|
267
|
-
f(L, "SalesforceConnection"),
|
|
267
|
+
f(L, "SalesforceConnection"), s(L, "type", "salesforce-connection"), s(L, "configSchema", W), s(L, "credentialsSchema", X);
|
|
268
268
|
let $ = L;
|
|
269
|
-
const
|
|
269
|
+
const ie = h(
|
|
270
270
|
{
|
|
271
|
-
name:
|
|
272
|
-
connection:
|
|
271
|
+
name: e.String({ default: "", "x-nrg-form": { icon: "tag" } }),
|
|
272
|
+
connection: e.NodeRef($, {
|
|
273
273
|
"x-nrg-form": { icon: "cloud" }
|
|
274
274
|
}),
|
|
275
|
-
query:
|
|
275
|
+
query: e.TypedInput({
|
|
276
276
|
"x-nrg-form": {
|
|
277
277
|
icon: "search",
|
|
278
278
|
typedInputTypes: ["str", "msg", "flow", "global"]
|
|
@@ -280,19 +280,19 @@ const it = h(
|
|
|
280
280
|
})
|
|
281
281
|
},
|
|
282
282
|
{ $id: "salesforce-soql:config" }
|
|
283
|
-
),
|
|
283
|
+
), se = h(
|
|
284
284
|
{
|
|
285
|
-
payload:
|
|
285
|
+
payload: e.Any()
|
|
286
286
|
},
|
|
287
287
|
{ $id: "salesforce-soql:input" }
|
|
288
|
-
),
|
|
288
|
+
), re = h(
|
|
289
289
|
{
|
|
290
|
-
payload:
|
|
291
|
-
totalSize:
|
|
292
|
-
done:
|
|
290
|
+
payload: e.Array(e.Any()),
|
|
291
|
+
totalSize: e.Number(),
|
|
292
|
+
done: e.Boolean()
|
|
293
293
|
},
|
|
294
294
|
{ $id: "salesforce-soql:output" }
|
|
295
|
-
),
|
|
295
|
+
), y = class y extends A {
|
|
296
296
|
async input(o) {
|
|
297
297
|
const n = this.config.connection;
|
|
298
298
|
if (!n) {
|
|
@@ -301,73 +301,76 @@ const it = h(
|
|
|
301
301
|
}
|
|
302
302
|
try {
|
|
303
303
|
this.status({ fill: "green", shape: "dot", text: "querying..." });
|
|
304
|
-
const
|
|
304
|
+
const t = await n.getConnection(), i = await this.config.query.resolve(o), r = await t.query(i);
|
|
305
305
|
this.status({
|
|
306
306
|
fill: "green",
|
|
307
307
|
shape: "dot",
|
|
308
|
-
text: `${
|
|
308
|
+
text: `${r.totalSize} records`
|
|
309
309
|
}), this.send({
|
|
310
310
|
...o,
|
|
311
|
-
payload:
|
|
312
|
-
totalSize:
|
|
313
|
-
done:
|
|
311
|
+
payload: r.records,
|
|
312
|
+
totalSize: r.totalSize,
|
|
313
|
+
done: r.done
|
|
314
314
|
});
|
|
315
|
-
} catch (
|
|
315
|
+
} catch (t) {
|
|
316
316
|
this.status({
|
|
317
317
|
fill: "red",
|
|
318
318
|
shape: "dot",
|
|
319
|
-
text:
|
|
319
|
+
text: t instanceof Error ? t.message : String(t)
|
|
320
320
|
}), this.error(
|
|
321
|
-
`SOQL query failed: ${
|
|
321
|
+
`SOQL query failed: ${t instanceof Error ? t.message : String(t)}`,
|
|
322
322
|
o
|
|
323
323
|
);
|
|
324
324
|
}
|
|
325
325
|
}
|
|
326
326
|
};
|
|
327
|
-
f(
|
|
328
|
-
let
|
|
329
|
-
const
|
|
327
|
+
f(y, "SalesforceSoql"), s(y, "type", "salesforce-soql"), s(y, "category", "salesforce"), s(y, "color", "#FFFFFF"), s(y, "configSchema", ie), s(y, "inputSchema", se), s(y, "outputsSchema", re);
|
|
328
|
+
let U = y;
|
|
329
|
+
const ae = h(
|
|
330
330
|
{
|
|
331
|
-
name:
|
|
332
|
-
connection:
|
|
331
|
+
name: e.String({ default: "", "x-nrg-form": { icon: "tag" } }),
|
|
332
|
+
connection: e.NodeRef($, {
|
|
333
333
|
"x-nrg-form": { icon: "cloud" }
|
|
334
334
|
}),
|
|
335
|
-
operation:
|
|
335
|
+
operation: e.Union(
|
|
336
336
|
[
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
337
|
+
e.Literal("create"),
|
|
338
|
+
e.Literal("read"),
|
|
339
|
+
e.Literal("update"),
|
|
340
|
+
e.Literal("delete"),
|
|
341
|
+
e.Literal("upsert")
|
|
342
342
|
],
|
|
343
343
|
{ default: "create", "x-nrg-form": { icon: "pencil" } }
|
|
344
344
|
),
|
|
345
|
-
sObjectType:
|
|
345
|
+
sObjectType: e.TypedInput({
|
|
346
346
|
"x-nrg-form": {
|
|
347
347
|
icon: "cube",
|
|
348
348
|
typedInputTypes: ["str", "msg"]
|
|
349
349
|
}
|
|
350
350
|
}),
|
|
351
|
-
record:
|
|
351
|
+
record: e.TypedInput({
|
|
352
352
|
"x-nrg-form": {
|
|
353
353
|
icon: "file-code-o",
|
|
354
354
|
typedInputTypes: ["json", "msg"]
|
|
355
355
|
}
|
|
356
356
|
}),
|
|
357
|
-
externalIdField:
|
|
358
|
-
|
|
357
|
+
externalIdField: e.Optional(
|
|
358
|
+
e.String({
|
|
359
359
|
default: "",
|
|
360
360
|
"x-nrg-form": { icon: "key" }
|
|
361
361
|
})
|
|
362
|
-
)
|
|
362
|
+
),
|
|
363
|
+
emitError: e.Boolean({ default: !1 }),
|
|
364
|
+
emitComplete: e.Boolean({ default: !1 }),
|
|
365
|
+
emitStatus: e.Boolean({ default: !1 })
|
|
363
366
|
},
|
|
364
367
|
{
|
|
365
368
|
$id: "salesforce-dml:config",
|
|
366
|
-
if:
|
|
367
|
-
operation:
|
|
369
|
+
if: e.Object({
|
|
370
|
+
operation: e.Literal("upsert")
|
|
368
371
|
}),
|
|
369
|
-
then:
|
|
370
|
-
externalIdField:
|
|
372
|
+
then: e.Object({
|
|
373
|
+
externalIdField: e.String({ minLength: 1 })
|
|
371
374
|
}),
|
|
372
375
|
errorMessage: {
|
|
373
376
|
properties: {
|
|
@@ -375,17 +378,17 @@ const at = h(
|
|
|
375
378
|
}
|
|
376
379
|
}
|
|
377
380
|
}
|
|
378
|
-
),
|
|
381
|
+
), ce = h(
|
|
379
382
|
{
|
|
380
|
-
payload:
|
|
383
|
+
payload: e.Any()
|
|
381
384
|
},
|
|
382
385
|
{ $id: "salesforce-dml:input" }
|
|
383
|
-
),
|
|
386
|
+
), le = h(
|
|
384
387
|
{
|
|
385
|
-
payload:
|
|
388
|
+
payload: e.Any()
|
|
386
389
|
},
|
|
387
390
|
{ $id: "salesforce-dml:output" }
|
|
388
|
-
),
|
|
391
|
+
), x = class x extends A {
|
|
389
392
|
async input(o) {
|
|
390
393
|
const n = this.config.connection;
|
|
391
394
|
if (!n) {
|
|
@@ -393,11 +396,11 @@ const at = h(
|
|
|
393
396
|
return;
|
|
394
397
|
}
|
|
395
398
|
try {
|
|
396
|
-
const
|
|
397
|
-
this.status({ fill: "green", shape: "dot", text: `${
|
|
398
|
-
const
|
|
399
|
+
const t = this.config.operation;
|
|
400
|
+
this.status({ fill: "green", shape: "dot", text: `${t}...` });
|
|
401
|
+
const i = await n.getConnection(), r = await this.config.sObjectType.resolve(o), l = i.sobject(r), d = await this.config.record.resolve(o) ?? o.payload;
|
|
399
402
|
let c;
|
|
400
|
-
switch (
|
|
403
|
+
switch (t) {
|
|
401
404
|
case "create":
|
|
402
405
|
c = await l.create(d);
|
|
403
406
|
break;
|
|
@@ -414,95 +417,98 @@ const at = h(
|
|
|
414
417
|
c = await l.upsert(d, this.config.externalIdField);
|
|
415
418
|
break;
|
|
416
419
|
default:
|
|
417
|
-
throw new Error(`Unknown operation: ${
|
|
420
|
+
throw new Error(`Unknown operation: ${t}`);
|
|
418
421
|
}
|
|
419
|
-
this.status({ fill: "green", shape: "dot", text: `${
|
|
420
|
-
} catch (
|
|
422
|
+
this.status({ fill: "green", shape: "dot", text: `${t} done` }), this.send({ ...o, payload: c });
|
|
423
|
+
} catch (t) {
|
|
421
424
|
this.status({
|
|
422
425
|
fill: "red",
|
|
423
426
|
shape: "dot",
|
|
424
|
-
text:
|
|
427
|
+
text: t instanceof Error ? t.message : String(t)
|
|
425
428
|
}), this.error(
|
|
426
|
-
`DML ${this.config.operation} failed: ${
|
|
429
|
+
`DML ${this.config.operation} failed: ${t instanceof Error ? t.message : String(t)}`,
|
|
427
430
|
o
|
|
428
431
|
);
|
|
429
432
|
}
|
|
430
433
|
}
|
|
431
434
|
};
|
|
432
|
-
f(
|
|
433
|
-
let R =
|
|
434
|
-
const
|
|
435
|
+
f(x, "SalesforceDml"), s(x, "type", "salesforce-dml"), s(x, "category", "salesforce"), s(x, "color", "#FFFFFF"), s(x, "configSchema", ae), s(x, "inputSchema", ce), s(x, "outputsSchema", le);
|
|
436
|
+
let R = x;
|
|
437
|
+
const de = h(
|
|
435
438
|
{
|
|
436
|
-
name:
|
|
437
|
-
connection:
|
|
439
|
+
name: e.String({ default: "", "x-nrg-form": { icon: "tag" } }),
|
|
440
|
+
connection: e.NodeRef($, {
|
|
438
441
|
"x-nrg-form": { icon: "cloud" }
|
|
439
442
|
}),
|
|
440
|
-
operation:
|
|
443
|
+
operation: e.Union(
|
|
441
444
|
[
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
445
|
+
e.Literal("insert"),
|
|
446
|
+
e.Literal("update"),
|
|
447
|
+
e.Literal("upsert"),
|
|
448
|
+
e.Literal("delete"),
|
|
449
|
+
e.Literal("query")
|
|
447
450
|
],
|
|
448
451
|
{ default: "insert", "x-nrg-form": { icon: "database" } }
|
|
449
452
|
),
|
|
450
|
-
sObjectType:
|
|
453
|
+
sObjectType: e.TypedInput({
|
|
451
454
|
"x-nrg-form": {
|
|
452
455
|
icon: "cube",
|
|
453
456
|
typedInputTypes: ["str", "msg"]
|
|
454
457
|
}
|
|
455
458
|
}),
|
|
456
|
-
externalIdField:
|
|
457
|
-
|
|
459
|
+
externalIdField: e.Optional(
|
|
460
|
+
e.String({
|
|
458
461
|
default: "",
|
|
459
462
|
"x-nrg-form": { icon: "key" }
|
|
460
463
|
})
|
|
461
464
|
),
|
|
462
|
-
assignmentRuleId:
|
|
463
|
-
|
|
465
|
+
assignmentRuleId: e.Optional(
|
|
466
|
+
e.String({
|
|
464
467
|
default: "",
|
|
465
468
|
"x-nrg-form": { icon: "gavel" }
|
|
466
469
|
})
|
|
467
470
|
),
|
|
468
|
-
columnDelimiter:
|
|
471
|
+
columnDelimiter: e.Union(
|
|
469
472
|
[
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
473
|
+
e.Literal("COMMA"),
|
|
474
|
+
e.Literal("TAB"),
|
|
475
|
+
e.Literal("PIPE"),
|
|
476
|
+
e.Literal("SEMICOLON"),
|
|
477
|
+
e.Literal("CARET"),
|
|
478
|
+
e.Literal("BACKQUOTE")
|
|
476
479
|
],
|
|
477
480
|
{ default: "COMMA", "x-nrg-form": { icon: "columns" } }
|
|
478
481
|
),
|
|
479
|
-
lineEnding:
|
|
480
|
-
[
|
|
482
|
+
lineEnding: e.Union(
|
|
483
|
+
[e.Literal("LF"), e.Literal("CRLF")],
|
|
481
484
|
{ default: "LF", "x-nrg-form": { icon: "level-down" } }
|
|
482
485
|
),
|
|
483
|
-
pollInterval:
|
|
486
|
+
pollInterval: e.Number({
|
|
484
487
|
default: 5e3,
|
|
485
488
|
minimum: 1e3,
|
|
486
489
|
"x-nrg-form": { icon: "clock-o" }
|
|
487
490
|
}),
|
|
488
|
-
pollTimeout:
|
|
491
|
+
pollTimeout: e.Number({
|
|
489
492
|
default: 6e4,
|
|
490
493
|
minimum: 5e3,
|
|
491
494
|
"x-nrg-form": { icon: "hourglass" }
|
|
492
495
|
}),
|
|
493
|
-
emitJobCreated:
|
|
496
|
+
emitJobCreated: e.Boolean({
|
|
494
497
|
default: !1,
|
|
495
498
|
"x-nrg-form": { icon: "flag", toggle: !0 }
|
|
496
499
|
}),
|
|
497
|
-
outputs:
|
|
500
|
+
outputs: e.Number({ default: 2 }),
|
|
501
|
+
emitError: e.Boolean({ default: !1 }),
|
|
502
|
+
emitComplete: e.Boolean({ default: !1 }),
|
|
503
|
+
emitStatus: e.Boolean({ default: !1 })
|
|
498
504
|
},
|
|
499
505
|
{
|
|
500
506
|
$id: "salesforce-bulk:config",
|
|
501
|
-
if:
|
|
502
|
-
operation:
|
|
507
|
+
if: e.Object({
|
|
508
|
+
operation: e.Literal("upsert")
|
|
503
509
|
}),
|
|
504
|
-
then:
|
|
505
|
-
externalIdField:
|
|
510
|
+
then: e.Object({
|
|
511
|
+
externalIdField: e.String({ minLength: 1 })
|
|
506
512
|
}),
|
|
507
513
|
errorMessage: {
|
|
508
514
|
properties: {
|
|
@@ -510,29 +516,35 @@ const dt = h(
|
|
|
510
516
|
}
|
|
511
517
|
}
|
|
512
518
|
}
|
|
513
|
-
),
|
|
519
|
+
), ue = h(
|
|
514
520
|
{
|
|
515
|
-
payload:
|
|
521
|
+
payload: e.Any()
|
|
516
522
|
},
|
|
517
523
|
{ $id: "salesforce-bulk:input" }
|
|
518
524
|
);
|
|
519
525
|
h(
|
|
520
526
|
{
|
|
521
|
-
payload:
|
|
527
|
+
payload: e.Array(e.Any())
|
|
522
528
|
},
|
|
523
529
|
{ $id: "salesforce-bulk:output" }
|
|
524
530
|
);
|
|
525
|
-
const
|
|
531
|
+
const he = h(
|
|
532
|
+
{},
|
|
533
|
+
{ $id: "salesforce-bulk:output-port-1" }
|
|
534
|
+
), pe = h(
|
|
535
|
+
{},
|
|
536
|
+
{ $id: "salesforce-bulk:output-port-2" }
|
|
537
|
+
), b = class b extends A {
|
|
526
538
|
sendRecord(o, n) {
|
|
527
|
-
const
|
|
528
|
-
|
|
539
|
+
const t = this.config.emitJobCreated ? 3 : 2, i = Array(t).fill(null);
|
|
540
|
+
i[0] = { ...o, payload: n }, this.send(i);
|
|
529
541
|
}
|
|
530
542
|
sendJobCreated(o, n) {
|
|
531
543
|
this.config.emitJobCreated && this.send([null, null, { ...o, payload: n }]);
|
|
532
544
|
}
|
|
533
545
|
sendComplete(o, n) {
|
|
534
|
-
const
|
|
535
|
-
|
|
546
|
+
const t = this.config.emitJobCreated ? 3 : 2, i = Array(t).fill(null);
|
|
547
|
+
i[1] = { ...o, payload: n }, this.send(i);
|
|
536
548
|
}
|
|
537
549
|
async input(o) {
|
|
538
550
|
const n = this.config.connection;
|
|
@@ -541,16 +553,16 @@ const T = class T extends F {
|
|
|
541
553
|
return;
|
|
542
554
|
}
|
|
543
555
|
try {
|
|
544
|
-
const
|
|
556
|
+
const t = this.config.operation;
|
|
545
557
|
this.status({
|
|
546
558
|
fill: "green",
|
|
547
559
|
shape: "dot",
|
|
548
|
-
text: `bulk ${
|
|
560
|
+
text: `bulk ${t}...`
|
|
549
561
|
});
|
|
550
|
-
const
|
|
562
|
+
const i = await n.getConnection(), r = await this.config.sObjectType.resolve(o);
|
|
551
563
|
let l = 0;
|
|
552
|
-
if (
|
|
553
|
-
const d = await
|
|
564
|
+
if (t === "query") {
|
|
565
|
+
const d = await i.bulk2.query(o.payload, {
|
|
554
566
|
pollTimeout: this.config.pollTimeout,
|
|
555
567
|
pollInterval: this.config.pollInterval,
|
|
556
568
|
columnDelimiter: this.config.columnDelimiter,
|
|
@@ -563,82 +575,88 @@ const T = class T extends F {
|
|
|
563
575
|
}), this.status({
|
|
564
576
|
fill: "green",
|
|
565
577
|
shape: "dot",
|
|
566
|
-
text: `bulk ${
|
|
567
|
-
}), this.sendComplete(o, { operation:
|
|
578
|
+
text: `bulk ${t}: ${l} records`
|
|
579
|
+
}), this.sendComplete(o, { operation: t, sObjectType: r, totalRecords: l });
|
|
568
580
|
} else {
|
|
569
|
-
const d = o.payload, c =
|
|
570
|
-
operation:
|
|
571
|
-
object:
|
|
581
|
+
const d = o.payload, c = i.bulk2.createJob({
|
|
582
|
+
operation: t,
|
|
583
|
+
object: r,
|
|
572
584
|
columnDelimiter: this.config.columnDelimiter,
|
|
573
585
|
lineEnding: this.config.lineEnding,
|
|
574
|
-
...
|
|
586
|
+
...t === "upsert" && this.config.externalIdField ? { externalIdFieldName: this.config.externalIdField } : {},
|
|
575
587
|
...this.config.assignmentRuleId ? { assignmentRuleId: this.config.assignmentRuleId } : {}
|
|
576
588
|
});
|
|
577
589
|
await c.open(), this.sendJobCreated(o, {
|
|
578
590
|
jobId: c.id,
|
|
579
|
-
operation:
|
|
580
|
-
sObjectType:
|
|
591
|
+
operation: t,
|
|
592
|
+
sObjectType: r,
|
|
581
593
|
state: "Open"
|
|
582
594
|
}), await c.uploadData(d), await c.close(), await c.poll(this.config.pollInterval, this.config.pollTimeout);
|
|
583
|
-
const g = await c.getAllResults(), u = g.successfulResults ?? [],
|
|
584
|
-
l = u.length +
|
|
585
|
-
for (const
|
|
586
|
-
this.sendRecord(o,
|
|
587
|
-
for (const
|
|
588
|
-
this.sendRecord(o,
|
|
589
|
-
const
|
|
595
|
+
const g = await c.getAllResults(), u = g.successfulResults ?? [], m = g.failedResults ?? [], p = g.unprocessedRecords ?? [];
|
|
596
|
+
l = u.length + m.length + p.length;
|
|
597
|
+
for (const E of u)
|
|
598
|
+
this.sendRecord(o, E);
|
|
599
|
+
for (const E of m)
|
|
600
|
+
this.sendRecord(o, E);
|
|
601
|
+
const S = u.length, z = m.length;
|
|
590
602
|
this.status({
|
|
591
|
-
fill:
|
|
603
|
+
fill: z > 0 ? "red" : "green",
|
|
592
604
|
shape: "dot",
|
|
593
|
-
text: `bulk ${
|
|
605
|
+
text: `bulk ${t}: ${l} records`
|
|
594
606
|
}), this.sendComplete(o, {
|
|
595
607
|
jobId: c.id,
|
|
596
|
-
operation:
|
|
597
|
-
sObjectType:
|
|
608
|
+
operation: t,
|
|
609
|
+
sObjectType: r,
|
|
598
610
|
totalRecords: l,
|
|
599
|
-
successCount:
|
|
600
|
-
failureCount:
|
|
601
|
-
unprocessedCount:
|
|
611
|
+
successCount: S,
|
|
612
|
+
failureCount: z,
|
|
613
|
+
unprocessedCount: p.length
|
|
602
614
|
});
|
|
603
615
|
}
|
|
604
|
-
} catch (
|
|
605
|
-
const
|
|
606
|
-
this.status({ fill: "red", shape: "dot", text:
|
|
616
|
+
} catch (t) {
|
|
617
|
+
const i = t instanceof Error ? t.message : String(t);
|
|
618
|
+
this.status({ fill: "red", shape: "dot", text: i }), this.error(`Bulk ${this.config.operation} failed: ${i}`, o);
|
|
607
619
|
}
|
|
608
620
|
}
|
|
609
621
|
};
|
|
610
|
-
f(
|
|
611
|
-
|
|
612
|
-
|
|
622
|
+
f(b, "SalesforceBulk"), s(b, "type", "salesforce-bulk"), s(b, "category", "salesforce"), s(b, "color", "#FFFFFF"), s(b, "configSchema", de), s(b, "inputSchema", ue), s(b, "outputsSchema", [
|
|
623
|
+
he,
|
|
624
|
+
pe
|
|
625
|
+
]);
|
|
626
|
+
let O = b;
|
|
627
|
+
const fe = h(
|
|
613
628
|
{
|
|
614
|
-
name:
|
|
615
|
-
connection:
|
|
629
|
+
name: e.String({ default: "", "x-nrg-form": { icon: "tag" } }),
|
|
630
|
+
connection: e.NodeRef($, {
|
|
616
631
|
"x-nrg-form": { icon: "cloud" }
|
|
617
632
|
}),
|
|
618
|
-
sObjectType:
|
|
633
|
+
sObjectType: e.TypedInput({
|
|
619
634
|
"x-nrg-form": {
|
|
620
635
|
icon: "cube",
|
|
621
636
|
typedInputTypes: ["str", "msg"]
|
|
622
637
|
}
|
|
623
|
-
})
|
|
638
|
+
}),
|
|
639
|
+
emitError: e.Boolean({ default: !1 }),
|
|
640
|
+
emitComplete: e.Boolean({ default: !1 }),
|
|
641
|
+
emitStatus: e.Boolean({ default: !1 })
|
|
624
642
|
},
|
|
625
643
|
{ $id: "salesforce-describe:config" }
|
|
626
|
-
),
|
|
644
|
+
), ge = h(
|
|
627
645
|
{
|
|
628
|
-
payload:
|
|
646
|
+
payload: e.Any()
|
|
629
647
|
},
|
|
630
648
|
{ $id: "salesforce-describe:input" }
|
|
631
|
-
),
|
|
649
|
+
), me = h(
|
|
632
650
|
{
|
|
633
|
-
payload:
|
|
634
|
-
name:
|
|
635
|
-
fields:
|
|
636
|
-
childRelationships:
|
|
637
|
-
recordTypeInfos:
|
|
651
|
+
payload: e.Object({
|
|
652
|
+
name: e.String(),
|
|
653
|
+
fields: e.Array(e.Any()),
|
|
654
|
+
childRelationships: e.Array(e.Any()),
|
|
655
|
+
recordTypeInfos: e.Array(e.Any())
|
|
638
656
|
})
|
|
639
657
|
},
|
|
640
658
|
{ $id: "salesforce-describe:output" }
|
|
641
|
-
),
|
|
659
|
+
), T = class T extends A {
|
|
642
660
|
async input(o) {
|
|
643
661
|
const n = this.config.connection;
|
|
644
662
|
if (!n) {
|
|
@@ -647,72 +665,74 @@ const ht = h(
|
|
|
647
665
|
}
|
|
648
666
|
try {
|
|
649
667
|
this.status({ fill: "green", shape: "dot", text: "describing..." });
|
|
650
|
-
const
|
|
668
|
+
const t = await n.getConnection(), i = await this.config.sObjectType.resolve(o), r = await t.sobject(i).describe();
|
|
651
669
|
this.status({
|
|
652
670
|
fill: "green",
|
|
653
671
|
shape: "dot",
|
|
654
|
-
text: `${
|
|
672
|
+
text: `${r.name}: ${r.fields.length} fields`
|
|
655
673
|
}), this.send({
|
|
656
674
|
...o,
|
|
657
675
|
payload: {
|
|
658
|
-
name:
|
|
659
|
-
fields:
|
|
660
|
-
childRelationships:
|
|
661
|
-
recordTypeInfos:
|
|
676
|
+
name: r.name,
|
|
677
|
+
fields: r.fields,
|
|
678
|
+
childRelationships: r.childRelationships,
|
|
679
|
+
recordTypeInfos: r.recordTypeInfos
|
|
662
680
|
}
|
|
663
681
|
});
|
|
664
|
-
} catch (
|
|
682
|
+
} catch (t) {
|
|
665
683
|
this.status({
|
|
666
684
|
fill: "red",
|
|
667
685
|
shape: "dot",
|
|
668
|
-
text:
|
|
686
|
+
text: t instanceof Error ? t.message : String(t)
|
|
669
687
|
}), this.error(
|
|
670
|
-
`Describe failed: ${
|
|
688
|
+
`Describe failed: ${t instanceof Error ? t.message : String(t)}`,
|
|
671
689
|
o
|
|
672
690
|
);
|
|
673
691
|
}
|
|
674
692
|
}
|
|
675
693
|
};
|
|
676
|
-
f(
|
|
677
|
-
let
|
|
678
|
-
const
|
|
694
|
+
f(T, "SalesforceDescribe"), s(T, "type", "salesforce-describe"), s(T, "category", "salesforce"), s(T, "color", "#FFFFFF"), s(T, "configSchema", fe), s(T, "inputSchema", ge), s(T, "outputsSchema", me);
|
|
695
|
+
let j = T;
|
|
696
|
+
const ye = h(
|
|
679
697
|
{
|
|
680
|
-
name:
|
|
681
|
-
connection:
|
|
698
|
+
name: e.String({ default: "", "x-nrg-form": { icon: "tag" } }),
|
|
699
|
+
connection: e.NodeRef($, {
|
|
682
700
|
"x-nrg-form": { icon: "cloud" }
|
|
683
701
|
}),
|
|
684
|
-
channelName:
|
|
702
|
+
channelName: e.String({
|
|
685
703
|
default: "",
|
|
686
704
|
"x-nrg-form": { icon: "rss" }
|
|
687
705
|
}),
|
|
688
|
-
subscribeType:
|
|
706
|
+
subscribeType: e.Union(
|
|
689
707
|
[
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
708
|
+
e.Literal("LATEST"),
|
|
709
|
+
e.Literal("EARLIEST"),
|
|
710
|
+
e.Literal("CUSTOM")
|
|
693
711
|
],
|
|
694
712
|
{ default: "LATEST", "x-nrg-form": { icon: "history" } }
|
|
695
713
|
),
|
|
696
|
-
replayId:
|
|
697
|
-
|
|
714
|
+
replayId: e.Optional(
|
|
715
|
+
e.String({
|
|
698
716
|
default: "",
|
|
699
717
|
"x-nrg-form": { icon: "bookmark" }
|
|
700
718
|
})
|
|
701
719
|
),
|
|
702
|
-
numRequested:
|
|
720
|
+
numRequested: e.Number({
|
|
703
721
|
default: 100,
|
|
704
722
|
minimum: 1,
|
|
705
723
|
maximum: 100,
|
|
706
724
|
"x-nrg-form": { icon: "sort-numeric-asc" }
|
|
707
|
-
})
|
|
725
|
+
}),
|
|
726
|
+
emitError: e.Boolean({ default: !1 }),
|
|
727
|
+
emitStatus: e.Boolean({ default: !1 })
|
|
708
728
|
},
|
|
709
729
|
{
|
|
710
730
|
$id: "salesforce-streaming:config",
|
|
711
|
-
if:
|
|
712
|
-
subscribeType:
|
|
731
|
+
if: e.Object({
|
|
732
|
+
subscribeType: e.Literal("CUSTOM")
|
|
713
733
|
}),
|
|
714
|
-
then:
|
|
715
|
-
replayId:
|
|
734
|
+
then: e.Object({
|
|
735
|
+
replayId: e.String({ minLength: 1 })
|
|
716
736
|
}),
|
|
717
737
|
errorMessage: {
|
|
718
738
|
properties: {
|
|
@@ -720,20 +740,23 @@ const gt = h(
|
|
|
720
740
|
}
|
|
721
741
|
}
|
|
722
742
|
}
|
|
723
|
-
),
|
|
743
|
+
), xe = h(
|
|
724
744
|
{
|
|
725
|
-
payload:
|
|
726
|
-
replayId:
|
|
727
|
-
channel:
|
|
728
|
-
topic:
|
|
745
|
+
payload: e.Any(),
|
|
746
|
+
replayId: e.Any(),
|
|
747
|
+
channel: e.String(),
|
|
748
|
+
topic: e.String()
|
|
729
749
|
},
|
|
730
750
|
{ $id: "salesforce-streaming:output" }
|
|
731
|
-
),
|
|
751
|
+
), w = class w extends A {
|
|
732
752
|
constructor() {
|
|
733
753
|
super(...arguments);
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
754
|
+
s(this, "client", null);
|
|
755
|
+
s(this, "reconnectAttempt", 0);
|
|
756
|
+
s(this, "maxReconnectDelay", 6e4);
|
|
757
|
+
s(this, "maxReconnectAttempts", 10);
|
|
758
|
+
s(this, "grpcErrorHandler", null);
|
|
759
|
+
s(this, "stopped", !1);
|
|
737
760
|
}
|
|
738
761
|
async created() {
|
|
739
762
|
const n = this.config.connection;
|
|
@@ -744,129 +767,168 @@ const gt = h(
|
|
|
744
767
|
await this.subscribe(n);
|
|
745
768
|
}
|
|
746
769
|
async subscribe(n) {
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
770
|
+
if (!this.stopped)
|
|
771
|
+
try {
|
|
772
|
+
this.status({ fill: "green", shape: "dot", text: "connecting..." });
|
|
773
|
+
let t;
|
|
774
|
+
try {
|
|
775
|
+
t = await n.getConnection(), await t.identity();
|
|
776
|
+
} catch {
|
|
777
|
+
this.status({ fill: "red", shape: "dot", text: "auth expired" }), this.error("Salesforce token expired. Re-authorize the connection.");
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
const i = n.getAccessToken(), r = n.getInstanceUrl();
|
|
781
|
+
if (!i || !r) {
|
|
782
|
+
this.status({ fill: "red", shape: "dot", text: "not authorized" }), this.error("Salesforce connection not authorized");
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
785
|
+
const l = (await import("salesforce-pubsub-api-client")).default;
|
|
786
|
+
this.client = new l({
|
|
787
|
+
authType: "user-supplied",
|
|
788
|
+
accessToken: i,
|
|
789
|
+
instanceUrl: r
|
|
790
|
+
}), await this.client.connect();
|
|
791
|
+
const d = this.config.numRequested || null, c = this.config.channelName, g = /* @__PURE__ */ f((u, m, p) => {
|
|
792
|
+
if (m === "event" || m === "lastevent")
|
|
793
|
+
this.send({
|
|
794
|
+
payload: (p == null ? void 0 : p.payload) ?? p,
|
|
795
|
+
replayId: p == null ? void 0 : p.replayId,
|
|
796
|
+
channel: c,
|
|
797
|
+
topic: c
|
|
798
|
+
});
|
|
799
|
+
else if (m === "error") {
|
|
800
|
+
const S = p instanceof Error ? p.message : String(p ?? "stream error");
|
|
801
|
+
if (this.warn(`Streaming error: ${S}`), S.includes("UNAUTHENTICATED") || S.includes("authentication")) {
|
|
802
|
+
this.stopped = !0, this.status({
|
|
803
|
+
fill: "red",
|
|
804
|
+
shape: "dot",
|
|
805
|
+
text: "auth expired — re-authorize"
|
|
806
|
+
}), this.error(
|
|
807
|
+
"Salesforce token expired. Re-authorize the connection."
|
|
808
|
+
), this.cleanup();
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
this.status({ fill: "red", shape: "dot", text: S }), this.scheduleReconnect(n);
|
|
812
|
+
} else if (m === "end") {
|
|
813
|
+
if (this.stopped) return;
|
|
814
|
+
this.log("Streaming subscription ended"), this.status({ fill: "red", shape: "dot", text: "disconnected" }), this.scheduleReconnect(n);
|
|
815
|
+
}
|
|
816
|
+
}, "callback");
|
|
817
|
+
if (this.grpcErrorHandler && process.removeListener("uncaughtException", this.grpcErrorHandler), this.grpcErrorHandler = (u) => {
|
|
818
|
+
var m, p;
|
|
819
|
+
((m = u.message) != null && m.includes("UNAUTHENTICATED") || (p = u.message) != null && p.includes("authentication")) && (this.stopped = !0, this.warn(`Caught gRPC auth error: ${u.message}`), this.status({
|
|
820
|
+
fill: "red",
|
|
821
|
+
shape: "dot",
|
|
822
|
+
text: "auth expired — re-authorize"
|
|
823
|
+
}), this.cleanup());
|
|
824
|
+
}, process.on("uncaughtException", this.grpcErrorHandler), this.config.subscribeType === "EARLIEST")
|
|
825
|
+
this.client.subscribeFromEarliestEvent(
|
|
826
|
+
c,
|
|
827
|
+
g,
|
|
828
|
+
d
|
|
829
|
+
);
|
|
830
|
+
else if (this.config.subscribeType === "CUSTOM" && this.config.replayId) {
|
|
831
|
+
const u = parseInt(this.config.replayId, 10);
|
|
832
|
+
this.client.subscribeFromReplayId(
|
|
833
|
+
c,
|
|
834
|
+
g,
|
|
835
|
+
d,
|
|
836
|
+
u
|
|
837
|
+
);
|
|
838
|
+
} else
|
|
839
|
+
this.client.subscribe(c, g, d);
|
|
840
|
+
this.status({
|
|
841
|
+
fill: "green",
|
|
842
|
+
shape: "dot",
|
|
843
|
+
text: `subscribed: ${c}`
|
|
844
|
+
}), this.reconnectAttempt = 0;
|
|
845
|
+
} catch (t) {
|
|
846
|
+
this.status({
|
|
847
|
+
fill: "red",
|
|
848
|
+
shape: "dot",
|
|
849
|
+
text: t instanceof Error ? t.message : String(t)
|
|
850
|
+
}), this.error(
|
|
851
|
+
`Streaming subscription failed: ${t instanceof Error ? t.message : String(t)}`
|
|
852
|
+
), this.scheduleReconnect(n);
|
|
753
853
|
}
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
if (u === "event" || u === "lastevent")
|
|
762
|
-
this.send({
|
|
763
|
-
payload: (p == null ? void 0 : p.payload) ?? p,
|
|
764
|
-
replayId: p == null ? void 0 : p.replayId,
|
|
765
|
-
channel: d,
|
|
766
|
-
topic: d
|
|
767
|
-
});
|
|
768
|
-
else if (u === "error") {
|
|
769
|
-
const w = p instanceof Error ? p.message : String(p ?? "stream error");
|
|
770
|
-
this.warn(`Streaming error: ${w}`), this.status({ fill: "red", shape: "dot", text: w }), this.scheduleReconnect(n);
|
|
771
|
-
} else u === "end" && (this.log("Streaming subscription ended"), this.status({ fill: "red", shape: "dot", text: "disconnected" }), this.scheduleReconnect(n));
|
|
772
|
-
}, "callback");
|
|
773
|
-
if (this.config.subscribeType === "EARLIEST")
|
|
774
|
-
this.client.subscribeFromEarliestEvent(
|
|
775
|
-
d,
|
|
776
|
-
c,
|
|
777
|
-
l
|
|
778
|
-
);
|
|
779
|
-
else if (this.config.subscribeType === "CUSTOM" && this.config.replayId) {
|
|
780
|
-
const g = parseInt(this.config.replayId, 10);
|
|
781
|
-
this.client.subscribeFromReplayId(
|
|
782
|
-
d,
|
|
783
|
-
c,
|
|
784
|
-
l,
|
|
785
|
-
g
|
|
786
|
-
);
|
|
787
|
-
} else
|
|
788
|
-
this.client.subscribe(d, c, l);
|
|
789
|
-
this.status({
|
|
790
|
-
fill: "green",
|
|
791
|
-
shape: "dot",
|
|
792
|
-
text: `subscribed: ${d}`
|
|
793
|
-
}), this.reconnectAttempt = 0;
|
|
794
|
-
} catch (e) {
|
|
795
|
-
this.status({
|
|
854
|
+
}
|
|
855
|
+
scheduleReconnect(n) {
|
|
856
|
+
if (this.stopped) return;
|
|
857
|
+
if (this.reconnectAttempt++, this.reconnectAttempt > this.maxReconnectAttempts) {
|
|
858
|
+
this.error(
|
|
859
|
+
`Streaming: max reconnect attempts (${this.maxReconnectAttempts}) reached. Giving up.`
|
|
860
|
+
), this.status({
|
|
796
861
|
fill: "red",
|
|
797
862
|
shape: "dot",
|
|
798
|
-
text:
|
|
799
|
-
})
|
|
800
|
-
|
|
801
|
-
), this.scheduleReconnect(n);
|
|
863
|
+
text: "reconnect failed — re-deploy to retry"
|
|
864
|
+
});
|
|
865
|
+
return;
|
|
802
866
|
}
|
|
803
|
-
|
|
804
|
-
scheduleReconnect(n) {
|
|
805
|
-
this.reconnectAttempt++;
|
|
806
|
-
const e = Math.min(
|
|
867
|
+
const t = Math.min(
|
|
807
868
|
1e3 * Math.pow(2, this.reconnectAttempt),
|
|
808
869
|
this.maxReconnectDelay
|
|
809
870
|
);
|
|
810
871
|
this.log(
|
|
811
|
-
`Scheduling reconnect in ${
|
|
872
|
+
`Scheduling reconnect in ${t}ms (attempt ${this.reconnectAttempt}/${this.maxReconnectAttempts})`
|
|
812
873
|
), this.status({
|
|
813
874
|
fill: "green",
|
|
814
875
|
shape: "dot",
|
|
815
|
-
text: `reconnecting in ${Math.round(
|
|
876
|
+
text: `reconnecting in ${Math.round(t / 1e3)}s`
|
|
816
877
|
}), this.setTimeout(async () => {
|
|
817
878
|
await this.cleanup(), await this.subscribe(n);
|
|
818
|
-
},
|
|
879
|
+
}, t);
|
|
819
880
|
}
|
|
820
881
|
async cleanup() {
|
|
821
|
-
var n,
|
|
882
|
+
var n, t;
|
|
822
883
|
try {
|
|
823
|
-
this.client && (await ((
|
|
884
|
+
this.grpcErrorHandler && (process.removeListener("uncaughtException", this.grpcErrorHandler), this.grpcErrorHandler = null), this.client && (await ((t = (n = this.client).close) == null ? void 0 : t.call(n)), this.client = null);
|
|
824
885
|
} catch {
|
|
825
886
|
}
|
|
826
887
|
}
|
|
827
|
-
async input() {
|
|
828
|
-
}
|
|
829
888
|
async closed() {
|
|
830
889
|
await this.cleanup();
|
|
831
890
|
}
|
|
832
891
|
};
|
|
833
|
-
f(
|
|
834
|
-
let
|
|
835
|
-
const
|
|
892
|
+
f(w, "SalesforceStreaming"), s(w, "type", "salesforce-streaming"), s(w, "category", "salesforce"), s(w, "color", "#FFFFFF"), s(w, "configSchema", ye), s(w, "outputsSchema", xe);
|
|
893
|
+
let v = w;
|
|
894
|
+
const be = h(
|
|
836
895
|
{
|
|
837
|
-
name:
|
|
838
|
-
connection:
|
|
896
|
+
name: e.String({ default: "", "x-nrg-form": { icon: "tag" } }),
|
|
897
|
+
connection: e.NodeRef($, {
|
|
839
898
|
"x-nrg-form": { icon: "cloud" }
|
|
840
899
|
}),
|
|
841
|
-
method:
|
|
900
|
+
method: e.Union(
|
|
842
901
|
[
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
902
|
+
e.Literal("GET"),
|
|
903
|
+
e.Literal("POST"),
|
|
904
|
+
e.Literal("PUT"),
|
|
905
|
+
e.Literal("PATCH"),
|
|
906
|
+
e.Literal("DELETE")
|
|
848
907
|
],
|
|
849
908
|
{ default: "POST", "x-nrg-form": { icon: "random" } }
|
|
850
909
|
),
|
|
851
|
-
path:
|
|
910
|
+
path: e.TypedInput({
|
|
852
911
|
"x-nrg-form": {
|
|
853
912
|
icon: "link",
|
|
854
913
|
typedInputTypes: ["str", "msg"]
|
|
855
914
|
}
|
|
856
|
-
})
|
|
915
|
+
}),
|
|
916
|
+
emitError: e.Boolean({ default: !1 }),
|
|
917
|
+
emitComplete: e.Boolean({ default: !1 }),
|
|
918
|
+
emitStatus: e.Boolean({ default: !1 })
|
|
857
919
|
},
|
|
858
920
|
{ $id: "salesforce-apex:config" }
|
|
859
|
-
),
|
|
921
|
+
), Te = h(
|
|
860
922
|
{
|
|
861
|
-
payload:
|
|
923
|
+
payload: e.Any()
|
|
862
924
|
},
|
|
863
925
|
{ $id: "salesforce-apex:input" }
|
|
864
|
-
),
|
|
926
|
+
), Ie = h(
|
|
865
927
|
{
|
|
866
|
-
payload:
|
|
928
|
+
payload: e.Any()
|
|
867
929
|
},
|
|
868
930
|
{ $id: "salesforce-apex:output" }
|
|
869
|
-
),
|
|
931
|
+
), I = class I extends A {
|
|
870
932
|
async input(o) {
|
|
871
933
|
const n = this.config.connection;
|
|
872
934
|
if (!n) {
|
|
@@ -874,40 +936,40 @@ const yt = h(
|
|
|
874
936
|
return;
|
|
875
937
|
}
|
|
876
938
|
try {
|
|
877
|
-
const
|
|
878
|
-
this.status({ fill: "green", shape: "dot", text: `${
|
|
879
|
-
const
|
|
939
|
+
const t = this.config.method;
|
|
940
|
+
this.status({ fill: "green", shape: "dot", text: `${t}...` });
|
|
941
|
+
const i = await n.getConnection(), r = await this.config.path.resolve(o);
|
|
880
942
|
let l;
|
|
881
|
-
const d =
|
|
882
|
-
d === "get" || d === "delete" ? l = await
|
|
883
|
-
} catch (
|
|
943
|
+
const d = t.toLowerCase();
|
|
944
|
+
d === "get" || d === "delete" ? l = await i.apex[d](r) : l = await i.apex[d](r, o.payload), this.status({ fill: "green", shape: "dot", text: `${t} done` }), this.send({ ...o, payload: l });
|
|
945
|
+
} catch (t) {
|
|
884
946
|
this.status({
|
|
885
947
|
fill: "red",
|
|
886
948
|
shape: "dot",
|
|
887
|
-
text:
|
|
949
|
+
text: t instanceof Error ? t.message : String(t)
|
|
888
950
|
}), this.error(
|
|
889
|
-
`Apex ${this.config.method} failed: ${
|
|
951
|
+
`Apex ${this.config.method} failed: ${t instanceof Error ? t.message : String(t)}`,
|
|
890
952
|
o
|
|
891
953
|
);
|
|
892
954
|
}
|
|
893
955
|
}
|
|
894
956
|
};
|
|
895
|
-
f(
|
|
896
|
-
let
|
|
897
|
-
const
|
|
957
|
+
f(I, "SalesforceApex"), s(I, "type", "salesforce-apex"), s(I, "category", "salesforce"), s(I, "color", "#FFFFFF"), s(I, "configSchema", be), s(I, "inputSchema", Te), s(I, "outputsSchema", Ie);
|
|
958
|
+
let N = I;
|
|
959
|
+
const $e = Y({
|
|
898
960
|
nodes: [
|
|
899
961
|
$,
|
|
900
|
-
|
|
962
|
+
U,
|
|
901
963
|
R,
|
|
902
|
-
|
|
903
|
-
E,
|
|
964
|
+
O,
|
|
904
965
|
j,
|
|
905
|
-
v
|
|
966
|
+
v,
|
|
967
|
+
N
|
|
906
968
|
]
|
|
907
969
|
});
|
|
908
|
-
var
|
|
909
|
-
|
|
970
|
+
var C = $e;
|
|
971
|
+
C && typeof C == "object" && Array.isArray(C.nodes) && (C = G(C.nodes));
|
|
910
972
|
export {
|
|
911
|
-
|
|
973
|
+
C as default
|
|
912
974
|
};
|
|
913
975
|
//# sourceMappingURL=index.mjs.map
|