UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

375 lines (302 loc) • 9.15 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../core/resource'; import { APIPromise } from '../../core/api-promise'; import { PagePromise, SinglePage } from '../../core/pagination'; import { RequestOptions } from '../../internal/request-options'; import { path } from '../../internal/utils/path'; export class BaseScripts extends APIResource { static override readonly _key: readonly ['pageShield', 'scripts'] = Object.freeze([ 'pageShield', 'scripts', ] as const); /** * Lists scripts detected on webpages in the zone, with filtering and pagination. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const scriptListResponse of client.pageShield.scripts.list( * { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * )) { * // ... * } * ``` */ list( params: ScriptListParams, options?: RequestOptions, ): PagePromise<ScriptListResponsesSinglePage, ScriptListResponse> { const { zone_id, ...query } = params; return this._client.getAPIList( path`/zones/${zone_id}/page_shield/scripts`, SinglePage<ScriptListResponse>, { query, ...options }, ); } /** * Returns a script detected on the zone by script ID. * * @example * ```ts * const script = await client.pageShield.scripts.get( * '023e105f4ecef8ad9ca31a8372d0c353', * { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ get( scriptID: string, params: ScriptGetParams, options?: RequestOptions, ): APIPromise<ScriptGetResponse | null> { const { zone_id } = params; return ( this._client.get(path`/zones/${zone_id}/page_shield/scripts/${scriptID}`, options) as APIPromise<{ result: ScriptGetResponse | null; }> )._thenUnwrap((obj) => obj.result); } } export class Scripts extends BaseScripts {} export type ScriptListResponsesSinglePage = SinglePage<ScriptListResponse>; export interface ScriptListResponse { /** * Identifier */ id: string; added_at: string; first_seen_at: string; host: string; last_seen_at: string; url: string; url_contains_cdn_cgi_path: boolean; /** * The cryptomining score of the JavaScript content. */ cryptomining_score?: number | null; /** * @deprecated The dataflow score of the JavaScript content. This field has been * deprecated in favour of js_integrity_score. */ dataflow_score?: number | null; domain_reported_malicious?: boolean; /** * The timestamp of when the script was last fetched. */ fetched_at?: string | null; first_page_url?: string; /** * The computed hash of the analyzed script. */ hash?: string | null; /** * The integrity score of the JavaScript content. */ js_integrity_score?: number | null; /** * The magecart score of the JavaScript content. */ magecart_score?: number | null; malicious_domain_categories?: Array<string>; malicious_url_categories?: Array<string>; /** * The malware score of the JavaScript content. */ malware_score?: number | null; /** * @deprecated The obfuscation score of the JavaScript content. This field has been * deprecated in favour of js_integrity_score. */ obfuscation_score?: number | null; page_urls?: Array<string>; url_reported_malicious?: boolean; } export interface ScriptGetResponse { /** * Identifier */ id: string; added_at: string; first_seen_at: string; host: string; last_seen_at: string; url: string; url_contains_cdn_cgi_path: boolean; /** * The cryptomining score of the JavaScript content. */ cryptomining_score?: number | null; /** * @deprecated The dataflow score of the JavaScript content. This field has been * deprecated in favour of js_integrity_score. */ dataflow_score?: number | null; domain_reported_malicious?: boolean; /** * The timestamp of when the script was last fetched. */ fetched_at?: string | null; first_page_url?: string; /** * The computed hash of the analyzed script. */ hash?: string | null; /** * The integrity score of the JavaScript content. */ js_integrity_score?: number | null; /** * The magecart score of the JavaScript content. */ magecart_score?: number | null; malicious_domain_categories?: Array<string>; malicious_url_categories?: Array<string>; /** * The malware score of the JavaScript content. */ malware_score?: number | null; /** * @deprecated The obfuscation score of the JavaScript content. This field has been * deprecated in favour of js_integrity_score. */ obfuscation_score?: number | null; page_urls?: Array<string>; url_reported_malicious?: boolean; versions?: Array<ScriptGetResponse.Version> | null; } export namespace ScriptGetResponse { /** * The version of the analyzed script. */ export interface Version { /** * The cryptomining score of the JavaScript content. */ cryptomining_score?: number | null; /** * @deprecated The dataflow score of the JavaScript content. This field has been * deprecated in favour of js_integrity_score. */ dataflow_score?: number | null; /** * The timestamp of when the script was last fetched. */ fetched_at?: string | null; /** * The computed hash of the analyzed script. */ hash?: string | null; /** * The integrity score of the JavaScript content. */ js_integrity_score?: number | null; /** * The magecart score of the JavaScript content. */ magecart_score?: number | null; /** * The malware score of the JavaScript content. */ malware_score?: number | null; /** * @deprecated The obfuscation score of the JavaScript content. This field has been * deprecated in favour of js_integrity_score. */ obfuscation_score?: number | null; } } export interface ScriptListParams { /** * Path param: Identifier */ zone_id: string; /** * Query param: The direction used to sort returned scripts. */ direction?: 'asc' | 'desc'; /** * Query param: When true, excludes scripts seen in a `/cdn-cgi` path from the * returned scripts. The default value is true. */ exclude_cdn_cgi?: boolean; /** * Query param: When true, excludes duplicate scripts. We consider a script * duplicate of another if their javascript content matches and they share the same * url host and zone hostname. In such case, we return the most recent script for * the URL host and zone hostname combination. */ exclude_duplicates?: boolean; /** * Query param: Excludes scripts whose URL contains one of the URL-encoded URLs * separated by commas. */ exclude_urls?: string; /** * Query param: Export the list of scripts as a file, limited to 50000 entries. */ export?: 'csv'; /** * Query param: Includes scripts that match one or more URL-encoded hostnames * separated by commas. * * Wildcards are supported at the start and end of each hostname to support starts * with, ends with and contains. If no wildcards are used, results will be filtered * by exact match */ hosts?: string; /** * Query param: The field used to sort returned scripts. */ order_by?: 'first_seen_at' | 'last_seen_at'; /** * Query param: The current page number of the paginated results. * * We additionally support a special value "all". When "all" is used, the API will * return all the scripts with the applied filters in a single page. This feature * is best-effort and it may only work for zones with a low number of scripts */ page?: string; /** * Query param: Includes scripts that match one or more page URLs (separated by * commas) where they were last seen * * Wildcards are supported at the start and end of each page URL to support starts * with, ends with and contains. If no wildcards are used, results will be filtered * by exact match */ page_url?: string; /** * Query param: The number of results per page. */ per_page?: number; /** * Query param: When true, malicious scripts appear first in the returned scripts. */ prioritize_malicious?: boolean; /** * Query param: Filters the returned scripts using a comma-separated list of * scripts statuses. Accepted values: `active`, `infrequent`, and `inactive`. The * default value is `active`. */ status?: string; /** * Query param: Includes scripts whose URL contain one or more URL-encoded URLs * separated by commas. */ urls?: string; } export interface ScriptGetParams { /** * Identifier */ zone_id: string; } export declare namespace Scripts { export { type ScriptListResponse as ScriptListResponse, type ScriptGetResponse as ScriptGetResponse, type ScriptListResponsesSinglePage as ScriptListResponsesSinglePage, type ScriptListParams as ScriptListParams, type ScriptGetParams as ScriptGetParams, }; }