@metasession.co/devaudit-plugin-sdk 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.
- package/LICENSE +201 -0
- package/README.md +72 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +112 -0
- package/dist/index.js.map +1 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Metasession
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
200
|
+
implied. See the License for the specific language governing permissions
|
|
201
|
+
and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# @metasession.co/devaudit-plugin-sdk
|
|
2
|
+
|
|
3
|
+
Contract types, manifest schema, and lifecycle hooks that DevAudit CLI plugins compile against.
|
|
4
|
+
|
|
5
|
+
> **Status:** v0 contract. The shape will stabilise at v1; until then expect breaking changes between minor versions.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install --save-dev @metasession.co/devaudit-plugin-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Author a plugin
|
|
14
|
+
|
|
15
|
+
A plugin is an npm package whose `package.json` declares a `devaudit` field, and whose `main` module default-exports a `Plugin` object.
|
|
16
|
+
|
|
17
|
+
### `package.json`
|
|
18
|
+
|
|
19
|
+
```jsonc
|
|
20
|
+
{
|
|
21
|
+
"name": "devaudit-plugin-prisma",
|
|
22
|
+
"version": "1.0.0",
|
|
23
|
+
"main": "./dist/plugin.js",
|
|
24
|
+
"devaudit": {
|
|
25
|
+
"apiVersion": "1",
|
|
26
|
+
"displayName": "Prisma migration helper",
|
|
27
|
+
"description": "Prisma migration deploy hooks for Node consumers",
|
|
28
|
+
"commands": [
|
|
29
|
+
{ "name": "migrate-status", "description": "Show pending Prisma migrations" }
|
|
30
|
+
],
|
|
31
|
+
"hooks": ["afterUpdate"]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### `src/plugin.ts`
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import type { Plugin } from '@metasession.co/devaudit-plugin-sdk';
|
|
40
|
+
|
|
41
|
+
const plugin: Plugin = {
|
|
42
|
+
name: 'devaudit-plugin-prisma',
|
|
43
|
+
apiVersion: '1',
|
|
44
|
+
hooks: {
|
|
45
|
+
afterUpdate: async (ctx) => {
|
|
46
|
+
ctx.logger.info(`Sync done. Now run \`npx prisma migrate deploy\` in ${ctx.projectPath}.`);
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
commands: {
|
|
50
|
+
'migrate-status': async (ctx) => {
|
|
51
|
+
ctx.logger.info('Running Prisma migration status check…');
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export default plugin;
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## What's exported
|
|
60
|
+
|
|
61
|
+
| Export | Purpose |
|
|
62
|
+
|---|---|
|
|
63
|
+
| `Plugin` | The object a plugin's main module default-exports |
|
|
64
|
+
| `PluginContext` | What the CLI passes to hooks and commands at runtime |
|
|
65
|
+
| `PluginManifest` | The `devaudit` field shape inside a plugin's `package.json` |
|
|
66
|
+
| `LifecycleHookName` | Union of supported hook names |
|
|
67
|
+
| `CommandContribution` | Shape of an entry in `manifest.devaudit.commands` |
|
|
68
|
+
| `validateManifest(input)` | Zero-dep shape check; returns either `{ valid: true, manifest }` or `{ valid: false, errors }` |
|
|
69
|
+
|
|
70
|
+
## Semantic versioning
|
|
71
|
+
|
|
72
|
+
Plugins declare `devaudit.apiVersion` in their manifest. The CLI's plugin loader rejects plugins whose `apiVersion` is incompatible with the loader's supported range. v0 starts at `apiVersion: "1"`; bumps follow semver of this package.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
declare const LIFECYCLE_HOOK_NAMES: readonly ["beforeInstall", "afterInstall", "beforeUpdate", "afterUpdate", "beforePush", "afterPush", "beforeSync", "afterSync", "onDoctor"];
|
|
2
|
+
type LifecycleHookName = (typeof LIFECYCLE_HOOK_NAMES)[number];
|
|
3
|
+
declare function isLifecycleHookName(value: unknown): value is LifecycleHookName;
|
|
4
|
+
|
|
5
|
+
interface PluginLogger {
|
|
6
|
+
info(message: string): void;
|
|
7
|
+
warn(message: string): void;
|
|
8
|
+
error(message: string): void;
|
|
9
|
+
debug(message: string): void;
|
|
10
|
+
}
|
|
11
|
+
interface PluginSdlcConfigView {
|
|
12
|
+
readonly project_slug: string;
|
|
13
|
+
readonly stack?: string;
|
|
14
|
+
readonly host?: string;
|
|
15
|
+
readonly node_version?: string | number;
|
|
16
|
+
readonly python_version?: string | number;
|
|
17
|
+
readonly working_directory?: string;
|
|
18
|
+
readonly source_dirs?: string;
|
|
19
|
+
readonly [key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
interface PluginEvent {
|
|
22
|
+
readonly type: string;
|
|
23
|
+
readonly payload?: Readonly<Record<string, unknown>>;
|
|
24
|
+
}
|
|
25
|
+
interface PluginContext {
|
|
26
|
+
readonly projectPath: string;
|
|
27
|
+
readonly sdlcConfig: PluginSdlcConfigView;
|
|
28
|
+
readonly logger: PluginLogger;
|
|
29
|
+
readonly apiVersion: '1';
|
|
30
|
+
emit(event: PluginEvent): void;
|
|
31
|
+
}
|
|
32
|
+
type LifecycleHook = (ctx: PluginContext) => Promise<void> | void;
|
|
33
|
+
type PluginCommand = (ctx: PluginContext, args: readonly string[]) => Promise<void> | void;
|
|
34
|
+
interface Plugin {
|
|
35
|
+
readonly name: string;
|
|
36
|
+
readonly apiVersion: '1';
|
|
37
|
+
readonly hooks?: Partial<Record<LifecycleHookName, LifecycleHook>>;
|
|
38
|
+
readonly commands?: Readonly<Record<string, PluginCommand>>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface CommandContribution {
|
|
42
|
+
readonly name: string;
|
|
43
|
+
readonly description: string;
|
|
44
|
+
}
|
|
45
|
+
declare function isValidCommandName(value: unknown): value is string;
|
|
46
|
+
|
|
47
|
+
declare const SUPPORTED_API_VERSIONS: readonly string[];
|
|
48
|
+
interface PluginManifest {
|
|
49
|
+
readonly apiVersion: '1';
|
|
50
|
+
readonly displayName?: string;
|
|
51
|
+
readonly description?: string;
|
|
52
|
+
readonly commands?: readonly CommandContribution[];
|
|
53
|
+
readonly hooks?: readonly LifecycleHookName[];
|
|
54
|
+
}
|
|
55
|
+
interface ManifestSource {
|
|
56
|
+
readonly name?: string;
|
|
57
|
+
readonly version?: string;
|
|
58
|
+
readonly main?: string;
|
|
59
|
+
readonly devaudit?: unknown;
|
|
60
|
+
readonly [key: string]: unknown;
|
|
61
|
+
}
|
|
62
|
+
interface ManifestValidationOk {
|
|
63
|
+
readonly valid: true;
|
|
64
|
+
readonly manifest: PluginManifest;
|
|
65
|
+
readonly packageName: string;
|
|
66
|
+
readonly packageVersion: string;
|
|
67
|
+
readonly main: string;
|
|
68
|
+
}
|
|
69
|
+
interface ManifestValidationFail {
|
|
70
|
+
readonly valid: false;
|
|
71
|
+
readonly errors: readonly string[];
|
|
72
|
+
}
|
|
73
|
+
type ManifestValidationResult = ManifestValidationOk | ManifestValidationFail;
|
|
74
|
+
declare function validateManifest(input: unknown): ManifestValidationResult;
|
|
75
|
+
|
|
76
|
+
export { type CommandContribution, LIFECYCLE_HOOK_NAMES, type LifecycleHook, type LifecycleHookName, type ManifestSource, type ManifestValidationFail, type ManifestValidationOk, type ManifestValidationResult, type Plugin, type PluginCommand, type PluginContext, type PluginEvent, type PluginLogger, type PluginManifest, type PluginSdlcConfigView, SUPPORTED_API_VERSIONS, isLifecycleHookName, isValidCommandName, validateManifest };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// src/commands.ts
|
|
2
|
+
var COMMAND_NAME_RE = /^[a-z][a-z0-9-]*$/;
|
|
3
|
+
function isValidCommandName(value) {
|
|
4
|
+
return typeof value === "string" && COMMAND_NAME_RE.test(value);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// src/lifecycle.ts
|
|
8
|
+
var LIFECYCLE_HOOK_NAMES = [
|
|
9
|
+
"beforeInstall",
|
|
10
|
+
"afterInstall",
|
|
11
|
+
"beforeUpdate",
|
|
12
|
+
"afterUpdate",
|
|
13
|
+
"beforePush",
|
|
14
|
+
"afterPush",
|
|
15
|
+
"beforeSync",
|
|
16
|
+
"afterSync",
|
|
17
|
+
"onDoctor"
|
|
18
|
+
];
|
|
19
|
+
function isLifecycleHookName(value) {
|
|
20
|
+
return typeof value === "string" && LIFECYCLE_HOOK_NAMES.includes(value);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/manifest.ts
|
|
24
|
+
var SUPPORTED_API_VERSIONS = ["1"];
|
|
25
|
+
function validateManifest(input) {
|
|
26
|
+
const errors = [];
|
|
27
|
+
if (typeof input !== "object" || input === null) {
|
|
28
|
+
return { valid: false, errors: ["manifest source must be an object (got null or non-object)"] };
|
|
29
|
+
}
|
|
30
|
+
const src = input;
|
|
31
|
+
const name = requireString(src, "name", errors);
|
|
32
|
+
const version = requireString(src, "version", errors);
|
|
33
|
+
const main = requireString(src, "main", errors);
|
|
34
|
+
const devaudit = src.devaudit;
|
|
35
|
+
if (typeof devaudit !== "object" || devaudit === null) {
|
|
36
|
+
errors.push("package.json must include a top-level `devaudit` object");
|
|
37
|
+
return { valid: false, errors };
|
|
38
|
+
}
|
|
39
|
+
const d = devaudit;
|
|
40
|
+
const apiVersion = d["apiVersion"];
|
|
41
|
+
if (typeof apiVersion !== "string") {
|
|
42
|
+
errors.push("devaudit.apiVersion must be a string");
|
|
43
|
+
} else if (!SUPPORTED_API_VERSIONS.includes(apiVersion)) {
|
|
44
|
+
errors.push(`devaudit.apiVersion '${apiVersion}' is not supported (supported: ${SUPPORTED_API_VERSIONS.join(", ")})`);
|
|
45
|
+
}
|
|
46
|
+
const commands = validateCommands(d["commands"], errors);
|
|
47
|
+
const hooks = validateHooks(d["hooks"], errors);
|
|
48
|
+
if (errors.length > 0) return { valid: false, errors };
|
|
49
|
+
const manifest = {
|
|
50
|
+
apiVersion: "1",
|
|
51
|
+
...typeof d["displayName"] === "string" ? { displayName: d["displayName"] } : {},
|
|
52
|
+
...typeof d["description"] === "string" ? { description: d["description"] } : {},
|
|
53
|
+
...commands ? { commands } : {},
|
|
54
|
+
...hooks ? { hooks } : {}
|
|
55
|
+
};
|
|
56
|
+
return { valid: true, manifest, packageName: name, packageVersion: version, main };
|
|
57
|
+
}
|
|
58
|
+
function requireString(src, key, errors) {
|
|
59
|
+
const value = src[key];
|
|
60
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
61
|
+
errors.push(`package.json must include a non-empty '${key}' string`);
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
function validateCommands(input, errors) {
|
|
67
|
+
if (input === void 0) return null;
|
|
68
|
+
if (!Array.isArray(input)) {
|
|
69
|
+
errors.push("devaudit.commands must be an array");
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const out = [];
|
|
73
|
+
for (const entry of input) {
|
|
74
|
+
if (typeof entry !== "object" || entry === null) {
|
|
75
|
+
errors.push("devaudit.commands[] entries must be objects");
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const e = entry;
|
|
79
|
+
const name = e["name"];
|
|
80
|
+
const description = e["description"];
|
|
81
|
+
if (!isValidCommandName(name)) {
|
|
82
|
+
errors.push(`devaudit.commands[].name must match /^[a-z][a-z0-9-]*$/, got: ${JSON.stringify(name)}`);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (typeof description !== "string") {
|
|
86
|
+
errors.push(`devaudit.commands[].description must be a string (for command '${name}')`);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
out.push({ name, description });
|
|
90
|
+
}
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
function validateHooks(input, errors) {
|
|
94
|
+
if (input === void 0) return null;
|
|
95
|
+
if (!Array.isArray(input)) {
|
|
96
|
+
errors.push("devaudit.hooks must be an array");
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const out = [];
|
|
100
|
+
for (const entry of input) {
|
|
101
|
+
if (!isLifecycleHookName(entry)) {
|
|
102
|
+
errors.push(`devaudit.hooks[] entry '${String(entry)}' is not a recognised lifecycle hook`);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
out.push(entry);
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { LIFECYCLE_HOOK_NAMES, SUPPORTED_API_VERSIONS, isLifecycleHookName, isValidCommandName, validateManifest };
|
|
111
|
+
//# sourceMappingURL=index.js.map
|
|
112
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands.ts","../src/lifecycle.ts","../src/manifest.ts"],"names":[],"mappings":";AAKA,IAAM,eAAA,GAAkB,mBAAA;AAEjB,SAAS,mBAAmB,KAAA,EAAiC;AAClE,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,eAAA,CAAgB,KAAK,KAAK,CAAA;AAChE;;;ACTO,IAAM,oBAAA,GAAuB;AAAA,EAClC,eAAA;AAAA,EACA,cAAA;AAAA,EACA,cAAA;AAAA,EACA,aAAA;AAAA,EACA,YAAA;AAAA,EACA,WAAA;AAAA,EACA,YAAA;AAAA,EACA,WAAA;AAAA,EACA;AACF;AAIO,SAAS,oBAAoB,KAAA,EAA4C;AAC9E,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAa,oBAAA,CAA2C,SAAS,KAAK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AAoB,KAAK,CAAA,EAAG;AAC/B,MAAA,MAAA,CAAO,IAAA,CAAK,CAAA,wBAAA,EAA2B,MAAA,CAAO,KAAK,CAAC,CAAA,oCAAA,CAAsC,CAAA;AAC1F,MAAA;AAAA,IACF;AACA,IAAA,GAAA,CAAI,KAAK,KAAK,CAAA;AAAA,EAChB;AACA,EAAA,OAAO,GAAA;AACT","file":"index.js","sourcesContent":["export interface CommandContribution {\n readonly name: string;\n readonly description: string;\n}\n\nconst COMMAND_NAME_RE = /^[a-z][a-z0-9-]*$/;\n\nexport function isValidCommandName(value: unknown): value is string {\n return typeof value === 'string' && COMMAND_NAME_RE.test(value);\n}\n","export const LIFECYCLE_HOOK_NAMES = [\n 'beforeInstall',\n 'afterInstall',\n 'beforeUpdate',\n 'afterUpdate',\n 'beforePush',\n 'afterPush',\n 'beforeSync',\n 'afterSync',\n 'onDoctor',\n] as const;\n\nexport type LifecycleHookName = (typeof LIFECYCLE_HOOK_NAMES)[number];\n\nexport function isLifecycleHookName(value: unknown): value is LifecycleHookName {\n return typeof value === 'string' && (LIFECYCLE_HOOK_NAMES as readonly string[]).includes(value);\n}\n","import type { CommandContribution } from './commands.js';\nimport { isValidCommandName } from './commands.js';\nimport type { LifecycleHookName } from './lifecycle.js';\nimport { isLifecycleHookName } from './lifecycle.js';\n\nexport const SUPPORTED_API_VERSIONS: readonly string[] = ['1'];\n\nexport interface PluginManifest {\n readonly apiVersion: '1';\n readonly displayName?: string;\n readonly description?: string;\n readonly commands?: readonly CommandContribution[];\n readonly hooks?: readonly LifecycleHookName[];\n}\n\nexport interface ManifestSource {\n readonly name?: string;\n readonly version?: string;\n readonly main?: string;\n readonly devaudit?: unknown;\n readonly [key: string]: unknown;\n}\n\nexport interface ManifestValidationOk {\n readonly valid: true;\n readonly manifest: PluginManifest;\n readonly packageName: string;\n readonly packageVersion: string;\n readonly main: string;\n}\n\nexport interface ManifestValidationFail {\n readonly valid: false;\n readonly errors: readonly string[];\n}\n\nexport type ManifestValidationResult = ManifestValidationOk | ManifestValidationFail;\n\nexport function validateManifest(input: unknown): ManifestValidationResult {\n const errors: string[] = [];\n if (typeof input !== 'object' || input === null) {\n return { valid: false, errors: ['manifest source must be an object (got null or non-object)'] };\n }\n const src = input as ManifestSource;\n const name = requireString(src, 'name', errors);\n const version = requireString(src, 'version', errors);\n const main = requireString(src, 'main', errors);\n const devaudit = src.devaudit;\n if (typeof devaudit !== 'object' || devaudit === null) {\n errors.push('package.json must include a top-level `devaudit` object');\n return { valid: false, errors };\n }\n const d = devaudit as Record<string, unknown>;\n const apiVersion = d['apiVersion'];\n if (typeof apiVersion !== 'string') {\n errors.push('devaudit.apiVersion must be a string');\n } else if (!SUPPORTED_API_VERSIONS.includes(apiVersion)) {\n errors.push(`devaudit.apiVersion '${apiVersion}' is not supported (supported: ${SUPPORTED_API_VERSIONS.join(', ')})`);\n }\n const commands = validateCommands(d['commands'], errors);\n const hooks = validateHooks(d['hooks'], errors);\n if (errors.length > 0) return { valid: false, errors };\n const manifest: PluginManifest = {\n apiVersion: '1',\n ...(typeof d['displayName'] === 'string' ? { displayName: d['displayName'] } : {}),\n ...(typeof d['description'] === 'string' ? { description: d['description'] } : {}),\n ...(commands ? { commands } : {}),\n ...(hooks ? { hooks } : {}),\n };\n return { valid: true, manifest, packageName: name!, packageVersion: version!, main: main! };\n}\n\nfunction requireString(src: Record<string, unknown>, key: string, errors: string[]): string | null {\n const value = src[key];\n if (typeof value !== 'string' || value.length === 0) {\n errors.push(`package.json must include a non-empty '${key}' string`);\n return null;\n }\n return value;\n}\n\nfunction validateCommands(input: unknown, errors: string[]): readonly CommandContribution[] | null {\n if (input === undefined) return null;\n if (!Array.isArray(input)) {\n errors.push('devaudit.commands must be an array');\n return null;\n }\n const out: CommandContribution[] = [];\n for (const entry of input) {\n if (typeof entry !== 'object' || entry === null) {\n errors.push('devaudit.commands[] entries must be objects');\n continue;\n }\n const e = entry as Record<string, unknown>;\n const name = e['name'];\n const description = e['description'];\n if (!isValidCommandName(name)) {\n errors.push(`devaudit.commands[].name must match /^[a-z][a-z0-9-]*$/, got: ${JSON.stringify(name)}`);\n continue;\n }\n if (typeof description !== 'string') {\n errors.push(`devaudit.commands[].description must be a string (for command '${name}')`);\n continue;\n }\n out.push({ name, description });\n }\n return out;\n}\n\nfunction validateHooks(input: unknown, errors: string[]): readonly LifecycleHookName[] | null {\n if (input === undefined) return null;\n if (!Array.isArray(input)) {\n errors.push('devaudit.hooks must be an array');\n return null;\n }\n const out: LifecycleHookName[] = [];\n for (const entry of input) {\n if (!isLifecycleHookName(entry)) {\n errors.push(`devaudit.hooks[] entry '${String(entry)}' is not a recognised lifecycle hook`);\n continue;\n }\n out.push(entry);\n }\n return out;\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@metasession.co/devaudit-plugin-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "DevAudit CLI plugin contract — interfaces, manifest schema, and lifecycle hooks that DevAudit plugins compile against.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=22"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsup",
|
|
24
|
+
"dev": "tsup --watch",
|
|
25
|
+
"test": "vitest run",
|
|
26
|
+
"test:watch": "vitest",
|
|
27
|
+
"typecheck": "tsc --noEmit"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^22.9.0",
|
|
31
|
+
"tsup": "^8.3.5",
|
|
32
|
+
"typescript": "^5.7.2",
|
|
33
|
+
"vitest": "^4.1.6"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/metasession-dev/DevAudit-Installer",
|
|
41
|
+
"directory": "plugin-sdk"
|
|
42
|
+
},
|
|
43
|
+
"license": "Apache-2.0"
|
|
44
|
+
}
|