@nauticana/sail 1.1.28 → 1.1.29
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/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
A shared Angular component library for building CRUD-based admin frontends. Provides table management, form handling, navigation, authentication, two-factor authentication, and trusted device management — all driven by metadata from a [keel](https://github.com/nauticana/keel) Go backend.
|
|
4
4
|
|
|
5
|
-
> **Compatibility:** sail and keel are versioned in lock-step. The current line is **sail v1.1.x ↔ keel v1.2.x**; sail v1.1.28 adopts keel v1.2.93 (absolute `return` for the OAuth hand-off), sail v1.1.18 adopts keel v1.2.58 (refresh-token rotation, `/public/logout`, setup intents, the realtime hub), the agency components in sail v1.1.14 require keel v1.2.41 (sail v1.1.9 needs keel v1.2.16 for the OAuth-connect layer). Earlier lines: **sail v0.5.x ↔ keel v0.5.x**, **sail v0.6.x / v0.7.x ↔ keel v0.7.x**, **sail v0.8.x ↔ keel v0.8.x**, **sail v0.9.x ↔ keel v0.9.x**. Newer sail releases extend the contract — older keel servers reject unknown endpoints with HTTP 404 / 400. The v0.8.x line additionally ships the `table_action` framework (per-table custom buttons surfaced in `TableList` / `TableSearch` / `TableEdit` / `TableDetail`); see the [Migrating to v0.7.0 §5 — TableAction](#migrating-to-v070--payout-user-payment-methods-table-actions) section for the seed shape (basis `table_action` + `authorization_object` + `authorization_object_action` rows) and the [keel/README Table Actions](https://github.com/nauticana/keel#table-actions) section for backend wiring via `handler.WrapTableAction`.
|
|
5
|
+
> **Compatibility:** sail and keel are versioned in lock-step. The current line is **sail v1.1.x ↔ keel v1.2.x**; sail v1.1.29 adopts keel v1.2.94 (signup: confirmation signs in, partner setup, sign-in hand-off code), sail v1.1.28 adopts keel v1.2.93 (absolute `return` for the OAuth hand-off), sail v1.1.18 adopts keel v1.2.58 (refresh-token rotation, `/public/logout`, setup intents, the realtime hub), the agency components in sail v1.1.14 require keel v1.2.41 (sail v1.1.9 needs keel v1.2.16 for the OAuth-connect layer). Earlier lines: **sail v0.5.x ↔ keel v0.5.x**, **sail v0.6.x / v0.7.x ↔ keel v0.7.x**, **sail v0.8.x ↔ keel v0.8.x**, **sail v0.9.x ↔ keel v0.9.x**. Newer sail releases extend the contract — older keel servers reject unknown endpoints with HTTP 404 / 400. The v0.8.x line additionally ships the `table_action` framework (per-table custom buttons surfaced in `TableList` / `TableSearch` / `TableEdit` / `TableDetail`); see the [Migrating to v0.7.0 §5 — TableAction](#migrating-to-v070--payout-user-payment-methods-table-actions) section for the seed shape (basis `table_action` + `authorization_object` + `authorization_object_action` rows) and the [keel/README Table Actions](https://github.com/nauticana/keel#table-actions) section for backend wiring via `handler.WrapTableAction`.
|
|
6
6
|
|
|
7
7
|
**Recent additions:** `BaseAuthService.acceptToken(jwt)` — adopt an externally-minted JWT (registration / SSO-handoff flows) and run the full post-login sequence (store under the canonical `jwt` key, load appdata, init routes); apps must use this instead of writing `localStorage` directly. `BaseRestService.analytic<T>(endpoint, params?)` — GET a keel `analytic/<endpoint>` report and return its rows. `passwordPolicyValidator` + `BaseAuthService.ensurePasswordPolicy()` — validate passwords against keel's policy (via `SailGuiConfig.passwordPolicyUrl`); see Configuration reference.
|
|
8
8
|
|
|
@@ -346,6 +346,10 @@ Omit the URL to skip client-side policy checks. The server stays the authoritati
|
|
|
346
346
|
| `POST /public/otp/resend` | Re-issue OTP for an existing `otpToken` |
|
|
347
347
|
| `POST /public/2fa/verify` | Login-time TOTP verification (uses `loginToken`) |
|
|
348
348
|
| `POST /public/2fa/backup-verify` | Login-time backup-code verification |
|
|
349
|
+
| `POST /public/register` | Start a signup from a `PartnerRegistration`; emails the confirmation code |
|
|
350
|
+
| `POST /public/register/confirm` | Confirm `?email=&code=`; answers session tokens and the partner result (`confirmRegister`) |
|
|
351
|
+
| `POST /public/register/exchange` | Trade a single-use hand-off `{code}` for a session (`exchangeHandoff`) |
|
|
352
|
+
| `POST /api/register/partner` | Create the signed-in user's partner from a `PartnerSetup` (`createPartner`) |
|
|
349
353
|
| `POST /public/token/refresh` | Rotate `{refreshToken}` → new `{token, refreshToken}`; 401 ends the session |
|
|
350
354
|
| `POST /public/logout` | Revoke `{refreshToken}` (called by `BaseAuthService.logout()`) |
|
|
351
355
|
| `GET /public/ws` | keel realtime hub handshake (`RealtimeService`; JWT via `?token=`) |
|
|
@@ -512,7 +516,9 @@ metadata: {
|
|
|
512
516
|
|
|
513
517
|
### Registration → checkout flow
|
|
514
518
|
|
|
515
|
-
|
|
519
|
+
`BaseAuthService.confirmRegister(email, code)` signs the user in from the tokens keel answers (keel v1.2.94), so no separate login follows. `ConfirmRegisterComponent` then sends the user to `resp.paymentUrl` when the backend returns `paymentRequired: true` with one; otherwise the post-login navigation applies.
|
|
520
|
+
|
|
521
|
+
A two-step signup registers the account alone (a `PartnerRegistration` without partner fields), then calls `createPartner(setup)` once signed in. It posts keel's `PartnerSetup` — application fields ride in `extra` — rotates the refresh token so the session carries the new partner, reloads appdata and routes, and emits `PartnerCreated`. When `paymentRequired` comes without a `paymentUrl`, the application's billing page opens the checkout. `exchangeHandoff(code)` completes a sign-in that arrived by redirect with keel's single-use code, including the 2FA step.
|
|
516
522
|
|
|
517
523
|
### `BaseAsync`
|
|
518
524
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nauticana/sail",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.29",
|
|
4
4
|
"description": "Metadata-driven Angular component library for CRUD admin frontends backed by the keel Go backend. Tables, forms, navigation, OTP/2FA/social auth, billing, payout onboarding.",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"exports": {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ChangeDetectionStrategy, Component, inject, OnInit, ViewEncapsulation } from '@angular/core';
|
|
2
2
|
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
|
3
3
|
import { BaseAuthService } from '../../service/auth.service';
|
|
4
|
-
import { ActivatedRoute,
|
|
4
|
+
import { ActivatedRoute, RouterLink } from '@angular/router';
|
|
5
5
|
import { MatButtonModule } from '@angular/material/button';
|
|
6
6
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
|
7
7
|
import { MatInputModule } from '@angular/material/input';
|
|
@@ -24,7 +24,6 @@ import { BaseAsync } from '../abstract/base_async';
|
|
|
24
24
|
export class ConfirmRegisterComponent extends BaseAsync implements OnInit {
|
|
25
25
|
private auth = inject(BaseAuthService);
|
|
26
26
|
private fb = inject(FormBuilder);
|
|
27
|
-
private router = inject(Router);
|
|
28
27
|
private route = inject(ActivatedRoute);
|
|
29
28
|
protected readonly guiConfig: SailGuiConfig = inject(SAIL_GUI_CONFIG, {optional: true}) ?? DEFAULT_CONFIG;
|
|
30
29
|
|
|
@@ -49,15 +48,11 @@ export class ConfirmRegisterComponent extends BaseAsync implements OnInit {
|
|
|
49
48
|
this.auth.confirmRegister(email!, code!),
|
|
50
49
|
(resp) => {
|
|
51
50
|
this.successMessage.set('Registration confirmed.');
|
|
51
|
+
// confirmRegister signed the user in and owns navigation; only a paid
|
|
52
|
+
// plan's checkout leaves the SPA (window.location: it is cross-origin).
|
|
52
53
|
if (resp?.paymentRequired && resp.paymentUrl) {
|
|
53
|
-
// Paid plan: go straight to payment. Subscription is 'P' until paid.
|
|
54
|
-
// Using window.location (not router) so absolute / cross-origin
|
|
55
|
-
// payment URLs also work.
|
|
56
54
|
window.location.href = resp.paymentUrl;
|
|
57
|
-
return;
|
|
58
55
|
}
|
|
59
|
-
// Free plan: land on login.
|
|
60
|
-
this.router.navigate(['/login/local']);
|
|
61
56
|
},
|
|
62
57
|
'Confirmation failed. Please try again.',
|
|
63
58
|
);
|
|
@@ -159,22 +159,22 @@ export class RegisterComponent implements OnInit {
|
|
|
159
159
|
this.registerError.set('');
|
|
160
160
|
const formValue = this.registerForm.getRawValue();
|
|
161
161
|
const partnerReg: PartnerRegistration = {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
162
|
+
firstName: formValue.FirstName!,
|
|
163
|
+
lastName: formValue.LastName!,
|
|
164
|
+
userName: formValue.UserName!,
|
|
165
|
+
email: formValue.Email!,
|
|
166
|
+
password: formValue.Password!,
|
|
167
|
+
partnerCaption: formValue.PartnerCaption!,
|
|
168
|
+
address: formValue.Address!,
|
|
169
|
+
city: formValue.City!,
|
|
170
|
+
state: formValue.State!,
|
|
171
|
+
zipcode: formValue.Zipcode!,
|
|
172
|
+
country: formValue.Country!,
|
|
173
|
+
phone: formValue.Phone!,
|
|
174
|
+
domainUrl: formValue.DomainURL!,
|
|
175
|
+
latitude: formValue.Latitude ?? undefined,
|
|
176
|
+
longitude: formValue.Longitude ?? undefined,
|
|
177
|
+
planId: formValue.PlanID!,
|
|
178
178
|
};
|
|
179
179
|
this.auth.register(partnerReg).subscribe({
|
|
180
180
|
// Pass the email along so the confirm page pre-fills it.
|
package/src/model/appdata.ts
CHANGED
|
@@ -198,24 +198,46 @@ export interface TrustedDevice {
|
|
|
198
198
|
created_at: string;
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
201
|
+
// Mirrors keel `user.AccountRegistration`.
|
|
202
|
+
export interface AccountRegistration {
|
|
203
|
+
firstName: string;
|
|
204
|
+
lastName: string;
|
|
205
|
+
userName: string;
|
|
206
|
+
email: string;
|
|
207
|
+
password: string;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Mirrors keel `user.PartnerSetup`. `extra` carries the application's own fields.
|
|
211
|
+
export interface PartnerSetup<TExtra = unknown> {
|
|
212
|
+
partnerCaption: string;
|
|
213
|
+
address: string;
|
|
214
|
+
city: string;
|
|
215
|
+
state: string;
|
|
216
|
+
zipcode: string;
|
|
217
|
+
country: string;
|
|
218
|
+
phone: string;
|
|
219
|
+
latitude?: number;
|
|
220
|
+
longitude?: number;
|
|
221
|
+
domainUrl: string;
|
|
222
|
+
planId: string;
|
|
223
|
+
// Chosen offer (PERIOD_TYPE codes); none selects the plan's cheapest.
|
|
224
|
+
billingCycle?: string;
|
|
225
|
+
termType?: string;
|
|
226
|
+
termCount?: number;
|
|
227
|
+
extra?: TExtra;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Mirrors keel `user.PartnerRegistration`. Without partner fields only the
|
|
231
|
+
// account is created and the partner follows through `createPartner`.
|
|
232
|
+
export type PartnerRegistration<TExtra = unknown> = AccountRegistration & Partial<PartnerSetup<TExtra>>;
|
|
233
|
+
|
|
234
|
+
// Mirrors keel `user.PartnerCreated`. `paymentRequired` without a `paymentUrl`
|
|
235
|
+
// means the application's billing page opens the checkout.
|
|
236
|
+
export interface PartnerCreated {
|
|
237
|
+
partnerId: number;
|
|
238
|
+
planId: string;
|
|
239
|
+
paymentRequired: boolean;
|
|
240
|
+
paymentUrl?: string;
|
|
219
241
|
}
|
|
220
242
|
|
|
221
243
|
// One purchasable offer for a plan — a (billing cycle × commitment term) row of
|
|
@@ -261,15 +283,13 @@ export interface PublicPlan {
|
|
|
261
283
|
trialDays?: number;
|
|
262
284
|
}
|
|
263
285
|
|
|
264
|
-
// ConfirmRegisterResponse — shape returned by POST /public/confirm
|
|
265
|
-
//
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
paymentRequired: boolean;
|
|
272
|
-
paymentUrl?: string;
|
|
286
|
+
// ConfirmRegisterResponse — shape returned by POST /public/register/confirm:
|
|
287
|
+
// the new session's tokens, plus the partner result when the registration had one.
|
|
288
|
+
export interface ConfirmRegisterResponse extends TokenPair {
|
|
289
|
+
status: string;
|
|
290
|
+
planId?: string;
|
|
291
|
+
paymentRequired?: boolean;
|
|
292
|
+
paymentUrl?: string;
|
|
273
293
|
}
|
|
274
294
|
|
|
275
295
|
// ── Billing / Payment types ──
|
|
@@ -2,7 +2,7 @@ import { Injectable, WritableSignal, inject, signal } from '@angular/core';
|
|
|
2
2
|
import { HttpErrorResponse, HttpParams } from '@angular/common/http';
|
|
3
3
|
import { filter, finalize, map, mergeMap, shareReplay, take, tap } from 'rxjs/operators';
|
|
4
4
|
import { PasswordRules } from '../util/password_policy';
|
|
5
|
-
import { ApplicationData, ConfirmRegisterResponse, DictionaryPath, LoginResponse2FA, PartnerRegistration, RestReport, TableDefinition, TokenPair, TrustedDevice, TwoFactorSetupResponse, TwoFactorVerifyRequest, TwoFactorVerifyResponse } from '../model/appdata';
|
|
5
|
+
import { ApplicationData, ConfirmRegisterResponse, DictionaryPath, LoginResponse2FA, PartnerCreated, PartnerRegistration, PartnerSetup, RestReport, TableDefinition, TokenPair, TrustedDevice, TwoFactorSetupResponse, TwoFactorVerifyRequest, TwoFactorVerifyResponse } from '../model/appdata';
|
|
6
6
|
import {
|
|
7
7
|
LoginResponseSocial,
|
|
8
8
|
OtpRequest, OtpResendRequest, OtpResponse, OtpVerifyRequest, OtpVerifyResponse,
|
|
@@ -90,6 +90,8 @@ export abstract class BaseAuthService extends BaseRestService {
|
|
|
90
90
|
protected get registerUrl() { return this.url(RestURL.registerURL); }
|
|
91
91
|
protected get chpassUrl() { return this.url(RestURL.chpassURL); }
|
|
92
92
|
protected get confirmRegisterUrl() { return this.url(RestURL.confirmRegisterURL); }
|
|
93
|
+
protected get registerExchangeUrl() { return this.url(RestURL.registerExchangeURL); }
|
|
94
|
+
protected get registerPartnerUrl() { return this.url(RestURL.registerPartnerURL); }
|
|
93
95
|
protected get confirmChpassUrl() { return this.url(RestURL.confirmChpassURL); }
|
|
94
96
|
protected get loginGoogleUrl() { return this.url(RestURL.loginGoogleURL); }
|
|
95
97
|
protected get twoFactorSetupUrl() { return this.url(RestURL.twoFactorSetupURL); }
|
|
@@ -449,9 +451,32 @@ export abstract class BaseAuthService extends BaseRestService {
|
|
|
449
451
|
return this.http.post<{ message: string }>(this.profilePhoneConfirmUrl, { value, code });
|
|
450
452
|
}
|
|
451
453
|
|
|
452
|
-
|
|
454
|
+
/** Confirm a registration; success completes the login from the tokens keel
|
|
455
|
+
* answers. A registration without partner fields leaves `partnerId` 0. */
|
|
456
|
+
confirmRegister(email: string, code: string): Observable<ConfirmRegisterResponse> {
|
|
453
457
|
const params = new HttpParams().set('email', email).set('code', code);
|
|
454
|
-
return this.http.post<ConfirmRegisterResponse>(this.confirmRegisterUrl, null, { params })
|
|
458
|
+
return this.http.post<ConfirmRegisterResponse>(this.confirmRegisterUrl, null, { params }).pipe(
|
|
459
|
+
tap((res) => this.completeLogin(res.token, res.refreshToken)),
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/** Create the partner of a signed-in user who has none, then rotate the
|
|
464
|
+
* refresh token so the session carries the partner. An error after keel
|
|
465
|
+
* created the partner means only the rotation failed; do not post again. */
|
|
466
|
+
createPartner(setup: PartnerSetup): Observable<PartnerCreated> {
|
|
467
|
+
return this.http.post<PartnerCreated>(this.registerPartnerUrl, setup).pipe(
|
|
468
|
+
mergeMap((created) => this.refreshSession().pipe(
|
|
469
|
+
tap((token) => this.completeLogin(token, localStorage.getItem('refreshToken') ?? undefined)),
|
|
470
|
+
map(() => created),
|
|
471
|
+
)),
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/** Trade keel's single-use hand-off code for a session; same contract as login(). */
|
|
476
|
+
exchangeHandoff(code: string): Observable<LoginResponse2FA> {
|
|
477
|
+
return this.http.post<LoginResponse2FA>(this.registerExchangeUrl, { code }, { withCredentials: true }).pipe(
|
|
478
|
+
tap((res) => this.handleLoginResponse(res)),
|
|
479
|
+
);
|
|
455
480
|
}
|
|
456
481
|
|
|
457
482
|
confirmChpass(username: string, code: string, new_password: string) {
|
|
@@ -485,7 +510,7 @@ export abstract class BaseAuthService extends BaseRestService {
|
|
|
485
510
|
}
|
|
486
511
|
|
|
487
512
|
register(reg: PartnerRegistration) {
|
|
488
|
-
return this.http.post<
|
|
513
|
+
return this.http.post<{ status: string }>(this.registerUrl, reg);
|
|
489
514
|
}
|
|
490
515
|
|
|
491
516
|
// ── Phone / email OTP ──
|
package/src/service/rest_url.ts
CHANGED
|
@@ -9,7 +9,9 @@ export const RestURL = {
|
|
|
9
9
|
loginGoogleURL: '/public/login/google',
|
|
10
10
|
registerURL: '/public/register',
|
|
11
11
|
chpassURL: '/public/login/chpass',
|
|
12
|
-
confirmRegisterURL: '/public/confirm
|
|
12
|
+
confirmRegisterURL: '/public/register/confirm',
|
|
13
|
+
registerExchangeURL: '/public/register/exchange',
|
|
14
|
+
registerPartnerURL: '/api/register/partner',
|
|
13
15
|
plansURL: '/public/plans',
|
|
14
16
|
confirmChpassURL: '/public/confirm/password',
|
|
15
17
|
twoFactorSetupURL: '/api/user/2fa/setup',
|