@bonsae/node-red-salesforce 0.5.0 → 0.6.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/README.md +52 -10
- package/index.d.ts +1 -0
- package/index.html +2 -1
- package/index.mjs +391 -316
- package/index.mjs.map +1 -1
- package/locales/de/index.html +1 -1
- package/locales/en-US/index.html +1 -1
- package/locales/es-ES/index.html +1 -1
- package/locales/fr/index.html +1 -1
- package/locales/ja/index.html +1 -1
- package/locales/ko/index.html +1 -1
- package/locales/pt-BR/index.html +1 -1
- package/locales/ru/index.html +1 -1
- package/locales/zh-CN/index.html +1 -1
- package/locales/zh-TW/index.html +1 -1
- package/package.json +2 -2
- package/resources/index.C1dzx4s2.js +49 -0
- package/resources/index.zXteTlSH.css +48 -0
- package/resources/index.dnWzY-T-.js +0 -1
package/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
import { fileURLToPath as
|
|
6
|
-
import { dirname as
|
|
7
|
-
import { registerTypes as
|
|
8
|
-
import { defineSchema as
|
|
9
|
-
import
|
|
1
|
+
var V = Object.defineProperty;
|
|
2
|
+
var Q = (i, s, t) => s in i ? V(i, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[s] = t;
|
|
3
|
+
var h = (i, s) => V(i, "name", { value: s, configurable: !0 });
|
|
4
|
+
var a = (i, s, t) => Q(i, typeof s != "symbol" ? s + "" : s, t);
|
|
5
|
+
import { fileURLToPath as X } from "url";
|
|
6
|
+
import { dirname as W } from "path";
|
|
7
|
+
import { registerTypes as Z } from "@bonsae/nrg/server";
|
|
8
|
+
import { defineSchema as f, SchemaType as e, ConfigNode as _, IONode as C, defineModule as ee } from "@bonsae/nrg/server";
|
|
9
|
+
import Y from "jsforce";
|
|
10
10
|
import z from "node:crypto";
|
|
11
|
-
var
|
|
12
|
-
const
|
|
11
|
+
var K = X(import.meta.url), Ge = W(K);
|
|
12
|
+
const te = f(
|
|
13
13
|
{
|
|
14
14
|
name: e.String({ default: "" }),
|
|
15
15
|
loginUrl: e.String({
|
|
@@ -41,112 +41,112 @@ const ee = p(
|
|
|
41
41
|
)
|
|
42
42
|
},
|
|
43
43
|
{ $id: "salesforce-connection:config" }
|
|
44
|
-
),
|
|
44
|
+
), ne = f(
|
|
45
45
|
{
|
|
46
46
|
accessToken: e.String({ default: "", format: "password" }),
|
|
47
47
|
refreshToken: e.String({ default: "", format: "password" }),
|
|
48
48
|
instanceUrl: e.String({ default: "" })
|
|
49
49
|
},
|
|
50
50
|
{ $id: "salesforce-connection:credentials" }
|
|
51
|
-
),
|
|
52
|
-
function
|
|
51
|
+
), J = 600 * 1e3, U = /* @__PURE__ */ new Map();
|
|
52
|
+
function se() {
|
|
53
53
|
return z.randomBytes(32).toString("base64url");
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
function
|
|
57
|
-
return z.createHash("sha256").update(
|
|
55
|
+
h(se, "generateCodeVerifier");
|
|
56
|
+
function oe(i) {
|
|
57
|
+
return z.createHash("sha256").update(i).digest("base64url");
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
function
|
|
61
|
-
const s = z.randomUUID(), t =
|
|
62
|
-
|
|
59
|
+
h(oe, "generateCodeChallenge");
|
|
60
|
+
function re(i) {
|
|
61
|
+
const s = z.randomUUID(), t = se(), n = oe(t);
|
|
62
|
+
U.set(s, {
|
|
63
63
|
codeVerifier: t,
|
|
64
|
-
nodeId:
|
|
65
|
-
clientId:
|
|
66
|
-
loginUrl:
|
|
67
|
-
callbackUrl:
|
|
64
|
+
nodeId: i.nodeId,
|
|
65
|
+
clientId: i.clientId,
|
|
66
|
+
loginUrl: i.loginUrl,
|
|
67
|
+
callbackUrl: i.callbackUrl,
|
|
68
68
|
timestamp: Date.now()
|
|
69
69
|
});
|
|
70
|
-
for (const [o,
|
|
71
|
-
Date.now() -
|
|
70
|
+
for (const [o, r] of U)
|
|
71
|
+
Date.now() - r.timestamp > J && U.delete(o);
|
|
72
72
|
return { state: s, codeChallenge: n };
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
function
|
|
76
|
-
const s =
|
|
77
|
-
return !s || (
|
|
74
|
+
h(re, "createAuthState");
|
|
75
|
+
function ae(i) {
|
|
76
|
+
const s = U.get(i);
|
|
77
|
+
return !s || (U.delete(i), Date.now() - s.timestamp > J) ? null : s;
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
function
|
|
81
|
-
return
|
|
79
|
+
h(ae, "consumeAuthState");
|
|
80
|
+
function ie(i) {
|
|
81
|
+
return i.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
function
|
|
83
|
+
h(ie, "escapeHtml");
|
|
84
|
+
function v(i, s = !0) {
|
|
85
85
|
const t = s ? "<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>${ie(i)}</p>${t}</body></html>`;
|
|
87
87
|
}
|
|
88
|
-
|
|
89
|
-
function
|
|
90
|
-
const s = (
|
|
88
|
+
h(v, "errorPage");
|
|
89
|
+
function ce(i) {
|
|
90
|
+
const s = (i.settings.httpAdminRoot || "").replace(
|
|
91
91
|
/\/$/,
|
|
92
92
|
""
|
|
93
93
|
);
|
|
94
|
-
|
|
94
|
+
i.httpAdmin.post("/salesforce/auth/start", (t, n) => {
|
|
95
95
|
try {
|
|
96
96
|
const {
|
|
97
97
|
nodeId: o,
|
|
98
|
-
loginUrl:
|
|
98
|
+
loginUrl: r,
|
|
99
99
|
clientId: c,
|
|
100
100
|
callbackUrl: u
|
|
101
101
|
} = t.body;
|
|
102
|
-
if (!o || !
|
|
102
|
+
if (!o || !r || !c) {
|
|
103
103
|
n.status(400).json({ error: "nodeId, loginUrl, and clientId are required" });
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
|
-
const l = u || `${t.protocol}://${t.get("host")}${s}/salesforce/auth/callback`, { state:
|
|
106
|
+
const l = u || `${t.protocol}://${t.get("host")}${s}/salesforce/auth/callback`, { state: p, codeChallenge: d } = re({
|
|
107
107
|
nodeId: o,
|
|
108
108
|
clientId: c,
|
|
109
|
-
loginUrl:
|
|
109
|
+
loginUrl: r,
|
|
110
110
|
callbackUrl: l
|
|
111
111
|
}), m = new URLSearchParams({
|
|
112
112
|
response_type: "code",
|
|
113
113
|
client_id: c,
|
|
114
114
|
redirect_uri: l,
|
|
115
|
-
state:
|
|
116
|
-
code_challenge:
|
|
115
|
+
state: p,
|
|
116
|
+
code_challenge: d,
|
|
117
117
|
code_challenge_method: "S256"
|
|
118
118
|
});
|
|
119
119
|
n.json({
|
|
120
|
-
authorizationUrl: `${
|
|
120
|
+
authorizationUrl: `${r}/services/oauth2/authorize?${m.toString()}`
|
|
121
121
|
});
|
|
122
122
|
} catch (o) {
|
|
123
|
-
|
|
123
|
+
i.log.error(
|
|
124
124
|
`salesforce-connection: auth/start error: ${o instanceof Error ? o.message : String(o)}`
|
|
125
125
|
), n.status(500).json({ error: "Failed to start authorization" });
|
|
126
126
|
}
|
|
127
|
-
}),
|
|
127
|
+
}), i.httpAdmin.get("/salesforce/auth/callback", async (t, n) => {
|
|
128
128
|
try {
|
|
129
|
-
const { code: o, state:
|
|
129
|
+
const { code: o, state: r, error: c, error_description: u } = t.query;
|
|
130
130
|
if (c) {
|
|
131
|
-
|
|
131
|
+
i.log.error(
|
|
132
132
|
`salesforce-connection: OAuth error: ${c} - ${u}`
|
|
133
|
-
), n.status(400).send(
|
|
133
|
+
), n.status(400).send(v(String(u || c)));
|
|
134
134
|
return;
|
|
135
135
|
}
|
|
136
|
-
if (!o || !
|
|
137
|
-
n.status(400).send(
|
|
136
|
+
if (!o || !r) {
|
|
137
|
+
n.status(400).send(v("Missing code or state parameter"));
|
|
138
138
|
return;
|
|
139
139
|
}
|
|
140
|
-
const l =
|
|
140
|
+
const l = ae(r);
|
|
141
141
|
if (!l) {
|
|
142
142
|
n.status(400).send(
|
|
143
|
-
|
|
143
|
+
v(
|
|
144
144
|
"Invalid or expired authorization state. Please try again."
|
|
145
145
|
)
|
|
146
146
|
);
|
|
147
147
|
return;
|
|
148
148
|
}
|
|
149
|
-
const
|
|
149
|
+
const p = await fetch(
|
|
150
150
|
`${l.loginUrl}/services/oauth2/token`,
|
|
151
151
|
{
|
|
152
152
|
method: "POST",
|
|
@@ -160,31 +160,31 @@ function ae(a) {
|
|
|
160
160
|
})
|
|
161
161
|
}
|
|
162
162
|
);
|
|
163
|
-
if (!
|
|
164
|
-
const g = await
|
|
165
|
-
|
|
163
|
+
if (!p.ok) {
|
|
164
|
+
const g = await p.text();
|
|
165
|
+
i.log.error(
|
|
166
166
|
`salesforce-connection: Token exchange failed: ${g}`
|
|
167
167
|
), n.status(500).send(
|
|
168
|
-
|
|
168
|
+
v(
|
|
169
169
|
"Token exchange failed. Check the Node-RED logs for details."
|
|
170
170
|
)
|
|
171
171
|
);
|
|
172
172
|
return;
|
|
173
173
|
}
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
accessToken:
|
|
177
|
-
refreshToken:
|
|
178
|
-
instanceUrl:
|
|
179
|
-
}),
|
|
180
|
-
`salesforce-connection: Successfully authorized node ${l.nodeId} for ${
|
|
174
|
+
const d = await p.json();
|
|
175
|
+
i.nodes.addCredentials(l.nodeId, {
|
|
176
|
+
accessToken: d.access_token,
|
|
177
|
+
refreshToken: d.refresh_token,
|
|
178
|
+
instanceUrl: d.instance_url
|
|
179
|
+
}), i.log.info(
|
|
180
|
+
`salesforce-connection: Successfully authorized node ${l.nodeId} for ${d.instance_url}`
|
|
181
181
|
);
|
|
182
182
|
const m = JSON.stringify({
|
|
183
183
|
type: "salesforce-auth-success",
|
|
184
184
|
nodeId: l.nodeId,
|
|
185
|
-
accessToken:
|
|
186
|
-
refreshToken:
|
|
187
|
-
instanceUrl:
|
|
185
|
+
accessToken: d.access_token,
|
|
186
|
+
refreshToken: d.refresh_token,
|
|
187
|
+
instanceUrl: d.instance_url
|
|
188
188
|
});
|
|
189
189
|
n.send(`<!DOCTYPE html>
|
|
190
190
|
<html>
|
|
@@ -200,41 +200,41 @@ function ae(a) {
|
|
|
200
200
|
</body>
|
|
201
201
|
</html>`);
|
|
202
202
|
} catch (o) {
|
|
203
|
-
|
|
203
|
+
i.log.error(
|
|
204
204
|
`salesforce-connection: auth/callback error: ${o instanceof Error ? o.message : String(o)}`
|
|
205
|
-
), n.status(500).send(
|
|
205
|
+
), n.status(500).send(v("An unexpected error occurred."));
|
|
206
206
|
}
|
|
207
|
-
}),
|
|
207
|
+
}), i.httpAdmin.get("/salesforce/auth/status/:nodeId", (t, n) => {
|
|
208
208
|
try {
|
|
209
|
-
const o =
|
|
209
|
+
const o = i.nodes.getCredentials(t.params.nodeId), r = !!(o != null && o.accessToken && (o != null && o.instanceUrl));
|
|
210
210
|
n.json({
|
|
211
|
-
authenticated:
|
|
212
|
-
instanceUrl:
|
|
211
|
+
authenticated: r,
|
|
212
|
+
instanceUrl: r ? o.instanceUrl : void 0
|
|
213
213
|
});
|
|
214
214
|
} catch {
|
|
215
215
|
n.json({ authenticated: !1 });
|
|
216
216
|
}
|
|
217
217
|
});
|
|
218
218
|
}
|
|
219
|
-
|
|
220
|
-
function
|
|
221
|
-
const t =
|
|
219
|
+
h(ce, "initAuthRoutes");
|
|
220
|
+
function P(i, s) {
|
|
221
|
+
const t = i.nodes.getCredentials(s);
|
|
222
222
|
if (!(t != null && t.accessToken) || !(t != null && t.instanceUrl))
|
|
223
223
|
throw new Error("Connection not authenticated");
|
|
224
|
-
return new
|
|
224
|
+
return new Y.Connection({
|
|
225
225
|
instanceUrl: t.instanceUrl,
|
|
226
226
|
accessToken: t.accessToken
|
|
227
227
|
});
|
|
228
228
|
}
|
|
229
|
-
|
|
230
|
-
const
|
|
229
|
+
h(P, "getConnection");
|
|
230
|
+
const T = class T {
|
|
231
231
|
constructor(s) {
|
|
232
|
-
|
|
232
|
+
a(this, "conn");
|
|
233
233
|
this.conn = s;
|
|
234
234
|
}
|
|
235
235
|
// --- Apex REST ---
|
|
236
236
|
async invoke(s, t) {
|
|
237
|
-
const n = this.conn.version || "62.0",
|
|
237
|
+
const n = this.conn.version || "62.0", r = (await this.conn.request({
|
|
238
238
|
method: "POST",
|
|
239
239
|
url: `/services/data/v${n}/actions/custom/apex/${s}`,
|
|
240
240
|
body: JSON.stringify({
|
|
@@ -242,11 +242,11 @@ const b = class b {
|
|
|
242
242
|
}),
|
|
243
243
|
headers: { "Content-Type": "application/json" }
|
|
244
244
|
}))[0];
|
|
245
|
-
if (!
|
|
246
|
-
const c =
|
|
245
|
+
if (!r.isSuccess) {
|
|
246
|
+
const c = r.errors.map((u) => u.message).join("; ");
|
|
247
247
|
throw new Error(`Invocable action failed: ${c}`);
|
|
248
248
|
}
|
|
249
|
-
return
|
|
249
|
+
return r;
|
|
250
250
|
}
|
|
251
251
|
async post(s, t) {
|
|
252
252
|
return await this.conn.apex.post(
|
|
@@ -274,14 +274,14 @@ const b = class b {
|
|
|
274
274
|
}
|
|
275
275
|
// --- Tooling API ---
|
|
276
276
|
async queryApexClassesByName(s) {
|
|
277
|
-
const t = s.map((
|
|
277
|
+
const t = s.map((r) => `'${r}'`).join(","), n = await this.conn.tooling.query(
|
|
278
278
|
`SELECT Id, Name, Body FROM ApexClass WHERE Name IN (${t})`
|
|
279
279
|
), o = /* @__PURE__ */ new Map();
|
|
280
|
-
for (const
|
|
281
|
-
o.set(
|
|
282
|
-
Id:
|
|
283
|
-
Name:
|
|
284
|
-
Body:
|
|
280
|
+
for (const r of n.records)
|
|
281
|
+
o.set(r.Name, {
|
|
282
|
+
Id: r.Id,
|
|
283
|
+
Name: r.Name,
|
|
284
|
+
Body: r.Body
|
|
285
285
|
});
|
|
286
286
|
return o;
|
|
287
287
|
}
|
|
@@ -293,8 +293,8 @@ const b = class b {
|
|
|
293
293
|
Body: t
|
|
294
294
|
});
|
|
295
295
|
if (!n.success) {
|
|
296
|
-
const
|
|
297
|
-
throw new Error(`Apex create failed: ${
|
|
296
|
+
const r = (o = n.errors) == null ? void 0 : o.map((c) => c.message).join("; ");
|
|
297
|
+
throw new Error(`Apex create failed: ${r}`);
|
|
298
298
|
}
|
|
299
299
|
return { id: n.id };
|
|
300
300
|
}, `create ${s}`);
|
|
@@ -306,7 +306,7 @@ const b = class b {
|
|
|
306
306
|
);
|
|
307
307
|
}
|
|
308
308
|
async queryApexRestAndInvocableClasses() {
|
|
309
|
-
var o,
|
|
309
|
+
var o, r;
|
|
310
310
|
const s = await this.conn.tooling.query(
|
|
311
311
|
"SELECT Name, Body FROM ApexClass ORDER BY Name"
|
|
312
312
|
), t = [], n = [];
|
|
@@ -317,7 +317,7 @@ const b = class b {
|
|
|
317
317
|
);
|
|
318
318
|
t.push({ name: c.Name, urlMapping: u ? u[1] : void 0 });
|
|
319
319
|
}
|
|
320
|
-
(
|
|
320
|
+
(r = c.Body) != null && r.includes("@InvocableMethod") && n.push({ name: c.Name });
|
|
321
321
|
}
|
|
322
322
|
return { rest: t, invocable: n };
|
|
323
323
|
}
|
|
@@ -342,42 +342,113 @@ const b = class b {
|
|
|
342
342
|
}
|
|
343
343
|
// --- Retry ---
|
|
344
344
|
async withRetry(s, t) {
|
|
345
|
-
for (let n = 1; n <=
|
|
345
|
+
for (let n = 1; n <= T.MAX_RETRIES; n++)
|
|
346
346
|
try {
|
|
347
347
|
return await s();
|
|
348
348
|
} catch (o) {
|
|
349
|
-
if (n ===
|
|
350
|
-
const
|
|
349
|
+
if (n === T.MAX_RETRIES) throw o;
|
|
350
|
+
const r = T.RETRY_DELAY_MS * n;
|
|
351
351
|
console.warn(
|
|
352
|
-
`[SalesforceClient] ${t} failed (attempt ${n}/${
|
|
353
|
-
), await new Promise((c) => setTimeout(c,
|
|
352
|
+
`[SalesforceClient] ${t} failed (attempt ${n}/${T.MAX_RETRIES}), retrying in ${r}ms...`
|
|
353
|
+
), await new Promise((c) => setTimeout(c, r));
|
|
354
354
|
}
|
|
355
355
|
throw new Error("unreachable");
|
|
356
356
|
}
|
|
357
357
|
};
|
|
358
|
-
|
|
359
|
-
let R =
|
|
360
|
-
function
|
|
361
|
-
|
|
358
|
+
h(T, "SalesforceClient"), a(T, "MAX_RETRIES", 3), a(T, "RETRY_DELAY_MS", 1e3);
|
|
359
|
+
let R = T;
|
|
360
|
+
function le(i) {
|
|
361
|
+
switch (i) {
|
|
362
|
+
case "boolean":
|
|
363
|
+
return "Boolean";
|
|
364
|
+
case "int":
|
|
365
|
+
return "Integer";
|
|
366
|
+
case "long":
|
|
367
|
+
return "Long";
|
|
368
|
+
case "double":
|
|
369
|
+
return "Double";
|
|
370
|
+
case "currency":
|
|
371
|
+
case "percent":
|
|
372
|
+
return "Decimal";
|
|
373
|
+
case "date":
|
|
374
|
+
return "Date";
|
|
375
|
+
case "datetime":
|
|
376
|
+
return "Datetime";
|
|
377
|
+
case "time":
|
|
378
|
+
return "Time";
|
|
379
|
+
case "id":
|
|
380
|
+
return "Id";
|
|
381
|
+
case "reference":
|
|
382
|
+
return "Id";
|
|
383
|
+
case "base64":
|
|
384
|
+
return "Blob";
|
|
385
|
+
case "location":
|
|
386
|
+
return "Location";
|
|
387
|
+
case "address":
|
|
388
|
+
return "Address";
|
|
389
|
+
default:
|
|
390
|
+
return "String";
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
h(le, "sfTypeToApex");
|
|
394
|
+
function ue(i) {
|
|
395
|
+
const s = [`global class ${i.name} {`];
|
|
396
|
+
for (const t of i.fields) {
|
|
397
|
+
const n = le(t.type);
|
|
398
|
+
s.push(` global ${n} ${t.name};`);
|
|
399
|
+
}
|
|
400
|
+
return s.push("}"), s.join(`
|
|
401
|
+
`);
|
|
402
|
+
}
|
|
403
|
+
h(ue, "buildFauxClass");
|
|
404
|
+
function de(i) {
|
|
405
|
+
i.httpAdmin.get(
|
|
362
406
|
"/salesforce/list-apex-classes/:nodeId",
|
|
363
407
|
async (s, t) => {
|
|
364
408
|
try {
|
|
365
|
-
const n =
|
|
409
|
+
const n = P(i, s.params.nodeId), o = new R(n);
|
|
366
410
|
t.json(await o.queryApexRestAndInvocableClasses());
|
|
367
411
|
} catch (n) {
|
|
368
412
|
const o = n instanceof Error ? n.message : String(n);
|
|
369
413
|
t.status(500).json({ error: o });
|
|
370
414
|
}
|
|
371
415
|
}
|
|
416
|
+
), i.httpAdmin.get(
|
|
417
|
+
"/salesforce/describe-sobjects/:nodeId",
|
|
418
|
+
async (s, t) => {
|
|
419
|
+
try {
|
|
420
|
+
const n = P(i, s.params.nodeId), o = s.params.nodeId, r = G.get(o);
|
|
421
|
+
if (r && Date.now() - r.timestamp < pe) {
|
|
422
|
+
t.json({ sobjects: r.data });
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
const u = (await n.describeGlobal()).sobjects.filter((d) => d.queryable).map((d) => d.name), l = 25, p = {};
|
|
426
|
+
for (let d = 0; d < u.length; d += l) {
|
|
427
|
+
const m = u.slice(d, d + l), g = await Promise.all(
|
|
428
|
+
m.map((x) => n.describe(x).catch(() => null))
|
|
429
|
+
);
|
|
430
|
+
for (const x of g)
|
|
431
|
+
x && (p[x.name] = ue(x));
|
|
432
|
+
}
|
|
433
|
+
G.set(o, {
|
|
434
|
+
data: p,
|
|
435
|
+
timestamp: Date.now()
|
|
436
|
+
}), t.json({ sobjects: p });
|
|
437
|
+
} catch (n) {
|
|
438
|
+
const o = n instanceof Error ? n.message : String(n);
|
|
439
|
+
t.status(500).json({ error: o });
|
|
440
|
+
}
|
|
441
|
+
}
|
|
372
442
|
);
|
|
373
443
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
444
|
+
h(de, "initApexRoutes");
|
|
445
|
+
const pe = 1800 * 1e3, G = /* @__PURE__ */ new Map();
|
|
446
|
+
function he(i) {
|
|
447
|
+
i.httpAdmin.get(
|
|
377
448
|
"/salesforce/list-streaming-channels/:nodeId",
|
|
378
449
|
async (s, t) => {
|
|
379
450
|
try {
|
|
380
|
-
const n =
|
|
451
|
+
const n = P(i, s.params.nodeId), o = new R(n);
|
|
381
452
|
t.json(await o.queryStreamingChannels());
|
|
382
453
|
} catch (n) {
|
|
383
454
|
const o = n instanceof Error ? n.message : String(n);
|
|
@@ -386,18 +457,18 @@ function le(a) {
|
|
|
386
457
|
}
|
|
387
458
|
);
|
|
388
459
|
}
|
|
389
|
-
|
|
390
|
-
function
|
|
391
|
-
|
|
460
|
+
h(he, "initStreamingRoutes");
|
|
461
|
+
function fe(i) {
|
|
462
|
+
ce(i), de(i), he(i);
|
|
392
463
|
}
|
|
393
|
-
|
|
394
|
-
const
|
|
464
|
+
h(fe, "initRoutes");
|
|
465
|
+
const F = class F extends _ {
|
|
395
466
|
constructor() {
|
|
396
467
|
super(...arguments);
|
|
397
|
-
|
|
468
|
+
a(this, "conn", null);
|
|
398
469
|
}
|
|
399
470
|
static async registered(t) {
|
|
400
|
-
|
|
471
|
+
fe(t);
|
|
401
472
|
}
|
|
402
473
|
async getConnection() {
|
|
403
474
|
if (this.conn) return this.conn;
|
|
@@ -406,7 +477,7 @@ const v = class v extends Z {
|
|
|
406
477
|
throw new Error(
|
|
407
478
|
"Salesforce connection not authorized. Please authorize in the node configuration."
|
|
408
479
|
);
|
|
409
|
-
return this.conn = new
|
|
480
|
+
return this.conn = new Y.Connection({
|
|
410
481
|
oauth2: {
|
|
411
482
|
clientId: this.config.clientId,
|
|
412
483
|
loginUrl: this.config.loginUrl
|
|
@@ -434,9 +505,9 @@ const v = class v extends Z {
|
|
|
434
505
|
this.conn = null;
|
|
435
506
|
}
|
|
436
507
|
};
|
|
437
|
-
|
|
438
|
-
let w =
|
|
439
|
-
const
|
|
508
|
+
h(F, "SalesforceConnection"), a(F, "type", "salesforce-connection"), a(F, "configSchema", te), a(F, "credentialsSchema", ne);
|
|
509
|
+
let w = F;
|
|
510
|
+
const ge = f(
|
|
440
511
|
{
|
|
441
512
|
name: e.String({ default: "", "x-nrg-form": { icon: "tag" } }),
|
|
442
513
|
connection: e.NodeRef(w, {
|
|
@@ -453,19 +524,19 @@ const de = p(
|
|
|
453
524
|
statusPort: e.Boolean({ default: !1 })
|
|
454
525
|
},
|
|
455
526
|
{ $id: "salesforce-soql:config" }
|
|
456
|
-
),
|
|
527
|
+
), me = f(
|
|
457
528
|
{
|
|
458
529
|
payload: e.Any()
|
|
459
530
|
},
|
|
460
531
|
{ $id: "salesforce-soql:input" }
|
|
461
|
-
),
|
|
532
|
+
), ye = f(
|
|
462
533
|
{
|
|
463
534
|
payload: e.Array(e.Any()),
|
|
464
535
|
totalSize: e.Number(),
|
|
465
536
|
done: e.Boolean()
|
|
466
537
|
},
|
|
467
538
|
{ $id: "salesforce-soql:output" }
|
|
468
|
-
),
|
|
539
|
+
), $ = class $ extends C {
|
|
469
540
|
async input(s) {
|
|
470
541
|
const t = this.config.connection;
|
|
471
542
|
if (!t) {
|
|
@@ -474,16 +545,16 @@ const de = p(
|
|
|
474
545
|
}
|
|
475
546
|
try {
|
|
476
547
|
this.status({ fill: "green", shape: "dot", text: "querying..." });
|
|
477
|
-
const n = await t.getConnection(), o = await this.config.query.resolve(s),
|
|
548
|
+
const n = await t.getConnection(), o = await this.config.query.resolve(s), r = await n.query(o);
|
|
478
549
|
this.status({
|
|
479
550
|
fill: "green",
|
|
480
551
|
shape: "dot",
|
|
481
|
-
text: `${
|
|
552
|
+
text: `${r.totalSize} records`
|
|
482
553
|
}), this.send({
|
|
483
554
|
...s,
|
|
484
|
-
payload:
|
|
485
|
-
totalSize:
|
|
486
|
-
done:
|
|
555
|
+
payload: r.records,
|
|
556
|
+
totalSize: r.totalSize,
|
|
557
|
+
done: r.done
|
|
487
558
|
});
|
|
488
559
|
} catch (n) {
|
|
489
560
|
this.status({
|
|
@@ -497,9 +568,9 @@ const de = p(
|
|
|
497
568
|
}
|
|
498
569
|
}
|
|
499
570
|
};
|
|
500
|
-
|
|
501
|
-
let
|
|
502
|
-
const
|
|
571
|
+
h($, "SalesforceSoql"), a($, "type", "salesforce-soql"), a($, "category", "salesforce"), a($, "color", "#FFFFFF"), a($, "configSchema", ge), a($, "inputSchema", me), a($, "outputsSchema", ye);
|
|
572
|
+
let k = $;
|
|
573
|
+
const xe = f(
|
|
503
574
|
{
|
|
504
575
|
name: e.String({ default: "", "x-nrg-form": { icon: "tag" } }),
|
|
505
576
|
connection: e.NodeRef(w, {
|
|
@@ -551,17 +622,17 @@ const fe = p(
|
|
|
551
622
|
}
|
|
552
623
|
}
|
|
553
624
|
}
|
|
554
|
-
),
|
|
625
|
+
), be = f(
|
|
555
626
|
{
|
|
556
627
|
payload: e.Any()
|
|
557
628
|
},
|
|
558
629
|
{ $id: "salesforce-dml:input" }
|
|
559
|
-
),
|
|
630
|
+
), we = f(
|
|
560
631
|
{
|
|
561
632
|
payload: e.Any()
|
|
562
633
|
},
|
|
563
634
|
{ $id: "salesforce-dml:output" }
|
|
564
|
-
),
|
|
635
|
+
), I = class I extends C {
|
|
565
636
|
async input(s) {
|
|
566
637
|
const t = this.config.connection;
|
|
567
638
|
if (!t) {
|
|
@@ -571,7 +642,7 @@ const fe = p(
|
|
|
571
642
|
try {
|
|
572
643
|
const n = this.config.operation;
|
|
573
644
|
this.status({ fill: "green", shape: "dot", text: `${n}...` });
|
|
574
|
-
const o = await t.getConnection(),
|
|
645
|
+
const o = await t.getConnection(), r = await this.config.sObjectType.resolve(s), c = o.sobject(r), u = await this.config.record.resolve(s) ?? s.payload;
|
|
575
646
|
let l;
|
|
576
647
|
switch (n) {
|
|
577
648
|
case "create":
|
|
@@ -605,9 +676,9 @@ const fe = p(
|
|
|
605
676
|
}
|
|
606
677
|
}
|
|
607
678
|
};
|
|
608
|
-
|
|
609
|
-
let
|
|
610
|
-
const
|
|
679
|
+
h(I, "SalesforceDml"), a(I, "type", "salesforce-dml"), a(I, "category", "salesforce"), a(I, "color", "#FFFFFF"), a(I, "configSchema", xe), a(I, "inputSchema", be), a(I, "outputsSchema", we);
|
|
680
|
+
let j = I;
|
|
681
|
+
const Te = f(
|
|
611
682
|
{
|
|
612
683
|
name: e.String({ default: "", "x-nrg-form": { icon: "tag" } }),
|
|
613
684
|
connection: e.NodeRef(w, {
|
|
@@ -691,21 +762,21 @@ const ye = p(
|
|
|
691
762
|
}
|
|
692
763
|
}
|
|
693
764
|
}
|
|
694
|
-
),
|
|
765
|
+
), $e = f(
|
|
695
766
|
{
|
|
696
767
|
payload: e.Any({
|
|
697
768
|
description: "Records array, CSV string, readable stream (ingest) or SOQL string (query)"
|
|
698
769
|
})
|
|
699
770
|
},
|
|
700
771
|
{ $id: "salesforce-bulk:input" }
|
|
701
|
-
),
|
|
772
|
+
), Ie = f(
|
|
702
773
|
{
|
|
703
774
|
payload: e.Any({
|
|
704
775
|
description: "Query: individual record. Ingest: { successfulResults, failedResults, unprocessedRecords }"
|
|
705
776
|
})
|
|
706
777
|
},
|
|
707
778
|
{ $id: "salesforce-bulk:output" }
|
|
708
|
-
),
|
|
779
|
+
), S = class S extends C {
|
|
709
780
|
async input(s) {
|
|
710
781
|
try {
|
|
711
782
|
const t = this.config.connection;
|
|
@@ -726,30 +797,30 @@ const ye = p(
|
|
|
726
797
|
columnDelimiter: this.config.columnDelimiter,
|
|
727
798
|
lineEnding: this.config.lineEnding
|
|
728
799
|
});
|
|
729
|
-
let
|
|
800
|
+
let r = 0;
|
|
730
801
|
await new Promise((c, u) => {
|
|
731
802
|
o.on("data", (l) => {
|
|
732
|
-
|
|
803
|
+
r++, this.send({ ...t, payload: l }), r % 1e3 === 0 && this.status({
|
|
733
804
|
fill: "green",
|
|
734
805
|
shape: "dot",
|
|
735
|
-
text: `query: ${
|
|
806
|
+
text: `query: ${r} records...`
|
|
736
807
|
});
|
|
737
808
|
}), o.on("end", () => c()), o.on("error", u);
|
|
738
809
|
}), this.status({
|
|
739
810
|
fill: "green",
|
|
740
811
|
shape: "dot",
|
|
741
|
-
text: `query complete: ${
|
|
812
|
+
text: `query complete: ${r} records`
|
|
742
813
|
});
|
|
743
814
|
}
|
|
744
815
|
async executeIngest(s, t, n) {
|
|
745
|
-
var
|
|
816
|
+
var d, m, g;
|
|
746
817
|
const o = await this.config.sObjectType.resolve(t);
|
|
747
818
|
this.status({
|
|
748
819
|
fill: "green",
|
|
749
820
|
shape: "dot",
|
|
750
821
|
text: `creating ${n} job...`
|
|
751
822
|
});
|
|
752
|
-
const
|
|
823
|
+
const r = s.bulk2.createJob({
|
|
753
824
|
operation: n,
|
|
754
825
|
object: o,
|
|
755
826
|
columnDelimiter: this.config.columnDelimiter,
|
|
@@ -757,30 +828,30 @@ const ye = p(
|
|
|
757
828
|
...n === "upsert" && this.config.externalIdField ? { externalIdFieldName: this.config.externalIdField } : {},
|
|
758
829
|
...this.config.assignmentRuleId ? { assignmentRuleId: this.config.assignmentRuleId } : {}
|
|
759
830
|
});
|
|
760
|
-
await
|
|
831
|
+
await r.open(), this.status({
|
|
761
832
|
fill: "green",
|
|
762
833
|
shape: "dot",
|
|
763
834
|
text: "uploading data..."
|
|
764
|
-
}), await
|
|
835
|
+
}), await r.uploadData(t.payload), this.status({
|
|
765
836
|
fill: "green",
|
|
766
837
|
shape: "dot",
|
|
767
838
|
text: "processing..."
|
|
768
|
-
}), await
|
|
839
|
+
}), await r.close(), await r.poll(this.config.pollInterval, this.config.pollTimeout), this.status({
|
|
769
840
|
fill: "green",
|
|
770
841
|
shape: "dot",
|
|
771
842
|
text: "retrieving results..."
|
|
772
843
|
});
|
|
773
|
-
const c = await
|
|
844
|
+
const c = await r.getAllResults(), u = ((d = c.successfulResults) == null ? void 0 : d.length) ?? 0, l = ((m = c.failedResults) == null ? void 0 : m.length) ?? 0, p = u + l + (((g = c.unprocessedRecords) == null ? void 0 : g.length) ?? 0);
|
|
774
845
|
this.send({ ...t, payload: c }), this.status({
|
|
775
846
|
fill: l > 0 ? "red" : "green",
|
|
776
847
|
shape: "dot",
|
|
777
|
-
text: `${n} complete: ${u} ok, ${l} failed, ${
|
|
848
|
+
text: `${n} complete: ${u} ok, ${l} failed, ${p} total`
|
|
778
849
|
});
|
|
779
850
|
}
|
|
780
851
|
};
|
|
781
|
-
|
|
782
|
-
let
|
|
783
|
-
const
|
|
852
|
+
h(S, "SalesforceBulk"), a(S, "type", "salesforce-bulk"), a(S, "category", "salesforce"), a(S, "color", "#FFFFFF"), a(S, "configSchema", Te), a(S, "inputSchema", $e), a(S, "outputsSchema", Ie);
|
|
853
|
+
let M = S;
|
|
854
|
+
const Se = f(
|
|
784
855
|
{
|
|
785
856
|
name: e.String({ default: "", "x-nrg-form": { icon: "tag" } }),
|
|
786
857
|
connection: e.NodeRef(w, {
|
|
@@ -797,12 +868,12 @@ const be = p(
|
|
|
797
868
|
statusPort: e.Boolean({ default: !1 })
|
|
798
869
|
},
|
|
799
870
|
{ $id: "salesforce-describe:config" }
|
|
800
|
-
),
|
|
871
|
+
), Ee = f(
|
|
801
872
|
{
|
|
802
873
|
payload: e.Any()
|
|
803
874
|
},
|
|
804
875
|
{ $id: "salesforce-describe:input" }
|
|
805
|
-
),
|
|
876
|
+
), Le = f(
|
|
806
877
|
{
|
|
807
878
|
payload: e.Object({
|
|
808
879
|
name: e.String(),
|
|
@@ -812,7 +883,7 @@ const be = p(
|
|
|
812
883
|
})
|
|
813
884
|
},
|
|
814
885
|
{ $id: "salesforce-describe:output" }
|
|
815
|
-
),
|
|
886
|
+
), E = class E extends C {
|
|
816
887
|
async input(s) {
|
|
817
888
|
const t = this.config.connection;
|
|
818
889
|
if (!t) {
|
|
@@ -821,18 +892,18 @@ const be = p(
|
|
|
821
892
|
}
|
|
822
893
|
try {
|
|
823
894
|
this.status({ fill: "green", shape: "dot", text: "describing..." });
|
|
824
|
-
const n = await t.getConnection(), o = await this.config.sObjectType.resolve(s),
|
|
895
|
+
const n = await t.getConnection(), o = await this.config.sObjectType.resolve(s), r = await n.sobject(o).describe();
|
|
825
896
|
this.status({
|
|
826
897
|
fill: "green",
|
|
827
898
|
shape: "dot",
|
|
828
|
-
text: `${
|
|
899
|
+
text: `${r.name}: ${r.fields.length} fields`
|
|
829
900
|
}), this.send({
|
|
830
901
|
...s,
|
|
831
902
|
payload: {
|
|
832
|
-
name:
|
|
833
|
-
fields:
|
|
834
|
-
childRelationships:
|
|
835
|
-
recordTypeInfos:
|
|
903
|
+
name: r.name,
|
|
904
|
+
fields: r.fields,
|
|
905
|
+
childRelationships: r.childRelationships,
|
|
906
|
+
recordTypeInfos: r.recordTypeInfos
|
|
836
907
|
}
|
|
837
908
|
});
|
|
838
909
|
} catch (n) {
|
|
@@ -847,9 +918,9 @@ const be = p(
|
|
|
847
918
|
}
|
|
848
919
|
}
|
|
849
920
|
};
|
|
850
|
-
|
|
851
|
-
let
|
|
852
|
-
const
|
|
921
|
+
h(E, "SalesforceDescribe"), a(E, "type", "salesforce-describe"), a(E, "category", "salesforce"), a(E, "color", "#FFFFFF"), a(E, "configSchema", Se), a(E, "inputSchema", Ee), a(E, "outputsSchema", Le);
|
|
922
|
+
let B = E;
|
|
923
|
+
const Ae = f(
|
|
853
924
|
{
|
|
854
925
|
name: e.String({ default: "", "x-nrg-form": { icon: "tag" } }),
|
|
855
926
|
connection: e.NodeRef(w, {
|
|
@@ -897,7 +968,7 @@ const Ie = p(
|
|
|
897
968
|
}
|
|
898
969
|
}
|
|
899
970
|
}
|
|
900
|
-
),
|
|
971
|
+
), Re = f(
|
|
901
972
|
{
|
|
902
973
|
payload: e.Any(),
|
|
903
974
|
replayId: e.Any(),
|
|
@@ -905,15 +976,15 @@ const Ie = p(
|
|
|
905
976
|
topic: e.String()
|
|
906
977
|
},
|
|
907
978
|
{ $id: "salesforce-streaming:output" }
|
|
908
|
-
),
|
|
979
|
+
), A = class A extends C {
|
|
909
980
|
constructor() {
|
|
910
981
|
super(...arguments);
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
982
|
+
a(this, "client", null);
|
|
983
|
+
a(this, "reconnectAttempt", 0);
|
|
984
|
+
a(this, "maxReconnectDelay", 6e4);
|
|
985
|
+
a(this, "maxReconnectAttempts", 10);
|
|
986
|
+
a(this, "grpcErrorHandler", null);
|
|
987
|
+
a(this, "stopped", !1);
|
|
917
988
|
}
|
|
918
989
|
async created() {
|
|
919
990
|
const t = this.config.connection;
|
|
@@ -934,8 +1005,8 @@ const Ie = p(
|
|
|
934
1005
|
this.status({ fill: "red", shape: "dot", text: "auth expired" }), this.error("Salesforce token expired. Re-authorize the connection.");
|
|
935
1006
|
return;
|
|
936
1007
|
}
|
|
937
|
-
const o = n.accessToken,
|
|
938
|
-
if (!o || !
|
|
1008
|
+
const o = n.accessToken, r = n.instanceUrl;
|
|
1009
|
+
if (!o || !r) {
|
|
939
1010
|
this.status({ fill: "red", shape: "dot", text: "not authorized" }), this.error("Salesforce connection not authorized");
|
|
940
1011
|
return;
|
|
941
1012
|
}
|
|
@@ -943,9 +1014,9 @@ const Ie = p(
|
|
|
943
1014
|
this.client = new c({
|
|
944
1015
|
authType: "user-supplied",
|
|
945
1016
|
accessToken: o,
|
|
946
|
-
instanceUrl:
|
|
1017
|
+
instanceUrl: r
|
|
947
1018
|
}), await this.client.connect();
|
|
948
|
-
const u = this.config.numRequested || null, l = this.config.channelName,
|
|
1019
|
+
const u = this.config.numRequested || null, l = this.config.channelName, p = /* @__PURE__ */ h((d, m, g) => {
|
|
949
1020
|
if (m === "event" || m === "lastevent")
|
|
950
1021
|
this.send({
|
|
951
1022
|
payload: (g == null ? void 0 : g.payload) ?? g,
|
|
@@ -954,8 +1025,8 @@ const Ie = p(
|
|
|
954
1025
|
topic: l
|
|
955
1026
|
});
|
|
956
1027
|
else if (m === "error") {
|
|
957
|
-
const
|
|
958
|
-
if (this.warn(`Streaming error: ${
|
|
1028
|
+
const x = g instanceof Error ? g.message : String(g ?? "stream error");
|
|
1029
|
+
if (this.warn(`Streaming error: ${x}`), x.includes("UNAUTHENTICATED") || x.includes("authentication")) {
|
|
959
1030
|
this.stopped = !0, this.status({
|
|
960
1031
|
fill: "red",
|
|
961
1032
|
shape: "dot",
|
|
@@ -965,15 +1036,15 @@ const Ie = p(
|
|
|
965
1036
|
), this.cleanup();
|
|
966
1037
|
return;
|
|
967
1038
|
}
|
|
968
|
-
this.status({ fill: "red", shape: "dot", text:
|
|
1039
|
+
this.status({ fill: "red", shape: "dot", text: x }), this.scheduleReconnect(t);
|
|
969
1040
|
} else if (m === "end") {
|
|
970
1041
|
if (this.stopped) return;
|
|
971
1042
|
this.log("Streaming subscription ended"), this.status({ fill: "red", shape: "dot", text: "disconnected" }), this.scheduleReconnect(t);
|
|
972
1043
|
}
|
|
973
1044
|
}, "callback");
|
|
974
|
-
if (this.grpcErrorHandler && process.removeListener("uncaughtException", this.grpcErrorHandler), this.grpcErrorHandler = (
|
|
1045
|
+
if (this.grpcErrorHandler && process.removeListener("uncaughtException", this.grpcErrorHandler), this.grpcErrorHandler = (d) => {
|
|
975
1046
|
var m, g;
|
|
976
|
-
((m =
|
|
1047
|
+
((m = d.message) != null && m.includes("UNAUTHENTICATED") || (g = d.message) != null && g.includes("authentication")) && (this.stopped = !0, this.warn(`Caught gRPC auth error: ${d.message}`), this.status({
|
|
977
1048
|
fill: "red",
|
|
978
1049
|
shape: "dot",
|
|
979
1050
|
text: "auth expired — re-authorize"
|
|
@@ -981,19 +1052,19 @@ const Ie = p(
|
|
|
981
1052
|
}, process.on("uncaughtException", this.grpcErrorHandler), this.config.subscribeType === "EARLIEST")
|
|
982
1053
|
this.client.subscribeFromEarliestEvent(
|
|
983
1054
|
l,
|
|
984
|
-
|
|
1055
|
+
p,
|
|
985
1056
|
u
|
|
986
1057
|
);
|
|
987
1058
|
else if (this.config.subscribeType === "CUSTOM" && this.config.replayId) {
|
|
988
|
-
const
|
|
1059
|
+
const d = parseInt(this.config.replayId, 10);
|
|
989
1060
|
this.client.subscribeFromReplayId(
|
|
990
1061
|
l,
|
|
991
|
-
|
|
1062
|
+
p,
|
|
992
1063
|
u,
|
|
993
|
-
|
|
1064
|
+
d
|
|
994
1065
|
);
|
|
995
1066
|
} else
|
|
996
|
-
this.client.subscribe(l,
|
|
1067
|
+
this.client.subscribe(l, p, u);
|
|
997
1068
|
this.status({
|
|
998
1069
|
fill: "green",
|
|
999
1070
|
shape: "dot",
|
|
@@ -1046,9 +1117,9 @@ const Ie = p(
|
|
|
1046
1117
|
await this.cleanup();
|
|
1047
1118
|
}
|
|
1048
1119
|
};
|
|
1049
|
-
|
|
1050
|
-
let H =
|
|
1051
|
-
const
|
|
1120
|
+
h(A, "SalesforceStreaming"), a(A, "type", "salesforce-streaming"), a(A, "category", "salesforce"), a(A, "color", "#FFFFFF"), a(A, "configSchema", Ae), a(A, "outputsSchema", Re);
|
|
1121
|
+
let H = A;
|
|
1122
|
+
const Ce = f(
|
|
1052
1123
|
{
|
|
1053
1124
|
name: e.String({ default: "", "x-nrg-form": { icon: "tag" } }),
|
|
1054
1125
|
connection: e.NodeRef(w, {
|
|
@@ -1085,13 +1156,13 @@ const Ee = p(
|
|
|
1085
1156
|
statusPort: e.Boolean({ default: !1 })
|
|
1086
1157
|
},
|
|
1087
1158
|
{ $id: "salesforce-apex-invocation:config" }
|
|
1088
|
-
),
|
|
1159
|
+
), Fe = f(
|
|
1089
1160
|
{ payload: e.Any() },
|
|
1090
1161
|
{ $id: "salesforce-apex-invocation:input" }
|
|
1091
|
-
),
|
|
1162
|
+
), ve = f(
|
|
1092
1163
|
{ payload: e.Any() },
|
|
1093
1164
|
{ $id: "salesforce-apex-invocation:output" }
|
|
1094
|
-
),
|
|
1165
|
+
), L = class L extends C {
|
|
1095
1166
|
async input(s) {
|
|
1096
1167
|
const t = this.config.connection;
|
|
1097
1168
|
if (!t) {
|
|
@@ -1101,16 +1172,16 @@ const Ee = p(
|
|
|
1101
1172
|
try {
|
|
1102
1173
|
const n = await t.getConnection();
|
|
1103
1174
|
if (this.status({ fill: "green", shape: "dot", text: "executing..." }), this.config.apexType === "rest") {
|
|
1104
|
-
const o = await this.config.path.resolve(s),
|
|
1175
|
+
const o = await this.config.path.resolve(s), r = this.config.method.toLowerCase();
|
|
1105
1176
|
let c;
|
|
1106
|
-
|
|
1177
|
+
r === "get" || r === "delete" ? c = await n.apex[r](o) : c = await n.apex[r](o, s.payload), this.status({
|
|
1107
1178
|
fill: "green",
|
|
1108
1179
|
shape: "dot",
|
|
1109
1180
|
text: `${this.config.method} done`
|
|
1110
1181
|
}), this.send({ ...s, payload: c });
|
|
1111
1182
|
} else {
|
|
1112
|
-
const
|
|
1113
|
-
this.status({ fill: "green", shape: "dot", text: "done" }), this.send({ ...s, payload:
|
|
1183
|
+
const r = await new R(n).invoke(this.config.actionName, s.payload);
|
|
1184
|
+
this.status({ fill: "green", shape: "dot", text: "done" }), this.send({ ...s, payload: r.outputValues });
|
|
1114
1185
|
}
|
|
1115
1186
|
} catch (n) {
|
|
1116
1187
|
const o = n instanceof Error ? n.message : String(n);
|
|
@@ -1118,9 +1189,73 @@ const Ee = p(
|
|
|
1118
1189
|
}
|
|
1119
1190
|
}
|
|
1120
1191
|
};
|
|
1121
|
-
|
|
1122
|
-
let
|
|
1123
|
-
const
|
|
1192
|
+
h(L, "SalesforceApex"), a(L, "type", "salesforce-apex-invocation"), a(L, "category", "salesforce"), a(L, "color", "#FFFFFF"), a(L, "configSchema", Ce), a(L, "inputSchema", Fe), a(L, "outputsSchema", ve);
|
|
1193
|
+
let q = L;
|
|
1194
|
+
const Oe = `private static Object run(String payload) {
|
|
1195
|
+
// Your code here
|
|
1196
|
+
return payload;
|
|
1197
|
+
}`;
|
|
1198
|
+
function Ue(i, s) {
|
|
1199
|
+
return `public class ${i} {
|
|
1200
|
+
public class Input {
|
|
1201
|
+
@InvocableVariable(required=true)
|
|
1202
|
+
public String payload;
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
public class Output {
|
|
1206
|
+
@InvocableVariable
|
|
1207
|
+
public String result;
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
@InvocableMethod(label='${i}' description='Generated by NRG')
|
|
1211
|
+
public static List<Output> execute(List<Input> inputs) {
|
|
1212
|
+
Output out = new Output();
|
|
1213
|
+
Object returnValue = run(inputs[0].payload);
|
|
1214
|
+
out.result = returnValue instanceof String
|
|
1215
|
+
? (String) returnValue
|
|
1216
|
+
: JSON.serialize(returnValue);
|
|
1217
|
+
return new List<Output>{ out };
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
${s}
|
|
1221
|
+
}`;
|
|
1222
|
+
}
|
|
1223
|
+
h(Ue, "buildInvocableClass");
|
|
1224
|
+
const Ne = {
|
|
1225
|
+
HttpGet: "doGet",
|
|
1226
|
+
HttpPost: "doPost",
|
|
1227
|
+
HttpPut: "doPut",
|
|
1228
|
+
HttpPatch: "doPatch",
|
|
1229
|
+
HttpDelete: "doDelete"
|
|
1230
|
+
}, Pe = {
|
|
1231
|
+
HttpGet: !1,
|
|
1232
|
+
HttpPost: !0,
|
|
1233
|
+
HttpPut: !0,
|
|
1234
|
+
HttpPatch: !0,
|
|
1235
|
+
HttpDelete: !1
|
|
1236
|
+
};
|
|
1237
|
+
function ke(i, s, t, n) {
|
|
1238
|
+
const o = Ne[t], c = Pe[t] ? ` String payload = RestContext.request.requestBody != null
|
|
1239
|
+
? RestContext.request.requestBody.toString()
|
|
1240
|
+
: null;` : ` String payload = RestContext.request.params != null
|
|
1241
|
+
? JSON.serialize(RestContext.request.params)
|
|
1242
|
+
: null;`;
|
|
1243
|
+
return `@RestResource(urlMapping='${s}')
|
|
1244
|
+
global class ${i} {
|
|
1245
|
+
@${t}
|
|
1246
|
+
global static String ${o}() {
|
|
1247
|
+
${c}
|
|
1248
|
+
Object returnValue = run(payload);
|
|
1249
|
+
return returnValue instanceof String
|
|
1250
|
+
? (String) returnValue
|
|
1251
|
+
: JSON.serialize(returnValue);
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
${n}
|
|
1255
|
+
}`;
|
|
1256
|
+
}
|
|
1257
|
+
h(ke, "buildRestClass");
|
|
1258
|
+
const je = f(
|
|
1124
1259
|
{
|
|
1125
1260
|
name: e.String({ default: "", "x-nrg-form": { icon: "tag" } }),
|
|
1126
1261
|
connection: e.NodeRef(w, {
|
|
@@ -1149,31 +1284,35 @@ const Ae = p(
|
|
|
1149
1284
|
{ default: "HttpPost", "x-nrg-form": { icon: "random" } }
|
|
1150
1285
|
),
|
|
1151
1286
|
code: e.String({
|
|
1152
|
-
default:
|
|
1153
|
-
"x-nrg-form": { editorLanguage: "
|
|
1287
|
+
default: Oe,
|
|
1288
|
+
"x-nrg-form": { editorLanguage: "apex" }
|
|
1154
1289
|
}),
|
|
1155
1290
|
errorPort: e.Boolean({ default: !1 }),
|
|
1156
1291
|
completePort: e.Boolean({ default: !1 }),
|
|
1157
1292
|
statusPort: e.Boolean({ default: !1 })
|
|
1158
1293
|
},
|
|
1159
1294
|
{ $id: "salesforce-apex-code:config" }
|
|
1160
|
-
),
|
|
1295
|
+
), Me = f(
|
|
1161
1296
|
{
|
|
1162
|
-
classPrefix: e.String({ default: "NRG_" })
|
|
1297
|
+
classPrefix: e.String({ default: "NRG_" }),
|
|
1298
|
+
languageServerUrl: e.String({
|
|
1299
|
+
default: "",
|
|
1300
|
+
exportable: !0
|
|
1301
|
+
})
|
|
1163
1302
|
},
|
|
1164
1303
|
{ $id: "salesforce-apex-code:settings" }
|
|
1165
|
-
),
|
|
1304
|
+
), Be = f(
|
|
1166
1305
|
{ payload: e.Any() },
|
|
1167
1306
|
{ $id: "salesforce-apex-code:input" }
|
|
1168
|
-
),
|
|
1307
|
+
), He = f(
|
|
1169
1308
|
{ payload: e.Any() },
|
|
1170
1309
|
{ $id: "salesforce-apex-code:output" }
|
|
1171
1310
|
), y = class y {
|
|
1172
1311
|
constructor(s) {
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1312
|
+
a(this, "pendingDeploys", /* @__PURE__ */ new Map());
|
|
1313
|
+
a(this, "pendingDeletes", /* @__PURE__ */ new Set());
|
|
1314
|
+
a(this, "flushTimer", null);
|
|
1315
|
+
a(this, "connectionProvider");
|
|
1177
1316
|
this.connectionProvider = s;
|
|
1178
1317
|
}
|
|
1179
1318
|
static getInstance(s, t) {
|
|
@@ -1204,115 +1343,51 @@ const Ae = p(
|
|
|
1204
1343
|
async flush() {
|
|
1205
1344
|
const s = new Set(this.pendingDeletes), t = new Map(this.pendingDeploys);
|
|
1206
1345
|
if (this.pendingDeletes.clear(), this.pendingDeploys.clear(), s.size === 0 && t.size === 0) return;
|
|
1207
|
-
const n = await this.connectionProvider.getConnection(), o = new R(n),
|
|
1346
|
+
const n = await this.connectionProvider.getConnection(), o = new R(n), r = [...s, ...t.keys()], c = await o.queryApexClassesByName(r);
|
|
1208
1347
|
for (const u of s) {
|
|
1209
1348
|
const l = c.get(u);
|
|
1210
1349
|
if (l)
|
|
1211
1350
|
try {
|
|
1212
1351
|
await o.deleteApexClass(l.Id);
|
|
1213
|
-
} catch (
|
|
1214
|
-
console.error(`[ApexClassManager] Failed to delete ${u}:`,
|
|
1352
|
+
} catch (p) {
|
|
1353
|
+
console.error(`[ApexClassManager] Failed to delete ${u}:`, p);
|
|
1215
1354
|
}
|
|
1216
1355
|
}
|
|
1217
1356
|
for (const [u, l] of t)
|
|
1218
1357
|
try {
|
|
1219
|
-
const
|
|
1220
|
-
if (
|
|
1221
|
-
if (
|
|
1222
|
-
l.resolve({ id:
|
|
1358
|
+
const p = c.get(u);
|
|
1359
|
+
if (p) {
|
|
1360
|
+
if (p.Body === l.body) {
|
|
1361
|
+
l.resolve({ id: p.Id });
|
|
1223
1362
|
continue;
|
|
1224
1363
|
}
|
|
1225
|
-
await o.deleteApexClass(
|
|
1364
|
+
await o.deleteApexClass(p.Id);
|
|
1226
1365
|
}
|
|
1227
|
-
const { id:
|
|
1228
|
-
l.resolve({ id:
|
|
1229
|
-
} catch (
|
|
1230
|
-
l.reject(
|
|
1366
|
+
const { id: d } = await o.createApexClass(u, l.body);
|
|
1367
|
+
l.resolve({ id: d });
|
|
1368
|
+
} catch (p) {
|
|
1369
|
+
l.reject(p instanceof Error ? p : new Error(String(p)));
|
|
1231
1370
|
}
|
|
1232
1371
|
}
|
|
1233
1372
|
};
|
|
1234
|
-
|
|
1235
|
-
let
|
|
1236
|
-
|
|
1237
|
-
return `public class ${a} {
|
|
1238
|
-
public class Input {
|
|
1239
|
-
@InvocableVariable(required=true)
|
|
1240
|
-
public String payload;
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
public class Output {
|
|
1244
|
-
@InvocableVariable
|
|
1245
|
-
public String result;
|
|
1246
|
-
}
|
|
1247
|
-
|
|
1248
|
-
@InvocableMethod(label='${a}' description='Generated by NRG')
|
|
1249
|
-
public static List<Output> execute(List<Input> inputs) {
|
|
1250
|
-
Output out = new Output();
|
|
1251
|
-
Object returnValue = run(inputs[0].payload);
|
|
1252
|
-
out.result = returnValue instanceof String
|
|
1253
|
-
? (String) returnValue
|
|
1254
|
-
: JSON.serialize(returnValue);
|
|
1255
|
-
return new List<Output>{ out };
|
|
1256
|
-
}
|
|
1257
|
-
|
|
1258
|
-
private static Object run(String payload) {
|
|
1259
|
-
${s}
|
|
1260
|
-
}
|
|
1261
|
-
}`;
|
|
1262
|
-
}
|
|
1263
|
-
d(Oe, "buildInvocableClass");
|
|
1264
|
-
const Ne = {
|
|
1265
|
-
HttpGet: "doGet",
|
|
1266
|
-
HttpPost: "doPost",
|
|
1267
|
-
HttpPut: "doPut",
|
|
1268
|
-
HttpPatch: "doPatch",
|
|
1269
|
-
HttpDelete: "doDelete"
|
|
1270
|
-
}, Pe = {
|
|
1271
|
-
HttpGet: !1,
|
|
1272
|
-
HttpPost: !0,
|
|
1273
|
-
HttpPut: !0,
|
|
1274
|
-
HttpPatch: !0,
|
|
1275
|
-
HttpDelete: !1
|
|
1276
|
-
};
|
|
1277
|
-
function Ue(a, s, t, n) {
|
|
1278
|
-
const o = Ne[t], c = Pe[t] ? ` String payload = RestContext.request.requestBody != null
|
|
1279
|
-
? RestContext.request.requestBody.toString()
|
|
1280
|
-
: null;` : ` String payload = RestContext.request.params != null
|
|
1281
|
-
? JSON.serialize(RestContext.request.params)
|
|
1282
|
-
: null;`;
|
|
1283
|
-
return `@RestResource(urlMapping='${s}')
|
|
1284
|
-
global class ${a} {
|
|
1285
|
-
@${t}
|
|
1286
|
-
global static String ${o}() {
|
|
1287
|
-
${c}
|
|
1288
|
-
Object returnValue = run(payload);
|
|
1289
|
-
return returnValue instanceof String
|
|
1290
|
-
? (String) returnValue
|
|
1291
|
-
: JSON.serialize(returnValue);
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
|
-
private static Object run(String payload) {
|
|
1295
|
-
${n}
|
|
1296
|
-
}
|
|
1297
|
-
}`;
|
|
1298
|
-
}
|
|
1299
|
-
d(Ue, "buildRestClass");
|
|
1300
|
-
const x = class x extends A {
|
|
1373
|
+
h(y, "ApexClassManager"), a(y, "instances", /* @__PURE__ */ new Map()), a(y, "FLUSH_DELAY_MS", 500);
|
|
1374
|
+
let N = y;
|
|
1375
|
+
const b = class b extends C {
|
|
1301
1376
|
constructor() {
|
|
1302
1377
|
super(...arguments);
|
|
1303
|
-
|
|
1378
|
+
a(this, "deployed", !1);
|
|
1304
1379
|
}
|
|
1305
1380
|
getFullClassName() {
|
|
1306
1381
|
return `${this.settings.classPrefix}${this.config.className}`;
|
|
1307
1382
|
}
|
|
1308
1383
|
buildApexBody() {
|
|
1309
1384
|
const t = this.getFullClassName();
|
|
1310
|
-
return this.config.apexType === "rest" ?
|
|
1385
|
+
return this.config.apexType === "rest" ? ke(
|
|
1311
1386
|
t,
|
|
1312
1387
|
this.config.urlMapping,
|
|
1313
1388
|
this.config.httpMethod,
|
|
1314
1389
|
this.config.code
|
|
1315
|
-
) :
|
|
1390
|
+
) : Ue(t, this.config.code);
|
|
1316
1391
|
}
|
|
1317
1392
|
async created() {
|
|
1318
1393
|
const t = this.config.connection;
|
|
@@ -1324,15 +1399,15 @@ const x = class x extends A {
|
|
|
1324
1399
|
this.status({ fill: "red", shape: "dot", text: "class name required" });
|
|
1325
1400
|
return;
|
|
1326
1401
|
}
|
|
1327
|
-
const n =
|
|
1402
|
+
const n = N.getInstance(
|
|
1328
1403
|
t.id,
|
|
1329
1404
|
t
|
|
1330
1405
|
);
|
|
1331
1406
|
this.status({ fill: "green", shape: "dot", text: "deploying..." }), n.register(this.getFullClassName(), this.buildApexBody()).then(() => {
|
|
1332
1407
|
this.deployed = !0, this.status({ fill: "green", shape: "dot", text: "deployed" });
|
|
1333
1408
|
}).catch((o) => {
|
|
1334
|
-
const
|
|
1335
|
-
this.status({ fill: "red", shape: "dot", text:
|
|
1409
|
+
const r = o instanceof Error ? o.message : String(o);
|
|
1410
|
+
this.status({ fill: "red", shape: "dot", text: r }), this.error(`Apex deploy failed: ${r}`);
|
|
1336
1411
|
});
|
|
1337
1412
|
}
|
|
1338
1413
|
async input(t) {
|
|
@@ -1349,9 +1424,9 @@ const x = class x extends A {
|
|
|
1349
1424
|
return;
|
|
1350
1425
|
}
|
|
1351
1426
|
try {
|
|
1352
|
-
const o = await n.getConnection(),
|
|
1427
|
+
const o = await n.getConnection(), r = new R(o);
|
|
1353
1428
|
if (this.status({ fill: "green", shape: "dot", text: "executing..." }), this.config.apexType === "invocable") {
|
|
1354
|
-
const c = await
|
|
1429
|
+
const c = await r.invoke(
|
|
1355
1430
|
this.getFullClassName(),
|
|
1356
1431
|
t.payload
|
|
1357
1432
|
);
|
|
@@ -1359,17 +1434,17 @@ const x = class x extends A {
|
|
|
1359
1434
|
} else {
|
|
1360
1435
|
const c = this.config.urlMapping, u = this.config.httpMethod;
|
|
1361
1436
|
let l;
|
|
1362
|
-
u === "HttpGet" || u === "HttpDelete" ? l = u === "HttpGet" ? await
|
|
1437
|
+
u === "HttpGet" || u === "HttpDelete" ? l = u === "HttpGet" ? await r.get(c) : await r.delete(c) : l = await r[u === "HttpPut" ? "put" : u === "HttpPatch" ? "patch" : "post"](c, t.payload), this.status({ fill: "green", shape: "dot", text: "done" }), this.send({ ...t, payload: l });
|
|
1363
1438
|
}
|
|
1364
1439
|
} catch (o) {
|
|
1365
|
-
const
|
|
1366
|
-
this.status({ fill: "red", shape: "dot", text:
|
|
1440
|
+
const r = o instanceof Error ? o.message : String(o);
|
|
1441
|
+
this.status({ fill: "red", shape: "dot", text: r }), this.error(`Apex execution failed: ${r}`, t);
|
|
1367
1442
|
}
|
|
1368
1443
|
}
|
|
1369
1444
|
async closed(t) {
|
|
1370
1445
|
if (t) {
|
|
1371
1446
|
const n = this.config.connection;
|
|
1372
|
-
n &&
|
|
1447
|
+
n && N.getInstance(
|
|
1373
1448
|
n.id,
|
|
1374
1449
|
n
|
|
1375
1450
|
).unregister(this.getFullClassName());
|
|
@@ -1377,23 +1452,23 @@ const x = class x extends A {
|
|
|
1377
1452
|
this.deployed = !1;
|
|
1378
1453
|
}
|
|
1379
1454
|
};
|
|
1380
|
-
|
|
1381
|
-
let
|
|
1382
|
-
const
|
|
1455
|
+
h(b, "SalesforceApexCode"), a(b, "type", "salesforce-apex-code"), a(b, "category", "salesforce"), a(b, "color", "#FFFFFF"), a(b, "configSchema", je), a(b, "inputSchema", Be), a(b, "outputsSchema", He), a(b, "settingsSchema", Me);
|
|
1456
|
+
let D = b;
|
|
1457
|
+
const qe = ee({
|
|
1383
1458
|
nodes: [
|
|
1384
1459
|
w,
|
|
1385
|
-
U,
|
|
1386
1460
|
k,
|
|
1387
1461
|
j,
|
|
1388
1462
|
M,
|
|
1389
|
-
H,
|
|
1390
1463
|
B,
|
|
1391
|
-
|
|
1464
|
+
H,
|
|
1465
|
+
q,
|
|
1466
|
+
D
|
|
1392
1467
|
]
|
|
1393
1468
|
});
|
|
1394
|
-
var
|
|
1395
|
-
|
|
1469
|
+
var O = qe;
|
|
1470
|
+
O && typeof O == "object" && Array.isArray(O.nodes) && (O = Z(O.nodes));
|
|
1396
1471
|
export {
|
|
1397
|
-
|
|
1472
|
+
O as default
|
|
1398
1473
|
};
|
|
1399
1474
|
//# sourceMappingURL=index.mjs.map
|