@servicenow/sdk-build-plugins 4.5.0 → 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.
Files changed (144) hide show
  1. package/dist/column-plugin.js +3 -7
  2. package/dist/column-plugin.js.map +1 -1
  3. package/dist/flow/flow-logic/flow-logic-diagnostics.js +5 -5
  4. package/dist/flow/flow-logic/flow-logic-diagnostics.js.map +1 -1
  5. package/dist/flow/plugins/flow-action-definition-plugin.js +1229 -54
  6. package/dist/flow/plugins/flow-action-definition-plugin.js.map +1 -1
  7. package/dist/flow/plugins/flow-data-pill-plugin.js +5 -2
  8. package/dist/flow/plugins/flow-data-pill-plugin.js.map +1 -1
  9. package/dist/flow/plugins/flow-definition-plugin.js +16 -42
  10. package/dist/flow/plugins/flow-definition-plugin.js.map +1 -1
  11. package/dist/flow/plugins/flow-diagnostics-plugin.d.ts +2 -2
  12. package/dist/flow/plugins/flow-diagnostics-plugin.js +2 -2
  13. package/dist/flow/plugins/flow-instance-plugin.js +68 -22
  14. package/dist/flow/plugins/flow-instance-plugin.js.map +1 -1
  15. package/dist/flow/plugins/step-definition-plugin.js +2 -1
  16. package/dist/flow/plugins/step-definition-plugin.js.map +1 -1
  17. package/dist/flow/plugins/step-instance-plugin.d.ts +9 -1
  18. package/dist/flow/plugins/step-instance-plugin.js +649 -136
  19. package/dist/flow/plugins/step-instance-plugin.js.map +1 -1
  20. package/dist/flow/plugins/wfa-datapill-plugin.js +20 -5
  21. package/dist/flow/plugins/wfa-datapill-plugin.js.map +1 -1
  22. package/dist/flow/post-install.js +1 -0
  23. package/dist/flow/post-install.js.map +1 -1
  24. package/dist/flow/utils/complex-object-resolver.js +4 -1
  25. package/dist/flow/utils/complex-object-resolver.js.map +1 -1
  26. package/dist/flow/utils/complex-objects.js +1 -1
  27. package/dist/flow/utils/complex-objects.js.map +1 -1
  28. package/dist/flow/utils/flow-constants.d.ts +66 -2
  29. package/dist/flow/utils/flow-constants.js +402 -6
  30. package/dist/flow/utils/flow-constants.js.map +1 -1
  31. package/dist/flow/utils/flow-io-to-record.d.ts +1 -1
  32. package/dist/flow/utils/flow-io-to-record.js +37 -16
  33. package/dist/flow/utils/flow-io-to-record.js.map +1 -1
  34. package/dist/flow/utils/flow-shapes.js +4 -0
  35. package/dist/flow/utils/flow-shapes.js.map +1 -1
  36. package/dist/flow/utils/label-cache-parser.d.ts +9 -2
  37. package/dist/flow/utils/label-cache-parser.js +32 -4
  38. package/dist/flow/utils/label-cache-parser.js.map +1 -1
  39. package/dist/flow/utils/pill-shape-helpers.d.ts +15 -0
  40. package/dist/flow/utils/pill-shape-helpers.js +35 -0
  41. package/dist/flow/utils/pill-shape-helpers.js.map +1 -0
  42. package/dist/flow/utils/pill-string-parser.js +1 -0
  43. package/dist/flow/utils/pill-string-parser.js.map +1 -1
  44. package/dist/flow/utils/schema-to-flow-object.d.ts +6 -1
  45. package/dist/flow/utils/schema-to-flow-object.js +131 -15
  46. package/dist/flow/utils/schema-to-flow-object.js.map +1 -1
  47. package/dist/flow/utils/utils.d.ts +1 -0
  48. package/dist/flow/utils/utils.js +6 -1
  49. package/dist/flow/utils/utils.js.map +1 -1
  50. package/dist/form-plugin.js +7 -9
  51. package/dist/form-plugin.js.map +1 -1
  52. package/dist/inbound-email-action-plugin.d.ts +10 -0
  53. package/dist/inbound-email-action-plugin.js +128 -0
  54. package/dist/inbound-email-action-plugin.js.map +1 -0
  55. package/dist/index.d.ts +4 -0
  56. package/dist/index.js +4 -0
  57. package/dist/index.js.map +1 -1
  58. package/dist/instance-scan-plugin.js +0 -5
  59. package/dist/instance-scan-plugin.js.map +1 -1
  60. package/dist/property-plugin.js +1 -1
  61. package/dist/property-plugin.js.map +1 -1
  62. package/dist/record-plugin.d.ts +7 -0
  63. package/dist/record-plugin.js +10 -2
  64. package/dist/record-plugin.js.map +1 -1
  65. package/dist/rest-api-plugin.js +8 -1
  66. package/dist/rest-api-plugin.js.map +1 -1
  67. package/dist/schedule-script/scheduled-script-plugin.js +8 -3
  68. package/dist/schedule-script/scheduled-script-plugin.js.map +1 -1
  69. package/dist/service-catalog/service-catalog-base.d.ts +18 -18
  70. package/dist/service-catalog/service-catalog-base.js +22 -22
  71. package/dist/service-catalog/service-catalog-base.js.map +1 -1
  72. package/dist/service-portal/header-footer-plugin.d.ts +2 -0
  73. package/dist/service-portal/header-footer-plugin.js +50 -0
  74. package/dist/service-portal/header-footer-plugin.js.map +1 -0
  75. package/dist/service-portal/menu-plugin.js +3 -22
  76. package/dist/service-portal/menu-plugin.js.map +1 -1
  77. package/dist/service-portal/page-plugin.js +3 -24
  78. package/dist/service-portal/page-plugin.js.map +1 -1
  79. package/dist/service-portal/page-route-map-plugin.d.ts +2 -0
  80. package/dist/service-portal/page-route-map-plugin.js +114 -0
  81. package/dist/service-portal/page-route-map-plugin.js.map +1 -0
  82. package/dist/service-portal/portal-plugin.js +21 -8
  83. package/dist/service-portal/portal-plugin.js.map +1 -1
  84. package/dist/service-portal/utils.d.ts +40 -2
  85. package/dist/service-portal/utils.js +283 -2
  86. package/dist/service-portal/utils.js.map +1 -1
  87. package/dist/service-portal/widget-plugin.js +9 -218
  88. package/dist/service-portal/widget-plugin.js.map +1 -1
  89. package/dist/static-content-plugin.js +4 -0
  90. package/dist/static-content-plugin.js.map +1 -1
  91. package/dist/table-plugin.js +190 -26
  92. package/dist/table-plugin.js.map +1 -1
  93. package/dist/ui-action-plugin.js +1 -4
  94. package/dist/ui-action-plugin.js.map +1 -1
  95. package/dist/ui-page-plugin.js +68 -13
  96. package/dist/ui-page-plugin.js.map +1 -1
  97. package/dist/view-plugin.js +8 -3
  98. package/dist/view-plugin.js.map +1 -1
  99. package/dist/workspace-plugin.js +39 -36
  100. package/dist/workspace-plugin.js.map +1 -1
  101. package/package.json +5 -4
  102. package/src/column-plugin.ts +3 -8
  103. package/src/flow/flow-logic/flow-logic-diagnostics.ts +5 -6
  104. package/src/flow/plugins/flow-action-definition-plugin.ts +1581 -61
  105. package/src/flow/plugins/flow-data-pill-plugin.ts +5 -2
  106. package/src/flow/plugins/flow-definition-plugin.ts +12 -47
  107. package/src/flow/plugins/flow-diagnostics-plugin.ts +2 -2
  108. package/src/flow/plugins/flow-instance-plugin.ts +98 -22
  109. package/src/flow/plugins/step-definition-plugin.ts +2 -1
  110. package/src/flow/plugins/step-instance-plugin.ts +772 -156
  111. package/src/flow/plugins/wfa-datapill-plugin.ts +25 -5
  112. package/src/flow/post-install.ts +1 -0
  113. package/src/flow/utils/complex-object-resolver.ts +4 -1
  114. package/src/flow/utils/complex-objects.ts +1 -1
  115. package/src/flow/utils/flow-constants.ts +421 -5
  116. package/src/flow/utils/flow-io-to-record.ts +43 -17
  117. package/src/flow/utils/flow-shapes.ts +4 -0
  118. package/src/flow/utils/label-cache-parser.ts +33 -4
  119. package/src/flow/utils/pill-shape-helpers.ts +42 -0
  120. package/src/flow/utils/pill-string-parser.ts +1 -0
  121. package/src/flow/utils/schema-to-flow-object.ts +183 -15
  122. package/src/flow/utils/utils.ts +12 -1
  123. package/src/form-plugin.ts +1 -3
  124. package/src/inbound-email-action-plugin.ts +145 -0
  125. package/src/index.ts +4 -0
  126. package/src/instance-scan-plugin.ts +0 -5
  127. package/src/property-plugin.ts +4 -1
  128. package/src/record-plugin.ts +14 -4
  129. package/src/rest-api-plugin.ts +7 -1
  130. package/src/schedule-script/scheduled-script-plugin.ts +14 -3
  131. package/src/service-catalog/service-catalog-base.ts +22 -22
  132. package/src/service-portal/header-footer-plugin.ts +57 -0
  133. package/src/service-portal/menu-plugin.ts +1 -23
  134. package/src/service-portal/page-plugin.ts +3 -28
  135. package/src/service-portal/page-route-map-plugin.ts +124 -0
  136. package/src/service-portal/portal-plugin.ts +33 -10
  137. package/src/service-portal/utils.ts +404 -3
  138. package/src/service-portal/widget-plugin.ts +14 -290
  139. package/src/static-content-plugin.ts +3 -0
  140. package/src/table-plugin.ts +226 -36
  141. package/src/ui-action-plugin.ts +1 -8
  142. package/src/ui-page-plugin.ts +76 -13
  143. package/src/view-plugin.ts +10 -4
  144. package/src/workspace-plugin.ts +43 -43
@@ -1,22 +1,6 @@
1
- import { CallExpressionShape, isGUID, Plugin, type Shape } from '@servicenow/sdk-build-core'
2
- import { noThrow, reverseObject } from '../utils'
3
- import { type SPTemplate, WidgetCategories } from '@servicenow/sdk-core/runtime/service-portal'
4
- import { NowIdShape } from '../now-id-plugin'
5
- import { NowIncludeShape } from '../now-include-plugin'
1
+ import { CallExpressionShape, Plugin } from '@servicenow/sdk-build-core'
6
2
  import { createSdkDocEntry } from '../utils'
7
- import { createIncludeShape } from './utils'
8
-
9
- function convertOptionSchemaKeys(optionSchema: unknown, convertKey: (key: string) => string): unknown {
10
- if (!Array.isArray(optionSchema)) {
11
- return optionSchema
12
- }
13
- return optionSchema.map((option: Record<string, unknown>) =>
14
- Object.fromEntries(Object.entries(option).map(([k, v]) => [convertKey(k), v]))
15
- )
16
- }
17
-
18
- const toCamelCase = (key: string) => key.replace(/_([a-z])/g, (_, c: string) => c.toUpperCase())
19
- const toSnakeCase = (key: string) => key.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`)
3
+ import { createWidgetToRecord, createWidgetToShape } from './utils'
20
4
 
21
5
  export const SPWidgetPlugin = Plugin.create({
22
6
  name: 'SPWidgetPlugin',
@@ -29,108 +13,7 @@ export const SPWidgetPlugin = Plugin.create({
29
13
  sp_ng_template: { via: 'sp_widget', descendant: true },
30
14
  },
31
15
  async toShape(record, { descendants }) {
32
- const folderName =
33
- record.get('id')?.asString()?.getValue()?.replace(/[\s-]/g, '_') ||
34
- record.get('name')?.asString()?.getValue()?.toLowerCase().replace(/[\s-]/g, '_')
35
- const dependencies = descendants.query('m2m_sp_widget_dependency')
36
- const angularProviders = descendants.query('m2m_sp_ng_pro_sp_widget')
37
- const templates = descendants.query('sp_ng_template').map((template) => {
38
- return {
39
- $id: template.getId(),
40
- id: template.get('id'),
41
- htmlTemplate: template.get('template'),
42
- }
43
- })
44
-
45
- const category = reverseObject(WidgetCategories)[record.get('category').ifString()?.getValue() || '']
46
- const serverScript = await createIncludeShape(
47
- record,
48
- record.get('script'),
49
- 'server_script',
50
- 'js',
51
- folderName
52
- )
53
- const clientScript = await createIncludeShape(
54
- record,
55
- record.get('client_script'),
56
- 'client_script',
57
- 'js',
58
- folderName
59
- )
60
- const css = await createIncludeShape(record, record.get('css'), 'style', 'scss', folderName)
61
- const htmlTemplate = await createIncludeShape(
62
- record,
63
- record.get('template'),
64
- 'template',
65
- 'html',
66
- folderName
67
- )
68
- const linkScript = await createIncludeShape(record, record.get('link'), 'link-script', 'js', folderName)
69
- return {
70
- success: true,
71
- value: new CallExpressionShape({
72
- source: record,
73
- callee: 'SPWidget',
74
- args: [
75
- record.transform(({ $ }) => ({
76
- $id: $.val(NowIdShape.from(record)),
77
- name: $,
78
- category: $.val(category).def('custom'),
79
- clientScript: $.val(clientScript).def(''),
80
- serverScript: $.val(serverScript).def(''),
81
- controllerAs: $.from('controller_as').def('c'),
82
- htmlTemplate: $.val(htmlTemplate).def(''),
83
- customCss: $.val(css).def(''),
84
- dataTable: $.from('data_table').def('sp_instance'),
85
- demoData: $.from('demo_data')
86
- .map((d) => {
87
- const json = d.ifString()?.getValue()
88
-
89
- const parsed = noThrow(() => json && JSON.parse(json))
90
- return parsed instanceof Error ? json : parsed
91
- })
92
- .def(''),
93
- description: $.def(''),
94
- docs: $.def(''),
95
- fields: $.from('field_list')
96
- .map((fields) => {
97
- const fieldStr = fields.ifString()?.getValue()
98
- return fieldStr && fieldStr.split(',')
99
- })
100
- .def(''),
101
- hasPreview: $.from('has_preview').toBoolean().def(false),
102
- id: $.def(''),
103
- internal: $.toBoolean().def(false),
104
- linkScript: $.val(linkScript).def(''),
105
- roles: $.map((role) => {
106
- const roleStr = role.ifString()?.getValue()
107
- return roleStr && roleStr.split(',')
108
- }).def(''),
109
- servicenow: $.toBoolean().def(false),
110
- optionSchema: $.from('option_schema')
111
- .map((v) => {
112
- const json = v.ifString()?.getValue()
113
- const parsed = noThrow(() => json && JSON.parse(json))
114
- const result = parsed instanceof Error ? json : parsed
115
- return convertOptionSchemaKeys(result, toCamelCase)
116
- })
117
- .def(''),
118
- public: $.toBoolean().def(false),
119
- dependencies: $.val(
120
- dependencies.length > 0
121
- ? dependencies.map((dep) => dep.get('sp_dependency'))
122
- : undefined
123
- ),
124
- angularProviders: $.val(
125
- angularProviders.length > 0
126
- ? angularProviders.map((ap) => ap.get('sp_angular_provider'))
127
- : undefined
128
- ),
129
- templates: $.val(templates.length > 0 ? templates : undefined),
130
- })),
131
- ],
132
- }),
133
- }
16
+ return createWidgetToShape(record, descendants, 'SPWidget')
134
17
  },
135
18
  },
136
19
  m2m_sp_widget_dependency: {
@@ -149,177 +32,18 @@ export const SPWidgetPlugin = Plugin.create({
149
32
  return { success: false }
150
33
  }
151
34
 
152
- const widget = callExpression.getArgument(0).asObject()
153
- const dependencies =
154
- widget
155
- .get('dependencies')
156
- .ifArray()
157
- ?.map((dep) => (dep.isString() ? dep.getValue() : dep.ifRecord()?.getId())) || []
158
- const angularProviders =
159
- widget
160
- .get('angularProviders')
161
- .ifArray()
162
- ?.map((ap) => (ap.isString() ? ap.getValue() : ap.ifRecord()?.getId())) || []
163
-
164
- const templates =
165
- widget
166
- .get('templates')
167
- .ifArray()
168
- ?.map((shp) => shp.getValue() as SPTemplate) || []
169
- const widgetId = widget.get('id').ifString()
170
- if (widgetId && !/^[a-zA-Z0-9_-]+$/g.test(widgetId.getValue())) {
171
- diagnostics.error(
172
- widgetId.getOriginalNode(),
173
- `Invalid value: must contain only alphanumeric, -, or _ characters`
174
- )
175
- }
176
-
177
- const clientScript = widget.get('clientScript')
178
- const clientScriptValue =
179
- clientScript instanceof NowIncludeShape
180
- ? clientScript.getValue()
181
- : clientScript.ifString()?.getValue()
182
- if (clientScriptValue && clientScriptValue.trim().length > 0) {
183
- const clientScriptPattern =
184
- /^(function|api\.controller\s?=\s?function)\s?([$a-z_][$0-9a-z_]*)?\s?\(.*\)\s?\n?{/i
185
- if (!clientScriptPattern.test(clientScriptValue.trim())) {
186
- diagnostics.error(
187
- clientScript.getOriginalNode(),
188
- `Client controller must contain a JavaScript function. Example: api.controller = function($scope) { ... }`
189
- )
35
+ return createWidgetToRecord(
36
+ callExpression,
37
+ { diagnostics, factory, config },
38
+ {
39
+ callee: 'SPWidget',
40
+ table: 'sp_widget',
41
+ getDefaultClientScript,
42
+ defaultServerScript: SP_WIDGET_DEFAULT_SERVER_SCRIPT,
43
+ defaultLinkScript: SP_WIDGET_DEFAULT_LINK_SCRIPT,
44
+ defaultHtmlTemplate: SP_WIDGET_DEFAULT_HTML_TEMPLATE,
190
45
  }
191
- }
192
-
193
- const htmlTemplate = widget.get('htmlTemplate')
194
- const htmlTemplateValue =
195
- htmlTemplate instanceof NowIncludeShape
196
- ? htmlTemplate.getValue()
197
- : htmlTemplate.ifString()?.getValue()
198
- if (htmlTemplateValue && htmlTemplateValue.length > 0 && htmlTemplateValue.indexOf('href="#"') > 0) {
199
- diagnostics.error(
200
- htmlTemplate.getOriginalNode(),
201
- `Do not use href="#" in the Service Portal, use href="javascript:void(0)" instead`
202
- )
203
- }
204
-
205
- const roles = widget
206
- .get('roles')
207
- .ifArray()
208
- ?.map((role) => {
209
- if (role.isString()) {
210
- return role
211
- }
212
- if (role.isRecord()) {
213
- return role.get('name')
214
- }
215
-
216
- return undefined
217
- })
218
- .filter((role) => role) as Shape[] | undefined
219
-
220
- if (roles) {
221
- roles
222
- .filter((role) => isGUID(role.getValue() as string))
223
- .forEach((role) =>
224
- diagnostics.error(
225
- role!.getOriginalNode(),
226
- `expecting role names or role records created by the Role or Record plugins, not sys_ids`
227
- )
228
- )
229
- }
230
-
231
- const controller = widget.get('controllerAs').ifString()?.getValue() || 'c'
232
- const servicenow =
233
- (widget.get('servicenow').ifBoolean()?.getValue() &&
234
- (config.scope.startsWith('sn_') || config.scope.startsWith('snc_'))) ||
235
- false
236
-
237
- const widgetRecord = await factory.createRecord({
238
- source: callExpression,
239
- table: 'sp_widget',
240
- explicitId: widget.get('$id'),
241
- properties: widget.transform(({ $ }) => ({
242
- name: $,
243
- category: $.map((v) => {
244
- const catKey = v.ifString()?.getValue() || ''
245
- return WidgetCategories[catKey as keyof typeof WidgetCategories]
246
- }).def('custom'),
247
- client_script: $.from('clientScript').def(getDefaultClientScript(controller)),
248
- script: $.from('serverScript').def(SP_WIDGET_DEFAULT_SERVER_SCRIPT),
249
- controller_as: $.from('controllerAs').def('c'),
250
- template: $.from('htmlTemplate').def(SP_WIDGET_DEFAULT_HTML_TEMPLATE),
251
- css: $.from('customCss').def(''),
252
- data_table: $.from('dataTable').def('sp_instance'),
253
- demo_data: $.from('demoData')
254
- .map((v) =>
255
- v.ifString() || v instanceof NowIncludeShape ? v : JSON.stringify(v.getValue())
256
- )
257
- .def(''),
258
- description: $.def(''),
259
- docs: $.map((v) => (v.isString() ? v : v.ifRecord()?.getId())),
260
- field_list: $.from('fields')
261
- .map((v) => v.getValue()?.toString())
262
- .def(''),
263
- has_preview: $.from('hasPreview').toBoolean().def(false),
264
- id: $.def(''),
265
- internal: $.def(false),
266
- servicenow: $.val(servicenow),
267
- link: $.from('linkScript').def(SP_WIDGET_DEFAULT_LINK_SCRIPT),
268
- roles: $.val(roles?.map((r) => r.getValue()).toString()).def(''),
269
- option_schema: $.from('optionSchema')
270
- .map((v) => {
271
- const json = v.getValue()
272
- const converted = convertOptionSchemaKeys(json, toSnakeCase)
273
- return converted && JSON.stringify(converted)
274
- })
275
- .def(''),
276
- public: $.def(false),
277
- })),
278
- })
279
-
280
- return {
281
- success: true,
282
- value: widgetRecord.with(
283
- ...(await Promise.all(
284
- templates.map(async (template: SPTemplate) => {
285
- return await factory.createRecord({
286
- source: callExpression,
287
- table: 'sp_ng_template',
288
- explicitId: template.$id as string,
289
- properties: {
290
- id: template.id,
291
- sp_widget: widgetRecord.getId(),
292
- template: template.htmlTemplate,
293
- },
294
- })
295
- })
296
- )),
297
- ...(await Promise.all(
298
- dependencies.map(async (dep) => {
299
- return await factory.createRecord({
300
- source: callExpression,
301
- table: 'm2m_sp_widget_dependency',
302
- properties: {
303
- sp_dependency: dep!,
304
- sp_widget: widgetRecord.getId(),
305
- },
306
- })
307
- })
308
- )),
309
- ...(await Promise.all(
310
- angularProviders.map(async (ap) => {
311
- return await factory.createRecord({
312
- source: callExpression,
313
- table: 'm2m_sp_ng_pro_sp_widget',
314
- properties: {
315
- sp_angular_provider: ap!,
316
- sp_widget: widgetRecord.getId(),
317
- },
318
- })
319
- })
320
- ))
321
- ),
322
- }
46
+ )
323
47
  },
324
48
  },
325
49
  ],
@@ -3,6 +3,7 @@ import * as mime from 'mime-types'
3
3
  import { Shape, Plugin, type Record, unloadBuilder, gzipSync, type RecordContext } from '@servicenow/sdk-build-core'
4
4
  import { path as pathModule } from '@servicenow/sdk-build-core'
5
5
  import { INVALID_XML_CHARACTERS } from './utils'
6
+ import { TRANSLATIONS_ASSET_NAME } from '@servicenow/isomorphic-rollup'
6
7
 
7
8
  // based on tectonic code for attachments
8
9
  // https://code.devsnc.com/dev/sn-tectonic/blob/b3ab42ce742158cb5a0d00efd540b97eeafcbdd7/core/metadata-transform-san-diego/utils/index.js#L66
@@ -166,6 +167,8 @@ export const StaticContentPlugin = Plugin.create({
166
167
  // Build-time manifest produced by the uiPageSourceManifest rollup plugin.
167
168
  // Consumed by UiPage during build to determine which source files to include
168
169
  // in the source artifact record. Not a deployable asset.
170
+ } else if (relativePath === TRANSLATIONS_ASSET_NAME) {
171
+ logger.debug('translations not supported yet')
169
172
  } else if (mimeType === 'application/javascript') {
170
173
  tableName = 'sys_ux_lib_asset'
171
174
  assetName = pathModule.join(