@leisuresaas/react-native 0.6.8 → 0.6.9-dev.2
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/package.json +1 -1
- package/src/index.ts +5 -5
- package/src/public-auth.ts +70 -39
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leisuresaas/react-native",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9-dev.2",
|
|
4
4
|
"description": "React Native SDK for LeisureSaas: OAuth, Public Ads/App Config, Drive User Plane (publishable keys). Frontend-only — no Integration Key.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/src/index.ts
CHANGED
|
@@ -73,7 +73,6 @@ export {
|
|
|
73
73
|
changePassword,
|
|
74
74
|
changeProductPassword,
|
|
75
75
|
confirmEmailVerification,
|
|
76
|
-
confirmEmailCode,
|
|
77
76
|
confirmPasswordReset,
|
|
78
77
|
confirmProductEmailVerification,
|
|
79
78
|
confirmProductPasswordReset,
|
|
@@ -90,10 +89,10 @@ export {
|
|
|
90
89
|
refreshSession,
|
|
91
90
|
register,
|
|
92
91
|
registerProductAccount,
|
|
93
|
-
EmailCodePurpose,
|
|
94
92
|
inspectPasswordReset,
|
|
95
|
-
requestEmailCode,
|
|
96
93
|
requestEmailVerification,
|
|
94
|
+
resendVerification,
|
|
95
|
+
verifyRegistrationCode,
|
|
97
96
|
requestPasswordReset,
|
|
98
97
|
requestProductEmailVerification,
|
|
99
98
|
requestProductPasswordReset,
|
|
@@ -106,13 +105,14 @@ export {
|
|
|
106
105
|
} from "./public-auth";
|
|
107
106
|
export type {
|
|
108
107
|
AuthTokens,
|
|
109
|
-
EmailCodeRequest,
|
|
110
|
-
EmailProof,
|
|
111
108
|
HeartbeatOptions,
|
|
112
109
|
PasswordResetInfo,
|
|
113
110
|
ProductAuthTokens,
|
|
114
111
|
PublicAuthContext,
|
|
112
|
+
RegisterResult,
|
|
115
113
|
UserSession,
|
|
114
|
+
VerificationMethod,
|
|
115
|
+
VerificationSent,
|
|
116
116
|
} from "./public-auth";
|
|
117
117
|
export { appDeviceId } from "./device-id";
|
|
118
118
|
export { getPublicAdsFeed, recordPublicAdEvents } from "./public-ads";
|
package/src/public-auth.ts
CHANGED
|
@@ -114,70 +114,101 @@ function tokensFromJSON(data: TokenJSON): AuthTokens {
|
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
/** How `register` confirms the email: `"link"` (default) or a 6-digit `"code"`. */
|
|
118
|
+
export type VerificationMethod = "link" | "code";
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Outcome of `register`. `tokens` is set when `emailProof` skipped verification; otherwise
|
|
122
|
+
* `verification` says which email was sent, and `expiresIn` / `resendAfter` (seconds) are set for codes.
|
|
123
|
+
*/
|
|
124
|
+
export type RegisterResult = {
|
|
125
|
+
verificationRequired: boolean;
|
|
126
|
+
tokens?: AuthTokens;
|
|
127
|
+
verification?: VerificationMethod;
|
|
128
|
+
expiresIn?: number;
|
|
129
|
+
resendAfter?: number;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/** Outcome of `resendVerification`; `expiresIn` / `resendAfter` (seconds) are set for `"code"`. */
|
|
133
|
+
export type VerificationSent = { expiresIn?: number; resendAfter?: number };
|
|
134
|
+
|
|
135
|
+
type VerificationJSON = { verification?: string; expires_in?: number; resend_after?: number };
|
|
136
|
+
|
|
117
137
|
/**
|
|
118
|
-
* Without `emailProof` the platform emails a verification link
|
|
119
|
-
*
|
|
138
|
+
* Without `emailProof` the platform emails a verification link (`verification: "link"`, default) or a
|
|
139
|
+
* 6-digit code (`"code"`, confirm with `verifyRegistrationCode`) and returns `verificationRequired`.
|
|
140
|
+
* With a proof from the product backend (Integration `POST /v1/auth/email-proofs`) it returns
|
|
141
|
+
* `tokens` instead and ignores `verification`. Errors: EmailAlreadyExists (verified account), FeatureDisabled (`"code"`
|
|
142
|
+
* switched off), RateLimited (`"code"`, `err.retryAfter`).
|
|
120
143
|
*/
|
|
121
144
|
export async function register(
|
|
122
145
|
ctx: PublicAuthContext,
|
|
123
|
-
input: {
|
|
124
|
-
|
|
146
|
+
input: {
|
|
147
|
+
email: string;
|
|
148
|
+
password: string;
|
|
149
|
+
name?: string;
|
|
150
|
+
locale?: string;
|
|
151
|
+
emailProof?: string;
|
|
152
|
+
verification?: VerificationMethod;
|
|
153
|
+
},
|
|
154
|
+
): Promise<RegisterResult> {
|
|
125
155
|
const body: Record<string, string> = {
|
|
126
156
|
email: input.email, password: input.password, name: input.name ?? "", locale: input.locale ?? "",
|
|
127
157
|
};
|
|
128
158
|
const proof = input.emailProof?.trim() ?? "";
|
|
129
159
|
if (proof) body.email_proof = proof;
|
|
130
|
-
|
|
160
|
+
if (input.verification && input.verification !== "link") body.verification = input.verification;
|
|
161
|
+
const resp = await publicAuthRequest<TokenJSON & VerificationJSON & { verification_required?: boolean }>(
|
|
162
|
+
ctx, "/register", body,
|
|
163
|
+
);
|
|
131
164
|
if (resp.access_token?.trim()) {
|
|
132
165
|
return { verificationRequired: false, tokens: tokensFromJSON(resp) };
|
|
133
166
|
}
|
|
134
|
-
|
|
167
|
+
const out: RegisterResult = {
|
|
168
|
+
verificationRequired: resp.verification_required !== false,
|
|
169
|
+
verification: resp.verification === "code" ? "code" : "link",
|
|
170
|
+
};
|
|
171
|
+
if (resp.expires_in !== undefined) out.expiresIn = resp.expires_in;
|
|
172
|
+
if (resp.resend_after !== undefined) out.resendAfter = resp.resend_after;
|
|
173
|
+
return out;
|
|
135
174
|
}
|
|
136
175
|
|
|
137
|
-
/** `purpose` values for `requestEmailCode`. Only `register` today. */
|
|
138
|
-
export const EmailCodePurpose = { Register: "register" } as const;
|
|
139
|
-
|
|
140
|
-
/** Result of `requestEmailCode`; the same for registered emails. Times in seconds. */
|
|
141
|
-
export type EmailCodeRequest = { expiresIn: number; resendAfter: number };
|
|
142
|
-
|
|
143
|
-
/** One-time proof from `confirmEmailCode`; pass `proof` as `register({ emailProof })`. */
|
|
144
|
-
export type EmailProof = { proof: string; expiresAtUnix: number };
|
|
145
|
-
|
|
146
|
-
/** The account behind a valid password reset token. */
|
|
147
|
-
export type PasswordResetInfo = { email: string; expiresAtUnix: number };
|
|
148
|
-
|
|
149
176
|
/**
|
|
150
|
-
*
|
|
151
|
-
*
|
|
177
|
+
* Confirms the 6-digit code sent by `register` / `resendVerification` with `"code"` and signs the user
|
|
178
|
+
* in (same tokens as `confirmEmailVerification`). Errors: EmailCodeInvalid (wrong, voided or used code,
|
|
179
|
+
* or 5 wrong tries), EmailCodeExpired, RateLimited, FeatureDisabled.
|
|
152
180
|
*/
|
|
153
|
-
export async function
|
|
181
|
+
export async function verifyRegistrationCode(
|
|
154
182
|
ctx: PublicAuthContext,
|
|
155
|
-
input: { email: string;
|
|
156
|
-
): Promise<
|
|
157
|
-
const resp = await publicAuthRequest<
|
|
158
|
-
email: input.email.trim(),
|
|
183
|
+
input: { email: string; code: string },
|
|
184
|
+
): Promise<AuthTokens> {
|
|
185
|
+
const resp = await publicAuthRequest<TokenJSON>(ctx, "/email-verification/verify-code", {
|
|
186
|
+
email: input.email.trim(), code: input.code.trim(),
|
|
159
187
|
});
|
|
160
|
-
return
|
|
188
|
+
return tokensFromJSON(resp);
|
|
161
189
|
}
|
|
162
190
|
|
|
163
191
|
/**
|
|
164
|
-
*
|
|
165
|
-
*
|
|
192
|
+
* Sends a new confirmation link or code to an unverified account. Unknown and verified emails get no
|
|
193
|
+
* email but the same result. `"link"` is `requestEmailVerification`.
|
|
194
|
+
* Errors: RateLimited (`"code"`, `err.retryAfter`), FeatureDisabled (`"code"`).
|
|
166
195
|
*/
|
|
167
|
-
export async function
|
|
196
|
+
export async function resendVerification(
|
|
168
197
|
ctx: PublicAuthContext,
|
|
169
|
-
input: { email: string;
|
|
170
|
-
): Promise<
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
if (
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return { proof, expiresAtUnix: resp.expires_at_unix ?? 0 };
|
|
198
|
+
input: { email: string; verification?: VerificationMethod; locale?: string },
|
|
199
|
+
): Promise<VerificationSent> {
|
|
200
|
+
const body: Record<string, string> = { email: input.email, locale: input.locale ?? "" };
|
|
201
|
+
if (input.verification && input.verification !== "link") body.verification = input.verification;
|
|
202
|
+
const resp = await publicAuthRequest<VerificationJSON>(ctx, "/email-verification", body);
|
|
203
|
+
const out: VerificationSent = {};
|
|
204
|
+
if (resp.expires_in !== undefined) out.expiresIn = resp.expires_in;
|
|
205
|
+
if (resp.resend_after !== undefined) out.resendAfter = resp.resend_after;
|
|
206
|
+
return out;
|
|
179
207
|
}
|
|
180
208
|
|
|
209
|
+
/** The account behind a valid password reset token. */
|
|
210
|
+
export type PasswordResetInfo = { email: string; expiresAtUnix: number };
|
|
211
|
+
|
|
181
212
|
/**
|
|
182
213
|
* Returns the email behind the `token` of a password reset link; the token is not consumed.
|
|
183
214
|
* Errors: PasswordResetTokenInvalid, RateLimited, FeatureDisabled.
|