@koine/next 1.0.9 → 1.0.12

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 (86) hide show
  1. package/Analytics/AnalyticsGoogle.js +12 -16
  2. package/Auth/helpers.js +6 -5
  3. package/Auth/useLogin.js +17 -18
  4. package/Auth/useLoginUrl.js +5 -5
  5. package/Auth/useLogout.js +19 -19
  6. package/Favicon/Favicon.js +2 -1
  7. package/Forms/useForm.js +11 -13
  8. package/Forms/useSubmit.js +24 -19
  9. package/I18n/I18n.js +35 -14
  10. package/Img/Img.js +22 -20
  11. package/Link/Link.js +4 -2
  12. package/NextProgress/NextProgress.js +12 -9
  13. package/Seo/Seo.js +2 -2
  14. package/Seo/SeoDefaults.js +2 -2
  15. package/Seo/helpers.js +34 -30
  16. package/Theme/Theme.js +98 -88
  17. package/app/AppHead.js +1 -1
  18. package/app/css/AppMain.js +4 -2
  19. package/app/css/AppTheme.js +4 -2
  20. package/app/css/auth/index.js +3 -2
  21. package/app/css/index.js +3 -2
  22. package/app/em/AppMain.js +9 -7
  23. package/app/em/AppTheme.js +6 -5
  24. package/app/em/auth/index.js +3 -2
  25. package/app/em/index.js +3 -2
  26. package/app/sc/AppMain.js +9 -7
  27. package/app/sc/AppTheme.js +4 -2
  28. package/app/sc/auth/index.js +3 -2
  29. package/app/sc/index.js +3 -2
  30. package/config/index.js +62 -72
  31. package/document/Document.js +12 -5
  32. package/document/css/index.js +26 -12
  33. package/document/em/index.js +39 -48
  34. package/document/sc/index.js +44 -23
  35. package/node/Analytics/AnalyticsGoogle.js +17 -22
  36. package/node/Analytics/index.js +1 -1
  37. package/node/Auth/helpers.js +6 -5
  38. package/node/Auth/index.js +1 -1
  39. package/node/Auth/useLogin.js +23 -24
  40. package/node/Auth/useLoginUrl.js +8 -8
  41. package/node/Auth/useLogout.js +25 -25
  42. package/node/Favicon/Favicon.js +5 -5
  43. package/node/Favicon/index.js +1 -1
  44. package/node/Forms/index.js +1 -1
  45. package/node/Forms/useForm.js +15 -17
  46. package/node/Forms/useSubmit.js +25 -20
  47. package/node/Head/index.js +1 -1
  48. package/node/I18n/I18n.js +40 -20
  49. package/node/I18n/index.js +1 -1
  50. package/node/Img/Img.js +24 -23
  51. package/node/Img/index.js +1 -1
  52. package/node/Link/Link.js +7 -6
  53. package/node/Link/index.js +1 -1
  54. package/node/NextProgress/NextProgress.js +15 -12
  55. package/node/Seo/Seo.js +6 -6
  56. package/node/Seo/SeoDefaults.js +6 -6
  57. package/node/Seo/helpers.js +36 -32
  58. package/node/Seo/index.js +1 -1
  59. package/node/Theme/Theme.js +102 -93
  60. package/node/Theme/index.js +1 -1
  61. package/node/app/AppHead.js +4 -4
  62. package/node/app/css/AppMain.js +7 -6
  63. package/node/app/css/AppTheme.js +6 -4
  64. package/node/app/css/auth/index.js +9 -9
  65. package/node/app/css/index.js +8 -8
  66. package/node/app/em/AppMain.js +16 -14
  67. package/node/app/em/AppTheme.js +13 -13
  68. package/node/app/em/auth/index.js +9 -9
  69. package/node/app/em/index.js +8 -8
  70. package/node/app/index.js +1 -1
  71. package/node/app/sc/AppMain.js +16 -14
  72. package/node/app/sc/AppTheme.js +7 -5
  73. package/node/app/sc/auth/index.js +9 -9
  74. package/node/app/sc/index.js +8 -8
  75. package/node/config/index.js +62 -72
  76. package/node/document/Document.js +14 -9
  77. package/node/document/css/index.js +29 -17
  78. package/node/document/em/index.js +43 -54
  79. package/node/document/sc/index.js +48 -29
  80. package/node/index.js +1 -1
  81. package/node/utils/api.js +41 -32
  82. package/node/utils/emotion-cache.js +2 -2
  83. package/node/utils/index.js +7 -6
  84. package/package.json +28 -2
  85. package/utils/api.js +40 -31
  86. package/utils/index.js +7 -6
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Document = void 0;
4
- const tslib_1 = require("tslib");
5
- const jsx_runtime_1 = require("react/jsx-runtime");
6
- const document_1 = tslib_1.__importStar(require("next/document"));
7
- const react_1 = require("@koine/react");
8
- const create_instance_1 = tslib_1.__importDefault(require("@emotion/server/create-instance"));
9
- const emotion_cache_1 = require("../../utils/emotion-cache");
4
+ var tslib_1 = require("tslib");
5
+ var jsx_runtime_1 = require("react/jsx-runtime");
6
+ var document_1 = tslib_1.__importStar(require("next/document"));
7
+ var react_1 = require("@koine/react");
8
+ var create_instance_1 = tslib_1.__importDefault(require("@emotion/server/create-instance"));
9
+ var emotion_cache_1 = require("../../utils/emotion-cache");
10
10
  /**
11
11
  * Next Document wrapper for `emotion` based projects
12
12
  *
@@ -17,57 +17,46 @@ const emotion_cache_1 = require("../../utils/emotion-cache");
17
17
  * export { Document as default } from "@koine/next/document/em";
18
18
  * ```
19
19
  */
20
- class Document extends document_1.default {
21
- render() {
22
- const { locale, defaultLocale } = this.props.__NEXT_DATA__;
23
- return ((0, jsx_runtime_1.jsxs)(document_1.Html, { lang: locale || defaultLocale, className: "no-js", children: [(0, jsx_runtime_1.jsxs)(document_1.Head, { children: [(0, jsx_runtime_1.jsx)(react_1.Meta, {}), (0, jsx_runtime_1.jsx)(react_1.NoJs, {}), this.props.emotionStyleTags] }), (0, jsx_runtime_1.jsxs)("body", { children: [(0, jsx_runtime_1.jsx)(document_1.Main, {}), (0, jsx_runtime_1.jsx)(document_1.NextScript, {})] })] }));
20
+ var Document = /** @class */ (function (_super) {
21
+ tslib_1.__extends(Document, _super);
22
+ function Document() {
23
+ return _super !== null && _super.apply(this, arguments) || this;
24
24
  }
25
- }
25
+ Document.prototype.render = function () {
26
+ var _a = this.props.__NEXT_DATA__, locale = _a.locale, defaultLocale = _a.defaultLocale;
27
+ return ((0, jsx_runtime_1.jsxs)(document_1.Html, tslib_1.__assign({ lang: locale || defaultLocale, className: "no-js" }, { children: [(0, jsx_runtime_1.jsxs)(document_1.Head, { children: [(0, jsx_runtime_1.jsx)(react_1.Meta, {}), (0, jsx_runtime_1.jsx)(react_1.NoJs, {}), this.props.emotionStyleTags] }), (0, jsx_runtime_1.jsxs)("body", { children: [(0, jsx_runtime_1.jsx)(document_1.Main, {}), (0, jsx_runtime_1.jsx)(document_1.NextScript, {})] })] })));
28
+ };
29
+ return Document;
30
+ }(document_1.default));
26
31
  exports.Document = Document;
27
32
  // `getInitialProps` belongs to `_document` (instead of `_app`),
28
33
  // it's compatible with static-site generation (SSG).
29
- Document.getInitialProps = async (ctx) => {
30
- // Resolution order
31
- //
32
- // On the server:
33
- // 1. app.getInitialProps
34
- // 2. page.getInitialProps
35
- // 3. document.getInitialProps
36
- // 4. app.render
37
- // 5. page.render
38
- // 6. document.render
39
- //
40
- // On the server with error:
41
- // 1. document.getInitialProps
42
- // 2. app.render
43
- // 3. page.render
44
- // 4. document.render
45
- //
46
- // On the client
47
- // 1. app.getInitialProps
48
- // 2. page.getInitialProps
49
- // 3. app.render
50
- // 4. page.render
51
- const originalRenderPage = ctx.renderPage;
52
- // You can consider sharing the same emotion cache between all the SSR requests to speed up performance.
53
- // However, be aware that it can have global side effects.
54
- const cache = (0, emotion_cache_1.createEmotionCache)();
55
- const { extractCriticalToChunks } = (0, create_instance_1.default)(cache);
56
- ctx.renderPage = () => originalRenderPage({
57
- enhanceApp: (App) => function EnhanceApp(props) {
58
- return (0, jsx_runtime_1.jsx)(App, { emotionCache: cache, ...props });
59
- },
34
+ Document.getInitialProps = function (ctx) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
35
+ var originalRenderPage, cache, extractCriticalToChunks, initialProps, emotionStyles, emotionStyleTags;
36
+ return tslib_1.__generator(this, function (_a) {
37
+ switch (_a.label) {
38
+ case 0:
39
+ originalRenderPage = ctx.renderPage;
40
+ cache = (0, emotion_cache_1.createEmotionCache)();
41
+ extractCriticalToChunks = (0, create_instance_1.default)(cache).extractCriticalToChunks;
42
+ ctx.renderPage = function () {
43
+ return originalRenderPage({
44
+ enhanceApp: function (App) {
45
+ return function EnhanceApp(props) {
46
+ return (0, jsx_runtime_1.jsx)(App, tslib_1.__assign({ emotionCache: cache }, props));
47
+ };
48
+ },
49
+ });
50
+ };
51
+ return [4 /*yield*/, Document.getInitialProps(ctx)];
52
+ case 1:
53
+ initialProps = _a.sent();
54
+ emotionStyles = extractCriticalToChunks(initialProps.html);
55
+ emotionStyleTags = emotionStyles.styles.map(function (style) { return ((0, jsx_runtime_1.jsx)("style", { "data-emotion": "".concat(style.key, " ").concat(style.ids.join(" ")),
56
+ // eslint-disable-next-line react/no-danger
57
+ dangerouslySetInnerHTML: { __html: style.css } }, style.key)); });
58
+ return [2 /*return*/, tslib_1.__assign(tslib_1.__assign({}, initialProps), { emotionStyleTags: emotionStyleTags })];
59
+ }
60
60
  });
61
- const initialProps = await Document.getInitialProps(ctx);
62
- // This is important. It prevents emotion to render invalid HTML.
63
- // See https://github.com/mui-org/material-ui/issues/26561#issuecomment-855286153
64
- const emotionStyles = extractCriticalToChunks(initialProps.html);
65
- const emotionStyleTags = emotionStyles.styles.map((style) => ((0, jsx_runtime_1.jsx)("style", { "data-emotion": `${style.key} ${style.ids.join(" ")}`,
66
- // eslint-disable-next-line react/no-danger
67
- dangerouslySetInnerHTML: { __html: style.css } }, style.key)));
68
- return {
69
- ...initialProps,
70
- emotionStyleTags,
71
- };
72
- };
61
+ }); };
73
62
  exports.default = Document;
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Document = void 0;
4
- const tslib_1 = require("tslib");
5
- const jsx_runtime_1 = require("react/jsx-runtime");
6
- const react_1 = tslib_1.__importDefault(require("react"));
4
+ var tslib_1 = require("tslib");
5
+ var jsx_runtime_1 = require("react/jsx-runtime");
6
+ var react_1 = tslib_1.__importDefault(require("react"));
7
7
  /* ? eslint-disable @next/next/no-document-import-in-page */
8
- const document_1 = tslib_1.__importStar(require("next/document"));
9
- const react_2 = require("@koine/react");
10
- const styled_components_1 = require("styled-components");
8
+ var document_1 = tslib_1.__importStar(require("next/document"));
9
+ var react_2 = require("@koine/react");
10
+ var styled_components_1 = require("styled-components");
11
11
  /**
12
12
  * Next Document wrapper for `styled-components` based projects
13
13
  *
@@ -21,29 +21,48 @@ const styled_components_1 = require("styled-components");
21
21
  * export { Document as default } from "@koine/next/document/sc";
22
22
  * ```
23
23
  */
24
- class Document extends document_1.default {
25
- static async getInitialProps(ctx) {
26
- const sheet = new styled_components_1.ServerStyleSheet();
27
- const originalRenderPage = ctx.renderPage;
28
- try {
29
- ctx.renderPage = () => originalRenderPage({
30
- enhanceApp: (App) => (props) => sheet.collectStyles((0, jsx_runtime_1.jsx)(App, { ...props })),
31
- });
32
- const initialProps = await document_1.default.getInitialProps(ctx);
33
- return {
34
- ...initialProps,
35
- // @ts-expect-error FIXME: have they changed type?
36
- styles: ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [initialProps.styles, sheet.getStyleElement()] })),
37
- };
38
- }
39
- finally {
40
- sheet.seal();
41
- }
42
- }
43
- render() {
44
- const { locale, defaultLocale } = this.props.__NEXT_DATA__;
45
- return ((0, jsx_runtime_1.jsxs)(document_1.Html, { lang: locale || defaultLocale, className: "no-js", children: [(0, jsx_runtime_1.jsxs)(document_1.Head, { children: [(0, jsx_runtime_1.jsx)(react_2.Meta, {}), (0, jsx_runtime_1.jsx)(react_2.NoJs, {})] }), (0, jsx_runtime_1.jsxs)("body", { children: [(0, jsx_runtime_1.jsx)(document_1.Main, {}), (0, jsx_runtime_1.jsx)(document_1.NextScript, {})] })] }));
24
+ var Document = /** @class */ (function (_super) {
25
+ tslib_1.__extends(Document, _super);
26
+ function Document() {
27
+ return _super !== null && _super.apply(this, arguments) || this;
46
28
  }
47
- }
29
+ Document.getInitialProps = function (ctx) {
30
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
31
+ var sheet, originalRenderPage, initialProps;
32
+ return tslib_1.__generator(this, function (_a) {
33
+ switch (_a.label) {
34
+ case 0:
35
+ sheet = new styled_components_1.ServerStyleSheet();
36
+ originalRenderPage = ctx.renderPage;
37
+ _a.label = 1;
38
+ case 1:
39
+ _a.trys.push([1, , 3, 4]);
40
+ ctx.renderPage = function () {
41
+ return originalRenderPage({
42
+ enhanceApp: function (App) { return function (props) {
43
+ return sheet.collectStyles((0, jsx_runtime_1.jsx)(App, tslib_1.__assign({}, props)));
44
+ }; },
45
+ });
46
+ };
47
+ return [4 /*yield*/, document_1.default.getInitialProps(ctx)];
48
+ case 2:
49
+ initialProps = _a.sent();
50
+ return [2 /*return*/, tslib_1.__assign(tslib_1.__assign({}, initialProps), {
51
+ // @ts-expect-error FIXME: have they changed type?
52
+ styles: ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [initialProps.styles, sheet.getStyleElement()] })) })];
53
+ case 3:
54
+ sheet.seal();
55
+ return [7 /*endfinally*/];
56
+ case 4: return [2 /*return*/];
57
+ }
58
+ });
59
+ });
60
+ };
61
+ Document.prototype.render = function () {
62
+ var _a = this.props.__NEXT_DATA__, locale = _a.locale, defaultLocale = _a.defaultLocale;
63
+ return ((0, jsx_runtime_1.jsxs)(document_1.Html, tslib_1.__assign({ lang: locale || defaultLocale, className: "no-js" }, { children: [(0, jsx_runtime_1.jsxs)(document_1.Head, { children: [(0, jsx_runtime_1.jsx)(react_2.Meta, {}), (0, jsx_runtime_1.jsx)(react_2.NoJs, {})] }), (0, jsx_runtime_1.jsxs)("body", { children: [(0, jsx_runtime_1.jsx)(document_1.Main, {}), (0, jsx_runtime_1.jsx)(document_1.NextScript, {})] })] })));
64
+ };
65
+ return Document;
66
+ }(document_1.default));
48
67
  exports.Document = Document;
49
68
  exports.default = Document;
package/node/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
3
+ var tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./Analytics"), exports);
5
5
  tslib_1.__exportStar(require("./Auth"), exports);
6
6
  tslib_1.__exportStar(require("./Favicon"), exports);
package/node/utils/api.js CHANGED
@@ -1,38 +1,47 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.api = void 0;
4
- const utils_1 = require("@koine/utils");
5
- exports.api = ["get", "post", "put", "patch", "delete"].reduce((api, method) => {
6
- api[method] = async (endpoint, options = {}) => {
7
- const { json = {}, params, headers = {}, timeout = 10000 } = options;
8
- const requestInit = {
9
- method: method.toUpperCase(),
10
- headers: {
11
- "content-type": "application/json",
12
- ...headers,
13
- },
14
- };
15
- const timeoutNumber = Number(timeout);
16
- let controller;
17
- let timeoutId;
18
- let url = `/api/${endpoint.replace(/^\/*/, "")}`;
19
- if (method !== "get") {
20
- requestInit.body = JSON.stringify(json);
21
- }
22
- if (timeoutNumber > 0) {
23
- controller = new AbortController();
24
- timeoutId = setTimeout(() => controller.abort(), timeoutNumber);
25
- requestInit.signal = controller.signal;
26
- }
27
- if (params) {
28
- url += (0, utils_1.buildUrlQueryString)(params);
29
- }
30
- const response = await fetch(url, requestInit);
31
- if (timeoutId) {
32
- clearTimeout(timeoutId);
33
- }
34
- const result = (await response.json());
35
- return result;
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
+ });
36
45
  };
37
46
  return api;
38
47
  }, {});
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createEmotionCache = void 0;
4
- const tslib_1 = require("tslib");
5
- const cache_1 = tslib_1.__importDefault(require("@emotion/cache"));
4
+ var tslib_1 = require("tslib");
5
+ var cache_1 = tslib_1.__importDefault(require("@emotion/cache"));
6
6
  /**
7
7
  * prepend: true moves MUI styles to the top of the <head> so they're loaded first.
8
8
  * It allows developers to easily override MUI styles with other styling solutions, like CSS modules.
@@ -1,8 +1,8 @@
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
- const tslib_1 = require("tslib");
5
- const utils_1 = require("@koine/utils");
4
+ var tslib_1 = require("tslib");
5
+ var utils_1 = require("@koine/utils");
6
6
  tslib_1.__exportStar(require("./api"), exports);
7
7
  exports.ONE_HOUR = 3600;
8
8
  exports.ONE_DAY = 84000;
@@ -12,8 +12,9 @@ exports.ONE_DAY = 84000;
12
12
  * - It uses the `NEXT_PUBLIC_APP_URL` env variable
13
13
  * - It removes the trailing slashes
14
14
  */
15
- function getSiteUrl(path = "") {
16
- return (0, utils_1.normaliseUrl)(`${process.env["NEXT_PUBLIC_APP_URL"]}/${path}`);
15
+ function getSiteUrl(path) {
16
+ if (path === void 0) { path = ""; }
17
+ return (0, utils_1.normaliseUrl)("".concat(process.env["NEXT_PUBLIC_APP_URL"], "/").concat(path));
17
18
  }
18
19
  exports.getSiteUrl = getSiteUrl;
19
20
  /**
@@ -25,8 +26,8 @@ exports.getSiteUrl = getSiteUrl;
25
26
  * @see https://github.com/vercel/next.js/blob/canary/examples/with-dynamic-import/pages/index.js
26
27
  */
27
28
  function load(component, milliseconds) {
28
- return new Promise((resolve) => {
29
- setTimeout(() => resolve(component), milliseconds);
29
+ return new Promise(function (resolve) {
30
+ setTimeout(function () { return resolve(component); }, milliseconds);
30
31
  });
31
32
  }
32
33
  exports.load = load;
package/package.json CHANGED
@@ -1,8 +1,34 @@
1
1
  {
2
- "version": "1.0.9",
3
2
  "name": "@koine/next",
3
+ "version": "1.0.12",
4
4
  "sideEffects": false,
5
5
  "main": "./node/index.js",
6
6
  "typings": "./index.d.ts",
7
- "module": "./index.js"
7
+ "dependencies": {
8
+ "react": "^16.8 || ^17 || ^18",
9
+ "react-dom": "^16.8 || ^17 || ^18",
10
+ "next": "^12.1.6",
11
+ "framer-motion": "^6.3.3",
12
+ "styled-components": "^5.3.5",
13
+ "@mui/base": "^5.0.0-alpha.81",
14
+ "react-icons": "^4.3.1",
15
+ "date-fns": "^2.28.0",
16
+ "react-swipeable": "^7.0.0",
17
+ "@tiptap/react": "^2.0.0-beta.109",
18
+ "@tiptap/starter-kit": "^2.0.0-beta.184",
19
+ "yup": "^0.32.11",
20
+ "react-hook-form": "^7.31.1",
21
+ "type-fest": "^2.12.2",
22
+ "tslib": "^2.4.0",
23
+ "next-auth": "^4.3.4",
24
+ "@mui/material": "^5.8.0",
25
+ "@emotion/react": "^11.9.0",
26
+ "@emotion/server": "^11.4.0",
27
+ "@hookform/resolvers": "^2.8.10",
28
+ "next-translate": "^1.4.0",
29
+ "next-seo": "^5.4.0"
30
+ },
31
+ "peerDependencies": {},
32
+ "module": "./index.js",
33
+ "types": "./index.d.ts"
8
34
  }
package/utils/api.js CHANGED
@@ -1,35 +1,44 @@
1
+ import { __assign, __awaiter, __generator } from "tslib";
1
2
  import { buildUrlQueryString } from "@koine/utils";
2
- export const api = ["get", "post", "put", "patch", "delete"].reduce((api, method) => {
3
- api[method] = async (endpoint, options = {}) => {
4
- const { json = {}, params, headers = {}, timeout = 10000 } = options;
5
- const requestInit = {
6
- method: method.toUpperCase(),
7
- headers: {
8
- "content-type": "application/json",
9
- ...headers,
10
- },
11
- };
12
- const timeoutNumber = Number(timeout);
13
- let controller;
14
- let timeoutId;
15
- let url = `/api/${endpoint.replace(/^\/*/, "")}`;
16
- if (method !== "get") {
17
- requestInit.body = JSON.stringify(json);
18
- }
19
- if (timeoutNumber > 0) {
20
- controller = new AbortController();
21
- timeoutId = setTimeout(() => controller.abort(), timeoutNumber);
22
- requestInit.signal = controller.signal;
23
- }
24
- if (params) {
25
- url += buildUrlQueryString(params);
26
- }
27
- const response = await fetch(url, requestInit);
28
- if (timeoutId) {
29
- clearTimeout(timeoutId);
30
- }
31
- const result = (await response.json());
32
- return result;
3
+ export var api = ["get", "post", "put", "patch", "delete"].reduce(function (api, method) {
4
+ api[method] = function (endpoint, options) {
5
+ if (options === void 0) { options = {}; }
6
+ return __awaiter(void 0, void 0, void 0, function () {
7
+ var _a, json, params, _b, headers, _c, timeout, requestInit, timeoutNumber, controller, timeoutId, url, response, result;
8
+ return __generator(this, function (_d) {
9
+ switch (_d.label) {
10
+ case 0:
11
+ _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;
12
+ requestInit = {
13
+ method: method.toUpperCase(),
14
+ headers: __assign({ "content-type": "application/json" }, headers),
15
+ };
16
+ timeoutNumber = Number(timeout);
17
+ url = "/api/".concat(endpoint.replace(/^\/*/, ""));
18
+ if (method !== "get") {
19
+ requestInit.body = JSON.stringify(json);
20
+ }
21
+ if (timeoutNumber > 0) {
22
+ controller = new AbortController();
23
+ timeoutId = setTimeout(function () { return controller.abort(); }, timeoutNumber);
24
+ requestInit.signal = controller.signal;
25
+ }
26
+ if (params) {
27
+ url += buildUrlQueryString(params);
28
+ }
29
+ return [4 /*yield*/, fetch(url, requestInit)];
30
+ case 1:
31
+ response = _d.sent();
32
+ if (timeoutId) {
33
+ clearTimeout(timeoutId);
34
+ }
35
+ return [4 /*yield*/, response.json()];
36
+ case 2:
37
+ result = (_d.sent());
38
+ return [2 /*return*/, result];
39
+ }
40
+ });
41
+ });
33
42
  };
34
43
  return api;
35
44
  }, {});
package/utils/index.js CHANGED
@@ -1,15 +1,16 @@
1
1
  import { normaliseUrl } from "@koine/utils";
2
2
  export * from "./api";
3
- export const ONE_HOUR = 3600;
4
- export const ONE_DAY = 84000;
3
+ export var ONE_HOUR = 3600;
4
+ export var ONE_DAY = 84000;
5
5
  /**
6
6
  * Get site absolute url with the given path
7
7
  *
8
8
  * - It uses the `NEXT_PUBLIC_APP_URL` env variable
9
9
  * - It removes the trailing slashes
10
10
  */
11
- export function getSiteUrl(path = "") {
12
- return normaliseUrl(`${process.env["NEXT_PUBLIC_APP_URL"]}/${path}`);
11
+ export function getSiteUrl(path) {
12
+ if (path === void 0) { path = ""; }
13
+ return normaliseUrl("".concat(process.env["NEXT_PUBLIC_APP_URL"], "/").concat(path));
13
14
  }
14
15
  /**
15
16
  * Utility to load a component with an optional pre-determined delay.
@@ -20,7 +21,7 @@ export function getSiteUrl(path = "") {
20
21
  * @see https://github.com/vercel/next.js/blob/canary/examples/with-dynamic-import/pages/index.js
21
22
  */
22
23
  export function load(component, milliseconds) {
23
- return new Promise((resolve) => {
24
- setTimeout(() => resolve(component), milliseconds);
24
+ return new Promise(function (resolve) {
25
+ setTimeout(function () { return resolve(component); }, milliseconds);
25
26
  });
26
27
  }