@servicenow/sdk-build-plugins 3.0.3 → 4.0.1
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.d.ts +19 -0
- package/dist/acl-plugin.js +210 -0
- package/dist/acl-plugin.js.map +1 -0
- package/dist/application-menu-plugin.d.ts +18 -0
- package/dist/application-menu-plugin.js +104 -0
- package/dist/application-menu-plugin.js.map +1 -0
- package/dist/arrow-function-plugin.d.ts +16 -0
- package/dist/arrow-function-plugin.js +107 -0
- package/dist/arrow-function-plugin.js.map +1 -0
- package/dist/atf/step-configs.d.ts +39 -0
- package/dist/atf/step-configs.js +2334 -0
- package/dist/atf/step-configs.js.map +1 -0
- package/dist/atf/test-plugin.d.ts +4 -0
- package/dist/atf/test-plugin.js +600 -0
- package/dist/atf/test-plugin.js.map +1 -0
- package/dist/basic-syntax-plugin.d.ts +2 -0
- package/dist/basic-syntax-plugin.js +636 -0
- package/dist/basic-syntax-plugin.js.map +1 -0
- package/dist/business-rule-plugin.d.ts +3 -0
- package/dist/business-rule-plugin.js +205 -0
- package/dist/business-rule-plugin.js.map +1 -0
- package/dist/call-expression-plugin.d.ts +2 -0
- package/dist/call-expression-plugin.js +175 -0
- package/dist/call-expression-plugin.js.map +1 -0
- package/dist/client-script-plugin.d.ts +29 -0
- package/dist/client-script-plugin.js +164 -0
- package/dist/client-script-plugin.js.map +1 -0
- package/dist/column/column-helper.d.ts +12 -0
- package/dist/column/column-helper.js +84 -0
- package/dist/column/column-helper.js.map +1 -0
- package/dist/column/column-to-record.d.ts +3 -0
- package/dist/column/column-to-record.js +105 -0
- package/dist/column/column-to-record.js.map +1 -0
- package/dist/column-plugin.d.ts +8 -0
- package/dist/column-plugin.js +453 -0
- package/dist/column-plugin.js.map +1 -0
- package/dist/cross-scope-privilege-plugin.d.ts +15 -0
- package/dist/cross-scope-privilege-plugin.js +82 -0
- package/dist/cross-scope-privilege-plugin.js.map +1 -0
- package/dist/html-import-plugin.d.ts +2 -0
- package/dist/html-import-plugin.js +72 -0
- package/dist/html-import-plugin.js.map +1 -0
- package/dist/index.d.ts +37 -21
- package/dist/index.js +40 -45
- package/dist/index.js.map +1 -1
- package/dist/json-plugin.d.ts +15 -0
- package/dist/json-plugin.js +104 -0
- package/dist/json-plugin.js.map +1 -0
- package/dist/list-plugin.d.ts +2 -0
- package/dist/list-plugin.js +191 -0
- package/dist/list-plugin.js.map +1 -0
- package/dist/now-config-plugin.d.ts +4 -0
- package/dist/now-config-plugin.js +154 -0
- package/dist/now-config-plugin.js.map +1 -0
- package/dist/now-id-plugin.d.ts +11 -0
- package/dist/now-id-plugin.js +71 -0
- package/dist/now-id-plugin.js.map +1 -0
- package/dist/now-include-plugin.d.ts +16 -0
- package/dist/now-include-plugin.js +118 -0
- package/dist/now-include-plugin.js.map +1 -0
- package/dist/now-ref-plugin.d.ts +2 -0
- package/dist/now-ref-plugin.js +43 -0
- package/dist/now-ref-plugin.js.map +1 -0
- package/dist/now-unresolved-plugin.d.ts +2 -0
- package/dist/now-unresolved-plugin.js +32 -0
- package/dist/now-unresolved-plugin.js.map +1 -0
- package/dist/package-json-plugin.d.ts +2 -0
- package/dist/package-json-plugin.js +70 -0
- package/dist/package-json-plugin.js.map +1 -0
- package/dist/property-plugin.d.ts +2 -0
- package/dist/property-plugin.js +105 -0
- package/dist/property-plugin.js.map +1 -0
- package/dist/record-plugin.d.ts +43 -0
- package/dist/record-plugin.js +147 -0
- package/dist/record-plugin.js.map +1 -0
- package/dist/repack/index.d.ts +1 -0
- package/dist/repack/index.js +10 -2
- package/dist/repack/index.js.map +1 -1
- package/dist/repack/lint/Rules.d.ts +1 -1
- package/dist/repack/lint/Rules.js +7 -3
- package/dist/repack/lint/Rules.js.map +1 -1
- package/dist/repack/lint/index.js +1 -1
- package/dist/rest-api-plugin.d.ts +2 -0
- package/dist/rest-api-plugin.js +469 -0
- package/dist/rest-api-plugin.js.map +1 -0
- package/dist/role-plugin.d.ts +2 -0
- package/dist/role-plugin.js +117 -0
- package/dist/role-plugin.js.map +1 -0
- package/dist/script-action-plugin.d.ts +2 -0
- package/dist/script-action-plugin.js +62 -0
- package/dist/script-action-plugin.js.map +1 -0
- package/dist/script-include-plugin.d.ts +2 -0
- package/dist/script-include-plugin.js +102 -0
- package/dist/script-include-plugin.js.map +1 -0
- package/dist/server-module-plugin/index.d.ts +14 -0
- package/dist/server-module-plugin/index.js +378 -0
- package/dist/server-module-plugin/index.js.map +1 -0
- package/dist/server-module-plugin/sbom-builder.d.ts +45 -0
- package/dist/server-module-plugin/sbom-builder.js +179 -0
- package/dist/server-module-plugin/sbom-builder.js.map +1 -0
- package/dist/service-portal/angular-provider-plugin.d.ts +2 -0
- package/dist/service-portal/angular-provider-plugin.js +78 -0
- package/dist/service-portal/angular-provider-plugin.js.map +1 -0
- package/dist/service-portal/dependency-plugin.d.ts +2 -0
- package/dist/service-portal/dependency-plugin.js +235 -0
- package/dist/service-portal/dependency-plugin.js.map +1 -0
- package/dist/service-portal/widget-plugin.d.ts +6 -0
- package/dist/service-portal/widget-plugin.js +230 -0
- package/dist/service-portal/widget-plugin.js.map +1 -0
- package/dist/static-content-plugin.d.ts +2 -0
- package/dist/static-content-plugin.js +272 -0
- package/dist/static-content-plugin.js.map +1 -0
- package/dist/table-plugin.d.ts +3 -0
- package/dist/table-plugin.js +1324 -0
- package/dist/table-plugin.js.map +1 -0
- package/dist/ui-action-plugin.d.ts +2 -0
- package/dist/ui-action-plugin.js +291 -0
- package/dist/ui-action-plugin.js.map +1 -0
- package/dist/ui-page-plugin.d.ts +2 -0
- package/dist/ui-page-plugin.js +165 -0
- package/dist/ui-page-plugin.js.map +1 -0
- package/dist/user-preference-plugin.d.ts +15 -0
- package/dist/user-preference-plugin.js +63 -0
- package/dist/user-preference-plugin.js.map +1 -0
- package/dist/utils.d.ts +17 -0
- package/dist/utils.js +72 -0
- package/dist/utils.js.map +1 -0
- package/dist/view-plugin.d.ts +2 -0
- package/dist/view-plugin.js +45 -0
- package/dist/view-plugin.js.map +1 -0
- package/package.json +17 -13
- package/src/acl-plugin.ts +256 -0
- package/src/application-menu-plugin.ts +109 -0
- package/src/arrow-function-plugin.ts +127 -0
- package/src/atf/step-configs.ts +2384 -0
- package/src/atf/test-plugin.ts +739 -0
- package/src/basic-syntax-plugin.ts +729 -0
- package/src/business-rule-plugin.ts +266 -0
- package/src/call-expression-plugin.ts +202 -0
- package/src/client-script-plugin.ts +179 -0
- package/src/column/column-helper.ts +119 -0
- package/src/column/column-to-record.ts +131 -0
- package/src/column-plugin.ts +506 -0
- package/src/cross-scope-privilege-plugin.ts +82 -0
- package/src/html-import-plugin.ts +79 -0
- package/src/index.ts +39 -21
- package/src/json-plugin.ts +128 -0
- package/src/list-plugin.ts +222 -0
- package/src/now-config-plugin.ts +194 -0
- package/src/now-id-plugin.ts +78 -0
- package/src/now-include-plugin.ts +140 -0
- package/src/now-ref-plugin.ts +48 -0
- package/src/now-unresolved-plugin.ts +30 -0
- package/src/package-json-plugin.ts +87 -0
- package/src/property-plugin.ts +118 -0
- package/src/record-plugin.ts +171 -0
- package/src/repack/index.ts +10 -1
- package/src/repack/lint/Rules.ts +5 -4
- package/src/repack/lint/index.ts +1 -1
- package/src/rest-api-plugin.ts +658 -0
- package/src/role-plugin.ts +128 -0
- package/src/script-action-plugin.ts +63 -0
- package/src/script-include-plugin.ts +110 -0
- package/src/server-module-plugin/index.ts +470 -0
- package/src/server-module-plugin/sbom-builder.ts +183 -0
- package/src/service-portal/angular-provider-plugin.ts +83 -0
- package/src/service-portal/dependency-plugin.ts +284 -0
- package/src/service-portal/widget-plugin.ts +263 -0
- package/src/static-content-plugin.ts +254 -0
- package/src/table-plugin.ts +1698 -0
- package/src/ui-action-plugin.ts +324 -0
- package/src/ui-page-plugin.ts +168 -0
- package/src/user-preference-plugin.ts +62 -0
- package/src/utils.ts +69 -0
- package/src/view-plugin.ts +46 -0
- package/dist/AttachmentPlugin.d.ts +0 -254
- package/dist/AttachmentPlugin.js +0 -220
- package/dist/AttachmentPlugin.js.map +0 -1
- package/dist/BusinessRulePlugin.d.ts +0 -30
- package/dist/BusinessRulePlugin.js +0 -149
- package/dist/BusinessRulePlugin.js.map +0 -1
- package/dist/CrossScopePrivilegePlugin.d.ts +0 -35
- package/dist/CrossScopePrivilegePlugin.js +0 -80
- package/dist/CrossScopePrivilegePlugin.js.map +0 -1
- package/dist/DefaultPlugin.d.ts +0 -86
- package/dist/DefaultPlugin.js +0 -226
- package/dist/DefaultPlugin.js.map +0 -1
- package/dist/HtmlTemplatePlugin.d.ts +0 -21
- package/dist/HtmlTemplatePlugin.js +0 -29
- package/dist/HtmlTemplatePlugin.js.map +0 -1
- package/dist/IdPlugin.d.ts +0 -28
- package/dist/IdPlugin.js +0 -68
- package/dist/IdPlugin.js.map +0 -1
- package/dist/IncludePlugin.d.ts +0 -34
- package/dist/IncludePlugin.js +0 -155
- package/dist/IncludePlugin.js.map +0 -1
- package/dist/JsonPlugin.d.ts +0 -28
- package/dist/JsonPlugin.js +0 -69
- package/dist/JsonPlugin.js.map +0 -1
- package/dist/ListPlugin.d.ts +0 -93
- package/dist/ListPlugin.js +0 -456
- package/dist/ListPlugin.js.map +0 -1
- package/dist/NowConfigPlugin.d.ts +0 -45
- package/dist/NowConfigPlugin.js +0 -64
- package/dist/NowConfigPlugin.js.map +0 -1
- package/dist/PackageJsonPlugin.d.ts +0 -34
- package/dist/PackageJsonPlugin.js +0 -63
- package/dist/PackageJsonPlugin.js.map +0 -1
- package/dist/PropertyPlugin.d.ts +0 -51
- package/dist/PropertyPlugin.js +0 -181
- package/dist/PropertyPlugin.js.map +0 -1
- package/dist/ScriptTemplatePlugin.d.ts +0 -13
- package/dist/ScriptTemplatePlugin.js +0 -55
- package/dist/ScriptTemplatePlugin.js.map +0 -1
- package/dist/ServerModulePlugin.d.ts +0 -75
- package/dist/ServerModulePlugin.js +0 -368
- package/dist/ServerModulePlugin.js.map +0 -1
- package/dist/UserPreferencePlugin.d.ts +0 -19
- package/dist/UserPreferencePlugin.js +0 -32
- package/dist/UserPreferencePlugin.js.map +0 -1
- package/dist/aclAndRole/AclPlugin.d.ts +0 -82
- package/dist/aclAndRole/AclPlugin.js +0 -262
- package/dist/aclAndRole/AclPlugin.js.map +0 -1
- package/dist/aclAndRole/RolePlugin.d.ts +0 -66
- package/dist/aclAndRole/RolePlugin.js +0 -179
- package/dist/aclAndRole/RolePlugin.js.map +0 -1
- package/dist/aclAndRole/Util.d.ts +0 -3
- package/dist/aclAndRole/Util.js +0 -90
- package/dist/aclAndRole/Util.js.map +0 -1
- package/dist/app/ApplicationMenuPlugin.d.ts +0 -34
- package/dist/app/ApplicationMenuPlugin.js +0 -112
- package/dist/app/ApplicationMenuPlugin.js.map +0 -1
- package/dist/db/ColumnPlugins.d.ts +0 -750
- package/dist/db/ColumnPlugins.js +0 -114
- package/dist/db/ColumnPlugins.js.map +0 -1
- package/dist/db/DBUtils.d.ts +0 -2
- package/dist/db/DBUtils.js +0 -27
- package/dist/db/DBUtils.js.map +0 -1
- package/dist/db/DocumentationPlugin.d.ts +0 -67
- package/dist/db/DocumentationPlugin.js +0 -258
- package/dist/db/DocumentationPlugin.js.map +0 -1
- package/dist/db/LicensingPlugin.d.ts +0 -60
- package/dist/db/LicensingPlugin.js +0 -117
- package/dist/db/LicensingPlugin.js.map +0 -1
- package/dist/db/RecordPlugin.d.ts +0 -133
- package/dist/db/RecordPlugin.js +0 -337
- package/dist/db/RecordPlugin.js.map +0 -1
- package/dist/db/TablePlugin.d.ts +0 -231
- package/dist/db/TablePlugin.js +0 -1630
- package/dist/db/TablePlugin.js.map +0 -1
- package/dist/db/index.d.ts +0 -6
- package/dist/db/index.js +0 -32
- package/dist/db/index.js.map +0 -1
- package/dist/scriptedRESTAPI/RESTDeserializationUtils.d.ts +0 -10
- package/dist/scriptedRESTAPI/RESTDeserializationUtils.js +0 -373
- package/dist/scriptedRESTAPI/RESTDeserializationUtils.js.map +0 -1
- package/dist/scriptedRESTAPI/RESTSerializationUtils.d.ts +0 -13
- package/dist/scriptedRESTAPI/RESTSerializationUtils.js +0 -177
- package/dist/scriptedRESTAPI/RESTSerializationUtils.js.map +0 -1
- package/dist/scriptedRESTAPI/RestApiPlugin.d.ts +0 -81
- package/dist/scriptedRESTAPI/RestApiPlugin.js +0 -345
- package/dist/scriptedRESTAPI/RestApiPlugin.js.map +0 -1
- package/dist/scriptedRESTAPI/RestSchemaUtils.d.ts +0 -190
- package/dist/scriptedRESTAPI/RestSchemaUtils.js +0 -53
- package/dist/scriptedRESTAPI/RestSchemaUtils.js.map +0 -1
- package/dist/scriptedRESTAPI/RestUtils.d.ts +0 -69
- package/dist/scriptedRESTAPI/RestUtils.js +0 -497
- package/dist/scriptedRESTAPI/RestUtils.js.map +0 -1
- package/dist/scripts/ClientScriptPlugin.d.ts +0 -64
- package/dist/scripts/ClientScriptPlugin.js +0 -170
- package/dist/scripts/ClientScriptPlugin.js.map +0 -1
- package/dist/scripts/scriptUtils.d.ts +0 -1
- package/dist/scripts/scriptUtils.js +0 -9
- package/dist/scripts/scriptUtils.js.map +0 -1
- package/dist/uxf/ExperiencePlugin.d.ts +0 -45
- package/dist/uxf/ExperiencePlugin.js +0 -61
- package/dist/uxf/ExperiencePlugin.js.map +0 -1
- package/dist/uxf/RoutesPlugin.d.ts +0 -29
- package/dist/uxf/RoutesPlugin.js +0 -181
- package/dist/uxf/RoutesPlugin.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/cleanUxValue.d.ts +0 -4
- package/dist/uxf/UxfFormulaParser/cleanUxValue.js +0 -65
- package/dist/uxf/UxfFormulaParser/cleanUxValue.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/grammerParser/api.d.ts +0 -189
- package/dist/uxf/UxfFormulaParser/grammerParser/api.js +0 -158
- package/dist/uxf/UxfFormulaParser/grammerParser/api.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/grammerParser/clientTransformMap.d.ts +0 -13
- package/dist/uxf/UxfFormulaParser/grammerParser/clientTransformMap.js +0 -604
- package/dist/uxf/UxfFormulaParser/grammerParser/clientTransformMap.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/grammerParser/grammarParser.d.ts +0 -12
- package/dist/uxf/UxfFormulaParser/grammerParser/grammarParser.js +0 -551
- package/dist/uxf/UxfFormulaParser/grammerParser/grammarParser.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/grammerParser/spanHelpers.d.ts +0 -31
- package/dist/uxf/UxfFormulaParser/grammerParser/spanHelpers.js +0 -64
- package/dist/uxf/UxfFormulaParser/grammerParser/spanHelpers.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/index.d.ts +0 -3
- package/dist/uxf/UxfFormulaParser/index.js +0 -11
- package/dist/uxf/UxfFormulaParser/index.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/parser.d.ts +0 -8
- package/dist/uxf/UxfFormulaParser/parser.js +0 -87
- package/dist/uxf/UxfFormulaParser/parser.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/utils/getErrorMsg.d.ts +0 -8
- package/dist/uxf/UxfFormulaParser/utils/getErrorMsg.js +0 -17
- package/dist/uxf/UxfFormulaParser/utils/getErrorMsg.js.map +0 -1
- package/dist/uxf/constants.d.ts +0 -2
- package/dist/uxf/constants.js +0 -8
- package/dist/uxf/constants.js.map +0 -1
- package/dist/uxf/index.d.ts +0 -2
- package/dist/uxf/index.js +0 -11
- package/dist/uxf/index.js.map +0 -1
- package/dist/uxf/tectonicIdGenerator.d.ts +0 -12
- package/dist/uxf/tectonicIdGenerator.js +0 -79
- package/dist/uxf/tectonicIdGenerator.js.map +0 -1
- package/src/AttachmentPlugin.ts +0 -268
- package/src/BusinessRulePlugin.ts +0 -238
- package/src/CrossScopePrivilegePlugin.ts +0 -115
- package/src/DefaultPlugin.ts +0 -288
- package/src/HtmlTemplatePlugin.ts +0 -31
- package/src/IdPlugin.ts +0 -74
- package/src/IncludePlugin.ts +0 -206
- package/src/JsonPlugin.ts +0 -76
- package/src/ListPlugin.ts +0 -570
- package/src/NowConfigPlugin.ts +0 -69
- package/src/PackageJsonPlugin.ts +0 -68
- package/src/PropertyPlugin.ts +0 -237
- package/src/ScriptTemplatePlugin.ts +0 -53
- package/src/ServerModulePlugin.ts +0 -480
- package/src/UserPreferencePlugin.ts +0 -45
- package/src/aclAndRole/AclPlugin.ts +0 -420
- package/src/aclAndRole/RolePlugin.ts +0 -254
- package/src/aclAndRole/Util.ts +0 -113
- package/src/app/ApplicationMenuPlugin.ts +0 -165
- package/src/db/ColumnPlugins.ts +0 -114
- package/src/db/DBUtils.ts +0 -36
- package/src/db/DocumentationPlugin.ts +0 -316
- package/src/db/LicensingPlugin.ts +0 -138
- package/src/db/RecordPlugin.ts +0 -459
- package/src/db/TablePlugin.ts +0 -2072
- package/src/db/index.ts +0 -6
- package/src/scriptedRESTAPI/RESTDeserializationUtils.ts +0 -419
- package/src/scriptedRESTAPI/RESTSerializationUtils.ts +0 -228
- package/src/scriptedRESTAPI/RestApiPlugin.ts +0 -469
- package/src/scriptedRESTAPI/RestSchemaUtils.ts +0 -72
- package/src/scriptedRESTAPI/RestUtils.ts +0 -569
- package/src/scripts/ClientScriptPlugin.ts +0 -257
- package/src/scripts/scriptUtils.ts +0 -5
- package/src/uxf/ExperiencePlugin.ts +0 -67
- package/src/uxf/RoutesPlugin.ts +0 -211
- package/src/uxf/UxfFormulaParser/cleanUxValue.ts +0 -73
- package/src/uxf/UxfFormulaParser/grammerParser/api.js +0 -166
- package/src/uxf/UxfFormulaParser/grammerParser/clientTransformMap.js +0 -606
- package/src/uxf/UxfFormulaParser/grammerParser/grammarParser.js +0 -551
- package/src/uxf/UxfFormulaParser/grammerParser/spanHelpers.js +0 -65
- package/src/uxf/UxfFormulaParser/index.ts +0 -4
- package/src/uxf/UxfFormulaParser/parser.ts +0 -64
- package/src/uxf/UxfFormulaParser/utils/getErrorMsg.ts +0 -13
- package/src/uxf/constants.ts +0 -4
- package/src/uxf/index.ts +0 -2
- package/src/uxf/tectonicIdGenerator.ts +0 -78
|
@@ -0,0 +1,658 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CallExpressionShape,
|
|
3
|
+
type Factory,
|
|
4
|
+
Plugin,
|
|
5
|
+
Shape,
|
|
6
|
+
type Record,
|
|
7
|
+
type Diagnostics,
|
|
8
|
+
type ObjectShape,
|
|
9
|
+
type RecordId,
|
|
10
|
+
type NowConfig,
|
|
11
|
+
} from '@servicenow/sdk-build-core'
|
|
12
|
+
import { ModuleFunctionShape } from './server-module-plugin'
|
|
13
|
+
import { NowIdShape } from './now-id-plugin'
|
|
14
|
+
import { generateDeprecatedDiagnostics } from './utils'
|
|
15
|
+
|
|
16
|
+
const DEFAULT_MEDIA_TYPE = 'application/json,application/xml,text/xml'
|
|
17
|
+
const DEFAULT_REST_ENFORCED_ACL = 'cf9d01d3e73003009d6247e603f6a990'
|
|
18
|
+
const methodsAllowedToOverrideRequests = ['PUT', 'PATCH', 'POST']
|
|
19
|
+
const restDefAliases = {
|
|
20
|
+
serviceId: ['service_id'],
|
|
21
|
+
enforceAcl: ['enforce_acl'],
|
|
22
|
+
docLink: ['doc_link'],
|
|
23
|
+
shortDescription: ['short_description'],
|
|
24
|
+
}
|
|
25
|
+
const routeAliases = {
|
|
26
|
+
shortDescription: ['short_description'],
|
|
27
|
+
requestExample: ['request_example'],
|
|
28
|
+
enforceAcl: ['enforce_acl'],
|
|
29
|
+
}
|
|
30
|
+
const versionAliases = {
|
|
31
|
+
isDefault: ['is_default'],
|
|
32
|
+
shortDescription: ['short_description'],
|
|
33
|
+
}
|
|
34
|
+
const attributeAliases = {
|
|
35
|
+
shortDescription: ['short_description'],
|
|
36
|
+
exampleValue: ['example_value'],
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function mergeAcls(acls: Shape | undefined) {
|
|
40
|
+
if (acls?.isArray()) {
|
|
41
|
+
return acls?.pipe((r) =>
|
|
42
|
+
Array.from(new Set(r.getElements().map((r) => r.ifRecord()?.getId().getValue() ?? r.getValue()))).join(',')
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return DEFAULT_REST_ENFORCED_ACL
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function splitAcls(acls: Shape | undefined) {
|
|
50
|
+
if (acls?.isString() && !acls?.isEmpty()) {
|
|
51
|
+
return acls?.pipe((r) => r.getValue().split(','))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return []
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function getVersionNumber(versionShape: Shape, versions: Record[]) {
|
|
58
|
+
const versionId = versionShape.ifString()?.getValue() ?? versionShape.ifRecordId()?.getValue() ?? undefined
|
|
59
|
+
if (!versionId) {
|
|
60
|
+
return undefined
|
|
61
|
+
}
|
|
62
|
+
const version = versions.find((v) => v.getId().getValue() === versionId)
|
|
63
|
+
if (!version) {
|
|
64
|
+
return undefined
|
|
65
|
+
}
|
|
66
|
+
return version.get('version').toNumber().getValue()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function getAttributeRecord(attrAssociationRecord: Record, attrRecords: Record[], attrType: string) {
|
|
70
|
+
return attrRecords.find((r) => {
|
|
71
|
+
const attrId = r.getId().getValue()
|
|
72
|
+
const attr = attrAssociationRecord.get(`web_service_${attrType}`)
|
|
73
|
+
const associationId = attr.ifString()?.getValue() ?? attr.asRecordId().getValue()
|
|
74
|
+
return attrId === associationId
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function getVersionId(
|
|
79
|
+
versionShape: Shape,
|
|
80
|
+
versionToVersionRecordMap: Map<string, Record>,
|
|
81
|
+
diagnostics: Diagnostics
|
|
82
|
+
): string | RecordId {
|
|
83
|
+
const version = versionShape.ifNumber()?.getValue() ?? undefined
|
|
84
|
+
if (!version) {
|
|
85
|
+
return ''
|
|
86
|
+
}
|
|
87
|
+
if (!versionToVersionRecordMap.has(`v${version}`)) {
|
|
88
|
+
diagnostics.error(
|
|
89
|
+
versionShape,
|
|
90
|
+
`Unable to resolve version details for version number "${version}". Check if the version is listed in your API versions list.`
|
|
91
|
+
)
|
|
92
|
+
return ''
|
|
93
|
+
}
|
|
94
|
+
return versionToVersionRecordMap.get(`v${version}`)!.getId()
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function generateVersionRecords(
|
|
98
|
+
versions: Shape[],
|
|
99
|
+
restApi: ObjectShape,
|
|
100
|
+
restRecord: Record,
|
|
101
|
+
defaultVersion: number,
|
|
102
|
+
factory: Factory,
|
|
103
|
+
diagnostics: Diagnostics,
|
|
104
|
+
callExpression: CallExpressionShape
|
|
105
|
+
): Map<string, Record> {
|
|
106
|
+
const versionMap = new Map<string, Record>()
|
|
107
|
+
for (const v of versions) {
|
|
108
|
+
const version = v.asObject().get('version').getValue()
|
|
109
|
+
const versionId = `v${version}`
|
|
110
|
+
const versionRecord = factory.createRecord({
|
|
111
|
+
source: callExpression,
|
|
112
|
+
table: 'sys_ws_version',
|
|
113
|
+
explicitId: v.asObject().get('$id'),
|
|
114
|
+
properties: v.asObject().transform(({ $ }) => ({
|
|
115
|
+
active: $.def(true),
|
|
116
|
+
deprecated: $.def(false),
|
|
117
|
+
is_default: $.val(defaultVersion === version).def(false),
|
|
118
|
+
short_description: $.from('shortDescription').def(''),
|
|
119
|
+
version: $,
|
|
120
|
+
version_id: $.val(versionId),
|
|
121
|
+
web_service_definition: $.val(restRecord.getId()),
|
|
122
|
+
})),
|
|
123
|
+
})
|
|
124
|
+
/** versions have to be unique */
|
|
125
|
+
if (versionMap.has(versionId)) {
|
|
126
|
+
diagnostics.error(
|
|
127
|
+
v.asObject().get('version'),
|
|
128
|
+
`Duplicate versions with version number "${version}" found in RestApi with id "${restApi.get('$id').getValue()}". All versions are expected to be unique.`
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
versionMap.set(versionId, versionRecord)
|
|
132
|
+
}
|
|
133
|
+
return versionMap
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function checkForDuplicateRecords(
|
|
137
|
+
recordMap: Map<string, Record>,
|
|
138
|
+
record: Record,
|
|
139
|
+
attrShape: ObjectShape,
|
|
140
|
+
diagnostics: Diagnostics
|
|
141
|
+
): void {
|
|
142
|
+
const recordId = record.getId().getValue()
|
|
143
|
+
if (!recordMap.has(recordId)) {
|
|
144
|
+
recordMap.set(recordId, record)
|
|
145
|
+
} else {
|
|
146
|
+
const matchRec = recordMap.get(recordId)!
|
|
147
|
+
const originalShape = Shape.from(record.getSource(), record.getValue())
|
|
148
|
+
const matchedShape = Shape.from(matchRec.getSource(), matchRec.getValue())
|
|
149
|
+
if (!matchedShape.equals(originalShape)) {
|
|
150
|
+
diagnostics.error(
|
|
151
|
+
attrShape.get('$id'),
|
|
152
|
+
`Multiple route attributes found with the same ID "${attrShape.get('$id').getValue()}" but with different property values. Attributes with same ID are expected to have identical property values.`
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function generateRouteAttributeRecords(
|
|
159
|
+
attributes: Shape[],
|
|
160
|
+
restDef: Record,
|
|
161
|
+
routeDef: Record,
|
|
162
|
+
attrType: string,
|
|
163
|
+
attrMap: Map<string, Record>,
|
|
164
|
+
factory: Factory,
|
|
165
|
+
diagnostics: Diagnostics,
|
|
166
|
+
callExpression: CallExpressionShape
|
|
167
|
+
): Record[] {
|
|
168
|
+
const records: Record[] = []
|
|
169
|
+
for (const attr of attributes) {
|
|
170
|
+
const attrRecord = factory.createRecord({
|
|
171
|
+
source: callExpression,
|
|
172
|
+
table: `sys_ws_${attrType}`,
|
|
173
|
+
explicitId: attr.asObject().get('$id'),
|
|
174
|
+
properties: attr.asObject().transform(({ $ }) => ({
|
|
175
|
+
name: $,
|
|
176
|
+
required: $.def(false),
|
|
177
|
+
short_description: $.from('shortDescription').def(''),
|
|
178
|
+
example_value: $.from('exampleValue').def(''),
|
|
179
|
+
web_service_definition: $.val(restDef.getId()),
|
|
180
|
+
})),
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
checkForDuplicateRecords(attrMap, attrRecord, attr.asObject(), diagnostics)
|
|
184
|
+
|
|
185
|
+
const attributeMappingRecord = factory.createRecord({
|
|
186
|
+
source: callExpression,
|
|
187
|
+
table: `sys_ws_${attrType}_map`,
|
|
188
|
+
properties: attr.asObject().transform(({ $ }) => ({
|
|
189
|
+
web_service_operation: $.val(routeDef.getId()),
|
|
190
|
+
[`web_service_${attrType}`]: $.val(attrRecord.getId()),
|
|
191
|
+
})),
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
records.push(attrRecord.with(attributeMappingRecord))
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return records
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function generateRouteAndRouteAttrRecords(
|
|
201
|
+
routes: Shape[],
|
|
202
|
+
restDef: Record,
|
|
203
|
+
factory: Factory,
|
|
204
|
+
config: NowConfig,
|
|
205
|
+
diagnostics: Diagnostics,
|
|
206
|
+
versionToVersionRecordMap: Map<string, Record>,
|
|
207
|
+
callExpression: CallExpressionShape
|
|
208
|
+
): Record[] {
|
|
209
|
+
const routeRecords: Record[] = []
|
|
210
|
+
const headersMap = new Map<string, Record>()
|
|
211
|
+
const parametersMap = new Map<string, Record>()
|
|
212
|
+
|
|
213
|
+
for (const r of routes) {
|
|
214
|
+
const route = r.asObject()
|
|
215
|
+
const routeVersion = route.get('version').getValue() as unknown as number
|
|
216
|
+
const versionId = getVersionId(route.get('version'), versionToVersionRecordMap, diagnostics)
|
|
217
|
+
let routeConsumes = route.get('consumes')?.ifString()?.getValue() ?? ''
|
|
218
|
+
const routeMethod = route.get('method').ifString()?.getValue() ?? 'GET'
|
|
219
|
+
const restConsumes = restDef.get('consumes').asString().getValue()
|
|
220
|
+
const restProduces = restDef.get('produces').asString().getValue()
|
|
221
|
+
|
|
222
|
+
if (
|
|
223
|
+
routeConsumes &&
|
|
224
|
+
routeConsumes !== restConsumes &&
|
|
225
|
+
!methodsAllowedToOverrideRequests.includes(routeMethod)
|
|
226
|
+
) {
|
|
227
|
+
diagnostics.error(route.get('consumes'), `Cannot override consumer type for ${routeMethod} method`)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
routeConsumes = routeConsumes ? routeConsumes : restConsumes
|
|
231
|
+
const routeProduces = route.get('produces').getValue() ?? restProduces
|
|
232
|
+
|
|
233
|
+
const baseURI = restDef.get('base_uri').getValue()
|
|
234
|
+
const routePath = route.get('path').getValue() ?? '/'
|
|
235
|
+
const defaultOperationURI = `${baseURI}${routePath}`
|
|
236
|
+
const operationURIPrefix = `/api/${restDef.get('namespace').getValue()}`
|
|
237
|
+
const operationURISuffix = `${restDef.get('service_id').getValue()}${routePath}`
|
|
238
|
+
const operationURI = versionId
|
|
239
|
+
? `${operationURIPrefix}/v${routeVersion}/${operationURISuffix}`
|
|
240
|
+
: `${operationURIPrefix}/${operationURISuffix}`
|
|
241
|
+
|
|
242
|
+
if (route.get('script').isUnresolved()) {
|
|
243
|
+
diagnostics.error(
|
|
244
|
+
route.get('script').getOriginalNode(),
|
|
245
|
+
`Unable to resolve the script reference, ensure the imported module is within the ${config.serverModulesDir} directory.`
|
|
246
|
+
)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const routeRecord = factory.createRecord({
|
|
250
|
+
source: callExpression,
|
|
251
|
+
table: 'sys_ws_operation',
|
|
252
|
+
explicitId: route.get('$id'),
|
|
253
|
+
properties: route.transform(({ $ }) => ({
|
|
254
|
+
name: $.val(route.get('name').ifString()?.getValue() ?? routePath).def('something random'),
|
|
255
|
+
active: $.def(true),
|
|
256
|
+
consumes: $.val(routeConsumes),
|
|
257
|
+
consumes_customized: $.val(routeConsumes !== restConsumes),
|
|
258
|
+
default_operation_uri: $.val(defaultOperationURI),
|
|
259
|
+
http_method: $.from('method').def('GET'),
|
|
260
|
+
operation_script: $.from('script')
|
|
261
|
+
.map(
|
|
262
|
+
(v) =>
|
|
263
|
+
v.if(ModuleFunctionShape)?.toString((n) => `${n}({{PARAMS}})`, ['request', 'response']) ?? v
|
|
264
|
+
)
|
|
265
|
+
.toCdata()
|
|
266
|
+
.def(''),
|
|
267
|
+
operation_uri: $.val(operationURI),
|
|
268
|
+
produces: $.val(routeProduces),
|
|
269
|
+
produces_customized: $.val(routeProduces !== restProduces),
|
|
270
|
+
relative_path: $.from('path').def('/'),
|
|
271
|
+
enforce_acl: $.val(mergeAcls(route.get('enforceAcl'))),
|
|
272
|
+
requires_acl_authorization: $.from('authorization').def(true),
|
|
273
|
+
requires_authentication: $.from('authentication').def(true),
|
|
274
|
+
requires_snc_internal_role: $.from('internalRole').def(true),
|
|
275
|
+
short_description: $.from('shortDescription').def(''),
|
|
276
|
+
request_example: $.from('requestExample').def(''),
|
|
277
|
+
web_service_definition: $.val(restDef.getId()),
|
|
278
|
+
web_service_version: $.val(versionId),
|
|
279
|
+
sys_policy: $.from('policy').def(''),
|
|
280
|
+
})),
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
const routeHeaders = route.get('headers')?.ifArray()?.getElements() ?? []
|
|
284
|
+
routeHeaders.forEach((h) => {
|
|
285
|
+
h.asObject().withAliasedKeys(attributeAliases)
|
|
286
|
+
generateDeprecatedDiagnostics(h.asObject(), diagnostics)
|
|
287
|
+
})
|
|
288
|
+
const headerRecords = generateRouteAttributeRecords(
|
|
289
|
+
routeHeaders,
|
|
290
|
+
restDef,
|
|
291
|
+
routeRecord,
|
|
292
|
+
'header',
|
|
293
|
+
headersMap,
|
|
294
|
+
factory,
|
|
295
|
+
diagnostics,
|
|
296
|
+
callExpression
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
const routeParameters = route.get('parameters')?.ifArray()?.getElements() ?? []
|
|
300
|
+
routeParameters.forEach((p) => {
|
|
301
|
+
p.asObject().withAliasedKeys(attributeAliases)
|
|
302
|
+
generateDeprecatedDiagnostics(p.asObject(), diagnostics)
|
|
303
|
+
})
|
|
304
|
+
const parameterRecords = generateRouteAttributeRecords(
|
|
305
|
+
routeParameters,
|
|
306
|
+
restDef,
|
|
307
|
+
routeRecord,
|
|
308
|
+
'query_parameter',
|
|
309
|
+
parametersMap,
|
|
310
|
+
factory,
|
|
311
|
+
diagnostics,
|
|
312
|
+
callExpression
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
routeRecords.push(routeRecord.with(...headerRecords, ...parameterRecords))
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return routeRecords
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function validateAttributesAndAssociations(
|
|
322
|
+
attributes: Record[],
|
|
323
|
+
attributeRouteAssociations: Record[],
|
|
324
|
+
attributeType: string
|
|
325
|
+
) {
|
|
326
|
+
const attributeIdToRecordMap = new Map<string, Record>()
|
|
327
|
+
attributes.forEach((attribute) => {
|
|
328
|
+
attributeIdToRecordMap.set(attribute.getId().getValue(), attribute)
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
const attributeIds = new Set(attributeIdToRecordMap.keys())
|
|
332
|
+
const referencedAttributeIds = new Set(
|
|
333
|
+
attributeRouteAssociations.map((m2m) => {
|
|
334
|
+
const attr = m2m.get(`web_service_${attributeType}`)
|
|
335
|
+
return attr.ifString()?.getValue() ?? attr.ifRecordId()?.getValue() ?? undefined
|
|
336
|
+
})
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
const orphanedAttributes = Array.from(attributeIds).filter((id) => !referencedAttributeIds.has(id))
|
|
340
|
+
if (orphanedAttributes.length > 0) {
|
|
341
|
+
const orphanedAttributeNames = orphanedAttributes
|
|
342
|
+
.map((id) => {
|
|
343
|
+
const attribute = attributeIdToRecordMap.get(id)
|
|
344
|
+
return attribute?.get('name')?.getValue() || id
|
|
345
|
+
})
|
|
346
|
+
.join(', ')
|
|
347
|
+
|
|
348
|
+
throw new Error(
|
|
349
|
+
`Found ${orphanedAttributes.length} attribute record(s) without route associations: ${orphanedAttributeNames}. ` +
|
|
350
|
+
`Either associate these attributes with routes or delete them.`
|
|
351
|
+
)
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const invalidAttributeAssociations = attributeRouteAssociations.filter((association) => {
|
|
355
|
+
const attr = association.get(`web_service_${attributeType}`)
|
|
356
|
+
const attributeId = attr.ifString()?.getValue() ?? attr.ifRecordId()?.getValue() ?? ''
|
|
357
|
+
return !attributeIdToRecordMap.has(attributeId)
|
|
358
|
+
})
|
|
359
|
+
|
|
360
|
+
if (invalidAttributeAssociations.length > 0) {
|
|
361
|
+
const invalidAttributeAssociationIds = invalidAttributeAssociations
|
|
362
|
+
.map((association) => association.getId().getValue())
|
|
363
|
+
.join(', ')
|
|
364
|
+
throw new Error(
|
|
365
|
+
`Found ${invalidAttributeAssociations.length} ${attributeType} association record(s) referencing non-existent ${attributeType}s: ${invalidAttributeAssociationIds}. ` +
|
|
366
|
+
`Please clean up these m2m records.`
|
|
367
|
+
)
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function routeAttributeTransform(
|
|
372
|
+
associationRecords: Record[],
|
|
373
|
+
attributes: Record[],
|
|
374
|
+
operationFilterId: string,
|
|
375
|
+
attributeType: string
|
|
376
|
+
) {
|
|
377
|
+
const results = associationRecords
|
|
378
|
+
.filter((pm) => {
|
|
379
|
+
const operation = pm.get(`web_service_operation`)
|
|
380
|
+
const operationId = operation.asRecordId().getValue()
|
|
381
|
+
return operationId === operationFilterId
|
|
382
|
+
})
|
|
383
|
+
.map((pm) => {
|
|
384
|
+
const attribute = getAttributeRecord(pm, attributes, attributeType)!
|
|
385
|
+
return attribute
|
|
386
|
+
.transform(({ $ }) => ({
|
|
387
|
+
$id: $.val(NowIdShape.from(attribute)),
|
|
388
|
+
name: $,
|
|
389
|
+
required: $.toBoolean().def(false),
|
|
390
|
+
exampleValue: $.from('example_value').def(''),
|
|
391
|
+
shortDescription: $.from('short_description').def(''),
|
|
392
|
+
}))
|
|
393
|
+
.withAliasedKeys(attributeAliases)
|
|
394
|
+
})
|
|
395
|
+
|
|
396
|
+
return results
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function versionsTransform(versions: Record[]) {
|
|
400
|
+
if (versions.length === 0) {
|
|
401
|
+
return undefined
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return versions.map((v) =>
|
|
405
|
+
v
|
|
406
|
+
.transform(({ $ }) => ({
|
|
407
|
+
$id: $.val(NowIdShape.from(v)),
|
|
408
|
+
active: $.toBoolean().def(true),
|
|
409
|
+
deprecated: $.toBoolean().def(false),
|
|
410
|
+
isDefault: $.from('is_default').toBoolean().def(false),
|
|
411
|
+
shortDescription: $.from('short_description').def(''),
|
|
412
|
+
version: $.toNumber(),
|
|
413
|
+
}))
|
|
414
|
+
.withAliasedKeys(versionAliases)
|
|
415
|
+
)
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
export const RestApiPlugin = Plugin.create({
|
|
419
|
+
name: 'RestApiPlugin',
|
|
420
|
+
records: {
|
|
421
|
+
sys_ws_header_map: {
|
|
422
|
+
coalesce: ['web_service_operation', 'web_service_header'],
|
|
423
|
+
},
|
|
424
|
+
sys_ws_query_parameter_map: {
|
|
425
|
+
coalesce: ['web_service_operation', 'web_service_query_parameter'],
|
|
426
|
+
},
|
|
427
|
+
sys_ws_definition: {
|
|
428
|
+
relationships: {
|
|
429
|
+
sys_ws_operation: {
|
|
430
|
+
via: 'web_service_definition',
|
|
431
|
+
descendant: true,
|
|
432
|
+
relationships: {
|
|
433
|
+
sys_ws_header_map: {
|
|
434
|
+
via: 'web_service_operation',
|
|
435
|
+
descendant: true,
|
|
436
|
+
},
|
|
437
|
+
sys_ws_query_parameter_map: {
|
|
438
|
+
via: 'web_service_operation',
|
|
439
|
+
descendant: true,
|
|
440
|
+
},
|
|
441
|
+
},
|
|
442
|
+
},
|
|
443
|
+
sys_ws_version: {
|
|
444
|
+
via: 'web_service_definition',
|
|
445
|
+
descendant: true,
|
|
446
|
+
},
|
|
447
|
+
sys_ws_header: {
|
|
448
|
+
via: 'web_service_definition',
|
|
449
|
+
descendant: true,
|
|
450
|
+
},
|
|
451
|
+
sys_ws_query_parameter: {
|
|
452
|
+
via: 'web_service_definition',
|
|
453
|
+
descendant: true,
|
|
454
|
+
},
|
|
455
|
+
},
|
|
456
|
+
toShape(record, { descendants }) {
|
|
457
|
+
const versions = descendants.query('sys_ws_version')
|
|
458
|
+
const routes = descendants.query('sys_ws_operation')
|
|
459
|
+
const headers = descendants.query('sys_ws_header')
|
|
460
|
+
const parameters = descendants.query('sys_ws_query_parameter')
|
|
461
|
+
const headerRouteAssociations = descendants.query('sys_ws_header_map')
|
|
462
|
+
const paramRouteAssociations = descendants.query('sys_ws_query_parameter_map')
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Special cases:
|
|
466
|
+
* Case 1: No m2m records exists for a header or parameter record. Can happen in following scenarios:
|
|
467
|
+
* - User has created a header or parameter record but these records are not associated with any routes on instance.
|
|
468
|
+
* - User has removed all the m2m associations on instance but not the actual header or parameter record.
|
|
469
|
+
* Solution: Throw error guiding user to do one of the following:
|
|
470
|
+
* - Associate the header or parameter record with a route
|
|
471
|
+
* - Delete the header or parameter record
|
|
472
|
+
*
|
|
473
|
+
* Case 2: Deleting a header record on instance wouldn't delete the m2m records which map those headers to a route.
|
|
474
|
+
* Solution: Throw error and request the user to cleanup the m2m records on instance.
|
|
475
|
+
*/
|
|
476
|
+
validateAttributesAndAssociations(headers, headerRouteAssociations, 'header')
|
|
477
|
+
validateAttributesAndAssociations(parameters, paramRouteAssociations, 'query_parameter')
|
|
478
|
+
|
|
479
|
+
return {
|
|
480
|
+
success: true,
|
|
481
|
+
value: new CallExpressionShape({
|
|
482
|
+
source: record,
|
|
483
|
+
callee: 'RestApi',
|
|
484
|
+
args: [
|
|
485
|
+
record
|
|
486
|
+
.transform(({ $ }) => ({
|
|
487
|
+
$id: $.val(NowIdShape.from(record)),
|
|
488
|
+
name: $,
|
|
489
|
+
active: $.toBoolean().def(true),
|
|
490
|
+
consumes: $.def(DEFAULT_MEDIA_TYPE),
|
|
491
|
+
produces: $.def(DEFAULT_MEDIA_TYPE),
|
|
492
|
+
enforceAcl: $.from('enforce_acl')
|
|
493
|
+
.map((v) => splitAcls(v))
|
|
494
|
+
.def([DEFAULT_REST_ENFORCED_ACL]),
|
|
495
|
+
serviceId: $.from('service_id'),
|
|
496
|
+
shortDescription: $.from('short_description').def(''),
|
|
497
|
+
policy: $.from('sys_policy').def(''),
|
|
498
|
+
docLink: $.from('doc_link').def(''),
|
|
499
|
+
routes: $.val(
|
|
500
|
+
routes.map((r) =>
|
|
501
|
+
r
|
|
502
|
+
.transform(({ $ }) => ({
|
|
503
|
+
$id: $.val(NowIdShape.from(r)),
|
|
504
|
+
name: $,
|
|
505
|
+
active: $.toBoolean().def(true),
|
|
506
|
+
consumes: $,
|
|
507
|
+
method: $.from('http_method').def('GET'),
|
|
508
|
+
script: $.from('operation_script'),
|
|
509
|
+
produces: $,
|
|
510
|
+
path: $.from('relative_path').def('/'),
|
|
511
|
+
enforceAcl: $.val(splitAcls(r.get('enforce_acl'))).def([
|
|
512
|
+
DEFAULT_REST_ENFORCED_ACL,
|
|
513
|
+
]),
|
|
514
|
+
authorization: $.from('requires_acl_authorization')
|
|
515
|
+
.toBoolean()
|
|
516
|
+
.def(true),
|
|
517
|
+
authentication: $.from('requires_authentication')
|
|
518
|
+
.toBoolean()
|
|
519
|
+
.def(true),
|
|
520
|
+
internalRole: $.from('requires_snc_internal_role')
|
|
521
|
+
.toBoolean()
|
|
522
|
+
.def(true),
|
|
523
|
+
shortDescription: $.from('short_description').def(''),
|
|
524
|
+
requestExample: $.from('request_example').def(''),
|
|
525
|
+
policy: $.from('sys_policy').def(''),
|
|
526
|
+
parameters: $.val(
|
|
527
|
+
routeAttributeTransform(
|
|
528
|
+
paramRouteAssociations,
|
|
529
|
+
parameters,
|
|
530
|
+
r.getId().getValue(),
|
|
531
|
+
'query_parameter'
|
|
532
|
+
)
|
|
533
|
+
).def([]),
|
|
534
|
+
headers: $.val(
|
|
535
|
+
routeAttributeTransform(
|
|
536
|
+
headerRouteAssociations,
|
|
537
|
+
headers,
|
|
538
|
+
r.getId().getValue(),
|
|
539
|
+
'header'
|
|
540
|
+
)
|
|
541
|
+
).def([]),
|
|
542
|
+
version: $.from('web_service_version').map((v) =>
|
|
543
|
+
getVersionNumber(v, versions)
|
|
544
|
+
),
|
|
545
|
+
}))
|
|
546
|
+
.withAliasedKeys(routeAliases)
|
|
547
|
+
)
|
|
548
|
+
).def([]),
|
|
549
|
+
versions: $.val(versionsTransform(versions)).def([]),
|
|
550
|
+
}))
|
|
551
|
+
.withAliasedKeys(restDefAliases),
|
|
552
|
+
],
|
|
553
|
+
}),
|
|
554
|
+
}
|
|
555
|
+
},
|
|
556
|
+
},
|
|
557
|
+
},
|
|
558
|
+
shapes: [
|
|
559
|
+
{
|
|
560
|
+
shape: CallExpressionShape,
|
|
561
|
+
fileTypes: ['fluent'],
|
|
562
|
+
async toRecord(callExpression, { factory, config, diagnostics }) {
|
|
563
|
+
if (callExpression.getCallee() !== 'RestApi') {
|
|
564
|
+
return { success: false }
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
const restApi = callExpression.getArgument(0).asObject().withAliasedKeys(restDefAliases)
|
|
568
|
+
generateDeprecatedDiagnostics(restApi, diagnostics)
|
|
569
|
+
|
|
570
|
+
const scope = config.scope
|
|
571
|
+
const serviceId = restApi.get('serviceId')
|
|
572
|
+
const serviceIdRegex = /^[a-z0-9_]*[a-z0-9]$/
|
|
573
|
+
|
|
574
|
+
if (!serviceId.asString().getValue().match(serviceIdRegex)) {
|
|
575
|
+
diagnostics.error(
|
|
576
|
+
serviceId,
|
|
577
|
+
`Rest service_id must only contain lowercase letters, numbers, and underscores and end with a letter or number`
|
|
578
|
+
)
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
const versions = restApi.get('versions')?.ifArray()?.getElements() ?? []
|
|
582
|
+
versions.forEach((v) => {
|
|
583
|
+
v.asObject().withAliasedKeys(versionAliases)
|
|
584
|
+
generateDeprecatedDiagnostics(v.asObject(), diagnostics)
|
|
585
|
+
})
|
|
586
|
+
const defaultVersions = versions.filter(
|
|
587
|
+
(v) => v.asObject().get('isDefault').ifBoolean()?.getValue() ?? false
|
|
588
|
+
)
|
|
589
|
+
const defaultVersion =
|
|
590
|
+
defaultVersions.length === 1 ? defaultVersions[0]!.asObject().get('version').getValue() : -1
|
|
591
|
+
|
|
592
|
+
if (defaultVersions.length > 1) {
|
|
593
|
+
diagnostics.error(restApi.get('versions'), `Multiple versions cannot be set to default.`)
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
const enforceAcls = restApi.get('enforceAcl')
|
|
597
|
+
const restRecord = factory.createRecord({
|
|
598
|
+
source: callExpression,
|
|
599
|
+
table: 'sys_ws_definition',
|
|
600
|
+
explicitId: restApi.get('$id'),
|
|
601
|
+
properties: restApi.transform(({ $ }) => ({
|
|
602
|
+
name: $,
|
|
603
|
+
service_id: $.val(serviceId),
|
|
604
|
+
active: $.def(true),
|
|
605
|
+
base_uri: $.val(`/api/${scope}/${serviceId.getValue()}`),
|
|
606
|
+
short_description: $.from('shortDescription').def(''),
|
|
607
|
+
consumes: $.def(DEFAULT_MEDIA_TYPE),
|
|
608
|
+
consumes_customized: $.from('consumes').map((v) =>
|
|
609
|
+
v.isString() ? v.getValue() !== DEFAULT_MEDIA_TYPE : false
|
|
610
|
+
),
|
|
611
|
+
default_version: $.val(
|
|
612
|
+
defaultVersion !== -1 ? `v${defaultVersion}` : 'No active default version'
|
|
613
|
+
),
|
|
614
|
+
is_versioned: $.val(versions.length > 0 ? true : false),
|
|
615
|
+
namespace: $.val(scope),
|
|
616
|
+
doc_link: $.from('docLink').def(''),
|
|
617
|
+
produces: $.def(DEFAULT_MEDIA_TYPE),
|
|
618
|
+
produces_customized: $.from('produces').map((v) =>
|
|
619
|
+
v.isString() ? v.getValue() !== DEFAULT_MEDIA_TYPE : false
|
|
620
|
+
),
|
|
621
|
+
sys_policy: $.from('policy').def(''),
|
|
622
|
+
enforce_acl: $.val(mergeAcls(enforceAcls)),
|
|
623
|
+
})),
|
|
624
|
+
})
|
|
625
|
+
const versionToVersionRecordMap = generateVersionRecords(
|
|
626
|
+
versions,
|
|
627
|
+
restApi,
|
|
628
|
+
restRecord,
|
|
629
|
+
defaultVersion as number,
|
|
630
|
+
factory,
|
|
631
|
+
diagnostics,
|
|
632
|
+
callExpression
|
|
633
|
+
)
|
|
634
|
+
|
|
635
|
+
const routes = restApi.get('routes')?.ifArray()?.getElements() ?? []
|
|
636
|
+
routes.forEach((r) => {
|
|
637
|
+
r.asObject().withAliasedKeys(routeAliases)
|
|
638
|
+
generateDeprecatedDiagnostics(r.asObject(), diagnostics)
|
|
639
|
+
})
|
|
640
|
+
|
|
641
|
+
const routeAndRouteAttrRecords = generateRouteAndRouteAttrRecords(
|
|
642
|
+
routes,
|
|
643
|
+
restRecord,
|
|
644
|
+
factory,
|
|
645
|
+
config,
|
|
646
|
+
diagnostics,
|
|
647
|
+
versionToVersionRecordMap,
|
|
648
|
+
callExpression
|
|
649
|
+
)
|
|
650
|
+
|
|
651
|
+
return {
|
|
652
|
+
success: true,
|
|
653
|
+
value: restRecord.with(...versionToVersionRecordMap.values(), ...routeAndRouteAttrRecords),
|
|
654
|
+
}
|
|
655
|
+
},
|
|
656
|
+
},
|
|
657
|
+
],
|
|
658
|
+
})
|