@enonic-types/lib-auditlog 0.1.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.
Files changed (3) hide show
  1. package/README.md +81 -0
  2. package/auditlog.d.ts +92 -0
  3. package/package.json +36 -0
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # Enonic XP lib-auditlog TS types
2
+
3
+ > TypeScript definitions for `lib-auditlog` library of Enonic XP
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm i --save-dev @enonic/lib-auditlog
9
+ ```
10
+
11
+ ## Use
12
+
13
+ Add the corresponding types to your `tsconfig.json` file that is used for application's server-side TypeScript code.
14
+
15
+ `tsconfig.json`
16
+
17
+ ```json
18
+ {
19
+ "compilerOptions": {
20
+ "types": [
21
+ "@enonic-types/lib-auditlog"
22
+ ]
23
+ }
24
+ }
25
+ ```
26
+
27
+ ### Require and custom imports
28
+
29
+ To make `require` work out of box, you must install and add the `@enonic-types/global` types. Aside from providing definitions for XP global
30
+ objects, e.g. `log`, `app`, `__`, etc, requiring library by the default path will return typed object.
31
+
32
+ `tsconfig.json`
33
+
34
+ ```diff
35
+ {
36
+ "compilerOptions": {
37
+ "types": [
38
+ + "@enonic-types/global"
39
+ "@enonic-types/lib-auditlog"
40
+ ]
41
+ }
42
+ }
43
+ ```
44
+
45
+ `example.ts`
46
+
47
+ ```ts
48
+ const {log, get, find} = require('/lib/xp/auditlog');
49
+ ```
50
+
51
+ More detailed explanation on how it works and how to type custom import function can be
52
+ found [here](https://github.com/enonic/xp/tree/master/modules/lib/typescript/README.md).
53
+
54
+ ### ES6-style import
55
+
56
+ If you are planning to use `import` in your code and transpile it with the default `tsc` TypeScript compiler, you'll need to add proper
57
+ types mapping to your configuration.
58
+
59
+ `tsconfig.json`
60
+
61
+ ```diff
62
+ {
63
+ "compilerOptions": {
64
+ "types": [
65
+ "@enonic-types/lib-auditlog"
66
+ ]
67
+ + "baseUrl": "./",
68
+ + "paths": {
69
+ + "/lib/xp/auditlog": ["node_modules/@enonic-types/lib-auditlog"],
70
+ + }
71
+ }
72
+ }
73
+ ```
74
+
75
+ `example.ts`
76
+
77
+ ```ts
78
+ import {log, get, find} from '/lib/xp/auditlog';
79
+ ```
80
+
81
+ Setting `baseUrl` and `paths` will allow the `tsc` to keep the valid paths in the resulting JavaScript files.
package/auditlog.d.ts ADDED
@@ -0,0 +1,92 @@
1
+ declare global {
2
+ interface XpLibraries {
3
+ '/lib/xp/auditlog': typeof import('./auditlog');
4
+ }
5
+ }
6
+ export interface AuditLogParams {
7
+ type: string;
8
+ time?: string;
9
+ source?: string;
10
+ user?: string;
11
+ objects?: string[];
12
+ data?: Record<string, unknown>;
13
+ }
14
+ export interface AuditLog {
15
+ _id: string;
16
+ type: string;
17
+ time: string;
18
+ source: string;
19
+ user: string;
20
+ objects: string[];
21
+ data: Record<string, unknown>;
22
+ }
23
+ /**
24
+ * This function creates a single audit log entry.
25
+ *
26
+ * The parameter 'type' is required and all other parameters are optional.
27
+ *
28
+ * @example-ref examples/auditlog/log.js
29
+ *
30
+ * @param {object} params JSON with the parameters.
31
+ * @param {string} params.type Type of log entry.
32
+ * @param {string} [params.time] Log entry timestamp. Defaults to now.
33
+ * @param {string} [params.source] Log entry source. Defaults to the application ID.
34
+ * @param {string} [params.user] Log entry user. Defaults to the user of current context.
35
+ * @param {array} [params.objects] URIs to objects that relate to this log entry. Defaults to empty array.
36
+ * @param {object} [params.data] Custom extra data for the this log entry. Defaults to empty object.
37
+ *
38
+ * @returns {object} Audit log created as JSON.
39
+ */
40
+ export declare function log(params: AuditLogParams): AuditLog;
41
+ export interface GetAuditLogParams {
42
+ id: string;
43
+ }
44
+ /**
45
+ * This function fetches an audit log.
46
+ *
47
+ * @example-ref examples/auditlog/get.js
48
+ *
49
+ * @param {object} params JSON with the parameters.
50
+ * @param {string} params.id Id of the audit log.
51
+ *
52
+ * @returns {object} Audit log as JSON.
53
+ */
54
+ export declare function get(params: GetAuditLogParams): AuditLog | null;
55
+ export interface FindAuditLogParams {
56
+ start?: number;
57
+ count?: number;
58
+ ids?: string[];
59
+ from?: string;
60
+ to?: string;
61
+ type?: string;
62
+ source?: string;
63
+ users?: string[];
64
+ objects?: string[];
65
+ }
66
+ export interface AuditLogs {
67
+ total: number;
68
+ count: number;
69
+ hits: AuditLog[];
70
+ }
71
+ /**
72
+ * This function searches for audit logs.
73
+ *
74
+ * All parameters are semi-optional, meaning that you should at least supply one
75
+ * of them. If no parameters are supplied you will get an empty result.
76
+ *
77
+ * @example-ref examples/auditlog/find.js
78
+ *
79
+ * @param {object} params JSON with the parameters.
80
+ * @param {number} [params.start=0] Start index (used for paging).
81
+ * @param {number} [params.count=10] Number of contents to fetch.
82
+ * @param {array} [params.ids] Filter by ids of audit logs.
83
+ * @param {string} [params.from] Filter by logs younger than from.
84
+ * @param {string} [params.to] Filter by logs older than to.
85
+ * @param {string} [params.type] Filter by type.
86
+ * @param {string} [params.source] Filter by source.
87
+ * @param {array} [params.users] Filter by user keys.
88
+ * @param {array} [params.objects] Filter by object URIs.
89
+ *
90
+ * @returns {object} Audit log search results.
91
+ */
92
+ export declare function find(params: FindAuditLogParams): AuditLogs;
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@enonic-types/lib-auditlog",
3
+ "version": "0.1.0",
4
+ "description": "Type definitions for lib-auditlog.",
5
+ "types": "auditlog.d.ts",
6
+ "files": [
7
+ "auditlog.d.ts"
8
+ ],
9
+ "scripts": {
10
+ "pre": "npm run --prefix ../ pre",
11
+ "packlist": "npx npm-packlist"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/enonic/xp.git#master"
16
+ },
17
+ "keywords": [
18
+ "enonic",
19
+ "enonic-xp",
20
+ "lib-auditlog",
21
+ "auditlog",
22
+ "types",
23
+ "typescript"
24
+ ],
25
+ "contributors": [
26
+ "Mikita Taukachou <edloidas@gmail.com> (https://edloidas.github.io/)"
27
+ ],
28
+ "license": "Apache-2.0",
29
+ "bugs": {
30
+ "url": "https://github.com/enonic/xp/issues"
31
+ },
32
+ "homepage": "https://github.com/enonic/xp/tree/master#readme",
33
+ "publishConfig": {
34
+ "access": "public"
35
+ }
36
+ }