From 879972e31781b033b0647ed35a46cbb6008fc613 Mon Sep 17 00:00:00 2001 From: Jeremy Moseley Date: Tue, 30 Jul 2024 08:24:31 -0700 Subject: [PATCH] Add user agent for requests. (#42) * Add user agent for requests. * Bump version. * Fix lint * More closely follow the spec for user agent strings. --- package.json | 2 +- src/api-client.ts | 4 ++++ tsconfig.json | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index aef64a4..3974f7b 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "url": "https://github.com/cortexclick/cortex-sdk", "type": "git" }, - "version": "0.0.8", + "version": "0.0.9", "type": "module", "main": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/src/api-client.ts b/src/api-client.ts index 7288a35..8d596e2 100644 --- a/src/api-client.ts +++ b/src/api-client.ts @@ -1,3 +1,5 @@ +import { version } from "../package.json"; + type Method = "POST" | "GET" | "PUT" | "DELETE"; // body can be any object @@ -38,6 +40,7 @@ export class CortexApiClient { method: "POST", headers: { Authorization: `Bearer ${this.accessToken}`, + "User-Agent": `cortex-js-sdk/${version}`, }, body: form, }); @@ -56,6 +59,7 @@ export class CortexApiClient { headers: { Authorization: `Bearer ${this.accessToken}`, "Content-Type": "application/json", + "User-Agent": `cortex-js-sdk-v${version}`, }, body: requestBody, }); diff --git a/tsconfig.json b/tsconfig.json index b419a0a..ce7e246 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -42,7 +42,7 @@ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ - // "resolveJsonModule": true, /* Enable importing .json files. */ + "resolveJsonModule": true /* Enable importing .json files. */, // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ /* JavaScript Support */