postgresdk 0.1.2-alpha.2 → 0.1.2-alpha.3

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/README.md CHANGED
@@ -348,7 +348,23 @@ export default {
348
348
  ### API Key Authentication
349
349
 
350
350
  ```typescript
351
- // postgresdk.config.ts
351
+ // postgresdk.config.ts - Simplified syntax
352
+ export default {
353
+ connectionString: "...",
354
+ auth: {
355
+ apiKey: "your-api-key" // Single key shorthand
356
+ }
357
+ };
358
+
359
+ // Or multiple keys
360
+ export default {
361
+ connectionString: "...",
362
+ auth: {
363
+ apiKeys: ["key1", "key2", "key3"]
364
+ }
365
+ };
366
+
367
+ // Or full syntax with custom header
352
368
  export default {
353
369
  connectionString: "...",
354
370
  auth: {
@@ -373,7 +389,15 @@ const sdk = new SDK({
373
389
  ### JWT Authentication (HS256)
374
390
 
375
391
  ```typescript
376
- // postgresdk.config.ts
392
+ // postgresdk.config.ts - Simplified syntax
393
+ export default {
394
+ connectionString: "...",
395
+ auth: {
396
+ jwt: "your-secret-key" // Shared secret shorthand
397
+ }
398
+ };
399
+
400
+ // Or full syntax with issuer/audience validation
377
401
  export default {
378
402
  connectionString: "...",
379
403
  auth: {
package/dist/cli.js CHANGED
@@ -1740,11 +1740,50 @@ export * from "./include-spec";
1740
1740
  `;
1741
1741
  }
1742
1742
 
1743
+ // src/types.ts
1744
+ function normalizeAuthConfig(input) {
1745
+ if (!input)
1746
+ return;
1747
+ if ("strategy" in input && input.strategy) {
1748
+ return input;
1749
+ }
1750
+ if ("apiKey" in input && input.apiKey) {
1751
+ return {
1752
+ strategy: "api-key",
1753
+ apiKeyHeader: input.apiKeyHeader,
1754
+ apiKeys: [input.apiKey, ...input.apiKeys || []]
1755
+ };
1756
+ }
1757
+ if ("apiKeys" in input && input.apiKeys?.length) {
1758
+ return {
1759
+ strategy: "api-key",
1760
+ apiKeyHeader: input.apiKeyHeader,
1761
+ apiKeys: input.apiKeys
1762
+ };
1763
+ }
1764
+ if ("jwt" in input && input.jwt) {
1765
+ if (typeof input.jwt === "string") {
1766
+ return {
1767
+ strategy: "jwt-hs256",
1768
+ jwt: { sharedSecret: input.jwt }
1769
+ };
1770
+ } else {
1771
+ return {
1772
+ strategy: "jwt-hs256",
1773
+ jwt: input.jwt
1774
+ };
1775
+ }
1776
+ }
1777
+ return { strategy: "none" };
1778
+ }
1779
+
1743
1780
  // src/index.ts
1744
1781
  async function generate(configPath) {
1745
1782
  const configUrl = pathToFileURL(configPath).href;
1746
1783
  const module = await import(configUrl);
1747
- const cfg = module.default || module;
1784
+ const rawCfg = module.default || module;
1785
+ const normalizedAuth = normalizeAuthConfig(rawCfg.auth);
1786
+ const cfg = { ...rawCfg, auth: normalizedAuth };
1748
1787
  console.log("\uD83D\uDD0D Introspecting database...");
1749
1788
  const model = await introspect(cfg.connectionString, cfg.schema || "public");
1750
1789
  console.log("\uD83D\uDD17 Building relationship graph...");
@@ -1774,8 +1813,8 @@ async function generate(configPath) {
1774
1813
  content: emitIncludeLoader(graph, model, cfg.includeDepthLimit || 3)
1775
1814
  });
1776
1815
  files.push({ path: join(serverDir, "logger.ts"), content: emitLogger() });
1777
- if (cfg.auth?.strategy && cfg.auth.strategy !== "none") {
1778
- files.push({ path: join(serverDir, "auth.ts"), content: emitAuth(cfg.auth) });
1816
+ if (normalizedAuth?.strategy && normalizedAuth.strategy !== "none") {
1817
+ files.push({ path: join(serverDir, "auth.ts"), content: emitAuth(normalizedAuth) });
1779
1818
  }
1780
1819
  for (const table of Object.values(model.tables)) {
1781
1820
  const typesSrc = emitTypes(table, { dateType: normDateType, numericMode: "string" });
@@ -1790,7 +1829,7 @@ async function generate(configPath) {
1790
1829
  content: emitRoutes(table, graph, {
1791
1830
  softDeleteColumn: cfg.softDeleteColumn || null,
1792
1831
  includeDepthLimit: cfg.includeDepthLimit || 3,
1793
- authStrategy: cfg.auth?.strategy
1832
+ authStrategy: normalizedAuth?.strategy
1794
1833
  })
1795
1834
  });
1796
1835
  files.push({
@@ -1804,7 +1843,7 @@ async function generate(configPath) {
1804
1843
  });
1805
1844
  files.push({
1806
1845
  path: join(serverDir, "router.ts"),
1807
- content: emitRouter(Object.values(model.tables), !!cfg.auth?.strategy && cfg.auth.strategy !== "none")
1846
+ content: emitRouter(Object.values(model.tables), !!normalizedAuth?.strategy && normalizedAuth.strategy !== "none")
1808
1847
  });
1809
1848
  console.log("✍️ Writing files...");
1810
1849
  await writeFiles(files);
package/dist/index.js CHANGED
@@ -1739,11 +1739,50 @@ export * from "./include-spec";
1739
1739
  `;
1740
1740
  }
1741
1741
 
1742
+ // src/types.ts
1743
+ function normalizeAuthConfig(input) {
1744
+ if (!input)
1745
+ return;
1746
+ if ("strategy" in input && input.strategy) {
1747
+ return input;
1748
+ }
1749
+ if ("apiKey" in input && input.apiKey) {
1750
+ return {
1751
+ strategy: "api-key",
1752
+ apiKeyHeader: input.apiKeyHeader,
1753
+ apiKeys: [input.apiKey, ...input.apiKeys || []]
1754
+ };
1755
+ }
1756
+ if ("apiKeys" in input && input.apiKeys?.length) {
1757
+ return {
1758
+ strategy: "api-key",
1759
+ apiKeyHeader: input.apiKeyHeader,
1760
+ apiKeys: input.apiKeys
1761
+ };
1762
+ }
1763
+ if ("jwt" in input && input.jwt) {
1764
+ if (typeof input.jwt === "string") {
1765
+ return {
1766
+ strategy: "jwt-hs256",
1767
+ jwt: { sharedSecret: input.jwt }
1768
+ };
1769
+ } else {
1770
+ return {
1771
+ strategy: "jwt-hs256",
1772
+ jwt: input.jwt
1773
+ };
1774
+ }
1775
+ }
1776
+ return { strategy: "none" };
1777
+ }
1778
+
1742
1779
  // src/index.ts
1743
1780
  async function generate(configPath) {
1744
1781
  const configUrl = pathToFileURL(configPath).href;
1745
1782
  const module = await import(configUrl);
1746
- const cfg = module.default || module;
1783
+ const rawCfg = module.default || module;
1784
+ const normalizedAuth = normalizeAuthConfig(rawCfg.auth);
1785
+ const cfg = { ...rawCfg, auth: normalizedAuth };
1747
1786
  console.log("\uD83D\uDD0D Introspecting database...");
1748
1787
  const model = await introspect(cfg.connectionString, cfg.schema || "public");
1749
1788
  console.log("\uD83D\uDD17 Building relationship graph...");
@@ -1773,8 +1812,8 @@ async function generate(configPath) {
1773
1812
  content: emitIncludeLoader(graph, model, cfg.includeDepthLimit || 3)
1774
1813
  });
1775
1814
  files.push({ path: join(serverDir, "logger.ts"), content: emitLogger() });
1776
- if (cfg.auth?.strategy && cfg.auth.strategy !== "none") {
1777
- files.push({ path: join(serverDir, "auth.ts"), content: emitAuth(cfg.auth) });
1815
+ if (normalizedAuth?.strategy && normalizedAuth.strategy !== "none") {
1816
+ files.push({ path: join(serverDir, "auth.ts"), content: emitAuth(normalizedAuth) });
1778
1817
  }
1779
1818
  for (const table of Object.values(model.tables)) {
1780
1819
  const typesSrc = emitTypes(table, { dateType: normDateType, numericMode: "string" });
@@ -1789,7 +1828,7 @@ async function generate(configPath) {
1789
1828
  content: emitRoutes(table, graph, {
1790
1829
  softDeleteColumn: cfg.softDeleteColumn || null,
1791
1830
  includeDepthLimit: cfg.includeDepthLimit || 3,
1792
- authStrategy: cfg.auth?.strategy
1831
+ authStrategy: normalizedAuth?.strategy
1793
1832
  })
1794
1833
  });
1795
1834
  files.push({
@@ -1803,7 +1842,7 @@ async function generate(configPath) {
1803
1842
  });
1804
1843
  files.push({
1805
1844
  path: join(serverDir, "router.ts"),
1806
- content: emitRouter(Object.values(model.tables), !!cfg.auth?.strategy && cfg.auth.strategy !== "none")
1845
+ content: emitRouter(Object.values(model.tables), !!normalizedAuth?.strategy && normalizedAuth.strategy !== "none")
1807
1846
  });
1808
1847
  console.log("✍️ Writing files...");
1809
1848
  await writeFiles(files);
package/dist/types.d.ts CHANGED
@@ -8,6 +8,16 @@ export interface AuthConfig {
8
8
  audience?: string;
9
9
  };
10
10
  }
11
+ export type AuthConfigInput = AuthConfig | {
12
+ apiKey?: string;
13
+ apiKeys?: string[];
14
+ apiKeyHeader?: string;
15
+ jwt?: string | {
16
+ sharedSecret?: string;
17
+ issuer?: string;
18
+ audience?: string;
19
+ };
20
+ };
11
21
  export interface Config {
12
22
  connectionString: string;
13
23
  schema?: string;
@@ -16,5 +26,6 @@ export interface Config {
16
26
  softDeleteColumn?: string | null;
17
27
  includeDepthLimit?: number;
18
28
  dateType?: "date" | "string";
19
- auth?: AuthConfig;
29
+ auth?: AuthConfigInput;
20
30
  }
31
+ export declare function normalizeAuthConfig(input: AuthConfigInput | undefined): AuthConfig | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postgresdk",
3
- "version": "0.1.2-alpha.2",
3
+ "version": "0.1.2-alpha.3",
4
4
  "description": "Generate a typed server/client SDK from a Postgres schema (includes, Zod, Hono).",
5
5
  "type": "module",
6
6
  "bin": {