@techfinityedge/koolbase-react-native 1.9.0 → 1.10.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/dist/auth-errors.d.ts +12 -0
- package/dist/auth-errors.js +33 -1
- package/dist/auth.d.ts +33 -1
- package/dist/auth.js +92 -0
- package/dist/device-metadata.d.ts +1 -1
- package/dist/device-metadata.js +1 -1
- package/dist/types.d.ts +23 -0
- package/package.json +1 -1
package/dist/auth-errors.d.ts
CHANGED
|
@@ -94,3 +94,15 @@ export declare class PhoneAlreadyLinkedError extends KoolbaseAuthError {
|
|
|
94
94
|
export declare class SmsConfigMissingError extends KoolbaseAuthError {
|
|
95
95
|
constructor();
|
|
96
96
|
}
|
|
97
|
+
export declare class AppleSignInNotConfiguredError extends KoolbaseAuthError {
|
|
98
|
+
constructor();
|
|
99
|
+
}
|
|
100
|
+
export declare class InvalidAppleTokenError extends KoolbaseAuthError {
|
|
101
|
+
constructor();
|
|
102
|
+
}
|
|
103
|
+
export declare class AppleEmailRequiredError extends KoolbaseAuthError {
|
|
104
|
+
constructor();
|
|
105
|
+
}
|
|
106
|
+
export declare class OAuthEmailConflictError extends KoolbaseAuthError {
|
|
107
|
+
constructor();
|
|
108
|
+
}
|
package/dist/auth-errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SmsConfigMissingError = exports.PhoneAlreadyLinkedError = exports.OtpRateLimitError = exports.OtpMaxAttemptsError = exports.OtpInvalidError = exports.OtpExpiredError = exports.InvalidPhoneNumberError = exports.NetworkError = exports.RateLimitError = exports.UnlockTokenInvalidError = exports.AccountLockedError = exports.TokenRevokedError = exports.SessionExpiredError = exports.WeakPasswordError = exports.UserDisabledError = exports.EmailAlreadyInUseError = exports.InvalidCredentialsError = exports.KoolbaseAuthError = void 0;
|
|
3
|
+
exports.OAuthEmailConflictError = exports.AppleEmailRequiredError = exports.InvalidAppleTokenError = exports.AppleSignInNotConfiguredError = exports.SmsConfigMissingError = exports.PhoneAlreadyLinkedError = exports.OtpRateLimitError = exports.OtpMaxAttemptsError = exports.OtpInvalidError = exports.OtpExpiredError = exports.InvalidPhoneNumberError = exports.NetworkError = exports.RateLimitError = exports.UnlockTokenInvalidError = exports.AccountLockedError = exports.TokenRevokedError = exports.SessionExpiredError = exports.WeakPasswordError = exports.UserDisabledError = exports.EmailAlreadyInUseError = exports.InvalidCredentialsError = exports.KoolbaseAuthError = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Base error type for all Koolbase auth errors. Catchable via
|
|
6
6
|
* `instanceof KoolbaseAuthError` to handle any auth-related failure
|
|
@@ -192,3 +192,35 @@ class SmsConfigMissingError extends KoolbaseAuthError {
|
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
exports.SmsConfigMissingError = SmsConfigMissingError;
|
|
195
|
+
class AppleSignInNotConfiguredError extends KoolbaseAuthError {
|
|
196
|
+
constructor() {
|
|
197
|
+
super('Apple Sign-In is not configured for this environment', 'apple_not_configured');
|
|
198
|
+
this.name = 'AppleSignInNotConfiguredError';
|
|
199
|
+
Object.setPrototypeOf(this, AppleSignInNotConfiguredError.prototype);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
exports.AppleSignInNotConfiguredError = AppleSignInNotConfiguredError;
|
|
203
|
+
class InvalidAppleTokenError extends KoolbaseAuthError {
|
|
204
|
+
constructor() {
|
|
205
|
+
super('Invalid Apple identity token', 'invalid_apple_token');
|
|
206
|
+
this.name = 'InvalidAppleTokenError';
|
|
207
|
+
Object.setPrototypeOf(this, InvalidAppleTokenError.prototype);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.InvalidAppleTokenError = InvalidAppleTokenError;
|
|
211
|
+
class AppleEmailRequiredError extends KoolbaseAuthError {
|
|
212
|
+
constructor() {
|
|
213
|
+
super('Apple did not return email for this sign-in. Revoke this app in iOS Settings → Apple ID and retry.', 'apple_email_required');
|
|
214
|
+
this.name = 'AppleEmailRequiredError';
|
|
215
|
+
Object.setPrototypeOf(this, AppleEmailRequiredError.prototype);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.AppleEmailRequiredError = AppleEmailRequiredError;
|
|
219
|
+
class OAuthEmailConflictError extends KoolbaseAuthError {
|
|
220
|
+
constructor() {
|
|
221
|
+
super('Email is already in use by another account. Sign in with your existing method and link Apple from settings.', 'oauth_email_conflict');
|
|
222
|
+
this.name = 'OAuthEmailConflictError';
|
|
223
|
+
Object.setPrototypeOf(this, OAuthEmailConflictError.prototype);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
exports.OAuthEmailConflictError = OAuthEmailConflictError;
|
package/dist/auth.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthStateListener, KoolbaseConfig, KoolbaseSession, KoolbaseUser, LinkPhoneParams, LoginParams, OtpSendResult, PhoneVerifyResult, RegisterParams, RestoreResult, SendOtpParams, VerifyOtpParams } from './types';
|
|
1
|
+
import { AuthStateListener, KoolbaseConfig, KoolbaseSession, KoolbaseUser, LinkPhoneParams, LoginParams, OtpSendResult, PhoneVerifyResult, RegisterParams, RestoreResult, SendOtpParams, SignInWithAppleParams, VerifyOtpParams } from './types';
|
|
2
2
|
export declare class KoolbaseAuth {
|
|
3
3
|
private config;
|
|
4
4
|
private storage;
|
|
@@ -59,6 +59,38 @@ export declare class KoolbaseAuth {
|
|
|
59
59
|
restoreSession(): Promise<RestoreResult>;
|
|
60
60
|
register(params: RegisterParams): Promise<KoolbaseUser>;
|
|
61
61
|
login(params: LoginParams): Promise<KoolbaseSession>;
|
|
62
|
+
/**
|
|
63
|
+
* Sign in with Apple using a credential obtained from a native Apple
|
|
64
|
+
* Sign-In SDK.
|
|
65
|
+
*
|
|
66
|
+
* The SDK is library-agnostic — use any native Apple Sign-In package
|
|
67
|
+
* (`@invertase/react-native-apple-authentication`, etc.) and pass the
|
|
68
|
+
* resulting `identityToken`, optional `nonce`, and optional `fullName`.
|
|
69
|
+
*
|
|
70
|
+
* `fullName` is meaningful only on first sign-in — Apple omits name
|
|
71
|
+
* data on subsequent sign-ins. The server persists at link time and
|
|
72
|
+
* ignores on subsequent sign-ins.
|
|
73
|
+
*
|
|
74
|
+
* On success the session is persisted via the configured storage and
|
|
75
|
+
* `onAuthStateChange` fires with the resolved user.
|
|
76
|
+
*
|
|
77
|
+
* @throws AppleSignInNotConfiguredError when Apple is not enabled in
|
|
78
|
+
* the dashboard OAuth config for this environment (400).
|
|
79
|
+
* @throws InvalidAppleTokenError when the token signature, audience,
|
|
80
|
+
* expiry, replay, or nonce check failed server-side (401).
|
|
81
|
+
* @throws UserDisabledError when the account flag is set to disabled (403).
|
|
82
|
+
* @throws AppleEmailRequiredError when Apple did not return email for
|
|
83
|
+
* a new-account sign-in (400).
|
|
84
|
+
* @throws OAuthEmailConflictError when email matches existing user
|
|
85
|
+
* but auto-link rule blocked (409).
|
|
86
|
+
*/
|
|
87
|
+
signInWithApple(params: SignInWithAppleParams): Promise<KoolbaseSession>;
|
|
88
|
+
/**
|
|
89
|
+
* Parses a /v1/sdk/auth/oauth/apple response. Distinct from
|
|
90
|
+
* parseSessionResponse because OAuth error semantics differ from
|
|
91
|
+
* credential auth — status codes map to a separate error set.
|
|
92
|
+
*/
|
|
93
|
+
private parseAppleSessionResponse;
|
|
62
94
|
refresh(refreshToken?: string): Promise<KoolbaseSession>;
|
|
63
95
|
private _doRefresh;
|
|
64
96
|
logout(): Promise<boolean>;
|
package/dist/auth.js
CHANGED
|
@@ -209,6 +209,98 @@ class KoolbaseAuth {
|
|
|
209
209
|
await this.setSessionInternal(session);
|
|
210
210
|
return session;
|
|
211
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Sign in with Apple using a credential obtained from a native Apple
|
|
214
|
+
* Sign-In SDK.
|
|
215
|
+
*
|
|
216
|
+
* The SDK is library-agnostic — use any native Apple Sign-In package
|
|
217
|
+
* (`@invertase/react-native-apple-authentication`, etc.) and pass the
|
|
218
|
+
* resulting `identityToken`, optional `nonce`, and optional `fullName`.
|
|
219
|
+
*
|
|
220
|
+
* `fullName` is meaningful only on first sign-in — Apple omits name
|
|
221
|
+
* data on subsequent sign-ins. The server persists at link time and
|
|
222
|
+
* ignores on subsequent sign-ins.
|
|
223
|
+
*
|
|
224
|
+
* On success the session is persisted via the configured storage and
|
|
225
|
+
* `onAuthStateChange` fires with the resolved user.
|
|
226
|
+
*
|
|
227
|
+
* @throws AppleSignInNotConfiguredError when Apple is not enabled in
|
|
228
|
+
* the dashboard OAuth config for this environment (400).
|
|
229
|
+
* @throws InvalidAppleTokenError when the token signature, audience,
|
|
230
|
+
* expiry, replay, or nonce check failed server-side (401).
|
|
231
|
+
* @throws UserDisabledError when the account flag is set to disabled (403).
|
|
232
|
+
* @throws AppleEmailRequiredError when Apple did not return email for
|
|
233
|
+
* a new-account sign-in (400).
|
|
234
|
+
* @throws OAuthEmailConflictError when email matches existing user
|
|
235
|
+
* but auto-link rule blocked (409).
|
|
236
|
+
*/
|
|
237
|
+
async signInWithApple(params) {
|
|
238
|
+
const body = {
|
|
239
|
+
identity_token: params.identityToken,
|
|
240
|
+
};
|
|
241
|
+
if (params.nonce && params.nonce.length > 0) {
|
|
242
|
+
body.nonce = params.nonce;
|
|
243
|
+
}
|
|
244
|
+
if (params.fullName) {
|
|
245
|
+
const nameJson = {};
|
|
246
|
+
if (params.fullName.givenName)
|
|
247
|
+
nameJson.given_name = params.fullName.givenName;
|
|
248
|
+
if (params.fullName.familyName)
|
|
249
|
+
nameJson.family_name = params.fullName.familyName;
|
|
250
|
+
if (Object.keys(nameJson).length > 0) {
|
|
251
|
+
body.full_name = nameJson;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const res = await this.authRequest('/v1/sdk/auth/oauth/apple', {
|
|
255
|
+
method: 'POST',
|
|
256
|
+
body,
|
|
257
|
+
});
|
|
258
|
+
const session = await this.parseAppleSessionResponse(res);
|
|
259
|
+
await this.setSessionInternal(session);
|
|
260
|
+
return session;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Parses a /v1/sdk/auth/oauth/apple response. Distinct from
|
|
264
|
+
* parseSessionResponse because OAuth error semantics differ from
|
|
265
|
+
* credential auth — status codes map to a separate error set.
|
|
266
|
+
*/
|
|
267
|
+
async parseAppleSessionResponse(res) {
|
|
268
|
+
if (res.status === 200) {
|
|
269
|
+
const data = await res.json();
|
|
270
|
+
return {
|
|
271
|
+
accessToken: data.access_token,
|
|
272
|
+
refreshToken: data.refresh_token,
|
|
273
|
+
expiresAt: data.expires_at,
|
|
274
|
+
user: this.mapUser(data.user),
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
let errorMessage = '';
|
|
278
|
+
try {
|
|
279
|
+
const data = await res.json();
|
|
280
|
+
errorMessage = data?.error ?? '';
|
|
281
|
+
}
|
|
282
|
+
catch {
|
|
283
|
+
// best-effort error message extraction
|
|
284
|
+
}
|
|
285
|
+
if (res.status === 400) {
|
|
286
|
+
if (errorMessage.includes('not configured')) {
|
|
287
|
+
throw new auth_errors_1.AppleSignInNotConfiguredError();
|
|
288
|
+
}
|
|
289
|
+
if (errorMessage.includes('did not return email')) {
|
|
290
|
+
throw new auth_errors_1.AppleEmailRequiredError();
|
|
291
|
+
}
|
|
292
|
+
throw new auth_errors_1.KoolbaseAuthError(`apple sign-in failed: ${errorMessage}`, 'apple_signin_failed');
|
|
293
|
+
}
|
|
294
|
+
if (res.status === 401)
|
|
295
|
+
throw new auth_errors_1.InvalidAppleTokenError();
|
|
296
|
+
if (res.status === 403)
|
|
297
|
+
throw new auth_errors_1.UserDisabledError();
|
|
298
|
+
if (res.status === 409)
|
|
299
|
+
throw new auth_errors_1.OAuthEmailConflictError();
|
|
300
|
+
if (res.status === 429)
|
|
301
|
+
throw new auth_errors_1.RateLimitError(errorMessage);
|
|
302
|
+
throw new auth_errors_1.KoolbaseAuthError(`apple sign-in failed: ${res.status} ${errorMessage}`, `apple_signin_http_${res.status}`);
|
|
303
|
+
}
|
|
212
304
|
async refresh(refreshToken) {
|
|
213
305
|
if (this.ongoingRefresh) {
|
|
214
306
|
return this.ongoingRefresh;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* version-conditional logic (deprecation warnings, schema migrations,
|
|
5
5
|
* feature flags). Must match the `version` field in package.json.
|
|
6
6
|
*/
|
|
7
|
-
export declare const koolbaseSdkVersion = "1.
|
|
7
|
+
export declare const koolbaseSdkVersion = "1.10.0";
|
|
8
8
|
/**
|
|
9
9
|
* Builds device-identifying headers attached to every Koolbase auth
|
|
10
10
|
* request. Mirrors the Flutter SDK's `DeviceMetadata` for parity. Apps
|
package/dist/device-metadata.js
CHANGED
|
@@ -9,7 +9,7 @@ const auth_storage_1 = require("./auth-storage");
|
|
|
9
9
|
* version-conditional logic (deprecation warnings, schema migrations,
|
|
10
10
|
* feature flags). Must match the `version` field in package.json.
|
|
11
11
|
*/
|
|
12
|
-
exports.koolbaseSdkVersion = '1.
|
|
12
|
+
exports.koolbaseSdkVersion = '1.10.0';
|
|
13
13
|
/**
|
|
14
14
|
* Generate a UUIDv4-shaped string for use as a stable per-install
|
|
15
15
|
* device label. Not cryptographically secure — this is a label, not a
|
package/dist/types.d.ts
CHANGED
|
@@ -201,3 +201,26 @@ export interface FunctionInvokeResult {
|
|
|
201
201
|
data: Record<string, unknown> | null;
|
|
202
202
|
success: boolean;
|
|
203
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* Apple's optional full-name structure returned only on a user's FIRST
|
|
206
|
+
* Sign in with Apple. Both fields nullable; subsequent sign-ins omit
|
|
207
|
+
* this entirely.
|
|
208
|
+
*
|
|
209
|
+
* Pass to `KoolbaseAuth.signInWithApple` only on first sign-in. The
|
|
210
|
+
* server persists at link time and ignores on subsequent sign-ins
|
|
211
|
+
* (matches Apple's documented contract).
|
|
212
|
+
*/
|
|
213
|
+
export interface AppleFullName {
|
|
214
|
+
givenName?: string;
|
|
215
|
+
familyName?: string;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Parameters for `KoolbaseAuth.signInWithApple`. The SDK is
|
|
219
|
+
* library-agnostic — `identityToken` should come from any native
|
|
220
|
+
* Apple Sign-In package (e.g. `@invertase/react-native-apple-authentication`).
|
|
221
|
+
*/
|
|
222
|
+
export interface SignInWithAppleParams {
|
|
223
|
+
identityToken: string;
|
|
224
|
+
nonce?: string;
|
|
225
|
+
fullName?: AppleFullName;
|
|
226
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@techfinityedge/koolbase-react-native",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "React Native SDK for Koolbase \u2014 auth, database, storage, realtime, feature flags, and functions in one package.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|