@@ -51,16 +51,18 @@ function isAbortAction(result: Parameters<CollectUsageCallback>[1]): result is A
51
51
return 'action' in result && result . action === 'abort' ;
52
52
}
53
53
54
+ const noopUsageCollector : UsageCollector = {
55
+ collect ( ) {
56
+ return async ( ) => { } ;
57
+ } ,
58
+ collectRequest ( ) { } ,
59
+ async dispose ( ) { } ,
60
+ collectSubscription ( ) { } ,
61
+ } ;
62
+
54
63
export function createUsage ( pluginOptions : HivePluginOptions ) : UsageCollector {
55
64
if ( ! pluginOptions . usage || pluginOptions . enabled === false ) {
56
- return {
57
- collect ( ) {
58
- return async ( ) => { } ;
59
- } ,
60
- collectRequest ( ) { } ,
61
- async dispose ( ) { } ,
62
- collectSubscription ( ) { } ,
63
- } ;
65
+ return noopUsageCollector ;
64
66
}
65
67
66
68
let reportSize = 0 ;
@@ -75,6 +77,23 @@ export function createUsage(pluginOptions: HivePluginOptions): UsageCollector {
75
77
const collector = memo ( createCollector , arg => arg . schema ) ;
76
78
const excludeSet = new Set ( options . exclude ?? [ ] ) ;
77
79
80
+ /** Access tokens using the `hvo1/` require a target. */
81
+ if ( ! options . target && pluginOptions . token . startsWith ( 'hvo1/' ) ) {
82
+ logger . error (
83
+ "Using an organization access token (starting with 'hvo1/') requires providing the 'target' option." +
84
+ '\nUsage reporting is disabled.' ,
85
+ ) ;
86
+ return noopUsageCollector ;
87
+ }
88
+
89
+ if ( options . target && ! pluginOptions . token . startsWith ( 'hvo1/' ) ) {
90
+ logger . error (
91
+ "Using the 'target' option requires using an organization access token (starting with 'hvo1/')." +
92
+ '\nUsage reporting is disabled.' ,
93
+ ) ;
94
+ return noopUsageCollector ;
95
+ }
96
+
78
97
const baseEndpoint =
79
98
selfHostingOptions ?. usageEndpoint ?? options . endpoint ?? 'https://app.graphql-hive.com/usage' ;
80
99
0 commit comments