@ysk-kit/web-sdk 1.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 +21 -0
- package/dist/billing-hooks.d.ts +50 -0
- package/dist/billing-hooks.d.ts.map +1 -0
- package/dist/billing-hooks.js +47 -0
- package/dist/billing-hooks.js.map +1 -0
- package/dist/index.d.ts +182 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +144 -0
- package/dist/index.js.map +1 -0
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.d.ts.map +1 -0
- package/dist/index.test.js +29 -0
- package/dist/index.test.js.map +1 -0
- package/dist/llm-hooks.d.ts +19 -0
- package/dist/llm-hooks.d.ts.map +1 -0
- package/dist/llm-hooks.js +9 -0
- package/dist/llm-hooks.js.map +1 -0
- package/dist/organizations-hooks.d.ts +64 -0
- package/dist/organizations-hooks.d.ts.map +1 -0
- package/dist/organizations-hooks.js +67 -0
- package/dist/organizations-hooks.js.map +1 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 YSK Limited
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { YskClient } from '@ysk-kit/sdk';
|
|
2
|
+
export declare const billingQueryKey: (organizationId: string) => readonly ["billing", string];
|
|
3
|
+
export declare function createBillingHooks(client: YskClient): {
|
|
4
|
+
useBillingPlans: () => import("@tanstack/react-query").UseQueryResult<{
|
|
5
|
+
code: "free" | "pro";
|
|
6
|
+
name: string;
|
|
7
|
+
amountHkdCents: number;
|
|
8
|
+
interval: "month";
|
|
9
|
+
}[], Error>;
|
|
10
|
+
useSubscription: (organizationId: string, enabled?: boolean) => import("@tanstack/react-query").UseQueryResult<{
|
|
11
|
+
planCode: "free" | "pro";
|
|
12
|
+
status: "active" | "canceled";
|
|
13
|
+
currentPeriodEnd: string | null;
|
|
14
|
+
seatCount: number;
|
|
15
|
+
}, Error>;
|
|
16
|
+
useInvoices: (organizationId: string, enabled?: boolean) => import("@tanstack/react-query").UseQueryResult<{
|
|
17
|
+
id: string;
|
|
18
|
+
number: string | null;
|
|
19
|
+
status: string;
|
|
20
|
+
amountDue: number;
|
|
21
|
+
currency: string;
|
|
22
|
+
hostedInvoiceUrl: string | null;
|
|
23
|
+
createdAt: string;
|
|
24
|
+
}[], Error>;
|
|
25
|
+
useCheckout: () => import("@tanstack/react-query").UseMutationResult<{
|
|
26
|
+
url: string;
|
|
27
|
+
}, Error, {
|
|
28
|
+
organizationId: string;
|
|
29
|
+
planCode: "free" | "pro";
|
|
30
|
+
successUrl: string;
|
|
31
|
+
cancelUrl: string;
|
|
32
|
+
seatCount: number;
|
|
33
|
+
}, unknown>;
|
|
34
|
+
useBillingPortal: () => import("@tanstack/react-query").UseMutationResult<{
|
|
35
|
+
url: string;
|
|
36
|
+
}, Error, {
|
|
37
|
+
organizationId: string;
|
|
38
|
+
returnUrl: string;
|
|
39
|
+
}, unknown>;
|
|
40
|
+
useCancelSubscription: () => import("@tanstack/react-query").UseMutationResult<{
|
|
41
|
+
canceled: true;
|
|
42
|
+
}, Error, {
|
|
43
|
+
organizationId: string;
|
|
44
|
+
}, unknown>;
|
|
45
|
+
useInvoicePdf: () => import("@tanstack/react-query").UseMutationResult<string, Error, {
|
|
46
|
+
id: string;
|
|
47
|
+
organizationId: string;
|
|
48
|
+
}, unknown>;
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=billing-hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing-hooks.d.ts","sourceRoot":"","sources":["../src/billing-hooks.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,eAAO,MAAM,eAAe,GAAI,gBAAgB,MAAM,iCAAyC,CAAC;AAEhG,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS;;;;;;;sCAOd,MAAM;;;;;;kCAOV,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA+BP,MAAM;wBAAkB,MAAM;;EAI9D"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
2
|
+
export const billingQueryKey = (organizationId) => ['billing', organizationId];
|
|
3
|
+
export function createBillingHooks(client) {
|
|
4
|
+
return {
|
|
5
|
+
useBillingPlans: () => useQuery({
|
|
6
|
+
queryKey: ['billing-plans'],
|
|
7
|
+
queryFn: () => client.billing.plans(),
|
|
8
|
+
}),
|
|
9
|
+
useSubscription: (organizationId, enabled = true) => useQuery({
|
|
10
|
+
queryKey: [...billingQueryKey(organizationId), 'subscription'],
|
|
11
|
+
queryFn: () => client.billing.subscription(organizationId),
|
|
12
|
+
enabled: organizationId.length > 0 && enabled,
|
|
13
|
+
retry: false,
|
|
14
|
+
}),
|
|
15
|
+
useInvoices: (organizationId, enabled = true) => useQuery({
|
|
16
|
+
queryKey: [...billingQueryKey(organizationId), 'invoices'],
|
|
17
|
+
queryFn: () => client.billing.invoices(organizationId),
|
|
18
|
+
enabled: organizationId.length > 0 && enabled,
|
|
19
|
+
retry: false,
|
|
20
|
+
}),
|
|
21
|
+
useCheckout: () => {
|
|
22
|
+
const qc = useQueryClient();
|
|
23
|
+
return useMutation({
|
|
24
|
+
mutationFn: (body) => client.billing.checkout(body),
|
|
25
|
+
onSuccess: (_data, body) => {
|
|
26
|
+
void qc.invalidateQueries({ queryKey: billingQueryKey(body.organizationId) });
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
useBillingPortal: () => useMutation({
|
|
31
|
+
mutationFn: (body) => client.billing.portal(body),
|
|
32
|
+
}),
|
|
33
|
+
useCancelSubscription: () => {
|
|
34
|
+
const qc = useQueryClient();
|
|
35
|
+
return useMutation({
|
|
36
|
+
mutationFn: (body) => client.billing.cancel(body),
|
|
37
|
+
onSuccess: (_data, body) => {
|
|
38
|
+
void qc.invalidateQueries({ queryKey: billingQueryKey(body.organizationId) });
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
useInvoicePdf: () => useMutation({
|
|
43
|
+
mutationFn: (args) => client.billing.invoicePdfUrl(args.id, args.organizationId),
|
|
44
|
+
}),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=billing-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing-hooks.js","sourceRoot":"","sources":["../src/billing-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,c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I,CAAC;gBACpE,SAAS,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;oBACzB,KAAK,EAAE,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;gBAChF,CAAC;aACF,CAAC,CAAC;QACL,CAAC;QACD,gBAAgB,EAAE,GAAG,EAAE,CACrB,WAAW,CAAC;YACV,UAAU,EAAE,CAAC,IAAmB,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;SACjE,CAAC;QACJ,qBAAqB,EAAE,GAAG,EAAE;YAC1B,MAAM,EAAE,GAAG,cAAc,EAAE,CAAC;YAC5B,OAAO,WAAW,CAAC;gBACjB,UAAU,EAAE,CAAC,IAAmB,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;gBAChE,SAAS,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;oBACzB,KAAK,EAAE,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;gBAChF,CAAC;aACF,CAAC,CAAC;QACL,CAAC;QACD,aAAa,EAAE,GAAG,EAAE,CAClB,WAAW,CAAC;YACV,UAAU,EAAE,CAAC,IAA4C,EAAE,EAAE,CAC3D,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,cAAc,CAAC;SAC7D,CAAC;KACL,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import type { YskClient } from '@ysk-kit/sdk';
|
|
2
|
+
export declare const usersQueryKey: readonly ["users"];
|
|
3
|
+
export declare const meQueryKey: readonly ["me"];
|
|
4
|
+
export declare const notificationsQueryKey: readonly ["notifications"];
|
|
5
|
+
export declare const auditQueryKey: readonly ["audit"];
|
|
6
|
+
export declare const apiKeysQueryKey: readonly ["api-keys"];
|
|
7
|
+
export declare function createUserHooks(client: YskClient): {
|
|
8
|
+
useUsers: (query?: {
|
|
9
|
+
cursor?: string;
|
|
10
|
+
limit?: number;
|
|
11
|
+
}) => import("@tanstack/react-query").UseQueryResult<{
|
|
12
|
+
items: {
|
|
13
|
+
id: string;
|
|
14
|
+
email: string | null;
|
|
15
|
+
phone: string | null;
|
|
16
|
+
displayName: string;
|
|
17
|
+
role: "USER" | "ADMIN" | "OPS";
|
|
18
|
+
status: "ACTIVE" | "INVITED" | "SUSPENDED" | "DELETED";
|
|
19
|
+
createdAt: string;
|
|
20
|
+
}[];
|
|
21
|
+
nextCursor: string | null;
|
|
22
|
+
}, Error>;
|
|
23
|
+
useCreateUser: () => import("@tanstack/react-query").UseMutationResult<{
|
|
24
|
+
id: string;
|
|
25
|
+
email: string | null;
|
|
26
|
+
phone: string | null;
|
|
27
|
+
displayName: string;
|
|
28
|
+
role: "USER" | "ADMIN" | "OPS";
|
|
29
|
+
status: "ACTIVE" | "INVITED" | "SUSPENDED" | "DELETED";
|
|
30
|
+
createdAt: string;
|
|
31
|
+
}, Error, {
|
|
32
|
+
email: string;
|
|
33
|
+
displayName: string;
|
|
34
|
+
role: "USER" | "ADMIN" | "OPS";
|
|
35
|
+
}, unknown>;
|
|
36
|
+
useSuspendUser: () => import("@tanstack/react-query").UseMutationResult<{
|
|
37
|
+
id: string;
|
|
38
|
+
email: string | null;
|
|
39
|
+
phone: string | null;
|
|
40
|
+
displayName: string;
|
|
41
|
+
role: "USER" | "ADMIN" | "OPS";
|
|
42
|
+
status: "ACTIVE" | "INVITED" | "SUSPENDED" | "DELETED";
|
|
43
|
+
createdAt: string;
|
|
44
|
+
}, Error, string, unknown>;
|
|
45
|
+
useMe: () => import("@tanstack/react-query").UseQueryResult<{
|
|
46
|
+
id: string;
|
|
47
|
+
email: string | null;
|
|
48
|
+
phone: string | null;
|
|
49
|
+
displayName: string;
|
|
50
|
+
role: "USER" | "ADMIN" | "OPS";
|
|
51
|
+
status: "ACTIVE" | "INVITED" | "SUSPENDED" | "DELETED";
|
|
52
|
+
createdAt: string;
|
|
53
|
+
}, Error>;
|
|
54
|
+
useRequestAdminOtp: () => import("@tanstack/react-query").UseMutationResult<{
|
|
55
|
+
sent: true;
|
|
56
|
+
}, Error, {
|
|
57
|
+
email: string;
|
|
58
|
+
}, unknown>;
|
|
59
|
+
useVerifyAdminOtp: () => import("@tanstack/react-query").UseMutationResult<{
|
|
60
|
+
accessToken: string;
|
|
61
|
+
refreshToken: string;
|
|
62
|
+
expiresIn: number;
|
|
63
|
+
user: {
|
|
64
|
+
id: string;
|
|
65
|
+
email: string | null;
|
|
66
|
+
phone: string | null;
|
|
67
|
+
displayName: string;
|
|
68
|
+
role: "USER" | "ADMIN" | "OPS";
|
|
69
|
+
status: "ACTIVE" | "INVITED" | "SUSPENDED" | "DELETED";
|
|
70
|
+
createdAt: string;
|
|
71
|
+
};
|
|
72
|
+
}, Error, {
|
|
73
|
+
email: string;
|
|
74
|
+
code: string;
|
|
75
|
+
}, unknown>;
|
|
76
|
+
useLogin: () => import("@tanstack/react-query").UseMutationResult<{
|
|
77
|
+
accessToken: string;
|
|
78
|
+
refreshToken: string;
|
|
79
|
+
expiresIn: number;
|
|
80
|
+
user: {
|
|
81
|
+
id: string;
|
|
82
|
+
email: string | null;
|
|
83
|
+
phone: string | null;
|
|
84
|
+
displayName: string;
|
|
85
|
+
role: "USER" | "ADMIN" | "OPS";
|
|
86
|
+
status: "ACTIVE" | "INVITED" | "SUSPENDED" | "DELETED";
|
|
87
|
+
createdAt: string;
|
|
88
|
+
};
|
|
89
|
+
}, Error, {
|
|
90
|
+
email: string;
|
|
91
|
+
password: string;
|
|
92
|
+
}, unknown>;
|
|
93
|
+
useRegister: () => import("@tanstack/react-query").UseMutationResult<{
|
|
94
|
+
accessToken: string;
|
|
95
|
+
refreshToken: string;
|
|
96
|
+
expiresIn: number;
|
|
97
|
+
user: {
|
|
98
|
+
id: string;
|
|
99
|
+
email: string | null;
|
|
100
|
+
phone: string | null;
|
|
101
|
+
displayName: string;
|
|
102
|
+
role: "USER" | "ADMIN" | "OPS";
|
|
103
|
+
status: "ACTIVE" | "INVITED" | "SUSPENDED" | "DELETED";
|
|
104
|
+
createdAt: string;
|
|
105
|
+
};
|
|
106
|
+
}, Error, {
|
|
107
|
+
email: string;
|
|
108
|
+
password: string;
|
|
109
|
+
displayName: string;
|
|
110
|
+
}, unknown>;
|
|
111
|
+
useLogout: () => import("@tanstack/react-query").UseMutationResult<void, Error, void, unknown>;
|
|
112
|
+
useForgotPassword: () => import("@tanstack/react-query").UseMutationResult<{
|
|
113
|
+
accepted: true;
|
|
114
|
+
}, Error, {
|
|
115
|
+
email: string;
|
|
116
|
+
}, unknown>;
|
|
117
|
+
useResetPassword: () => import("@tanstack/react-query").UseMutationResult<{
|
|
118
|
+
accepted: true;
|
|
119
|
+
}, Error, {
|
|
120
|
+
token: string;
|
|
121
|
+
password: string;
|
|
122
|
+
}, unknown>;
|
|
123
|
+
useNotifications: () => import("@tanstack/react-query").UseQueryResult<{
|
|
124
|
+
items: {
|
|
125
|
+
id: string;
|
|
126
|
+
type: "auth.reset" | "auth.welcome" | "user.created" | "org.invited";
|
|
127
|
+
title: string;
|
|
128
|
+
body: string;
|
|
129
|
+
readAt: string | null;
|
|
130
|
+
createdAt: string;
|
|
131
|
+
}[];
|
|
132
|
+
nextCursor: string | null;
|
|
133
|
+
}, Error>;
|
|
134
|
+
useMarkNotificationRead: () => import("@tanstack/react-query").UseMutationResult<{
|
|
135
|
+
read: true;
|
|
136
|
+
}, Error, string, unknown>;
|
|
137
|
+
useNotificationsLive: () => void;
|
|
138
|
+
useAuditLogs: (query?: {
|
|
139
|
+
cursor?: string;
|
|
140
|
+
limit?: number;
|
|
141
|
+
}, enabled?: boolean) => import("@tanstack/react-query").UseQueryResult<{
|
|
142
|
+
items: {
|
|
143
|
+
id: string;
|
|
144
|
+
actorId: string | null;
|
|
145
|
+
action: "user.create" | "user.suspend" | "file.upload" | "auth.register" | "auth.login" | "auth.logout" | "auth.reset" | "org.create" | "org.invite" | "org.member.remove" | "api_key.create" | "api_key.revoke";
|
|
146
|
+
resourceType: string;
|
|
147
|
+
resourceId: string;
|
|
148
|
+
createdAt: string;
|
|
149
|
+
}[];
|
|
150
|
+
nextCursor: string | null;
|
|
151
|
+
}, Error>;
|
|
152
|
+
useApiKeys: () => import("@tanstack/react-query").UseQueryResult<{
|
|
153
|
+
id: string;
|
|
154
|
+
name: string;
|
|
155
|
+
prefix: string;
|
|
156
|
+
last4: string;
|
|
157
|
+
permissions: ("user.create" | "user.suspend" | "audit.read" | "file.upload" | "llm.use" | "billing.checkout")[];
|
|
158
|
+
createdAt: string;
|
|
159
|
+
lastUsedAt: string | null;
|
|
160
|
+
}[], Error>;
|
|
161
|
+
useCreateApiKey: () => import("@tanstack/react-query").UseMutationResult<{
|
|
162
|
+
id: string;
|
|
163
|
+
name: string;
|
|
164
|
+
prefix: string;
|
|
165
|
+
last4: string;
|
|
166
|
+
permissions: ("user.create" | "user.suspend" | "audit.read" | "file.upload" | "llm.use" | "billing.checkout")[];
|
|
167
|
+
createdAt: string;
|
|
168
|
+
lastUsedAt: string | null;
|
|
169
|
+
token: string;
|
|
170
|
+
}, Error, {
|
|
171
|
+
name: string;
|
|
172
|
+
permissions: ("user.create" | "user.suspend" | "audit.read" | "file.upload" | "llm.use" | "billing.checkout")[];
|
|
173
|
+
}, unknown>;
|
|
174
|
+
useRevokeApiKey: () => import("@tanstack/react-query").UseMutationResult<{
|
|
175
|
+
revoked: true;
|
|
176
|
+
}, Error, string, unknown>;
|
|
177
|
+
};
|
|
178
|
+
export type UserHooks = ReturnType<typeof createUserHooks>;
|
|
179
|
+
export { billingQueryKey, createBillingHooks } from './billing-hooks';
|
|
180
|
+
export { createLlmHooks } from './llm-hooks';
|
|
181
|
+
export { createOrganizationHooks, organizationQueryKey, organizationsQueryKey, } from './organizations-hooks';
|
|
182
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAG9C,eAAO,MAAM,aAAa,oBAAqB,CAAC;AAChD,eAAO,MAAM,UAAU,iBAAkB,CAAC;AAC1C,eAAO,MAAM,qBAAqB,4BAA6B,CAAC;AAChE,eAAO,MAAM,aAAa,oBAAqB,CAAC;AAChD,eAAO,MAAM,eAAe,uBAAwB,CAAC;AAErD,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS;uBAE1B;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BA0G/B;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+B7D;AAED,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;AAE3D,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { RealtimeEvent } from '@ysk-kit/contracts';
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
export const usersQueryKey = ['users'];
|
|
5
|
+
export const meQueryKey = ['me'];
|
|
6
|
+
export const notificationsQueryKey = ['notifications'];
|
|
7
|
+
export const auditQueryKey = ['audit'];
|
|
8
|
+
export const apiKeysQueryKey = ['api-keys'];
|
|
9
|
+
export function createUserHooks(client) {
|
|
10
|
+
return {
|
|
11
|
+
useUsers: (query) => useQuery({
|
|
12
|
+
queryKey: [...usersQueryKey, query],
|
|
13
|
+
queryFn: () => client.users.list(query),
|
|
14
|
+
}),
|
|
15
|
+
useCreateUser: () => {
|
|
16
|
+
const qc = useQueryClient();
|
|
17
|
+
return useMutation({
|
|
18
|
+
mutationFn: (body) => client.users.create(body),
|
|
19
|
+
onSuccess: () => {
|
|
20
|
+
void qc.invalidateQueries({ queryKey: usersQueryKey });
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
useSuspendUser: () => {
|
|
25
|
+
const qc = useQueryClient();
|
|
26
|
+
return useMutation({
|
|
27
|
+
mutationFn: (id) => client.users.suspend(id),
|
|
28
|
+
onSuccess: () => {
|
|
29
|
+
void qc.invalidateQueries({ queryKey: usersQueryKey });
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
useMe: () => useQuery({
|
|
34
|
+
queryKey: meQueryKey,
|
|
35
|
+
queryFn: () => client.auth.me(),
|
|
36
|
+
retry: false,
|
|
37
|
+
}),
|
|
38
|
+
useRequestAdminOtp: () => useMutation({
|
|
39
|
+
mutationFn: (body) => client.auth.requestAdminOtp(body),
|
|
40
|
+
}),
|
|
41
|
+
useVerifyAdminOtp: () => {
|
|
42
|
+
const qc = useQueryClient();
|
|
43
|
+
return useMutation({
|
|
44
|
+
mutationFn: (body) => client.auth.verifyAdminOtp(body),
|
|
45
|
+
onSuccess: () => {
|
|
46
|
+
void qc.invalidateQueries({ queryKey: meQueryKey });
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
useLogin: () => {
|
|
51
|
+
const qc = useQueryClient();
|
|
52
|
+
return useMutation({
|
|
53
|
+
mutationFn: (body) => client.auth.login(body),
|
|
54
|
+
onSuccess: () => {
|
|
55
|
+
void qc.invalidateQueries({ queryKey: meQueryKey });
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
useRegister: () => {
|
|
60
|
+
const qc = useQueryClient();
|
|
61
|
+
return useMutation({
|
|
62
|
+
mutationFn: (body) => client.auth.register(body),
|
|
63
|
+
onSuccess: () => {
|
|
64
|
+
void qc.invalidateQueries({ queryKey: meQueryKey });
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
useLogout: () => {
|
|
69
|
+
const qc = useQueryClient();
|
|
70
|
+
return useMutation({
|
|
71
|
+
mutationFn: () => client.auth.logout(),
|
|
72
|
+
onSuccess: () => {
|
|
73
|
+
qc.removeQueries({ queryKey: meQueryKey });
|
|
74
|
+
qc.removeQueries({ queryKey: usersQueryKey });
|
|
75
|
+
qc.removeQueries({ queryKey: notificationsQueryKey });
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
useForgotPassword: () => useMutation({
|
|
80
|
+
mutationFn: (body) => client.auth.forgot(body),
|
|
81
|
+
}),
|
|
82
|
+
useResetPassword: () => useMutation({
|
|
83
|
+
mutationFn: (body) => client.auth.reset(body),
|
|
84
|
+
}),
|
|
85
|
+
useNotifications: () => useQuery({
|
|
86
|
+
queryKey: notificationsQueryKey,
|
|
87
|
+
queryFn: () => client.notifications.list(),
|
|
88
|
+
}),
|
|
89
|
+
useMarkNotificationRead: () => {
|
|
90
|
+
const qc = useQueryClient();
|
|
91
|
+
return useMutation({
|
|
92
|
+
mutationFn: (id) => client.notifications.markRead(id),
|
|
93
|
+
onSuccess: () => {
|
|
94
|
+
void qc.invalidateQueries({ queryKey: notificationsQueryKey });
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
useNotificationsLive: () => {
|
|
99
|
+
const qc = useQueryClient();
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
let close;
|
|
102
|
+
void client.connectRealtime().then((socket) => {
|
|
103
|
+
socket.on(RealtimeEvent.NOTIFICATION_CREATED, () => {
|
|
104
|
+
void qc.invalidateQueries({ queryKey: notificationsQueryKey });
|
|
105
|
+
});
|
|
106
|
+
close = socket.close;
|
|
107
|
+
});
|
|
108
|
+
return () => close?.();
|
|
109
|
+
}, [qc]);
|
|
110
|
+
},
|
|
111
|
+
useAuditLogs: (query, enabled = true) => useQuery({
|
|
112
|
+
queryKey: [...auditQueryKey, query],
|
|
113
|
+
queryFn: () => client.audit.list(query),
|
|
114
|
+
enabled,
|
|
115
|
+
retry: false,
|
|
116
|
+
}),
|
|
117
|
+
useApiKeys: () => useQuery({
|
|
118
|
+
queryKey: apiKeysQueryKey,
|
|
119
|
+
queryFn: () => client.apiKeys.list(),
|
|
120
|
+
}),
|
|
121
|
+
useCreateApiKey: () => {
|
|
122
|
+
const qc = useQueryClient();
|
|
123
|
+
return useMutation({
|
|
124
|
+
mutationFn: (body) => client.apiKeys.create(body),
|
|
125
|
+
onSuccess: () => {
|
|
126
|
+
void qc.invalidateQueries({ queryKey: apiKeysQueryKey });
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
useRevokeApiKey: () => {
|
|
131
|
+
const qc = useQueryClient();
|
|
132
|
+
return useMutation({
|
|
133
|
+
mutationFn: (id) => client.apiKeys.revoke(id),
|
|
134
|
+
onSuccess: () => {
|
|
135
|
+
void qc.invalidateQueries({ queryKey: apiKeysQueryKey });
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
export { billingQueryKey, createBillingHooks } from './billing-hooks';
|
|
142
|
+
export { createLlmHooks } from './llm-hooks';
|
|
143
|
+
export { createOrganizationHooks, organizationQueryKey, organizationsQueryKey, } from './organizations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,GACtB,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
3
|
+
import { renderHook, waitFor } from '@testing-library/react';
|
|
4
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
5
|
+
import { createUserHooks } from './index';
|
|
6
|
+
const wrapper = ({ children }) => {
|
|
7
|
+
const client = new QueryClient({
|
|
8
|
+
defaultOptions: { queries: { retry: false }, mutations: { retry: false } },
|
|
9
|
+
});
|
|
10
|
+
return _jsx(QueryClientProvider, { client: client, children: children });
|
|
11
|
+
};
|
|
12
|
+
describe('createUserHooks', () => {
|
|
13
|
+
it('loads users through the client', async () => {
|
|
14
|
+
const list = vi.fn().mockResolvedValue({ items: [], nextCursor: null });
|
|
15
|
+
const hooks = createUserHooks({ users: { list } });
|
|
16
|
+
const { result } = renderHook(() => hooks.useUsers({ limit: 10 }), { wrapper });
|
|
17
|
+
await waitFor(() => expect(result.current.isSuccess).toBe(true));
|
|
18
|
+
expect(list).toHaveBeenCalledWith({ limit: 10 });
|
|
19
|
+
});
|
|
20
|
+
it('logs in through the client', async () => {
|
|
21
|
+
const login = vi.fn().mockResolvedValue({ accessToken: 'a' });
|
|
22
|
+
const hooks = createUserHooks({ auth: { login } });
|
|
23
|
+
const { result } = renderHook(() => hooks.useLogin(), { wrapper });
|
|
24
|
+
result.current.mutate({ email: 'a@ysk.hk', password: 'password1' });
|
|
25
|
+
await waitFor(() => expect(result.current.isSuccess).toBe(true));
|
|
26
|
+
expect(login).toHaveBeenCalled();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=index.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACjE,MAAM,CAAC,IAAI,CAAC,CAAC,oBAAoB,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;QAC1C,MAAM,KAAK,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC;QAC9D,MAAM,KAAK,GAAG,eAAe,CAAC,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,EAAW,CAAC,CAAC;QAC5D,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QACnE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAC;QACpE,MAAM,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACjE,MAAM,CAAC,KAAK,CAAC,CAAC,gBAAgB,EAAE,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { YskClient } from '@ysk-kit/sdk';
|
|
2
|
+
export declare function createLlmHooks(client: YskClient): {
|
|
3
|
+
useLlmComplete: () => import("@tanstack/react-query").UseMutationResult<{
|
|
4
|
+
text: string;
|
|
5
|
+
model: string;
|
|
6
|
+
usage: {
|
|
7
|
+
promptTokens: number;
|
|
8
|
+
completionTokens: number;
|
|
9
|
+
totalTokens: number;
|
|
10
|
+
};
|
|
11
|
+
}, Error, {
|
|
12
|
+
messages: {
|
|
13
|
+
role: "user" | "system" | "assistant";
|
|
14
|
+
content: string;
|
|
15
|
+
}[];
|
|
16
|
+
temperature?: number | undefined;
|
|
17
|
+
}, unknown>;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=llm-hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-hooks.d.ts","sourceRoot":"","sources":["../src/llm-hooks.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS;;;;;;;;;;;;;;;;EAO/C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-hooks.js","sourceRoot":"","sources":["../src/llm-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAIpD,MAAM,UAAU,cAAc,CAAC,MAAiB;IAC9C,OAAO;QACL,cAAc,EAAE,GAAG,EAAE,CACnB,WAAW,CAAC;YACV,UAAU,EAAE,CAAC,IAAwB,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;SACpE,CAAC;KACL,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { YskClient } from '@ysk-kit/sdk';
|
|
2
|
+
export declare const organizationsQueryKey: readonly ["organizations"];
|
|
3
|
+
export declare const organizationQueryKey: (id: string) => readonly ["organization", string];
|
|
4
|
+
export declare function createOrganizationHooks(client: YskClient): {
|
|
5
|
+
useOrganizations: () => import("@tanstack/react-query").UseQueryResult<{
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
createdAt: string;
|
|
9
|
+
}[], Error>;
|
|
10
|
+
useOrganization: (id: string) => import("@tanstack/react-query").UseQueryResult<{
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
createdAt: string;
|
|
14
|
+
}, Error>;
|
|
15
|
+
useOrganizationMembers: (id: string) => import("@tanstack/react-query").UseQueryResult<{
|
|
16
|
+
id: string;
|
|
17
|
+
organizationId: string;
|
|
18
|
+
userId: string;
|
|
19
|
+
email: string | null;
|
|
20
|
+
displayName: string;
|
|
21
|
+
role: "ADMIN" | "OWNER" | "MEMBER";
|
|
22
|
+
createdAt: string;
|
|
23
|
+
}[], Error>;
|
|
24
|
+
useOrganizationInvites: (id: string, enabled?: boolean) => import("@tanstack/react-query").UseQueryResult<{
|
|
25
|
+
id: string;
|
|
26
|
+
organizationId: string;
|
|
27
|
+
email: string;
|
|
28
|
+
role: "ADMIN" | "MEMBER";
|
|
29
|
+
createdAt: string;
|
|
30
|
+
expiresAt: string;
|
|
31
|
+
}[], Error>;
|
|
32
|
+
useCreateOrganization: () => import("@tanstack/react-query").UseMutationResult<{
|
|
33
|
+
id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
createdAt: string;
|
|
36
|
+
}, Error, {
|
|
37
|
+
name: string;
|
|
38
|
+
}, unknown>;
|
|
39
|
+
useInviteMember: (organizationId: string) => import("@tanstack/react-query").UseMutationResult<{
|
|
40
|
+
id: string;
|
|
41
|
+
organizationId: string;
|
|
42
|
+
email: string;
|
|
43
|
+
role: "ADMIN" | "MEMBER";
|
|
44
|
+
createdAt: string;
|
|
45
|
+
expiresAt: string;
|
|
46
|
+
}, Error, {
|
|
47
|
+
email: string;
|
|
48
|
+
role: "ADMIN" | "MEMBER";
|
|
49
|
+
}, unknown>;
|
|
50
|
+
useRemoveMember: (organizationId: string) => import("@tanstack/react-query").UseMutationResult<{
|
|
51
|
+
removed: true;
|
|
52
|
+
}, Error, string, unknown>;
|
|
53
|
+
useLeaveOrganization: () => import("@tanstack/react-query").UseMutationResult<{
|
|
54
|
+
left: true;
|
|
55
|
+
}, Error, string, unknown>;
|
|
56
|
+
useAcceptInvite: () => import("@tanstack/react-query").UseMutationResult<{
|
|
57
|
+
accepted: true;
|
|
58
|
+
}, Error, {
|
|
59
|
+
token: string;
|
|
60
|
+
password?: string | undefined;
|
|
61
|
+
displayName?: string | undefined;
|
|
62
|
+
}, unknown>;
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=organizations-hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"organizations-hooks.d.ts","sourceRoot":"","sources":["../src/organizations-hooks.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,eAAO,MAAM,qBAAqB,4BAA6B,CAAC;AAChE,eAAO,MAAM,oBAAoB,GAAI,IAAI,MAAM,sCAAkC,CAAC;AAElF,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS;;;;;;0BAO/B,MAAM;;;;;iCAMC,MAAM;;;;;;;;;iCAMN,MAAM;;;;;;;;;;;;;;;sCAgBD,MAAM;;;;;;;;;;;sCAUN,MAAM;;;;;;;;;;;;;EAuB3C"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
2
|
+
export const organizationsQueryKey = ['organizations'];
|
|
3
|
+
export const organizationQueryKey = (id) => ['organization', id];
|
|
4
|
+
export function createOrganizationHooks(client) {
|
|
5
|
+
return {
|
|
6
|
+
useOrganizations: () => useQuery({
|
|
7
|
+
queryKey: organizationsQueryKey,
|
|
8
|
+
queryFn: () => client.organizations.list(),
|
|
9
|
+
}),
|
|
10
|
+
useOrganization: (id) => useQuery({
|
|
11
|
+
queryKey: organizationQueryKey(id),
|
|
12
|
+
queryFn: () => client.organizations.get(id),
|
|
13
|
+
enabled: id.length > 0,
|
|
14
|
+
}),
|
|
15
|
+
useOrganizationMembers: (id) => useQuery({
|
|
16
|
+
queryKey: [...organizationQueryKey(id), 'members'],
|
|
17
|
+
queryFn: () => client.organizations.members(id),
|
|
18
|
+
enabled: id.length > 0,
|
|
19
|
+
}),
|
|
20
|
+
useOrganizationInvites: (id, enabled = true) => useQuery({
|
|
21
|
+
queryKey: [...organizationQueryKey(id), 'invites'],
|
|
22
|
+
queryFn: () => client.organizations.invites(id),
|
|
23
|
+
enabled: id.length > 0 && enabled,
|
|
24
|
+
retry: false,
|
|
25
|
+
}),
|
|
26
|
+
useCreateOrganization: () => {
|
|
27
|
+
const qc = useQueryClient();
|
|
28
|
+
return useMutation({
|
|
29
|
+
mutationFn: (body) => client.organizations.create(body),
|
|
30
|
+
onSuccess: () => {
|
|
31
|
+
void qc.invalidateQueries({ queryKey: organizationsQueryKey });
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
useInviteMember: (organizationId) => {
|
|
36
|
+
const qc = useQueryClient();
|
|
37
|
+
return useMutation({
|
|
38
|
+
mutationFn: (body) => client.organizations.invite(organizationId, body),
|
|
39
|
+
onSuccess: () => {
|
|
40
|
+
void qc.invalidateQueries({ queryKey: organizationQueryKey(organizationId) });
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
useRemoveMember: (organizationId) => {
|
|
45
|
+
const qc = useQueryClient();
|
|
46
|
+
return useMutation({
|
|
47
|
+
mutationFn: (userId) => client.organizations.removeMember(organizationId, userId),
|
|
48
|
+
onSuccess: () => {
|
|
49
|
+
void qc.invalidateQueries({ queryKey: organizationQueryKey(organizationId) });
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
useLeaveOrganization: () => {
|
|
54
|
+
const qc = useQueryClient();
|
|
55
|
+
return useMutation({
|
|
56
|
+
mutationFn: (organizationId) => client.organizations.leave(organizationId),
|
|
57
|
+
onSuccess: () => {
|
|
58
|
+
void qc.invalidateQueries({ queryKey: organizationsQueryKey });
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
useAcceptInvite: () => useMutation({
|
|
63
|
+
mutationFn: (body) => client.organizations.acceptInvite(body),
|
|
64
|
+
}),
|
|
65
|
+
};
|
|
66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AC;gBACzF,SAAS,EAAE,GAAG,EAAE;oBACd,KAAK,EAAE,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,oBAAoB,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;gBAChF,CAAC;aACF,CAAC,CAAC;QACL,CAAC;QACD,oBAAoB,EAAE,GAAG,EAAE;YACzB,MAAM,EAAE,GAAG,cAAc,EAAE,CAAC;YAC5B,OAAO,WAAW,CAAC;gBACjB,UAAU,EAAE,CAAC,cAAsB,EAAE,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,cAAc,CAAC;gBAClF,SAAS,EAAE,GAAG,EAAE;oBACd,KAAK,EAAE,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,qBAAqB,EAAE,CAAC,CAAC;gBACjE,CAAC;aACF,CAAC,CAAC;QACL,CAAC;QACD,eAAe,EAAE,GAAG,EAAE,CACpB,WAAW,CAAC;YACV,UAAU,EAAE,CAAC,IAAyB,EAAE,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC;SACnF,CAAC;KACL,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ysk-kit/web-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@ysk-kit/contracts": "1.0.0",
|
|
15
|
+
"@ysk-kit/sdk": "1.0.0"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@tanstack/react-query": "^5.75.0",
|
|
19
|
+
"react": "^19.0.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^24.5.2",
|
|
23
|
+
"@tanstack/react-query": "^5.75.0",
|
|
24
|
+
"@testing-library/react": "^16.3.0",
|
|
25
|
+
"@types/react": "^19.1.2",
|
|
26
|
+
"@vitejs/plugin-react": "^6.1.1",
|
|
27
|
+
"happy-dom": "^20.0.0",
|
|
28
|
+
"react": "19.2.3",
|
|
29
|
+
"typescript": "^6.0.3",
|
|
30
|
+
"vitest": "^5.0.2"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"registry": "https://registry.npmjs.org",
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
41
|
+
"test": "vitest run --passWithNoTests",
|
|
42
|
+
"build": "tsc -p tsconfig.build.json"
|
|
43
|
+
}
|
|
44
|
+
}
|