@sortlist/cli 0.39.0 → 0.40.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.
package/dist/index.js CHANGED
@@ -290,6 +290,19 @@ import {
290
290
  // src/graphql/client.ts
291
291
  import { print } from "graphql";
292
292
 
293
+ // src/lib/api-headers.ts
294
+ var API_CLIENT = "sl-cli";
295
+ function userAgent() {
296
+ return `${API_CLIENT}/${pkg.version} (node/${process.versions.node})`;
297
+ }
298
+ function baseRequestHeaders() {
299
+ return {
300
+ "Content-Type": "application/json",
301
+ "X-API-Client": API_CLIENT,
302
+ "User-Agent": userAgent()
303
+ };
304
+ }
305
+
293
306
  // src/lib/token-claims.ts
294
307
  function tokenClaims(accessToken) {
295
308
  try {
@@ -537,7 +550,7 @@ var GraphQLRequestError = class extends Error {
537
550
  async function refreshAccessToken(creds, endpoint) {
538
551
  const res = await fetch(endpoint, {
539
552
  method: "POST",
540
- headers: { "Content-Type": "application/json", "X-API-Client": "sl-cli" },
553
+ headers: baseRequestHeaders(),
541
554
  body: JSON.stringify({
542
555
  query: print(RefreshToken),
543
556
  variables: { input: { refreshToken: creds.refreshToken } }
@@ -781,10 +794,7 @@ async function executeQuery(query, variables, options = {}) {
781
794
  level: "info"
782
795
  });
783
796
  if (attempt.verbose) logRequest(query, variables, attempt);
784
- const headers = {
785
- "Content-Type": "application/json",
786
- "X-API-Client": "sl-cli"
787
- };
797
+ const headers = baseRequestHeaders();
788
798
  if (authenticated) {
789
799
  const { token, kind } = await resolveAccessToken(options, attempt);
790
800
  headers["Authorization"] = `Bearer ${token}`;
@@ -850,6 +860,7 @@ import {
850
860
  isScalarType,
851
861
  isUnionType
852
862
  } from "graphql";
863
+ var CLI_OPERATION_PREFIX = "SlCli_";
853
864
  function unwrap(type) {
854
865
  if (isNonNullType(type)) return unwrap(type.ofType);
855
866
  if (isListType(type)) return unwrap(type.ofType);
@@ -1019,7 +1030,7 @@ ${body}
1019
1030
  }`;
1020
1031
  }
1021
1032
  }
1022
- const opName = ucfirst(fieldName);
1033
+ const opName = `${CLI_OPERATION_PREFIX}${ucfirst(fieldName)}`;
1023
1034
  const query = `${kind} ${opName}${varDefs} {
1024
1035
  ${selectionBody}
1025
1036
  }`;
@@ -1959,10 +1970,7 @@ function writeCache(endpoint, token, introspection, raw) {
1959
1970
  }
1960
1971
  }
1961
1972
  async function fetchIntrospection(endpoint, token) {
1962
- const headers = {
1963
- "Content-Type": "application/json",
1964
- "X-API-Client": "sl-cli"
1965
- };
1973
+ const headers = baseRequestHeaders();
1966
1974
  if (token) headers["Authorization"] = `Bearer ${token}`;
1967
1975
  const res = await fetch(endpoint, {
1968
1976
  method: "POST",