@progalaxyelabs/ngx-stonescriptphp-client 1.16.1 → 1.17.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.
|
@@ -13,13 +13,6 @@ class MyEnvironmentModel {
|
|
|
13
13
|
* Used for multi-tenant authentication.
|
|
14
14
|
*/
|
|
15
15
|
platformCode = '';
|
|
16
|
-
/**
|
|
17
|
-
* Platform's own API base URL.
|
|
18
|
-
* Used for routes that go through the platform API proxy (e.g. register-tenant).
|
|
19
|
-
* Falls back to apiServer.host if not set.
|
|
20
|
-
* @example '//api.medstoreapp.in'
|
|
21
|
-
*/
|
|
22
|
-
apiUrl;
|
|
23
16
|
apiServer = { host: '' };
|
|
24
17
|
/**
|
|
25
18
|
* Files service server configuration.
|
|
@@ -210,9 +203,6 @@ class StoneScriptPHPAuth {
|
|
|
210
203
|
}
|
|
211
204
|
return this.config.host;
|
|
212
205
|
}
|
|
213
|
-
getPlatformApiUrl() {
|
|
214
|
-
return this.config.apiUrl || this.config.host;
|
|
215
|
-
}
|
|
216
206
|
getDefaultServer() {
|
|
217
207
|
if (!this.config.authServers)
|
|
218
208
|
return null;
|
|
@@ -520,82 +510,6 @@ class StoneScriptPHPAuth {
|
|
|
520
510
|
return [];
|
|
521
511
|
}
|
|
522
512
|
}
|
|
523
|
-
async registerTenant(data) {
|
|
524
|
-
if (data.provider !== 'emailPassword') {
|
|
525
|
-
return this.registerTenantWithOAuth(data.tenantName, data.provider);
|
|
526
|
-
}
|
|
527
|
-
try {
|
|
528
|
-
const apiUrl = this.getPlatformApiUrl();
|
|
529
|
-
const body = {
|
|
530
|
-
tenant_name: data.tenantName,
|
|
531
|
-
email: data.email ?? '',
|
|
532
|
-
password: data.password ?? '',
|
|
533
|
-
provider: 'emailPassword'
|
|
534
|
-
};
|
|
535
|
-
if (data.displayName)
|
|
536
|
-
body['display_name'] = data.displayName;
|
|
537
|
-
if (data.countryCode)
|
|
538
|
-
body['country_code'] = data.countryCode;
|
|
539
|
-
if (data.role)
|
|
540
|
-
body['role'] = data.role;
|
|
541
|
-
const response = await fetch(`${apiUrl}/auth/register-tenant`, {
|
|
542
|
-
method: 'POST',
|
|
543
|
-
headers: { 'Content-Type': 'application/json' },
|
|
544
|
-
credentials: 'include',
|
|
545
|
-
body: JSON.stringify(body)
|
|
546
|
-
});
|
|
547
|
-
const result = await response.json();
|
|
548
|
-
if (result?.status === 'ok' || result?.success === true) {
|
|
549
|
-
return { success: true };
|
|
550
|
-
}
|
|
551
|
-
return { success: false, message: result?.data?.message || result?.message || 'Registration failed' };
|
|
552
|
-
}
|
|
553
|
-
catch {
|
|
554
|
-
return { success: false, message: 'Network error. Please try again.' };
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
async registerTenantWithOAuth(tenantName, provider) {
|
|
558
|
-
return new Promise((resolve) => {
|
|
559
|
-
const width = 500, height = 600;
|
|
560
|
-
const left = (window.screen.width - width) / 2;
|
|
561
|
-
const top = (window.screen.height - height) / 2;
|
|
562
|
-
const accountsUrl = this.getAccountsUrl();
|
|
563
|
-
const oauthUrl = `${accountsUrl}/oauth/${provider}?` +
|
|
564
|
-
`platform=${this.config.platformCode}&mode=popup&action=register_tenant&` +
|
|
565
|
-
`tenant_name=${encodeURIComponent(tenantName)}`;
|
|
566
|
-
const popup = window.open(oauthUrl, `${provider}_register_tenant`, `width=${width},height=${height},left=${left},top=${top}`);
|
|
567
|
-
if (!popup) {
|
|
568
|
-
resolve({ success: false, message: 'Popup blocked. Please allow popups for this site.' });
|
|
569
|
-
return;
|
|
570
|
-
}
|
|
571
|
-
const messageHandler = (event) => {
|
|
572
|
-
if (event.origin !== new URL(accountsUrl).origin)
|
|
573
|
-
return;
|
|
574
|
-
if (event.data.type === 'tenant_register_success') {
|
|
575
|
-
window.removeEventListener('message', messageHandler);
|
|
576
|
-
popup.close();
|
|
577
|
-
resolve({
|
|
578
|
-
success: true,
|
|
579
|
-
accessToken: event.data.access_token,
|
|
580
|
-
user: event.data.user ? this.normalizeUser(event.data.user) : undefined
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
else if (event.data.type === 'tenant_register_error') {
|
|
584
|
-
window.removeEventListener('message', messageHandler);
|
|
585
|
-
popup.close();
|
|
586
|
-
resolve({ success: false, message: event.data.message || 'Tenant registration failed' });
|
|
587
|
-
}
|
|
588
|
-
};
|
|
589
|
-
window.addEventListener('message', messageHandler);
|
|
590
|
-
const checkClosed = setInterval(() => {
|
|
591
|
-
if (popup.closed) {
|
|
592
|
-
clearInterval(checkClosed);
|
|
593
|
-
window.removeEventListener('message', messageHandler);
|
|
594
|
-
resolve({ success: false, message: 'Registration cancelled' });
|
|
595
|
-
}
|
|
596
|
-
}, 500);
|
|
597
|
-
});
|
|
598
|
-
}
|
|
599
513
|
async checkTenantSlugAvailable(slug) {
|
|
600
514
|
try {
|
|
601
515
|
const accountsUrl = this.getAccountsUrl();
|
|
@@ -618,49 +532,6 @@ class StoneScriptPHPAuth {
|
|
|
618
532
|
throw new Error('Failed to check onboarding status');
|
|
619
533
|
return response.json();
|
|
620
534
|
}
|
|
621
|
-
async completeTenantOnboarding(countryCode, tenantName, accessToken) {
|
|
622
|
-
const apiUrl = this.getPlatformApiUrl();
|
|
623
|
-
const response = await fetch(`${apiUrl}/auth/register-tenant`, {
|
|
624
|
-
method: 'POST',
|
|
625
|
-
headers: {
|
|
626
|
-
'Content-Type': 'application/json',
|
|
627
|
-
'Authorization': `Bearer ${accessToken}`
|
|
628
|
-
},
|
|
629
|
-
credentials: 'include',
|
|
630
|
-
body: JSON.stringify({
|
|
631
|
-
platform: this.config.platformCode,
|
|
632
|
-
tenant_name: tenantName,
|
|
633
|
-
country_code: countryCode,
|
|
634
|
-
provider: 'google',
|
|
635
|
-
oauth_token: accessToken
|
|
636
|
-
})
|
|
637
|
-
});
|
|
638
|
-
if (!response.ok) {
|
|
639
|
-
const errorData = await response.json();
|
|
640
|
-
throw new Error(errorData.message || 'Failed to create tenant');
|
|
641
|
-
}
|
|
642
|
-
return response.json();
|
|
643
|
-
}
|
|
644
|
-
async provisionTenant(storeName, countryCode, accessToken) {
|
|
645
|
-
const apiUrl = this.getPlatformApiUrl();
|
|
646
|
-
const response = await fetch(`${apiUrl}/auth/provision-tenant`, {
|
|
647
|
-
method: 'POST',
|
|
648
|
-
headers: {
|
|
649
|
-
'Content-Type': 'application/json',
|
|
650
|
-
'Authorization': `Bearer ${accessToken}`
|
|
651
|
-
},
|
|
652
|
-
credentials: 'include',
|
|
653
|
-
body: JSON.stringify({
|
|
654
|
-
store_name: storeName,
|
|
655
|
-
country_code: countryCode,
|
|
656
|
-
})
|
|
657
|
-
});
|
|
658
|
-
if (!response.ok) {
|
|
659
|
-
const errorData = await response.json();
|
|
660
|
-
throw new Error(errorData.message || 'Failed to provision tenant');
|
|
661
|
-
}
|
|
662
|
-
return response.json();
|
|
663
|
-
}
|
|
664
535
|
async checkEmail(email) {
|
|
665
536
|
try {
|
|
666
537
|
const accountsUrl = this.getAccountsUrl();
|
|
@@ -723,8 +594,7 @@ function provideNgxStoneScriptPhpClient(environment, plugin) {
|
|
|
723
594
|
platformCode: environment.platformCode,
|
|
724
595
|
authServers: environment.authServers,
|
|
725
596
|
responseMap: environment.auth?.responseMap ?? environment.authResponseMap,
|
|
726
|
-
auth: environment.auth
|
|
727
|
-
apiUrl: environment.apiUrl
|
|
597
|
+
auth: environment.auth
|
|
728
598
|
});
|
|
729
599
|
return makeEnvironmentProviders([
|
|
730
600
|
{ provide: MyEnvironmentModel, useValue: environment },
|
|
@@ -1040,25 +910,6 @@ class AuthService {
|
|
|
1040
910
|
return this.userSubject.value;
|
|
1041
911
|
}
|
|
1042
912
|
// ── Multi-tenant operations ───────────────────────────────────────────────
|
|
1043
|
-
async registerTenant(data) {
|
|
1044
|
-
if (!this.plugin.registerTenant) {
|
|
1045
|
-
return { success: false, message: 'registerTenant not supported by the configured auth plugin' };
|
|
1046
|
-
}
|
|
1047
|
-
const registered = await this.plugin.registerTenant(data);
|
|
1048
|
-
if (!registered.success)
|
|
1049
|
-
return registered;
|
|
1050
|
-
// OAuth: token comes directly from the popup — store it and we're done.
|
|
1051
|
-
if (registered.accessToken) {
|
|
1052
|
-
this.storeAuthResult(registered);
|
|
1053
|
-
return registered;
|
|
1054
|
-
}
|
|
1055
|
-
// emailPassword: registration succeeded but no token yet.
|
|
1056
|
-
// Login via auth (SSO) to obtain tokens.
|
|
1057
|
-
if (data.provider === 'emailPassword' && data.email && data.password) {
|
|
1058
|
-
return await this.loginWithEmail(data.email, data.password);
|
|
1059
|
-
}
|
|
1060
|
-
return registered;
|
|
1061
|
-
}
|
|
1062
913
|
async getTenantMemberships(serverName) {
|
|
1063
914
|
if (!this.plugin.getTenantMemberships)
|
|
1064
915
|
return { memberships: [] };
|
|
@@ -1085,27 +936,6 @@ class AuthService {
|
|
|
1085
936
|
throw new Error('checkOnboardingStatus not supported');
|
|
1086
937
|
return this.plugin.checkOnboardingStatus(identityId);
|
|
1087
938
|
}
|
|
1088
|
-
async provisionTenant(storeName, countryCode = 'IN') {
|
|
1089
|
-
if (!this.plugin.provisionTenant) {
|
|
1090
|
-
throw new Error('provisionTenant not supported by the configured auth plugin');
|
|
1091
|
-
}
|
|
1092
|
-
const result = await this.plugin.provisionTenant(storeName, countryCode, this.tokens.getAccessToken());
|
|
1093
|
-
if (result?.access_token) {
|
|
1094
|
-
this.tokens.setAccessToken(result.access_token);
|
|
1095
|
-
this.signinStatus.setSigninStatus(true);
|
|
1096
|
-
}
|
|
1097
|
-
return result;
|
|
1098
|
-
}
|
|
1099
|
-
async completeTenantOnboarding(countryCode, tenantName, serverName) {
|
|
1100
|
-
if (!this.plugin.completeTenantOnboarding)
|
|
1101
|
-
throw new Error('completeTenantOnboarding not supported');
|
|
1102
|
-
const result = await this.plugin.completeTenantOnboarding(countryCode, tenantName, this.tokens.getAccessToken());
|
|
1103
|
-
if (result?.access_token) {
|
|
1104
|
-
this.tokens.setAccessToken(result.access_token);
|
|
1105
|
-
this.signinStatus.setSigninStatus(true);
|
|
1106
|
-
}
|
|
1107
|
-
return result;
|
|
1108
|
-
}
|
|
1109
939
|
// ── Multi-server (delegated to plugin) ────────────────────────────────────
|
|
1110
940
|
getAvailableAuthServers() {
|
|
1111
941
|
return this.plugin.getAvailableServers?.() ?? [];
|
|
@@ -3219,7 +3049,7 @@ class TenantRegisterComponent {
|
|
|
3219
3049
|
tenantSlugLabel = 'Organization URL';
|
|
3220
3050
|
tenantSlugPlaceholder = 'organization-name';
|
|
3221
3051
|
urlPreviewEnabled = true;
|
|
3222
|
-
urlPreviewPrefix = '
|
|
3052
|
+
urlPreviewPrefix = 'yourapp.com/';
|
|
3223
3053
|
// User Labels
|
|
3224
3054
|
userSectionTitle = 'Your Information';
|
|
3225
3055
|
oauthDescription = 'Recommended: Sign up with your Google account';
|
|
@@ -3232,6 +3062,7 @@ class TenantRegisterComponent {
|
|
|
3232
3062
|
loginLinkAction = 'Sign in';
|
|
3233
3063
|
// Outputs
|
|
3234
3064
|
tenantCreated = new EventEmitter();
|
|
3065
|
+
registerRequested = new EventEmitter();
|
|
3235
3066
|
navigateToLogin = new EventEmitter();
|
|
3236
3067
|
// Form Fields
|
|
3237
3068
|
tenantName = '';
|
|
@@ -3354,64 +3185,49 @@ class TenantRegisterComponent {
|
|
|
3354
3185
|
}
|
|
3355
3186
|
return true;
|
|
3356
3187
|
}
|
|
3357
|
-
|
|
3188
|
+
onOAuthRegister(provider) {
|
|
3358
3189
|
if (!this.isFormValid()) {
|
|
3359
3190
|
this.error = 'Please complete the organization information';
|
|
3360
3191
|
return;
|
|
3361
3192
|
}
|
|
3362
|
-
this.loading = true;
|
|
3363
|
-
this.loadingText = `Signing up with ${provider}...`;
|
|
3364
3193
|
this.error = '';
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
if (result.success && result.user) {
|
|
3371
|
-
this.success = 'Organization created successfully!';
|
|
3372
|
-
this.tenantCreated.emit({ user: result.user });
|
|
3373
|
-
}
|
|
3374
|
-
else {
|
|
3375
|
-
this.error = result.message || 'Registration failed';
|
|
3376
|
-
}
|
|
3377
|
-
}
|
|
3378
|
-
catch (err) {
|
|
3379
|
-
this.error = err.message || 'An unexpected error occurred';
|
|
3380
|
-
}
|
|
3381
|
-
finally {
|
|
3382
|
-
this.loading = false;
|
|
3383
|
-
}
|
|
3194
|
+
this.registerRequested.emit({
|
|
3195
|
+
tenantName: this.tenantName,
|
|
3196
|
+
tenantSlug: this.tenantSlug,
|
|
3197
|
+
provider: provider
|
|
3198
|
+
});
|
|
3384
3199
|
}
|
|
3385
|
-
|
|
3200
|
+
onRegister() {
|
|
3386
3201
|
if (!this.isFormValid()) {
|
|
3387
3202
|
this.error = 'Please fill in all required fields correctly';
|
|
3388
3203
|
return;
|
|
3389
3204
|
}
|
|
3390
|
-
this.loading = true;
|
|
3391
|
-
this.loadingText = 'Creating your organization...';
|
|
3392
3205
|
this.error = '';
|
|
3393
3206
|
this.success = '';
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3207
|
+
this.registerRequested.emit({
|
|
3208
|
+
tenantName: this.tenantName,
|
|
3209
|
+
tenantSlug: this.tenantSlug,
|
|
3210
|
+
displayName: this.displayName,
|
|
3211
|
+
email: this.email,
|
|
3212
|
+
password: this.password,
|
|
3213
|
+
provider: 'emailPassword'
|
|
3214
|
+
});
|
|
3215
|
+
}
|
|
3216
|
+
/** Call from consuming component after handling registerRequested to show loading state */
|
|
3217
|
+
setLoading(loading, text) {
|
|
3218
|
+
this.loading = loading;
|
|
3219
|
+
if (text)
|
|
3220
|
+
this.loadingText = text;
|
|
3221
|
+
}
|
|
3222
|
+
/** Call from consuming component to show success/error after handling registerRequested */
|
|
3223
|
+
setResult(result) {
|
|
3224
|
+
this.loading = false;
|
|
3225
|
+
if (result.success && result.user) {
|
|
3226
|
+
this.success = 'Organization created successfully!';
|
|
3227
|
+
this.tenantCreated.emit({ user: result.user });
|
|
3412
3228
|
}
|
|
3413
|
-
|
|
3414
|
-
this.
|
|
3229
|
+
else if (!result.success) {
|
|
3230
|
+
this.error = result.message || 'Registration failed';
|
|
3415
3231
|
}
|
|
3416
3232
|
}
|
|
3417
3233
|
onLoginClick(event) {
|
|
@@ -3419,7 +3235,7 @@ class TenantRegisterComponent {
|
|
|
3419
3235
|
this.navigateToLogin.emit();
|
|
3420
3236
|
}
|
|
3421
3237
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.17", ngImport: i0, type: TenantRegisterComponent, deps: [{ token: AuthService }, { token: ProviderRegistryService }], target: i0.ɵɵFactoryTarget.Component });
|
|
3422
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.17", type: TenantRegisterComponent, isStandalone: true, selector: "lib-tenant-register", inputs: { title: "title", providers: "providers", requireTenantName: "requireTenantName", tenantSectionTitle: "tenantSectionTitle", tenantNameLabel: "tenantNameLabel", tenantNamePlaceholder: "tenantNamePlaceholder", tenantSlugLabel: "tenantSlugLabel", tenantSlugPlaceholder: "tenantSlugPlaceholder", urlPreviewEnabled: "urlPreviewEnabled", urlPreviewPrefix: "urlPreviewPrefix", userSectionTitle: "userSectionTitle", oauthDescription: "oauthDescription", ownershipTitle: "ownershipTitle", ownershipMessage: "ownershipMessage", submitButtonText: "submitButtonText", loginLinkText: "loginLinkText", loginLinkAction: "loginLinkAction" }, outputs: { tenantCreated: "tenantCreated", navigateToLogin: "navigateToLogin" }, ngImport: i0, template: `
|
|
3238
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.17", type: TenantRegisterComponent, isStandalone: true, selector: "lib-tenant-register", inputs: { title: "title", providers: "providers", requireTenantName: "requireTenantName", tenantSectionTitle: "tenantSectionTitle", tenantNameLabel: "tenantNameLabel", tenantNamePlaceholder: "tenantNamePlaceholder", tenantSlugLabel: "tenantSlugLabel", tenantSlugPlaceholder: "tenantSlugPlaceholder", urlPreviewEnabled: "urlPreviewEnabled", urlPreviewPrefix: "urlPreviewPrefix", userSectionTitle: "userSectionTitle", oauthDescription: "oauthDescription", ownershipTitle: "ownershipTitle", ownershipMessage: "ownershipMessage", submitButtonText: "submitButtonText", loginLinkText: "loginLinkText", loginLinkAction: "loginLinkAction" }, outputs: { tenantCreated: "tenantCreated", registerRequested: "registerRequested", navigateToLogin: "navigateToLogin" }, ngImport: i0, template: `
|
|
3423
3239
|
<div class="tenant-register-dialog">
|
|
3424
3240
|
<h2 class="register-title">{{ title }}</h2>
|
|
3425
3241
|
|
|
@@ -3876,6 +3692,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.17", ngImpo
|
|
|
3876
3692
|
type: Input
|
|
3877
3693
|
}], tenantCreated: [{
|
|
3878
3694
|
type: Output
|
|
3695
|
+
}], registerRequested: [{
|
|
3696
|
+
type: Output
|
|
3879
3697
|
}], navigateToLogin: [{
|
|
3880
3698
|
type: Output
|
|
3881
3699
|
}] } });
|
|
@@ -4057,7 +3875,7 @@ class TenantRegisterDialogComponent {
|
|
|
4057
3875
|
(navigateToLogin)="onNavigateToLogin()">
|
|
4058
3876
|
</lib-tenant-register>
|
|
4059
3877
|
</div>
|
|
4060
|
-
`, isInline: true, styles: [".dialog-wrapper{padding:0}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "component", type: TenantRegisterComponent, selector: "lib-tenant-register", inputs: ["title", "providers", "requireTenantName", "tenantSectionTitle", "tenantNameLabel", "tenantNamePlaceholder", "tenantSlugLabel", "tenantSlugPlaceholder", "urlPreviewEnabled", "urlPreviewPrefix", "userSectionTitle", "oauthDescription", "ownershipTitle", "ownershipMessage", "submitButtonText", "loginLinkText", "loginLinkAction"], outputs: ["tenantCreated", "navigateToLogin"] }] });
|
|
3878
|
+
`, isInline: true, styles: [".dialog-wrapper{padding:0}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "component", type: TenantRegisterComponent, selector: "lib-tenant-register", inputs: ["title", "providers", "requireTenantName", "tenantSectionTitle", "tenantNameLabel", "tenantNamePlaceholder", "tenantSlugLabel", "tenantSlugPlaceholder", "urlPreviewEnabled", "urlPreviewPrefix", "userSectionTitle", "oauthDescription", "ownershipTitle", "ownershipMessage", "submitButtonText", "loginLinkText", "loginLinkAction"], outputs: ["tenantCreated", "registerRequested", "navigateToLogin"] }] });
|
|
4061
3879
|
}
|
|
4062
3880
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.17", ngImport: i0, type: TenantRegisterDialogComponent, decorators: [{
|
|
4063
3881
|
type: Component,
|