@prismicio/e2e-tests-utils 1.3.1 → 1.4.0-alpha.2

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.
@@ -32,14 +32,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
32
32
  const test = require("@playwright/test");
33
33
  class ContentApiClient {
34
34
  /**
35
- * @example To instantiate the class:
36
- *
37
- * ```js
38
- * new ContentApiClient("https://my-repo.cdn.prismic.io", {
39
- * version: "v2",
40
- * accessToken: "my-secret-token",
41
- * });
42
- * ```
35
+ * @example new ContentApiClient("https://my-repo.cdn.prismic.io" { version :
36
+ * "v2", accessToken: "my-secret-token" })
43
37
  *
44
38
  * @param baseURL - the api base URL like https://my-repo.cdn.prismic.io
45
39
  * @param config - Optional configuration
@@ -1 +1 @@
1
- {"version":3,"file":"contentApi.cjs","sources":["../../../src/clients/contentApi.ts"],"sourcesContent":["import { APIResponse, request } from \"@playwright/test\";\n\nexport interface ContentApiError {\n\ttype: string;\n\tmessage: string;\n}\nexport interface ContentApiSearchResponse {\n\tpage: number;\n\tresults_per_page: number;\n\tresults_size: number;\n\ttotal_results_size: number;\n\ttotal_pages: number;\n\tnext_page: string | null;\n\tprev_page: string | null;\n\tresults: ContentApiDocument[];\n}\n\nexport interface ContentApiDocument {\n\tid: string;\n\tuid: string | null;\n\turl: string | null;\n\ttype: string;\n\thref: string;\n\ttags: string[];\n\tfirst_publication_date: string;\n\tlast_publication_date: string;\n\tslugs: string[];\n\tlinked_documents: unknown[];\n\tlang: string;\n\talternate_languages: string[];\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdata: Record<string, any>;\n}\n\nexport interface ContentApiGraphQLResponse {\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdata: Record<string, any>;\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\terrors?: { message: string; locations: any }[];\n}\n\nexport interface ContentApiRef {\n\tid: string;\n\tref: string;\n\tlabel: string;\n\tisMasterRef?: boolean;\n}\n\ninterface ContentApiRepoConfigResponse {\n\trefs: ContentApiRef[];\n\tbookmarks: Record<string, unknown>;\n\ttypes: Record<string, string>;\n\tlanguages: {\n\t\tid: string;\n\t\tname: string;\n\t\tis_master: boolean;\n\t}[];\n\toauth_initiate: string;\n\toauth_token: string;\n\ttags: string[];\n\tlicense: string;\n\tversion: string;\n}\n\ntype SearchQueryParams = {\n\tref?: string;\n\tquery?: string;\n\tq?: string;\n\tgraphQuery?: string;\n\tfetchLinks?: string;\n\torderings?: string;\n\tpageSize?: number;\n\tpage?: number;\n\tlang?: string;\n\tafter?: string;\n\troutes?: string;\n};\n\ntype ApiVersions = \"v1\" | \"v2\";\n\n/**\n * Client to query the Prismic content api. Uses Playwright to benefit from\n * network request traces in your reports. The @prismicio/client package could\n * have been used but had too many abstractions (caching, error handling) that\n * we didn't want for test execution. See api docs:\n * https://prismic.io/docs/rest-api-technical-reference\n */\nexport class ContentApiClient {\n\t#version: ApiVersions;\n\t#accessToken: string | undefined;\n\n\t/**\n\t * @example To instantiate the class:\n\t *\n\t * ```js\n\t * new ContentApiClient(\"https://my-repo.cdn.prismic.io\", {\n\t * \tversion: \"v2\",\n\t * \taccessToken: \"my-secret-token\",\n\t * });\n\t * ```\n\t *\n\t * @param baseURL - the api base URL like https://my-repo.cdn.prismic.io\n\t * @param config - Optional configuration\n\t *\n\t * - {@link config.version}: Api version, default is \"v2\"\n\t * - {@link config.accessToken}: Access token for the content api -\n\t * https://prismic.io/docs/access-token\n\t */\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tconfig: { version?: ApiVersions; accessToken?: string } = {},\n\t) {\n\t\tthis.#version = config.version || \"v2\";\n\t\tthis.#accessToken = config.accessToken;\n\t}\n\n\t#context() {\n\t\treturn request.newContext({\n\t\t\tbaseURL: this.baseURL,\n\t\t\t// reset any Authorization header set globally with Playwright\n\t\t\t// didn't find a way to delete it\n\t\t\textraHTTPHeaders: { Authorization: \"\" },\n\t\t});\n\t}\n\n\tasync get(\n\t\tpath: string,\n\t\tparams?: SearchQueryParams,\n\t\theaders?: Record<string, string>,\n\t): Promise<APIResponse> {\n\t\tconst context = await this.#context();\n\t\tconst securityParams = {\n\t\t\t...(this.#accessToken ? { access_token: this.#accessToken } : {}),\n\t\t};\n\n\t\treturn context.get(path, {\n\t\t\tparams: { ...securityParams, ...params },\n\t\t\theaders,\n\t\t});\n\t}\n\n\tasync getAsJson<T>(\n\t\turl: string,\n\t\tparams?: SearchQueryParams,\n\t\theaders?: Record<string, string>,\n\t): Promise<T> {\n\t\tconst response = await this.get(url, params, headers);\n\n\t\treturn response.json() as T;\n\t}\n\n\t/** Query the graphql api - https://prismic.io/docs/graphql-technical-reference */\n\tasync graphql(\n\t\tref: string,\n\t\tquery: string,\n\t): Promise<ContentApiGraphQLResponse> {\n\t\treturn this.getAsJson<ContentApiGraphQLResponse>(\n\t\t\t\"/graphql\",\n\t\t\t{ query },\n\t\t\t{ \"Prismic-ref\": ref },\n\t\t);\n\t}\n\n\tasync getRefs(): Promise<ContentApiRef[]> {\n\t\tconst data = await this.getAsJson<ContentApiRepoConfigResponse>(\n\t\t\t`/api/${this.#version}`,\n\t\t);\n\n\t\treturn data.refs;\n\t}\n\n\tasync getMasterRef(): Promise<string> {\n\t\tconst refs = await this.getRefs();\n\n\t\tconst masterRef = refs.find(({ isMasterRef }) => isMasterRef === true);\n\t\tif (!masterRef) {\n\t\t\tthrow \"No master ref found\";\n\t\t}\n\n\t\treturn masterRef.ref;\n\t}\n\n\tasync getRefByReleaseID(releaseID: string): Promise<string> {\n\t\tconst refs = await this.getRefs();\n\t\tconst release = refs.find(({ id }) => id === releaseID);\n\t\tif (!release) {\n\t\t\tthrow `No ref found for release ${releaseID}`;\n\t\t}\n\n\t\treturn release.ref;\n\t}\n\n\t/** Search documents from the `/api/v<version>/documents/search` endpoint. */\n\tasync search(filters?: SearchQueryParams): Promise<ContentApiSearchResponse> {\n\t\tlet ref = filters?.ref;\n\t\tif (!ref) {\n\t\t\tref = await this.getMasterRef();\n\t\t}\n\n\t\treturn this.getAsJson<ContentApiSearchResponse>(\n\t\t\t`/api/${this.#version}/documents/search`,\n\t\t\t{\n\t\t\t\t...filters,\n\t\t\t\tref,\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * Search for a single document by its it, using the\n\t * `/api/v<version>/documents/search` endpoint and a default filter.\n\t */\n\tasync searchByID(\n\t\tid: string,\n\t\tfilters?: SearchQueryParams,\n\t): Promise<ContentApiSearchResponse> {\n\t\treturn this.search({ ...filters, q: `[[at(document.id, \"${id}\")]]` });\n\t}\n\n\t/** Retrieve a single document or undefined if not found. */\n\tasync getDocumentByID(\n\t\tid: string,\n\t\tfilters?: SearchQueryParams,\n\t): Promise<ContentApiDocument | undefined> {\n\t\tconst data = await this.searchByID(id, filters);\n\t\tswitch (data.results_size) {\n\t\t\tcase 0:\n\t\t\t\treturn;\n\t\t\tcase 1:\n\t\t\t\treturn data.results[0];\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Too many documents returned with the same id ${id}`);\n\t\t}\n\t}\n}\n"],"names":["request"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAuFa,iBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqB5B,YACkB,SACjB,SAA0D,IAAE;AAM7D;AAPkB;AArBlB;AACA;AAoBkB,SAAO,UAAP;AAGZ,uBAAA,UAAW,OAAO,WAAW;AAClC,uBAAK,cAAe,OAAO;AAAA,EAC5B;AAAA,EAWA,MAAM,IACL,MACA,QACA,SAAgC;AAE1B,UAAA,UAAU,MAAM,sBAAK,sBAAL;AACtB,UAAM,iBAAiB;AAAA,MACtB,GAAI,mBAAK,gBAAe,EAAE,cAAc,mBAAK,cAAA,IAAiB;;AAGxD,WAAA,QAAQ,IAAI,MAAM;AAAA,MACxB,QAAQ,E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,gBACL,IACA,SAA2B;AAE3B,UAAM,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO;AAC9C,YAAQ,KAAK,cAAc;AAAA,MAC1B,KAAK;AACJ;AAAA,MACD,KAAK;AACG,eAAA,KAAK,QAAQ,CAAC;AAAA,MACtB;AACC,cAAM,IAAI,MAAM,gDAAgD,EAAE,EAAE;AAAA,IACtE;AAAA,EACD;AACA;AAlJA;AACA;AA2BA;AAAA,aAAQ,WAAA;AACP,SAAOA,KAAAA,QAAQ,WAAW;AAAA,IACzB,SAAS,KAAK;AAAA;AAAA;AAAA,IAGd,kBAAkB,EAAE,eAAe,GAAI;AAAA,EAAA,CACvC;AACF;;"}
1
+ {"version":3,"file":"contentApi.cjs","sources":["../../../src/clients/contentApi.ts"],"sourcesContent":["import { APIResponse, request } from \"@playwright/test\";\n\nexport interface Error {\n\ttype: string;\n\tmessage: string;\n}\nexport interface SearchResponse {\n\tpage: number;\n\tresults_per_page: number;\n\tresults_size: number;\n\ttotal_results_size: number;\n\ttotal_pages: number;\n\tnext_page: string | null;\n\tprev_page: string | null;\n\tresults: Document[];\n}\n\nexport interface Document {\n\tid: string;\n\tuid: string | null;\n\turl: string | null;\n\ttype: string;\n\thref: string;\n\ttags: string[];\n\tfirst_publication_date: string;\n\tlast_publication_date: string;\n\tslugs: string[];\n\tlinked_documents: unknown[];\n\tlang: string;\n\talternate_languages: string[];\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdata: Record<string, any>;\n}\n\nexport interface GraphQLResponse {\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdata: Record<string, any>;\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\terrors?: { message: string; locations: any }[];\n}\n\nexport interface Ref {\n\tid: string;\n\tref: string;\n\tlabel: string;\n\tisMasterRef?: boolean;\n}\n\nexport interface RepoConfig {\n\trefs: Ref[];\n\tbookmarks: Record<string, unknown>;\n\ttypes: Record<string, string>;\n\tlanguages: {\n\t\tid: string;\n\t\tname: string;\n\t\tis_master: boolean;\n\t}[];\n\toauth_initiate: string;\n\toauth_token: string;\n\ttags: string[];\n\tlicense: string;\n\tversion: string;\n}\n\nexport type QueryParams = {\n\tref?: string;\n\tquery?: string;\n\tq?: string;\n\tgraphQuery?: string;\n\tfetchLinks?: string;\n\torderings?: string;\n\tpageSize?: number;\n\tpage?: number;\n\tlang?: string;\n\tafter?: string;\n\troutes?: string;\n};\n\ntype ApiVersions = \"v1\" | \"v2\";\n\n/**\n * Client to query the Prismic content api. Uses Playwright to benefit from\n * network request traces in your reports. The @prismicio/client could have been\n * used but had too many abstractions (caching, error handling) that we didn't\n * want for test execution. See api docs:\n * https://prismic.io/docs/rest-api-technical-reference\n */\nexport class ContentApiClient {\n\t#version: ApiVersions;\n\t#accessToken: string | undefined;\n\n\t/**\n\t * @example new ContentApiClient(\"https://my-repo.cdn.prismic.io\" { version :\n\t * \"v2\", accessToken: \"my-secret-token\" })\n\t *\n\t * @param baseURL - the api base URL like https://my-repo.cdn.prismic.io\n\t * @param config - Optional configuration\n\t *\n\t * - {@link config.version}: Api version, default is \"v2\"\n\t * - {@link config.accessToken}: Access token for the content api -\n\t * https://prismic.io/docs/access-token\n\t */\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tconfig: { version?: ApiVersions; accessToken?: string } = {},\n\t) {\n\t\tthis.#version = config.version || \"v2\";\n\t\tthis.#accessToken = config.accessToken;\n\t}\n\n\t#context() {\n\t\treturn request.newContext({\n\t\t\tbaseURL: this.baseURL,\n\t\t\t// reset any Authorization header set globally with Playwright\n\t\t\t// didn't find a way to delete it\n\t\t\textraHTTPHeaders: { Authorization: \"\" },\n\t\t});\n\t}\n\n\tasync get(\n\t\tpath: string,\n\t\tparams?: QueryParams,\n\t\theaders?: Record<string, string>,\n\t): Promise<APIResponse> {\n\t\tconst context = await this.#context();\n\t\tconst securityParams = {\n\t\t\t...(this.#accessToken ? { access_token: this.#accessToken } : {}),\n\t\t};\n\n\t\treturn context.get(path, {\n\t\t\tparams: { ...securityParams, ...params },\n\t\t\theaders,\n\t\t});\n\t}\n\n\tasync getAsJson<T>(\n\t\turl: string,\n\t\tparams?: QueryParams,\n\t\theaders?: Record<string, string>,\n\t): Promise<T> {\n\t\tconst response = await this.get(url, params, headers);\n\n\t\treturn response.json() as T;\n\t}\n\n\t/** Query the graphql api - https://prismic.io/docs/graphql-technical-reference */\n\tasync graphql(ref: string, query: string): Promise<GraphQLResponse> {\n\t\treturn this.getAsJson<GraphQLResponse>(\n\t\t\t\"/graphql\",\n\t\t\t{ query },\n\t\t\t{ \"Prismic-ref\": ref },\n\t\t);\n\t}\n\n\tasync getRefs(): Promise<Ref[]> {\n\t\tconst data = await this.getAsJson<RepoConfig>(`/api/${this.#version}`);\n\n\t\treturn data.refs;\n\t}\n\n\tasync getMasterRef(): Promise<string> {\n\t\tconst refs = await this.getRefs();\n\n\t\tconst masterRef = refs.find(({ isMasterRef }) => isMasterRef === true);\n\t\tif (!masterRef) {\n\t\t\tthrow \"No master ref found\";\n\t\t}\n\n\t\treturn masterRef.ref;\n\t}\n\n\tasync getRefByReleaseID(releaseID: string): Promise<string> {\n\t\tconst refs = await this.getRefs();\n\t\tconst release = refs.find(({ id }) => id === releaseID);\n\t\tif (!release) {\n\t\t\tthrow `No ref found for release ${releaseID}`;\n\t\t}\n\n\t\treturn release.ref;\n\t}\n\n\t/** Search documents from the `/api/v<version>/documents/search` endpoint. */\n\tasync search(filters?: QueryParams): Promise<SearchResponse> {\n\t\tlet ref = filters?.ref;\n\t\tif (!ref) {\n\t\t\tref = await this.getMasterRef();\n\t\t}\n\n\t\treturn this.getAsJson<SearchResponse>(\n\t\t\t`/api/${this.#version}/documents/search`,\n\t\t\t{\n\t\t\t\t...filters,\n\t\t\t\tref,\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * Search for a single document by its it, using the\n\t * `/api/v<version>/documents/search` endpoint and a default filter.\n\t */\n\tasync searchByID(id: string, filters?: QueryParams): Promise<SearchResponse> {\n\t\treturn this.search({ ...filters, q: `[[at(document.id, \"${id}\")]]` });\n\t}\n\n\t/** Retrieve a single document or undefined if not found. */\n\tasync getDocumentByID(\n\t\tid: string,\n\t\tfilters?: QueryParams,\n\t): Promise<Document | undefined> {\n\t\tconst data = await this.searchByID(id, filters);\n\t\tswitch (data.results_size) {\n\t\t\tcase 0:\n\t\t\t\treturn;\n\t\t\tcase 1:\n\t\t\t\treturn data.results[0];\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Too many documents returned with the same id ${id}`);\n\t\t}\n\t}\n}\n"],"names":["request"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAuFa,iBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAe5B,YACkB,SACjB,SAA0D,IAAE;AAM7D;AAPkB;AAflB;AACA;AAckB,SAAO,UAAP;AAGZ,uBAAA,UAAW,OAAO,WAAW;AAClC,uBAAK,cAAe,OAAO;AAAA,EAC5B;AAAA,EAWA,MAAM,IACL,MACA,QACA,SAAgC;AAE1B,UAAA,UAAU,MAAM,sBAAK,sBAAL;AACtB,UAAM,iBAAiB;AAAA,MACtB,GAAI,mBAAK,gBAAe,EAAE,cAAc,mBAAK,cAAA,IAAiB;;AAGxD,WAAA,QAAQ,IAAI,MAAM;AAAA,MACxB,QAAQ,EAAE,GAAG,gBAAgB,GAAG,OAAQ;AAAA,MACxC;AAAA,IAAA,CACA;AAAA,EACF;AAAA,EAEA,MAAM,UACL,KACA,QACA,SAAgC;AAEhC,UAAM,WAAW,MAAM,KAAK,IAAI,KAAK,QAAQ,OAAO;AAEpD,WAAO,SAAS;EACjB;AAAA;AAAA,EAGA,MAAM,QAAQ,KAAa,OAAa;AAChC,WAAA,KAAK,UACX,YACA,EAAE,SACF,EAAE,eAAe,IAAA,CAAK;AAAA,EAExB;AAAA,EAEA,MAAM,UAAO;AACZ,UAAM,OAAO,MAAM,KAAK,UAAsB,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kBAAkB,EAAE,eAAe,GAAI;AAAA,EAAA,CACvC;AACF;;"}
@@ -1,9 +1,9 @@
1
1
  import { APIResponse } from "@playwright/test";
2
- export interface ContentApiError {
2
+ export interface Error {
3
3
  type: string;
4
4
  message: string;
5
5
  }
6
- export interface ContentApiSearchResponse {
6
+ export interface SearchResponse {
7
7
  page: number;
8
8
  results_per_page: number;
9
9
  results_size: number;
@@ -11,9 +11,9 @@ export interface ContentApiSearchResponse {
11
11
  total_pages: number;
12
12
  next_page: string | null;
13
13
  prev_page: string | null;
14
- results: ContentApiDocument[];
14
+ results: Document[];
15
15
  }
16
- export interface ContentApiDocument {
16
+ export interface Document {
17
17
  id: string;
18
18
  uid: string | null;
19
19
  url: string | null;
@@ -28,20 +28,35 @@ export interface ContentApiDocument {
28
28
  alternate_languages: string[];
29
29
  data: Record<string, any>;
30
30
  }
31
- export interface ContentApiGraphQLResponse {
31
+ export interface GraphQLResponse {
32
32
  data: Record<string, any>;
33
33
  errors?: {
34
34
  message: string;
35
35
  locations: any;
36
36
  }[];
37
37
  }
38
- export interface ContentApiRef {
38
+ export interface Ref {
39
39
  id: string;
40
40
  ref: string;
41
41
  label: string;
42
42
  isMasterRef?: boolean;
43
43
  }
44
- type SearchQueryParams = {
44
+ export interface RepoConfig {
45
+ refs: Ref[];
46
+ bookmarks: Record<string, unknown>;
47
+ types: Record<string, string>;
48
+ languages: {
49
+ id: string;
50
+ name: string;
51
+ is_master: boolean;
52
+ }[];
53
+ oauth_initiate: string;
54
+ oauth_token: string;
55
+ tags: string[];
56
+ license: string;
57
+ version: string;
58
+ }
59
+ export type QueryParams = {
45
60
  ref?: string;
46
61
  query?: string;
47
62
  q?: string;
@@ -57,23 +72,17 @@ type SearchQueryParams = {
57
72
  type ApiVersions = "v1" | "v2";
58
73
  /**
59
74
  * Client to query the Prismic content api. Uses Playwright to benefit from
60
- * network request traces in your reports. The @prismicio/client package could
61
- * have been used but had too many abstractions (caching, error handling) that
62
- * we didn't want for test execution. See api docs:
75
+ * network request traces in your reports. The @prismicio/client could have been
76
+ * used but had too many abstractions (caching, error handling) that we didn't
77
+ * want for test execution. See api docs:
63
78
  * https://prismic.io/docs/rest-api-technical-reference
64
79
  */
65
80
  export declare class ContentApiClient {
66
81
  #private;
67
82
  private readonly baseURL;
68
83
  /**
69
- * @example To instantiate the class:
70
- *
71
- * ```js
72
- * new ContentApiClient("https://my-repo.cdn.prismic.io", {
73
- * version: "v2",
74
- * accessToken: "my-secret-token",
75
- * });
76
- * ```
84
+ * @example new ContentApiClient("https://my-repo.cdn.prismic.io" { version :
85
+ * "v2", accessToken: "my-secret-token" })
77
86
  *
78
87
  * @param baseURL - the api base URL like https://my-repo.cdn.prismic.io
79
88
  * @param config - Optional configuration
@@ -86,21 +95,21 @@ export declare class ContentApiClient {
86
95
  version?: ApiVersions;
87
96
  accessToken?: string;
88
97
  });
89
- get(path: string, params?: SearchQueryParams, headers?: Record<string, string>): Promise<APIResponse>;
90
- getAsJson<T>(url: string, params?: SearchQueryParams, headers?: Record<string, string>): Promise<T>;
98
+ get(path: string, params?: QueryParams, headers?: Record<string, string>): Promise<APIResponse>;
99
+ getAsJson<T>(url: string, params?: QueryParams, headers?: Record<string, string>): Promise<T>;
91
100
  /** Query the graphql api - https://prismic.io/docs/graphql-technical-reference */
92
- graphql(ref: string, query: string): Promise<ContentApiGraphQLResponse>;
93
- getRefs(): Promise<ContentApiRef[]>;
101
+ graphql(ref: string, query: string): Promise<GraphQLResponse>;
102
+ getRefs(): Promise<Ref[]>;
94
103
  getMasterRef(): Promise<string>;
95
104
  getRefByReleaseID(releaseID: string): Promise<string>;
96
105
  /** Search documents from the `/api/v<version>/documents/search` endpoint. */
97
- search(filters?: SearchQueryParams): Promise<ContentApiSearchResponse>;
106
+ search(filters?: QueryParams): Promise<SearchResponse>;
98
107
  /**
99
108
  * Search for a single document by its it, using the
100
109
  * `/api/v<version>/documents/search` endpoint and a default filter.
101
110
  */
102
- searchByID(id: string, filters?: SearchQueryParams): Promise<ContentApiSearchResponse>;
111
+ searchByID(id: string, filters?: QueryParams): Promise<SearchResponse>;
103
112
  /** Retrieve a single document or undefined if not found. */
104
- getDocumentByID(id: string, filters?: SearchQueryParams): Promise<ContentApiDocument | undefined>;
113
+ getDocumentByID(id: string, filters?: QueryParams): Promise<Document | undefined>;
105
114
  }
106
115
  export {};
@@ -30,14 +30,8 @@ var _version, _accessToken, _context, context_fn;
30
30
  import { request } from "@playwright/test";
31
31
  class ContentApiClient {
32
32
  /**
33
- * @example To instantiate the class:
34
- *
35
- * ```js
36
- * new ContentApiClient("https://my-repo.cdn.prismic.io", {
37
- * version: "v2",
38
- * accessToken: "my-secret-token",
39
- * });
40
- * ```
33
+ * @example new ContentApiClient("https://my-repo.cdn.prismic.io" { version :
34
+ * "v2", accessToken: "my-secret-token" })
41
35
  *
42
36
  * @param baseURL - the api base URL like https://my-repo.cdn.prismic.io
43
37
  * @param config - Optional configuration
@@ -1 +1 @@
1
- {"version":3,"file":"contentApi.js","sources":["../../../src/clients/contentApi.ts"],"sourcesContent":["import { APIResponse, request } from \"@playwright/test\";\n\nexport interface ContentApiError {\n\ttype: string;\n\tmessage: string;\n}\nexport interface ContentApiSearchResponse {\n\tpage: number;\n\tresults_per_page: number;\n\tresults_size: number;\n\ttotal_results_size: number;\n\ttotal_pages: number;\n\tnext_page: string | null;\n\tprev_page: string | null;\n\tresults: ContentApiDocument[];\n}\n\nexport interface ContentApiDocument {\n\tid: string;\n\tuid: string | null;\n\turl: string | null;\n\ttype: string;\n\thref: string;\n\ttags: string[];\n\tfirst_publication_date: string;\n\tlast_publication_date: string;\n\tslugs: string[];\n\tlinked_documents: unknown[];\n\tlang: string;\n\talternate_languages: string[];\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdata: Record<string, any>;\n}\n\nexport interface ContentApiGraphQLResponse {\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdata: Record<string, any>;\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\terrors?: { message: string; locations: any }[];\n}\n\nexport interface ContentApiRef {\n\tid: string;\n\tref: string;\n\tlabel: string;\n\tisMasterRef?: boolean;\n}\n\ninterface ContentApiRepoConfigResponse {\n\trefs: ContentApiRef[];\n\tbookmarks: Record<string, unknown>;\n\ttypes: Record<string, string>;\n\tlanguages: {\n\t\tid: string;\n\t\tname: string;\n\t\tis_master: boolean;\n\t}[];\n\toauth_initiate: string;\n\toauth_token: string;\n\ttags: string[];\n\tlicense: string;\n\tversion: string;\n}\n\ntype SearchQueryParams = {\n\tref?: string;\n\tquery?: string;\n\tq?: string;\n\tgraphQuery?: string;\n\tfetchLinks?: string;\n\torderings?: string;\n\tpageSize?: number;\n\tpage?: number;\n\tlang?: string;\n\tafter?: string;\n\troutes?: string;\n};\n\ntype ApiVersions = \"v1\" | \"v2\";\n\n/**\n * Client to query the Prismic content api. Uses Playwright to benefit from\n * network request traces in your reports. The @prismicio/client package could\n * have been used but had too many abstractions (caching, error handling) that\n * we didn't want for test execution. See api docs:\n * https://prismic.io/docs/rest-api-technical-reference\n */\nexport class ContentApiClient {\n\t#version: ApiVersions;\n\t#accessToken: string | undefined;\n\n\t/**\n\t * @example To instantiate the class:\n\t *\n\t * ```js\n\t * new ContentApiClient(\"https://my-repo.cdn.prismic.io\", {\n\t * \tversion: \"v2\",\n\t * \taccessToken: \"my-secret-token\",\n\t * });\n\t * ```\n\t *\n\t * @param baseURL - the api base URL like https://my-repo.cdn.prismic.io\n\t * @param config - Optional configuration\n\t *\n\t * - {@link config.version}: Api version, default is \"v2\"\n\t * - {@link config.accessToken}: Access token for the content api -\n\t * https://prismic.io/docs/access-token\n\t */\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tconfig: { version?: ApiVersions; accessToken?: string } = {},\n\t) {\n\t\tthis.#version = config.version || \"v2\";\n\t\tthis.#accessToken = config.accessToken;\n\t}\n\n\t#context() {\n\t\treturn request.newContext({\n\t\t\tbaseURL: this.baseURL,\n\t\t\t// reset any Authorization header set globally with Playwright\n\t\t\t// didn't find a way to delete it\n\t\t\textraHTTPHeaders: { Authorization: \"\" },\n\t\t});\n\t}\n\n\tasync get(\n\t\tpath: string,\n\t\tparams?: SearchQueryParams,\n\t\theaders?: Record<string, string>,\n\t): Promise<APIResponse> {\n\t\tconst context = await this.#context();\n\t\tconst securityParams = {\n\t\t\t...(this.#accessToken ? { access_token: this.#accessToken } : {}),\n\t\t};\n\n\t\treturn context.get(path, {\n\t\t\tparams: { ...securityParams, ...params },\n\t\t\theaders,\n\t\t});\n\t}\n\n\tasync getAsJson<T>(\n\t\turl: string,\n\t\tparams?: SearchQueryParams,\n\t\theaders?: Record<string, string>,\n\t): Promise<T> {\n\t\tconst response = await this.get(url, params, headers);\n\n\t\treturn response.json() as T;\n\t}\n\n\t/** Query the graphql api - https://prismic.io/docs/graphql-technical-reference */\n\tasync graphql(\n\t\tref: string,\n\t\tquery: string,\n\t): Promise<ContentApiGraphQLResponse> {\n\t\treturn this.getAsJson<ContentApiGraphQLResponse>(\n\t\t\t\"/graphql\",\n\t\t\t{ query },\n\t\t\t{ \"Prismic-ref\": ref },\n\t\t);\n\t}\n\n\tasync getRefs(): Promise<ContentApiRef[]> {\n\t\tconst data = await this.getAsJson<ContentApiRepoConfigResponse>(\n\t\t\t`/api/${this.#version}`,\n\t\t);\n\n\t\treturn data.refs;\n\t}\n\n\tasync getMasterRef(): Promise<string> {\n\t\tconst refs = await this.getRefs();\n\n\t\tconst masterRef = refs.find(({ isMasterRef }) => isMasterRef === true);\n\t\tif (!masterRef) {\n\t\t\tthrow \"No master ref found\";\n\t\t}\n\n\t\treturn masterRef.ref;\n\t}\n\n\tasync getRefByReleaseID(releaseID: string): Promise<string> {\n\t\tconst refs = await this.getRefs();\n\t\tconst release = refs.find(({ id }) => id === releaseID);\n\t\tif (!release) {\n\t\t\tthrow `No ref found for release ${releaseID}`;\n\t\t}\n\n\t\treturn release.ref;\n\t}\n\n\t/** Search documents from the `/api/v<version>/documents/search` endpoint. */\n\tasync search(filters?: SearchQueryParams): Promise<ContentApiSearchResponse> {\n\t\tlet ref = filters?.ref;\n\t\tif (!ref) {\n\t\t\tref = await this.getMasterRef();\n\t\t}\n\n\t\treturn this.getAsJson<ContentApiSearchResponse>(\n\t\t\t`/api/${this.#version}/documents/search`,\n\t\t\t{\n\t\t\t\t...filters,\n\t\t\t\tref,\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * Search for a single document by its it, using the\n\t * `/api/v<version>/documents/search` endpoint and a default filter.\n\t */\n\tasync searchByID(\n\t\tid: string,\n\t\tfilters?: SearchQueryParams,\n\t): Promise<ContentApiSearchResponse> {\n\t\treturn this.search({ ...filters, q: `[[at(document.id, \"${id}\")]]` });\n\t}\n\n\t/** Retrieve a single document or undefined if not found. */\n\tasync getDocumentByID(\n\t\tid: string,\n\t\tfilters?: SearchQueryParams,\n\t): Promise<ContentApiDocument | undefined> {\n\t\tconst data = await this.searchByID(id, filters);\n\t\tswitch (data.results_size) {\n\t\t\tcase 0:\n\t\t\t\treturn;\n\t\t\tcase 1:\n\t\t\t\treturn data.results[0];\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Too many documents returned with the same id ${id}`);\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAuFa,iBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqB5B,YACkB,SACjB,SAA0D,IAAE;AAM7D;AAPkB;AArBlB;AACA;AAoBkB,SAAO,UAAP;AAGZ,uBAAA,UAAW,OAAO,WAAW;AAClC,uBAAK,cAAe,OAAO;AAAA,EAC5B;AAAA,EAWA,MAAM,IACL,MACA,QACA,SAAgC;AAE1B,UAAA,UAAU,MAAM,sBAAK,sBAAL;AACtB,UAAM,iBAAiB;AAAA,MACtB,GAAI,mBAAK,gBAAe,EAAE,cAAc,mBAAK,c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AG,sBAAsB,EAAE,OAAA,CAAQ;AAAA,EACrE;AAAA;AAAA,EAGA,MAAM,gBACL,IACA,SAA2B;AAE3B,UAAM,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO;AAC9C,YAAQ,KAAK,cAAc;AAAA,MAC1B,KAAK;AACJ;AAAA,MACD,KAAK;AACG,eAAA,KAAK,QAAQ,CAAC;AAAA,MACtB;AACC,cAAM,IAAI,MAAM,gDAAgD,EAAE,EAAE;AAAA,IACtE;AAAA,EACD;AACA;AAlJA;AACA;AA2BA;AAAA,aAAQ,WAAA;AACP,SAAO,QAAQ,WAAW;AAAA,IACzB,SAAS,KAAK;AAAA;AAAA;AAAA,IAGd,kBAAkB,EAAE,eAAe,GAAI;AAAA,EAAA,CACvC;AACF;"}
1
+ {"version":3,"file":"contentApi.js","sources":["../../../src/clients/contentApi.ts"],"sourcesContent":["import { APIResponse, request } from \"@playwright/test\";\n\nexport interface Error {\n\ttype: string;\n\tmessage: string;\n}\nexport interface SearchResponse {\n\tpage: number;\n\tresults_per_page: number;\n\tresults_size: number;\n\ttotal_results_size: number;\n\ttotal_pages: number;\n\tnext_page: string | null;\n\tprev_page: string | null;\n\tresults: Document[];\n}\n\nexport interface Document {\n\tid: string;\n\tuid: string | null;\n\turl: string | null;\n\ttype: string;\n\thref: string;\n\ttags: string[];\n\tfirst_publication_date: string;\n\tlast_publication_date: string;\n\tslugs: string[];\n\tlinked_documents: unknown[];\n\tlang: string;\n\talternate_languages: string[];\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdata: Record<string, any>;\n}\n\nexport interface GraphQLResponse {\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdata: Record<string, any>;\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\terrors?: { message: string; locations: any }[];\n}\n\nexport interface Ref {\n\tid: string;\n\tref: string;\n\tlabel: string;\n\tisMasterRef?: boolean;\n}\n\nexport interface RepoConfig {\n\trefs: Ref[];\n\tbookmarks: Record<string, unknown>;\n\ttypes: Record<string, string>;\n\tlanguages: {\n\t\tid: string;\n\t\tname: string;\n\t\tis_master: boolean;\n\t}[];\n\toauth_initiate: string;\n\toauth_token: string;\n\ttags: string[];\n\tlicense: string;\n\tversion: string;\n}\n\nexport type QueryParams = {\n\tref?: string;\n\tquery?: string;\n\tq?: string;\n\tgraphQuery?: string;\n\tfetchLinks?: string;\n\torderings?: string;\n\tpageSize?: number;\n\tpage?: number;\n\tlang?: string;\n\tafter?: string;\n\troutes?: string;\n};\n\ntype ApiVersions = \"v1\" | \"v2\";\n\n/**\n * Client to query the Prismic content api. Uses Playwright to benefit from\n * network request traces in your reports. The @prismicio/client could have been\n * used but had too many abstractions (caching, error handling) that we didn't\n * want for test execution. See api docs:\n * https://prismic.io/docs/rest-api-technical-reference\n */\nexport class ContentApiClient {\n\t#version: ApiVersions;\n\t#accessToken: string | undefined;\n\n\t/**\n\t * @example new ContentApiClient(\"https://my-repo.cdn.prismic.io\" { version :\n\t * \"v2\", accessToken: \"my-secret-token\" })\n\t *\n\t * @param baseURL - the api base URL like https://my-repo.cdn.prismic.io\n\t * @param config - Optional configuration\n\t *\n\t * - {@link config.version}: Api version, default is \"v2\"\n\t * - {@link config.accessToken}: Access token for the content api -\n\t * https://prismic.io/docs/access-token\n\t */\n\tconstructor(\n\t\tprivate readonly baseURL: string,\n\t\tconfig: { version?: ApiVersions; accessToken?: string } = {},\n\t) {\n\t\tthis.#version = config.version || \"v2\";\n\t\tthis.#accessToken = config.accessToken;\n\t}\n\n\t#context() {\n\t\treturn request.newContext({\n\t\t\tbaseURL: this.baseURL,\n\t\t\t// reset any Authorization header set globally with Playwright\n\t\t\t// didn't find a way to delete it\n\t\t\textraHTTPHeaders: { Authorization: \"\" },\n\t\t});\n\t}\n\n\tasync get(\n\t\tpath: string,\n\t\tparams?: QueryParams,\n\t\theaders?: Record<string, string>,\n\t): Promise<APIResponse> {\n\t\tconst context = await this.#context();\n\t\tconst securityParams = {\n\t\t\t...(this.#accessToken ? { access_token: this.#accessToken } : {}),\n\t\t};\n\n\t\treturn context.get(path, {\n\t\t\tparams: { ...securityParams, ...params },\n\t\t\theaders,\n\t\t});\n\t}\n\n\tasync getAsJson<T>(\n\t\turl: string,\n\t\tparams?: QueryParams,\n\t\theaders?: Record<string, string>,\n\t): Promise<T> {\n\t\tconst response = await this.get(url, params, headers);\n\n\t\treturn response.json() as T;\n\t}\n\n\t/** Query the graphql api - https://prismic.io/docs/graphql-technical-reference */\n\tasync graphql(ref: string, query: string): Promise<GraphQLResponse> {\n\t\treturn this.getAsJson<GraphQLResponse>(\n\t\t\t\"/graphql\",\n\t\t\t{ query },\n\t\t\t{ \"Prismic-ref\": ref },\n\t\t);\n\t}\n\n\tasync getRefs(): Promise<Ref[]> {\n\t\tconst data = await this.getAsJson<RepoConfig>(`/api/${this.#version}`);\n\n\t\treturn data.refs;\n\t}\n\n\tasync getMasterRef(): Promise<string> {\n\t\tconst refs = await this.getRefs();\n\n\t\tconst masterRef = refs.find(({ isMasterRef }) => isMasterRef === true);\n\t\tif (!masterRef) {\n\t\t\tthrow \"No master ref found\";\n\t\t}\n\n\t\treturn masterRef.ref;\n\t}\n\n\tasync getRefByReleaseID(releaseID: string): Promise<string> {\n\t\tconst refs = await this.getRefs();\n\t\tconst release = refs.find(({ id }) => id === releaseID);\n\t\tif (!release) {\n\t\t\tthrow `No ref found for release ${releaseID}`;\n\t\t}\n\n\t\treturn release.ref;\n\t}\n\n\t/** Search documents from the `/api/v<version>/documents/search` endpoint. */\n\tasync search(filters?: QueryParams): Promise<SearchResponse> {\n\t\tlet ref = filters?.ref;\n\t\tif (!ref) {\n\t\t\tref = await this.getMasterRef();\n\t\t}\n\n\t\treturn this.getAsJson<SearchResponse>(\n\t\t\t`/api/${this.#version}/documents/search`,\n\t\t\t{\n\t\t\t\t...filters,\n\t\t\t\tref,\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * Search for a single document by its it, using the\n\t * `/api/v<version>/documents/search` endpoint and a default filter.\n\t */\n\tasync searchByID(id: string, filters?: QueryParams): Promise<SearchResponse> {\n\t\treturn this.search({ ...filters, q: `[[at(document.id, \"${id}\")]]` });\n\t}\n\n\t/** Retrieve a single document or undefined if not found. */\n\tasync getDocumentByID(\n\t\tid: string,\n\t\tfilters?: QueryParams,\n\t): Promise<Document | undefined> {\n\t\tconst data = await this.searchByID(id, filters);\n\t\tswitch (data.results_size) {\n\t\t\tcase 0:\n\t\t\t\treturn;\n\t\t\tcase 1:\n\t\t\t\treturn data.results[0];\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Too many documents returned with the same id ${id}`);\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAuFa,iBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAe5B,YACkB,SACjB,SAA0D,IAAE;AAM7D;AAPkB;AAflB;AACA;AAckB,SAAO,UAAP;AAGZ,uBAAA,UAAW,OAAO,WAAW;AAClC,uBAAK,cAAe,OAAO;AAAA,EAC5B;AAAA,EAWA,MAAM,IACL,MACA,QACA,SAAgC;AAE1B,UAAA,UAAU,MAAM,sBAAK,sBAAL;AACtB,UAAM,iBAAiB;AAAA,MACtB,GAAI,mBAAK,gBAAe,EAAE,cAAc,mBAAK,cAAA,IAAiB;;AAGxD,WAAA,QAAQ,IAAI,MAAM;AAAA,MACxB,QAAQ,EAAE,GAAG,gBAAgB,GAAG,OAAQ;AAAA,MACxC;AAAA,IAAA,CACA;AAAA,EACF;AAAA,EAEA,MAAM,UACL,KACA,QACA,SAAgC;AAEhC,UAAM,WAAW,MAAM,KAAK,IAAI,KAAK,QAAQ,OAAO;AAEpD,WAAO,SAAS;EACjB;AAAA;AAAA,EAGA,MAAM,QAAQ,KAAa,OAAa;AAChC,WAAA,KAAK,UACX,YACA,EAAE,SACF,EAAE,eAAe,IAAA,CAAK;AAAA,EAExB;AAAA,EAEA,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ACzB,SAAS,KAAK;AAAA;AAAA;AAAA,IAGd,kBAAkB,EAAE,eAAe,GAAI;AAAA,EAAA,CACvC;AACF;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/e2e-tests-utils",
3
- "version": "1.3.1",
3
+ "version": "1.4.0-alpha.2",
4
4
  "description": "A collection of utilities for to manage Prismic test data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -40,8 +40,6 @@
40
40
  "prepare": "npm run build",
41
41
  "release": "npm run test && standard-version && git push --follow-tags && npm run build && npm publish",
42
42
  "release:dry": "standard-version --dry-run",
43
- "release:patch": "npm run test && standard-version --release-as patch && git push --follow-tags && npm run build && npm publish",
44
- "release:patch:dry": "standard-version --dry-run --release-as patch",
45
43
  "release:alpha": "npm run test && standard-version --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha",
46
44
  "release:alpha:dry": "standard-version --prerelease alpha --dry-run",
47
45
  "lint": "eslint --ext .js,.ts .",
@@ -1,10 +1,10 @@
1
1
  import { APIResponse, request } from "@playwright/test";
2
2
 
3
- export interface ContentApiError {
3
+ export interface Error {
4
4
  type: string;
5
5
  message: string;
6
6
  }
7
- export interface ContentApiSearchResponse {
7
+ export interface SearchResponse {
8
8
  page: number;
9
9
  results_per_page: number;
10
10
  results_size: number;
@@ -12,10 +12,10 @@ export interface ContentApiSearchResponse {
12
12
  total_pages: number;
13
13
  next_page: string | null;
14
14
  prev_page: string | null;
15
- results: ContentApiDocument[];
15
+ results: Document[];
16
16
  }
17
17
 
18
- export interface ContentApiDocument {
18
+ export interface Document {
19
19
  id: string;
20
20
  uid: string | null;
21
21
  url: string | null;
@@ -32,22 +32,22 @@ export interface ContentApiDocument {
32
32
  data: Record<string, any>;
33
33
  }
34
34
 
35
- export interface ContentApiGraphQLResponse {
35
+ export interface GraphQLResponse {
36
36
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
37
  data: Record<string, any>;
38
38
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
39
  errors?: { message: string; locations: any }[];
40
40
  }
41
41
 
42
- export interface ContentApiRef {
42
+ export interface Ref {
43
43
  id: string;
44
44
  ref: string;
45
45
  label: string;
46
46
  isMasterRef?: boolean;
47
47
  }
48
48
 
49
- interface ContentApiRepoConfigResponse {
50
- refs: ContentApiRef[];
49
+ export interface RepoConfig {
50
+ refs: Ref[];
51
51
  bookmarks: Record<string, unknown>;
52
52
  types: Record<string, string>;
53
53
  languages: {
@@ -62,7 +62,7 @@ interface ContentApiRepoConfigResponse {
62
62
  version: string;
63
63
  }
64
64
 
65
- type SearchQueryParams = {
65
+ export type QueryParams = {
66
66
  ref?: string;
67
67
  query?: string;
68
68
  q?: string;
@@ -80,9 +80,9 @@ type ApiVersions = "v1" | "v2";
80
80
 
81
81
  /**
82
82
  * Client to query the Prismic content api. Uses Playwright to benefit from
83
- * network request traces in your reports. The @prismicio/client package could
84
- * have been used but had too many abstractions (caching, error handling) that
85
- * we didn't want for test execution. See api docs:
83
+ * network request traces in your reports. The @prismicio/client could have been
84
+ * used but had too many abstractions (caching, error handling) that we didn't
85
+ * want for test execution. See api docs:
86
86
  * https://prismic.io/docs/rest-api-technical-reference
87
87
  */
88
88
  export class ContentApiClient {
@@ -90,14 +90,8 @@ export class ContentApiClient {
90
90
  #accessToken: string | undefined;
91
91
 
92
92
  /**
93
- * @example To instantiate the class:
94
- *
95
- * ```js
96
- * new ContentApiClient("https://my-repo.cdn.prismic.io", {
97
- * version: "v2",
98
- * accessToken: "my-secret-token",
99
- * });
100
- * ```
93
+ * @example new ContentApiClient("https://my-repo.cdn.prismic.io" { version :
94
+ * "v2", accessToken: "my-secret-token" })
101
95
  *
102
96
  * @param baseURL - the api base URL like https://my-repo.cdn.prismic.io
103
97
  * @param config - Optional configuration
@@ -125,7 +119,7 @@ export class ContentApiClient {
125
119
 
126
120
  async get(
127
121
  path: string,
128
- params?: SearchQueryParams,
122
+ params?: QueryParams,
129
123
  headers?: Record<string, string>,
130
124
  ): Promise<APIResponse> {
131
125
  const context = await this.#context();
@@ -141,7 +135,7 @@ export class ContentApiClient {
141
135
 
142
136
  async getAsJson<T>(
143
137
  url: string,
144
- params?: SearchQueryParams,
138
+ params?: QueryParams,
145
139
  headers?: Record<string, string>,
146
140
  ): Promise<T> {
147
141
  const response = await this.get(url, params, headers);
@@ -150,21 +144,16 @@ export class ContentApiClient {
150
144
  }
151
145
 
152
146
  /** Query the graphql api - https://prismic.io/docs/graphql-technical-reference */
153
- async graphql(
154
- ref: string,
155
- query: string,
156
- ): Promise<ContentApiGraphQLResponse> {
157
- return this.getAsJson<ContentApiGraphQLResponse>(
147
+ async graphql(ref: string, query: string): Promise<GraphQLResponse> {
148
+ return this.getAsJson<GraphQLResponse>(
158
149
  "/graphql",
159
150
  { query },
160
151
  { "Prismic-ref": ref },
161
152
  );
162
153
  }
163
154
 
164
- async getRefs(): Promise<ContentApiRef[]> {
165
- const data = await this.getAsJson<ContentApiRepoConfigResponse>(
166
- `/api/${this.#version}`,
167
- );
155
+ async getRefs(): Promise<Ref[]> {
156
+ const data = await this.getAsJson<RepoConfig>(`/api/${this.#version}`);
168
157
 
169
158
  return data.refs;
170
159
  }
@@ -191,13 +180,13 @@ export class ContentApiClient {
191
180
  }
192
181
 
193
182
  /** Search documents from the `/api/v<version>/documents/search` endpoint. */
194
- async search(filters?: SearchQueryParams): Promise<ContentApiSearchResponse> {
183
+ async search(filters?: QueryParams): Promise<SearchResponse> {
195
184
  let ref = filters?.ref;
196
185
  if (!ref) {
197
186
  ref = await this.getMasterRef();
198
187
  }
199
188
 
200
- return this.getAsJson<ContentApiSearchResponse>(
189
+ return this.getAsJson<SearchResponse>(
201
190
  `/api/${this.#version}/documents/search`,
202
191
  {
203
192
  ...filters,
@@ -210,18 +199,15 @@ export class ContentApiClient {
210
199
  * Search for a single document by its it, using the
211
200
  * `/api/v<version>/documents/search` endpoint and a default filter.
212
201
  */
213
- async searchByID(
214
- id: string,
215
- filters?: SearchQueryParams,
216
- ): Promise<ContentApiSearchResponse> {
202
+ async searchByID(id: string, filters?: QueryParams): Promise<SearchResponse> {
217
203
  return this.search({ ...filters, q: `[[at(document.id, "${id}")]]` });
218
204
  }
219
205
 
220
206
  /** Retrieve a single document or undefined if not found. */
221
207
  async getDocumentByID(
222
208
  id: string,
223
- filters?: SearchQueryParams,
224
- ): Promise<ContentApiDocument | undefined> {
209
+ filters?: QueryParams,
210
+ ): Promise<Document | undefined> {
225
211
  const data = await this.searchByID(id, filters);
226
212
  switch (data.results_size) {
227
213
  case 0: