berget 2.1.2 → 2.2.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.
@@ -1,163 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __importDefault = (this && this.__importDefault) || function (mod) {
35
- return (mod && mod.__esModule) ? mod : { "default": mod };
36
- };
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.RegistrationService = void 0;
39
- const client_1 = require("../client");
40
- const error_handler_1 = require("../utils/error-handler");
41
- const chalk_1 = __importDefault(require("chalk"));
42
- const readline = __importStar(require("readline"));
43
- /**
44
- * Service for handling user registration and account completion
45
- */
46
- class RegistrationService {
47
- constructor() {
48
- this.client = (0, client_1.createAuthenticatedClient)();
49
- }
50
- static getInstance() {
51
- if (!RegistrationService.instance) {
52
- RegistrationService.instance = new RegistrationService();
53
- }
54
- return RegistrationService.instance;
55
- }
56
- /**
57
- * Check authentication status to see if user has completed registration
58
- */
59
- checkAuthStatus() {
60
- return __awaiter(this, void 0, void 0, function* () {
61
- try {
62
- const { data, error } = yield this.client.GET('/v1/auth/status');
63
- if (error)
64
- throw error;
65
- return data;
66
- }
67
- catch (error) {
68
- (0, error_handler_1.handleError)('Failed to check authentication status', error);
69
- throw error;
70
- }
71
- });
72
- }
73
- /**
74
- * Complete registration for a new user
75
- */
76
- completeRegistration(request) {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- try {
79
- const { data, error } = yield this.client.POST('/v1/users/me/complete-registration', {
80
- body: request,
81
- });
82
- if (error) {
83
- throw new Error(JSON.stringify(error));
84
- }
85
- return data;
86
- }
87
- catch (error) {
88
- console.error('Failed to complete registration:', error);
89
- throw error;
90
- }
91
- });
92
- }
93
- /**
94
- * Check if registration is needed based on auth status
95
- */
96
- isRegistrationNeeded() {
97
- return __awaiter(this, void 0, void 0, function* () {
98
- try {
99
- const status = yield this.checkAuthStatus();
100
- return !status.hasOdooAccount;
101
- }
102
- catch (error) {
103
- return false;
104
- }
105
- });
106
- }
107
- /**
108
- * Prompt user for registration information
109
- */
110
- collectRegistrationInfo() {
111
- return __awaiter(this, void 0, void 0, function* () {
112
- const rl = readline.createInterface({
113
- input: process.stdin,
114
- output: process.stdout,
115
- });
116
- const question = (prompt) => {
117
- return new Promise((resolve) => {
118
- rl.question(prompt, (answer) => {
119
- resolve(answer.trim());
120
- });
121
- });
122
- };
123
- console.log(chalk_1.default.cyan('\nšŸ“ Complete your registration\n'));
124
- console.log(chalk_1.default.dim('─'.repeat(50)));
125
- const companyName = yield question(chalk_1.default.blue('Company name: '));
126
- const companyEmail = yield question(chalk_1.default.blue('Company email: '));
127
- const vatNumber = yield question(chalk_1.default.blue('VAT number (optional): '));
128
- console.log(chalk_1.default.cyan('\nšŸ“‹ Plan Selection'));
129
- console.log(chalk_1.default.dim('─'.repeat(50)));
130
- console.log(chalk_1.default.yellow('You will start with a trial plan (ID: 142). To add a credit card,'));
131
- console.log(chalk_1.default.yellow('please visit https://console.berget.ai\n'));
132
- const marketingConsent = yield question(chalk_1.default.blue('Subscribe to marketing emails? (Y/n): '));
133
- console.log(chalk_1.default.cyan('\nšŸ“„ Terms of Service'));
134
- console.log(chalk_1.default.dim('─'.repeat(50)));
135
- console.log(chalk_1.default.cyan('Please review our terms:'));
136
- console.log(chalk_1.default.dim(' • https://berget.ai/terms'));
137
- console.log(chalk_1.default.dim(' • https://berget.ai/acceptable-use'));
138
- console.log(chalk_1.default.dim(' • https://berget.ai/dpa\n'));
139
- const termsAccepted = yield question(chalk_1.default.blue('Do you accept the terms? (Y/n): '));
140
- rl.close();
141
- return {
142
- company: {
143
- name: companyName,
144
- email: companyEmail,
145
- vatNumber: vatNumber || '',
146
- },
147
- plans: [
148
- {
149
- id: '142',
150
- quantity: 1,
151
- },
152
- ],
153
- paymentMethodId: '',
154
- stripeCustomerId: '',
155
- marketingConsent: marketingConsent.toLowerCase() !== 'n' &&
156
- marketingConsent.toLowerCase() !== 'no',
157
- termsAccepted: termsAccepted.toLowerCase() !== 'n' &&
158
- termsAccepted.toLowerCase() !== 'no',
159
- };
160
- });
161
- }
162
- }
163
- exports.RegistrationService = RegistrationService;