@fourtwelvelabs/fetch-contentful 0.4.1 → 1.0.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.
@@ -13,7 +13,6 @@ function readEnvSettings() {
13
13
  space: void 0,
14
14
  environment: void 0,
15
15
  deliveryToken: void 0,
16
- token: void 0,
17
16
  previewToken: void 0
18
17
  };
19
18
  }
@@ -28,7 +27,6 @@ function readEnvSettings() {
28
27
  process.env.CONTENTFUL_ENVIRONMENT || process.env.NEXT_PUBLIC_CONTENTFUL_ENVIRONMENT
29
28
  ),
30
29
  deliveryToken,
31
- token: deliveryToken,
32
30
  // No `NEXT_PUBLIC_` fallback: see the note at the top of this file.
33
31
  previewToken: orUndefined(process.env.CONTENTFUL_PREVIEW_ACCESS_TOKEN)
34
32
  };
@@ -191,9 +189,7 @@ function loadEnvFiles(directory, explicit) {
191
189
  const path = resolve(directory, candidate);
192
190
  if (!existsSync(path)) continue;
193
191
  load.files.push(candidate);
194
- for (const [key, value] of Object.entries(
195
- parseEnvFile(readFileSync(path, "utf8"))
196
- )) {
192
+ for (const [key, value] of Object.entries(parseEnvFile(readFileSync(path, "utf8")))) {
197
193
  if (!process.env[key]) {
198
194
  process.env[key] = value;
199
195
  load.applied.push(key);
@@ -262,26 +258,19 @@ async function fetchSchemaSdl(options) {
262
258
  });
263
259
  } catch (cause) {
264
260
  throw new CliError(
265
- `Could not reach Contentful at ${url}: ${redact(
266
- String(cause),
267
- options.token
268
- )}`
261
+ `Could not reach Contentful at ${url}: ${redact(String(cause), options.token)}`
269
262
  );
270
263
  }
271
264
  if (response.status === 401 || response.status === 403) {
272
265
  throw new CliError(
273
- `Contentful rejected the access token (HTTP ${String(
274
- response.status
275
- )}).
266
+ `Contentful rejected the access token (HTTP ${String(response.status)}).
276
267
  Check that the token is a Content Delivery API token for space "${options.space}", and that it has access to environment "${options.environment}".`
277
268
  );
278
269
  }
279
270
  if (!response.ok) {
280
271
  const body = bodySnippet(await response.text().catch(() => ""), options.token);
281
- throw new CliError(
282
- `Contentful responded with HTTP ${String(response.status)}.
283
- ${body}`
284
- );
272
+ throw new CliError(`Contentful responded with HTTP ${String(response.status)}.
273
+ ${body}`);
285
274
  }
286
275
  let payload;
287
276
  try {
@@ -292,10 +281,7 @@ async function fetchSchemaSdl(options) {
292
281
  if (payload.errors && payload.errors.length > 0) {
293
282
  const messages = payload.errors.map((error) => error.message ?? "unknown error").join("; ");
294
283
  throw new CliError(
295
- `Contentful returned GraphQL errors during introspection: ${redact(
296
- messages,
297
- options.token
298
- )}`
284
+ `Contentful returned GraphQL errors during introspection: ${redact(messages, options.token)}`
299
285
  );
300
286
  }
301
287
  if (!payload.data) {
@@ -308,9 +294,7 @@ async function fetchSchemaSdl(options) {
308
294
  `;
309
295
  } catch (cause) {
310
296
  throw new CliError(
311
- `Could not build a schema from Contentful's introspection response: ${String(
312
- cause
313
- )}`
297
+ `Could not build a schema from Contentful's introspection response: ${String(cause)}`
314
298
  );
315
299
  }
316
300
  }
@@ -343,9 +327,7 @@ function installCommand(manager, packages) {
343
327
  function missingDependencies(cwd, packages) {
344
328
  let manifest;
345
329
  try {
346
- manifest = JSON.parse(
347
- readFileSync(join(cwd, "package.json"), "utf8")
348
- );
330
+ manifest = JSON.parse(readFileSync(join(cwd, "package.json"), "utf8"));
349
331
  } catch {
350
332
  return [...packages];
351
333
  }
@@ -406,9 +388,7 @@ var Scanner = class {
406
388
  }
407
389
  expect(character) {
408
390
  if (this.peek() !== character) {
409
- throw new JsoncError(
410
- `Expected "${character}" at offset ${String(this.index)}.`
411
- );
391
+ throw new JsoncError(`Expected "${character}" at offset ${String(this.index)}.`);
412
392
  }
413
393
  this.index += 1;
414
394
  }
@@ -416,9 +396,7 @@ var Scanner = class {
416
396
  const node = this.parseValue();
417
397
  this.skipTrivia();
418
398
  if (this.index !== this.source.length) {
419
- throw new JsoncError(
420
- `Unexpected trailing content at offset ${String(this.index)}.`
421
- );
399
+ throw new JsoncError(`Unexpected trailing content at offset ${String(this.index)}.`);
422
400
  }
423
401
  return node;
424
402
  }
@@ -538,9 +516,7 @@ function renderPluginEntry(indent, unit, config) {
538
516
  "{",
539
517
  `${indent}${unit}"name": ${JSON.stringify(GRAPHQLSP_PLUGIN)},`,
540
518
  `${indent}${unit}"schema": ${JSON.stringify(config.schema)},`,
541
- `${indent}${unit}"tadaOutputLocation": ${JSON.stringify(
542
- config.tadaOutputLocation
543
- )}`,
519
+ `${indent}${unit}"tadaOutputLocation": ${JSON.stringify(config.tadaOutputLocation)}`,
544
520
  `${indent}}`
545
521
  ].join("\n");
546
522
  }
@@ -568,11 +544,7 @@ ${closeIndent}`
568
544
  function renderPluginsArray(indent, unit, config) {
569
545
  const entryIndent = `${indent}${unit}`;
570
546
  return `[
571
- ${entryIndent}${renderPluginEntry(
572
- entryIndent,
573
- unit,
574
- config
575
- )}
547
+ ${entryIndent}${renderPluginEntry(entryIndent, unit, config)}
576
548
  ${indent}]`;
577
549
  }
578
550
  function patchTsconfig(source, config) {
@@ -642,9 +614,7 @@ ${indent}}`,
642
614
  text: JSON.stringify(value)
643
615
  });
644
616
  } else {
645
- edits.push(
646
- insertMember(source, existing, key, () => JSON.stringify(value), unit)
647
- );
617
+ edits.push(insertMember(source, existing, key, () => JSON.stringify(value), unit));
648
618
  }
649
619
  }
650
620
  const patched = applyEdits(source, edits);
@@ -674,11 +644,7 @@ ${indent}${renderPluginEntry(indent, unit, config)}`
674
644
  start: plugins.value.start + 1,
675
645
  end: plugins.value.end - 1,
676
646
  text: `
677
- ${entryIndent}${renderPluginEntry(
678
- entryIndent,
679
- unit,
680
- config
681
- )}
647
+ ${entryIndent}${renderPluginEntry(entryIndent, unit, config)}
682
648
  ${closeIndent}`
683
649
  }
684
650
  ])
@@ -814,9 +780,7 @@ function planTsconfig(paths) {
814
780
  }
815
781
  function planGraphqlModule(paths, force) {
816
782
  const before = readIfExists(paths.graphqlFile);
817
- const after = renderGraphqlModule(
818
- relativeSpecifier(paths.graphqlFile, paths.tadaOutput)
819
- );
783
+ const after = renderGraphqlModule(relativeSpecifier(paths.graphqlFile, paths.tadaOutput));
820
784
  if (before !== void 0 && !force) {
821
785
  return {
822
786
  kind: "skip",
@@ -883,9 +847,7 @@ function apply(action) {
883
847
  function reportManual(action, paths, io) {
884
848
  if (action.kind !== "manual") return;
885
849
  io.stdout("");
886
- io.stdout(
887
- `${display(paths.root, action.path)} was left untouched because ${action.reason}.`
888
- );
850
+ io.stdout(`${display(paths.root, action.path)} was left untouched because ${action.reason}.`);
889
851
  io.stdout('Add this entry to "compilerOptions.plugins" by hand:');
890
852
  io.stdout("");
891
853
  for (const line of action.block.split("\n")) io.stdout(` ${line}`);
@@ -923,18 +885,11 @@ async function tadaInit(args, io) {
923
885
  io.stdout("Next steps:");
924
886
  io.stdout(` 1. Restart the TypeScript server so ${GRAPHQLSP_PLUGIN} loads.`);
925
887
  io.stdout(
926
- ` 2. Write a query with the \`graphql\` helper from ${display(
927
- paths.root,
928
- paths.graphqlFile
929
- )},`
930
- );
931
- io.stdout(
932
- ` then pass it to fetchContentful from ${PACKAGE_NAME}.`
888
+ ` 2. Write a query with the \`graphql\` helper from ${display(paths.root, paths.graphqlFile)},`
933
889
  );
890
+ io.stdout(` then pass it to fetchContentful from ${PACKAGE_NAME}.`);
934
891
  io.stdout(" Result and variable types are inferred from the document.");
935
- io.stdout(
936
- " 3. After a content-model change, run `fetch-contentful tada-refresh`."
937
- );
892
+ io.stdout(" 3. After a content-model change, run `fetch-contentful tada-refresh`.");
938
893
  return 0;
939
894
  }
940
895
  async function tadaRefresh(args, io) {
@@ -946,10 +901,7 @@ async function tadaRefresh(args, io) {
946
901
  const action = planSchema(sdl, paths);
947
902
  if (action.kind === "unchanged") {
948
903
  io.stdout(
949
- `Schema is already up to date \u2014 ${display(
950
- paths.root,
951
- paths.schema
952
- )} left untouched.`
904
+ `Schema is already up to date \u2014 ${display(paths.root, paths.schema)} left untouched.`
953
905
  );
954
906
  return 0;
955
907
  }
@@ -974,10 +926,7 @@ async function dispatch(argv, io) {
974
926
  }
975
927
  function knownTokens(argv) {
976
928
  const env = readEnvSettings();
977
- const tokens = [
978
- env.deliveryToken,
979
- env.previewToken
980
- ];
929
+ const tokens = [env.deliveryToken, env.previewToken];
981
930
  for (const [index, argument] of argv.entries()) {
982
931
  if (argument.startsWith("--token=")) tokens.push(argument.slice(8));
983
932
  else if (argument === "--token") tokens.push(argv[index + 1]);