@startsimpli/auth 0.4.20 → 0.4.22
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.
package/package.json
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { resolveAppHomeUrl, buildCentralAuthUrl } from '../utils/central-auth';
|
|
3
|
+
|
|
4
|
+
describe('resolveAppHomeUrl', () => {
|
|
5
|
+
it('maps known app slugs to their home URL', () => {
|
|
6
|
+
expect(resolveAppHomeUrl('present')).toBe('https://present.startsimpli.com');
|
|
7
|
+
expect(resolveAppHomeUrl('market')).toBe('https://market.startsimpli.com');
|
|
8
|
+
expect(resolveAppHomeUrl('raise')).toBe('https://app.raisesimpli.com');
|
|
9
|
+
expect(resolveAppHomeUrl('crochet')).toBe('https://crochets.site');
|
|
10
|
+
});
|
|
11
|
+
it('defaults unknown slugs to a startsimpli.com subdomain (never off-platform)', () => {
|
|
12
|
+
expect(resolveAppHomeUrl('whatever')).toBe('https://whatever.startsimpli.com');
|
|
13
|
+
expect(resolveAppHomeUrl('EVIL')).toBe('https://evil.startsimpli.com');
|
|
14
|
+
});
|
|
15
|
+
it('returns null for empty input', () => {
|
|
16
|
+
expect(resolveAppHomeUrl(null)).toBeNull();
|
|
17
|
+
expect(resolveAppHomeUrl(undefined)).toBeNull();
|
|
18
|
+
expect(resolveAppHomeUrl(' ')).toBeNull();
|
|
19
|
+
});
|
|
20
|
+
it('buildCentralAuthUrl still preserves app + return_to', () => {
|
|
21
|
+
const u = buildCentralAuthUrl('signin', { app: 'present', returnTo: 'https://present.startsimpli.com/x' });
|
|
22
|
+
expect(u).toContain('app=present');
|
|
23
|
+
expect(u).toContain('return_to=');
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -39,6 +39,35 @@ export function resolveCentralAuthHost(): string {
|
|
|
39
39
|
return DEFAULT_CENTRAL_AUTH_HOST;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Known app slug → production home URL. Most apps live at
|
|
44
|
+
* `<slug>.startsimpli.com`; the exceptions (different registrable domains) are
|
|
45
|
+
* listed explicitly. Used to bounce a user to the right app after an auth flow
|
|
46
|
+
* when no explicit `return_to` was supplied (e.g. `/signin?app=present`).
|
|
47
|
+
*/
|
|
48
|
+
const APP_HOME_URLS: Record<string, string> = {
|
|
49
|
+
market: 'https://market.startsimpli.com',
|
|
50
|
+
trade: 'https://trade.startsimpli.com',
|
|
51
|
+
present: 'https://present.startsimpli.com',
|
|
52
|
+
vault: 'https://vault.startsimpli.com',
|
|
53
|
+
raise: 'https://app.raisesimpli.com',
|
|
54
|
+
recipe: 'https://recipesimpli.com',
|
|
55
|
+
crochet: 'https://crochets.site',
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Resolve an app slug to its production home URL. Falls back to
|
|
60
|
+
* `https://<slug>.startsimpli.com` for any unregistered slug — always a
|
|
61
|
+
* startsimpli.com subdomain, so a bad `?app=` value can't redirect off-platform.
|
|
62
|
+
* Returns null for empty input.
|
|
63
|
+
*/
|
|
64
|
+
export function resolveAppHomeUrl(app: string | null | undefined): string | null {
|
|
65
|
+
if (!app) return null;
|
|
66
|
+
const slug = app.trim().toLowerCase();
|
|
67
|
+
if (!slug) return null;
|
|
68
|
+
return APP_HOME_URLS[slug] ?? `https://${slug}.startsimpli.com`;
|
|
69
|
+
}
|
|
70
|
+
|
|
42
71
|
export interface BuildCentralAuthUrlOptions {
|
|
43
72
|
/** Slug identifying the calling app (e.g. `vault`, `raise`, `market`). */
|
|
44
73
|
app: string;
|