identityscope 0.0.0-stage → 0.28.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +916 -2
- package/SECURITY.md +56 -0
- package/dist/core/audit-readiness.d.ts +158 -0
- package/dist/core/audit-readiness.js +357 -0
- package/dist/core/audit-readiness.js.map +1 -0
- package/dist/core/certs.d.ts +68 -0
- package/dist/core/certs.js +132 -0
- package/dist/core/certs.js.map +1 -0
- package/dist/core/checks.d.ts +133 -0
- package/dist/core/checks.js +512 -0
- package/dist/core/checks.js.map +1 -0
- package/dist/core/cloud-rules.d.ts +20 -0
- package/dist/core/cloud-rules.js +44 -0
- package/dist/core/cloud-rules.js.map +1 -0
- package/dist/core/compare.d.ts +45 -0
- package/dist/core/compare.js +372 -0
- package/dist/core/compare.js.map +1 -0
- package/dist/core/conditions.d.ts +10 -0
- package/dist/core/conditions.js +201 -0
- package/dist/core/conditions.js.map +1 -0
- package/dist/core/credentials.d.ts +71 -0
- package/dist/core/credentials.js +211 -0
- package/dist/core/credentials.js.map +1 -0
- package/dist/core/datasets.d.ts +53 -0
- package/dist/core/datasets.js +596 -0
- package/dist/core/datasets.js.map +1 -0
- package/dist/core/definition.d.ts +32 -0
- package/dist/core/definition.js +301 -0
- package/dist/core/definition.js.map +1 -0
- package/dist/core/discover.d.ts +32 -0
- package/dist/core/discover.js +105 -0
- package/dist/core/discover.js.map +1 -0
- package/dist/core/engine.d.ts +18 -0
- package/dist/core/engine.js +290 -0
- package/dist/core/engine.js.map +1 -0
- package/dist/core/fields.d.ts +16 -0
- package/dist/core/fields.js +132 -0
- package/dist/core/fields.js.map +1 -0
- package/dist/core/governance-trail.d.ts +211 -0
- package/dist/core/governance-trail.js +557 -0
- package/dist/core/governance-trail.js.map +1 -0
- package/dist/core/http-transport.d.ts +66 -0
- package/dist/core/http-transport.js +247 -0
- package/dist/core/http-transport.js.map +1 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.js +16 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/insights.d.ts +176 -0
- package/dist/core/insights.js +417 -0
- package/dist/core/insights.js.map +1 -0
- package/dist/core/joiner-evidence.d.ts +98 -0
- package/dist/core/joiner-evidence.js +254 -0
- package/dist/core/joiner-evidence.js.map +1 -0
- package/dist/core/lab/credential-map.d.ts +50 -0
- package/dist/core/lab/credential-map.js +163 -0
- package/dist/core/lab/credential-map.js.map +1 -0
- package/dist/core/lab/javadate.d.ts +7 -0
- package/dist/core/lab/javadate.js +307 -0
- package/dist/core/lab/javadate.js.map +1 -0
- package/dist/core/lab/jsonpath.d.ts +11 -0
- package/dist/core/lab/jsonpath.js +273 -0
- package/dist/core/lab/jsonpath.js.map +1 -0
- package/dist/core/lab/policy-preview.d.ts +43 -0
- package/dist/core/lab/policy-preview.js +78 -0
- package/dist/core/lab/policy-preview.js.map +1 -0
- package/dist/core/lab/rfc5646.d.ts +2 -0
- package/dist/core/lab/rfc5646.js +421 -0
- package/dist/core/lab/rfc5646.js.map +1 -0
- package/dist/core/lab/transform-impact.d.ts +63 -0
- package/dist/core/lab/transform-impact.js +138 -0
- package/dist/core/lab/transform-impact.js.map +1 -0
- package/dist/core/lab/transform-people.d.ts +61 -0
- package/dist/core/lab/transform-people.js +132 -0
- package/dist/core/lab/transform-people.js.map +1 -0
- package/dist/core/lab/transforms.d.ts +79 -0
- package/dist/core/lab/transforms.js +738 -0
- package/dist/core/lab/transforms.js.map +1 -0
- package/dist/core/lab/velocity.d.ts +33 -0
- package/dist/core/lab/velocity.js +874 -0
- package/dist/core/lab/velocity.js.map +1 -0
- package/dist/core/lab/workflow-health.d.ts +80 -0
- package/dist/core/lab/workflow-health.js +234 -0
- package/dist/core/lab/workflow-health.js.map +1 -0
- package/dist/core/lab/workflows.d.ts +87 -0
- package/dist/core/lab/workflows.js +568 -0
- package/dist/core/lab/workflows.js.map +1 -0
- package/dist/core/lifecycle-gaps.d.ts +192 -0
- package/dist/core/lifecycle-gaps.js +389 -0
- package/dist/core/lifecycle-gaps.js.map +1 -0
- package/dist/core/logs.d.ts +145 -0
- package/dist/core/logs.js +342 -0
- package/dist/core/logs.js.map +1 -0
- package/dist/core/lookup.d.ts +129 -0
- package/dist/core/lookup.js +289 -0
- package/dist/core/lookup.js.map +1 -0
- package/dist/core/model-insights.d.ts +247 -0
- package/dist/core/model-insights.js +474 -0
- package/dist/core/model-insights.js.map +1 -0
- package/dist/core/narrow.d.ts +23 -0
- package/dist/core/narrow.js +137 -0
- package/dist/core/narrow.js.map +1 -0
- package/dist/core/nerm.d.ts +154 -0
- package/dist/core/nerm.js +397 -0
- package/dist/core/nerm.js.map +1 -0
- package/dist/core/operations-watch.d.ts +232 -0
- package/dist/core/operations-watch.js +491 -0
- package/dist/core/operations-watch.js.map +1 -0
- package/dist/core/output/csv.d.ts +6 -0
- package/dist/core/output/csv.js +22 -0
- package/dist/core/output/csv.js.map +1 -0
- package/dist/core/output/html.d.ts +11 -0
- package/dist/core/output/html.js +66 -0
- package/dist/core/output/html.js.map +1 -0
- package/dist/core/output/xlsx.d.ts +3 -0
- package/dist/core/output/xlsx.js +130 -0
- package/dist/core/output/xlsx.js.map +1 -0
- package/dist/core/output/zip.d.ts +16 -0
- package/dist/core/output/zip.js +106 -0
- package/dist/core/output/zip.js.map +1 -0
- package/dist/core/ownership.d.ts +39 -0
- package/dist/core/ownership.js +100 -0
- package/dist/core/ownership.js.map +1 -0
- package/dist/core/patterns.d.ts +11 -0
- package/dist/core/patterns.js +31 -0
- package/dist/core/patterns.js.map +1 -0
- package/dist/core/preview.d.ts +96 -0
- package/dist/core/preview.js +173 -0
- package/dist/core/preview.js.map +1 -0
- package/dist/core/roles.d.ts +125 -0
- package/dist/core/roles.js +420 -0
- package/dist/core/roles.js.map +1 -0
- package/dist/core/tenant.d.ts +67 -0
- package/dist/core/tenant.js +194 -0
- package/dist/core/tenant.js.map +1 -0
- package/dist/core/threat-signals.d.ts +112 -0
- package/dist/core/threat-signals.js +250 -0
- package/dist/core/threat-signals.js.map +1 -0
- package/dist/core/threat-watch.d.ts +144 -0
- package/dist/core/threat-watch.js +282 -0
- package/dist/core/threat-watch.js.map +1 -0
- package/dist/core/transport.d.ts +82 -0
- package/dist/core/transport.js +312 -0
- package/dist/core/transport.js.map +1 -0
- package/dist/core/types.d.ts +137 -0
- package/dist/core/types.js +10 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/warnings.d.ts +236 -0
- package/dist/core/warnings.js +504 -0
- package/dist/core/warnings.js.map +1 -0
- package/dist/demo/tenant.d.ts +1572 -0
- package/dist/demo/tenant.js +1023 -0
- package/dist/demo/tenant.js.map +1 -0
- package/dist/node/attribute-history.d.ts +22 -0
- package/dist/node/attribute-history.js +86 -0
- package/dist/node/attribute-history.js.map +1 -0
- package/dist/node/changes.d.ts +20 -0
- package/dist/node/changes.js +78 -0
- package/dist/node/changes.js.map +1 -0
- package/dist/node/cli.d.ts +2 -0
- package/dist/node/cli.js +291 -0
- package/dist/node/cli.js.map +1 -0
- package/dist/node/config.d.ts +72 -0
- package/dist/node/config.js +203 -0
- package/dist/node/config.js.map +1 -0
- package/dist/node/credentials.d.ts +13 -0
- package/dist/node/credentials.js +24 -0
- package/dist/node/credentials.js.map +1 -0
- package/dist/node/delivery.d.ts +10 -0
- package/dist/node/delivery.js +105 -0
- package/dist/node/delivery.js.map +1 -0
- package/dist/node/doctor.d.ts +2 -0
- package/dist/node/doctor.js +151 -0
- package/dist/node/doctor.js.map +1 -0
- package/dist/node/drift.d.ts +31 -0
- package/dist/node/drift.js +56 -0
- package/dist/node/drift.js.map +1 -0
- package/dist/node/evidence.d.ts +42 -0
- package/dist/node/evidence.js +129 -0
- package/dist/node/evidence.js.map +1 -0
- package/dist/node/exceptions.d.ts +30 -0
- package/dist/node/exceptions.js +83 -0
- package/dist/node/exceptions.js.map +1 -0
- package/dist/node/history.d.ts +35 -0
- package/dist/node/history.js +74 -0
- package/dist/node/history.js.map +1 -0
- package/dist/node/index.d.ts +7 -0
- package/dist/node/index.js +8 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/keep.d.ts +9 -0
- package/dist/node/keep.js +39 -0
- package/dist/node/keep.js.map +1 -0
- package/dist/node/loader.d.ts +7 -0
- package/dist/node/loader.js +35 -0
- package/dist/node/loader.js.map +1 -0
- package/dist/node/log-files.d.ts +16 -0
- package/dist/node/log-files.js +93 -0
- package/dist/node/log-files.js.map +1 -0
- package/dist/node/monthly.d.ts +41 -0
- package/dist/node/monthly.js +108 -0
- package/dist/node/monthly.js.map +1 -0
- package/dist/node/oauth-login.d.ts +45 -0
- package/dist/node/oauth-login.js +121 -0
- package/dist/node/oauth-login.js.map +1 -0
- package/dist/node/packs.d.ts +32 -0
- package/dist/node/packs.js +43 -0
- package/dist/node/packs.js.map +1 -0
- package/dist/node/privileged-seen.d.ts +11 -0
- package/dist/node/privileged-seen.js +41 -0
- package/dist/node/privileged-seen.js.map +1 -0
- package/dist/node/recipients.d.ts +17 -0
- package/dist/node/recipients.js +51 -0
- package/dist/node/recipients.js.map +1 -0
- package/dist/node/runner.d.ts +51 -0
- package/dist/node/runner.js +298 -0
- package/dist/node/runner.js.map +1 -0
- package/dist/node/runtime.d.ts +12 -0
- package/dist/node/runtime.js +13 -0
- package/dist/node/runtime.js.map +1 -0
- package/dist/node/schedules.d.ts +87 -0
- package/dist/node/schedules.js +141 -0
- package/dist/node/schedules.js.map +1 -0
- package/dist/node/secrets.d.ts +37 -0
- package/dist/node/secrets.js +219 -0
- package/dist/node/secrets.js.map +1 -0
- package/dist/node/support.d.ts +14 -0
- package/dist/node/support.js +133 -0
- package/dist/node/support.js.map +1 -0
- package/dist/node/tenants.d.ts +93 -0
- package/dist/node/tenants.js +255 -0
- package/dist/node/tenants.js.map +1 -0
- package/dist/node/ui-page.d.ts +1 -0
- package/dist/node/ui-page.js +3 -0
- package/dist/node/ui-page.js.map +1 -0
- package/dist/node/ui-server.d.ts +48 -0
- package/dist/node/ui-server.js +2665 -0
- package/dist/node/ui-server.js.map +1 -0
- package/dist/node/write.d.ts +9 -0
- package/dist/node/write.js +53 -0
- package/dist/node/write.js.map +1 -0
- package/dist/reports/builtin.generated.d.ts +1 -0
- package/dist/reports/builtin.generated.js +49 -0
- package/dist/reports/builtin.generated.js.map +1 -0
- package/dist/reports/library.d.ts +6 -0
- package/dist/reports/library.js +18 -0
- package/dist/reports/library.js.map +1 -0
- package/launcher/IdentityScope.cmd +11 -0
- package/package.json +69 -4
- package/reports/access-profile-members.yaml +29 -0
- package/reports/access-profile-membership-counts.yaml +17 -0
- package/reports/access-profiles-without-owner.yaml +16 -0
- package/reports/access-request-audit-trail.yaml +36 -0
- package/reports/accounts-by-source.yaml +19 -0
- package/reports/active-identities-without-manager.yaml +22 -0
- package/reports/aggregation-failures.yaml +29 -0
- package/reports/aggregation-history.yaml +27 -0
- package/reports/all-sources.yaml +16 -0
- package/reports/application-accounts.yaml +32 -0
- package/reports/application-entitlements.yaml +31 -0
- package/reports/campaign-progress.yaml +23 -0
- package/reports/certification-decisions.yaml +31 -0
- package/reports/direct-reports-per-manager.yaml +20 -0
- package/reports/disabled-accounts-of-active-people.yaml +33 -0
- package/reports/duplicate-emails.yaml +16 -0
- package/reports/entitlement-holders.yaml +35 -0
- package/reports/entitlements-held-by-inactive-identities.yaml +31 -0
- package/reports/entitlements-without-owner.yaml +28 -0
- package/reports/identities-by-lifecycle-state.yaml +15 -0
- package/reports/identities-missing-key-attributes.yaml +27 -0
- package/reports/identities-with-processing-errors.yaml +19 -0
- package/reports/identity-attribute-mappings.yaml +27 -0
- package/reports/machine-accounts.yaml +28 -0
- package/reports/managers-and-direct-reports.yaml +23 -0
- package/reports/most-access.yaml +18 -0
- package/reports/new-identities.yaml +24 -0
- package/reports/old-passwords.yaml +35 -0
- package/reports/pending-reviews-by-reviewer.yaml +20 -0
- package/reports/person-access.yaml +31 -0
- package/reports/privileged-access.yaml +29 -0
- package/reports/provisioning-error-causes.yaml +27 -0
- package/reports/provisioning-errors.yaml +32 -0
- package/reports/provisioning-failures.yaml +28 -0
- package/reports/recent-access-requests.yaml +22 -0
- package/reports/recent-activity.yaml +32 -0
- package/reports/recent-leavers.yaml +34 -0
- package/reports/role-members.yaml +29 -0
- package/reports/role-membership-counts.yaml +18 -0
- package/reports/roles-without-owner.yaml +17 -0
- package/reports/sources-needing-attention.yaml +23 -0
- package/reports/stuck-access-requests.yaml +29 -0
- package/reports/team-access.yaml +30 -0
- package/reports/terminated-users-with-active-accounts.yaml +46 -0
- package/reports/uncorrelated-accounts.yaml +38 -0
- package/ui/js/00-setup.js +6 -0
- package/ui/js/01-small-helpers.js +143 -0
- package/ui/js/02-connection.js +150 -0
- package/ui/js/03-health-check.js +17 -0
- package/ui/js/04-library.js +135 -0
- package/ui/js/05-pickers.js +163 -0
- package/ui/js/06-report-view.js +157 -0
- package/ui/js/07-fields.js +85 -0
- package/ui/js/08-designer.js +360 -0
- package/ui/js/09-yaml.js +22 -0
- package/ui/js/10-instant-check.js +171 -0
- package/ui/js/11-lookup.js +161 -0
- package/ui/js/12-tenant.js +115 -0
- package/ui/js/13-source-configuration-and-diagnostics.js +64 -0
- package/ui/js/14-certifications.js +68 -0
- package/ui/js/15-monthly-report.js +24 -0
- package/ui/js/16-ownership.js +39 -0
- package/ui/js/17-compare-tenants.js +102 -0
- package/ui/js/18-audit.js +181 -0
- package/ui/js/19-insights.js +108 -0
- package/ui/js/20-role-mining.js +35 -0
- package/ui/js/21-share-reports.js +45 -0
- package/ui/js/22-partner-overview-all-customer-tenants.js +228 -0
- package/ui/js/23-in-app-guidance.js +217 -0
- package/ui/js/24-role-tools.js +220 -0
- package/ui/js/25-schedules.js +264 -0
- package/ui/js/26-start.js +7 -0
- package/ui/js/27-warnings.js +224 -0
- package/ui/js/28-audit-readiness.js +99 -0
- package/ui/js/29-lifecycle.js +182 -0
- package/ui/js/30-labs.js +265 -0
- package/ui/js/31-build.js +203 -0
- package/ui/js/32-lab-examples.js +148 -0
- package/ui/js/33-finder.js +89 -0
- package/ui/js/34-governance.js +129 -0
- package/ui/js/35-watch.js +266 -0
- package/ui/js/36-model.js +247 -0
- package/ui/js/37-logs-and-watch.js +224 -0
- package/ui/shell.html +112 -0
- package/ui/style.css +350 -0
|
@@ -0,0 +1,738 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Offline transform engine: evaluates SailPoint ISC transform JSON locally,
|
|
3
|
+
* following SailPoint's transform documentation, with a step-by-step trace.
|
|
4
|
+
* Nothing is sent to ISC. Types that only ISC can evaluate (cloud rules,
|
|
5
|
+
* uniqueness checks against a target system) end with an "only in ISC"
|
|
6
|
+
* result instead of a guess.
|
|
7
|
+
*/
|
|
8
|
+
import { formatNamed, parseNamed } from './javadate.js';
|
|
9
|
+
import { RFC5646 } from './rfc5646.js';
|
|
10
|
+
import { Evaluator, javaRegex, javaReplacement, javaSplit, tools, UnsupportedError } from './velocity.js';
|
|
11
|
+
export class TransformError extends Error {
|
|
12
|
+
constructor(msg) {
|
|
13
|
+
super(msg);
|
|
14
|
+
this.name = 'TransformError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
class IscOnly extends Error {
|
|
18
|
+
constructor(msg) {
|
|
19
|
+
super(msg);
|
|
20
|
+
this.name = 'IscOnly';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const isDef = (v) => !!v && typeof v === 'object' && !Array.isArray(v) && typeof v.type === 'string';
|
|
24
|
+
const RESERVED = new Set(['input', 'value', 'expression', 'positiveCondition', 'negativeCondition', 'values', 'table', 'regex', 'replacement', 'begin', 'beginOffset', 'end', 'endOffset', 'delimiter', 'index', 'throws', 'substring', 'length', 'padding', 'inputFormat', 'outputFormat', 'roundUp', 'firstDate', 'secondDate', 'operator', 'name', 'operation', 'numChars', 'uid', 'attributeName', 'sourceName', 'applicationId', 'applicationName', 'accountSortAttribute', 'accountSortDescending', 'accountReturnFirstLink', 'accountFilter', 'accountPropertyFilter', 'defaultRegion', 'format', 'separator', 'ignoreErrors', 'id', 'patterns', 'sourceCheck', 'includeNumbers', 'includeSpecialChars', 'requiresPeriodicRefresh', 'sourceId', 'type']);
|
|
25
|
+
function asString(v) {
|
|
26
|
+
if (v === null)
|
|
27
|
+
return null;
|
|
28
|
+
if (Array.isArray(v))
|
|
29
|
+
return v.length ? asString(v[0]) : null;
|
|
30
|
+
return String(v);
|
|
31
|
+
}
|
|
32
|
+
function toValue(v) {
|
|
33
|
+
if (v === undefined || v === null)
|
|
34
|
+
return null;
|
|
35
|
+
if (Array.isArray(v))
|
|
36
|
+
return v.map(toValue);
|
|
37
|
+
if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean')
|
|
38
|
+
return v;
|
|
39
|
+
if (v instanceof Date)
|
|
40
|
+
return v.toISOString();
|
|
41
|
+
return JSON.stringify(v);
|
|
42
|
+
}
|
|
43
|
+
export class TransformEngine {
|
|
44
|
+
transforms;
|
|
45
|
+
now;
|
|
46
|
+
trace = [];
|
|
47
|
+
assumptions = new Set();
|
|
48
|
+
random = false;
|
|
49
|
+
depth = 0;
|
|
50
|
+
constructor(transforms, now = new Date()) {
|
|
51
|
+
this.transforms = transforms;
|
|
52
|
+
this.now = now;
|
|
53
|
+
}
|
|
54
|
+
static fromList(list, now) {
|
|
55
|
+
const m = new Map();
|
|
56
|
+
for (const t of list) {
|
|
57
|
+
if (t.name)
|
|
58
|
+
m.set(t.name, t);
|
|
59
|
+
if (t.id)
|
|
60
|
+
m.set(t.id, t);
|
|
61
|
+
}
|
|
62
|
+
return new TransformEngine(m, now);
|
|
63
|
+
}
|
|
64
|
+
run(def, input = {}) {
|
|
65
|
+
this.trace = [];
|
|
66
|
+
this.assumptions = new Set();
|
|
67
|
+
this.random = false;
|
|
68
|
+
this.depth = 0;
|
|
69
|
+
try {
|
|
70
|
+
const value = this.evalAny(def, input, input.implicit === undefined ? null : toValue(input.implicit));
|
|
71
|
+
return { value, status: this.random ? 'random' : 'ok', trace: this.trace, assumptions: [...this.assumptions] };
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
const msg = e.message;
|
|
75
|
+
if (e instanceof IscOnly || e instanceof UnsupportedError)
|
|
76
|
+
return { value: null, status: 'isc-only', error: msg, trace: this.trace, assumptions: [...this.assumptions] };
|
|
77
|
+
return { value: null, status: 'error', error: msg, trace: this.trace, assumptions: [...this.assumptions] };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// ------------------------------------------------------------ plumbing
|
|
81
|
+
evalAny(v, ctx, implicit, vars = {}) {
|
|
82
|
+
if (isDef(v))
|
|
83
|
+
return this.evalDef(v, ctx, implicit);
|
|
84
|
+
if (typeof v === 'string')
|
|
85
|
+
return this.render(v, ctx, vars);
|
|
86
|
+
return toValue(v);
|
|
87
|
+
}
|
|
88
|
+
velocityCtx(ctx, vars) {
|
|
89
|
+
const identityObj = ctx.identity ? { __attributes: ctx.identity, name: ctx.identity['uid'] ?? ctx.identity['name'], ...ctx.identity, getAttribute: (n) => ctx.identity?.[n] ?? null, getName: () => ctx.identity?.['uid'] ?? ctx.identity?.['name'] ?? null } : null;
|
|
90
|
+
return { ...tools(this.now), ...(identityObj ? { identity: identityObj } : {}), oldValue: ctx.oldValue ?? null, ...vars };
|
|
91
|
+
}
|
|
92
|
+
render(s, ctx, vars) {
|
|
93
|
+
return new Evaluator(this.velocityCtx(ctx, vars)).render(s);
|
|
94
|
+
}
|
|
95
|
+
/** The transform's input: explicit attributes.input if set, else the implicit input. */
|
|
96
|
+
inputOf(a, ctx, implicit) {
|
|
97
|
+
// An absent or empty "input" means the implicit input (SailPoint's own examples use "input": "").
|
|
98
|
+
if (a['input'] === undefined || a['input'] === null || a['input'] === '')
|
|
99
|
+
return implicit;
|
|
100
|
+
return this.evalAny(a['input'], ctx, implicit);
|
|
101
|
+
}
|
|
102
|
+
/** Dynamic variables: attributes that are not reserved names, evaluated first. */
|
|
103
|
+
variables(a, ctx, implicit, extraReserved = []) {
|
|
104
|
+
const vars = {};
|
|
105
|
+
for (const [k, v] of Object.entries(a)) {
|
|
106
|
+
if (RESERVED.has(k) || extraReserved.includes(k))
|
|
107
|
+
continue;
|
|
108
|
+
const val = this.evalAny(v, ctx, implicit);
|
|
109
|
+
vars[k] = val;
|
|
110
|
+
}
|
|
111
|
+
return vars;
|
|
112
|
+
}
|
|
113
|
+
evalDef(def, ctx, implicit) {
|
|
114
|
+
const type = def.type;
|
|
115
|
+
const a = (def.attributes ?? {});
|
|
116
|
+
const step = { depth: this.depth, type, name: def.name };
|
|
117
|
+
this.trace.push(step);
|
|
118
|
+
this.depth++;
|
|
119
|
+
try {
|
|
120
|
+
const out = this.apply(type, a, ctx, implicit, step);
|
|
121
|
+
step.output = out;
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
step.error = e.message;
|
|
126
|
+
throw e;
|
|
127
|
+
}
|
|
128
|
+
finally {
|
|
129
|
+
this.depth--;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// ------------------------------------------------------------ types
|
|
133
|
+
apply(type, a, ctx, implicit, step) {
|
|
134
|
+
const input = () => {
|
|
135
|
+
const v = this.inputOf(a, ctx, implicit);
|
|
136
|
+
step.input = v;
|
|
137
|
+
return v;
|
|
138
|
+
};
|
|
139
|
+
const str = (k, vars = {}) => (typeof a[k] === 'string' ? this.render(a[k], ctx, vars) : a[k] === undefined || a[k] === null ? undefined : String(a[k]));
|
|
140
|
+
const int = (k) => {
|
|
141
|
+
const v = str(k);
|
|
142
|
+
if (v === undefined)
|
|
143
|
+
return undefined;
|
|
144
|
+
const n = Number(v);
|
|
145
|
+
if (!Number.isInteger(n))
|
|
146
|
+
throw new TransformError(`NumberFormatException: "${v}" is not a whole number (${k})`);
|
|
147
|
+
return n;
|
|
148
|
+
};
|
|
149
|
+
switch (type) {
|
|
150
|
+
case 'static': {
|
|
151
|
+
const vars = this.variables(a, ctx, implicit);
|
|
152
|
+
if (typeof a['value'] !== 'string')
|
|
153
|
+
throw new TransformError('static: "value" is required');
|
|
154
|
+
return this.render(a['value'], ctx, vars);
|
|
155
|
+
}
|
|
156
|
+
case 'concat': {
|
|
157
|
+
const vals = Array.isArray(a['values']) ? a['values'] : null;
|
|
158
|
+
if (!vals)
|
|
159
|
+
throw new TransformError('concat: "values" must be a list');
|
|
160
|
+
let out = '';
|
|
161
|
+
for (const v of vals) {
|
|
162
|
+
const r = this.evalAny(v, ctx, implicit);
|
|
163
|
+
if (r === null)
|
|
164
|
+
this.assumptions.add('concat: a null value is left out (treated as empty)');
|
|
165
|
+
out += r === null ? '' : asString(r) ?? '';
|
|
166
|
+
}
|
|
167
|
+
return out;
|
|
168
|
+
}
|
|
169
|
+
case 'join': {
|
|
170
|
+
const vals = Array.isArray(a['values']) ? a['values'] : null;
|
|
171
|
+
if (!vals)
|
|
172
|
+
throw new TransformError('join: "values" must be a list');
|
|
173
|
+
const sep = str('separator') ?? ',';
|
|
174
|
+
const parts = vals.map((v) => this.evalAny(v, ctx, implicit)).filter((v) => {
|
|
175
|
+
if (v === null)
|
|
176
|
+
this.assumptions.add('join: null values are left out');
|
|
177
|
+
return v !== null;
|
|
178
|
+
});
|
|
179
|
+
return parts.map((p) => asString(p)).join(sep);
|
|
180
|
+
}
|
|
181
|
+
case 'conditional': {
|
|
182
|
+
const vars = this.variables(a, ctx, implicit);
|
|
183
|
+
const exprRaw = a['expression'];
|
|
184
|
+
if (typeof exprRaw !== 'string')
|
|
185
|
+
throw new TransformError('IllegalArgumentException: conditional needs an "expression"');
|
|
186
|
+
const expr = this.render(exprRaw, ctx, vars);
|
|
187
|
+
const parts = expr.split(/\s+eq\s+/);
|
|
188
|
+
if (parts.length !== 2)
|
|
189
|
+
throw new TransformError(`IllegalArgumentException: the expression must be "ValueA eq ValueB", got "${expr}"`);
|
|
190
|
+
const [x, y] = parts.map((p) => p.trim());
|
|
191
|
+
step.note = `"${x}" eq "${y}"`;
|
|
192
|
+
const pos = str('positiveCondition', vars);
|
|
193
|
+
const neg = str('negativeCondition', vars);
|
|
194
|
+
if (pos === undefined || neg === undefined)
|
|
195
|
+
throw new TransformError('IllegalArgumentException: positiveCondition and negativeCondition are required');
|
|
196
|
+
return x === y ? pos : neg;
|
|
197
|
+
}
|
|
198
|
+
case 'firstValid': {
|
|
199
|
+
const vals = Array.isArray(a['values']) ? a['values'] : null;
|
|
200
|
+
if (!vals)
|
|
201
|
+
throw new TransformError('firstValid: "values" must be a list');
|
|
202
|
+
const ignore = a['ignoreErrors'] === true || a['ignoreErrors'] === 'true';
|
|
203
|
+
for (const [i, v] of vals.entries()) {
|
|
204
|
+
try {
|
|
205
|
+
const r = this.evalAny(v, ctx, implicit);
|
|
206
|
+
if (r !== null) {
|
|
207
|
+
step.note = `value ${i + 1} of ${vals.length} is the first that is not null`;
|
|
208
|
+
return r;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
catch (e) {
|
|
212
|
+
if (!ignore || e instanceof IscOnly || e instanceof UnsupportedError)
|
|
213
|
+
throw e;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
step.note = 'every value was null';
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
case 'lower':
|
|
220
|
+
case 'upper':
|
|
221
|
+
case 'trim':
|
|
222
|
+
case 'base64Encode':
|
|
223
|
+
case 'base64Decode':
|
|
224
|
+
case 'decomposeDiacriticalMarks':
|
|
225
|
+
case 'normalizeNames': {
|
|
226
|
+
const v = asString(input());
|
|
227
|
+
if (v === null)
|
|
228
|
+
return null;
|
|
229
|
+
if (type === 'lower')
|
|
230
|
+
return v.toLowerCase();
|
|
231
|
+
if (type === 'upper')
|
|
232
|
+
return v.toUpperCase();
|
|
233
|
+
if (type === 'trim')
|
|
234
|
+
return v.replace(/^[\u0000- ]+|[\u0000- ]+$/g, '');
|
|
235
|
+
if (type === 'base64Encode')
|
|
236
|
+
return Buffer.from(v, 'utf8').toString('base64');
|
|
237
|
+
if (type === 'base64Decode')
|
|
238
|
+
return Buffer.from(v, 'base64').toString('utf8');
|
|
239
|
+
if (type === 'decomposeDiacriticalMarks')
|
|
240
|
+
return v.normalize('NFKD').replace(/[̀-ͯ]/g, '');
|
|
241
|
+
return normalizeName(v);
|
|
242
|
+
}
|
|
243
|
+
case 'lookup': {
|
|
244
|
+
const table = a['table'];
|
|
245
|
+
if (!table || typeof table !== 'object')
|
|
246
|
+
throw new TransformError('lookup: "table" is required');
|
|
247
|
+
const v = asString(input());
|
|
248
|
+
if (v !== null && Object.prototype.hasOwnProperty.call(table, v)) {
|
|
249
|
+
step.note = `matched "${v}"`;
|
|
250
|
+
return this.evalAny(table[v], ctx, implicit);
|
|
251
|
+
}
|
|
252
|
+
if (Object.prototype.hasOwnProperty.call(table, 'default')) {
|
|
253
|
+
step.note = `no key "${v}": default`;
|
|
254
|
+
return this.evalAny(table['default'], ctx, implicit);
|
|
255
|
+
}
|
|
256
|
+
throw new TransformError(`lookup: no key matches "${v}" and there is no default`);
|
|
257
|
+
}
|
|
258
|
+
case 'replace': {
|
|
259
|
+
const v = asString(input());
|
|
260
|
+
if (v === null)
|
|
261
|
+
return null;
|
|
262
|
+
const re = str('regex');
|
|
263
|
+
if (re === undefined)
|
|
264
|
+
throw new TransformError('replace: "regex" is required');
|
|
265
|
+
return v.replace(javaRegex(re), javaReplacement(str('replacement') ?? ''));
|
|
266
|
+
}
|
|
267
|
+
case 'replaceAll': {
|
|
268
|
+
let v = asString(input());
|
|
269
|
+
if (v === null)
|
|
270
|
+
return null;
|
|
271
|
+
const table = (a['table'] ?? {});
|
|
272
|
+
for (const [k, r] of Object.entries(table))
|
|
273
|
+
v = v.replace(javaRegex(k), javaReplacement(String(r ?? '')));
|
|
274
|
+
return v;
|
|
275
|
+
}
|
|
276
|
+
case 'substring': {
|
|
277
|
+
const v = asString(input());
|
|
278
|
+
if (v === null)
|
|
279
|
+
return null;
|
|
280
|
+
const b0 = int('begin');
|
|
281
|
+
if (b0 === undefined)
|
|
282
|
+
throw new TransformError('substring: "begin" is required');
|
|
283
|
+
const b = b0 === -1 ? 0 : b0 + (int('beginOffset') ?? 0);
|
|
284
|
+
const e0 = int('end');
|
|
285
|
+
const e = e0 === undefined || e0 === -1 ? v.length : e0 + (int('endOffset') ?? 0);
|
|
286
|
+
if (b < 0 || e > v.length || b > e)
|
|
287
|
+
throw new TransformError(`StringIndexOutOfBoundsException: begin ${b}, end ${e}, length ${v.length}`);
|
|
288
|
+
return v.substring(b, e);
|
|
289
|
+
}
|
|
290
|
+
case 'split': {
|
|
291
|
+
const v = asString(input());
|
|
292
|
+
if (v === null)
|
|
293
|
+
return null;
|
|
294
|
+
const d = str('delimiter');
|
|
295
|
+
const i = int('index');
|
|
296
|
+
if (d === undefined || i === undefined)
|
|
297
|
+
throw new TransformError('split: "delimiter" and "index" are required');
|
|
298
|
+
const parts = javaSplit(v, d);
|
|
299
|
+
step.note = `${parts.length} part${parts.length === 1 ? '' : 's'}`;
|
|
300
|
+
if (i < 0 || i >= parts.length) {
|
|
301
|
+
const throws = !(a['throws'] === false || a['throws'] === 'false');
|
|
302
|
+
if (throws)
|
|
303
|
+
throw new TransformError(`IndexOutOfBoundsException: index ${i}, ${parts.length} parts`);
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
return parts[i];
|
|
307
|
+
}
|
|
308
|
+
case 'indexOf':
|
|
309
|
+
case 'lastIndexOf': {
|
|
310
|
+
const v = asString(input());
|
|
311
|
+
if (v === null)
|
|
312
|
+
return null;
|
|
313
|
+
const sub = str('substring');
|
|
314
|
+
if (sub === undefined)
|
|
315
|
+
throw new TransformError(`${type}: "substring" is required`);
|
|
316
|
+
return type === 'indexOf' ? v.indexOf(sub) : v.lastIndexOf(sub);
|
|
317
|
+
}
|
|
318
|
+
case 'leftPad':
|
|
319
|
+
case 'rightPad': {
|
|
320
|
+
const v = asString(input());
|
|
321
|
+
if (v === null)
|
|
322
|
+
return null;
|
|
323
|
+
const len = int('length');
|
|
324
|
+
if (len === undefined)
|
|
325
|
+
throw new TransformError(`${type}: "length" is required`);
|
|
326
|
+
const p = str('padding') ?? ' ';
|
|
327
|
+
if (!p.length || v.length >= len)
|
|
328
|
+
return v;
|
|
329
|
+
const fill = p.repeat(Math.ceil((len - v.length) / p.length)).slice(0, len - v.length);
|
|
330
|
+
return type === 'leftPad' ? fill + v : v + fill;
|
|
331
|
+
}
|
|
332
|
+
case 'dateFormat': {
|
|
333
|
+
const v = asString(input());
|
|
334
|
+
if (v === null)
|
|
335
|
+
return null;
|
|
336
|
+
const inF = str('inputFormat') ?? 'ISO8601';
|
|
337
|
+
const outF = str('outputFormat') ?? 'ISO8601';
|
|
338
|
+
const d = parseNamed(v, inF);
|
|
339
|
+
if (!d)
|
|
340
|
+
throw new TransformError(`ParseException: "${v}" does not match the input format ${inF}`);
|
|
341
|
+
if (outF === 'ISO8601')
|
|
342
|
+
this.assumptions.add('dateFormat ISO8601 output follows Java’s pattern yyyy-MM-dd\'T\'HH:mm:ss.SSSZ (time zone written as +0000)');
|
|
343
|
+
return formatNamed(d, outF);
|
|
344
|
+
}
|
|
345
|
+
case 'dateMath': {
|
|
346
|
+
const expr = str('expression');
|
|
347
|
+
if (!expr)
|
|
348
|
+
throw new TransformError('dateMath: "expression" is required');
|
|
349
|
+
let rest = expr.trim();
|
|
350
|
+
let d;
|
|
351
|
+
if (rest.startsWith('now')) {
|
|
352
|
+
d = new Date(this.now);
|
|
353
|
+
rest = rest.slice(3);
|
|
354
|
+
step.note = 'from now';
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
const v = asString(input());
|
|
358
|
+
if (v === null)
|
|
359
|
+
return null;
|
|
360
|
+
const p = parseNamed(v, 'ISO8601');
|
|
361
|
+
if (!p)
|
|
362
|
+
throw new TransformError(`dateMath: input "${v}" is not ISO 8601`);
|
|
363
|
+
d = p;
|
|
364
|
+
}
|
|
365
|
+
d = dateMath(d, rest, a['roundUp'] === true || a['roundUp'] === 'true');
|
|
366
|
+
return formatNamed(d, "yyyy-MM-dd'T'HH:mm");
|
|
367
|
+
}
|
|
368
|
+
case 'dateCompare': {
|
|
369
|
+
const get = (k) => {
|
|
370
|
+
const raw = a[k];
|
|
371
|
+
const v = typeof raw === 'string' && raw.trim().toLowerCase() === 'now' ? this.now.toISOString() : asString(this.evalAny(raw, ctx, implicit));
|
|
372
|
+
if (v === null)
|
|
373
|
+
throw new TransformError(`dateCompare: ${k} is null`);
|
|
374
|
+
const d = v.toLowerCase() === 'now' ? this.now : parseNamed(v, 'ISO8601');
|
|
375
|
+
if (!d)
|
|
376
|
+
throw new TransformError(`dateCompare: ${k} "${v}" is not ISO 8601`);
|
|
377
|
+
return d.getTime();
|
|
378
|
+
};
|
|
379
|
+
const x = get('firstDate');
|
|
380
|
+
const y = get('secondDate');
|
|
381
|
+
const op = String(a['operator'] ?? '').toUpperCase();
|
|
382
|
+
const r = op === 'LT' ? x < y : op === 'LTE' ? x <= y : op === 'GT' ? x > y : op === 'GTE' ? x >= y : null;
|
|
383
|
+
if (r === null)
|
|
384
|
+
throw new TransformError(`dateCompare: operator must be LT, LTE, GT or GTE, got "${a['operator']}"`);
|
|
385
|
+
step.note = `${new Date(x).toISOString()} ${op} ${new Date(y).toISOString()}: ${r}`;
|
|
386
|
+
const out = str(r ? 'positiveCondition' : 'negativeCondition');
|
|
387
|
+
if (out === undefined)
|
|
388
|
+
throw new TransformError('dateCompare: positiveCondition and negativeCondition are required');
|
|
389
|
+
return out;
|
|
390
|
+
}
|
|
391
|
+
case 'reference': {
|
|
392
|
+
const id = str('id');
|
|
393
|
+
const ref = id ? this.transforms.get(id) : undefined;
|
|
394
|
+
if (!ref)
|
|
395
|
+
throw new TransformError(`reference: no transform named "${id}" (load the tenant's transforms or add it to the lab)`);
|
|
396
|
+
step.note = `uses "${ref.name ?? id}"`;
|
|
397
|
+
const inner = a['input'] !== undefined ? this.evalAny(a['input'], ctx, implicit) : implicit;
|
|
398
|
+
step.input = inner;
|
|
399
|
+
return this.evalDef(ref, ctx, inner);
|
|
400
|
+
}
|
|
401
|
+
case 'identityAttribute': {
|
|
402
|
+
const n = str('name');
|
|
403
|
+
if (!n)
|
|
404
|
+
throw new TransformError('identityAttribute: "name" is required');
|
|
405
|
+
if (!ctx.identity)
|
|
406
|
+
throw new IscOnly('identityAttribute needs the identity’s attributes (add them as test input)');
|
|
407
|
+
return toValue(ctx.identity[n]);
|
|
408
|
+
}
|
|
409
|
+
case 'accountAttribute':
|
|
410
|
+
return this.accountAttribute(a, ctx, step);
|
|
411
|
+
case 'displayName': {
|
|
412
|
+
const id = ctx.identity ?? {};
|
|
413
|
+
const first = asString(toValue(id['preferredName'])) ?? asString(toValue(id['firstname']));
|
|
414
|
+
const last = asString(toValue(id['lastname']));
|
|
415
|
+
if (first === null && last === null)
|
|
416
|
+
return null;
|
|
417
|
+
return [first, last].filter(Boolean).join(' ');
|
|
418
|
+
}
|
|
419
|
+
case 'e164phone':
|
|
420
|
+
return e164(asString(input()), str('defaultRegion') ?? 'US', (m) => this.assumptions.add(m));
|
|
421
|
+
case 'iso3166':
|
|
422
|
+
return iso3166(asString(input()), str('format') ?? 'alpha2');
|
|
423
|
+
case 'rfc5646': {
|
|
424
|
+
const v = asString(input());
|
|
425
|
+
if (v === null)
|
|
426
|
+
return null;
|
|
427
|
+
return RFC5646[v] ?? RFC5646[v.toUpperCase()] ?? Object.entries(RFC5646).find(([k]) => k.toLowerCase() === v.toLowerCase())?.[1] ?? null;
|
|
428
|
+
}
|
|
429
|
+
case 'randomAlphaNumeric':
|
|
430
|
+
case 'randomNumeric':
|
|
431
|
+
case 'uuid': {
|
|
432
|
+
this.random = true;
|
|
433
|
+
if (type === 'uuid')
|
|
434
|
+
return crypto.randomUUID();
|
|
435
|
+
const len = int('length') ?? (type === 'randomNumeric' ? 10 : 32);
|
|
436
|
+
if (len < 1 || len > 450)
|
|
437
|
+
throw new TransformError(`${type}: length must be 1 to 450`);
|
|
438
|
+
const chars = type === 'randomNumeric' ? '0123456789' : 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
439
|
+
return Array.from({ length: len }, () => chars[Math.floor(Math.random() * chars.length)]).join('');
|
|
440
|
+
}
|
|
441
|
+
case 'rule': {
|
|
442
|
+
const name = str('name');
|
|
443
|
+
if (name === 'Cloud Services Deployment Utility')
|
|
444
|
+
return this.utility(a, ctx, implicit, step);
|
|
445
|
+
throw new IscOnly(`rule "${name}" is custom code that runs only in ISC`);
|
|
446
|
+
}
|
|
447
|
+
case 'usernameGenerator': {
|
|
448
|
+
const vars = this.variables(a, ctx, implicit);
|
|
449
|
+
const patterns = Array.isArray(a['patterns']) ? a['patterns'] : [];
|
|
450
|
+
if (!patterns.length)
|
|
451
|
+
throw new TransformError('usernameGenerator: "patterns" is required');
|
|
452
|
+
const first = this.render(String(patterns[0]), ctx, { ...vars, uniqueCounter: '' });
|
|
453
|
+
step.note = 'first candidate; ISC checks uniqueness and may pick a later pattern';
|
|
454
|
+
throw new IscOnly(`uniqueness is checked only in ISC; the first candidate would be "${first}"`);
|
|
455
|
+
}
|
|
456
|
+
default:
|
|
457
|
+
throw new IscOnly(`transform type "${type}" is not available offline`);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
utility(a, ctx, implicit, step) {
|
|
461
|
+
const op = String(a['operation'] ?? '');
|
|
462
|
+
if (op === 'getEndOfString') {
|
|
463
|
+
const v = asString(this.inputOf(a, ctx, implicit));
|
|
464
|
+
step.input = v;
|
|
465
|
+
if (v === null)
|
|
466
|
+
return null;
|
|
467
|
+
const n = Number(this.render(String(a['numChars'] ?? ''), ctx, {}));
|
|
468
|
+
if (!Number.isInteger(n))
|
|
469
|
+
throw new TransformError('getEndOfString: numChars must be a whole number');
|
|
470
|
+
return n > v.length ? null : v.slice(v.length - n);
|
|
471
|
+
}
|
|
472
|
+
if (op === 'getReferenceIdentityAttribute') {
|
|
473
|
+
const uid = this.render(String(a['uid'] ?? ''), ctx, {});
|
|
474
|
+
const attr = String(a['attributeName'] ?? '');
|
|
475
|
+
const who = uid === 'manager' ? ctx.manager : ctx.people?.[uid];
|
|
476
|
+
if (!who)
|
|
477
|
+
throw new IscOnly(`needs the attributes of ${uid === 'manager' ? 'the manager' : `"${uid}"`} (add them as test input)`);
|
|
478
|
+
return toValue(who[attr]);
|
|
479
|
+
}
|
|
480
|
+
if (op === 'generateRandomString') {
|
|
481
|
+
this.random = true;
|
|
482
|
+
const len = Number(a['length'] ?? 0);
|
|
483
|
+
if (!Number.isInteger(len) || len < 1 || len > 450)
|
|
484
|
+
throw new TransformError('generateRandomString: length must be 1 to 450');
|
|
485
|
+
let chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
486
|
+
if (String(a['includeNumbers']) === 'true')
|
|
487
|
+
chars += '0123456789';
|
|
488
|
+
if (String(a['includeSpecialChars']) === 'true')
|
|
489
|
+
chars += '!@#$%&*()+<>?';
|
|
490
|
+
return Array.from({ length: len }, () => chars[Math.floor(Math.random() * chars.length)]).join('');
|
|
491
|
+
}
|
|
492
|
+
throw new IscOnly(`Cloud Services Deployment Utility operation "${op}" is not available offline`);
|
|
493
|
+
}
|
|
494
|
+
accountAttribute(a, ctx, step) {
|
|
495
|
+
const attr = String(a['attributeName'] ?? '');
|
|
496
|
+
if (!attr)
|
|
497
|
+
throw new TransformError('accountAttribute: "attributeName" is required');
|
|
498
|
+
const src = (a['sourceName'] ?? a['applicationName']);
|
|
499
|
+
const srcId = (a['applicationId'] ?? a['sourceId']);
|
|
500
|
+
if (!ctx.accounts)
|
|
501
|
+
throw new IscOnly('accountAttribute needs the person’s accounts (add them as test input)');
|
|
502
|
+
const clean = (s) => s.replace(/\s*\[source\]$/i, '');
|
|
503
|
+
let list = ctx.accounts.filter((x) => (srcId && x.sourceId === srcId) || (src !== undefined && clean(x.source) === clean(String(src))));
|
|
504
|
+
if (a['accountFilter'])
|
|
505
|
+
list = list.filter((x) => matchFilter(String(a['accountFilter']), { nativeIdentity: x.nativeIdentity, displayName: x.name, ...x.attributes }));
|
|
506
|
+
if (a['accountPropertyFilter'])
|
|
507
|
+
list = list.filter((x) => matchFilter(String(a['accountPropertyFilter']), x.attributes));
|
|
508
|
+
const sortBy = String(a['accountSortAttribute'] ?? 'created');
|
|
509
|
+
const desc = a['accountSortDescending'] === true || a['accountSortDescending'] === 'true';
|
|
510
|
+
list = [...list].sort((x, y) => {
|
|
511
|
+
const xv = sortBy === 'created' ? x.created ?? '' : String(x.attributes[sortBy] ?? '');
|
|
512
|
+
const yv = sortBy === 'created' ? y.created ?? '' : String(y.attributes[sortBy] ?? '');
|
|
513
|
+
return (xv < yv ? -1 : xv > yv ? 1 : 0) * (desc ? -1 : 1);
|
|
514
|
+
});
|
|
515
|
+
step.note = `${list.length} matching account${list.length === 1 ? '' : 's'} on ${src ?? srcId}`;
|
|
516
|
+
if (!list.length)
|
|
517
|
+
return null;
|
|
518
|
+
if (a['accountReturnFirstLink'] === true || a['accountReturnFirstLink'] === 'true')
|
|
519
|
+
return toValue(list[0].attributes[attr]);
|
|
520
|
+
for (const x of list) {
|
|
521
|
+
const v = x.attributes[attr];
|
|
522
|
+
if (v !== null && v !== undefined)
|
|
523
|
+
return toValue(v);
|
|
524
|
+
}
|
|
525
|
+
return null;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
// ------------------------------------------------------------ helpers
|
|
529
|
+
const UNIT = { y: true, M: true, w: true, d: true, h: true, m: true, s: true };
|
|
530
|
+
export function dateMath(start, expr, roundUp) {
|
|
531
|
+
const d = new Date(start);
|
|
532
|
+
let i = 0;
|
|
533
|
+
while (i < expr.length) {
|
|
534
|
+
const op = expr[i];
|
|
535
|
+
if (op === '+' || op === '-') {
|
|
536
|
+
const m = /^(\d+)([yMwdhms])/.exec(expr.slice(i + 1));
|
|
537
|
+
if (!m)
|
|
538
|
+
throw new TransformError(`dateMath: cannot read "${expr.slice(i)}"`);
|
|
539
|
+
const n = Number(m[1]) * (op === '-' ? -1 : 1);
|
|
540
|
+
add(d, m[2], n);
|
|
541
|
+
i += 1 + m[0].length;
|
|
542
|
+
}
|
|
543
|
+
else if (op === '/') {
|
|
544
|
+
const u = expr[i + 1];
|
|
545
|
+
if (!u || !UNIT[u])
|
|
546
|
+
throw new TransformError(`dateMath: cannot read "${expr.slice(i)}"`);
|
|
547
|
+
if (u === 'w')
|
|
548
|
+
throw new TransformError('dateMath: rounding by week is not supported');
|
|
549
|
+
truncate(d, u);
|
|
550
|
+
if (roundUp)
|
|
551
|
+
add(d, u, 1); // documented: truncate, then add one unit
|
|
552
|
+
i += 2;
|
|
553
|
+
}
|
|
554
|
+
else
|
|
555
|
+
throw new TransformError(`dateMath: cannot read "${expr.slice(i)}"`);
|
|
556
|
+
}
|
|
557
|
+
return d;
|
|
558
|
+
}
|
|
559
|
+
function add(d, u, n) {
|
|
560
|
+
if (u === 'y' || u === 'M') {
|
|
561
|
+
const day = d.getUTCDate();
|
|
562
|
+
d.setUTCDate(1);
|
|
563
|
+
if (u === 'y')
|
|
564
|
+
d.setUTCFullYear(d.getUTCFullYear() + n);
|
|
565
|
+
else
|
|
566
|
+
d.setUTCMonth(d.getUTCMonth() + n);
|
|
567
|
+
const last = new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth() + 1, 0)).getUTCDate();
|
|
568
|
+
d.setUTCDate(Math.min(day, last)); // Java Calendar keeps the day within the month
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
const ms = { w: 604_800_000, d: 86_400_000, h: 3_600_000, m: 60_000, s: 1000 }[u];
|
|
572
|
+
d.setTime(d.getTime() + n * ms);
|
|
573
|
+
}
|
|
574
|
+
function truncate(d, u) {
|
|
575
|
+
if (u === 's')
|
|
576
|
+
d.setUTCMilliseconds(0);
|
|
577
|
+
if (u === 'm')
|
|
578
|
+
d.setUTCSeconds(0, 0);
|
|
579
|
+
if (u === 'h')
|
|
580
|
+
d.setUTCMinutes(0, 0, 0);
|
|
581
|
+
if (u === 'd')
|
|
582
|
+
d.setUTCHours(0, 0, 0, 0);
|
|
583
|
+
if (u === 'M') {
|
|
584
|
+
d.setUTCDate(1);
|
|
585
|
+
d.setUTCHours(0, 0, 0, 0);
|
|
586
|
+
}
|
|
587
|
+
if (u === 'y') {
|
|
588
|
+
d.setUTCMonth(0, 1);
|
|
589
|
+
d.setUTCHours(0, 0, 0, 0);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
/** sailpoint.object.Filter subset: (a == "x"), (a != "x"), a.startsWith("x"), a.containsAll({"x"}), &&, ||, !. */
|
|
593
|
+
export function matchFilter(expr, attrs) {
|
|
594
|
+
let s = expr.trim();
|
|
595
|
+
const strip = (x) => {
|
|
596
|
+
x = x.trim();
|
|
597
|
+
while (x.startsWith('(') && x.endsWith(')') && balanced(x.slice(1, -1)))
|
|
598
|
+
x = x.slice(1, -1).trim();
|
|
599
|
+
return x;
|
|
600
|
+
};
|
|
601
|
+
s = strip(s);
|
|
602
|
+
const top = splitTop(s, '||');
|
|
603
|
+
if (top.length > 1)
|
|
604
|
+
return top.some((p) => matchFilter(p, attrs));
|
|
605
|
+
const all = splitTop(s, '&&');
|
|
606
|
+
if (all.length > 1)
|
|
607
|
+
return all.every((p) => matchFilter(p, attrs));
|
|
608
|
+
if (s.startsWith('!'))
|
|
609
|
+
return !matchFilter(s.slice(1), attrs);
|
|
610
|
+
let m = /^([\w.]+)\s*(==|!=)\s*(?:"([^"]*)"|'([^']*)'|(true|false|null|-?\d+))$/i.exec(s);
|
|
611
|
+
if (m) {
|
|
612
|
+
const v = attrs[m[1]];
|
|
613
|
+
const want = m[3] ?? m[4] ?? m[5];
|
|
614
|
+
const eq = want === 'null' ? v === null || v === undefined : Array.isArray(v) ? v.map(String).includes(want) : String(v) === want;
|
|
615
|
+
return m[2] === '==' ? eq : !eq;
|
|
616
|
+
}
|
|
617
|
+
m = /^([\w]+)\.(startsWith|endsWith|contains)\(\s*"([^"]*)"\s*\)$/i.exec(s);
|
|
618
|
+
if (m) {
|
|
619
|
+
const v = String(attrs[m[1]] ?? '');
|
|
620
|
+
return m[2] === 'startsWith' ? v.startsWith(m[3]) : m[2] === 'endsWith' ? v.endsWith(m[3]) : v.includes(m[3]);
|
|
621
|
+
}
|
|
622
|
+
m = /^([\w]+)\.containsAll\(\s*\{([^}]*)\}\s*\)$/i.exec(s);
|
|
623
|
+
if (m) {
|
|
624
|
+
const v = attrs[m[1]];
|
|
625
|
+
const have = Array.isArray(v) ? v.map(String) : v === undefined || v === null ? [] : [String(v)];
|
|
626
|
+
const want = [...m[2].matchAll(/"([^"]*)"/g)].map((x) => x[1]);
|
|
627
|
+
return want.every((w) => have.includes(w));
|
|
628
|
+
}
|
|
629
|
+
throw new IscOnly(`account filter "${expr}" is not available offline`);
|
|
630
|
+
}
|
|
631
|
+
function balanced(s) {
|
|
632
|
+
let d = 0;
|
|
633
|
+
for (const c of s) {
|
|
634
|
+
if (c === '(')
|
|
635
|
+
d++;
|
|
636
|
+
if (c === ')')
|
|
637
|
+
d--;
|
|
638
|
+
if (d < 0)
|
|
639
|
+
return false;
|
|
640
|
+
}
|
|
641
|
+
return d === 0;
|
|
642
|
+
}
|
|
643
|
+
function splitTop(s, op) {
|
|
644
|
+
const out = [];
|
|
645
|
+
let d = 0;
|
|
646
|
+
let q = false;
|
|
647
|
+
let cur = '';
|
|
648
|
+
for (let i = 0; i < s.length; i++) {
|
|
649
|
+
const c = s[i];
|
|
650
|
+
if (c === '"')
|
|
651
|
+
q = !q;
|
|
652
|
+
if (!q && c === '(')
|
|
653
|
+
d++;
|
|
654
|
+
if (!q && c === ')')
|
|
655
|
+
d--;
|
|
656
|
+
if (!q && d === 0 && s.startsWith(op, i)) {
|
|
657
|
+
out.push(cur);
|
|
658
|
+
cur = '';
|
|
659
|
+
i += op.length - 1;
|
|
660
|
+
continue;
|
|
661
|
+
}
|
|
662
|
+
cur += c;
|
|
663
|
+
}
|
|
664
|
+
out.push(cur);
|
|
665
|
+
return out.map((x) => x.trim()).filter(Boolean);
|
|
666
|
+
}
|
|
667
|
+
const SMALL = new Set(['von', 'del', 'of', 'de', 'la', 'y']);
|
|
668
|
+
/** nameNormalizer, following the documented rules. */
|
|
669
|
+
export function normalizeName(v) {
|
|
670
|
+
return v
|
|
671
|
+
.split(/(\s+|-|')/)
|
|
672
|
+
.map((part) => {
|
|
673
|
+
if (/^(\s+|-|')$/.test(part) || !part)
|
|
674
|
+
return part;
|
|
675
|
+
const low = part.toLowerCase();
|
|
676
|
+
if (SMALL.has(low))
|
|
677
|
+
return low;
|
|
678
|
+
if (/^(i{1,3}|iv|v|vi{1,3}|ix|x)$/i.test(part))
|
|
679
|
+
return part.toUpperCase();
|
|
680
|
+
if (/^mc./i.test(part))
|
|
681
|
+
return 'Mc' + part[2].toUpperCase() + part.slice(3).toLowerCase();
|
|
682
|
+
if (/^mac.{3,}/i.test(part))
|
|
683
|
+
return 'Mac' + part[3].toUpperCase() + part.slice(4).toLowerCase();
|
|
684
|
+
return part[0].toUpperCase() + part.slice(1).toLowerCase();
|
|
685
|
+
})
|
|
686
|
+
.join('');
|
|
687
|
+
}
|
|
688
|
+
/** E.164 for numbers in the North American plan; other regions need ISC (libphonenumber). */
|
|
689
|
+
function e164(v, region, note) {
|
|
690
|
+
if (v === null)
|
|
691
|
+
return null;
|
|
692
|
+
const trimmed = v.trim();
|
|
693
|
+
const digits = trimmed.replace(/[^\d]/g, '');
|
|
694
|
+
if (trimmed.startsWith('+')) {
|
|
695
|
+
note('e164phone: numbers already starting with + are only checked for length offline');
|
|
696
|
+
return digits.length >= 8 && digits.length <= 15 ? '+' + digits : null;
|
|
697
|
+
}
|
|
698
|
+
if (region === 'US' || region === 'CA') {
|
|
699
|
+
if (digits.length === 10 && /^[2-9]\d{2}[2-9]/.test(digits))
|
|
700
|
+
return '+1' + digits;
|
|
701
|
+
if (digits.length === 11 && digits.startsWith('1') && /^1[2-9]\d{2}[2-9]/.test(digits))
|
|
702
|
+
return '+' + digits;
|
|
703
|
+
return null;
|
|
704
|
+
}
|
|
705
|
+
throw new IscOnly(`e164phone for region ${region} needs ISC’s phone number library`);
|
|
706
|
+
}
|
|
707
|
+
function iso3166(v, format) {
|
|
708
|
+
if (v === null)
|
|
709
|
+
return null;
|
|
710
|
+
if (format !== 'alpha2')
|
|
711
|
+
throw new IscOnly(`iso3166 with format "${format}" is not available offline`);
|
|
712
|
+
const t = v.trim();
|
|
713
|
+
const names = new Intl.DisplayNames(['en'], { type: 'region' });
|
|
714
|
+
if (/^[A-Za-z]{2}$/.test(t)) {
|
|
715
|
+
const up = t.toUpperCase();
|
|
716
|
+
try {
|
|
717
|
+
return names.of(up) && names.of(up) !== up ? up : null;
|
|
718
|
+
}
|
|
719
|
+
catch {
|
|
720
|
+
return null;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
if (/^[A-Za-z]{3}$|^\d{3}$/.test(t))
|
|
724
|
+
throw new IscOnly('three-letter and numeric country codes are converted only in ISC');
|
|
725
|
+
for (let a = 65; a <= 90; a++)
|
|
726
|
+
for (let b = 65; b <= 90; b++) {
|
|
727
|
+
const code = String.fromCharCode(a, b);
|
|
728
|
+
try {
|
|
729
|
+
if (names.of(code)?.toLowerCase() === t.toLowerCase())
|
|
730
|
+
return code;
|
|
731
|
+
}
|
|
732
|
+
catch {
|
|
733
|
+
/* not a region */
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
throw new IscOnly(`"${t}" is not an English country name; native names are converted only in ISC`);
|
|
737
|
+
}
|
|
738
|
+
//# sourceMappingURL=transforms.js.map
|