@servicenow/sdk-build-plugins 4.4.1 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acl-plugin.js +54 -4
- package/dist/acl-plugin.js.map +1 -1
- package/dist/applicability-plugin.js +2 -0
- package/dist/applicability-plugin.js.map +1 -1
- package/dist/application-menu-plugin.js +2 -0
- package/dist/application-menu-plugin.js.map +1 -1
- package/dist/arrow-function-plugin.d.ts +6 -1
- package/dist/arrow-function-plugin.js +105 -12
- package/dist/arrow-function-plugin.js.map +1 -1
- package/dist/atf/test-plugin.js +2 -0
- package/dist/atf/test-plugin.js.map +1 -1
- package/dist/basic-syntax-plugin.js +20 -0
- package/dist/basic-syntax-plugin.js.map +1 -1
- package/dist/call-expression-plugin.js +1 -0
- package/dist/call-expression-plugin.js.map +1 -1
- package/dist/claims-plugin.js +1 -0
- package/dist/claims-plugin.js.map +1 -1
- package/dist/client-script-plugin.js +1 -0
- package/dist/client-script-plugin.js.map +1 -1
- package/dist/column-plugin.js +4 -7
- package/dist/column-plugin.js.map +1 -1
- package/dist/cross-scope-privilege-plugin.js +1 -0
- package/dist/cross-scope-privilege-plugin.js.map +1 -1
- package/dist/dashboard/dashboard-plugin.js +2 -0
- package/dist/dashboard/dashboard-plugin.js.map +1 -1
- package/dist/data-plugin.js +1 -0
- package/dist/data-plugin.js.map +1 -1
- package/dist/email-notification-plugin.js +9 -13
- package/dist/email-notification-plugin.js.map +1 -1
- package/dist/flow/constants/flow-plugin-constants.d.ts +1 -1
- package/dist/flow/constants/flow-plugin-constants.js +1 -1
- package/dist/flow/constants/flow-plugin-constants.js.map +1 -1
- package/dist/flow/flow-logic/flow-logic-diagnostics.js +5 -5
- package/dist/flow/flow-logic/flow-logic-diagnostics.js.map +1 -1
- package/dist/flow/flow-logic/flow-logic-plugin-helpers.d.ts +82 -2
- package/dist/flow/flow-logic/flow-logic-plugin-helpers.js +48 -40
- package/dist/flow/flow-logic/flow-logic-plugin-helpers.js.map +1 -1
- package/dist/flow/flow-logic/flow-logic-plugin.js +1 -0
- package/dist/flow/flow-logic/flow-logic-plugin.js.map +1 -1
- package/dist/flow/plugins/approval-rules-plugin.js +1 -0
- package/dist/flow/plugins/approval-rules-plugin.js.map +1 -1
- package/dist/flow/plugins/flow-action-definition-plugin.js +1232 -55
- package/dist/flow/plugins/flow-action-definition-plugin.js.map +1 -1
- package/dist/flow/plugins/flow-data-pill-plugin.js +6 -2
- package/dist/flow/plugins/flow-data-pill-plugin.js.map +1 -1
- package/dist/flow/plugins/flow-definition-plugin.js +23 -44
- package/dist/flow/plugins/flow-definition-plugin.js.map +1 -1
- package/dist/flow/plugins/flow-diagnostics-plugin.d.ts +2 -2
- package/dist/flow/plugins/flow-diagnostics-plugin.js +3 -2
- package/dist/flow/plugins/flow-diagnostics-plugin.js.map +1 -1
- package/dist/flow/plugins/flow-instance-plugin.js +136 -34
- package/dist/flow/plugins/flow-instance-plugin.js.map +1 -1
- package/dist/flow/plugins/flow-trigger-instance-plugin.js +1 -0
- package/dist/flow/plugins/flow-trigger-instance-plugin.js.map +1 -1
- package/dist/flow/plugins/inline-script-plugin.js +1 -0
- package/dist/flow/plugins/inline-script-plugin.js.map +1 -1
- package/dist/flow/plugins/step-definition-plugin.js +4 -2
- package/dist/flow/plugins/step-definition-plugin.js.map +1 -1
- package/dist/flow/plugins/step-instance-plugin.d.ts +9 -1
- package/dist/flow/plugins/step-instance-plugin.js +649 -135
- package/dist/flow/plugins/step-instance-plugin.js.map +1 -1
- package/dist/flow/plugins/trigger-plugin.js +2 -0
- package/dist/flow/plugins/trigger-plugin.js.map +1 -1
- package/dist/flow/plugins/wfa-datapill-plugin.js +21 -5
- package/dist/flow/plugins/wfa-datapill-plugin.js.map +1 -1
- package/dist/flow/post-install.d.ts +2 -0
- package/dist/flow/post-install.js +59 -0
- package/dist/flow/post-install.js.map +1 -0
- package/dist/flow/utils/complex-object-resolver.js +4 -1
- package/dist/flow/utils/complex-object-resolver.js.map +1 -1
- package/dist/flow/utils/complex-objects.js +5 -3
- package/dist/flow/utils/complex-objects.js.map +1 -1
- package/dist/flow/utils/flow-constants.d.ts +90 -2
- package/dist/flow/utils/flow-constants.js +430 -7
- package/dist/flow/utils/flow-constants.js.map +1 -1
- package/dist/flow/utils/flow-io-to-record.d.ts +1 -1
- package/dist/flow/utils/flow-io-to-record.js +37 -16
- package/dist/flow/utils/flow-io-to-record.js.map +1 -1
- package/dist/flow/utils/flow-shapes.js +4 -0
- package/dist/flow/utils/flow-shapes.js.map +1 -1
- package/dist/flow/utils/flow-to-xml.d.ts +3 -2
- package/dist/flow/utils/flow-to-xml.js +3 -4
- package/dist/flow/utils/flow-to-xml.js.map +1 -1
- package/dist/flow/utils/label-cache-parser.d.ts +9 -2
- package/dist/flow/utils/label-cache-parser.js +32 -4
- package/dist/flow/utils/label-cache-parser.js.map +1 -1
- package/dist/flow/utils/label-cache-processor.d.ts +5 -0
- package/dist/flow/utils/label-cache-processor.js +14 -2
- package/dist/flow/utils/label-cache-processor.js.map +1 -1
- package/dist/flow/utils/pill-shape-helpers.d.ts +15 -0
- package/dist/flow/utils/pill-shape-helpers.js +35 -0
- package/dist/flow/utils/pill-shape-helpers.js.map +1 -0
- package/dist/flow/utils/pill-string-parser.js +1 -0
- package/dist/flow/utils/pill-string-parser.js.map +1 -1
- package/dist/flow/utils/schema-to-flow-object.d.ts +6 -1
- package/dist/flow/utils/schema-to-flow-object.js +131 -15
- package/dist/flow/utils/schema-to-flow-object.js.map +1 -1
- package/dist/flow/utils/service-catalog.js +5 -1
- package/dist/flow/utils/service-catalog.js.map +1 -1
- package/dist/flow/utils/utils.d.ts +1 -0
- package/dist/flow/utils/utils.js +6 -1
- package/dist/flow/utils/utils.js.map +1 -1
- package/dist/form-plugin.d.ts +2 -0
- package/dist/form-plugin.js +1132 -0
- package/dist/form-plugin.js.map +1 -0
- package/dist/html-import-plugin.js +1 -0
- package/dist/html-import-plugin.js.map +1 -1
- package/dist/import-sets-plugin.js +2 -0
- package/dist/import-sets-plugin.js.map +1 -1
- package/dist/inbound-email-action-plugin.d.ts +10 -0
- package/dist/inbound-email-action-plugin.js +128 -0
- package/dist/inbound-email-action-plugin.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -1
- package/dist/instance-scan-plugin.d.ts +2 -0
- package/dist/instance-scan-plugin.js +293 -0
- package/dist/instance-scan-plugin.js.map +1 -0
- package/dist/json-plugin.js +1 -0
- package/dist/json-plugin.js.map +1 -1
- package/dist/list-plugin.js +1 -0
- package/dist/list-plugin.js.map +1 -1
- package/dist/now-attach-plugin.js +1 -0
- package/dist/now-attach-plugin.js.map +1 -1
- package/dist/now-config-plugin.js +659 -51
- package/dist/now-config-plugin.js.map +1 -1
- package/dist/now-id-plugin.js +1 -0
- package/dist/now-id-plugin.js.map +1 -1
- package/dist/now-include-plugin.js +1 -0
- package/dist/now-include-plugin.js.map +1 -1
- package/dist/now-ref-plugin.js +1 -0
- package/dist/now-ref-plugin.js.map +1 -1
- package/dist/now-unresolved-plugin.js +1 -0
- package/dist/now-unresolved-plugin.js.map +1 -1
- package/dist/package-json-plugin.js +1 -0
- package/dist/package-json-plugin.js.map +1 -1
- package/dist/property-plugin.js +3 -1
- package/dist/property-plugin.js.map +1 -1
- package/dist/record-plugin.d.ts +37 -0
- package/dist/record-plugin.js +47 -3
- package/dist/record-plugin.js.map +1 -1
- package/dist/repack/lint/Rules.d.ts +11 -2
- package/dist/repack/lint/Rules.js +160 -16
- package/dist/repack/lint/Rules.js.map +1 -1
- package/dist/repack/lint/index.d.ts +10 -5
- package/dist/repack/lint/index.js +76 -50
- package/dist/repack/lint/index.js.map +1 -1
- package/dist/rest-api-plugin.js +22 -1
- package/dist/rest-api-plugin.js.map +1 -1
- package/dist/role-plugin.js +1 -0
- package/dist/role-plugin.js.map +1 -1
- package/dist/schedule-script/index.d.ts +1 -0
- package/dist/schedule-script/index.js +18 -0
- package/dist/schedule-script/index.js.map +1 -0
- package/dist/schedule-script/scheduled-script-plugin.d.ts +2 -0
- package/dist/schedule-script/scheduled-script-plugin.js +556 -0
- package/dist/schedule-script/scheduled-script-plugin.js.map +1 -0
- package/dist/schedule-script/timeZoneConverter.d.ts +61 -0
- package/dist/schedule-script/timeZoneConverter.js +170 -0
- package/dist/schedule-script/timeZoneConverter.js.map +1 -0
- package/dist/script-action-plugin.js +2 -0
- package/dist/script-action-plugin.js.map +1 -1
- package/dist/script-include-plugin.js +2 -0
- package/dist/script-include-plugin.js.map +1 -1
- package/dist/server-module-plugin/index.js +13 -2
- package/dist/server-module-plugin/index.js.map +1 -1
- package/dist/service-catalog/catalog-clientscript-plugin.js +2 -0
- package/dist/service-catalog/catalog-clientscript-plugin.js.map +1 -1
- package/dist/service-catalog/catalog-item-plugin.js +2 -0
- package/dist/service-catalog/catalog-item-plugin.js.map +1 -1
- package/dist/service-catalog/catalog-ui-policy-plugin.js +2 -0
- package/dist/service-catalog/catalog-ui-policy-plugin.js.map +1 -1
- package/dist/service-catalog/sc-record-producer-plugin.js +2 -0
- package/dist/service-catalog/sc-record-producer-plugin.js.map +1 -1
- package/dist/service-catalog/service-catalog-base.d.ts +18 -18
- package/dist/service-catalog/service-catalog-base.js +22 -22
- package/dist/service-catalog/service-catalog-base.js.map +1 -1
- package/dist/service-catalog/service-catalog-diagnostics.d.ts +6 -0
- package/dist/service-catalog/service-catalog-diagnostics.js +20 -0
- package/dist/service-catalog/service-catalog-diagnostics.js.map +1 -1
- package/dist/service-catalog/shape-to-record.js +7 -2
- package/dist/service-catalog/shape-to-record.js.map +1 -1
- package/dist/service-catalog/variable-set-plugin.js +2 -0
- package/dist/service-catalog/variable-set-plugin.js.map +1 -1
- package/dist/service-portal/angular-provider-plugin.js +2 -0
- package/dist/service-portal/angular-provider-plugin.js.map +1 -1
- package/dist/service-portal/dependency-plugin.js +5 -31
- package/dist/service-portal/dependency-plugin.js.map +1 -1
- package/dist/service-portal/header-footer-plugin.d.ts +2 -0
- package/dist/service-portal/header-footer-plugin.js +50 -0
- package/dist/service-portal/header-footer-plugin.js.map +1 -0
- package/dist/service-portal/menu-plugin.d.ts +2 -0
- package/dist/service-portal/menu-plugin.js +334 -0
- package/dist/service-portal/menu-plugin.js.map +1 -0
- package/dist/service-portal/page-plugin.d.ts +2 -0
- package/dist/service-portal/page-plugin.js +681 -0
- package/dist/service-portal/page-plugin.js.map +1 -0
- package/dist/service-portal/page-route-map-plugin.d.ts +2 -0
- package/dist/service-portal/page-route-map-plugin.js +114 -0
- package/dist/service-portal/page-route-map-plugin.js.map +1 -0
- package/dist/service-portal/portal-plugin.d.ts +2 -0
- package/dist/service-portal/portal-plugin.js +309 -0
- package/dist/service-portal/portal-plugin.js.map +1 -0
- package/dist/service-portal/theme-plugin.d.ts +2 -0
- package/dist/service-portal/theme-plugin.js +112 -0
- package/dist/service-portal/theme-plugin.js.map +1 -0
- package/dist/service-portal/utils.d.ts +46 -0
- package/dist/service-portal/utils.js +331 -0
- package/dist/service-portal/utils.js.map +1 -0
- package/dist/service-portal/widget-plugin.js +10 -182
- package/dist/service-portal/widget-plugin.js.map +1 -1
- package/dist/sla-plugin.js +2 -0
- package/dist/sla-plugin.js.map +1 -1
- package/dist/static-content-plugin.js +5 -0
- package/dist/static-content-plugin.js.map +1 -1
- package/dist/table-plugin.js +191 -26
- package/dist/table-plugin.js.map +1 -1
- package/dist/ui-action-plugin.js +3 -4
- package/dist/ui-action-plugin.js.map +1 -1
- package/dist/ui-page-plugin.js +101 -21
- package/dist/ui-page-plugin.js.map +1 -1
- package/dist/ui-policy-plugin.js +1 -0
- package/dist/ui-policy-plugin.js.map +1 -1
- package/dist/user-preference-plugin.js +2 -0
- package/dist/user-preference-plugin.js.map +1 -1
- package/dist/utils.d.ts +20 -2
- package/dist/utils.js +34 -3
- package/dist/utils.js.map +1 -1
- package/dist/ux-list-menu-config-plugin.js +2 -0
- package/dist/ux-list-menu-config-plugin.js.map +1 -1
- package/dist/view-plugin.js +9 -3
- package/dist/view-plugin.js.map +1 -1
- package/dist/workspace-plugin.js +41 -36
- package/dist/workspace-plugin.js.map +1 -1
- package/package.json +11 -11
- package/src/_types/eslint-community-eslint-utils.d.ts +15 -0
- package/src/acl-plugin.ts +97 -8
- package/src/applicability-plugin.ts +2 -0
- package/src/application-menu-plugin.ts +2 -0
- package/src/arrow-function-plugin.ts +128 -13
- package/src/atf/test-plugin.ts +2 -0
- package/src/basic-syntax-plugin.ts +21 -0
- package/src/call-expression-plugin.ts +1 -0
- package/src/claims-plugin.ts +1 -0
- package/src/client-script-plugin.ts +2 -1
- package/src/column-plugin.ts +4 -8
- package/src/cross-scope-privilege-plugin.ts +2 -1
- package/src/dashboard/dashboard-plugin.ts +2 -0
- package/src/data-plugin.ts +1 -0
- package/src/email-notification-plugin.ts +3 -23
- package/src/flow/constants/flow-plugin-constants.ts +1 -1
- package/src/flow/flow-logic/flow-logic-diagnostics.ts +5 -6
- package/src/flow/flow-logic/flow-logic-plugin-helpers.ts +47 -45
- package/src/flow/flow-logic/flow-logic-plugin.ts +1 -0
- package/src/flow/plugins/approval-rules-plugin.ts +1 -0
- package/src/flow/plugins/flow-action-definition-plugin.ts +1584 -62
- package/src/flow/plugins/flow-data-pill-plugin.ts +6 -2
- package/src/flow/plugins/flow-definition-plugin.ts +22 -51
- package/src/flow/plugins/flow-diagnostics-plugin.ts +3 -2
- package/src/flow/plugins/flow-instance-plugin.ts +201 -36
- package/src/flow/plugins/flow-trigger-instance-plugin.ts +1 -0
- package/src/flow/plugins/inline-script-plugin.ts +1 -0
- package/src/flow/plugins/step-definition-plugin.ts +4 -2
- package/src/flow/plugins/step-instance-plugin.ts +772 -155
- package/src/flow/plugins/trigger-plugin.ts +2 -0
- package/src/flow/plugins/wfa-datapill-plugin.ts +26 -5
- package/src/flow/post-install.ts +93 -0
- package/src/flow/utils/complex-object-resolver.ts +4 -1
- package/src/flow/utils/complex-objects.ts +11 -3
- package/src/flow/utils/flow-constants.ts +451 -6
- package/src/flow/utils/flow-io-to-record.ts +43 -17
- package/src/flow/utils/flow-shapes.ts +4 -0
- package/src/flow/utils/flow-to-xml.ts +4 -4
- package/src/flow/utils/label-cache-parser.ts +33 -4
- package/src/flow/utils/label-cache-processor.ts +14 -2
- package/src/flow/utils/pill-shape-helpers.ts +42 -0
- package/src/flow/utils/pill-string-parser.ts +1 -0
- package/src/flow/utils/schema-to-flow-object.ts +183 -15
- package/src/flow/utils/service-catalog.ts +5 -2
- package/src/flow/utils/utils.ts +12 -1
- package/src/form-plugin.ts +1409 -0
- package/src/html-import-plugin.ts +1 -0
- package/src/import-sets-plugin.ts +2 -0
- package/src/inbound-email-action-plugin.ts +145 -0
- package/src/index.ts +13 -0
- package/src/instance-scan-plugin.ts +313 -0
- package/src/json-plugin.ts +1 -0
- package/src/list-plugin.ts +2 -1
- package/src/now-attach-plugin.ts +1 -0
- package/src/now-config-plugin.ts +833 -53
- package/src/now-id-plugin.ts +1 -0
- package/src/now-include-plugin.ts +1 -0
- package/src/now-ref-plugin.ts +1 -0
- package/src/now-unresolved-plugin.ts +1 -0
- package/src/package-json-plugin.ts +1 -0
- package/src/property-plugin.ts +6 -1
- package/src/record-plugin.ts +56 -6
- package/src/repack/lint/Rules.ts +171 -22
- package/src/repack/lint/index.ts +80 -56
- package/src/rest-api-plugin.ts +28 -2
- package/src/role-plugin.ts +2 -1
- package/src/schedule-script/index.ts +1 -0
- package/src/schedule-script/scheduled-script-plugin.ts +690 -0
- package/src/schedule-script/timeZoneConverter.ts +188 -0
- package/src/script-action-plugin.ts +2 -0
- package/src/script-include-plugin.ts +2 -0
- package/src/server-module-plugin/index.ts +14 -2
- package/src/service-catalog/catalog-clientscript-plugin.ts +2 -0
- package/src/service-catalog/catalog-item-plugin.ts +2 -0
- package/src/service-catalog/catalog-ui-policy-plugin.ts +2 -0
- package/src/service-catalog/sc-record-producer-plugin.ts +2 -0
- package/src/service-catalog/service-catalog-base.ts +22 -22
- package/src/service-catalog/service-catalog-diagnostics.ts +30 -0
- package/src/service-catalog/shape-to-record.ts +8 -2
- package/src/service-catalog/variable-set-plugin.ts +2 -0
- package/src/service-portal/angular-provider-plugin.ts +2 -0
- package/src/service-portal/dependency-plugin.ts +6 -53
- package/src/service-portal/header-footer-plugin.ts +57 -0
- package/src/service-portal/menu-plugin.ts +413 -0
- package/src/service-portal/page-plugin.ts +805 -0
- package/src/service-portal/page-route-map-plugin.ts +124 -0
- package/src/service-portal/portal-plugin.ts +342 -0
- package/src/service-portal/theme-plugin.ts +135 -0
- package/src/service-portal/utils.ts +470 -0
- package/src/service-portal/widget-plugin.ts +18 -224
- package/src/sla-plugin.ts +2 -0
- package/src/static-content-plugin.ts +4 -0
- package/src/table-plugin.ts +228 -37
- package/src/ui-action-plugin.ts +3 -8
- package/src/ui-page-plugin.ts +110 -21
- package/src/ui-policy-plugin.ts +2 -1
- package/src/user-preference-plugin.ts +2 -0
- package/src/utils.ts +42 -2
- package/src/ux-list-menu-config-plugin.ts +2 -0
- package/src/view-plugin.ts +11 -4
- package/src/workspace-plugin.ts +45 -43
- package/src/_types/eslint-plugin-es-x.d.ts +0 -17
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
import { NowIncludeShape } from '../now-include-plugin'
|
|
2
|
+
import {
|
|
3
|
+
type Record,
|
|
4
|
+
Shape,
|
|
5
|
+
type RecordId,
|
|
6
|
+
type Diagnostics,
|
|
7
|
+
type Factory,
|
|
8
|
+
CallExpressionShape,
|
|
9
|
+
isGUID,
|
|
10
|
+
} from '@servicenow/sdk-build-core'
|
|
11
|
+
import { noThrow, reverseObject } from '../utils'
|
|
12
|
+
import { WidgetCategories } from '@servicenow/sdk-core/runtime/service-portal'
|
|
13
|
+
import { NowIdShape } from '../now-id-plugin'
|
|
14
|
+
|
|
15
|
+
function convertOptionSchemaKeys(optionSchema: unknown, convertKey: (key: string) => string): unknown {
|
|
16
|
+
if (!Array.isArray(optionSchema)) {
|
|
17
|
+
return optionSchema
|
|
18
|
+
}
|
|
19
|
+
return optionSchema.map((option: globalThis.Record<string, unknown>) =>
|
|
20
|
+
Object.fromEntries(Object.entries(option).map(([k, v]) => [convertKey(k), v]))
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const toCamelCase = (key: string) => key.replace(/_([a-z])/g, (_, c: string) => c.toUpperCase())
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Shared toShape implementation for SPWidget and SPHeaderFooter
|
|
28
|
+
*/
|
|
29
|
+
export async function createWidgetToShape(
|
|
30
|
+
record: Record,
|
|
31
|
+
descendants: { query: (table: string) => Record[] },
|
|
32
|
+
callee: 'SPWidget' | 'SPHeaderFooter',
|
|
33
|
+
tablePrefix: string = 'sp_widget',
|
|
34
|
+
includeStaticField: boolean = false
|
|
35
|
+
) {
|
|
36
|
+
const folderName =
|
|
37
|
+
record.get('id')?.asString()?.getValue()?.replace(/[\s-]/g, '_') ||
|
|
38
|
+
record.get('name')?.asString()?.getValue()?.toLowerCase().replace(/[\s-]/g, '_')
|
|
39
|
+
const dependencies = descendants.query('m2m_sp_widget_dependency')
|
|
40
|
+
const angularProviders = descendants.query('m2m_sp_ng_pro_sp_widget')
|
|
41
|
+
const templates = descendants.query('sp_ng_template').map((template) => {
|
|
42
|
+
return {
|
|
43
|
+
$id: template.getId(),
|
|
44
|
+
id: template.get('id'),
|
|
45
|
+
htmlTemplate: template.get('template'),
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
const category = reverseObject(WidgetCategories)[record.get('category').ifString()?.getValue() || '']
|
|
50
|
+
const serverScript = await createIncludeShape(
|
|
51
|
+
record,
|
|
52
|
+
record.get('script'),
|
|
53
|
+
'server_script',
|
|
54
|
+
'js',
|
|
55
|
+
folderName,
|
|
56
|
+
tablePrefix
|
|
57
|
+
)
|
|
58
|
+
const clientScript = await createIncludeShape(
|
|
59
|
+
record,
|
|
60
|
+
record.get('client_script'),
|
|
61
|
+
'client_script',
|
|
62
|
+
'js',
|
|
63
|
+
folderName,
|
|
64
|
+
tablePrefix
|
|
65
|
+
)
|
|
66
|
+
const css = await createIncludeShape(record, record.get('css'), 'style', 'scss', folderName, tablePrefix)
|
|
67
|
+
const htmlTemplate = await createIncludeShape(
|
|
68
|
+
record,
|
|
69
|
+
record.get('template'),
|
|
70
|
+
'template',
|
|
71
|
+
'html',
|
|
72
|
+
folderName,
|
|
73
|
+
tablePrefix
|
|
74
|
+
)
|
|
75
|
+
const linkScript = await createIncludeShape(
|
|
76
|
+
record,
|
|
77
|
+
record.get('link'),
|
|
78
|
+
'link-script',
|
|
79
|
+
'js',
|
|
80
|
+
folderName,
|
|
81
|
+
tablePrefix
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
success: true,
|
|
86
|
+
value: new CallExpressionShape({
|
|
87
|
+
source: record,
|
|
88
|
+
callee,
|
|
89
|
+
args: [
|
|
90
|
+
record.transform(({ $ }) => {
|
|
91
|
+
const baseTransform = {
|
|
92
|
+
$id: $.val(NowIdShape.from(record)),
|
|
93
|
+
name: $,
|
|
94
|
+
category: $.val(category).def('custom'),
|
|
95
|
+
clientScript: $.val(clientScript).def(''),
|
|
96
|
+
serverScript: $.val(serverScript).def(''),
|
|
97
|
+
controllerAs: $.from('controller_as').def('c'),
|
|
98
|
+
htmlTemplate: $.val(htmlTemplate).def(''),
|
|
99
|
+
customCss: $.val(css).def(''),
|
|
100
|
+
dataTable: $.from('data_table')
|
|
101
|
+
.map((v: Shape) => {
|
|
102
|
+
const val = v.ifString()?.getValue()
|
|
103
|
+
return val && val.trim() !== '' ? val : 'sp_instance'
|
|
104
|
+
})
|
|
105
|
+
.def('sp_instance'),
|
|
106
|
+
demoData: $.from('demo_data')
|
|
107
|
+
.map((d: Shape) => {
|
|
108
|
+
const json = d.ifString()?.getValue()
|
|
109
|
+
|
|
110
|
+
const parsed = noThrow(() => json && JSON.parse(json))
|
|
111
|
+
return parsed instanceof Error ? json : parsed
|
|
112
|
+
})
|
|
113
|
+
.def(''),
|
|
114
|
+
description: $.def(''),
|
|
115
|
+
docs: $.def(''),
|
|
116
|
+
fields: $.from('field_list')
|
|
117
|
+
.map((fields: Shape) => {
|
|
118
|
+
const fieldStr = fields.ifString()?.getValue()
|
|
119
|
+
const fieldArray = fieldStr?.split(',').filter((f: string) => f.trim())
|
|
120
|
+
return fieldArray && fieldArray.length > 0 ? fieldArray : undefined
|
|
121
|
+
})
|
|
122
|
+
.def(undefined),
|
|
123
|
+
hasPreview: $.from('has_preview').toBoolean().def(false),
|
|
124
|
+
id: $.def(''),
|
|
125
|
+
internal: $.toBoolean().def(false),
|
|
126
|
+
linkScript: $.val(linkScript).def(''),
|
|
127
|
+
roles: $.map((role: Shape) => {
|
|
128
|
+
const roleStr = role.ifString()?.getValue()
|
|
129
|
+
const roleArray = roleStr?.split(',').filter((r: string) => r.trim())
|
|
130
|
+
return roleArray && roleArray.length > 0 ? roleArray : undefined
|
|
131
|
+
}).def(undefined),
|
|
132
|
+
servicenow: $.toBoolean().def(false),
|
|
133
|
+
optionSchema: $.from('option_schema')
|
|
134
|
+
.map((v: Shape) => {
|
|
135
|
+
const json = v.ifString()?.getValue()
|
|
136
|
+
const parsed = noThrow(() => json && JSON.parse(json))
|
|
137
|
+
const result = parsed instanceof Error ? json : parsed
|
|
138
|
+
return convertOptionSchemaKeys(result, toCamelCase)
|
|
139
|
+
})
|
|
140
|
+
.def(''),
|
|
141
|
+
public: $.toBoolean().def(false),
|
|
142
|
+
dependencies: $.val(
|
|
143
|
+
dependencies.length > 0 ? dependencies.map((dep) => dep.get('sp_dependency')) : undefined
|
|
144
|
+
),
|
|
145
|
+
angularProviders: $.val(
|
|
146
|
+
angularProviders.length > 0
|
|
147
|
+
? angularProviders.map((ap) => ap.get('sp_angular_provider'))
|
|
148
|
+
: undefined
|
|
149
|
+
),
|
|
150
|
+
templates: $.val(templates.length > 0 ? templates : undefined),
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return includeStaticField
|
|
154
|
+
? { ...baseTransform, static: $.from('static').toBoolean().def(false) }
|
|
155
|
+
: baseTransform
|
|
156
|
+
}),
|
|
157
|
+
],
|
|
158
|
+
}),
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Creates a NowIncludeShape with a custom file path suffix and extension
|
|
164
|
+
*/
|
|
165
|
+
export async function createIncludeShape(
|
|
166
|
+
record: Record,
|
|
167
|
+
content: string | Shape,
|
|
168
|
+
suffix: string,
|
|
169
|
+
extension: 'js' | 'html' | 'scss',
|
|
170
|
+
folderName: string,
|
|
171
|
+
tablePrefix: string = 'sp_widget'
|
|
172
|
+
): Promise<NowIncludeShape> {
|
|
173
|
+
const baseName = `${tablePrefix}_${folderName}`
|
|
174
|
+
const includedText = content instanceof Shape ? content.toString().getValue() : content
|
|
175
|
+
|
|
176
|
+
return new NowIncludeShape({
|
|
177
|
+
source: record,
|
|
178
|
+
path: `./${baseName}/${suffix}.${extension}`,
|
|
179
|
+
includedText,
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export const DEFAULT_ORDER = 100
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Shared toRecord implementation for SPWidget and SPHeaderFooter
|
|
187
|
+
*/
|
|
188
|
+
export async function createWidgetToRecord(
|
|
189
|
+
callExpression: CallExpressionShape,
|
|
190
|
+
{
|
|
191
|
+
diagnostics,
|
|
192
|
+
factory,
|
|
193
|
+
config,
|
|
194
|
+
}: {
|
|
195
|
+
diagnostics: Diagnostics
|
|
196
|
+
factory: Factory
|
|
197
|
+
config: { scope: string }
|
|
198
|
+
},
|
|
199
|
+
options: {
|
|
200
|
+
callee: 'SPWidget' | 'SPHeaderFooter'
|
|
201
|
+
table: 'sp_widget' | 'sp_header_footer'
|
|
202
|
+
includeStaticField?: boolean
|
|
203
|
+
getDefaultClientScript: (controller: string) => string
|
|
204
|
+
defaultServerScript: string
|
|
205
|
+
defaultLinkScript: string
|
|
206
|
+
defaultHtmlTemplate: string
|
|
207
|
+
}
|
|
208
|
+
) {
|
|
209
|
+
const { table, includeStaticField = false } = options
|
|
210
|
+
const widget = callExpression.getArgument(0).asObject()
|
|
211
|
+
const dependencies =
|
|
212
|
+
widget
|
|
213
|
+
.get('dependencies')
|
|
214
|
+
.ifArray()
|
|
215
|
+
?.map((dep) => (dep.isString() ? dep.getValue() : dep.ifRecord()?.getId()))
|
|
216
|
+
.filter((dep) => dep) ?? []
|
|
217
|
+
const angularProviders =
|
|
218
|
+
widget
|
|
219
|
+
.get('angularProviders')
|
|
220
|
+
.ifArray()
|
|
221
|
+
?.map((ap) => (ap.isString() ? ap.getValue() : ap.ifRecord()?.getId()))
|
|
222
|
+
.filter((ap) => ap) ?? []
|
|
223
|
+
|
|
224
|
+
const templates: Array<{ $id: string; id: unknown; htmlTemplate: unknown }> =
|
|
225
|
+
widget
|
|
226
|
+
.get('templates')
|
|
227
|
+
.ifArray()
|
|
228
|
+
?.map((shp) => shp.getValue() as { $id: string; id: unknown; htmlTemplate: unknown }) ?? []
|
|
229
|
+
const widgetId = widget.get('id').ifString()
|
|
230
|
+
if (widgetId && !/^[a-zA-Z0-9_-]+$/g.test(widgetId.getValue())) {
|
|
231
|
+
diagnostics.error(
|
|
232
|
+
widgetId.getOriginalNode(),
|
|
233
|
+
`Invalid value: must contain only alphanumeric, -, or _ characters`
|
|
234
|
+
)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const clientScript = widget.get('clientScript')
|
|
238
|
+
const clientScriptValue =
|
|
239
|
+
clientScript instanceof NowIncludeShape ? clientScript.getValue() : clientScript.ifString()?.getValue()
|
|
240
|
+
if (clientScriptValue && clientScriptValue.trim().length > 0) {
|
|
241
|
+
const clientScriptPattern =
|
|
242
|
+
/^(function|api\.controller\s?=\s?function)\s?([$a-z_][$0-9a-z_]*)?\s?\(.*\)\s?\n?{/i
|
|
243
|
+
if (!clientScriptPattern.test(clientScriptValue.trim())) {
|
|
244
|
+
diagnostics.error(
|
|
245
|
+
clientScript.getOriginalNode(),
|
|
246
|
+
`Client controller must contain a JavaScript function. Example: api.controller = function($scope) { ... }`
|
|
247
|
+
)
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const htmlTemplate = widget.get('htmlTemplate')
|
|
252
|
+
const htmlTemplateValue =
|
|
253
|
+
htmlTemplate instanceof NowIncludeShape ? htmlTemplate.getValue() : htmlTemplate.ifString()?.getValue()
|
|
254
|
+
if (htmlTemplateValue && htmlTemplateValue.length > 0 && htmlTemplateValue.indexOf('href="#"') > 0) {
|
|
255
|
+
diagnostics.error(
|
|
256
|
+
htmlTemplate.getOriginalNode(),
|
|
257
|
+
`Do not use href="#" in the Service Portal, use href="javascript:void(0)" instead`
|
|
258
|
+
)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const roles = widget
|
|
262
|
+
.get('roles')
|
|
263
|
+
.ifArray()
|
|
264
|
+
?.map((role) => {
|
|
265
|
+
if (role.isString()) {
|
|
266
|
+
return role
|
|
267
|
+
}
|
|
268
|
+
if (role.isRecord()) {
|
|
269
|
+
return role.get('name')
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return undefined
|
|
273
|
+
})
|
|
274
|
+
.filter((role) => role) as Shape[] | undefined
|
|
275
|
+
|
|
276
|
+
if (roles) {
|
|
277
|
+
roles
|
|
278
|
+
.filter((role) => isGUID(role.getValue() as string))
|
|
279
|
+
.forEach((role) =>
|
|
280
|
+
diagnostics.error(
|
|
281
|
+
role!.getOriginalNode(),
|
|
282
|
+
`expecting role names or role records created by the Role or Record plugins, not sys_ids`
|
|
283
|
+
)
|
|
284
|
+
)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const controller = widget.get('controllerAs').ifString()?.getValue() || 'c'
|
|
288
|
+
const servicenow =
|
|
289
|
+
(widget.get('servicenow').ifBoolean()?.getValue() &&
|
|
290
|
+
(config.scope.startsWith('sn_') || config.scope.startsWith('snc_'))) ||
|
|
291
|
+
false
|
|
292
|
+
|
|
293
|
+
const widgetRecord = await factory.createRecord({
|
|
294
|
+
source: callExpression,
|
|
295
|
+
table,
|
|
296
|
+
explicitId: widget.get('$id'),
|
|
297
|
+
properties: widget.transform(({ $ }) => {
|
|
298
|
+
const baseTransform = {
|
|
299
|
+
name: $,
|
|
300
|
+
category: $.map((v) => {
|
|
301
|
+
const catKey = v.ifString()?.getValue() || ''
|
|
302
|
+
return WidgetCategories[catKey as keyof typeof WidgetCategories]
|
|
303
|
+
}).def('custom'),
|
|
304
|
+
client_script: $.from('clientScript').def(options.getDefaultClientScript(controller)),
|
|
305
|
+
script: $.from('serverScript').def(options.defaultServerScript),
|
|
306
|
+
controller_as: $.from('controllerAs').def('c'),
|
|
307
|
+
template: $.from('htmlTemplate').def(options.defaultHtmlTemplate),
|
|
308
|
+
css: $.from('customCss').def(''),
|
|
309
|
+
data_table: $.from('dataTable').def('sp_instance'),
|
|
310
|
+
demo_data: $.from('demoData')
|
|
311
|
+
.map((v) => (v.ifString() || v instanceof NowIncludeShape ? v : JSON.stringify(v.getValue())))
|
|
312
|
+
.def(''),
|
|
313
|
+
description: $.def(''),
|
|
314
|
+
docs: $.map((v) => (v.isString() ? v : v.ifRecord()?.getId())),
|
|
315
|
+
field_list: $.from('fields')
|
|
316
|
+
.map((v) => v.getValue()?.toString())
|
|
317
|
+
.def(''),
|
|
318
|
+
has_preview: $.from('hasPreview').toBoolean().def(false),
|
|
319
|
+
id: $.def(''),
|
|
320
|
+
internal: $.def(false),
|
|
321
|
+
servicenow: $.val(servicenow),
|
|
322
|
+
link: $.from('linkScript').def(options.defaultLinkScript),
|
|
323
|
+
roles: $.val(roles?.map((r) => r.getValue()).toString()).def(''),
|
|
324
|
+
option_schema: $.from('optionSchema')
|
|
325
|
+
.map((v) => {
|
|
326
|
+
const json = v.getValue()
|
|
327
|
+
const converted = convertOptionSchemaKeys(json, (key: string) =>
|
|
328
|
+
key.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`)
|
|
329
|
+
)
|
|
330
|
+
return converted && JSON.stringify(converted)
|
|
331
|
+
})
|
|
332
|
+
.def(''),
|
|
333
|
+
public: $.def(false),
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
return includeStaticField
|
|
337
|
+
? { ...baseTransform, static: $.from('static').toBoolean().def(false) }
|
|
338
|
+
: baseTransform
|
|
339
|
+
}),
|
|
340
|
+
})
|
|
341
|
+
|
|
342
|
+
return {
|
|
343
|
+
success: true,
|
|
344
|
+
value: widgetRecord.with(
|
|
345
|
+
...(await Promise.all(
|
|
346
|
+
templates.map(async (template) => {
|
|
347
|
+
return await factory.createRecord({
|
|
348
|
+
source: callExpression,
|
|
349
|
+
table: 'sp_ng_template',
|
|
350
|
+
explicitId: template.$id,
|
|
351
|
+
properties: {
|
|
352
|
+
id: template.id,
|
|
353
|
+
sp_widget: widgetRecord.getId(),
|
|
354
|
+
template: template.htmlTemplate,
|
|
355
|
+
},
|
|
356
|
+
})
|
|
357
|
+
})
|
|
358
|
+
)),
|
|
359
|
+
...(await Promise.all(
|
|
360
|
+
dependencies.map(async (dep) => {
|
|
361
|
+
return await factory.createRecord({
|
|
362
|
+
source: callExpression,
|
|
363
|
+
table: 'm2m_sp_widget_dependency',
|
|
364
|
+
properties: {
|
|
365
|
+
sp_dependency: dep!,
|
|
366
|
+
sp_widget: widgetRecord.getId(),
|
|
367
|
+
},
|
|
368
|
+
})
|
|
369
|
+
})
|
|
370
|
+
)),
|
|
371
|
+
...(await Promise.all(
|
|
372
|
+
angularProviders.map(async (ap) => {
|
|
373
|
+
return await factory.createRecord({
|
|
374
|
+
source: callExpression,
|
|
375
|
+
table: 'm2m_sp_ng_pro_sp_widget',
|
|
376
|
+
properties: {
|
|
377
|
+
sp_angular_provider: ap!,
|
|
378
|
+
sp_widget: widgetRecord.getId(),
|
|
379
|
+
},
|
|
380
|
+
})
|
|
381
|
+
})
|
|
382
|
+
))
|
|
383
|
+
),
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Converts a roles Shape (array of strings, Role() expressions, or Record references)
|
|
389
|
+
* to a deduplicated comma-separated string of role names.
|
|
390
|
+
* @param rolesShape - Shape containing the roles array
|
|
391
|
+
* @param diagnostics - Optional diagnostics for reporting invalid role entries
|
|
392
|
+
* @returns Comma-separated string of unique role names, or empty string if no roles
|
|
393
|
+
*/
|
|
394
|
+
export function getRolesString(rolesShape: Shape, diagnostics?: Diagnostics): string {
|
|
395
|
+
const roles = rolesShape
|
|
396
|
+
.ifArray()
|
|
397
|
+
?.getElements()
|
|
398
|
+
.map((role) => {
|
|
399
|
+
if (role.isString()) {
|
|
400
|
+
return role.getValue()
|
|
401
|
+
}
|
|
402
|
+
if (role instanceof CallExpressionShape) {
|
|
403
|
+
const name = role.getArgument(0).asObject().get('name')
|
|
404
|
+
if (name.isString()) {
|
|
405
|
+
return name.getValue()
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
if (role.isRecord()) {
|
|
409
|
+
const name = role.get('name')
|
|
410
|
+
if (name?.isString()) {
|
|
411
|
+
return name.getValue()
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
if (diagnostics) {
|
|
415
|
+
diagnostics.error(role, 'roles must be strings or role records')
|
|
416
|
+
}
|
|
417
|
+
return undefined
|
|
418
|
+
})
|
|
419
|
+
.filter((r): r is string => r !== undefined && r.trim() !== '')
|
|
420
|
+
|
|
421
|
+
if (!roles || roles.length === 0) {
|
|
422
|
+
return ''
|
|
423
|
+
}
|
|
424
|
+
return [...new Set(roles)].join(',')
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
export async function getIncludeRecords(
|
|
428
|
+
shape: Shape,
|
|
429
|
+
parentId: Shape,
|
|
430
|
+
factory: Factory,
|
|
431
|
+
m2mTable: string,
|
|
432
|
+
includeTable: string,
|
|
433
|
+
parentTable: string,
|
|
434
|
+
diagnostics: Diagnostics
|
|
435
|
+
) {
|
|
436
|
+
return (
|
|
437
|
+
await Promise.all(
|
|
438
|
+
shape?.ifArray()?.map(async (include) => {
|
|
439
|
+
const includeProps = include.ifObject()?.get('include')
|
|
440
|
+
|
|
441
|
+
let includeId: string | RecordId
|
|
442
|
+
if (includeProps?.isString()) {
|
|
443
|
+
includeId = includeProps.toString().getValue()
|
|
444
|
+
} else if (includeProps?.isRecord()) {
|
|
445
|
+
includeId = includeProps.getId()
|
|
446
|
+
} else {
|
|
447
|
+
const necessaryPlugin = includeTable === 'sp_js_include' ? 'JsInclude' : 'CssInclude'
|
|
448
|
+
diagnostics.error(
|
|
449
|
+
includeProps!,
|
|
450
|
+
`include must contain a valid ${necessaryPlugin}, Record<'${includeTable}'> or sys_id'`
|
|
451
|
+
)
|
|
452
|
+
return undefined
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
const m2mProps = {
|
|
456
|
+
[includeTable]: includeId,
|
|
457
|
+
[parentTable]: parentId,
|
|
458
|
+
}
|
|
459
|
+
return await factory.createRecord({
|
|
460
|
+
source: shape,
|
|
461
|
+
table: m2mTable,
|
|
462
|
+
properties: {
|
|
463
|
+
order: include.ifObject()?.get('order').asNumber().getValue() || DEFAULT_ORDER,
|
|
464
|
+
...m2mProps,
|
|
465
|
+
},
|
|
466
|
+
})
|
|
467
|
+
}) ?? []
|
|
468
|
+
)
|
|
469
|
+
).filter((rec) => rec) as Record[]
|
|
470
|
+
}
|