@prismicio/client 6.3.0 → 6.4.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/src/client.ts CHANGED
@@ -181,11 +181,11 @@ type GetAllParams = {
181
181
  /**
182
182
  * Arguments to determine how the URL for a preview session is resolved.
183
183
  */
184
- type ResolvePreviewArgs = {
184
+ type ResolvePreviewArgs<LinkResolverReturnType> = {
185
185
  /**
186
186
  * A function that maps a Prismic document to a URL within your app.
187
187
  */
188
- linkResolver?: prismicH.LinkResolverFunction;
188
+ linkResolver?: prismicH.LinkResolverFunction<LinkResolverReturnType>;
189
189
 
190
190
  /**
191
191
  * A fallback URL if the Link Resolver does not return a value.
@@ -381,7 +381,7 @@ export class Client {
381
381
  this.fetchFn = this.fetchFn.bind(globalThis);
382
382
  }
383
383
 
384
- this.graphqlFetch = this.graphqlFetch.bind(this);
384
+ this.graphQLFetch = this.graphQLFetch.bind(this);
385
385
  }
386
386
 
387
387
  /**
@@ -547,7 +547,8 @@ export class Client {
547
547
  const { limit = Infinity, ...actualParams } = params;
548
548
  const resolvedParams = {
549
549
  ...actualParams,
550
- pageSize: actualParams.pageSize || MAX_PAGE_SIZE,
550
+ pageSize:
551
+ actualParams.pageSize || this.defaultParams?.pageSize || MAX_PAGE_SIZE,
551
552
  };
552
553
 
553
554
  const documents: TDocument[] = [];
@@ -1193,8 +1194,8 @@ export class Client {
1193
1194
  * @returns The URL for the previewed document during an active preview
1194
1195
  * session. The user should be redirected to this URL.
1195
1196
  */
1196
- async resolvePreviewURL(
1197
- args: ResolvePreviewArgs & FetchParams,
1197
+ async resolvePreviewURL<LinkResolverReturnType>(
1198
+ args: ResolvePreviewArgs<LinkResolverReturnType> & FetchParams,
1198
1199
  ): Promise<string> {
1199
1200
  let documentID = args.documentID;
1200
1201
  let previewToken = args.previewToken;
@@ -1211,19 +1212,21 @@ export class Client {
1211
1212
  previewToken || (this.refState.httpRequest.query.token as string);
1212
1213
  }
1213
1214
 
1214
- if (documentID != null) {
1215
+ if (documentID != null && previewToken != null) {
1215
1216
  const document = await this.getByID(documentID, {
1216
1217
  signal: args.signal,
1217
1218
  ref: previewToken,
1218
1219
  lang: "*",
1219
1220
  });
1220
1221
 
1221
- // We know we have a valid field to resolve since we are using prismicH.documentToLinkField
1222
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1223
- return prismicH.asLink(document, args.linkResolver)!;
1224
- } else {
1225
- return args.defaultURL;
1222
+ const url = prismicH.asLink(document, args.linkResolver);
1223
+
1224
+ if (typeof url === "string") {
1225
+ return url;
1226
+ }
1226
1227
  }
1228
+
1229
+ return args.defaultURL;
1227
1230
  }
1228
1231
 
1229
1232
  /**
@@ -1312,6 +1315,12 @@ export class Client {
1312
1315
  };
1313
1316
  }
1314
1317
 
1318
+ /**
1319
+ * @deprecated Renamed to `graphQLFetch()` (note the capitalization of "QL").
1320
+ */
1321
+ // TODO: Remove in v3
1322
+ graphqlFetch = this.graphQLFetch;
1323
+
1315
1324
  /**
1316
1325
  * A `fetch()` function to be used with GraphQL clients configured for
1317
1326
  * Prismic's GraphQL API. It automatically applies the necessary `prismic-ref`
@@ -1339,7 +1348,7 @@ export class Client {
1339
1348
  * @returns The `fetch()` Response for the request.
1340
1349
  * @experimental
1341
1350
  */
1342
- async graphqlFetch(
1351
+ async graphQLFetch(
1343
1352
  input: RequestInfo,
1344
1353
  init?: RequestInit,
1345
1354
  ): Promise<Response> {