@leisuresaas/react-native 0.6.8-dev.3 → 0.6.9-dev.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leisuresaas/react-native",
3
- "version": "0.6.8-dev.3",
3
+ "version": "0.6.9-dev.1",
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
@@ -94,6 +94,8 @@ export {
94
94
  inspectPasswordReset,
95
95
  requestEmailCode,
96
96
  requestEmailVerification,
97
+ resendVerification,
98
+ verifyRegistrationCode,
97
99
  requestPasswordReset,
98
100
  requestProductEmailVerification,
99
101
  requestProductPasswordReset,
@@ -112,7 +114,10 @@ export type {
112
114
  PasswordResetInfo,
113
115
  ProductAuthTokens,
114
116
  PublicAuthContext,
117
+ RegisterResult,
115
118
  UserSession,
119
+ VerificationMethod,
120
+ VerificationSent,
116
121
  } from "./public-auth";
117
122
  export { appDeviceId } from "./device-id";
118
123
  export { getPublicAdsFeed, recordPublicAdEvents } from "./public-ads";
@@ -114,24 +114,96 @@ 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 and returns `verificationRequired`.
119
- * With a proof from `confirmEmailCode` (or the product backend) it returns `tokens` instead.
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 `confirmEmailCode` (or the product backend) it returns `tokens` instead and
141
+ * 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: { email: string; password: string; name?: string; locale?: string; emailProof?: string },
124
- ): Promise<{ verificationRequired: boolean; tokens?: AuthTokens }> {
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
- const resp = await publicAuthRequest<TokenJSON & { verification_required?: boolean }>(ctx, "/register", body);
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
- return { verificationRequired: resp.verification_required !== false };
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;
174
+ }
175
+
176
+ /**
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.
180
+ */
181
+ export async function verifyRegistrationCode(
182
+ ctx: PublicAuthContext,
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(),
187
+ });
188
+ return tokensFromJSON(resp);
189
+ }
190
+
191
+ /**
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"`).
195
+ */
196
+ export async function resendVerification(
197
+ ctx: PublicAuthContext,
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;
135
207
  }
136
208
 
137
209
  /** `purpose` values for `requestEmailCode`. Only `register` today. */