frappe-nextjs 0.1.0

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 (98) hide show
  1. package/README.md +90 -0
  2. package/dist/bin/cli.d.ts +3 -0
  3. package/dist/bin/cli.d.ts.map +1 -0
  4. package/dist/bin/cli.js +156 -0
  5. package/dist/bin/cli.js.map +1 -0
  6. package/dist/build/boilerplates.d.ts +12 -0
  7. package/dist/build/boilerplates.d.ts.map +1 -0
  8. package/dist/build/boilerplates.js +261 -0
  9. package/dist/build/boilerplates.js.map +1 -0
  10. package/dist/build/build.d.ts +27 -0
  11. package/dist/build/build.d.ts.map +1 -0
  12. package/dist/build/build.js +172 -0
  13. package/dist/build/build.js.map +1 -0
  14. package/dist/build/context-generator.d.ts +13 -0
  15. package/dist/build/context-generator.d.ts.map +1 -0
  16. package/dist/build/context-generator.js +76 -0
  17. package/dist/build/context-generator.js.map +1 -0
  18. package/dist/build/hooks-patcher.d.ts +11 -0
  19. package/dist/build/hooks-patcher.d.ts.map +1 -0
  20. package/dist/build/hooks-patcher.js +78 -0
  21. package/dist/build/hooks-patcher.js.map +1 -0
  22. package/dist/build/index.d.ts +8 -0
  23. package/dist/build/index.d.ts.map +1 -0
  24. package/dist/build/index.js +33 -0
  25. package/dist/build/index.js.map +1 -0
  26. package/dist/build/init.d.ts +27 -0
  27. package/dist/build/init.d.ts.map +1 -0
  28. package/dist/build/init.js +175 -0
  29. package/dist/build/init.js.map +1 -0
  30. package/dist/build/nginx-generator.d.ts +22 -0
  31. package/dist/build/nginx-generator.d.ts.map +1 -0
  32. package/dist/build/nginx-generator.js +114 -0
  33. package/dist/build/nginx-generator.js.map +1 -0
  34. package/dist/build/supervisor-generator.d.ts +31 -0
  35. package/dist/build/supervisor-generator.d.ts.map +1 -0
  36. package/dist/build/supervisor-generator.js +105 -0
  37. package/dist/build/supervisor-generator.js.map +1 -0
  38. package/dist/client/FrappeClient.d.ts +143 -0
  39. package/dist/client/FrappeClient.d.ts.map +1 -0
  40. package/dist/client/FrappeClient.js +446 -0
  41. package/dist/client/FrappeClient.js.map +1 -0
  42. package/dist/client/index.d.ts +3 -0
  43. package/dist/client/index.d.ts.map +1 -0
  44. package/dist/client/index.js +21 -0
  45. package/dist/client/index.js.map +1 -0
  46. package/dist/client/types.d.ts +140 -0
  47. package/dist/client/types.d.ts.map +1 -0
  48. package/dist/client/types.js +17 -0
  49. package/dist/client/types.js.map +1 -0
  50. package/dist/hooks/FrappeProvider.d.ts +41 -0
  51. package/dist/hooks/FrappeProvider.d.ts.map +1 -0
  52. package/dist/hooks/FrappeProvider.js +48 -0
  53. package/dist/hooks/FrappeProvider.js.map +1 -0
  54. package/dist/hooks/index.d.ts +8 -0
  55. package/dist/hooks/index.d.ts.map +1 -0
  56. package/dist/hooks/index.js +17 -0
  57. package/dist/hooks/index.js.map +1 -0
  58. package/dist/hooks/useFrappeAuth.d.ts +37 -0
  59. package/dist/hooks/useFrappeAuth.d.ts.map +1 -0
  60. package/dist/hooks/useFrappeAuth.js +111 -0
  61. package/dist/hooks/useFrappeAuth.js.map +1 -0
  62. package/dist/hooks/useFrappeCall.d.ts +26 -0
  63. package/dist/hooks/useFrappeCall.d.ts.map +1 -0
  64. package/dist/hooks/useFrappeCall.js +47 -0
  65. package/dist/hooks/useFrappeCall.js.map +1 -0
  66. package/dist/hooks/useFrappeDoc.d.ts +37 -0
  67. package/dist/hooks/useFrappeDoc.d.ts.map +1 -0
  68. package/dist/hooks/useFrappeDoc.js +79 -0
  69. package/dist/hooks/useFrappeDoc.js.map +1 -0
  70. package/dist/hooks/useFrappeDocList.d.ts +37 -0
  71. package/dist/hooks/useFrappeDocList.d.ts.map +1 -0
  72. package/dist/hooks/useFrappeDocList.js +65 -0
  73. package/dist/hooks/useFrappeDocList.js.map +1 -0
  74. package/dist/hooks/useFrappeFileUpload.d.ts +40 -0
  75. package/dist/hooks/useFrappeFileUpload.d.ts.map +1 -0
  76. package/dist/hooks/useFrappeFileUpload.js +68 -0
  77. package/dist/hooks/useFrappeFileUpload.js.map +1 -0
  78. package/dist/index.d.ts +10 -0
  79. package/dist/index.d.ts.map +1 -0
  80. package/dist/index.js +24 -0
  81. package/dist/index.js.map +1 -0
  82. package/dist/ssr/index.d.ts +4 -0
  83. package/dist/ssr/index.d.ts.map +1 -0
  84. package/dist/ssr/index.js +13 -0
  85. package/dist/ssr/index.js.map +1 -0
  86. package/dist/ssr/middleware.d.ts +18 -0
  87. package/dist/ssr/middleware.d.ts.map +1 -0
  88. package/dist/ssr/middleware.js +132 -0
  89. package/dist/ssr/middleware.js.map +1 -0
  90. package/dist/ssr/proxy-config.d.ts +33 -0
  91. package/dist/ssr/proxy-config.d.ts.map +1 -0
  92. package/dist/ssr/proxy-config.js +133 -0
  93. package/dist/ssr/proxy-config.js.map +1 -0
  94. package/dist/ssr/server-client.d.ts +73 -0
  95. package/dist/ssr/server-client.d.ts.map +1 -0
  96. package/dist/ssr/server-client.js +94 -0
  97. package/dist/ssr/server-client.js.map +1 -0
  98. package/package.json +79 -0
@@ -0,0 +1,22 @@
1
+ interface NginxOptions {
2
+ /** SPA name / route prefix (e.g. 'dashboard') */
3
+ spaName: string;
4
+ /** Port the Next.js server listens on (default: 3100) */
5
+ port?: number;
6
+ /** Absolute path to the SPA directory (for static asset serving) */
7
+ spaPath: string;
8
+ }
9
+ /**
10
+ * Generate nginx location blocks to proxy requests to the Next.js SSR server
11
+ * and serve static assets directly.
12
+ *
13
+ * The generated config should be added inside the `server { }` block
14
+ * for your Frappe site's nginx configuration.
15
+ */
16
+ export declare function generateNginxConfig(options: NginxOptions): string;
17
+ /**
18
+ * Generate instructions for setting up nginx.
19
+ */
20
+ export declare function getNginxInstructions(spaName: string): string;
21
+ export {};
22
+ //# sourceMappingURL=nginx-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nginx-generator.d.ts","sourceRoot":"","sources":["../../src/build/nginx-generator.ts"],"names":[],"mappings":"AAEA,UAAU,YAAY;IACpB,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CA0CjE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAsB5D"}
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.generateNginxConfig = generateNginxConfig;
37
+ exports.getNginxInstructions = getNginxInstructions;
38
+ const path = __importStar(require("path"));
39
+ /**
40
+ * Generate nginx location blocks to proxy requests to the Next.js SSR server
41
+ * and serve static assets directly.
42
+ *
43
+ * The generated config should be added inside the `server { }` block
44
+ * for your Frappe site's nginx configuration.
45
+ */
46
+ function generateNginxConfig(options) {
47
+ const { spaName, port = 3100, spaPath } = options;
48
+ const staticPath = path.join(spaPath, '.next', 'static');
49
+ return `
50
+ # ─── Next.js SSR: '${spaName}' ─────────────────────────────────────
51
+ # Add these location blocks inside your Frappe site's server { } block.
52
+ # Typically found at: /etc/nginx/conf.d/<site-name>.conf
53
+ # or generated by: bench setup nginx
54
+
55
+ # Proxy dynamic requests to Next.js server
56
+ location /${spaName} {
57
+ proxy_pass http://127.0.0.1:${port};
58
+ proxy_http_version 1.1;
59
+ proxy_set_header Upgrade $http_upgrade;
60
+ proxy_set_header Connection 'upgrade';
61
+ proxy_set_header Host $host;
62
+ proxy_set_header X-Real-IP $remote_addr;
63
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
64
+ proxy_set_header X-Forwarded-Proto $scheme;
65
+ proxy_cache_bypass $http_upgrade;
66
+
67
+ # Increase timeouts for SSR
68
+ proxy_read_timeout 120s;
69
+ proxy_connect_timeout 10s;
70
+ }
71
+
72
+ # Serve Next.js static assets directly (much faster than proxying)
73
+ location /_next/static {
74
+ alias ${staticPath};
75
+ expires 365d;
76
+ add_header Cache-Control "public, immutable";
77
+ access_log off;
78
+ }
79
+
80
+ # Next.js image optimization (if using next/image)
81
+ location /_next/image {
82
+ proxy_pass http://127.0.0.1:${port};
83
+ proxy_http_version 1.1;
84
+ proxy_set_header Host $host;
85
+ }
86
+ `;
87
+ }
88
+ /**
89
+ * Generate instructions for setting up nginx.
90
+ */
91
+ function getNginxInstructions(spaName) {
92
+ return `
93
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
94
+ Nginx Setup for '${spaName}'
95
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
96
+
97
+ 1. Add the generated location blocks to your site's nginx config.
98
+ The config file is typically at:
99
+ /etc/nginx/conf.d/<your-site-name>.conf
100
+
101
+ Insert the location blocks inside the existing server { } block,
102
+ BEFORE the catch-all location / { } block.
103
+
104
+ 2. Test the nginx configuration:
105
+ sudo nginx -t
106
+
107
+ 3. Reload nginx:
108
+ sudo nginx -s reload
109
+
110
+ 4. Your Next.js app should now be accessible at:
111
+ https://<your-site>/${spaName}/
112
+ `;
113
+ }
114
+ //# sourceMappingURL=nginx-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nginx-generator.js","sourceRoot":"","sources":["../../src/build/nginx-generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,kDA0CC;AAKD,oDAsBC;AAvFD,2CAA6B;AAW7B;;;;;;GAMG;AACH,SAAgB,mBAAmB,CAAC,OAAqB;IACvD,MAAM,EAAE,OAAO,EAAE,IAAI,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAClD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAEzD,OAAO;sBACa,OAAO;;;;;;YAMjB,OAAO;kCACe,IAAI;;;;;;;;;;;;;;;;;YAiB1B,UAAU;;;;;;;;kCAQY,IAAI;;;;CAIrC,CAAC;AACF,CAAC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAAC,OAAe;IAClD,OAAO;;qBAEY,OAAO;;;;;;;;;;;;;;;;;2BAiBD,OAAO;CACjC,CAAC;AACF,CAAC"}
@@ -0,0 +1,31 @@
1
+ interface SupervisorOptions {
2
+ /** Absolute path to the SPA directory containing .next/standalone */
3
+ spaPath: string;
4
+ /** SPA name (used for the program name) */
5
+ spaName: string;
6
+ /** Port for the Next.js server (default: 3100) */
7
+ port?: number;
8
+ /** Absolute path to the bench directory (for log paths) */
9
+ benchPath: string;
10
+ /** User to run the process as */
11
+ user?: string;
12
+ }
13
+ /**
14
+ * Generate a supervisor program configuration for the Next.js SSR server.
15
+ *
16
+ * The generated config should be appended to the bench's supervisor.conf
17
+ * or placed in a supervisor conf.d directory.
18
+ *
19
+ * @example
20
+ * ```
21
+ * frappe-nextjs setup-ssr --app myapp --name dashboard
22
+ * # Generates and outputs the supervisor config to add
23
+ * ```
24
+ */
25
+ export declare function generateSupervisorConfig(options: SupervisorOptions): string;
26
+ /**
27
+ * Generate instructions for setting up the supervisor config.
28
+ */
29
+ export declare function getSupervisorInstructions(spaName: string, benchPath: string): string;
30
+ export {};
31
+ //# sourceMappingURL=supervisor-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"supervisor-generator.d.ts","sourceRoot":"","sources":["../../src/build/supervisor-generator.ts"],"names":[],"mappings":"AAEA,UAAU,iBAAiB;IACzB,qEAAqE;IACrE,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,kDAAkD;IAClD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2DAA2D;IAC3D,SAAS,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAmC3E;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAChB,MAAM,CAyBR"}
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.generateSupervisorConfig = generateSupervisorConfig;
37
+ exports.getSupervisorInstructions = getSupervisorInstructions;
38
+ const path = __importStar(require("path"));
39
+ /**
40
+ * Generate a supervisor program configuration for the Next.js SSR server.
41
+ *
42
+ * The generated config should be appended to the bench's supervisor.conf
43
+ * or placed in a supervisor conf.d directory.
44
+ *
45
+ * @example
46
+ * ```
47
+ * frappe-nextjs setup-ssr --app myapp --name dashboard
48
+ * # Generates and outputs the supervisor config to add
49
+ * ```
50
+ */
51
+ function generateSupervisorConfig(options) {
52
+ const { spaPath, spaName, port = 3100, benchPath, user, } = options;
53
+ const serverJsPath = path.join(spaPath, '.next', 'standalone', 'server.js');
54
+ const logDir = path.join(benchPath, 'logs');
55
+ const programName = `nextjs-${spaName}`;
56
+ let config = `
57
+ ; ─── Next.js SSR Server for '${spaName}' ───────────────────
58
+ [program:${programName}]
59
+ command=node ${serverJsPath}
60
+ directory=${spaPath}
61
+ environment=PORT="${port}",HOSTNAME="127.0.0.1",NODE_ENV="production"
62
+ autostart=true
63
+ autorestart=true
64
+ startretries=3
65
+ startsecs=5
66
+ stdout_logfile=${logDir}/${programName}.log
67
+ stderr_logfile=${logDir}/${programName}.error.log
68
+ stdout_logfile_maxbytes=50MB
69
+ stderr_logfile_maxbytes=50MB`;
70
+ if (user) {
71
+ config += `\nuser=${user}`;
72
+ }
73
+ config += '\n';
74
+ return config;
75
+ }
76
+ /**
77
+ * Generate instructions for setting up the supervisor config.
78
+ */
79
+ function getSupervisorInstructions(spaName, benchPath) {
80
+ return `
81
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
82
+ Supervisor Setup for '${spaName}'
83
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
84
+
85
+ 1. Copy the generated config above into your supervisor configuration.
86
+
87
+ Option A — Append to bench's supervisor.conf:
88
+ cat nextjs-${spaName}.conf >> ${benchPath}/config/supervisor.conf
89
+
90
+ Option B — Place in conf.d directory (if configured):
91
+ cp nextjs-${spaName}.conf /etc/supervisor/conf.d/nextjs-${spaName}.conf
92
+
93
+ 2. Reload supervisor:
94
+ sudo supervisorctl reread
95
+ sudo supervisorctl update
96
+
97
+ 3. Check status:
98
+ sudo supervisorctl status nextjs-${spaName}
99
+
100
+ 4. View logs:
101
+ tail -f ${benchPath}/logs/nextjs-${spaName}.log
102
+ tail -f ${benchPath}/logs/nextjs-${spaName}.error.log
103
+ `;
104
+ }
105
+ //# sourceMappingURL=supervisor-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"supervisor-generator.js","sourceRoot":"","sources":["../../src/build/supervisor-generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,4DAmCC;AAKD,8DA4BC;AA/FD,2CAA6B;AAe7B;;;;;;;;;;;GAWG;AACH,SAAgB,wBAAwB,CAAC,OAA0B;IACjE,MAAM,EACJ,OAAO,EACP,OAAO,EACP,IAAI,GAAG,IAAI,EACX,SAAS,EACT,IAAI,GACL,GAAG,OAAO,CAAC;IAEZ,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;IAC5E,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC5C,MAAM,WAAW,GAAG,UAAU,OAAO,EAAE,CAAC;IAExC,IAAI,MAAM,GAAG;gCACiB,OAAO;WAC5B,WAAW;eACP,YAAY;YACf,OAAO;oBACC,IAAI;;;;;iBAKP,MAAM,IAAI,WAAW;iBACrB,MAAM,IAAI,WAAW;;6BAET,CAAC;IAE5B,IAAI,IAAI,EAAE,CAAC;QACT,MAAM,IAAI,UAAU,IAAI,EAAE,CAAC;IAC7B,CAAC;IAED,MAAM,IAAI,IAAI,CAAC;IAEf,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,SAAgB,yBAAyB,CACvC,OAAe,EACf,SAAiB;IAEjB,OAAO;;0BAEiB,OAAO;;;;;;kBAMf,OAAO,YAAY,SAAS;;;iBAG7B,OAAO,uCAAuC,OAAO;;;;;;;wCAO9B,OAAO;;;eAGhC,SAAS,gBAAgB,OAAO;eAChC,SAAS,gBAAgB,OAAO;CAC9C,CAAC;AACF,CAAC"}
@@ -0,0 +1,143 @@
1
+ import { FrappeClientConfig, FrappeDoc, GetDocListParams, GetDocParams, CreateDocParams, UpdateDocParams, CallParams, FileUploadOptions, FileUploadResponse } from './types';
2
+ /**
3
+ * Core Frappe API client.
4
+ *
5
+ * Works in both browser (cookie auth) and server (token auth) environments.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * // Browser (same-origin, cookie auth)
10
+ * const client = new FrappeClient();
11
+ *
12
+ * // Server-side (token auth)
13
+ * const client = new FrappeClient({
14
+ * baseUrl: 'https://mysite.frappe.cloud',
15
+ * token: { apiKey: '...', apiSecret: '...' },
16
+ * });
17
+ * ```
18
+ */
19
+ export declare class FrappeClient {
20
+ private baseUrl;
21
+ private headers;
22
+ private csrfToken;
23
+ private fetchFn;
24
+ constructor(config?: FrappeClientConfig);
25
+ /**
26
+ * Set CSRF token (required for browser-side POST/PUT/DELETE requests).
27
+ * In Frappe, this is injected into the page via `{{ frappe.session.csrf_token }}`.
28
+ */
29
+ setCsrfToken(token: string): void;
30
+ /**
31
+ * Get CSRF token from the window object (browser only).
32
+ */
33
+ private getCsrfToken;
34
+ private request;
35
+ /**
36
+ * Parse a Frappe error response into a FrappeApiError.
37
+ */
38
+ private parseError;
39
+ /**
40
+ * Get a list of documents.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const todos = await client.getDocList({
45
+ * doctype: 'ToDo',
46
+ * fields: ['name', 'description', 'status'],
47
+ * filters: [['status', '=', 'Open']],
48
+ * orderBy: { field: 'creation', order: 'desc' },
49
+ * limit: 20,
50
+ * });
51
+ * ```
52
+ */
53
+ getDocList<T extends Record<string, unknown> = Record<string, unknown>>(params: GetDocListParams): Promise<FrappeDoc<T>[]>;
54
+ /**
55
+ * Get a single document.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * const todo = await client.getDoc({ doctype: 'ToDo', name: 'TODO-001' });
60
+ * ```
61
+ */
62
+ getDoc<T extends Record<string, unknown> = Record<string, unknown>>(params: GetDocParams): Promise<FrappeDoc<T>>;
63
+ /**
64
+ * Create a new document.
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * const newTodo = await client.createDoc({
69
+ * doctype: 'ToDo',
70
+ * data: { description: 'Buy milk', status: 'Open' },
71
+ * });
72
+ * ```
73
+ */
74
+ createDoc<T extends Record<string, unknown> = Record<string, unknown>>(params: CreateDocParams): Promise<FrappeDoc<T>>;
75
+ /**
76
+ * Update an existing document.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * const updated = await client.updateDoc({
81
+ * doctype: 'ToDo',
82
+ * name: 'TODO-001',
83
+ * data: { status: 'Closed' },
84
+ * });
85
+ * ```
86
+ */
87
+ updateDoc<T extends Record<string, unknown> = Record<string, unknown>>(params: UpdateDocParams): Promise<FrappeDoc<T>>;
88
+ /**
89
+ * Delete a document.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * await client.deleteDoc({ doctype: 'ToDo', name: 'TODO-001' });
94
+ * ```
95
+ */
96
+ deleteDoc(doctype: string, name: string): Promise<void>;
97
+ /**
98
+ * Get the count of documents matching filters.
99
+ */
100
+ getCount(doctype: string, filters?: GetDocListParams['filters']): Promise<number>;
101
+ /**
102
+ * Call a whitelisted Frappe backend method.
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * const result = await client.call({
107
+ * method: 'frappe.ping',
108
+ * });
109
+ * // result === 'pong'
110
+ * ```
111
+ */
112
+ call<T = unknown>(params: CallParams): Promise<T>;
113
+ /**
114
+ * Upload a file to Frappe.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * const fileInput = document.querySelector('input[type="file"]');
119
+ * const result = await client.uploadFile({
120
+ * file: fileInput.files[0],
121
+ * doctype: 'ToDo',
122
+ * docname: 'TODO-001',
123
+ * isPrivate: true,
124
+ * onProgress: (pct) => console.log(`${pct}% uploaded`),
125
+ * });
126
+ * ```
127
+ */
128
+ uploadFile(options: FileUploadOptions): Promise<FileUploadResponse>;
129
+ /**
130
+ * Login with username and password (sets session cookie).
131
+ */
132
+ login(username: string, password: string): Promise<void>;
133
+ /**
134
+ * Logout the current user.
135
+ */
136
+ logout(): Promise<void>;
137
+ /**
138
+ * Get the currently logged-in user.
139
+ */
140
+ getLoggedUser(): Promise<string>;
141
+ private buildHeaders;
142
+ }
143
+ //# sourceMappingURL=FrappeClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FrappeClient.d.ts","sourceRoot":"","sources":["../../src/client/FrappeClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAElB,SAAS,EAET,gB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