@swetate/core 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/dist/error.d.ts +6 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +8 -0
- package/dist/error.js.map +1 -0
- package/dist/iframe.d.ts +2 -0
- package/dist/iframe.d.ts.map +1 -0
- package/dist/iframe.js +9 -0
- package/dist/iframe.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/sdk.d.ts +3 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +57 -0
- package/dist/sdk.js.map +1 -0
- package/package.json +26 -0
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,qBAAa,UAAW,SAAQ,KAAK;IACnC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;gBAElB,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM;CAKlD"}
|
package/dist/error.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,UAAW,SAAQ,KAAK;IAGnC,YAAY,IAAoB,EAAE,OAAe;QAC/C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
|
package/dist/iframe.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iframe.d.ts","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,IAAI,OAAO,CAMpC"}
|
package/dist/iframe.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iframe.js","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,UAAU;IACxB,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,GAAG,CAAC;IACpC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,YAAY,EACV,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,aAAa,GACd,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/sdk.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EAGX,aAAa,EACd,MAAM,gBAAgB,CAAC;AAYxB,wBAAgB,WAAW,CAAC,MAAM,GAAE,WAAgB,GAAG,aAAa,CA4DnE"}
|
package/dist/sdk.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { PiSDKError } from './error';
|
|
3
|
+
const DEFAULT_TIMEOUT = 10000;
|
|
4
|
+
function createHttpClient(config) {
|
|
5
|
+
return axios.create({
|
|
6
|
+
baseURL: config.backendUrl,
|
|
7
|
+
timeout: DEFAULT_TIMEOUT,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export function createPiSDK(config = {}) {
|
|
11
|
+
const backendClient = createHttpClient(config);
|
|
12
|
+
const internals = new Map();
|
|
13
|
+
const context = {
|
|
14
|
+
backendClient,
|
|
15
|
+
config,
|
|
16
|
+
inject(name) {
|
|
17
|
+
return internals.get(name);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
const instance = {
|
|
21
|
+
backendClient,
|
|
22
|
+
use(plugin) {
|
|
23
|
+
if (!plugin.name) {
|
|
24
|
+
throw new PiSDKError('PLUGIN_INVALID', 'Plugins must have a non-empty "name" property.');
|
|
25
|
+
}
|
|
26
|
+
if (internals.has(plugin.name)) {
|
|
27
|
+
throw new PiSDKError('PLUGIN_DUPLICATE', `A plugin named "${plugin.name}" has already been registered.`);
|
|
28
|
+
}
|
|
29
|
+
const namespacedClient = createHttpClient(config);
|
|
30
|
+
namespacedClient.interceptors.request.use((req) => {
|
|
31
|
+
// Ensures plugin requests are automatically namespaced as /pi/{name}/{apiVersion}{path}
|
|
32
|
+
const normalizedPath = req.url?.startsWith('/') ? req.url : `/${req.url ?? ''}`;
|
|
33
|
+
req.url = `/pi/${plugin.name}/${plugin.apiVersion}${normalizedPath}`;
|
|
34
|
+
return req;
|
|
35
|
+
});
|
|
36
|
+
const pluginContext = { ...context, backendClient: namespacedClient };
|
|
37
|
+
const result = plugin.install(pluginContext);
|
|
38
|
+
if (result?.internal) {
|
|
39
|
+
internals.set(plugin.name, result.internal);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// Always set internals so we prevent double-installation even when no methods made available
|
|
43
|
+
internals.set(plugin.name, {});
|
|
44
|
+
}
|
|
45
|
+
if (result?.public) {
|
|
46
|
+
instance[plugin.name] = result.public;
|
|
47
|
+
// Also mount under camelCase for ergonomic dot-access (e.g. pi.userState alongside pi["user-state"]).
|
|
48
|
+
const camelName = plugin.name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
49
|
+
if (camelName !== plugin.name) {
|
|
50
|
+
instance[camelName] = result.public;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
return instance;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=sdk.js.map
|
package/dist/sdk.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAO1B,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,MAAM,eAAe,GAAG,KAAM,CAAC;AAE/B,SAAS,gBAAgB,CAAC,MAAmB;IAC3C,OAAO,KAAK,CAAC,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC,UAAU;QAC1B,OAAO,EAAE,eAAe;KACzB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,SAAsB,EAAE;IAClD,MAAM,aAAa,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC/C,MAAM,SAAS,GAAG,IAAI,GAAG,EAAmC,CAAC;IAE7D,MAAM,OAAO,GAAiB;QAC5B,aAAa;QACb,MAAM;QACN,MAAM,CAAI,IAAY;YACpB,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,CAAkB,CAAC;QAC9C,CAAC;KACF,CAAC;IAEF,MAAM,QAAQ,GAAkB;QAC9B,aAAa;QAEb,GAAG,CAAC,MAAmB;YACrB,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;gBACjB,MAAM,IAAI,UAAU,CA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gBACtC,sGAAsG;gBACtG,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,MAAc,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;gBAChG,IAAI,SAAS,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC;oBAC9B,QAAQ,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;gBACtC,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAC;IAEF,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@swetate/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Runtime foundation for Pi SDK — plugin registry, HTTP client, error handling",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": ["dist"],
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"clean": "rm -rf dist",
|
|
11
|
+
"test": "vitest run",
|
|
12
|
+
"publish:local": "npm run clean && npm run build && yalc publish"
|
|
13
|
+
},
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@swetate/types": "^0.1.0",
|
|
20
|
+
"axios": "^1.9.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"typescript": "^5.9.0",
|
|
24
|
+
"vitest": "^4.0.18"
|
|
25
|
+
}
|
|
26
|
+
}
|