Skip to content

Commit a8a11fe

Browse files
committed
Fix object in props
1 parent 27be0ae commit a8a11fe

8 files changed

Lines changed: 110 additions & 114 deletions

File tree

packages/bundle/src/adaptiveCards/Attachment/AnimationCardContent.tsx

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,19 @@
33
import { Components } from 'botframework-webchat-component';
44
import { parseProps } from 'botframework-webchat-component/internal';
55
import React, { memo } from 'react';
6-
import { array, boolean, object, optional, pipe, readonly, string, type InferInput } from 'valibot';
6+
import { boolean, custom, object, optional, pipe, readonly, safeParse, string, type InferInput } from 'valibot';
77

88
import useStyleSet from '../../hooks/useStyleSet';
99
import CommonCard from './CommonCard';
10+
import { directLineMediaCardSchema } from './private/directLineSchema';
1011

1112
const { ImageContent, VideoContent } = Components;
1213

1314
const animationCardContentPropsSchema = pipe(
1415
object({
1516
actionPerformedClassName: optional(string(), ''), // TODO: Should remove default value.
16-
content: pipe(
17-
object({
18-
media: pipe(
19-
array(
20-
pipe(
21-
object({
22-
profile: optional(string()),
23-
url: string()
24-
}),
25-
readonly()
26-
)
27-
),
28-
readonly()
29-
)
30-
}),
31-
readonly()
17+
content: custom<InferInput<typeof directLineMediaCardSchema>>(
18+
value => safeParse(directLineMediaCardSchema, value).success
3219
),
3320
disabled: optional(boolean())
3421
}),

packages/bundle/src/adaptiveCards/Attachment/AudioCardContent.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,19 @@
33
import { Components } from 'botframework-webchat-component';
44
import { parseProps } from 'botframework-webchat-component/internal';
55
import React, { memo } from 'react';
6-
import { array, boolean, object, optional, pipe, readonly, string, type InferInput } from 'valibot';
6+
import { boolean, custom, object, optional, pipe, readonly, safeParse, string, type InferInput } from 'valibot';
77

88
import useStyleSet from '../../hooks/useStyleSet';
99
import CommonCard from './CommonCard';
10+
import { directLineMediaCardSchema } from './private/directLineSchema';
1011

1112
const { AudioContent } = Components;
1213

1314
const audioCardContentPropsSchema = pipe(
1415
object({
1516
actionPerformedClassName: optional(string()),
16-
content: pipe(
17-
object({
18-
autostart: optional(boolean()),
19-
autoloop: optional(boolean()),
20-
image: optional(object({ url: string() })),
21-
media: pipe(array(object({ url: string() })), readonly())
22-
}),
23-
readonly()
17+
content: custom<InferInput<typeof directLineMediaCardSchema>>(
18+
value => safeParse(directLineMediaCardSchema, value).success
2419
),
2520
disabled: optional(boolean())
2621
}),

packages/bundle/src/adaptiveCards/Attachment/HeroCardContent.tsx

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,21 @@ import { hooks } from 'botframework-webchat-component';
22
import { parseProps } from 'botframework-webchat-component/internal';
33
import { type DirectLineCardAction } from 'botframework-webchat-core';
44
import React, { memo, useMemo } from 'react';
5-
import { array, boolean, looseObject, object, optional, pipe, readonly, string, type InferInput } from 'valibot';
5+
import { boolean, custom, object, optional, pipe, readonly, safeParse, string, type InferInput } from 'valibot';
66

77
import useStyleOptions from '../../hooks/useStyleOptions';
88
import useAdaptiveCardsPackage from '../hooks/useAdaptiveCardsPackage';
99
import AdaptiveCardBuilder from './AdaptiveCardBuilder';
1010
import AdaptiveCardRenderer from './AdaptiveCardRenderer';
11+
import { directLineBasicCardSchema } from './private/directLineSchema';
1112

1213
const { useDirection } = hooks;
1314

14-
// TODO: Should build `directLineCardActionSchema`.
15-
const directLineCardActionSchema = pipe(
16-
looseObject({
17-
image: optional(string()),
18-
title: optional(string()),
19-
type: string(),
20-
value: optional(string())
21-
}),
22-
readonly()
23-
);
24-
2515
const heroCardContentPropsSchema = pipe(
2616
object({
2717
actionPerformedClassName: optional(string(), ''), // TODO: Should remove default value.
2818
content: pipe(
29-
object({
30-
buttons: optional(pipe(array(directLineCardActionSchema), readonly())),
31-
images: optional(
32-
pipe(
33-
array(
34-
pipe(
35-
object({
36-
alt: string(),
37-
tap: optional(directLineCardActionSchema),
38-
url: string()
39-
}),
40-
readonly()
41-
)
42-
),
43-
readonly()
44-
)
45-
),
46-
subtitle: optional(string()),
47-
tap: optional(directLineCardActionSchema),
48-
text: optional(string()),
49-
title: optional(string())
50-
}),
51-
readonly()
19+
custom<InferInput<typeof directLineBasicCardSchema>>(value => safeParse(directLineBasicCardSchema, value).success)
5220
),
5321
disabled: optional(boolean())
5422
}),

packages/bundle/src/adaptiveCards/Attachment/OAuthCardContent.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
import { hooks } from 'botframework-webchat-component';
22
import { parseProps } from 'botframework-webchat-component/internal';
33
import React, { memo, useMemo } from 'react';
4-
import { any, array, boolean, object, optional, pipe, readonly, string, type InferInput } from 'valibot';
4+
import { boolean, custom, object, optional, pipe, readonly, safeParse, string, type InferInput } from 'valibot';
55

66
import useStyleOptions from '../../hooks/useStyleOptions';
77
import useAdaptiveCardsPackage from '../hooks/useAdaptiveCardsPackage';
88
import AdaptiveCardBuilder from './AdaptiveCardBuilder';
99
import AdaptiveCardRenderer from './AdaptiveCardRenderer';
10+
import { directLineSignInCardSchema } from './private/directLineSchema';
1011

1112
const { useDirection } = hooks;
1213

1314
const oauthCardContentPropsSchema = pipe(
1415
object({
1516
actionPerformedClassName: optional(string(), ''), // TODO: Should remove default value.
16-
content: pipe(
17-
object({
18-
buttons: pipe(array(any()), readonly())
19-
}),
20-
readonly()
17+
content: custom<InferInput<typeof directLineSignInCardSchema>>(
18+
value => safeParse(directLineSignInCardSchema, value).success
2119
),
2220
disabled: optional(boolean())
2321
}),
@@ -37,8 +35,8 @@ function OAuthCardContent(props: OAuthCardContentProps) {
3735
if (content) {
3836
const builder = new AdaptiveCardBuilder(adaptiveCardsPackage, styleOptions, direction);
3937

40-
builder.addCommonHeaders(content);
41-
builder.addButtons(content.buttons, true);
38+
builder.addCommonHeaders(content as any);
39+
builder.addButtons(content.buttons as any, true);
4240

4341
return builder.card;
4442
}

packages/bundle/src/adaptiveCards/Attachment/SignInCardContent.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { parseProps } from 'botframework-webchat-component/internal';
22
import React, { memo } from 'react';
3-
import { any, boolean, object, optional, pipe, readonly, string, type InferInput } from 'valibot';
3+
import { boolean, custom, object, optional, pipe, readonly, safeParse, string, type InferInput } from 'valibot';
44

55
import useStyleSet from '../../hooks/useStyleSet';
66
import CommonCard from './CommonCard';
7+
import { directLineSignInCardSchema } from './private/directLineSchema';
78

89
const signInCardContentPropsSchema = pipe(
910
object({
1011
actionPerformedClassName: optional(string(), ''), // TODO: Should remove default value.
11-
content: pipe(any()),
12+
content: custom<InferInput<typeof directLineSignInCardSchema>>(
13+
value => safeParse(directLineSignInCardSchema, value).success
14+
),
1215
disabled: optional(boolean())
1316
}),
1417
readonly()

packages/bundle/src/adaptiveCards/Attachment/ThumbnailCardContent.tsx

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,21 @@
22

33
import { hooks } from 'botframework-webchat-component';
44
import React, { memo, useMemo } from 'react';
5-
import { any, array, boolean, object, optional, parse, pipe, readonly, string, type InferInput } from 'valibot';
5+
import { boolean, custom, object, optional, parse, pipe, readonly, safeParse, string, type InferInput } from 'valibot';
66

77
import useStyleOptions from '../../hooks/useStyleOptions';
88
import useAdaptiveCardsPackage from '../hooks/useAdaptiveCardsPackage';
99
import AdaptiveCardBuilder from './AdaptiveCardBuilder';
1010
import AdaptiveCardRenderer from './AdaptiveCardRenderer';
11+
import { directLineBasicCardSchema } from './private/directLineSchema';
1112

1213
const { useDirection } = hooks;
1314

1415
const thumbnailCardContentPropsSchema = pipe(
1516
object({
1617
actionPerformedClassName: optional(string(), ''), // TODO: Should remove default value.
17-
content: pipe(
18-
object({
19-
buttons: pipe(array(any()), readonly()),
20-
images: pipe(
21-
array(
22-
object({
23-
alt: string(),
24-
tap: optional(any()),
25-
url: string()
26-
})
27-
),
28-
readonly()
29-
),
30-
subtitle: optional(string()),
31-
tap: optional(any()),
32-
text: optional(string()),
33-
title: optional(string())
34-
}),
35-
readonly()
18+
content: custom<InferInput<typeof directLineBasicCardSchema>>(
19+
value => safeParse(directLineBasicCardSchema, value).success
3620
),
3721
disabled: optional(boolean())
3822
}),
@@ -66,11 +50,11 @@ function ThumbnailCardContent(props: ThumbnailCardContentProps) {
6650
);
6751

6852
builder.addTextBlock(subtitle, { isSubtle: true, wrap: richCardWrapTitle }, firstColumn);
69-
builder.addImage(url, lastColumn, tap, alt);
53+
builder.addImage(url, lastColumn, tap as any, alt);
7054
builder.addTextBlock(text, { wrap: true });
71-
builder.addButtons(buttons);
55+
builder.addButtons(buttons as any);
7256
} else {
73-
builder.addCommon(content);
57+
builder.addCommon(content as any);
7458
}
7559
return builder.card;
7660
}

packages/bundle/src/adaptiveCards/Attachment/VideoCardContent.tsx

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,19 @@
22

33
import { Components } from 'botframework-webchat-component';
44
import React, { memo } from 'react';
5-
import { array, boolean, object, optional, parse, pipe, readonly, string, type InferInput } from 'valibot';
5+
import { boolean, custom, object, optional, parse, pipe, readonly, safeParse, string, type InferInput } from 'valibot';
66

77
import useStyleSet from '../../hooks/useStyleSet';
88
import CommonCard from './CommonCard';
9+
import { directLineMediaCardSchema } from './private/directLineSchema';
910

1011
const { VideoContent } = Components;
1112

1213
const videoCardContentPropsSchema = pipe(
1314
object({
1415
actionPerformedClassName: optional(string(), ''), // TODO: Should remove default value.
15-
content: pipe(
16-
object({
17-
autoloop: optional(boolean()),
18-
autostart: optional(boolean()),
19-
image: optional(pipe(object({ url: string() }), readonly())),
20-
media: pipe(
21-
array(
22-
pipe(
23-
object({
24-
profile: optional(string()),
25-
url: string()
26-
}),
27-
readonly()
28-
)
29-
),
30-
readonly()
31-
)
32-
}),
33-
readonly()
16+
content: custom<InferInput<typeof directLineMediaCardSchema>>(
17+
value => safeParse(directLineMediaCardSchema, value).success
3418
),
3519
disabled: optional(boolean())
3620
}),
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { any, array, boolean, literal, looseObject, object, optional, pipe, readonly, string, union } from 'valibot';
2+
3+
// TODO: Should build a better `directLineCardActionSchema`.
4+
const directLineCardActionSchema = pipe(
5+
looseObject({
6+
image: optional(string()),
7+
title: optional(string()),
8+
type: string(),
9+
value: optional(string())
10+
}),
11+
readonly()
12+
);
13+
14+
// https://github.com/microsoft/botframework-sdk/blob/master/specs/botframework-activity/botframework-cards.md#media-cards
15+
const directLineMediaCardSchema = pipe(
16+
object({
17+
aspect: optional(union([literal('4:3'), literal('16:9')])),
18+
autoloop: optional(boolean()),
19+
autostart: optional(boolean()),
20+
buttons: optional(pipe(array(directLineCardActionSchema), readonly())),
21+
duration: optional(string()),
22+
// In the spec, "image" is of type "thumbnailUrl", which is simply a string.
23+
image: optional(
24+
pipe(
25+
object({
26+
url: string()
27+
}),
28+
readonly()
29+
)
30+
),
31+
media: pipe(array(pipe(object({ profile: optional(string()), url: string() }), readonly())), readonly()),
32+
shareable: optional(boolean()),
33+
subtitle: optional(string()),
34+
text: optional(string()), // TODO: Media cards should not have `text` field.
35+
title: optional(string()),
36+
value: optional(any())
37+
}),
38+
readonly()
39+
);
40+
41+
// https://github.com/microsoft/botframework-sdk/blob/master/specs/botframework-activity/botframework-cards.md#basic-cards
42+
const directLineBasicCardSchema = pipe(
43+
object({
44+
buttons: optional(pipe(array(directLineCardActionSchema), readonly())),
45+
images: optional(
46+
pipe(
47+
array(
48+
pipe(
49+
object({
50+
alt: string(),
51+
tap: optional(directLineCardActionSchema),
52+
url: string()
53+
}),
54+
readonly()
55+
)
56+
),
57+
readonly()
58+
)
59+
),
60+
subtitle: optional(string()),
61+
tap: optional(directLineCardActionSchema),
62+
text: optional(string()),
63+
title: optional(string())
64+
}),
65+
readonly()
66+
);
67+
68+
// https://github.com/microsoft/botframework-sdk/blob/master/specs/botframework-activity/botframework-cards.md#Signin-card
69+
const directLineSignInCardSchema = pipe(
70+
object({
71+
buttons: pipe(array(directLineCardActionSchema), readonly()),
72+
text: optional(string())
73+
}),
74+
readonly()
75+
);
76+
77+
export { directLineBasicCardSchema, directLineCardActionSchema, directLineMediaCardSchema, directLineSignInCardSchema };

0 commit comments

Comments
 (0)