@truecodeio/sdk-react 0.2.9 → 0.2.11
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/dist/index.d.ts +55 -26
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -5,66 +5,95 @@ export declare const ClientProvider: ({ children, client, }: React.PropsWithChil
|
|
|
5
5
|
export declare const useClient: () => {
|
|
6
6
|
getEligibleCampaign: () => Promise<{
|
|
7
7
|
template: {
|
|
8
|
-
content: {
|
|
8
|
+
content: Readonly<{
|
|
9
9
|
id: string;
|
|
10
10
|
type: "root";
|
|
11
11
|
name: string;
|
|
12
12
|
isCollapsed: boolean;
|
|
13
|
-
props: {
|
|
13
|
+
props: Readonly<{
|
|
14
14
|
color: string;
|
|
15
|
-
}
|
|
16
|
-
children: {
|
|
15
|
+
}>;
|
|
16
|
+
children: readonly Readonly<{
|
|
17
17
|
id: string;
|
|
18
18
|
type: "row";
|
|
19
19
|
name: string;
|
|
20
20
|
isCollapsed: boolean;
|
|
21
|
-
props: {
|
|
22
|
-
padding: {
|
|
21
|
+
props: Readonly<{
|
|
22
|
+
padding: Readonly<{
|
|
23
23
|
top: number;
|
|
24
24
|
right: number;
|
|
25
25
|
bottom: number;
|
|
26
26
|
left: number;
|
|
27
|
-
}
|
|
27
|
+
}>;
|
|
28
28
|
gap: number;
|
|
29
|
-
background: {
|
|
29
|
+
background: Readonly<{
|
|
30
30
|
color: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
}>;
|
|
32
|
+
alignment: Readonly<{
|
|
33
|
+
horizontal: "default" | "start" | "center" | "end";
|
|
34
|
+
}>;
|
|
35
|
+
}>;
|
|
36
|
+
children: readonly Readonly<{
|
|
34
37
|
id: string;
|
|
35
38
|
type: "column";
|
|
36
39
|
name: string;
|
|
37
40
|
isCollapsed: boolean;
|
|
38
|
-
props:
|
|
39
|
-
|
|
41
|
+
props: Readonly<{
|
|
42
|
+
flexChildSize: "default" | "equal" | "none";
|
|
43
|
+
alignment: Readonly<{
|
|
44
|
+
vertical: "start" | "center" | "end";
|
|
45
|
+
}>;
|
|
46
|
+
}>;
|
|
47
|
+
children: readonly (Readonly<{
|
|
40
48
|
id: string;
|
|
41
49
|
type: "spacer";
|
|
42
50
|
name: string;
|
|
43
51
|
isCollapsed: boolean;
|
|
44
|
-
props: {
|
|
52
|
+
props: Readonly<{
|
|
45
53
|
size: number;
|
|
46
|
-
}
|
|
47
|
-
} | {
|
|
54
|
+
}>;
|
|
55
|
+
}> | Readonly<{
|
|
48
56
|
id: string;
|
|
49
57
|
type: "text";
|
|
50
58
|
name: string;
|
|
51
59
|
isCollapsed: boolean;
|
|
52
|
-
props: {
|
|
53
|
-
type: "paragraph" | "heading-1" | "heading-2" | "heading-3" | "heading-4" | "heading-5" | "heading-6";
|
|
60
|
+
props: Readonly<{
|
|
54
61
|
content: string;
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
type: "paragraph" | "heading-1" | "heading-2" | "heading-3" | "heading-4" | "heading-5" | "heading-6";
|
|
63
|
+
}>;
|
|
64
|
+
}> | Readonly<{
|
|
57
65
|
id: string;
|
|
58
66
|
type: "button";
|
|
59
67
|
name: string;
|
|
60
68
|
isCollapsed: boolean;
|
|
61
|
-
props: {
|
|
69
|
+
props: Readonly<{
|
|
62
70
|
title: string;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
71
|
+
background: Readonly<{
|
|
72
|
+
color: Readonly<{
|
|
73
|
+
default: string;
|
|
74
|
+
hover: string;
|
|
75
|
+
}>;
|
|
76
|
+
}>;
|
|
77
|
+
text: Readonly<{
|
|
78
|
+
color: Readonly<{
|
|
79
|
+
default: string;
|
|
80
|
+
hover: string;
|
|
81
|
+
}>;
|
|
82
|
+
}>;
|
|
83
|
+
padding: Readonly<{
|
|
84
|
+
top: number;
|
|
85
|
+
right: number;
|
|
86
|
+
bottom: number;
|
|
87
|
+
left: number;
|
|
88
|
+
}>;
|
|
89
|
+
borderRadius: number;
|
|
90
|
+
fontSize: number;
|
|
91
|
+
fontWeight: number;
|
|
92
|
+
}>;
|
|
93
|
+
}>)[];
|
|
94
|
+
}>[];
|
|
95
|
+
}>[];
|
|
96
|
+
}>;
|
|
68
97
|
id: string;
|
|
69
98
|
name: string;
|
|
70
99
|
organizationId: string;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../node_modules/.pnpm/@truecodeio+common@0.1.
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../node_modules/.pnpm/@truecodeio+common@0.1.4_react@19.1.0/node_modules/@truecodeio/common/src/typescript/utils/assert.ts","../../../node_modules/.pnpm/@truecodeio+common@0.1.4_react@19.1.0/node_modules/@truecodeio/common/src/typescript/utils/non-nullable.ts","../src/index.tsx"],"sourcesContent":["export class AssertionError extends Error {\n constructor(message?: string) {\n super(message);\n\n this.name = \"AssertionError\";\n }\n}\n\n// eslint-disable-next-line prefer-arrow/prefer-arrow-functions\nexport function assert<InputT, OutputT extends InputT>(\n input: InputT,\n guard: (input: InputT) => input is OutputT,\n message?: string,\n): asserts input is OutputT {\n if (!guard(input)) {\n throw new AssertionError(message);\n }\n}\n\n// eslint-disable-next-line prefer-arrow/prefer-arrow-functions\nexport function asserted<InputT, OutputT extends InputT>(\n input: InputT,\n guard: (input: InputT) => input is OutputT,\n message?: string,\n): OutputT {\n assert(input, guard, message);\n\n return input;\n}\n","import { asserted } from \"./assert.ts\";\n\nexport const checkNonUndefined = <ValueT>(\n value: ValueT,\n): value is Exclude<ValueT, undefined> => {\n return value !== undefined;\n};\n\nexport const assertedNonUndefined = <ValueT>(\n value: ValueT,\n message = \"should be non undefined\",\n) => {\n return asserted(value, checkNonUndefined, message);\n};\n\nexport const checkNonNull = <ValueT>(\n value: ValueT,\n): value is Exclude<ValueT, null> => {\n return value !== null;\n};\n\nexport const assertedNonNull = <ValueT>(\n value: ValueT,\n message = \"should be non null\",\n) => {\n return asserted(value, checkNonNull, message);\n};\n\nexport const checkNonNullable = <ValueT>(\n value: ValueT,\n): value is Exclude<ValueT, null> => {\n return checkNonUndefined(value) && checkNonNull(value);\n};\n\nexport const assertedNonNullable = <ValueT>(value: ValueT) => {\n return asserted(\n value,\n checkNonNullable,\n \"should be non null and non undefined\",\n );\n};\n\nexport const checkIsNullable = <ValueT>(\n value: ValueT,\n): value is Extract<ValueT, null> => {\n return !checkNonNullable(value);\n};\n","import { createContext, use, useEffect, useState } from \"react\";\nimport type { createBokoClient, EligibleCampaign } from \"@truecodeio/sdk-core\";\nimport type { NodeT } from \"@truecodeio/domain-shared/schemas/tree-nodes/index.ts\";\nimport { assertedNonNull } from \"@truecodeio/common/typescript/utils/non-nullable.ts\";\n\ntype ClientContextValue = {\n client: ReturnType<typeof createBokoClient>;\n};\n\nconst ClientContext = createContext<ClientContextValue | null>(null);\n\nexport const ClientProvider = ({\n children,\n client,\n}: React.PropsWithChildren<{\n client: ReturnType<typeof createBokoClient>;\n}>) => {\n return <ClientContext value={{ client }}>{children}</ClientContext>;\n};\n\nexport const useClient = () => {\n return assertedNonNull(use(ClientContext)).client;\n};\n\nexport const Renderer = () => {\n const [campaign, setCampaign] = useState<EligibleCampaign | null>(null);\n\n const client = useClient();\n\n useEffect(() => {\n // TODO: Replace with tanstack query\n const fetchCampaign = async () => {\n try {\n const response = await client.getEligibleCampaign();\n\n setCampaign(response);\n } catch (error) {\n console.error(\"Error fetching campaign:\", error);\n }\n };\n\n void fetchCampaign();\n }, []);\n\n const renderCampaign = () => {\n if (!campaign) {\n return null;\n }\n\n const renderNode = (node: NodeT) => {\n switch (node.type) {\n case \"root\": {\n return (\n <div style={{ color: node.props.color }}>\n {node.children.map(renderNode)}\n </div>\n );\n }\n case \"row\": {\n return (\n <div\n style={{\n display: \"flex\",\n backgroundColor: node.props.background.color,\n paddingLeft: node.props.padding.left,\n paddingRight: node.props.padding.right,\n paddingTop: node.props.padding.top,\n paddingBottom: node.props.padding.bottom,\n }}\n key={node.id}\n >\n {node.children.map(renderNode)}\n </div>\n );\n }\n case \"column\": {\n return (\n <div style={{ flex: 1 }} key={node.id}>\n {node.children.map(renderNode)}\n </div>\n );\n }\n case \"button\": {\n return (\n <button type=\"button\" key={node.id}>\n {node.props.title}\n </button>\n );\n }\n case \"text\": {\n switch (node.props.type) {\n case \"paragraph\": {\n return <p key={node.id}>{node.props.content}</p>;\n }\n case \"heading-1\": {\n return <h1 key={node.id}>{node.props.content}</h1>;\n }\n case \"heading-2\": {\n return <h2 key={node.id}>{node.props.content}</h2>;\n }\n case \"heading-3\": {\n return <h3 key={node.id}>{node.props.content}</h3>;\n }\n case \"heading-4\": {\n return <h4 key={node.id}>{node.props.content}</h4>;\n }\n case \"heading-5\": {\n return <h5 key={node.id}>{node.props.content}</h5>;\n }\n case \"heading-6\": {\n return <h6 key={node.id}>{node.props.content}</h6>;\n }\n\n default: {\n return node.props.type satisfies never;\n }\n }\n }\n case \"spacer\": {\n return <div style={{ height: node.props.size }} key={node.id}></div>;\n }\n\n default: {\n return node satisfies never;\n }\n }\n };\n\n return renderNode(campaign.template.content);\n };\n\n return renderCampaign();\n};\n\nexport { createBokoClient } from \"@truecodeio/sdk-core\";\n"],"names":["AssertionError","message","assert","input","guard","asserted","checkNonNull","value","assertedNonNull","ClientContext","createContext","ClientProvider","children","client","useClient","use","Renderer","campaign","setCampaign","useState","useEffect","response","error","renderNode","node","jsx"],"mappings":";;;AAAO,MAAMA,UAAuB,MAAM;AAAA,EACxC,YAAYC,GAAkB;AAC5B,UAAMA,CAAO,GAEb,KAAK,OAAO;AAAA,EAAA;AAEhB;AAGO,SAASC,EACdC,GACAC,GACAH,GAC0B;AAC1B,MAAI,CAACG,EAAMD,CAAK;AACd,UAAM,IAAIH,EAAeC,CAAO;AAEpC;AAGO,SAASI,EACdF,GACAC,GACAH,GACS;AACT,SAAAC,EAAOC,GAAOC,GAA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OD,EAAWN,EAAS,SAAS,OAAO;AAAA,EAAA,GAGtC;AACT;","x_google_ignoreList":[0,1]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@truecodeio/sdk-react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -12,20 +12,20 @@
|
|
|
12
12
|
"dist"
|
|
13
13
|
],
|
|
14
14
|
"devDependencies": {
|
|
15
|
+
"@truecodeio/sdk-core": "^0.2.9",
|
|
15
16
|
"@types/react": "^19.1.8",
|
|
16
17
|
"react": "^19.1.0",
|
|
17
|
-
"vite": "^7.0.
|
|
18
|
+
"vite": "^7.0.6",
|
|
18
19
|
"vite-plugin-dts": "^4.5.4",
|
|
19
|
-
"@truecodeio/sdk-core": "0.2.7",
|
|
20
20
|
"@boko/tsconfig": "^1.0.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@truecodeio/
|
|
24
|
-
"@truecodeio/
|
|
23
|
+
"@truecodeio/common": "^0.1.3",
|
|
24
|
+
"@truecodeio/domain-shared": "^0.1.6"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"
|
|
28
|
-
"
|
|
27
|
+
"@truecodeio/sdk-core": "^0.2.9",
|
|
28
|
+
"react": "^19.1.0"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "vite build",
|