@servicenow/sdk-build-plugins 4.2.0 → 4.4.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/dist/acl-plugin.js +11 -0
- package/dist/acl-plugin.js.map +1 -1
- package/dist/applicability-plugin.d.ts +2 -0
- package/dist/applicability-plugin.js +72 -0
- package/dist/applicability-plugin.js.map +1 -0
- package/dist/atf/test-plugin.js +5 -2
- package/dist/atf/test-plugin.js.map +1 -1
- package/dist/basic-syntax-plugin.js +7 -1
- package/dist/basic-syntax-plugin.js.map +1 -1
- package/dist/business-rule-plugin.js +1 -0
- package/dist/business-rule-plugin.js.map +1 -1
- package/dist/call-expression-plugin.js +1 -107
- package/dist/call-expression-plugin.js.map +1 -1
- package/dist/column/column-to-record.d.ts +10 -3
- package/dist/column/column-to-record.js +44 -7
- package/dist/column/column-to-record.js.map +1 -1
- package/dist/column-plugin.d.ts +3 -1
- package/dist/column-plugin.js +12 -12
- package/dist/column-plugin.js.map +1 -1
- package/dist/dashboard/dashboard-component-property-defaults.d.ts +152 -0
- package/dist/dashboard/dashboard-component-property-defaults.js +264 -0
- package/dist/dashboard/dashboard-component-property-defaults.js.map +1 -0
- package/dist/dashboard/dashboard-component-resolver.d.ts +13 -0
- package/dist/dashboard/dashboard-component-resolver.js +69 -0
- package/dist/dashboard/dashboard-component-resolver.js.map +1 -0
- package/dist/dashboard/dashboard-plugin.d.ts +12 -0
- package/dist/dashboard/dashboard-plugin.js +397 -0
- package/dist/dashboard/dashboard-plugin.js.map +1 -0
- package/dist/data-plugin.d.ts +3 -0
- package/dist/data-plugin.js +61 -113
- package/dist/data-plugin.js.map +1 -1
- package/dist/email-notification-plugin.d.ts +2 -0
- package/dist/email-notification-plugin.js +541 -0
- package/dist/email-notification-plugin.js.map +1 -0
- package/dist/flow/constants/flow-plugin-constants.d.ts +58 -0
- package/dist/flow/constants/flow-plugin-constants.js +70 -0
- package/dist/flow/constants/flow-plugin-constants.js.map +1 -0
- package/dist/flow/flow-logic/flow-logic-constants.d.ts +38 -0
- package/dist/flow/flow-logic/flow-logic-constants.js +118 -0
- package/dist/flow/flow-logic/flow-logic-constants.js.map +1 -0
- package/dist/flow/flow-logic/flow-logic-diagnostics.d.ts +19 -0
- package/dist/flow/flow-logic/flow-logic-diagnostics.js +503 -0
- package/dist/flow/flow-logic/flow-logic-diagnostics.js.map +1 -0
- package/dist/flow/flow-logic/flow-logic-plugin-helpers.d.ts +62 -0
- package/dist/flow/flow-logic/flow-logic-plugin-helpers.js +2092 -0
- package/dist/flow/flow-logic/flow-logic-plugin-helpers.js.map +1 -0
- package/dist/flow/flow-logic/flow-logic-plugin.d.ts +52 -0
- package/dist/flow/flow-logic/flow-logic-plugin.js +283 -0
- package/dist/flow/flow-logic/flow-logic-plugin.js.map +1 -0
- package/dist/flow/flow-logic/flow-logic-shapes.d.ts +104 -0
- package/dist/flow/flow-logic/flow-logic-shapes.js +201 -0
- package/dist/flow/flow-logic/flow-logic-shapes.js.map +1 -0
- package/dist/flow/plugins/approval-rules-plugin.d.ts +2 -0
- package/dist/flow/plugins/approval-rules-plugin.js +49 -0
- package/dist/flow/plugins/approval-rules-plugin.js.map +1 -0
- package/dist/flow/plugins/flow-action-definition-plugin.d.ts +2 -0
- package/dist/flow/plugins/flow-action-definition-plugin.js +286 -0
- package/dist/flow/plugins/flow-action-definition-plugin.js.map +1 -0
- package/dist/flow/plugins/flow-data-pill-plugin.d.ts +9 -0
- package/dist/flow/plugins/flow-data-pill-plugin.js +212 -0
- package/dist/flow/plugins/flow-data-pill-plugin.js.map +1 -0
- package/dist/flow/plugins/flow-definition-plugin.d.ts +2 -0
- package/dist/flow/plugins/flow-definition-plugin.js +1668 -0
- package/dist/flow/plugins/flow-definition-plugin.js.map +1 -0
- package/dist/flow/plugins/flow-diagnostics-plugin.d.ts +26 -0
- package/dist/flow/plugins/flow-diagnostics-plugin.js +217 -0
- package/dist/flow/plugins/flow-diagnostics-plugin.js.map +1 -0
- package/dist/flow/plugins/flow-instance-plugin.d.ts +12 -0
- package/dist/flow/plugins/flow-instance-plugin.js +1205 -0
- package/dist/flow/plugins/flow-instance-plugin.js.map +1 -0
- package/dist/flow/plugins/flow-trigger-instance-plugin.d.ts +2 -0
- package/dist/flow/plugins/flow-trigger-instance-plugin.js +338 -0
- package/dist/flow/plugins/flow-trigger-instance-plugin.js.map +1 -0
- package/dist/flow/plugins/inline-script-plugin.d.ts +39 -0
- package/dist/flow/plugins/inline-script-plugin.js +80 -0
- package/dist/flow/plugins/inline-script-plugin.js.map +1 -0
- package/dist/flow/plugins/step-definition-plugin.d.ts +5 -0
- package/dist/flow/plugins/step-definition-plugin.js +71 -0
- package/dist/flow/plugins/step-definition-plugin.js.map +1 -0
- package/dist/flow/plugins/step-instance-plugin.d.ts +31 -0
- package/dist/flow/plugins/step-instance-plugin.js +339 -0
- package/dist/flow/plugins/step-instance-plugin.js.map +1 -0
- package/dist/flow/plugins/trigger-plugin.d.ts +2 -0
- package/dist/flow/plugins/trigger-plugin.js +96 -0
- package/dist/flow/plugins/trigger-plugin.js.map +1 -0
- package/dist/flow/plugins/wfa-datapill-plugin.d.ts +15 -0
- package/dist/flow/plugins/wfa-datapill-plugin.js +178 -0
- package/dist/flow/plugins/wfa-datapill-plugin.js.map +1 -0
- package/dist/flow/utils/approval-rules-processor.d.ts +13 -0
- package/dist/flow/utils/approval-rules-processor.js +267 -0
- package/dist/flow/utils/approval-rules-processor.js.map +1 -0
- package/dist/flow/utils/built-in-complex-objects.d.ts +19 -0
- package/dist/flow/utils/built-in-complex-objects.js +62 -0
- package/dist/flow/utils/built-in-complex-objects.js.map +1 -0
- package/dist/flow/utils/complex-object-resolver.d.ts +8 -0
- package/dist/flow/utils/complex-object-resolver.js +614 -0
- package/dist/flow/utils/complex-object-resolver.js.map +1 -0
- package/dist/flow/utils/complex-objects.d.ts +36 -0
- package/dist/flow/utils/complex-objects.js +481 -0
- package/dist/flow/utils/complex-objects.js.map +1 -0
- package/dist/flow/utils/data-pill-shapes.d.ts +58 -0
- package/dist/flow/utils/data-pill-shapes.js +135 -0
- package/dist/flow/utils/data-pill-shapes.js.map +1 -0
- package/dist/flow/utils/datapill-transformer.d.ts +110 -0
- package/dist/flow/utils/datapill-transformer.js +503 -0
- package/dist/flow/utils/datapill-transformer.js.map +1 -0
- package/dist/flow/utils/flow-constants.d.ts +72 -0
- package/dist/flow/utils/flow-constants.js +230 -0
- package/dist/flow/utils/flow-constants.js.map +1 -0
- package/dist/flow/utils/flow-io-to-record.d.ts +44 -0
- package/dist/flow/utils/flow-io-to-record.js +409 -0
- package/dist/flow/utils/flow-io-to-record.js.map +1 -0
- package/dist/flow/utils/flow-shapes.d.ts +161 -0
- package/dist/flow/utils/flow-shapes.js +255 -0
- package/dist/flow/utils/flow-shapes.js.map +1 -0
- package/dist/flow/utils/flow-to-xml.d.ts +16 -0
- package/dist/flow/utils/flow-to-xml.js +237 -0
- package/dist/flow/utils/flow-to-xml.js.map +1 -0
- package/dist/flow/utils/flow-variable-processor.d.ts +51 -0
- package/dist/flow/utils/flow-variable-processor.js +69 -0
- package/dist/flow/utils/flow-variable-processor.js.map +1 -0
- package/dist/flow/utils/label-cache-parser.d.ts +7 -0
- package/dist/flow/utils/label-cache-parser.js +24 -0
- package/dist/flow/utils/label-cache-parser.js.map +1 -0
- package/dist/flow/utils/label-cache-processor.d.ts +119 -0
- package/dist/flow/utils/label-cache-processor.js +719 -0
- package/dist/flow/utils/label-cache-processor.js.map +1 -0
- package/dist/flow/utils/pill-string-parser.d.ts +88 -0
- package/dist/flow/utils/pill-string-parser.js +306 -0
- package/dist/flow/utils/pill-string-parser.js.map +1 -0
- package/dist/flow/utils/schema-to-flow-object.d.ts +22 -0
- package/dist/flow/utils/schema-to-flow-object.js +318 -0
- package/dist/flow/utils/schema-to-flow-object.js.map +1 -0
- package/dist/flow/utils/service-catalog.d.ts +47 -0
- package/dist/flow/utils/service-catalog.js +137 -0
- package/dist/flow/utils/service-catalog.js.map +1 -0
- package/dist/flow/utils/utils.d.ts +117 -0
- package/dist/flow/utils/utils.js +345 -0
- package/dist/flow/utils/utils.js.map +1 -0
- package/dist/index.d.ts +20 -1
- package/dist/index.js +21 -1
- package/dist/index.js.map +1 -1
- package/dist/list-plugin.js +1 -1
- package/dist/list-plugin.js.map +1 -1
- package/dist/now-attach-plugin.d.ts +1 -0
- package/dist/now-attach-plugin.js +10 -10
- package/dist/now-attach-plugin.js.map +1 -1
- package/dist/now-ref-plugin.js +1 -1
- package/dist/now-ref-plugin.js.map +1 -1
- package/dist/record-plugin.d.ts +29 -0
- package/dist/record-plugin.js +66 -7
- package/dist/record-plugin.js.map +1 -1
- package/dist/repack/index.d.ts +2 -0
- package/dist/repack/index.js +8 -0
- package/dist/repack/index.js.map +1 -1
- package/dist/rest-api-plugin.js +54 -44
- package/dist/rest-api-plugin.js.map +1 -1
- package/dist/server-module-plugin/index.d.ts +10 -0
- package/dist/server-module-plugin/index.js +83 -59
- package/dist/server-module-plugin/index.js.map +1 -1
- package/dist/service-catalog/catalog-clientscript-plugin.d.ts +2 -0
- package/dist/service-catalog/catalog-clientscript-plugin.js +117 -0
- package/dist/service-catalog/catalog-clientscript-plugin.js.map +1 -0
- package/dist/service-catalog/catalog-item-plugin.d.ts +2 -0
- package/dist/service-catalog/catalog-item-plugin.js +115 -0
- package/dist/service-catalog/catalog-item-plugin.js.map +1 -0
- package/dist/service-catalog/catalog-ui-policy-plugin.d.ts +2 -0
- package/dist/service-catalog/catalog-ui-policy-plugin.js +266 -0
- package/dist/service-catalog/catalog-ui-policy-plugin.js.map +1 -0
- package/dist/service-catalog/index.d.ts +5 -0
- package/dist/service-catalog/index.js +22 -0
- package/dist/service-catalog/index.js.map +1 -0
- package/dist/service-catalog/record-to-shape.d.ts +6 -0
- package/dist/service-catalog/record-to-shape.js +93 -0
- package/dist/service-catalog/record-to-shape.js.map +1 -0
- package/dist/service-catalog/sc-record-producer-plugin.d.ts +2 -0
- package/dist/service-catalog/sc-record-producer-plugin.js +140 -0
- package/dist/service-catalog/sc-record-producer-plugin.js.map +1 -0
- package/dist/service-catalog/service-catalog-base.d.ts +311 -0
- package/dist/service-catalog/service-catalog-base.js +542 -0
- package/dist/service-catalog/service-catalog-base.js.map +1 -0
- package/dist/service-catalog/service-catalog-diagnostics.d.ts +45 -0
- package/dist/service-catalog/service-catalog-diagnostics.js +172 -0
- package/dist/service-catalog/service-catalog-diagnostics.js.map +1 -0
- package/dist/service-catalog/shape-to-record.d.ts +8 -0
- package/dist/service-catalog/shape-to-record.js +235 -0
- package/dist/service-catalog/shape-to-record.js.map +1 -0
- package/dist/service-catalog/utils.d.ts +323 -0
- package/dist/service-catalog/utils.js +1216 -0
- package/dist/service-catalog/utils.js.map +1 -0
- package/dist/service-catalog/variable-helper.d.ts +43 -0
- package/dist/service-catalog/variable-helper.js +92 -0
- package/dist/service-catalog/variable-helper.js.map +1 -0
- package/dist/service-catalog/variable-set-plugin.d.ts +2 -0
- package/dist/service-catalog/variable-set-plugin.js +175 -0
- package/dist/service-catalog/variable-set-plugin.js.map +1 -0
- package/dist/service-catalog/variables-transform.d.ts +139 -0
- package/dist/service-catalog/variables-transform.js +403 -0
- package/dist/service-catalog/variables-transform.js.map +1 -0
- package/dist/sla/sla-validators.d.ts +61 -0
- package/dist/sla/sla-validators.js +224 -0
- package/dist/sla/sla-validators.js.map +1 -0
- package/dist/sla-plugin.d.ts +5 -0
- package/dist/sla-plugin.js +280 -0
- package/dist/sla-plugin.js.map +1 -0
- package/dist/static-content-plugin.js +25 -2
- package/dist/static-content-plugin.js.map +1 -1
- package/dist/table-plugin.js +32 -15
- package/dist/table-plugin.js.map +1 -1
- package/dist/ui-page-plugin.js +832 -19
- package/dist/ui-page-plugin.js.map +1 -1
- package/dist/ui-policy-plugin.js +5 -7
- package/dist/ui-policy-plugin.js.map +1 -1
- package/dist/utils.d.ts +10 -1
- package/dist/utils.js +16 -0
- package/dist/utils.js.map +1 -1
- package/dist/ux-list-menu-config-plugin.d.ts +2 -0
- package/dist/ux-list-menu-config-plugin.js +292 -0
- package/dist/ux-list-menu-config-plugin.js.map +1 -0
- package/dist/workspace-plugin/chrome-tab.d.ts +2 -0
- package/dist/workspace-plugin/chrome-tab.js +46 -0
- package/dist/workspace-plugin/chrome-tab.js.map +1 -0
- package/dist/workspace-plugin/constants.d.ts +52 -0
- package/dist/workspace-plugin/constants.js +56 -0
- package/dist/workspace-plugin/constants.js.map +1 -0
- package/dist/workspace-plugin/fluent-utils.d.ts +9 -0
- package/dist/workspace-plugin/fluent-utils.js +60 -0
- package/dist/workspace-plugin/fluent-utils.js.map +1 -0
- package/dist/workspace-plugin/page.d.ts +8 -0
- package/dist/workspace-plugin/page.js +108 -0
- package/dist/workspace-plugin/page.js.map +1 -0
- package/dist/workspace-plugin/screen.d.ts +1 -0
- package/dist/workspace-plugin/screen.js +38 -0
- package/dist/workspace-plugin/screen.js.map +1 -0
- package/dist/workspace-plugin/templates/index.d.ts +10 -0
- package/dist/workspace-plugin/templates/index.js +20 -0
- package/dist/workspace-plugin/templates/index.js.map +1 -0
- package/dist/workspace-plugin/templates/record-page-composition.d.ts +1 -0
- package/dist/workspace-plugin/templates/record-page-composition.js +4043 -0
- package/dist/workspace-plugin/templates/record-page-composition.js.map +1 -0
- package/dist/workspace-plugin/templates/record-page-data.d.ts +1 -0
- package/dist/workspace-plugin/templates/record-page-data.js +527 -0
- package/dist/workspace-plugin/templates/record-page-data.js.map +1 -0
- package/dist/workspace-plugin/templates/record-page-interalEventMappings.d.ts +1 -0
- package/dist/workspace-plugin/templates/record-page-interalEventMappings.js +39 -0
- package/dist/workspace-plugin/templates/record-page-interalEventMappings.js.map +1 -0
- package/dist/workspace-plugin/templates/record-page-layoutModel.d.ts +1 -0
- package/dist/workspace-plugin/templates/record-page-layoutModel.js +55 -0
- package/dist/workspace-plugin/templates/record-page-layoutModel.js.map +1 -0
- package/dist/workspace-plugin/templates/record-page-properties.d.ts +1 -0
- package/dist/workspace-plugin/templates/record-page-properties.js +135 -0
- package/dist/workspace-plugin/templates/record-page-properties.js.map +1 -0
- package/dist/workspace-plugin/templates/record-page.d.ts +3 -0
- package/dist/workspace-plugin/templates/record-page.js +8 -0
- package/dist/workspace-plugin/templates/record-page.js.map +1 -0
- package/dist/workspace-plugin.d.ts +2 -0
- package/dist/workspace-plugin.js +453 -0
- package/dist/workspace-plugin.js.map +1 -0
- package/package.json +10 -12
- package/src/acl-plugin.ts +16 -1
- package/src/applicability-plugin.ts +82 -0
- package/src/atf/test-plugin.ts +6 -3
- package/src/basic-syntax-plugin.ts +10 -1
- package/src/business-rule-plugin.ts +2 -1
- package/src/call-expression-plugin.ts +2 -130
- package/src/column/column-to-record.ts +54 -8
- package/src/column-plugin.ts +29 -13
- package/src/dashboard/dashboard-component-property-defaults.ts +277 -0
- package/src/dashboard/dashboard-component-resolver.ts +69 -0
- package/src/dashboard/dashboard-plugin.ts +450 -0
- package/src/data-plugin.ts +67 -139
- package/src/email-notification-plugin.ts +850 -0
- package/src/flow/constants/flow-plugin-constants.ts +79 -0
- package/src/flow/flow-logic/flow-logic-constants.ts +120 -0
- package/src/flow/flow-logic/flow-logic-diagnostics.ts +591 -0
- package/src/flow/flow-logic/flow-logic-plugin-helpers.ts +2550 -0
- package/src/flow/flow-logic/flow-logic-plugin.ts +337 -0
- package/src/flow/flow-logic/flow-logic-shapes.ts +215 -0
- package/src/flow/plugins/approval-rules-plugin.ts +48 -0
- package/src/flow/plugins/flow-action-definition-plugin.ts +295 -0
- package/src/flow/plugins/flow-data-pill-plugin.ts +258 -0
- package/src/flow/plugins/flow-definition-plugin.ts +2173 -0
- package/src/flow/plugins/flow-diagnostics-plugin.ts +280 -0
- package/src/flow/plugins/flow-instance-plugin.ts +1499 -0
- package/src/flow/plugins/flow-trigger-instance-plugin.ts +444 -0
- package/src/flow/plugins/inline-script-plugin.ts +83 -0
- package/src/flow/plugins/step-definition-plugin.ts +67 -0
- package/src/flow/plugins/step-instance-plugin.ts +431 -0
- package/src/flow/plugins/trigger-plugin.ts +95 -0
- package/src/flow/plugins/wfa-datapill-plugin.ts +213 -0
- package/src/flow/utils/approval-rules-processor.ts +298 -0
- package/src/flow/utils/built-in-complex-objects.ts +81 -0
- package/src/flow/utils/complex-object-resolver.ts +875 -0
- package/src/flow/utils/complex-objects.ts +656 -0
- package/src/flow/utils/data-pill-shapes.ts +165 -0
- package/src/flow/utils/datapill-transformer.ts +632 -0
- package/src/flow/utils/flow-constants.ts +285 -0
- package/src/flow/utils/flow-io-to-record.ts +533 -0
- package/src/flow/utils/flow-shapes.ts +296 -0
- package/src/flow/utils/flow-to-xml.ts +318 -0
- package/src/flow/utils/flow-variable-processor.ts +100 -0
- package/src/flow/utils/label-cache-parser.ts +37 -0
- package/src/flow/utils/label-cache-processor.ts +870 -0
- package/src/flow/utils/pill-string-parser.ts +375 -0
- package/src/flow/utils/schema-to-flow-object.ts +385 -0
- package/src/flow/utils/service-catalog.ts +174 -0
- package/src/flow/utils/utils.ts +395 -0
- package/src/index.ts +20 -1
- package/src/list-plugin.ts +1 -1
- package/src/now-attach-plugin.ts +14 -11
- package/src/now-ref-plugin.ts +1 -1
- package/src/record-plugin.ts +76 -11
- package/src/repack/index.ts +14 -0
- package/src/rest-api-plugin.ts +62 -50
- package/src/server-module-plugin/index.ts +112 -86
- package/src/service-catalog/catalog-clientscript-plugin.ts +140 -0
- package/src/service-catalog/catalog-item-plugin.ts +162 -0
- package/src/service-catalog/catalog-ui-policy-plugin.ts +324 -0
- package/src/service-catalog/index.ts +5 -0
- package/src/service-catalog/record-to-shape.ts +109 -0
- package/src/service-catalog/sc-record-producer-plugin.ts +201 -0
- package/src/service-catalog/service-catalog-base.ts +600 -0
- package/src/service-catalog/service-catalog-diagnostics.ts +254 -0
- package/src/service-catalog/shape-to-record.ts +279 -0
- package/src/service-catalog/utils.ts +1455 -0
- package/src/service-catalog/variable-helper.ts +135 -0
- package/src/service-catalog/variable-set-plugin.ts +197 -0
- package/src/service-catalog/variables-transform.ts +438 -0
- package/src/sla/sla-validators.ts +331 -0
- package/src/sla-plugin.ts +358 -0
- package/src/static-content-plugin.ts +25 -2
- package/src/table-plugin.ts +49 -16
- package/src/ui-page-plugin.ts +1063 -20
- package/src/ui-policy-plugin.ts +5 -9
- package/src/utils.ts +24 -1
- package/src/ux-list-menu-config-plugin.ts +312 -0
- package/src/workspace-plugin/chrome-tab.ts +44 -0
- package/src/workspace-plugin/constants.ts +53 -0
- package/src/workspace-plugin/fluent-utils.ts +60 -0
- package/src/workspace-plugin/page.ts +139 -0
- package/src/workspace-plugin/screen.ts +34 -0
- package/src/workspace-plugin/templates/index.ts +17 -0
- package/src/workspace-plugin/templates/record-page-composition.ts +4051 -0
- package/src/workspace-plugin/templates/record-page-data.ts +523 -0
- package/src/workspace-plugin/templates/record-page-interalEventMappings.ts +35 -0
- package/src/workspace-plugin/templates/record-page-layoutModel.ts +51 -0
- package/src/workspace-plugin/templates/record-page-properties.ts +131 -0
- package/src/workspace-plugin/templates/record-page.ts +6 -0
- package/src/workspace-plugin.ts +574 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CallExpressionShape,
|
|
3
|
+
Plugin,
|
|
4
|
+
type Record,
|
|
5
|
+
VariableStatementShape,
|
|
6
|
+
IdentifierShape,
|
|
7
|
+
} from '@servicenow/sdk-build-core'
|
|
8
|
+
import { buildVariableRecords } from './shape-to-record'
|
|
9
|
+
import {
|
|
10
|
+
toValidIdentifier,
|
|
11
|
+
shouldWriteAsCallExpression,
|
|
12
|
+
validateRequestedForVariableConflict,
|
|
13
|
+
validateVariableNameConflicts,
|
|
14
|
+
createScript,
|
|
15
|
+
} from './utils'
|
|
16
|
+
import { validateFulfillmentProcessExclusivity, validateCategoriesRequireCatalogs } from './service-catalog-diagnostics'
|
|
17
|
+
import {
|
|
18
|
+
buildVariablesSchema,
|
|
19
|
+
CatalogItemBaseRelationships,
|
|
20
|
+
CatalogItemBaseCoalesce,
|
|
21
|
+
transformCatalogBaseFieldsToShape,
|
|
22
|
+
transformCatalogItemBaseFieldsToRecord,
|
|
23
|
+
transformCatalogItemSpecificFieldsToShape,
|
|
24
|
+
transformCatalogItemSpecificFieldsToRecord,
|
|
25
|
+
createSharedM2MRecords,
|
|
26
|
+
} from './service-catalog-base'
|
|
27
|
+
|
|
28
|
+
export const CatalogItemPlugin = Plugin.create({
|
|
29
|
+
name: 'CatalogItemPlugin',
|
|
30
|
+
records: {
|
|
31
|
+
sc_cat_item: {
|
|
32
|
+
relationships: CatalogItemBaseRelationships,
|
|
33
|
+
async toShape(record, { descendants, transform, logger }) {
|
|
34
|
+
const variablesSchema = buildVariablesSchema(descendants, logger)
|
|
35
|
+
const deliveryPlanScript = await createScript(
|
|
36
|
+
record,
|
|
37
|
+
record.get('delivery_plan_script'),
|
|
38
|
+
transform,
|
|
39
|
+
'delivery-plan-script'
|
|
40
|
+
)
|
|
41
|
+
const entitlementScript = await createScript(
|
|
42
|
+
record,
|
|
43
|
+
record.get('entitlement_script'),
|
|
44
|
+
transform,
|
|
45
|
+
'entitlement-script'
|
|
46
|
+
)
|
|
47
|
+
const callExpression = new CallExpressionShape({
|
|
48
|
+
source: record,
|
|
49
|
+
callee: 'CatalogItem',
|
|
50
|
+
args: [
|
|
51
|
+
record.transform(({ $ }) => ({
|
|
52
|
+
...transformCatalogBaseFieldsToShape(record, $, descendants),
|
|
53
|
+
...transformCatalogItemSpecificFieldsToShape(record, $, descendants),
|
|
54
|
+
entitlementScript: $.val(entitlementScript).def(''),
|
|
55
|
+
deliveryPlanScript: $.val(deliveryPlanScript).def(''),
|
|
56
|
+
variables: $.val(variablesSchema).def({}),
|
|
57
|
+
})),
|
|
58
|
+
],
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
success: true,
|
|
63
|
+
value: shouldWriteAsCallExpression(record)
|
|
64
|
+
? callExpression
|
|
65
|
+
: new VariableStatementShape({
|
|
66
|
+
source: record,
|
|
67
|
+
isExported: true,
|
|
68
|
+
variableName: new IdentifierShape({
|
|
69
|
+
source: record,
|
|
70
|
+
name: toValidIdentifier(record.get('name').toString().getValue()),
|
|
71
|
+
}),
|
|
72
|
+
initializer: callExpression,
|
|
73
|
+
}),
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
...CatalogItemBaseCoalesce,
|
|
78
|
+
},
|
|
79
|
+
shapes: [
|
|
80
|
+
{
|
|
81
|
+
shape: CallExpressionShape,
|
|
82
|
+
fileTypes: ['fluent'],
|
|
83
|
+
async toRecord(callExpression, { diagnostics, factory }) {
|
|
84
|
+
if (callExpression.getCallee() !== 'CatalogItem') {
|
|
85
|
+
return { success: false }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const arg = callExpression.getArgument(0).asObject()
|
|
89
|
+
|
|
90
|
+
// Validate mutually exclusive fulfillment process fields (executionPlan/flow/workflow)
|
|
91
|
+
validateFulfillmentProcessExclusivity(arg, diagnostics)
|
|
92
|
+
|
|
93
|
+
// Validate categories require catalogs
|
|
94
|
+
validateCategoriesRequireCatalogs(arg, diagnostics)
|
|
95
|
+
|
|
96
|
+
// Validate all RequestedForVariable constraints (direct variables + variable sets) in a single optimized pass
|
|
97
|
+
if (!validateRequestedForVariableConflict(arg, diagnostics, 'CatalogItem')) {
|
|
98
|
+
return { success: false }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Validate that variable names don't conflict between direct variables and variable sets
|
|
102
|
+
if (!validateVariableNameConflicts(arg, diagnostics, 'CatalogItem')) {
|
|
103
|
+
return { success: false }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const catItem = await factory.createRecord({
|
|
107
|
+
source: callExpression,
|
|
108
|
+
table: 'sc_cat_item',
|
|
109
|
+
explicitId: arg.get('$id'),
|
|
110
|
+
properties: arg.transform(({ $ }) => ({
|
|
111
|
+
...transformCatalogItemBaseFieldsToRecord($),
|
|
112
|
+
...transformCatalogItemSpecificFieldsToRecord(arg, $),
|
|
113
|
+
})),
|
|
114
|
+
})
|
|
115
|
+
const m2mRecords = await createSharedM2MRecords(callExpression, arg, catItem, factory)
|
|
116
|
+
let variableRecords: Record[] = []
|
|
117
|
+
if (arg.get('variables').isDefined()) {
|
|
118
|
+
const variablesConfig = arg.get('variables').asObject()
|
|
119
|
+
variableRecords = await buildVariableRecords({
|
|
120
|
+
variablesConfig,
|
|
121
|
+
factory,
|
|
122
|
+
parent: catItem,
|
|
123
|
+
diagnostics,
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
const pricingDetails = arg.get('pricingDetails').ifArray()?.getElements() ?? []
|
|
127
|
+
const pricingDetailsRecords: Record[] = []
|
|
128
|
+
for (const pricingDetail of pricingDetails) {
|
|
129
|
+
const pricingDetailObj = pricingDetail.asObject()
|
|
130
|
+
pricingDetailsRecords.push(
|
|
131
|
+
await factory.createRecord({
|
|
132
|
+
source: callExpression,
|
|
133
|
+
table: 'fx_price',
|
|
134
|
+
properties: {
|
|
135
|
+
id: catItem,
|
|
136
|
+
amount: pricingDetailObj.get('amount')?.getValue(),
|
|
137
|
+
currency: pricingDetailObj.get('currencyType')?.getValue(),
|
|
138
|
+
type: 'calculated',
|
|
139
|
+
field: pricingDetailObj.get('field')?.getValue(),
|
|
140
|
+
table: 'sc_cat_item',
|
|
141
|
+
},
|
|
142
|
+
})
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
success: true,
|
|
148
|
+
value: catItem.with(
|
|
149
|
+
...m2mRecords.catalogsRecords,
|
|
150
|
+
...m2mRecords.categoriesRecords,
|
|
151
|
+
...m2mRecords.variableSetRecords,
|
|
152
|
+
...m2mRecords.availableForRecords,
|
|
153
|
+
...m2mRecords.notAvailableForRecords,
|
|
154
|
+
...m2mRecords.assignedTopicsRecords,
|
|
155
|
+
...pricingDetailsRecords,
|
|
156
|
+
...variableRecords
|
|
157
|
+
),
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
})
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CallExpressionShape,
|
|
3
|
+
Plugin,
|
|
4
|
+
type Record,
|
|
5
|
+
PropertyAccessShape,
|
|
6
|
+
type TemplateExpressionShape,
|
|
7
|
+
} from '@servicenow/sdk-build-core'
|
|
8
|
+
import {
|
|
9
|
+
createVariablePropertyAccess,
|
|
10
|
+
createScript,
|
|
11
|
+
getTargetRecord,
|
|
12
|
+
resolveVariableAccess,
|
|
13
|
+
processCatalogCondition,
|
|
14
|
+
processCatalogConditionsToShape,
|
|
15
|
+
resolveCatalogReferences,
|
|
16
|
+
convertToNumber,
|
|
17
|
+
resolveAndValidateVariableId,
|
|
18
|
+
} from './utils'
|
|
19
|
+
import { NowIdShape } from '../now-id-plugin'
|
|
20
|
+
import {
|
|
21
|
+
APPLIES_TO_CATALOG_ITEM,
|
|
22
|
+
getUITypeFromId,
|
|
23
|
+
getUITypeId,
|
|
24
|
+
getValueActionFromDb,
|
|
25
|
+
getValueActionToDb,
|
|
26
|
+
} from './utils'
|
|
27
|
+
import { validateCatalogItemVariableSetExclusivity, validateUiPolicyActionMessage } from './service-catalog-diagnostics'
|
|
28
|
+
|
|
29
|
+
// Define table names as constants since they're not exported from the core tables
|
|
30
|
+
const CATALOG_UI_POLICY = 'catalog_ui_policy'
|
|
31
|
+
const CATALOG_UI_POLICY_ACTION = 'catalog_ui_policy_action'
|
|
32
|
+
const DEFAULT_SCRIPT = 'function onCondition() {\n\n}'
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Helper function to convert ServiceNow string format ('true'/'false'/'ignore') to boolean | 'ignore'
|
|
36
|
+
*/
|
|
37
|
+
const getBooleanOrIgnore = (action: Record, field: string): boolean | 'ignore' | undefined => {
|
|
38
|
+
const value = action.isRecord() ? action.asRecord() : action
|
|
39
|
+
if (value.get(field)?.ifString()?.getValue() === 'ignore' || value.get(field)?.ifString()?.isEmpty()) {
|
|
40
|
+
return 'ignore'
|
|
41
|
+
}
|
|
42
|
+
return value.get(field)?.toBoolean()?.getValue()
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Helper function to strip IO: prefix from variable names
|
|
46
|
+
*/
|
|
47
|
+
const stripIOPrefix = (value: string): string => {
|
|
48
|
+
return value.startsWith('IO:') ? value.substring(3) : value
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const CatalogUiPolicyPlugin = Plugin.create({
|
|
52
|
+
name: 'CatalogUiPolicyPlugin',
|
|
53
|
+
records: {
|
|
54
|
+
[CATALOG_UI_POLICY]: {
|
|
55
|
+
relationships: {
|
|
56
|
+
[CATALOG_UI_POLICY_ACTION]: {
|
|
57
|
+
via: 'ui_policy',
|
|
58
|
+
descendant: true,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
async toShape(record, { descendants, database, transform }) {
|
|
62
|
+
let processedConditions: string | TemplateExpressionShape | undefined
|
|
63
|
+
|
|
64
|
+
// Handle catalog_condition - convert variables to PropertyAccessShape in template expression
|
|
65
|
+
|
|
66
|
+
if (!record.get('catalog_conditions')?.ifString()?.isEmpty()) {
|
|
67
|
+
processedConditions = processCatalogConditionsToShape(record, database)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const { catalogItemReference, variableSetReference } = resolveCatalogReferences(record, database)
|
|
71
|
+
const actions = descendants.query(CATALOG_UI_POLICY_ACTION).map((action) => {
|
|
72
|
+
const variableValue = action.get('catalog_variable')?.ifString()?.getValue()
|
|
73
|
+
if (!variableValue) {
|
|
74
|
+
return {
|
|
75
|
+
success: false,
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const variableId = stripIOPrefix(variableValue)
|
|
79
|
+
const varRecord = database.get('item_option_new', variableId)
|
|
80
|
+
|
|
81
|
+
let variableName: PropertyAccessShape | string | undefined
|
|
82
|
+
if (varRecord?.isRecord()) {
|
|
83
|
+
const appliesToRecord = getTargetRecord(record, database)
|
|
84
|
+
variableName =
|
|
85
|
+
(appliesToRecord?.isRecord() &&
|
|
86
|
+
createVariablePropertyAccess(varRecord, record, appliesToRecord)) ||
|
|
87
|
+
variableId
|
|
88
|
+
} else {
|
|
89
|
+
variableName = variableId
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return action.transform(({ $ }) => {
|
|
93
|
+
const visible = getBooleanOrIgnore(action, 'visible')
|
|
94
|
+
const readOnly = getBooleanOrIgnore(action, 'disabled')
|
|
95
|
+
const mandatory = getBooleanOrIgnore(action, 'mandatory')
|
|
96
|
+
const cleared = action.get('cleared')?.toBoolean()?.getValue()
|
|
97
|
+
const variableMessage = action.get('field_message')?.ifString()?.getValue()
|
|
98
|
+
const variableMessageType = action.get('field_message_type')?.ifString()?.getValue()
|
|
99
|
+
const valueActionDb = action.get('value_action')?.ifString()?.getValue()
|
|
100
|
+
const valueAction = valueActionDb ? getValueActionFromDb(valueActionDb) : undefined
|
|
101
|
+
const order = convertToNumber(action.get('order'), 100)
|
|
102
|
+
const value = action.get('value')?.ifString()?.getValue()
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
variableName: $.val(variableName),
|
|
106
|
+
...(visible !== 'ignore' && visible !== undefined && { visible: $.val(visible) }),
|
|
107
|
+
...(readOnly !== 'ignore' && readOnly !== undefined && { readOnly: $.val(readOnly) }),
|
|
108
|
+
...(mandatory !== 'ignore' && mandatory !== undefined && { mandatory: $.val(mandatory) }),
|
|
109
|
+
...(cleared && { cleared: $.val(cleared) }),
|
|
110
|
+
...(variableMessageType &&
|
|
111
|
+
variableMessageType !== 'none' && {
|
|
112
|
+
variableMessageType: $.val(variableMessageType),
|
|
113
|
+
}),
|
|
114
|
+
...(variableMessage &&
|
|
115
|
+
variableMessageType !== 'none' && {
|
|
116
|
+
variableMessage: $.val(variableMessage),
|
|
117
|
+
}),
|
|
118
|
+
...(valueAction && { valueAction: $.val(valueAction) }),
|
|
119
|
+
...(order && order !== 100 && { order: $.val(order) }),
|
|
120
|
+
...(value && { value: $.val(value) }),
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
const executeIfTrue = await createScript(record, record.get('script_true'), transform, 'script-true')
|
|
126
|
+
const executeIfFalse = await createScript(record, record.get('script_false'), transform, 'script-false')
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
success: true,
|
|
130
|
+
value: new CallExpressionShape({
|
|
131
|
+
source: record,
|
|
132
|
+
callee: 'CatalogUiPolicy',
|
|
133
|
+
args: [
|
|
134
|
+
record.transform(({ $ }) => ({
|
|
135
|
+
$id: $.val(NowIdShape.from(record)),
|
|
136
|
+
appliesTo: $.from('applies_to').def(APPLIES_TO_CATALOG_ITEM),
|
|
137
|
+
catalogItem: $.val(catalogItemReference).def(''),
|
|
138
|
+
variableSet: $.val(variableSetReference).def(''),
|
|
139
|
+
shortDescription: $.from('short_description'),
|
|
140
|
+
active: $.toBoolean().def(true),
|
|
141
|
+
global: $.toBoolean().def(true),
|
|
142
|
+
onLoad: $.from('on_load').toBoolean().def(true),
|
|
143
|
+
reverseIfFalse: $.from('reverse_if_false').toBoolean().def(true),
|
|
144
|
+
inherit: $.toBoolean().def(false),
|
|
145
|
+
isolateScript: $.from('isolate_script').toBoolean().def(true),
|
|
146
|
+
conditions: $.def(''),
|
|
147
|
+
catalogCondition: $.val(processedConditions).def(''),
|
|
148
|
+
appliesOnCatalogItemView: $.from('applies_catalog').toBoolean().def(true),
|
|
149
|
+
appliesOnTargetRecord: $.from('applies_target_record').toBoolean().def(false),
|
|
150
|
+
appliesOnCatalogTasks: $.from('applies_sc_task').toBoolean().def(false),
|
|
151
|
+
appliesOnRequestedItems: $.from('applies_req_item').toBoolean().def(false),
|
|
152
|
+
runScripts: $.from('run_scripts').toBoolean().def(false),
|
|
153
|
+
executeIfTrue: $.val(executeIfTrue).def(DEFAULT_SCRIPT),
|
|
154
|
+
executeIfFalse: $.val(executeIfFalse).def(DEFAULT_SCRIPT),
|
|
155
|
+
description: $.from('description').def(''),
|
|
156
|
+
modelId: $.from('model_id').def(''),
|
|
157
|
+
modelTable: $.from('model_table').def(''),
|
|
158
|
+
order: $.map((c) => convertToNumber(c, 100)).def(100),
|
|
159
|
+
setValues: $.from('set_values').def(''),
|
|
160
|
+
vaSupported: $.from('va_supported').toBoolean().def(true),
|
|
161
|
+
view: $.from('view').def(''),
|
|
162
|
+
publishedRef: $.from('published_ref').def(''),
|
|
163
|
+
runScriptsInUiType: $.from('ui_type')
|
|
164
|
+
.map((v) =>
|
|
165
|
+
v.ifString()?.isEmpty() ? undefined : getUITypeFromId(v.toNumber()?.getValue())
|
|
166
|
+
)
|
|
167
|
+
.def('desktop'),
|
|
168
|
+
actions: $.val(actions.length > 0 ? actions : []).def([]),
|
|
169
|
+
})),
|
|
170
|
+
],
|
|
171
|
+
}),
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
[CATALOG_UI_POLICY_ACTION]: {
|
|
176
|
+
coalesce: ['ui_policy', 'catalog_variable'],
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
shapes: [
|
|
180
|
+
{
|
|
181
|
+
shape: CallExpressionShape,
|
|
182
|
+
fileTypes: ['fluent'],
|
|
183
|
+
async toRecord(callExpression, { diagnostics, factory }) {
|
|
184
|
+
if (callExpression.getCallee() !== 'CatalogUiPolicy') {
|
|
185
|
+
return { success: false }
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const arg = callExpression.getArgument(0).asObject()
|
|
189
|
+
|
|
190
|
+
// Validate catalogItem and variableSet are mutually exclusive
|
|
191
|
+
validateCatalogItemVariableSetExclusivity(arg, diagnostics, 'CatalogUiPolicy')
|
|
192
|
+
|
|
193
|
+
const catalogConditionShape = arg.get('catalogCondition')
|
|
194
|
+
let catalogConditionIO: string | TemplateExpressionShape | undefined
|
|
195
|
+
const appliedTo: 'set' | 'item' =
|
|
196
|
+
arg.get('appliesTo')?.toString()?.getValue() === 'set' ? 'set' : APPLIES_TO_CATALOG_ITEM
|
|
197
|
+
if (catalogConditionShape.isDefined()) {
|
|
198
|
+
catalogConditionIO = processCatalogCondition(
|
|
199
|
+
catalogConditionShape,
|
|
200
|
+
appliedTo,
|
|
201
|
+
arg.get('variableSet', false),
|
|
202
|
+
arg.get('catalogItem', false),
|
|
203
|
+
diagnostics
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Create the Catalog UI Policy record
|
|
208
|
+
const catalogUiPolicyRecord = await factory.createRecord({
|
|
209
|
+
source: callExpression,
|
|
210
|
+
table: CATALOG_UI_POLICY,
|
|
211
|
+
explicitId: arg.get('$id'),
|
|
212
|
+
properties: arg.transform(({ $ }) => ({
|
|
213
|
+
catalog_item: $.from('catalogItem').def(''),
|
|
214
|
+
variable_set: $.from('variableSet').def(''),
|
|
215
|
+
applies_to: $.from('appliesTo').def(APPLIES_TO_CATALOG_ITEM),
|
|
216
|
+
short_description: $.from('shortDescription'),
|
|
217
|
+
active: $.def(true),
|
|
218
|
+
global: $.def(true),
|
|
219
|
+
on_load: $.from('onLoad').def(true),
|
|
220
|
+
reverse_if_false: $.from('reverseIfFalse').def(true),
|
|
221
|
+
inherit: $.def(false),
|
|
222
|
+
isolate_script: $.from('isolateScript').def(true),
|
|
223
|
+
conditions: $.def(''),
|
|
224
|
+
catalog_conditions: $.val(catalogConditionIO).def(''),
|
|
225
|
+
applies_catalog: $.from('appliesOnCatalogItemView').def(true),
|
|
226
|
+
applies_target_record: $.from('appliesOnTargetRecord').def(false),
|
|
227
|
+
applies_sc_task: $.from('appliesOnCatalogTasks').def(false),
|
|
228
|
+
applies_req_item: $.from('appliesOnRequestedItems').def(false),
|
|
229
|
+
run_scripts: $.from('runScripts').def(false),
|
|
230
|
+
script_true: $.from('executeIfTrue').toCdata().def('function onCondition() {\n\n}'),
|
|
231
|
+
script_false: $.from('executeIfFalse').toCdata().def('function onCondition() {\n\n}'),
|
|
232
|
+
description: $.from('description').def(''),
|
|
233
|
+
model_id: $.from('modelId').def(''),
|
|
234
|
+
model_table: $.from('modelTable').def(''),
|
|
235
|
+
order: $.def(100),
|
|
236
|
+
set_values: $.from('setValues').def(''),
|
|
237
|
+
published_ref: $.from('publishedRef').def(''),
|
|
238
|
+
ui_type: $.from('runScriptsInUiType')
|
|
239
|
+
.map((v) => (v.isString() && !v.isEmpty() ? getUITypeId(v.getValue()) : undefined))
|
|
240
|
+
.def(0),
|
|
241
|
+
table: $.def(''),
|
|
242
|
+
va_supported: $.from('vaSupported').def(true),
|
|
243
|
+
view: $.def(''),
|
|
244
|
+
})),
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
// Process actions if they exist
|
|
248
|
+
const actions = arg.get('actions')?.ifArray()?.getElements() ?? []
|
|
249
|
+
const actionRecords: Record[] = []
|
|
250
|
+
if (actions?.length > 0) {
|
|
251
|
+
const variableNames = new Set<string>()
|
|
252
|
+
// Process each action sequentially
|
|
253
|
+
for (const action of actions) {
|
|
254
|
+
const actionObj = action.asObject()
|
|
255
|
+
|
|
256
|
+
// Validate variableMessageType/variableMessage consistency
|
|
257
|
+
validateUiPolicyActionMessage(actionObj, diagnostics)
|
|
258
|
+
|
|
259
|
+
const variableNameShape = actionObj.get('variableName', false)
|
|
260
|
+
|
|
261
|
+
// Resolve and validate catalog_variable
|
|
262
|
+
const catalogVariable = resolveAndValidateVariableId(
|
|
263
|
+
variableNameShape,
|
|
264
|
+
appliedTo,
|
|
265
|
+
arg.get('variableSet', false),
|
|
266
|
+
arg.get('catalogItem', false),
|
|
267
|
+
diagnostics
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
// Extract variable name for duplicate checking
|
|
271
|
+
let catalogVariableName: string | undefined
|
|
272
|
+
if (variableNameShape?.is(PropertyAccessShape)) {
|
|
273
|
+
const variableAccess = resolveVariableAccess(variableNameShape.as(PropertyAccessShape))
|
|
274
|
+
if (variableAccess) {
|
|
275
|
+
catalogVariableName = variableAccess.variableName
|
|
276
|
+
} else {
|
|
277
|
+
catalogVariableName = variableNameShape.toString()?.getValue()
|
|
278
|
+
}
|
|
279
|
+
} else {
|
|
280
|
+
catalogVariableName = variableNameShape?.toString()?.getValue()
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (catalogVariableName) {
|
|
284
|
+
if (variableNames.has(catalogVariableName)) {
|
|
285
|
+
diagnostics.error(
|
|
286
|
+
variableNameShape,
|
|
287
|
+
`Duplicate variableName '${catalogVariableName}' found in actions. Each action must have a unique variableName.`
|
|
288
|
+
)
|
|
289
|
+
}
|
|
290
|
+
variableNames.add(catalogVariableName)
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
actionRecords.push(
|
|
294
|
+
await factory.createRecord({
|
|
295
|
+
source: action, // Use the action as source instead of callExpression
|
|
296
|
+
table: CATALOG_UI_POLICY_ACTION,
|
|
297
|
+
properties: actionObj.transform(({ $ }) => ({
|
|
298
|
+
ui_policy: $.val(catalogUiPolicyRecord.getId()),
|
|
299
|
+
catalog_item: $.val(arg.get('catalogItem')?.toString()?.getValue() ?? ''),
|
|
300
|
+
variable_set: $.val(arg.get('variableSet')?.toString()?.getValue() ?? ''),
|
|
301
|
+
catalog_variable: $.val(catalogVariable).def(''),
|
|
302
|
+
variable: $.val(catalogVariableName).def(''),
|
|
303
|
+
visible: $.from('visible').def('ignore'),
|
|
304
|
+
disabled: $.from('readOnly').def('ignore'),
|
|
305
|
+
mandatory: $.from('mandatory').def('ignore'),
|
|
306
|
+
order: $.def(100),
|
|
307
|
+
cleared: $.from('cleared').toBoolean().def(false),
|
|
308
|
+
field_message: $.from('variableMessage').def(''),
|
|
309
|
+
field_message_type: $.from('variableMessageType').def('none'),
|
|
310
|
+
value: $.from('value').def(''),
|
|
311
|
+
value_action: $.from('valueAction')
|
|
312
|
+
.map((v) => getValueActionToDb(v.toString().getValue()))
|
|
313
|
+
.def('ignore'),
|
|
314
|
+
})),
|
|
315
|
+
})
|
|
316
|
+
)
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return { success: true, value: catalogUiPolicyRecord.with(...actionRecords) }
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
],
|
|
324
|
+
})
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { CallExpressionShape, type Record, type Database, type Logger } from '@servicenow/sdk-build-core'
|
|
2
|
+
import type { ExtendedChoices } from '@servicenow/sdk-core/service-catalog'
|
|
3
|
+
import { VARIABLE_TYPE_TO_NAME, VariableTypeName } from './variable-helper'
|
|
4
|
+
import { convertToNumber } from './utils'
|
|
5
|
+
import { buildVariableTransform } from './variables-transform'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Converts a ServiceNow variable record to a CallExpressionShape for code generation.
|
|
9
|
+
* This function queries the database for variable data and delegates transformation to buildVariableTransform.
|
|
10
|
+
*/
|
|
11
|
+
export function variableToCallExpression(variable: Record, descendants: Database, logger: Logger): CallExpressionShape {
|
|
12
|
+
const typeCode = variable.get('type').ifString()?.getValue() || ''
|
|
13
|
+
const callExpression = VARIABLE_TYPE_TO_NAME[typeCode]
|
|
14
|
+
if (!callExpression) {
|
|
15
|
+
throw new Error(`Unknown variable type: ${typeCode}`)
|
|
16
|
+
}
|
|
17
|
+
const choicesData: ExtendedChoices = {}
|
|
18
|
+
|
|
19
|
+
if (callExpression === VariableTypeName.MULTIPLE_CHOICE || callExpression === VariableTypeName.SELECT_BOX) {
|
|
20
|
+
const choices = descendants.query('question_choice', {
|
|
21
|
+
question: variable.getId()?.getValue(),
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
choices.forEach((choice) => {
|
|
25
|
+
const choicePriceDetails = descendants.query('fx_price', {
|
|
26
|
+
id: choice.getId()?.getValue(),
|
|
27
|
+
})
|
|
28
|
+
const choiceValue =
|
|
29
|
+
choice.get('value')?.ifString()?.getValue() ?? choice.get('value')?.ifNumber()?.getValue()
|
|
30
|
+
|
|
31
|
+
const pricingDetailsArray = choicePriceDetails.map((price) => {
|
|
32
|
+
const amount = convertToNumber(price.get('amount'), 0)
|
|
33
|
+
const currencyType = price.get('currency').ifString()?.getValue() || ''
|
|
34
|
+
const field = price.get('field').ifString()?.getValue() || ''
|
|
35
|
+
return { amount, currencyType, field }
|
|
36
|
+
})
|
|
37
|
+
if (choiceValue === undefined) {
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
choicesData[choiceValue] = {
|
|
41
|
+
label: choice.get('text').ifString()?.getValue() || '',
|
|
42
|
+
inactive: choice.get('inactive').toBoolean().getValue() || false,
|
|
43
|
+
sequence:
|
|
44
|
+
choice.get('order').ifString()?.isEmpty() || choice.get('order').isUndefined()
|
|
45
|
+
? 0
|
|
46
|
+
: choice.get('order').toNumber().getValue(),
|
|
47
|
+
...(pricingDetailsArray.length > 0 && { pricingDetails: pricingDetailsArray }),
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
const prices = descendants.query('fx_price', {
|
|
52
|
+
id: variable.getId()?.getValue(),
|
|
53
|
+
})
|
|
54
|
+
let varPricingDetails: { amount: number; currencyType: string; field: string }[] = []
|
|
55
|
+
if (callExpression === VariableTypeName.CHECKBOX) {
|
|
56
|
+
varPricingDetails = prices.map((price) => {
|
|
57
|
+
const amount = convertToNumber(price.get('amount'), 0)
|
|
58
|
+
const currencyType = price.get('currency').ifString()?.getValue() || ''
|
|
59
|
+
const field = price.get('field').ifString()?.getValue() || ''
|
|
60
|
+
return { amount, currencyType, field }
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Determine discriminated union types before transform
|
|
65
|
+
let qualifierType: 'dynamic' | 'advanced' | 'simple' = 'simple'
|
|
66
|
+
if (
|
|
67
|
+
callExpression === VariableTypeName.REFERENCE ||
|
|
68
|
+
callExpression === VariableTypeName.REQUESTED_FOR ||
|
|
69
|
+
callExpression === VariableTypeName.LIST_COLLECTOR
|
|
70
|
+
) {
|
|
71
|
+
const useRefQual = variable.get('use_reference_qualifier')?.ifString()?.getValue()
|
|
72
|
+
if (useRefQual === 'dynamic') {
|
|
73
|
+
qualifierType = 'dynamic'
|
|
74
|
+
} else if (useRefQual === 'advanced') {
|
|
75
|
+
qualifierType = 'advanced'
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let lookupSource: 'choices' | 'table' = 'table'
|
|
80
|
+
if (
|
|
81
|
+
callExpression === VariableTypeName.LOOKUP_SELECT_BOX ||
|
|
82
|
+
callExpression === VariableTypeName.LOOKUP_MULTIPLE_CHOICE
|
|
83
|
+
) {
|
|
84
|
+
const lookupSourceValue = variable.get('lookup_source')?.ifString()?.getValue()
|
|
85
|
+
if (lookupSourceValue === 'choices') {
|
|
86
|
+
lookupSource = 'choices'
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return new CallExpressionShape({
|
|
91
|
+
source: variable,
|
|
92
|
+
callee: callExpression,
|
|
93
|
+
args: [
|
|
94
|
+
variable.transform(({ $ }) =>
|
|
95
|
+
buildVariableTransform(
|
|
96
|
+
callExpression,
|
|
97
|
+
$,
|
|
98
|
+
{
|
|
99
|
+
choicesData,
|
|
100
|
+
varPricingDetails,
|
|
101
|
+
qualifierType,
|
|
102
|
+
lookupSource,
|
|
103
|
+
},
|
|
104
|
+
logger
|
|
105
|
+
)
|
|
106
|
+
),
|
|
107
|
+
],
|
|
108
|
+
})
|
|
109
|
+
}
|