@conferencesuite/core 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/auth/api.d.ts +24 -0
- package/dist/auth/api.js +47 -0
- package/dist/auth/api.js.map +1 -0
- package/dist/auth/cookies.d.ts +49 -0
- package/dist/auth/cookies.js +124 -0
- package/dist/auth/cookies.js.map +1 -0
- package/dist/auth/machine.d.ts +84 -0
- package/dist/auth/machine.js +117 -0
- package/dist/auth/machine.js.map +1 -0
- package/dist/auth/schemas.d.ts +28 -0
- package/dist/auth/schemas.js +38 -0
- package/dist/auth/schemas.js.map +1 -0
- package/dist/auth/service.d.ts +46 -0
- package/dist/auth/service.js +117 -0
- package/dist/auth/service.js.map +1 -0
- package/dist/auth/session.d.ts +18 -0
- package/dist/auth/session.js +28 -0
- package/dist/auth/session.js.map +1 -0
- package/dist/cookie-domain.d.ts +35 -0
- package/dist/cookie-domain.js +61 -0
- package/dist/cookie-domain.js.map +1 -0
- package/dist/currencies.d.ts +19 -0
- package/dist/currencies.js +218 -0
- package/dist/currencies.js.map +1 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.js +23 -0
- package/dist/errors.js.map +1 -0
- package/dist/forms/api.d.ts +25 -0
- package/dist/forms/api.js +43 -0
- package/dist/forms/api.js.map +1 -0
- package/dist/forms/types.d.ts +15 -0
- package/dist/forms/types.js +1 -0
- package/dist/money.d.ts +18 -0
- package/dist/money.js +87 -0
- package/dist/money.js.map +1 -0
- package/dist/names.d.ts +18 -0
- package/dist/names.js +28 -0
- package/dist/names.js.map +1 -0
- package/dist/registration/api.d.ts +34 -0
- package/dist/registration/api.js +61 -0
- package/dist/registration/api.js.map +1 -0
- package/dist/registration/catalog.d.ts +91 -0
- package/dist/registration/catalog.js +84 -0
- package/dist/registration/catalog.js.map +1 -0
- package/dist/registration/draft.d.ts +19 -0
- package/dist/registration/draft.js +39 -0
- package/dist/registration/draft.js.map +1 -0
- package/dist/registration/errors.d.ts +7 -0
- package/dist/registration/errors.js +34 -0
- package/dist/registration/errors.js.map +1 -0
- package/dist/registration/member.d.ts +15 -0
- package/dist/registration/member.js +28 -0
- package/dist/registration/member.js.map +1 -0
- package/dist/registration/options.d.ts +21 -0
- package/dist/registration/options.js +30 -0
- package/dist/registration/options.js.map +1 -0
- package/dist/registration/types.d.ts +103 -0
- package/dist/registration/types.js +1 -0
- package/dist/registration/validation.d.ts +101 -0
- package/dist/registration/validation.js +122 -0
- package/dist/registration/validation.js.map +1 -0
- package/dist/schedule/agenda.d.ts +22 -0
- package/dist/schedule/agenda.js +45 -0
- package/dist/schedule/agenda.js.map +1 -0
- package/dist/schedule/api.d.ts +31 -0
- package/dist/schedule/api.js +55 -0
- package/dist/schedule/api.js.map +1 -0
- package/dist/schedule/logic.d.ts +38 -0
- package/dist/schedule/logic.js +103 -0
- package/dist/schedule/logic.js.map +1 -0
- package/dist/schedule/theme.d.ts +9 -0
- package/dist/schedule/theme.js +29 -0
- package/dist/schedule/theme.js.map +1 -0
- package/dist/schedule/time.d.ts +23 -0
- package/dist/schedule/time.js +68 -0
- package/dist/schedule/time.js.map +1 -0
- package/dist/schedule/types.d.ts +61 -0
- package/dist/schedule/types.js +1 -0
- package/dist/types.d.ts +14 -0
- package/dist/types.js +1 -0
- package/package.json +37 -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/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Plain TypeScript client for the Conference Suite API: auth, registration, forms and schedule logic. No React, no DOM beyond `fetch` and an injected storage.
|
|
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/core/<path>"`.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SuiteConfig } from "../types.js";
|
|
2
|
+
import { EmailCheck } from "./machine.js";
|
|
3
|
+
type Fetch = typeof fetch;
|
|
4
|
+
/** `GET /api/auth/[org_id]?email=`: a plain GET, so no CORS preflight. */
|
|
5
|
+
export declare function checkEmail(config: SuiteConfig, email: string, doFetch?: Fetch): Promise<EmailCheck>;
|
|
6
|
+
export type OrgPublic = {
|
|
7
|
+
id: string;
|
|
8
|
+
url: string;
|
|
9
|
+
name: string;
|
|
10
|
+
shortName: string | null;
|
|
11
|
+
};
|
|
12
|
+
/** `GET /api/org/[id]`: public org details (its `url` is the base_url that scopes the shared cookie). */
|
|
13
|
+
export declare function getOrg(config: SuiteConfig, doFetch?: Fetch): Promise<OrgPublic>;
|
|
14
|
+
/**
|
|
15
|
+
* `PUT /api/auth`: add an existing account to this org. With `profile` it is the
|
|
16
|
+
* sign-up form (the `signup` header selects that body); without, a plain sign-in.
|
|
17
|
+
* Failures here never undo the sign-in, so callers treat them as non-fatal.
|
|
18
|
+
*/
|
|
19
|
+
export declare function linkAccount(config: SuiteConfig, token: string, profile?: {
|
|
20
|
+
fname: string;
|
|
21
|
+
lname: string;
|
|
22
|
+
institution: string;
|
|
23
|
+
}, doFetch?: Fetch): Promise<void>;
|
|
24
|
+
export {};
|
package/dist/auth/api.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SuiteError, toSuiteError } from "../errors.js";
|
|
2
|
+
// src/auth/api.ts
|
|
3
|
+
/** `GET /api/auth/[org_id]?email=`: a plain GET, so no CORS preflight. */
|
|
4
|
+
async function checkEmail(config, email, doFetch = fetch) {
|
|
5
|
+
try {
|
|
6
|
+
const res = await doFetch(`${config.suiteUrl}/api/auth/${config.orgId}?email=${encodeURIComponent(email)}`);
|
|
7
|
+
if (res.ok) return (await res.json()).authed ? { kind: "registered" } : { kind: "guest" };
|
|
8
|
+
if (res.status === 404) return { kind: "not_found" };
|
|
9
|
+
if (res.status === 406) return { kind: "other_org" };
|
|
10
|
+
if (res.status === 429) return { kind: "rate_limited" };
|
|
11
|
+
return { kind: "error" };
|
|
12
|
+
} catch {
|
|
13
|
+
return { kind: "error" };
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** `GET /api/org/[id]`: public org details (its `url` is the base_url that scopes the shared cookie). */
|
|
17
|
+
async function getOrg(config, doFetch = fetch) {
|
|
18
|
+
const res = await doFetch(`${config.suiteUrl}/api/org/${config.orgId}`);
|
|
19
|
+
if (!res.ok) throw await toSuiteError(res);
|
|
20
|
+
return await res.json();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* `PUT /api/auth`: add an existing account to this org. With `profile` it is the
|
|
24
|
+
* sign-up form (the `signup` header selects that body); without, a plain sign-in.
|
|
25
|
+
* Failures here never undo the sign-in, so callers treat them as non-fatal.
|
|
26
|
+
*/
|
|
27
|
+
async function linkAccount(config, token, profile, doFetch = fetch) {
|
|
28
|
+
const res = await doFetch(`${config.suiteUrl}/api/auth`, {
|
|
29
|
+
method: "PUT",
|
|
30
|
+
headers: {
|
|
31
|
+
"Content-Type": "application/json",
|
|
32
|
+
...profile ? { signup: "true" } : {}
|
|
33
|
+
},
|
|
34
|
+
body: JSON.stringify({
|
|
35
|
+
org_id: config.orgId,
|
|
36
|
+
token,
|
|
37
|
+
...profile
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
if (!res.ok && res.status !== 409) {
|
|
41
|
+
const err = await toSuiteError(res);
|
|
42
|
+
throw new SuiteError(err.message, err.code, err.status);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export { checkEmail, getOrg, linkAccount };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","names":[],"sources":["../../src/auth/api.ts"],"sourcesContent":["import type { SuiteConfig } from \"../types\";\nimport { SuiteError, toSuiteError } from \"../errors\";\nimport type { EmailCheck } from \"./machine\";\n\ntype Fetch = typeof fetch;\n\n/** `GET /api/auth/[org_id]?email=`: a plain GET, so no CORS preflight. */\nexport async function checkEmail(\n config: SuiteConfig,\n email: string,\n doFetch: Fetch = fetch,\n): Promise<EmailCheck> {\n try {\n const res = await doFetch(\n `${config.suiteUrl}/api/auth/${config.orgId}?email=${encodeURIComponent(email)}`,\n );\n if (res.ok) {\n const body = (await res.json()) as { authed?: boolean };\n return body.authed ? { kind: \"registered\" } : { kind: \"guest\" };\n }\n if (res.status === 404) return { kind: \"not_found\" };\n if (res.status === 406) return { kind: \"other_org\" };\n if (res.status === 429) return { kind: \"rate_limited\" };\n return { kind: \"error\" };\n } catch {\n return { kind: \"error\" };\n }\n}\n\nexport type OrgPublic = { id: string; url: string; name: string; shortName: string | null };\n\n/** `GET /api/org/[id]`: public org details (its `url` is the base_url that scopes the shared cookie). */\nexport async function getOrg(config: SuiteConfig, doFetch: Fetch = fetch): Promise<OrgPublic> {\n const res = await doFetch(`${config.suiteUrl}/api/org/${config.orgId}`);\n if (!res.ok) throw await toSuiteError(res);\n return (await res.json()) as OrgPublic;\n}\n\n/**\n * `PUT /api/auth`: add an existing account to this org. With `profile` it is the\n * sign-up form (the `signup` header selects that body); without, a plain sign-in.\n * Failures here never undo the sign-in, so callers treat them as non-fatal.\n */\nexport async function linkAccount(\n config: SuiteConfig,\n token: string,\n profile?: { fname: string; lname: string; institution: string },\n doFetch: Fetch = fetch,\n): Promise<void> {\n const res = await doFetch(`${config.suiteUrl}/api/auth`, {\n method: \"PUT\",\n headers: { \"Content-Type\": \"application/json\", ...(profile ? { signup: \"true\" } : {}) },\n body: JSON.stringify({ org_id: config.orgId, token, ...profile }),\n });\n // 409: already a member, which is the goal\n if (!res.ok && res.status !== 409) {\n const err = await toSuiteError(res);\n throw new SuiteError(err.message, err.code, err.status);\n }\n}\n"],"mappings":";;;AAOA,eAAsB,WACpB,QACA,OACA,UAAiB,OACI;CACrB,IAAI;EACF,MAAM,MAAM,MAAM,QAChB,GAAG,OAAO,SAAS,YAAY,OAAO,MAAM,SAAS,mBAAmB,KAAK,GAC/E;EACA,IAAI,IAAI,IAEN,QAAO,MADa,IAAI,KAAK,EAAA,CACjB,SAAS,EAAE,MAAM,aAAa,IAAI,EAAE,MAAM,QAAQ;EAEhE,IAAI,IAAI,WAAW,KAAK,OAAO,EAAE,MAAM,YAAY;EACnD,IAAI,IAAI,WAAW,KAAK,OAAO,EAAE,MAAM,YAAY;EACnD,IAAI,IAAI,WAAW,KAAK,OAAO,EAAE,MAAM,eAAe;EACtD,OAAO,EAAE,MAAM,QAAQ;CACzB,QAAQ;EACN,OAAO,EAAE,MAAM,QAAQ;CACzB;AACF;;AAKA,eAAsB,OAAO,QAAqB,UAAiB,OAA2B;CAC5F,MAAM,MAAM,MAAM,QAAQ,GAAG,OAAO,SAAS,WAAW,OAAO,OAAO;CACtE,IAAI,CAAC,IAAI,IAAI,MAAM,MAAM,aAAa,GAAG;CACzC,OAAQ,MAAM,IAAI,KAAK;AACzB;;;;;;AAOA,eAAsB,YACpB,QACA,OACA,SACA,UAAiB,OACF;CACf,MAAM,MAAM,MAAM,QAAQ,GAAG,OAAO,SAAS,YAAY;EACvD,QAAQ;EACR,SAAS;GAAE,gBAAgB;GAAoB,GAAI,UAAU,EAAE,QAAQ,OAAO,IAAI,CAAC;EAAG;EACtF,MAAM,KAAK,UAAU;GAAE,QAAQ,OAAO;GAAO;GAAO,GAAG;EAAQ,CAAC;CAClE,CAAC;CAED,IAAI,CAAC,IAAI,MAAM,IAAI,WAAW,KAAK;EACjC,MAAM,MAAM,MAAM,aAAa,GAAG;EAClC,MAAM,IAAI,WAAW,IAAI,SAAS,IAAI,MAAM,IAAI,MAAM;CACxD;AACF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { CookieOptions } from "@supabase/ssr";
|
|
2
|
+
import { CookieIO } from "../cookie-domain.js";
|
|
3
|
+
/** The browser surface the session layer needs; a fake in tests, `document`/`location` in the app. */
|
|
4
|
+
export type CookieEnv = CookieIO & {
|
|
5
|
+
hostname: () => string;
|
|
6
|
+
isSecure: () => boolean;
|
|
7
|
+
};
|
|
8
|
+
/** document + location + localStorage, or inert stand-ins during server rendering. */
|
|
9
|
+
export declare function browserCookieEnv(): CookieEnv;
|
|
10
|
+
export declare function parseCookies(header: string): {
|
|
11
|
+
name: string;
|
|
12
|
+
value: string;
|
|
13
|
+
}[];
|
|
14
|
+
export declare function serializeCookie(name: string, value: string, o: CookieOptions & {
|
|
15
|
+
secure?: boolean;
|
|
16
|
+
}): string;
|
|
17
|
+
/**
|
|
18
|
+
* getAll/setAll for @supabase/ssr's browser client. The cookie names, chunking
|
|
19
|
+
* and encoding stay @supabase/ssr's (so a session written here is readable by
|
|
20
|
+
* the main site and the reverse); we only decide the Domain attribute, at write
|
|
21
|
+
* time, from `resolveDomain`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createCookieHandlers(env: CookieEnv, resolveDomain: () => string | undefined): {
|
|
24
|
+
getAll: () => {
|
|
25
|
+
name: string;
|
|
26
|
+
value: string;
|
|
27
|
+
}[];
|
|
28
|
+
setAll: (cookies: {
|
|
29
|
+
name: string;
|
|
30
|
+
value: string;
|
|
31
|
+
options: CookieOptions;
|
|
32
|
+
}[]) => void;
|
|
33
|
+
};
|
|
34
|
+
export declare function readCachedBaseUrl(orgId: string, storage: CookieEnv["storage"], now?: number): string | undefined;
|
|
35
|
+
export declare function cacheBaseUrl(orgId: string, url: string, storage: CookieEnv["storage"], now?: number): void;
|
|
36
|
+
/**
|
|
37
|
+
* Resolves the shared-cookie domain lazily: explicit config, else the org's
|
|
38
|
+
* `base_url` (cached after one fetch). `ensure()` is awaited before a sign-in
|
|
39
|
+
* writes its first cookie so a brand-new browser still gets the shared domain.
|
|
40
|
+
*/
|
|
41
|
+
export declare function createDomainResolver(args: {
|
|
42
|
+
orgId: string;
|
|
43
|
+
explicit?: string;
|
|
44
|
+
env: CookieEnv;
|
|
45
|
+
fetchOrgUrl: () => Promise<string>;
|
|
46
|
+
}): {
|
|
47
|
+
resolve: () => string | undefined;
|
|
48
|
+
ensure: () => Promise<void>;
|
|
49
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { clearHostOnlyAuthCookies, cookieDomainFor } from "../cookie-domain.js";
|
|
2
|
+
// src/auth/cookies.ts
|
|
3
|
+
/** document + location + localStorage, or inert stand-ins during server rendering. */
|
|
4
|
+
function browserCookieEnv() {
|
|
5
|
+
if (typeof document === "undefined") return {
|
|
6
|
+
getCookie: () => "",
|
|
7
|
+
setCookie: () => {},
|
|
8
|
+
hostname: () => "",
|
|
9
|
+
isSecure: () => false
|
|
10
|
+
};
|
|
11
|
+
let storage;
|
|
12
|
+
try {
|
|
13
|
+
storage = window.localStorage;
|
|
14
|
+
} catch {
|
|
15
|
+
storage = void 0;
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
getCookie: () => document.cookie,
|
|
19
|
+
setCookie: (c) => {
|
|
20
|
+
document.cookie = c;
|
|
21
|
+
},
|
|
22
|
+
storage,
|
|
23
|
+
hostname: () => window.location.hostname,
|
|
24
|
+
isSecure: () => window.location.protocol === "https:"
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function parseCookies(header) {
|
|
28
|
+
const out = [];
|
|
29
|
+
for (const part of header.split(";")) {
|
|
30
|
+
const i = part.indexOf("=");
|
|
31
|
+
if (i < 0) continue;
|
|
32
|
+
const name = part.slice(0, i).trim();
|
|
33
|
+
if (!name) continue;
|
|
34
|
+
let value = part.slice(i + 1).trim();
|
|
35
|
+
try {
|
|
36
|
+
value = decodeURIComponent(value);
|
|
37
|
+
} catch {}
|
|
38
|
+
out.push({
|
|
39
|
+
name,
|
|
40
|
+
value
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
function serializeCookie(name, value, o) {
|
|
46
|
+
let s = `${name}=${encodeURIComponent(value)}`;
|
|
47
|
+
if (o.maxAge != null) s += `; Max-Age=${Math.floor(o.maxAge)}`;
|
|
48
|
+
if (o.domain) s += `; Domain=${o.domain}`;
|
|
49
|
+
s += `; Path=${o.path ?? "/"}`;
|
|
50
|
+
if (o.expires) s += `; Expires=${o.expires.toUTCString()}`;
|
|
51
|
+
if (o.sameSite) s += `; SameSite=${typeof o.sameSite === "string" ? o.sameSite.charAt(0).toUpperCase() + o.sameSite.slice(1) : "Lax"}`;
|
|
52
|
+
if (o.secure) s += "; Secure";
|
|
53
|
+
return s;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* getAll/setAll for @supabase/ssr's browser client. The cookie names, chunking
|
|
57
|
+
* and encoding stay @supabase/ssr's (so a session written here is readable by
|
|
58
|
+
* the main site and the reverse); we only decide the Domain attribute, at write
|
|
59
|
+
* time, from `resolveDomain`.
|
|
60
|
+
*/
|
|
61
|
+
function createCookieHandlers(env, resolveDomain) {
|
|
62
|
+
return {
|
|
63
|
+
getAll: () => parseCookies(env.getCookie()),
|
|
64
|
+
setAll: (cookies) => {
|
|
65
|
+
const domain = resolveDomain();
|
|
66
|
+
for (const { name, value, options } of cookies) env.setCookie(serializeCookie(name, value, {
|
|
67
|
+
...options,
|
|
68
|
+
...domain ? { domain } : {},
|
|
69
|
+
secure: env.isSecure()
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const ORG_CACHE_TTL_MS = 864e5;
|
|
75
|
+
const orgKey = (orgId) => `cs:org-base-url:${orgId}`;
|
|
76
|
+
function readCachedBaseUrl(orgId, storage, now = Date.now()) {
|
|
77
|
+
try {
|
|
78
|
+
const raw = storage?.getItem(orgKey(orgId));
|
|
79
|
+
if (!raw) return void 0;
|
|
80
|
+
const { url, at } = JSON.parse(raw);
|
|
81
|
+
return url && at && now - at < ORG_CACHE_TTL_MS ? url : void 0;
|
|
82
|
+
} catch {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function cacheBaseUrl(orgId, url, storage, now = Date.now()) {
|
|
87
|
+
try {
|
|
88
|
+
storage?.setItem(orgKey(orgId), JSON.stringify({
|
|
89
|
+
url,
|
|
90
|
+
at: now
|
|
91
|
+
}));
|
|
92
|
+
} catch {}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Resolves the shared-cookie domain lazily: explicit config, else the org's
|
|
96
|
+
* `base_url` (cached after one fetch). `ensure()` is awaited before a sign-in
|
|
97
|
+
* writes its first cookie so a brand-new browser still gets the shared domain.
|
|
98
|
+
*/
|
|
99
|
+
function createDomainResolver(args) {
|
|
100
|
+
let baseUrl = readCachedBaseUrl(args.orgId, args.env.storage);
|
|
101
|
+
let ensured = null;
|
|
102
|
+
const resolve = () => cookieDomainFor({
|
|
103
|
+
hostname: args.env.hostname(),
|
|
104
|
+
explicit: args.explicit,
|
|
105
|
+
orgBaseUrl: baseUrl
|
|
106
|
+
});
|
|
107
|
+
const ensure = () => ensured ??= (async () => {
|
|
108
|
+
if (!args.explicit && !baseUrl) try {
|
|
109
|
+
baseUrl = await args.fetchOrgUrl();
|
|
110
|
+
cacheBaseUrl(args.orgId, baseUrl, args.env.storage);
|
|
111
|
+
} catch {
|
|
112
|
+
ensured = null;
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (resolve()) clearHostOnlyAuthCookies(args.env);
|
|
116
|
+
})();
|
|
117
|
+
return {
|
|
118
|
+
resolve,
|
|
119
|
+
ensure
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
export { browserCookieEnv, cacheBaseUrl, createCookieHandlers, createDomainResolver, parseCookies, readCachedBaseUrl, serializeCookie };
|
|
123
|
+
|
|
124
|
+
//# sourceMappingURL=cookies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookies.js","names":[],"sources":["../../src/auth/cookies.ts"],"sourcesContent":["import type { CookieOptions } from \"@supabase/ssr\";\nimport { type CookieIO, clearHostOnlyAuthCookies, cookieDomainFor } from \"../cookie-domain\";\n\n/** The browser surface the session layer needs; a fake in tests, `document`/`location` in the app. */\nexport type CookieEnv = CookieIO & {\n hostname: () => string;\n isSecure: () => boolean;\n};\n\n/** document + location + localStorage, or inert stand-ins during server rendering. */\nexport function browserCookieEnv(): CookieEnv {\n if (typeof document === \"undefined\") {\n return { getCookie: () => \"\", setCookie: () => {}, hostname: () => \"\", isSecure: () => false };\n }\n let storage: CookieEnv[\"storage\"];\n try {\n storage = window.localStorage;\n } catch {\n storage = undefined; // blocked storage\n }\n return {\n getCookie: () => document.cookie,\n setCookie: (c) => {\n document.cookie = c;\n },\n storage,\n hostname: () => window.location.hostname,\n isSecure: () => window.location.protocol === \"https:\",\n };\n}\n\nexport function parseCookies(header: string): { name: string; value: string }[] {\n const out: { name: string; value: string }[] = [];\n for (const part of header.split(\";\")) {\n const i = part.indexOf(\"=\");\n if (i < 0) continue;\n const name = part.slice(0, i).trim();\n if (!name) continue;\n let value = part.slice(i + 1).trim();\n try {\n value = decodeURIComponent(value);\n } catch {\n // leave undecodable values as they are\n }\n out.push({ name, value });\n }\n return out;\n}\n\nexport function serializeCookie(name: string, value: string, o: CookieOptions & { secure?: boolean }): string {\n let s = `${name}=${encodeURIComponent(value)}`;\n if (o.maxAge != null) s += `; Max-Age=${Math.floor(o.maxAge)}`;\n if (o.domain) s += `; Domain=${o.domain}`;\n s += `; Path=${o.path ?? \"/\"}`;\n if (o.expires) s += `; Expires=${o.expires.toUTCString()}`;\n if (o.sameSite) s += `; SameSite=${typeof o.sameSite === \"string\" ? o.sameSite.charAt(0).toUpperCase() + o.sameSite.slice(1) : \"Lax\"}`;\n if (o.secure) s += \"; Secure\";\n return s;\n}\n\n/**\n * getAll/setAll for @supabase/ssr's browser client. The cookie names, chunking\n * and encoding stay @supabase/ssr's (so a session written here is readable by\n * the main site and the reverse); we only decide the Domain attribute, at write\n * time, from `resolveDomain`.\n */\nexport function createCookieHandlers(env: CookieEnv, resolveDomain: () => string | undefined) {\n return {\n getAll: () => parseCookies(env.getCookie()),\n setAll: (cookies: { name: string; value: string; options: CookieOptions }[]) => {\n const domain = resolveDomain();\n for (const { name, value, options } of cookies) {\n env.setCookie(\n serializeCookie(name, value, { ...options, ...(domain ? { domain } : {}), secure: env.isSecure() }),\n );\n }\n },\n };\n}\n\nconst ORG_CACHE_TTL_MS = 24 * 60 * 60 * 1000;\nconst orgKey = (orgId: string) => `cs:org-base-url:${orgId}`;\n\nexport function readCachedBaseUrl(orgId: string, storage: CookieEnv[\"storage\"], now = Date.now()): string | undefined {\n try {\n const raw = storage?.getItem(orgKey(orgId));\n if (!raw) return undefined;\n const { url, at } = JSON.parse(raw) as { url?: string; at?: number };\n return url && at && now - at < ORG_CACHE_TTL_MS ? url : undefined;\n } catch {\n return undefined;\n }\n}\n\nexport function cacheBaseUrl(orgId: string, url: string, storage: CookieEnv[\"storage\"], now = Date.now()): void {\n try {\n storage?.setItem(orgKey(orgId), JSON.stringify({ url, at: now }));\n } catch {\n // blocked storage: just refetch next time\n }\n}\n\n/**\n * Resolves the shared-cookie domain lazily: explicit config, else the org's\n * `base_url` (cached after one fetch). `ensure()` is awaited before a sign-in\n * writes its first cookie so a brand-new browser still gets the shared domain.\n */\nexport function createDomainResolver(args: {\n orgId: string;\n explicit?: string;\n env: CookieEnv;\n fetchOrgUrl: () => Promise<string>;\n}) {\n let baseUrl = readCachedBaseUrl(args.orgId, args.env.storage);\n let ensured: Promise<void> | null = null;\n\n const resolve = () =>\n cookieDomainFor({ hostname: args.env.hostname(), explicit: args.explicit, orgBaseUrl: baseUrl });\n\n const ensure = () =>\n (ensured ??= (async () => {\n if (!args.explicit && !baseUrl) {\n try {\n baseUrl = await args.fetchOrgUrl();\n cacheBaseUrl(args.orgId, baseUrl, args.env.storage);\n } catch {\n // offline or suite down: stay host-only for now, self-corrects on the next load\n ensured = null;\n return;\n }\n }\n if (resolve()) clearHostOnlyAuthCookies(args.env);\n })());\n\n return { resolve, ensure };\n}\n"],"mappings":";;;AAUA,SAAgB,mBAA8B;CAC5C,IAAI,OAAO,aAAa,aACtB,OAAO;EAAE,iBAAiB;EAAI,iBAAiB,CAAC;EAAG,gBAAgB;EAAI,gBAAgB;CAAM;CAE/F,IAAI;CACJ,IAAI;EACF,UAAU,OAAO;CACnB,QAAQ;EACN,UAAU,KAAA;CACZ;CACA,OAAO;EACL,iBAAiB,SAAS;EAC1B,YAAY,MAAM;GAChB,SAAS,SAAS;EACpB;EACA;EACA,gBAAgB,OAAO,SAAS;EAChC,gBAAgB,OAAO,SAAS,aAAa;CAC/C;AACF;AAEA,SAAgB,aAAa,QAAmD;CAC9E,MAAM,MAAyC,CAAC;CAChD,KAAK,MAAM,QAAQ,OAAO,MAAM,GAAG,GAAG;EACpC,MAAM,IAAI,KAAK,QAAQ,GAAG;EAC1B,IAAI,IAAI,GAAG;EACX,MAAM,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK;EACnC,IAAI,CAAC,MAAM;EACX,IAAI,QAAQ,KAAK,MAAM,IAAI,CAAC,CAAC,CAAC,KAAK;EACnC,IAAI;GACF,QAAQ,mBAAmB,KAAK;EAClC,QAAQ,CAER;EACA,IAAI,KAAK;GAAE;GAAM;EAAM,CAAC;CAC1B;CACA,OAAO;AACT;AAEA,SAAgB,gBAAgB,MAAc,OAAe,GAAiD;CAC5G,IAAI,IAAI,GAAG,KAAK,GAAG,mBAAmB,KAAK;CAC3C,IAAI,EAAE,UAAU,MAAM,KAAK,aAAa,KAAK,MAAM,EAAE,MAAM;CAC3D,IAAI,EAAE,QAAQ,KAAK,YAAY,EAAE;CACjC,KAAK,UAAU,EAAE,QAAQ;CACzB,IAAI,EAAE,SAAS,KAAK,aAAa,EAAE,QAAQ,YAAY;CACvD,IAAI,EAAE,UAAU,KAAK,cAAc,OAAO,EAAE,aAAa,WAAW,EAAE,SAAS,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,EAAE,SAAS,MAAM,CAAC,IAAI;CAC/H,IAAI,EAAE,QAAQ,KAAK;CACnB,OAAO;AACT;;;;;;;AAQA,SAAgB,qBAAqB,KAAgB,eAAyC;CAC5F,OAAO;EACL,cAAc,aAAa,IAAI,UAAU,CAAC;EAC1C,SAAS,YAAuE;GAC9E,MAAM,SAAS,cAAc;GAC7B,KAAK,MAAM,EAAE,MAAM,OAAO,aAAa,SACrC,IAAI,UACF,gBAAgB,MAAM,OAAO;IAAE,GAAG;IAAS,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;IAAI,QAAQ,IAAI,SAAS;GAAE,CAAC,CACpG;EAEJ;CACF;AACF;AAEA,MAAM,mBAAmB;AACzB,MAAM,UAAU,UAAkB,mBAAmB;AAErD,SAAgB,kBAAkB,OAAe,SAA+B,MAAM,KAAK,IAAI,GAAuB;CACpH,IAAI;EACF,MAAM,MAAM,SAAS,QAAQ,OAAO,KAAK,CAAC;EAC1C,IAAI,CAAC,KAAK,OAAO,KAAA;EACjB,MAAM,EAAE,KAAK,OAAO,KAAK,MAAM,GAAG;EAClC,OAAO,OAAO,MAAM,MAAM,KAAK,mBAAmB,MAAM,KAAA;CAC1D,QAAQ;EACN;CACF;AACF;AAEA,SAAgB,aAAa,OAAe,KAAa,SAA+B,MAAM,KAAK,IAAI,GAAS;CAC9G,IAAI;EACF,SAAS,QAAQ,OAAO,KAAK,GAAG,KAAK,UAAU;GAAE;GAAK,IAAI;EAAI,CAAC,CAAC;CAClE,QAAQ,CAER;AACF;;;;;;AAOA,SAAgB,qBAAqB,MAKlC;CACD,IAAI,UAAU,kBAAkB,KAAK,OAAO,KAAK,IAAI,OAAO;CAC5D,IAAI,UAAgC;CAEpC,MAAM,gBACJ,gBAAgB;EAAE,UAAU,KAAK,IAAI,SAAS;EAAG,UAAU,KAAK;EAAU,YAAY;CAAQ,CAAC;CAEjG,MAAM,eACH,aAAa,YAAY;EACxB,IAAI,CAAC,KAAK,YAAY,CAAC,SACrB,IAAI;GACF,UAAU,MAAM,KAAK,YAAY;GACjC,aAAa,KAAK,OAAO,SAAS,KAAK,IAAI,OAAO;EACpD,QAAQ;GAEN,UAAU;GACV;EACF;EAEF,IAAI,QAAQ,GAAG,yBAAyB,KAAK,GAAG;CAClD,EAAA,CAAG;CAEL,OAAO;EAAE;EAAS;CAAO;AAC3B"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sign-in / sign-up / reset dialog as a pure state machine (no React, no
|
|
3
|
+
* network). `reduce` is the whole decision table; the host performs the effects
|
|
4
|
+
* (fetching, signing in) and feeds results back in as events.
|
|
5
|
+
*/
|
|
6
|
+
export type Mode = "signin" | "signup" | "reset";
|
|
7
|
+
/** What `GET /api/auth/[org_id]?email=` told us. */
|
|
8
|
+
export type EmailCheck = {
|
|
9
|
+
kind: "registered";
|
|
10
|
+
} | {
|
|
11
|
+
kind: "guest";
|
|
12
|
+
} | {
|
|
13
|
+
kind: "not_found";
|
|
14
|
+
} | {
|
|
15
|
+
kind: "other_org";
|
|
16
|
+
} | {
|
|
17
|
+
kind: "rate_limited";
|
|
18
|
+
} | {
|
|
19
|
+
kind: "error";
|
|
20
|
+
};
|
|
21
|
+
export type Status = {
|
|
22
|
+
kind: "idle";
|
|
23
|
+
} | {
|
|
24
|
+
kind: "busy";
|
|
25
|
+
} | {
|
|
26
|
+
kind: "info";
|
|
27
|
+
message: string;
|
|
28
|
+
} | {
|
|
29
|
+
kind: "error";
|
|
30
|
+
message: string;
|
|
31
|
+
};
|
|
32
|
+
export type AuthState = {
|
|
33
|
+
open: boolean;
|
|
34
|
+
mode: Mode;
|
|
35
|
+
/** 0: ask for the email. 1: ask for the password (and profile when signing up). */
|
|
36
|
+
step: 0 | 1;
|
|
37
|
+
email: string;
|
|
38
|
+
/** The account lives in another org: sign in with its password, then link it to this org. */
|
|
39
|
+
linking: boolean;
|
|
40
|
+
/** Ask for name and institution: a brand-new account, or linking one from another org. */
|
|
41
|
+
needsProfile: boolean;
|
|
42
|
+
status: Status;
|
|
43
|
+
};
|
|
44
|
+
export type AuthEvent = {
|
|
45
|
+
type: "open";
|
|
46
|
+
mode?: Mode;
|
|
47
|
+
} | {
|
|
48
|
+
type: "close";
|
|
49
|
+
} | {
|
|
50
|
+
type: "setMode";
|
|
51
|
+
mode: Mode;
|
|
52
|
+
} | {
|
|
53
|
+
type: "back";
|
|
54
|
+
} | {
|
|
55
|
+
type: "emailChecking";
|
|
56
|
+
email: string;
|
|
57
|
+
} | {
|
|
58
|
+
type: "emailChecked";
|
|
59
|
+
check: EmailCheck;
|
|
60
|
+
} | {
|
|
61
|
+
type: "busy";
|
|
62
|
+
} | {
|
|
63
|
+
type: "failed";
|
|
64
|
+
message: string;
|
|
65
|
+
} | {
|
|
66
|
+
type: "done";
|
|
67
|
+
};
|
|
68
|
+
export declare const initialAuthState: AuthState;
|
|
69
|
+
/** What the email check decides: where to go next, and which form to show. */
|
|
70
|
+
export type EmailDecision = {
|
|
71
|
+
mode: Mode;
|
|
72
|
+
step: 0 | 1;
|
|
73
|
+
linking: boolean;
|
|
74
|
+
needsProfile: boolean;
|
|
75
|
+
status: Status;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* The email-check decision table. Differs from the original AuthModal in one
|
|
79
|
+
* case: signing up with an email that already has an account here switches to
|
|
80
|
+
* sign-in (password only) instead of showing the full sign-up form, since the
|
|
81
|
+
* member row already exists and the profile would be thrown away.
|
|
82
|
+
*/
|
|
83
|
+
export declare function decideEmailCheck(mode: Mode, check: EmailCheck): EmailDecision;
|
|
84
|
+
export declare function reduce(state: AuthState, event: AuthEvent): AuthState;
|