From 004fc796cad3bbe4598e7f163979030ecf36ad65 Mon Sep 17 00:00:00 2001 From: Henning Perl Date: Fri, 8 Mar 2024 08:33:36 +0100 Subject: [PATCH 1/3] fix by adding script and ts-nocheck --- package-lock.json | 4 +- src/pkg/index.ts | 9 +-- src/pkg/ui_nodes.ts | 189 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 193 insertions(+), 9 deletions(-) create mode 100644 src/pkg/ui_nodes.ts diff --git a/package-lock.json b/package-lock.json index be3fbfcc..1e99a3b7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ory/kratos-selfservice-ui-node", - "version": "0.13.0-25", + "version": "0.14.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@ory/kratos-selfservice-ui-node", - "version": "0.13.0-25", + "version": "0.14.0", "license": "Apache-2.0", "dependencies": { "@ory/client": "1.6.2", diff --git a/src/pkg/index.ts b/src/pkg/index.ts index 46df7e6a..9c1a71b5 100644 --- a/src/pkg/index.ts +++ b/src/pkg/index.ts @@ -2,18 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 import { RouteOptionsCreator } from "./route" import sdk, { apiBaseUrl } from "./sdk" +import { filterNodesByGroups } from "./ui_nodes" import { UiNode, ErrorAuthenticatorAssuranceLevelNotSatisfied, OAuth2LogoutRequest, } from "@ory/client" -import { - ButtonLink, - Divider, - MenuLink, - Typography, - filterNodesByGroups, -} from "@ory/elements-markup" +import { ButtonLink, Divider, MenuLink, Typography } from "@ory/elements-markup" import { AxiosError } from "axios" import { NextFunction, Response } from "express" import { UnknownObject } from "express-handlebars/types" diff --git a/src/pkg/ui_nodes.ts b/src/pkg/ui_nodes.ts new file mode 100644 index 00000000..81566cc3 --- /dev/null +++ b/src/pkg/ui_nodes.ts @@ -0,0 +1,189 @@ +// @ts-nocheck +import { + UiNode, + UiNodeAnchorAttributes, + UiNodeAttributes, + UiNodeGroupEnum, + UiNodeImageAttributes, + UiNodeInputAttributes, + UiNodeInputAttributesTypeEnum, + UiNodeScriptAttributes, + UiNodeTextAttributes, +} from "@ory/client" + +/** + * Returns the node's label. + * + * @param node + * @return label + */ +export const getNodeLabel = (node: UiNode): string => { + const attributes = node.attributes + if (isUiNodeAnchorAttributes(attributes)) { + return attributes.title.text + } + + if (isUiNodeImageAttributes(attributes)) { + return node.meta.label?.text || "" + } + + if (isUiNodeInputAttributes(attributes)) { + if (attributes.label?.text) { + return attributes.label.text + } + } + + return node.meta.label?.text || "" +} + +/** + * A TypeScript type guard for nodes of the type + * + * @param attrs + */ +export function isUiNodeAnchorAttributes( + attrs: UiNodeAttributes, +): attrs is UiNodeAnchorAttributes { + return attrs.node_type === "a" +} + +/** + * A TypeScript type guard for nodes of the type + * + * @param attrs + */ +export function isUiNodeImageAttributes( + attrs: UiNodeAttributes, +): attrs is UiNodeImageAttributes { + return attrs.node_type === "img" +} + +/** + * A TypeScript type guard for nodes of the type + * + * @param attrs + */ +export function isUiNodeInputAttributes( + attrs: UiNodeAttributes, +): attrs is UiNodeInputAttributes { + return attrs.node_type === "input" +} + +/** + * A TypeScript type guard for nodes of the type {text} + * + * @param attrs + */ +export function isUiNodeTextAttributes( + attrs: UiNodeAttributes, +): attrs is UiNodeTextAttributes { + return attrs.node_type === "text" +} + +/** + * A TypeScript type guard for nodes of the type