@agenticmail/enterprise 0.5.6 → 0.5.8

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.
@@ -91,23 +91,97 @@ export async function promptRegistration(
91
91
  const data = await res.json().catch(() => ({})) as any;
92
92
 
93
93
  if (res.status === 409) {
94
- spinner.fail('Domain already registered');
94
+ spinner.info('Domain already registered — verifying ownership');
95
95
  console.log('');
96
96
  console.log(chalk.yellow(' This domain is already registered and verified.'));
97
- console.log(chalk.dim(' If this is your domain, use: npx @agenticmail/enterprise recover'));
98
- console.log('');
99
-
100
- const { continueAnyway } = await inquirer.prompt([{
101
- type: 'confirm',
102
- name: 'continueAnyway',
103
- message: 'Continue setup without registration?',
104
- default: true,
97
+ console.log(chalk.dim(' Enter your deployment key to prove ownership and continue.\n'));
98
+
99
+ const { deploymentKey } = await inquirer.prompt([{
100
+ type: 'password',
101
+ name: 'deploymentKey',
102
+ message: 'Deployment key:',
103
+ mask: '*',
104
+ validate: (v: string) => v.length === 64 || 'Deployment key should be 64 hex characters',
105
105
  }]);
106
106
 
107
- if (continueAnyway) {
108
- return { registered: false, verificationStatus: 'skipped' };
107
+ // Recover via registry — this re-registers with a new challenge
108
+ const recoverSpinner = ora('Verifying deployment key...').start();
109
+ try {
110
+ const recoverRes = await fetch(`${registryUrl}/domains/recover`, {
111
+ method: 'POST',
112
+ headers: { 'Content-Type': 'application/json' },
113
+ body: JSON.stringify({
114
+ domain: domain!.toLowerCase().trim(),
115
+ deploymentKey,
116
+ }),
117
+ signal: AbortSignal.timeout(15_000),
118
+ });
119
+
120
+ const recoverData = await recoverRes.json().catch(() => ({})) as any;
121
+
122
+ if (recoverRes.status === 403) {
123
+ recoverSpinner.fail('Invalid deployment key');
124
+ console.log('');
125
+ console.log(chalk.red(' The deployment key does not match this domain.'));
126
+ console.log('');
127
+
128
+ const { continueAnyway } = await inquirer.prompt([{
129
+ type: 'confirm',
130
+ name: 'continueAnyway',
131
+ message: 'Continue setup without registration?',
132
+ default: true,
133
+ }]);
134
+
135
+ if (continueAnyway) {
136
+ return { registered: false, verificationStatus: 'skipped' };
137
+ }
138
+ process.exit(1);
139
+ }
140
+
141
+ if (!recoverRes.ok) {
142
+ throw new Error(recoverData.error || `HTTP ${recoverRes.status}`);
143
+ }
144
+
145
+ recoverSpinner.succeed('Ownership verified — domain recovered');
146
+
147
+ // Now verify DNS with the new challenge
148
+ registrationId = recoverData.registrationId;
149
+ dnsChallenge = recoverData.dnsChallenge;
150
+
151
+ // Auto-verify DNS since they already own the domain
152
+ const verifyRes = await fetch(`${registryUrl}/domains/verify`, {
153
+ method: 'POST',
154
+ headers: { 'Content-Type': 'application/json' },
155
+ body: JSON.stringify({ domain: domain!.toLowerCase().trim() }),
156
+ signal: AbortSignal.timeout(15_000),
157
+ });
158
+ const verifyData = await verifyRes.json().catch(() => ({})) as any;
159
+
160
+ // Re-hash the provided key for local storage
161
+ const { createHash } = await import('crypto');
162
+ const localKeyHash = createHash('sha256').update(deploymentKey).digest('hex');
163
+
164
+ return {
165
+ registered: true,
166
+ deploymentKeyHash: localKeyHash,
167
+ dnsChallenge,
168
+ registrationId,
169
+ verificationStatus: verifyData?.verified ? 'verified' : 'pending_dns',
170
+ };
171
+ } catch (err: any) {
172
+ recoverSpinner.fail(`Recovery failed: ${err.message}`);
173
+ const { continueAnyway } = await inquirer.prompt([{
174
+ type: 'confirm',
175
+ name: 'continueAnyway',
176
+ message: 'Continue setup without registration?',
177
+ default: true,
178
+ }]);
179
+
180
+ if (continueAnyway) {
181
+ return { registered: false, verificationStatus: 'skipped' };
182
+ }
183
+ process.exit(1);
109
184
  }
110
- process.exit(1);
111
185
  }
112
186
 
113
187
  if (!res.ok) {