@medusajs/audit 0.0.0-stage → 2.22.6
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/AGENTS.md +67 -0
- package/LICENSE +32 -0
- package/README.md +99 -2
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/loaders/providers.d.ts +5 -0
- package/dist/loaders/providers.d.ts.map +1 -0
- package/dist/loaders/providers.js +75 -0
- package/dist/loaders/providers.js.map +1 -0
- package/dist/migrations/Migration20261112093536.d.ts +5 -0
- package/dist/migrations/Migration20261112093536.d.ts.map +1 -0
- package/dist/migrations/Migration20261112093536.js +15 -0
- package/dist/migrations/Migration20261112093536.js.map +1 -0
- package/dist/models/audit-log.d.ts +18 -0
- package/dist/models/audit-log.d.ts.map +1 -0
- package/dist/models/audit-log.js +33 -0
- package/dist/models/audit-log.js.map +1 -0
- package/dist/models/index.d.ts +2 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +9 -0
- package/dist/models/index.js.map +1 -0
- package/dist/providers/audit-medusa/services/medusa-audit.d.ts +49 -0
- package/dist/providers/audit-medusa/services/medusa-audit.d.ts.map +1 -0
- package/dist/providers/audit-medusa/services/medusa-audit.js +111 -0
- package/dist/providers/audit-medusa/services/medusa-audit.js.map +1 -0
- package/dist/providers/audit-postgres/services/postgres-audit.d.ts +51 -0
- package/dist/providers/audit-postgres/services/postgres-audit.d.ts.map +1 -0
- package/dist/providers/audit-postgres/services/postgres-audit.js +107 -0
- package/dist/providers/audit-postgres/services/postgres-audit.js.map +1 -0
- package/dist/providers/index.d.ts +3 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +19 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/services/audit-module-service.d.ts +51 -0
- package/dist/services/audit-module-service.d.ts.map +1 -0
- package/dist/services/audit-module-service.js +118 -0
- package/dist/services/audit-module-service.js.map +1 -0
- package/dist/services/audit-provider.d.ts +19 -0
- package/dist/services/audit-provider.d.ts.map +1 -0
- package/dist/services/audit-provider.js +27 -0
- package/dist/services/audit-provider.js.map +1 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +19 -0
- package/dist/services/index.js.map +1 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +9 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/buffer.d.ts +48 -0
- package/dist/utils/buffer.d.ts.map +1 -0
- package/dist/utils/buffer.js +113 -0
- package/dist/utils/buffer.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +19 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/normalize.d.ts +17 -0
- package/dist/utils/normalize.d.ts.map +1 -0
- package/dist/utils/normalize.js +101 -0
- package/dist/utils/normalize.js.map +1 -0
- package/package.json +50 -4
package/AGENTS.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# @medusajs/audit
|
|
2
|
+
|
|
3
|
+
Audit Module: records audit logs (who did what, on which resource, how it ended) and reads them back. Registered as `Modules.AUDIT` (`"audit"`). Audit logs are insert and read only: there is no update or delete API.
|
|
4
|
+
|
|
5
|
+
## Using this package
|
|
6
|
+
|
|
7
|
+
- Not registered by default: applications add `{ resolve: "@medusajs/medusa/audit" }` to `modules` in `medusa-config.ts`. Without `providers` or a Cloud endpoint, audit logs are stored in the application's database; run `db:migrate` for the table.
|
|
8
|
+
- It is a licensed module: the loader (`packages/core/modules-sdk/src/loaders/utils/load-internal.ts`, `LICENSED_MODULES`) only loads it when the license covers `LicenseFeature.AUDIT` (`"audit"`). There is no feature flag.
|
|
9
|
+
- Options (`AuditModuleOptions` in `packages/core/types/src/audit/options.ts`):
|
|
10
|
+
- `enabled` (default `true`): when `false`, `createAuditLogs()` is a no-op and nothing is buffered. Reads still go to the default provider.
|
|
11
|
+
- `retention_days`: for the built-in Postgres storage only; audit logs older than this are deleted. Unset keeps them forever. Invalid values throw at boot. With `providers` or a Cloud endpoint it has no effect, and the loader logs a warning.
|
|
12
|
+
- `providers`: `{ resolve, id, options }[]`, custom providers. When set, the built-in Postgres storage is not registered.
|
|
13
|
+
- `default_provider`: a provider `id`. Defaults to `cloud` when `cloud.endpoint` is set, otherwise to the only provider (the built-in `postgres` one when nothing else is configured). Required with several providers and no Cloud.
|
|
14
|
+
- `cloud`: `{ api_key, endpoint, environment_handle }`. When `endpoint` is set, the built-in Cloud provider is registered with the id `cloud` and becomes the default; the other two are then required.
|
|
15
|
+
- `buffer`: `{ max_size = 100, flush_interval_ms = 1000, max_buffered = 10000 }`.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { Modules } from "@medusajs/framework/utils"
|
|
19
|
+
import type { IAuditModuleService } from "@medusajs/framework/types"
|
|
20
|
+
|
|
21
|
+
const audit: IAuditModuleService = container.resolve(Modules.AUDIT)
|
|
22
|
+
|
|
23
|
+
audit.createAuditLogs({ actor_type: "system", action: "catalog.import" }) // returns void
|
|
24
|
+
const [logs, count] = await audit.listAndCountAuditLogs(
|
|
25
|
+
{ resource_type: "order", resource_id: "order_123" },
|
|
26
|
+
{ skip: 0, take: 20 }
|
|
27
|
+
)
|
|
28
|
+
const log = await audit.retrieveAuditLog("audlog_123") // NOT_FOUND when missing
|
|
29
|
+
await audit.flush() // only needed when a script must read its own records back
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Service (`src/services/audit-module-service.ts`)
|
|
33
|
+
|
|
34
|
+
- `createAuditLogs(entry | entries): void`: never throws and never awaits storage. Each entry is normalized (`src/utils/normalize.ts`): `action` is required; `actor_type` defaults to `system`, `outcome` to `succeeded`, `started_at` to now, `ended_at` to `started_at`; dates may be ISO strings; an `audlog_` id is always generated. Invalid entries are dropped with one warning that names the reasons, never the contents.
|
|
35
|
+
- `listAuditLogs(filters?, config?)`, `listAndCountAuditLogs(filters?, config?)`: delegate to the default provider with `skip: 0`, `take: 20` and `order: { started_at: "DESC" }` filled in.
|
|
36
|
+
- `retrieveAuditLog(id, config?)`: the provider returns `null` for a missing id; the module throws `MedusaError.Types.NOT_FOUND`.
|
|
37
|
+
- `flush()`: drains the buffer, never throws.
|
|
38
|
+
- Filters (`FilterableAuditLogProps`): `id`, `actor_type`, `actor_id`, `action`, `resource_type`, `resource_id`, `outcome` (value or array), `started_at` (`$gt`/`$gte`/`$lt`/`$lte`), `q`.
|
|
39
|
+
|
|
40
|
+
## Architecture
|
|
41
|
+
|
|
42
|
+
- `src/utils/buffer.ts` (`AuditBuffer`): in-memory queue. Writes when it holds `max_size` entries or `flush_interval_ms` after the first pending one (the timer is `unref`'d). Batches are at most `max_size`. A failed batch is retried 3 times in total with 200 ms then 400 ms backoff, then dropped with an error log carrying the count and the reason. Over `max_buffered`, the oldest entries are dropped with a warning. Concurrent `flush()` calls share one drain, which also picks up entries pushed meanwhile.
|
|
43
|
+
- Hooks: `onApplicationPrepareShutdown` and `onApplicationShutdown` flush.
|
|
44
|
+
- `src/loaders/providers.ts`: registers the Cloud provider from `options.cloud`, then `options.providers` through `moduleProviderLoader`, each as `aud_<id>` instantiated with its own options. It registers `audit_default_provider` and `auditProviderService`, and throws at boot for duplicate ids, an unknown `default_provider`, or several providers without a default. With no Cloud endpoint and no `providers`, it registers the built-in Postgres storage.
|
|
45
|
+
- `src/services/audit-provider.ts` (`AuditProviderService`): the only place that knows which provider stores audit logs. The module service calls it and never sees provider ids.
|
|
46
|
+
- `src/providers/audit-medusa`: the built-in Medusa Cloud provider (`MedusaAuditService`, identifier `audit-medusa`). The whole wire contract is in `services/medusa-audit.ts`, with no separate client: `POST {endpoint}/records` with `{ records }`, `GET {endpoint}/records` with filters as query parameters (arrays repeated, `started_at[$gte]=<ISO>`, `q`, `offset`, `limit`, `order=-started_at|started_at`, `fields`) answering `{ records, count }`, and `GET {endpoint}/records/:id` answering `{ record }` or 404. Headers: `Authorization: Basic <api_key>` and `x-medusa-environment-handle`. The contract is provisional until the Cloud audit service exists.
|
|
47
|
+
- `src/models/audit-log.ts`: the `audit_log` data model, with generated migrations (`yarn migration:create`). It carries the implicit `created_at`, `updated_at` and `deleted_at` columns, which are never used or returned. `AuditModuleService` extends `MedusaService({ AuditLog })` and overrides every generated method: `createAuditLogs`, `listAuditLogs`, `listAndCountAuditLogs` and `retrieveAuditLog` go through the buffer and the provider, and `updateAuditLogs`, `deleteAuditLogs`, `softDeleteAuditLogs` and `restoreAuditLogs` throw `NOT_ALLOWED`.
|
|
48
|
+
- `src/providers/audit-postgres` (`PostgresAuditService`, id `postgres`): the default storage. It reads and writes through the generated `auditLogService`, so filters, `q` (over `action`, `actor_id`, `resource_type`, `resource_id`), pagination and field selection are core's. `write` starts `prune()` in the background at most once an hour when `retention_days` is set; there is no timer, so nothing is pruned while nothing is written.
|
|
49
|
+
- Custom providers extend `AbstractAuditProviderService` from `@medusajs/framework/utils` and implement `IAuditProvider` (`write`, `list`, `listAndCount`, `retrieve`). Retention is a provider's own concern.
|
|
50
|
+
|
|
51
|
+
## Development
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
cd packages/modules/audit
|
|
55
|
+
yarn build
|
|
56
|
+
yarn test # buffer, normalization, loader, Cloud provider
|
|
57
|
+
yarn test:integration # integration-tests/__tests__/audit-module.spec.ts, loads dist: build first
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
- Integration suites inject `testLicense([LicenseFeature.AUDIT])` from `@medusajs/test-utils`, or the module won't load, and use the in-memory provider in `integration-tests/__fixtures__`. Postgres storage is covered in `integration-tests/__tests__/postgres-storage.spec.ts`.
|
|
61
|
+
|
|
62
|
+
## Gotchas
|
|
63
|
+
|
|
64
|
+
- `createAuditLogs()` returns `void`, not a promise. Audit logs are lost if the process dies before a flush, or if the provider stays down beyond the retries; this is the accepted trade-off for not delaying requests.
|
|
65
|
+
- Never pass whole request or response bodies in `request_data` / `response_data`: they hold personal data and secrets. Pass the fields to keep.
|
|
66
|
+
- Writes and reads go to the default provider only.
|
|
67
|
+
- An explicit `default_provider` wins over the Cloud default.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Medusa Enterprise Edition License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MedusaJS, Inc. All rights reserved.
|
|
4
|
+
|
|
5
|
+
This package is part of the Medusa Enterprise Edition and is proprietary
|
|
6
|
+
software. It is not licensed under the MIT License that applies to Medusa's
|
|
7
|
+
open-source core.
|
|
8
|
+
|
|
9
|
+
You may use, reproduce, modify, distribute, or otherwise exploit this software
|
|
10
|
+
only under a separate, valid commercial agreement with MedusaJS, Inc. that
|
|
11
|
+
expressly grants those rights. Possession of or access to the source code does
|
|
12
|
+
not grant a license. If you do not have such an agreement, no rights are
|
|
13
|
+
granted except those that cannot lawfully be restricted.
|
|
14
|
+
|
|
15
|
+
The terms of an applicable commercial agreement control if they conflict with
|
|
16
|
+
this notice. To obtain a commercial license, contact Medusa through
|
|
17
|
+
https://medusajs.com/enterprise/.
|
|
18
|
+
|
|
19
|
+
This notice applies prospectively and does not withdraw rights already granted
|
|
20
|
+
for earlier versions of this software under the MIT License.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS" TO THE MAXIMUM EXTENT PERMITTED BY LAW,
|
|
23
|
+
UNLESS A COMMERCIAL AGREEMENT EXPRESSLY STATES OTHERWISE. MEDUSAJS, INC.
|
|
24
|
+
DISCLAIMS ALL WARRANTIES, WHETHER EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
|
|
25
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND
|
|
26
|
+
NON-INFRINGEMENT. TO THE MAXIMUM EXTENT PERMITTED BY LAW, MEDUSAJS, INC. WILL
|
|
27
|
+
NOT BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL, OR
|
|
28
|
+
PUNITIVE DAMAGES, OR ANY LOSS OF DATA, PROFITS, REVENUE, OR BUSINESS, ARISING
|
|
29
|
+
FROM THE SOFTWARE.
|
|
30
|
+
|
|
31
|
+
The canonical repository-level notice and complete scope definition are in
|
|
32
|
+
`ENTERPRISE-LICENSE.md` at the root of the Medusa repository.
|
package/README.md
CHANGED
|
@@ -1,3 +1,100 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://www.medusajs.com">
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/59018053/229103275-b5e482bb-4601-46e6-8142-244f531cebdb.svg">
|
|
5
|
+
<source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
|
|
6
|
+
<img alt="Medusa logo" src="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
|
|
7
|
+
</picture>
|
|
8
|
+
</a>
|
|
9
|
+
</p>
|
|
10
|
+
<h1 align="center">
|
|
11
|
+
@medusajs/audit
|
|
12
|
+
</h1>
|
|
2
13
|
|
|
3
|
-
|
|
14
|
+
<h4 align="center">
|
|
15
|
+
<a href="https://docs.medusajs.com">Documentation</a> |
|
|
16
|
+
<a href="https://www.medusajs.com">Website</a>
|
|
17
|
+
</h4>
|
|
18
|
+
|
|
19
|
+
<p align="center">
|
|
20
|
+
Building blocks for digital commerce
|
|
21
|
+
</p>
|
|
22
|
+
<p align="center">
|
|
23
|
+
<a href="https://github.com/medusajs/medusa/blob/develop/LICENSE">
|
|
24
|
+
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="Medusa is released under the MIT license." />
|
|
25
|
+
</a>
|
|
26
|
+
<a href="https://github.com/medusajs/medusa/blob/develop/CONTRIBUTING.md">
|
|
27
|
+
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" alt="PRs welcome!" />
|
|
28
|
+
</a>
|
|
29
|
+
<a href="https://discord.gg/xpCwq3Kfn8">
|
|
30
|
+
<img src="https://img.shields.io/badge/chat-on%20discord-7289DA.svg" alt="Discord Chat" />
|
|
31
|
+
</a>
|
|
32
|
+
<a href="https://twitter.com/intent/follow?screen_name=medusajs">
|
|
33
|
+
<img src="https://img.shields.io/twitter/follow/medusajs.svg?label=Follow%20@medusajs" alt="Follow @medusajs" />
|
|
34
|
+
</a>
|
|
35
|
+
</p>
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
Audit Module for Medusa: records who did what, on which resource, and how it ended, and reads those audit logs back. Audit logs are only inserted and read, never updated, and only deleted when a retention period is set. Recording is buffered and written in batches through a provider, so it never delays or fails the caller. It ships with `@medusajs/medusa`, requires a Medusa license that covers the `audit` feature, and is registered by adding it to the `modules` of your `medusa-config.ts`.
|
|
39
|
+
|
|
40
|
+
## At a glance
|
|
41
|
+
|
|
42
|
+
| | |
|
|
43
|
+
| --- | --- |
|
|
44
|
+
| Package | `@medusajs/audit` |
|
|
45
|
+
| Type | Infrastructure Module |
|
|
46
|
+
| Module key | `Modules.AUDIT` (`"audit"`) |
|
|
47
|
+
| Registered by default | No |
|
|
48
|
+
| Import from | `@medusajs/medusa/audit` |
|
|
49
|
+
| License | Medusa Enterprise (`audit` license feature) |
|
|
50
|
+
|
|
51
|
+
## Features
|
|
52
|
+
|
|
53
|
+
- `createAuditLogs()` validates, buffers, and batch-writes audit logs without waiting for storage or throwing.
|
|
54
|
+
- `listAuditLogs()`, `listAndCountAuditLogs()`, and `retrieveAuditLog()` read audit logs back, filtered by actor, action, resource, outcome, and time.
|
|
55
|
+
- Built-in storage: the application's PostgreSQL database by default, with an optional `retention_days`, or Medusa Cloud when the `cloud` option is set. Custom providers can replace both.
|
|
56
|
+
- An `enabled` option turns auditing off for the whole application without changing callers.
|
|
57
|
+
|
|
58
|
+
## Installation
|
|
59
|
+
|
|
60
|
+
No installation needed. The module is included in `@medusajs/medusa`. Register it in `medusa-config.ts`.
|
|
61
|
+
|
|
62
|
+
## Usage
|
|
63
|
+
|
|
64
|
+
Register the module. Audit logs are stored in the application's database:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { defineConfig } from "@medusajs/framework/utils"
|
|
68
|
+
|
|
69
|
+
module.exports = defineConfig({
|
|
70
|
+
// ...
|
|
71
|
+
modules: [
|
|
72
|
+
{
|
|
73
|
+
resolve: "@medusajs/medusa/audit",
|
|
74
|
+
// optional: delete audit logs older than a year
|
|
75
|
+
options: { retention_days: 365 },
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
})
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Then run migrations with `npx medusa db:migrate`.
|
|
82
|
+
|
|
83
|
+
Record an audit log from a job, subscriber, workflow step, or script:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { Modules } from "@medusajs/framework/utils"
|
|
87
|
+
|
|
88
|
+
const auditModuleService = container.resolve(Modules.AUDIT)
|
|
89
|
+
|
|
90
|
+
auditModuleService.createAuditLogs({
|
|
91
|
+
actor_type: "system",
|
|
92
|
+
action: "inventory.sync",
|
|
93
|
+
resource_type: "inventory_item",
|
|
94
|
+
resource_id: "iitem_123",
|
|
95
|
+
})
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Resources
|
|
99
|
+
|
|
100
|
+
- [Modules](https://docs.medusajs.com/learn/fundamentals/modules)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import "./types";
|
|
2
|
+
import { AuditModuleService } from "./services/index.js";
|
|
3
|
+
declare const _default: import("@medusajs/types").ModuleExports<typeof AuditModuleService> & {
|
|
4
|
+
linkable: {
|
|
5
|
+
readonly auditLog: {
|
|
6
|
+
toJSON: () => {
|
|
7
|
+
serviceName: "audit";
|
|
8
|
+
field: "auditLog";
|
|
9
|
+
linkable: "audit_log_id";
|
|
10
|
+
primaryKey: "id";
|
|
11
|
+
};
|
|
12
|
+
id: {
|
|
13
|
+
serviceName: "audit";
|
|
14
|
+
field: "auditLog";
|
|
15
|
+
linkable: "audit_log_id";
|
|
16
|
+
primaryKey: "id";
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export default _default;
|
|
22
|
+
export type { AuditModuleOptions } from "./types";
|
|
23
|
+
export { MedusaAuditService } from "./providers";
|
|
24
|
+
export type { MedusaAuditProviderOptions } from "./providers";
|
|
25
|
+
export { PostgresAuditService } from "./providers";
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,CAAA;AAGhB,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;;;;;;;;;;;;;;;;;;;;AAQ9C,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAChD,YAAY,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAA;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PostgresAuditService = exports.MedusaAuditService = void 0;
|
|
7
|
+
require("./types");
|
|
8
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
9
|
+
const _services_1 = require("./services/index.js");
|
|
10
|
+
const providers_1 = __importDefault(require("./loaders/providers"));
|
|
11
|
+
exports.default = (0, utils_1.Module)(utils_1.Modules.AUDIT, {
|
|
12
|
+
service: _services_1.AuditModuleService,
|
|
13
|
+
loaders: [providers_1.default],
|
|
14
|
+
});
|
|
15
|
+
var providers_2 = require("./providers");
|
|
16
|
+
Object.defineProperty(exports, "MedusaAuditService", { enumerable: true, get: function () { return providers_2.MedusaAuditService; } });
|
|
17
|
+
var providers_3 = require("./providers");
|
|
18
|
+
Object.defineProperty(exports, "PostgresAuditService", { enumerable: true, get: function () { return providers_3.PostgresAuditService; } });
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,mBAAgB;AAEhB,qDAA2D;AAC3D,yCAA8C;AAC9C,oEAAiD;kBAElC,IAAA,cAAM,EAAC,eAAO,CAAC,KAAK,EAAE;IACnC,OAAO,EAAE,8BAAkB;IAC3B,OAAO,EAAE,CAAC,mBAAe,CAAC;CAC3B,CAAC;AAGF,yCAAgD;AAAvC,+GAAA,kBAAkB,OAAA;AAE3B,yCAAkD;AAAzC,iHAAA,oBAAoB,OAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { LoaderOptions } from "@medusajs/framework/types";
|
|
2
|
+
import { AuditModuleOptions } from "../types/index.js";
|
|
3
|
+
export default _default;
|
|
4
|
+
declare function _default({ container, options, }: LoaderOptions<AuditModuleOptions>): Promise<void>;
|
|
5
|
+
//# sourceMappingURL=providers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../src/loaders/providers.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,aAAa,EAGd,MAAM,2BAA2B,CAAA;AAElC,OAAO,EAEL,kBAAkB,EAInB,MAAM,QAAQ,CAAA;;0BAyCO,EACpB,SAAS,EACT,OAAO,GACR,EAAE,aAAa,CAAC,kBAAkB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const awilix_1 = require("@medusajs/framework/awilix");
|
|
4
|
+
const modules_sdk_1 = require("@medusajs/framework/modules-sdk");
|
|
5
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
6
|
+
const _types_1 = require("../types/index.js");
|
|
7
|
+
const providers_1 = require("../providers");
|
|
8
|
+
const audit_provider_1 = require("../services/audit-provider");
|
|
9
|
+
function register(container, ids, klass, id, options = {}) {
|
|
10
|
+
if (!id) {
|
|
11
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `The audit provider "${klass.identifier}" has no "id"`);
|
|
12
|
+
}
|
|
13
|
+
if (ids.includes(id)) {
|
|
14
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `The audit provider id "${id}" is registered twice. ${id === _types_1.MEDUSA_CLOUD_AUDIT_PROVIDER_ID
|
|
15
|
+
? `"${id}" is reserved for Medusa Cloud audit storage.`
|
|
16
|
+
: "Give each provider its own id."}`);
|
|
17
|
+
}
|
|
18
|
+
// Instantiated here rather than aliased to the module loader's own provider
|
|
19
|
+
// registration, which is constructed with the module options instead of the
|
|
20
|
+
// provider's.
|
|
21
|
+
container.register({
|
|
22
|
+
[_types_1.AuditProviderRegistrationPrefix + id]: (0, awilix_1.asFunction)((cradle) => new klass(cradle, options)).singleton(),
|
|
23
|
+
});
|
|
24
|
+
ids.push(id);
|
|
25
|
+
}
|
|
26
|
+
exports.default = async ({ container, options, }) => {
|
|
27
|
+
const logger = container.resolve("logger");
|
|
28
|
+
const ids = [];
|
|
29
|
+
const cloud = options?.cloud;
|
|
30
|
+
if (cloud?.endpoint) {
|
|
31
|
+
register(container, ids, providers_1.MedusaAuditService, _types_1.MEDUSA_CLOUD_AUDIT_PROVIDER_ID, cloud);
|
|
32
|
+
// Constructed now so that missing credentials fail the boot.
|
|
33
|
+
container.resolve(_types_1.AuditProviderRegistrationPrefix + _types_1.MEDUSA_CLOUD_AUDIT_PROVIDER_ID);
|
|
34
|
+
}
|
|
35
|
+
await (0, modules_sdk_1.moduleProviderLoader)({
|
|
36
|
+
container,
|
|
37
|
+
providers: options?.providers ?? [],
|
|
38
|
+
registerServiceFn: async (klass, container, { id, options }) => register(container, ids, klass, id, options),
|
|
39
|
+
});
|
|
40
|
+
// Without other storage, audit logs go to the application's database.
|
|
41
|
+
if (!ids.length) {
|
|
42
|
+
register(container, ids, providers_1.PostgresAuditService, _types_1.POSTGRES_AUDIT_PROVIDER_ID, {
|
|
43
|
+
retention_days: options?.retention_days,
|
|
44
|
+
});
|
|
45
|
+
// Constructed now so that an invalid retention fails the boot.
|
|
46
|
+
container.resolve(_types_1.AuditProviderRegistrationPrefix + _types_1.POSTGRES_AUDIT_PROVIDER_ID);
|
|
47
|
+
}
|
|
48
|
+
else if (options?.retention_days !== undefined) {
|
|
49
|
+
logger.warn('Audit: "retention_days" only applies to the built-in Postgres storage and is ignored, because audit logs are stored by another provider.');
|
|
50
|
+
}
|
|
51
|
+
const defaultProvider = resolveDefaultProvider(ids, options ?? {}, !!cloud?.endpoint);
|
|
52
|
+
if (!options?.default_provider) {
|
|
53
|
+
logger.info(`Audit module: Using "${defaultProvider}" as default.`);
|
|
54
|
+
}
|
|
55
|
+
container.register({
|
|
56
|
+
[_types_1.AuditDefaultProviderRegistrationName]: (0, awilix_1.asValue)(defaultProvider),
|
|
57
|
+
auditProviderService: (0, awilix_1.asFunction)((cradle) => new audit_provider_1.AuditProviderService(cradle)).singleton(),
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
function resolveDefaultProvider(ids, options, hasCloud) {
|
|
61
|
+
if (options.default_provider) {
|
|
62
|
+
if (!ids.includes(options.default_provider)) {
|
|
63
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `The audit "default_provider" "${options.default_provider}" is not registered. Registered providers: ${ids.join(", ") || "(none)"}`);
|
|
64
|
+
}
|
|
65
|
+
return options.default_provider;
|
|
66
|
+
}
|
|
67
|
+
if (hasCloud) {
|
|
68
|
+
return _types_1.MEDUSA_CLOUD_AUDIT_PROVIDER_ID;
|
|
69
|
+
}
|
|
70
|
+
if (ids.length === 1) {
|
|
71
|
+
return ids[0];
|
|
72
|
+
}
|
|
73
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Several audit providers are registered (${ids.join(", ")}), so "default_provider" must be set`);
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../../src/loaders/providers.ts"],"names":[],"mappings":";;AAAA,uDAAgE;AAChE,iEAAsE;AAMtE,qDAAuD;AACvD,mCAMe;AACf,4CAAuE;AACvE,+DAAiE;AAEjE,SAAS,QAAQ,CACf,SAA0B,EAC1B,GAAa,EACb,KAAU,EACV,EAAsB,EACtB,OAAO,GAA4B,EAAE;IAErC,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,uBAAuB,KAAK,CAAC,UAAU,eAAe,CACvD,CAAA;IACH,CAAC;IAED,IAAI,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,0BAA0B,EAAE,0BAC1B,EAAE,KAAK,uCAA8B;YACnC,CAAC,CAAC,IAAI,EAAE,+CAA+C;YACvD,CAAC,CAAC,gCACN,EAAE,CACH,CAAA;IACH,CAAC;IAED,4EAA4E;IAC5E,4EAA4E;IAC5E,cAAc;IACd,SAAS,CAAC,QAAQ,CAAC;QACjB,CAAC,wCAA+B,GAAG,EAAE,CAAC,EAAE,IAAA,mBAAU,EAChD,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,M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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration20261112093536.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20261112093536.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAA;AAEpE,qBAAa,uBAAwB,SAAQ,SAAS;IACrC,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC,CAgBjC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Migration20261112093536 = void 0;
|
|
4
|
+
const migrations_1 = require("@medusajs/framework/mikro-orm/migrations");
|
|
5
|
+
class Migration20261112093536 extends migrations_1.Migration {
|
|
6
|
+
async up() {
|
|
7
|
+
this.addSql(`create table if not exists "audit_log" ("id" text not null, "started_at" timestamptz not null, "ended_at" timestamptz not null, "actor_type" text check ("actor_type" in ('user', 'api_key', 'customer', 'system', 'anonymous')) not null, "actor_id" text null, "impersonator_id" text null, "action" text not null, "resource_type" text null, "resource_id" text null, "outcome" text check ("outcome" in ('succeeded', 'denied', 'failed')) not null, "request" jsonb null, "request_data" jsonb null, "response_data" jsonb null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "audit_log_pkey" primary key ("id"));`);
|
|
8
|
+
this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_audit_log_deleted_at" ON "audit_log" ("deleted_at") WHERE deleted_at IS NULL;`);
|
|
9
|
+
this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_audit_log_started_at" ON "audit_log" ("started_at") WHERE deleted_at IS NULL;`);
|
|
10
|
+
this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_audit_log_actor_id_started_at" ON "audit_log" ("actor_id", "started_at") WHERE deleted_at IS NULL;`);
|
|
11
|
+
this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_audit_log_resource_type_resource_id_started_at" ON "audit_log" ("resource_type", "resource_id", "started_at") WHERE deleted_at IS NULL;`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.Migration20261112093536 = Migration20261112093536;
|
|
15
|
+
//# sourceMappingURL=Migration20261112093536.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration20261112093536.js","sourceRoot":"","sources":["../../src/migrations/Migration20261112093536.ts"],"names":[],"mappings":";;;AAAA,yEAAoE;AAEpE,6BAAqC,SAAQ,sBAAS;IAC3C,KAAK,CAAC,EAAE;QACf,IAAI,CAAC,MAAM,CACT,itBAAitB,CACltB,CAAA;QACD,IAAI,CAAC,MAAM,CACT,+GAA+G,CAChH,CAAA;QACD,IAAI,CAAC,MAAM,CACT,+GAA+G,CAChH,CAAA;QACD,IAAI,CAAC,MAAM,CACT,oIAAoI,CACrI,CAAA;QACD,IAAI,CAAC,MAAM,CACT,yKAAyK,CAC1K,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare const AuditLog: import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<{
|
|
2
|
+
id: import("@medusajs/framework/utils").PrimaryKeyModifier<string, import("@medusajs/framework/utils").IdProperty>;
|
|
3
|
+
started_at: import("@medusajs/framework/utils").DateTimeProperty;
|
|
4
|
+
ended_at: import("@medusajs/framework/utils").DateTimeProperty;
|
|
5
|
+
actor_type: import("@medusajs/framework/utils").EnumProperty<["user", "api_key", "customer", "system", "anonymous"]>;
|
|
6
|
+
actor_id: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
|
|
7
|
+
impersonator_id: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
|
|
8
|
+
action: import("@medusajs/framework/utils").TextProperty;
|
|
9
|
+
resource_type: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
|
|
10
|
+
resource_id: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
|
|
11
|
+
outcome: import("@medusajs/framework/utils").EnumProperty<["succeeded", "denied", "failed"]>;
|
|
12
|
+
request: import("@medusajs/framework/utils").NullableModifier<NoInfer<Record<string, unknown>>, import("@medusajs/framework/utils").JSONProperty<NoInfer<Record<string, unknown>>>>;
|
|
13
|
+
request_data: import("@medusajs/framework/utils").NullableModifier<NoInfer<Record<string, unknown>>, import("@medusajs/framework/utils").JSONProperty<NoInfer<Record<string, unknown>>>>;
|
|
14
|
+
response_data: import("@medusajs/framework/utils").NullableModifier<NoInfer<Record<string, unknown>>, import("@medusajs/framework/utils").JSONProperty<NoInfer<Record<string, unknown>>>>;
|
|
15
|
+
metadata: import("@medusajs/framework/utils").NullableModifier<NoInfer<Record<string, unknown>>, import("@medusajs/framework/utils").JSONProperty<NoInfer<Record<string, unknown>>>>;
|
|
16
|
+
}>, "audit_log">;
|
|
17
|
+
export default AuditLog;
|
|
18
|
+
//# sourceMappingURL=audit-log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-log.d.ts","sourceRoot":"","sources":["../../src/models/audit-log.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,QAAQ;;;;;;;;;;;;;;;gBA2BV,CAAA;eAEW,QAAQ"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
4
|
+
const AuditLog = utils_1.model
|
|
5
|
+
.define("audit_log", {
|
|
6
|
+
id: utils_1.model.id({ prefix: "audlog" }).primaryKey(),
|
|
7
|
+
started_at: utils_1.model.dateTime(),
|
|
8
|
+
ended_at: utils_1.model.dateTime(),
|
|
9
|
+
actor_type: utils_1.model.enum([
|
|
10
|
+
"user",
|
|
11
|
+
"api_key",
|
|
12
|
+
"customer",
|
|
13
|
+
"system",
|
|
14
|
+
"anonymous",
|
|
15
|
+
]),
|
|
16
|
+
actor_id: utils_1.model.text().searchable().nullable(),
|
|
17
|
+
impersonator_id: utils_1.model.text().nullable(),
|
|
18
|
+
action: utils_1.model.text().searchable(),
|
|
19
|
+
resource_type: utils_1.model.text().searchable().nullable(),
|
|
20
|
+
resource_id: utils_1.model.text().searchable().nullable(),
|
|
21
|
+
outcome: utils_1.model.enum(["succeeded", "denied", "failed"]),
|
|
22
|
+
request: utils_1.model.json().nullable(),
|
|
23
|
+
request_data: utils_1.model.json().nullable(),
|
|
24
|
+
response_data: utils_1.model.json().nullable(),
|
|
25
|
+
metadata: utils_1.model.json().nullable(),
|
|
26
|
+
})
|
|
27
|
+
.indexes([
|
|
28
|
+
{ on: ["started_at"] },
|
|
29
|
+
{ on: ["actor_id", "started_at"] },
|
|
30
|
+
{ on: ["resource_type", "resource_id", "started_at"] },
|
|
31
|
+
]);
|
|
32
|
+
exports.default = AuditLog;
|
|
33
|
+
//# sourceMappingURL=audit-log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-log.js","sourceRoot":"","sources":["../../src/models/audit-log.ts"],"names":[],"mappings":";;AAAA,qDAAiD;AAEjD,MAAM,QAAQ,GAAG,aAAK;KACnB,MAAM,CAAC,WAAW,EAAE;IACnB,EAAE,EAAE,aAAK,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,UAAU,EAAE;IAC/C,UAAU,EAAE,aAAK,CAAC,QAAQ,EAAE;IAC5B,QAAQ,EAAE,aAAK,CAAC,QAAQ,EAAE;IAC1B,UAAU,EAAE,aAAK,CAAC,IAAI,CAAC;QACrB,MAAM;QACN,SAAS;QACT,UAAU;QACV,QAAQ;QACR,WAAW;KACZ,CAAC;IACF,QAAQ,EAAE,aAAK,CAAC,IAAI,EAAE,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE;IAC9C,eAAe,EAAE,aAAK,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE;IACxC,MAAM,EAAE,aAAK,CAAC,IAAI,EAAE,CAAC,UAAU,EAAE;IACjC,aAAa,EAAE,aAAK,CAAC,IAAI,EAAE,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE;IACnD,WAAW,EAAE,aAAK,CAAC,IAAI,EAAE,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE;IACjD,OAAO,EAAE,aAAK,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACtD,OAAO,EAAE,aAAK,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE;IAChC,YAAY,EAAE,aAAK,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE;IACrC,aAAa,EAAE,aAAK,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE;IACtC,QAAQ,EAAE,aAAK,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE;CAClC,CAAC;KACD,OAAO,CAAC;IACP,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE;IACtB,EAAE,EAAE,EAAE,CAAC,UAAU,EAAE,YAAY,CAAC,EAAE;IAClC,EAAE,EAAE,EAAE,CAAC,eAAe,EAAE,aAAa,EAAE,YAAY,CAAC,EAAE;CACvD,CAAC,CAAA;kBAEW,QAAQ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AuditLog = void 0;
|
|
7
|
+
var audit_log_1 = require("./audit-log");
|
|
8
|
+
Object.defineProperty(exports, "AuditLog", { enumerable: true, get: function () { return __importDefault(audit_log_1).default; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAiD;AAAxC,sHAAA,OAAO,OAAY"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { AuditLogDTO, AuditLogFindConfig, FilterableAuditLogProps } from "@medusajs/framework/types";
|
|
2
|
+
import { AbstractAuditProviderService } from "@medusajs/framework/utils";
|
|
3
|
+
export type MedusaAuditProviderOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* The Medusa Cloud API key.
|
|
6
|
+
*/
|
|
7
|
+
api_key: string;
|
|
8
|
+
/**
|
|
9
|
+
* The base URL of the Medusa Cloud audit service.
|
|
10
|
+
*/
|
|
11
|
+
endpoint: string;
|
|
12
|
+
/**
|
|
13
|
+
* The handle of the Medusa Cloud environment the audit logs belong to.
|
|
14
|
+
*/
|
|
15
|
+
environment_handle: string;
|
|
16
|
+
/**
|
|
17
|
+
* @ignore
|
|
18
|
+
*
|
|
19
|
+
* Replaces the HTTP transport. It receives the requests that would go to the
|
|
20
|
+
* Cloud audit service and must answer as the service would.
|
|
21
|
+
*/
|
|
22
|
+
fetch?: typeof fetch;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Stores audit logs in the Medusa Cloud audit service. Registered by the module
|
|
26
|
+
* itself from its `cloud` option.
|
|
27
|
+
*
|
|
28
|
+
* The service is write and read only, so there is no update or delete:
|
|
29
|
+
*
|
|
30
|
+
* - `POST /records` with `{ records }` stores a batch.
|
|
31
|
+
* - `GET /records` with filter and pagination query parameters answers
|
|
32
|
+
* `{ records, count }`.
|
|
33
|
+
* - `GET /records/:id` answers `{ record }`, or 404.
|
|
34
|
+
*/
|
|
35
|
+
export declare class MedusaAuditService extends AbstractAuditProviderService {
|
|
36
|
+
static identifier: string;
|
|
37
|
+
protected readonly options_: MedusaAuditProviderOptions;
|
|
38
|
+
protected readonly endpoint_: string;
|
|
39
|
+
constructor(_: unknown, options: MedusaAuditProviderOptions);
|
|
40
|
+
write(entries: AuditLogDTO[]): Promise<void>;
|
|
41
|
+
list(filters: FilterableAuditLogProps, config: AuditLogFindConfig): Promise<AuditLogDTO[]>;
|
|
42
|
+
listAndCount(filters: FilterableAuditLogProps, config: AuditLogFindConfig): Promise<[AuditLogDTO[], number]>;
|
|
43
|
+
retrieve(id: string, config: AuditLogFindConfig): Promise<AuditLogDTO | null>;
|
|
44
|
+
protected request_(method: "GET" | "POST", path: string, payload?: object, acceptedStatuses?: number[]): Promise<{
|
|
45
|
+
status: number;
|
|
46
|
+
body: Record<string, any>;
|
|
47
|
+
}>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=medusa-audit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"medusa-audit.d.ts","sourceRoot":"","sources":["../../../../src/providers/audit-medusa/services/medusa-audit.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACL,4BAA4B,EAE7B,MAAM,2BAA2B,CAAA;AAElC,MAAM,MAAM,0BAA0B,GAAG;IACvC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,kBAAkB,EAAE,MAAM,CAAA;IAC1B;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;CACrB,CAAA;AAYD;;;;;;;;;;GAUG;AACH,qBAAa,kBAAmB,SAAQ,4BAA4B;IAClE,MAAM,CAAC,UAAU,SAAiB;IAElC,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,0BAA0B,CAAA;IACvD,SA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