@nauticana/sail 1.1.9 → 1.1.11

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.
Files changed (79) hide show
  1. package/README.md +4 -2
  2. package/package.json +5 -1
  3. package/src/component/abstract/base_async.ts +9 -11
  4. package/src/component/abstract/base_form.ts +6 -5
  5. package/src/component/abstract/base_table.ts +131 -58
  6. package/src/component/abstract/base_view.ts +43 -27
  7. package/src/component/account/profile_editor.ts +2 -2
  8. package/src/component/billing/payment_methods.ts +1 -2
  9. package/src/component/billing/price_selector.html +2 -1
  10. package/src/component/billing/price_selector.ts +28 -13
  11. package/src/component/billing/trial_banner.ts +7 -1
  12. package/src/component/billing/usage_meter.ts +2 -2
  13. package/src/component/dashboard/data_card.html +1 -1
  14. package/src/component/dashboard/entity_selector.ts +21 -23
  15. package/src/component/form/form_field.html +6 -5
  16. package/src/component/form/form_field.ts +39 -21
  17. package/src/component/form/form_record.html +3 -3
  18. package/src/component/form/form_record.ts +23 -8
  19. package/src/component/form/form_table.html +2 -2
  20. package/src/component/form/form_table.ts +6 -5
  21. package/src/component/login/account_deletion.ts +6 -6
  22. package/src/component/login/chpass_component.html +4 -4
  23. package/src/component/login/chpass_component.ts +0 -1
  24. package/src/component/login/confirm_chpass_component.html +4 -4
  25. package/src/component/login/confirm_chpass_component.ts +1 -4
  26. package/src/component/login/consent_gate.html +6 -6
  27. package/src/component/login/consent_gate.ts +17 -24
  28. package/src/component/login/login_component.html +7 -4
  29. package/src/component/login/login_component.ts +9 -5
  30. package/src/component/login/otp_input.html +13 -5
  31. package/src/component/login/otp_input.ts +34 -27
  32. package/src/component/login/register_component.html +31 -14
  33. package/src/component/login/register_component.ts +80 -89
  34. package/src/component/login/sms_consent.html +11 -0
  35. package/src/component/login/sms_consent.ts +38 -0
  36. package/src/component/login/social_login.html +2 -2
  37. package/src/component/login/social_login.ts +20 -13
  38. package/src/component/navigation/navigation.html +2 -2
  39. package/src/component/navigation/navigation.ts +2 -0
  40. package/src/component/oauth_connection/oauth_connection_panel.ts +24 -3
  41. package/src/component/payment/user_payment_methods.html +2 -2
  42. package/src/component/payment/user_payment_methods.ts +12 -23
  43. package/src/component/payout/bank_info_form.html +4 -4
  44. package/src/component/payout/bank_info_form.ts +22 -26
  45. package/src/component/payout/provider_onboarding.html +5 -5
  46. package/src/component/payout/provider_onboarding.ts +28 -48
  47. package/src/component/security/trusted_devices.html +1 -1
  48. package/src/component/security/trusted_devices.ts +0 -1
  49. package/src/component/security/twofactor_setup.html +8 -4
  50. package/src/component/security/twofactor_setup.ts +21 -3
  51. package/src/component/security/twofactor_verify.html +2 -1
  52. package/src/component/security/twofactor_verify.ts +2 -8
  53. package/src/component/table/table_detail.html +15 -14
  54. package/src/component/table/table_detail.ts +62 -41
  55. package/src/component/table/table_edit.html +15 -11
  56. package/src/component/table/table_edit.ts +94 -67
  57. package/src/component/table/table_list.html +45 -12
  58. package/src/component/table/table_list.ts +98 -26
  59. package/src/component/table/table_lookup.html +11 -8
  60. package/src/component/table/table_lookup.ts +45 -37
  61. package/src/component/table/table_report.html +2 -2
  62. package/src/component/table/table_report.ts +37 -31
  63. package/src/component/table/table_search.html +4 -4
  64. package/src/component/table/table_search.ts +36 -45
  65. package/src/config.ts +5 -1
  66. package/src/index.ts +2 -0
  67. package/src/model/appdata.ts +5 -9
  68. package/src/model/common.ts +27 -27
  69. package/src/model/decorator.ts +25 -21
  70. package/src/service/api-response.interceptor.ts +4 -1
  71. package/src/service/auth.interceptor.ts +27 -7
  72. package/src/service/auth.service.ts +188 -134
  73. package/src/service/label.service.ts +6 -5
  74. package/src/service/oauth_connection.service.ts +2 -2
  75. package/src/service/rest_service.ts +57 -13
  76. package/src/service/rest_url.ts +23 -7
  77. package/src/service/script_loader.ts +12 -2
  78. package/src/util/errors.ts +20 -0
  79. package/src/util/money.ts +19 -7
@@ -1,4 +1,4 @@
1
- import { ChangeDetectionStrategy, Component, inject, signal, ViewEncapsulation } from '@angular/core';
1
+ import { ChangeDetectionStrategy, Component, effect, inject, input, signal, ViewEncapsulation } from '@angular/core';
2
2
  import { BaseAuthService } from '../../service/auth.service';
3
3
  import { MatButtonModule } from '@angular/material/button';
4
4
  import { MatFormFieldModule } from '@angular/material/form-field';
@@ -6,6 +6,7 @@ import { MatInputModule } from '@angular/material/input';
6
6
  import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
7
7
  import { RouterLink } from '@angular/router';
8
8
  import { BaseAsync } from '../abstract/base_async';
9
+ import { toDataURL } from 'qrcode';
9
10
 
10
11
  @Component({
11
12
  selector: 'sail-twofactor-setup',
@@ -24,8 +25,13 @@ export class TwoFactorSetupComponent extends BaseAsync {
24
25
  private readonly auth = inject(BaseAuthService);
25
26
  private readonly fb = inject(FormBuilder);
26
27
 
28
+ /** keel has no 2FA-status endpoint — the app tells us whether 2FA is already
29
+ * on so returning users land on the manage/disable view, not a fresh setup
30
+ * (which would rotate their seed and revoke all refresh tokens). */
31
+ readonly twoFactorEnabled = input(false);
32
+
27
33
  readonly step = signal<'init' | 'qr' | 'verify' | 'done'>('init');
28
- readonly qrUri = signal('');
34
+ readonly qrDataUrl = signal('');
29
35
  readonly secret = signal('');
30
36
  readonly backupCodes = signal<string[]>([]);
31
37
  readonly showCodes = signal(false);
@@ -46,13 +52,25 @@ export class TwoFactorSetupComponent extends BaseAsync {
46
52
  code: ['', [Validators.required, Validators.minLength(6), Validators.maxLength(6)]],
47
53
  });
48
54
 
55
+ constructor() {
56
+ super();
57
+ // Only flips between the two idle states; never yanks a user out of a flow.
58
+ effect(() => {
59
+ const enabled = this.twoFactorEnabled();
60
+ this.step.update((s) => (s === 'init' || s === 'done') ? (enabled ? 'done' : 'init') : s);
61
+ });
62
+ }
63
+
49
64
  startSetup() {
50
65
  if (this.initForm.invalid) return;
51
66
  const password = this.initForm.value.password!;
52
67
  this.run(
53
68
  this.auth.setup2FA({ password }),
54
69
  (res) => {
55
- this.qrUri.set(res.qrUri);
70
+ // keel returns an otpauth:// provisioning URI, not an image — render it.
71
+ toDataURL(res.qrUri, { width: 200, margin: 1 })
72
+ .then((url) => this.qrDataUrl.set(url))
73
+ .catch(() => this.qrDataUrl.set(''));
56
74
  this.secret.set(res.secret);
57
75
  this.backupCodes.set(res.backupCodes);
58
76
  this.step.set('qr');
@@ -36,7 +36,8 @@
36
36
  </button>
37
37
  </form>
38
38
  <div class="auth-actions">
39
- <a tabindex="0" role="button" (click)="toggleBackupCode()" (keydown.enter)="toggleBackupCode()">
39
+ <a tabindex="0" role="button" (click)="toggleBackupCode()" (keydown.enter)="toggleBackupCode()"
40
+ (keydown.space)="$event.preventDefault(); toggleBackupCode()">
40
41
  {{ useBackupCode() ? 'Use authenticator code' : 'Use a backup code instead' }}
41
42
  </a>
42
43
  <a routerLink="/login/local">Back to Login</a>
@@ -46,17 +46,11 @@ export class TwoFactorVerifyComponent extends BaseAsync {
46
46
  const { code, trustDevice } = this.verifyForm.value;
47
47
 
48
48
  if (this.useBackupCode()) {
49
+ // verifyBackupCode completes the login inside BaseAuthService.
49
50
  this.run(
50
51
  this.auth.verifyBackupCode(code!),
51
52
  (res) => {
52
- if (res.valid && res.token) {
53
- localStorage.removeItem('loginToken');
54
- this.auth.token = res.token;
55
- this.auth.isLoggedIn.set(true);
56
- localStorage.setItem('jwt', res.token);
57
- this.auth.loadAppData();
58
- this.auth.initRoutes();
59
- } else {
53
+ if (!res.valid || !res.token) {
60
54
  this.errorMessage.set('Invalid backup code.');
61
55
  }
62
56
  },
@@ -4,7 +4,7 @@
4
4
  @if (canCreate()) {
5
5
  <button matButton="elevated" class="accent" (click)="addRecord()">New Record</button>
6
6
  }
7
- @for (action of getActions(false); track action.action) {
7
+ @for (action of tableActions(); track action.action) {
8
8
  @if (canExecuteAction(action)) {
9
9
  <button matButton="outlined" type="button"
10
10
  [title]="action.caption"
@@ -18,17 +18,17 @@
18
18
  <table class="mat-table">
19
19
  <thead>
20
20
  <tr>
21
- @for (col of displayedColumns; track col) {
22
- <th>{{ colCaption(col) }}</th>
21
+ @for (col of displayedColumns(); track col) {
22
+ <th scope="col">{{ colCaption(col) }}</th>
23
23
  }
24
- <th>Actions</th>
24
+ <th scope="col">Actions</th>
25
25
  </tr>
26
26
  </thead>
27
27
  <tbody>
28
- @for (record of records; track $index) {
28
+ @for (record of visibleRecords(); track trackByRecord($index, record)) {
29
29
  <tr [class.deleted-record]="isDeleted(record)" [class.updated-record]="isUpdated(record)" [class.new-record]="isInserted(record)">
30
- @if (record == editingRecord) {
31
- @for (col of displayedColumns; track col) {
30
+ @if (record === editingRecord()) {
31
+ @for (col of displayedColumns(); track col) {
32
32
  <td>
33
33
  @if (isReadOnly(col)) {
34
34
  {{ record[col] }}
@@ -38,27 +38,28 @@
38
38
  </td>
39
39
  }
40
40
  <td>
41
- <button matIconButton (click)="saveRow()" [title]="isNew ? 'Add' : 'Update'"><mat-icon>{{ isNew ? 'add' : 'check' }}</mat-icon></button>
42
- <button matIconButton (click)="cancelRow(record)" title="Cancel"><mat-icon>cancel</mat-icon></button>
41
+ <button matIconButton (click)="saveRow()" [title]="isNew() ? 'Add' : 'Update'" [attr.aria-label]="isNew() ? 'Add' : 'Update'"><mat-icon>{{ isNew() ? 'add' : 'check' }}</mat-icon></button>
42
+ <button matIconButton (click)="cancelRow(record)" title="Cancel" aria-label="Cancel"><mat-icon>cancel</mat-icon></button>
43
43
  </td>
44
44
  } @else {
45
- @for (col of displayedColumns; track col) {
45
+ @for (col of displayedColumns(); track col) {
46
46
  <td>{{ displayValue(col, record[col]) }}</td>
47
47
  }
48
48
  <td>
49
49
  @if (canUpdate()) {
50
- <button matIconButton (click)="editRow(record)" title="Edit"><mat-icon>edit</mat-icon></button>
50
+ <button matIconButton (click)="editRow(record)" title="Edit" aria-label="Edit"><mat-icon>edit</mat-icon></button>
51
51
  }
52
52
  @if (isDeleted(record)) {
53
- <button matIconButton (click)="unDeleteRow(record)" title="Undelete"><mat-icon>restore_from_trash</mat-icon></button>
53
+ <button matIconButton (click)="unDeleteRow(record)" title="Undelete" aria-label="Undelete"><mat-icon>restore_from_trash</mat-icon></button>
54
54
  } @else if (canDelete()) {
55
- <button matIconButton (click)="deleteRow(record)" title="Delete"><mat-icon>delete</mat-icon></button>
55
+ <button matIconButton (click)="deleteRow(record)" title="Delete" aria-label="Delete"><mat-icon>delete</mat-icon></button>
56
56
  }
57
57
  @if (!isInserted(record)) {
58
- @for (action of getActions(true); track action.action) {
58
+ @for (action of recordActions(); track action.action) {
59
59
  @if (canExecuteAction(action)) {
60
60
  <button matIconButton type="button"
61
61
  [title]="action.caption"
62
+ [attr.aria-label]="action.caption"
62
63
  (click)="executeAction(action, record)">
63
64
  <mat-icon>{{ action.icon || 'play_arrow' }}</mat-icon>
64
65
  </button>
@@ -1,4 +1,4 @@
1
- import { ChangeDetectionStrategy, Component, effect, inject, input, linkedSignal, OnInit, output, ViewEncapsulation } from "@angular/core";
1
+ import { ChangeDetectionStrategy, Component, computed, effect, inject, input, linkedSignal, output, signal, ViewEncapsulation } from "@angular/core";
2
2
  import { DynamicField } from "../form/form_field";
3
3
  import { MatButtonModule } from "@angular/material/button";
4
4
  import { BaseForm } from "../abstract/base_form";
@@ -19,11 +19,11 @@ import { OpCode } from "../../model/common";
19
19
  MatIconModule,
20
20
  ],
21
21
  })
22
- export class TableDetail extends BaseForm implements OnInit {
22
+ export class TableDetail extends BaseForm {
23
23
  readonly tableNameInput = input('', { alias: 'tableName' });
24
- readonly recordsInput = input<any[]>([], { alias: 'records' });
24
+ readonly recordsInput = input<Record<string, unknown>[]>([], { alias: 'records' });
25
25
  readonly parentTableName = input('');
26
- readonly parentRecord = input<any>({});
26
+ readonly parentRecord = input<Record<string, unknown>>({});
27
27
  /** When true, the parent view is in read-only mode — disable all child row editing. */
28
28
  readonly parentReadOnly = input(false);
29
29
  /** Fires after any grid mutation (add/edit/delete/undelete/cancel) so a parent
@@ -32,19 +32,34 @@ export class TableDetail extends BaseForm implements OnInit {
32
32
 
33
33
  override readonly tableName = linkedSignal<string, string>({ source: () => this.tableNameInput(), computation: (v, p) => v || p?.value || '' });
34
34
 
35
- records: any[] = [];
36
- editingRecord: any = null;
37
- originalRecord: any = null;
38
- displayedColumns: string[] = [];
39
- fkColumns: string[] = [];
35
+ // The parent owns the rows array (TableEdit saves it verbatim), so mutations
36
+ // happen in place; refresh() snapshots them for the template.
37
+ records: Record<string, unknown>[] = [];
38
+ readonly visibleRecords = signal<Record<string, unknown>[]>([]);
39
+
40
+ readonly editingRecord = signal<Record<string, unknown> | null>(null);
41
+ private originalRecord: Record<string, unknown> | null = null;
42
+
43
+ readonly displayedColumns = computed(() => {
44
+ this.visibleRecords();
45
+ return this.getDisplayedColumns(this.records);
46
+ });
47
+
48
+ readonly fkColumns = computed(() =>
49
+ this.getForeignKeyConfig(this.parentTableName())?.fk?.Columns?.map((col) => col.PascalName) ?? []);
40
50
 
41
51
  private readonly dialog = inject(MatDialog);
42
52
 
43
53
  constructor() {
44
54
  super();
45
- // records is a writable array (push/splice in event handlers); keep it in sync with the input
46
- // via effect rather than linkedSignal so mutations work on the consumer's array reference.
47
- effect(() => { this.records = this.recordsInput(); });
55
+ effect(() => {
56
+ this.records = this.recordsInput() ?? [];
57
+ this.refresh();
58
+ });
59
+ }
60
+
61
+ private refresh() {
62
+ this.visibleRecords.set([...this.records]);
48
63
  }
49
64
 
50
65
  /**
@@ -64,21 +79,11 @@ export class TableDetail extends BaseForm implements OnInit {
64
79
  override canUpdate() { return !this.parentReadOnly() && super.canUpdate(); }
65
80
  override canDelete() { return !this.parentReadOnly() && super.canDelete(); }
66
81
 
67
- ngOnInit(): void {
68
- this.displayedColumns = this.getDisplayedColumns(this.records);
69
- const fkCfg = this.getForeignKeyConfig(this.parentTableName());
70
- if (fkCfg && fkCfg.fk && fkCfg.fk.Columns) {
71
- for (const col of fkCfg.fk.Columns) {
72
- this.fkColumns.push(col.PascalName);
73
- }
74
- }
75
- }
76
-
77
82
  override isReadOnly(fieldName: string): boolean {
78
- return (this.fkColumns.includes(fieldName) || super.isReadOnly(fieldName));
83
+ return (this.fkColumns().includes(fieldName) || super.isReadOnly(fieldName));
79
84
  }
80
85
 
81
- openEditDialog(record: any, isNew: boolean, readOnlyColumns: string[]) {
86
+ openEditDialog(record: Record<string, unknown>, isNew: boolean, readOnlyColumns: string[]) {
82
87
  const dialogRef = this.dialog.open(TableForm, {
83
88
  width: this.dialogWidth,
84
89
  disableClose: true,
@@ -91,46 +96,59 @@ export class TableDetail extends BaseForm implements OnInit {
91
96
  } else {
92
97
  Object.assign(record, result);
93
98
  }
99
+ this.refresh();
94
100
  this.changed.emit();
95
101
  }
96
102
  });
97
103
  }
98
104
 
105
+ /** Finish an in-progress inline edit before starting another (its values are
106
+ * already in the row; leaving it un-finalized would drop them on save). */
107
+ private finalizeInlineEdit() {
108
+ if (this.editingRecord()) this.saveRow();
109
+ }
110
+
99
111
  addRecord() {
112
+ this.finalizeInlineEdit();
100
113
  const newRecord = this.emptyRecord();
101
114
  newRecord[this.config.opField] = OpCode.Insert;
102
115
  this.initializeForeignKeys(newRecord, this.parentTableName(), this.parentRecord());
103
116
 
104
- if (this.displayedColumns.length > 6) {
105
- this.openEditDialog(newRecord, true, this.fkColumns);
117
+ if (this.displayedColumns().length > 6) {
118
+ this.openEditDialog(newRecord, true, this.fkColumns());
106
119
  } else {
107
120
  this.records.push(newRecord);
108
- this.isNew = true;
121
+ this.isNew.set(true);
109
122
  this.originalRecord = null;
110
- this.editingRecord = newRecord;
123
+ this.editingRecord.set(newRecord);
124
+ this.refresh();
111
125
  }
112
126
  }
113
127
 
114
- editRow(record: any) {
115
- if (this.displayedColumns.length > 6) {
116
- this.openEditDialog(record, false, this.fkColumns);
128
+ editRow(record: Record<string, unknown>) {
129
+ if (this.displayedColumns().length > 6) {
130
+ this.openEditDialog(record, false, this.fkColumns());
117
131
  } else {
118
- this.editingRecord = record;
119
- this.isNew = record[this.config.opField] === OpCode.Insert;
132
+ this.finalizeInlineEdit();
133
+ this.isNew.set(record[this.config.opField] === OpCode.Insert);
120
134
  this.originalRecord = {...record};
121
135
  this.formatRecordTimeStamp(record);
136
+ this.editingRecord.set(record);
137
+ this.refresh();
122
138
  }
123
139
  }
124
140
 
125
141
  saveRow() {
126
- this.readyToSave(this.editingRecord);
127
- this.editingRecord = null;
142
+ const editing = this.editingRecord();
143
+ if (editing) this.readyToSave(editing, this.originalRecord);
144
+ this.editingRecord.set(null);
128
145
  this.originalRecord = null;
129
- this.isNew = false;
146
+ this.isNew.set(false);
147
+ this.refresh();
130
148
  this.changed.emit();
131
149
  }
132
150
 
133
- cancelRow(record: any) {
151
+ cancelRow(record: Record<string, unknown>) {
134
152
  if (this.originalRecord) {
135
153
  Object.assign(record, this.originalRecord);
136
154
  } else {
@@ -139,13 +157,14 @@ export class TableDetail extends BaseForm implements OnInit {
139
157
  this.records.splice(index, 1);
140
158
  }
141
159
  }
142
- this.editingRecord = null;
160
+ this.editingRecord.set(null);
143
161
  this.originalRecord = null;
144
- this.isNew = false;
162
+ this.isNew.set(false);
163
+ this.refresh();
145
164
  this.changed.emit();
146
165
  }
147
166
 
148
- deleteRow(record: any) {
167
+ deleteRow(record: Record<string, unknown>) {
149
168
  if (record[this.config.opField] === OpCode.Insert) {
150
169
  const index = this.records.indexOf(record);
151
170
  if (index > -1) {
@@ -154,13 +173,15 @@ export class TableDetail extends BaseForm implements OnInit {
154
173
  } else {
155
174
  record[this.config.opField] = OpCode.Delete;
156
175
  }
176
+ this.refresh();
157
177
  this.changed.emit();
158
178
  }
159
179
 
160
- unDeleteRow(record: any) {
180
+ unDeleteRow(record: Record<string, unknown>) {
161
181
  if (record[this.config.opField] === OpCode.Delete) {
162
182
  record[this.config.opField] = OpCode.Update;
163
183
  }
184
+ this.refresh();
164
185
  this.changed.emit();
165
186
  }
166
187
  }
@@ -1,8 +1,8 @@
1
1
  <h1 class="mat-h1 table-edit-title">
2
2
  <span class="table-edit-title-text">
3
- @if (title) {
4
- {{ title }}
5
- } @else if (isNew) {
3
+ @if (title()) {
4
+ {{ title() }}
5
+ } @else if (isNew()) {
6
6
  New {{ getCaption() }} Record
7
7
  } @else {
8
8
  {{ getCaption() }} Details
@@ -18,7 +18,7 @@
18
18
 
19
19
  <div class="edit-container">
20
20
  <div class="actions-bar">
21
- @if (isReadOnlyMode) {
21
+ @if (isReadOnlyMode()) {
22
22
  @if (canUpdate()) {
23
23
  <button matButton="elevated" class="primary" (click)="onEdit()">Edit</button>
24
24
  }
@@ -28,7 +28,7 @@
28
28
  @if (canDelete()) {
29
29
  <button matButton class="warn" (click)="onDelete()">Delete</button>
30
30
  }
31
- @for (action of getActions(true); track action.action) {
31
+ @for (action of recordActions(); track action.action) {
32
32
  @if (canExecuteAction(action)) {
33
33
  <button matButton="outlined" type="button"
34
34
  [title]="action.caption"
@@ -44,20 +44,24 @@
44
44
  }
45
45
  </div>
46
46
 
47
- <sail-record-form [tableName]="tableName()" [record]="editableRecord" [isReadOnly]="isReadOnlyBound"></sail-record-form>
47
+ @if (saveError()) {
48
+ <p class="table-edit-error" role="alert">{{ saveError() }}</p>
49
+ }
50
+
51
+ <sail-record-form [tableName]="tableName()" [record]="editableRecord()" (recordChange)="editableRecord.set($event)" [isReadOnly]="isReadOnlyFn"></sail-record-form>
48
52
 
49
- @if (tabCount > 0) {
53
+ @if (tabFields().length > 0) {
50
54
  <mat-tab-group>
51
- @for (key of tabFields; track key) {
55
+ @for (key of tabFields(); track key) {
52
56
  @if (cacheService.canRead(getTableName(key))) {
53
57
  <mat-tab [label]="key">
54
58
  <div class="tab-content">
55
59
  <sail-table-detail
56
- [records]="editableRecord[key]"
60
+ [records]="childRecords(key)"
57
61
  [tableName]="getTableName(key)"
58
62
  [parentTableName]="tableName()"
59
- [parentRecord]="editableRecord"
60
- [parentReadOnly]="isReadOnlyMode">
63
+ [parentRecord]="editableRecord()"
64
+ [parentReadOnly]="isReadOnlyMode()">
61
65
  </sail-table-detail>
62
66
  </div>
63
67
  </mat-tab>