diff --git a/.stats.yml b/.stats.yml index 006b15f4..58526a77 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1 +1 @@ -configured_endpoints: 47 +configured_endpoints: 48 diff --git a/api.md b/api.md index ddd53dd9..bd17b032 100644 --- a/api.md +++ b/api.md @@ -178,6 +178,17 @@ Methods: - client.accounts.usage.get({ ...params }) -> UsageGetResponse +## UsageAnalytics + +Types: + +- RequestBandwidthEntry +- UsageAnalyticsResponse + +Methods: + +- client.accounts.usageAnalytics.get({ ...params }) -> UsageAnalyticsResponse + ## Origins Types: diff --git a/packages/mcp-server/src/code-tool-worker.ts b/packages/mcp-server/src/code-tool-worker.ts index 07b79f57..5a77482d 100644 --- a/packages/mcp-server/src/code-tool-worker.ts +++ b/packages/mcp-server/src/code-tool-worker.ts @@ -144,6 +144,7 @@ const fuse = new Fuse( 'client.folders.rename', 'client.folders.job.get', 'client.accounts.usage.get', + 'client.accounts.usageAnalytics.get', 'client.accounts.origins.create', 'client.accounts.origins.delete', 'client.accounts.origins.get', diff --git a/packages/mcp-server/src/local-docs-search.ts b/packages/mcp-server/src/local-docs-search.ts index ed9ada0c..af96b280 100644 --- a/packages/mcp-server/src/local-docs-search.ts +++ b/packages/mcp-server/src/local-docs-search.ts @@ -2059,14 +2059,14 @@ const EMBEDDED_METHODS: MethodEntry[] = [ httpMethod: 'get', summary: 'Get account usage information', description: - 'Get the account usage information between two dates. Note that the API response includes data from the start date while excluding data from the end date. In other words, the data covers the period starting from the specified start date up to, but not including, the end date.\n', + 'Get the account usage information between two dates. Note that the API response includes data from the start date while excluding data from the end date. In other words, the data covers the period starting from the specified start date up to, but not including, the end date.\n\nFor an agency account, the returned usage is aggregated across the agency and all of its child accounts that are billed to it.\n\nThe response is cached for 6 hours per account, date range and requested metrics.\n', stainlessPath: '(resource) accounts.usage > (method) get', qualified: 'client.accounts.usage.get', params: ['endDate: string;', 'startDate: string;'], response: '{ bandwidthBytes?: number; extensionUnitsCount?: number; mediaLibraryStorageBytes?: number; originalCacheStorageBytes?: number; videoProcessingUnitsCount?: number; }', markdown: - "## get\n\n`client.accounts.usage.get(endDate: string, startDate: string): { bandwidthBytes?: number; extensionUnitsCount?: number; mediaLibraryStorageBytes?: number; originalCacheStorageBytes?: number; videoProcessingUnitsCount?: number; }`\n\n**get** `/v1/accounts/usage`\n\nGet the account usage information between two dates. Note that the API response includes data from the start date while excluding data from the end date. In other words, the data covers the period starting from the specified start date up to, but not including, the end date.\n\n\n### Parameters\n\n- `endDate: string`\n Specify a `endDate` in `YYYY-MM-DD` format. It should be after the `startDate`. The difference between `startDate` and `endDate` should be less than 90 days.\n\n- `startDate: string`\n Specify a `startDate` in `YYYY-MM-DD` format. It should be before the `endDate`. The difference between `startDate` and `endDate` should be less than 90 days.\n\n### Returns\n\n- `{ bandwidthBytes?: number; extensionUnitsCount?: number; mediaLibraryStorageBytes?: number; originalCacheStorageBytes?: number; videoProcessingUnitsCount?: number; }`\n\n - `bandwidthBytes?: number`\n - `extensionUnitsCount?: number`\n - `mediaLibraryStorageBytes?: number`\n - `originalCacheStorageBytes?: number`\n - `videoProcessingUnitsCount?: number`\n\n### Example\n\n```typescript\nimport ImageKit from '@imagekit/nodejs';\n\nconst client = new ImageKit();\n\nconst usage = await client.accounts.usage.get({ endDate: '2019-12-27', startDate: '2019-12-27' });\n\nconsole.log(usage);\n```", + "## get\n\n`client.accounts.usage.get(endDate: string, startDate: string): { bandwidthBytes?: number; extensionUnitsCount?: number; mediaLibraryStorageBytes?: number; originalCacheStorageBytes?: number; videoProcessingUnitsCount?: number; }`\n\n**get** `/v1/accounts/usage`\n\nGet the account usage information between two dates. Note that the API response includes data from the start date while excluding data from the end date. In other words, the data covers the period starting from the specified start date up to, but not including, the end date.\n\nFor an agency account, the returned usage is aggregated across the agency and all of its child accounts that are billed to it.\n\nThe response is cached for 6 hours per account, date range and requested metrics.\n\n\n### Parameters\n\n- `endDate: string`\n Specify a `endDate` in `YYYY-MM-DD` format. It should be after the `startDate`. The difference between `startDate` and `endDate` should be less than 90 days.\n\n- `startDate: string`\n Specify a `startDate` in `YYYY-MM-DD` format. It should be before the `endDate`. The difference between `startDate` and `endDate` should be less than 90 days.\n\n### Returns\n\n- `{ bandwidthBytes?: number; extensionUnitsCount?: number; mediaLibraryStorageBytes?: number; originalCacheStorageBytes?: number; videoProcessingUnitsCount?: number; }`\n\n - `bandwidthBytes?: number`\n - `extensionUnitsCount?: number`\n - `mediaLibraryStorageBytes?: number`\n - `originalCacheStorageBytes?: number`\n - `videoProcessingUnitsCount?: number`\n\n### Example\n\n```typescript\nimport ImageKit from '@imagekit/nodejs';\n\nconst client = new ImageKit();\n\nconst usage = await client.accounts.usage.get({ endDate: '2019-12-27', startDate: '2019-12-27' });\n\nconsole.log(usage);\n```", perLanguage: { go: { method: 'client.Accounts.Usage.Get', @@ -2109,6 +2109,62 @@ const EMBEDDED_METHODS: MethodEntry[] = [ }, }, }, + { + name: 'get', + endpoint: '/v1/accounts/usage-analytics', + httpMethod: 'get', + summary: 'Get usage analytics', + description: + "**Note:** This API is currently in beta. \n\nGet the account analytics data between two dates. The response covers the period from the start date to the end date, both dates inclusive. Both dates are interpreted as UTC calendar days.\n\nThe returned data is scoped to the requesting account only. Unlike `/v1/accounts/usage`, an agency account's analytics are not aggregated across its child accounts.\n\nThe response is cached for 5 minutes per account and date range. Use `generatedAt` to check how fresh the returned data is.\n", + stainlessPath: '(resource) accounts.usageAnalytics > (method) get', + qualified: 'client.accounts.usageAnalytics.get', + params: ['endDate: string;', 'startDate: string;'], + response: + '{ bandwidthBytes: number; browser: object; cache: object; country: object; device: object; endDate: string; errorReasons: object[]; extensions: object[]; format: object; generatedAt: string; requestCount: number; startDate: string; statusCodes: object[]; top404Assets: object[]; topImages: object; topImageTransforms: object; topOtherAssets: object; topReferrers: object; topUserAgents: object; topVideos: object; topVideoTransforms: object; urlEndpoints: object; videoProcessing: object[]; }', + markdown: + "## get\n\n`client.accounts.usageAnalytics.get(endDate: string, startDate: string): { bandwidthBytes: number; browser: object; cache: object; country: object; device: object; endDate: string; errorReasons: object[]; extensions: object[]; format: object; generatedAt: string; requestCount: number; startDate: string; statusCodes: object[]; top404Assets: object[]; topImages: object; topImageTransforms: object; topOtherAssets: object; topReferrers: object; topUserAgents: object; topVideos: object; topVideoTransforms: object; urlEndpoints: object; videoProcessing: object[]; }`\n\n**get** `/v1/accounts/usage-analytics`\n\n**Note:** This API is currently in beta. \n\nGet the account analytics data between two dates. The response covers the period from the start date to the end date, both dates inclusive. Both dates are interpreted as UTC calendar days.\n\nThe returned data is scoped to the requesting account only. Unlike `/v1/accounts/usage`, an agency account's analytics are not aggregated across its child accounts.\n\nThe response is cached for 5 minutes per account and date range. Use `generatedAt` to check how fresh the returned data is.\n\n\n### Parameters\n\n- `endDate: string`\n Specify an `endDate` in `YYYY-MM-DD` format, interpreted as a UTC calendar day. It should be after the `startDate`. The difference between `startDate` and `endDate` should be less than 90 days.\n\n\n- `startDate: string`\n Specify a `startDate` in `YYYY-MM-DD` format, interpreted as a UTC calendar day. It should be before the `endDate`. The difference between `startDate` and `endDate` should be less than 90 days.\n\n\n### Returns\n\n- `{ bandwidthBytes: number; browser: { byBandwidth: object[]; byRequests: object[]; }; cache: { errorCount: number; hitCount: number; missCount: number; }; country: { byBandwidth: object[]; byRequests: object[]; }; device: { byBandwidth: object[]; byRequests: object[]; }; endDate: string; errorReasons: { name: string; requestCount: number; }[]; extensions: { name: string; operationCount: number; }[]; format: { byBandwidth: object[]; byRequests: object[]; }; generatedAt: string; requestCount: number; startDate: string; statusCodes: { name: string; requestCount: number; }[]; top404Assets: { name: string; requestCount: number; }[]; topImages: { byBandwidth: object[]; byRequests: object[]; }; topImageTransforms: { byBandwidth: object[]; byRequests: object[]; }; topOtherAssets: { byBandwidth: object[]; byRequests: object[]; }; topReferrers: { byBandwidth: object[]; byRequests: object[]; }; topUserAgents: { byBandwidth: object[]; byRequests: object[]; }; topVideos: { byBandwidth: object[]; byRequests: object[]; }; topVideoTransforms: { byBandwidth: object[]; byRequests: object[]; }; urlEndpoints: { byBandwidth: object[]; byRequests: object[]; }; videoProcessing: { codec: string; durationSeconds: number; resolution: string; }[]; }`\n\n - `bandwidthBytes: number`\n - `browser: { byBandwidth: { bandwidthBytes: number; requestCount: number; }[]; byRequests: { bandwidthBytes: number; requestCount: number; }[]; }`\n - `cache: { errorCount: number; hitCount: number; missCount: number; }`\n - `country: { byBandwidth: { bandwidthBytes: number; requestCount: number; }[]; byRequests: { bandwidthBytes: number; requestCount: number; }[]; }`\n - `device: { byBandwidth: { bandwidthBytes: number; requestCount: number; }[]; byRequests: { bandwidthBytes: number; requestCount: number; }[]; }`\n - `endDate: string`\n - `errorReasons: { name: string; requestCount: number; }[]`\n - `extensions: { name: string; operationCount: number; }[]`\n - `format: { byBandwidth: { bandwidthBytes: number; requestCount: number; }[]; byRequests: { bandwidthBytes: number; requestCount: number; }[]; }`\n - `generatedAt: string`\n - `requestCount: number`\n - `startDate: string`\n - `statusCodes: { name: string; requestCount: number; }[]`\n - `top404Assets: { name: string; requestCount: number; }[]`\n - `topImages: { byBandwidth: { bandwidthBytes: number; requestCount: number; }[]; byRequests: { bandwidthBytes: number; requestCount: number; }[]; }`\n - `topImageTransforms: { byBandwidth: { bandwidthBytes: number; requestCount: number; }[]; byRequests: { bandwidthBytes: number; requestCount: number; }[]; }`\n - `topOtherAssets: { byBandwidth: { bandwidthBytes: number; requestCount: number; }[]; byRequests: { bandwidthBytes: number; requestCount: number; }[]; }`\n - `topReferrers: { byBandwidth: { bandwidthBytes: number; requestCount: number; }[]; byRequests: { bandwidthBytes: number; requestCount: number; }[]; }`\n - `topUserAgents: { byBandwidth: { bandwidthBytes: number; requestCount: number; }[]; byRequests: { bandwidthBytes: number; requestCount: number; }[]; }`\n - `topVideos: { byBandwidth: { bandwidthBytes: number; requestCount: number; }[]; byRequests: { bandwidthBytes: number; requestCount: number; }[]; }`\n - `topVideoTransforms: { byBandwidth: { bandwidthBytes: number; requestCount: number; }[]; byRequests: { bandwidthBytes: number; requestCount: number; }[]; }`\n - `urlEndpoints: { byBandwidth: { bandwidthBytes: number; requestCount: number; }[]; byRequests: { bandwidthBytes: number; requestCount: number; }[]; }`\n - `videoProcessing: { codec: string; durationSeconds: number; resolution: string; }[]`\n\n### Example\n\n```typescript\nimport ImageKit from '@imagekit/nodejs';\n\nconst client = new ImageKit();\n\nconst usageAnalyticsResponse = await client.accounts.usageAnalytics.get({ endDate: '2019-12-27', startDate: '2019-12-27' });\n\nconsole.log(usageAnalyticsResponse);\n```", + perLanguage: { + typescript: { + method: 'client.accounts.usageAnalytics.get', + example: + "import ImageKit from '@imagekit/nodejs';\n\nconst client = new ImageKit({\n privateKey: process.env['IMAGEKIT_PRIVATE_KEY'], // This is the default and can be omitted\n password: process.env['OPTIONAL_IMAGEKIT_IGNORES_THIS'], // This is the default and can be omitted\n});\n\nconst usageAnalyticsResponse = await client.accounts.usageAnalytics.get({\n endDate: '2019-12-27',\n startDate: '2019-12-27',\n});\n\nconsole.log(usageAnalyticsResponse.bandwidthBytes);", + }, + http: { + example: + 'curl https://api.imagekit.io/v1/accounts/usage-analytics \\\n -u "$IMAGEKIT_PRIVATE_KEY:OPTIONAL_IMAGEKIT_IGNORES_THIS"', + }, + python: { + method: 'accounts.usage_analytics.get', + example: + 'import os\nfrom datetime import date\nfrom imagekitio import ImageKit\n\nclient = ImageKit(\n private_key=os.environ.get("IMAGEKIT_PRIVATE_KEY"), # This is the default and can be omitted\n password=os.environ.get("OPTIONAL_IMAGEKIT_IGNORES_THIS"), # This is the default and can be omitted\n)\nusage_analytics_response = client.accounts.usage_analytics.get(\n end_date=date.fromisoformat("2019-12-27"),\n start_date=date.fromisoformat("2019-12-27"),\n)\nprint(usage_analytics_response.bandwidth_bytes)', + }, + java: { + method: 'accounts().usageAnalytics().get', + example: + 'package io.imagekit.example;\n\nimport io.imagekit.client.ImageKitClient;\nimport io.imagekit.client.okhttp.ImageKitOkHttpClient;\nimport io.imagekit.models.accounts.usageanalytics.UsageAnalyticsGetParams;\nimport io.imagekit.models.accounts.usageanalytics.UsageAnalyticsResponse;\nimport java.time.LocalDate;\n\npublic final class Main {\n private Main() {}\n\n public static void main(String[] args) {\n ImageKitClient client = ImageKitOkHttpClient.fromEnv();\n\n UsageAnalyticsGetParams params = UsageAnalyticsGetParams.builder()\n .endDate(LocalDate.parse("2019-12-27"))\n .startDate(LocalDate.parse("2019-12-27"))\n .build();\n UsageAnalyticsResponse usageAnalyticsResponse = client.accounts().usageAnalytics().get(params);\n }\n}', + }, + go: { + method: 'client.Accounts.UsageAnalytics.Get', + example: + 'package main\n\nimport (\n\t"context"\n\t"fmt"\n\t"time"\n\n\t"github.com/imagekit-developer/imagekit-go"\n\t"github.com/imagekit-developer/imagekit-go/option"\n)\n\nfunc main() {\n\tclient := imagekit.NewClient(\n\t\toption.WithPrivateKey("My Private Key"),\n\t\toption.WithPassword("My Password"),\n\t)\n\tusageAnalyticsResponse, err := client.Accounts.UsageAnalytics.Get(context.TODO(), imagekit.AccountUsageAnalyticsGetParams{\n\t\tEndDate: time.Now(),\n\t\tStartDate: time.Now(),\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf("%+v\\n", usageAnalyticsResponse.BandwidthBytes)\n}\n', + }, + ruby: { + method: 'accounts.usage_analytics.get', + example: + 'require "imagekitio"\n\nimage_kit = Imagekitio::Client.new(private_key: "My Private Key", password: "My Password")\n\nusage_analytics_response = image_kit.accounts.usage_analytics.get(end_date: "2019-12-27", start_date: "2019-12-27")\n\nputs(usage_analytics_response)', + }, + php: { + method: 'accounts->usageAnalytics->get', + example: + "accounts->usageAnalytics->get(\n endDate: '2019-12-27', startDate: '2019-12-27'\n);\n\nvar_dump($usageAnalyticsResponse);", + }, + csharp: { + method: 'Accounts.UsageAnalytics.Get', + example: + 'UsageAnalyticsGetParams parameters = new()\n{\n EndDate = "2019-12-27",\n StartDate = "2019-12-27",\n};\n\nvar usageAnalyticsResponse = await client.Accounts.UsageAnalytics.Get(parameters);\n\nConsole.WriteLine(usageAnalyticsResponse);', + }, + }, + }, { name: 'list', endpoint: '/v1/accounts/origins', diff --git a/packages/mcp-server/src/methods.ts b/packages/mcp-server/src/methods.ts index 94f8da06..15207aa2 100644 --- a/packages/mcp-server/src/methods.ts +++ b/packages/mcp-server/src/methods.ts @@ -226,6 +226,12 @@ export const sdkMethods: SdkMethod[] = [ httpMethod: 'get', httpPath: '/v1/accounts/usage', }, + { + clientCallName: 'client.accounts.usageAnalytics.get', + fullyQualifiedName: 'accounts.usageAnalytics.get', + httpMethod: 'get', + httpPath: '/v1/accounts/usage-analytics', + }, { clientCallName: 'client.accounts.origins.list', fullyQualifiedName: 'accounts.origins.list', diff --git a/src/resources/accounts/accounts.ts b/src/resources/accounts/accounts.ts index 82d1b238..b90a7cd6 100644 --- a/src/resources/accounts/accounts.ts +++ b/src/resources/accounts/accounts.ts @@ -21,20 +21,36 @@ import { } from './url-endpoints'; import * as UsageAPI from './usage'; import { Usage, UsageGetParams, UsageGetResponse } from './usage'; +import * as UsageAnalyticsAPI from './usage-analytics'; +import { + RequestBandwidthEntry, + UsageAnalytics, + UsageAnalyticsGetParams, + UsageAnalyticsResponse, +} from './usage-analytics'; export class Accounts extends APIResource { usage: UsageAPI.Usage = new UsageAPI.Usage(this._client); + usageAnalytics: UsageAnalyticsAPI.UsageAnalytics = new UsageAnalyticsAPI.UsageAnalytics(this._client); origins: OriginsAPI.Origins = new OriginsAPI.Origins(this._client); urlEndpoints: URLEndpointsAPI.URLEndpoints = new URLEndpointsAPI.URLEndpoints(this._client); } Accounts.Usage = Usage; +Accounts.UsageAnalytics = UsageAnalytics; Accounts.Origins = Origins; Accounts.URLEndpoints = URLEndpoints; export declare namespace Accounts { export { Usage as Usage, type UsageGetResponse as UsageGetResponse, type UsageGetParams as UsageGetParams }; + export { + UsageAnalytics as UsageAnalytics, + type RequestBandwidthEntry as RequestBandwidthEntry, + type UsageAnalyticsResponse as UsageAnalyticsResponse, + type UsageAnalyticsGetParams as UsageAnalyticsGetParams, + }; + export { Origins as Origins, type OriginRequest as OriginRequest, diff --git a/src/resources/accounts/index.ts b/src/resources/accounts/index.ts index 34a0246d..0f099574 100644 --- a/src/resources/accounts/index.ts +++ b/src/resources/accounts/index.ts @@ -18,3 +18,9 @@ export { type URLEndpointUpdateParams, } from './url-endpoints'; export { Usage, type UsageGetResponse, type UsageGetParams } from './usage'; +export { + UsageAnalytics, + type RequestBandwidthEntry, + type UsageAnalyticsResponse, + type UsageAnalyticsGetParams, +} from './usage-analytics'; diff --git a/src/resources/accounts/usage-analytics.ts b/src/resources/accounts/usage-analytics.ts new file mode 100644 index 00000000..39f6453b --- /dev/null +++ b/src/resources/accounts/usage-analytics.ts @@ -0,0 +1,676 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import { APIResource } from '../../core/resource'; +import * as UsageAnalyticsAPI from './usage-analytics'; +import { APIPromise } from '../../core/api-promise'; +import { RequestOptions } from '../../internal/request-options'; + +export class UsageAnalytics extends APIResource { + /** + * **Note:** This API is currently in beta. + * + * Get the account analytics data between two dates. The response covers the period + * from the start date to the end date, both dates inclusive. Both dates are + * interpreted as UTC calendar days. + * + * The returned data is scoped to the requesting account only. Unlike + * `/v1/accounts/usage`, an agency account's analytics are not aggregated across + * its child accounts. + * + * The response is cached for 5 minutes per account and date range. Use + * `generatedAt` to check how fresh the returned data is. + * + * @example + * ```ts + * const usageAnalyticsResponse = + * await client.accounts.usageAnalytics.get({ + * endDate: '2019-12-27', + * startDate: '2019-12-27', + * }); + * ``` + */ + get(query: UsageAnalyticsGetParams, options?: RequestOptions): APIPromise { + return this._client.get('/v1/accounts/usage-analytics', { query, ...options }); + } +} + +export interface RequestBandwidthEntry { + /** + * Total bandwidth used in bytes. + */ + bandwidthBytes: number; + + /** + * Number of requests. + */ + requestCount: number; +} + +export interface UsageAnalyticsResponse { + /** + * Total bandwidth, in bytes, utilized during the specified date range. + */ + bandwidthBytes: number; + + /** + * CDN traffic grouped by browser. + */ + browser: UsageAnalyticsResponse.Browser; + + /** + * CDN cache hit, miss and error counts for the date range. + */ + cache: UsageAnalyticsResponse.Cache; + + /** + * CDN traffic grouped by country. + */ + country: UsageAnalyticsResponse.Country; + + /** + * CDN traffic grouped by device and operating system (e.g. `Desktop - Apple Mac`, + * `Smartphone - Apple iPhone`). + */ + device: UsageAnalyticsResponse.Device; + + /** + * End date of the computed analytics data. + */ + endDate: string; + + /** + * Request count grouped by origin error reason. This covers failed origin fetches, + * such as an asset not found at origin or an origin timeout. It is not the HTTP + * status code returned to the client, see `statusCodes` for that. + */ + errorReasons: Array; + + /** + * Raw per-extension operation counts for the date range. These are raw operation + * counts, not billable extension units. For billable usage, use the + * `/v1/accounts/usage` endpoint. + */ + extensions: Array; + + /** + * CDN traffic grouped by response `Content-Type`. + */ + format: UsageAnalyticsResponse.Format; + + /** + * Date and time when the analytics data was computed. Use this to gauge how fresh + * the returned data is. The date and time is in ISO8601 format. + */ + generatedAt: string; + + /** + * Total number of requests made during the specified date range. + */ + requestCount: number; + + /** + * Start date of the computed analytics data. + */ + startDate: string; + + /** + * Request count grouped by HTTP status code. + */ + statusCodes: Array; + + /** + * Top URLs that returned a 404 response. + */ + top404Assets: Array; + + /** + * Top image assets by traffic. + */ + topImages: UsageAnalyticsResponse.TopImages; + + /** + * Top image transformation strings by traffic. + */ + topImageTransforms: UsageAnalyticsResponse.TopImageTransforms; + + /** + * Top non-image, non-video assets by traffic. + */ + topOtherAssets: UsageAnalyticsResponse.TopOtherAssets; + + /** + * Top HTTP referrers by traffic. + */ + topReferrers: UsageAnalyticsResponse.TopReferrers; + + /** + * Top user agents by traffic. + */ + topUserAgents: UsageAnalyticsResponse.TopUserAgents; + + /** + * Top video assets by traffic. + */ + topVideos: UsageAnalyticsResponse.TopVideos; + + /** + * Top video transformation strings by traffic. + */ + topVideoTransforms: UsageAnalyticsResponse.TopVideoTransforms; + + /** + * CDN traffic grouped by configured URL endpoint. Traffic that does not match any + * named URL endpoint pattern is grouped under `Default`. + */ + urlEndpoints: UsageAnalyticsResponse.URLEndpoints; + + /** + * Raw observed video transcode output duration, in seconds, grouped by resolution + * and codec. These are raw seconds, not billable Video Processing Units (VPU). For + * billable VPU totals, use the `/v1/accounts/usage` endpoint. + */ + videoProcessing: Array; + + [k: string]: unknown; +} + +export namespace UsageAnalyticsResponse { + /** + * CDN traffic grouped by browser. + */ + export interface Browser { + /** + * Top browsers sorted by bandwidth utilized. + */ + byBandwidth: Array; + + /** + * Top browsers sorted by request count. + */ + byRequests: Array; + } + + export namespace Browser { + export interface ByBandwidth extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * Browser name (e.g. `Chrome`). + */ + name: string; + } + + export interface ByRequest extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * Browser name (e.g. `Chrome`). + */ + name: string; + } + } + + /** + * CDN cache hit, miss and error counts for the date range. + */ + export interface Cache { + /** + * Number of requests where the CDN encountered a cache error or exceeded capacity + * while serving the response. + */ + errorCount: number; + + /** + * Number of requests served from cache, including full hits and revalidated hits. + */ + hitCount: number; + + /** + * Number of requests that were not found in cache and had to be fetched from + * origin. + */ + missCount: number; + } + + /** + * CDN traffic grouped by country. + */ + export interface Country { + /** + * Top requesting countries sorted by total bandwidth utilized. + */ + byBandwidth: Array; + + /** + * Top requesting countries sorted by request count. + */ + byRequests: Array; + } + + export namespace Country { + export interface ByBandwidth extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * ISO country code. + */ + code: string; + + /** + * Country name. + */ + name: string; + } + + export interface ByRequest extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * ISO country code. + */ + code: string; + + /** + * Country name. + */ + name: string; + } + } + + /** + * CDN traffic grouped by device and operating system (e.g. `Desktop - Apple Mac`, + * `Smartphone - Apple iPhone`). + */ + export interface Device { + /** + * Top device/OS combinations sorted by bandwidth utilized. + */ + byBandwidth: Array; + + /** + * Top device/OS combinations sorted by request count. + */ + byRequests: Array; + } + + export namespace Device { + export interface ByBandwidth extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * Device category combined with operating system or vendor (e.g. + * `Desktop - Windows PC`). + */ + name: string; + } + + export interface ByRequest extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * Device category combined with operating system or vendor (e.g. + * `Desktop - Windows PC`). + */ + name: string; + } + } + + export interface ErrorReason { + /** + * Description of the error reason. + */ + name: string; + + /** + * Number of requests that failed with this error reason. + */ + requestCount: number; + } + + export interface Extension { + /** + * Extension identifier. + */ + name: string; + + /** + * Number of times this extension ran during the date range. + */ + operationCount: number; + } + + /** + * CDN traffic grouped by response `Content-Type`. + */ + export interface Format { + /** + * Top content types sorted by bandwidth utilized. + */ + byBandwidth: Array; + + /** + * Top content types sorted by request count. + */ + byRequests: Array; + } + + export namespace Format { + export interface ByBandwidth extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * MIME type (e.g. `image/webp`). + */ + name: string; + } + + export interface ByRequest extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * MIME type (e.g. `image/webp`). + */ + name: string; + } + } + + export interface StatusCode { + /** + * HTTP status code. + */ + name: string; + + /** + * Number of requests that received this status code. + */ + requestCount: number; + } + + export interface Top404Asset { + /** + * URL that returned a 404 response. + */ + name: string; + + /** + * Number of requests to this URL that returned a 404 response. + */ + requestCount: number; + } + + /** + * Top image assets by traffic. + */ + export interface TopImages { + /** + * Top image assets sorted by bandwidth utilized. + */ + byBandwidth: Array; + + /** + * Top image assets sorted by request count. + */ + byRequests: Array; + } + + export namespace TopImages { + export interface ByBandwidth extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * URL of the image asset. + */ + name: string; + } + + export interface ByRequest extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * URL of the image asset. + */ + name: string; + } + } + + /** + * Top image transformation strings by traffic. + */ + export interface TopImageTransforms { + /** + * Top image transformation strings sorted by bandwidth utilized. + */ + byBandwidth: Array; + + /** + * Top image transformation strings sorted by request count. + */ + byRequests: Array; + } + + export namespace TopImageTransforms { + export interface ByBandwidth extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * Image transformation string (e.g. `tr:w-400,h-400`). + */ + name: string; + } + + export interface ByRequest extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * Image transformation string (e.g. `tr:w-400,h-400`). + */ + name: string; + } + } + + /** + * Top non-image, non-video assets by traffic. + */ + export interface TopOtherAssets { + /** + * Top non-image, non-video assets sorted by bandwidth utilized. + */ + byBandwidth: Array; + + /** + * Top non-image, non-video assets sorted by request count. + */ + byRequests: Array; + } + + export namespace TopOtherAssets { + export interface ByBandwidth extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * URL of the non-image, non-video asset. + */ + name: string; + } + + export interface ByRequest extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * URL of the non-image, non-video asset. + */ + name: string; + } + } + + /** + * Top HTTP referrers by traffic. + */ + export interface TopReferrers { + /** + * Top HTTP referrers sorted by bandwidth utilized. + */ + byBandwidth: Array; + + /** + * Top HTTP referrers sorted by request count. + */ + byRequests: Array; + } + + export namespace TopReferrers { + export interface ByBandwidth extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * Referrer URL. + */ + name: string; + } + + export interface ByRequest extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * Referrer URL. + */ + name: string; + } + } + + /** + * Top user agents by traffic. + */ + export interface TopUserAgents { + /** + * Top user agents sorted by bandwidth utilized. + */ + byBandwidth: Array; + + /** + * Top user agents sorted by request count. + */ + byRequests: Array; + } + + export namespace TopUserAgents { + export interface ByBandwidth extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * User agent string. + */ + name: string; + } + + export interface ByRequest extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * User agent string. + */ + name: string; + } + } + + /** + * Top video assets by traffic. + */ + export interface TopVideos { + /** + * Top video assets sorted by bandwidth utilized. + */ + byBandwidth: Array; + + /** + * Top video assets sorted by request count. + */ + byRequests: Array; + } + + export namespace TopVideos { + export interface ByBandwidth extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * URL of the video asset. + */ + name: string; + } + + export interface ByRequest extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * Full URL of the video asset (e.g. `https://ik.imagekit.io/demo/clip.mp4`). + */ + name: string; + } + } + + /** + * Top video transformation strings by traffic. + */ + export interface TopVideoTransforms { + /** + * Top video transformation strings sorted by bandwidth utilized. + */ + byBandwidth: Array; + + /** + * Top video transformation strings sorted by request count. + */ + byRequests: Array; + } + + export namespace TopVideoTransforms { + export interface ByBandwidth extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * Video transformation string (e.g. `tr:h-720,f-mp4`). + */ + name: string; + } + + export interface ByRequest extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * Video transformation string (e.g. `tr:h-720,f-mp4`). + */ + name: string; + } + } + + /** + * CDN traffic grouped by configured URL endpoint. Traffic that does not match any + * named URL endpoint pattern is grouped under `Default`. + */ + export interface URLEndpoints { + /** + * Top URL endpoints sorted by bandwidth utilized. + */ + byBandwidth: Array; + + /** + * Top URL endpoints sorted by request count. + */ + byRequests: Array; + } + + export namespace URLEndpoints { + export interface ByBandwidth extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * URL endpoint name, or `Default` for traffic that does not match a named + * endpoint. + */ + name: string; + } + + export interface ByRequest extends UsageAnalyticsAPI.RequestBandwidthEntry { + /** + * URL endpoint name, or `Default` for traffic that does not match a named + * endpoint. + */ + name: string; + } + } + + export interface VideoProcessing { + /** + * Video codec used for the output (e.g. `h264`, `av1`). + */ + codec: string; + + /** + * Total output duration, in seconds, for this resolution and codec combination. + */ + durationSeconds: number; + + /** + * Output resolution tier (e.g. `SD`, `HD`, `4K`). + */ + resolution: string; + } +} + +export interface UsageAnalyticsGetParams { + /** + * Specify an `endDate` in `YYYY-MM-DD` format, interpreted as a UTC calendar day. + * It should be after the `startDate`. The difference between `startDate` and + * `endDate` should be less than 90 days. + */ + endDate: string; + + /** + * Specify a `startDate` in `YYYY-MM-DD` format, interpreted as a UTC calendar day. + * It should be before the `endDate`. The difference between `startDate` and + * `endDate` should be less than 90 days. + */ + startDate: string; +} + +export declare namespace UsageAnalytics { + export { + type RequestBandwidthEntry as RequestBandwidthEntry, + type UsageAnalyticsResponse as UsageAnalyticsResponse, + type UsageAnalyticsGetParams as UsageAnalyticsGetParams, + }; +} diff --git a/src/resources/accounts/usage.ts b/src/resources/accounts/usage.ts index 87e703a4..1e4e0925 100644 --- a/src/resources/accounts/usage.ts +++ b/src/resources/accounts/usage.ts @@ -11,6 +11,12 @@ export class Usage extends APIResource { * other words, the data covers the period starting from the specified start date * up to, but not including, the end date. * + * For an agency account, the returned usage is aggregated across the agency and + * all of its child accounts that are billed to it. + * + * The response is cached for 6 hours per account, date range and requested + * metrics. + * * @example * ```ts * const usage = await client.accounts.usage.get({ diff --git a/tests/api-resources/accounts/usage-analytics.test.ts b/tests/api-resources/accounts/usage-analytics.test.ts new file mode 100644 index 00000000..83b8d692 --- /dev/null +++ b/tests/api-resources/accounts/usage-analytics.test.ts @@ -0,0 +1,34 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import ImageKit from '@imagekit/nodejs'; + +const client = new ImageKit({ + privateKey: 'My Private Key', + password: 'My Password', + baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', +}); + +describe('resource usageAnalytics', () => { + // Mock server tests are disabled + test.skip('get: only required params', async () => { + const responsePromise = client.accounts.usageAnalytics.get({ + endDate: '2019-12-27', + startDate: '2019-12-27', + }); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + // Mock server tests are disabled + test.skip('get: required and optional params', async () => { + const response = await client.accounts.usageAnalytics.get({ + endDate: '2019-12-27', + startDate: '2019-12-27', + }); + }); +}); diff --git a/yarn.lock b/yarn.lock index a2134ae4..df050683 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1220,9 +1220,9 @@ baseline-browser-mapping@^2.9.0: integrity sha512-B0xUquLkiGLgHhpPBqvl7GWegWBUNuujQ6kXd/r1U38ElPT6Ok8KZ8e+FpUGEc2ZoRQUzq/aUnaKFc/svWUGSg== brace-expansion@^2.0.2: - version "2.1.1" - resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.1.1.tgz#c68b1c4111c76aae3a6fba55d496cee10c39dad8" - integrity sha512-WR1cURNjuvBLMZBMbqM0UoE+WAfdUcEV1ccD8PVBVOI+Z3ND4+SZbN8RsfT2bMuG1qwz5RFvPukSZm5fF2D5eA== + version "2.1.2" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.1.2.tgz#0bba2271feb7d458b0d31ad13625aaa4754431e2" + integrity sha512-w5JZcKgdhDOgOwm8H+KgbosopHMuGcl6qbulwjtz3SM7I7P3yW1eAjzMPLrIE+NQ9vjgANKHWeMHnrT0OXW1oA== dependencies: balanced-match "^1.0.0"