@koine/next 1.0.12 → 1.0.15

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/Forms/index.d.ts CHANGED
@@ -1,2 +1 @@
1
1
  export * from "./useForm";
2
- export * from "./useSubmit";
package/Forms/index.js CHANGED
@@ -1,2 +1 @@
1
1
  export * from "./useForm";
2
- export * from "./useSubmit";
package/config/index.d.ts CHANGED
@@ -1,5 +1,18 @@
1
1
  import type { NextConfig } from "next";
2
2
  import type { Redirect, Rewrite } from "next/dist/lib/load-custom-routes";
3
+ /**
4
+ * Transform to path any absolute or relative URL
5
+ *
6
+ * Useful when setting up `rewrites` and `redirects` especally in a [multi-zones
7
+ * setup](https://nextjs.org/docs/advanced-features/multi-zones).
8
+ *
9
+ * From a path like `http://localhost/some//malformed/path///` it returns `/some/malformed/path`
10
+ *
11
+ * - just get the pathname form an absolute URL (if that is given)
12
+ * - Removes subsequent slashes
13
+ * - Removing initial and ending slashes
14
+ */
15
+ export declare function toPath(urlOrPathname?: string): string;
3
16
  /**
4
17
  * Normalise pathname
5
18
  *
package/config/index.js CHANGED
@@ -1,4 +1,28 @@
1
1
  import { __assign, __awaiter, __generator, __rest } from "tslib";
2
+ /**
3
+ * Transform to path any absolute or relative URL
4
+ *
5
+ * Useful when setting up `rewrites` and `redirects` especally in a [multi-zones
6
+ * setup](https://nextjs.org/docs/advanced-features/multi-zones).
7
+ *
8
+ * From a path like `http://localhost/some//malformed/path///` it returns `/some/malformed/path`
9
+ *
10
+ * - just get the pathname form an absolute URL (if that is given)
11
+ * - Removes subsequent slashes
12
+ * - Removing initial and ending slashes
13
+ */
14
+ export function toPath(urlOrPathname) {
15
+ if (urlOrPathname === void 0) { urlOrPathname = ""; }
16
+ var pathname = "";
17
+ try {
18
+ var parsed = new URL(urlOrPathname);
19
+ pathname = parsed.pathname;
20
+ }
21
+ catch (e) {
22
+ pathname = urlOrPathname;
23
+ }
24
+ return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
25
+ }
2
26
  /**
3
27
  * Normalise pathname
4
28
  *
@@ -118,7 +142,9 @@ export function withKoine(_a) {
118
142
  // @see https://github.com/vercel/next.js/discussions/30174#discussion-3643870
119
143
  scrollRestoration: true }, (nextConfig.experimental || {})), {
120
144
  // @see https://nextjs.org/docs/advanced-features/compiler#modularize-imports
121
- modularizeImports: __assign({}, (((_b = nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.experimental) === null || _b === void 0 ? void 0 : _b.modularizeImports) || {})) }) }, nextConfig);
145
+ modularizeImports: __assign({}, (((_b = nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.experimental) === null || _b === void 0 ? void 0 : _b.modularizeImports) || {})) }),
146
+ // @see https://github.com/vercel/next.js/issues/7322#issuecomment-887330111
147
+ reactStrictMode: true }, nextConfig);
122
148
  if (svg) {
123
149
  if (nx) {
124
150
  // @see https://github.com/gregberge/svgr
@@ -2,4 +2,3 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./useForm"), exports);
5
- tslib_1.__exportStar(require("./useSubmit"), exports);
package/node/Head/Head.js CHANGED
@@ -1,7 +1,4 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Head = void 0;
7
4
  var head_1 = require("next/head");
@@ -1,7 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withKoine = exports.getRewrites = exports.getRedirects = exports.getPathRewrite = exports.getPathRedirect = exports.encodePathname = exports.normaliseUrlPathname = void 0;
3
+ exports.withKoine = exports.getRewrites = exports.getRedirects = exports.getPathRewrite = exports.getPathRedirect = exports.encodePathname = exports.normaliseUrlPathname = exports.toPath = void 0;
4
4
  var tslib_1 = require("tslib");
5
+ /**
6
+ * Transform to path any absolute or relative URL
7
+ *
8
+ * Useful when setting up `rewrites` and `redirects` especally in a [multi-zones
9
+ * setup](https://nextjs.org/docs/advanced-features/multi-zones).
10
+ *
11
+ * From a path like `http://localhost/some//malformed/path///` it returns `/some/malformed/path`
12
+ *
13
+ * - just get the pathname form an absolute URL (if that is given)
14
+ * - Removes subsequent slashes
15
+ * - Removing initial and ending slashes
16
+ */
17
+ function toPath(urlOrPathname) {
18
+ if (urlOrPathname === void 0) { urlOrPathname = ""; }
19
+ var pathname = "";
20
+ try {
21
+ var parsed = new URL(urlOrPathname);
22
+ pathname = parsed.pathname;
23
+ }
24
+ catch (e) {
25
+ pathname = urlOrPathname;
26
+ }
27
+ return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
28
+ }
29
+ exports.toPath = toPath;
5
30
  /**
6
31
  * Normalise pathname
7
32
  *
@@ -127,7 +152,9 @@ function withKoine(_a) {
127
152
  // @see https://github.com/vercel/next.js/discussions/30174#discussion-3643870
128
153
  scrollRestoration: true }, (nextConfig.experimental || {})), {
129
154
  // @see https://nextjs.org/docs/advanced-features/compiler#modularize-imports
130
- modularizeImports: tslib_1.__assign({}, (((_b = nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.experimental) === null || _b === void 0 ? void 0 : _b.modularizeImports) || {})) }) }, nextConfig);
155
+ modularizeImports: tslib_1.__assign({}, (((_b = nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.experimental) === null || _b === void 0 ? void 0 : _b.modularizeImports) || {})) }),
156
+ // @see https://github.com/vercel/next.js/issues/7322#issuecomment-887330111
157
+ reactStrictMode: true }, nextConfig);
131
158
  if (svg) {
132
159
  if (nx) {
133
160
  // @see https://github.com/gregberge/svgr
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.load = exports.getSiteUrl = exports.ONE_DAY = exports.ONE_HOUR = void 0;
4
- var tslib_1 = require("tslib");
5
4
  var utils_1 = require("@koine/utils");
6
- tslib_1.__exportStar(require("./api"), exports);
7
5
  exports.ONE_HOUR = 3600;
8
6
  exports.ONE_DAY = 84000;
9
7
  /**
package/package.json CHANGED
@@ -1,27 +1,27 @@
1
1
  {
2
2
  "name": "@koine/next",
3
- "version": "1.0.12",
4
3
  "sideEffects": false,
5
4
  "main": "./node/index.js",
6
5
  "typings": "./index.d.ts",
7
6
  "dependencies": {
8
7
  "react": "^16.8 || ^17 || ^18",
9
- "react-dom": "^16.8 || ^17 || ^18",
10
8
  "next": "^12.1.6",
11
- "framer-motion": "^6.3.3",
9
+ "@koine/utils": "1.0.15",
10
+ "framer-motion": "^6.3.4",
11
+ "@koine/react": "1.0.15",
12
12
  "styled-components": "^5.3.5",
13
- "@mui/base": "^5.0.0-alpha.81",
13
+ "@mui/base": "^5.0.0-alpha.82",
14
14
  "react-icons": "^4.3.1",
15
15
  "date-fns": "^2.28.0",
16
16
  "react-swipeable": "^7.0.0",
17
17
  "@tiptap/react": "^2.0.0-beta.109",
18
- "@tiptap/starter-kit": "^2.0.0-beta.184",
18
+ "@tiptap/starter-kit": "^2.0.0-beta.185",
19
19
  "yup": "^0.32.11",
20
- "react-hook-form": "^7.31.1",
21
- "type-fest": "^2.12.2",
20
+ "react-hook-form": "^7.31.2",
21
+ "type-fest": "^2.13.0",
22
22
  "tslib": "^2.4.0",
23
23
  "next-auth": "^4.3.4",
24
- "@mui/material": "^5.8.0",
24
+ "@mui/material": "^5.8.1",
25
25
  "@emotion/react": "^11.9.0",
26
26
  "@emotion/server": "^11.4.0",
27
27
  "@hookform/resolvers": "^2.8.10",
@@ -29,6 +29,7 @@
29
29
  "next-seo": "^5.4.0"
30
30
  },
31
31
  "peerDependencies": {},
32
+ "version": "1.0.15",
32
33
  "module": "./index.js",
33
34
  "types": "./index.d.ts"
34
35
  }
package/utils/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export * from "./api";
2
1
  export declare const ONE_HOUR = 3600;
3
2
  export declare const ONE_DAY = 84000;
4
3
  /**
package/utils/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { normaliseUrl } from "@koine/utils";
2
- export * from "./api";
3
2
  export var ONE_HOUR = 3600;
4
3
  export var ONE_DAY = 84000;
5
4
  /**
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useSubmit = void 0;
4
- var tslib_1 = require("tslib");
5
- var react_1 = require("@koine/react");
6
- var api_1 = require("../utils/api");
7
- function useSubmit(url, transformData) {
8
- var _this = this;
9
- var _a = (0, react_1.useAsyncFn)(function (json) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
10
- var response;
11
- return tslib_1.__generator(this, function (_a) {
12
- switch (_a.label) {
13
- case 0:
14
- if (transformData)
15
- json = transformData(json);
16
- return [4 /*yield*/, api_1.api.post(url, {
17
- json: json,
18
- })];
19
- case 1:
20
- response = _a.sent();
21
- if (process.env["NODE_ENV"] !== "production") {
22
- console.log("[@koine/next] useSubmit response", response);
23
- }
24
- return [2 /*return*/, response];
25
- }
26
- });
27
- }); }, [url, transformData]), state = _a[0], submit = _a[1];
28
- var loading = state.loading, error = state.error, value = state.value;
29
- var fail = !loading && (!!error || (value === null || value === void 0 ? void 0 : value.fail));
30
- return tslib_1.__assign(tslib_1.__assign({ submit: submit, loading: loading }, (value || {})), { fail: fail });
31
- }
32
- exports.useSubmit = useSubmit;
package/node/utils/api.js DELETED
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.api = void 0;
4
- var tslib_1 = require("tslib");
5
- var utils_1 = require("@koine/utils");
6
- exports.api = ["get", "post", "put", "patch", "delete"].reduce(function (api, method) {
7
- api[method] = function (endpoint, options) {
8
- if (options === void 0) { options = {}; }
9
- return tslib_1.__awaiter(void 0, void 0, void 0, function () {
10
- var _a, json, params, _b, headers, _c, timeout, requestInit, timeoutNumber, controller, timeoutId, url, response, result;
11
- return tslib_1.__generator(this, function (_d) {
12
- switch (_d.label) {
13
- case 0:
14
- _a = options.json, json = _a === void 0 ? {} : _a, params = options.params, _b = options.headers, headers = _b === void 0 ? {} : _b, _c = options.timeout, timeout = _c === void 0 ? 10000 : _c;
15
- requestInit = {
16
- method: method.toUpperCase(),
17
- headers: tslib_1.__assign({ "content-type": "application/json" }, headers),
18
- };
19
- timeoutNumber = Number(timeout);
20
- url = "/api/".concat(endpoint.replace(/^\/*/, ""));
21
- if (method !== "get") {
22
- requestInit.body = JSON.stringify(json);
23
- }
24
- if (timeoutNumber > 0) {
25
- controller = new AbortController();
26
- timeoutId = setTimeout(function () { return controller.abort(); }, timeoutNumber);
27
- requestInit.signal = controller.signal;
28
- }
29
- if (params) {
30
- url += (0, utils_1.buildUrlQueryString)(params);
31
- }
32
- return [4 /*yield*/, fetch(url, requestInit)];
33
- case 1:
34
- response = _d.sent();
35
- if (timeoutId) {
36
- clearTimeout(timeoutId);
37
- }
38
- return [4 /*yield*/, response.json()];
39
- case 2:
40
- result = (_d.sent());
41
- return [2 /*return*/, result];
42
- }
43
- });
44
- });
45
- };
46
- return api;
47
- }, {});