@pylonsync/sdk 0.3.8 → 0.3.10

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +91 -0
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.3.8",
6
+ "version": "0.3.10",
7
7
  "type": "module",
8
8
  "main": "src/index.ts",
9
9
  "types": "src/index.ts",
package/src/index.ts CHANGED
@@ -367,6 +367,7 @@ export interface AppManifest {
367
367
  queries: ManifestQuery[];
368
368
  actions: ManifestAction[];
369
369
  policies: ManifestPolicy[];
370
+ auth?: ManifestAuthConfig;
370
371
  }
371
372
 
372
373
  export function entitiesToManifest(
@@ -481,6 +482,94 @@ export function policiesToManifest(
481
482
  });
482
483
  }
483
484
 
485
+ /**
486
+ * Auth configuration block for the manifest. Mirrors better-auth's
487
+ * `betterAuth({ user, session, trustedOrigins })` shape.
488
+ *
489
+ * All fields optional with sensible defaults — apps that don't pass
490
+ * an `auth({...})` block to `buildManifest` get the framework defaults
491
+ * (User entity named "User", strip `passwordHash`, 30-day sessions,
492
+ * no cookie cache, trusted origins from `PYLON_TRUSTED_ORIGINS` env).
493
+ *
494
+ * @example
495
+ * auth({
496
+ * user: {
497
+ * entity: "User",
498
+ * expose: ["id", "email", "displayName"],
499
+ * hide: ["passwordHash", "internalNotes"],
500
+ * },
501
+ * session: { expiresIn: 60 * 60 * 24 * 7 }, // 7 days
502
+ * trustedOrigins: ["https://app.example.com"],
503
+ * })
504
+ */
505
+ export type AuthConfig = {
506
+ user?: {
507
+ /** Manifest entity name pylon treats as the User table. Default `"User"`. */
508
+ entity?: string;
509
+ /** Allowlist of fields exposed via `/api/auth/session`. Empty = all (minus hide list). */
510
+ expose?: string[];
511
+ /** Additional fields stripped (combined with default `passwordHash` + `_*`). */
512
+ hide?: string[];
513
+ };
514
+ session?: {
515
+ /** New session lifetime in seconds. Default 30 days. */
516
+ expiresIn?: number;
517
+ /** Cookie cache config — bake claims into the cookie so reads avoid the DB. */
518
+ cookieCache?: {
519
+ enabled?: boolean;
520
+ /** Max staleness in seconds. Default 5 minutes. */
521
+ maxAge?: number;
522
+ /** Auth-context fields baked into the cookie envelope (always includes `user_id`). */
523
+ claims?: string[];
524
+ };
525
+ };
526
+ /** Per-app trusted origins for OAuth `?callback=` validation. Merged with `PYLON_TRUSTED_ORIGINS` env. */
527
+ trustedOrigins?: string[];
528
+ };
529
+
530
+ export type ManifestAuthConfig = {
531
+ user: {
532
+ entity: string;
533
+ expose: string[];
534
+ hide: string[];
535
+ };
536
+ session: {
537
+ expires_in: number;
538
+ cookie_cache: {
539
+ enabled: boolean;
540
+ max_age: number;
541
+ claims: string[];
542
+ };
543
+ };
544
+ trusted_origins: string[];
545
+ };
546
+
547
+ /**
548
+ * Build the manifest's `auth` block from the user-facing camelCase
549
+ * config. Translates to the snake_case shape the Rust runtime expects.
550
+ *
551
+ * Defaults match `pylon_kernel::ManifestAuthConfig::default()` so
552
+ * passing nothing is equivalent to omitting the `auth({...})` call.
553
+ */
554
+ export function auth(cfg: AuthConfig = {}): ManifestAuthConfig {
555
+ return {
556
+ user: {
557
+ entity: cfg.user?.entity ?? "User",
558
+ expose: cfg.user?.expose ?? [],
559
+ hide: cfg.user?.hide ?? [],
560
+ },
561
+ session: {
562
+ expires_in: cfg.session?.expiresIn ?? 30 * 24 * 60 * 60,
563
+ cookie_cache: {
564
+ enabled: cfg.session?.cookieCache?.enabled ?? false,
565
+ max_age: cfg.session?.cookieCache?.maxAge ?? 5 * 60,
566
+ claims: cfg.session?.cookieCache?.claims ?? ["is_admin", "tenant_id"],
567
+ },
568
+ },
569
+ trusted_origins: cfg.trustedOrigins ?? [],
570
+ };
571
+ }
572
+
484
573
  export function buildManifest(options: {
485
574
  name: string;
486
575
  version: string;
@@ -489,6 +578,7 @@ export function buildManifest(options: {
489
578
  queries?: QueryDefinition[];
490
579
  actions?: ActionDefinition[];
491
580
  policies?: PolicyDefinition[];
581
+ auth?: ManifestAuthConfig;
492
582
  }): AppManifest {
493
583
  return {
494
584
  manifest_version: MANIFEST_VERSION,
@@ -499,5 +589,6 @@ export function buildManifest(options: {
499
589
  queries: queriesToManifest(options.queries ?? []),
500
590
  actions: actionsToManifest(options.actions ?? []),
501
591
  policies: policiesToManifest(options.policies ?? []),
592
+ auth: options.auth ?? auth(),
502
593
  };
503
594
  }