snow-flow 10.0.1-dev.396 → 10.0.1-dev.397
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/package.json
CHANGED
|
@@ -473,10 +473,19 @@ async function ensureFlowFactoryAPI(
|
|
|
473
473
|
var existing = checkResp.data.result[0];
|
|
474
474
|
var ns = await probeFlowFactoryNamespace(client, existing.sys_id, instanceUrl);
|
|
475
475
|
if (!ns) {
|
|
476
|
-
|
|
476
|
+
// Namespace can't be resolved — the API is stale (e.g. created by an older version
|
|
477
|
+
// without the /discover endpoint, or ServiceNow REST framework hasn't registered it).
|
|
478
|
+
// Delete and redeploy with current v5 scripts.
|
|
479
|
+
try {
|
|
480
|
+
await client.delete('/api/now/table/sys_ws_definition/' + existing.sys_id);
|
|
481
|
+
} catch (_) {
|
|
482
|
+
// If delete fails, try to continue anyway — deployment step will error if API ID conflicts
|
|
483
|
+
}
|
|
484
|
+
// Fall through to step 4 (deploy fresh)
|
|
485
|
+
} else {
|
|
486
|
+
_flowFactoryCache = { apiSysId: existing.sys_id, namespace: ns, timestamp: Date.now() };
|
|
487
|
+
return { namespace: ns, apiSysId: existing.sys_id };
|
|
477
488
|
}
|
|
478
|
-
_flowFactoryCache = { apiSysId: existing.sys_id, namespace: ns, timestamp: Date.now() };
|
|
479
|
-
return { namespace: ns, apiSysId: existing.sys_id };
|
|
480
489
|
}
|
|
481
490
|
|
|
482
491
|
// 4. Deploy the Scripted REST API (do NOT set namespace — let ServiceNow assign it)
|
|
@@ -531,10 +540,18 @@ async function ensureFlowFactoryAPI(
|
|
|
531
540
|
// Non-fatal: create endpoint is more important than discover
|
|
532
541
|
}
|
|
533
542
|
|
|
534
|
-
// 6.
|
|
543
|
+
// 6. Wait for ServiceNow REST framework to register the new endpoints
|
|
544
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
545
|
+
|
|
546
|
+
// 7. Probe to discover the namespace ServiceNow assigned
|
|
535
547
|
var resolvedNs = await probeFlowFactoryNamespace(client, apiSysId, instanceUrl);
|
|
536
548
|
if (!resolvedNs) {
|
|
537
|
-
|
|
549
|
+
// Retry once after extra delay — some instances are slow to register
|
|
550
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
551
|
+
resolvedNs = await probeFlowFactoryNamespace(client, apiSysId, instanceUrl);
|
|
552
|
+
}
|
|
553
|
+
if (!resolvedNs) {
|
|
554
|
+
throw new Error('Flow Factory API created (sys_id=' + apiSysId + ') but namespace could not be resolved via HTTP probing after 6s delay');
|
|
538
555
|
}
|
|
539
556
|
|
|
540
557
|
_flowFactoryCache = { apiSysId: apiSysId, namespace: resolvedNs, timestamp: Date.now() };
|