@gsb-core/core
Version:
GSB core services and classes for platform-independent web applications
117 lines • 5.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RegistrationService = exports.SocialProviders = exports.RegistrationType = void 0;
const subscription_service_1 = require("./subscription.service");
var RegistrationType;
(function (RegistrationType) {
RegistrationType[RegistrationType["Free"] = 1] = "Free";
RegistrationType[RegistrationType["Basic"] = 2] = "Basic";
RegistrationType[RegistrationType["Premium"] = 4] = "Premium";
RegistrationType[RegistrationType["Enterprise"] = 8] = "Enterprise";
RegistrationType[RegistrationType["Social"] = 16] = "Social";
})(RegistrationType || (exports.RegistrationType = RegistrationType = {}));
var SocialProviders;
(function (SocialProviders) {
SocialProviders[SocialProviders["None"] = 0] = "None";
SocialProviders[SocialProviders["Google"] = 1] = "Google";
SocialProviders[SocialProviders["Github"] = 2] = "Github";
SocialProviders[SocialProviders["Facebook"] = 4] = "Facebook";
})(SocialProviders || (exports.SocialProviders = SocialProviders = {}));
/**
* Registration service for handling user registration
*/
class RegistrationService {
constructor() {
this.subscriptionService = subscription_service_1.SubscriptionService.getInstance();
}
static getInstance() {
if (!RegistrationService.instance) {
RegistrationService.instance = new RegistrationService();
}
return RegistrationService.instance;
}
/**
* Register a new user
*/
async registerUser(data) {
var _a, _b, _c, _d;
console.log('Registering user with data:', data);
// Create a registration object
const registration = {
name: data.name,
surname: data.surname,
email: data.email,
phoneNumber: data.phoneNumber,
type: data.subscriptionType,
emailVerified: false,
// Set social login information if available
socialProvider: ((_a = data.socialInfo) === null || _a === void 0 ? void 0 : _a.provider) || SocialProviders.None,
socialToken: (_b = data.socialInfo) === null || _b === void 0 ? void 0 : _b.token,
// Set password only if not using social login
password: data.socialInfo ? undefined : data.password,
paymentToken: (_c = data.paymentInfo) === null || _c === void 0 ? void 0 : _c.token,
savePaymentInfo: ((_d = data.paymentInfo) === null || _d === void 0 ? void 0 : _d.saveInfo) || false,
};
// For now, return the mock registration
// In a real implementation, this would make API calls to GSB
return registration;
}
/**
* Verify user email with validation code
*/
async verifyUserEmail(email, validationCode) {
console.log(`Verifying email ${email} with code ${validationCode}`);
// In a real implementation, this would make API calls to GSB
// For now, just simulate success
return true;
}
/**
* Complete user registration and set up subscription if needed
*/
async completeRegistration(registrationId, verificationKey, subscriptionData) {
console.log(`Completing registration ${registrationId} with key ${verificationKey}`);
// In a real implementation, we would:
// 1. Verify the registration exists and is valid
// 2. Create the user account
// 3. Set up the subscription if needed
// 4. Update the registration status
// For now, simulate a successful registration
const mockUserId = 'user_' + Math.random().toString(36).substr(2, 9);
const mockTenantId = 'tenant_' + Math.random().toString(36).substr(2, 9);
let mockSubscriptionPlanId;
// Set up subscription for paid plans
if (subscriptionData && subscriptionData.planType !== RegistrationType.Free) {
const mockPlan = await this.subscriptionService.createSubscriptionPlan(mockUserId, mockTenantId, `${subscriptionData.planType === RegistrationType.Premium ? 'Premium' : 'Basic'} Plan`);
mockSubscriptionPlanId = mockPlan.id;
}
return {
success: true,
userId: mockUserId,
tenantId: mockTenantId,
subscriptionPlanId: mockSubscriptionPlanId
};
}
/**
* Process a social login based registration
*/
async processSocialRegistration(provider, token) {
console.log(`Processing social registration with provider ${provider} and token ${token}`);
// In a real implementation, we would:
// 1. Verify the social token with the provider
// 2. Check if the user already exists
// 3. Create a new registration if needed
// For now, simulate a successful registration
const mockUserId = 'user_' + Math.random().toString(36).substr(2, 9);
const mockRegistrationId = 'reg_' + Math.random().toString(36).substr(2, 9);
// Simulate a new user
const isNewUser = true;
return {
success: true,
isNewUser,
userId: mockUserId,
registrationId: mockRegistrationId
};
}
}
exports.RegistrationService = RegistrationService;
//# sourceMappingURL=registration.service.js.map