@apinteract/plugin-sdk 0.1.0-bootstrap.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 +21 -0
- package/README.md +25 -0
- package/dist/backend/import.d.ts +22 -0
- package/dist/backend/import.js +71 -0
- package/dist/backend/import.js.map +1 -0
- package/dist/frontend/localization.d.ts +2 -0
- package/dist/frontend/localization.js +5 -0
- package/dist/frontend/localization.js.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 APInteract contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# `@apinteract/plugin-sdk`
|
|
2
|
+
|
|
3
|
+
Optional authoring helpers for APInteract plugins.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pnpm add --save-dev @apinteract/plugin-api @apinteract/plugin-sdk
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Helpers are grouped by target and purpose:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { parseJsonObject } from "@apinteract/plugin-sdk/backend/import";
|
|
13
|
+
import { localize } from "@apinteract/plugin-sdk/frontend/localization";
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The SDK is independently versioned from the plugin contract. Plugin builds
|
|
17
|
+
must bundle SDK runtime helpers into their own `dist/` output; an installed
|
|
18
|
+
plugin must not require this package at runtime.
|
|
19
|
+
|
|
20
|
+
See the [plugin development guide](https://github.com/xirelogy/apinteract/blob/main/docs/plugins/README.md)
|
|
21
|
+
for packaging and compatibility details.
|
|
22
|
+
|
|
23
|
+
## License
|
|
24
|
+
|
|
25
|
+
MIT
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ImportSource } from "@apinteract/plugin-api/backend";
|
|
2
|
+
/** Represents an import-provider failure that the host may safely expose. */
|
|
3
|
+
export declare class ImportProviderError extends Error {
|
|
4
|
+
readonly code: string;
|
|
5
|
+
constructor(code: string, message: string);
|
|
6
|
+
}
|
|
7
|
+
/** Reports whether an unknown JSON value is a non-array object. */
|
|
8
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
9
|
+
/** Narrows an unknown JSON array without exposing an any-valued result. */
|
|
10
|
+
export declare function unknownArray(value: unknown): readonly unknown[];
|
|
11
|
+
/** Parses one JSON import source and requires an object document root. */
|
|
12
|
+
export declare function parseJsonObject(source: ImportSource): Record<string, unknown>;
|
|
13
|
+
/** Reads a string value or returns the supplied fallback. */
|
|
14
|
+
export declare function stringValue(value: unknown, fallback?: string): string;
|
|
15
|
+
/** Converts a JSON-compatible example into one editable text value. */
|
|
16
|
+
export declare function editableValue(value: unknown): string;
|
|
17
|
+
/** Derives a bounded display name after removing one declared extension. */
|
|
18
|
+
export declare function sourceStem(name: string, extensions: readonly string[]): string;
|
|
19
|
+
/** Returns the UTF-8 byte length of one imported text value. */
|
|
20
|
+
export declare function utf8Bytes(value: string): number;
|
|
21
|
+
/** Returns an ISO timestamp only when the source contains a valid instant. */
|
|
22
|
+
export declare function optionalTimestamp(value: unknown): string | null;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** Represents an import-provider failure that the host may safely expose. */
|
|
2
|
+
export class ImportProviderError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(code, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.code = code;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** Reports whether an unknown JSON value is a non-array object. */
|
|
10
|
+
export function isRecord(value) {
|
|
11
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12
|
+
}
|
|
13
|
+
/** Narrows an unknown JSON array without exposing an any-valued result. */
|
|
14
|
+
export function unknownArray(value) {
|
|
15
|
+
return Array.isArray(value) ? value : [];
|
|
16
|
+
}
|
|
17
|
+
/** Parses one JSON import source and requires an object document root. */
|
|
18
|
+
export function parseJsonObject(source) {
|
|
19
|
+
let value;
|
|
20
|
+
try {
|
|
21
|
+
value = JSON.parse(source.text);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
throw new ImportProviderError("import_json_invalid", `${source.name} does not contain valid JSON.`);
|
|
25
|
+
}
|
|
26
|
+
if (!isRecord(value)) {
|
|
27
|
+
throw new ImportProviderError("import_json_invalid", `${source.name} must contain a JSON object.`);
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
/** Reads a string value or returns the supplied fallback. */
|
|
32
|
+
export function stringValue(value, fallback = "") {
|
|
33
|
+
return typeof value === "string" ? value : fallback;
|
|
34
|
+
}
|
|
35
|
+
/** Converts a JSON-compatible example into one editable text value. */
|
|
36
|
+
export function editableValue(value) {
|
|
37
|
+
if (value === undefined || value === null)
|
|
38
|
+
return "";
|
|
39
|
+
if (typeof value === "string")
|
|
40
|
+
return value;
|
|
41
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
42
|
+
return String(value);
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
return JSON.stringify(value);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return "";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** Derives a bounded display name after removing one declared extension. */
|
|
52
|
+
export function sourceStem(name, extensions) {
|
|
53
|
+
const withoutPath = name.split(/[\\/]/).at(-1) ?? name;
|
|
54
|
+
const extension = extensions.find((candidate) => withoutPath.toLowerCase().endsWith(candidate.toLowerCase()));
|
|
55
|
+
const stem = (extension === undefined
|
|
56
|
+
? withoutPath
|
|
57
|
+
: withoutPath.slice(0, -extension.length)).trim();
|
|
58
|
+
return (stem || "Imported requests").slice(0, 200);
|
|
59
|
+
}
|
|
60
|
+
/** Returns the UTF-8 byte length of one imported text value. */
|
|
61
|
+
export function utf8Bytes(value) {
|
|
62
|
+
return Buffer.byteLength(value, "utf8");
|
|
63
|
+
}
|
|
64
|
+
/** Returns an ISO timestamp only when the source contains a valid instant. */
|
|
65
|
+
export function optionalTimestamp(value) {
|
|
66
|
+
if (typeof value !== "string")
|
|
67
|
+
return null;
|
|
68
|
+
const timestamp = Date.parse(value);
|
|
69
|
+
return Number.isFinite(timestamp) ? new Date(timestamp).toISOString() : null;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=import.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import.js","sourceRoot":"","sources":["../../src/backend/import.ts"],"names":[],"mappings":"AAEA,6EAA6E;AAC7E,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACnC,IAAI,CAAS;IAEtB,YAAY,IAAY,EAAE,OAAe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;IAC3C,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACpC,OAAO,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/E,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Resolves package-owned text through exact locale, base language, and default fallbacks. */
|
|
2
|
+
export function localize(fallback, translations, locale) {
|
|
3
|
+
return (translations[locale] ?? translations[locale.split("-")[0] ?? ""] ?? fallback);
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=localization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization.js","sourceRoot":"","sources":["../../src/frontend/localization.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,MAAM,UAAU,QAAQ,CACtB,QAAgB,EAChB,YAA8C,EAC9C,MAAc;IAEd,OAAO,CACL,YAAY,CAAC,MAAM,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,QAAQ,CAC7E,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@apinteract/plugin-sdk",
|
|
3
|
+
"version": "0.1.0-bootstrap.0",
|
|
4
|
+
"description": "Optional authoring helpers for developing APInteract plugins.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://github.com/xirelogy/apinteract/tree/main/packages/plugin-sdk#readme",
|
|
7
|
+
"bugs": "https://github.com/xirelogy/apinteract/issues",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/xirelogy/apinteract.git",
|
|
11
|
+
"directory": "packages/plugin-sdk"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"exports": {
|
|
21
|
+
"./backend/import": {
|
|
22
|
+
"types": "./dist/backend/import.d.ts",
|
|
23
|
+
"default": "./dist/backend/import.js"
|
|
24
|
+
},
|
|
25
|
+
"./frontend/localization": {
|
|
26
|
+
"types": "./dist/frontend/localization.d.ts",
|
|
27
|
+
"default": "./dist/frontend/localization.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@apinteract/plugin-api": "^0.1.0-0"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public",
|
|
35
|
+
"provenance": true,
|
|
36
|
+
"registry": "https://registry.npmjs.org/"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "24.10.0",
|
|
40
|
+
"typescript": "5.9.3",
|
|
41
|
+
"@apinteract/plugin-api": "0.1.0-bootstrap.0"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsc -p tsconfig.build.json",
|
|
45
|
+
"typecheck": "tsc --noEmit"
|
|
46
|
+
}
|
|
47
|
+
}
|