@nebulr-group/bridge-svelte 1.0.0-alpha.13 → 1.0.0-alpha.14

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/dist/bootstrap.js CHANGED
@@ -48,18 +48,33 @@ function followLink(config, url) {
48
48
  return;
49
49
  redirect(307, `${page}${hash}`);
50
50
  }
51
+ /**
52
+ * Whether the workspace is locked for payment, asked when the app's active flag is off. The flag is off both for a
53
+ * workspace with no plan and for one that is locked; only the first goes to the paywall. The flag can turn off before
54
+ * the lock held for the page is read again, so the lock is read now rather than taken from what is held.
55
+ */
56
+ async function lockedNow(client) {
57
+ if (client.isLocked())
58
+ return true;
59
+ const facts = await within(client.billing.gate(), READY_WAIT_MS);
60
+ return facts?.access === 'blocked';
61
+ }
51
62
  async function guard(client, config, url) {
52
63
  await within(client.ready, READY_WAIT_MS);
53
64
  const flagsNeeded = authPageAt(normalizePath(url.pathname), config.authBase) === null;
54
65
  if (flagsNeeded && get(client.flags.status) !== 'ready')
55
66
  await within(client.flags.load(), READY_WAIT_MS);
56
- return decide(config, {
67
+ const input = {
57
68
  path: url.pathname,
58
69
  target: `${normalizePath(url.pathname)}${url.search}`,
59
70
  session: client.session.get(),
60
71
  flags: client.flags,
61
72
  returnTo: readReturnTo(url, config.returnToParam),
62
- });
73
+ };
74
+ const decision = decide(config, input);
75
+ if (decision.type !== 'redirect' || decision.reason !== 'paywall')
76
+ return decision;
77
+ return (await lockedNow(client)) ? decide(config, { ...input, locked: true }) : decision;
63
78
  }
64
79
  /**
65
80
  * Makes the root layout's load function. Set `export const ssr = false`
@@ -6,6 +6,10 @@
6
6
  *
7
7
  * It fails closed: while Bridge cannot be reached, a protected page sends
8
8
  * the visitor to sign-in, and a flag that has no result is off.
9
+ *
10
+ * The paywall is for a workspace that has no plan yet. A workspace locked for
11
+ * payment keeps its page: it can still be read, and the lock screen covers it
12
+ * where the person is (`<BillingNotice mode="hard">`), as in 0.9.
9
13
  */
10
14
  import { type SessionState } from '@nebulr-group/bridge-auth-core';
11
15
  import type { FlagRequirement, ResolvedConfig, RouteRule } from './config.js';
@@ -46,6 +50,8 @@ export interface GuardInput {
46
50
  readonly flags: FlagReader;
47
51
  /** The return address already on the URL, on an auth page. */
48
52
  readonly returnTo: string | null;
53
+ /** Whether the workspace is locked for payment: then the page stays and shows the lock, rather than the paywall. */
54
+ readonly locked?: boolean;
49
55
  }
50
56
  /** Decides one navigation. */
51
57
  export declare function decide(config: ResolvedConfig, given: GuardInput): GuardDecision;
@@ -6,6 +6,10 @@
6
6
  *
7
7
  * It fails closed: while Bridge cannot be reached, a protected page sends
8
8
  * the visitor to sign-in, and a flag that has no result is off.
9
+ *
10
+ * The paywall is for a workspace that has no plan yet. A workspace locked for
11
+ * payment keeps its page: it can still be read, and the lock screen covers it
12
+ * where the person is (`<BillingNotice mode="hard">`), as in 0.9.
9
13
  */
10
14
  import { sanitizeReturnTo, withReturnTo } from '@nebulr-group/bridge-auth-core';
11
15
  import { authPageAt, isUnder } from './routes.js';
@@ -78,7 +82,7 @@ export function decide(config, given) {
78
82
  return { type: 'redirect', to, reason: 'flag' };
79
83
  }
80
84
  const billingPage = isUnder(input.path, config.billingBase);
81
- if (signedIn && !isPublic && !billingPage && config.paywall !== null && !input.flags.enabled(config.flagKeys.appActive)) {
85
+ if (signedIn && !isPublic && !billingPage && config.paywall !== null && input.locked !== true && !input.flags.enabled(config.flagKeys.appActive)) {
82
86
  if (config.paywall === input.path)
83
87
  return { type: 'allow' };
84
88
  return { type: 'redirect', to: withReturnTo(config.paywall, input.target, config.returnToParam), reason: 'paywall' };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nebulr-group/bridge-svelte",
3
- "version": "1.0.0-alpha.13",
3
+ "version": "1.0.0-alpha.14",
4
4
  "description": "The Bridge for SvelteKit: sign-in in your own pages, workspaces, flag-based route guards, plans and checkout, the team panel and live updates, on one setting: the issuer.",
5
5
  "author": "Iman Pouya",
6
6
  "license": "MIT",
@@ -60,7 +60,7 @@
60
60
  "@sveltejs/kit": "^2.0.0"
61
61
  },
62
62
  "dependencies": {
63
- "@nebulr-group/bridge-auth-core": "1.0.0-alpha.11"
63
+ "@nebulr-group/bridge-auth-core": "1.0.0-alpha.12"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@sveltejs/kit": "^2.16.0",