• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / blurts-server / #13312

pending completion
#13312

push

circleci

jswinarton
MNTOR-1385 Basic backend flow for Premium featureset

Add the backend elements necessary to run the basic Premium subscription flow.

Some important notes:

    This creates two new routes, /oauth/premium/upgrade and /oauth/premium/confirmed, which drive the flow. They are not real views but are responsible for redirects and validation.
    The whole feature is behind a feature flag. Set FXA_SUBSCRIPTION_ENABLED=1 in your .env to enable.

282 of 1774 branches covered (15.9%)

Branch coverage included in aggregate %.

22 of 22 new or added lines in 4 files covered. (100.0%)

959 of 4683 relevant lines covered (20.48%)

1.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/views/mainLayout.js
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4

5
import AppConstants from '../appConstants.js'
6
import { getMessage, getLocale } from '../utils/fluent.js'
7
import { isSubscribed } from '../utils/subscriber.js'
8

9
/**
10
 * @type {ViewPartial<MainViewPartialData<any>>}
11
 */
12
const mainLayout = data => `
×
13
<!doctype html>
14
<html lang=${getLocale()}>
15
  <head>
16
    <title>${getMessage('brand-fx-monitor')}</title>
17
    <style>html {display: none;}</style>
18

19
    <meta charset='utf-8'>
20
    <meta name='viewport' content='width=320, initial-scale=1'>
21
    <meta name='description' content='${getMessage('meta-desc')}'>
22
    <meta name='twitter:card' content='summary_large_image'>
23
    <meta name='twitter:title' content='${getMessage('brand-fx-monitor')}'>
24
    <meta name='twitter:description' content='${getMessage('meta-desc')}'>
25
    <meta name='twitter:image' content='${AppConstants.SERVER_URL}/images/og-image.webp'>
26
    <meta property='og:title' content='${getMessage('brand-fx-monitor')}'>
27
    <meta property='og:description' content='${getMessage('meta-desc')}'>
28
    <meta property='og:site_name' content='${getMessage('brand-fx-monitor')}'>
29
    <meta property='og:type' content='website'>
30
    <meta property='og:url' content='${AppConstants.SERVER_URL}'>
31
    <meta property='og:image' content='${AppConstants.SERVER_URL}/images/og-image.webp'>
32

33
    <link rel='preload' href='/fonts/Metropolis-Bold.woff2' as='font' type='font/woff2' crossorigin>
34
    <link rel='preload' href='/fonts/Inter-Regular-latin.woff2' as='font' type='font/woff2' crossorigin>
35
    <link rel='stylesheet' href='/css/index.css' type='text/css'>
36
    <link rel='stylesheet' href='/css/partials/${data.partial.name}.css' type='text/css'>
37
    <link rel='icon' href='/images/favicon-16.webp' sizes='16x16'>
38
    <link rel='icon' href='/images/favicon-32.webp' sizes='32x32'>
39
    <link rel='icon' href='/images/favicon-48.webp' sizes='48x48'>
40
    <link rel='icon' href='/images/favicon-96.webp' sizes='96x96'>
41
    <link rel='icon' href='/images/favicon-144.webp' sizes='144x144'>
42
    <link rel='icon' href='/images/favicon-256.webp' sizes='256x256'>
43
    <link rel='apple-touch-icon' href='/images/apple-touch-icon.webp' sizes='180x180'>
44

45
    <script src='/js/index.js' type='module'></script>
46
    ${data.skipPartialModule ? '' : `<script src='/js/partials/${data.partial.name}.js' type='module'></script>`}
×
47
  </head>
48
  <body>
49
    <header>
50
      <a href='/user/breaches'>
51
        <img class='monitor-logo' srcset='/images/monitor-logo-transparent.webp 213w, /images/monitor-logo-transparent@2x.webp 425w' width='213' height='33' alt='${getMessage('brand-fx-monitor')}'>
52
      </a>
53
      <div class='nav-wrapper'>
54
        <button class='nav-toggle'>
55
          <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 8' width='20'>
56
            <path d='M1 1h8M1 4h8M1 7h8' stroke='#000' stroke-width='1' stroke-linecap='round'/>
57
          </svg>
58
        </button>
59
        ${userMenu(data)}
60
      </div>
61
    </header>
62

63
    <nav class='site-nav'>
64
      <div class='pages-nav'>
65
        <a href='/user/breaches' class='nav-item ${data.partial.name === 'breaches' ? 'current' : ''}'>
×
66
          <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
67
            <path fill-rule="evenodd" clip-rule="evenodd" d="M10.5942 20.049C9.87439 21.3816 10.8394 22.9996 12.3539 22.9996H19.657C21.1692 22.9996 22.1344 21.3862 21.4193 20.0538L17.7796 13.2724C17.0264 11.8689 15.0148 11.8662 14.2577 13.2676L10.5942 20.049Z" fill="white" stroke="currentcolor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
68
            <path fill-rule="evenodd" clip-rule="evenodd" d="M16 21C16.5523 21 17 20.5523 17 20C17 19.4477 16.5523 19 16 19C15.4477 19 15 19.4477 15 20C15 20.5523 15.4477 21 16 21Z" fill="currentcolor"/>
69
            <path d="M16 17V16" stroke="currentcolor" stroke-width="2" stroke-linecap="round"/>
70
            <path d="M7 22H5C3.89543 22 3 21.1046 3 20V11C3 9.89543 3.89543 9 5 9H19C20.1046 9 21 9.89543 21 11V13" stroke="currentcolor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
71
            <path d="M7 9V7C7 4.23858 9.23858 2 12 2C14.7614 2 17 4.23858 17 7V9" stroke="currentcolor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
72
          </svg>
73
          ${getMessage('site-nav-breaches-link')}
74
        </a>
75
      </div>
76
      <div class='meta-nav'>
77
        <a href='/user/settings' class='nav-item ${data.partial.name === 'settings' ? 'current' : ''}'>
×
78
          ${getMessage('site-nav-settings-link')}
79
        </a>
80
        <a target="_blank" href='https://support.mozilla.org/kb/firefox-monitor' class='nav-item'>
81
          ${getMessage('site-nav-help-link')}
82
        </a>
83
      </div>
84
      <div class='callouts'>
85
        <p>${getMessage('site-nav-ad-callout')}</p>
86
        <a href='https://relay.firefox.com/?utm_medium=mozilla-websites&utm_source=monitor&utm_campaign=&utm_content=nav-bar-global' target='_blank'><img src='/images/logo-relay.svg' width='416' height='92' alt='${getMessage('brand-relay')}'></a>
87
        <a href='https://www.mozilla.org/products/vpn?utm_medium=mozilla-websites&utm_source=monitor&utm_campaign=&utm_content=nav-bar-global' target='_blank'><img src='/images/logo-vpn.svg' width='232' height='48' alt='${getMessage('brand-mozilla-vpn')}'></a>
88
      </div>
89
    </nav>
90

91
    <main data-partial='${data.partial.name}'>
92
      ${data.partial(data)}
93
    </main>
94
    <footer class='site-footer'>
95
      <a href='https://www.mozilla.org' target='_blank'>
96
        <img src='/images/moz-logo-1color-white-rgb-01.svg' width='100' height='29' loading='lazy' alt='${getMessage('mozilla')}'>
97
      </a>
98
      <menu>
99
        <li><a href='/breaches'>${getMessage('footer-nav-all-breaches')}</a></li>
100
        <li><a href='https://support.mozilla.org/kb/firefox-monitor-faq' target='_blank'>FAQ</a></li>
101
        <li><a href='https://www.mozilla.org/privacy/firefox-monitor' target='_blank'>${getMessage('terms-and-privacy')}</a></li>
102
        <li><a href='https://github.com/mozilla/blurts-server' target='_blank'>${getMessage('github')}</a></li>
103
      </menu>
104
    </footer>
105
  </body>
106
</html>
107
`
108

109
/**
110
 * @type {ViewPartial<MainViewPartialData>}
111
 */
112
const userMenu = data => `
×
113
<div class='user-menu-wrapper' tabindex='-1'>
114
  ${premiumButton(data)}
115
  <button
116
    aria-expanded='false'
117
    aria-haspopup='true'
118
    class='user-menu-button'
119
    title='${getMessage('menu-button-title')}'
120
  >
121
    <img src='${data.fxaProfile?.avatar}' alt='${getMessage('menu-button-alt')}' />
122
  </button>
123
  <menu
124
    aria-label='${getMessage('menu-list-accessible-label')}'
125
    class='user-menu-container user-menu-popover'
126
    role='navigation'
127
    hidden
128
  >
129
    <li tabindex='1'>
130
      <a href='${AppConstants.FXA_SETTINGS_URL}' target='_blank' class='user-menu-header'>
131
        <b class='user-menu-email'>${data.fxaProfile?.email}</b>
132
        <div class='user-menu-subtitle'>
133
          ${getMessage('menu-item-fxa')}
134
          <img src='/images/icon-open-in.svg' />
135
        </div>
136
      </a>
137
    </li>
138
    <hr>
139
    <li>
140
      <a href='/user/settings' class='user-menu-link'>
141
        <img src='/images/icon-settings.svg' />
142
        ${getMessage('menu-item-settings')}
143
      </a>
144
    </li>
145
    <li>
146
      <a href='https://support.mozilla.org/kb/firefox-monitor' target='_blank' class='user-menu-link'>
147
        <img src='/images/icon-help.svg' />
148
        ${getMessage('menu-item-help')}
149
      </a>
150
    </li>
151
    <li>
152
      <a href='/user/logout' class='user-menu-link'>
153
        <img src='/images/icon-signout.svg' />
154
        ${getMessage('menu-item-logout')}
155
      </a>
156
    </li>
157
  </menu>
158
</div>
159
`
160

161
/**
162
 * @type {ViewPartial<MainViewPartialData>}
163
 */
164
const premiumButton = data => {
×
165
  if (!AppConstants.FXA_SUBSCRIPTION_ENABLED) { return '' }
×
166

167
  if (isSubscribed(data.fxaProfile)) {
×
168
    return 'Premium subscriber'
×
169
  }
170
  return '<a href="/oauth/premium/upgrade">Upgrade to Premium</a>'
×
171
}
172

173
export { mainLayout }
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc