fxa/packages/fxa-shared
Barry Chen 58d8ca9bb0
Merge pull request #16458 from mozilla/FXA-9101-redis-password
chore(redis): add password config for oauth redis
2024-02-22 13:15:56 -06:00
..
.vscode chore(multiple): update mocha wherever used 2022-06-28 09:03:42 -07:00
auth Cherry pick squash for experimental dot releases v1.226.5 to v1.226.9 on train-226. These changes address issues with connection pool spiking and high latency on the attached clients route. 2022-03-18 10:33:35 -07:00
cache Cherry pick squash for experimental dot releases v1.226.5 to v1.226.9 on train-226. These changes address issues with connection pool spiking and high latency on the attached clients route. 2022-03-18 10:33:35 -07:00
configuration fix(content): Allow list valid redirect_to values 2022-06-15 18:09:03 -07:00
connected-services feat(libs): move fxa-shared/l10n to libs/shared/l10n 2023-10-04 16:08:01 -04:00
db chore(redis): add password config for oauth redis 2024-02-21 13:43:07 -06:00
dto/auth/payments feat(payments): update PlanUpgradeDetails content 2023-07-18 13:49:22 -04:00
email fix(email): Disable using Relay masks to create an account or secondary email 2024-02-05 11:19:45 -05:00
experiments chore(build): initial nx implementation 2023-05-23 08:37:47 -07:00
express task(settings): Create tests for signup container component 2023-11-22 11:25:42 -08:00
feature-flags chore(fxa-shared): removed exported redis from fxa-shared 2021-06-25 11:06:15 -07:00
guards task(admin-panel): Unsubcribe users from newsletters 2022-11-03 15:11:23 -07:00
l10n fix(l10n): Ensure Settings and Payments are displayed RTL for RTL locales 2023-10-23 13:12:19 -07:00
lib task(all): Add support for sentry performance monitoring 2023-12-19 16:05:05 -08:00
log Cherry pick squash for experimental dot releases v1.226.5 to v1.226.9 on train-226. These changes address issues with connection pool spiking and high latency on the attached clients route. 2022-03-18 10:33:35 -07:00
metrics refactor(sync): Remove 'Looking for Firefox Sync?' link from home page 2024-01-18 14:51:13 -06:00
monitoring task(all): Add support for sentry performance monitoring 2023-12-19 16:05:05 -08:00
nestjs task(shared): Remove unused imports 2024-01-03 10:54:56 -08:00
oauth chore(typescript): convert more of fxa-shared to TS 2022-11-30 17:31:23 -06:00
payments feat(auth): partial firestore cleanup script 2024-02-07 11:22:16 -05:00
scripts task(ci): Remove redis dev password from source 2023-11-03 14:24:07 -07:00
sentry bug(shared): Handle exception in email pii filter 2024-02-01 10:56:58 -08:00
speed-trap fix(content): Make sure startTime is an integer 2023-07-19 09:57:18 -07:00
subscriptions refactor(payments): Utilize new plan-eligibility endpoint 2023-11-21 19:51:11 -05:00
test feat(auth): Add atLeast18AtReg value to account 2024-01-22 22:13:41 -08:00
tracing task(all): Add support for sentry performance monitoring 2023-12-19 16:05:05 -08:00
.eslintignore task(monorepo): eslint consolidation 2019-11-15 23:24:09 +00:00
.eslintrc chore(build): initial nx implementation 2023-05-23 08:37:47 -07:00
.nsprc chore(deps): updated fxa-shared deps and added vuln exception for minimist 2020-03-17 19:56:00 -07:00
.prettierignore chore(ts): prepare fxa-shared for conversion to typescript 2019-08-19 14:15:32 -07:00
README.md task(all): Add support for sentry performance monitoring 2023-12-19 16:05:05 -08:00
index.ts feat(libs): move fxa-shared/l10n to libs/shared/l10n 2023-10-04 16:08:01 -04:00
package.json bump ip from 1.1.8 to 2.0.1 2024-02-22 15:57:18 +00:00
pm2.config.js task(CI): Improve nx caching for CI pipelines 2023-08-29 11:19:54 -07:00
tsconfig.base.json feat: add foundational db classes 2023-07-24 14:44:12 -04:00
tsconfig.cjs.json chore(deps): upgrade react-scripts and webpack to v5 2023-07-11 13:32:40 -05:00
tsconfig.json chore(deps): upgrade react-scripts and webpack to v5 2023-07-11 13:32:40 -05:00

README.md

Shared module for FxA repositories

Shared modules

Dual Package

Note that this is a dual package. The impetus for it was Webpack 5 compat. (And we'd want to move to all-ESM eventually.) But CommonJS was kept for backwards compatibility until we can be certain of its removal.

l10n

supportedLanguages.json is the shared list of all supported locales across FxA

oauth

oauth.scopes provides shared logic for validating and checking OAuth scopes.

Detailed documentation on the details of FxA OAuth scope values is available from the fxa-oauth-server. This library provides some convenient APIs for working with them according to the rules described there.

Given a string containing scopes, you can parse it into a ScopeSet object from either a raw space-delimited string:

let s1 = oauth.scopes.fromString('profile:write basket');

Or directly from a url-encoded string:

let s2 = oauth.scopes.fromURLEncodedString('profile%3Aemail+profile%3Adisplay_name+clients');

Once you have a ScopeSet object, you can check whether it is sufficient to wholly imply another set:

  s1.contains('profile:email:write');          // true, implied by 'profile:write'
  s2.contains('profile:email:write');          // false
  s1.contains('profile:email:write clients');  // false, 'clients' is not in `s1`

Or whether it has any scope values in common with another set:

  s1.intersects('profile:email:write clients'); // true, 'profile:email:write' is common
  s2.intersects(s1);                            // true, 'profile:email' is common
  s2.intersects('clients:write basket');        // false, no members in common

You can filter it down to only the scope values implied by another scope:

  let s3 = oauth.scope.fromString('profile:email clients:abcd'));
  s3.filtered(s1); // 'profile:email'
  s3.filtered(s2); // 'profile:email clients:abcd'

Or you can find out what values in the set are not implied by another scope:

  s3.difference(s1); // 'clients:abcd'
  s3.difference(s2); // the empty set
  s2.difference(s3); // 'profile:display_name clients'

You can also combine multiple sets of scopes, either by generating the union as a new set:

  s1.union(s2); // 'profile:write basket clients'

Or by building up the new set in place:

  let allScopes = scopes.fromArray([]);
  allScopes.add(s1);  // now "profile:write basket"
  allScopes.add(s2);  // now "profile:write basket clients"
  allScopes.add(s3);  // now "profile:write basket clients"

tracing

This utility allows for easy configuration of tracing. To use this in a service:

  • Add the config chunk in fxa-shared/tracing/config to your packages's config.

  • Then initialize as follows. This invocation should happen as early as possible in the service's or app's lifecycle. Ideally it's the first thing done, even before importing other modules.

// For services
const config = require('../config');
require('fxa-shared/tracing/node-tracing').initTracing(config.get('tracing'));

To see traces on your local system, set the following environment variables:

# Capture all traces
TRACING_SAMPLE_RATE=1

# Send traces to console (optional, it's nice to see it working but noisy...)
TRACING_CONSOLE_EXPORTER_ENABLED=true

# Send traces to the otel service
TRACING_OTEL_EXPORTER_ENABLED=true

# Enable the otel collector service and instruct it to export traces to jaeger
TRACING_OTEL_COLLECTOR_ENABLED=true
TRACING_OTEL_COLLECTOR_JAEGER_ENABLED=true

The default config for tracing found at fxa-shared/tracing/config.ts will pick up these variables and result in traces showing up in Jaeger which runs locally at localhost:16686.

It's important to note that sentry also supports tracing integration. So we typically let a call to 'initSentry', a function located in the sentry/node.ts module do the work of initializing tracing.

Used by:

Testing

This package uses Mocha to test its code. By default npm test will first lint the code and then test all files ending under test/, and uses esbuild-register so it can process TypeScript files.

Test specific tests with the following commands:

# Test only test/oauth/scopes.js
npx mocha -r esbuild-register test/oauth/scopes.js

# Grep for "invalid scope values"
npx mocha -r esbuild-register -g "invalid scope values" --recursive test

Refer to Mocha's CLI documentation for more advanced test configuration.