@researchdatabox/sails-hook-redbox-servicenow-catalog 0.0.1-beta.35 → 0.0.1-beta.40

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 (70) hide show
  1. package/README.md +269 -65
  2. package/dist/api/configmodels/ServiceNowCatalogAppConfig.d.ts +716 -333
  3. package/dist/api/configmodels/ServiceNowCatalogAppConfig.d.ts.map +1 -1
  4. package/dist/api/configmodels/ServiceNowCatalogAppConfig.js +150 -56
  5. package/dist/api/controllers/CatalogController.d.ts +3 -1
  6. package/dist/api/controllers/CatalogController.d.ts.map +1 -1
  7. package/dist/api/controllers/CatalogController.js +23 -13
  8. package/dist/api/models/ServicenowCatalogIdempotency.d.ts +18 -0
  9. package/dist/api/models/ServicenowCatalogIdempotency.d.ts.map +1 -0
  10. package/dist/api/models/ServicenowCatalogIdempotency.js +76 -0
  11. package/dist/api/models/index.d.ts +5 -0
  12. package/dist/api/models/index.d.ts.map +1 -0
  13. package/dist/api/models/index.js +23 -0
  14. package/dist/api/services/ServicenowCatalogService.d.ts +21 -14
  15. package/dist/api/services/ServicenowCatalogService.d.ts.map +1 -1
  16. package/dist/api/services/ServicenowCatalogService.js +580 -127
  17. package/dist/api/services/servicenow/audit.d.ts +19 -0
  18. package/dist/api/services/servicenow/audit.d.ts.map +1 -1
  19. package/dist/api/services/servicenow/audit.js +78 -3
  20. package/dist/api/services/servicenow/configuration.d.ts +26 -0
  21. package/dist/api/services/servicenow/configuration.d.ts.map +1 -0
  22. package/dist/api/services/servicenow/configuration.js +105 -0
  23. package/dist/api/services/servicenow/context.d.ts +18 -8
  24. package/dist/api/services/servicenow/context.d.ts.map +1 -1
  25. package/dist/api/services/servicenow/context.js +1 -1
  26. package/dist/api/services/servicenow/errors.d.ts +55 -14
  27. package/dist/api/services/servicenow/errors.d.ts.map +1 -1
  28. package/dist/api/services/servicenow/errors.js +50 -22
  29. package/dist/api/services/servicenow/http.d.ts +3 -3
  30. package/dist/api/services/servicenow/http.d.ts.map +1 -1
  31. package/dist/api/services/servicenow/http.js +6 -2
  32. package/dist/api/services/servicenow/idempotency.d.ts +29 -0
  33. package/dist/api/services/servicenow/idempotency.d.ts.map +1 -0
  34. package/dist/api/services/servicenow/idempotency.js +119 -0
  35. package/dist/api/services/servicenow/normalizeResponse.d.ts +4 -0
  36. package/dist/api/services/servicenow/normalizeResponse.d.ts.map +1 -0
  37. package/dist/api/services/servicenow/normalizeResponse.js +16 -0
  38. package/dist/api/services/servicenow/runtime.d.ts +3 -3
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +5 -13
  41. package/package.json +11 -11
  42. package/assets/fonts/.gitkeep +0 -1
  43. package/assets/images/blank.png +0 -0
  44. package/bootstrap-data/vocabularies/servicenow-catalog-storage-sizes.json +0 -11
  45. package/bootstrap-data/vocabularies/servicenow-catalog-storage-types.json +0 -12
  46. package/dist/config/recordtypes.d.ts +0 -3
  47. package/dist/config/recordtypes.d.ts.map +0 -1
  48. package/dist/config/recordtypes.js +0 -35
  49. package/dist/config/workflows.d.ts +0 -3
  50. package/dist/config/workflows.d.ts.map +0 -1
  51. package/dist/config/workflows.js +0 -83
  52. package/dist/config/workspacetypes.d.ts +0 -3
  53. package/dist/config/workspacetypes.d.ts.map +0 -1
  54. package/dist/config/workspacetypes.js +0 -13
  55. package/dist/form-config/index.d.ts +0 -3
  56. package/dist/form-config/index.d.ts.map +0 -1
  57. package/dist/form-config/index.js +0 -15
  58. package/dist/form-config/servicenow-catalog-1.0-draft.d.ts +0 -3
  59. package/dist/form-config/servicenow-catalog-1.0-draft.d.ts.map +0 -1
  60. package/dist/form-config/servicenow-catalog-1.0-draft.js +0 -5
  61. package/dist/form-config/servicenow-catalog-1.0-provisioned.d.ts +0 -3
  62. package/dist/form-config/servicenow-catalog-1.0-provisioned.d.ts.map +0 -1
  63. package/dist/form-config/servicenow-catalog-1.0-provisioned.js +0 -5
  64. package/dist/form-config/servicenow-catalog-1.0-provisioning.d.ts +0 -3
  65. package/dist/form-config/servicenow-catalog-1.0-provisioning.d.ts.map +0 -1
  66. package/dist/form-config/servicenow-catalog-1.0-provisioning.js +0 -5
  67. package/dist/form-config/servicenow-catalog-common.d.ts +0 -3
  68. package/dist/form-config/servicenow-catalog-common.d.ts.map +0 -1
  69. package/dist/form-config/servicenow-catalog-common.js +0 -250
  70. package/views/.gitkeep +0 -1
package/README.md CHANGED
@@ -1,97 +1,301 @@
1
1
  # ServiceNow Catalog Hook for ReDBox v5
2
2
 
3
- This Sails hook adds a ServiceNow-backed workspace record type to ReDBox. Creating a
4
- `servicenow-catalog` workspace can submit a configured ServiceNow catalog request,
5
- write the returned ServiceNow identifiers onto the workspace, and associate the
6
- workspace with its parent research data management plan.
3
+ This hook provides reusable ServiceNow catalog submission mechanics for ReDBox.
4
+ Customer hooks own record types, forms, workflows, and the decision to submit.
5
+ This hook owns named catalog configuration, mapping, OAuth, HTTP retries and
6
+ timeouts, optional parent association, response write-back, auditing, and
7
+ opt-in idempotency.
7
8
 
8
- ## ReDBox v5 structure
9
-
10
- - `src/index.ts` registers hook config, routes, controllers, services, and forms.
11
- - `src/config` contains typed ServiceNow, record type, workflow, authorization, and workspace type config.
12
- - `src/form-config` contains the draft, provisioning, and provisioned form stages.
13
- - `bootstrap-data/vocabularies` contains the production option vocabularies used by the forms.
14
- - `language-defaults/en/translation.json` contains the hook's default English labels.
15
- - `legacy-form-config` preserves the source v4 form and the single-form wrappers used by the migration tool.
16
-
17
- The legacy Angular 5 catalog app remains under `angular/catalog` as migration evidence.
18
- It depends on the removed v4 shared Angular tree and is not part of the v5 build.
9
+ The hook does not register a `servicenow-catalog` record type, workspace type,
10
+ workflow, form, Angular application, view, or navigation entry.
19
11
 
20
12
  ## Configuration
21
13
 
22
- The record trigger uses the brand-aware `servicenowCatalog` application configuration.
23
- It is disabled by default. Configure and enable it independently for each brand through
24
- the ReDBox Application Configuration administration interface.
14
+ `servicenowCatalog` is brand-aware and disabled by default. It contains any
15
+ number of named catalog definitions:
25
16
 
26
17
  ```json
27
18
  {
28
19
  "enabled": true,
29
- "connection": {
30
- "url": "https://example.service-now.com/api/sn_sc/servicecatalog/items/ITEM_ID/order_now",
31
- "method": "post",
32
- "headers": {
33
- "Authorization": "Basic BASE64_CREDENTIALS"
34
- },
35
- "timeoutMs": 30000,
36
- "totalTimeoutMs": 120000,
37
- "retry": {
38
- "maxAttempts": 3,
39
- "baseDelayMs": 1000,
40
- "maxDelayMs": 10000,
41
- "retryOnStatusCodes": [408, 429, 500, 502, 503, 504]
20
+ "catalogs": {
21
+ "storage-new": {
22
+ "enabled": true,
23
+ "connection": {
24
+ "url": "https://example.service-now.com/api/sn_sc/servicecatalog/items/ITEM_ID/order_now",
25
+ "method": "post",
26
+ "headers": {
27
+ "Authorization": "Basic BASE64_CREDENTIALS"
28
+ },
29
+ "timeoutMs": 30000,
30
+ "totalTimeoutMs": 120000,
31
+ "retry": {
32
+ "maxAttempts": 3,
33
+ "baseDelayMs": 1000,
34
+ "maxDelayMs": 10000,
35
+ "retryOnStatusCodes": [408, 429, 500, 502, 503, 504]
36
+ }
37
+ },
38
+ "oauth": {
39
+ "enabled": false,
40
+ "url": "",
41
+ "clientId": "",
42
+ "clientSecret": "",
43
+ "grantType": "client_credentials"
44
+ },
45
+ "bodyTemplate": {
46
+ "sysparm_quantity": "1",
47
+ "get_portal_messages": "true",
48
+ "variables": {}
49
+ },
50
+ "requestFields": [
51
+ {
52
+ "destination": "variables.short_description",
53
+ "source": {
54
+ "kind": "handlebars",
55
+ "template": "{{workspace.metadata.title}}"
56
+ }
57
+ },
58
+ {
59
+ "destination": "variables.requested_size",
60
+ "source": {
61
+ "kind": "jsonata",
62
+ "expression": "workspace.metadata.storage_size"
63
+ }
64
+ }
65
+ ],
66
+ "responseFields": {
67
+ "workspace": [
68
+ {
69
+ "destination": "metadata.servicenow_number",
70
+ "source": {
71
+ "kind": "path",
72
+ "path": "response.result.number"
73
+ }
74
+ },
75
+ {
76
+ "destination": "metadata.status",
77
+ "source": {
78
+ "kind": "path",
79
+ "path": "response.result.state",
80
+ "defaultValue": "Provisioning"
81
+ }
82
+ }
83
+ ],
84
+ "parentRecord": [
85
+ {
86
+ "destination": "metadata.storage_request_number",
87
+ "source": {
88
+ "kind": "path",
89
+ "path": "response.result.number"
90
+ }
91
+ }
92
+ ]
93
+ },
94
+ "parentRecord": {
95
+ "oid": {
96
+ "kind": "path",
97
+ "path": "workspace.metadata.parentOid"
98
+ }
99
+ },
100
+ "responseNormalization": {
101
+ "parseJsonString": true
102
+ },
103
+ "idempotency": {
104
+ "enabled": true,
105
+ "key": {
106
+ "kind": "handlebars",
107
+ "template": "{{oid}}:{{trigger.event}}:storage-new"
108
+ }
109
+ }
42
110
  }
111
+ }
112
+ }
113
+ ```
114
+
115
+ Hook defaults are merged with brand configuration, with the brand values taking
116
+ precedence. New configuration must use named catalogs. The previous
117
+ single-catalog shape is temporarily accepted as a catalog named `default` and
118
+ emits a deprecation warning.
119
+
120
+ The application-configuration model declares the Authorization header, OAuth
121
+ client secret, password, and refresh token as secrets. Do not put credentials
122
+ in mappings, audit summaries, source control, or trigger options.
123
+
124
+ ### OAuth
125
+
126
+ OAuth client-credentials, password, and refresh-token grants are supported.
127
+ When OAuth is enabled, the access token is fetched through the shared HTTP
128
+ runtime and reused across retries for one submission. Additional connection
129
+ headers are still applied, with the OAuth bearer token taking precedence over
130
+ an Authorization header.
131
+
132
+ ## Calling the service
133
+
134
+ A customer-owned save hook calls the standard exported service:
135
+
136
+ ```ts
137
+ const result = await sails.services.servicenowcatalogservice.submitRequest(
138
+ oid,
139
+ workspaceData,
140
+ {
141
+ catalog: 'storage-new',
142
+ event: 'create',
143
+ // Optional when the catalog's idempotency binding resolves a key.
144
+ idempotencyKey: oid + ':create:storage-new',
145
+ // Optional when the caller has already resolved the relationship.
146
+ parentRecordOid: workspaceData.metadata.parentOid
43
147
  },
44
- "requestFields": [
45
- {
46
- "destination": "variables.short_description",
47
- "source": { "kind": "handlebars", "template": "{{workspace.metadata.title}}" }
48
- },
49
- {
50
- "destination": "variables.requested_size",
51
- "source": { "kind": "jsonata", "expression": "workspace.metadata.storage_size" }
52
- }
53
- ]
148
+ req.user,
149
+ response
150
+ );
151
+ ```
152
+
153
+ `catalog` and `event` are required. Runtime options cannot replace catalog
154
+ URLs, credentials, body templates, retry policy, or mappings. An integration or
155
+ catalog that is explicitly disabled returns the incoming trigger response
156
+ unchanged. Validation, duplicate, mapping, parent, OAuth, request, timeout, and
157
+ write-back failures return the normal structured trigger failure without
158
+ deleting the saved workspace.
159
+
160
+ ## Mapping contract
161
+
162
+ Request and response fields use the core `ValueBinding` model:
163
+
164
+ - `path`: read a dot-notation path;
165
+ - `handlebars`: render a Handlebars template;
166
+ - `jsonata`: evaluate a JSONata expression.
167
+
168
+ Every request mapping receives this stable context:
169
+
170
+ ```ts
171
+ {
172
+ workspace,
173
+ parentRecord, // undefined when the catalog has no parent
174
+ oid,
175
+ brand, // resolved brand name
176
+ trigger: {
177
+ catalog,
178
+ event,
179
+ idempotencyKey?,
180
+ parentRecordOid?
181
+ },
182
+ now, // ISO-8601 string
183
+ translationService
54
184
  }
55
185
  ```
56
186
 
57
- Mappings use the same path, Handlebars, and JSONata value-binding model as the core DOI
58
- and Figshare integrations. Response mappings write ServiceNow identifiers back to the
59
- workspace. Trigger options can override the brand configuration for a single run.
187
+ Response mappings receive the same values plus `response`, containing the
188
+ normalized ServiceNow response. New response mappings should use paths such as
189
+ `response.result.number`. A temporary raw-response root alias is retained for
190
+ older `result.*` mappings.
60
191
 
61
- OAuth client-credentials, password, and refresh-token grants are supported through the
62
- `oauth` block. Application Configuration masks OAuth secrets and the Authorization
63
- header; do not commit raw credentials to this hook.
192
+ Mappings are applied to clones and reject prototype-polluting destination
193
+ paths. Workspace and parent mappings are independent. Metadata is written only
194
+ when the corresponding mapping list is non-empty. The service never assigns a
195
+ hard-coded status; status changes must be expressed as ordinary response
196
+ mappings, binding defaults, or expressions.
64
197
 
65
- The compatibility endpoints under `/:branding/:portal/ws/catalog` use the legacy
66
- `sails.config.workspaces.catalog` settings when the standalone workspace flow is still enabled.
198
+ ## Parent records
199
+
200
+ Parent handling is optional and relationship-neutral. A caller can supply
201
+ `parentRecordOid`, or the catalog can resolve it from `parentRecord.oid`.
202
+ When configured, the OID must be non-empty and the record must exist. The
203
+ service loads the parent through `RecordsService`, associates the workspace
204
+ through `WorkspaceService.addWorkspaceToRecord`, and applies optional parent
205
+ response mappings through `RecordsService.updateMeta`.
206
+
207
+ Catalogs without a parent binding perform no parent lookup, association, or
208
+ parent update. No generic code assumes `metadata.rdmpOid`.
209
+
210
+ ## Response normalization
211
+
212
+ With `responseNormalization.parseJsonString` enabled (the default), an HTTP
213
+ response whose root value is a JSON-encoded string is parsed before response
214
+ mapping. Object and array responses are unchanged. A root string that is not
215
+ valid JSON is preserved as a string.
216
+
217
+ ## Auditing and idempotency
218
+
219
+ The integration audit records the overall submission and nested phases for
220
+ parent lookup, association, ServiceNow HTTP work, workspace update, parent
221
+ update, and idempotency decisions. Request summaries include the selected
222
+ catalog, trigger event, optional parent OID, and stable idempotency key, but not
223
+ credentials or full request bodies.
224
+
225
+ Idempotency is disabled by default. When enabled, a key must come from the
226
+ trigger or the configured binding. The hook-owned
227
+ `ServicenowCatalogIdempotency` Waterline model is the atomic durable claim
228
+ ledger. Its primary key is derived from an unambiguous JSON-array encoding of
229
+ brand ID, record OID, catalog, and idempotency key. Integration audit history
230
+ provides the submission evidence used to reconcile claim state:
231
+
232
+ - a prior completed key is rejected as a duplicate;
233
+ - a prior started/interrupted key is rejected because ServiceNow may have
234
+ accepted the request;
235
+ - a prior failed trace can be retried;
236
+ - an in-process guard also rejects concurrent duplicates in one portal process.
237
+
238
+ Claims move through `claimed`, `completed`, `failed`, and `uncertain`.
239
+ A `claimed` row is leased for the greater of five minutes or the configured
240
+ `totalTimeoutMs` plus a one-minute safety margin, so the lease covers the
241
+ complete orchestration side-effect window. After expiry, one process atomically
242
+ takes reconciliation ownership and checks ServiceNow-scoped audit history
243
+ before doing anything external: a successful trace becomes `completed`, a
244
+ started or interrupted trace becomes `uncertain`, and a clear trace may be
245
+ submitted again. If reconciliation lookup itself fails, a recovered stale
246
+ claim becomes `uncertain` rather than retryable.
247
+
248
+ Completed and uncertain rows have no automatic retention expiry because deleting
249
+ them re-enables their keys. Operators may remove them only when the corresponding
250
+ idempotency-key protection window has deliberately ended. Failed rows are
251
+ retained until atomically reclaimed by a later attempt.
252
+
253
+ ## Legacy compatibility endpoints
254
+
255
+ These routes remain for compatibility only and are not the reusable save-hook
256
+ API:
257
+
258
+ - `POST /:branding/:portal/ws/catalog/rdmp`
259
+ - `POST /:branding/:portal/ws/catalog/request`
260
+ - `GET /:branding/:portal/ws/catalog/info`
261
+
262
+ They continue to use the isolated legacy `sails.config.workspaces.catalog`
263
+ settings and their existing authorization/response conventions. The request
264
+ endpoint no longer falls back to hook-owned record or workflow names:
265
+ `workspaces.catalog.recordType` and `workspaces.catalog.workflowStage` must
266
+ be configured when that endpoint creates a workspace.
267
+
268
+ The historical `legacy-form-config/` and `angular/catalog/` directories are
269
+ migration evidence only. They are not compiled, registered, or included in the
270
+ published package.
67
271
 
68
272
  ## Development
69
273
 
274
+ Use the hook archetype scripts:
275
+
70
276
  ```bash
71
- npm install
277
+ npm install --include=dev
72
278
  npm run compile
73
279
  npm run test:unit
74
- redbox-dev-tools check
280
+ npm run test:integration:mocha
281
+ npm run test:integration:bruno
75
282
  ```
76
283
 
77
- The Docker-backed portal integration harness is available with:
284
+ The integration suites build and lift a real ReDBox portal with MongoDB and
285
+ Solr. Mocha covers the service orchestration and Bruno covers authorization for
286
+ every retained compatibility route. Clean their Docker resources when needed:
78
287
 
79
288
  ```bash
80
- npm run test:integration:mocha
289
+ npm run test:integration:mocha:clean
290
+ npm run test:integration:bruno:clean
81
291
  ```
82
292
 
83
293
  ## CI and releases
84
294
 
85
- CircleCI compiles and runs the unit suite for every branch. Stable Git tags matching
86
- `vMAJOR.MINOR.PATCH` run the same checks and publish the matching package version with
87
- the npm `latest` dist-tag.
88
-
89
- Beta packages are published by triggering a CircleCI pipeline with:
90
-
91
- - `npm_publish_mode`: `beta`
92
- - `npm_publish_version`: the stable base version, for example `1.2.3`
93
- - `npm_publish_dist_tag`: `beta`, `next`, or `alpha`
295
+ CircleCI compiles and runs the unit suite for every branch. Stable Git tags
296
+ matching `vMAJOR.MINOR.PATCH` publish the matching package version with the npm
297
+ `latest` dist-tag.
94
298
 
95
- The published prerelease version includes the pipeline number, such as
96
- `1.2.3-beta.456`. Publishing uses npm trusted publishing through the CircleCI
97
- `npm-publish` context.
299
+ Beta packages are published by triggering a CircleCI pipeline with
300
+ `npm_publish_mode=beta`, a stable base `npm_publish_version`, and an
301
+ `npm_publish_dist_tag` such as `beta`, `next`, or `alpha`.