@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/index.mjs CHANGED
@@ -1,114 +1,114 @@
1
1
  var P = Object.defineProperty;
2
- var J = (r, o, n) => o in r ? P(r, o, { enumerable: !0, configurable: !0, writable: !0, value: n }) : r[o] = n;
3
- var f = (r, o) => P(r, "name", { value: o, configurable: !0 });
4
- var i = (r, o, n) => J(r, typeof o != "symbol" ? o + "" : o, n);
5
- import { fileURLToPath as V } from "url";
6
- import { dirname as H } from "path";
7
- import { registerTypes as Y } from "@bonsae/nrg/server";
8
- import { defineSchema as h, SchemaType as t, ConfigNode as G, IONode as F, defineModule as K } from "@bonsae/nrg/server";
9
- import W from "jsforce";
10
- import N from "node:crypto";
11
- var Q = V(import.meta.url), Lt = H(Q);
12
- const X = h(
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: t.String({ default: "" }),
15
- loginUrl: t.String({
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: t.String({
19
+ clientId: e.String({
20
20
  default: "",
21
21
  "x-nrg-form": { icon: "key" }
22
22
  }),
23
- apiVersion: t.Union(
23
+ apiVersion: e.Union(
24
24
  [
25
- t.Literal("62.0"),
26
- t.Literal("61.0"),
27
- t.Literal("60.0"),
28
- t.Literal("59.0"),
29
- t.Literal("58.0"),
30
- t.Literal("57.0"),
31
- t.Literal("56.0"),
32
- t.Literal("55.0")
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: t.Optional(
37
- t.String({
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
- ), Z = h(
44
+ ), X = h(
45
45
  {
46
- accessToken: t.String({ default: "", format: "password" }),
47
- refreshToken: t.String({ default: "", format: "password" }),
48
- instanceUrl: t.String({ default: "" })
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
- ), z = 600 * 1e3, C = /* @__PURE__ */ new Map();
52
- function B() {
53
- return N.randomBytes(32).toString("base64url");
51
+ ), H = 600 * 1e3, F = /* @__PURE__ */ new Map();
52
+ function Z() {
53
+ return M.randomBytes(32).toString("base64url");
54
54
  }
55
- f(B, "generateCodeVerifier");
56
- function D(r) {
57
- return N.createHash("sha256").update(r).digest("base64url");
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 _(r) {
61
- const o = N.randomUUID(), n = B(), e = D(n);
62
- C.set(o, {
60
+ function _(a) {
61
+ const o = M.randomUUID(), n = Z(), t = D(n);
62
+ F.set(o, {
63
63
  codeVerifier: n,
64
- nodeId: r.nodeId,
65
- clientId: r.clientId,
66
- loginUrl: r.loginUrl,
67
- callbackUrl: r.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 [s, a] of C)
71
- Date.now() - a.timestamp > z && C.delete(s);
72
- return { state: o, codeChallenge: e };
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 tt(r) {
76
- const o = C.get(r);
77
- return !o || (C.delete(r), Date.now() - o.timestamp > z) ? null : 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(tt, "consumeAuthState");
80
- function et(r) {
81
- return r.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
79
+ f(ee, "consumeAuthState");
80
+ function te(a) {
81
+ return a.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
82
82
  }
83
- f(et, "escapeHtml");
84
- function k(r, o = !0) {
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>${et(r)}</p>${n}</body></html>`;
86
+ return `<html><body><h2>Authorization Failed</h2><p>${te(a)}</p>${n}</body></html>`;
87
87
  }
88
88
  f(k, "errorPage");
89
- function nt(r) {
90
- const o = (r.settings.httpAdminRoot || "").replace(
89
+ function ne(a) {
90
+ const o = (a.settings.httpAdminRoot || "").replace(
91
91
  /\/$/,
92
92
  ""
93
93
  );
94
- r.httpAdmin.post("/salesforce/auth/start", (n, e) => {
94
+ a.httpAdmin.post("/salesforce/auth/start", (n, t) => {
95
95
  try {
96
96
  const {
97
- nodeId: s,
98
- loginUrl: a,
97
+ nodeId: i,
98
+ loginUrl: r,
99
99
  clientId: l,
100
100
  callbackUrl: d
101
101
  } = n.body;
102
- if (!s || !a || !l) {
103
- e.status(400).json({ error: "nodeId, loginUrl, and clientId are required" });
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: s,
107
+ nodeId: i,
108
108
  clientId: l,
109
- loginUrl: a,
109
+ loginUrl: r,
110
110
  callbackUrl: c
111
- }), p = new URLSearchParams({
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
- e.json({
120
- authorizationUrl: `${a}/services/oauth2/authorize?${p.toString()}`
119
+ t.json({
120
+ authorizationUrl: `${r}/services/oauth2/authorize?${m.toString()}`
121
121
  });
122
- } catch (s) {
123
- r.log.error(
124
- `salesforce-connection: auth/start error: ${s instanceof Error ? s.message : String(s)}`
125
- ), e.status(500).json({ error: "Failed to start authorization" });
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
- }), r.httpAdmin.get("/salesforce/auth/callback", async (n, e) => {
127
+ }), a.httpAdmin.get("/salesforce/auth/callback", async (n, t) => {
128
128
  try {
129
- const { code: s, state: a, error: l, error_description: d } = n.query;
129
+ const { code: i, state: r, error: l, error_description: d } = n.query;
130
130
  if (l) {
131
- r.log.error(
131
+ a.log.error(
132
132
  `salesforce-connection: OAuth error: ${l} - ${d}`
133
- ), e.status(400).send(k(String(d || l)));
133
+ ), t.status(400).send(k(String(d || l)));
134
134
  return;
135
135
  }
136
- if (!s || !a) {
137
- e.status(400).send(k("Missing code or state parameter"));
136
+ if (!i || !r) {
137
+ t.status(400).send(k("Missing code or state parameter"));
138
138
  return;
139
139
  }
140
- const c = tt(a);
140
+ const c = ee(r);
141
141
  if (!c) {
142
- e.status(400).send(
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: s,
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 w = await g.text();
165
- r.log.error(
166
- `salesforce-connection: Token exchange failed: ${w}`
167
- ), e.status(500).send(
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
- r.nodes.addCredentials(c.nodeId, {
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
- }), r.log.info(
179
+ }), a.log.info(
180
180
  `salesforce-connection: Successfully authorized node ${c.nodeId} for ${u.instance_url}`
181
181
  );
182
- const p = JSON.stringify({
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
- e.send(`<!DOCTYPE html>
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(${p}, "*");
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 (s) {
203
- r.log.error(
204
- `salesforce-connection: auth/callback error: ${s instanceof Error ? s.message : String(s)}`
205
- ), e.status(500).send(k("An unexpected error occurred."));
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
- }), r.httpAdmin.get("/salesforce/auth/status/:nodeId", (n, e) => {
207
+ }), a.httpAdmin.get("/salesforce/auth/status/:nodeId", (n, t) => {
208
208
  try {
209
- const s = r.nodes.getCredentials(n.params.nodeId), a = !!(s != null && s.accessToken && (s != null && s.instanceUrl));
210
- e.json({
211
- authenticated: a,
212
- instanceUrl: a ? s.instanceUrl : void 0
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
- e.json({ authenticated: !1 });
215
+ t.json({ authenticated: !1 });
216
216
  }
217
217
  });
218
218
  }
219
- f(nt, "initAuthRoutes");
220
- function ot(r) {
221
- nt(r);
219
+ f(ne, "initAuthRoutes");
220
+ function oe(a) {
221
+ ne(a);
222
222
  }
223
- f(ot, "initRoutes");
224
- const L = class L extends G {
223
+ f(oe, "initRoutes");
224
+ const L = class L extends Q {
225
225
  constructor() {
226
226
  super(...arguments);
227
- i(this, "conn", null);
227
+ s(this, "conn", null);
228
228
  }
229
229
  static async registered(n) {
230
- ot(n);
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 W.Connection({
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", (e) => {
248
+ }), this.conn.on("refresh", (t) => {
249
249
  this.RED.nodes.addCredentials(this.id, {
250
250
  ...this.credentials,
251
- accessToken: e
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"), i(L, "type", "salesforce-connection"), i(L, "configSchema", X), i(L, "credentialsSchema", Z);
267
+ f(L, "SalesforceConnection"), s(L, "type", "salesforce-connection"), s(L, "configSchema", W), s(L, "credentialsSchema", X);
268
268
  let $ = L;
269
- const it = h(
269
+ const ie = h(
270
270
  {
271
- name: t.String({ default: "", "x-nrg-form": { icon: "tag" } }),
272
- connection: t.NodeRef($, {
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: t.TypedInput({
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
- ), st = h(
283
+ ), se = h(
284
284
  {
285
- payload: t.Any()
285
+ payload: e.Any()
286
286
  },
287
287
  { $id: "salesforce-soql:input" }
288
- ), rt = h(
288
+ ), re = h(
289
289
  {
290
- payload: t.Array(t.Any()),
291
- totalSize: t.Number(),
292
- done: t.Boolean()
290
+ payload: e.Array(e.Any()),
291
+ totalSize: e.Number(),
292
+ done: e.Boolean()
293
293
  },
294
294
  { $id: "salesforce-soql:output" }
295
- ), m = class m extends F {
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 e = await n.getConnection(), s = await this.config.query.resolve(o), a = await e.query(s);
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: `${a.totalSize} records`
308
+ text: `${r.totalSize} records`
309
309
  }), this.send({
310
310
  ...o,
311
- payload: a.records,
312
- totalSize: a.totalSize,
313
- done: a.done
311
+ payload: r.records,
312
+ totalSize: r.totalSize,
313
+ done: r.done
314
314
  });
315
- } catch (e) {
315
+ } catch (t) {
316
316
  this.status({
317
317
  fill: "red",
318
318
  shape: "dot",
319
- text: e instanceof Error ? e.message : String(e)
319
+ text: t instanceof Error ? t.message : String(t)
320
320
  }), this.error(
321
- `SOQL query failed: ${e instanceof Error ? e.message : String(e)}`,
321
+ `SOQL query failed: ${t instanceof Error ? t.message : String(t)}`,
322
322
  o
323
323
  );
324
324
  }
325
325
  }
326
326
  };
327
- f(m, "SalesforceSoql"), i(m, "type", "salesforce-soql"), i(m, "category", "salesforce"), i(m, "color", "#FFFFFF"), i(m, "inputs", 1), i(m, "outputs", 1), i(m, "configSchema", it), i(m, "inputSchema", st), i(m, "outputsSchema", rt);
328
- let O = m;
329
- const at = h(
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: t.String({ default: "", "x-nrg-form": { icon: "tag" } }),
332
- connection: t.NodeRef($, {
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: t.Union(
335
+ operation: e.Union(
336
336
  [
337
- t.Literal("create"),
338
- t.Literal("read"),
339
- t.Literal("update"),
340
- t.Literal("delete"),
341
- t.Literal("upsert")
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: t.TypedInput({
345
+ sObjectType: e.TypedInput({
346
346
  "x-nrg-form": {
347
347
  icon: "cube",
348
348
  typedInputTypes: ["str", "msg"]
349
349
  }
350
350
  }),
351
- record: t.TypedInput({
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: t.Optional(
358
- t.String({
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: t.Object({
367
- operation: t.Literal("upsert")
369
+ if: e.Object({
370
+ operation: e.Literal("upsert")
368
371
  }),
369
- then: t.Object({
370
- externalIdField: t.String({ minLength: 1 })
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
- ), ct = h(
381
+ ), ce = h(
379
382
  {
380
- payload: t.Any()
383
+ payload: e.Any()
381
384
  },
382
385
  { $id: "salesforce-dml:input" }
383
- ), lt = h(
386
+ ), le = h(
384
387
  {
385
- payload: t.Any()
388
+ payload: e.Any()
386
389
  },
387
390
  { $id: "salesforce-dml:output" }
388
- ), y = class y extends F {
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 e = this.config.operation;
397
- this.status({ fill: "green", shape: "dot", text: `${e}...` });
398
- const s = await n.getConnection(), a = await this.config.sObjectType.resolve(o), l = s.sobject(a), d = await this.config.record.resolve(o) ?? o.payload;
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 (e) {
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: ${e}`);
420
+ throw new Error(`Unknown operation: ${t}`);
418
421
  }
419
- this.status({ fill: "green", shape: "dot", text: `${e} done` }), this.send({ ...o, payload: c });
420
- } catch (e) {
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: e instanceof Error ? e.message : String(e)
427
+ text: t instanceof Error ? t.message : String(t)
425
428
  }), this.error(
426
- `DML ${this.config.operation} failed: ${e instanceof Error ? e.message : String(e)}`,
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(y, "SalesforceDml"), i(y, "type", "salesforce-dml"), i(y, "category", "salesforce"), i(y, "color", "#FFFFFF"), i(y, "inputs", 1), i(y, "outputs", 1), i(y, "configSchema", at), i(y, "inputSchema", ct), i(y, "outputsSchema", lt);
433
- let R = y;
434
- const dt = h(
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: t.String({ default: "", "x-nrg-form": { icon: "tag" } }),
437
- connection: t.NodeRef($, {
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: t.Union(
443
+ operation: e.Union(
441
444
  [
442
- t.Literal("insert"),
443
- t.Literal("update"),
444
- t.Literal("upsert"),
445
- t.Literal("delete"),
446
- t.Literal("query")
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: t.TypedInput({
453
+ sObjectType: e.TypedInput({
451
454
  "x-nrg-form": {
452
455
  icon: "cube",
453
456
  typedInputTypes: ["str", "msg"]
454
457
  }
455
458
  }),
456
- externalIdField: t.Optional(
457
- t.String({
459
+ externalIdField: e.Optional(
460
+ e.String({
458
461
  default: "",
459
462
  "x-nrg-form": { icon: "key" }
460
463
  })
461
464
  ),
462
- assignmentRuleId: t.Optional(
463
- t.String({
465
+ assignmentRuleId: e.Optional(
466
+ e.String({
464
467
  default: "",
465
468
  "x-nrg-form": { icon: "gavel" }
466
469
  })
467
470
  ),
468
- columnDelimiter: t.Union(
471
+ columnDelimiter: e.Union(
469
472
  [
470
- t.Literal("COMMA"),
471
- t.Literal("TAB"),
472
- t.Literal("PIPE"),
473
- t.Literal("SEMICOLON"),
474
- t.Literal("CARET"),
475
- t.Literal("BACKQUOTE")
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: t.Union(
480
- [t.Literal("LF"), t.Literal("CRLF")],
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: t.Number({
486
+ pollInterval: e.Number({
484
487
  default: 5e3,
485
488
  minimum: 1e3,
486
489
  "x-nrg-form": { icon: "clock-o" }
487
490
  }),
488
- pollTimeout: t.Number({
491
+ pollTimeout: e.Number({
489
492
  default: 6e4,
490
493
  minimum: 5e3,
491
494
  "x-nrg-form": { icon: "hourglass" }
492
495
  }),
493
- emitJobCreated: t.Boolean({
496
+ emitJobCreated: e.Boolean({
494
497
  default: !1,
495
498
  "x-nrg-form": { icon: "flag", toggle: !0 }
496
499
  }),
497
- outputs: t.Number({ default: 2 })
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: t.Object({
502
- operation: t.Literal("upsert")
507
+ if: e.Object({
508
+ operation: e.Literal("upsert")
503
509
  }),
504
- then: t.Object({
505
- externalIdField: t.String({ minLength: 1 })
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
- ), ut = h(
519
+ ), ue = h(
514
520
  {
515
- payload: t.Any()
521
+ payload: e.Any()
516
522
  },
517
523
  { $id: "salesforce-bulk:input" }
518
524
  );
519
525
  h(
520
526
  {
521
- payload: t.Array(t.Any())
527
+ payload: e.Array(e.Any())
522
528
  },
523
529
  { $id: "salesforce-bulk:output" }
524
530
  );
525
- const T = class T extends F {
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 e = this.config.emitJobCreated ? 3 : 2, s = Array(e).fill(null);
528
- s[0] = { ...o, payload: n }, this.send(s);
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 e = this.config.emitJobCreated ? 3 : 2, s = Array(e).fill(null);
535
- s[1] = { ...o, payload: n }, this.send(s);
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 e = this.config.operation;
556
+ const t = this.config.operation;
545
557
  this.status({
546
558
  fill: "green",
547
559
  shape: "dot",
548
- text: `bulk ${e}...`
560
+ text: `bulk ${t}...`
549
561
  });
550
- const s = await n.getConnection(), a = await this.config.sObjectType.resolve(o);
562
+ const i = await n.getConnection(), r = await this.config.sObjectType.resolve(o);
551
563
  let l = 0;
552
- if (e === "query") {
553
- const d = await s.bulk2.query(o.payload, {
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 ${e}: ${l} records`
567
- }), this.sendComplete(o, { operation: e, sObjectType: a, totalRecords: l });
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 = s.bulk2.createJob({
570
- operation: e,
571
- object: a,
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
- ...e === "upsert" && this.config.externalIdField ? { externalIdFieldName: this.config.externalIdField } : {},
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: e,
580
- sObjectType: a,
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 ?? [], p = g.failedResults ?? [], w = g.unprocessedRecords ?? [];
584
- l = u.length + p.length + w.length;
585
- for (const A of u)
586
- this.sendRecord(o, A);
587
- for (const A of p)
588
- this.sendRecord(o, A);
589
- const q = u.length, M = p.length;
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: M > 0 ? "red" : "green",
603
+ fill: z > 0 ? "red" : "green",
592
604
  shape: "dot",
593
- text: `bulk ${e}: ${l} records`
605
+ text: `bulk ${t}: ${l} records`
594
606
  }), this.sendComplete(o, {
595
607
  jobId: c.id,
596
- operation: e,
597
- sObjectType: a,
608
+ operation: t,
609
+ sObjectType: r,
598
610
  totalRecords: l,
599
- successCount: q,
600
- failureCount: M,
601
- unprocessedCount: w.length
611
+ successCount: S,
612
+ failureCount: z,
613
+ unprocessedCount: p.length
602
614
  });
603
615
  }
604
- } catch (e) {
605
- const s = e instanceof Error ? e.message : String(e);
606
- this.status({ fill: "red", shape: "dot", text: s }), this.error(`Bulk ${this.config.operation} failed: ${s}`, o);
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(T, "SalesforceBulk"), i(T, "type", "salesforce-bulk"), i(T, "category", "salesforce"), i(T, "color", "#FFFFFF"), i(T, "inputs", 1), i(T, "outputs", 2), i(T, "configSchema", dt), i(T, "inputSchema", ut);
611
- let S = T;
612
- const ht = h(
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: t.String({ default: "", "x-nrg-form": { icon: "tag" } }),
615
- connection: t.NodeRef($, {
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: t.TypedInput({
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
- ), pt = h(
644
+ ), ge = h(
627
645
  {
628
- payload: t.Any()
646
+ payload: e.Any()
629
647
  },
630
648
  { $id: "salesforce-describe:input" }
631
- ), ft = h(
649
+ ), me = h(
632
650
  {
633
- payload: t.Object({
634
- name: t.String(),
635
- fields: t.Array(t.Any()),
636
- childRelationships: t.Array(t.Any()),
637
- recordTypeInfos: t.Array(t.Any())
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
- ), b = class b extends F {
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 e = await n.getConnection(), s = await this.config.sObjectType.resolve(o), a = await e.sobject(s).describe();
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: `${a.name}: ${a.fields.length} fields`
672
+ text: `${r.name}: ${r.fields.length} fields`
655
673
  }), this.send({
656
674
  ...o,
657
675
  payload: {
658
- name: a.name,
659
- fields: a.fields,
660
- childRelationships: a.childRelationships,
661
- recordTypeInfos: a.recordTypeInfos
676
+ name: r.name,
677
+ fields: r.fields,
678
+ childRelationships: r.childRelationships,
679
+ recordTypeInfos: r.recordTypeInfos
662
680
  }
663
681
  });
664
- } catch (e) {
682
+ } catch (t) {
665
683
  this.status({
666
684
  fill: "red",
667
685
  shape: "dot",
668
- text: e instanceof Error ? e.message : String(e)
686
+ text: t instanceof Error ? t.message : String(t)
669
687
  }), this.error(
670
- `Describe failed: ${e instanceof Error ? e.message : String(e)}`,
688
+ `Describe failed: ${t instanceof Error ? t.message : String(t)}`,
671
689
  o
672
690
  );
673
691
  }
674
692
  }
675
693
  };
676
- f(b, "SalesforceDescribe"), i(b, "type", "salesforce-describe"), i(b, "category", "salesforce"), i(b, "color", "#FFFFFF"), i(b, "inputs", 1), i(b, "outputs", 1), i(b, "configSchema", ht), i(b, "inputSchema", pt), i(b, "outputsSchema", ft);
677
- let E = b;
678
- const gt = h(
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: t.String({ default: "", "x-nrg-form": { icon: "tag" } }),
681
- connection: t.NodeRef($, {
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: t.String({
702
+ channelName: e.String({
685
703
  default: "",
686
704
  "x-nrg-form": { icon: "rss" }
687
705
  }),
688
- subscribeType: t.Union(
706
+ subscribeType: e.Union(
689
707
  [
690
- t.Literal("LATEST"),
691
- t.Literal("EARLIEST"),
692
- t.Literal("CUSTOM")
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: t.Optional(
697
- t.String({
714
+ replayId: e.Optional(
715
+ e.String({
698
716
  default: "",
699
717
  "x-nrg-form": { icon: "bookmark" }
700
718
  })
701
719
  ),
702
- numRequested: t.Number({
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: t.Object({
712
- subscribeType: t.Literal("CUSTOM")
731
+ if: e.Object({
732
+ subscribeType: e.Literal("CUSTOM")
713
733
  }),
714
- then: t.Object({
715
- replayId: t.String({ minLength: 1 })
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
- ), mt = h(
743
+ ), xe = h(
724
744
  {
725
- payload: t.Any(),
726
- replayId: t.Any(),
727
- channel: t.String(),
728
- topic: t.String()
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
- ), I = class I extends F {
751
+ ), w = class w extends A {
732
752
  constructor() {
733
753
  super(...arguments);
734
- i(this, "client", null);
735
- i(this, "reconnectAttempt", 0);
736
- i(this, "maxReconnectDelay", 6e4);
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
- try {
748
- this.status({ fill: "green", shape: "dot", text: "connecting..." });
749
- const e = n.getAccessToken(), s = n.getInstanceUrl();
750
- if (!e || !s) {
751
- this.status({ fill: "red", shape: "dot", text: "not authorized" }), this.error("Salesforce connection not authorized");
752
- return;
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
- const a = (await import("salesforce-pubsub-api-client")).default;
755
- this.client = new a({
756
- authType: "user-supplied",
757
- accessToken: e,
758
- instanceUrl: s
759
- }), await this.client.connect();
760
- const l = this.config.numRequested || null, d = this.config.channelName, c = /* @__PURE__ */ f((g, u, p) => {
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: e instanceof Error ? e.message : String(e)
799
- }), this.error(
800
- `Streaming subscription failed: ${e instanceof Error ? e.message : String(e)}`
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 ${e}ms (attempt ${this.reconnectAttempt})`
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(e / 1e3)}s`
876
+ text: `reconnecting in ${Math.round(t / 1e3)}s`
816
877
  }), this.setTimeout(async () => {
817
878
  await this.cleanup(), await this.subscribe(n);
818
- }, e);
879
+ }, t);
819
880
  }
820
881
  async cleanup() {
821
- var n, e;
882
+ var n, t;
822
883
  try {
823
- this.client && (await ((e = (n = this.client).close) == null ? void 0 : e.call(n)), this.client = null);
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(I, "SalesforceStreaming"), i(I, "type", "salesforce-streaming"), i(I, "category", "salesforce"), i(I, "color", "#FFFFFF"), i(I, "inputs", 0), i(I, "outputs", 1), i(I, "configSchema", gt), i(I, "outputsSchema", mt);
834
- let j = I;
835
- const yt = h(
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: t.String({ default: "", "x-nrg-form": { icon: "tag" } }),
838
- connection: t.NodeRef($, {
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: t.Union(
900
+ method: e.Union(
842
901
  [
843
- t.Literal("GET"),
844
- t.Literal("POST"),
845
- t.Literal("PUT"),
846
- t.Literal("PATCH"),
847
- t.Literal("DELETE")
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: t.TypedInput({
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
- ), bt = h(
921
+ ), Te = h(
860
922
  {
861
- payload: t.Any()
923
+ payload: e.Any()
862
924
  },
863
925
  { $id: "salesforce-apex:input" }
864
- ), xt = h(
926
+ ), Ie = h(
865
927
  {
866
- payload: t.Any()
928
+ payload: e.Any()
867
929
  },
868
930
  { $id: "salesforce-apex:output" }
869
- ), x = class x extends F {
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 e = this.config.method;
878
- this.status({ fill: "green", shape: "dot", text: `${e}...` });
879
- const s = await n.getConnection(), a = await this.config.path.resolve(o);
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 = e.toLowerCase();
882
- d === "get" || d === "delete" ? l = await s.apex[d](a) : l = await s.apex[d](a, o.payload), this.status({ fill: "green", shape: "dot", text: `${e} done` }), this.send({ ...o, payload: l });
883
- } catch (e) {
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: e instanceof Error ? e.message : String(e)
949
+ text: t instanceof Error ? t.message : String(t)
888
950
  }), this.error(
889
- `Apex ${this.config.method} failed: ${e instanceof Error ? e.message : String(e)}`,
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(x, "SalesforceApex"), i(x, "type", "salesforce-apex"), i(x, "category", "salesforce"), i(x, "color", "#FFFFFF"), i(x, "inputs", 1), i(x, "outputs", 1), i(x, "configSchema", yt), i(x, "inputSchema", bt), i(x, "outputsSchema", xt);
896
- let v = x;
897
- const Tt = K({
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
- O,
962
+ U,
901
963
  R,
902
- S,
903
- E,
964
+ O,
904
965
  j,
905
- v
966
+ v,
967
+ N
906
968
  ]
907
969
  });
908
- var U = Tt;
909
- U && typeof U == "object" && Array.isArray(U.nodes) && (U = Y(U.nodes));
970
+ var C = $e;
971
+ C && typeof C == "object" && Array.isArray(C.nodes) && (C = G(C.nodes));
910
972
  export {
911
- U as default
973
+ C as default
912
974
  };
913
975
  //# sourceMappingURL=index.mjs.map