@harborclient/sdk 1.0.36 → 1.0.39
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/dist/signing/manifest.d.ts +5 -3
- package/dist/signing/manifest.d.ts.map +1 -1
- package/dist/signing/manifest.js +27 -6
- package/dist/signing/testFixtures.d.ts +9 -0
- package/dist/signing/testFixtures.d.ts.map +1 -1
- package/dist/signing/testFixtures.js +26 -0
- package/dist/snippets.d.ts +131 -0
- package/package.json +14 -2
|
@@ -6,11 +6,13 @@ export interface PluginManifestIdentity {
|
|
|
6
6
|
version: string;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
|
-
* Reads and validates plugin id and version from manifest.json.
|
|
9
|
+
* Reads and validates plugin id and version from manifest.json or snippets.json.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* Prefers manifest.json when both files are present.
|
|
12
|
+
*
|
|
13
|
+
* @param pluginDir - Plugin or snippet bundle root directory.
|
|
12
14
|
* @returns Parsed manifest identity fields.
|
|
13
|
-
* @throws When manifest
|
|
15
|
+
* @throws When neither manifest file exists or validation fails.
|
|
14
16
|
*/
|
|
15
17
|
export declare function readPluginManifestIdentity(pluginDir: string): PluginManifestIdentity;
|
|
16
18
|
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/signing/manifest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/signing/manifest.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;CACjB;AAmCD;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,MAAM,GAAG,sBAAsB,CAcpF"}
|
package/dist/signing/manifest.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
const PLUGIN_ID_PATTERN = /^[a-zA-Z][a-zA-Z0-9.-]*\.[a-zA-Z][a-zA-Z0-9.-]+$/;
|
|
4
|
+
const PLUGIN_MANIFEST_FILENAME = 'manifest.json';
|
|
5
|
+
const SNIPPET_MANIFEST_FILENAME = 'snippets.json';
|
|
4
6
|
/**
|
|
5
|
-
*
|
|
7
|
+
* Parses and validates id and version from a manifest.json or snippets.json file.
|
|
6
8
|
*
|
|
7
|
-
* @param
|
|
9
|
+
* @param manifestPath - Absolute path to the manifest file on disk.
|
|
8
10
|
* @returns Parsed manifest identity fields.
|
|
9
|
-
* @throws When
|
|
11
|
+
* @throws When the file is invalid JSON or fails validation.
|
|
10
12
|
*/
|
|
11
|
-
|
|
12
|
-
const manifestPath = join(pluginDir, 'manifest.json');
|
|
13
|
+
function parseManifestIdentityFile(manifestPath) {
|
|
13
14
|
let raw;
|
|
14
15
|
try {
|
|
15
16
|
raw = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
@@ -31,3 +32,23 @@ export function readPluginManifestIdentity(pluginDir) {
|
|
|
31
32
|
}
|
|
32
33
|
return { id, version };
|
|
33
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Reads and validates plugin id and version from manifest.json or snippets.json.
|
|
37
|
+
*
|
|
38
|
+
* Prefers manifest.json when both files are present.
|
|
39
|
+
*
|
|
40
|
+
* @param pluginDir - Plugin or snippet bundle root directory.
|
|
41
|
+
* @returns Parsed manifest identity fields.
|
|
42
|
+
* @throws When neither manifest file exists or validation fails.
|
|
43
|
+
*/
|
|
44
|
+
export function readPluginManifestIdentity(pluginDir) {
|
|
45
|
+
const manifestPath = join(pluginDir, PLUGIN_MANIFEST_FILENAME);
|
|
46
|
+
if (existsSync(manifestPath)) {
|
|
47
|
+
return parseManifestIdentityFile(manifestPath);
|
|
48
|
+
}
|
|
49
|
+
const snippetsPath = join(pluginDir, SNIPPET_MANIFEST_FILENAME);
|
|
50
|
+
if (existsSync(snippetsPath)) {
|
|
51
|
+
return parseManifestIdentityFile(snippetsPath);
|
|
52
|
+
}
|
|
53
|
+
throw new Error(`Plugin or snippet manifest not found: expected ${PLUGIN_MANIFEST_FILENAME} or ${SNIPPET_MANIFEST_FILENAME} in ${pluginDir}`);
|
|
54
|
+
}
|
|
@@ -18,4 +18,13 @@ export declare function createTestPluginDir(pluginId?: string): {
|
|
|
18
18
|
pluginDir: string;
|
|
19
19
|
cleanup: () => void;
|
|
20
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* Creates a minimal snippet bundle directory suitable for signing tests.
|
|
23
|
+
*
|
|
24
|
+
* @param catalogId - Snippet bundle id from snippets.json.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createTestSnippetDir(catalogId?: string): {
|
|
27
|
+
pluginDir: string;
|
|
28
|
+
cleanup: () => void;
|
|
29
|
+
};
|
|
21
30
|
//# sourceMappingURL=testFixtures.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testFixtures.d.ts","sourceRoot":"","sources":["../../src/signing/testFixtures.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,eAAe,CASvD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,SAA4B,GAAG;IACzE,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CA0BA"}
|
|
1
|
+
{"version":3,"file":"testFixtures.d.ts","sourceRoot":"","sources":["../../src/signing/testFixtures.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,eAAe,CASvD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,SAA4B,GAAG;IACzE,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CA0BA;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,SAA8B,GAAG;IAC7E,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CA4BA"}
|
|
@@ -39,3 +39,29 @@ export function createTestPluginDir(pluginId = 'com.example.test-plugin') {
|
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates a minimal snippet bundle directory suitable for signing tests.
|
|
44
|
+
*
|
|
45
|
+
* @param catalogId - Snippet bundle id from snippets.json.
|
|
46
|
+
*/
|
|
47
|
+
export function createTestSnippetDir(catalogId = 'com.example.test-snippets') {
|
|
48
|
+
const pluginDir = mkdtempSync(join(tmpdir(), 'hc-snippet-sign-'));
|
|
49
|
+
mkdirSync(join(pluginDir, 'dist'), { recursive: true });
|
|
50
|
+
writeFileSync(join(pluginDir, 'snippets.json'), JSON.stringify({
|
|
51
|
+
id: catalogId,
|
|
52
|
+
name: 'Test Snippets',
|
|
53
|
+
version: '1.0.0',
|
|
54
|
+
summary: 'Test snippet bundle for signing.',
|
|
55
|
+
author: 'Example Inc.',
|
|
56
|
+
categories: ['testing'],
|
|
57
|
+
engines: { harborclient: '>=2.0.0' },
|
|
58
|
+
snippets: [{ name: 'Tester', where: 'post-request', file: 'dist/tester.js' }]
|
|
59
|
+
}, null, 2));
|
|
60
|
+
writeFileSync(join(pluginDir, 'dist', 'tester.js'), 'hc.test("ok", () => true);');
|
|
61
|
+
return {
|
|
62
|
+
pluginDir,
|
|
63
|
+
cleanup: () => {
|
|
64
|
+
rmSync(pluginDir, { recursive: true, force: true });
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ambient globals for HarborClient request/post-request script snippets.
|
|
3
|
+
*
|
|
4
|
+
* Keep in sync with the runtime hc sandbox in harborclient
|
|
5
|
+
* `src/main/scripting/scriptApi.ts` and editor completions in
|
|
6
|
+
* `src/renderer/src/scripting/hcCompletions.ts`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Header helpers on hc.request.headers and hc.collection.headers.
|
|
11
|
+
*/
|
|
12
|
+
interface HcHeaderApi {
|
|
13
|
+
/**
|
|
14
|
+
* Returns the first enabled header value for key (case-insensitive), or undefined.
|
|
15
|
+
*/
|
|
16
|
+
get(key: string): string | undefined;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Sets an existing header or appends a new enabled row.
|
|
20
|
+
*/
|
|
21
|
+
upsert(key: string, value: string): void;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Returns enabled headers as a flat key/value map.
|
|
25
|
+
*/
|
|
26
|
+
toObject(): Record<string, string>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Variable helpers on hc.variables, hc.collection.variables, hc.environment.variables, and hc.globals.
|
|
31
|
+
*/
|
|
32
|
+
interface HcVariablesApi {
|
|
33
|
+
/**
|
|
34
|
+
* Returns a variable value, preferring values set in the current script run.
|
|
35
|
+
*/
|
|
36
|
+
get(key: string): string | undefined;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Sets a variable for the remainder of the script run.
|
|
40
|
+
*/
|
|
41
|
+
set(key: string, value: unknown): void;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Replaces {{variable}} tokens and dynamic $ tokens in a template string.
|
|
45
|
+
*/
|
|
46
|
+
replaceIn(template: unknown): string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Chai-lite matcher returned by hc.expect(actual).
|
|
51
|
+
*/
|
|
52
|
+
interface HcExpectMatcher {
|
|
53
|
+
to: {
|
|
54
|
+
equal(expected: unknown): void;
|
|
55
|
+
eql(expected: unknown): void;
|
|
56
|
+
include(substr: string): void;
|
|
57
|
+
};
|
|
58
|
+
be: {
|
|
59
|
+
ok(): void;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Element surface exposed by hc.response.document() for HTML bodies.
|
|
65
|
+
*/
|
|
66
|
+
interface HcResponseElement {
|
|
67
|
+
textContent: string;
|
|
68
|
+
getAttribute(name: string): string | null;
|
|
69
|
+
innerHTML: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Document surface backed by Cheerio for querying HTML response bodies.
|
|
74
|
+
*/
|
|
75
|
+
interface HcResponseDocument {
|
|
76
|
+
querySelector(selector: string): HcResponseElement | null;
|
|
77
|
+
querySelectorAll(selector: string): HcResponseElement[];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Response snapshot available in post-request scripts as hc.response.
|
|
82
|
+
*/
|
|
83
|
+
interface HcResponseApi {
|
|
84
|
+
readonly code: number;
|
|
85
|
+
readonly status: string;
|
|
86
|
+
readonly headers: Record<string, string>;
|
|
87
|
+
readonly responseTime: number;
|
|
88
|
+
text(): string;
|
|
89
|
+
json(): unknown;
|
|
90
|
+
document(): HcResponseDocument;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* HarborClient script sandbox API exposed as the global hc object.
|
|
95
|
+
*/
|
|
96
|
+
interface HcScriptApi {
|
|
97
|
+
request: {
|
|
98
|
+
method: string;
|
|
99
|
+
url: string;
|
|
100
|
+
body: string;
|
|
101
|
+
headers: HcHeaderApi;
|
|
102
|
+
};
|
|
103
|
+
variables: HcVariablesApi;
|
|
104
|
+
collection: {
|
|
105
|
+
readonly id: number | null;
|
|
106
|
+
readonly name: string;
|
|
107
|
+
variables: HcVariablesApi;
|
|
108
|
+
headers: HcHeaderApi;
|
|
109
|
+
};
|
|
110
|
+
environment: {
|
|
111
|
+
readonly name: string;
|
|
112
|
+
variables: HcVariablesApi;
|
|
113
|
+
};
|
|
114
|
+
globals: HcVariablesApi;
|
|
115
|
+
test(name: string, fn: () => void): void;
|
|
116
|
+
expect(actual: unknown): HcExpectMatcher;
|
|
117
|
+
response: HcResponseApi;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* HarborClient script sandbox API for pre/post request scripts and snippet files.
|
|
122
|
+
*/
|
|
123
|
+
declare const hc: HcScriptApi;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Capturing console available inside request/post-request script sandboxes.
|
|
127
|
+
*/
|
|
128
|
+
declare const console: {
|
|
129
|
+
log(...args: unknown[]): void;
|
|
130
|
+
error(...args: unknown[]): void;
|
|
131
|
+
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harborclient/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.39",
|
|
4
4
|
"description": "TypeScript SDK for HarborClient development.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"harborclient",
|
|
7
|
-
"
|
|
7
|
+
"plugins",
|
|
8
|
+
"themes",
|
|
9
|
+
"snippets",
|
|
8
10
|
"typescript",
|
|
9
11
|
"types"
|
|
10
12
|
],
|
|
@@ -66,6 +68,9 @@
|
|
|
66
68
|
"./main": {
|
|
67
69
|
"types": "./dist/main.d.ts"
|
|
68
70
|
},
|
|
71
|
+
"./snippets": {
|
|
72
|
+
"types": "./dist/snippets.d.ts"
|
|
73
|
+
},
|
|
69
74
|
"./http": {
|
|
70
75
|
"types": "./dist/http/index.d.ts",
|
|
71
76
|
"import": "./dist/http/index.js",
|
|
@@ -144,6 +149,13 @@
|
|
|
144
149
|
"default": "./dist/styles.css"
|
|
145
150
|
}
|
|
146
151
|
},
|
|
152
|
+
"typesVersions": {
|
|
153
|
+
"*": {
|
|
154
|
+
"snippets": [
|
|
155
|
+
"./dist/snippets.d.ts"
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
},
|
|
147
159
|
"bin": {
|
|
148
160
|
"hc-plugin-sign": "./dist/signing/cli-sign.js",
|
|
149
161
|
"hc-plugin-verify": "./dist/signing/cli-verify.js"
|