favalib 0.0.15 → 0.0.16

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.
@@ -2,11 +2,14 @@ import type { LiteralUnion } from 'type-fest';
2
2
  import type { Tagged } from 'type-fest';
3
3
  export type EntryId = Tagged<string, 'TotpId'>;
4
4
  export type EntryType = LiteralUnion<'TOTP', string>;
5
+ export type MatchType = 'BaseDomain';
5
6
  export interface EntryMeta {
6
7
  id: EntryId;
7
8
  name: string;
8
9
  issuer: string;
9
10
  type: EntryType;
11
+ match: string | null;
12
+ matchType: MatchType | null;
10
13
  addedAt: number;
11
14
  updatedAt: number | null;
12
15
  }
@@ -7,6 +7,8 @@ const getMetaForEntry = (entry) => ({
7
7
  name: entry.name,
8
8
  issuer: entry.issuer,
9
9
  type: entry.type,
10
+ match: entry.match,
11
+ matchType: entry.matchType,
10
12
  addedAt: entry.addedAt,
11
13
  updatedAt: entry.updatedAt,
12
14
  });
@@ -50,6 +50,8 @@ export const parseOtpUri = (UrlParser, otpUri) => {
50
50
  const algorithm = parseOtpAlgorithm(searchParams.get('algorithm'));
51
51
  const digits = parseInt(searchParams.get('digits') ?? '6', 10);
52
52
  const period = parseInt(searchParams.get('period') ?? '30', 10);
53
+ const match = searchParams.get('match');
54
+ const matchType = searchParams.get('matchType');
53
55
  // if searchParams has an issuer, use that
54
56
  if (searchParams.get('issuer')) {
55
57
  if (!name) {
@@ -68,6 +70,8 @@ export const parseOtpUri = (UrlParser, otpUri) => {
68
70
  name: name && name.length > 0 ? name : 'Imported Entry',
69
71
  issuer: issuer && issuer.length > 0 ? issuer : 'Unknown Issuer',
70
72
  type: 'TOTP',
73
+ match: match ?? null,
74
+ matchType: matchType ?? null,
71
75
  payload: {
72
76
  secret,
73
77
  algorithm,
@@ -77,9 +81,20 @@ export const parseOtpUri = (UrlParser, otpUri) => {
77
81
  };
78
82
  };
79
83
  const generateOtpUrl = (entry) => {
80
- const { name, issuer, payload } = entry;
84
+ const { name, issuer, payload, match, matchType } = entry;
81
85
  const { secret, algorithm, digits, period } = payload;
82
- return `otpauth://totp/${encodeURIComponent(issuer)}:${encodeURIComponent(name)}?secret=${secret}&issuer=${encodeURIComponent(issuer)}&algorithm=${algorithm}&digits=${digits}&period=${period}`;
86
+ // Note: Using manual encodeURIComponent instead of URLSearchParams because
87
+ // URLSearchParams encodes spaces as '+' while encodeURIComponent uses '%20'.
88
+ // OTP clients expect standard percent encoding (%20) for better compatibility.
89
+ let url = `otpauth://totp/${encodeURIComponent(issuer)}:${encodeURIComponent(name)}?secret=${secret}&issuer=${encodeURIComponent(issuer)}&algorithm=${algorithm}&digits=${digits}&period=${period}`;
90
+ // Add match properties if they exist
91
+ if (match !== null && match !== undefined) {
92
+ url += `&match=${encodeURIComponent(match)}`;
93
+ }
94
+ if (matchType !== null && matchType !== undefined) {
95
+ url += `&matchType=${encodeURIComponent(matchType)}`;
96
+ }
97
+ return url;
83
98
  };
84
99
  /**
85
100
  * Generates an HTML page with QR codes for the provided OTP entries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "favalib",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {