55 * 2.0.
66 */
77
8+ import { isPlainObject } from 'lodash' ;
89import { PreConfiguredAction , RawAction } from '../types' ;
910
1011export type ConnectorWithOptionalDeprecation = Omit < PreConfiguredAction , 'isDeprecated' > &
1112 Pick < Partial < PreConfiguredAction > , 'isDeprecated' > ;
1213
14+ const isObject = ( obj : unknown ) : obj is Record < string , unknown > => isPlainObject ( obj ) ;
15+
1316export const isConnectorDeprecated = (
1417 connector : RawAction | ConnectorWithOptionalDeprecation
1518) : boolean => {
@@ -18,11 +21,40 @@ export const isConnectorDeprecated = (
1821 * Connectors after the Elastic ServiceNow application use the
1922 * Import Set API (https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_ImportSetAPI)
2023 * A ServiceNow connector is considered deprecated if it uses the Table API.
21- *
22- * All other connectors do not have the usesTableApi config property
23- * so the function will always return false for them.
2424 */
25- return ! ! connector . config ?. usesTableApi ;
25+
26+ /**
27+ * We cannot deduct if the connector is
28+ * deprecated without config. In this case
29+ * we always return false.
30+ */
31+ if ( ! isObject ( connector . config ) ) {
32+ return false ;
33+ }
34+
35+ /**
36+ * If the usesTableApi is not defined it means that the connector is created
37+ * before the introduction of the usesTableApi property. In that case, the connector is assumed
38+ * to be deprecated because all connectors prior 7.16 where using the Table API.
39+ * Migrations x-pack/plugins/actions/server/saved_objects/actions_migrations.ts set
40+ * the usesTableApi property to true to all connectors prior 7.16. Pre configured connectors
41+ * cannot be migrated. This check ensures that pre configured connectors without the
42+ * usesTableApi property explicitly in the kibana.yml file are considered deprecated.
43+ * According to the schema defined here x-pack/plugins/actions/server/builtin_action_types/servicenow/schema.ts
44+ * if the property is not defined it will be set to true at the execution of the connector.
45+ */
46+ if ( ! Object . hasOwn ( connector . config , 'usesTableApi' ) ) {
47+ return true ;
48+ }
49+
50+ /**
51+ * Connector created prior to 7.16 will be migrated to have the usesTableApi property set to true.
52+ * Connectors created after 7.16 should have the usesTableApi property set to true or false.
53+ * If the usesTableApi is omitted on an API call it will be defaulted to true. Check the schema
54+ * here x-pack/plugins/actions/server/builtin_action_types/servicenow/schema.ts.
55+ * The !! is to make TS happy.
56+ */
57+ return ! ! connector . config . usesTableApi ;
2658 }
2759
2860 return false ;
0 commit comments