@nocobase/app-plugin-message-broker 0.0.0-stage → 0.1.0-beta.1

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 (40) hide show
  1. package/LICENSE.txt +127 -0
  2. package/README.md +33 -2
  3. package/dist/database/migrations/.manifest.json +9 -0
  4. package/dist/database/migrations/202611230001_message_broker_create_outbox_inbox.d.ts +14 -0
  5. package/dist/database/migrations/202611230001_message_broker_create_outbox_inbox.d.ts.map +1 -0
  6. package/dist/database/migrations/202611230001_message_broker_create_outbox_inbox.js +56 -0
  7. package/dist/database/migrations/202611230001_message_broker_create_outbox_inbox.js.map +1 -0
  8. package/dist/server/config.d.ts +16 -0
  9. package/dist/server/config.d.ts.map +1 -0
  10. package/dist/server/config.js +28 -0
  11. package/dist/server/config.js.map +1 -0
  12. package/dist/server/index.d.ts +7 -0
  13. package/dist/server/index.d.ts.map +1 -0
  14. package/dist/server/index.js +6 -0
  15. package/dist/server/index.js.map +1 -0
  16. package/dist/server/plugin.d.ts +4 -0
  17. package/dist/server/plugin.d.ts.map +1 -0
  18. package/dist/server/plugin.js +13 -0
  19. package/dist/server/plugin.js.map +1 -0
  20. package/dist/server/providers/index.d.ts +4 -0
  21. package/dist/server/providers/index.d.ts.map +1 -0
  22. package/dist/server/providers/index.js +6 -0
  23. package/dist/server/providers/index.js.map +1 -0
  24. package/dist/server/providers/message-broker.d.ts +15 -0
  25. package/dist/server/providers/message-broker.d.ts.map +1 -0
  26. package/dist/server/providers/message-broker.js +79 -0
  27. package/dist/server/providers/message-broker.js.map +1 -0
  28. package/dist/server/relay.d.ts +60 -0
  29. package/dist/server/relay.d.ts.map +1 -0
  30. package/dist/server/relay.js +179 -0
  31. package/dist/server/relay.js.map +1 -0
  32. package/dist/server/store.d.ts +45 -0
  33. package/dist/server/store.d.ts.map +1 -0
  34. package/dist/server/store.js +113 -0
  35. package/dist/server/store.js.map +1 -0
  36. package/dist/server/tokens.d.ts +5 -0
  37. package/dist/server/tokens.d.ts.map +1 -0
  38. package/dist/server/tokens.js +4 -0
  39. package/dist/server/tokens.js.map +1 -0
  40. package/package.json +61 -3
package/LICENSE.txt ADDED
@@ -0,0 +1,127 @@
1
+ Updated Date: November 16, 2026
2
+
3
+ NocoBase License Agreement
4
+
5
+ NOCOBASE PTE. LTD., a Singaporean Exempt Private Company Limited by Shares with its principal place of business located at 112 ROBINSON ROAD, #03-01, SINGAPORE ("The Company") https://www.nocobase.com/ issues this License Agreement ("Agreement") to you. You, as an individual or a company ("The User"), will be deemed to voluntarily accept all terms of this Agreement by using NocoBase (including but not limited to obtaining NocoBase source code, installation package, or image in any form, installing and using NocoBase, developing Applications with NocoBase, purchasing NocoBase commercial license and services). If the User does not agree to any term of this Agreement, or cannot accurately understand our interpretation of the relevant terms, please stop using it immediately.
6
+
7
+ This Agreement applies to any use, quotation, contract, invoice, and all software delivered by the Company. The User and the Company or NocoBase's agents need not sign a separate license agreement for the sale and delivery of the software.
8
+
9
+ This Agreement applies to NocoBase 3 and later versions. NocoBase 2 and earlier versions are independent products and remain subject to their original license agreement. Where a NocoBase 2 Commercial Edition user uses NocoBase 3 or later versions under a policy announced by the Company, that use is subject to this Agreement.
10
+
11
+ The Company reserves the right to formulate and modify this Agreement from time to time as needed. If there are changes, the Company will announce them in the form of website announcements, without further individual notification. The changed Agreement will automatically take effect once it is announced, becoming part of this Agreement.
12
+
13
+ ==============
14
+ 1. Definitions
15
+ ==============
16
+
17
+ 1.1 "Software" refers to NocoBase, including its application foundation (Core), its workspace for people and agents building software together (Studio), and the application templates, development standards, and development skills that come with them, together with their source code, installation packages, images, and all their modifications, updates, and upgrades.
18
+
19
+ 1.2 "Community Edition" refers to the free version of the Software provided to the User as open source through public channels.
20
+
21
+ 1.3 "Commercial Edition" refers to the paid version of the Software purchased by the User from the Company or its agents, downloaded through exclusive channels, with additional features and benefits. It consists of two versions: Professional Edition and Enterprise Edition.
22
+
23
+ 1.4 "Application" refers to a specific business use case application serving internal or external customers of the User, developed based on the Software, such as ERP/CRM. Studio is a development tool and is not part of any Application.
24
+
25
+ 1.5 "Customer" refers to the clients who commission the User to develop Applications or purchase the User's Applications.
26
+
27
+ 1.6 "Agent" refers to an AI agent that works with the Software, including the coding agents the User uses to develop Applications and the business agents in Applications.
28
+
29
+ 1.7 "Third-Party Services" refers to the large models, coding agents, cloud services, and other third-party products and services that the User chooses to use with the Software.
30
+
31
+ 1.8 "Third-Party Open Source Software" refers to open source software provided with the Software. They are licensed through various published open source software licenses or copyright notices accompanying such software.
32
+
33
+ ===================================
34
+ 2. Intellectual Property Protection
35
+ ===================================
36
+
37
+ Except for Third-Party Open Source Software, the Company owns all copyrights, trademark rights, patent rights, trade secrets, and other intellectual property rights of the Software, and has registered and protected them in relevant countries and regions according to the "Paris Convention" or "TRIPS Agreement", ensuring that the intellectual property rights of the Software are internationally recognized and protected.
38
+
39
+ The Company claims no intellectual property rights in the business code written by the User or by Agents when developing Applications, or in the User's business data, skills, and knowledge bases. The parts of the Software contained in an Application remain the intellectual property of the Company and are subject to this Agreement.
40
+
41
+ =============
42
+ 3. Disclaimer
43
+ =============
44
+
45
+ 3.1 The User shall not use the Software to engage in activities that contravene applicable laws and regulations or offend against public order or religious prohibitions. All legal liabilities and consequences arising from the User's use shall be borne by the User.
46
+
47
+ 3.2 The Company shall not be liable for any direct, indirect, special, incidental, or consequential damages (including but not limited to loss of profits, business interruption, data loss, or business information disclosure) caused by the User's use of the Software, even if it has been previously informed of the possibility of such damages.
48
+
49
+ 3.3 Code written, content generated, and actions taken by Agents shall be reviewed and accepted by the User before being used in production. All consequences arising from the use of the work of Agents shall be borne by the User.
50
+
51
+ 3.4 Third-Party Services are chosen and paid for by the User and are subject to their own terms. The Company shall not be liable for the availability, output, or data handling of Third-Party Services.
52
+
53
+ ===============
54
+ 4. License Type
55
+ ===============
56
+
57
+ 4.1 This Agreement serves as the unified license agreement for NocoBase Software, applying to both the Community Edition and the Commercial Editions.
58
+
59
+ 4.2 The Community Edition is open source software. This Agreement incorporates and references the full text of the Apache License, Version 2.0 ("Apache-2.0", available at: https://www.apache.org/licenses/LICENSE-2.0 ). Users of the Community Edition must comply with the Apache-2.0 License as well as the supplementary terms set forth in this Agreement. In case of any inconsistency between Apache-2.0 and this Agreement, the supplementary terms of this Agreement shall prevail.
60
+
61
+ 4.3 The features that the Commercial Edition adds to the Community Edition are commercial software of the Company and are not licensed under Apache-2.0. They can only be used under the Commercial License and in accordance with this Agreement.
62
+
63
+ ================================================
64
+ 5. Rights and Obligations of Open Source License
65
+ ================================================
66
+
67
+ 5.1 The Community Edition can be used for commercial purposes, including developing Applications for Customers.
68
+
69
+ 5.2 It is not allowed to remove or change the NocoBase statement "AI + NocoBase" and "Build reliable business systems", or its link to https://www.nocobase.com/, at the bottom left of the interface of any Application, including Applications delivered to Customers, even though the code that displays the statement is part of the Application. If the default layout is replaced, the statement shall be kept at an equally visible position on the main interface of the Application. Pages that can be accessed without signing in and pages embedded in other systems are not subject to this requirement. When the sidebar is collapsed, showing the statement as an icon with a tooltip, as provided by default, meets this requirement. The main LOGO in the upper left corner of the page, the version number, and other information on the interface can be changed.
70
+
71
+ 5.3 It is not allowed to remove or change all intellectual property statements about NocoBase in the code.
72
+
73
+ 5.4 It is not allowed to provide to the public any form of AI application development platform or agent development platform SaaS/PaaS products using the original or modified Software, including Studio.
74
+
75
+ 5.5 It is not allowed to publicly release any plugin, skill, application template, or other extension that provides features identical or substantially similar to those of the Commercial Edition, whether free or paid and whether open source or not, including by publishing it to public code repositories, package registries, marketplaces, or websites, or by providing it to the public as a hosted service. The features of the Commercial Edition are as published on the Company's website. Developing and using such features for the User's own business, or providing them within Applications delivered to Customers, is not subject to this restriction.
76
+
77
+ ===============================
78
+ 6. Rights of Commercial License
79
+ ===============================
80
+
81
+ 6.1 Obtain a permanent commercial license of the Software.
82
+
83
+ 6.2 Can develop Applications for Customers, deploy the completed Applications, including the Commercial Edition features they use, on Customers' servers, or host them and provide them to Customers as a service.
84
+
85
+ 6.3 Customers can use the Commercial Edition features in the Applications delivered to them, within those Applications only, and can continue to develop those Applications on their own or through others.
86
+
87
+ 6.4 Get software upgrades and exclusive technical support during the upgrade validity period. Upgrades and technical support are provided to the User only, and the User can upgrade the Applications delivered to Customers during this period.
88
+
89
+ 6.5 The licensed Software can be used for commercial purposes with no restrictions on the number of Applications, Customers, users, and Agents.
90
+
91
+ 6.6 Can remove or change the NocoBase statement described in 5.2, and the brand, name, link, and other information about NocoBase on the interface of Applications.
92
+
93
+ 6.7 If there are other agreements in the contract for the above rights, the contract agreement shall prevail.
94
+
95
+ ====================================
96
+ 7. Obligations of Commercial License
97
+ ====================================
98
+
99
+ 7.1 It is not allowed to remove or change all intellectual property statements about NocoBase in the code.
100
+
101
+ 7.2 It is not allowed to sell, transfer, lease, share, gift, or distribute the Commercial License. Deploying Applications for Customers under 6.2 is not considered sharing the Commercial License, but the license key, access token, or other credentials of the Commercial License shall not be provided to Customers for any purpose other than deploying and running the Applications delivered to them.
102
+
103
+ 7.3 It is not allowed to sell, transfer, lease, share, or distribute any form of AI application development platform, agent development platform, or developer tools developed based on Software.
104
+
105
+ 7.4 It is not allowed to provide any form of AI application development platform or agent development platform SaaS/PaaS products to the public using the original or modified Software, including Studio.
106
+
107
+ 7.5 It is not allowed to publicly release any plugin, skill, application template, or other extension that provides features identical or substantially similar to those of the Commercial Edition, whether free or paid and whether open source or not, including by publishing it to public code repositories, package registries, marketplaces, or websites, or by providing it to the public as a hosted service. The features of the Commercial Edition are as published on the Company's website. Developing and using such features for the User's own business, or providing them within Applications delivered to Customers, is not subject to this restriction.
108
+
109
+ 7.6 The Commercial Edition can only be used by the User holding the Commercial License, on servers owned or rented by the User. Except for delivering Applications under 6.2, it is not allowed to deploy the Commercial Edition for Customers, or to provide it to Customers or any third party in any form, including as a hosted service. Customers that need the Commercial Edition shall purchase their own Commercial License.
110
+
111
+ 7.7 Customer personnel can take part in requirement confirmation, acceptance, and release approval in the User's Studio for the Applications the User develops for them. This is not considered providing the Commercial Edition to Customers, but it is not allowed to let Customers use the User's Studio to develop their own projects.
112
+
113
+ 7.8 If there is a violation of the above obligations or the terms of this Agreement, the rights owned by the User will be immediately terminated, the paid fees will not be refunded, and the Company reserves the right to pursue the User's legal responsibility.
114
+
115
+ 7.9 If there are other agreements in the contract for the above obligations, the contract agreement shall prevail.
116
+
117
+ =============================================================
118
+ 8. Legal Jurisdiction, Interpretation, and Dispute Resolution
119
+ =============================================================
120
+
121
+ 8.1 Except for Mainland China, the interpretation, application, and all matters related to this agreement are subject to the jurisdiction of Singapore law.
122
+
123
+ 8.2 Any dispute related to this Agreement should first be resolved through friendly negotiation. If the negotiation fails to resolve the dispute, the dispute should be submitted to the International Chamber of Commerce (ICC) for arbitration. The arbitration venue should be Singapore, conducted in English.
124
+
125
+ 8.3 All terms and conditions of this Agreement shall be deemed enforceable to the maximum extent permitted by applicable law. If any term of this Agreement is deemed invalid by any applicable law, the invalidity of that term does not affect the validity of any other term of this Agreement, and it should be deemed that the invalid term has been modified as much as possible to make it valid and enforceable, or if the term cannot be modified, it should be deemed to have been deleted from this Agreement.
126
+
127
+ 8.4 The arbitration award is final, binding on both parties, and can be enforced in any court with jurisdiction.
package/README.md CHANGED
@@ -1,3 +1,34 @@
1
- # Temporary Holding Version
1
+ # @nocobase/app-plugin-message-broker
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Transactional outbox, inbox and outbox relay for the application's message broker (`@nocobase/message-broker`). Register it with `MessageBrokerServiceProvider`; both templates do. It takes no backend of its own: the `messageBroker` section chooses the middleware, and this plugin makes `publish(message, { transaction })` and subscriptions with `inbox: true` work on any of them. It serves business events within one application as much as messages exchanged with other systems.
4
+
5
+ ## What it adds
6
+
7
+ - `messageBrokerOutbox`: a message published inside a transaction, written in that transaction and sent after it commits. A rolled-back transaction leaves no row; a committed row survives a crash and is sent by the next instance that runs a relay round.
8
+ - `messageBrokerInbox`: `(subscription, messageId)` of every message a subscription with `inbox: true` processed, written in the handler's transaction, so a redelivered message is acknowledged without running the handler again. Only writes the handler makes through `context.transaction` share that guarantee, and only within `inboxRetention`; external effects such as HTTP calls or emails need their own idempotency.
9
+ - The relay, started in the provider's `start()` and stopped in its `shutdown()`, before the broker service closes. It runs after every commit that wrote outbox rows and every `pollInterval`. Each run first looks for a due row with one indexed query and no lock; only when one is due does it take the concurrency lock `message-broker:outbox`, so one instance at a time sends a given row. Hourly cleanup takes the lock separately. Several instances need a shared concurrency backend for that; with process-local locks each instance relays on its own and receivers see duplicates, which their `messageId` deduplication absorbs.
10
+
11
+ Sending is at least once: a crash after the middleware confirmed a message and before the row is marked sent sends it again, so consumers deduplicate by `messageId`. The plugin makes a committed message durable in the database; it does not make an in-process backend such as `inMemory` durable. Both tables live on the default database connection; publish inside a transaction on that connection. Times are stored as epoch milliseconds. Message bodies are limited to 64 KB on every database.
12
+
13
+ The `@nocobase/message-broker` README describes delivery semantics, costs and how this plugin fits the service.
14
+
15
+ ## Configuration
16
+
17
+ The optional `messageBrokerOutbox` section, in milliseconds:
18
+
19
+ | Field | Default | Means |
20
+ | ----------------- | --------- | ------------------------------------------------------------------------------------------ |
21
+ | `pollInterval` | 5000 | Time between fallback relay rounds on each instance |
22
+ | `outboxRetention` | 86400000 | How long a sent row is kept for inspection; `0` deletes it at the next hourly cleanup |
23
+ | `inboxRetention` | 604800000 | How long a processed message is remembered: the window in which a redelivery is recognized |
24
+
25
+ A row that cannot be sent is retried after 2 s, doubling up to 5 minutes, without a limit; `attempts` and `lastError` on the row show why it is waiting.
26
+
27
+ ## Verification
28
+
29
+ ```bash
30
+ pnpm --filter @nocobase/app-plugin-message-broker lint
31
+ pnpm --filter @nocobase/app-plugin-message-broker typecheck
32
+ pnpm --filter @nocobase/app-plugin-message-broker test
33
+ pnpm --filter @nocobase/app-plugin-message-broker build
34
+ ```
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": 1,
3
+ "files": {
4
+ "202611230001_message_broker_create_outbox_inbox.js": {
5
+ "sourceChecksum": "37f721b3bfbf239f5225c6b422647e63eab981da4c7d63e17aa2505750de3a67",
6
+ "artifactChecksum": "378112a5271e033bf2f5d3a4f80772913e98bbbda04c5238518db55fb16e79c4"
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,14 @@
1
+ import { type MigrationDefinition } from '@nocobase/db';
2
+ /**
3
+ * The message broker's outbox and inbox.
4
+ *
5
+ * - `messageBrokerOutbox`: one row per message published inside a business transaction, written in that
6
+ * transaction and sent by the relay after it commits. Times are epoch milliseconds so that the relay compares
7
+ * plain integers on every dialect. `sentAt` stays null until the middleware confirmed the message; sent rows are
8
+ * kept for the configured retention so that an operator can check what went out.
9
+ * - `messageBrokerInbox`: one row per message a subscription with the inbox processed, keyed by
10
+ * `(subscription, messageId)`, written in the handler's transaction; the key is the deduplication.
11
+ */
12
+ declare const migration: MigrationDefinition;
13
+ export default migration;
14
+ //# sourceMappingURL=202611230001_message_broker_create_outbox_inbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"202611230001_message_broker_create_outbox_inbox.d.ts","sourceRoot":"","sources":["../../../database/migrations/202611230001_message_broker_create_outbox_inbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEzE;;;;;;;;;GASG;AACH,QAAA,MAAM,SAAS,EAAE,mBA2Cf,CAAC;AAEH,eAAe,SAAS,CAAC"}
@@ -0,0 +1,56 @@
1
+ import { defineMigration } from '@nocobase/db';
2
+ /**
3
+ * The message broker's outbox and inbox.
4
+ *
5
+ * - `messageBrokerOutbox`: one row per message published inside a business transaction, written in that
6
+ * transaction and sent by the relay after it commits. Times are epoch milliseconds so that the relay compares
7
+ * plain integers on every dialect. `sentAt` stays null until the middleware confirmed the message; sent rows are
8
+ * kept for the configured retention so that an operator can check what went out.
9
+ * - `messageBrokerInbox`: one row per message a subscription with the inbox processed, keyed by
10
+ * `(subscription, messageId)`, written in the handler's transaction; the key is the deduplication.
11
+ */
12
+ const migration = defineMigration({
13
+ name: '202611230001_message_broker_create_outbox_inbox',
14
+ async up({ builder }) {
15
+ await builder.createCollection('messageBrokerOutbox', (collection) => {
16
+ collection.bigInt('id').notNull();
17
+ collection.string('publisher', { length: 255 }).notNull();
18
+ collection.string('messageId', { length: 255 }).notNull();
19
+ collection.blob('body').notNull();
20
+ collection.string('contentType', { length: 255 }).nullable();
21
+ collection.json('headers').notNull();
22
+ collection.string('key', { length: 255 }).nullable();
23
+ collection.string('correlationId', { length: 255 }).nullable();
24
+ collection.string('replyTo', { length: 255 }).nullable();
25
+ collection.string('type', { length: 255 }).nullable();
26
+ collection.bigInt('timestamp').notNull();
27
+ collection.integer('attempts').notNull().defaultTo(0);
28
+ collection.bigInt('nextAttemptAt').notNull();
29
+ collection.text('lastError').nullable();
30
+ collection.bigInt('sentAt').nullable();
31
+ collection.primary('id', { name: 'pk_message_broker_outbox' });
32
+ // The relay reads `sentAt IS NULL AND nextAttemptAt <= now`, the cleanup `sentAt < cutoff`.
33
+ collection.index(['sentAt', 'nextAttemptAt'], {
34
+ name: 'idx_message_broker_outbox_pending',
35
+ });
36
+ });
37
+ await builder.createCollection('messageBrokerInbox', (collection) => {
38
+ collection.string('subscription', { length: 255 }).notNull();
39
+ collection.string('messageId', { length: 255 }).notNull();
40
+ collection.bigInt('processedAt').notNull();
41
+ collection.primary(['subscription', 'messageId'], {
42
+ name: 'pk_message_broker_inbox',
43
+ });
44
+ collection.index(['processedAt'], {
45
+ name: 'idx_message_broker_inbox_processed',
46
+ });
47
+ });
48
+ },
49
+ async down({ builder }) {
50
+ await builder.dropCollection('messageBrokerInbox');
51
+ await builder.dropCollection('messageBrokerOutbox');
52
+ },
53
+ });
54
+ export default migration;
55
+ //# sourceMappingURL=202611230001_message_broker_create_outbox_inbox.js.map
56
+ // @nocobase/task-manifest v1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"202611230001_message_broker_create_outbox_inbox.js","sourceRoot":"","sources":["../../../database/migr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AE,OAAO,EAAE;QACpB,MAAM,OAAO,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC;QACnD,MAAM,OAAO,CAAC,cAAc,CAAC,qBAAqB,CAAC,CAAC;IACtD,CAAC;CACF,CAAC,CAAC;AAEH,eAAe,SAAS,CAAC"}
@@ -0,0 +1,16 @@
1
+ /** The `messageBrokerOutbox` configuration section; every field is optional. */
2
+ export interface MessageBrokerOutboxConfig {
3
+ /** Milliseconds between the relay's fallback polls. Defaults to 5 seconds. */
4
+ readonly pollInterval?: number;
5
+ /** Milliseconds sent outbox rows are kept; `0` deletes them at the next hourly cleanup. Defaults to 1 day. */
6
+ readonly outboxRetention?: number;
7
+ /** Milliseconds inbox rows are kept, the window in which a repeated messageId is skipped. Defaults to 7 days. */
8
+ readonly inboxRetention?: number;
9
+ }
10
+ export interface ResolvedMessageBrokerOutboxConfig {
11
+ readonly pollInterval: number;
12
+ readonly outboxRetention: number;
13
+ readonly inboxRetention: number;
14
+ }
15
+ export declare function resolveMessageBrokerOutboxConfig(config: MessageBrokerOutboxConfig | undefined): ResolvedMessageBrokerOutboxConfig;
16
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,MAAM,WAAW,yBAAyB;IACxC,8EAA8E;IAC9E,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,8GAA8G;IAC9G,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,iHAAiH;IACjH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,MAAM,WAAW,iCAAiC;IAChD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAUD,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,yBAAyB,GAAG,SAAS,GAC5C,iCAAiC,CA0BnC"}
@@ -0,0 +1,28 @@
1
+ const DAY = 24 * 60 * 60 * 1000;
2
+ const DEFAULTS = {
3
+ pollInterval: 5000,
4
+ outboxRetention: DAY,
5
+ inboxRetention: 7 * DAY,
6
+ };
7
+ export function resolveMessageBrokerOutboxConfig(config) {
8
+ const value = config ?? {};
9
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
10
+ throw new TypeError('messageBrokerOutbox must be an object.');
11
+ }
12
+ const resolved = { ...DEFAULTS };
13
+ for (const field of Object.keys(value)) {
14
+ if (!(field in DEFAULTS)) {
15
+ throw new TypeError(`messageBrokerOutbox has an unknown field "${field}".`);
16
+ }
17
+ const number = value[field];
18
+ const minimum = field === 'pollInterval' ? 1 : 0;
19
+ if (typeof number !== 'number' ||
20
+ !Number.isInteger(number) ||
21
+ number < minimum) {
22
+ throw new TypeError(`messageBrokerOutbox.${field} must be an integer of at least ${minimum} milliseconds.`);
23
+ }
24
+ resolved[field] = number;
25
+ }
26
+ return resolved;
27
+ }
28
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../server/config.ts"],"names":[],"mappings":"AAgBA,MAAM,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEhC,MAAM,QAAQ,GAAsC;IAClD,YAAY,EAAE,IAAI;IAClB,eAAe,EAAE,GAAG;IACpB,cAAc,EAAE,CAAC,GAAG,GAAG;CACxB,CAAC;AAEF,MAAM,UAAU,gCAAgC,CAC9C,MAA6C;IAE7C,MAAM,KAAK,GAAG,MAAM,IAAI,EAAE,CAAC;IAC3B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACxE,MAAM,IAAI,SAAS,CAAC,wCAAwC,CAAC,CAAC;IAChE,CAAC;IACD,MAAM,QAAQ,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;IACjC,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACvC,IAAI,CAAC,CAAC,KAAK,IAAI,QAAQ,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,SAAS,CACjB,6CAA6C,KAAK,IAAI,CACvD,CAAC;QACJ,CAAC;QACD,MAAM,MAAM,GAAI,KAAiC,CAAC,KAAK,CAAC,CAAC;QACzD,MAAM,OAAO,GAAG,KAAK,KAAK,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACjD,IACE,OAAO,MAAM,KAAK,QAAQ;YAC1B,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;YACzB,MAAM,GAAG,OAAO,EAChB,CAAC;YACD,MAAM,IAAI,SAAS,CACjB,uBAAuB,KAAK,mCAAmC,OAAO,gBAAgB,CACvF,CAAC;QACJ,CAAC;QACA,QAAmC,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC;IACvD,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { default } from './plugin.js';
2
+ export { MessageBrokerOutboxProvider } from './providers/message-broker.js';
3
+ export { messageBrokerOutboxRelayToken } from './tokens.js';
4
+ export { OutboxRelay, backoff, type OutboxRelayOptions, type RelayExclusion, } from './relay.js';
5
+ export { MessageBrokerStore, type MessageBrokerStoreOptions } from './store.js';
6
+ export type { MessageBrokerOutboxConfig, ResolvedMessageBrokerOutboxConfig, } from './config.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,WAAW,EACX,OAAO,EACP,KAAK,kBAAkB,EACvB,KAAK,cAAc,GACpB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,KAAK,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAChF,YAAY,EACV,yBAAyB,EACzB,iCAAiC,GAClC,MAAM,aAAa,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { default } from './plugin.js';
2
+ export { MessageBrokerOutboxProvider } from './providers/message-broker.js';
3
+ export { messageBrokerOutboxRelayToken } from './tokens.js';
4
+ export { OutboxRelay, backoff, } from './relay.js';
5
+ export { MessageBrokerStore } from './store.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,WAAW,EACX,OAAO,GAGR,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAkC,MAAM,YAAY,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type AppServerPlugin } from '@nocobase/app-server/plugins';
2
+ declare const messageBrokerPlugin: AppServerPlugin;
3
+ export default messageBrokerPlugin;
4
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../server/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,8BAA8B,CAAC;AAItC,QAAA,MAAM,mBAAmB,EAAE,eAOzB,CAAC;AAEH,eAAe,mBAAmB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import path from 'node:path';
2
+ import { defineServerPlugin, } from '@nocobase/app-server/plugins';
3
+ import serviceProviders from './providers/index.js';
4
+ const messageBrokerPlugin = defineServerPlugin({
5
+ baseDir: path.resolve(import.meta.dirname, '..'),
6
+ packageName: '@nocobase/app-plugin-message-broker',
7
+ serviceProviders,
8
+ database: {
9
+ migrations: './database/migrations',
10
+ },
11
+ });
12
+ export default messageBrokerPlugin;
13
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../server/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACL,kBAAkB,GAEnB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,gBAAgB,MAAM,sBAAsB,CAAC;AAEpD,MAAM,mBAAmB,GAAoB,kBAAkB,CAAC;IAC9D,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC;IAChD,WAAW,EAAE,qCAAqC;IAClD,gBAAgB;IAChB,QAAQ,EAAE;QACR,UAAU,EAAE,uBAAuB;KACpC;CACF,CAAC,CAAC;AAEH,eAAe,mBAAmB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { AppPluginProviderConstructor } from '@nocobase/app-server/plugins';
2
+ export declare const serviceProviders: readonly AppPluginProviderConstructor[];
3
+ export default serviceProviders;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../server/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAIjF,eAAO,MAAM,gBAAgB,EAAE,SAAS,4BAA4B,EAEnE,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { MessageBrokerOutboxProvider } from './message-broker.js';
2
+ export const serviceProviders = [
3
+ MessageBrokerOutboxProvider,
4
+ ];
5
+ export default serviceProviders;
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/providers/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAElE,MAAM,CAAC,MAAM,gBAAgB,GAA4C;IACvE,2BAA2B;CAC5B,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { AppPluginApplication } from '@nocobase/app-server/plugins';
2
+ import { ServiceProvider } from '@nocobase/service-provider';
3
+ /**
4
+ * Registers the outbox and inbox with the application's message broker service in `boot()`, before the service is
5
+ * set up, and runs the outbox relay from `start()` to `shutdown()`.
6
+ */
7
+ export declare class MessageBrokerOutboxProvider extends ServiceProvider<AppPluginApplication> {
8
+ readonly name: string;
9
+ private relay;
10
+ register(): void;
11
+ boot(): Promise<void>;
12
+ start(): Promise<void>;
13
+ shutdown(): Promise<void>;
14
+ }
15
+ //# sourceMappingURL=message-broker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-broker.d.ts","sourceRoot":"","sources":["../../../server/providers/message-broker.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAGzE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAa7D;;;GAGG;AACH,qBAAa,2BAA4B,SAAQ,eAAe,CAAC,oBAAoB,CAAC;IACpF,SAAgB,IAAI,EAAE,MAAM,CAAyC;IACrE,OAAO,CAAC,KAAK,CAA0B;IAEvB,QAAQ,IAAI,IAAI;IAuChB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAcrB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAMhB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAIhD"}
@@ -0,0 +1,79 @@
1
+ import { concurrencyServiceToken } from '@nocobase/app-plugin-concurrency/server';
2
+ import { idGeneratorToken } from '@nocobase/app-server/id-generator';
3
+ import { loggingToken } from '@nocobase/app-server/logging';
4
+ import { messageBrokerServiceToken } from '@nocobase/app-server/message-broker';
5
+ import { databaseManagerToken } from '@nocobase/db';
6
+ import { ServiceProvider } from '@nocobase/service-provider';
7
+ import { resolveMessageBrokerOutboxConfig, } from '../config.js';
8
+ import { lazyExclusion, OutboxRelay } from '../relay.js';
9
+ import { MessageBrokerStore } from '../store.js';
10
+ import { messageBrokerOutboxRelayToken } from '../tokens.js';
11
+ /** The lock that keeps one outbox round running across every instance. */
12
+ const RELAY_LOCK = 'message-broker:outbox';
13
+ /**
14
+ * Registers the outbox and inbox with the application's message broker service in `boot()`, before the service is
15
+ * set up, and runs the outbox relay from `start()` to `shutdown()`.
16
+ */
17
+ export class MessageBrokerOutboxProvider extends ServiceProvider {
18
+ name = '@nocobase/app-plugin-message-broker';
19
+ relay;
20
+ register() {
21
+ this.app.container.singleton(messageBrokerOutboxRelayToken, (container) => {
22
+ const config = resolveMessageBrokerOutboxConfig(this.app.config.get('messageBrokerOutbox'));
23
+ const logger = container.has(loggingToken)
24
+ ? container
25
+ .resolve(loggingToken)
26
+ .getLogger('message-broker')
27
+ .child({ module: 'message-broker-outbox' })
28
+ : {
29
+ debug: () => undefined,
30
+ info: () => undefined,
31
+ warn: (bindings, message) => console.warn(message, bindings),
32
+ error: (bindings, message) => console.error(message, bindings),
33
+ };
34
+ const exclusive = lazyExclusion(async () => {
35
+ if (!container.has(concurrencyServiceToken)) {
36
+ return async (run) => {
37
+ await run();
38
+ return true;
39
+ };
40
+ }
41
+ const manager = await container
42
+ .resolve(concurrencyServiceToken)
43
+ .getManager();
44
+ const synchronous = await manager.createSynchronous(RELAY_LOCK);
45
+ return async (run) => (await synchronous.tryRun(run, 0)).acquired;
46
+ });
47
+ return new OutboxRelay({
48
+ database: () => container.resolve(databaseManagerToken),
49
+ broker: () => container.resolve(messageBrokerServiceToken),
50
+ exclusive,
51
+ logger,
52
+ ...config,
53
+ });
54
+ });
55
+ }
56
+ boot() {
57
+ const container = this.app.container;
58
+ const relay = container.resolve(messageBrokerOutboxRelayToken);
59
+ const store = new MessageBrokerStore({
60
+ database: () => container.resolve(databaseManagerToken),
61
+ generateId: () => container.resolve(idGeneratorToken).generate(),
62
+ onCommitted: () => relay.kick(),
63
+ });
64
+ const broker = container.resolve(messageBrokerServiceToken);
65
+ broker.registerOutbox(store);
66
+ broker.registerInbox(store);
67
+ return Promise.resolve();
68
+ }
69
+ start() {
70
+ this.relay = this.app.container.resolve(messageBrokerOutboxRelayToken);
71
+ this.relay.start();
72
+ return Promise.resolve();
73
+ }
74
+ async shutdown() {
75
+ await this.relay?.stop();
76
+ this.relay = undefined;
77
+ }
78
+ }
79
+ //# sourceMappingURL=message-broker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-broker.js","sourceRoot":"","sources":["../../../server/providers/message-broker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAClF,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AAEhF,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,EACL,gCAAgC,GAEjC,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAE7D,0EAA0E;AAC1E,MAAM,UAAU,GAAG,uBAAuB,CAAC;AAE3C;;;GAGG;AACH,MAAM,OAAO,2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AA6B,CAAC,CAAC;QACvE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACnB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAEe,KAAK,CAAC,QAAQ;QAC5B,MAAM,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,60 @@
1
+ import type { DatabaseManager } from '@nocobase/db';
2
+ import type { MessageBrokerLogger, MessageBrokerService } from '@nocobase/message-broker';
3
+ /** Runs `tick` only while no other instance runs it; resolves `false` when another instance holds it. */
4
+ export type RelayExclusion = (tick: () => Promise<void>) => Promise<boolean>;
5
+ export interface OutboxRelayOptions {
6
+ readonly database: () => DatabaseManager;
7
+ readonly broker: () => MessageBrokerService;
8
+ readonly exclusive: RelayExclusion;
9
+ readonly logger: MessageBrokerLogger;
10
+ /** Milliseconds between fallback polls. */
11
+ readonly pollInterval: number;
12
+ /** Milliseconds sent outbox rows are kept; `0` deletes them at the next cleanup. */
13
+ readonly outboxRetention: number;
14
+ /** Milliseconds inbox rows are kept: the window in which a repeated messageId is recognized. */
15
+ readonly inboxRetention: number;
16
+ readonly batchSize?: number;
17
+ readonly now?: () => number;
18
+ }
19
+ /**
20
+ * An exclusion created on first use, such as one from the concurrency plugin's lock. Creating it again after a
21
+ * failure keeps a lock backend that was unavailable at startup from failing every later round.
22
+ */
23
+ export declare function lazyExclusion(create: () => Promise<RelayExclusion>): RelayExclusion;
24
+ /** The wait before attempt `attempts + 1`: 2 s, 4 s, 8 s … up to 5 minutes. */
25
+ export declare function backoff(attempts: number): number;
26
+ /**
27
+ * Sends committed outbox rows. Each round reads due rows in ID order, publishes them, marks the confirmed ones sent
28
+ * and schedules the others for a later attempt. Rounds never overlap within the process, and `exclusive` keeps them
29
+ * from overlapping across instances, so each row is sent by one instance at a time.
30
+ */
31
+ export declare class OutboxRelay {
32
+ private readonly options;
33
+ private timer;
34
+ private running;
35
+ private again;
36
+ private stopped;
37
+ private lastCleanup;
38
+ private readonly now;
39
+ private readonly batchSize;
40
+ constructor(options: OutboxRelayOptions);
41
+ start(): void;
42
+ /** Schedules a round; a round already running runs once more after it ends. Never waits. */
43
+ kick(): void;
44
+ /** Resolves once a round is no longer running, for callers that need the outbox drained. */
45
+ idle(): Promise<void>;
46
+ /** Stops polling and waits for the current round. */
47
+ stop(): Promise<void>;
48
+ private loop;
49
+ /**
50
+ * One round: sends due rows when there are any, then cleans up once the cleanup interval passed. The lock is taken
51
+ * only for work: an idle poll is a single indexed read on each instance. Exposed for tests; production code calls
52
+ * `kick()`.
53
+ */
54
+ round(): Promise<void>;
55
+ private due;
56
+ /** Sends one batch of due rows; runs under the lock, so it reads them again. */
57
+ private send;
58
+ private cleanup;
59
+ }
60
+ //# sourceMappingURL=relay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay.d.ts","sourceRoot":"","sources":["../../server/relay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAA6B,MAAM,cAAc,CAAC;AAC/E,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,0BAA0B,CAAC;AAUlC,yGAAyG;AACzG,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAE7E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,eAAe,CAAC;IACzC,QAAQ,CAAC,MAAM,EAAE,MAAM,oBAAoB,CAAC;IAC5C,QAAQ,CAAC,SAAS,EAAE,cAAc,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;IACrC,2CAA2C;IAC3C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,oFAAoF;IACpF,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,gGAAgG;IAChG,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CAC7B;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,OAAO,CAAC,cAAc,CAAC,GACpC,cAAc,CAahB;AAMD,+EAA+E;AAC/E,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;GAIG;AACH,qBAAa,WAAW;IASH,OAAO,CAAC,QAAQ,CAAC,OAAO;IAR3C,OAAO,CAAC,KAAK,CAA6B;IAC1C,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAEC,OAAO,EAAE,kBAAkB;IAKxD,KAAK,IAAI,IAAI;IAQpB,4FAA4F;IACrF,IAAI,IAAI,IAAI;IAWnB,4FAA4F;IAC/E,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIlC,qDAAqD;IACxC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;YAOpB,IAAI;IAclB;;;;OAIG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAerB,GAAG;IAajB,gFAAgF;YAClE,IAAI;YAkDJ,OAAO;CAYtB"}
@@ -0,0 +1,179 @@
1
+ import { decodeOutboxRow, INBOX_COLLECTION, OUTBOX_COLLECTION, truncateError, } from './store.js';
2
+ /**
3
+ * An exclusion created on first use, such as one from the concurrency plugin's lock. Creating it again after a
4
+ * failure keeps a lock backend that was unavailable at startup from failing every later round.
5
+ */
6
+ export function lazyExclusion(create) {
7
+ let created;
8
+ return async (tick) => {
9
+ const pending = (created ??= create());
10
+ let exclusion;
11
+ try {
12
+ exclusion = await pending;
13
+ }
14
+ catch (error) {
15
+ if (created === pending)
16
+ created = undefined;
17
+ throw error;
18
+ }
19
+ return exclusion(tick);
20
+ };
21
+ }
22
+ const DEFAULT_BATCH_SIZE = 100;
23
+ const CLEANUP_INTERVAL_MS = 60 * 60 * 1000;
24
+ const MAX_BACKOFF_MS = 5 * 60 * 1000;
25
+ /** The wait before attempt `attempts + 1`: 2 s, 4 s, 8 s … up to 5 minutes. */
26
+ export function backoff(attempts) {
27
+ return Math.min(2 ** attempts * 1000, MAX_BACKOFF_MS);
28
+ }
29
+ /**
30
+ * Sends committed outbox rows. Each round reads due rows in ID order, publishes them, marks the confirmed ones sent
31
+ * and schedules the others for a later attempt. Rounds never overlap within the process, and `exclusive` keeps them
32
+ * from overlapping across instances, so each row is sent by one instance at a time.
33
+ */
34
+ export class OutboxRelay {
35
+ options;
36
+ timer;
37
+ running;
38
+ again = false;
39
+ stopped = true;
40
+ lastCleanup = 0;
41
+ now;
42
+ batchSize;
43
+ constructor(options) {
44
+ this.options = options;
45
+ this.now = options.now ?? Date.now;
46
+ this.batchSize = options.batchSize ?? DEFAULT_BATCH_SIZE;
47
+ }
48
+ start() {
49
+ if (!this.stopped)
50
+ return;
51
+ this.stopped = false;
52
+ this.timer = setInterval(() => this.kick(), this.options.pollInterval);
53
+ this.timer.unref();
54
+ this.kick();
55
+ }
56
+ /** Schedules a round; a round already running runs once more after it ends. Never waits. */
57
+ kick() {
58
+ if (this.stopped)
59
+ return;
60
+ if (this.running) {
61
+ this.again = true;
62
+ return;
63
+ }
64
+ this.running = this.loop().finally(() => {
65
+ this.running = undefined;
66
+ });
67
+ }
68
+ /** Resolves once a round is no longer running, for callers that need the outbox drained. */
69
+ async idle() {
70
+ while (this.running)
71
+ await this.running;
72
+ }
73
+ /** Stops polling and waits for the current round. */
74
+ async stop() {
75
+ this.stopped = true;
76
+ if (this.timer)
77
+ clearInterval(this.timer);
78
+ this.timer = undefined;
79
+ await this.idle();
80
+ }
81
+ async loop() {
82
+ do {
83
+ this.again = false;
84
+ try {
85
+ await this.round();
86
+ }
87
+ catch (error) {
88
+ this.options.logger.error({ error: truncateError(error) }, 'Message broker outbox relay round failed.');
89
+ }
90
+ } while (this.again && !this.stopped);
91
+ }
92
+ /**
93
+ * One round: sends due rows when there are any, then cleans up once the cleanup interval passed. The lock is taken
94
+ * only for work: an idle poll is a single indexed read on each instance. Exposed for tests; production code calls
95
+ * `kick()`.
96
+ */
97
+ async round() {
98
+ const database = this.options.database();
99
+ const outbox = database.repository(OUTBOX_COLLECTION);
100
+ if ((await this.due(outbox, 1)).length > 0) {
101
+ await this.options.exclusive(() => this.send(outbox));
102
+ }
103
+ const now = this.now();
104
+ if (now - this.lastCleanup >= CLEANUP_INTERVAL_MS) {
105
+ // Another instance holding the lock is sending; this one cleans up at its next round instead.
106
+ if (await this.options.exclusive(() => this.cleanup(database, now))) {
107
+ this.lastCleanup = now;
108
+ }
109
+ }
110
+ }
111
+ async due(outbox, limit) {
112
+ const now = this.now();
113
+ return await outbox.findMany({
114
+ filter: (f) => f.and([f.number('sentAt').empty(), f.number('nextAttemptAt').lte(now)]),
115
+ sort: (sort) => sort.field('id').asc(),
116
+ limit,
117
+ });
118
+ }
119
+ /** Sends one batch of due rows; runs under the lock, so it reads them again. */
120
+ async send(outbox) {
121
+ const rows = await this.due(outbox, this.batchSize);
122
+ const broker = this.options.broker();
123
+ const sent = [];
124
+ // A failed message holds back later ones with the same publisher and key within this round.
125
+ const blocked = new Set();
126
+ for (const row of rows) {
127
+ const order = row.key === null ? undefined : `${row.publisher}\0${row.key}`;
128
+ if (order !== undefined && blocked.has(order))
129
+ continue;
130
+ try {
131
+ await broker.publishEncoded(row.publisher, decodeOutboxRow(row));
132
+ sent.push(row.id);
133
+ }
134
+ catch (error) {
135
+ if (order !== undefined)
136
+ blocked.add(order);
137
+ const attempts = Number(row.attempts) + 1;
138
+ const lastError = truncateError(error);
139
+ this.options.logger.warn({
140
+ publisher: row.publisher,
141
+ messageId: row.messageId,
142
+ attempts,
143
+ error: lastError,
144
+ }, 'Message broker outbox could not send a message; it will retry.');
145
+ await outbox.updateOne({
146
+ filter: (f) => f.number('id').eq(row.id),
147
+ values: {
148
+ attempts,
149
+ nextAttemptAt: this.now() + backoff(attempts),
150
+ lastError,
151
+ },
152
+ });
153
+ }
154
+ }
155
+ if (sent.length > 0) {
156
+ const sentAt = this.now();
157
+ await outbox.updateMany({
158
+ filter: (f) => f.and([
159
+ f.or(sent.map((id) => f.number('id').eq(id))),
160
+ f.number('sentAt').empty(),
161
+ ]),
162
+ values: { sentAt, lastError: null },
163
+ });
164
+ }
165
+ if (rows.length === this.batchSize)
166
+ this.again = true;
167
+ }
168
+ async cleanup(database, now) {
169
+ await database.repository(OUTBOX_COLLECTION).deleteMany({
170
+ filter: (f) => f.number('sentAt').lte(now - this.options.outboxRetention),
171
+ });
172
+ await database
173
+ .repository(INBOX_COLLECTION)
174
+ .deleteMany({
175
+ filter: (f) => f.number('processedAt').lt(now - this.options.inboxRetention),
176
+ });
177
+ }
178
+ }
179
+ //# sourceMappingURL=relay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay.js","sourceRoot":"","sources":["../../server/relay.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,GAEd,MAAM,YAAY,CAAC;AAoBpB;;;GAGG;AACH,MAAM,UAAU,aAAa,CAC3B,MAAqC;IAErC,IAAI,OAA4C,CAAC;IACjD,OAAO,KAAK,EAAE,IAAI,EAAE,EAAE;QACpB,MAAM,OAAO,GAAG,CAAC,OAAO,KAAK,MAAM,EAAE,CAAC,CAAC;QACvC,IAAI,SAAyB,CAAC;QAC9B,IAAI,CAAC;YACH,SAAS,GAAG,MAAM,OAAO,CAAC;QAC5B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,OAAO,KAAK,OAAO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0B,gBAAgB,CAAC;aACrD,UAAU,CAAC;YACV,MAAM,EAAE,CAAC,CAAyC,EAAE,EAAE,CACpD,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC;SAChE,CAAC,CAAC;IACP,CAAC;CACF"}
@@ -0,0 +1,45 @@
1
+ import { type DatabaseManager } from '@nocobase/db';
2
+ import type { BrokerTransaction, EncodedMessage, InboxOutcome, MessageInbox, MessageOutbox } from '@nocobase/message-broker';
3
+ export declare const OUTBOX_COLLECTION = "messageBrokerOutbox";
4
+ export declare const INBOX_COLLECTION = "messageBrokerInbox";
5
+ /**
6
+ * Largest body the outbox stores. MySQL's BLOB holds 64 KB; the same limit applies on every dialect so that a message
7
+ * accepted on one database is accepted on all of them.
8
+ */
9
+ export declare const MAX_OUTBOX_BODY_BYTES = 65535;
10
+ export interface OutboxRow {
11
+ readonly id: number | string;
12
+ readonly publisher: string;
13
+ readonly messageId: string;
14
+ readonly body: Uint8Array;
15
+ readonly contentType: string | null;
16
+ readonly headers: Record<string, string>;
17
+ readonly key: string | null;
18
+ readonly correlationId: string | null;
19
+ readonly replyTo: string | null;
20
+ readonly type: string | null;
21
+ readonly timestamp: number | string;
22
+ readonly attempts: number;
23
+ readonly nextAttemptAt: number | string;
24
+ readonly lastError: string | null;
25
+ readonly sentAt: number | string | null;
26
+ }
27
+ export interface MessageBrokerStoreOptions {
28
+ readonly database: () => DatabaseManager;
29
+ /** A unique, roughly increasing ID for each outbox row. */
30
+ readonly generateId: () => number;
31
+ /** Called after the transaction that wrote outbox rows committed. */
32
+ readonly onCommitted: () => void;
33
+ readonly now?: () => number;
34
+ }
35
+ export declare function decodeOutboxRow(row: OutboxRow): EncodedMessage;
36
+ export declare function truncateError(error: unknown): string;
37
+ /** The outbox and inbox on the application's default database connection. */
38
+ export declare class MessageBrokerStore implements MessageOutbox, MessageInbox {
39
+ private readonly options;
40
+ private readonly now;
41
+ constructor(options: MessageBrokerStoreOptions);
42
+ enqueue(transaction: BrokerTransaction, publisher: string, message: EncodedMessage): Promise<void>;
43
+ process<T>(subscription: string, messageId: string, run: (transaction: unknown) => Promise<T>): Promise<InboxOutcome<T>>;
44
+ }
45
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../server/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,aAAa,EACd,MAAM,0BAA0B,CAAC;AAElC,eAAO,MAAM,iBAAiB,wBAAwB,CAAC;AACvD,eAAO,MAAM,gBAAgB,uBAAuB,CAAC;AAKrD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,QAAS,CAAC;AAE5C,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC;IACxC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CACzC;AAED,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,QAAQ,EAAE,MAAM,eAAe,CAAC;IACzC,2DAA2D;IAC3D,QAAQ,CAAC,UAAU,EAAE,MAAM,MAAM,CAAC;IAClC,qEAAqE;IACrE,QAAQ,CAAC,WAAW,EAAE,MAAM,IAAI,CAAC;IACjC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CAC7B;AAWD,wBAAgB,eAAe,CAAC,GAAG,EAAE,SAAS,GAAG,cAAc,CAY9D;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAKpD;AAED,6EAA6E;AAC7E,qBAAa,kBAAmB,YAAW,aAAa,EAAE,YAAY;IAGjD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAF3C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;gBAEC,OAAO,EAAE,yBAAyB;IAIzD,OAAO,CAClB,WAAW,EAAE,iBAAiB,EAC9B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,IAAI,CAAC;IAqDH,OAAO,CAAC,CAAC,EACpB,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,CAAC,WAAW,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,GACxC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;CAqB5B"}
@@ -0,0 +1,113 @@
1
+ import { isUniqueConstraintViolation, } from '@nocobase/db';
2
+ export const OUTBOX_COLLECTION = 'messageBrokerOutbox';
3
+ export const INBOX_COLLECTION = 'messageBrokerInbox';
4
+ /** Longest `lastError` kept on an outbox row. */
5
+ const LAST_ERROR_LENGTH = 1024;
6
+ /**
7
+ * Largest body the outbox stores. MySQL's BLOB holds 64 KB; the same limit applies on every dialect so that a message
8
+ * accepted on one database is accepted on all of them.
9
+ */
10
+ export const MAX_OUTBOX_BODY_BYTES = 65_535;
11
+ function isConnection(value) {
12
+ return (typeof value === 'object' &&
13
+ value !== null &&
14
+ typeof value.repository === 'function' &&
15
+ typeof value.afterCommit === 'function');
16
+ }
17
+ export function decodeOutboxRow(row) {
18
+ return {
19
+ body: Buffer.from(row.body),
20
+ headers: row.headers ?? {},
21
+ messageId: row.messageId,
22
+ timestamp: new Date(Number(row.timestamp)),
23
+ ...(row.contentType === null ? {} : { contentType: row.contentType }),
24
+ ...(row.key === null ? {} : { key: row.key }),
25
+ ...(row.correlationId === null ? {} : { correlationId: row.correlationId }),
26
+ ...(row.replyTo === null ? {} : { replyTo: row.replyTo }),
27
+ ...(row.type === null ? {} : { type: row.type }),
28
+ };
29
+ }
30
+ export function truncateError(error) {
31
+ const message = error instanceof Error ? error.message : String(error);
32
+ return message.length > LAST_ERROR_LENGTH
33
+ ? message.slice(0, LAST_ERROR_LENGTH)
34
+ : message;
35
+ }
36
+ /** The outbox and inbox on the application's default database connection. */
37
+ export class MessageBrokerStore {
38
+ options;
39
+ now;
40
+ constructor(options) {
41
+ this.options = options;
42
+ this.now = options.now ?? Date.now;
43
+ }
44
+ async enqueue(transaction, publisher, message) {
45
+ if (!isConnection(transaction)) {
46
+ throw new TypeError('The outbox takes a database transaction connection, such as the one database.transaction() passes to its callback.');
47
+ }
48
+ const defaultConnection = this.options.database().connection().name;
49
+ if (transaction.name !== defaultConnection) {
50
+ throw new Error(`The outbox lives on the "${defaultConnection}" connection; publish inside a transaction on it, not on "${transaction.name}".`);
51
+ }
52
+ // Outside a transaction, afterCommit() runs its callback at once; a row written through such a connection would
53
+ // stay behind when the caller's business transaction rolls back.
54
+ let committed = false;
55
+ transaction.afterCommit(() => {
56
+ committed = true;
57
+ });
58
+ if (committed) {
59
+ throw new TypeError('The outbox takes the connection database.transaction() passes to its callback; the connection given is not inside a transaction.');
60
+ }
61
+ if (message.body.length > MAX_OUTBOX_BODY_BYTES) {
62
+ throw new RangeError(`Message "${message.messageId}" has a ${message.body.length}-byte body; the outbox stores bodies of up to ${MAX_OUTBOX_BODY_BYTES} bytes. Publish a reference to the data instead.`);
63
+ }
64
+ const now = this.now();
65
+ await transaction.repository(OUTBOX_COLLECTION).createOne({
66
+ values: {
67
+ id: this.options.generateId(),
68
+ publisher,
69
+ messageId: message.messageId,
70
+ body: message.body,
71
+ contentType: message.contentType ?? null,
72
+ headers: { ...message.headers },
73
+ key: message.key ?? null,
74
+ correlationId: message.correlationId ?? null,
75
+ replyTo: message.replyTo ?? null,
76
+ type: message.type ?? null,
77
+ timestamp: message.timestamp.getTime(),
78
+ attempts: 0,
79
+ nextAttemptAt: now,
80
+ lastError: null,
81
+ sentAt: null,
82
+ },
83
+ });
84
+ // The relay only gets scheduled here: transaction() resolves after its commit callbacks, so waiting for the
85
+ // middleware in one would hold the business request.
86
+ transaction.afterCommit(() => this.options.onCommitted());
87
+ }
88
+ async process(subscription, messageId, run) {
89
+ let duplicate = false;
90
+ try {
91
+ return await this.options.database().transaction(async (transaction) => {
92
+ try {
93
+ await transaction.repository(INBOX_COLLECTION).createOne({
94
+ values: { subscription, messageId, processedAt: this.now() },
95
+ });
96
+ }
97
+ catch (error) {
98
+ // Only the inbox row's own key counts as a duplicate; a unique violation from the handler's writes is a
99
+ // failure that retries.
100
+ duplicate = isUniqueConstraintViolation(error);
101
+ throw error;
102
+ }
103
+ return { duplicate: false, value: await run(transaction) };
104
+ });
105
+ }
106
+ catch (error) {
107
+ if (duplicate)
108
+ return { duplicate: true };
109
+ throw error;
110
+ }
111
+ }
112
+ }
113
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../server/store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2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AAW,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAC5D,CAAC;IAEM,KAAK,CAAC,OAAO,CAClB,YAAoB,EACpB,SAAiB,EACjB,GAAyC;QAEzC,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;gBACrE,IAAI,CAAC;oBACH,MAAM,WAAW,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC,SAAS,CAAC;wBACvD,MAAM,EAAE,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE;qBAC7D,CAAC,CAAC;gBACL,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,wGAAwG;oBACxG,wBAAwB;oBACxB,SAAS,GAAG,2BAA2B,CAAC,KAAK,CAAC,CAAC;oBAC/C,MAAM,KAAK,CAAC;gBACd,CAAC;gBACD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YAC7D,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,SAAS;gBAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;YAC1C,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ import { type ServiceToken } from '@nocobase/service-provider';
2
+ import type { OutboxRelay } from './relay.js';
3
+ /** The outbox relay of this application. Tests use it to wait until committed messages were sent. */
4
+ export declare const messageBrokerOutboxRelayToken: ServiceToken<OutboxRelay>;
5
+ //# sourceMappingURL=tokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../server/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EAClB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,qGAAqG;AACrG,eAAO,MAAM,6BAA6B,EAAE,YAAY,CAAC,WAAW,CACU,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { createServiceToken, } from '@nocobase/service-provider';
2
+ /** The outbox relay of this application. Tests use it to wait until committed messages were sent. */
3
+ export const messageBrokerOutboxRelayToken = createServiceToken('@nocobase/app-plugin-message-broker/relay');
4
+ //# sourceMappingURL=tokens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../server/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAEnB,MAAM,4BAA4B,CAAC;AAIpC,qGAAqG;AACrG,MAAM,CAAC,MAAM,6BAA6B,GACxC,kBAAkB,CAAc,2CAA2C,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,64 @@
1
1
  {
2
2
  "name": "@nocobase/app-plugin-message-broker",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "displayName": "Message Broker App Plugin",
4
+ "description": "Transactional outbox, inbox and outbox relay for the application message broker.",
5
+ "version": "0.1.0-beta.1",
6
+ "type": "module",
7
+ "prettier": "@nocobase/dev-config/prettier",
8
+ "engines": {
9
+ "node": ">=24.0.0"
10
+ },
11
+ "nocobase": {
12
+ "pluginPolicy": "preinstall-and-enable",
13
+ "title": {
14
+ "en-US": "Message broker",
15
+ "zh-CN": "消息代理"
16
+ },
17
+ "description": {
18
+ "en-US": "Transactional outbox and inbox for publishing business events and consuming messages idempotently",
19
+ "zh-CN": "用于事务内发布业务事件与幂等消费消息的发件箱与收件箱"
20
+ }
21
+ },
22
+ "sideEffects": false,
23
+ "exports": {
24
+ "./server": {
25
+ "types": "./dist/server/index.d.ts",
26
+ "import": "./dist/server/index.js"
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "README.md"
33
+ ],
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "peerDependencies": {
38
+ "@nocobase/app-plugin-concurrency": "^0.1.0-beta.5",
39
+ "@nocobase/app-server": "^5.0.0-beta.12",
40
+ "@nocobase/db": "^1.0.0-beta.31",
41
+ "@nocobase/message-broker": "^0.1.0-beta.0",
42
+ "@nocobase/service-provider": "^0.0.2-beta.2"
43
+ },
44
+ "devDependencies": {
45
+ "@types/node": "^24.0.0",
46
+ "eslint": "^10.0.0",
47
+ "prettier": "^3.9.6",
48
+ "typescript": "^6.0.3",
49
+ "vitest": "^4.1.10",
50
+ "@nocobase/app-testing": "0.1.0-beta.11",
51
+ "@nocobase/dev-config": "0.1.0-beta.26"
52
+ },
53
+ "scripts": {
54
+ "build": "node ./scripts/clean-dist.mjs && tsc -p tsconfig.json && nocobase-db-manifests",
55
+ "typecheck": "tsc -p tsconfig.json --noEmit",
56
+ "test": "vitest run --passWithNoTests",
57
+ "lint": "eslint . --max-warnings 0",
58
+ "lint:fix": "eslint . --fix --max-warnings 0",
59
+ "format": "prettier . --write",
60
+ "format:check": "prettier . --check",
61
+ "check": "pnpm lint && pnpm format:check && pnpm typecheck && pnpm test && pnpm build",
62
+ "fix": "pnpm lint:fix && pnpm format"
63
+ }
6
64
  }