@conferencesuite/react 0.0.0-stage → 0.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 +202 -0
- package/NOTICE +9 -0
- package/README.md +11 -2
- package/dist/AuthProvider.d.ts +44 -0
- package/dist/AuthProvider.js +145 -0
- package/dist/AuthProvider.js.map +1 -0
- package/dist/useAgenda.d.ts +16 -0
- package/dist/useAgenda.js +121 -0
- package/dist/useAgenda.js.map +1 -0
- package/dist/useMediaQuery.d.ts +2 -0
- package/dist/useMediaQuery.js +14 -0
- package/dist/useMediaQuery.js.map +1 -0
- package/dist/useProposalForm.d.ts +36 -0
- package/dist/useProposalForm.js +94 -0
- package/dist/useProposalForm.js.map +1 -0
- package/dist/useRegistration.d.ts +95 -0
- package/dist/useRegistration.js +158 -0
- package/dist/useRegistration.js.map +1 -0
- package/dist/useSchedule.d.ts +21 -0
- package/dist/useSchedule.js +62 -0
- package/dist/useSchedule.js.map +1 -0
- package/dist/useStableConfig.d.ts +8 -0
- package/dist/useStableConfig.js +16 -0
- package/dist/useStableConfig.js.map +1 -0
- package/package.json +39 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
package/NOTICE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Conference Suite SDK
|
|
2
|
+
Copyright 2026 Tunji Productions LLC
|
|
3
|
+
|
|
4
|
+
This product includes software developed by Tunji Productions LLC
|
|
5
|
+
(https://github.com/conferencesuite).
|
|
6
|
+
|
|
7
|
+
"Conference Suite" and the Conference Suite logo are trademarks of
|
|
8
|
+
Tunji Productions LLC and are not licensed under the Apache License; see
|
|
9
|
+
TRADEMARKS.md.
|
package/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @conferencesuite/react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React hooks over [`@conferencesuite/core`](../core).
|
|
4
|
+
|
|
5
|
+
> Pre-release (`0.x`): minor versions may contain breaking changes. See the
|
|
6
|
+
> [support policy](https://github.com/conferencesuite/sdk/blob/main/docs/support-policy.md).
|
|
7
|
+
|
|
8
|
+
Part of the [Conference Suite SDK](https://github.com/conferencesuite/sdk). Licensed under Apache-2.0.
|
|
9
|
+
Every rule (limits, pricing, paid state) lives in the Conference Suite's database; this package calls the API
|
|
10
|
+
and renders the answer.
|
|
11
|
+
|
|
12
|
+
Deep imports are supported: `import { ... } from "@conferencesuite/react/<path>"`.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { SupabaseClient, User } from "@supabase/supabase-js";
|
|
2
|
+
import { AuthState, Mode } from "@conferencesuite/core/auth/machine";
|
|
3
|
+
import { SuiteConfig } from "@conferencesuite/core/types";
|
|
4
|
+
export type AuthApi = {
|
|
5
|
+
state: AuthState;
|
|
6
|
+
/** The signed-in user, or null. Only meaningful once `ready`. */
|
|
7
|
+
user: User | null;
|
|
8
|
+
/** False until the session has been read on the client (avoids a signed-out flash). */
|
|
9
|
+
ready: boolean;
|
|
10
|
+
/** A message to announce after the dialog closes ("Welcome back", "Check your email"). */
|
|
11
|
+
notice: string | null;
|
|
12
|
+
dismissNotice: () => void;
|
|
13
|
+
/** The Bearer token for the suite's API, or null when signed out. */
|
|
14
|
+
accessToken: () => Promise<string | null>;
|
|
15
|
+
/** The org-scoped Supabase client (RLS reads the member's own row with it). Client only. */
|
|
16
|
+
supabase: () => SupabaseClient;
|
|
17
|
+
/** Where focus goes when the dialog closes: whatever opened it. */
|
|
18
|
+
returnFocusEl: () => HTMLElement | null;
|
|
19
|
+
open: (mode?: Mode) => void;
|
|
20
|
+
close: () => void;
|
|
21
|
+
setMode: (mode: Mode) => void;
|
|
22
|
+
back: () => void;
|
|
23
|
+
checkEmail: (email: string) => Promise<void>;
|
|
24
|
+
signIn: (v: {
|
|
25
|
+
email: string;
|
|
26
|
+
password: string;
|
|
27
|
+
}) => Promise<void>;
|
|
28
|
+
signUp: (v: {
|
|
29
|
+
email: string;
|
|
30
|
+
password: string;
|
|
31
|
+
fname: string;
|
|
32
|
+
lname: string;
|
|
33
|
+
institution: string;
|
|
34
|
+
}) => Promise<void>;
|
|
35
|
+
reset: (email: string) => Promise<void>;
|
|
36
|
+
signOut: () => Promise<void>;
|
|
37
|
+
};
|
|
38
|
+
export declare function AuthProvider({ config: rawConfig, onSignedIn, children }: {
|
|
39
|
+
config: SuiteConfig;
|
|
40
|
+
/** Called after a successful sign-in or sign-up that returned a session. */
|
|
41
|
+
onSignedIn?: (user: User) => void;
|
|
42
|
+
children: React.ReactNode;
|
|
43
|
+
}): import("react").JSX.Element;
|
|
44
|
+
export declare function useAuth(): AuthApi;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useReducer, useRef, useState } from "react";
|
|
3
|
+
import { createSuiteSession } from "@conferencesuite/core/auth/session";
|
|
4
|
+
import { createAuthService } from "@conferencesuite/core/auth/service";
|
|
5
|
+
import { initialAuthState, reduce } from "@conferencesuite/core/auth/machine";
|
|
6
|
+
import { SuiteError } from "@conferencesuite/core/errors";
|
|
7
|
+
import { useStableConfig } from "./useStableConfig.js";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
// src/AuthProvider.tsx
|
|
10
|
+
const AuthContext = createContext(null);
|
|
11
|
+
function AuthProvider({ config: rawConfig, onSignedIn, children }) {
|
|
12
|
+
const config = useStableConfig(rawConfig);
|
|
13
|
+
const [state, dispatch] = useReducer(reduce, initialAuthState);
|
|
14
|
+
const [user, setUser] = useState(null);
|
|
15
|
+
const [ready, setReady] = useState(false);
|
|
16
|
+
const [notice, setNotice] = useState(null);
|
|
17
|
+
const sessionRef = useRef(null);
|
|
18
|
+
const getSession = useCallback(() => {
|
|
19
|
+
if (!sessionRef.current) {
|
|
20
|
+
const session = createSuiteSession(config);
|
|
21
|
+
sessionRef.current = {
|
|
22
|
+
svc: createAuthService(config, session),
|
|
23
|
+
supabase: session.supabase,
|
|
24
|
+
ensureCookieDomain: session.ensureCookieDomain
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return sessionRef.current;
|
|
28
|
+
}, [config]);
|
|
29
|
+
const returnFocusRef = useRef(null);
|
|
30
|
+
const onSignedInRef = useRef(onSignedIn);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
onSignedInRef.current = onSignedIn;
|
|
33
|
+
});
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const { svc, ensureCookieDomain } = getSession();
|
|
36
|
+
let alive = true;
|
|
37
|
+
svc.getUser().then((u) => {
|
|
38
|
+
if (alive) {
|
|
39
|
+
setUser(u);
|
|
40
|
+
setReady(true);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const off = svc.onChange((u) => alive && setUser(u));
|
|
44
|
+
ensureCookieDomain();
|
|
45
|
+
return () => {
|
|
46
|
+
alive = false;
|
|
47
|
+
off();
|
|
48
|
+
};
|
|
49
|
+
}, [getSession]);
|
|
50
|
+
const run = useCallback(async (fn) => {
|
|
51
|
+
dispatch({ type: "busy" });
|
|
52
|
+
try {
|
|
53
|
+
await fn(getSession().svc);
|
|
54
|
+
} catch (e) {
|
|
55
|
+
dispatch({
|
|
56
|
+
type: "failed",
|
|
57
|
+
message: e instanceof SuiteError ? e.message : "Something went wrong. Try again."
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}, [getSession]);
|
|
61
|
+
const api = useMemo(() => ({
|
|
62
|
+
state,
|
|
63
|
+
user,
|
|
64
|
+
ready,
|
|
65
|
+
notice,
|
|
66
|
+
dismissNotice: () => setNotice(null),
|
|
67
|
+
accessToken: () => getSession().svc.getAccessToken(),
|
|
68
|
+
supabase: () => getSession().supabase,
|
|
69
|
+
returnFocusEl: () => returnFocusRef.current?.isConnected ? returnFocusRef.current : null,
|
|
70
|
+
open: (mode) => {
|
|
71
|
+
returnFocusRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
72
|
+
dispatch({
|
|
73
|
+
type: "open",
|
|
74
|
+
mode
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
close: () => dispatch({ type: "close" }),
|
|
78
|
+
setMode: (mode) => dispatch({
|
|
79
|
+
type: "setMode",
|
|
80
|
+
mode
|
|
81
|
+
}),
|
|
82
|
+
back: () => dispatch({ type: "back" }),
|
|
83
|
+
checkEmail: async (email) => {
|
|
84
|
+
dispatch({
|
|
85
|
+
type: "emailChecking",
|
|
86
|
+
email
|
|
87
|
+
});
|
|
88
|
+
dispatch({
|
|
89
|
+
type: "emailChecked",
|
|
90
|
+
check: await getSession().svc.checkEmail(email)
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
signIn: ({ email, password }) => run(async (svc) => {
|
|
94
|
+
const { user: u, linkError } = await svc.signIn({
|
|
95
|
+
email,
|
|
96
|
+
password,
|
|
97
|
+
linking: state.linking
|
|
98
|
+
});
|
|
99
|
+
dispatch({ type: "done" });
|
|
100
|
+
setNotice(linkError ? `Signed in, but we could not add your account to this organization: ${linkError}.` : "Welcome back!");
|
|
101
|
+
onSignedInRef.current?.(u);
|
|
102
|
+
}),
|
|
103
|
+
signUp: (v) => run(async (svc) => {
|
|
104
|
+
const res = await svc.signUp({
|
|
105
|
+
...v,
|
|
106
|
+
linking: state.linking
|
|
107
|
+
});
|
|
108
|
+
dispatch({ type: "done" });
|
|
109
|
+
if (res.kind === "confirmEmail") setNotice("Check your email and open the confirmation link, then come back and sign in.");
|
|
110
|
+
else {
|
|
111
|
+
setNotice(res.linkError ? `Welcome! We could not add your account to this organization: ${res.linkError}.` : "Welcome!");
|
|
112
|
+
onSignedInRef.current?.(res.user);
|
|
113
|
+
}
|
|
114
|
+
}),
|
|
115
|
+
reset: (email) => run(async (svc) => {
|
|
116
|
+
await svc.resetPassword(email);
|
|
117
|
+
dispatch({ type: "done" });
|
|
118
|
+
setNotice("If an account exists for that email, a reset link is on its way. It opens Conference Suite, where you choose a new password; then sign in here again.");
|
|
119
|
+
}),
|
|
120
|
+
signOut: async () => {
|
|
121
|
+
await getSession().svc.signOut();
|
|
122
|
+
setUser(null);
|
|
123
|
+
setNotice("You are signed out.");
|
|
124
|
+
}
|
|
125
|
+
}), [
|
|
126
|
+
state,
|
|
127
|
+
user,
|
|
128
|
+
ready,
|
|
129
|
+
notice,
|
|
130
|
+
getSession,
|
|
131
|
+
run
|
|
132
|
+
]);
|
|
133
|
+
return /* @__PURE__ */ jsx(AuthContext.Provider, {
|
|
134
|
+
value: api,
|
|
135
|
+
children
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function useAuth() {
|
|
139
|
+
const ctx = useContext(AuthContext);
|
|
140
|
+
if (!ctx) throw new Error("useAuth must be used inside <AuthProvider>");
|
|
141
|
+
return ctx;
|
|
142
|
+
}
|
|
143
|
+
export { AuthProvider, useAuth };
|
|
144
|
+
|
|
145
|
+
//# sourceMappingURL=AuthProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthProvider.js","names":[],"sources":["../src/AuthProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport type { SupabaseClient, User } from \"@supabase/supabase-js\";\nimport { createContext, useCallback, useContext, useEffect, useMemo, useReducer, useRef, useState } from \"react\";\nimport { createSuiteSession } from \"@conferencesuite/core/auth/session\";\nimport { type AuthService, createAuthService } from \"@conferencesuite/core/auth/service\";\nimport { type AuthState, type Mode, initialAuthState, reduce } from \"@conferencesuite/core/auth/machine\";\nimport { SuiteError } from \"@conferencesuite/core/errors\";\nimport { useStableConfig } from \"./useStableConfig\";\nimport type { SuiteConfig } from \"@conferencesuite/core/types\";\n\nexport type AuthApi = {\n state: AuthState;\n /** The signed-in user, or null. Only meaningful once `ready`. */\n user: User | null;\n /** False until the session has been read on the client (avoids a signed-out flash). */\n ready: boolean;\n /** A message to announce after the dialog closes (\"Welcome back\", \"Check your email\"). */\n notice: string | null;\n dismissNotice: () => void;\n /** The Bearer token for the suite's API, or null when signed out. */\n accessToken: () => Promise<string | null>;\n /** The org-scoped Supabase client (RLS reads the member's own row with it). Client only. */\n supabase: () => SupabaseClient;\n /** Where focus goes when the dialog closes: whatever opened it. */\n returnFocusEl: () => HTMLElement | null;\n open: (mode?: Mode) => void;\n close: () => void;\n setMode: (mode: Mode) => void;\n back: () => void;\n checkEmail: (email: string) => Promise<void>;\n signIn: (v: { email: string; password: string }) => Promise<void>;\n signUp: (v: { email: string; password: string; fname: string; lname: string; institution: string }) => Promise<void>;\n reset: (email: string) => Promise<void>;\n signOut: () => Promise<void>;\n};\n\nconst AuthContext = createContext<AuthApi | null>(null);\n\nexport function AuthProvider({\n config: rawConfig,\n onSignedIn,\n children,\n}: {\n config: SuiteConfig;\n /** Called after a successful sign-in or sign-up that returned a session. */\n onSignedIn?: (user: User) => void;\n children: React.ReactNode;\n}) {\n const config = useStableConfig(rawConfig);\n const [state, dispatch] = useReducer(reduce, initialAuthState);\n const [user, setUser] = useState<User | null>(null);\n const [ready, setReady] = useState(false);\n const [notice, setNotice] = useState<string | null>(null);\n // Created on first use (an effect or a click), so it never runs during server rendering\n const sessionRef = useRef<{ svc: AuthService; supabase: SupabaseClient; ensureCookieDomain: () => Promise<void> } | null>(null);\n const getSession = useCallback(() => {\n if (!sessionRef.current) {\n const session = createSuiteSession(config);\n sessionRef.current = { svc: createAuthService(config, session), supabase: session.supabase, ensureCookieDomain: session.ensureCookieDomain };\n }\n return sessionRef.current;\n }, [config]);\n const returnFocusRef = useRef<HTMLElement | null>(null);\n const onSignedInRef = useRef(onSignedIn);\n useEffect(() => {\n onSignedInRef.current = onSignedIn;\n });\n\n // Client only: the Supabase browser client needs the browser (and the env on the page).\n useEffect(() => {\n const { svc, ensureCookieDomain } = getSession();\n let alive = true;\n svc.getUser().then((u) => {\n if (alive) {\n setUser(u);\n setReady(true);\n }\n });\n const off = svc.onChange((u) => alive && setUser(u));\n // Resolve the shared cookie domain early so the first sign-in already has it\n void ensureCookieDomain();\n return () => {\n alive = false;\n off();\n };\n }, [getSession]);\n\n const run = useCallback(\n async (fn: (svc: AuthService) => Promise<void>) => {\n dispatch({ type: \"busy\" });\n try {\n await fn(getSession().svc);\n } catch (e) {\n dispatch({ type: \"failed\", message: e instanceof SuiteError ? e.message : \"Something went wrong. Try again.\" });\n }\n },\n [getSession],\n );\n\n const api = useMemo<AuthApi>(\n () => ({\n state,\n user,\n ready,\n notice,\n dismissNotice: () => setNotice(null),\n accessToken: () => getSession().svc.getAccessToken(),\n supabase: () => getSession().supabase,\n returnFocusEl: () => (returnFocusRef.current?.isConnected ? returnFocusRef.current : null),\n open: (mode) => {\n returnFocusRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;\n dispatch({ type: \"open\", mode });\n },\n close: () => dispatch({ type: \"close\" }),\n setMode: (mode) => dispatch({ type: \"setMode\", mode }),\n back: () => dispatch({ type: \"back\" }),\n\n checkEmail: async (email) => {\n dispatch({ type: \"emailChecking\", email });\n dispatch({ type: \"emailChecked\", check: await getSession().svc.checkEmail(email) });\n },\n\n signIn: ({ email, password }) =>\n run(async (svc) => {\n const { user: u, linkError } = await svc.signIn({ email, password, linking: state.linking });\n dispatch({ type: \"done\" });\n setNotice(linkError ? `Signed in, but we could not add your account to this organization: ${linkError}.` : \"Welcome back!\");\n onSignedInRef.current?.(u);\n }),\n\n signUp: (v) =>\n run(async (svc) => {\n const res = await svc.signUp({ ...v, linking: state.linking });\n dispatch({ type: \"done\" });\n if (res.kind === \"confirmEmail\") {\n setNotice(\"Check your email and open the confirmation link, then come back and sign in.\");\n } else {\n setNotice(res.linkError ? `Welcome! We could not add your account to this organization: ${res.linkError}.` : \"Welcome!\");\n onSignedInRef.current?.(res.user);\n }\n }),\n\n reset: (email) =>\n run(async (svc) => {\n // No redirectTo: the suite's email function decides where the link goes (the Conference Suite reset page)\n await svc.resetPassword(email);\n dispatch({ type: \"done\" });\n setNotice(\"If an account exists for that email, a reset link is on its way. It opens Conference Suite, where you choose a new password; then sign in here again.\");\n }),\n\n signOut: async () => {\n await getSession().svc.signOut();\n setUser(null);\n setNotice(\"You are signed out.\");\n },\n }),\n [state, user, ready, notice, getSession, run],\n );\n\n return <AuthContext.Provider value={api}>{children}</AuthContext.Provider>;\n}\n\nexport function useAuth(): AuthApi {\n const ctx = useContext(AuthContext);\n if (!ctx) throw new Error(\"useAuth must be used inside <AuthProvider>\");\n return ctx;\n}\n"],"mappings":";;;;;;;;;AAqCA,MAAM,cAAc,cAA8B,IAAI;AAEtD,SAAgB,aAAa,EAC3B,QAAQ,WACR,YACA,YAMC;CACD,MAAM,SAAS,gBAAgB,SAAS;CACxC,MAAM,CAAC,OAAO,YAAY,WAAW,QAAQ,gBAAgB;CAC7D,MAAM,CAAC,MAAM,WAAW,SAAsB,IAAI;CAClD,MAAM,CAAC,OAAO,YAAY,SAAS,KAAK;CACxC,MAAM,CAAC,QAAQ,aAAa,SAAwB,IAAI;CAExD,MAAM,aAAa,OAAuG,IAAI;CAC9H,MAAM,aAAa,kBAAkB;EACnC,IAAI,CAAC,WAAW,SAAS;GACvB,MAAM,UAAU,mBAAmB,MAAM;GACzC,WAAW,UAAU;IAAE,KAAK,kBAAkB,QAAQ,OAAO;IAAG,UAAU,QAAQ;IAAU,oBAAoB,QAAQ;GAAmB;EAC7I;EACA,OAAO,WAAW;CACpB,GAAG,CAAC,MAAM,CAAC;CACX,MAAM,iBAAiB,OAA2B,IAAI;CACtD,MAAM,gBAAgB,OAAO,UAAU;CACvC,gBAAgB;EACd,cAAc,UAAU;CAC1B,CAAC;CAGD,gBAAgB;EACd,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,EAAE,MAAM,GAAG,cAAc,MAAM,IAAI,OAAO;IAAE;IAAO;IAAU,SAAS,MAAM;GAAQ,CAAC;GAC3F,SAAS,EAAE,MAAM,OAAO,CAAC;GACzB,UAAU,YAAY,sEAAsE,UAAU,KAAK,eAAe;GAC1H,cAAc,UAAU,CAAC;EAC3B,CAAC;EAEH,SAAS,MACP,IAAI,OAAO,QAAQ;GACjB,MAAM,MAAM,MAAM,IAAI,OAAO;IAAE,GAAG;IAAG,SAAS,MAAM;GAAQ,CAAC;GAC7D,SAAS,EAAE,MAAM,OAAO,CAAC;GACzB,IAAI,IAAI,SAAS,gBACf,UAAU,8EAA8E;QACnF;IACL,UAAU,IAAI,YAAY,gEAAgE,IAAI,UAAU,KAAK,UAAU;IACvH,cAAc,UAAU,IAAI,IAAI;GAClC;EACF,CAAC;EAEH,QAAQ,UACN,IAAI,OAAO,QAAQ;GAEjB,MAAM,IAAI,cAAc,KAAK;GAC7B,SAAS,EAAE,MAAM,OAAO,CAAC;GACzB,UAAU,uJAAuJ;EACnK,CAAC;EAEH,SAAS,YAAY;GACnB,MAAM,WAAW,CAAC,CAAC,IAAI,QAAQ;GAC/B,QAAQ,IAAI;GACZ,UAAU,qBAAqB;EACjC;CACF,IACA;EAAC;EAAO;EAAM;EAAO;EAAQ;EAAY;CAAG,CAC9C;CAEA,OAAO,oBAAC,YAAY,UAAb;EAAsB,OAAO;EAAM;CAA+B,CAAA;AAC3E;AAEA,SAAgB,UAAmB;CACjC,MAAM,MAAM,WAAW,WAAW;CAClC,IAAI,CAAC,KAAK,MAAM,IAAI,MAAM,4CAA4C;CACtE,OAAO;AACT"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Schedule } from "@conferencesuite/core/schedule/types";
|
|
2
|
+
import { SuiteConfig } from "@conferencesuite/core/types";
|
|
3
|
+
export type SyncState = "local" | "syncing" | "synced" | "failed";
|
|
4
|
+
/**
|
|
5
|
+
* "My schedule": local-first (works signed out, updates instantly) and, signed in, synced with
|
|
6
|
+
* the suite. On sign-in it merges this device's picks with the account's (3-way, so removals
|
|
7
|
+
* and adds both survive), then pushes changes a moment after each toggle.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useAgenda(rawConfig: SuiteConfig, schedule: Schedule | null): {
|
|
10
|
+
ids: Set<string>;
|
|
11
|
+
toggle: (id: string) => void;
|
|
12
|
+
sync: SyncState;
|
|
13
|
+
feedUrl: string | null;
|
|
14
|
+
signedIn: boolean;
|
|
15
|
+
retrySync: () => Promise<void>;
|
|
16
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { createAgendaStore, mergeAgenda, pruneAgenda } from "@conferencesuite/core/schedule/agenda";
|
|
4
|
+
import { getMyAgenda, putMyAgenda } from "@conferencesuite/core/schedule/api";
|
|
5
|
+
import { useAuth } from "./AuthProvider.js";
|
|
6
|
+
import { useStableConfig } from "./useStableConfig.js";
|
|
7
|
+
// src/useAgenda.ts
|
|
8
|
+
const SAVE_DELAY_MS = 600;
|
|
9
|
+
/**
|
|
10
|
+
* "My schedule": local-first (works signed out, updates instantly) and, signed in, synced with
|
|
11
|
+
* the suite. On sign-in it merges this device's picks with the account's (3-way, so removals
|
|
12
|
+
* and adds both survive), then pushes changes a moment after each toggle.
|
|
13
|
+
*/
|
|
14
|
+
function useAgenda(rawConfig, schedule) {
|
|
15
|
+
const config = useStableConfig(rawConfig);
|
|
16
|
+
const auth = useAuth();
|
|
17
|
+
const store = useMemo(() => createAgendaStore(config.orgId, typeof window === "undefined" ? void 0 : window.localStorage), [config.orgId]);
|
|
18
|
+
const [ids, setIds] = useState([]);
|
|
19
|
+
const [feedUrl, setFeedUrl] = useState(null);
|
|
20
|
+
const [sync, setSync] = useState("local");
|
|
21
|
+
const base = useRef([]);
|
|
22
|
+
const idsRef = useRef([]);
|
|
23
|
+
const timer = useRef(null);
|
|
24
|
+
const tokenRef = useRef(auth.accessToken);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
tokenRef.current = auth.accessToken;
|
|
27
|
+
});
|
|
28
|
+
const userId = auth.user?.id ?? null;
|
|
29
|
+
const known = useMemo(() => schedule ? new Set(schedule.sessions.map((s) => s.id)) : null, [schedule]);
|
|
30
|
+
const commit = useCallback((next, nextBase = base.current) => {
|
|
31
|
+
idsRef.current = next;
|
|
32
|
+
base.current = nextBase;
|
|
33
|
+
setIds(next);
|
|
34
|
+
store.save({
|
|
35
|
+
ids: next,
|
|
36
|
+
base: nextBase
|
|
37
|
+
});
|
|
38
|
+
}, [store]);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
const s = store.load();
|
|
41
|
+
idsRef.current = s.ids;
|
|
42
|
+
base.current = s.base;
|
|
43
|
+
setIds(s.ids);
|
|
44
|
+
}, [store]);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (!known) return;
|
|
47
|
+
const kept = pruneAgenda(idsRef.current, known);
|
|
48
|
+
if (kept.length !== idsRef.current.length) commit(kept);
|
|
49
|
+
}, [known, commit]);
|
|
50
|
+
const push = useCallback(async () => {
|
|
51
|
+
const token = await tokenRef.current();
|
|
52
|
+
if (!token) return setSync("local");
|
|
53
|
+
setSync("syncing");
|
|
54
|
+
try {
|
|
55
|
+
const saved = await putMyAgenda(config, token, idsRef.current);
|
|
56
|
+
commit(idsRef.current, saved.session_ids);
|
|
57
|
+
setFeedUrl(saved.feed_url);
|
|
58
|
+
setSync("synced");
|
|
59
|
+
} catch {
|
|
60
|
+
setSync("failed");
|
|
61
|
+
}
|
|
62
|
+
}, [config, commit]);
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (!userId || !known) {
|
|
65
|
+
setSync("local");
|
|
66
|
+
setFeedUrl(null);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
let alive = true;
|
|
70
|
+
(async () => {
|
|
71
|
+
const token = await tokenRef.current();
|
|
72
|
+
if (!token) return;
|
|
73
|
+
setSync("syncing");
|
|
74
|
+
try {
|
|
75
|
+
const remote = await getMyAgenda(config, token);
|
|
76
|
+
if (!alive) return;
|
|
77
|
+
const merged = pruneAgenda(mergeAgenda(idsRef.current, remote.session_ids, base.current), known);
|
|
78
|
+
commit(merged, remote.session_ids);
|
|
79
|
+
setFeedUrl(remote.feed_url);
|
|
80
|
+
if (merged.length === remote.session_ids.length && merged.every((i) => remote.session_ids.includes(i))) return setSync("synced");
|
|
81
|
+
await push();
|
|
82
|
+
} catch {
|
|
83
|
+
if (alive) setSync("failed");
|
|
84
|
+
}
|
|
85
|
+
})();
|
|
86
|
+
return () => {
|
|
87
|
+
alive = false;
|
|
88
|
+
};
|
|
89
|
+
}, [
|
|
90
|
+
userId,
|
|
91
|
+
known,
|
|
92
|
+
config,
|
|
93
|
+
commit,
|
|
94
|
+
push
|
|
95
|
+
]);
|
|
96
|
+
const toggle = useCallback((id) => {
|
|
97
|
+
const next = idsRef.current.includes(id) ? idsRef.current.filter((i) => i !== id) : [...idsRef.current, id];
|
|
98
|
+
commit(next);
|
|
99
|
+
if (!userId) return;
|
|
100
|
+
if (timer.current) window.clearTimeout(timer.current);
|
|
101
|
+
timer.current = window.setTimeout(() => void push(), SAVE_DELAY_MS);
|
|
102
|
+
}, [
|
|
103
|
+
commit,
|
|
104
|
+
push,
|
|
105
|
+
userId
|
|
106
|
+
]);
|
|
107
|
+
useEffect(() => () => {
|
|
108
|
+
if (timer.current) window.clearTimeout(timer.current);
|
|
109
|
+
}, []);
|
|
110
|
+
return {
|
|
111
|
+
ids: useMemo(() => new Set(ids), [ids]),
|
|
112
|
+
toggle,
|
|
113
|
+
sync,
|
|
114
|
+
feedUrl,
|
|
115
|
+
signedIn: !!userId,
|
|
116
|
+
retrySync: push
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
export { useAgenda };
|
|
120
|
+
|
|
121
|
+
//# sourceMappingURL=useAgenda.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAgenda.js","names":[],"sources":["../src/useAgenda.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { createAgendaStore, mergeAgenda, pruneAgenda } from \"@conferencesuite/core/schedule/agenda\";\nimport { getMyAgenda, putMyAgenda } from \"@conferencesuite/core/schedule/api\";\nimport type { Schedule } from \"@conferencesuite/core/schedule/types\";\nimport type { SuiteConfig } from \"@conferencesuite/core/types\";\nimport { useAuth } from \"./AuthProvider\";\nimport { useStableConfig } from \"./useStableConfig\";\n\nexport type SyncState = \"local\" | \"syncing\" | \"synced\" | \"failed\";\n\nconst SAVE_DELAY_MS = 600;\n\n/**\n * \"My schedule\": local-first (works signed out, updates instantly) and, signed in, synced with\n * the suite. On sign-in it merges this device's picks with the account's (3-way, so removals\n * and adds both survive), then pushes changes a moment after each toggle.\n */\nexport function useAgenda(rawConfig: SuiteConfig, schedule: Schedule | null) {\n const config = useStableConfig(rawConfig);\n const auth = useAuth();\n const store = useMemo(() => createAgendaStore(config.orgId, typeof window === \"undefined\" ? undefined : window.localStorage), [config.orgId]);\n const [ids, setIds] = useState<string[]>([]);\n const [feedUrl, setFeedUrl] = useState<string | null>(null);\n const [sync, setSync] = useState<SyncState>(\"local\");\n const base = useRef<string[]>([]);\n const idsRef = useRef<string[]>([]);\n const timer = useRef<number | null>(null);\n const tokenRef = useRef(auth.accessToken);\n useEffect(() => {\n tokenRef.current = auth.accessToken;\n });\n const userId = auth.user?.id ?? null;\n\n const known = useMemo(() => (schedule ? new Set(schedule.sessions.map((s) => s.id)) : null), [schedule]);\n\n const commit = useCallback(\n (next: string[], nextBase = base.current) => {\n idsRef.current = next;\n base.current = nextBase;\n setIds(next);\n store.save({ ids: next, base: nextBase });\n },\n [store],\n );\n\n // Load what this device has\n useEffect(() => {\n const s = store.load();\n idsRef.current = s.ids;\n base.current = s.base;\n // eslint-disable-next-line react-hooks/set-state-in-effect -- reading localStorage after mount (SSR-safe)\n setIds(s.ids);\n }, [store]);\n\n // Drop sessions that are no longer published\n useEffect(() => {\n if (!known) return;\n const kept = pruneAgenda(idsRef.current, known);\n if (kept.length !== idsRef.current.length) commit(kept);\n }, [known, commit]);\n\n const push = useCallback(async () => {\n const token = await tokenRef.current();\n if (!token) return setSync(\"local\");\n setSync(\"syncing\");\n try {\n const saved = await putMyAgenda(config, token, idsRef.current);\n commit(idsRef.current, saved.session_ids);\n setFeedUrl(saved.feed_url);\n setSync(\"synced\");\n } catch {\n setSync(\"failed\");\n }\n }, [config, commit]);\n\n // Signed in: pull the account's agenda, merge, push what's new\n useEffect(() => {\n if (!userId || !known) {\n // eslint-disable-next-line react-hooks/set-state-in-effect -- signed out: local only\n setSync(\"local\");\n setFeedUrl(null);\n return;\n }\n let alive = true;\n (async () => {\n const token = await tokenRef.current();\n if (!token) return;\n setSync(\"syncing\");\n try {\n const remote = await getMyAgenda(config, token);\n if (!alive) return;\n const merged = pruneAgenda(mergeAgenda(idsRef.current, remote.session_ids, base.current), known);\n commit(merged, remote.session_ids);\n setFeedUrl(remote.feed_url);\n const same = merged.length === remote.session_ids.length && merged.every((i) => remote.session_ids.includes(i));\n if (same) return setSync(\"synced\");\n await push();\n } catch {\n if (alive) setSync(\"failed\");\n }\n })();\n return () => {\n alive = false;\n };\n }, [userId, known, config, commit, push]);\n\n const toggle = useCallback(\n (id: string) => {\n const next = idsRef.current.includes(id) ? idsRef.current.filter((i) => i !== id) : [...idsRef.current, id];\n commit(next);\n if (!userId) return;\n if (timer.current) window.clearTimeout(timer.current);\n timer.current = window.setTimeout(() => void push(), SAVE_DELAY_MS);\n },\n [commit, push, userId],\n );\n\n useEffect(\n () => () => {\n if (timer.current) window.clearTimeout(timer.current);\n },\n [],\n );\n\n const set = useMemo(() => new Set(ids), [ids]);\n return { ids: set, toggle, sync, feedUrl, signedIn: !!userId, retrySync: push };\n}\n"],"mappings":";;;;;;;AAYA,MAAM,gBAAgB;;;;;;AAOtB,SAAgB,UAAU,WAAwB,UAA2B;CAC3E,MA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M,OAAO;EACpD,MAAM,UAAU,OAAO,iBAAiB,KAAK,KAAK,GAAG,aAAa;CACpE,GACA;EAAC;EAAQ;EAAM;CAAM,CACvB;CAEA,sBACc;EACV,IAAI,MAAM,SAAS,OAAO,aAAa,MAAM,OAAO;CACtD,GACA,CAAC,CACH;CAGA,OAAO;EAAE,KADG,cAAc,IAAI,IAAI,GAAG,GAAG,CAAC,GAAG,CAC5B;EAAG;EAAQ;EAAM;EAAS,UAAU,CAAC,CAAC;EAAQ,WAAW;CAAK;AAChF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useSyncExternalStore } from "react";
|
|
3
|
+
// src/useMediaQuery.ts
|
|
4
|
+
/** Does the viewport match `query`? False on the server and until the browser answers. */
|
|
5
|
+
function useMediaQuery(query) {
|
|
6
|
+
return useSyncExternalStore((notify) => {
|
|
7
|
+
const m = window.matchMedia(query);
|
|
8
|
+
m.addEventListener("change", notify);
|
|
9
|
+
return () => m.removeEventListener("change", notify);
|
|
10
|
+
}, () => window.matchMedia(query).matches, () => false);
|
|
11
|
+
}
|
|
12
|
+
export { useMediaQuery };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=useMediaQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMediaQuery.js","names":[],"sources":["../src/useMediaQuery.ts"],"sourcesContent":["\"use client\";\n\nimport { useSyncExternalStore } from \"react\";\n\n/** Does the viewport match `query`? False on the server and until the browser answers. */\nexport function useMediaQuery(query: string): boolean {\n return useSyncExternalStore(\n (notify) => {\n const m = window.matchMedia(query);\n m.addEventListener(\"change\", notify);\n return () => m.removeEventListener(\"change\", notify);\n },\n () => window.matchMedia(query).matches,\n () => false,\n );\n}\n"],"mappings":";;;;AAKA,SAAgB,cAAc,OAAwB;CACpD,OAAO,sBACJ,WAAW;EACV,MAAM,IAAI,OAAO,WAAW,KAAK;EACjC,EAAE,iBAAiB,UAAU,MAAM;EACnC,aAAa,EAAE,oBAAoB,UAAU,MAAM;CACrD,SACM,OAAO,WAAW,KAAK,CAAC,CAAC,eACzB,KACR;AACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { PublicForm } from "@conferencesuite/core/forms/types";
|
|
2
|
+
import { Details } from "@conferencesuite/core/registration/types";
|
|
3
|
+
import { SuiteConfig } from "@conferencesuite/core/types";
|
|
4
|
+
import { User } from "@supabase/supabase-js";
|
|
5
|
+
export type FormLoad = {
|
|
6
|
+
status: "loading";
|
|
7
|
+
} | {
|
|
8
|
+
status: "error";
|
|
9
|
+
message: string;
|
|
10
|
+
} | {
|
|
11
|
+
status: "ready";
|
|
12
|
+
form: PublicForm;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A public suite form rendered natively (proposals, awards, volunteers...): its
|
|
16
|
+
* fields, the signed-in person's profile for prefill, and a submit that sends the
|
|
17
|
+
* Bearer token when signed in (so the entry belongs to their account) or the
|
|
18
|
+
* guest's details when not. The suite decides whether it is accepted.
|
|
19
|
+
*/
|
|
20
|
+
export declare function useSuiteForm(rawConfig: SuiteConfig, formId: string): {
|
|
21
|
+
load: FormLoad;
|
|
22
|
+
retry: () => void;
|
|
23
|
+
auth: {
|
|
24
|
+
user: User | null;
|
|
25
|
+
ready: boolean;
|
|
26
|
+
};
|
|
27
|
+
profile: Partial<Details> | null;
|
|
28
|
+
submit: (data: {
|
|
29
|
+
id: string;
|
|
30
|
+
title: string;
|
|
31
|
+
value: unknown;
|
|
32
|
+
}[], guest?: Details) => Promise<{
|
|
33
|
+
id?: string;
|
|
34
|
+
updated_at?: string;
|
|
35
|
+
}>;
|
|
36
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { getPublicForm, submitForm } from "@conferencesuite/core/forms/api";
|
|
4
|
+
import { registrationMessage } from "@conferencesuite/core/registration/errors";
|
|
5
|
+
import { getProfile } from "@conferencesuite/core/registration/member";
|
|
6
|
+
import { useAuth } from "./AuthProvider.js";
|
|
7
|
+
import { useStableConfig } from "./useStableConfig.js";
|
|
8
|
+
// src/useProposalForm.ts
|
|
9
|
+
/**
|
|
10
|
+
* A public suite form rendered natively (proposals, awards, volunteers...): its
|
|
11
|
+
* fields, the signed-in person's profile for prefill, and a submit that sends the
|
|
12
|
+
* Bearer token when signed in (so the entry belongs to their account) or the
|
|
13
|
+
* guest's details when not. The suite decides whether it is accepted.
|
|
14
|
+
*/
|
|
15
|
+
function useSuiteForm(rawConfig, formId) {
|
|
16
|
+
const config = useStableConfig(rawConfig);
|
|
17
|
+
const auth = useAuth();
|
|
18
|
+
const { ready } = auth;
|
|
19
|
+
const user = auth.user;
|
|
20
|
+
const supabaseRef = useRef(auth.supabase);
|
|
21
|
+
const tokenRef = useRef(auth.accessToken);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
supabaseRef.current = auth.supabase;
|
|
24
|
+
tokenRef.current = auth.accessToken;
|
|
25
|
+
});
|
|
26
|
+
const [load, setLoad] = useState({ status: "loading" });
|
|
27
|
+
const [attempt, setAttempt] = useState(0);
|
|
28
|
+
const [member, setMember] = useState(null);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
let alive = true;
|
|
31
|
+
(async () => {
|
|
32
|
+
setLoad({ status: "loading" });
|
|
33
|
+
try {
|
|
34
|
+
const form = await getPublicForm(config, formId);
|
|
35
|
+
if (alive) setLoad({
|
|
36
|
+
status: "ready",
|
|
37
|
+
form
|
|
38
|
+
});
|
|
39
|
+
} catch (e) {
|
|
40
|
+
if (alive) setLoad({
|
|
41
|
+
status: "error",
|
|
42
|
+
message: registrationMessage(e)
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
})();
|
|
46
|
+
return () => {
|
|
47
|
+
alive = false;
|
|
48
|
+
};
|
|
49
|
+
}, [
|
|
50
|
+
config,
|
|
51
|
+
formId,
|
|
52
|
+
attempt
|
|
53
|
+
]);
|
|
54
|
+
const userId = user?.id;
|
|
55
|
+
const userEmail = user?.email ?? "";
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (!ready || !userId) return;
|
|
58
|
+
let alive = true;
|
|
59
|
+
getProfile(supabaseRef.current(), config.orgId, userId, userEmail).then((profile) => alive && setMember({
|
|
60
|
+
userId,
|
|
61
|
+
profile
|
|
62
|
+
}));
|
|
63
|
+
return () => {
|
|
64
|
+
alive = false;
|
|
65
|
+
};
|
|
66
|
+
}, [
|
|
67
|
+
ready,
|
|
68
|
+
userId,
|
|
69
|
+
userEmail,
|
|
70
|
+
config.orgId
|
|
71
|
+
]);
|
|
72
|
+
const submit = useCallback(async (data, guest) => {
|
|
73
|
+
const token = await tokenRef.current();
|
|
74
|
+
return submitForm(config, {
|
|
75
|
+
formId,
|
|
76
|
+
data,
|
|
77
|
+
guest
|
|
78
|
+
}, { token });
|
|
79
|
+
}, [config, formId]);
|
|
80
|
+
const mine = userId && member?.userId === userId ? member : null;
|
|
81
|
+
return {
|
|
82
|
+
load,
|
|
83
|
+
retry: () => setAttempt((n) => n + 1),
|
|
84
|
+
auth: {
|
|
85
|
+
user,
|
|
86
|
+
ready
|
|
87
|
+
},
|
|
88
|
+
profile: mine?.profile ?? null,
|
|
89
|
+
submit
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export { useSuiteForm };
|
|
93
|
+
|
|
94
|
+
//# sourceMappingURL=useProposalForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useProposalForm.js","names":[],"sources":["../src/useProposalForm.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { getPublicForm, submitForm } from \"@conferencesuite/core/forms/api\";\nimport type { PublicForm } from \"@conferencesuite/core/forms/types\";\nimport { registrationMessage } from \"@conferencesuite/core/registration/errors\";\nimport { getProfile } from \"@conferencesuite/core/registration/member\";\nimport type { Details } from \"@conferencesuite/core/registration/types\";\nimport type { SuiteConfig } from \"@conferencesuite/core/types\";\nimport type { User } from \"@supabase/supabase-js\";\nimport { useAuth } from \"./AuthProvider\";\nimport { useStableConfig } from \"./useStableConfig\";\n\nexport type FormLoad = { status: \"loading\" } | { status: \"error\"; message: string } | { status: \"ready\"; form: PublicForm };\n\n/**\n * A public suite form rendered natively (proposals, awards, volunteers...): its\n * fields, the signed-in person's profile for prefill, and a submit that sends the\n * Bearer token when signed in (so the entry belongs to their account) or the\n * guest's details when not. The suite decides whether it is accepted.\n */\nexport function useSuiteForm(rawConfig: SuiteConfig, formId: string) {\n const config = useStableConfig(rawConfig);\n const auth = useAuth();\n const { ready } = auth;\n const user: User | null = auth.user;\n const supabaseRef = useRef(auth.supabase);\n const tokenRef = useRef(auth.accessToken);\n useEffect(() => {\n supabaseRef.current = auth.supabase;\n tokenRef.current = auth.accessToken;\n });\n const [load, setLoad] = useState<FormLoad>({ status: \"loading\" });\n const [attempt, setAttempt] = useState(0);\n const [member, setMember] = useState<{ userId: string; profile: Partial<Details> | null } | null>(null);\n\n useEffect(() => {\n let alive = true;\n (async () => {\n setLoad({ status: \"loading\" });\n try {\n const form = await getPublicForm(config, formId);\n if (alive) setLoad({ status: \"ready\", form });\n } catch (e) {\n if (alive) setLoad({ status: \"error\", message: registrationMessage(e) });\n }\n })();\n return () => {\n alive = false;\n };\n }, [config, formId, attempt]);\n\n const userId = user?.id;\n const userEmail = user?.email ?? \"\";\n useEffect(() => {\n if (!ready || !userId) return;\n let alive = true;\n getProfile(supabaseRef.current(), config.orgId, userId, userEmail).then((profile) => alive && setMember({ userId, profile }));\n return () => {\n alive = false;\n };\n }, [ready, userId, userEmail, config.orgId]);\n\n const submit = useCallback(\n async (data: { id: string; title: string; value: unknown }[], guest?: Details) => {\n const token = await tokenRef.current();\n return submitForm(config, { formId, data, guest }, { token });\n },\n [config, formId],\n );\n\n const mine = userId && member?.userId === userId ? member : null;\n return { load, retry: () => setAttempt((n) => n + 1), auth: { user, ready }, profile: mine?.profile ?? null, submit };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D,UAAoB;EAChF,MAAM,QAAQ,MAAM,SAAS,QAAQ;EACrC,OAAO,WAAW,QAAQ;GAAE;GAAQ;GAAM;EAAM,GAAG,EAAE,MAAM,CAAC;CAC9D,GACA,CAAC,QAAQ,MAAM,CACjB;CAEA,MAAM,OAAO,UAAU,QAAQ,WAAW,SAAS,SAAS;CAC5D,OAAO;EAAE;EAAM,aAAa,YAAY,MAAM,IAAI,CAAC;EAAG,MAAM;GAAE;GAAM;EAAM;EAAG,SAAS,MAAM,WAAW;EAAM;CAAO;AACtH"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { RegistrationState } from "@conferencesuite/core/registration/options";
|
|
2
|
+
import { Catalog, Details, Membership, RegistrationFormSchema, Selection } from "@conferencesuite/core/registration/types";
|
|
3
|
+
import { SuiteConfig } from "@conferencesuite/core/types";
|
|
4
|
+
import { User } from "@supabase/supabase-js";
|
|
5
|
+
export type RegistrationData = {
|
|
6
|
+
catalog: Catalog;
|
|
7
|
+
state: RegistrationState;
|
|
8
|
+
form: RegistrationFormSchema | null;
|
|
9
|
+
};
|
|
10
|
+
export type RegistrationLoad = {
|
|
11
|
+
status: "loading";
|
|
12
|
+
} | {
|
|
13
|
+
status: "error";
|
|
14
|
+
message: string;
|
|
15
|
+
} | ({
|
|
16
|
+
status: "ready";
|
|
17
|
+
} & RegistrationData);
|
|
18
|
+
/** Registration actions for the current person: Bearer when signed in, guest otherwise. */
|
|
19
|
+
export declare function useRegistrationActions(rawConfig: SuiteConfig): {
|
|
20
|
+
drafts: {
|
|
21
|
+
save(formId: string, draft: Omit<import("@conferencesuite/core/registration/draft").Draft, "savedAt">, now?: number): void;
|
|
22
|
+
load(formId: string, now?: number): import("@conferencesuite/core/registration/draft").Draft | null;
|
|
23
|
+
clear(formId: string): void;
|
|
24
|
+
};
|
|
25
|
+
checkout(input: {
|
|
26
|
+
formId: string;
|
|
27
|
+
fieldId: string;
|
|
28
|
+
selection: Selection;
|
|
29
|
+
details: Details;
|
|
30
|
+
returnUrl: string;
|
|
31
|
+
}): Promise<{
|
|
32
|
+
clientSecret: string;
|
|
33
|
+
}>;
|
|
34
|
+
submit(input: {
|
|
35
|
+
formId: string;
|
|
36
|
+
data: {
|
|
37
|
+
id: string;
|
|
38
|
+
title: string;
|
|
39
|
+
value: unknown;
|
|
40
|
+
}[];
|
|
41
|
+
details?: Details;
|
|
42
|
+
}): Promise<{
|
|
43
|
+
id?: string;
|
|
44
|
+
updated_at?: string;
|
|
45
|
+
}>;
|
|
46
|
+
status: (sessionId: string) => Promise<import("@conferencesuite/core/registration/types").CheckoutStatus>;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Everything the registration screen needs: what is on sale and the window (from the suite),
|
|
50
|
+
* the form's fields, and, once signed in, the person's profile and membership.
|
|
51
|
+
* `formId` comes from config; without it there is nothing to render.
|
|
52
|
+
*/
|
|
53
|
+
export declare function useRegistration(rawConfig: SuiteConfig): {
|
|
54
|
+
load: RegistrationLoad;
|
|
55
|
+
retry: () => void;
|
|
56
|
+
applyCode: (code: string) => Promise<Catalog>;
|
|
57
|
+
refreshMembership: () => Promise<void>;
|
|
58
|
+
auth: {
|
|
59
|
+
user: User | null;
|
|
60
|
+
ready: boolean;
|
|
61
|
+
};
|
|
62
|
+
profile: Partial<Details> | null;
|
|
63
|
+
membership: Membership | null;
|
|
64
|
+
actions: {
|
|
65
|
+
drafts: {
|
|
66
|
+
save(formId: string, draft: Omit<import("@conferencesuite/core/registration/draft").Draft, "savedAt">, now?: number): void;
|
|
67
|
+
load(formId: string, now?: number): import("@conferencesuite/core/registration/draft").Draft | null;
|
|
68
|
+
clear(formId: string): void;
|
|
69
|
+
};
|
|
70
|
+
checkout(input: {
|
|
71
|
+
formId: string;
|
|
72
|
+
fieldId: string;
|
|
73
|
+
selection: Selection;
|
|
74
|
+
details: Details;
|
|
75
|
+
returnUrl: string;
|
|
76
|
+
}): Promise<{
|
|
77
|
+
clientSecret: string;
|
|
78
|
+
}>;
|
|
79
|
+
submit(input: {
|
|
80
|
+
formId: string;
|
|
81
|
+
data: {
|
|
82
|
+
id: string;
|
|
83
|
+
title: string;
|
|
84
|
+
value: unknown;
|
|
85
|
+
}[];
|
|
86
|
+
details?: Details;
|
|
87
|
+
}): Promise<{
|
|
88
|
+
id?: string;
|
|
89
|
+
updated_at?: string;
|
|
90
|
+
}>;
|
|
91
|
+
status: (sessionId: string) => Promise<import("@conferencesuite/core/registration/types").CheckoutStatus>;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
/** Just the state of registration (for buttons and badges elsewhere on the site). */
|
|
95
|
+
export declare function useRegistrationState(rawConfig: SuiteConfig): RegistrationState | null;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { createFormCheckout, getCatalog, getCheckoutStatus, getRegistrationForm, submitRegistration } from "@conferencesuite/core/registration/api";
|
|
4
|
+
import { createDraftStore } from "@conferencesuite/core/registration/draft";
|
|
5
|
+
import { registrationMessage } from "@conferencesuite/core/registration/errors";
|
|
6
|
+
import { getMembership, getProfile } from "@conferencesuite/core/registration/member";
|
|
7
|
+
import { registrationState } from "@conferencesuite/core/registration/options";
|
|
8
|
+
import { useAuth } from "./AuthProvider.js";
|
|
9
|
+
import { useStableConfig } from "./useStableConfig.js";
|
|
10
|
+
// src/useRegistration.ts
|
|
11
|
+
/** Registration actions for the current person: Bearer when signed in, guest otherwise. */
|
|
12
|
+
function useRegistrationActions(rawConfig) {
|
|
13
|
+
const config = useStableConfig(rawConfig);
|
|
14
|
+
const auth = useAuth();
|
|
15
|
+
const tokenRef = useRef(auth.accessToken);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
tokenRef.current = auth.accessToken;
|
|
18
|
+
});
|
|
19
|
+
const drafts = useMemo(() => createDraftStore(typeof window === "undefined" ? void 0 : window.localStorage), []);
|
|
20
|
+
return useMemo(() => ({
|
|
21
|
+
drafts,
|
|
22
|
+
async checkout(input) {
|
|
23
|
+
const token = await tokenRef.current();
|
|
24
|
+
return createFormCheckout(config, {
|
|
25
|
+
...input,
|
|
26
|
+
isPublic: true
|
|
27
|
+
}, { token });
|
|
28
|
+
},
|
|
29
|
+
async submit(input) {
|
|
30
|
+
const token = await tokenRef.current();
|
|
31
|
+
return submitRegistration(config, {
|
|
32
|
+
formId: input.formId,
|
|
33
|
+
data: input.data,
|
|
34
|
+
guest: input.details
|
|
35
|
+
}, { token });
|
|
36
|
+
},
|
|
37
|
+
status: (sessionId) => getCheckoutStatus(config, sessionId)
|
|
38
|
+
}), [config, drafts]);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Everything the registration screen needs: what is on sale and the window (from the suite),
|
|
42
|
+
* the form's fields, and, once signed in, the person's profile and membership.
|
|
43
|
+
* `formId` comes from config; without it there is nothing to render.
|
|
44
|
+
*/
|
|
45
|
+
function useRegistration(rawConfig) {
|
|
46
|
+
const config = useStableConfig(rawConfig);
|
|
47
|
+
const auth = useAuth();
|
|
48
|
+
const { ready } = auth;
|
|
49
|
+
const user = auth.user;
|
|
50
|
+
const supabaseRef = useRef(auth.supabase);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
supabaseRef.current = auth.supabase;
|
|
53
|
+
});
|
|
54
|
+
const [load, setLoad] = useState({ status: "loading" });
|
|
55
|
+
const [member, setMember] = useState(null);
|
|
56
|
+
const [attempt, setAttempt] = useState(0);
|
|
57
|
+
const formId = config.registrationFormId;
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
let alive = true;
|
|
60
|
+
(async () => {
|
|
61
|
+
setLoad({ status: "loading" });
|
|
62
|
+
try {
|
|
63
|
+
const catalog = await getCatalog(config);
|
|
64
|
+
const state = registrationState(catalog);
|
|
65
|
+
const form = formId && state.kind === "open" ? await getRegistrationForm(config, formId) : null;
|
|
66
|
+
if (alive) setLoad({
|
|
67
|
+
status: "ready",
|
|
68
|
+
catalog,
|
|
69
|
+
state,
|
|
70
|
+
form
|
|
71
|
+
});
|
|
72
|
+
} catch (e) {
|
|
73
|
+
if (alive) setLoad({
|
|
74
|
+
status: "error",
|
|
75
|
+
message: registrationMessage(e)
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
})();
|
|
79
|
+
return () => {
|
|
80
|
+
alive = false;
|
|
81
|
+
};
|
|
82
|
+
}, [
|
|
83
|
+
config,
|
|
84
|
+
formId,
|
|
85
|
+
attempt
|
|
86
|
+
]);
|
|
87
|
+
const userId = user?.id;
|
|
88
|
+
const userEmail = user?.email ?? "";
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
if (!ready || !userId) return;
|
|
91
|
+
let alive = true;
|
|
92
|
+
const db = supabaseRef.current();
|
|
93
|
+
Promise.all([getProfile(db, config.orgId, userId, userEmail), getMembership(db, config.orgId)]).then(([profile, membership]) => {
|
|
94
|
+
if (alive) setMember({
|
|
95
|
+
userId,
|
|
96
|
+
profile,
|
|
97
|
+
membership
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
return () => {
|
|
101
|
+
alive = false;
|
|
102
|
+
};
|
|
103
|
+
}, [
|
|
104
|
+
ready,
|
|
105
|
+
userId,
|
|
106
|
+
userEmail,
|
|
107
|
+
config.orgId
|
|
108
|
+
]);
|
|
109
|
+
const mine = userId && member?.userId === userId ? member : null;
|
|
110
|
+
const profile = mine?.profile ?? null;
|
|
111
|
+
const membership = mine?.membership ?? null;
|
|
112
|
+
const retry = useCallback(() => setAttempt((n) => n + 1), []);
|
|
113
|
+
const actions = useRegistrationActions(config);
|
|
114
|
+
return {
|
|
115
|
+
load,
|
|
116
|
+
retry,
|
|
117
|
+
applyCode: useCallback(async (code) => {
|
|
118
|
+
const catalog = await getCatalog(config, code);
|
|
119
|
+
setLoad((cur) => cur.status === "ready" ? {
|
|
120
|
+
...cur,
|
|
121
|
+
catalog,
|
|
122
|
+
state: registrationState(catalog)
|
|
123
|
+
} : cur);
|
|
124
|
+
return catalog;
|
|
125
|
+
}, [config]),
|
|
126
|
+
refreshMembership: useCallback(async () => {
|
|
127
|
+
if (!userId) return;
|
|
128
|
+
const membership = await getMembership(supabaseRef.current(), config.orgId);
|
|
129
|
+
setMember((cur) => cur && cur.userId === userId ? {
|
|
130
|
+
...cur,
|
|
131
|
+
membership
|
|
132
|
+
} : cur);
|
|
133
|
+
}, [userId, config.orgId]),
|
|
134
|
+
auth: {
|
|
135
|
+
user,
|
|
136
|
+
ready
|
|
137
|
+
},
|
|
138
|
+
profile,
|
|
139
|
+
membership,
|
|
140
|
+
actions
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/** Just the state of registration (for buttons and badges elsewhere on the site). */
|
|
144
|
+
function useRegistrationState(rawConfig) {
|
|
145
|
+
const config = useStableConfig(rawConfig);
|
|
146
|
+
const [state, setState] = useState(null);
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
let alive = true;
|
|
149
|
+
getCatalog(config).then((c) => alive && setState(registrationState(c))).catch(() => alive && setState({ kind: "unavailable" }));
|
|
150
|
+
return () => {
|
|
151
|
+
alive = false;
|
|
152
|
+
};
|
|
153
|
+
}, [config]);
|
|
154
|
+
return state;
|
|
155
|
+
}
|
|
156
|
+
export { useRegistration, useRegistrationActions, useRegistrationState };
|
|
157
|
+
|
|
158
|
+
//# sourceMappingURL=useRegistration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRegistration.js","names":[],"sources":["../src/useRegistration.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { createFormCheckout, getCatalog, getCheckoutStatus, getRegistrationForm, submitRegistration } from \"@conferencesuite/core/registration/api\";\nimport { createDraftStore } from \"@conferencesuite/core/registration/draft\";\nimport { registrationMessage } from \"@conferencesuite/core/registration/errors\";\nimport { getMembership, getProfile } from \"@conferencesuite/core/registration/member\";\nimport { type RegistrationState, registrationState } from \"@conferencesuite/core/registration/options\";\nimport type { Catalog, Details, Membership, RegistrationFormSchema, Selection } from \"@conferencesuite/core/registration/types\";\nimport type { SuiteConfig } from \"@conferencesuite/core/types\";\nimport type { User } from \"@supabase/supabase-js\";\nimport { useAuth } from \"./AuthProvider\";\nimport { useStableConfig } from \"./useStableConfig\";\n\nexport type RegistrationData = {\n catalog: Catalog;\n state: RegistrationState;\n form: RegistrationFormSchema | null;\n};\n\nexport type RegistrationLoad =\n | { status: \"loading\" }\n | { status: \"error\"; message: string }\n | ({ status: \"ready\" } & RegistrationData);\n\n/** Registration actions for the current person: Bearer when signed in, guest otherwise. */\nexport function useRegistrationActions(rawConfig: SuiteConfig) {\n const config = useStableConfig(rawConfig);\n const auth = useAuth();\n // The auth api object changes with every auth state change; keep the actions stable\n const tokenRef = useRef(auth.accessToken);\n useEffect(() => {\n tokenRef.current = auth.accessToken;\n });\n const drafts = useMemo(\n () => createDraftStore(typeof window === \"undefined\" ? undefined : window.localStorage),\n [],\n );\n return useMemo(\n () => ({\n drafts,\n async checkout(input: { formId: string; fieldId: string; selection: Selection; details: Details; returnUrl: string }) {\n const token = await tokenRef.current();\n return createFormCheckout(config, { ...input, isPublic: true }, { token });\n },\n async submit(input: { formId: string; data: { id: string; title: string; value: unknown }[]; details?: Details }) {\n const token = await tokenRef.current();\n return submitRegistration(config, { formId: input.formId, data: input.data, guest: input.details }, { token });\n },\n status: (sessionId: string) => getCheckoutStatus(config, sessionId),\n }),\n [config, drafts],\n );\n}\n\n/**\n * Everything the registration screen needs: what is on sale and the window (from the suite),\n * the form's fields, and, once signed in, the person's profile and membership.\n * `formId` comes from config; without it there is nothing to render.\n */\nexport function useRegistration(rawConfig: SuiteConfig) {\n const config = useStableConfig(rawConfig);\n const auth = useAuth();\n const { ready } = auth;\n const user: User | null = auth.user;\n const supabaseRef = useRef(auth.supabase);\n useEffect(() => {\n supabaseRef.current = auth.supabase;\n });\n const [load, setLoad] = useState<RegistrationLoad>({ status: \"loading\" });\n const [member, setMember] = useState<{ userId: string; profile: Partial<Details> | null; membership: Membership | null } | null>(null);\n const [attempt, setAttempt] = useState(0);\n const formId = config.registrationFormId;\n\n useEffect(() => {\n let alive = true;\n (async () => {\n setLoad({ status: \"loading\" });\n try {\n const catalog = await getCatalog(config);\n const state = registrationState(catalog);\n // The form is public; skip fetching it when registration can't happen anyway\n const form = formId && state.kind === \"open\" ? await getRegistrationForm(config, formId) : null;\n if (alive) setLoad({ status: \"ready\", catalog, state, form });\n } catch (e) {\n if (alive) setLoad({ status: \"error\", message: registrationMessage(e) });\n }\n })();\n return () => {\n alive = false;\n };\n }, [config, formId, attempt]);\n\n // Members: prefill and \"already registered\", both read from the suite's database\n const userId = user?.id;\n const userEmail = user?.email ?? \"\";\n useEffect(() => {\n if (!ready || !userId) return;\n let alive = true;\n const db = supabaseRef.current();\n Promise.all([getProfile(db, config.orgId, userId, userEmail), getMembership(db, config.orgId)]).then(([profile, membership]) => {\n if (alive) setMember({ userId, profile, membership });\n });\n return () => {\n alive = false;\n };\n }, [ready, userId, userEmail, config.orgId]);\n // Only this user's data counts (a sign-out or switch hides the previous person's)\n const mine = userId && member?.userId === userId ? member : null;\n const profile = mine?.profile ?? null;\n const membership = mine?.membership ?? null;\n\n const retry = useCallback(() => setAttempt((n) => n + 1), []);\n const actions = useRegistrationActions(config);\n\n /**\n * Ask the suite again with an access code (it reveals the hidden tiers the code unlocks). The catalog\n * is replaced in place, so what the person has typed is not lost; `codeValid` says whether it worked.\n */\n const applyCode = useCallback(\n async (code: string): Promise<Catalog> => {\n const catalog = await getCatalog(config, code);\n setLoad((cur) => (cur.status === \"ready\" ? { ...cur, catalog, state: registrationState(catalog) } : cur));\n return catalog;\n },\n [config],\n );\n\n /** Re-read the signed-in person's membership (after paying for add-ons, say). */\n const refreshMembership = useCallback(async () => {\n if (!userId) return;\n const membership = await getMembership(supabaseRef.current(), config.orgId);\n setMember((cur) => (cur && cur.userId === userId ? { ...cur, membership } : cur));\n }, [userId, config.orgId]);\n\n return { load, retry, applyCode, refreshMembership, auth: { user, ready }, profile, membership, actions };\n}\n\n/** Just the state of registration (for buttons and badges elsewhere on the site). */\nexport function useRegistrationState(rawConfig: SuiteConfig): RegistrationState | null {\n const config = useStableConfig(rawConfig);\n const [state, setState] = useState<RegistrationState | null>(null);\n useEffect(() => {\n let alive = true;\n getCatalog(config)\n .then((c) => alive && setState(registrationState(c)))\n .catch(() => alive && setState({ kind: \"unavailable\" }));\n return () => {\n alive = false;\n };\n }, [config]);\n return state;\n}\n"],"mappings":";;;;;;;;;;;AA0BA,SAAgB,uBAAuB,WAAwB;CAC7D,MAAM,SAAS,gBAAgB,SAAS;CACxC,MAAM,OAAO,QAAQ;CAErB,MAAM,WAAW,OAAO,KAAK,WAAW;CACxC,gBAAgB;EACd,SAAS,UAAU,KAAK;CAC1B,CAAC;CACD,MAAM,SAAS,cACP,iBAAiB,OAAO,WAAW,cAAc,KAAA,IAAY,OAAO,YAAY,GACtF,CAAC,CACH;CACA,OAAO,eACE;EACL;EACA,MAAM,SAAS,OAAuG;GACpH,MAAM,QAAQ,MAAM,SAAS,QAAQ;GACrC,OAAO,mBAAmB,QAAQ;IAAE,GAAG;IAAO,UAAU;GAAK,GAAG,EAAE,MAAM,CAAC;EAC3E;EACA,MAAM,OAAO,OAAqG;GAChH,MAAM,QAAQ,MAAM,SAAS,QAAQ;GACrC,OAAO,mBAAmB,QAAQ;IAAE,QAAQ,MAAM;IAAQ,MAAM,MAAM;IAAM,OAAO,MAAM;GAAQ,GAAG,EAAE,MAAM,CAAC;EAC/G;EACA,SAAS,cAAsB,kBAAkB,QAAQ,SAAS;CACpE,IACA,CAAC,QAAQ,MAAM,CACjB;AACF;;;;;;AAOA,SAAgB,gBAAgB,WAAwB;CACtD,MAAM,SAAS,gBAAgB,SAAS;CACxC,MAAM,OAAO,QAAQ;CACrB,MAAM,EAAE,UAAU;CAClB,MAAM,OAAoB,KAAK;CAC/B,MAAM,cAAc,OAAO,KAAK,QAAQ;CACxC,gBAAgB;EACd,YAAY,UAAU,KAAK;CAC7B,CAA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MAAM,cAAc;CAEvC,MAAM,QAAQ,kBAAkB,YAAY,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC;CAC5D,MAAM,UAAU,uBAAuB,MAAM;CAsB7C,OAAO;EAAE;EAAM;EAAO,WAhBJ,YAChB,OAAO,SAAmC;GACxC,MAAM,UAAU,MAAM,WAAW,QAAQ,IAAI;GAC7C,SAAS,QAAS,IAAI,WAAW,UAAU;IAAE,GAAG;IAAK;IAAS,OAAO,kBAAkB,OAAO;GAAE,IAAI,GAAI;GACxG,OAAO;EACT,GACA,CAAC,MAAM,CAUqB;EAAG,mBANP,YAAY,YAAY;GAChD,IAAI,CAAC,QAAQ;GACb,MAAM,aAAa,MAAM,cAAc,YAAY,QAAQ,GAAG,OAAO,KAAK;GAC1E,WAAW,QAAS,OAAO,IAAI,WAAW,SAAS;IAAE,GAAG;IAAK;GAAW,IAAI,GAAI;EAClF,GAAG,CAAC,QAAQ,OAAO,KAAK,CAEyB;EAAG,MAAM;GAAE;GAAM;EAAM;EAAG;EAAS;EAAY;CAAQ;AAC1G;;AAGA,SAAgB,qBAAqB,WAAkD;CACrF,MAAM,SAAS,gBAAgB,SAAS;CACxC,MAAM,CAAC,OAAO,YAAY,SAAmC,IAAI;CACjE,gBAAgB;EACd,IAAI,QAAQ;EACZ,WAAW,MAAM,CAAC,CACf,MAAM,MAAM,SAAS,SAAS,kBAAkB,CAAC,CAAC,CAAC,CAAC,CACpD,YAAY,SAAS,SAAS,EAAE,MAAM,cAAc,CAAC,CAAC;EACzD,aAAa;GACX,QAAQ;EACV;CACF,GAAG,CAAC,MAAM,CAAC;CACX,OAAO;AACT"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Schedule } from "@conferencesuite/core/schedule/types";
|
|
2
|
+
import { SuiteConfig } from "@conferencesuite/core/types";
|
|
3
|
+
export type ScheduleLoad = {
|
|
4
|
+
status: "loading";
|
|
5
|
+
} | {
|
|
6
|
+
status: "error";
|
|
7
|
+
message: string;
|
|
8
|
+
code?: string;
|
|
9
|
+
} | {
|
|
10
|
+
status: "ready";
|
|
11
|
+
schedule: Schedule;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The public schedule, kept fresh: loads once, then re-checks every minute while the tab is
|
|
15
|
+
* visible, using the ETag so an unchanged schedule costs a 304. A failed re-check never replaces
|
|
16
|
+
* a schedule you are already reading with an error.
|
|
17
|
+
*/
|
|
18
|
+
export declare function useSchedule(rawConfig: SuiteConfig, pollMs?: number): {
|
|
19
|
+
load: ScheduleLoad;
|
|
20
|
+
retry: () => void;
|
|
21
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { getSchedule } from "@conferencesuite/core/schedule/api";
|
|
4
|
+
import { SuiteError } from "@conferencesuite/core/errors";
|
|
5
|
+
import { useStableConfig } from "./useStableConfig.js";
|
|
6
|
+
// src/useSchedule.ts
|
|
7
|
+
const POLL_MS = 6e4;
|
|
8
|
+
/**
|
|
9
|
+
* The public schedule, kept fresh: loads once, then re-checks every minute while the tab is
|
|
10
|
+
* visible, using the ETag so an unchanged schedule costs a 304. A failed re-check never replaces
|
|
11
|
+
* a schedule you are already reading with an error.
|
|
12
|
+
*/
|
|
13
|
+
function useSchedule(rawConfig, pollMs = POLL_MS) {
|
|
14
|
+
const config = useStableConfig(rawConfig);
|
|
15
|
+
const [load, setLoad] = useState({ status: "loading" });
|
|
16
|
+
const etag = useRef(null);
|
|
17
|
+
const have = useRef(false);
|
|
18
|
+
const [attempt, setAttempt] = useState(0);
|
|
19
|
+
const fetchOnce = useCallback(async (initial) => {
|
|
20
|
+
try {
|
|
21
|
+
const r = await getSchedule(config, { etag: etag.current });
|
|
22
|
+
if (r.kind === "fresh") {
|
|
23
|
+
etag.current = r.etag;
|
|
24
|
+
have.current = true;
|
|
25
|
+
setLoad({
|
|
26
|
+
status: "ready",
|
|
27
|
+
schedule: r.schedule
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
} catch (e) {
|
|
31
|
+
if (initial || !have.current) {
|
|
32
|
+
const err = e instanceof SuiteError ? e : null;
|
|
33
|
+
setLoad({
|
|
34
|
+
status: "error",
|
|
35
|
+
message: err?.message ?? "Something went wrong. Try again.",
|
|
36
|
+
code: err?.code
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}, [config]);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
etag.current = null;
|
|
43
|
+
have.current = false;
|
|
44
|
+
setLoad({ status: "loading" });
|
|
45
|
+
fetchOnce(true);
|
|
46
|
+
const id = window.setInterval(() => {
|
|
47
|
+
if (document.visibilityState === "visible") fetchOnce(false);
|
|
48
|
+
}, pollMs);
|
|
49
|
+
return () => window.clearInterval(id);
|
|
50
|
+
}, [
|
|
51
|
+
fetchOnce,
|
|
52
|
+
attempt,
|
|
53
|
+
pollMs
|
|
54
|
+
]);
|
|
55
|
+
return {
|
|
56
|
+
load,
|
|
57
|
+
retry: useCallback(() => setAttempt((n) => n + 1), [])
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export { useSchedule };
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=useSchedule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSchedule.js","names":[],"sources":["../src/useSchedule.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { getSchedule } from \"@conferencesuite/core/schedule/api\";\nimport type { Schedule } from \"@conferencesuite/core/schedule/types\";\nimport { SuiteError } from \"@conferencesuite/core/errors\";\nimport type { SuiteConfig } from \"@conferencesuite/core/types\";\nimport { useStableConfig } from \"./useStableConfig\";\n\nexport type ScheduleLoad =\n | { status: \"loading\" }\n | { status: \"error\"; message: string; code?: string }\n | { status: \"ready\"; schedule: Schedule };\n\nconst POLL_MS = 60_000;\n\n/**\n * The public schedule, kept fresh: loads once, then re-checks every minute while the tab is\n * visible, using the ETag so an unchanged schedule costs a 304. A failed re-check never replaces\n * a schedule you are already reading with an error.\n */\nexport function useSchedule(rawConfig: SuiteConfig, pollMs: number = POLL_MS) {\n const config = useStableConfig(rawConfig);\n const [load, setLoad] = useState<ScheduleLoad>({ status: \"loading\" });\n const etag = useRef<string | null>(null);\n const have = useRef(false);\n const [attempt, setAttempt] = useState(0);\n\n const fetchOnce = useCallback(\n async (initial: boolean) => {\n try {\n const r = await getSchedule(config, { etag: etag.current });\n if (r.kind === \"fresh\") {\n etag.current = r.etag;\n have.current = true;\n setLoad({ status: \"ready\", schedule: r.schedule });\n }\n } catch (e) {\n if (initial || !have.current) {\n const err = e instanceof SuiteError ? e : null;\n setLoad({ status: \"error\", message: err?.message ?? \"Something went wrong. Try again.\", code: err?.code });\n }\n }\n },\n [config],\n );\n\n useEffect(() => {\n etag.current = null;\n have.current = false;\n // eslint-disable-next-line react-hooks/set-state-in-effect -- a retry shows the spinner again\n setLoad({ status: \"loading\" });\n void fetchOnce(true);\n const id = window.setInterval(() => {\n if (document.visibilityState === \"visible\") void fetchOnce(false);\n }, pollMs);\n return () => window.clearInterval(id);\n }, [fetchOnce, attempt, pollMs]);\n\n return { load, retry: useCallback(() => setAttempt((n) => n + 1), []) };\n}\n"],"mappings":";;;;;;AAcA,MAAM,UAAU;;;;;;AAOhB,SAAgB,YAAY,WAAwB,SAAiB,SAAS;CAC5E,MAAM,SAAS,gBAAgB,SAAS;CACxC,MAAM,CAAC,MAAM,WAAW,SAAuB,EAAE,QAAQ,UAAU,CAAC;CACpE,MAAM,OAAO,OAAsB,IAAI;CACvC,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,CAAC,SAAS,cAAc,SAAS,CAAC;CAExC,MAAM,YAAY,YAChB,OAAO,YAAqB;EAC1B,IAAI;GACF,MAAM,IAAI,MAAM,YAAY,QAAQ,EAAE,MAAM,KAAK,QAAQ,CAAC;GAC1D,IAAI,EAAE,SAAS,SAAS;IACtB,KAAK,UAAU,EAAE;IACjB,KAAK,UAAU;IACf,QAAQ;KAAE,QAAQ;KAAS,UAAU,EAAE;IAAS,CAAC;GACnD;EACF,SAAS,GAAG;GACV,IAAI,WAAW,CAAC,KAAK,SAAS;IAC5B,MAAM,MAAM,aAAa,aAAa,IAAI;IAC1C,QAAQ;KAAE,QAAQ;KAAS,SAAS,KAAK,WAAW;KAAoC,MAAM,KAAK;IAAK,CAAC;GAC3G;EACF;CACF,GACA,CAAC,MAAM,CACT;CAEA,gBAAgB;EACd,KAAK,UAAU;EACf,KAAK,UAAU;EAEf,QAAQ,EAAE,QAAQ,UAAU,CAAC;EACxB,UAAU,IAAI;EACnB,MAAM,KAAK,OAAO,kBAAkB;GAClC,IAAI,SAAS,oBAAoB,WAAgB,UAAU,KAAK;EAClE,GAAG,MAAM;EACT,aAAa,OAAO,cAAc,EAAE;CACtC,GAAG;EAAC;EAAW;EAAS;CAAM,CAAC;CAE/B,OAAO;EAAE;EAAM,OAAO,kBAAkB,YAAY,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC;CAAE;AACxE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SuiteConfig } from "@conferencesuite/core/types";
|
|
2
|
+
/**
|
|
3
|
+
* A config prop from a server component arrives as a new object whenever the server
|
|
4
|
+
* re-renders (Fast Refresh, router refresh), though its values never change. Keying
|
|
5
|
+
* effects on that identity would reload data and remount forms mid-use, so hand out
|
|
6
|
+
* one object per set of values.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useStableConfig(config: SuiteConfig): SuiteConfig;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
// src/useStableConfig.ts
|
|
4
|
+
/**
|
|
5
|
+
* A config prop from a server component arrives as a new object whenever the server
|
|
6
|
+
* re-renders (Fast Refresh, router refresh), though its values never change. Keying
|
|
7
|
+
* effects on that identity would reload data and remount forms mid-use, so hand out
|
|
8
|
+
* one object per set of values.
|
|
9
|
+
*/
|
|
10
|
+
function useStableConfig(config) {
|
|
11
|
+
const key = JSON.stringify(config);
|
|
12
|
+
return useMemo(() => config, [key]);
|
|
13
|
+
}
|
|
14
|
+
export { useStableConfig };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=useStableConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStableConfig.js","names":[],"sources":["../src/useStableConfig.ts"],"sourcesContent":["\"use client\";\n\nimport { useMemo } from \"react\";\nimport type { SuiteConfig } from \"@conferencesuite/core/types\";\n\n/**\n * A config prop from a server component arrives as a new object whenever the server\n * re-renders (Fast Refresh, router refresh), though its values never change. Keying\n * effects on that identity would reload data and remount forms mid-use, so hand out\n * one object per set of values.\n */\nexport function useStableConfig(config: SuiteConfig): SuiteConfig {\n const key = JSON.stringify(config);\n // eslint-disable-next-line react-hooks/exhaustive-deps -- the key is the config's values\n return useMemo(() => config, [key]);\n}\n"],"mappings":";;;;;;;;;AAWA,SAAgB,gBAAgB,QAAkC;CAChE,MAAM,MAAM,KAAK,UAAU,MAAM;CAEjC,OAAO,cAAc,QAAQ,CAAC,GAAG,CAAC;AACpC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@conferencesuite/react",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "React hooks over @conferencesuite/core.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/conferencesuite/sdk.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": "https://github.com/conferencesuite/sdk/issues",
|
|
13
|
+
"homepage": "https://github.com/conferencesuite/sdk#readme",
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE",
|
|
21
|
+
"NOTICE"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsdown",
|
|
25
|
+
"prepack": "cp ../../LICENSE ../../NOTICE .",
|
|
26
|
+
"postpack": "rm -f LICENSE NOTICE"
|
|
27
|
+
},
|
|
28
|
+
"exports": {
|
|
29
|
+
"./package.json": "./package.json",
|
|
30
|
+
"./*": {
|
|
31
|
+
"types": "./dist/*.d.ts",
|
|
32
|
+
"import": "./dist/*.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@conferencesuite/core": "^0.0.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@supabase/supabase-js": "^2.119.2",
|
|
40
|
+
"react": "^19"
|
|
41
|
+
}
|
|
6
42
|
}
|