@slicemachine/manager 0.2.2-dev-page-types.1 → 0.2.2-dev-page-types.3

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.
Files changed (55) hide show
  1. package/dist/_node_modules/node-fetch/src/index.js +2 -2
  2. package/dist/_node_modules/node-fetch/src/index.js.map +1 -1
  3. package/dist/auth/PrismicAuthManager.cjs +4 -4
  4. package/dist/auth/PrismicAuthManager.cjs.map +1 -1
  5. package/dist/auth/PrismicAuthManager.js +1 -1
  6. package/dist/auth/PrismicAuthManager.js.map +1 -1
  7. package/dist/lib/checkIsURLAccessible.cjs +2 -2
  8. package/dist/lib/checkIsURLAccessible.cjs.map +1 -1
  9. package/dist/lib/checkIsURLAccessible.js +1 -1
  10. package/dist/lib/checkIsURLAccessible.js.map +1 -1
  11. package/dist/lib/fetch.cjs +36 -0
  12. package/dist/lib/fetch.cjs.map +1 -0
  13. package/dist/lib/fetch.d.ts +15 -0
  14. package/dist/lib/fetch.js +18 -0
  15. package/dist/lib/fetch.js.map +1 -0
  16. package/dist/lib/fetchGitHubReleaseBodyForRelease.cjs +3 -3
  17. package/dist/lib/fetchGitHubReleaseBodyForRelease.cjs.map +1 -1
  18. package/dist/lib/fetchGitHubReleaseBodyForRelease.js +1 -1
  19. package/dist/lib/fetchGitHubReleaseBodyForRelease.js.map +1 -1
  20. package/dist/lib/fetchNPMPackageVersions.cjs +2 -2
  21. package/dist/lib/fetchNPMPackageVersions.cjs.map +1 -1
  22. package/dist/lib/fetchNPMPackageVersions.js +1 -1
  23. package/dist/lib/fetchNPMPackageVersions.js.map +1 -1
  24. package/dist/managers/customTypes/CustomTypesManager.cjs +7 -4
  25. package/dist/managers/customTypes/CustomTypesManager.cjs.map +1 -1
  26. package/dist/managers/customTypes/CustomTypesManager.js +5 -2
  27. package/dist/managers/customTypes/CustomTypesManager.js.map +1 -1
  28. package/dist/managers/prismicRepository/PrismicRepositoryManager.cjs +2 -2
  29. package/dist/managers/prismicRepository/PrismicRepositoryManager.cjs.map +1 -1
  30. package/dist/managers/prismicRepository/PrismicRepositoryManager.js +1 -1
  31. package/dist/managers/prismicRepository/PrismicRepositoryManager.js.map +1 -1
  32. package/dist/managers/screenshots/ScreenshotsManager.cjs +8 -4
  33. package/dist/managers/screenshots/ScreenshotsManager.cjs.map +1 -1
  34. package/dist/managers/screenshots/ScreenshotsManager.js +6 -2
  35. package/dist/managers/screenshots/ScreenshotsManager.js.map +1 -1
  36. package/dist/managers/simulator/SimulatorManager.cjs +2 -2
  37. package/dist/managers/simulator/SimulatorManager.cjs.map +1 -1
  38. package/dist/managers/simulator/SimulatorManager.js +1 -1
  39. package/dist/managers/simulator/SimulatorManager.js.map +1 -1
  40. package/dist/managers/slices/SlicesManager.cjs +10 -7
  41. package/dist/managers/slices/SlicesManager.cjs.map +1 -1
  42. package/dist/managers/slices/SlicesManager.d.ts +1 -1
  43. package/dist/managers/slices/SlicesManager.js +8 -5
  44. package/dist/managers/slices/SlicesManager.js.map +1 -1
  45. package/package.json +4 -4
  46. package/src/auth/PrismicAuthManager.ts +1 -1
  47. package/src/lib/checkIsURLAccessible.ts +1 -1
  48. package/src/lib/fetch.ts +46 -0
  49. package/src/lib/fetchGitHubReleaseBodyForRelease.ts +1 -1
  50. package/src/lib/fetchNPMPackageVersions.ts +1 -1
  51. package/src/managers/customTypes/CustomTypesManager.ts +6 -3
  52. package/src/managers/prismicRepository/PrismicRepositoryManager.ts +1 -1
  53. package/src/managers/screenshots/ScreenshotsManager.ts +1 -1
  54. package/src/managers/simulator/SimulatorManager.ts +1 -1
  55. package/src/managers/slices/SlicesManager.ts +8 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slicemachine/manager",
3
- "version": "0.2.2-dev-page-types.1",
3
+ "version": "0.2.2-dev-page-types.3",
4
4
  "description": "Manage all aspects of a Slice Machine project.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -62,10 +62,10 @@
62
62
  },
63
63
  "dependencies": {
64
64
  "@antfu/ni": "^0.20.0",
65
- "@prismicio/custom-types-client": "^1.1.0",
65
+ "@prismicio/custom-types-client": "1.2.0-alpha.0",
66
66
  "@prismicio/mocks": "2.0.0-alpha.2",
67
67
  "@prismicio/types-internal": "2.0.0-alpha.9",
68
- "@slicemachine/plugin-kit": "0.2.1-dev-page-types.1",
68
+ "@slicemachine/plugin-kit": "0.2.1-dev-page-types.3",
69
69
  "@wooorm/starry-night": "^1.6.0",
70
70
  "analytics-node": "^6.2.0",
71
71
  "cookie": "^0.5.0",
@@ -138,5 +138,5 @@
138
138
  "publishConfig": {
139
139
  "access": "public"
140
140
  },
141
- "gitHead": "9cb54f39f52db111f1430c4c19e6e8e431455438"
141
+ "gitHead": "d2c2d77cb89aba03b05df7647420fb20cc6aa7fb"
142
142
  }
@@ -5,7 +5,7 @@ import * as os from "node:os";
5
5
  import * as http from "node:http";
6
6
 
7
7
  import * as h3 from "h3";
8
- import fetch from "node-fetch";
8
+ import fetch from "../lib/fetch";
9
9
  import cookie from "cookie";
10
10
  import cors from "cors";
11
11
  import getPort from "get-port";
@@ -1,4 +1,4 @@
1
- import fetch from "node-fetch";
1
+ import fetch from "./fetch";
2
2
 
3
3
  export const checkIsURLAccessible = async (url: string): Promise<boolean> => {
4
4
  const res = await fetch(url);
@@ -0,0 +1,46 @@
1
+ // This temporary wrapper around `node-fetch` fixes an issue where quick
2
+ // consecutive network requests cause failed requests.
3
+ //
4
+ // See https://github.com/node-fetch/node-fetch/issues/1735 for more details.
5
+ //
6
+ // TODO: Remove this wrapper and replace all imports with `node-fetch` if https://github.com/node-fetch/node-fetch/pull/1736 is merged.
7
+
8
+ import * as http from "node:http";
9
+ import * as https from "node:https";
10
+ import baseFetch from "node-fetch";
11
+
12
+ export * from "node-fetch";
13
+
14
+ /**
15
+ * The default HTTP Agent with `keepAlive: true` used in `fetch()` requests.
16
+ */
17
+ const DEFAULT_HTTP_AGENT = new http.Agent({ keepAlive: true });
18
+
19
+ /**
20
+ * The default HTTPS Agent with `keepAlive: true` used in `fetch()` requests.
21
+ */
22
+ const DEFAULT_HTTPS_AGENT = new https.Agent({ keepAlive: true });
23
+
24
+ /**
25
+ * Patched `fetch()` from `node-fetch` that fixes a bug where quick consecutive
26
+ * network requests cause failed requests.
27
+ *
28
+ * Use this `fetch()` in place of `node-fetch`'s `fetch()`.
29
+ *
30
+ * @remarks
31
+ * `fetch()` is patched by setting an HTTP/HTTPS Agent with `keepAlive: true`.
32
+ * If you need to assign an Agent, be sure to retain the `keepAlive: true`
33
+ * option.
34
+ */
35
+ const fetch: typeof baseFetch = (url, init) => {
36
+ return baseFetch(url, {
37
+ agent: (parsedURL) => {
38
+ return parsedURL.protocol === "http:"
39
+ ? DEFAULT_HTTP_AGENT
40
+ : DEFAULT_HTTPS_AGENT;
41
+ },
42
+ ...init,
43
+ });
44
+ };
45
+
46
+ export default fetch;
@@ -1,5 +1,5 @@
1
1
  import * as t from "io-ts";
2
- import fetch from "node-fetch";
2
+ import fetch from "./fetch";
3
3
  import pLimit from "p-limit";
4
4
 
5
5
  import { decode } from "./decode";
@@ -1,5 +1,5 @@
1
1
  import * as t from "io-ts";
2
- import fetch from "node-fetch";
2
+ import fetch from "./fetch";
3
3
 
4
4
  import { decode } from "./decode";
5
5
 
@@ -1,5 +1,4 @@
1
1
  import * as t from "io-ts";
2
- import fetch from "node-fetch";
3
2
  import * as prismicCustomTypesClient from "@prismicio/custom-types-client";
4
3
  import { CustomType } from "@prismicio/types-internal/lib/customtypes";
5
4
  import {
@@ -17,12 +16,14 @@ import {
17
16
  import { DecodeError } from "../../lib/DecodeError";
18
17
  import { assertPluginsInitialized } from "../../lib/assertPluginsInitialized";
19
18
  import { decodeHookResult } from "../../lib/decodeHookResult";
19
+ import fetch from "../../lib/fetch";
20
20
 
21
- import { API_ENDPOINTS } from "../../constants/API_ENDPOINTS";
22
21
  import { OnlyHookErrors } from "../../types";
22
+ import { API_ENDPOINTS } from "../../constants/API_ENDPOINTS";
23
+ import { SLICE_MACHINE_USER_AGENT } from "../../constants/SLICE_MACHINE_USER_AGENT";
24
+ import { UnauthorizedError } from "../../errors";
23
25
 
24
26
  import { BaseManager } from "../BaseManager";
25
- import { UnauthorizedError } from "../../errors";
26
27
 
27
28
  type SliceMachineManagerReadCustomTypeLibraryReturnType = {
28
29
  ids: string[];
@@ -226,6 +227,7 @@ export class CustomTypesManager extends BaseManager {
226
227
  endpoint: API_ENDPOINTS.PrismicModels,
227
228
  repositoryName: sliceMachineConfig.repositoryName,
228
229
  token: authenticationToken,
230
+ userAgent: SLICE_MACHINE_USER_AGENT,
229
231
  fetch,
230
232
  });
231
233
 
@@ -310,6 +312,7 @@ export class CustomTypesManager extends BaseManager {
310
312
  endpoint: API_ENDPOINTS.PrismicModels,
311
313
  repositoryName: sliceMachineConfig.repositoryName,
312
314
  token: authenticationToken,
315
+ userAgent: SLICE_MACHINE_USER_AGENT,
313
316
  fetch,
314
317
  });
315
318
 
@@ -1,5 +1,5 @@
1
1
  import * as t from "io-ts";
2
- import fetch, { Response } from "node-fetch";
2
+ import fetch, { Response } from "../../lib/fetch";
3
3
  import { fold } from "fp-ts/Either";
4
4
 
5
5
  import { decode } from "../../lib/decode";
@@ -1,6 +1,6 @@
1
1
  import * as t from "io-ts";
2
2
  import { fileTypeFromBuffer } from "file-type";
3
- import fetch, { FormData, Blob, Response } from "node-fetch";
3
+ import fetch, { FormData, Blob, Response } from "../../lib/fetch";
4
4
  // puppeteer is lazy-loaded in captureSliceSimulatorScreenshot
5
5
  import type { BrowserContext, Viewport } from "puppeteer";
6
6
 
@@ -1,6 +1,6 @@
1
1
  import * as t from "io-ts";
2
2
  import { HookError } from "@slicemachine/plugin-kit";
3
- import fetch from "node-fetch";
3
+ import fetch from "../../lib/fetch";
4
4
 
5
5
  import { DecodeError } from "../../lib/DecodeError";
6
6
  import { assertPluginsInitialized } from "../../lib/assertPluginsInitialized";
@@ -1,7 +1,8 @@
1
1
  import * as t from "io-ts";
2
- import fetch from "node-fetch";
3
2
  import * as prismicCustomTypesClient from "@prismicio/custom-types-client";
4
3
  import { SharedSliceContent } from "@prismicio/types-internal/lib/content";
4
+ import { SliceComparator } from "@prismicio/types-internal/lib/customtypes/diff";
5
+ import { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
5
6
  import {
6
7
  CallHookReturnType,
7
8
  HookError,
@@ -19,17 +20,17 @@ import { DecodeError } from "../../lib/DecodeError";
19
20
  import { assertPluginsInitialized } from "../../lib/assertPluginsInitialized";
20
21
  import { bufferCodec } from "../../lib/bufferCodec";
21
22
  import { decodeHookResult } from "../../lib/decodeHookResult";
23
+ import { createContentDigest } from "../../lib/createContentDigest";
24
+ import { mockSlice } from "../../lib/mockSlice";
25
+ import fetch from "../../lib/fetch";
22
26
 
23
27
  import { OnlyHookErrors } from "../../types";
24
28
  import { DEFAULT_SLICE_SCREENSHOT_URL } from "../../constants/DEFAULT_SLICE_SCREENSHOT_URL";
29
+ import { SLICE_MACHINE_USER_AGENT } from "../../constants/SLICE_MACHINE_USER_AGENT";
25
30
  import { API_ENDPOINTS } from "../../constants/API_ENDPOINTS";
26
31
  import { UnauthenticatedError, UnauthorizedError } from "../../errors";
27
32
 
28
33
  import { BaseManager } from "../BaseManager";
29
- import { createContentDigest } from "../../lib/createContentDigest";
30
- import { mockSlice } from "../../lib/mockSlice";
31
- import { SliceComparator } from "@prismicio/types-internal/lib/customtypes/diff";
32
- import { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
33
34
 
34
35
  type SlicesManagerReadSliceLibraryReturnType = {
35
36
  sliceIDs: string[];
@@ -434,6 +435,7 @@ export class SlicesManager extends BaseManager {
434
435
  endpoint: API_ENDPOINTS.PrismicModels,
435
436
  repositoryName: sliceMachineConfig.repositoryName,
436
437
  token: authenticationToken,
438
+ userAgent: SLICE_MACHINE_USER_AGENT,
437
439
  fetch,
438
440
  });
439
441
 
@@ -630,6 +632,7 @@ export class SlicesManager extends BaseManager {
630
632
  endpoint: API_ENDPOINTS.PrismicModels,
631
633
  repositoryName: sliceMachineConfig.repositoryName,
632
634
  token: authenticationToken,
635
+ userAgent: SLICE_MACHINE_USER_AGENT,
633
636
  fetch,
634
637
  });
635
638