canxjs 1.6.2 → 1.6.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.
Files changed (173) hide show
  1. package/README.md +23 -0
  2. package/dist/src/Application.d.ts +17 -0
  3. package/dist/src/Application.d.ts.map +1 -1
  4. package/dist/src/Application.js +36 -0
  5. package/dist/src/adapter/inertia/InertiaManager.d.ts +31 -0
  6. package/dist/src/adapter/inertia/InertiaManager.d.ts.map +1 -0
  7. package/dist/src/adapter/inertia/InertiaManager.js +54 -0
  8. package/dist/src/adapter/inertia/InertiaMiddleware.d.ts +3 -0
  9. package/dist/src/adapter/inertia/InertiaMiddleware.d.ts.map +1 -0
  10. package/dist/src/adapter/inertia/InertiaMiddleware.js +127 -0
  11. package/dist/src/auth/OAuth.d.ts +39 -36
  12. package/dist/src/auth/OAuth.d.ts.map +1 -1
  13. package/dist/src/auth/OAuth.js +127 -174
  14. package/dist/src/cli/commands/DownCommand.d.ts +17 -0
  15. package/dist/src/cli/commands/DownCommand.d.ts.map +1 -0
  16. package/dist/src/cli/commands/DownCommand.js +67 -0
  17. package/dist/src/cli/commands/MakeCommand.d.ts.map +1 -1
  18. package/dist/src/cli/commands/MakeCommand.js +81 -21
  19. package/dist/src/cli/commands/UpCommand.d.ts +13 -0
  20. package/dist/src/cli/commands/UpCommand.d.ts.map +1 -0
  21. package/dist/src/cli/commands/UpCommand.js +34 -0
  22. package/dist/src/cli/index.d.ts.map +1 -1
  23. package/dist/src/cli/index.js +4 -0
  24. package/dist/src/core/MaintenanceMode.d.ts +95 -0
  25. package/dist/src/core/MaintenanceMode.d.ts.map +1 -0
  26. package/dist/src/core/MaintenanceMode.js +258 -0
  27. package/dist/src/core/Server.d.ts.map +1 -1
  28. package/dist/src/core/Server.js +7 -0
  29. package/dist/src/i18n/LocalizationMiddleware.d.ts +8 -0
  30. package/dist/src/i18n/LocalizationMiddleware.d.ts.map +1 -0
  31. package/dist/src/i18n/LocalizationMiddleware.js +38 -0
  32. package/dist/src/i18n/Translator.d.ts +39 -0
  33. package/dist/src/i18n/Translator.d.ts.map +1 -0
  34. package/dist/src/i18n/Translator.js +120 -0
  35. package/dist/src/i18n/helpers.d.ts +13 -0
  36. package/dist/src/i18n/helpers.d.ts.map +1 -0
  37. package/dist/src/i18n/helpers.js +32 -0
  38. package/dist/src/index.d.ts +36 -10
  39. package/dist/src/index.d.ts.map +1 -1
  40. package/dist/src/index.js +46 -16
  41. package/dist/src/inertia/InertiaManager.d.ts +31 -0
  42. package/dist/src/inertia/InertiaManager.d.ts.map +1 -0
  43. package/dist/src/inertia/InertiaManager.js +54 -0
  44. package/dist/src/inertia/InertiaMiddleware.d.ts +3 -0
  45. package/dist/src/inertia/InertiaMiddleware.d.ts.map +1 -0
  46. package/dist/src/inertia/InertiaMiddleware.js +127 -0
  47. package/dist/src/inertia/index.d.ts +3 -0
  48. package/dist/src/inertia/index.d.ts.map +1 -0
  49. package/dist/src/inertia/index.js +2 -0
  50. package/dist/src/mvc/ModelObserver.d.ts +152 -0
  51. package/dist/src/mvc/ModelObserver.d.ts.map +1 -0
  52. package/dist/src/mvc/ModelObserver.js +239 -0
  53. package/dist/src/mvc/View.d.ts +9 -0
  54. package/dist/src/mvc/View.d.ts.map +1 -1
  55. package/dist/src/mvc/View.js +10 -1
  56. package/dist/src/notifications/Notification.d.ts.map +1 -1
  57. package/dist/src/notifications/Notification.js +1 -0
  58. package/dist/src/notifications/channels/SmsChannel.d.ts +128 -0
  59. package/dist/src/notifications/channels/SmsChannel.d.ts.map +1 -0
  60. package/dist/src/notifications/channels/SmsChannel.js +268 -0
  61. package/dist/src/queue/JobBatch.d.ts +146 -0
  62. package/dist/src/queue/JobBatch.d.ts.map +1 -0
  63. package/dist/src/queue/JobBatch.js +300 -0
  64. package/dist/src/queue/JobChain.d.ts +113 -0
  65. package/dist/src/queue/JobChain.d.ts.map +1 -0
  66. package/dist/src/queue/JobChain.js +216 -0
  67. package/dist/src/queue/Queue.d.ts +4 -1
  68. package/dist/src/queue/Queue.d.ts.map +1 -1
  69. package/dist/src/queue/Queue.js +3 -2
  70. package/dist/src/realtime/Broadcasting.d.ts +137 -0
  71. package/dist/src/realtime/Broadcasting.d.ts.map +1 -0
  72. package/dist/src/realtime/Broadcasting.js +265 -0
  73. package/dist/src/search/SearchManager.d.ts +4 -4
  74. package/dist/src/search/SearchManager.d.ts.map +1 -1
  75. package/dist/src/search/SearchManager.js +5 -5
  76. package/dist/src/search/Searchable.d.ts +25 -0
  77. package/dist/src/search/Searchable.d.ts.map +1 -0
  78. package/dist/src/search/Searchable.js +19 -0
  79. package/dist/src/search/engines/DatabaseEngine.d.ts +17 -0
  80. package/dist/src/search/engines/DatabaseEngine.d.ts.map +1 -0
  81. package/dist/src/search/engines/DatabaseEngine.js +67 -0
  82. package/dist/src/search/engines/Engine.d.ts +26 -0
  83. package/dist/src/search/engines/Engine.d.ts.map +1 -0
  84. package/dist/src/search/engines/Engine.js +25 -0
  85. package/dist/src/storage/Storage.d.ts.map +1 -1
  86. package/dist/src/storage/Storage.js +7 -0
  87. package/dist/src/storage/drivers/GCSDriver.d.ts +10 -0
  88. package/dist/src/storage/drivers/GCSDriver.d.ts.map +1 -0
  89. package/dist/src/storage/drivers/GCSDriver.js +17 -0
  90. package/dist/src/storage/drivers/types.d.ts +4 -1
  91. package/dist/src/storage/drivers/types.d.ts.map +1 -1
  92. package/dist/src/storage/index.d.ts +6 -0
  93. package/dist/src/storage/index.d.ts.map +1 -0
  94. package/dist/src/storage/index.js +5 -0
  95. package/dist/src/telescope/Telescope.d.ts +110 -0
  96. package/dist/src/telescope/Telescope.d.ts.map +1 -0
  97. package/dist/src/telescope/Telescope.js +205 -0
  98. package/dist/src/telescope/ui/TelescopeController.d.ts +26 -0
  99. package/dist/src/telescope/ui/TelescopeController.d.ts.map +1 -0
  100. package/dist/src/telescope/ui/TelescopeController.js +387 -0
  101. package/dist/src/telescope/watchers/index.d.ts +13 -0
  102. package/dist/src/telescope/watchers/index.d.ts.map +1 -0
  103. package/dist/src/telescope/watchers/index.js +119 -0
  104. package/dist/src/testing/TestHelper.d.ts +11 -11
  105. package/dist/src/testing/TestHelper.d.ts.map +1 -1
  106. package/dist/src/testing/dusk/Browser.d.ts +73 -0
  107. package/dist/src/testing/dusk/Browser.d.ts.map +1 -0
  108. package/dist/src/testing/dusk/Browser.js +123 -0
  109. package/dist/src/testing/dusk/Chrome.d.ts +9 -0
  110. package/dist/src/testing/dusk/Chrome.d.ts.map +1 -0
  111. package/dist/src/testing/dusk/Chrome.js +31 -0
  112. package/dist/src/testing/index.d.ts +14 -0
  113. package/dist/src/testing/index.d.ts.map +1 -0
  114. package/dist/src/testing/index.js +36 -0
  115. package/dist/src/types/index.d.ts +8 -0
  116. package/dist/src/types/index.d.ts.map +1 -1
  117. package/dist/src/utils/Helpers.d.ts.map +1 -1
  118. package/dist/src/utils/Helpers.js +2 -3
  119. package/dist/src/validator/FormRequest.d.ts +24 -0
  120. package/dist/src/validator/FormRequest.d.ts.map +1 -0
  121. package/dist/src/validator/FormRequest.js +82 -0
  122. package/dist/src/vite/Vite.d.ts +44 -0
  123. package/dist/src/vite/Vite.d.ts.map +1 -0
  124. package/dist/src/vite/Vite.js +148 -0
  125. package/dist/src/vite/helpers.d.ts +13 -0
  126. package/dist/src/vite/helpers.d.ts.map +1 -0
  127. package/dist/src/vite/helpers.js +19 -0
  128. package/dist/src/vite/index.d.ts +3 -0
  129. package/dist/src/vite/index.d.ts.map +1 -0
  130. package/dist/src/vite/index.js +2 -0
  131. package/package.json +21 -1
  132. package/src/Application.ts +48 -0
  133. package/src/auth/OAuth.ts +259 -0
  134. package/src/cli/commands/DownCommand.ts +79 -0
  135. package/src/cli/commands/MakeCommand.ts +108 -21
  136. package/src/cli/commands/UpCommand.ts +39 -0
  137. package/src/cli/index.ts +4 -0
  138. package/src/core/MaintenanceMode.ts +336 -0
  139. package/src/core/Server.ts +8 -0
  140. package/src/i18n/LocalizationMiddleware.ts +52 -0
  141. package/src/i18n/Translator.ts +147 -0
  142. package/src/i18n/helpers.ts +35 -0
  143. package/src/index.ts +141 -28
  144. package/src/inertia/InertiaManager.ts +73 -0
  145. package/src/inertia/InertiaMiddleware.ts +148 -0
  146. package/src/inertia/index.ts +2 -0
  147. package/src/mvc/ModelObserver.ts +347 -0
  148. package/src/mvc/View.ts +15 -1
  149. package/src/notifications/Notification.ts +2 -0
  150. package/src/notifications/channels/SmsChannel.ts +362 -0
  151. package/src/queue/JobBatch.ts +398 -0
  152. package/src/queue/JobChain.ts +279 -0
  153. package/src/queue/Queue.ts +3 -2
  154. package/src/realtime/Broadcasting.ts +367 -0
  155. package/src/search/SearchManager.ts +9 -8
  156. package/src/search/Searchable.ts +35 -0
  157. package/src/search/engines/DatabaseEngine.ts +88 -0
  158. package/src/search/engines/Engine.ts +41 -0
  159. package/src/storage/Storage.ts +8 -0
  160. package/src/storage/drivers/GCSDriver.ts +19 -0
  161. package/src/storage/drivers/types.ts +6 -1
  162. package/src/storage/index.ts +5 -0
  163. package/src/testing/TestHelper.ts +12 -12
  164. package/src/testing/dusk/Browser.ts +150 -0
  165. package/src/testing/dusk/Chrome.ts +33 -0
  166. package/src/testing/index.ts +45 -0
  167. package/src/types/index.ts +10 -0
  168. package/src/utils/Helpers.ts +2 -3
  169. package/src/validator/FormRequest.ts +101 -0
  170. package/src/vite/Vite.ts +185 -0
  171. package/src/vite/helpers.ts +22 -0
  172. package/src/vite/index.ts +2 -0
  173. package/src/testing/Browser.ts +0 -112
package/README.md CHANGED
@@ -227,6 +227,29 @@ my-app/
227
227
  - [Middleware](http://docs-canxjs.netlify.app/docs/middleware)
228
228
  - [HotWire](http://docs-canxjs.netlify.app/docs/hotwire)
229
229
 
230
+ ## Optional Dependencies
231
+
232
+ CanxJS is designed to be lightweight. Some features require additional packages:
233
+
234
+ | Feature | Required Package | Install Command |
235
+ | ----------- | --------------------- | -------------------- |
236
+ | PostgreSQL | `pg` | `bun add pg` |
237
+ | S3 Storage | Built-in (uses fetch) | - |
238
+ | SMTP Email | `nodemailer` | `bun add nodemailer` |
239
+ | Redis Cache | `ioredis` | `bun add ioredis` |
240
+
241
+ ## Official Packages
242
+
243
+ Extend CanxJS with official packages:
244
+
245
+ | Package | Description | Install |
246
+ | ------------------------------------------------------------------ | -------------------------------------------------- | -------------------------- |
247
+ | [@canxjs/citadel](https://www.npmjs.com/package/@canxjs/citadel) | API Token Authentication (like Laravel Sanctum) | `bun add @canxjs/citadel` |
248
+ | [@canxjs/dominion](https://www.npmjs.com/package/@canxjs/dominion) | Role-Based Access Control (like Spatie Permission) | `bun add @canxjs/dominion` |
249
+ | [@canxjs/blocks](https://www.npmjs.com/package/@canxjs/blocks) | Modular Architecture (HMVC) | `bun add @canxjs/blocks` |
250
+ | [@canxjs/payment](https://www.npmjs.com/package/@canxjs/payment) | Midtrans Payment Gateway | `bun add @canxjs/payment` |
251
+ | [@canxjs/echo](https://www.npmjs.com/package/@canxjs/echo) | Real-time Event Broadcasting | `bun add @canxjs/echo` |
252
+
230
253
  ## License
231
254
 
232
255
  MIT © CanxJS Team
@@ -2,6 +2,7 @@
2
2
  * CanxJS - Main Application Class
3
3
  */
4
4
  import type { ServerConfig, MiddlewareHandler, CanxApplication, RouterInstance, Plugin } from './types';
5
+ import { Server } from './core/Server';
5
6
  import { Router } from './core/Router';
6
7
  export declare class Canx implements CanxApplication {
7
8
  config: ServerConfig;
@@ -38,6 +39,10 @@ export declare class Canx implements CanxApplication {
38
39
  * Stop the server
39
40
  */
40
41
  close(): Promise<void>;
42
+ /**
43
+ * Get the internal server instance
44
+ */
45
+ getServer(): Server | null;
41
46
  /**
42
47
  * Get router for chaining
43
48
  */
@@ -71,5 +76,17 @@ export declare function createApp(config?: ServerConfig): Canx;
71
76
  * Helper for creating typed configuration objects
72
77
  */
73
78
  export declare function defineConfig<T extends Record<string, any>>(config: T): T;
79
+ export { Canx as Application };
80
+ /**
81
+ * Application Configuration for module-based bootstrap
82
+ */
83
+ interface ApplicationConfig extends ServerConfig {
84
+ rootModule?: any;
85
+ }
86
+ /**
87
+ * Create a new CanxJS application instance with module support
88
+ * This is a NestJS-style factory function
89
+ */
90
+ export declare function createApplication(config?: ApplicationConfig): Canx;
74
91
  export default Canx;
75
92
  //# sourceMappingURL=Application.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Application.d.ts","sourceRoot":"","sources":["../../src/Application.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAc,eAAe,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEpH,OAAO,EAAE,MAAM,EAAgB,MAAM,eAAe,CAAC;AAKrD,qBAAa,IAAK,YAAW,eAAe;IAC1C,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,OAAO,CAAgB;gBAEnB,MAAM,GAAE,YAAiB;IAgBrC;;OAEG;IACH,GAAG,CAAC,UAAU,EAAE,iBAAiB,GAAG,IAAI;IAKxC;;OAEG;IACH,MAAM,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,GAAG,IAAI;IAKxD;;OAEG;IACH,UAAU,CAAC,eAAe,EAAE,UAAU,GAAG,GAAG,IAAI;IAoBhD;;OAEG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK5B;;OAEG;IACG,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBhF;;OAEG;IACG,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IA6ChD;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAW5B;;OAEG;IACH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*/
143
+ getServer() {
144
+ return this.server;
145
+ }
140
146
  /**
141
147
  * Get router for chaining
142
148
  */
@@ -184,4 +190,34 @@ export function createApp(config) {
184
190
  export function defineConfig(config) {
185
191
  return config;
186
192
  }
193
+ // Alias for consistency with NestJS-style naming
194
+ export { Canx as Application };
195
+ /**
196
+ * Create a new CanxJS application instance with module support
197
+ * This is a NestJS-style factory function
198
+ */
199
+ export function createApplication(config) {
200
+ const app = new Canx(config);
201
+ // If rootModule is provided, bootstrap it
202
+ if (config?.rootModule) {
203
+ const meta = Reflect.getMetadata('module:metadata', config.rootModule);
204
+ if (meta) {
205
+ // Register controllers from the module
206
+ if (meta.controllers) {
207
+ for (const ControllerClass of meta.controllers) {
208
+ app.controller(ControllerClass);
209
+ }
210
+ }
211
+ // Register providers to container
212
+ if (meta.providers) {
213
+ for (const provider of meta.providers) {
214
+ if (typeof provider === 'function') {
215
+ container.bind(provider, provider);
216
+ }
217
+ }
218
+ }
219
+ }
220
+ }
221
+ return app;
222
+ }
187
223
  export default Canx;
@@ -0,0 +1,31 @@
1
+ export interface InertiaConfig {
2
+ rootView: string;
3
+ sharedProps: Record<string, any>;
4
+ version: string | (() => string | Promise<string>);
5
+ }
6
+ export declare class InertiaManager {
7
+ private static instance;
8
+ private sharedProps;
9
+ private rootView;
10
+ private versionData;
11
+ constructor();
12
+ static getInstance(): InertiaManager;
13
+ /**
14
+ * Set the root view (e.g. 'app' for app.blade.php / app.html)
15
+ */
16
+ setRootView(view: string): void;
17
+ getRootView(): string;
18
+ /**
19
+ * Share data globally for all requests
20
+ */
21
+ share(key: string, value: any): void;
22
+ share(data: Record<string, any>): void;
23
+ getShared(key?: string): any;
24
+ /**
25
+ * Set version
26
+ */
27
+ version(v: string | (() => string | Promise<string>)): void;
28
+ getVersion(): Promise<string | undefined>;
29
+ }
30
+ export declare const inertiaManager: InertiaManager;
31
+ //# sourceMappingURL=InertiaManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InertiaManager.d.ts","sourceRoot":"","sources":["../../../../src/adapter/inertia/InertiaManager.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,aAAa;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;CACtD;AAED,qBAAa,cAAc;IACvB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAiB;IACxC,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,WAAW,CAA0D;;WAU/D,WAAW,IAAI,cAAc;IAO3C;;OAEG;IACI,WAAW,CAAC,IAAI,EAAE,MAAM;IAIxB,WAAW,IAAI,MAAM;IAI5B;;OAEG;IACI,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IACpC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAStC,SAAS,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG;IAKnC;;OAEG;IACI,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAI9C,UAAU,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;CAKzD;AAED,eAAO,MAAM,cAAc,gBAA+B,CAAC"}
@@ -0,0 +1,54 @@
1
+ export class InertiaManager {
2
+ static instance;
3
+ sharedProps = {};
4
+ rootView = 'root'; // default view name
5
+ versionData = null;
6
+ // Per-request sharing storage (using a weak map or similar mechanism in real frameworks,
7
+ // but here we might rely on the middleware attaching an instance to the request)
8
+ // Actually, distinct requests need distinct shared props (e.g. flash messages, auth user).
9
+ // So `share()` should ideally be scoped.
10
+ // For global shared props (e.g. app name), we use this class.
11
+ constructor() { }
12
+ static getInstance() {
13
+ if (!InertiaManager.instance) {
14
+ InertiaManager.instance = new InertiaManager();
15
+ }
16
+ return InertiaManager.instance;
17
+ }
18
+ /**
19
+ * Set the root view (e.g. 'app' for app.blade.php / app.html)
20
+ */
21
+ setRootView(view) {
22
+ this.rootView = view;
23
+ }
24
+ getRootView() {
25
+ return this.rootView;
26
+ }
27
+ share(keyOrData, value) {
28
+ if (typeof keyOrData === 'string') {
29
+ this.sharedProps[keyOrData] = value;
30
+ }
31
+ else {
32
+ Object.assign(this.sharedProps, keyOrData);
33
+ }
34
+ }
35
+ getShared(key) {
36
+ if (key)
37
+ return this.sharedProps[key];
38
+ return this.sharedProps;
39
+ }
40
+ /**
41
+ * Set version
42
+ */
43
+ version(v) {
44
+ this.versionData = v;
45
+ }
46
+ async getVersion() {
47
+ if (!this.versionData)
48
+ return undefined;
49
+ if (typeof this.versionData === 'function')
50
+ return await this.versionData();
51
+ return this.versionData;
52
+ }
53
+ }
54
+ export const inertiaManager = InertiaManager.getInstance();
@@ -0,0 +1,3 @@
1
+ import type { CanxRequest, CanxResponse, NextFunction } from '../../types';
2
+ export declare function inertiaMiddleware(): (req: CanxRequest, res: CanxResponse, next: NextFunction) => Promise<void | Response>;
3
+ //# sourceMappingURL=InertiaMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InertiaMiddleware.d.ts","sourceRoot":"","sources":["../../../../src/adapter/inertia/InertiaMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3E,wBAAgB,iBAAiB,KACjB,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,8BA8ItE"}
@@ -0,0 +1,127 @@
1
+ import { inertiaManager } from './InertiaManager';
2
+ export function inertiaMiddleware() {
3
+ return async (req, res, next) => {
4
+ // 1. Check if Inertia Request
5
+ const isInertia = req.headers.get('x-inertia') === 'true';
6
+ // Attach an inertia context to the request for scoped sharing
7
+ const scopeProps = {};
8
+ // Helper to share data for THIS request only
9
+ req.inertiaShare = (key, value) => {
10
+ if (typeof key === 'string') {
11
+ scopeProps[key] = value;
12
+ }
13
+ else {
14
+ Object.assign(scopeProps, key);
15
+ }
16
+ };
17
+ // 2. Asset Versioning
18
+ if (isInertia && req.method === 'GET') {
19
+ const version = await inertiaManager.getVersion();
20
+ const headerVersion = req.headers.get('x-inertia-version');
21
+ if (version && headerVersion !== version) {
22
+ // Asset version mismatch -> Force full reload
23
+ res.status(409).header('X-Inertia-Location', req.raw.url);
24
+ return res.empty();
25
+ }
26
+ }
27
+ // 3. Setup Response Helper
28
+ // We override or attach `res.inertia` here
29
+ res.inertia = async (component, props = {}) => {
30
+ const version = await inertiaManager.getVersion();
31
+ const globalProps = inertiaManager.getShared();
32
+ // Merge props: Global -> Request Scope -> Controller Props
33
+ const allProps = { ...globalProps, ...scopeProps, ...props };
34
+ // Lazy Evaluation (Partial Reloads)
35
+ const partialData = req.headers.get('x-inertia-partial-data');
36
+ const partialComponent = req.headers.get('x-inertia-partial-component');
37
+ let finalProps = allProps;
38
+ if (isInertia && partialData && partialComponent === component) {
39
+ const only = partialData.split(',').map(s => s.trim());
40
+ const newProps = {};
41
+ for (const key of only) {
42
+ if (key in allProps) {
43
+ newProps[key] = allProps[key];
44
+ }
45
+ }
46
+ finalProps = newProps;
47
+ }
48
+ // Resolve Lazy Props (functions)
49
+ for (const key in finalProps) {
50
+ if (typeof finalProps[key] === 'function') {
51
+ try {
52
+ finalProps[key] = await finalProps[key]();
53
+ }
54
+ catch (e) {
55
+ console.error(`[Inertia] Error resolving prop ${key}:`, e);
56
+ finalProps[key] = null;
57
+ }
58
+ }
59
+ }
60
+ const page = {
61
+ component,
62
+ props: finalProps,
63
+ url: req.raw.url, // Original URL
64
+ version: version || '',
65
+ };
66
+ if (isInertia) {
67
+ // JSON Response
68
+ res.header('X-Inertia', 'true')
69
+ .header('Content-Type', 'application/json')
70
+ .header('Vary', 'Accept');
71
+ return res.json(page);
72
+ }
73
+ else {
74
+ // HTML Full Page Load
75
+ const rootView = inertiaManager.getRootView();
76
+ const encodedPage = JSON.stringify(page).replace(/"/g, '&quot;');
77
+ // We need a way to render the root view with the app payload
78
+ // In Laravel/Blade: <div id="app" data-page="{{ json($page) }}"></div>
79
+ // Here, we'll try to use the view engine if available.
80
+ // Assumption: The user creates a view that prints `inertiaHead` and `inertiaBody`?
81
+ // Or simpler: We inject it into a template placeholder.
82
+ // Let's assume standard SSR/View usage.
83
+ // For now, we will construct a basic HTML shell if NO view engine is found,
84
+ // OR render the view passing `page` string.
85
+ try {
86
+ // Try to render the root view, passing 'page' variable
87
+ // The root view should have: <div id="app" data-page='<%= page %>'></div>
88
+ // or React-style.
89
+ // Construct a default html if view is likely missing or simple usage
90
+ const customView = await import('../../mvc/View').then(m => m.viewIfExists(rootView, { page: page }));
91
+ if (customView) {
92
+ return res.html(customView);
93
+ }
94
+ // Fallback default HTML
95
+ const html = `<!DOCTYPE html>
96
+ <html lang="en">
97
+ <head>
98
+ <meta charset="UTF-8">
99
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
100
+ <title>${component}</title>
101
+ <!-- Inertia Head -->
102
+ </head>
103
+ <body>
104
+ <div id="app" data-page="${encodedPage}"></div>
105
+ <!-- Scripts -->
106
+ </body>
107
+ </html>`;
108
+ return res.html(html);
109
+ }
110
+ catch (e) {
111
+ console.error('[Inertia] View render error:', e);
112
+ return res.status(500).text('Inertia View Error');
113
+ }
114
+ }
115
+ };
116
+ // 4. Handle External Redirects (303 for PUT/PATCH/DELETE)
117
+ // Common inertia pattern: non-GET requests redirecting must use 303 to avoid method preservation
118
+ const originalRedirect = res.redirect;
119
+ res.redirect = (url, status) => {
120
+ if (isInertia && ['PUT', 'PATCH', 'DELETE'].includes(req.method)) {
121
+ status = 303;
122
+ }
123
+ return originalRedirect.call(res, url, status);
124
+ };
125
+ return next();
126
+ };
127
+ }
@@ -1,64 +1,67 @@
1
1
  /**
2
- * CanxJS OAuth2 Provider
3
- * Social login integration for Google, GitHub, Facebook, Discord
2
+ * OAuth - Simple OAuth2 Social Login Helper
3
+ * For more advanced social login, use SocialManager from auth/social
4
4
  */
5
- import type { CanxRequest, CanxResponse, MiddlewareHandler } from '../types';
6
- export interface OAuthProvider {
7
- name: string;
5
+ interface OAuthProviderConfig {
8
6
  clientId: string;
9
7
  clientSecret: string;
10
8
  redirectUri: string;
11
- scopes: string[];
12
- authUrl: string;
13
- tokenUrl: string;
14
- userInfoUrl: string;
9
+ scopes?: string[];
15
10
  }
16
- export interface OAuthUser {
17
- id: string;
18
- email: string;
19
- name: string;
20
- avatar?: string;
21
- provider: string;
22
- accessToken: string;
23
- refreshToken?: string;
24
- raw: Record<string, unknown>;
25
- }
26
- export interface OAuthConfig {
27
- providers: Record<string, Partial<OAuthProvider>>;
28
- defaultScopes?: Record<string, string[]>;
11
+ interface OAuthConfig {
12
+ providers: Record<string, OAuthProviderConfig>;
29
13
  }
30
14
  export declare class OAuth {
31
- private providers;
15
+ private config;
32
16
  private stateStore;
33
17
  /**
34
18
  * Configure OAuth providers
35
19
  */
36
- configure(config: OAuthConfig): void;
20
+ configure(config: OAuthConfig): this;
21
+ /**
22
+ * Add a provider
23
+ */
24
+ addProvider(name: string, config: OAuthProviderConfig): this;
25
+ /**
26
+ * Get provider config
27
+ */
28
+ private getProvider;
37
29
  /**
38
- * Generate a secure state token
30
+ * Generate a random state string
39
31
  */
40
32
  private generateState;
41
33
  /**
42
- * Get authorization URL for a provider
34
+ * Store state for validation
43
35
  */
44
- getAuthUrl(providerName: string, additionalParams?: Record<string, string>): string;
36
+ private storeState;
45
37
  /**
46
- * Handle OAuth callback and exchange code for tokens
38
+ * Validate state
47
39
  */
48
- handleCallback(providerName: string, code: string, state: string): Promise<OAuthUser>;
40
+ validateState(state: string, provider: string): boolean;
49
41
  /**
50
- * Normalize user data from different providers
42
+ * Get authorization URL for provider
51
43
  */
52
- private normalizeUser;
44
+ getAuthUrl(provider: string, customState?: string): string;
53
45
  /**
54
- * Redirect middleware for OAuth flow
46
+ * Exchange code for tokens
55
47
  */
56
- redirect(providerName: string): MiddlewareHandler;
48
+ getToken(provider: string, code: string): Promise<{
49
+ accessToken: string;
50
+ refreshToken?: string;
51
+ expiresIn?: number;
52
+ tokenType: string;
53
+ }>;
57
54
  /**
58
- * Callback middleware for OAuth flow
55
+ * Get user info from provider
59
56
  */
60
- callback(providerName: string, onSuccess: (user: OAuthUser, req: CanxRequest, res: CanxResponse) => void | Promise<void>): MiddlewareHandler;
57
+ getUser(provider: string, accessToken: string): Promise<{
58
+ id: string;
59
+ email?: string;
60
+ name?: string;
61
+ avatar?: string;
62
+ raw: any;
63
+ }>;
61
64
  }
62
65
  export declare const oauth: OAuth;
63
- export declare function initOAuth(config: OAuthConfig): void;
66
+ export {};
64
67
  //# sourceMappingURL=OAuth.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"OAuth.d.ts","sourceRoot":"","sources":["../../../src/auth/OAuth.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAM7E,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,M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