@nocobase/audit 0.0.0-stage → 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +127 -0
- package/README.md +33 -2
- package/dist/config.d.ts +25 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +59 -0
- package/dist/config.js.map +1 -0
- package/dist/file-transport.d.ts +3 -0
- package/dist/file-transport.d.ts.map +1 -0
- package/dist/file-transport.js +121 -0
- package/dist/file-transport.js.map +1 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/ip.d.ts +4 -0
- package/dist/ip.d.ts.map +1 -0
- package/dist/ip.js +36 -0
- package/dist/ip.js.map +1 -0
- package/dist/locales/de-DE.d.ts +4 -0
- package/dist/locales/de-DE.d.ts.map +1 -0
- package/dist/locales/de-DE.js +11 -0
- package/dist/locales/de-DE.js.map +1 -0
- package/dist/locales/en-US.d.ts +13 -0
- package/dist/locales/en-US.d.ts.map +1 -0
- package/dist/locales/en-US.js +11 -0
- package/dist/locales/en-US.js.map +1 -0
- package/dist/locales/es-ES.d.ts +4 -0
- package/dist/locales/es-ES.d.ts.map +1 -0
- package/dist/locales/es-ES.js +11 -0
- package/dist/locales/es-ES.js.map +1 -0
- package/dist/locales/fr-FR.d.ts +4 -0
- package/dist/locales/fr-FR.d.ts.map +1 -0
- package/dist/locales/fr-FR.js +11 -0
- package/dist/locales/fr-FR.js.map +1 -0
- package/dist/locales/id-ID.d.ts +4 -0
- package/dist/locales/id-ID.d.ts.map +1 -0
- package/dist/locales/id-ID.js +11 -0
- package/dist/locales/id-ID.js.map +1 -0
- package/dist/locales/index.d.ts +4 -0
- package/dist/locales/index.d.ts.map +1 -0
- package/dist/locales/index.js +16 -0
- package/dist/locales/index.js.map +1 -0
- package/dist/locales/ja-JP.d.ts +4 -0
- package/dist/locales/ja-JP.d.ts.map +1 -0
- package/dist/locales/ja-JP.js +11 -0
- package/dist/locales/ja-JP.js.map +1 -0
- package/dist/locales/ko-KR.d.ts +4 -0
- package/dist/locales/ko-KR.d.ts.map +1 -0
- package/dist/locales/ko-KR.js +11 -0
- package/dist/locales/ko-KR.js.map +1 -0
- package/dist/locales/pt-BR.d.ts +4 -0
- package/dist/locales/pt-BR.d.ts.map +1 -0
- package/dist/locales/pt-BR.js +11 -0
- package/dist/locales/pt-BR.js.map +1 -0
- package/dist/locales/ru-RU.d.ts +4 -0
- package/dist/locales/ru-RU.d.ts.map +1 -0
- package/dist/locales/ru-RU.js +11 -0
- package/dist/locales/ru-RU.js.map +1 -0
- package/dist/locales/vi-VN.d.ts +4 -0
- package/dist/locales/vi-VN.d.ts.map +1 -0
- package/dist/locales/vi-VN.js +11 -0
- package/dist/locales/vi-VN.js.map +1 -0
- package/dist/locales/zh-CN.d.ts +4 -0
- package/dist/locales/zh-CN.d.ts.map +1 -0
- package/dist/locales/zh-CN.js +11 -0
- package/dist/locales/zh-CN.js.map +1 -0
- package/dist/locales/zh-TW.d.ts +4 -0
- package/dist/locales/zh-TW.d.ts.map +1 -0
- package/dist/locales/zh-TW.js +11 -0
- package/dist/locales/zh-TW.js.map +1 -0
- package/dist/redact.d.ts +12 -0
- package/dist/redact.d.ts.map +1 -0
- package/dist/redact.js +141 -0
- package/dist/redact.js.map +1 -0
- package/dist/repository.d.ts +4 -0
- package/dist/repository.d.ts.map +1 -0
- package/dist/repository.js +23 -0
- package/dist/repository.js.map +1 -0
- package/dist/request.d.ts +75 -0
- package/dist/request.d.ts.map +1 -0
- package/dist/request.js +291 -0
- package/dist/request.js.map +1 -0
- package/dist/runtime.d.ts +13 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +79 -0
- package/dist/runtime.js.map +1 -0
- package/dist/service.d.ts +48 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +136 -0
- package/dist/service.js.map +1 -0
- package/package.json +60 -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
|
-
#
|
|
1
|
+
# NocoBase Audit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@nocobase/audit` provides request auditing, route declarations, and event delivery. The application supplies this package as a production dependency. The official application templates include its provider and the built-in `file` driver. An application assembled separately with `@nocobase/app-server` can add `AuditProvider` from `@nocobase/audit/runtime` with `app.addServiceProvider(AuditProvider)` in its server composition root. Add it after the other providers and runtime contributions so its transports close before the services they use. Register `defineAuditConfig()` from `@nocobase/audit` in the application config factories. Plugins that import its route declarations or service token declare a peer dependency on `@nocobase/audit`.
|
|
4
|
+
|
|
5
|
+
## Configuration
|
|
6
|
+
|
|
7
|
+
Add the `audit` section to the application's `config.yaml`:
|
|
8
|
+
|
|
9
|
+
```yaml
|
|
10
|
+
audit:
|
|
11
|
+
transports:
|
|
12
|
+
localFile:
|
|
13
|
+
driver: file
|
|
14
|
+
options:
|
|
15
|
+
path: logs/audit.jsonl
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
With at least one destination, `audit.enabled` defaults to `true` and the app records explicitly declared operations. `audit.enabled: false` disables collection and delivery. `audit.autoDetect` defaults to `false`. Enable it to also record documented POST, PATCH, PUT, and DELETE operations that have an operation ID and are visible in the API document. An explicit `describeAudit(false)` excludes a route. A dynamic declaration that returns `undefined` leaves the route eligible for automatic detection. The audit provider reads generated Repository endpoint metadata before guards, records mutations, and excludes queries.
|
|
19
|
+
|
|
20
|
+
Relative file paths resolve under application storage. Absolute paths are supported. The driver creates directories with mode `0700` and opens files with mode `0600` on POSIX, subject to the process umask. Destinations that share a local file serialize appends within one process. Each file must have a single writer process. Complete records are written as JSON Lines and the file handle closes after each append. Use your deployment's log management for file rotation and retention.
|
|
21
|
+
|
|
22
|
+
Audit uses `auth.advanced.ipAddress.trustedProxies` and `auth.advanced.ipAddress.ipAddressHeaders`. For a trusted socket peer, it tries the configured headers in order, defaulting to `X-Forwarded-For`, and walks each chain from right to left to its first untrusted address. Invalid proxy entries are skipped with a startup warning. An untrusted peer, an empty allowlist, or a chain with no usable client address results in the socket peer address.
|
|
23
|
+
|
|
24
|
+
## Routes and transports
|
|
25
|
+
|
|
26
|
+
Audit events store the operation's declared name or its English default, with API summary and action as fallbacks. The name is independent of the request language. JSON Lines contains the event as recorded, including any `operationNameI18n` namespace and key.
|
|
27
|
+
|
|
28
|
+
The official templates contribute the lazy loader from `@nocobase/audit/locales` as a locales-only entry in their client plugin list. Custom applications can add the same entry with `defineClientPlugin({ packageName: '@nocobase/audit', locales: auditLocales })()` before client initialization. Installed business plugins provide their labels through their own locale contributions. Resolve `operationNameI18n` in the viewer's language, falling back to the stored `operationName`, then `action` for older events. The audit provider also registers the Repository labels on the server for localized exports.
|
|
29
|
+
|
|
30
|
+
Import `describeAudit` from `@nocobase/audit` and declare it alongside the route. Set an action, resource, and optional operation name for display. Use `target` for identifiers available before guards and `resolveTargets` for identifiers derived from a successful handler result. Use `captureBody: false` to omit both snapshots and `redact` to mask additional fields with `{ field: 'name' }` or paths with `{ path: 'parent.name' }`. The built-in credential masking and snapshot limits always apply.
|
|
31
|
+
|
|
32
|
+
In a service provider's `register` or `boot`, resolve `auditServiceToken` and register the transport with `registerDriver({ name, createTransport })`. Configure each named destination under `audit.transports` with its driver and driver-specific options. The synchronous factory receives the options and `{ name, paths }`, with the application storage directory available as `paths.storageDir`. The transport implements `write(event, { signal })` and can implement `close()` to release resources. The application validates active destination names, drivers, and factory options at startup. The commercial audit plugin supplies the `database` driver, which can be configured alongside `file`.
|
|
33
|
+
|
|
34
|
+
The coordinator delivers independent copies of the sanitized event in parallel. It bounds pending writes, signals timeouts through `AbortSignal`, and invokes transport cleanup as part of shutdown. A transport failure leaves the HTTP response intact. Audit records the HTTP outcome after the handler runs, independently of the business transaction. A process failure can lose an event awaiting delivery.
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface AuditDestinationConfig {
|
|
2
|
+
readonly driver: string;
|
|
3
|
+
readonly options?: Readonly<Record<string, unknown>>;
|
|
4
|
+
}
|
|
5
|
+
export interface AuditConfig {
|
|
6
|
+
readonly enabled?: boolean;
|
|
7
|
+
readonly autoDetect?: boolean;
|
|
8
|
+
readonly transports?: Readonly<Record<string, AuditDestinationConfig>>;
|
|
9
|
+
}
|
|
10
|
+
export declare const auditDefaults: Required<Pick<AuditConfig, 'enabled' | 'autoDetect'>>;
|
|
11
|
+
export declare function isAuditName(value: unknown): value is string;
|
|
12
|
+
export declare function validateAuditConfig(value: unknown, error: (path: string, message: string) => void): void;
|
|
13
|
+
export declare function defineAuditConfig(defaults?: AuditConfig): AuditConfigFactory;
|
|
14
|
+
export interface AuditConfigFactory {
|
|
15
|
+
(): AuditConfig;
|
|
16
|
+
readonly rules: {
|
|
17
|
+
readonly public: readonly string[];
|
|
18
|
+
readonly validators: readonly (typeof validateSection)[];
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
declare function validateSection(value: unknown, context: {
|
|
22
|
+
error(path: string, message: string): void;
|
|
23
|
+
}): void;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACtD;AAED,M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
|
+
return typeof value === 'string' && validName.test(value);
|
|
8
|
+
}
|
|
9
|
+
function isMapping(value) {
|
|
10
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
11
|
+
}
|
|
12
|
+
export function validateAuditConfig(value, error) {
|
|
13
|
+
if (!isMapping(value)) {
|
|
14
|
+
error('', 'must be a mapping.');
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
for (const key of Object.keys(value)) {
|
|
18
|
+
if (!['enabled', 'autoDetect', 'transports'].includes(key))
|
|
19
|
+
error(key, 'is not an audit setting.');
|
|
20
|
+
}
|
|
21
|
+
for (const key of ['enabled', 'autoDetect']) {
|
|
22
|
+
if (value[key] !== undefined && typeof value[key] !== 'boolean')
|
|
23
|
+
error(key, 'must be a boolean.');
|
|
24
|
+
}
|
|
25
|
+
if (value.transports === undefined)
|
|
26
|
+
return;
|
|
27
|
+
if (!isMapping(value.transports)) {
|
|
28
|
+
error('transports', 'must be a mapping.');
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
for (const [name, destination] of Object.entries(value.transports)) {
|
|
32
|
+
if (!isAuditName(name)) {
|
|
33
|
+
error('transports', 'contains an invalid destination name.');
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const path = `transports.${name}`;
|
|
37
|
+
if (!isMapping(destination) || !isAuditName(destination.driver)) {
|
|
38
|
+
error(path, 'requires a valid driver name.');
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (Object.keys(destination).some((key) => key !== 'driver' && key !== 'options'))
|
|
42
|
+
error(path, 'accepts only driver and options.');
|
|
43
|
+
if (destination.options !== undefined && !isMapping(destination.options))
|
|
44
|
+
error(`${path}.options`, 'must be a mapping.');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export function defineAuditConfig(defaults = {}) {
|
|
48
|
+
const values = { ...auditDefaults, ...defaults };
|
|
49
|
+
return Object.assign(() => values, {
|
|
50
|
+
rules: Object.freeze({
|
|
51
|
+
public: Object.freeze([]),
|
|
52
|
+
validators: Object.freeze([validateSection]),
|
|
53
|
+
}),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function validateSection(value, context) {
|
|
57
|
+
validateAuditConfig(value, (path, message) => context.error(path, message));
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,aAAa,GAEtB;IACF,OAAO,EAAE,IAAI;IACb,UAAU,EAAE,KAAK;CAClB,CAAC;AAEF,MAAM,SAAS,GAAG,oCAAoC,CAAC;AAEvD,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC5D,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,KAAc,EACd,KAA8C;IAE9C,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QACtB,KAAK,CAAC,EAAE,EAAE,oBAAoB,CAAC,CAAC;QAChC,OAAO;IACT,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACrC,IAAI,CAAC,CAAC,SAAS,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;YACxD,KAAK,CAAC,GAAG,EAAE,0BAA0B,CAAC,CAAC;IAC3C,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,EAAE,CAAC;QAC5C,IAAI,KAAK,CA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AM,GAAG,EAAE,GAAG,aAAa,EAAE,GAAG,QAAQ,EAAE,CAAC;IACjD,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE;QACjC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;YACnB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;YACzB,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC;SAC7C,CAAC;KACH,CAAC,CAAC;AACL,CAAC;AAUD,SAAS,eAAe,CACtB,KAAc,EACd,OAAuD;IAEvD,mBAAmB,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-transport.d.ts","sourceRoot":"","sources":["../src/file-transport.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AA4FvD,eAAO,MAAM,eAAe,EAAE,oBAyD7B,CAAC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import { mkdir, open, realpath } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
// Named destinations can point to the same file. Serialize across them and across applications in this process.
|
|
5
|
+
const queues = new Map();
|
|
6
|
+
const maxPendingAppends = 64;
|
|
7
|
+
function within(root, target) {
|
|
8
|
+
const relative = path.relative(root, target);
|
|
9
|
+
return (relative !== '..' &&
|
|
10
|
+
!relative.startsWith(`..${path.sep}`) &&
|
|
11
|
+
!path.isAbsolute(relative));
|
|
12
|
+
}
|
|
13
|
+
async function append(file, line) {
|
|
14
|
+
const handle = await open(file, constants.O_APPEND |
|
|
15
|
+
constants.O_CREAT |
|
|
16
|
+
constants.O_RDWR |
|
|
17
|
+
(constants.O_NOFOLLOW ?? 0) |
|
|
18
|
+
(constants.O_NONBLOCK ?? 0), 0o600);
|
|
19
|
+
try {
|
|
20
|
+
const info = await handle.stat();
|
|
21
|
+
if (!info.isFile() ||
|
|
22
|
+
info.nlink !== 1 ||
|
|
23
|
+
(process.platform !== 'win32' && (info.mode & 0o077) !== 0))
|
|
24
|
+
throw new Error('Audit destination must be a private regular file.');
|
|
25
|
+
if (info.size > 0) {
|
|
26
|
+
const lastByte = Buffer.alloc(1);
|
|
27
|
+
if ((await handle.read(lastByte, 0, 1, info.size - 1)).bytesRead !== 1 ||
|
|
28
|
+
lastByte[0] !== 10)
|
|
29
|
+
throw new Error('Audit destination ends with an incomplete line.');
|
|
30
|
+
}
|
|
31
|
+
const buffer = Buffer.from(line);
|
|
32
|
+
try {
|
|
33
|
+
let written = 0;
|
|
34
|
+
while (written < buffer.length) {
|
|
35
|
+
const result = await handle.write(buffer, written, buffer.length - written);
|
|
36
|
+
if (result.bytesWritten === 0)
|
|
37
|
+
throw new Error('Audit append made no progress.');
|
|
38
|
+
written += result.bytesWritten;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
await handle.truncate(info.size);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
await handle.close();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function enqueue(file, line, signal) {
|
|
51
|
+
let queue = queues.get(file);
|
|
52
|
+
if (!queue) {
|
|
53
|
+
queue = { size: 0, tail: Promise.resolve() };
|
|
54
|
+
queues.set(file, queue);
|
|
55
|
+
}
|
|
56
|
+
const current = queue;
|
|
57
|
+
if (current.size >= maxPendingAppends)
|
|
58
|
+
throw new Error('Audit file queue is full.');
|
|
59
|
+
current.size++;
|
|
60
|
+
const write = current.tail.then(async () => {
|
|
61
|
+
signal.throwIfAborted();
|
|
62
|
+
await append(file, line);
|
|
63
|
+
});
|
|
64
|
+
current.tail = write.catch(() => undefined);
|
|
65
|
+
return write.finally(() => {
|
|
66
|
+
if (--current.size === 0)
|
|
67
|
+
queues.delete(file);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
export const fileAuditDriver = {
|
|
71
|
+
name: 'file',
|
|
72
|
+
createTransport(options, { paths }) {
|
|
73
|
+
const value = options.path;
|
|
74
|
+
if (Object.keys(options).some((key) => key !== 'path') ||
|
|
75
|
+
typeof value !== 'string' ||
|
|
76
|
+
!value.trim() ||
|
|
77
|
+
value.includes('\0') ||
|
|
78
|
+
value.endsWith(path.sep))
|
|
79
|
+
throw new TypeError('File audit requires a file path.');
|
|
80
|
+
const relative = !path.isAbsolute(value);
|
|
81
|
+
const destination = path.resolve(paths.storageDir, value);
|
|
82
|
+
if (relative &&
|
|
83
|
+
(!within(paths.storageDir, destination) ||
|
|
84
|
+
paths.storageDir === destination))
|
|
85
|
+
throw new TypeError('Relative audit paths must stay inside application storage.');
|
|
86
|
+
let preparing;
|
|
87
|
+
const prepare = async () => {
|
|
88
|
+
const parent = path.dirname(destination);
|
|
89
|
+
if (relative) {
|
|
90
|
+
await mkdir(paths.storageDir, { recursive: true, mode: 0o700 });
|
|
91
|
+
const root = await realpath(paths.storageDir);
|
|
92
|
+
let directory = root;
|
|
93
|
+
for (const segment of path
|
|
94
|
+
.relative(paths.storageDir, parent)
|
|
95
|
+
.split(path.sep)
|
|
96
|
+
.filter(Boolean)) {
|
|
97
|
+
const next = path.join(directory, segment);
|
|
98
|
+
await mkdir(next, { recursive: true, mode: 0o700 });
|
|
99
|
+
directory = await realpath(next);
|
|
100
|
+
if (!within(root, directory))
|
|
101
|
+
throw new Error('Audit path leaves application storage.');
|
|
102
|
+
}
|
|
103
|
+
return path.join(directory, path.basename(destination));
|
|
104
|
+
}
|
|
105
|
+
await mkdir(parent, { recursive: true, mode: 0o700 });
|
|
106
|
+
return path.join(await realpath(parent), path.basename(destination));
|
|
107
|
+
};
|
|
108
|
+
return {
|
|
109
|
+
async write(event, { signal }) {
|
|
110
|
+
preparing ??= prepare().catch((error) => {
|
|
111
|
+
preparing = undefined;
|
|
112
|
+
throw error;
|
|
113
|
+
});
|
|
114
|
+
const file = await preparing;
|
|
115
|
+
signal.throwIfAborted();
|
|
116
|
+
await enqueue(file, `${JSON.stringify(event)}\n`, signal);
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
//# sourceMappingURL=file-transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-transport.js","sourceRoot":"","sources":["../src/file-transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,IAAI,MAAM,WAAW,CAAC;AAQ7B,gHAAgH;AAChH,MAAM,MAAM,GAAG,IAAI,GAAG,EAAuB,CAAC;AAC9C,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B,SAAS,MAAM,CAAC,IAAY,EAAE,MAAc;IAC1C,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC7C,OAAO,CACL,QAAQ,KAAK,IAAI;QACjB,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC;QACrC,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAC3B,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,MAAM,CAAC,IAAY,EAAE,IAAY;IAC9C,MAAM,MAAM,GAAG,MAAM,IAAI,CACvB,IAAI,EACJ,SAAS,CAAC,QAAQ;QAChB,SAAS,CAAC,OAAO;QACjB,SAAS,CAAC,MAAM;QAChB,CAAC,SAAS,CAAC,UAAU,IAAI,CAAC,CAAC;QAC3B,CAAC,SAAS,CAAC,UAAU,IAAI,CAAC,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CAAC;CACF,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Translation descriptor used by NocoBase labels (namespace and key). */
|
|
2
|
+
export interface AuditTranslation {
|
|
3
|
+
readonly ns: string;
|
|
4
|
+
readonly key: string;
|
|
5
|
+
}
|
|
6
|
+
export type AuditActor = {
|
|
7
|
+
readonly type: 'anonymous';
|
|
8
|
+
} | {
|
|
9
|
+
readonly type: 'user';
|
|
10
|
+
readonly userId: string;
|
|
11
|
+
} | {
|
|
12
|
+
readonly type: 'apiKey';
|
|
13
|
+
readonly userId: string;
|
|
14
|
+
readonly apiKeyId: string;
|
|
15
|
+
} | {
|
|
16
|
+
readonly type: 'agentRun';
|
|
17
|
+
readonly userId: string;
|
|
18
|
+
readonly runId: string;
|
|
19
|
+
};
|
|
20
|
+
export interface AuditTarget {
|
|
21
|
+
readonly collection: string;
|
|
22
|
+
/** A scalar key or a map of the fields of a compound key. */
|
|
23
|
+
readonly key?: unknown;
|
|
24
|
+
}
|
|
25
|
+
export interface AuditEvent {
|
|
26
|
+
readonly requestId: string;
|
|
27
|
+
readonly resource: string;
|
|
28
|
+
readonly action: string;
|
|
29
|
+
readonly operationName: string;
|
|
30
|
+
readonly operationNameI18n?: AuditTranslation;
|
|
31
|
+
readonly source?: AuditTarget;
|
|
32
|
+
readonly targets: readonly AuditTarget[];
|
|
33
|
+
readonly actor: AuditActor;
|
|
34
|
+
readonly roles: readonly string[];
|
|
35
|
+
readonly ip?: string;
|
|
36
|
+
readonly userAgent?: string;
|
|
37
|
+
readonly outcome: 'success' | 'failure' | 'denied';
|
|
38
|
+
readonly status: number;
|
|
39
|
+
readonly durationMs: number;
|
|
40
|
+
readonly occurredAt: string;
|
|
41
|
+
readonly request?: unknown;
|
|
42
|
+
readonly response?: unknown;
|
|
43
|
+
readonly metadata?: unknown;
|
|
44
|
+
}
|
|
45
|
+
export { auditServiceToken, type AuditService, type AuditActorResolver, type AuditTransport, type AuditTransportDriver, type AuditTransportContext, } from './service.js';
|
|
46
|
+
export { defineAuditConfig, type AuditConfig, type AuditConfigFactory, type AuditDestinationConfig, } from './config.js';
|
|
47
|
+
export { describeAudit, auditRecordKey, type AuditRouteOptions, type AuditExecutionResult, type AuditTargets, } from './request.js';
|
|
48
|
+
export type { AuditRedactRule } from './redact.js';
|
|
49
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GAC9B;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAClD;IACE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEN,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,6DAA6D;IAC7D,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,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+1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA+CA,OAAO,EACL,iBAAiB,GAMlB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,iBAAiB,GAIlB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,aAAa,EACb,cAAc,GAIf,MAAM,cAAc,CAAC"}
|
package/dist/ip.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BlockList, SocketAddress } from 'node:net';
|
|
2
|
+
export declare function parseAuditAddress(value: string): SocketAddress | undefined;
|
|
3
|
+
export declare function createTrustedAuditProxies(entries: unknown, warn: (message: string) => void): BlockList;
|
|
4
|
+
//# sourceMappingURL=ip.d.ts.map
|
package/dist/ip.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ip.d.ts","sourceRoot":"","sources":["../src/ip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAQ,MAAM,UAAU,CAAC;AAE1D,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAG1E;AAED,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAC9B,SAAS,CAiCX"}
|
package/dist/ip.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BlockList, SocketAddress, isIP } from 'node:net';
|
|
2
|
+
export function parseAuditAddress(value) {
|
|
3
|
+
if (!isIP(value))
|
|
4
|
+
return undefined;
|
|
5
|
+
return SocketAddress.parse(value) ?? SocketAddress.parse(`[${value}]:0`);
|
|
6
|
+
}
|
|
7
|
+
export function createTrustedAuditProxies(entries, warn) {
|
|
8
|
+
const list = new BlockList();
|
|
9
|
+
if (entries === undefined || entries === null)
|
|
10
|
+
return list;
|
|
11
|
+
const setting = 'auth.advanced.ipAddress.trustedProxies';
|
|
12
|
+
if (!Array.isArray(entries)) {
|
|
13
|
+
warn(`Ignoring ${setting}: expected a list of IP addresses or CIDR ranges.`);
|
|
14
|
+
return list;
|
|
15
|
+
}
|
|
16
|
+
for (const [index, entry] of entries.entries()) {
|
|
17
|
+
const [ip = '', prefix, extra] = typeof entry === 'string' ? entry.split('/') : [];
|
|
18
|
+
const parsed = parseAuditAddress(ip);
|
|
19
|
+
const prefixLength = prefix === undefined ? undefined : Number(prefix);
|
|
20
|
+
if (!parsed ||
|
|
21
|
+
parsed.port ||
|
|
22
|
+
extra !== undefined ||
|
|
23
|
+
(prefix !== undefined && !/^\d+$/u.test(prefix)) ||
|
|
24
|
+
(prefixLength !== undefined &&
|
|
25
|
+
prefixLength > (parsed.family === 'ipv4' ? 32 : 128))) {
|
|
26
|
+
warn(`Ignoring ${setting}[${index}]: expected an IP address or CIDR range.`);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (prefixLength === undefined)
|
|
30
|
+
list.addAddress(parsed.address, parsed.family);
|
|
31
|
+
else
|
|
32
|
+
list.addSubnet(parsed.address, prefixLength, parsed.family);
|
|
33
|
+
}
|
|
34
|
+
return list;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=ip.js.map
|
package/dist/ip.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ip.js","sourceRoot":"","sources":["../src/ip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAE1D,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACnC,OAAO,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,yBAAyB,CAC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AU,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;;YAC5C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"de-DE.d.ts","sourceRoot":"","sources":["../../src/locales/de-DE.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,QAAA,MAAM,IAAI,EAAE,mBAQX,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"de-DE.js","sourceRoot":"","sources":["../../src/locales/de-DE.ts"],"names":[],"mappings":"AAEA,MAAM,IAAI,GAAwB;IAChC,KAAK,EAAE;QACL,UAAU,EAAE;YACV,SAAS,EAAE,qBAAqB;YAChC,SAAS,EAAE,yBAAyB;YACpC,SAAS,EAAE,mBAAmB;SAC/B;KACF;CACF,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LocaleResource } from '@nocobase/i18n';
|
|
2
|
+
declare const enUS: {
|
|
3
|
+
audit: {
|
|
4
|
+
operations: {
|
|
5
|
+
createOne: string;
|
|
6
|
+
updateOne: string;
|
|
7
|
+
deleteOne: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export type AuditLocaleResource = LocaleResource<typeof enUS>;
|
|
12
|
+
export default enUS;
|
|
13
|
+
//# sourceMappingURL=en-US.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"en-US.d.ts","sourceRoot":"","sources":["../../src/locales/en-US.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,QAAA,MAAM,IAAI;;;;;;;;CAQT,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC,OAAO,IAAI,CAAC,CAAC;AAC9D,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"en-US.js","sourceRoot":"","sources":["../../src/locales/en-US.ts"],"names":[],"mappings":"AAEA,MAAM,IAAI,GAAG;IACX,KAAK,EAAE;QACL,UAAU,EAAE;YACV,SAAS,EAAE,iBAAiB;YAC5B,SAAS,EAAE,iBAAiB;YAC5B,SAAS,EAAE,iBAAiB;SAC7B;KACF;CACF,CAAC;AAGF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"es-ES.d.ts","sourceRoot":"","sources":["../../src/locales/es-ES.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,QAAA,MAAM,IAAI,EAAE,mBAQX,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"es-ES.js","sourceRoot":"","sources":["../../src/locales/es-ES.ts"],"names":[],"mappings":"AAEA,MAAM,IAAI,GAAwB;IAChC,KAAK,EAAE;QACL,UAAU,EAAE;YACV,SAAS,EAAE,mBAAmB;YAC9B,SAAS,EAAE,wBAAwB;YACnC,SAAS,EAAE,sBAAsB;SAClC;KACF;CACF,CAAC;AAEF,eAAe,IAAI,CAAC"}
|