@forsakringskassan/devindex-menu 1.0.0 → 2.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.
package/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2025 Försäkringskassan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # @forsakringskassan/devindex-menu
2
2
 
3
+ ![Closed](docs/closed.png)
4
+ ![Opened](docs/opened.png)
5
+
3
6
  > npm install --save-dev @forsakringskassan/devindex-menu
4
7
 
5
8
  Menu for development mode that can be used with advantage together with [fapimock-express](https://www.npmjs.com/package/@forsakringskassan/apimock-express).
package/dist/cjs/menu.js CHANGED
@@ -17,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
- // src/menu.js
20
+ // src/menu.ts
21
21
  var menu_exports = {};
22
22
  __export(menu_exports, {
23
23
  default: () => menu_default
@@ -112,7 +112,15 @@ var style_default = `.secret-menu {
112
112
  width: 100%;
113
113
  }`;
114
114
 
115
- // src/menu.js
115
+ // src/menu.ts
116
+ function evaluateMock(mock) {
117
+ if (typeof mock === "function") {
118
+ const req = {};
119
+ return mock(req);
120
+ } else {
121
+ return mock;
122
+ }
123
+ }
116
124
  function generateOptionMarkupForSelect(setting) {
117
125
  const reload = setting.reloadOnChange !== void 0 ? setting.reloadOnChange : true;
118
126
  const description = setting.description ? `<p>${setting.description}</p>` : "";
@@ -154,15 +162,20 @@ function isMock(userSettingsOrMock) {
154
162
  return "responses" in userSettingsOrMock || "defaultResponse" in userSettingsOrMock;
155
163
  }
156
164
  function getFirstCookie(matcher) {
157
- const entries = Object.entries(matcher.request.cookies);
165
+ const entries = Object.entries(matcher.request.cookies || {});
158
166
  const [key, value] = entries[0];
159
167
  return { key, value };
160
168
  }
161
169
  function entryFromMock(mock) {
170
+ if (!mock.responses || mock.responses.length === 0) {
171
+ throw new Error(
172
+ "Mock must have at least one response to generate entry from."
173
+ );
174
+ }
162
175
  const { key } = getFirstCookie(mock.responses[0]);
163
- const title = mock.meta.title ?? key;
176
+ const title = mock.meta?.title ?? key;
164
177
  const defaultEntry = {
165
- title: mock.defaultResponse?.label ?? "Default",
178
+ title: evaluateMock(mock.defaultResponse).label ?? "Default",
166
179
  value: "default"
167
180
  };
168
181
  return {
@@ -174,7 +187,7 @@ function entryFromMock(mock) {
174
187
  ...mock.responses.map((entry) => {
175
188
  const { value } = getFirstCookie(entry);
176
189
  return {
177
- title: entry.response.label ?? value,
190
+ title: evaluateMock(entry.response).label ?? value,
178
191
  value
179
192
  };
180
193
  })
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
7
  var __export = (target, all) => {
7
8
  for (var name in all)
8
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,8 +17,9 @@ var __copyProps = (to, from, except, desc) => {
16
17
  return to;
17
18
  };
18
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
19
21
 
20
- // src/pageobjects/pageobjects.ts
22
+ // src/pageobjects.ts
21
23
  var pageobjects_exports = {};
22
24
  __export(pageobjects_exports, {
23
25
  DevindexPageObject: () => DevindexPageObject
@@ -27,6 +29,8 @@ module.exports = __toCommonJS(pageobjects_exports);
27
29
  // src/pageobjects/Devindex.pageobject.ts
28
30
  var DevindexPageObject = class {
29
31
  constructor() {
32
+ __publicField(this, "selector");
33
+ __publicField(this, "el");
30
34
  this.selector = ".secret-menu";
31
35
  this.el = () => cy.get(this.selector);
32
36
  }
@@ -36,4 +40,12 @@ var DevindexPageObject = class {
36
40
  valj(id, value) {
37
41
  cy.get(`#${id}`).select(value);
38
42
  }
43
+ /**
44
+ * Inputs text into a text field.
45
+ * @param name - The name of the text field.
46
+ * @param value - The text to input.
47
+ */
48
+ textField(name, value) {
49
+ cy.get(`input[name="${name}"]`).clear().type(value);
50
+ }
39
51
  };
package/dist/esm/menu.js CHANGED
@@ -86,7 +86,15 @@ var style_default = `.secret-menu {
86
86
  width: 100%;
87
87
  }`;
88
88
 
89
- // src/menu.js
89
+ // src/menu.ts
90
+ function evaluateMock(mock) {
91
+ if (typeof mock === "function") {
92
+ const req = {};
93
+ return mock(req);
94
+ } else {
95
+ return mock;
96
+ }
97
+ }
90
98
  function generateOptionMarkupForSelect(setting) {
91
99
  const reload = setting.reloadOnChange !== void 0 ? setting.reloadOnChange : true;
92
100
  const description = setting.description ? `<p>${setting.description}</p>` : "";
@@ -128,15 +136,20 @@ function isMock(userSettingsOrMock) {
128
136
  return "responses" in userSettingsOrMock || "defaultResponse" in userSettingsOrMock;
129
137
  }
130
138
  function getFirstCookie(matcher) {
131
- const entries = Object.entries(matcher.request.cookies);
139
+ const entries = Object.entries(matcher.request.cookies || {});
132
140
  const [key, value] = entries[0];
133
141
  return { key, value };
134
142
  }
135
143
  function entryFromMock(mock) {
144
+ if (!mock.responses || mock.responses.length === 0) {
145
+ throw new Error(
146
+ "Mock must have at least one response to generate entry from."
147
+ );
148
+ }
136
149
  const { key } = getFirstCookie(mock.responses[0]);
137
- const title = mock.meta.title ?? key;
150
+ const title = mock.meta?.title ?? key;
138
151
  const defaultEntry = {
139
- title: mock.defaultResponse?.label ?? "Default",
152
+ title: evaluateMock(mock.defaultResponse).label ?? "Default",
140
153
  value: "default"
141
154
  };
142
155
  return {
@@ -148,7 +161,7 @@ function entryFromMock(mock) {
148
161
  ...mock.responses.map((entry) => {
149
162
  const { value } = getFirstCookie(entry);
150
163
  return {
151
- title: entry.response.label ?? value,
164
+ title: evaluateMock(entry.response).label ?? value,
152
165
  value
153
166
  };
154
167
  })
@@ -0,0 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+
5
+ // src/pageobjects/Devindex.pageobject.ts
6
+ var DevindexPageObject = class {
7
+ constructor() {
8
+ __publicField(this, "selector");
9
+ __publicField(this, "el");
10
+ this.selector = ".secret-menu";
11
+ this.el = () => cy.get(this.selector);
12
+ }
13
+ toggleMenu() {
14
+ cy.get(".secret-menu > button").click();
15
+ }
16
+ valj(id, value) {
17
+ cy.get(`#${id}`).select(value);
18
+ }
19
+ /**
20
+ * Inputs text into a text field.
21
+ * @param name - The name of the text field.
22
+ * @param value - The text to input.
23
+ */
24
+ textField(name, value) {
25
+ cy.get(`input[name="${name}"]`).clear().type(value);
26
+ }
27
+ };
28
+ export {
29
+ DevindexPageObject
30
+ };
@@ -0,0 +1,46 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ import { Mock } from '@forsakringskassan/apimock-express';
4
+
5
+ export interface SelectOption {
6
+ title: string;
7
+ value: unknown;
8
+ }
9
+ export interface SelectSettings {
10
+ type: "select";
11
+ key: string;
12
+ title: string;
13
+ reloadOnChange?: boolean;
14
+ execOnChange?: string;
15
+ description?: string;
16
+ sessionStorage?: boolean;
17
+ options: SelectOption[];
18
+ }
19
+ export interface LinkOption {
20
+ title: string;
21
+ href: string;
22
+ }
23
+ export interface LinkSettings {
24
+ type: "links";
25
+ title: string;
26
+ description?: string;
27
+ options: LinkOption[];
28
+ }
29
+ export interface TextSettings {
30
+ type: "text";
31
+ key: string;
32
+ title: string;
33
+ description?: string;
34
+ options: LinkOption[];
35
+ }
36
+ export type Settings = SelectSettings | LinkSettings | TextSettings;
37
+ /**
38
+ * @param userSettingsAndMocks - An array of user settings and/or mocks to generate the menu from.
39
+ */
40
+ declare const _default: (userSettingsAndMocks: Array<Settings | Mock>) => void;
41
+
42
+ export {
43
+ _default as default,
44
+ };
45
+
46
+ export {};
@@ -0,0 +1,17 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ export declare class DevindexPageObject {
4
+ selector: string;
5
+ el: () => Cypress.Chainable<JQuery>;
6
+ constructor();
7
+ toggleMenu(): void;
8
+ valj(id: string, value: string): void;
9
+ /**
10
+ * Inputs text into a text field.
11
+ * @param name - The name of the text field.
12
+ * @param value - The text to input.
13
+ */
14
+ textField(name: string, value: string): void;
15
+ }
16
+
17
+ export {};
package/package.json CHANGED
@@ -1,38 +1,44 @@
1
1
  {
2
2
  "name": "@forsakringskassan/devindex-menu",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
+ "homepage": "https://github.com/Forsakringskassan/devindex-menu",
6
+ "bugs": "https://github.com/Forsakringskassan/devindex-menu/issues",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Forsakringskassan/devindex-menu.git"
10
+ },
5
11
  "license": "ISC",
6
12
  "author": "FK",
7
13
  "exports": {
8
14
  ".": {
9
- "types": "./menu.d.ts",
15
+ "types": "./dist/types/menu.d.ts",
10
16
  "require": "./dist/cjs/menu.js",
11
17
  "import": "./dist/esm/menu.js"
12
18
  },
13
19
  "./pageobjects": {
14
- "types": "./pageobjects.d.ts",
15
- "require": "./dist/cjs/pageobjects/pageobjects.js",
16
- "import": "./dist/esm/pageobjects/pageobjects.js"
20
+ "types": "./dist/types/pageobjects.d.ts",
21
+ "require": "./dist/cjs/pageobjects.js",
22
+ "import": "./dist/esm/pageobjects.js"
17
23
  }
18
24
  },
19
25
  "main": "dist/cjs/menu.js",
20
26
  "module": "dist/esm/menu.js",
21
27
  "types": "./menu.d.ts",
22
28
  "files": [
23
- "dist",
24
- "pageobjects",
25
- "./pageobjects.d.ts",
26
- "./pageobjects.js",
27
- "./menu.d.ts"
29
+ "dist"
28
30
  ],
29
31
  "scripts": {
30
- "prebuild": "rimraf dist && tsc",
31
- "build": "node generate.mjs",
32
+ "prebuild": "tsc",
33
+ "build": "node ./scripts/generate.mjs",
34
+ "postbuild": "npm run types:main && npm run types:pageobject",
35
+ "types:main": "dts-bundle-generator -o dist/types/index.d.ts temp/types/menu.d.ts",
36
+ "types:pageobject": "dts-bundle-generator -o dist/types/pageobjects.d.ts temp/types/pageobjects.d.ts",
32
37
  "eslint": "eslint --cache .",
33
38
  "prettier:check": "prettier --check .",
34
39
  "prettier:write": "prettier --write .",
35
- "test": "npm run prettier:check && npm run eslint"
40
+ "test": "npm run prettier:check && npm run eslint",
41
+ "start": "node ./scripts/serve.mjs"
36
42
  },
37
43
  "commitlint": {
38
44
  "extends": "@forsakringskassan/commitlint-config/no-jira"
@@ -42,27 +48,28 @@
42
48
  "extends": "@forsakringskassan/semantic-release-config"
43
49
  },
44
50
  "devDependencies": {
45
- "@babel/core": "7.28.4",
46
- "@babel/preset-env": "7.28.3",
47
- "@forsakringskassan/apimock-express": "2.9.0",
48
- "@forsakringskassan/commitlint-config": "3.1.2",
49
- "@forsakringskassan/eslint-config": "13.1.0",
50
- "@forsakringskassan/eslint-config-cli": "13.1.0",
51
- "@forsakringskassan/eslint-config-cypress": "13.1.0",
52
- "@forsakringskassan/eslint-config-jest": "13.1.0",
53
- "@forsakringskassan/eslint-config-typescript": "13.1.0",
54
- "@forsakringskassan/eslint-config-typescript-typeinfo": "13.1.0",
55
- "@forsakringskassan/prettier-config": "3.1.7",
56
- "@tsconfig/node16": "16.1.5",
57
- "@types/node": "16.18.126",
58
- "cypress": "15.4.0",
59
- "esbuild": "0.25.10",
51
+ "@babel/core": "7.28.5",
52
+ "@babel/preset-env": "7.28.5",
53
+ "@fkui/tsconfig": "6.31.0",
54
+ "@forsakringskassan/apimock-express": "2.12.0",
55
+ "@forsakringskassan/commitlint-config": "3.3.1",
56
+ "@forsakringskassan/eslint-config": "13.2.6",
57
+ "@forsakringskassan/eslint-config-cli": "13.2.0",
58
+ "@forsakringskassan/eslint-config-cypress": "13.2.5",
59
+ "@forsakringskassan/eslint-config-jest": "13.2.6",
60
+ "@forsakringskassan/eslint-config-typescript": "13.2.6",
61
+ "@forsakringskassan/eslint-config-typescript-typeinfo": "13.2.6",
62
+ "@forsakringskassan/prettier-config": "3.3.2",
63
+ "@tsconfig/node22": "22.0.5",
64
+ "@types/node": "22.19.3",
65
+ "cypress": "15.7.1",
66
+ "dts-bundle-generator": "9.5.1",
67
+ "esbuild": "0.27.1",
60
68
  "esbuild-sass-plugin": "3.3.1",
61
- "rimraf": "6.0.1",
62
- "sass": "1.93.2",
69
+ "sass": "1.96.0",
63
70
  "typescript": "5.9.3"
64
71
  },
65
72
  "engines": {
66
- "node": ">= 16"
73
+ "node": ">= 22.0.0"
67
74
  }
68
75
  }
@@ -1,7 +0,0 @@
1
- export declare class DevindexPageObject {
2
- selector: string;
3
- el: () => Cypress.Chainable<JQuery>;
4
- constructor();
5
- toggleMenu(): void;
6
- valj(id: string, value: string): void;
7
- }
@@ -1,16 +0,0 @@
1
- // src/pageobjects/Devindex.pageobject.ts
2
- var DevindexPageObject = class {
3
- constructor() {
4
- this.selector = ".secret-menu";
5
- this.el = () => cy.get(this.selector);
6
- }
7
- toggleMenu() {
8
- cy.get(".secret-menu > button").click();
9
- }
10
- valj(id, value) {
11
- cy.get(`#${id}`).select(value);
12
- }
13
- };
14
- export {
15
- DevindexPageObject
16
- };
@@ -1 +0,0 @@
1
- export * from "./Devindex.pageobject";
package/menu.d.ts DELETED
@@ -1,35 +0,0 @@
1
- import { type Mock } from "@forsakringskassan/apimock-express";
2
-
3
- export interface SelectOption {
4
- title: string;
5
- value: unknown;
6
- }
7
-
8
- export interface SelectSettings {
9
- type?: "select";
10
- key: string;
11
- title: string;
12
- reloadOnChange?: boolean;
13
- execOnChange?: string;
14
- description?: string;
15
- sessionStorage?: boolean;
16
- options: SelectOption[];
17
- }
18
-
19
- export interface LinkOption {
20
- title: string;
21
- href: string;
22
- }
23
-
24
- export interface LinkSettings {
25
- type: "links";
26
- title: string;
27
- description?: string;
28
- options: LinkOption[];
29
- }
30
-
31
- export type Settings = SelectSettings | LinkSettings;
32
-
33
- export default function devindexMenu(
34
- userSettingsAndMocks: Array<Settings | Mock>,
35
- ): void;
package/pageobjects.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/pageobjects";