@fiduswriter/frontend 0.1.27 → 0.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.
Files changed (146) hide show
  1. package/dist/admin_console/index.d.ts +9 -2
  2. package/dist/admin_console/index.d.ts.map +1 -1
  3. package/dist/admin_console/index.js.map +1 -1
  4. package/dist/api/index.d.ts +62 -75
  5. package/dist/api/index.d.ts.map +1 -1
  6. package/dist/app/index.d.ts +11 -6
  7. package/dist/app/index.d.ts.map +1 -1
  8. package/dist/app/index.js +66 -23
  9. package/dist/app/index.js.map +1 -1
  10. package/dist/document_templates/actions.js +2 -4
  11. package/dist/document_templates/actions.js.map +1 -1
  12. package/dist/document_templates/editor.d.ts +2 -2
  13. package/dist/document_templates/editor.d.ts.map +1 -1
  14. package/dist/document_templates/editor.js +2 -2
  15. package/dist/document_templates/editor.js.map +1 -1
  16. package/dist/document_templates/overview.d.ts +7 -7
  17. package/dist/document_templates/overview.d.ts.map +1 -1
  18. package/dist/document_templates/overview.js.map +1 -1
  19. package/dist/documents/overview/actions.d.ts +3 -2
  20. package/dist/documents/overview/actions.d.ts.map +1 -1
  21. package/dist/documents/overview/actions.js +20 -17
  22. package/dist/documents/overview/actions.js.map +1 -1
  23. package/dist/documents/overview/index.d.ts +8 -17
  24. package/dist/documents/overview/index.d.ts.map +1 -1
  25. package/dist/documents/overview/index.js +2 -2
  26. package/dist/documents/overview/index.js.map +1 -1
  27. package/dist/documents/overview/menu.d.ts.map +1 -1
  28. package/dist/documents/overview/menu.js +2 -2
  29. package/dist/documents/overview/menu.js.map +1 -1
  30. package/dist/documents/tools.d.ts +2 -2
  31. package/dist/documents/tools.d.ts.map +1 -1
  32. package/dist/documents/tools.js.map +1 -1
  33. package/dist/e2ee/passphrase_urls.d.ts +10 -0
  34. package/dist/e2ee/passphrase_urls.d.ts.map +1 -0
  35. package/dist/e2ee/passphrase_urls.js +23 -0
  36. package/dist/e2ee/passphrase_urls.js.map +1 -0
  37. package/dist/error_hook/index.d.ts +8 -1
  38. package/dist/error_hook/index.d.ts.map +1 -1
  39. package/dist/error_hook/index.js +10 -12
  40. package/dist/error_hook/index.js.map +1 -1
  41. package/dist/feedback/index.d.ts +3 -2
  42. package/dist/feedback/index.d.ts.map +1 -1
  43. package/dist/feedback/index.js.map +1 -1
  44. package/dist/index.d.ts +1 -1
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/maintenance/index.d.ts +3 -2
  47. package/dist/maintenance/index.d.ts.map +1 -1
  48. package/dist/maintenance/index.js.map +1 -1
  49. package/dist/menu/index.d.ts +3 -3
  50. package/dist/menu/index.d.ts.map +1 -1
  51. package/dist/menu/index.js +0 -1
  52. package/dist/menu/index.js.map +1 -1
  53. package/dist/pages/flatpage.js.map +1 -1
  54. package/dist/prelogin/index.d.ts +3 -7
  55. package/dist/prelogin/index.d.ts.map +1 -1
  56. package/dist/prelogin/index.js.map +1 -1
  57. package/dist/types.d.ts +63 -8
  58. package/dist/types.d.ts.map +1 -1
  59. package/dist/user/auth/email_confirm.d.ts +2 -2
  60. package/dist/user/auth/email_confirm.d.ts.map +1 -1
  61. package/dist/user/auth/email_confirm.js +5 -6
  62. package/dist/user/auth/email_confirm.js.map +1 -1
  63. package/dist/user/auth/login.d.ts +3 -3
  64. package/dist/user/auth/login.d.ts.map +1 -1
  65. package/dist/user/auth/login.js +18 -19
  66. package/dist/user/auth/login.js.map +1 -1
  67. package/dist/user/auth/password_reset_change.d.ts +2 -2
  68. package/dist/user/auth/password_reset_change.d.ts.map +1 -1
  69. package/dist/user/auth/password_reset_change.js +0 -1
  70. package/dist/user/auth/password_reset_change.js.map +1 -1
  71. package/dist/user/auth/password_reset_request.d.ts +2 -2
  72. package/dist/user/auth/password_reset_request.d.ts.map +1 -1
  73. package/dist/user/auth/password_reset_request.js +0 -1
  74. package/dist/user/auth/password_reset_request.js.map +1 -1
  75. package/dist/user/auth/signup.d.ts +2 -2
  76. package/dist/user/auth/signup.d.ts.map +1 -1
  77. package/dist/user/auth/signup.js +2 -2
  78. package/dist/user/auth/signup.js.map +1 -1
  79. package/dist/user/auth/two_factor.d.ts +7 -5
  80. package/dist/user/auth/two_factor.d.ts.map +1 -1
  81. package/dist/user/auth/two_factor.js +3 -2
  82. package/dist/user/auth/two_factor.js.map +1 -1
  83. package/dist/user/contacts/add_dialog.d.ts +16 -2
  84. package/dist/user/contacts/add_dialog.d.ts.map +1 -1
  85. package/dist/user/contacts/add_dialog.js +4 -4
  86. package/dist/user/contacts/add_dialog.js.map +1 -1
  87. package/dist/user/contacts/delete_dialog.d.ts +3 -2
  88. package/dist/user/contacts/delete_dialog.d.ts.map +1 -1
  89. package/dist/user/contacts/delete_dialog.js.map +1 -1
  90. package/dist/user/contacts/index.d.ts +10 -2
  91. package/dist/user/contacts/index.d.ts.map +1 -1
  92. package/dist/user/contacts/index.js.map +1 -1
  93. package/dist/user/contacts/invite.d.ts +3 -2
  94. package/dist/user/contacts/invite.d.ts.map +1 -1
  95. package/dist/user/contacts/invite.js +3 -2
  96. package/dist/user/contacts/invite.js.map +1 -1
  97. package/dist/user/contacts/menu.d.ts.map +1 -1
  98. package/dist/user/contacts/menu.js +1 -1
  99. package/dist/user/contacts/menu.js.map +1 -1
  100. package/dist/user/contacts/respond_invite.d.ts +3 -2
  101. package/dist/user/contacts/respond_invite.d.ts.map +1 -1
  102. package/dist/user/contacts/respond_invite.js.map +1 -1
  103. package/dist/user/profile/delete_user.d.ts +3 -2
  104. package/dist/user/profile/delete_user.d.ts.map +1 -1
  105. package/dist/user/profile/delete_user.js.map +1 -1
  106. package/dist/user/profile/dialogs.d.ts +8 -7
  107. package/dist/user/profile/dialogs.d.ts.map +1 -1
  108. package/dist/user/profile/dialogs.js +3 -4
  109. package/dist/user/profile/dialogs.js.map +1 -1
  110. package/dist/user/profile/index.d.ts +9 -4
  111. package/dist/user/profile/index.d.ts.map +1 -1
  112. package/dist/user/profile/index.js.map +1 -1
  113. package/package.json +12 -9
  114. package/src/admin_console/index.ts +9 -2
  115. package/src/api/index.ts +78 -39
  116. package/src/app/index.ts +114 -50
  117. package/src/document_templates/actions.ts +6 -6
  118. package/src/document_templates/editor.ts +10 -8
  119. package/src/document_templates/overview.ts +10 -12
  120. package/src/documents/overview/actions.ts +52 -25
  121. package/src/documents/overview/index.ts +16 -27
  122. package/src/documents/overview/menu.ts +4 -2
  123. package/src/documents/tools.ts +2 -2
  124. package/src/error_hook/index.ts +20 -15
  125. package/src/feedback/index.ts +5 -3
  126. package/src/index.ts +3 -1
  127. package/src/maintenance/index.ts +16 -7
  128. package/src/menu/index.ts +4 -4
  129. package/src/pages/flatpage.ts +4 -4
  130. package/src/prelogin/index.ts +4 -8
  131. package/src/types.ts +53 -9
  132. package/src/user/auth/email_confirm.ts +19 -19
  133. package/src/user/auth/login.ts +23 -22
  134. package/src/user/auth/password_reset_change.ts +4 -4
  135. package/src/user/auth/password_reset_request.ts +3 -3
  136. package/src/user/auth/signup.ts +8 -8
  137. package/src/user/auth/two_factor.ts +31 -22
  138. package/src/user/contacts/add_dialog.ts +7 -4
  139. package/src/user/contacts/delete_dialog.ts +3 -2
  140. package/src/user/contacts/index.ts +14 -4
  141. package/src/user/contacts/invite.ts +9 -5
  142. package/src/user/contacts/menu.ts +4 -1
  143. package/src/user/contacts/respond_invite.ts +3 -2
  144. package/src/user/profile/delete_user.ts +3 -2
  145. package/src/user/profile/dialogs.ts +19 -18
  146. package/src/user/profile/index.ts +13 -10
package/src/types.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export interface Email {
2
2
  address: string
3
3
  primary?: boolean
4
+ verified?: boolean
4
5
  }
5
6
 
6
7
  export interface User {
@@ -17,13 +18,8 @@ export interface Route {
17
18
 
18
19
  export type RouteMap = Record<string, Route>
19
20
 
20
- export interface Settings {
21
- APPS: string[]
22
- [key: string]: unknown
23
- }
24
-
25
21
  export interface SiteMenuLike {
26
- app: App
22
+ app: FrontendApp
27
23
  navItems: NavItem[]
28
24
  }
29
25
 
@@ -45,20 +41,68 @@ export type MenuPlugin = Record<string, MenuPluginExport>
45
41
 
46
42
  export type MenuPlugins = Array<[string, MenuPlugin]>
47
43
 
44
+ import type {Settings as FwSettings} from "fwtoolkit/settings"
45
+ import type {ApiConnectors} from "./api/index.js"
46
+
48
47
  export interface App {
49
48
  routes: RouteMap
50
49
  goTo: (url: string) => void
51
50
  settings: Settings
52
51
  menuPlugins?: MenuPlugins
53
- apiConnectors?: Record<string, any>
54
- name?: string
52
+ apiConnectors: ApiConnectors
53
+ name: string
54
+ }
55
+
56
+ export interface Settings extends FwSettings {
57
+ APPS: string[]
58
+ }
59
+
60
+ export interface FrontendApp extends App {
61
+ app: FrontendApp
62
+ user: User & {
63
+ is_authenticated?: boolean
64
+ id?: number
65
+ waiting_invites?: boolean
66
+ [key: string]: unknown
67
+ }
68
+ isOffline: () => boolean
69
+ bibDB?: unknown
70
+ csl?: {getStyles(): Promise<unknown>}
71
+ imageDB?: unknown
72
+ indexedDB?: {
73
+ readAllData(store: string): Promise<unknown[]>
74
+ clearData(store: string): Promise<void>
75
+ insertData(store: string, data: Record<string, unknown>[] | undefined): void
76
+ }
77
+ page?: unknown
78
+ plugins?: Record<string, unknown>
79
+ ws?: {
80
+ connectionCount?: number
81
+ connected?: boolean
82
+ init(): void
83
+ close(): void
84
+ }
85
+ ws_url_base?: string
86
+ socialaccount_providers?: Array<Record<string, unknown>>
87
+ inviteKey?: string
88
+ getConfiguration(): Promise<void>
89
+ selectPage(): Promise<void>
90
+ goTo(url: string): Promise<void>
91
+ init(): Promise<any>
92
+ openLoginPage(): {init(): Promise<any>; [key: string]: unknown}
93
+ openOfflinePage(): {init(): Promise<any>; [key: string]: unknown}
94
+ openSetupPage(): {init(): Promise<any>; [key: string]: unknown}
95
+ open404Page(): {init(): Promise<any>; [key: string]: unknown}
96
+ handleSWUpdate(): void
97
+ [key: string]: unknown
55
98
  }
56
99
 
57
100
  export interface BaseBodyTemplateOptions {
58
101
  user: User
59
102
  contents: string
60
103
  hasOverview?: boolean
61
- app: App
104
+ app: FrontendApp
62
105
  }
63
106
 
64
107
 
108
+
@@ -4,7 +4,7 @@ import {
4
4
  deactivateWait,
5
5
  whenReady
6
6
  } from "fwtoolkit"
7
- import {PreloginPage} from "../../prelogin/index.js"
7
+ import {PreloginPage, type PreloginApp} from "../../prelogin/index.js"
8
8
  import {
9
9
  checkTermsTemplate,
10
10
  confirmAccountTemplate,
@@ -25,7 +25,7 @@ export class EmailConfirm extends PreloginPage {
25
25
  confirmMethods: Array<() => Promise<unknown>>
26
26
  firstVerification: boolean
27
27
 
28
- constructor({app, language}: {app: any; language: string}, key: string) {
28
+ constructor({app, language}: {app: PreloginApp; language: string}, key: string) {
29
29
  super({app, language})
30
30
 
31
31
  this.title = gettext("Confirm Email")
@@ -43,7 +43,7 @@ export class EmailConfirm extends PreloginPage {
43
43
  this.formChecks = []
44
44
  this.confirmQuestionsTemplates = []
45
45
  this.confirmMethods = [
46
- () => (this.app as any).apiConnectors.userProfile.confirmEmail(this.key)
46
+ () => this.app.apiConnectors.userProfile.confirmEmail(this.key)
47
47
  ]
48
48
  this.firstVerification = false
49
49
  }
@@ -57,7 +57,7 @@ export class EmailConfirm extends PreloginPage {
57
57
  }
58
58
 
59
59
  getConfirmData(): Promise<void> {
60
- return (this.app as any).apiConnectors.userProfile.getConfirmKeyData({key: this.key})
60
+ return this.app.apiConnectors.userProfile.getConfirmKeyData({key: this.key})
61
61
  .then((json: any) => {
62
62
  this.username = json.username
63
63
  this.email = json.email
@@ -65,7 +65,7 @@ export class EmailConfirm extends PreloginPage {
65
65
  this.verified = json.verified
66
66
  this.firstVerification = !json.verified
67
67
  if (json.logout) {
68
- this.app.config.user = {is_authenticated: false}
68
+ this.app.config.user = {is_authenticated: false} as PreloginApp["user"]
69
69
  }
70
70
  })
71
71
  .catch(() => {})
@@ -127,23 +127,23 @@ export class EmailConfirm extends PreloginPage {
127
127
  activateWait()
128
128
  Promise.all(this.confirmMethods.map(method => method())).then(() => {
129
129
  deactivateWait()
130
- if ((this.app.config as any).user.is_authenticated) {
131
- const emailObject = (this.app.config as any).user.emails.find(
132
- (email: any) => email.address === this.email
133
- )
134
- if (emailObject) {
135
- emailObject.verified = true
136
- }
137
- return (this.app.goTo("/user/profile/") as any)
138
- .then(() =>
139
- addAlert("info", gettext("Email verified!"))
130
+ if (this.app.config.user.is_authenticated) {
131
+ const emailObject = this.app.config.user.emails.find(
132
+ email => email.address === this.email
140
133
  )
141
- } else {
142
- const contentsDOM = document.querySelector(".fw-contents")
143
- if (contentsDOM) {
144
- contentsDOM.innerHTML = verifiedAccountTemplate()
134
+ if (emailObject) {
135
+ emailObject.verified = true
145
136
  }
137
+ return this.app.goTo("/user/profile/")
138
+ .then(() =>
139
+ addAlert("info", gettext("Email verified!"))
140
+ )
141
+ }
142
+ const contentsDOM = document.querySelector(".fw-contents")
143
+ if (contentsDOM) {
144
+ contentsDOM.innerHTML = verifiedAccountTemplate()
146
145
  }
146
+ return undefined
147
147
  })
148
148
  })
149
149
  }
@@ -1,5 +1,5 @@
1
1
  import {escapeText} from "fwtoolkit"
2
- import {PreloginPage} from "../../prelogin/index.js"
2
+ import {PreloginPage, type PreloginApp} from "../../prelogin/index.js"
3
3
 
4
4
  export class LoginPage extends PreloginPage {
5
5
  socialaccount_providers: Array<Record<string, unknown>>
@@ -9,7 +9,7 @@ export class LoginPage extends PreloginPage {
9
9
  language,
10
10
  socialaccount_providers
11
11
  }: {
12
- app: any
12
+ app: PreloginApp
13
13
  language: string
14
14
  socialaccount_providers: Array<Record<string, unknown>>
15
15
  }) {
@@ -138,7 +138,7 @@ export class LoginPage extends PreloginPage {
138
138
  if (errors) {
139
139
  return
140
140
  }
141
- return (this.app as any).apiConnectors.auth.login({login, password, remember})
141
+ return this.app.apiConnectors.auth.login({login, password, remember})
142
142
  .catch((response: any) => {
143
143
  if (!(response instanceof Response) || response.status !== 400) {
144
144
  return Promise.reject(response)
@@ -181,42 +181,43 @@ export class LoginPage extends PreloginPage {
181
181
  })
182
182
  .then((result: any) => {
183
183
  if (!result) return
184
- const {json, status} = result
184
+ const {json, status, requiresEmailConfirmation} = result
185
185
  if (status === 400) {
186
186
  return
187
187
  }
188
- this.afterLogin(json)
188
+ this.afterLogin(json, requiresEmailConfirmation)
189
189
  })
190
190
  })
191
191
  }
192
192
 
193
- afterLogin(json: any): void {
193
+ afterLogin(json: any, requiresEmailConfirmation?: boolean): void {
194
194
  const currentLang = document.documentElement.lang
195
+ if (requiresEmailConfirmation) {
196
+ const contentsEl = document.querySelector(".fw-contents")
197
+ if (contentsEl) {
198
+ contentsEl.innerHTML = `<div class="fw-login-left">
199
+ <h1 class="fw-login-title">${gettext("Verify Your E-mail Address")}</h1>
200
+ <p>
201
+ ${gettext("We have sent an e-mail to your email address for verification. Follow the link provided to finalize the signup process.")}
202
+ <br />
203
+ ${gettext("Please contact us if you do not receive it within a few minutes.")}
204
+ </p>
205
+ </div>`
206
+ }
207
+ return
208
+ }
195
209
  if (json.html && json.html.length > 0) {
196
210
  const htmlValues = JSON.parse(json.html)
197
-
198
- if (htmlValues.Location === "/api/account/confirm-email/") {
199
- const contentsEl = document.querySelector(".fw-contents")
200
- if (contentsEl) {
201
- contentsEl.innerHTML = `<div class="fw-login-left">
202
- <h1 class="fw-login-title">${gettext("Verify Your E-mail Address")}</h1>
203
- <p>
204
- ${gettext("We have sent an e-mail to your email address for verification. Follow the link provided to finalize the signup process.")}
205
- <br />
206
- ${gettext("Please contact us if you do not receive it within a few minutes.")}
207
- </p>
208
- </div>`
209
- }
210
- } else if (
211
+ if (
211
212
  htmlValues.user?.language &&
212
213
  htmlValues.user?.language !== currentLang
213
214
  ) {
214
215
  window.location.reload()
215
216
  } else {
216
- ;(this.app as any).init()
217
+ this.app.init()
217
218
  }
218
219
  } else {
219
- ;(this.app as any).init()
220
+ this.app.init()
220
221
  }
221
222
  }
222
223
  }
@@ -1,10 +1,10 @@
1
1
  import {escapeText} from "fwtoolkit"
2
- import {PreloginPage} from "../../prelogin/index.js"
2
+ import {PreloginPage, type PreloginApp} from "../../prelogin/index.js"
3
3
 
4
4
  export class PasswordResetChangePassword extends PreloginPage {
5
5
  key: string
6
6
 
7
- constructor({app, language}: {app: any; language: string}, key: string) {
7
+ constructor({app, language}: {app: PreloginApp; language: string}, key: string) {
8
8
  super({app, language})
9
9
  this.title = gettext("Change Password")
10
10
  this.key = key
@@ -76,10 +76,10 @@ export class PasswordResetChangePassword extends PreloginPage {
76
76
  if (errors) {
77
77
  return
78
78
  }
79
- ;(this.app as any).apiConnectors.auth
79
+ this.app.apiConnectors.auth
80
80
  .passwordResetKeyGet(this.key)
81
81
  .then(({url}: {url: string}) =>
82
- (this.app as any).apiConnectors.auth.passwordResetKeyPost(
82
+ this.app.apiConnectors.auth.passwordResetKeyPost(
83
83
  url,
84
84
  {password1, password2}
85
85
  )
@@ -1,8 +1,8 @@
1
1
  import {escapeText} from "fwtoolkit"
2
- import {PreloginPage} from "../../prelogin/index.js"
2
+ import {PreloginPage, type PreloginApp} from "../../prelogin/index.js"
3
3
 
4
4
  export class PasswordResetRequest extends PreloginPage {
5
- constructor({app, language}: {app: any; language: string}) {
5
+ constructor({app, language}: {app: PreloginApp; language: string}) {
6
6
  super({app, language})
7
7
  this.title = gettext("Reset Password")
8
8
  }
@@ -66,7 +66,7 @@ export class PasswordResetRequest extends PreloginPage {
66
66
  return
67
67
  }
68
68
 
69
- ;(this.app as any).apiConnectors.auth.passwordReset({email})
69
+ this.app.apiConnectors.auth.passwordReset({email})
70
70
  .then(() => {
71
71
  if (document.body !== this.dom) {
72
72
  return
@@ -1,8 +1,8 @@
1
1
  import {escapeText} from "fwtoolkit"
2
- import {PreloginPage} from "../../prelogin/index.js"
2
+ import {PreloginPage, type PreloginApp} from "../../prelogin/index.js"
3
3
 
4
4
  export class Signup extends PreloginPage {
5
- constructor({app, language}: {app: any; language: string}) {
5
+ constructor({app, language}: {app: PreloginApp; language: string}) {
6
6
  super({app, language})
7
7
  this.title = gettext("Signup")
8
8
  if (this.app.settings?.REGISTRATION_OPEN) {
@@ -126,12 +126,12 @@ export class Signup extends PreloginPage {
126
126
  return
127
127
  }
128
128
  const sendData: Record<string, unknown> = {username, password1, password2, email}
129
- if ((this.app as any).inviteKey) {
130
- sendData["invite_key"] = (this.app as any).inviteKey
129
+ if (this.app.inviteKey) {
130
+ sendData["invite_key"] = this.app.inviteKey
131
131
  }
132
- (this.app as any).apiConnectors.auth.signup(sendData)
133
- .then(({json}: any) => {
134
- if (json.location === "/api/account/confirm-email/") {
132
+ this.app.apiConnectors.auth.signup(sendData)
133
+ .then(({requiresEmailConfirmation}) => {
134
+ if (requiresEmailConfirmation) {
135
135
  fwContents.innerHTML = `<div class="fw-login-left">
136
136
  <h1 class="fw-login-title">${gettext("Verify Your E-mail Address")}</h1>
137
137
  <p>
@@ -150,7 +150,7 @@ export class Signup extends PreloginPage {
150
150
  </div>`
151
151
  } else {
152
152
  window.history.pushState({}, "", "/")
153
- ;(this.app as any).init()
153
+ this.app.init()
154
154
  }
155
155
  })
156
156
  .catch((response: any) =>
@@ -2,21 +2,30 @@ import {
2
2
  Dialog,
3
3
  activateWait,
4
4
  addAlert,
5
- deactivateWait
5
+ deactivateWait,
6
+ type DialogButtonSpec
6
7
  } from "fwtoolkit"
7
8
  import QRCode from "qrcode"
8
-
9
- export const twoFactorSetupDialog = (app: any): Promise<any> => {
9
+ import type {
10
+ TwoFactorSetupResponse,
11
+ TwoFactorStatusResponse,
12
+ TwoFactorVerifyResponse
13
+ } from "../../api/index.js"
14
+ import type {FrontendApp} from "../../types.js"
15
+ import type {LoginPage} from "./login.js"
16
+
17
+ export const twoFactorSetupDialog = (app: FrontendApp): Promise<any> => {
10
18
  let secretKey: string | null = null
11
19
  let deviceId: string | null = null
12
20
 
13
21
  activateWait()
14
- return app.apiConnectors.auth.twoFactorSetup().then((json: any): any => {
22
+ return app.apiConnectors.auth.twoFactorSetup().then((json: TwoFactorSetupResponse): any => {
15
23
  deactivateWait()
16
24
 
17
25
  if (json.status !== "success") {
18
- addAlert("error", json.message)
19
- return Promise.reject(json.message)
26
+ const message = json.message || gettext("Two-factor setup failed.")
27
+ addAlert("error", message)
28
+ return Promise.reject(message)
20
29
  }
21
30
 
22
31
  secretKey = json.secret_key
@@ -46,7 +55,7 @@ export const twoFactorSetupDialog = (app: any): Promise<any> => {
46
55
  }
47
56
  )
48
57
 
49
- const buttons = [
58
+ const buttons: DialogButtonSpec[] = [
50
59
  {
51
60
  text: gettext("Verify"),
52
61
  classes: "fw-dark",
@@ -65,7 +74,7 @@ export const twoFactorSetupDialog = (app: any): Promise<any> => {
65
74
  code,
66
75
  device_id: deviceId
67
76
  })
68
- .then((json: any) => {
77
+ .then((json: TwoFactorVerifyResponse) => {
69
78
  if (json.status === "success") {
70
79
  addAlert("success", json.message)
71
80
  dialog.close()
@@ -98,7 +107,7 @@ export const twoFactorSetupDialog = (app: any): Promise<any> => {
98
107
  buttons,
99
108
  icon: "shield-alt",
100
109
  width: 500
101
- } as any)
110
+ })
102
111
 
103
112
  dialog.open()
104
113
 
@@ -112,22 +121,22 @@ export const twoFactorSetupDialog = (app: any): Promise<any> => {
112
121
  ;(codeInput as HTMLElement).addEventListener("keypress", (event: Event) => {
113
122
  if ((event as KeyboardEvent).key === "Enter") {
114
123
  event.preventDefault()
115
- ;(buttons[0] as any).click()
124
+ buttons[0].click!()
116
125
  }
117
126
  })
118
127
  }
119
128
  })
120
129
  }
121
130
 
122
- export const twoFactorDisableDialog = (app: any): any => {
123
- const buttons = [
131
+ export const twoFactorDisableDialog = (app: FrontendApp): any => {
132
+ const buttons: DialogButtonSpec[] = [
124
133
  {
125
134
  text: gettext("Disable 2FA"),
126
135
  classes: "fw-orange",
127
136
  click: () => {
128
137
  activateWait()
129
138
  app.apiConnectors.auth.twoFactorDisable()
130
- .then((json: any) => {
139
+ .then((json: TwoFactorVerifyResponse) => {
131
140
  if (json.status === "success") {
132
141
  addAlert("success", json.message)
133
142
  dialog.close()
@@ -156,7 +165,7 @@ export const twoFactorDisableDialog = (app: any): any => {
156
165
  body: `<p>${gettext("Are you sure you want to disable two-factor authentication? This will reduce the security of your account.")}</p>`,
157
166
  buttons,
158
167
  icon: "exclamation-triangle"
159
- } as any)
168
+ })
160
169
 
161
170
  dialog.open()
162
171
  return dialog
@@ -172,10 +181,10 @@ export const twoFactorLoginDialog = ({
172
181
  login: string
173
182
  password: string
174
183
  remember: boolean
175
- loginPage: any
176
- app: any
184
+ loginPage: LoginPage
185
+ app: FrontendApp
177
186
  }): any => {
178
- const buttons = [
187
+ const buttons: DialogButtonSpec[] = [
179
188
  {
180
189
  text: gettext("Verify"),
181
190
  classes: "fw-dark",
@@ -197,7 +206,7 @@ export const twoFactorLoginDialog = ({
197
206
  remember,
198
207
  twofactor
199
208
  })
200
- .then((json: any) => {
209
+ .then((json: TwoFactorVerifyResponse) => {
201
210
  deactivateWait()
202
211
  dialog.close()
203
212
  loginPage.afterLogin(json)
@@ -218,7 +227,7 @@ export const twoFactorLoginDialog = ({
218
227
  buttons,
219
228
  icon: "shield-alt",
220
229
  width: 500
221
- } as any)
230
+ })
222
231
 
223
232
  dialog.open()
224
233
  const codeInput = dialog.dialogEl.querySelector("#two-factor-code")
@@ -226,16 +235,16 @@ export const twoFactorLoginDialog = ({
226
235
  ;(codeInput as HTMLElement).addEventListener("keypress", (event: Event) => {
227
236
  if ((event as KeyboardEvent).key === "Enter") {
228
237
  event.preventDefault()
229
- buttons[0].click()
238
+ buttons[0].click!()
230
239
  }
231
240
  })
232
241
  }
233
242
  return dialog
234
243
  }
235
244
 
236
- export const checkTwoFactorStatus = (app: any): Promise<boolean> => {
245
+ export const checkTwoFactorStatus = (app: FrontendApp): Promise<boolean> => {
237
246
  return app.apiConnectors.auth.twoFactorStatus()
238
- .then((json: any) => {
247
+ .then((json: TwoFactorStatusResponse) => {
239
248
  if (json.status === "success") {
240
249
  return json.enabled
241
250
  }
@@ -3,11 +3,14 @@ import {addContactTemplate} from "./templates.js"
3
3
 
4
4
  export class AddContactDialog {
5
5
  settings: Record<string, unknown>
6
- app: any
6
+ contactsApi: {add(data: {user_string: string}): Promise<{json: unknown; status: number}>}
7
7
 
8
- constructor(settings: Record<string, unknown>, app: any) {
8
+ constructor(
9
+ settings: Record<string, unknown>,
10
+ contactsApi: {add(data: {user_string: string}): Promise<{json: unknown; status: number}>}
11
+ ) {
9
12
  this.settings = settings
10
- this.app = app
13
+ this.contactsApi = contactsApi
11
14
  }
12
15
 
13
16
  init(): Promise<Array<Record<string, unknown>>> {
@@ -78,7 +81,7 @@ export class AddContactDialog {
78
81
  return cancelPromise()
79
82
  }
80
83
 
81
- return this.app.apiConnectors.contacts.add({
84
+ return this.contactsApi.add({
82
85
  user_string: userString
83
86
  }).then(({json, status}: any) => {
84
87
  if (status == 201) {
@@ -1,10 +1,11 @@
1
1
  import {Dialog} from "fwtoolkit"
2
+ import type {FrontendApp} from "../../types.js"
2
3
 
3
4
  export class DeleteContactDialog {
4
5
  contacts: Array<Record<string, unknown>>
5
- app: any
6
+ app: FrontendApp
6
7
 
7
- constructor(contacts: Array<Record<string, unknown>>, app?: any) {
8
+ constructor(contacts: Array<Record<string, unknown>>, app: FrontendApp) {
8
9
  this.contacts = contacts
9
10
  this.app = app
10
11
  }
@@ -21,9 +21,19 @@ import {
21
21
  displayContactType,
22
22
  respondInviteCell
23
23
  } from "./templates.js"
24
+ import type {ContactsListResponse} from "../../api/index.js"
25
+ import type {FrontendApp} from "../../types.js"
26
+
27
+ export interface ContactsApp extends FrontendApp {
28
+ indexedDB: {
29
+ readAllData: (store: string) => Promise<Array<Record<string, unknown>>>
30
+ clearData: (store: string) => Promise<void>
31
+ insertData: (store: string, data: Array<Record<string, unknown>>) => Promise<void>
32
+ }
33
+ }
24
34
 
25
35
  export class ContactsOverview {
26
- app: any
36
+ app: ContactsApp
27
37
  user: Record<string, unknown>
28
38
  contacts: Array<Record<string, unknown>>
29
39
  lastSort: {column: number; dir: string}
@@ -33,7 +43,7 @@ export class ContactsOverview {
33
43
  dtBulk: any
34
44
  menu: any
35
45
 
36
- constructor({app, user}: {app: any; user: Record<string, unknown>}) {
46
+ constructor({app, user}: {app: ContactsApp; user: Record<string, unknown>}) {
37
47
  this.app = app
38
48
  this.user = user
39
49
  this.contacts = []
@@ -168,8 +178,8 @@ export class ContactsOverview {
168
178
  if (this.app.isOffline()) {
169
179
  return cachedPromise.then(() => {})
170
180
  }
171
- return (this.app as any).apiConnectors.contacts.list()
172
- .then((json: any) => {
181
+ return this.app.apiConnectors.contacts.list()
182
+ .then((json: ContactsListResponse) => {
173
183
  return cachedPromise.then(oldJson => {
174
184
  if (!deepEqual(json, oldJson)) {
175
185
  this.updateIndexedDB(json)
@@ -1,8 +1,11 @@
1
+ import type {ContactsInviteResponse} from "../../api/index.js"
2
+ import type {PreloginApp} from "../../prelogin/index.js"
3
+
1
4
  export class ContactInvite {
2
- app: any
5
+ app: PreloginApp
3
6
  key: string
4
7
 
5
- constructor({app}: {app: any}, key: string) {
8
+ constructor({app}: {app: PreloginApp}, key: string) {
6
9
  this.app = app
7
10
  this.key = key
8
11
  }
@@ -10,11 +13,12 @@ export class ContactInvite {
10
13
  init(): Promise<any> {
11
14
  if (!this.app.config.user.is_authenticated) {
12
15
  this.app.inviteKey = this.key
13
- this.app.page = this.app.openLoginPage()
14
- return this.app.page.init()
16
+ const loginPage = this.app.openLoginPage()
17
+ this.app.page = loginPage
18
+ return loginPage.init()
15
19
  }
16
20
 
17
- return this.app.apiConnectors.contacts.invite({key: this.key}).then((json: any) => {
21
+ return this.app.apiConnectors.contacts.invite({key: this.key}).then((json: ContactsInviteResponse) => {
18
22
  window.history.replaceState({}, "", json.redirect)
19
23
  return this.app.selectPage()
20
24
  })
@@ -37,7 +37,10 @@ export const menuModel = (): {content: Array<Record<string, unknown>>} => ({
37
37
  title: gettext("Invite contact"),
38
38
  keys: "Alt-i",
39
39
  action: (overview: any) => {
40
- const dialog = new AddContactDialog(overview.app.settings, overview.app)
40
+ const dialog = new AddContactDialog(
41
+ overview.app.settings,
42
+ overview.app.apiConnectors.contacts
43
+ )
41
44
  dialog.init().then((contacts: any) => {
42
45
  contacts.forEach((contact: any) => overview.contacts.push(contact))
43
46
  overview.initializeView()
@@ -1,18 +1,19 @@
1
1
  import {Dialog, escapeText} from "fwtoolkit"
2
+ import type {FrontendApp} from "../../types.js"
2
3
 
3
4
  export class RespondInviteDialog {
4
5
  invites: Array<Record<string, unknown>>
5
6
  addCallback: (contacts: Array<Record<string, unknown>>) => void
6
7
  deleteCallback: (invites: Array<Record<string, unknown>>) => void
7
8
  doneCallback: () => void
8
- app: any
9
+ app: FrontendApp
9
10
 
10
11
  constructor(
11
12
  invites: Array<Record<string, unknown>>,
12
13
  addCallback: (contacts: Array<Record<string, unknown>>) => void = () => {},
13
14
  deleteCallback: (invites: Array<Record<string, unknown>>) => void = () => {},
14
15
  doneCallback: () => void = () => {},
15
- app?: any
16
+ app: FrontendApp
16
17
  ) {
17
18
  this.invites = invites
18
19
  this.addCallback = addCallback
@@ -1,12 +1,13 @@
1
1
  import {Dialog, activateWait, addAlert, deactivateWait} from "fwtoolkit"
2
+ import type {FrontendApp} from "../../types.js"
2
3
  import {deleteUserDialogTemplate} from "./templates.js"
3
4
 
4
5
  export class DeleteUserDialog {
5
6
  username: string
6
- app: any
7
+ app: FrontendApp
7
8
  dialog: any
8
9
 
9
- constructor(username: string, app: any) {
10
+ constructor(username: string, app: FrontendApp) {
10
11
  this.username = username
11
12
  this.app = app
12
13
  }