apps-sdk 2.1.3 → 2.1.5
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/config.js +1 -0
- package/index.js +1 -1
- package/package.json +2 -2
- package/src/libraries/Session.js +31 -0
- package/types/index.d.ts +267 -0
package/config.js
CHANGED
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {NotificationsPush, Networking, Storage, Session, Utils, PayWallLogic, Rating, AdJust, TrackingTransparency, Voice, MixPanel, Adapty, HomeActions, Facebook, Legal, Authentication} from "./src/libraries";
|
|
1
|
+
import {NotificationsPush, Networking, Storage, Session, Utils, PayWallLogic, Rating, AdJust, TrackingTransparency, Voice, MixPanel, Adapty, HomeActions, Facebook, Legal, Authentication,Firebase} from "./src/libraries";
|
|
2
2
|
// import PayWall from "./src/components/PayWall"; // DEPRECATED: Use SDK.adaptyOnboarding or SDK.adapty.showPaywall() instead
|
|
3
3
|
import AdaptyOnboarding from "./src/components/AdaptyOnboarding";
|
|
4
4
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apps-sdk",
|
|
3
|
-
"version": "2.1.
|
|
4
|
-
"description": "Apps SDK - Compatible with Expo SDK 54 + React 19 - add
|
|
3
|
+
"version": "2.1.5",
|
|
4
|
+
"description": "Apps SDK - Compatible with Expo SDK 54 + React 19 - add generic method checksubscription to check if user has active subscription in webapp",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "ASD",
|
|
7
7
|
"license": "ISC",
|
package/src/libraries/Session.js
CHANGED
|
@@ -284,6 +284,37 @@ class Session {
|
|
|
284
284
|
return 0;
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
|
+
|
|
288
|
+
checkSubscriptionWebapp = async (webappUrl, websiteId) => {
|
|
289
|
+
config.DEBUG_MODE && console.debug("checkSubscriptionWebapp");
|
|
290
|
+
|
|
291
|
+
try {
|
|
292
|
+
const endpoint = `${webappUrl}${config.WEBAPP_PATHS.CHECK_SUBS}`;
|
|
293
|
+
const payload = this.getWebappBasePayload(websiteId);
|
|
294
|
+
|
|
295
|
+
const response = await fetch(endpoint, {
|
|
296
|
+
method: 'POST',
|
|
297
|
+
headers: { 'Content-Type': 'application/json' },
|
|
298
|
+
body: JSON.stringify(payload),
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
const data = await response.json();
|
|
302
|
+
config.DEBUG_MODE && console.debug("checkSubscriptionWebapp - result: ", data);
|
|
303
|
+
|
|
304
|
+
if (data?.success && data?.data?.[0]) {
|
|
305
|
+
const subData = data.data[0];
|
|
306
|
+
await this.setIsSubscribed(subData.subscription_active);
|
|
307
|
+
await this.setSubscriptionData(subData);
|
|
308
|
+
|
|
309
|
+
return subData;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return null;
|
|
313
|
+
} catch (error) {
|
|
314
|
+
console.error('[SDK] checkSubscriptionWebapp error:', error);
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
287
318
|
}
|
|
288
319
|
|
|
289
320
|
export default new Session();
|
package/types/index.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ declare module 'apps-sdk' {
|
|
|
40
40
|
setUserCreateEndpoint(endpoint: string): void;
|
|
41
41
|
setBaseUrl(baseUrl: string): void;
|
|
42
42
|
getCredits(webappUrl: string, websiteId: string): Promise<number>;
|
|
43
|
+
checkSubscriptionWebapp(webappUrl: string, websiteId: string): Promise<any>;
|
|
43
44
|
getWebappBasePayload(websiteId: string, additionalData?: any): any;
|
|
44
45
|
initSession(): Promise<void>;
|
|
45
46
|
storeSessionStructure(): Promise<void>;
|
|
@@ -343,6 +344,269 @@ declare module 'apps-sdk' {
|
|
|
343
344
|
setUserProperty(name: string, value: string): Promise<void>;
|
|
344
345
|
}
|
|
345
346
|
|
|
347
|
+
// ─── Authentication ────────────────────────────────────────────────────────
|
|
348
|
+
|
|
349
|
+
export interface AuthApiResult<T = any> {
|
|
350
|
+
success: boolean;
|
|
351
|
+
data?: T;
|
|
352
|
+
error?: string;
|
|
353
|
+
code?: number;
|
|
354
|
+
message?: string;
|
|
355
|
+
raw?: any;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export interface AuthLoginPayload {
|
|
359
|
+
/** Email or username */
|
|
360
|
+
login?: string;
|
|
361
|
+
/** Credential (alias for login) */
|
|
362
|
+
credential?: string;
|
|
363
|
+
/** Password */
|
|
364
|
+
password: string;
|
|
365
|
+
/** Optional website ID (defaults to config value) */
|
|
366
|
+
websiteid?: string;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export interface AuthRegisterPayload {
|
|
370
|
+
/** Email or username */
|
|
371
|
+
login?: string;
|
|
372
|
+
/** Email (alias for login) */
|
|
373
|
+
email?: string;
|
|
374
|
+
/** Password */
|
|
375
|
+
password: string;
|
|
376
|
+
/** Optional website ID (defaults to config value) */
|
|
377
|
+
websiteid?: string;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export interface AuthRegisterAndLinkPayload {
|
|
381
|
+
email: string;
|
|
382
|
+
password: string;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export interface AuthLinkUserPayload {
|
|
386
|
+
/** Web user ID */
|
|
387
|
+
user_id: string;
|
|
388
|
+
/** Mobile app user ID */
|
|
389
|
+
app_user_id: string;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export interface AuthCheckLinkPayload {
|
|
393
|
+
user_id: string;
|
|
394
|
+
app_user_id: string;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export interface AuthCheckSubscriptionPayload {
|
|
398
|
+
user_id: string;
|
|
399
|
+
app_user_id: string;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export interface AuthValidatePhonePayload {
|
|
403
|
+
phoneNumber: string;
|
|
404
|
+
countryCode: string;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export interface AuthRequestPasswordResetPayload {
|
|
408
|
+
credential: string;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
export interface AuthVerifyResetCodePayload {
|
|
412
|
+
code: string;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export interface AuthResetPasswordPayload {
|
|
416
|
+
resetToken: string;
|
|
417
|
+
newPassword: string;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export interface AuthResendCodePayload {
|
|
421
|
+
credential: string;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export interface AuthValidateQrCodePayload {
|
|
425
|
+
qrData: string;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
export interface AuthLinkWithQrCodePayload {
|
|
429
|
+
user_id: string;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export interface AuthUserData {
|
|
433
|
+
us_id: string | number;
|
|
434
|
+
us_login?: string;
|
|
435
|
+
login?: string;
|
|
436
|
+
metadata?: Record<string, any> | any[];
|
|
437
|
+
subscription_data?: AuthSubscriptionData;
|
|
438
|
+
success?: number;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export interface AuthSubscriptionData {
|
|
442
|
+
subscription_active?: boolean;
|
|
443
|
+
[key: string]: any;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
export interface AuthLinkedUserData {
|
|
447
|
+
success: number;
|
|
448
|
+
linked: boolean;
|
|
449
|
+
items?: AuthUserData[];
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export interface AuthRegisterAndLinkResult {
|
|
453
|
+
success: boolean;
|
|
454
|
+
user?: AuthUserData;
|
|
455
|
+
linked?: boolean;
|
|
456
|
+
error?: string;
|
|
457
|
+
code?: number;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
export interface AuthQrValidationData {
|
|
461
|
+
valid: boolean;
|
|
462
|
+
user_id?: string;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
export interface AuthQrLinkData {
|
|
466
|
+
linked: boolean;
|
|
467
|
+
message?: string;
|
|
468
|
+
subscriptionActive?: boolean;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
export interface AuthCallApiOptions {
|
|
472
|
+
retries?: number;
|
|
473
|
+
timeoutMs?: number;
|
|
474
|
+
silent?: boolean;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
export class Authentication {
|
|
478
|
+
AUTH_API_BASE_URL: string;
|
|
479
|
+
USER_API_BASE_URL: string;
|
|
480
|
+
CHATCONNECT_API_BASE_URL: string;
|
|
481
|
+
|
|
482
|
+
/** Get website ID from config */
|
|
483
|
+
getWebsiteId(): string;
|
|
484
|
+
|
|
485
|
+
/** Get app user ID from session */
|
|
486
|
+
getAppUserId(): string;
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Generic API call helper with retry logic.
|
|
490
|
+
*/
|
|
491
|
+
callApi(url: string, payload: object, opts?: AuthCallApiOptions): Promise<AuthApiResult>;
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Login with credentials.
|
|
495
|
+
* POST /auth/auth-user
|
|
496
|
+
*/
|
|
497
|
+
login(payload: AuthLoginPayload): Promise<AuthApiResult<AuthUserData>>;
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Register a new user account.
|
|
501
|
+
* POST /chatconnect/create-user
|
|
502
|
+
*/
|
|
503
|
+
register(payload: AuthRegisterPayload): Promise<AuthApiResult<{ user: AuthUserData }>>;
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Complete registration flow: create-user → link-user.
|
|
507
|
+
*/
|
|
508
|
+
registerAndLinkAccount(payload: AuthRegisterAndLinkPayload): Promise<AuthRegisterAndLinkResult>;
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Link a user account.
|
|
512
|
+
* POST /user/link
|
|
513
|
+
*/
|
|
514
|
+
linkUser(payload: AuthLinkUserPayload): Promise<AuthApiResult<AuthLinkedUserData>>;
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Fetch authenticated user profile using stored credentials.
|
|
518
|
+
*/
|
|
519
|
+
fetchUserProfile(): Promise<AuthApiResult<AuthUserData>>;
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Check if user account is linked (using stored data).
|
|
523
|
+
*/
|
|
524
|
+
isAccountLinked(): Promise<boolean>;
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Get stored auth user login (email).
|
|
528
|
+
*/
|
|
529
|
+
getStoredUserLogin(): Promise<string | null>;
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Check if user is linked.
|
|
533
|
+
* POST /user/check-link
|
|
534
|
+
*/
|
|
535
|
+
checkLink(payload: AuthCheckLinkPayload): Promise<AuthApiResult>;
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Check user subscription status.
|
|
539
|
+
* POST /user/check-subs
|
|
540
|
+
*/
|
|
541
|
+
checkSubscription(payload: AuthCheckSubscriptionPayload): Promise<AuthApiResult>;
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Check if a credential exists (stub for backward compatibility).
|
|
545
|
+
*/
|
|
546
|
+
checkCredential(payload: { credentialType: string; [key: string]: any }): Promise<AuthApiResult<{ exists: boolean; credentialType: string; requiresPhone: boolean }>>;
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Validate phone number (client-side).
|
|
550
|
+
*/
|
|
551
|
+
validatePhone(payload: AuthValidatePhonePayload): Promise<AuthApiResult<{ valid: boolean; formattedPhone?: string }>>;
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Request password reset (stub).
|
|
555
|
+
*/
|
|
556
|
+
requestPasswordReset(payload: AuthRequestPasswordResetPayload): Promise<AuthApiResult<{ sent: boolean; destination: string; expiresIn: number }>>;
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Verify reset code (stub).
|
|
560
|
+
*/
|
|
561
|
+
verifyResetCode(payload: AuthVerifyResetCodePayload): Promise<AuthApiResult<{ valid: boolean; resetToken: string }>>;
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Reset password (stub).
|
|
565
|
+
*/
|
|
566
|
+
resetPassword(payload: AuthResetPasswordPayload): Promise<AuthApiResult<{ success: boolean; message: string }>>;
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Resend verification code (stub).
|
|
570
|
+
*/
|
|
571
|
+
resendCode(payload: AuthResendCodePayload): Promise<AuthApiResult<{ sent: boolean; canResendAt: string }>>;
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Validate QR code data.
|
|
575
|
+
*/
|
|
576
|
+
validateQrCode(payload: AuthValidateQrCodePayload): Promise<AuthApiResult<AuthQrValidationData>>;
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Link account using QR code.
|
|
580
|
+
* POST /user/link
|
|
581
|
+
*/
|
|
582
|
+
linkWithQrCode(payload: AuthLinkWithQrCodePayload): Promise<AuthApiResult<AuthQrLinkData>>;
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* Logout current user (clears stored auth data).
|
|
586
|
+
*/
|
|
587
|
+
logout(): Promise<AuthApiResult<{ success: boolean }>>;
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* Check if user is currently authenticated (has stored user ID).
|
|
591
|
+
*/
|
|
592
|
+
isAuthenticated(): Promise<boolean>;
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Get stored user ID.
|
|
596
|
+
*/
|
|
597
|
+
getStoredUserId(): Promise<string | null>;
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Get stored user metadata.
|
|
601
|
+
*/
|
|
602
|
+
getStoredUserMetadata(): Promise<Record<string, any> | null>;
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* Get stored subscription data.
|
|
606
|
+
*/
|
|
607
|
+
getStoredSubscription(): Promise<AuthSubscriptionData | null>;
|
|
608
|
+
}
|
|
609
|
+
|
|
346
610
|
export class AppsSDK {
|
|
347
611
|
initializePushNotifications(): Promise<string>;
|
|
348
612
|
}
|
|
@@ -361,13 +625,16 @@ declare module 'apps-sdk' {
|
|
|
361
625
|
mixpanel : MixPanel;
|
|
362
626
|
tracking : TrackingTransparency;
|
|
363
627
|
paywallLogic : PayWallLogic;
|
|
628
|
+
/** @deprecated Use `notifications` instead */
|
|
364
629
|
notificationsPush : NotificationsPush;
|
|
630
|
+
notifications : NotificationsPush;
|
|
365
631
|
voice : Voice;
|
|
366
632
|
adapty : Adapty;
|
|
367
633
|
homeActions : HomeActions;
|
|
368
634
|
facebook : Facebook;
|
|
369
635
|
firebase : Firebase;
|
|
370
636
|
legal : Legal;
|
|
637
|
+
authentication : Authentication;
|
|
371
638
|
}
|
|
372
639
|
|
|
373
640
|
const Core: AppsSDK;
|