@classytic/revenue 1.0.0 → 1.0.2

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Classytic (Classytic)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Classytic (Classytic)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -667,7 +667,7 @@ import type {
667
667
  ## Testing
668
668
 
669
669
  ```bash
670
- # Run all tests (75 tests)
670
+ # Run all tests (84 tests)
671
671
  npm test
672
672
 
673
673
  # Run integration tests (requires MongoDB)
@@ -1,5 +1,5 @@
1
1
  import { M as MonetizationService, P as PaymentService, T as TransactionService, E as EscrowService, C as Container } from '../index-BnJWVXuw.js';
2
- import { d as TransactionDocument, e as SubscriptionDocument, a as MongooseModel, w as PaymentProviderInterface } from '../index-ChVD3P9k.js';
2
+ import { d as TransactionDocument, e as SubscriptionDocument, a as MongooseModel, z as HooksRegistry, w as PaymentProviderInterface } from '../index-ChVD3P9k.js';
3
3
  import { PaymentResult, RefundResult, PaymentProvider } from '../providers/index.js';
4
4
  import { x as RetryConfig, R as Result } from '../retry-80lBCmSe.js';
5
5
  export { E as Err, O as Ok, g as all, e as err, f as flatMap, a as isErr, i as isOk, m as map, c as mapErr, h as match, o as ok, t as tryCatch, d as tryCatchSync, u as unwrap, b as unwrapOr } from '../retry-80lBCmSe.js';
@@ -496,9 +496,14 @@ interface ModelsConfig {
496
496
  interface ProvidersConfig {
497
497
  [name: string]: PaymentProvider;
498
498
  }
499
- interface HooksConfig {
500
- [key: string]: ((...args: any[]) => void | Promise<void>) | undefined;
501
- }
499
+ type HookHandler = (data: unknown) => void | Promise<void>;
500
+ /**
501
+ * Hooks config accepted by the builder.
502
+ *
503
+ * At runtime, hooks are executed via the `HooksRegistry` shape (event -> handlers[]).
504
+ * This type also accepts a legacy shorthand (event -> handler or handlers[]).
505
+ */
506
+ type HooksConfig = HooksRegistry | Record<string, HookHandler | HookHandler[] | undefined>;
502
507
  /**
503
508
  * Revenue - Main entry point
504
509
  *
@@ -685,6 +690,7 @@ declare class RevenueBuilder {
685
690
  * })
686
691
  * ```
687
692
  */
693
+ withHooks(hooks: HooksRegistry): this;
688
694
  withHooks(hooks: HooksConfig): this;
689
695
  /**
690
696
  * Set retry configuration
@@ -2777,19 +2777,13 @@ var RevenueBuilder = class {
2777
2777
  this.plugins.push(...plugins);
2778
2778
  return this;
2779
2779
  }
2780
- /**
2781
- * Register event hooks (for backward compatibility)
2782
- *
2783
- * @example
2784
- * ```typescript
2785
- * .withHooks({
2786
- * onPaymentVerified: async (tx) => { ... },
2787
- * onSubscriptionRenewed: async (sub) => { ... },
2788
- * })
2789
- * ```
2790
- */
2791
2780
  withHooks(hooks) {
2792
- this.hooks = { ...this.hooks, ...hooks };
2781
+ const normalized = {};
2782
+ for (const [event, handlerOrHandlers] of Object.entries(hooks)) {
2783
+ if (!handlerOrHandlers) continue;
2784
+ normalized[event] = Array.isArray(handlerOrHandlers) ? handlerOrHandlers : [handlerOrHandlers];
2785
+ }
2786
+ this.hooks = { ...this.hooks, ...normalized };
2793
2787
  return this;
2794
2788
  }
2795
2789
  /**