@@ -16,13 +16,19 @@ import type { ExtendedSecurity } from 'respect-core/src/types.js';
1616import { ulid } from 'ulid' ;
1717import type { Arguments } from 'yargs' ;
1818
19+ import type { CriterionObject } from '../../../core/src/typings/arazzo.js' ;
1920import { getReuniteUrl } from '../reunite/api/index.js' ;
2021import type { CommandArgv } from '../types.js' ;
2122import { ANONYMOUS_ID_CACHE_FILE } from './constants.js' ;
2223import type { ExitCode } from './miscellaneous.js' ;
2324import { respondWithinMs } from './network-check.js' ;
2425import { version } from './package.js' ;
2526
27+ type ArazzoWorkflow = NonNullable < ArazzoDefinition [ 'workflows' ] > [ number ] ;
28+ type ArazzoStep = ArazzoWorkflow [ 'steps' ] [ number ] ;
29+ type ArazzoSuccessAction = NonNullable < ArazzoWorkflow [ 'successActions' ] > [ number ] ;
30+ type ArazzoFailureAction = NonNullable < ArazzoWorkflow [ 'failureActions' ] > [ number ] ;
31+
2632const SECRET_REPLACEMENT = '***' ;
2733
2834export async function sendTelemetry ( {
@@ -34,6 +40,8 @@ export async function sendTelemetry({
3440 spec_keyword,
3541 spec_full_version,
3642 respect_x_security_auth_types,
43+ respect_source_description_types,
44+ respect_criterion_object_types,
3745} : {
3846 config : Config | undefined ;
3947 argv : Arguments < CommandArgv > | undefined ;
@@ -43,6 +51,8 @@ export async function sendTelemetry({
4351 spec_keyword : string | undefined ;
4452 spec_full_version : string | undefined ;
4553 respect_x_security_auth_types : string [ ] | undefined ;
54+ respect_source_description_types : string [ ] | undefined ;
55+ respect_criterion_object_types : string [ ] | undefined ;
4656} ) : Promise < void > {
4757 try {
4858 if ( ! argv ) {
@@ -93,6 +103,14 @@ export async function sendTelemetry({
93103 spec_version === 'arazzo1' && respect_x_security_auth_types ?. length
94104 ? JSON . stringify ( respect_x_security_auth_types )
95105 : undefined ,
106+ respect_source_description_types :
107+ spec_version === 'arazzo1' && respect_source_description_types ?. length
108+ ? JSON . stringify ( respect_source_description_types )
109+ : undefined ,
110+ respect_criterion_object_types :
111+ spec_version === 'arazzo1' && respect_criterion_object_types ?. length
112+ ? JSON . stringify ( respect_criterion_object_types )
113+ : undefined ,
96114 } ,
97115 ] ;
98116
@@ -117,18 +135,79 @@ export async function sendTelemetry({
117135 }
118136}
119137
138+ export function collectSourceDescriptionTypes (
139+ document : Partial < ArazzoDefinition > ,
140+ respectSourceDescriptionTypes : Set < string >
141+ ) {
142+ for ( const sourceDescription of document . sourceDescriptions ?? [ ] ) {
143+ if ( sourceDescription . type ) {
144+ respectSourceDescriptionTypes . add ( sourceDescription . type ) ;
145+ }
146+ }
147+ }
148+
149+ export function collectCriterionObjectTypes (
150+ document : Partial < ArazzoDefinition > ,
151+ respectCriterionObjectTypes : Set < string >
152+ ) {
153+ for ( const criterionObject of getCriterionObjects ( document ) ) {
154+ const type = getCriterionObjectType ( criterionObject ) ;
155+ if ( type ) {
156+ respectCriterionObjectTypes . add ( type ) ;
157+ }
158+ }
159+ }
160+
161+ function getCriterionObjects ( document : Partial < ArazzoDefinition > ) {
162+ const criterionObjects : CriterionObject [ ] = [ ] ;
163+
164+ for ( const workflow of document . workflows ?? [ ] ) {
165+ collectActionCriteria ( workflow . successActions , criterionObjects ) ;
166+ collectActionCriteria ( workflow . failureActions , criterionObjects ) ;
167+
168+ for ( const step of workflow . steps ?? [ ] ) {
169+ collectStepCriteria ( step , criterionObjects ) ;
170+ }
171+ }
172+
173+ collectActionCriteria ( Object . values ( document . components ?. successActions ?? { } ) , criterionObjects ) ;
174+ collectActionCriteria ( Object . values ( document . components ?. failureActions ?? { } ) , criterionObjects ) ;
175+
176+ return criterionObjects ;
177+ }
178+
179+ function collectStepCriteria ( step : ArazzoStep , criterionObjects : CriterionObject [ ] ) {
180+ criterionObjects . push ( ...( step . successCriteria ?? [ ] ) ) ;
181+ collectActionCriteria ( step . onSuccess , criterionObjects ) ;
182+ collectActionCriteria ( step . onFailure , criterionObjects ) ;
183+ }
184+
185+ function collectActionCriteria (
186+ actions : readonly ( ArazzoSuccessAction | ArazzoFailureAction ) [ ] | undefined ,
187+ criterionObjects : CriterionObject [ ]
188+ ) {
189+ criterionObjects . push ( ...( actions ?? [ ] ) . flatMap ( ( action ) => action . criteria ?? [ ] ) ) ;
190+ }
191+
192+ function getCriterionObjectType ( criterionObject : CriterionObject ) {
193+ const type = criterionObject . type ;
194+ return typeof type === 'string'
195+ ? type
196+ : type ?. type || ( criterionObject . condition ? 'simple' : undefined ) ;
197+ }
198+
120199export function collectXSecurityAuthTypes (
121200 document : Partial < ArazzoDefinition > ,
122- respectXSecurityAuthTypesAndSchemeName : string [ ]
201+ respectXSecurityAuthTypesAndSchemeName : Set < string >
123202) {
124203 for ( const workflow of document . workflows ?? [ ] ) {
125204 // Collect auth types from workflow-level x-security
126205 for ( const security of workflow [ 'x-security' ] ?? [ ] ) {
127206 const scheme = ( security as ExtendedSecurity ) . scheme ;
128207 if ( scheme ?. type ) {
129208 const authType = scheme . type === 'http' ? scheme . scheme : scheme . type ;
130- if ( authType && ! respectXSecurityAuthTypesAndSchemeName . includes ( authType ) ) {
131- respectXSecurityAuthTypesAndSchemeName . push ( authType ) ;
209+ if ( authType ) {
210+ respectXSecurityAuthTypesAndSchemeName . add ( authType ) ;
132211 }
133212 }
134213 }
@@ -140,15 +219,15 @@ export function collectXSecurityAuthTypes(
140219 const scheme = ( security as ExtendedSecurity ) . scheme ;
141220 if ( scheme ?. type ) {
142221 const authType = scheme . type === 'http' ? scheme . scheme : scheme . type ;
143- if ( authType && ! respectXSecurityAuthTypesAndSchemeName . includes ( authType ) ) {
144- respectXSecurityAuthTypesAndSchemeName . push ( authType ) ;
222+ if ( authType ) {
223+ respectXSecurityAuthTypesAndSchemeName . add ( authType ) ;
145224 }
146225 }
147226
148227 // Handle schemeName case
149228 const schemeName = ( security as ExtendedSecurity ) . schemeName ;
150- if ( schemeName && ! respectXSecurityAuthTypesAndSchemeName . includes ( schemeName ) ) {
151- respectXSecurityAuthTypesAndSchemeName . push ( schemeName ) ;
229+ if ( schemeName ) {
230+ respectXSecurityAuthTypesAndSchemeName . add ( schemeName ) ;
152231 }
153232 }
154233 }
0 commit comments